• Home
  • Raw
  • Download

Lines Matching +full:stm32 +full:- +full:rng

1 // SPDX-License-Identifier: GPL-2.0-or-later
32 struct hwrng rng; member
39 static int stm32_rng_read(struct hwrng *rng, void *data, size_t max, bool wait) in stm32_rng_read() argument
42 container_of(rng, struct stm32_rng_private, rng); in stm32_rng_read()
46 pm_runtime_get_sync((struct device *) priv->rng.priv); in stm32_rng_read()
49 sr = readl_relaxed(priv->base + RNG_SR); in stm32_rng_read()
51 /* care of initial delay time when enabling rng */ in stm32_rng_read()
55 err = readl_relaxed_poll_timeout_atomic(priv->base in stm32_rng_read()
60 dev_err((struct device *)priv->rng.priv, in stm32_rng_read()
67 "bad RNG status - %x\n", sr)) in stm32_rng_read()
68 writel_relaxed(0, priv->base + RNG_SR); in stm32_rng_read()
72 *(u32 *)data = readl_relaxed(priv->base + RNG_DR); in stm32_rng_read()
76 max -= sizeof(u32); in stm32_rng_read()
79 pm_runtime_mark_last_busy((struct device *) priv->rng.priv); in stm32_rng_read()
80 pm_runtime_put_sync_autosuspend((struct device *) priv->rng.priv); in stm32_rng_read()
82 return retval || !wait ? retval : -EIO; in stm32_rng_read()
85 static int stm32_rng_init(struct hwrng *rng) in stm32_rng_init() argument
88 container_of(rng, struct stm32_rng_private, rng); in stm32_rng_init()
91 err = clk_prepare_enable(priv->clk); in stm32_rng_init()
95 if (priv->ced) in stm32_rng_init()
96 writel_relaxed(RNG_CR_RNGEN, priv->base + RNG_CR); in stm32_rng_init()
99 priv->base + RNG_CR); in stm32_rng_init()
102 writel_relaxed(0, priv->base + RNG_SR); in stm32_rng_init()
107 static void stm32_rng_cleanup(struct hwrng *rng) in stm32_rng_cleanup() argument
110 container_of(rng, struct stm32_rng_private, rng); in stm32_rng_cleanup()
112 writel_relaxed(0, priv->base + RNG_CR); in stm32_rng_cleanup()
113 clk_disable_unprepare(priv->clk); in stm32_rng_cleanup()
118 struct device *dev = &ofdev->dev; in stm32_rng_probe()
119 struct device_node *np = ofdev->dev.of_node; in stm32_rng_probe()
126 return -ENOMEM; in stm32_rng_probe()
132 priv->base = devm_ioremap_resource(dev, &res); in stm32_rng_probe()
133 if (IS_ERR(priv->base)) in stm32_rng_probe()
134 return PTR_ERR(priv->base); in stm32_rng_probe()
136 priv->clk = devm_clk_get(&ofdev->dev, NULL); in stm32_rng_probe()
137 if (IS_ERR(priv->clk)) in stm32_rng_probe()
138 return PTR_ERR(priv->clk); in stm32_rng_probe()
140 priv->rst = devm_reset_control_get(&ofdev->dev, NULL); in stm32_rng_probe()
141 if (!IS_ERR(priv->rst)) { in stm32_rng_probe()
142 reset_control_assert(priv->rst); in stm32_rng_probe()
144 reset_control_deassert(priv->rst); in stm32_rng_probe()
147 priv->ced = of_property_read_bool(np, "clock-error-detect"); in stm32_rng_probe()
151 priv->rng.name = dev_driver_string(dev); in stm32_rng_probe()
153 priv->rng.init = stm32_rng_init; in stm32_rng_probe()
154 priv->rng.cleanup = stm32_rng_cleanup; in stm32_rng_probe()
156 priv->rng.read = stm32_rng_read; in stm32_rng_probe()
157 priv->rng.priv = (unsigned long) dev; in stm32_rng_probe()
158 priv->rng.quality = 900; in stm32_rng_probe()
164 return devm_hwrng_register(dev, &priv->rng); in stm32_rng_probe()
169 pm_runtime_disable(&ofdev->dev); in stm32_rng_remove()
179 stm32_rng_cleanup(&priv->rng); in stm32_rng_runtime_suspend()
188 return stm32_rng_init(&priv->rng); in stm32_rng_runtime_resume()
202 .compatible = "st,stm32-rng",
210 .name = "stm32-rng",
222 MODULE_DESCRIPTION("STMicroelectronics STM32 RNG device driver");