Lines Matching refs:drvdata

77 static inline void cc_iowrite(struct cctrng_drvdata *drvdata, u32 reg, u32 val)  in cc_iowrite()  argument
79 iowrite32(val, (drvdata->cc_base + reg)); in cc_iowrite()
81 static inline u32 cc_ioread(struct cctrng_drvdata *drvdata, u32 reg) in cc_ioread() argument
83 return ioread32(drvdata->cc_base + reg); in cc_ioread()
107 static int cc_trng_pm_init(struct cctrng_drvdata *drvdata) in cc_trng_pm_init() argument
109 struct device *dev = &(drvdata->pdev->dev); in cc_trng_pm_init()
118 static void cc_trng_pm_go(struct cctrng_drvdata *drvdata) in cc_trng_pm_go() argument
120 struct device *dev = &(drvdata->pdev->dev); in cc_trng_pm_go()
126 static void cc_trng_pm_fini(struct cctrng_drvdata *drvdata) in cc_trng_pm_fini() argument
128 struct device *dev = &(drvdata->pdev->dev); in cc_trng_pm_fini()
134 static inline int cc_trng_parse_sampling_ratio(struct cctrng_drvdata *drvdata) in cc_trng_parse_sampling_ratio() argument
136 struct device *dev = &(drvdata->pdev->dev); in cc_trng_parse_sampling_ratio()
137 struct device_node *np = drvdata->pdev->dev.of_node; in cc_trng_parse_sampling_ratio()
144 drvdata->smpl_ratio, in cc_trng_parse_sampling_ratio()
154 i, drvdata->smpl_ratio[i]); in cc_trng_parse_sampling_ratio()
156 if (drvdata->smpl_ratio[i] > 0) in cc_trng_parse_sampling_ratio()
163 static int cc_trng_change_rosc(struct cctrng_drvdata *drvdata) in cc_trng_change_rosc() argument
165 struct device *dev = &(drvdata->pdev->dev); in cc_trng_change_rosc()
167 dev_dbg(dev, "cctrng change rosc (was %d)\n", drvdata->active_rosc); in cc_trng_change_rosc()
168 drvdata->active_rosc += 1; in cc_trng_change_rosc()
170 while (drvdata->active_rosc < CC_TRNG_NUM_OF_ROSCS) { in cc_trng_change_rosc()
171 if (drvdata->smpl_ratio[drvdata->active_rosc] > 0) in cc_trng_change_rosc()
174 drvdata->active_rosc += 1; in cc_trng_change_rosc()
180 static void cc_trng_enable_rnd_source(struct cctrng_drvdata *drvdata) in cc_trng_enable_rnd_source() argument
185 max_cycles = CCTRNG_TIMEOUT(drvdata->smpl_ratio[drvdata->active_rosc]); in cc_trng_enable_rnd_source()
186 cc_iowrite(drvdata, CC_RNG_WATCHDOG_VAL_REG_OFFSET, max_cycles); in cc_trng_enable_rnd_source()
189 cc_iowrite(drvdata, CC_RND_SOURCE_ENABLE_REG_OFFSET, 0x1); in cc_trng_enable_rnd_source()
192 cc_iowrite(drvdata, CC_RNG_IMR_REG_OFFSET, (u32)~CC_RNG_INT_MASK); in cc_trng_enable_rnd_source()
203 static inline size_t circ_buf_space(struct cctrng_drvdata *drvdata) in circ_buf_space() argument
205 return CIRC_SPACE(drvdata->circ.head, in circ_buf_space()
206 drvdata->circ.tail, CCTRNG_DATA_BUF_WORDS); in circ_buf_space()
214 struct cctrng_drvdata *drvdata = (struct cctrng_drvdata *)rng->priv; in cctrng_read() local
215 struct device *dev = &(drvdata->pdev->dev); in cctrng_read()
216 u32 *buf = (u32 *)drvdata->circ.buf; in cctrng_read()
222 if (!spin_trylock(&drvdata->read_lock)) { in cctrng_read()
229 cnt_w = CIRC_CNT_TO_END(drvdata->circ.head, in cctrng_read()
230 drvdata->circ.tail, CCTRNG_DATA_BUF_WORDS); in cctrng_read()
232 memcpy(data, &(buf[drvdata->circ.tail]), size); in cctrng_read()
234 circ_idx_inc(&drvdata->circ.tail, size); in cctrng_read()
238 cnt_w = CIRC_CNT(drvdata->circ.head, in cctrng_read()
239 drvdata->circ.tail, CCTRNG_DATA_BUF_WORDS); in cctrng_read()
241 memcpy(data, &(buf[drvdata->circ.tail]), size); in cctrng_read()
243 circ_idx_inc(&drvdata->circ.tail, size); in cctrng_read()
246 spin_unlock(&drvdata->read_lock); in cctrng_read()
248 if (circ_buf_space(drvdata) >= CC_TRNG_EHR_IN_WORDS) { in cctrng_read()
249 if (atomic_cmpxchg(&drvdata->pending_hw, 0, 1) == 0) { in cctrng_read()
251 if (circ_buf_space(drvdata) >= CC_TRNG_EHR_IN_WORDS) { in cctrng_read()
265 schedule_work(&drvdata->startwork); in cctrng_read()
267 atomic_set(&drvdata->pending_hw, 0); in cctrng_read()
275 static void cc_trng_hw_trigger(struct cctrng_drvdata *drvdata) in cc_trng_hw_trigger() argument
278 struct device *dev = &(drvdata->pdev->dev); in cc_trng_hw_trigger()
283 cc_iowrite(drvdata, CC_RNG_CLK_ENABLE_REG_OFFSET, 0x1); in cc_trng_hw_trigger()
286 cc_iowrite(drvdata, CC_RNG_SW_RESET_REG_OFFSET, 0x1); in cc_trng_hw_trigger()
292 cc_iowrite(drvdata, CC_RNG_CLK_ENABLE_REG_OFFSET, 0x1); in cc_trng_hw_trigger()
295 cc_iowrite(drvdata, CC_SAMPLE_CNT1_REG_OFFSET, in cc_trng_hw_trigger()
296 drvdata->smpl_ratio[drvdata->active_rosc]); in cc_trng_hw_trigger()
299 tmp_smpl_cnt = cc_ioread(drvdata, CC_SAMPLE_CNT1_REG_OFFSET); in cc_trng_hw_trigger()
301 } while (tmp_smpl_cnt != drvdata->smpl_ratio[drvdata->active_rosc]); in cc_trng_hw_trigger()
304 cc_iowrite(drvdata, CC_RND_SOURCE_ENABLE_REG_OFFSET, 0); in cc_trng_hw_trigger()
306 cc_iowrite(drvdata, CC_RNG_ICR_REG_OFFSET, 0xFFFFFFFF); in cc_trng_hw_trigger()
308 cc_iowrite(drvdata, CC_TRNG_CONFIG_REG_OFFSET, drvdata->active_rosc); in cc_trng_hw_trigger()
311 cc_iowrite(drvdata, CC_TRNG_DEBUG_CONTROL_REG_OFFSET, 0); in cc_trng_hw_trigger()
313 cc_trng_enable_rnd_source(drvdata); in cc_trng_hw_trigger()
320 struct cctrng_drvdata *drvdata = in cc_trng_compwork_handler() local
322 struct device *dev = &(drvdata->pdev->dev); in cc_trng_compwork_handler()
326 cc_iowrite(drvdata, CC_RNG_DMA_ENABLE_REG_OFFSET, 0); in cc_trng_compwork_handler()
327 cc_iowrite(drvdata, CC_RND_SOURCE_ENABLE_REG_OFFSET, 0); in cc_trng_compwork_handler()
330 isr = cc_ioread(drvdata, CC_RNG_ISR_REG_OFFSET); in cc_trng_compwork_handler()
341 cc_iowrite(drvdata, CC_RNG_ICR_REG_OFFSET, isr); in cc_trng_compwork_handler()
358 u32 *buf = (u32 *)drvdata->circ.buf; in cc_trng_compwork_handler()
360 buf[drvdata->circ.head] = cc_ioread(drvdata, in cc_trng_compwork_handler()
366 if (buf[drvdata->circ.head] == 0) { in cc_trng_compwork_handler()
368 drvdata->active_rosc); in cc_trng_compwork_handler()
372 circ_idx_inc(&drvdata->circ.head, 1<<2); in cc_trng_compwork_handler()
375 atomic_set(&drvdata->pending_hw, 0); in cc_trng_compwork_handler()
378 if (circ_buf_space(drvdata) >= CC_TRNG_EHR_IN_WORDS) { in cc_trng_compwork_handler()
379 if (atomic_cmpxchg(&drvdata->pending_hw, 0, 1) == 0) { in cc_trng_compwork_handler()
381 cc_trng_enable_rnd_source(drvdata); in cc_trng_compwork_handler()
392 if ((circ_buf_space(drvdata) >= CC_TRNG_EHR_IN_WORDS) && in cc_trng_compwork_handler()
393 (cc_trng_change_rosc(drvdata) == 0)) { in cc_trng_compwork_handler()
395 cc_trng_hw_trigger(drvdata); in cc_trng_compwork_handler()
397 atomic_set(&drvdata->pending_hw, 0); in cc_trng_compwork_handler()
404 struct cctrng_drvdata *drvdata = (struct cctrng_drvdata *)dev_id; in cc_isr() local
405 struct device *dev = &(drvdata->pdev->dev); in cc_isr()
413 irr = cc_ioread(drvdata, CC_HOST_RGF_IRR_REG_OFFSET); in cc_isr()
420 cc_iowrite(drvdata, CC_HOST_RGF_ICR_REG_OFFSET, irr); in cc_isr()
425 cc_iowrite(drvdata, CC_RNG_IMR_REG_OFFSET, 0xFFFFFFFF); in cc_isr()
430 cc_iowrite(drvdata, CC_HOST_RGF_ICR_REG_OFFSET, in cc_isr()
436 schedule_work(&drvdata->compwork); in cc_isr()
451 struct cctrng_drvdata *drvdata = in cc_trng_startwork_handler() local
454 drvdata->active_rosc = 0; in cc_trng_startwork_handler()
455 cc_trng_hw_trigger(drvdata); in cc_trng_startwork_handler()
460 struct cctrng_drvdata *drvdata; in cctrng_probe() local
470 drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL); in cctrng_probe()
471 if (!drvdata) in cctrng_probe()
474 drvdata->rng.name = devm_kstrdup(dev, dev_name(dev), GFP_KERNEL); in cctrng_probe()
475 if (!drvdata->rng.name) in cctrng_probe()
478 drvdata->rng.read = cctrng_read; in cctrng_probe()
479 drvdata->rng.priv = (unsigned long)drvdata; in cctrng_probe()
480 drvdata->rng.quality = CC_TRNG_QUALITY; in cctrng_probe()
482 platform_set_drvdata(pdev, drvdata); in cctrng_probe()
483 drvdata->pdev = pdev; in cctrng_probe()
485 drvdata->circ.buf = (char *)drvdata->data_buf; in cctrng_probe()
487 drvdata->cc_base = devm_platform_ioremap_resource(pdev, 0); in cctrng_probe()
488 if (IS_ERR(drvdata->cc_base)) in cctrng_probe()
489 return dev_err_probe(dev, PTR_ERR(drvdata->cc_base), "Failed to ioremap registers"); in cctrng_probe()
497 rc = cc_trng_parse_sampling_ratio(drvdata); in cctrng_probe()
501 drvdata->clk = devm_clk_get_optional_enabled(dev, NULL); in cctrng_probe()
502 if (IS_ERR(drvdata->clk)) in cctrng_probe()
503 return dev_err_probe(dev, PTR_ERR(drvdata->clk), in cctrng_probe()
506 INIT_WORK(&drvdata->compwork, cc_trng_compwork_handler); in cctrng_probe()
507 INIT_WORK(&drvdata->startwork, cc_trng_startwork_handler); in cctrng_probe()
508 spin_lock_init(&drvdata->read_lock); in cctrng_probe()
511 rc = devm_request_irq(dev, irq, cc_isr, IRQF_SHARED, "cctrng", drvdata); in cctrng_probe()
517 val = cc_ioread(drvdata, CC_HOST_RGF_IRR_REG_OFFSET); in cctrng_probe()
519 cc_iowrite(drvdata, CC_HOST_RGF_ICR_REG_OFFSET, val); in cctrng_probe()
522 cc_iowrite(drvdata, CC_HOST_RGF_IMR_REG_OFFSET, in cctrng_probe()
523 cc_ioread(drvdata, CC_HOST_RGF_IMR_REG_OFFSET) & in cctrng_probe()
527 rc = cc_trng_pm_init(drvdata); in cctrng_probe()
537 atomic_set(&drvdata->pending_hw, 1); in cctrng_probe()
540 rc = devm_hwrng_register(dev, &drvdata->rng); in cctrng_probe()
547 drvdata->active_rosc = 0; in cctrng_probe()
548 cc_trng_hw_trigger(drvdata); in cctrng_probe()
551 cc_trng_pm_go(drvdata); in cctrng_probe()
558 cc_trng_pm_fini(drvdata); in cctrng_probe()
565 struct cctrng_drvdata *drvdata = platform_get_drvdata(pdev); in cctrng_remove() local
570 cc_trng_pm_fini(drvdata); in cctrng_remove()
579 struct cctrng_drvdata *drvdata = dev_get_drvdata(dev); in cctrng_suspend() local
582 cc_iowrite(drvdata, CC_HOST_POWER_DOWN_EN_REG_OFFSET, in cctrng_suspend()
585 clk_disable_unprepare(drvdata->clk); in cctrng_suspend()
590 static bool cctrng_wait_for_reset_completion(struct cctrng_drvdata *drvdata) in cctrng_wait_for_reset_completion() argument
599 val = cc_ioread(drvdata, CC_NVM_IS_IDLE_REG_OFFSET); in cctrng_wait_for_reset_completion()
613 struct cctrng_drvdata *drvdata = dev_get_drvdata(dev); in cctrng_resume() local
618 rc = clk_prepare_enable(drvdata->clk); in cctrng_resume()
625 if (!cctrng_wait_for_reset_completion(drvdata)) { in cctrng_resume()
627 clk_disable_unprepare(drvdata->clk); in cctrng_resume()
632 cc_iowrite(drvdata, CC_HOST_RGF_IMR_REG_OFFSET, in cctrng_resume()
633 cc_ioread(drvdata, CC_HOST_RGF_IMR_REG_OFFSET) & in cctrng_resume()
636 cc_iowrite(drvdata, CC_HOST_POWER_DOWN_EN_REG_OFFSET, in cctrng_resume()