summaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorFlorian Fainelli <f.fainelli@gmail.com>2017-11-07 19:44:43 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2017-11-29 00:43:45 -0500
commit04b154fa86afb6ccfd38ef9b563c098b13f5984d (patch)
tree242fea0e72c936116f26045a2c2a266937f349b3 /drivers/char
parent16a4c04b3729910f864512a1150fee5ad19efb4a (diff)
hwrng: bcm2835 - Rework interrupt masking
The interrupt masking done for Northstart Plus and Northstar (BCM5301X) is moved from being a function pointer mapped to of_device_id::data into a proper part of the hwrng::init callback. While at it, we also make the of_data be a proper structure indicating the platform specifics, since the day we need to add a second type of platform information, we would have to do that anyway. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Reviewed-by: Eric Anholt <eric@anholt.net> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/hw_random/bcm2835-rng.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c
index 67b9bd3be28d..ed20e0b6b7ae 100644
--- a/drivers/char/hw_random/bcm2835-rng.c
+++ b/drivers/char/hw_random/bcm2835-rng.c
@@ -32,18 +32,9 @@
32struct bcm2835_rng_priv { 32struct bcm2835_rng_priv {
33 struct hwrng rng; 33 struct hwrng rng;
34 void __iomem *base; 34 void __iomem *base;
35 bool mask_interrupts;
35}; 36};
36 37
37static void __init nsp_rng_init(void __iomem *base)
38{
39 u32 val;
40
41 /* mask the interrupt */
42 val = readl(base + RNG_INT_MASK);
43 val |= RNG_INT_OFF;
44 writel(val, base + RNG_INT_MASK);
45}
46
47static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) 38static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng)
48{ 39{
49 return container_of(rng, struct bcm2835_rng_priv, rng); 40 return container_of(rng, struct bcm2835_rng_priv, rng);
@@ -75,6 +66,14 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
75static int bcm2835_rng_init(struct hwrng *rng) 66static int bcm2835_rng_init(struct hwrng *rng)
76{ 67{
77 struct bcm2835_rng_priv *priv = to_rng_priv(rng); 68 struct bcm2835_rng_priv *priv = to_rng_priv(rng);
69 u32 val;
70
71 if (priv->mask_interrupts) {
72 /* mask the interrupt */
73 val = readl(priv->base + RNG_INT_MASK);
74 val |= RNG_INT_OFF;
75 writel(val, priv->base + RNG_INT_MASK);
76 }
78 77
79 /* set warm-up count & enable */ 78 /* set warm-up count & enable */
80 __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); 79 __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS);
@@ -91,18 +90,26 @@ static void bcm2835_rng_cleanup(struct hwrng *rng)
91 __raw_writel(0, priv->base + RNG_CTRL); 90 __raw_writel(0, priv->base + RNG_CTRL);
92} 91}
93 92
93struct bcm2835_rng_of_data {
94 bool mask_interrupts;
95};
96
97static const struct bcm2835_rng_of_data nsp_rng_of_data = {
98 .mask_interrupts = true,
99};
100
94static const struct of_device_id bcm2835_rng_of_match[] = { 101static const struct of_device_id bcm2835_rng_of_match[] = {
95 { .compatible = "brcm,bcm2835-rng"}, 102 { .compatible = "brcm,bcm2835-rng"},
96 { .compatible = "brcm,bcm-nsp-rng", .data = nsp_rng_init}, 103 { .compatible = "brcm,bcm-nsp-rng", .data = &nsp_rng_of_data },
97 { .compatible = "brcm,bcm5301x-rng", .data = nsp_rng_init}, 104 { .compatible = "brcm,bcm5301x-rng", .data = &nsp_rng_of_data },
98 {}, 105 {},
99}; 106};
100 107
101static int bcm2835_rng_probe(struct platform_device *pdev) 108static int bcm2835_rng_probe(struct platform_device *pdev)
102{ 109{
110 const struct bcm2835_rng_of_data *of_data;
103 struct device *dev = &pdev->dev; 111 struct device *dev = &pdev->dev;
104 struct device_node *np = dev->of_node; 112 struct device_node *np = dev->of_node;
105 void (*rng_setup)(void __iomem *base);
106 const struct of_device_id *rng_id; 113 const struct of_device_id *rng_id;
107 struct bcm2835_rng_priv *priv; 114 struct bcm2835_rng_priv *priv;
108 struct resource *r; 115 struct resource *r;
@@ -133,9 +140,9 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
133 return -EINVAL; 140 return -EINVAL;
134 141
135 /* Check for rng init function, execute it */ 142 /* Check for rng init function, execute it */
136 rng_setup = rng_id->data; 143 of_data = rng_id->data;
137 if (rng_setup) 144 if (of_data)
138 rng_setup(priv->base); 145 priv->mask_interrupts = of_data->mask_interrupts;
139 146
140 /* register driver */ 147 /* register driver */
141 err = devm_hwrng_register(dev, &priv->rng); 148 err = devm_hwrng_register(dev, &priv->rng);