Lines Matching +full:reseed +full:- +full:disable
1 // SPDX-License-Identifier: GPL-2.0
85 enum reseed { enum
106 u32 reseed; member
113 MODULE_PARM_DESC(autoreq, "Auto-reseeding after random number requests by host reaches specified co…
114 " 0 - disable counter\n"
115 " other - reload value for internal counter");
119 MODULE_PARM_DESC(autoage, "Auto-reseeding after specified timer countdowns to 0:\n"
120 " 0 - disable timer\n"
121 " other - reload value for internal timer");
127 return readl_relaxed_poll_timeout(trng->base + STARFIVE_STAT, stat, in starfive_trng_wait_idle()
136 u32 data = readl(trng->base + STARFIVE_ISTAT); in starfive_trng_irq_mask_clear()
138 writel(data, trng->base + STARFIVE_ISTAT); in starfive_trng_irq_mask_clear()
151 reinit_completion(&trng->random_done); in starfive_trng_cmd()
152 spin_lock_irq(&trng->write_lock); in starfive_trng_cmd()
153 writel(cmd, trng->base + STARFIVE_CTRL); in starfive_trng_cmd()
154 spin_unlock_irq(&trng->write_lock); in starfive_trng_cmd()
155 if (!wait_for_completion_timeout(&trng->random_done, usecs_to_jiffies(wait_time))) in starfive_trng_cmd()
156 return -ETIMEDOUT; in starfive_trng_cmd()
159 reinit_completion(&trng->reseed_done); in starfive_trng_cmd()
160 spin_lock_irq(&trng->write_lock); in starfive_trng_cmd()
161 writel(cmd, trng->base + STARFIVE_CTRL); in starfive_trng_cmd()
162 spin_unlock_irq(&trng->write_lock); in starfive_trng_cmd()
163 if (!wait_for_completion_timeout(&trng->reseed_done, usecs_to_jiffies(wait_time))) in starfive_trng_cmd()
164 return -ETIMEDOUT; in starfive_trng_cmd()
167 return -EINVAL; in starfive_trng_cmd()
179 writel(autoage, trng->base + STARFIVE_AUTO_AGE); in starfive_trng_init()
180 writel(autoreq, trng->base + STARFIVE_AUTO_RQSTS); in starfive_trng_init()
186 writel(intr, trng->base + STARFIVE_IE); in starfive_trng_init()
188 mode = readl(trng->base + STARFIVE_MODE); in starfive_trng_init()
190 switch (trng->mode) { in starfive_trng_init()
202 writel(mode, trng->base + STARFIVE_MODE); in starfive_trng_init()
212 status = readl(trng->base + STARFIVE_ISTAT); in starfive_trng_irq()
214 writel(STARFIVE_ISTAT_RAND_RDY, trng->base + STARFIVE_ISTAT); in starfive_trng_irq()
215 complete(&trng->random_done); in starfive_trng_irq()
219 writel(STARFIVE_ISTAT_SEED_DONE, trng->base + STARFIVE_ISTAT); in starfive_trng_irq()
220 complete(&trng->reseed_done); in starfive_trng_irq()
224 writel(STARFIVE_ISTAT_LFSR_LOCKUP, trng->base + STARFIVE_ISTAT); in starfive_trng_irq()
226 spin_lock(&trng->write_lock); in starfive_trng_irq()
227 writel(STARFIVE_CTRL_EXEC_RANDRESEED, trng->base + STARFIVE_CTRL); in starfive_trng_irq()
228 spin_unlock(&trng->write_lock); in starfive_trng_irq()
238 writel(0, trng->base + STARFIVE_CTRL); in starfive_trng_cleanup()
240 reset_control_assert(trng->rst); in starfive_trng_cleanup()
241 clk_disable_unprepare(trng->hclk); in starfive_trng_cleanup()
242 clk_disable_unprepare(trng->ahb); in starfive_trng_cleanup()
250 pm_runtime_get_sync(trng->dev); in starfive_trng_read()
252 if (trng->mode == PRNG_256BIT) in starfive_trng_read()
260 return -ETIMEDOUT; in starfive_trng_read()
267 memcpy_fromio(buf, trng->base + STARFIVE_RAND0, max); in starfive_trng_read()
269 pm_runtime_put_sync_autosuspend(trng->dev); in starfive_trng_read()
280 trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL); in starfive_trng_probe()
282 return -ENOMEM; in starfive_trng_probe()
285 trng->dev = &pdev->dev; in starfive_trng_probe()
287 trng->base = devm_platform_ioremap_resource(pdev, 0); in starfive_trng_probe()
288 if (IS_ERR(trng->base)) in starfive_trng_probe()
289 return dev_err_probe(&pdev->dev, PTR_ERR(trng->base), in starfive_trng_probe()
296 init_completion(&trng->random_done); in starfive_trng_probe()
297 init_completion(&trng->reseed_done); in starfive_trng_probe()
298 spin_lock_init(&trng->write_lock); in starfive_trng_probe()
300 ret = devm_request_irq(&pdev->dev, irq, starfive_trng_irq, 0, pdev->name, in starfive_trng_probe()
303 return dev_err_probe(&pdev->dev, ret, in starfive_trng_probe()
306 trng->hclk = devm_clk_get(&pdev->dev, "hclk"); in starfive_trng_probe()
307 if (IS_ERR(trng->hclk)) in starfive_trng_probe()
308 return dev_err_probe(&pdev->dev, PTR_ERR(trng->hclk), in starfive_trng_probe()
311 trng->ahb = devm_clk_get(&pdev->dev, "ahb"); in starfive_trng_probe()
312 if (IS_ERR(trng->ahb)) in starfive_trng_probe()
313 return dev_err_probe(&pdev->dev, PTR_ERR(trng->ahb), in starfive_trng_probe()
316 trng->rst = devm_reset_control_get_shared(&pdev->dev, NULL); in starfive_trng_probe()
317 if (IS_ERR(trng->rst)) in starfive_trng_probe()
318 return dev_err_probe(&pdev->dev, PTR_ERR(trng->rst), in starfive_trng_probe()
321 clk_prepare_enable(trng->hclk); in starfive_trng_probe()
322 clk_prepare_enable(trng->ahb); in starfive_trng_probe()
323 reset_control_deassert(trng->rst); in starfive_trng_probe()
325 trng->rng.name = dev_driver_string(&pdev->dev); in starfive_trng_probe()
326 trng->rng.init = starfive_trng_init; in starfive_trng_probe()
327 trng->rng.cleanup = starfive_trng_cleanup; in starfive_trng_probe()
328 trng->rng.read = starfive_trng_read; in starfive_trng_probe()
330 trng->mode = PRNG_256BIT; in starfive_trng_probe()
331 trng->mission = 1; in starfive_trng_probe()
332 trng->reseed = RANDOM_RESEED; in starfive_trng_probe()
334 pm_runtime_use_autosuspend(&pdev->dev); in starfive_trng_probe()
335 pm_runtime_set_autosuspend_delay(&pdev->dev, 100); in starfive_trng_probe()
336 pm_runtime_enable(&pdev->dev); in starfive_trng_probe()
338 ret = devm_hwrng_register(&pdev->dev, &trng->rng); in starfive_trng_probe()
340 pm_runtime_disable(&pdev->dev); in starfive_trng_probe()
342 reset_control_assert(trng->rst); in starfive_trng_probe()
343 clk_disable_unprepare(trng->ahb); in starfive_trng_probe()
344 clk_disable_unprepare(trng->hclk); in starfive_trng_probe()
346 return dev_err_probe(&pdev->dev, ret, "Failed to register hwrng\n"); in starfive_trng_probe()
356 clk_disable_unprepare(trng->hclk); in starfive_trng_suspend()
357 clk_disable_unprepare(trng->ahb); in starfive_trng_suspend()
366 clk_prepare_enable(trng->hclk); in starfive_trng_resume()
367 clk_prepare_enable(trng->ahb); in starfive_trng_resume()
380 { .compatible = "starfive,jh7110-trng" },
388 .name = "jh7110-trng",