Lines Matching full:efuse
39 * The Spreadtrum AP efuse contains 2 parts: normal efuse and secure efuse,
40 * and we can only access the normal efuse in kernel. So define the normal
52 * when reading or writing data to efuse memory, the controller can save double
80 * efuse controller, so we need one hardware spinlock to synchronize between
83 static int sprd_efuse_lock(struct sprd_efuse *efuse) in sprd_efuse_lock() argument
87 mutex_lock(&efuse->mutex); in sprd_efuse_lock()
89 ret = hwspin_lock_timeout_raw(efuse->hwlock, in sprd_efuse_lock()
92 dev_err(efuse->dev, "timeout get the hwspinlock\n"); in sprd_efuse_lock()
93 mutex_unlock(&efuse->mutex); in sprd_efuse_lock()
100 static void sprd_efuse_unlock(struct sprd_efuse *efuse) in sprd_efuse_unlock() argument
102 hwspin_unlock_raw(efuse->hwlock); in sprd_efuse_unlock()
103 mutex_unlock(&efuse->mutex); in sprd_efuse_unlock()
106 static void sprd_efuse_set_prog_power(struct sprd_efuse *efuse, bool en) in sprd_efuse_set_prog_power() argument
108 u32 val = readl(efuse->base + SPRD_EFUSE_PW_SWT); in sprd_efuse_set_prog_power()
115 writel(val, efuse->base + SPRD_EFUSE_PW_SWT); in sprd_efuse_set_prog_power()
117 /* Open or close efuse power need wait 1000us to make power stable. */ in sprd_efuse_set_prog_power()
125 writel(val, efuse->base + SPRD_EFUSE_PW_SWT); in sprd_efuse_set_prog_power()
127 /* Open or close efuse power need wait 1000us to make power stable. */ in sprd_efuse_set_prog_power()
131 static void sprd_efuse_set_read_power(struct sprd_efuse *efuse, bool en) in sprd_efuse_set_read_power() argument
133 u32 val = readl(efuse->base + SPRD_EFUSE_ENABLE); in sprd_efuse_set_read_power()
140 writel(val, efuse->base + SPRD_EFUSE_ENABLE); in sprd_efuse_set_read_power()
142 /* Open or close efuse power need wait 1000us to make power stable. */ in sprd_efuse_set_read_power()
146 static void sprd_efuse_set_prog_lock(struct sprd_efuse *efuse, bool en) in sprd_efuse_set_prog_lock() argument
148 u32 val = readl(efuse->base + SPRD_EFUSE_ENABLE); in sprd_efuse_set_prog_lock()
155 writel(val, efuse->base + SPRD_EFUSE_ENABLE); in sprd_efuse_set_prog_lock()
158 static void sprd_efuse_set_auto_check(struct sprd_efuse *efuse, bool en) in sprd_efuse_set_auto_check() argument
160 u32 val = readl(efuse->base + SPRD_EFUSE_ENABLE); in sprd_efuse_set_auto_check()
167 writel(val, efuse->base + SPRD_EFUSE_ENABLE); in sprd_efuse_set_auto_check()
170 static void sprd_efuse_set_data_double(struct sprd_efuse *efuse, bool en) in sprd_efuse_set_data_double() argument
172 u32 val = readl(efuse->base + SPRD_EFUSE_ENABLE); in sprd_efuse_set_data_double()
179 writel(val, efuse->base + SPRD_EFUSE_ENABLE); in sprd_efuse_set_data_double()
182 static void sprd_efuse_set_prog_en(struct sprd_efuse *efuse, bool en) in sprd_efuse_set_prog_en() argument
184 u32 val = readl(efuse->base + SPRD_EFUSE_PW_SWT); in sprd_efuse_set_prog_en()
191 writel(val, efuse->base + SPRD_EFUSE_PW_SWT); in sprd_efuse_set_prog_en()
194 static int sprd_efuse_raw_prog(struct sprd_efuse *efuse, u32 blk, bool doub, in sprd_efuse_raw_prog() argument
201 * We need set the correct magic number before writing the efuse to in sprd_efuse_raw_prog()
206 efuse->base + SPRD_EFUSE_MAGIC_NUM); in sprd_efuse_raw_prog()
209 * Power on the efuse, enable programme and enable double data in sprd_efuse_raw_prog()
212 sprd_efuse_set_prog_power(efuse, true); in sprd_efuse_raw_prog()
213 sprd_efuse_set_prog_en(efuse, true); in sprd_efuse_raw_prog()
214 sprd_efuse_set_data_double(efuse, doub); in sprd_efuse_raw_prog()
221 sprd_efuse_set_auto_check(efuse, true); in sprd_efuse_raw_prog()
223 writel(*data, efuse->base + SPRD_EFUSE_MEM(blk)); in sprd_efuse_raw_prog()
227 sprd_efuse_set_auto_check(efuse, false); in sprd_efuse_raw_prog()
228 sprd_efuse_set_data_double(efuse, false); in sprd_efuse_raw_prog()
231 * Check the efuse error status, if the programming is successful, in sprd_efuse_raw_prog()
232 * we should lock this efuse block to avoid programming again. in sprd_efuse_raw_prog()
234 status = readl(efuse->base + SPRD_EFUSE_ERR_FLAG); in sprd_efuse_raw_prog()
236 dev_err(efuse->dev, in sprd_efuse_raw_prog()
240 efuse->base + SPRD_EFUSE_ERR_CLR); in sprd_efuse_raw_prog()
243 sprd_efuse_set_prog_lock(efuse, lock); in sprd_efuse_raw_prog()
244 writel(0, efuse->base + SPRD_EFUSE_MEM(blk)); in sprd_efuse_raw_prog()
245 sprd_efuse_set_prog_lock(efuse, false); in sprd_efuse_raw_prog()
248 sprd_efuse_set_prog_power(efuse, false); in sprd_efuse_raw_prog()
249 writel(0, efuse->base + SPRD_EFUSE_MAGIC_NUM); in sprd_efuse_raw_prog()
254 static int sprd_efuse_raw_read(struct sprd_efuse *efuse, int blk, u32 *val, in sprd_efuse_raw_read() argument
260 * Need power on the efuse before reading data from efuse, and will in sprd_efuse_raw_read()
261 * power off the efuse after reading process. in sprd_efuse_raw_read()
263 sprd_efuse_set_read_power(efuse, true); in sprd_efuse_raw_read()
266 sprd_efuse_set_data_double(efuse, doub); in sprd_efuse_raw_read()
268 /* Start to read data from efuse block */ in sprd_efuse_raw_read()
269 *val = readl(efuse->base + SPRD_EFUSE_MEM(blk)); in sprd_efuse_raw_read()
272 sprd_efuse_set_data_double(efuse, false); in sprd_efuse_raw_read()
274 /* Power off the efuse */ in sprd_efuse_raw_read()
275 sprd_efuse_set_read_power(efuse, false); in sprd_efuse_raw_read()
278 * Check the efuse error status and clear them if there are some in sprd_efuse_raw_read()
281 status = readl(efuse->base + SPRD_EFUSE_ERR_FLAG); in sprd_efuse_raw_read()
283 dev_err(efuse->dev, in sprd_efuse_raw_read()
287 efuse->base + SPRD_EFUSE_ERR_CLR); in sprd_efuse_raw_read()
296 struct sprd_efuse *efuse = context; in sprd_efuse_read() local
297 bool blk_double = efuse->data->blk_double; in sprd_efuse_read()
298 u32 index = offset / SPRD_EFUSE_BLOCK_WIDTH + efuse->data->blk_offset; in sprd_efuse_read()
303 ret = sprd_efuse_lock(efuse); in sprd_efuse_read()
307 ret = clk_prepare_enable(efuse->clk); in sprd_efuse_read()
311 ret = sprd_efuse_raw_read(efuse, index, &data, blk_double); in sprd_efuse_read()
317 clk_disable_unprepare(efuse->clk); in sprd_efuse_read()
320 sprd_efuse_unlock(efuse); in sprd_efuse_read()
326 struct sprd_efuse *efuse = context; in sprd_efuse_write() local
327 bool blk_double = efuse->data->blk_double; in sprd_efuse_write()
331 ret = sprd_efuse_lock(efuse); in sprd_efuse_write()
335 ret = clk_prepare_enable(efuse->clk); in sprd_efuse_write()
352 ret = sprd_efuse_raw_prog(efuse, offset, blk_double, lock, val); in sprd_efuse_write()
354 clk_disable_unprepare(efuse->clk); in sprd_efuse_write()
357 sprd_efuse_unlock(efuse); in sprd_efuse_write()
366 struct sprd_efuse *efuse; in sprd_efuse_probe() local
376 efuse = devm_kzalloc(&pdev->dev, sizeof(*efuse), GFP_KERNEL); in sprd_efuse_probe()
377 if (!efuse) in sprd_efuse_probe()
380 efuse->base = devm_platform_ioremap_resource(pdev, 0); in sprd_efuse_probe()
381 if (IS_ERR(efuse->base)) in sprd_efuse_probe()
382 return PTR_ERR(efuse->base); in sprd_efuse_probe()
390 efuse->hwlock = devm_hwspin_lock_request_specific(&pdev->dev, ret); in sprd_efuse_probe()
391 if (!efuse->hwlock) { in sprd_efuse_probe()
396 efuse->clk = devm_clk_get(&pdev->dev, "enable"); in sprd_efuse_probe()
397 if (IS_ERR(efuse->clk)) { in sprd_efuse_probe()
399 return PTR_ERR(efuse->clk); in sprd_efuse_probe()
402 mutex_init(&efuse->mutex); in sprd_efuse_probe()
403 efuse->dev = &pdev->dev; in sprd_efuse_probe()
404 efuse->data = pdata; in sprd_efuse_probe()
409 econfig.name = "sprd-efuse"; in sprd_efuse_probe()
410 econfig.size = efuse->data->blk_nums * SPRD_EFUSE_BLOCK_WIDTH; in sprd_efuse_probe()
413 econfig.priv = efuse; in sprd_efuse_probe()
425 { .compatible = "sprd,ums312-efuse", .data = &ums312_data },
432 .name = "sprd-efuse",
440 MODULE_DESCRIPTION("Spreadtrum AP efuse driver");