Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * i.MX6 OCOTP fusebox driver
0004  *
0005  * Copyright (c) 2015 Pengutronix, Philipp Zabel <p.zabel@pengutronix.de>
0006  *
0007  * Copyright 2019 NXP
0008  *
0009  * Based on the barebox ocotp driver,
0010  * Copyright (c) 2010 Baruch Siach <baruch@tkos.co.il>,
0011  *  Orex Computed Radiography
0012  *
0013  * Write support based on the fsl_otp driver,
0014  * Copyright (C) 2010-2013 Freescale Semiconductor, Inc
0015  */
0016 
0017 #include <linux/clk.h>
0018 #include <linux/device.h>
0019 #include <linux/io.h>
0020 #include <linux/module.h>
0021 #include <linux/nvmem-provider.h>
0022 #include <linux/of.h>
0023 #include <linux/of_device.h>
0024 #include <linux/platform_device.h>
0025 #include <linux/slab.h>
0026 #include <linux/delay.h>
0027 
0028 #define IMX_OCOTP_OFFSET_B0W0       0x400 /* Offset from base address of the
0029                            * OTP Bank0 Word0
0030                            */
0031 #define IMX_OCOTP_OFFSET_PER_WORD   0x10  /* Offset between the start addr
0032                            * of two consecutive OTP words.
0033                            */
0034 
0035 #define IMX_OCOTP_ADDR_CTRL     0x0000
0036 #define IMX_OCOTP_ADDR_CTRL_SET     0x0004
0037 #define IMX_OCOTP_ADDR_CTRL_CLR     0x0008
0038 #define IMX_OCOTP_ADDR_TIMING       0x0010
0039 #define IMX_OCOTP_ADDR_DATA0        0x0020
0040 #define IMX_OCOTP_ADDR_DATA1        0x0030
0041 #define IMX_OCOTP_ADDR_DATA2        0x0040
0042 #define IMX_OCOTP_ADDR_DATA3        0x0050
0043 
0044 #define IMX_OCOTP_BM_CTRL_ADDR      0x000000FF
0045 #define IMX_OCOTP_BM_CTRL_BUSY      0x00000100
0046 #define IMX_OCOTP_BM_CTRL_ERROR     0x00000200
0047 #define IMX_OCOTP_BM_CTRL_REL_SHADOWS   0x00000400
0048 
0049 #define IMX_OCOTP_BM_CTRL_ADDR_8MP      0x000001FF
0050 #define IMX_OCOTP_BM_CTRL_BUSY_8MP      0x00000200
0051 #define IMX_OCOTP_BM_CTRL_ERROR_8MP     0x00000400
0052 #define IMX_OCOTP_BM_CTRL_REL_SHADOWS_8MP   0x00000800
0053 
0054 #define IMX_OCOTP_BM_CTRL_DEFAULT               \
0055     {                           \
0056         .bm_addr = IMX_OCOTP_BM_CTRL_ADDR,      \
0057         .bm_busy = IMX_OCOTP_BM_CTRL_BUSY,      \
0058         .bm_error = IMX_OCOTP_BM_CTRL_ERROR,        \
0059         .bm_rel_shadows = IMX_OCOTP_BM_CTRL_REL_SHADOWS,\
0060     }
0061 
0062 #define IMX_OCOTP_BM_CTRL_8MP                   \
0063     {                           \
0064         .bm_addr = IMX_OCOTP_BM_CTRL_ADDR_8MP,      \
0065         .bm_busy = IMX_OCOTP_BM_CTRL_BUSY_8MP,      \
0066         .bm_error = IMX_OCOTP_BM_CTRL_ERROR_8MP,    \
0067         .bm_rel_shadows = IMX_OCOTP_BM_CTRL_REL_SHADOWS_8MP,\
0068     }
0069 
0070 #define TIMING_STROBE_PROG_US       10  /* Min time to blow a fuse */
0071 #define TIMING_STROBE_READ_NS       37  /* Min time before read */
0072 #define TIMING_RELAX_NS         17
0073 #define DEF_FSOURCE         1001    /* > 1000 ns */
0074 #define DEF_STROBE_PROG         10000   /* IPG clocks */
0075 #define IMX_OCOTP_WR_UNLOCK     0x3E770000
0076 #define IMX_OCOTP_READ_LOCKED_VAL   0xBADABADA
0077 
0078 static DEFINE_MUTEX(ocotp_mutex);
0079 
0080 struct ocotp_priv {
0081     struct device *dev;
0082     struct clk *clk;
0083     void __iomem *base;
0084     const struct ocotp_params *params;
0085     struct nvmem_config *config;
0086 };
0087 
0088 struct ocotp_ctrl_reg {
0089     u32 bm_addr;
0090     u32 bm_busy;
0091     u32 bm_error;
0092     u32 bm_rel_shadows;
0093 };
0094 
0095 struct ocotp_params {
0096     unsigned int nregs;
0097     unsigned int bank_address_words;
0098     void (*set_timing)(struct ocotp_priv *priv);
0099     struct ocotp_ctrl_reg ctrl;
0100     bool reverse_mac_address;
0101 };
0102 
0103 static int imx_ocotp_wait_for_busy(struct ocotp_priv *priv, u32 flags)
0104 {
0105     int count;
0106     u32 c, mask;
0107     u32 bm_ctrl_busy, bm_ctrl_error;
0108     void __iomem *base = priv->base;
0109 
0110     bm_ctrl_busy = priv->params->ctrl.bm_busy;
0111     bm_ctrl_error = priv->params->ctrl.bm_error;
0112 
0113     mask = bm_ctrl_busy | bm_ctrl_error | flags;
0114 
0115     for (count = 10000; count >= 0; count--) {
0116         c = readl(base + IMX_OCOTP_ADDR_CTRL);
0117         if (!(c & mask))
0118             break;
0119         cpu_relax();
0120     }
0121 
0122     if (count < 0) {
0123         /* HW_OCOTP_CTRL[ERROR] will be set under the following
0124          * conditions:
0125          * - A write is performed to a shadow register during a shadow
0126          *   reload (essentially, while HW_OCOTP_CTRL[RELOAD_SHADOWS] is
0127          *   set. In addition, the contents of the shadow register shall
0128          *   not be updated.
0129          * - A write is performed to a shadow register which has been
0130          *   locked.
0131          * - A read is performed to from a shadow register which has
0132          *   been read locked.
0133          * - A program is performed to a fuse word which has been locked
0134          * - A read is performed to from a fuse word which has been read
0135          *   locked.
0136          */
0137         if (c & bm_ctrl_error)
0138             return -EPERM;
0139         return -ETIMEDOUT;
0140     }
0141 
0142     return 0;
0143 }
0144 
0145 static void imx_ocotp_clr_err_if_set(struct ocotp_priv *priv)
0146 {
0147     u32 c, bm_ctrl_error;
0148     void __iomem *base = priv->base;
0149 
0150     bm_ctrl_error = priv->params->ctrl.bm_error;
0151 
0152     c = readl(base + IMX_OCOTP_ADDR_CTRL);
0153     if (!(c & bm_ctrl_error))
0154         return;
0155 
0156     writel(bm_ctrl_error, base + IMX_OCOTP_ADDR_CTRL_CLR);
0157 }
0158 
0159 static int imx_ocotp_read(void *context, unsigned int offset,
0160               void *val, size_t bytes)
0161 {
0162     struct ocotp_priv *priv = context;
0163     unsigned int count;
0164     u8 *buf, *p;
0165     int i, ret;
0166     u32 index, num_bytes;
0167 
0168     index = offset >> 2;
0169     num_bytes = round_up((offset % 4) + bytes, 4);
0170     count = num_bytes >> 2;
0171 
0172     if (count > (priv->params->nregs - index))
0173         count = priv->params->nregs - index;
0174 
0175     p = kzalloc(num_bytes, GFP_KERNEL);
0176     if (!p)
0177         return -ENOMEM;
0178 
0179     mutex_lock(&ocotp_mutex);
0180 
0181     buf = p;
0182 
0183     ret = clk_prepare_enable(priv->clk);
0184     if (ret < 0) {
0185         mutex_unlock(&ocotp_mutex);
0186         dev_err(priv->dev, "failed to prepare/enable ocotp clk\n");
0187         kfree(p);
0188         return ret;
0189     }
0190 
0191     ret = imx_ocotp_wait_for_busy(priv, 0);
0192     if (ret < 0) {
0193         dev_err(priv->dev, "timeout during read setup\n");
0194         goto read_end;
0195     }
0196 
0197     for (i = index; i < (index + count); i++) {
0198         *(u32 *)buf = readl(priv->base + IMX_OCOTP_OFFSET_B0W0 +
0199                    i * IMX_OCOTP_OFFSET_PER_WORD);
0200 
0201         /* 47.3.1.2
0202          * For "read locked" registers 0xBADABADA will be returned and
0203          * HW_OCOTP_CTRL[ERROR] will be set. It must be cleared by
0204          * software before any new write, read or reload access can be
0205          * issued
0206          */
0207         if (*((u32 *)buf) == IMX_OCOTP_READ_LOCKED_VAL)
0208             imx_ocotp_clr_err_if_set(priv);
0209 
0210         buf += 4;
0211     }
0212 
0213     index = offset % 4;
0214     memcpy(val, &p[index], bytes);
0215 
0216 read_end:
0217     clk_disable_unprepare(priv->clk);
0218     mutex_unlock(&ocotp_mutex);
0219 
0220     kfree(p);
0221 
0222     return ret;
0223 }
0224 
0225 static int imx_ocotp_cell_pp(void *context, const char *id, unsigned int offset,
0226                  void *data, size_t bytes)
0227 {
0228     struct ocotp_priv *priv = context;
0229 
0230     /* Deal with some post processing of nvmem cell data */
0231     if (id && !strcmp(id, "mac-address")) {
0232         if (priv->params->reverse_mac_address) {
0233             u8 *buf = data;
0234             int i;
0235 
0236             for (i = 0; i < bytes/2; i++)
0237                 swap(buf[i], buf[bytes - i - 1]);
0238         }
0239     }
0240 
0241     return 0;
0242 }
0243 
0244 static void imx_ocotp_set_imx6_timing(struct ocotp_priv *priv)
0245 {
0246     unsigned long clk_rate;
0247     unsigned long strobe_read, relax, strobe_prog;
0248     u32 timing;
0249 
0250     /* 47.3.1.3.1
0251      * Program HW_OCOTP_TIMING[STROBE_PROG] and HW_OCOTP_TIMING[RELAX]
0252      * fields with timing values to match the current frequency of the
0253      * ipg_clk. OTP writes will work at maximum bus frequencies as long
0254      * as the HW_OCOTP_TIMING parameters are set correctly.
0255      *
0256      * Note: there are minimum timings required to ensure an OTP fuse burns
0257      * correctly that are independent of the ipg_clk. Those values are not
0258      * formally documented anywhere however, working from the minimum
0259      * timings given in u-boot we can say:
0260      *
0261      * - Minimum STROBE_PROG time is 10 microseconds. Intuitively 10
0262      *   microseconds feels about right as representative of a minimum time
0263      *   to physically burn out a fuse.
0264      *
0265      * - Minimum STROBE_READ i.e. the time to wait post OTP fuse burn before
0266      *   performing another read is 37 nanoseconds
0267      *
0268      * - Minimum RELAX timing is 17 nanoseconds. This final RELAX minimum
0269      *   timing is not entirely clear the documentation says "This
0270      *   count value specifies the time to add to all default timing
0271      *   parameters other than the Tpgm and Trd. It is given in number
0272      *   of ipg_clk periods." where Tpgm and Trd refer to STROBE_PROG
0273      *   and STROBE_READ respectively. What the other timing parameters
0274      *   are though, is not specified. Experience shows a zero RELAX
0275      *   value will mess up a re-load of the shadow registers post OTP
0276      *   burn.
0277      */
0278     clk_rate = clk_get_rate(priv->clk);
0279 
0280     relax = DIV_ROUND_UP(clk_rate * TIMING_RELAX_NS, 1000000000) - 1;
0281     strobe_read = DIV_ROUND_UP(clk_rate * TIMING_STROBE_READ_NS,
0282                    1000000000);
0283     strobe_read += 2 * (relax + 1) - 1;
0284     strobe_prog = DIV_ROUND_CLOSEST(clk_rate * TIMING_STROBE_PROG_US,
0285                     1000000);
0286     strobe_prog += 2 * (relax + 1) - 1;
0287 
0288     timing = readl(priv->base + IMX_OCOTP_ADDR_TIMING) & 0x0FC00000;
0289     timing |= strobe_prog & 0x00000FFF;
0290     timing |= (relax       << 12) & 0x0000F000;
0291     timing |= (strobe_read << 16) & 0x003F0000;
0292 
0293     writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING);
0294 }
0295 
0296 static void imx_ocotp_set_imx7_timing(struct ocotp_priv *priv)
0297 {
0298     unsigned long clk_rate;
0299     u64 fsource, strobe_prog;
0300     u32 timing;
0301 
0302     /* i.MX 7Solo Applications Processor Reference Manual, Rev. 0.1
0303      * 6.4.3.3
0304      */
0305     clk_rate = clk_get_rate(priv->clk);
0306     fsource = DIV_ROUND_UP_ULL((u64)clk_rate * DEF_FSOURCE,
0307                    NSEC_PER_SEC) + 1;
0308     strobe_prog = DIV_ROUND_CLOSEST_ULL((u64)clk_rate * DEF_STROBE_PROG,
0309                         NSEC_PER_SEC) + 1;
0310 
0311     timing = strobe_prog & 0x00000FFF;
0312     timing |= (fsource << 12) & 0x000FF000;
0313 
0314     writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING);
0315 }
0316 
0317 static int imx_ocotp_write(void *context, unsigned int offset, void *val,
0318                size_t bytes)
0319 {
0320     struct ocotp_priv *priv = context;
0321     u32 *buf = val;
0322     int ret;
0323 
0324     u32 ctrl;
0325     u8 waddr;
0326     u8 word = 0;
0327 
0328     /* allow only writing one complete OTP word at a time */
0329     if ((bytes != priv->config->word_size) ||
0330         (offset % priv->config->word_size))
0331         return -EINVAL;
0332 
0333     mutex_lock(&ocotp_mutex);
0334 
0335     ret = clk_prepare_enable(priv->clk);
0336     if (ret < 0) {
0337         mutex_unlock(&ocotp_mutex);
0338         dev_err(priv->dev, "failed to prepare/enable ocotp clk\n");
0339         return ret;
0340     }
0341 
0342     /* Setup the write timing values */
0343     priv->params->set_timing(priv);
0344 
0345     /* 47.3.1.3.2
0346      * Check that HW_OCOTP_CTRL[BUSY] and HW_OCOTP_CTRL[ERROR] are clear.
0347      * Overlapped accesses are not supported by the controller. Any pending
0348      * write or reload must be completed before a write access can be
0349      * requested.
0350      */
0351     ret = imx_ocotp_wait_for_busy(priv, 0);
0352     if (ret < 0) {
0353         dev_err(priv->dev, "timeout during timing setup\n");
0354         goto write_end;
0355     }
0356 
0357     /* 47.3.1.3.3
0358      * Write the requested address to HW_OCOTP_CTRL[ADDR] and program the
0359      * unlock code into HW_OCOTP_CTRL[WR_UNLOCK]. This must be programmed
0360      * for each write access. The lock code is documented in the register
0361      * description. Both the unlock code and address can be written in the
0362      * same operation.
0363      */
0364     if (priv->params->bank_address_words != 0) {
0365         /*
0366          * In banked/i.MX7 mode the OTP register bank goes into waddr
0367          * see i.MX 7Solo Applications Processor Reference Manual, Rev.
0368          * 0.1 section 6.4.3.1
0369          */
0370         offset = offset / priv->config->word_size;
0371         waddr = offset / priv->params->bank_address_words;
0372         word  = offset & (priv->params->bank_address_words - 1);
0373     } else {
0374         /*
0375          * Non-banked i.MX6 mode.
0376          * OTP write/read address specifies one of 128 word address
0377          * locations
0378          */
0379         waddr = offset / 4;
0380     }
0381 
0382     ctrl = readl(priv->base + IMX_OCOTP_ADDR_CTRL);
0383     ctrl &= ~priv->params->ctrl.bm_addr;
0384     ctrl |= waddr & priv->params->ctrl.bm_addr;
0385     ctrl |= IMX_OCOTP_WR_UNLOCK;
0386 
0387     writel(ctrl, priv->base + IMX_OCOTP_ADDR_CTRL);
0388 
0389     /* 47.3.1.3.4
0390      * Write the data to the HW_OCOTP_DATA register. This will automatically
0391      * set HW_OCOTP_CTRL[BUSY] and clear HW_OCOTP_CTRL[WR_UNLOCK]. To
0392      * protect programming same OTP bit twice, before program OCOTP will
0393      * automatically read fuse value in OTP and use read value to mask
0394      * program data. The controller will use masked program data to program
0395      * a 32-bit word in the OTP per the address in HW_OCOTP_CTRL[ADDR]. Bit
0396      * fields with 1's will result in that OTP bit being programmed. Bit
0397      * fields with 0's will be ignored. At the same time that the write is
0398      * accepted, the controller makes an internal copy of
0399      * HW_OCOTP_CTRL[ADDR] which cannot be updated until the next write
0400      * sequence is initiated. This copy guarantees that erroneous writes to
0401      * HW_OCOTP_CTRL[ADDR] will not affect an active write operation. It
0402      * should also be noted that during the programming HW_OCOTP_DATA will
0403      * shift right (with zero fill). This shifting is required to program
0404      * the OTP serially. During the write operation, HW_OCOTP_DATA cannot be
0405      * modified.
0406      * Note: on i.MX7 there are four data fields to write for banked write
0407      *       with the fuse blowing operation only taking place after data0
0408      *   has been written. This is why data0 must always be the last
0409      *   register written.
0410      */
0411     if (priv->params->bank_address_words != 0) {
0412         /* Banked/i.MX7 mode */
0413         switch (word) {
0414         case 0:
0415             writel(0, priv->base + IMX_OCOTP_ADDR_DATA1);
0416             writel(0, priv->base + IMX_OCOTP_ADDR_DATA2);
0417             writel(0, priv->base + IMX_OCOTP_ADDR_DATA3);
0418             writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA0);
0419             break;
0420         case 1:
0421             writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA1);
0422             writel(0, priv->base + IMX_OCOTP_ADDR_DATA2);
0423             writel(0, priv->base + IMX_OCOTP_ADDR_DATA3);
0424             writel(0, priv->base + IMX_OCOTP_ADDR_DATA0);
0425             break;
0426         case 2:
0427             writel(0, priv->base + IMX_OCOTP_ADDR_DATA1);
0428             writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA2);
0429             writel(0, priv->base + IMX_OCOTP_ADDR_DATA3);
0430             writel(0, priv->base + IMX_OCOTP_ADDR_DATA0);
0431             break;
0432         case 3:
0433             writel(0, priv->base + IMX_OCOTP_ADDR_DATA1);
0434             writel(0, priv->base + IMX_OCOTP_ADDR_DATA2);
0435             writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA3);
0436             writel(0, priv->base + IMX_OCOTP_ADDR_DATA0);
0437             break;
0438         }
0439     } else {
0440         /* Non-banked i.MX6 mode */
0441         writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA0);
0442     }
0443 
0444     /* 47.4.1.4.5
0445      * Once complete, the controller will clear BUSY. A write request to a
0446      * protected or locked region will result in no OTP access and no
0447      * setting of HW_OCOTP_CTRL[BUSY]. In addition HW_OCOTP_CTRL[ERROR] will
0448      * be set. It must be cleared by software before any new write access
0449      * can be issued.
0450      */
0451     ret = imx_ocotp_wait_for_busy(priv, 0);
0452     if (ret < 0) {
0453         if (ret == -EPERM) {
0454             dev_err(priv->dev, "failed write to locked region");
0455             imx_ocotp_clr_err_if_set(priv);
0456         } else {
0457             dev_err(priv->dev, "timeout during data write\n");
0458         }
0459         goto write_end;
0460     }
0461 
0462     /* 47.3.1.4
0463      * Write Postamble: Due to internal electrical characteristics of the
0464      * OTP during writes, all OTP operations following a write must be
0465      * separated by 2 us after the clearing of HW_OCOTP_CTRL_BUSY following
0466      * the write.
0467      */
0468     udelay(2);
0469 
0470     /* reload all shadow registers */
0471     writel(priv->params->ctrl.bm_rel_shadows,
0472            priv->base + IMX_OCOTP_ADDR_CTRL_SET);
0473     ret = imx_ocotp_wait_for_busy(priv,
0474                       priv->params->ctrl.bm_rel_shadows);
0475     if (ret < 0)
0476         dev_err(priv->dev, "timeout during shadow register reload\n");
0477 
0478 write_end:
0479     clk_disable_unprepare(priv->clk);
0480     mutex_unlock(&ocotp_mutex);
0481     return ret < 0 ? ret : bytes;
0482 }
0483 
0484 static struct nvmem_config imx_ocotp_nvmem_config = {
0485     .name = "imx-ocotp",
0486     .read_only = false,
0487     .word_size = 4,
0488     .stride = 1,
0489     .reg_read = imx_ocotp_read,
0490     .reg_write = imx_ocotp_write,
0491     .cell_post_process = imx_ocotp_cell_pp,
0492 };
0493 
0494 static const struct ocotp_params imx6q_params = {
0495     .nregs = 128,
0496     .bank_address_words = 0,
0497     .set_timing = imx_ocotp_set_imx6_timing,
0498     .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
0499 };
0500 
0501 static const struct ocotp_params imx6sl_params = {
0502     .nregs = 64,
0503     .bank_address_words = 0,
0504     .set_timing = imx_ocotp_set_imx6_timing,
0505     .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
0506 };
0507 
0508 static const struct ocotp_params imx6sll_params = {
0509     .nregs = 128,
0510     .bank_address_words = 0,
0511     .set_timing = imx_ocotp_set_imx6_timing,
0512     .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
0513 };
0514 
0515 static const struct ocotp_params imx6sx_params = {
0516     .nregs = 128,
0517     .bank_address_words = 0,
0518     .set_timing = imx_ocotp_set_imx6_timing,
0519     .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
0520 };
0521 
0522 static const struct ocotp_params imx6ul_params = {
0523     .nregs = 128,
0524     .bank_address_words = 0,
0525     .set_timing = imx_ocotp_set_imx6_timing,
0526     .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
0527 };
0528 
0529 static const struct ocotp_params imx6ull_params = {
0530     .nregs = 64,
0531     .bank_address_words = 0,
0532     .set_timing = imx_ocotp_set_imx6_timing,
0533     .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
0534 };
0535 
0536 static const struct ocotp_params imx7d_params = {
0537     .nregs = 64,
0538     .bank_address_words = 4,
0539     .set_timing = imx_ocotp_set_imx7_timing,
0540     .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
0541 };
0542 
0543 static const struct ocotp_params imx7ulp_params = {
0544     .nregs = 256,
0545     .bank_address_words = 0,
0546     .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
0547 };
0548 
0549 static const struct ocotp_params imx8mq_params = {
0550     .nregs = 256,
0551     .bank_address_words = 0,
0552     .set_timing = imx_ocotp_set_imx6_timing,
0553     .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
0554     .reverse_mac_address = true,
0555 };
0556 
0557 static const struct ocotp_params imx8mm_params = {
0558     .nregs = 256,
0559     .bank_address_words = 0,
0560     .set_timing = imx_ocotp_set_imx6_timing,
0561     .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
0562     .reverse_mac_address = true,
0563 };
0564 
0565 static const struct ocotp_params imx8mn_params = {
0566     .nregs = 256,
0567     .bank_address_words = 0,
0568     .set_timing = imx_ocotp_set_imx6_timing,
0569     .ctrl = IMX_OCOTP_BM_CTRL_DEFAULT,
0570     .reverse_mac_address = true,
0571 };
0572 
0573 static const struct ocotp_params imx8mp_params = {
0574     .nregs = 384,
0575     .bank_address_words = 0,
0576     .set_timing = imx_ocotp_set_imx6_timing,
0577     .ctrl = IMX_OCOTP_BM_CTRL_8MP,
0578     .reverse_mac_address = true,
0579 };
0580 
0581 static const struct of_device_id imx_ocotp_dt_ids[] = {
0582     { .compatible = "fsl,imx6q-ocotp",  .data = &imx6q_params },
0583     { .compatible = "fsl,imx6sl-ocotp", .data = &imx6sl_params },
0584     { .compatible = "fsl,imx6sx-ocotp", .data = &imx6sx_params },
0585     { .compatible = "fsl,imx6ul-ocotp", .data = &imx6ul_params },
0586     { .compatible = "fsl,imx6ull-ocotp", .data = &imx6ull_params },
0587     { .compatible = "fsl,imx7d-ocotp",  .data = &imx7d_params },
0588     { .compatible = "fsl,imx6sll-ocotp", .data = &imx6sll_params },
0589     { .compatible = "fsl,imx7ulp-ocotp", .data = &imx7ulp_params },
0590     { .compatible = "fsl,imx8mq-ocotp", .data = &imx8mq_params },
0591     { .compatible = "fsl,imx8mm-ocotp", .data = &imx8mm_params },
0592     { .compatible = "fsl,imx8mn-ocotp", .data = &imx8mn_params },
0593     { .compatible = "fsl,imx8mp-ocotp", .data = &imx8mp_params },
0594     { },
0595 };
0596 MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids);
0597 
0598 static int imx_ocotp_probe(struct platform_device *pdev)
0599 {
0600     struct device *dev = &pdev->dev;
0601     struct ocotp_priv *priv;
0602     struct nvmem_device *nvmem;
0603 
0604     priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
0605     if (!priv)
0606         return -ENOMEM;
0607 
0608     priv->dev = dev;
0609 
0610     priv->base = devm_platform_ioremap_resource(pdev, 0);
0611     if (IS_ERR(priv->base))
0612         return PTR_ERR(priv->base);
0613 
0614     priv->clk = devm_clk_get(dev, NULL);
0615     if (IS_ERR(priv->clk))
0616         return PTR_ERR(priv->clk);
0617 
0618     priv->params = of_device_get_match_data(&pdev->dev);
0619     imx_ocotp_nvmem_config.size = 4 * priv->params->nregs;
0620     imx_ocotp_nvmem_config.dev = dev;
0621     imx_ocotp_nvmem_config.priv = priv;
0622     priv->config = &imx_ocotp_nvmem_config;
0623 
0624     clk_prepare_enable(priv->clk);
0625     imx_ocotp_clr_err_if_set(priv);
0626     clk_disable_unprepare(priv->clk);
0627 
0628     nvmem = devm_nvmem_register(dev, &imx_ocotp_nvmem_config);
0629 
0630     return PTR_ERR_OR_ZERO(nvmem);
0631 }
0632 
0633 static struct platform_driver imx_ocotp_driver = {
0634     .probe  = imx_ocotp_probe,
0635     .driver = {
0636         .name   = "imx_ocotp",
0637         .of_match_table = imx_ocotp_dt_ids,
0638     },
0639 };
0640 module_platform_driver(imx_ocotp_driver);
0641 
0642 MODULE_AUTHOR("Philipp Zabel <p.zabel@pengutronix.de>");
0643 MODULE_DESCRIPTION("i.MX6/i.MX7 OCOTP fuse box driver");
0644 MODULE_LICENSE("GPL v2");