Commit b149a30d87d165e1079163fdab6f14e48b2f57b2
Committed by
Herbert Xu
1 parent
1907da78bf
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
hwrng: timeriomem - added devicetree hooks
This patch allows timeriomem_rng to be used via devicetree. Signed-off-by: Alexander Clouter <alex@digriz.org.uk> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Showing 2 changed files with 40 additions and 2 deletions Side-by-side Diff
Documentation/devicetree/bindings/hwrng/timeriomem_rng.txt
1 | +HWRNG support for the timeriomem_rng driver | |
2 | + | |
3 | +Required properties: | |
4 | +- compatible : "timeriomem_rng" | |
5 | +- reg : base address to sample from | |
6 | +- period : wait time in microseconds to use between samples | |
7 | + | |
8 | +N.B. currently 'reg' must be four bytes wide and aligned | |
9 | + | |
10 | +Example: | |
11 | + | |
12 | +hwrng@44 { | |
13 | + #address-cells = <1>; | |
14 | + #size-cells = <1>; | |
15 | + compatible = "timeriomem_rng"; | |
16 | + reg = <0x44 0x04>; | |
17 | + period = <1000000>; | |
18 | +}; |
drivers/char/hw_random/timeriomem-rng.c
... | ... | @@ -23,6 +23,7 @@ |
23 | 23 | #include <linux/module.h> |
24 | 24 | #include <linux/kernel.h> |
25 | 25 | #include <linux/platform_device.h> |
26 | +#include <linux/of.h> | |
26 | 27 | #include <linux/hw_random.h> |
27 | 28 | #include <linux/io.h> |
28 | 29 | #include <linux/slab.h> |
... | ... | @@ -101,7 +102,7 @@ |
101 | 102 | int err = 0; |
102 | 103 | int period; |
103 | 104 | |
104 | - if (!pdata) { | |
105 | + if (!pdev->dev.of_node && !pdata) { | |
105 | 106 | dev_err(&pdev->dev, "timeriomem_rng_data is missing\n"); |
106 | 107 | return -EINVAL; |
107 | 108 | } |
108 | 109 | |
... | ... | @@ -125,8 +126,20 @@ |
125 | 126 | |
126 | 127 | platform_set_drvdata(pdev, priv); |
127 | 128 | |
128 | - period = pdata->period; | |
129 | + if (pdev->dev.of_node) { | |
130 | + int i; | |
129 | 131 | |
132 | + if (!of_property_read_u32(pdev->dev.of_node, | |
133 | + "period", &i)) | |
134 | + period = i; | |
135 | + else { | |
136 | + dev_err(&pdev->dev, "missing period\n"); | |
137 | + err = -EINVAL; | |
138 | + goto out_free; | |
139 | + } | |
140 | + } else | |
141 | + period = pdata->period; | |
142 | + | |
130 | 143 | priv->period = usecs_to_jiffies(period); |
131 | 144 | if (priv->period < 1) { |
132 | 145 | dev_err(&pdev->dev, "period is less than one jiffy\n"); |
133 | 146 | |
... | ... | @@ -202,10 +215,17 @@ |
202 | 215 | return 0; |
203 | 216 | } |
204 | 217 | |
218 | +static const struct of_device_id timeriomem_rng_match[] = { | |
219 | + { .compatible = "timeriomem_rng" }, | |
220 | + {}, | |
221 | +}; | |
222 | +MODULE_DEVICE_TABLE(of, timeriomem_rng_match); | |
223 | + | |
205 | 224 | static struct platform_driver timeriomem_rng_driver = { |
206 | 225 | .driver = { |
207 | 226 | .name = "timeriomem_rng", |
208 | 227 | .owner = THIS_MODULE, |
228 | + .of_match_table = timeriomem_rng_match, | |
209 | 229 | }, |
210 | 230 | .probe = timeriomem_rng_probe, |
211 | 231 | .remove = timeriomem_rng_remove, |