.. | .. |
---|
7 | 7 | #include <linux/acpi.h> |
---|
8 | 8 | #include <linux/clk.h> |
---|
9 | 9 | #include <linux/crypto.h> |
---|
| 10 | +#include <linux/io.h> |
---|
| 11 | +#include <linux/iopoll.h> |
---|
10 | 12 | #include <linux/module.h> |
---|
11 | 13 | #include <linux/of.h> |
---|
12 | 14 | #include <linux/platform_device.h> |
---|
.. | .. |
---|
42 | 44 | { |
---|
43 | 45 | unsigned int currsize = 0; |
---|
44 | 46 | u32 val; |
---|
| 47 | + int ret; |
---|
45 | 48 | |
---|
46 | 49 | /* read random data from hardware */ |
---|
47 | 50 | do { |
---|
48 | | - val = readl_relaxed(rng->base + PRNG_STATUS); |
---|
49 | | - if (!(val & PRNG_STATUS_DATA_AVAIL)) |
---|
50 | | - break; |
---|
| 51 | + ret = readl_poll_timeout(rng->base + PRNG_STATUS, val, |
---|
| 52 | + val & PRNG_STATUS_DATA_AVAIL, |
---|
| 53 | + 200, 10000); |
---|
| 54 | + if (ret) |
---|
| 55 | + return ret; |
---|
51 | 56 | |
---|
52 | 57 | val = readl_relaxed(rng->base + PRNG_DATA_OUT); |
---|
53 | 58 | if (!val) |
---|
54 | | - break; |
---|
| 59 | + return -EINVAL; |
---|
55 | 60 | |
---|
56 | 61 | if ((max - currsize) >= WORD_SZ) { |
---|
57 | 62 | memcpy(data, &val, WORD_SZ); |
---|
.. | .. |
---|
64 | 69 | } |
---|
65 | 70 | } while (currsize < max); |
---|
66 | 71 | |
---|
67 | | - return currsize; |
---|
| 72 | + return 0; |
---|
68 | 73 | } |
---|
69 | 74 | |
---|
70 | 75 | static int qcom_rng_generate(struct crypto_rng *tfm, |
---|
.. | .. |
---|
86 | 91 | mutex_unlock(&rng->lock); |
---|
87 | 92 | clk_disable_unprepare(rng->clk); |
---|
88 | 93 | |
---|
89 | | - return 0; |
---|
| 94 | + return ret; |
---|
90 | 95 | } |
---|
91 | 96 | |
---|
92 | 97 | static int qcom_rng_seed(struct crypto_rng *tfm, const u8 *seed, |
---|
.. | .. |
---|
153 | 158 | |
---|
154 | 159 | static int qcom_rng_probe(struct platform_device *pdev) |
---|
155 | 160 | { |
---|
156 | | - struct resource *res; |
---|
157 | 161 | struct qcom_rng *rng; |
---|
158 | 162 | int ret; |
---|
159 | 163 | |
---|
.. | .. |
---|
164 | 168 | platform_set_drvdata(pdev, rng); |
---|
165 | 169 | mutex_init(&rng->lock); |
---|
166 | 170 | |
---|
167 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
168 | | - rng->base = devm_ioremap_resource(&pdev->dev, res); |
---|
| 171 | + rng->base = devm_platform_ioremap_resource(pdev, 0); |
---|
169 | 172 | if (IS_ERR(rng->base)) |
---|
170 | 173 | return PTR_ERR(rng->base); |
---|
171 | 174 | |
---|