Lines Matching refs:efuse

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()
125 writel(val, efuse->base + SPRD_EFUSE_PW_SWT); 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()
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
206 efuse->base + SPRD_EFUSE_MAGIC_NUM); 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()
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
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()
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()
275 sprd_efuse_set_read_power(efuse, false); 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()
410 econfig.size = efuse->data->blk_nums * SPRD_EFUSE_BLOCK_WIDTH; in sprd_efuse_probe()
413 econfig.priv = efuse; in sprd_efuse_probe()