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