#define IMX_OCOTP_OFFSET_B0W0 0x400 /* Offset from base address of the * OTP Bank0 Word0
*/ #define IMX_OCOTP_OFFSET_PER_WORD 0x10 /* Offset between the start addr * of two consecutive OTP words.
*/
for (count = 10000; count >= 0; count--) {
c = readl(base + IMX_OCOTP_ADDR_CTRL); if (!(c & mask)) break;
cpu_relax();
}
if (count < 0) { /* HW_OCOTP_CTRL[ERROR] will be set under the following * conditions: * - A write is performed to a shadow register during a shadow * reload (essentially, while HW_OCOTP_CTRL[RELOAD_SHADOWS] is * set. In addition, the contents of the shadow register shall * not be updated. * - A write is performed to a shadow register which has been * locked. * - A read is performed to from a shadow register which has * been read locked. * - A program is performed to a fuse word which has been locked * - A read is performed to from a fuse word which has been read * locked.
*/ if (c & bm_ctrl_error) return -EPERM; return -ETIMEDOUT;
}
p = kzalloc(num_bytes, GFP_KERNEL); if (!p) return -ENOMEM;
mutex_lock(&ocotp_mutex);
buf = p;
ret = clk_prepare_enable(priv->clk); if (ret < 0) {
mutex_unlock(&ocotp_mutex);
dev_err(priv->dev, "failed to prepare/enable ocotp clk\n");
kfree(p); return ret;
}
ret = imx_ocotp_wait_for_busy(priv, 0); if (ret < 0) {
dev_err(priv->dev, "timeout during read setup\n"); goto read_end;
}
for (i = index; i < (index + count); i++) {
*(u32 *)buf = readl(priv->base + IMX_OCOTP_OFFSET_B0W0 +
i * IMX_OCOTP_OFFSET_PER_WORD);
/* 47.3.1.2 * For "read locked" registers 0xBADABADA will be returned and * HW_OCOTP_CTRL[ERROR] will be set. It must be cleared by * software before any new write, read or reload access can be * issued
*/ if (*((u32 *)buf) == IMX_OCOTP_READ_LOCKED_VAL)
imx_ocotp_clr_err_if_set(priv);
buf += 4;
}
index = offset % 4;
memcpy(val, &p[index], bytes);
staticint imx_ocotp_cell_pp(void *context, constchar *id, int index, unsignedint offset, void *data, size_t bytes)
{
u8 *buf = data; int i;
/* Deal with some post processing of nvmem cell data */ if (id && !strcmp(id, "mac-address")) {
bytes = min(bytes, ETH_ALEN); for (i = 0; i < bytes / 2; i++)
swap(buf[i], buf[bytes - i - 1]);
}
/* 47.3.1.3.1 * Program HW_OCOTP_TIMING[STROBE_PROG] and HW_OCOTP_TIMING[RELAX] * fields with timing values to match the current frequency of the * ipg_clk. OTP writes will work at maximum bus frequencies as long * as the HW_OCOTP_TIMING parameters are set correctly. * * Note: there are minimum timings required to ensure an OTP fuse burns * correctly that are independent of the ipg_clk. Those values are not * formally documented anywhere however, working from the minimum * timings given in u-boot we can say: * * - Minimum STROBE_PROG time is 10 microseconds. Intuitively 10 * microseconds feels about right as representative of a minimum time * to physically burn out a fuse. * * - Minimum STROBE_READ i.e. the time to wait post OTP fuse burn before * performing another read is 37 nanoseconds * * - Minimum RELAX timing is 17 nanoseconds. This final RELAX minimum * timing is not entirely clear the documentation says "This * count value specifies the time to add to all default timing * parameters other than the Tpgm and Trd. It is given in number * of ipg_clk periods." where Tpgm and Trd refer to STROBE_PROG * and STROBE_READ respectively. What the other timing parameters * are though, is not specified. Experience shows a zero RELAX * value will mess up a re-load of the shadow registers post OTP * burn.
*/
clk_rate = clk_get_rate(priv->clk);
/* allow only writing one complete OTP word at a time */ if ((bytes != priv->config->word_size) ||
(offset % priv->config->word_size)) return -EINVAL;
mutex_lock(&ocotp_mutex);
ret = clk_prepare_enable(priv->clk); if (ret < 0) {
mutex_unlock(&ocotp_mutex);
dev_err(priv->dev, "failed to prepare/enable ocotp clk\n"); return ret;
}
/* Setup the write timing values */
priv->params->set_timing(priv);
/* 47.3.1.3.2 * Check that HW_OCOTP_CTRL[BUSY] and HW_OCOTP_CTRL[ERROR] are clear. * Overlapped accesses are not supported by the controller. Any pending * write or reload must be completed before a write access can be * requested.
*/
ret = imx_ocotp_wait_for_busy(priv, 0); if (ret < 0) {
dev_err(priv->dev, "timeout during timing setup\n"); goto write_end;
}
/* 47.3.1.3.3 * Write the requested address to HW_OCOTP_CTRL[ADDR] and program the * unlock code into HW_OCOTP_CTRL[WR_UNLOCK]. This must be programmed * for each write access. The lock code is documented in the register * description. Both the unlock code and address can be written in the * same operation.
*/ if (priv->params->bank_address_words != 0) { /* * In banked/i.MX7 mode the OTP register bank goes into waddr * see i.MX 7Solo Applications Processor Reference Manual, Rev. * 0.1 section 6.4.3.1
*/
offset = offset / priv->config->word_size;
waddr = offset / priv->params->bank_address_words;
word = offset & (priv->params->bank_address_words - 1);
} else { /* * Non-banked i.MX6 mode. * OTP write/read address specifies one of 128 word address * locations
*/
waddr = offset / 4;
}
/* 47.3.1.3.4 * Write the data to the HW_OCOTP_DATA register. This will automatically * set HW_OCOTP_CTRL[BUSY] and clear HW_OCOTP_CTRL[WR_UNLOCK]. To * protect programming same OTP bit twice, before program OCOTP will * automatically read fuse value in OTP and use read value to mask * program data. The controller will use masked program data to program * a 32-bit word in the OTP per the address in HW_OCOTP_CTRL[ADDR]. Bit * fields with 1's will result in that OTP bit being programmed. Bit * fields with 0's will be ignored. At the same time that the write is * accepted, the controller makes an internal copy of * HW_OCOTP_CTRL[ADDR] which cannot be updated until the next write * sequence is initiated. This copy guarantees that erroneous writes to * HW_OCOTP_CTRL[ADDR] will not affect an active write operation. It * should also be noted that during the programming HW_OCOTP_DATA will * shift right (with zero fill). This shifting is required to program * the OTP serially. During the write operation, HW_OCOTP_DATA cannot be * modified. * Note: on i.MX7 there are four data fields to write for banked write * with the fuse blowing operation only taking place after data0 * has been written. This is why data0 must always be the last * register written.
*/ if (priv->params->bank_address_words != 0) { /* Banked/i.MX7 mode */ switch (word) { case 0:
writel(0, priv->base + IMX_OCOTP_ADDR_DATA1);
writel(0, priv->base + IMX_OCOTP_ADDR_DATA2);
writel(0, priv->base + IMX_OCOTP_ADDR_DATA3);
writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA0); break; case 1:
writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA1);
writel(0, priv->base + IMX_OCOTP_ADDR_DATA2);
writel(0, priv->base + IMX_OCOTP_ADDR_DATA3);
writel(0, priv->base + IMX_OCOTP_ADDR_DATA0); break; case 2:
writel(0, priv->base + IMX_OCOTP_ADDR_DATA1);
writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA2);
writel(0, priv->base + IMX_OCOTP_ADDR_DATA3);
writel(0, priv->base + IMX_OCOTP_ADDR_DATA0); break; case 3:
writel(0, priv->base + IMX_OCOTP_ADDR_DATA1);
writel(0, priv->base + IMX_OCOTP_ADDR_DATA2);
writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA3);
writel(0, priv->base + IMX_OCOTP_ADDR_DATA0); break;
}
} else { /* Non-banked i.MX6 mode */
writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA0);
}
/* 47.4.1.4.5 * Once complete, the controller will clear BUSY. A write request to a * protected or locked region will result in no OTP access and no * setting of HW_OCOTP_CTRL[BUSY]. In addition HW_OCOTP_CTRL[ERROR] will * be set. It must be cleared by software before any new write access * can be issued.
*/
ret = imx_ocotp_wait_for_busy(priv, 0); if (ret < 0) { if (ret == -EPERM) {
dev_err(priv->dev, "failed write to locked region");
imx_ocotp_clr_err_if_set(priv);
} else {
dev_err(priv->dev, "timeout during data write\n");
} goto write_end;
}
/* 47.3.1.4 * Write Postamble: Due to internal electrical characteristics of the * OTP during writes, all OTP operations following a write must be * separated by 2 us after the clearing of HW_OCOTP_CTRL_BUSY following * the write.
*/
udelay(2);
/* reload all shadow registers */
writel(priv->params->ctrl.bm_rel_shadows,
priv->base + IMX_OCOTP_ADDR_CTRL_SET);
ret = imx_ocotp_wait_for_busy(priv,
priv->params->ctrl.bm_rel_shadows); if (ret < 0)
dev_err(priv->dev, "timeout during shadow register reload\n");
write_end:
clk_disable_unprepare(priv->clk);
mutex_unlock(&ocotp_mutex); return ret < 0 ? ret : bytes;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.