Lines Matching refs:rngc
74 static inline void imx_rngc_irq_mask_clear(struct imx_rngc *rngc) in imx_rngc_irq_mask_clear() argument
79 ctrl = readl(rngc->base + RNGC_CONTROL); in imx_rngc_irq_mask_clear()
81 writel(ctrl, rngc->base + RNGC_CONTROL); in imx_rngc_irq_mask_clear()
88 cmd = readl(rngc->base + RNGC_COMMAND); in imx_rngc_irq_mask_clear()
90 writel(cmd, rngc->base + RNGC_COMMAND); in imx_rngc_irq_mask_clear()
93 static inline void imx_rngc_irq_unmask(struct imx_rngc *rngc) in imx_rngc_irq_unmask() argument
97 ctrl = readl(rngc->base + RNGC_CONTROL); in imx_rngc_irq_unmask()
99 writel(ctrl, rngc->base + RNGC_CONTROL); in imx_rngc_irq_unmask()
102 static int imx_rngc_self_test(struct imx_rngc *rngc) in imx_rngc_self_test() argument
107 imx_rngc_irq_unmask(rngc); in imx_rngc_self_test()
110 cmd = readl(rngc->base + RNGC_COMMAND); in imx_rngc_self_test()
111 writel(cmd | RNGC_CMD_SELF_TEST, rngc->base + RNGC_COMMAND); in imx_rngc_self_test()
113 ret = wait_for_completion_timeout(&rngc->rng_op_done, in imx_rngc_self_test()
115 imx_rngc_irq_mask_clear(rngc); in imx_rngc_self_test()
119 return rngc->err_reg ? -EIO : 0; in imx_rngc_self_test()
124 struct imx_rngc *rngc = container_of(rng, struct imx_rngc, rng); in imx_rngc_read() local
129 status = readl(rngc->base + RNGC_STATUS); in imx_rngc_read()
137 *(u32 *)data = readl(rngc->base + RNGC_FIFO); in imx_rngc_read()
150 struct imx_rngc *rngc = (struct imx_rngc *)priv; in imx_rngc_irq() local
157 status = readl(rngc->base + RNGC_STATUS); in imx_rngc_irq()
158 rngc->err_reg = readl(rngc->base + RNGC_ERROR); in imx_rngc_irq()
160 imx_rngc_irq_mask_clear(rngc); in imx_rngc_irq()
163 complete(&rngc->rng_op_done); in imx_rngc_irq()
170 struct imx_rngc *rngc = container_of(rng, struct imx_rngc, rng); in imx_rngc_init() local
175 cmd = readl(rngc->base + RNGC_COMMAND); in imx_rngc_init()
176 writel(cmd | RNGC_CMD_CLR_ERR, rngc->base + RNGC_COMMAND); in imx_rngc_init()
178 imx_rngc_irq_unmask(rngc); in imx_rngc_init()
183 cmd = readl(rngc->base + RNGC_COMMAND); in imx_rngc_init()
184 writel(cmd | RNGC_CMD_SEED, rngc->base + RNGC_COMMAND); in imx_rngc_init()
186 ret = wait_for_completion_timeout(&rngc->rng_op_done, in imx_rngc_init()
193 } while (rngc->err_reg == RNGC_ERROR_STATUS_STAT_ERR); in imx_rngc_init()
195 if (rngc->err_reg) { in imx_rngc_init()
204 ctrl = readl(rngc->base + RNGC_CONTROL); in imx_rngc_init()
206 writel(ctrl, rngc->base + RNGC_CONTROL); in imx_rngc_init()
216 imx_rngc_irq_mask_clear(rngc); in imx_rngc_init()
222 struct imx_rngc *rngc = container_of(rng, struct imx_rngc, rng); in imx_rngc_cleanup() local
224 imx_rngc_irq_mask_clear(rngc); in imx_rngc_cleanup()
229 struct imx_rngc *rngc; in imx_rngc_probe() local
235 rngc = devm_kzalloc(&pdev->dev, sizeof(*rngc), GFP_KERNEL); in imx_rngc_probe()
236 if (!rngc) in imx_rngc_probe()
239 rngc->base = devm_platform_ioremap_resource(pdev, 0); in imx_rngc_probe()
240 if (IS_ERR(rngc->base)) in imx_rngc_probe()
241 return PTR_ERR(rngc->base); in imx_rngc_probe()
243 rngc->clk = devm_clk_get_enabled(&pdev->dev, NULL); in imx_rngc_probe()
244 if (IS_ERR(rngc->clk)) in imx_rngc_probe()
245 return dev_err_probe(&pdev->dev, PTR_ERR(rngc->clk), "Cannot get rng_clk\n"); in imx_rngc_probe()
251 ver_id = readl(rngc->base + RNGC_VER_ID); in imx_rngc_probe()
260 init_completion(&rngc->rng_op_done); in imx_rngc_probe()
262 rngc->rng.name = pdev->name; in imx_rngc_probe()
263 rngc->rng.init = imx_rngc_init; in imx_rngc_probe()
264 rngc->rng.read = imx_rngc_read; in imx_rngc_probe()
265 rngc->rng.cleanup = imx_rngc_cleanup; in imx_rngc_probe()
266 rngc->rng.quality = 19; in imx_rngc_probe()
268 rngc->dev = &pdev->dev; in imx_rngc_probe()
269 platform_set_drvdata(pdev, rngc); in imx_rngc_probe()
271 imx_rngc_irq_mask_clear(rngc); in imx_rngc_probe()
274 irq, imx_rngc_irq, 0, pdev->name, (void *)rngc); in imx_rngc_probe()
279 ret = imx_rngc_self_test(rngc); in imx_rngc_probe()
284 ret = devm_hwrng_register(&pdev->dev, &rngc->rng); in imx_rngc_probe()
297 struct imx_rngc *rngc = dev_get_drvdata(dev); in imx_rngc_suspend() local
299 clk_disable_unprepare(rngc->clk); in imx_rngc_suspend()
306 struct imx_rngc *rngc = dev_get_drvdata(dev); in imx_rngc_resume() local
308 clk_prepare_enable(rngc->clk); in imx_rngc_resume()