bmips: switch to upstream bcm2835-rng reset patch
[openwrt/staging/rmilecki.git] / target / linux / bmips / patches-5.10 / 054-hwrng-bcm2835-add-reset-support.patch
1 From e5f9f41d5e62004c913bfd4ddf06abe032f5ce1c Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= <noltari@gmail.com>
3 Date: Fri, 5 Mar 2021 08:01:32 +0100
4 Subject: [PATCH 3/3] hwrng: bcm2835 - add reset support
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 BCM6368 devices need to reset the IPSEC controller in order to generate true
10 random numbers.
11
12 This is what BCM6368 produces without a reset:
13 root@OpenWrt:/# cat /dev/hwrng | rngtest -c 1000
14 rngtest 6.10
15 Copyright (c) 2004 by Henrique de Moraes Holschuh
16 This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18 rngtest: starting FIPS tests...
19 rngtest: bits received from input: 20000032
20 rngtest: FIPS 140-2 successes: 0
21 rngtest: FIPS 140-2 failures: 1000
22 rngtest: FIPS 140-2(2001-10-10) Monobit: 2
23 rngtest: FIPS 140-2(2001-10-10) Poker: 1000
24 rngtest: FIPS 140-2(2001-10-10) Runs: 1000
25 rngtest: FIPS 140-2(2001-10-10) Long run: 30
26 rngtest: FIPS 140-2(2001-10-10) Continuous run: 0
27 rngtest: input channel speed: (min=37.253; avg=320.827; max=635.783)Mibits/s
28 rngtest: FIPS tests speed: (min=12.141; avg=15.034; max=16.428)Mibits/s
29 rngtest: Program run time: 1336176 microseconds
30
31 Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
32 Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
33 Acked-by: Florian Fainelli <f.fainelli@gmail.com>
34 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
35 ---
36 drivers/char/hw_random/bcm2835-rng.c | 10 ++++++++++
37 1 file changed, 10 insertions(+)
38
39 --- a/drivers/char/hw_random/bcm2835-rng.c
40 +++ b/drivers/char/hw_random/bcm2835-rng.c
41 @@ -13,6 +13,7 @@
42 #include <linux/platform_device.h>
43 #include <linux/printk.h>
44 #include <linux/clk.h>
45 +#include <linux/reset.h>
46
47 #define RNG_CTRL 0x0
48 #define RNG_STATUS 0x4
49 @@ -32,6 +33,7 @@ struct bcm2835_rng_priv {
50 void __iomem *base;
51 bool mask_interrupts;
52 struct clk *clk;
53 + struct reset_control *reset;
54 };
55
56 static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng)
57 @@ -94,6 +96,10 @@ static int bcm2835_rng_init(struct hwrng
58 return ret;
59 }
60
61 + ret = reset_control_reset(priv->reset);
62 + if (ret)
63 + return ret;
64 +
65 if (priv->mask_interrupts) {
66 /* mask the interrupt */
67 val = rng_readl(priv, RNG_INT_MASK);
68 @@ -159,6 +165,10 @@ static int bcm2835_rng_probe(struct plat
69 if (PTR_ERR(priv->clk) == -EPROBE_DEFER)
70 return -EPROBE_DEFER;
71
72 + priv->reset = devm_reset_control_get_optional_exclusive(dev, NULL);
73 + if (IS_ERR(priv->reset))
74 + return PTR_ERR(priv->reset);
75 +
76 priv->rng.name = pdev->name;
77 priv->rng.init = bcm2835_rng_init;
78 priv->rng.read = bcm2835_rng_read;