Lines Matching +full:stm32 +full:- +full:rng
1 // SPDX-License-Identifier: GPL-2.0-or-later
31 struct hwrng rng; member
38 static int stm32_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) in stm32_rng_read() argument
41 container_of(rng, struct stm32_rng_private, rng); in stm32_rng_read()
45 pm_runtime_get_sync((struct device *) priv->rng.priv); in stm32_rng_read()
48 sr = readl_relaxed(priv->base + RNG_SR); in stm32_rng_read()
50 /* care of initial delay time when enabling rng */ in stm32_rng_read()
52 retval = readl_relaxed_poll_timeout_atomic(priv->base in stm32_rng_read()
57 dev_err((struct device *)priv->rng.priv, in stm32_rng_read()
64 "bad RNG status - %x\n", sr)) in stm32_rng_read()
65 writel_relaxed(0, priv->base + RNG_SR); in stm32_rng_read()
69 *(u32 *)data = readl_relaxed(priv->base + RNG_DR); in stm32_rng_read()
73 max -= sizeof(u32); in stm32_rng_read()
76 pm_runtime_mark_last_busy((struct device *) priv->rng.priv); in stm32_rng_read()
77 pm_runtime_put_sync_autosuspend((struct device *) priv->rng.priv); in stm32_rng_read()
79 return retval || !wait ? retval : -EIO; in stm32_rng_read()
82 static int stm32_rng_init(struct hwrng *rng) in stm32_rng_init() argument
85 container_of(rng, struct stm32_rng_private, rng); in stm32_rng_init()
88 err = clk_prepare_enable(priv->clk); in stm32_rng_init()
92 if (priv->ced) in stm32_rng_init()
93 writel_relaxed(RNG_CR_RNGEN, priv->base + RNG_CR); in stm32_rng_init()
96 priv->base + RNG_CR); in stm32_rng_init()
99 writel_relaxed(0, priv->base + RNG_SR); in stm32_rng_init()
104 static void stm32_rng_cleanup(struct hwrng *rng) in stm32_rng_cleanup() argument
107 container_of(rng, struct stm32_rng_private, rng); in stm32_rng_cleanup()
109 writel_relaxed(0, priv->base + RNG_CR); in stm32_rng_cleanup()
110 clk_disable_unprepare(priv->clk); in stm32_rng_cleanup()
115 struct device *dev = &ofdev->dev; in stm32_rng_probe()
116 struct device_node *np = ofdev->dev.of_node; in stm32_rng_probe()
123 return -ENOMEM; in stm32_rng_probe()
129 priv->base = devm_ioremap_resource(dev, &res); in stm32_rng_probe()
130 if (IS_ERR(priv->base)) in stm32_rng_probe()
131 return PTR_ERR(priv->base); in stm32_rng_probe()
133 priv->clk = devm_clk_get(&ofdev->dev, NULL); in stm32_rng_probe()
134 if (IS_ERR(priv->clk)) in stm32_rng_probe()
135 return PTR_ERR(priv->clk); in stm32_rng_probe()
137 priv->rst = devm_reset_control_get(&ofdev->dev, NULL); in stm32_rng_probe()
138 if (!IS_ERR(priv->rst)) { in stm32_rng_probe()
139 reset_control_assert(priv->rst); in stm32_rng_probe()
141 reset_control_deassert(priv->rst); in stm32_rng_probe()
144 priv->ced = of_property_read_bool(np, "clock-error-detect"); in stm32_rng_probe()
148 priv->rng.name = dev_driver_string(dev); in stm32_rng_probe()
150 priv->rng.init = stm32_rng_init; in stm32_rng_probe()
151 priv->rng.cleanup = stm32_rng_cleanup; in stm32_rng_probe()
153 priv->rng.read = stm32_rng_read; in stm32_rng_probe()
154 priv->rng.priv = (unsigned long) dev; in stm32_rng_probe()
155 priv->rng.quality = 900; in stm32_rng_probe()
161 return devm_hwrng_register(dev, &priv->rng); in stm32_rng_probe()
166 pm_runtime_disable(&ofdev->dev); in stm32_rng_remove()
176 stm32_rng_cleanup(&priv->rng); in stm32_rng_runtime_suspend()
185 return stm32_rng_init(&priv->rng); in stm32_rng_runtime_resume()
199 .compatible = "st,stm32-rng",
207 .name = "stm32-rng",
219 MODULE_DESCRIPTION("STMicroelectronics STM32 RNG device driver");