hwrng: bcm2835 - Support Broadcom NSP SoC rng
authorYendapally Reddy Dhananjaya Reddy <yendapally.reddy@broadcom.com>
Fri, 27 May 2016 10:10:39 +0000 (06:10 -0400)
committerHerbert Xu <herbert@gondor.apana.org.au>
Tue, 31 May 2016 09:52:23 +0000 (17:52 +0800)
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>
Acked-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/char/hw_random/Kconfig
drivers/char/hw_random/bcm2835-rng.c

index ac51149e977758beb8db91e159175be9525fc13c..43d527ea9014667facaaaf055747fc443053affe 100644 (file)
@@ -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
index 7192ec25f66763f5ca2d12e463650359cfa44c10..b1e8b7847e9ac0b29651186e031dd185ee6f2549 100644 (file)
@@ -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
 /* 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 = {