blob: f4e117bbf2c3e49ab1101decf2abde7314eeadbf [file] [log] [blame]
Thomas Gleixneracee2e82019-06-04 10:10:53 +02001// SPDX-License-Identifier: GPL-2.0-only
Philipp Zabel3edba6b2015-09-30 13:55:47 +01002/*
3 * i.MX6 OCOTP fusebox driver
4 *
5 * Copyright (c) 2015 Pengutronix, Philipp Zabel <p.zabel@pengutronix.de>
6 *
7 * Based on the barebox ocotp driver,
8 * Copyright (c) 2010 Baruch Siach <baruch@tkos.co.il>,
9 * Orex Computed Radiography
10 *
Richard Leitner0642bac2017-03-31 13:44:55 +010011 * Write support based on the fsl_otp driver,
12 * Copyright (C) 2010-2013 Freescale Semiconductor, Inc
Philipp Zabel3edba6b2015-09-30 13:55:47 +010013 */
14
Peng Fandeb31972016-06-02 12:05:11 +010015#include <linux/clk.h>
Philipp Zabel3edba6b2015-09-30 13:55:47 +010016#include <linux/device.h>
17#include <linux/io.h>
18#include <linux/module.h>
19#include <linux/nvmem-provider.h>
20#include <linux/of.h>
21#include <linux/of_device.h>
22#include <linux/platform_device.h>
Philipp Zabel3edba6b2015-09-30 13:55:47 +010023#include <linux/slab.h>
Richard Leitner0642bac2017-03-31 13:44:55 +010024#include <linux/delay.h>
Philipp Zabel3edba6b2015-09-30 13:55:47 +010025
Richard Leitner9b665872017-03-31 13:44:54 +010026#define IMX_OCOTP_OFFSET_B0W0 0x400 /* Offset from base address of the
27 * OTP Bank0 Word0
28 */
29#define IMX_OCOTP_OFFSET_PER_WORD 0x10 /* Offset between the start addr
30 * of two consecutive OTP words.
31 */
Richard Leitner0642bac2017-03-31 13:44:55 +010032
Richard Leitner9b665872017-03-31 13:44:54 +010033#define IMX_OCOTP_ADDR_CTRL 0x0000
Richard Leitner0642bac2017-03-31 13:44:55 +010034#define IMX_OCOTP_ADDR_CTRL_SET 0x0004
Richard Leitner9b665872017-03-31 13:44:54 +010035#define IMX_OCOTP_ADDR_CTRL_CLR 0x0008
Richard Leitner0642bac2017-03-31 13:44:55 +010036#define IMX_OCOTP_ADDR_TIMING 0x0010
Bryan O'Donoghueffd91152017-10-24 10:54:29 +010037#define IMX_OCOTP_ADDR_DATA0 0x0020
38#define IMX_OCOTP_ADDR_DATA1 0x0030
39#define IMX_OCOTP_ADDR_DATA2 0x0040
40#define IMX_OCOTP_ADDR_DATA3 0x0050
Richard Leitner9b665872017-03-31 13:44:54 +010041
Bryan O'Donoghuec03bb442019-06-26 11:27:28 +010042#define IMX_OCOTP_BM_CTRL_ADDR 0x000000FF
Richard Leitner0642bac2017-03-31 13:44:55 +010043#define IMX_OCOTP_BM_CTRL_BUSY 0x00000100
Richard Leitner9b665872017-03-31 13:44:54 +010044#define IMX_OCOTP_BM_CTRL_ERROR 0x00000200
Richard Leitner0642bac2017-03-31 13:44:55 +010045#define IMX_OCOTP_BM_CTRL_REL_SHADOWS 0x00000400
Richard Leitner9b665872017-03-31 13:44:54 +010046
Bryan O'Donoghue828ae7a42017-10-24 10:54:31 +010047#define DEF_RELAX 20 /* > 16.5ns */
48#define DEF_FSOURCE 1001 /* > 1000 ns */
49#define DEF_STROBE_PROG 10000 /* IPG clocks */
Richard Leitner0642bac2017-03-31 13:44:55 +010050#define IMX_OCOTP_WR_UNLOCK 0x3E770000
Richard Leitner9b665872017-03-31 13:44:54 +010051#define IMX_OCOTP_READ_LOCKED_VAL 0xBADABADA
52
Richard Leitner0642bac2017-03-31 13:44:55 +010053static DEFINE_MUTEX(ocotp_mutex);
54
Philipp Zabel3edba6b2015-09-30 13:55:47 +010055struct ocotp_priv {
56 struct device *dev;
Peng Fandeb31972016-06-02 12:05:11 +010057 struct clk *clk;
Philipp Zabel3edba6b2015-09-30 13:55:47 +010058 void __iomem *base;
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +010059 const struct ocotp_params *params;
Richard Leitner0642bac2017-03-31 13:44:55 +010060 struct nvmem_config *config;
Philipp Zabel3edba6b2015-09-30 13:55:47 +010061};
62
Bryan O'Donoghue828ae7a42017-10-24 10:54:31 +010063struct ocotp_params {
64 unsigned int nregs;
65 unsigned int bank_address_words;
66 void (*set_timing)(struct ocotp_priv *priv);
67};
68
Richard Leitner0642bac2017-03-31 13:44:55 +010069static int imx_ocotp_wait_for_busy(void __iomem *base, u32 flags)
70{
71 int count;
72 u32 c, mask;
73
74 mask = IMX_OCOTP_BM_CTRL_BUSY | IMX_OCOTP_BM_CTRL_ERROR | flags;
75
76 for (count = 10000; count >= 0; count--) {
77 c = readl(base + IMX_OCOTP_ADDR_CTRL);
78 if (!(c & mask))
79 break;
80 cpu_relax();
81 }
82
83 if (count < 0) {
84 /* HW_OCOTP_CTRL[ERROR] will be set under the following
85 * conditions:
86 * - A write is performed to a shadow register during a shadow
87 * reload (essentially, while HW_OCOTP_CTRL[RELOAD_SHADOWS] is
88 * set. In addition, the contents of the shadow register shall
89 * not be updated.
90 * - A write is performed to a shadow register which has been
91 * locked.
92 * - A read is performed to from a shadow register which has
93 * been read locked.
94 * - A program is performed to a fuse word which has been locked
95 * - A read is performed to from a fuse word which has been read
96 * locked.
97 */
98 if (c & IMX_OCOTP_BM_CTRL_ERROR)
99 return -EPERM;
100 return -ETIMEDOUT;
101 }
102
103 return 0;
104}
105
Richard Leitner9b665872017-03-31 13:44:54 +0100106static void imx_ocotp_clr_err_if_set(void __iomem *base)
107{
108 u32 c;
109
110 c = readl(base + IMX_OCOTP_ADDR_CTRL);
111 if (!(c & IMX_OCOTP_BM_CTRL_ERROR))
112 return;
113
114 writel(IMX_OCOTP_BM_CTRL_ERROR, base + IMX_OCOTP_ADDR_CTRL_CLR);
115}
116
Srinivas Kandagatla33e5e292016-04-24 20:28:13 +0100117static int imx_ocotp_read(void *context, unsigned int offset,
118 void *val, size_t bytes)
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100119{
120 struct ocotp_priv *priv = context;
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100121 unsigned int count;
Srinivas Kandagatla33e5e292016-04-24 20:28:13 +0100122 u32 *buf = val;
Peng Fandeb31972016-06-02 12:05:11 +0100123 int i, ret;
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100124 u32 index;
125
126 index = offset >> 2;
Srinivas Kandagatla33e5e292016-04-24 20:28:13 +0100127 count = bytes >> 2;
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100128
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +0100129 if (count > (priv->params->nregs - index))
130 count = priv->params->nregs - index;
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100131
Richard Leitner0642bac2017-03-31 13:44:55 +0100132 mutex_lock(&ocotp_mutex);
133
Peng Fandeb31972016-06-02 12:05:11 +0100134 ret = clk_prepare_enable(priv->clk);
135 if (ret < 0) {
Richard Leitner0642bac2017-03-31 13:44:55 +0100136 mutex_unlock(&ocotp_mutex);
Peng Fandeb31972016-06-02 12:05:11 +0100137 dev_err(priv->dev, "failed to prepare/enable ocotp clk\n");
138 return ret;
139 }
Richard Leitner9b665872017-03-31 13:44:54 +0100140
Richard Leitner0642bac2017-03-31 13:44:55 +0100141 ret = imx_ocotp_wait_for_busy(priv->base, 0);
142 if (ret < 0) {
143 dev_err(priv->dev, "timeout during read setup\n");
144 goto read_end;
145 }
146
Richard Leitner9b665872017-03-31 13:44:54 +0100147 for (i = index; i < (index + count); i++) {
148 *buf++ = readl(priv->base + IMX_OCOTP_OFFSET_B0W0 +
149 i * IMX_OCOTP_OFFSET_PER_WORD);
150
151 /* 47.3.1.2
152 * For "read locked" registers 0xBADABADA will be returned and
153 * HW_OCOTP_CTRL[ERROR] will be set. It must be cleared by
154 * software before any new write, read or reload access can be
155 * issued
156 */
157 if (*(buf - 1) == IMX_OCOTP_READ_LOCKED_VAL)
158 imx_ocotp_clr_err_if_set(priv->base);
159 }
Richard Leitner0642bac2017-03-31 13:44:55 +0100160 ret = 0;
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100161
Richard Leitner0642bac2017-03-31 13:44:55 +0100162read_end:
Peng Fandeb31972016-06-02 12:05:11 +0100163 clk_disable_unprepare(priv->clk);
Richard Leitner0642bac2017-03-31 13:44:55 +0100164 mutex_unlock(&ocotp_mutex);
165 return ret;
166}
167
Bryan O'Donoghueb50cb682017-10-24 10:54:30 +0100168static void imx_ocotp_set_imx6_timing(struct ocotp_priv *priv)
Richard Leitner0642bac2017-03-31 13:44:55 +0100169{
Richard Leitner0642bac2017-03-31 13:44:55 +0100170 unsigned long clk_rate = 0;
171 unsigned long strobe_read, relax, strobe_prog;
172 u32 timing = 0;
Richard Leitner0642bac2017-03-31 13:44:55 +0100173
174 /* 47.3.1.3.1
175 * Program HW_OCOTP_TIMING[STROBE_PROG] and HW_OCOTP_TIMING[RELAX]
176 * fields with timing values to match the current frequency of the
177 * ipg_clk. OTP writes will work at maximum bus frequencies as long
178 * as the HW_OCOTP_TIMING parameters are set correctly.
179 */
180 clk_rate = clk_get_rate(priv->clk);
181
182 relax = clk_rate / (1000000000 / DEF_RELAX) - 1;
183 strobe_prog = clk_rate / (1000000000 / 10000) + 2 * (DEF_RELAX + 1) - 1;
184 strobe_read = clk_rate / (1000000000 / 40) + 2 * (DEF_RELAX + 1) - 1;
185
Bryan O'Donoghue0493c472019-06-26 11:27:29 +0100186 timing = readl(priv->base + IMX_OCOTP_ADDR_TIMING) & 0x0FC00000;
187 timing |= strobe_prog & 0x00000FFF;
Richard Leitner0642bac2017-03-31 13:44:55 +0100188 timing |= (relax << 12) & 0x0000F000;
189 timing |= (strobe_read << 16) & 0x003F0000;
190
191 writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING);
Bryan O'Donoghueb50cb682017-10-24 10:54:30 +0100192}
193
Bryan O'Donoghue828ae7a42017-10-24 10:54:31 +0100194static void imx_ocotp_set_imx7_timing(struct ocotp_priv *priv)
195{
196 unsigned long clk_rate = 0;
197 u64 fsource, strobe_prog;
198 u32 timing = 0;
199
200 /* i.MX 7Solo Applications Processor Reference Manual, Rev. 0.1
201 * 6.4.3.3
202 */
203 clk_rate = clk_get_rate(priv->clk);
204 fsource = DIV_ROUND_UP_ULL((u64)clk_rate * DEF_FSOURCE,
205 NSEC_PER_SEC) + 1;
206 strobe_prog = DIV_ROUND_CLOSEST_ULL((u64)clk_rate * DEF_STROBE_PROG,
207 NSEC_PER_SEC) + 1;
208
209 timing = strobe_prog & 0x00000FFF;
210 timing |= (fsource << 12) & 0x000FF000;
211
212 writel(timing, priv->base + IMX_OCOTP_ADDR_TIMING);
213}
214
Bryan O'Donoghueb50cb682017-10-24 10:54:30 +0100215static int imx_ocotp_write(void *context, unsigned int offset, void *val,
216 size_t bytes)
217{
218 struct ocotp_priv *priv = context;
219 u32 *buf = val;
220 int ret;
221
222 u32 ctrl;
223 u8 waddr;
224 u8 word = 0;
225
226 /* allow only writing one complete OTP word at a time */
227 if ((bytes != priv->config->word_size) ||
228 (offset % priv->config->word_size))
229 return -EINVAL;
230
231 mutex_lock(&ocotp_mutex);
232
233 ret = clk_prepare_enable(priv->clk);
234 if (ret < 0) {
235 mutex_unlock(&ocotp_mutex);
236 dev_err(priv->dev, "failed to prepare/enable ocotp clk\n");
237 return ret;
238 }
239
240 /* Setup the write timing values */
Bryan O'Donoghue828ae7a42017-10-24 10:54:31 +0100241 priv->params->set_timing(priv);
Richard Leitner0642bac2017-03-31 13:44:55 +0100242
243 /* 47.3.1.3.2
244 * Check that HW_OCOTP_CTRL[BUSY] and HW_OCOTP_CTRL[ERROR] are clear.
245 * Overlapped accesses are not supported by the controller. Any pending
246 * write or reload must be completed before a write access can be
247 * requested.
248 */
249 ret = imx_ocotp_wait_for_busy(priv->base, 0);
250 if (ret < 0) {
251 dev_err(priv->dev, "timeout during timing setup\n");
252 goto write_end;
253 }
254
255 /* 47.3.1.3.3
256 * Write the requested address to HW_OCOTP_CTRL[ADDR] and program the
257 * unlock code into HW_OCOTP_CTRL[WR_UNLOCK]. This must be programmed
258 * for each write access. The lock code is documented in the register
259 * description. Both the unlock code and address can be written in the
260 * same operation.
261 */
Bryan O'Donoghueffd91152017-10-24 10:54:29 +0100262 if (priv->params->bank_address_words != 0) {
263 /*
264 * In banked/i.MX7 mode the OTP register bank goes into waddr
265 * see i.MX 7Solo Applications Processor Reference Manual, Rev.
266 * 0.1 section 6.4.3.1
267 */
268 offset = offset / priv->config->word_size;
269 waddr = offset / priv->params->bank_address_words;
270 word = offset & (priv->params->bank_address_words - 1);
271 } else {
272 /*
273 * Non-banked i.MX6 mode.
274 * OTP write/read address specifies one of 128 word address
275 * locations
276 */
277 waddr = offset / 4;
278 }
Richard Leitner0642bac2017-03-31 13:44:55 +0100279
280 ctrl = readl(priv->base + IMX_OCOTP_ADDR_CTRL);
281 ctrl &= ~IMX_OCOTP_BM_CTRL_ADDR;
282 ctrl |= waddr & IMX_OCOTP_BM_CTRL_ADDR;
283 ctrl |= IMX_OCOTP_WR_UNLOCK;
284
285 writel(ctrl, priv->base + IMX_OCOTP_ADDR_CTRL);
286
287 /* 47.3.1.3.4
288 * Write the data to the HW_OCOTP_DATA register. This will automatically
289 * set HW_OCOTP_CTRL[BUSY] and clear HW_OCOTP_CTRL[WR_UNLOCK]. To
290 * protect programming same OTP bit twice, before program OCOTP will
291 * automatically read fuse value in OTP and use read value to mask
292 * program data. The controller will use masked program data to program
293 * a 32-bit word in the OTP per the address in HW_OCOTP_CTRL[ADDR]. Bit
294 * fields with 1's will result in that OTP bit being programmed. Bit
295 * fields with 0's will be ignored. At the same time that the write is
296 * accepted, the controller makes an internal copy of
297 * HW_OCOTP_CTRL[ADDR] which cannot be updated until the next write
298 * sequence is initiated. This copy guarantees that erroneous writes to
299 * HW_OCOTP_CTRL[ADDR] will not affect an active write operation. It
300 * should also be noted that during the programming HW_OCOTP_DATA will
301 * shift right (with zero fill). This shifting is required to program
302 * the OTP serially. During the write operation, HW_OCOTP_DATA cannot be
303 * modified.
Bryan O'Donoghueffd91152017-10-24 10:54:29 +0100304 * Note: on i.MX7 there are four data fields to write for banked write
305 * with the fuse blowing operation only taking place after data0
306 * has been written. This is why data0 must always be the last
307 * register written.
Richard Leitner0642bac2017-03-31 13:44:55 +0100308 */
Bryan O'Donoghueffd91152017-10-24 10:54:29 +0100309 if (priv->params->bank_address_words != 0) {
310 /* Banked/i.MX7 mode */
311 switch (word) {
312 case 0:
313 writel(0, priv->base + IMX_OCOTP_ADDR_DATA1);
314 writel(0, priv->base + IMX_OCOTP_ADDR_DATA2);
315 writel(0, priv->base + IMX_OCOTP_ADDR_DATA3);
316 writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA0);
317 break;
318 case 1:
319 writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA1);
320 writel(0, priv->base + IMX_OCOTP_ADDR_DATA2);
321 writel(0, priv->base + IMX_OCOTP_ADDR_DATA3);
322 writel(0, priv->base + IMX_OCOTP_ADDR_DATA0);
323 break;
324 case 2:
325 writel(0, priv->base + IMX_OCOTP_ADDR_DATA1);
326 writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA2);
327 writel(0, priv->base + IMX_OCOTP_ADDR_DATA3);
328 writel(0, priv->base + IMX_OCOTP_ADDR_DATA0);
329 break;
330 case 3:
331 writel(0, priv->base + IMX_OCOTP_ADDR_DATA1);
332 writel(0, priv->base + IMX_OCOTP_ADDR_DATA2);
333 writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA3);
334 writel(0, priv->base + IMX_OCOTP_ADDR_DATA0);
335 break;
336 }
337 } else {
338 /* Non-banked i.MX6 mode */
339 writel(*buf, priv->base + IMX_OCOTP_ADDR_DATA0);
340 }
Richard Leitner0642bac2017-03-31 13:44:55 +0100341
342 /* 47.4.1.4.5
343 * Once complete, the controller will clear BUSY. A write request to a
344 * protected or locked region will result in no OTP access and no
345 * setting of HW_OCOTP_CTRL[BUSY]. In addition HW_OCOTP_CTRL[ERROR] will
346 * be set. It must be cleared by software before any new write access
347 * can be issued.
348 */
349 ret = imx_ocotp_wait_for_busy(priv->base, 0);
350 if (ret < 0) {
351 if (ret == -EPERM) {
352 dev_err(priv->dev, "failed write to locked region");
353 imx_ocotp_clr_err_if_set(priv->base);
354 } else {
355 dev_err(priv->dev, "timeout during data write\n");
356 }
357 goto write_end;
358 }
359
360 /* 47.3.1.4
361 * Write Postamble: Due to internal electrical characteristics of the
362 * OTP during writes, all OTP operations following a write must be
363 * separated by 2 us after the clearing of HW_OCOTP_CTRL_BUSY following
364 * the write.
365 */
366 udelay(2);
367
368 /* reload all shadow registers */
369 writel(IMX_OCOTP_BM_CTRL_REL_SHADOWS,
370 priv->base + IMX_OCOTP_ADDR_CTRL_SET);
371 ret = imx_ocotp_wait_for_busy(priv->base,
372 IMX_OCOTP_BM_CTRL_REL_SHADOWS);
373 if (ret < 0) {
374 dev_err(priv->dev, "timeout during shadow register reload\n");
375 goto write_end;
376 }
377
378write_end:
379 clk_disable_unprepare(priv->clk);
380 mutex_unlock(&ocotp_mutex);
381 if (ret < 0)
382 return ret;
383 return bytes;
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100384}
385
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100386static struct nvmem_config imx_ocotp_nvmem_config = {
387 .name = "imx-ocotp",
Richard Leitner0642bac2017-03-31 13:44:55 +0100388 .read_only = false,
Srinivas Kandagatla33e5e292016-04-24 20:28:13 +0100389 .word_size = 4,
390 .stride = 4,
Srinivas Kandagatla33e5e292016-04-24 20:28:13 +0100391 .reg_read = imx_ocotp_read,
Richard Leitner0642bac2017-03-31 13:44:55 +0100392 .reg_write = imx_ocotp_write,
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100393};
394
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +0100395static const struct ocotp_params imx6q_params = {
396 .nregs = 128,
Bryan O'Donoghueffd91152017-10-24 10:54:29 +0100397 .bank_address_words = 0,
Bryan O'Donoghue828ae7a42017-10-24 10:54:31 +0100398 .set_timing = imx_ocotp_set_imx6_timing,
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +0100399};
400
401static const struct ocotp_params imx6sl_params = {
402 .nregs = 64,
Bryan O'Donoghueffd91152017-10-24 10:54:29 +0100403 .bank_address_words = 0,
Bryan O'Donoghue828ae7a42017-10-24 10:54:31 +0100404 .set_timing = imx_ocotp_set_imx6_timing,
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +0100405};
406
Anson Huang6da27822018-07-11 11:20:43 +0100407static const struct ocotp_params imx6sll_params = {
408 .nregs = 128,
409 .bank_address_words = 0,
410 .set_timing = imx_ocotp_set_imx6_timing,
411};
412
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +0100413static const struct ocotp_params imx6sx_params = {
414 .nregs = 128,
Bryan O'Donoghueffd91152017-10-24 10:54:29 +0100415 .bank_address_words = 0,
Bryan O'Donoghue828ae7a42017-10-24 10:54:31 +0100416 .set_timing = imx_ocotp_set_imx6_timing,
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +0100417};
418
419static const struct ocotp_params imx6ul_params = {
420 .nregs = 128,
Bryan O'Donoghueffd91152017-10-24 10:54:29 +0100421 .bank_address_words = 0,
Bryan O'Donoghue828ae7a42017-10-24 10:54:31 +0100422 .set_timing = imx_ocotp_set_imx6_timing,
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +0100423};
424
Stefan Wahrenffbc34b2019-01-28 15:54:59 +0000425static const struct ocotp_params imx6ull_params = {
426 .nregs = 64,
427 .bank_address_words = 0,
428 .set_timing = imx_ocotp_set_imx6_timing,
429};
430
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +0100431static const struct ocotp_params imx7d_params = {
432 .nregs = 64,
Bryan O'Donoghueffd91152017-10-24 10:54:29 +0100433 .bank_address_words = 4,
Bryan O'Donoghue828ae7a42017-10-24 10:54:31 +0100434 .set_timing = imx_ocotp_set_imx7_timing,
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +0100435};
436
Anson Huangc8b63dd2019-01-28 15:54:57 +0000437static const struct ocotp_params imx7ulp_params = {
438 .nregs = 256,
439 .bank_address_words = 0,
440};
441
Lucas Stach38e7b6e2019-04-13 11:32:47 +0100442static const struct ocotp_params imx8mq_params = {
443 .nregs = 256,
444 .bank_address_words = 4,
445 .set_timing = imx_ocotp_set_imx7_timing,
446};
447
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100448static const struct of_device_id imx_ocotp_dt_ids[] = {
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +0100449 { .compatible = "fsl,imx6q-ocotp", .data = &imx6q_params },
450 { .compatible = "fsl,imx6sl-ocotp", .data = &imx6sl_params },
451 { .compatible = "fsl,imx6sx-ocotp", .data = &imx6sx_params },
452 { .compatible = "fsl,imx6ul-ocotp", .data = &imx6ul_params },
Stefan Wahrenffbc34b2019-01-28 15:54:59 +0000453 { .compatible = "fsl,imx6ull-ocotp", .data = &imx6ull_params },
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +0100454 { .compatible = "fsl,imx7d-ocotp", .data = &imx7d_params },
Anson Huang6da27822018-07-11 11:20:43 +0100455 { .compatible = "fsl,imx6sll-ocotp", .data = &imx6sll_params },
Anson Huangc8b63dd2019-01-28 15:54:57 +0000456 { .compatible = "fsl,imx7ulp-ocotp", .data = &imx7ulp_params },
Lucas Stach38e7b6e2019-04-13 11:32:47 +0100457 { .compatible = "fsl,imx8mq-ocotp", .data = &imx8mq_params },
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100458 { },
459};
460MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids);
461
462static int imx_ocotp_probe(struct platform_device *pdev)
463{
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100464 struct device *dev = &pdev->dev;
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100465 struct ocotp_priv *priv;
466 struct nvmem_device *nvmem;
467
468 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
469 if (!priv)
470 return -ENOMEM;
471
Richard Leitner4cefb742017-03-31 13:44:49 +0100472 priv->dev = dev;
473
Anson Huang3b26cd82019-04-13 11:32:59 +0100474 priv->base = devm_platform_ioremap_resource(pdev, 0);
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100475 if (IS_ERR(priv->base))
476 return PTR_ERR(priv->base);
477
Richard Leitner4cefb742017-03-31 13:44:49 +0100478 priv->clk = devm_clk_get(dev, NULL);
Peng Fandeb31972016-06-02 12:05:11 +0100479 if (IS_ERR(priv->clk))
480 return PTR_ERR(priv->clk);
481
Bryan O'Donoghuee20d2b22017-10-24 10:54:28 +0100482 priv->params = of_device_get_match_data(&pdev->dev);
483 imx_ocotp_nvmem_config.size = 4 * priv->params->nregs;
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100484 imx_ocotp_nvmem_config.dev = dev;
Srinivas Kandagatla33e5e292016-04-24 20:28:13 +0100485 imx_ocotp_nvmem_config.priv = priv;
Richard Leitner0642bac2017-03-31 13:44:55 +0100486 priv->config = &imx_ocotp_nvmem_config;
Andrey Smirnova8302742018-03-09 14:46:59 +0000487 nvmem = devm_nvmem_register(dev, &imx_ocotp_nvmem_config);
Richard Leitner0642bac2017-03-31 13:44:55 +0100488
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100489
Andrey Smirnova8302742018-03-09 14:46:59 +0000490 return PTR_ERR_OR_ZERO(nvmem);
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100491}
492
493static struct platform_driver imx_ocotp_driver = {
494 .probe = imx_ocotp_probe,
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100495 .driver = {
496 .name = "imx_ocotp",
497 .of_match_table = imx_ocotp_dt_ids,
498 },
499};
500module_platform_driver(imx_ocotp_driver);
501
502MODULE_AUTHOR("Philipp Zabel <p.zabel@pengutronix.de>");
Bryan O'Donoghueaef9a4d2017-10-24 10:54:33 +0100503MODULE_DESCRIPTION("i.MX6/i.MX7 OCOTP fuse box driver");
Philipp Zabel3edba6b2015-09-30 13:55:47 +0100504MODULE_LICENSE("GPL v2");