Lines Matching +full:clk +full:- +full:delay +full:- +full:cycles

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2016 Texas Instruments Incorporated - https://www.ti.com
16 #include <linux/clk.h>
23 #include <linux/delay.h>
64 /* Number of CLK input cycles between samples */
70 /* Delay between retries (in usecs) */
85 struct clk *clk; member
92 static unsigned int cycles_to_ns(unsigned long clk_rate, unsigned int cycles) in cycles_to_ns() argument
95 cycles, clk_rate); in cycles_to_ns()
116 unsigned long clk_rate = clk_get_rate(ks_sa_rng->clk); in ks_sa_rng_init()
119 regmap_write_bits(ks_sa_rng->regmap_cfg, SA_CMD_STATUS_OFS, in ks_sa_rng_init()
124 writel(0, &ks_sa_rng->reg_rng->control); in ks_sa_rng_init()
126 writel(value, &ks_sa_rng->reg_rng->control); in ks_sa_rng_init()
135 writel(value, &ks_sa_rng->reg_rng->config); in ks_sa_rng_init()
138 writel(0, &ks_sa_rng->reg_rng->intmask); in ks_sa_rng_init()
141 value = readl(&ks_sa_rng->reg_rng->control); in ks_sa_rng_init()
143 writel(value, &ks_sa_rng->reg_rng->control); in ks_sa_rng_init()
145 ks_sa_rng->refill_delay_ns = refill_delay_ns(clk_rate); in ks_sa_rng_init()
146 ks_sa_rng->ready_ts = ktime_get_ns() + in ks_sa_rng_init()
157 writel(0, &ks_sa_rng->reg_rng->control); in ks_sa_rng_cleanup()
158 regmap_write_bits(ks_sa_rng->regmap_cfg, SA_CMD_STATUS_OFS, in ks_sa_rng_cleanup()
167 data[0] = readl(&ks_sa_rng->reg_rng->output_l); in ks_sa_rng_data_read()
168 data[1] = readl(&ks_sa_rng->reg_rng->output_h); in ks_sa_rng_data_read()
170 writel(TRNG_INTACK_REG_READY, &ks_sa_rng->reg_rng->intack); in ks_sa_rng_data_read()
171 ks_sa_rng->ready_ts = ktime_get_ns() + ks_sa_rng->refill_delay_ns; in ks_sa_rng_data_read()
184 if (wait && now < ks_sa_rng->ready_ts) { in ks_sa_rng_data_present()
185 /* Max delay expected here is 81920000 ns */ in ks_sa_rng_data_present()
187 DIV_ROUND_UP((u32)(ks_sa_rng->ready_ts - now), 1000); in ks_sa_rng_data_present()
193 ready = readl(&ks_sa_rng->reg_rng->status); in ks_sa_rng_data_present()
208 struct device *dev = &pdev->dev; in ks_sa_rng_probe()
213 return -ENOMEM; in ks_sa_rng_probe()
215 ks_sa_rng->rng = (struct hwrng) { in ks_sa_rng_probe()
223 ks_sa_rng->reg_rng = devm_platform_ioremap_resource(pdev, 0); in ks_sa_rng_probe()
224 if (IS_ERR(ks_sa_rng->reg_rng)) in ks_sa_rng_probe()
225 return PTR_ERR(ks_sa_rng->reg_rng); in ks_sa_rng_probe()
227 ks_sa_rng->regmap_cfg = in ks_sa_rng_probe()
228 syscon_regmap_lookup_by_phandle(dev->of_node, in ks_sa_rng_probe()
229 "ti,syscon-sa-cfg"); in ks_sa_rng_probe()
231 if (IS_ERR(ks_sa_rng->regmap_cfg)) in ks_sa_rng_probe()
232 return dev_err_probe(dev, -EINVAL, "syscon_node_to_regmap failed\n"); in ks_sa_rng_probe()
238 return dev_err_probe(dev, ret, "Failed to enable SA power-domain\n"); in ks_sa_rng_probe()
241 return devm_hwrng_register(&pdev->dev, &ks_sa_rng->rng); in ks_sa_rng_probe()
246 pm_runtime_put_sync(&pdev->dev); in ks_sa_rng_remove()
247 pm_runtime_disable(&pdev->dev); in ks_sa_rng_remove()
252 .compatible = "ti,keystone-rng",
260 .name = "ks-sa-rng",