* [PATCH 1/4] dt-bindings: rng: Northstar Plus SoC rng bindings
2016-05-23 16:20 [PATCH 0/4] hw rng support for NSP SoC Yendapally Reddy Dhananjaya Reddy
@ 2016-05-23 16:20 ` Yendapally Reddy Dhananjaya Reddy
2016-05-23 21:39 ` Rob Herring
2016-05-24 2:22 ` Eric Anholt
2016-05-23 16:20 ` [PATCH 2/4] hwrng: bcm2835: Support Broadcom NSP SoC rng Yendapally Reddy Dhananjaya Reddy
` (2 subsequent siblings)
3 siblings, 2 replies; 9+ messages in thread
From: Yendapally Reddy Dhananjaya Reddy @ 2016-05-23 16:20 UTC (permalink / raw)
To: linux-arm-kernel
Document the bindings used by Northstar Plus(NSP) SoC random number
generator.
Signed-off-by: Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com>
---
Documentation/devicetree/bindings/rng/brcm,bcm2835.txt | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt b/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt
index 07ccdaa..aa304d4 100644
--- a/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt
+++ b/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt
@@ -2,7 +2,7 @@ BCM2835 Random number generator
Required properties:
-- compatible : should be "brcm,bcm2835-rng"
+- compatible : should be "brcm,bcm2835-rng" or "brcm,bcm-nsp-rng"
- reg : Specifies base physical address and size of the registers.
Example:
@@ -11,3 +11,8 @@ rng {
compatible = "brcm,bcm2835-rng";
reg = <0x7e104000 0x10>;
};
+
+rng at 18033000 {
+ compatible = "brcm,bcm-nsp-rng";
+ reg = <0x18033000 0x14>;
+};
--
2.1.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 2/4] hwrng: bcm2835: Support Broadcom NSP SoC rng
2016-05-23 16:20 [PATCH 0/4] hw rng support for NSP SoC Yendapally Reddy Dhananjaya Reddy
2016-05-23 16:20 ` [PATCH 1/4] dt-bindings: rng: Northstar Plus SoC rng bindings Yendapally Reddy Dhananjaya Reddy
@ 2016-05-23 16:20 ` Yendapally Reddy Dhananjaya Reddy
2016-05-24 2:14 ` Eric Anholt
2016-05-23 16:20 ` [PATCH 3/4] ARM: dts: nsp: Add rng device tree entry Yendapally Reddy Dhananjaya Reddy
2016-05-23 16:20 ` [PATCH 4/4] hwrng: bcm2835: Read as much data as available Yendapally Reddy Dhananjaya Reddy
3 siblings, 1 reply; 9+ messages in thread
From: Yendapally Reddy Dhananjaya Reddy @ 2016-05-23 16:20 UTC (permalink / raw)
To: linux-arm-kernel
This supports the random number generator available in NSP SoC.
Masks the rng interrupt for NSP.
Signed-off-by: Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com>
---
drivers/char/hw_random/Kconfig | 2 +-
drivers/char/hw_random/bcm2835-rng.c | 34 ++++++++++++++++++++++++++++++----
2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 67ee8b0..f8d1a2b 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -90,7 +90,7 @@ config HW_RANDOM_BCM63XX
config HW_RANDOM_BCM2835
tristate "Broadcom BCM2835 Random Number Generator support"
- depends on ARCH_BCM2835
+ depends on ARCH_BCM2835 || ARCH_BCM_NSP
default HW_RANDOM
---help---
This driver provides kernel-side support for the Random Number
diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c
index 7192ec2..b1e8b78 100644
--- a/drivers/char/hw_random/bcm2835-rng.c
+++ b/drivers/char/hw_random/bcm2835-rng.c
@@ -19,6 +19,7 @@
#define RNG_CTRL 0x0
#define RNG_STATUS 0x4
#define RNG_DATA 0x8
+#define RNG_INT_MASK 0x10
/* enable rng */
#define RNG_RBGEN 0x1
@@ -26,6 +27,18 @@
/* the initial numbers generated are "less random" so will be discarded */
#define RNG_WARMUP_COUNT 0x40000
+#define RNG_INT_OFF 0x1
+
+static void __init nsp_rng_init(void __iomem *base)
+{
+ u32 val;
+
+ /* mask the interrupt */
+ val = readl(base + RNG_INT_MASK);
+ val |= RNG_INT_OFF;
+ writel(val, base + RNG_INT_MASK);
+}
+
static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
bool wait)
{
@@ -46,10 +59,18 @@ static struct hwrng bcm2835_rng_ops = {
.read = bcm2835_rng_read,
};
+static const struct of_device_id bcm2835_rng_of_match[] = {
+ { .compatible = "brcm,bcm2835-rng"},
+ { .compatible = "brcm,bcm-nsp-rng", .data = nsp_rng_init},
+ {},
+};
+
static int bcm2835_rng_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
+ void (*rng_setup)(void __iomem *base);
+ const struct of_device_id *rng_id;
void __iomem *rng_base;
int err;
@@ -61,6 +82,15 @@ static int bcm2835_rng_probe(struct platform_device *pdev)
}
bcm2835_rng_ops.priv = (unsigned long)rng_base;
+ rng_id = of_match_node(bcm2835_rng_of_match, np);
+ if (!rng_id)
+ return -EINVAL;
+
+ /* Check for rng init function, execute it */
+ rng_setup = rng_id->data;
+ if (rng_setup)
+ rng_setup(rng_base);
+
/* set warm-up count & enable */
__raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
__raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
@@ -90,10 +120,6 @@ static int bcm2835_rng_remove(struct platform_device *pdev)
return 0;
}
-static const struct of_device_id bcm2835_rng_of_match[] = {
- { .compatible = "brcm,bcm2835-rng", },
- {},
-};
MODULE_DEVICE_TABLE(of, bcm2835_rng_of_match);
static struct platform_driver bcm2835_rng_driver = {
--
2.1.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 3/4] ARM: dts: nsp: Add rng device tree entry
2016-05-23 16:20 [PATCH 0/4] hw rng support for NSP SoC Yendapally Reddy Dhananjaya Reddy
2016-05-23 16:20 ` [PATCH 1/4] dt-bindings: rng: Northstar Plus SoC rng bindings Yendapally Reddy Dhananjaya Reddy
2016-05-23 16:20 ` [PATCH 2/4] hwrng: bcm2835: Support Broadcom NSP SoC rng Yendapally Reddy Dhananjaya Reddy
@ 2016-05-23 16:20 ` Yendapally Reddy Dhananjaya Reddy
2016-05-23 16:20 ` [PATCH 4/4] hwrng: bcm2835: Read as much data as available Yendapally Reddy Dhananjaya Reddy
3 siblings, 0 replies; 9+ messages in thread
From: Yendapally Reddy Dhananjaya Reddy @ 2016-05-23 16:20 UTC (permalink / raw)
To: linux-arm-kernel
Add support for the random number generator to the Northstar Plus
SoC device tree.
Signed-off-by: Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com>
---
arch/arm/boot/dts/bcm-nsp.dtsi | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/arm/boot/dts/bcm-nsp.dtsi b/arch/arm/boot/dts/bcm-nsp.dtsi
index def9e78..1ed829e 100644
--- a/arch/arm/boot/dts/bcm-nsp.dtsi
+++ b/arch/arm/boot/dts/bcm-nsp.dtsi
@@ -206,6 +206,11 @@
brcm,nand-has-wp;
};
+ rng: rng at 33000 {
+ compatible = "brcm,bcm-nsp-rng";
+ reg = <0x33000 0x14>;
+ };
+
ccbtimer0: timer at 34000 {
compatible = "arm,sp804";
reg = <0x34000 0x1000>;
--
2.1.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 4/4] hwrng: bcm2835: Read as much data as available
2016-05-23 16:20 [PATCH 0/4] hw rng support for NSP SoC Yendapally Reddy Dhananjaya Reddy
` (2 preceding siblings ...)
2016-05-23 16:20 ` [PATCH 3/4] ARM: dts: nsp: Add rng device tree entry Yendapally Reddy Dhananjaya Reddy
@ 2016-05-23 16:20 ` Yendapally Reddy Dhananjaya Reddy
2016-05-24 2:21 ` Eric Anholt
3 siblings, 1 reply; 9+ messages in thread
From: Yendapally Reddy Dhananjaya Reddy @ 2016-05-23 16:20 UTC (permalink / raw)
To: linux-arm-kernel
Read the requested number of data from the fifo
Signed-off-by: Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com>
---
drivers/char/hw_random/bcm2835-rng.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c
index b1e8b78..9bbdc07 100644
--- a/drivers/char/hw_random/bcm2835-rng.c
+++ b/drivers/char/hw_random/bcm2835-rng.c
@@ -43,6 +43,8 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
bool wait)
{
void __iomem *rng_base = (void __iomem *)rng->priv;
+ u32 max_words = max/sizeof(u32);
+ u32 num_words, count;
while ((__raw_readl(rng_base + RNG_STATUS) >> 24) == 0) {
if (!wait)
@@ -50,8 +52,14 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
cpu_relax();
}
- *(u32 *)buf = __raw_readl(rng_base + RNG_DATA);
- return sizeof(u32);
+ num_words = (readl(rng_base + RNG_STATUS) >> 24);
+ if (num_words > max_words)
+ num_words = max_words;
+
+ for (count = 0; count < num_words; count++)
+ ((u32 *)buf)[count] = readl(rng_base + RNG_DATA);
+
+ return (num_words * sizeof(u32));
}
static struct hwrng bcm2835_rng_ops = {
--
2.1.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 4/4] hwrng: bcm2835: Read as much data as available
2016-05-23 16:20 ` [PATCH 4/4] hwrng: bcm2835: Read as much data as available Yendapally Reddy Dhananjaya Reddy
@ 2016-05-24 2:21 ` Eric Anholt
0 siblings, 0 replies; 9+ messages in thread
From: Eric Anholt @ 2016-05-24 2:21 UTC (permalink / raw)
To: linux-arm-kernel
Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com>
writes:
> Read the requested number of data from the fifo
>
> Signed-off-by: Yendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com>
> ---
> drivers/char/hw_random/bcm2835-rng.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c
> index b1e8b78..9bbdc07 100644
> --- a/drivers/char/hw_random/bcm2835-rng.c
> +++ b/drivers/char/hw_random/bcm2835-rng.c
> @@ -43,6 +43,8 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
> bool wait)
> {
> void __iomem *rng_base = (void __iomem *)rng->priv;
> + u32 max_words = max/sizeof(u32);
Style fix: Binary operators get a space on each side, so
"max / sizeof(u32);"
> @@ -50,8 +52,14 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max,
> cpu_relax();
> }
>
> - *(u32 *)buf = __raw_readl(rng_base + RNG_DATA);
> - return sizeof(u32);
> + num_words = (readl(rng_base + RNG_STATUS) >> 24);
Optional cleanup: here and in the return statement, drop the extra
parenthesis.
Functionality-wise, this patch looks great to me, and should make the
driver more efficient. With at least the binary operators change done,
it will be:
Reviewed-by: Eric Anholt <eric@anholt.net>
Thanks!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20160523/14498083/attachment.sig>
^ permalink raw reply [flat|nested] 9+ messages in thread