Lines Matching +full:npcm750 +full:- +full:rng
1 // SPDX-License-Identifier: GPL-2.0
21 #define NPCM_RNG_CLK_SET_62_5MHZ BIT(2) /* 60-80 MHz */
22 #define NPCM_RNG_CLK_SET_25MHZ GENMASK(4, 3) /* 20-25 MHz */
30 #define to_npcm_rng(p) container_of(p, struct npcm_rng, rng)
34 struct hwrng rng; member
38 static int npcm_rng_init(struct hwrng *rng) in npcm_rng_init() argument
40 struct npcm_rng *priv = to_npcm_rng(rng); in npcm_rng_init()
42 writel(priv->clkp | NPCM_RNG_ENABLE, priv->base + NPCM_RNGCS_REG); in npcm_rng_init()
47 static void npcm_rng_cleanup(struct hwrng *rng) in npcm_rng_cleanup() argument
49 struct npcm_rng *priv = to_npcm_rng(rng); in npcm_rng_cleanup()
51 writel(priv->clkp, priv->base + NPCM_RNGCS_REG); in npcm_rng_cleanup()
54 static int npcm_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) in npcm_rng_read() argument
56 struct npcm_rng *priv = to_npcm_rng(rng); in npcm_rng_read()
60 pm_runtime_get_sync((struct device *)priv->rng.priv); in npcm_rng_read()
64 if (readb_poll_timeout(priv->base + NPCM_RNGCS_REG, in npcm_rng_read()
71 if ((readb(priv->base + NPCM_RNGCS_REG) & in npcm_rng_read()
76 *(u8 *)buf = readb(priv->base + NPCM_RNGD_REG); in npcm_rng_read()
79 max--; in npcm_rng_read()
82 pm_runtime_mark_last_busy((struct device *)priv->rng.priv); in npcm_rng_read()
83 pm_runtime_put_sync_autosuspend((struct device *)priv->rng.priv); in npcm_rng_read()
85 return retval || !wait ? retval : -EIO; in npcm_rng_read()
93 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in npcm_rng_probe()
95 return -ENOMEM; in npcm_rng_probe()
97 priv->base = devm_platform_ioremap_resource(pdev, 0); in npcm_rng_probe()
98 if (IS_ERR(priv->base)) in npcm_rng_probe()
99 return PTR_ERR(priv->base); in npcm_rng_probe()
101 dev_set_drvdata(&pdev->dev, priv); in npcm_rng_probe()
102 pm_runtime_set_autosuspend_delay(&pdev->dev, 100); in npcm_rng_probe()
103 pm_runtime_use_autosuspend(&pdev->dev); in npcm_rng_probe()
104 pm_runtime_enable(&pdev->dev); in npcm_rng_probe()
107 priv->rng.init = npcm_rng_init; in npcm_rng_probe()
108 priv->rng.cleanup = npcm_rng_cleanup; in npcm_rng_probe()
110 priv->rng.name = pdev->name; in npcm_rng_probe()
111 priv->rng.read = npcm_rng_read; in npcm_rng_probe()
112 priv->rng.priv = (unsigned long)&pdev->dev; in npcm_rng_probe()
113 priv->clkp = (u32)(uintptr_t)of_device_get_match_data(&pdev->dev); in npcm_rng_probe()
115 writel(NPCM_RNG_M1ROSEL, priv->base + NPCM_RNGMODE_REG); in npcm_rng_probe()
117 ret = devm_hwrng_register(&pdev->dev, &priv->rng); in npcm_rng_probe()
119 dev_err(&pdev->dev, "Failed to register rng device: %d\n", in npcm_rng_probe()
121 pm_runtime_disable(&pdev->dev); in npcm_rng_probe()
122 pm_runtime_set_suspended(&pdev->dev); in npcm_rng_probe()
133 devm_hwrng_unregister(&pdev->dev, &priv->rng); in npcm_rng_remove()
134 pm_runtime_disable(&pdev->dev); in npcm_rng_remove()
135 pm_runtime_set_suspended(&pdev->dev); in npcm_rng_remove()
143 npcm_rng_cleanup(&priv->rng); in npcm_rng_runtime_suspend()
152 return npcm_rng_init(&priv->rng); in npcm_rng_runtime_resume()
164 { .compatible = "nuvoton,npcm750-rng",
166 { .compatible = "nuvoton,npcm845-rng",
174 .name = "npcm-rng",