Lines Matching +full:stm32 +full:- +full:rng
40 struct hwrng rng; member
47 static int stm32_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) in stm32_rng_read() argument
50 container_of(rng, struct stm32_rng_private, rng); in stm32_rng_read()
54 pm_runtime_get_sync((struct device *) priv->rng.priv); in stm32_rng_read()
57 sr = readl_relaxed(priv->base + RNG_SR); in stm32_rng_read()
59 /* care of initial delay time when enabling rng */ in stm32_rng_read()
61 retval = readl_relaxed_poll_timeout_atomic(priv->base in stm32_rng_read()
66 dev_err((struct device *)priv->rng.priv, in stm32_rng_read()
73 "bad RNG status - %x\n", sr)) in stm32_rng_read()
74 writel_relaxed(0, priv->base + RNG_SR); in stm32_rng_read()
78 *(u32 *)data = readl_relaxed(priv->base + RNG_DR); in stm32_rng_read()
82 max -= sizeof(u32); in stm32_rng_read()
85 pm_runtime_mark_last_busy((struct device *) priv->rng.priv); in stm32_rng_read()
86 pm_runtime_put_sync_autosuspend((struct device *) priv->rng.priv); in stm32_rng_read()
88 return retval || !wait ? retval : -EIO; in stm32_rng_read()
91 static int stm32_rng_init(struct hwrng *rng) in stm32_rng_init() argument
94 container_of(rng, struct stm32_rng_private, rng); in stm32_rng_init()
97 err = clk_prepare_enable(priv->clk); in stm32_rng_init()
101 if (priv->ced) in stm32_rng_init()
102 writel_relaxed(RNG_CR_RNGEN, priv->base + RNG_CR); in stm32_rng_init()
105 priv->base + RNG_CR); in stm32_rng_init()
108 writel_relaxed(0, priv->base + RNG_SR); in stm32_rng_init()
113 static void stm32_rng_cleanup(struct hwrng *rng) in stm32_rng_cleanup() argument
116 container_of(rng, struct stm32_rng_private, rng); in stm32_rng_cleanup()
118 writel_relaxed(0, priv->base + RNG_CR); in stm32_rng_cleanup()
119 clk_disable_unprepare(priv->clk); in stm32_rng_cleanup()
124 struct device *dev = &ofdev->dev; in stm32_rng_probe()
125 struct device_node *np = ofdev->dev.of_node; in stm32_rng_probe()
132 return -ENOMEM; in stm32_rng_probe()
138 priv->base = devm_ioremap_resource(dev, &res); in stm32_rng_probe()
139 if (IS_ERR(priv->base)) in stm32_rng_probe()
140 return PTR_ERR(priv->base); in stm32_rng_probe()
142 priv->clk = devm_clk_get(&ofdev->dev, NULL); in stm32_rng_probe()
143 if (IS_ERR(priv->clk)) in stm32_rng_probe()
144 return PTR_ERR(priv->clk); in stm32_rng_probe()
146 priv->rst = devm_reset_control_get(&ofdev->dev, NULL); in stm32_rng_probe()
147 if (!IS_ERR(priv->rst)) { in stm32_rng_probe()
148 reset_control_assert(priv->rst); in stm32_rng_probe()
150 reset_control_deassert(priv->rst); in stm32_rng_probe()
153 priv->ced = of_property_read_bool(np, "clock-error-detect"); in stm32_rng_probe()
157 priv->rng.name = dev_driver_string(dev), in stm32_rng_probe()
159 priv->rng.init = stm32_rng_init, in stm32_rng_probe()
160 priv->rng.cleanup = stm32_rng_cleanup, in stm32_rng_probe()
162 priv->rng.read = stm32_rng_read, in stm32_rng_probe()
163 priv->rng.priv = (unsigned long) dev; in stm32_rng_probe()
169 return devm_hwrng_register(dev, &priv->rng); in stm32_rng_probe()
174 pm_runtime_disable(&ofdev->dev); in stm32_rng_remove()
184 stm32_rng_cleanup(&priv->rng); in stm32_rng_runtime_suspend()
193 return stm32_rng_init(&priv->rng); in stm32_rng_runtime_resume()
207 .compatible = "st,stm32-rng",
215 .name = "stm32-rng",
227 MODULE_DESCRIPTION("STMicroelectronics STM32 RNG device driver");