Re: [PATCH 2/2] ARM: bcm283x: Add missing interrupt for RNG block
On Sat, 18 Nov 2017 14:04:13 +0100, Stefan Wahren <stefan.wah...@i2se.com> wrote: > This patch adds the missing interrupt property to the RNG block > of BCM283x. > > Link: https://github.com/raspberrypi/linux/issues/2195 > CC: Florian Fainelli <f.faine...@gmail.com> > Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com> > --- Applied to devicetree/next, thanks! -- Florian
Re: [PATCH 1/2] dt-binding: rng: Add interrupt property for BCM2835
On 11/18/2017 05:04 AM, Stefan Wahren wrote: > As Sylvain Garrigues pointed out the BCM2835 RNG block has an > interrupt. Also in preparation for Florian's upcoming patch series > add this property to the binding. While we are at it fix the > indenting of the example. > > Link: https://github.com/raspberrypi/linux/issues/2195 > CC: Florian Fainelli <f.faine...@gmail.com> > Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com> Applied to devicetree/next, thanks! -- Florian
Re: [PATCH] hwrng: bcm2835: Handle deferred clock properly
On 02/12/2018 12:11 PM, Stefan Wahren wrote: > In case the probe of the clock is deferred, we would assume it is > optional. This is wrong, so defer the probe of this driver until > the clock is available. > > Fixes: 791af4f4907a ("hwrng: bcm2835 - Manage an optional clock") > Signed-off-by: Stefan Wahren <stefan.wah...@i2se.com> Acked-by: Florian Fainelli <f.faine...@gmail.com> Thanks Stephan! -- Florian
Re: [PATCH -next] hwrng: bcm2835 - Remove redundant dev_err call in bcm2835_rng_probe()
On 01/17/2018 03:40 AM, Wei Yongjun wrote: > There is a error message within devm_ioremap_resource > already, so remove the dev_err call to avoid redundant > error message. > > Signed-off-by: Wei Yongjun <weiyongj...@huawei.com> Acked-by: Florian Fainelli <f.faine...@gmail.com> -- Florian
Re: [v2,01/12] hwrng: bcm2835 - Obtain base register via resource
On 11/28/2017 10:30 PM, Herbert Xu wrote: > On Tue, Nov 07, 2017 at 04:44:38PM -0800, Florian Fainelli wrote: >> In preparation for consolidating bcm63xx-rng into bcm2835-rng, make sure >> that we obtain the base register via platform_get_resource() since we >> need to support the non-DT enabled MIPS-based BCM63xx DSL SoCs. >> >> Signed-off-by: Florian Fainelli <f.faine...@gmail.com> > > All applied. Thanks. Hu, okay, I actually had a v3 prepared that I was going to post addressing some of the comments. Should I send an incremental set of changes now? -- Florian
[PATCH v2 04/12] hwrng: bcm2835-rng: Implementation cleanup callback
We should be disabling the RNG in a hwrng::cleanup callback if we are not longer the system selected RNG, not wait until the device driver is removed. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 12 +--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 82000a637504..4d0356110b1b 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -83,6 +83,14 @@ static int bcm2835_rng_init(struct hwrng *rng) return 0; } +static void bcm2835_rng_cleanup(struct hwrng *rng) +{ + struct bcm2835_rng_priv *priv = to_rng_priv(rng); + + /* disable rng hardware */ + __raw_writel(0, priv->base + RNG_CTRL); +} + static const struct of_device_id bcm2835_rng_of_match[] = { { .compatible = "brcm,bcm2835-rng"}, { .compatible = "brcm,bcm-nsp-rng", .data = nsp_rng_init}, @@ -118,6 +126,7 @@ static int bcm2835_rng_probe(struct platform_device *pdev) priv->rng.name = "bcm2835-rng"; priv->rng.init = bcm2835_rng_init; priv->rng.read = bcm2835_rng_read; + priv->rng.cleanup = bcm2835_rng_cleanup; rng_id = of_match_node(bcm2835_rng_of_match, np); if (!rng_id) @@ -142,9 +151,6 @@ static int bcm2835_rng_remove(struct platform_device *pdev) { struct bcm2835_rng_priv *priv = platform_get_drvdata(pdev); - /* disable rng hardware */ - __raw_writel(0, priv->base + RNG_CTRL); - /* unregister driver */ hwrng_unregister(>rng); -- 2.9.3
[PATCH v2 01/12] hwrng: bcm2835-rng: Obtain base register via resource
In preparation for consolidating bcm63xx-rng into bcm2835-rng, make sure that we obtain the base register via platform_get_resource() since we need to support the non-DT enabled MIPS-based BCM63xx DSL SoCs. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 20 ++-- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 574211a49549..a818418a7e4c 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -81,21 +81,23 @@ static int bcm2835_rng_probe(struct platform_device *pdev) void (*rng_setup)(void __iomem *base); const struct of_device_id *rng_id; void __iomem *rng_base; + struct resource *r; int err; + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + /* map peripheral */ - rng_base = of_iomap(np, 0); - if (!rng_base) { + rng_base = devm_ioremap_resource(dev, r); + if (IS_ERR(rng_base)) { dev_err(dev, "failed to remap rng regs"); - return -ENODEV; + return PTR_ERR(rng_base); } bcm2835_rng_ops.priv = (unsigned long)rng_base; rng_id = of_match_node(bcm2835_rng_of_match, np); - if (!rng_id) { - iounmap(rng_base); + if (!rng_id) return -EINVAL; - } + /* Check for rng init function, execute it */ rng_setup = rng_id->data; if (rng_setup) @@ -107,10 +109,9 @@ static int bcm2835_rng_probe(struct platform_device *pdev) /* register driver */ err = hwrng_register(_rng_ops); - if (err) { + if (err) dev_err(dev, "hwrng registration failed\n"); - iounmap(rng_base); - } else + else dev_info(dev, "hwrng registered\n"); return err; @@ -125,7 +126,6 @@ static int bcm2835_rng_remove(struct platform_device *pdev) /* unregister driver */ hwrng_unregister(_rng_ops); - iounmap(rng_base); return 0; } -- 2.9.3
[PATCH v2 02/12] hwrng: bcm2835-rng: Define a driver private context
Instead of making hwrng::priv host the base register address, define a driver private context, make it per platform device instance and pass it down the different functions. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 55 ++-- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index a818418a7e4c..0d72147ab45b 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -29,6 +29,11 @@ #define RNG_INT_OFF0x1 +struct bcm2835_rng_priv { + struct hwrng rng; + void __iomem *base; +}; + static void __init nsp_rng_init(void __iomem *base) { u32 val; @@ -39,34 +44,34 @@ static void __init nsp_rng_init(void __iomem *base) writel(val, base + RNG_INT_MASK); } +static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) +{ + return container_of(rng, struct bcm2835_rng_priv, rng); +} + static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) { - void __iomem *rng_base = (void __iomem *)rng->priv; + struct bcm2835_rng_priv *priv = to_rng_priv(rng); u32 max_words = max / sizeof(u32); u32 num_words, count; - while ((__raw_readl(rng_base + RNG_STATUS) >> 24) == 0) { + while ((__raw_readl(priv->base + RNG_STATUS) >> 24) == 0) { if (!wait) return 0; cpu_relax(); } - num_words = readl(rng_base + RNG_STATUS) >> 24; + num_words = readl(priv->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); + ((u32 *)buf)[count] = readl(priv->base + RNG_DATA); return num_words * sizeof(u32); } -static struct hwrng bcm2835_rng_ops = { - .name = "bcm2835", - .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}, @@ -80,19 +85,27 @@ static int bcm2835_rng_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; void (*rng_setup)(void __iomem *base); const struct of_device_id *rng_id; - void __iomem *rng_base; + struct bcm2835_rng_priv *priv; struct resource *r; int err; + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + platform_set_drvdata(pdev, priv); + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); /* map peripheral */ - rng_base = devm_ioremap_resource(dev, r); - if (IS_ERR(rng_base)) { + priv->base = devm_ioremap_resource(dev, r); + if (IS_ERR(priv->base)) { dev_err(dev, "failed to remap rng regs"); - return PTR_ERR(rng_base); + return PTR_ERR(priv->base); } - bcm2835_rng_ops.priv = (unsigned long)rng_base; + + priv->rng.name = "bcm2835-rng"; + priv->rng.read = bcm2835_rng_read; rng_id = of_match_node(bcm2835_rng_of_match, np); if (!rng_id) @@ -101,14 +114,14 @@ static int bcm2835_rng_probe(struct platform_device *pdev) /* Check for rng init function, execute it */ rng_setup = rng_id->data; if (rng_setup) - rng_setup(rng_base); + rng_setup(priv->base); /* set warm-up count & enable */ - __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS); - __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL); + __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); + __raw_writel(RNG_RBGEN, priv->base + RNG_CTRL); /* register driver */ - err = hwrng_register(_rng_ops); + err = hwrng_register(>rng); if (err) dev_err(dev, "hwrng registration failed\n"); else @@ -119,13 +132,13 @@ static int bcm2835_rng_probe(struct platform_device *pdev) static int bcm2835_rng_remove(struct platform_device *pdev) { - void __iomem *rng_base = (void __iomem *)bcm2835_rng_ops.priv; + struct bcm2835_rng_priv *priv = platform_get_drvdata(pdev); /* disable rng hardware */ - __raw_writel(0, rng_base + RNG_CTRL); + __raw_writel(0, priv->base + RNG_CTRL); /* unregister driver */ - hwrng_unregister(_rng_ops); + hwrng_unregister(>rng); return 0; } -- 2.9.3
[PATCH v2 07/12] hwrng: bcm2835-rng: Manage an optional clock
One of the last steps before bcm63xx-rng can be eliminated is to manage a clock during hwrng::init and hwrng::cleanup, so fetch it in the probe function, and manage it during these two steps when valid. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 17 - 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index ed20e0b6b7ae..99b56fd5482c 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -15,6 +15,7 @@ #include #include #include +#include #define RNG_CTRL 0x0 #define RNG_STATUS 0x4 @@ -33,6 +34,7 @@ struct bcm2835_rng_priv { struct hwrng rng; void __iomem *base; bool mask_interrupts; + struct clk *clk; }; static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) @@ -66,8 +68,15 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, static int bcm2835_rng_init(struct hwrng *rng) { struct bcm2835_rng_priv *priv = to_rng_priv(rng); + int ret = 0; u32 val; + if (!IS_ERR(priv->clk)) { + ret = clk_prepare_enable(priv->clk); + if (ret) + return ret; + } + if (priv->mask_interrupts) { /* mask the interrupt */ val = readl(priv->base + RNG_INT_MASK); @@ -79,7 +88,7 @@ static int bcm2835_rng_init(struct hwrng *rng) __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); __raw_writel(RNG_RBGEN, priv->base + RNG_CTRL); - return 0; + return ret; } static void bcm2835_rng_cleanup(struct hwrng *rng) @@ -88,6 +97,9 @@ static void bcm2835_rng_cleanup(struct hwrng *rng) /* disable rng hardware */ __raw_writel(0, priv->base + RNG_CTRL); + + if (!IS_ERR(priv->clk)) + clk_disable_unprepare(priv->clk); } struct bcm2835_rng_of_data { @@ -130,6 +142,9 @@ static int bcm2835_rng_probe(struct platform_device *pdev) return PTR_ERR(priv->base); } + /* Clock is optional on most platforms */ + priv->clk = devm_clk_get(dev, NULL); + priv->rng.name = "bcm2835-rng"; priv->rng.init = bcm2835_rng_init; priv->rng.read = bcm2835_rng_read; -- 2.9.3
[PATCH v2 09/12] hwrng: bcm2835-rng: Add Broadcom MIPS I/O accessors
Broadcom MIPS HW is always strapped to match the system-wide endian such that all I/O access to this RNG block is done with the native CPU endian, account for that. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 13 +++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 3a607472687d..6dd8f48701b5 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -44,13 +44,22 @@ static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) static inline u32 rng_readl(struct bcm2835_rng_priv *priv, u32 offset) { - return readl(priv->base + offset); + /* MIPS chips strapped for BE will automagically configure the +* peripheral registers for CPU-native byte order. +*/ + if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) + return __raw_readl(priv->base + offset); + else + return readl(priv->base + offset); } static inline void rng_writel(struct bcm2835_rng_priv *priv, u32 val, u32 offset) { - writel(val, priv->base + offset); + if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) + __raw_writel(val, priv->base + offset); + else + writel(val, priv->base + offset); } static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, -- 2.9.3
[PATCH v2 08/12] hwrng: bcm2835-rng: Abstract I/O accessors
In preparation for allowing BCM63xx to use this driver, we abstract I/O accessors such that we can easily change those later on. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 27 +++ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 99b56fd5482c..3a607472687d 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -42,6 +42,17 @@ static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) return container_of(rng, struct bcm2835_rng_priv, rng); } +static inline u32 rng_readl(struct bcm2835_rng_priv *priv, u32 offset) +{ + return readl(priv->base + offset); +} + +static inline void rng_writel(struct bcm2835_rng_priv *priv, u32 val, + u32 offset) +{ + writel(val, priv->base + offset); +} + static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) { @@ -49,18 +60,18 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, u32 max_words = max / sizeof(u32); u32 num_words, count; - while ((__raw_readl(priv->base + RNG_STATUS) >> 24) == 0) { + while ((rng_readl(priv, RNG_STATUS) >> 24) == 0) { if (!wait) return 0; cpu_relax(); } - num_words = readl(priv->base + RNG_STATUS) >> 24; + num_words = rng_readl(priv, RNG_STATUS) >> 24; if (num_words > max_words) num_words = max_words; for (count = 0; count < num_words; count++) - ((u32 *)buf)[count] = readl(priv->base + RNG_DATA); + ((u32 *)buf)[count] = rng_readl(priv, RNG_DATA); return num_words * sizeof(u32); } @@ -79,14 +90,14 @@ static int bcm2835_rng_init(struct hwrng *rng) if (priv->mask_interrupts) { /* mask the interrupt */ - val = readl(priv->base + RNG_INT_MASK); + val = rng_readl(priv, RNG_INT_MASK); val |= RNG_INT_OFF; - writel(val, priv->base + RNG_INT_MASK); + rng_writel(priv, val, RNG_INT_MASK); } /* set warm-up count & enable */ - __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); - __raw_writel(RNG_RBGEN, priv->base + RNG_CTRL); + rng_writel(priv, RNG_WARMUP_COUNT, RNG_STATUS); + rng_writel(priv, RNG_RBGEN, RNG_CTRL); return ret; } @@ -96,7 +107,7 @@ static void bcm2835_rng_cleanup(struct hwrng *rng) struct bcm2835_rng_priv *priv = to_rng_priv(rng); /* disable rng hardware */ - __raw_writel(0, priv->base + RNG_CTRL); + rng_writel(priv, 0, RNG_CTRL); if (!IS_ERR(priv->clk)) clk_disable_unprepare(priv->clk); -- 2.9.3
[PATCH v2 06/12] hwrng: bcm2835-rng: 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.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 39 +--- 1 file 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 @@ struct bcm2835_rng_priv { struct hwrng rng; void __iomem *base; + bool mask_interrupts; }; -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 inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) { 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, static int bcm2835_rng_init(struct hwrng *rng) { struct bcm2835_rng_priv *priv = to_rng_priv(rng); + u32 val; + + if (priv->mask_interrupts) { + /* mask the interrupt */ + val = readl(priv->base + RNG_INT_MASK); + val |= RNG_INT_OFF; + writel(val, priv->base + RNG_INT_MASK); + } /* set warm-up count & enable */ __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); @@ -91,18 +90,26 @@ static void bcm2835_rng_cleanup(struct hwrng *rng) __raw_writel(0, priv->base + RNG_CTRL); } +struct bcm2835_rng_of_data { + bool mask_interrupts; +}; + +static const struct bcm2835_rng_of_data nsp_rng_of_data = { + .mask_interrupts = true, +}; + static const struct of_device_id bcm2835_rng_of_match[] = { { .compatible = "brcm,bcm2835-rng"}, - { .compatible = "brcm,bcm-nsp-rng", .data = nsp_rng_init}, - { .compatible = "brcm,bcm5301x-rng", .data = nsp_rng_init}, + { .compatible = "brcm,bcm-nsp-rng", .data = _rng_of_data }, + { .compatible = "brcm,bcm5301x-rng", .data = _rng_of_data }, {}, }; static int bcm2835_rng_probe(struct platform_device *pdev) { + const struct bcm2835_rng_of_data *of_data; struct device *dev = >dev; struct device_node *np = dev->of_node; - void (*rng_setup)(void __iomem *base); const struct of_device_id *rng_id; struct bcm2835_rng_priv *priv; struct resource *r; @@ -133,9 +140,9 @@ static int bcm2835_rng_probe(struct platform_device *pdev) return -EINVAL; /* Check for rng init function, execute it */ - rng_setup = rng_id->data; - if (rng_setup) - rng_setup(priv->base); + of_data = rng_id->data; + if (of_data) + priv->mask_interrupts = of_data->mask_interrupts; /* register driver */ err = devm_hwrng_register(dev, >rng); -- 2.9.3
[PATCH v2 05/12] hwrng: bcm2835-rng: Use device managed helpers
Now that we have moved the RNG disabling into a hwrng::cleanup callback, we can use the device managed registration operation and remove our remove callback since it won't do anything necessary. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 13 + 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 4d0356110b1b..67b9bd3be28d 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -138,7 +138,7 @@ static int bcm2835_rng_probe(struct platform_device *pdev) rng_setup(priv->base); /* register driver */ - err = hwrng_register(>rng); + err = devm_hwrng_register(dev, >rng); if (err) dev_err(dev, "hwrng registration failed\n"); else @@ -147,16 +147,6 @@ static int bcm2835_rng_probe(struct platform_device *pdev) return err; } -static int bcm2835_rng_remove(struct platform_device *pdev) -{ - struct bcm2835_rng_priv *priv = platform_get_drvdata(pdev); - - /* unregister driver */ - hwrng_unregister(>rng); - - return 0; -} - MODULE_DEVICE_TABLE(of, bcm2835_rng_of_match); static struct platform_driver bcm2835_rng_driver = { @@ -165,7 +155,6 @@ static struct platform_driver bcm2835_rng_driver = { .of_match_table = bcm2835_rng_of_match, }, .probe = bcm2835_rng_probe, - .remove = bcm2835_rng_remove, }; module_platform_driver(bcm2835_rng_driver); -- 2.9.3
[PATCH v2 11/12] hwrng: bcm2835-rng: Enable BCM2835 RNG to work on BCM63xx platforms
We have now incorporated all necessary functionality for the BCM63xx platforms to successfully migrate over bcm2835-rng, so add the final bits: Kconfig selection and proper platform_device device type matching to keep the same platform device name for registration to work. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/Kconfig | 7 --- drivers/char/hw_random/bcm2835-rng.c | 11 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index 95a031e9eced..d0689cc8c7fc 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig @@ -87,12 +87,13 @@ config HW_RANDOM_BCM63XX If unusure, say Y. config HW_RANDOM_BCM2835 - tristate "Broadcom BCM2835 Random Number Generator support" - depends on ARCH_BCM2835 || ARCH_BCM_NSP || ARCH_BCM_5301X + tristate "Broadcom BCM2835/BCM63xx Random Number Generator support" + depends on ARCH_BCM2835 || ARCH_BCM_NSP || ARCH_BCM_5301X || \ + ARCH_BCM_63XX || BCM63XX || BMIPS_GENERIC default HW_RANDOM ---help--- This driver provides kernel-side support for the Random Number - Generator hardware found on the Broadcom BCM2835 SoCs. + Generator hardware found on the Broadcom BCM2835 and BCM63xx SoCs. To compile this driver as a module, choose M here: the module will be called bcm2835-rng diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 6dd8f48701b5..25e56311a197 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -134,6 +134,7 @@ static const struct of_device_id bcm2835_rng_of_match[] = { { .compatible = "brcm,bcm2835-rng"}, { .compatible = "brcm,bcm-nsp-rng", .data = _rng_of_data }, { .compatible = "brcm,bcm5301x-rng", .data = _rng_of_data }, + { .compatible = "brcm,bcm6368-rng"}, {}, }; @@ -165,7 +166,7 @@ static int bcm2835_rng_probe(struct platform_device *pdev) /* Clock is optional on most platforms */ priv->clk = devm_clk_get(dev, NULL); - priv->rng.name = "bcm2835-rng"; + priv->rng.name = pdev->name; priv->rng.init = bcm2835_rng_init; priv->rng.read = bcm2835_rng_read; priv->rng.cleanup = bcm2835_rng_cleanup; @@ -191,12 +192,20 @@ static int bcm2835_rng_probe(struct platform_device *pdev) MODULE_DEVICE_TABLE(of, bcm2835_rng_of_match); +static struct platform_device_id bcm2835_rng_devtype[] = { + { .name = "bcm2835-rng" }, + { .name = "bcm63xx-rng" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(platform, bcm2835_rng_devtype); + static struct platform_driver bcm2835_rng_driver = { .driver = { .name = "bcm2835-rng", .of_match_table = bcm2835_rng_of_match, }, .probe = bcm2835_rng_probe, + .id_table = bcm2835_rng_devtype, }; module_platform_driver(bcm2835_rng_driver); -- 2.9.3
[PATCH v2 10/12] dt-bindings: rng: Incorporate brcm,bcm6368.txt binding
Since the same block is used on BCM2835 and BCM6368, merge the bindings and remove the brcm,bcm6368.txt binding document. Acked-by: Rob Herring <r...@kernel.org> Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- .../devicetree/bindings/rng/brcm,bcm2835.txt | 22 +++--- .../devicetree/bindings/rng/brcm,bcm6368.txt | 17 - 2 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 Documentation/devicetree/bindings/rng/brcm,bcm6368.txt diff --git a/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt b/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt index 26542690b578..627b29531a32 100644 --- a/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt +++ b/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt @@ -1,11 +1,19 @@ -BCM2835 Random number generator +BCM2835/6368 Random number generator Required properties: -- compatible : should be "brcm,bcm2835-rng" or "brcm,bcm-nsp-rng" or - "brcm,bcm5301x-rng" +- compatible : should be one of + "brcm,bcm2835-rng" + "brcm,bcm-nsp-rng" + "brcm,bcm5301x-rng" or + "brcm,bcm6368-rng" - reg : Specifies base physical address and size of the registers. +Optional properties: + +- clocks : phandle to clock-controller plus clock-specifier pair +- clock-names : "ipsec" as a clock name + Example: rng { @@ -17,3 +25,11 @@ rng@18033000 { compatible = "brcm,bcm-nsp-rng"; reg = <0x18033000 0x14>; }; + +random: rng@10004180 { + compatible = "brcm,bcm6368-rng"; + reg = <0x10004180 0x14>; + + clocks = <_clk 18>; + clock-names = "ipsec"; +}; diff --git a/Documentation/devicetree/bindings/rng/brcm,bcm6368.txt b/Documentation/devicetree/bindings/rng/brcm,bcm6368.txt deleted file mode 100644 index 4b5ac600bfbd.. --- a/Documentation/devicetree/bindings/rng/brcm,bcm6368.txt +++ /dev/null @@ -1,17 +0,0 @@ -BCM6368 Random number generator - -Required properties: - -- compatible : should be "brcm,bcm6368-rng" -- reg : Specifies base physical address and size of the registers -- clocks : phandle to clock-controller plus clock-specifier pair -- clock-names : "ipsec" as a clock name - -Example: - random: rng@10004180 { - compatible = "brcm,bcm6368-rng"; - reg = <0x10004180 0x14>; - - clocks = <_clk 18>; - clock-names = "ipsec"; - }; -- 2.9.3
[PATCH v2 12/12] hwrng: bcm63xx-rng: Remove since bcm2835-rng takes over
bcm2835-rng is now capable of supporting the BCM63xx hardware, so remove the driver which duplicates the same functionality. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/Kconfig | 13 --- drivers/char/hw_random/Makefile | 1 - drivers/char/hw_random/bcm63xx-rng.c | 154 --- 3 files changed, 168 deletions(-) delete mode 100644 drivers/char/hw_random/bcm63xx-rng.c diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index d0689cc8c7fc..2d3775b9c0c7 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig @@ -73,19 +73,6 @@ config HW_RANDOM_ATMEL If unsure, say Y. -config HW_RANDOM_BCM63XX - tristate "Broadcom BCM63xx Random Number Generator support" - depends on BCM63XX || BMIPS_GENERIC - default HW_RANDOM - ---help--- - This driver provides kernel-side support for the Random Number - Generator hardware found on the Broadcom BCM63xx SoCs. - - To compile this driver as a module, choose M here: the - module will be called bcm63xx-rng - - If unusure, say Y. - config HW_RANDOM_BCM2835 tristate "Broadcom BCM2835/BCM63xx Random Number Generator support" depends on ARCH_BCM2835 || ARCH_BCM_NSP || ARCH_BCM_5301X || \ diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile index f3728d008fff..e7146a84d44a 100644 --- a/drivers/char/hw_random/Makefile +++ b/drivers/char/hw_random/Makefile @@ -9,7 +9,6 @@ obj-$(CONFIG_HW_RANDOM_TIMERIOMEM) += timeriomem-rng.o obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o obj-$(CONFIG_HW_RANDOM_ATMEL) += atmel-rng.o -obj-$(CONFIG_HW_RANDOM_BCM63XX)+= bcm63xx-rng.o obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o obj-$(CONFIG_HW_RANDOM_N2RNG) += n2-rng.o n2-rng-y := n2-drv.o n2-asm.o diff --git a/drivers/char/hw_random/bcm63xx-rng.c b/drivers/char/hw_random/bcm63xx-rng.c deleted file mode 100644 index 5132c9cde50d.. --- a/drivers/char/hw_random/bcm63xx-rng.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Broadcom BCM63xx Random Number Generator support - * - * Copyright (C) 2011, Florian Fainelli <flor...@openwrt.org> - * Copyright (C) 2009, Broadcom Corporation - * - */ -#include -#include -#include -#include -#include -#include -#include -#include - -#define RNG_CTRL 0x00 -#define RNG_EN (1 << 0) - -#define RNG_STAT 0x04 -#define RNG_AVAIL_MASK (0xff00) - -#define RNG_DATA 0x08 -#define RNG_THRES 0x0c -#define RNG_MASK 0x10 - -struct bcm63xx_rng_priv { - struct hwrng rng; - struct clk *clk; - void __iomem *regs; -}; - -#define to_rng_priv(rng) container_of(rng, struct bcm63xx_rng_priv, rng) - -static int bcm63xx_rng_init(struct hwrng *rng) -{ - struct bcm63xx_rng_priv *priv = to_rng_priv(rng); - u32 val; - int error; - - error = clk_prepare_enable(priv->clk); - if (error) - return error; - - val = __raw_readl(priv->regs + RNG_CTRL); - val |= RNG_EN; - __raw_writel(val, priv->regs + RNG_CTRL); - - return 0; -} - -static void bcm63xx_rng_cleanup(struct hwrng *rng) -{ - struct bcm63xx_rng_priv *priv = to_rng_priv(rng); - u32 val; - - val = __raw_readl(priv->regs + RNG_CTRL); - val &= ~RNG_EN; - __raw_writel(val, priv->regs + RNG_CTRL); - - clk_disable_unprepare(priv->clk); -} - -static int bcm63xx_rng_data_present(struct hwrng *rng, int wait) -{ - struct bcm63xx_rng_priv *priv = to_rng_priv(rng); - - return __raw_readl(priv->regs + RNG_STAT) & RNG_AVAIL_MASK; -} - -static int bcm63xx_rng_data_read(struct hwrng *rng, u32 *data) -{ - struct bcm63xx_rng_priv *priv = to_rng_priv(rng); - - *data = __raw_readl(priv->regs + RNG_DATA); - - return 4; -} - -static int bcm63xx_rng_probe(struct platform_device *pdev) -{ - struct resource *r; - int ret; - struct bcm63xx_rng_priv *priv; - - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!r) { - dev_err(>dev, "no iomem resource\n"); - return -ENXIO; - } - - priv = devm_kzalloc(>dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - - priv->rng.name = pdev->name; - priv->rng.init = bcm63xx_rng_init; - priv->rng.cleanup = bcm63xx_rng_cleanup; - priv->rng.data_present = bcm63xx_rng_data_present; - priv->rng.data_read = bcm63xx_rng_data_read; - - priv->clk = devm_clk_get(>dev, "ipsec"); - if (IS_ERR(priv->clk)) { -
[PATCH v2 03/12] hwrng: bcm2835-rng: Move enabling to hwrng::init
We should be moving the enabling of the HWRNG into a hwrng::init callback since we can be disabled and enabled every time a different hwrng is selected in the system. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 16 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 0d72147ab45b..82000a637504 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -72,6 +72,17 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, return num_words * sizeof(u32); } +static int bcm2835_rng_init(struct hwrng *rng) +{ + struct bcm2835_rng_priv *priv = to_rng_priv(rng); + + /* set warm-up count & enable */ + __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); + __raw_writel(RNG_RBGEN, priv->base + RNG_CTRL); + + return 0; +} + static const struct of_device_id bcm2835_rng_of_match[] = { { .compatible = "brcm,bcm2835-rng"}, { .compatible = "brcm,bcm-nsp-rng", .data = nsp_rng_init}, @@ -105,6 +116,7 @@ static int bcm2835_rng_probe(struct platform_device *pdev) } priv->rng.name = "bcm2835-rng"; + priv->rng.init = bcm2835_rng_init; priv->rng.read = bcm2835_rng_read; rng_id = of_match_node(bcm2835_rng_of_match, np); @@ -116,10 +128,6 @@ static int bcm2835_rng_probe(struct platform_device *pdev) if (rng_setup) rng_setup(priv->base); - /* set warm-up count & enable */ - __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); - __raw_writel(RNG_RBGEN, priv->base + RNG_CTRL); - /* register driver */ err = hwrng_register(>rng); if (err) -- 2.9.3
[PATCH v2 00/12] bcm63xx-rng conversion to bcm2835-rng
Hi, As it usually happens when there is a fair amount of HW IP block re-use, competing implementations show up. In that case the BCM2835 HWRNG driver and the BCM63xx RNG driver have exactly the same register offsets and this is indeed the same piece of HW. This patch series first prepares the bcm2835-rng to be more future proof and support newer platforms, and the last part brings in what is necessary to migrate the bcm63xx-rng over to bcm2835-rng. Finally we delete bcm63xx-rng completely. The reason why BCM2835 RNG was kept over BCM63xx RNG is because the former deals correctly with a warm up count and the number of words available in the FIFO size. Thanks! Changes in v2: - rework the logic about how we manage the optional clock - use pdev->name for the rng.name member Florian Fainelli (12): hwrng: bcm2835-rng: Obtain base register via resource hwrng: bcm2835-rng: Define a driver private context hwrng: bcm2835-rng: Move enabling to hwrng::init hwrng: bcm2835-rng: Implementation cleanup callback hwrng: bcm2835-rng: Use device managed helpers hwrng: bcm2835-rng: Rework interrupt masking hwrng: bcm2835-rng: Manage an optional clock hwrng: bcm2835-rng: Abstract I/O accessors hwrng: bcm2835-rng: Add Broadcom MIPS I/O accessors dt-bindings: rng: Incorporate brcm,bcm6368.txt binding hwrng: bcm2835-rng: Enable BCM2835 RNG to work on BCM63xx platforms hwrng: bcm63xx-rng: Remove since bcm2835-rng takes over .../devicetree/bindings/rng/brcm,bcm2835.txt | 22 ++- .../devicetree/bindings/rng/brcm,bcm6368.txt | 17 --- drivers/char/hw_random/Kconfig | 20 +-- drivers/char/hw_random/Makefile| 1 - drivers/char/hw_random/bcm2835-rng.c | 167 +++-- drivers/char/hw_random/bcm63xx-rng.c | 154 --- 6 files changed, 140 insertions(+), 241 deletions(-) delete mode 100644 Documentation/devicetree/bindings/rng/brcm,bcm6368.txt delete mode 100644 drivers/char/hw_random/bcm63xx-rng.c -- 2.9.3
Re: [PATCH 11/12] hwrng: bcm2835-rng: Enable BCM2835 RNG to work on BCM63xx platforms
On 11/04/2017 11:27 AM, Stefan Wahren wrote: > Hi Florian > >> Florian Fainelli <f.faine...@gmail.com> hat am 2. November 2017 um 02:04 >> geschrieben: >> >> >> We have now incorporated all necessary functionality for the BCM63xx >> platforms to successfully migrate over bcm2835-rng, so add the final >> bits: Kconfig selection and proper platform_device device type matching >> to keep the same platform device name for registration to work. >> >> Signed-off-by: Florian Fainelli <f.faine...@gmail.com> >> --- >> drivers/char/hw_random/Kconfig | 7 --- >> drivers/char/hw_random/bcm2835-rng.c | 11 ++- >> 2 files changed, 14 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig >> index 95a031e9eced..d0689cc8c7fc 100644 >> --- a/drivers/char/hw_random/Kconfig >> +++ b/drivers/char/hw_random/Kconfig >> @@ -87,12 +87,13 @@ config HW_RANDOM_BCM63XX >>If unusure, say Y. >> >> config HW_RANDOM_BCM2835 >> -tristate "Broadcom BCM2835 Random Number Generator support" >> -depends on ARCH_BCM2835 || ARCH_BCM_NSP || ARCH_BCM_5301X >> +tristate "Broadcom BCM2835/BCM63xx Random Number Generator support" >> +depends on ARCH_BCM2835 || ARCH_BCM_NSP || ARCH_BCM_5301X || \ >> + ARCH_BCM_63XX || BCM63XX || BMIPS_GENERIC >> default HW_RANDOM >> ---help--- >>This driver provides kernel-side support for the Random Number >> - Generator hardware found on the Broadcom BCM2835 SoCs. >> + Generator hardware found on the Broadcom BCM2835 and BCM63xx SoCs. >> >>To compile this driver as a module, choose M here: the >>module will be called bcm2835-rng >> diff --git a/drivers/char/hw_random/bcm2835-rng.c >> b/drivers/char/hw_random/bcm2835-rng.c >> index 650e0033c273..d9ffe14f312b 100644 >> --- a/drivers/char/hw_random/bcm2835-rng.c >> +++ b/drivers/char/hw_random/bcm2835-rng.c >> @@ -131,6 +131,7 @@ static const struct of_device_id bcm2835_rng_of_match[] >> = { >> { .compatible = "brcm,bcm2835-rng"}, >> { .compatible = "brcm,bcm-nsp-rng", .data = _rng_of_data }, >> { .compatible = "brcm,bcm5301x-rng", .data = _rng_of_data }, >> +{ .compatible = "brcm,bcm6368-rng"}, >> {}, >> }; >> >> @@ -164,7 +165,7 @@ static int bcm2835_rng_probe(struct platform_device >> *pdev) >> if (IS_ERR(priv->clk)) >> priv->clk = NULL; >> >> -priv->rng.name = "bcm2835-rng"; >> +priv->rng.name = pdev->id_entry->name; > > this change breaks registration on bcm2835, because the name is NULL. OH right, I will fix that in v2, I am assuming that if you did something like this, things still work correctly for you on 2835: if (!priv->id_entry->name) priv->rng.name = "bcm2835-rng"; else priv->rng.name = priv->id_entry->name; ? > > Regards > Stefan > >> priv->rng.init = bcm2835_rng_init; >> priv->rng.read = bcm2835_rng_read; >> priv->rng.cleanup = bcm2835_rng_cleanup; >> @@ -190,12 +191,20 @@ static int bcm2835_rng_probe(struct platform_device >> *pdev) >> >> MODULE_DEVICE_TABLE(of, bcm2835_rng_of_match); >> >> +static struct platform_device_id bcm2835_rng_devtype[] = { >> +{ .name = "bcm2835-rng" }, >> +{ .name = "bcm63xx-rng" }, >> +{ /* sentinel */ } >> +}; >> +MODULE_DEVICE_TABLE(platform, bcm2835_rng_devtype); >> + >> static struct platform_driver bcm2835_rng_driver = { >> .driver = { >> .name = "bcm2835-rng", >> .of_match_table = bcm2835_rng_of_match, >> }, >> .probe = bcm2835_rng_probe, >> +.id_table = bcm2835_rng_devtype, >> }; >> module_platform_driver(bcm2835_rng_driver); >> >> -- >> 2.9.3 >> >> >> ___ >> linux-arm-kernel mailing list >> linux-arm-ker...@lists.infradead.org >> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel -- Florian
Re: [PATCH 07/12] hwrng: bcm2835-rng: Manage an optional clock
Hi Stefan, On 11/04/2017 06:50 AM, Stefan Wahren wrote: > Hi Florian, > >> Florian Fainelli <f.faine...@gmail.com> hat am 2. November 2017 um 02:04 >> geschrieben: >> >> >> One of the last steps before bcm63xx-rng can be eliminated is to manage >> a clock during hwrng::init and hwrng::cleanup, so fetch it in the probe >> function, and manage it during these two steps when valid. >> >> Signed-off-by: Florian Fainelli <f.faine...@gmail.com> >> --- >> drivers/char/hw_random/bcm2835-rng.c | 14 ++ >> 1 file changed, 14 insertions(+) >> >> diff --git a/drivers/char/hw_random/bcm2835-rng.c >> b/drivers/char/hw_random/bcm2835-rng.c >> index ed20e0b6b7ae..35928efb52e7 100644 >> --- a/drivers/char/hw_random/bcm2835-rng.c >> +++ b/drivers/char/hw_random/bcm2835-rng.c >> @@ -15,6 +15,7 @@ >> #include >> #include >> #include >> +#include >> >> #define RNG_CTRL0x0 >> #define RNG_STATUS 0x4 >> @@ -33,6 +34,7 @@ struct bcm2835_rng_priv { >> struct hwrng rng; >> void __iomem *base; >> bool mask_interrupts; >> +struct clk *clk; >> }; >> >> static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) >> @@ -67,6 +69,11 @@ static int bcm2835_rng_init(struct hwrng *rng) >> { >> struct bcm2835_rng_priv *priv = to_rng_priv(rng); >> u32 val; >> +int ret; >> + >> +ret = clk_prepare_enable(priv->clk); >> +if (ret) >> +return ret; >> >> if (priv->mask_interrupts) { >> /* mask the interrupt */ >> @@ -88,6 +95,8 @@ static void bcm2835_rng_cleanup(struct hwrng *rng) >> >> /* disable rng hardware */ >> __raw_writel(0, priv->base + RNG_CTRL); >> + >> +clk_disable_unprepare(priv->clk); >> } >> >> struct bcm2835_rng_of_data { >> @@ -130,6 +139,11 @@ static int bcm2835_rng_probe(struct platform_device >> *pdev) >> return PTR_ERR(priv->base); >> } >> >> +/* Clock is optional on most platforms */ >> +priv->clk = devm_clk_get(dev, NULL); >> +if (IS_ERR(priv->clk)) >> +priv->clk = NULL; > > at least in case of EPROBE_DEFERED this isn't the expected behavior. Maybe we > should better trigger on non-existing clock? Good point, so more like: if (IS_ERR(priv->clk) && PTR_ERR(priv->clk) == -ENODEV)? -- Florian
Re: [PATCH 08/12] hwrng: bcm2835-rng: Abstract I/O accessors
On 11/03/2017 01:19 PM, Eric Anholt wrote: > Florian Fainelli <f.faine...@gmail.com> writes: > >> In preparation for allowing BCM63xx to use this driver, we abstract I/O >> accessors such that we can easily change those later on. >> >> Signed-off-by: Florian Fainelli <f.faine...@gmail.com> >> --- >> drivers/char/hw_random/bcm2835-rng.c | 27 +++ >> 1 file changed, 19 insertions(+), 8 deletions(-) >> >> diff --git a/drivers/char/hw_random/bcm2835-rng.c >> b/drivers/char/hw_random/bcm2835-rng.c >> index 35928efb52e7..500275d55044 100644 >> --- a/drivers/char/hw_random/bcm2835-rng.c >> +++ b/drivers/char/hw_random/bcm2835-rng.c >> @@ -42,6 +42,17 @@ static inline struct bcm2835_rng_priv *to_rng_priv(struct >> hwrng *rng) >> return container_of(rng, struct bcm2835_rng_priv, rng); >> } >> >> +static inline u32 rng_readl(struct bcm2835_rng_priv *priv, u32 offset) >> +{ >> +return readl(priv->base + offset); >> +} >> + >> +static inline void rng_writel(struct bcm2835_rng_priv *priv, u32 val, >> + u32 offset) >> +{ >> +writel(val, priv->base + offset); >> +} >> + >> static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, >> bool wait) >> { >> @@ -49,18 +60,18 @@ static int bcm2835_rng_read(struct hwrng *rng, void >> *buf, size_t max, >> u32 max_words = max / sizeof(u32); >> u32 num_words, count; >> >> -while ((__raw_readl(priv->base + RNG_STATUS) >> 24) == 0) { >> +while ((rng_readl(priv, RNG_STATUS) >> 24) == 0) { >> if (!wait) >> return 0; >> cpu_relax(); >> } > > What was the difference between the __raw_readl and readl that's now > being done in the new call? Is it important? readl() on ARM contains a memory barrier, which has therefore stronger ordering guarantees than __raw_readl() which does not. In practice I don't think this makes a whole lot of difference in that the above loop does not even have a barrier outside of it to try to have any sort of ordering guarantee so it seems to me like this may be an oversight. I took the liberty to use the stronger operation here because it seems to me like this is what is desired, or at least won't cause functional problems, and because I am not intimately familiar with the 2835 busing architecture. I know for a thing that the Broadcom STB and DSL busses (named GISB and UBUS respectively) do not require such barriers since they do not re-order transactions and are non-posted. > >> /* set warm-up count & enable */ >> -__raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); >> -__raw_writel(RNG_RBGEN, priv->base + RNG_CTRL); >> +rng_writel(priv, RNG_WARMUP_COUNT, RNG_STATUS); >> +rng_writel(priv, RNG_RBGEN, RNG_CTRL); > > Similar question. And here we definitively are not in a hot-path so the more "ordered" variant is acceptable it seems. -- Florian
Re: [PATCH 12/12] hwrng: bcm63xx-rng: Remove since bcm2835-rng takes over
On 11/03/2017 01:18 PM, Eric Anholt wrote: > Florian Fainelli <f.faine...@gmail.com> writes: > >> bcm2835-rng is now capable of supporting the BCM63xx hardware, so remove >> the driver which duplicates the same functionality. >> >> Signed-off-by: Florian Fainelli <f.faine...@gmail.com> >> --- >> drivers/char/hw_random/Kconfig | 13 --- >> drivers/char/hw_random/Makefile | 1 - >> drivers/char/hw_random/bcm63xx-rng.c | 154 >> --- >> 3 files changed, 168 deletions(-) >> delete mode 100644 drivers/char/hw_random/bcm63xx-rng.c >> > >> diff --git a/drivers/char/hw_random/bcm63xx-rng.c >> b/drivers/char/hw_random/bcm63xx-rng.c >> deleted file mode 100644 >> index 5132c9cde50d.. >> --- a/drivers/char/hw_random/bcm63xx-rng.c >> +++ /dev/null > >> -static int bcm63xx_rng_data_present(struct hwrng *rng, int wait) >> -{ >> -struct bcm63xx_rng_priv *priv = to_rng_priv(rng); >> - >> -return __raw_readl(priv->regs + RNG_STAT) & RNG_AVAIL_MASK; >> -} > > It looks like this method isn't in the 2835 implementation. Should it > get ported over? The read method already has something similar in that it busy loops until it gets some random words available, which is why I did not port it over. -- Florian
Re: [PATCH 00/12] bcm63xx-rng conversion to bcm2835-rng
Hi Stefan, On 11/02/2017 12:01 PM, Stefan Wahren wrote: > Hi Florian, > >> Florian Fainelli <f.faine...@gmail.com> hat am 2. November 2017 um 02:03 >> geschrieben: >> >> >> Hi, >> >> As it usually happens when there is a fair amount of HW IP block re-use, >> competing implementations show up. In that case the BCM2835 HWRNG driver and >> the BCM63xx RNG driver have exactly the same register offsets and this is >> indeed the same piece of HW. >> >> This patch series first prepares the bcm2835-rng to be more future proof and >> support newer platforms, and the last part brings in what is necessary to >> migrate the bcm63xx-rng over to bcm2835-rng. Finally we delete bcm63xx-rng >> completely. >> >> The reason why BCM2835 RNG was kept over BCM63xx RNG is because the former >> deals correctly with a warm up count and the number of words available in the >> FIFO size. > > are these the same patches as in this branch [1]? > > https://github.com/ffainelli/linux/commits/rng-consolidation Yes, this branch contains these 12 patches. -- Florian
[PATCH 02/12] hwrng: bcm2835-rng: Define a driver private context
Instead of making hwrng::priv host the base register address, define a driver private context, make it per platform device instance and pass it down the different functions. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 55 ++-- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index a818418a7e4c..0d72147ab45b 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -29,6 +29,11 @@ #define RNG_INT_OFF0x1 +struct bcm2835_rng_priv { + struct hwrng rng; + void __iomem *base; +}; + static void __init nsp_rng_init(void __iomem *base) { u32 val; @@ -39,34 +44,34 @@ static void __init nsp_rng_init(void __iomem *base) writel(val, base + RNG_INT_MASK); } +static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) +{ + return container_of(rng, struct bcm2835_rng_priv, rng); +} + static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) { - void __iomem *rng_base = (void __iomem *)rng->priv; + struct bcm2835_rng_priv *priv = to_rng_priv(rng); u32 max_words = max / sizeof(u32); u32 num_words, count; - while ((__raw_readl(rng_base + RNG_STATUS) >> 24) == 0) { + while ((__raw_readl(priv->base + RNG_STATUS) >> 24) == 0) { if (!wait) return 0; cpu_relax(); } - num_words = readl(rng_base + RNG_STATUS) >> 24; + num_words = readl(priv->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); + ((u32 *)buf)[count] = readl(priv->base + RNG_DATA); return num_words * sizeof(u32); } -static struct hwrng bcm2835_rng_ops = { - .name = "bcm2835", - .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}, @@ -80,19 +85,27 @@ static int bcm2835_rng_probe(struct platform_device *pdev) struct device_node *np = dev->of_node; void (*rng_setup)(void __iomem *base); const struct of_device_id *rng_id; - void __iomem *rng_base; + struct bcm2835_rng_priv *priv; struct resource *r; int err; + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + platform_set_drvdata(pdev, priv); + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); /* map peripheral */ - rng_base = devm_ioremap_resource(dev, r); - if (IS_ERR(rng_base)) { + priv->base = devm_ioremap_resource(dev, r); + if (IS_ERR(priv->base)) { dev_err(dev, "failed to remap rng regs"); - return PTR_ERR(rng_base); + return PTR_ERR(priv->base); } - bcm2835_rng_ops.priv = (unsigned long)rng_base; + + priv->rng.name = "bcm2835-rng"; + priv->rng.read = bcm2835_rng_read; rng_id = of_match_node(bcm2835_rng_of_match, np); if (!rng_id) @@ -101,14 +114,14 @@ static int bcm2835_rng_probe(struct platform_device *pdev) /* Check for rng init function, execute it */ rng_setup = rng_id->data; if (rng_setup) - rng_setup(rng_base); + rng_setup(priv->base); /* set warm-up count & enable */ - __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS); - __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL); + __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); + __raw_writel(RNG_RBGEN, priv->base + RNG_CTRL); /* register driver */ - err = hwrng_register(_rng_ops); + err = hwrng_register(>rng); if (err) dev_err(dev, "hwrng registration failed\n"); else @@ -119,13 +132,13 @@ static int bcm2835_rng_probe(struct platform_device *pdev) static int bcm2835_rng_remove(struct platform_device *pdev) { - void __iomem *rng_base = (void __iomem *)bcm2835_rng_ops.priv; + struct bcm2835_rng_priv *priv = platform_get_drvdata(pdev); /* disable rng hardware */ - __raw_writel(0, rng_base + RNG_CTRL); + __raw_writel(0, priv->base + RNG_CTRL); /* unregister driver */ - hwrng_unregister(_rng_ops); + hwrng_unregister(>rng); return 0; } -- 2.9.3
[PATCH 00/12] bcm63xx-rng conversion to bcm2835-rng
Hi, As it usually happens when there is a fair amount of HW IP block re-use, competing implementations show up. In that case the BCM2835 HWRNG driver and the BCM63xx RNG driver have exactly the same register offsets and this is indeed the same piece of HW. This patch series first prepares the bcm2835-rng to be more future proof and support newer platforms, and the last part brings in what is necessary to migrate the bcm63xx-rng over to bcm2835-rng. Finally we delete bcm63xx-rng completely. The reason why BCM2835 RNG was kept over BCM63xx RNG is because the former deals correctly with a warm up count and the number of words available in the FIFO size. Thanks! Florian Fainelli (12): hwrng: bcm2835-rng: Obtain base register via resource hwrng: bcm2835-rng: Define a driver private context hwrng: bcm2835-rng: Move enabling to hwrng::init hwrng: bcm2835-rng: Implementation cleanup callback hwrng: bcm2835-rng: Use device managed helpers hwrng: bcm2835-rng: Rework interrupt masking hwrng: bcm2835-rng: Manage an optional clock hwrng: bcm2835-rng: Abstract I/O accessors hwrng: bcm2835-rng: Add Broadcom MIPS I/O accessors dt-bindings: rng: Incorporate brcm,bcm6368.txt binding hwrng: bcm2835-rng: Enable BCM2835 RNG to work on BCM63xx platforms hwrng: bcm63xx-rng: Remove since bcm2835-rng takes over .../devicetree/bindings/rng/brcm,bcm2835.txt | 22 ++- .../devicetree/bindings/rng/brcm,bcm6368.txt | 17 --- drivers/char/hw_random/Kconfig | 20 +-- drivers/char/hw_random/Makefile| 1 - drivers/char/hw_random/bcm2835-rng.c | 166 ++--- drivers/char/hw_random/bcm63xx-rng.c | 154 --- 6 files changed, 139 insertions(+), 241 deletions(-) delete mode 100644 Documentation/devicetree/bindings/rng/brcm,bcm6368.txt delete mode 100644 drivers/char/hw_random/bcm63xx-rng.c -- 2.9.3
[PATCH 05/12] hwrng: bcm2835-rng: Use device managed helpers
Now that we have moved the RNG disabling into a hwrng::cleanup callback, we can use the device managed registration operation and remove our remove callback since it won't do anything necessary. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 13 + 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 4d0356110b1b..67b9bd3be28d 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -138,7 +138,7 @@ static int bcm2835_rng_probe(struct platform_device *pdev) rng_setup(priv->base); /* register driver */ - err = hwrng_register(>rng); + err = devm_hwrng_register(dev, >rng); if (err) dev_err(dev, "hwrng registration failed\n"); else @@ -147,16 +147,6 @@ static int bcm2835_rng_probe(struct platform_device *pdev) return err; } -static int bcm2835_rng_remove(struct platform_device *pdev) -{ - struct bcm2835_rng_priv *priv = platform_get_drvdata(pdev); - - /* unregister driver */ - hwrng_unregister(>rng); - - return 0; -} - MODULE_DEVICE_TABLE(of, bcm2835_rng_of_match); static struct platform_driver bcm2835_rng_driver = { @@ -165,7 +155,6 @@ static struct platform_driver bcm2835_rng_driver = { .of_match_table = bcm2835_rng_of_match, }, .probe = bcm2835_rng_probe, - .remove = bcm2835_rng_remove, }; module_platform_driver(bcm2835_rng_driver); -- 2.9.3
[PATCH 01/12] hwrng: bcm2835-rng: Obtain base register via resource
In preparation for consolidating bcm63xx-rng into bcm2835-rng, make sure that we obtain the base register via platform_get_resource() since we need to support the non-DT enabled MIPS-based BCM63xx DSL SoCs. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 20 ++-- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 574211a49549..a818418a7e4c 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -81,21 +81,23 @@ static int bcm2835_rng_probe(struct platform_device *pdev) void (*rng_setup)(void __iomem *base); const struct of_device_id *rng_id; void __iomem *rng_base; + struct resource *r; int err; + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); + /* map peripheral */ - rng_base = of_iomap(np, 0); - if (!rng_base) { + rng_base = devm_ioremap_resource(dev, r); + if (IS_ERR(rng_base)) { dev_err(dev, "failed to remap rng regs"); - return -ENODEV; + return PTR_ERR(rng_base); } bcm2835_rng_ops.priv = (unsigned long)rng_base; rng_id = of_match_node(bcm2835_rng_of_match, np); - if (!rng_id) { - iounmap(rng_base); + if (!rng_id) return -EINVAL; - } + /* Check for rng init function, execute it */ rng_setup = rng_id->data; if (rng_setup) @@ -107,10 +109,9 @@ static int bcm2835_rng_probe(struct platform_device *pdev) /* register driver */ err = hwrng_register(_rng_ops); - if (err) { + if (err) dev_err(dev, "hwrng registration failed\n"); - iounmap(rng_base); - } else + else dev_info(dev, "hwrng registered\n"); return err; @@ -125,7 +126,6 @@ static int bcm2835_rng_remove(struct platform_device *pdev) /* unregister driver */ hwrng_unregister(_rng_ops); - iounmap(rng_base); return 0; } -- 2.9.3
[PATCH 03/12] hwrng: bcm2835-rng: Move enabling to hwrng::init
We should be moving the enabling of the HWRNG into a hwrng::init callback since we can be disabled and enabled every time a different hwrng is selected in the system. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 16 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 0d72147ab45b..82000a637504 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -72,6 +72,17 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, return num_words * sizeof(u32); } +static int bcm2835_rng_init(struct hwrng *rng) +{ + struct bcm2835_rng_priv *priv = to_rng_priv(rng); + + /* set warm-up count & enable */ + __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); + __raw_writel(RNG_RBGEN, priv->base + RNG_CTRL); + + return 0; +} + static const struct of_device_id bcm2835_rng_of_match[] = { { .compatible = "brcm,bcm2835-rng"}, { .compatible = "brcm,bcm-nsp-rng", .data = nsp_rng_init}, @@ -105,6 +116,7 @@ static int bcm2835_rng_probe(struct platform_device *pdev) } priv->rng.name = "bcm2835-rng"; + priv->rng.init = bcm2835_rng_init; priv->rng.read = bcm2835_rng_read; rng_id = of_match_node(bcm2835_rng_of_match, np); @@ -116,10 +128,6 @@ static int bcm2835_rng_probe(struct platform_device *pdev) if (rng_setup) rng_setup(priv->base); - /* set warm-up count & enable */ - __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); - __raw_writel(RNG_RBGEN, priv->base + RNG_CTRL); - /* register driver */ err = hwrng_register(>rng); if (err) -- 2.9.3
[PATCH 04/12] hwrng: bcm2835-rng: Implementation cleanup callback
We should be disabling the RNG in a hwrng::cleanup callback if we are not longer the system selected RNG, not wait until the device driver is removed. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 12 +--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 82000a637504..4d0356110b1b 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -83,6 +83,14 @@ static int bcm2835_rng_init(struct hwrng *rng) return 0; } +static void bcm2835_rng_cleanup(struct hwrng *rng) +{ + struct bcm2835_rng_priv *priv = to_rng_priv(rng); + + /* disable rng hardware */ + __raw_writel(0, priv->base + RNG_CTRL); +} + static const struct of_device_id bcm2835_rng_of_match[] = { { .compatible = "brcm,bcm2835-rng"}, { .compatible = "brcm,bcm-nsp-rng", .data = nsp_rng_init}, @@ -118,6 +126,7 @@ static int bcm2835_rng_probe(struct platform_device *pdev) priv->rng.name = "bcm2835-rng"; priv->rng.init = bcm2835_rng_init; priv->rng.read = bcm2835_rng_read; + priv->rng.cleanup = bcm2835_rng_cleanup; rng_id = of_match_node(bcm2835_rng_of_match, np); if (!rng_id) @@ -142,9 +151,6 @@ static int bcm2835_rng_remove(struct platform_device *pdev) { struct bcm2835_rng_priv *priv = platform_get_drvdata(pdev); - /* disable rng hardware */ - __raw_writel(0, priv->base + RNG_CTRL); - /* unregister driver */ hwrng_unregister(>rng); -- 2.9.3
[PATCH 07/12] hwrng: bcm2835-rng: Manage an optional clock
One of the last steps before bcm63xx-rng can be eliminated is to manage a clock during hwrng::init and hwrng::cleanup, so fetch it in the probe function, and manage it during these two steps when valid. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index ed20e0b6b7ae..35928efb52e7 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -15,6 +15,7 @@ #include #include #include +#include #define RNG_CTRL 0x0 #define RNG_STATUS 0x4 @@ -33,6 +34,7 @@ struct bcm2835_rng_priv { struct hwrng rng; void __iomem *base; bool mask_interrupts; + struct clk *clk; }; static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) @@ -67,6 +69,11 @@ static int bcm2835_rng_init(struct hwrng *rng) { struct bcm2835_rng_priv *priv = to_rng_priv(rng); u32 val; + int ret; + + ret = clk_prepare_enable(priv->clk); + if (ret) + return ret; if (priv->mask_interrupts) { /* mask the interrupt */ @@ -88,6 +95,8 @@ static void bcm2835_rng_cleanup(struct hwrng *rng) /* disable rng hardware */ __raw_writel(0, priv->base + RNG_CTRL); + + clk_disable_unprepare(priv->clk); } struct bcm2835_rng_of_data { @@ -130,6 +139,11 @@ static int bcm2835_rng_probe(struct platform_device *pdev) return PTR_ERR(priv->base); } + /* Clock is optional on most platforms */ + priv->clk = devm_clk_get(dev, NULL); + if (IS_ERR(priv->clk)) + priv->clk = NULL; + priv->rng.name = "bcm2835-rng"; priv->rng.init = bcm2835_rng_init; priv->rng.read = bcm2835_rng_read; -- 2.9.3
[PATCH 06/12] hwrng: bcm2835-rng: 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.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 39 +--- 1 file 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 @@ struct bcm2835_rng_priv { struct hwrng rng; void __iomem *base; + bool mask_interrupts; }; -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 inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) { 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, static int bcm2835_rng_init(struct hwrng *rng) { struct bcm2835_rng_priv *priv = to_rng_priv(rng); + u32 val; + + if (priv->mask_interrupts) { + /* mask the interrupt */ + val = readl(priv->base + RNG_INT_MASK); + val |= RNG_INT_OFF; + writel(val, priv->base + RNG_INT_MASK); + } /* set warm-up count & enable */ __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); @@ -91,18 +90,26 @@ static void bcm2835_rng_cleanup(struct hwrng *rng) __raw_writel(0, priv->base + RNG_CTRL); } +struct bcm2835_rng_of_data { + bool mask_interrupts; +}; + +static const struct bcm2835_rng_of_data nsp_rng_of_data = { + .mask_interrupts = true, +}; + static const struct of_device_id bcm2835_rng_of_match[] = { { .compatible = "brcm,bcm2835-rng"}, - { .compatible = "brcm,bcm-nsp-rng", .data = nsp_rng_init}, - { .compatible = "brcm,bcm5301x-rng", .data = nsp_rng_init}, + { .compatible = "brcm,bcm-nsp-rng", .data = _rng_of_data }, + { .compatible = "brcm,bcm5301x-rng", .data = _rng_of_data }, {}, }; static int bcm2835_rng_probe(struct platform_device *pdev) { + const struct bcm2835_rng_of_data *of_data; struct device *dev = >dev; struct device_node *np = dev->of_node; - void (*rng_setup)(void __iomem *base); const struct of_device_id *rng_id; struct bcm2835_rng_priv *priv; struct resource *r; @@ -133,9 +140,9 @@ static int bcm2835_rng_probe(struct platform_device *pdev) return -EINVAL; /* Check for rng init function, execute it */ - rng_setup = rng_id->data; - if (rng_setup) - rng_setup(priv->base); + of_data = rng_id->data; + if (of_data) + priv->mask_interrupts = of_data->mask_interrupts; /* register driver */ err = devm_hwrng_register(dev, >rng); -- 2.9.3
[PATCH 09/12] hwrng: bcm2835-rng: Add Broadcom MIPS I/O accessors
Broadcom MIPS HW is always strapped to match the system-wide endian such that all I/O access to this RNG block is done with the native CPU endian, account for that. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 13 +++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 500275d55044..650e0033c273 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -44,13 +44,22 @@ static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) static inline u32 rng_readl(struct bcm2835_rng_priv *priv, u32 offset) { - return readl(priv->base + offset); + /* MIPS chips strapped for BE will automagically configure the +* peripheral registers for CPU-native byte order. +*/ + if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) + return __raw_readl(priv->base + offset); + else + return readl(priv->base + offset); } static inline void rng_writel(struct bcm2835_rng_priv *priv, u32 val, u32 offset) { - writel(val, priv->base + offset); + if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(CONFIG_CPU_BIG_ENDIAN)) + __raw_writel(val, priv->base + offset); + else + writel(val, priv->base + offset); } static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, -- 2.9.3
[PATCH 10/12] dt-bindings: rng: Incorporate brcm,bcm6368.txt binding
Since the same block is used on BCM2835 and BCM6368, merge the bindings and remove the brcm,bcm6368.txt binding document. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- .../devicetree/bindings/rng/brcm,bcm2835.txt | 22 +++--- .../devicetree/bindings/rng/brcm,bcm6368.txt | 17 - 2 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 Documentation/devicetree/bindings/rng/brcm,bcm6368.txt diff --git a/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt b/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt index 26542690b578..627b29531a32 100644 --- a/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt +++ b/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt @@ -1,11 +1,19 @@ -BCM2835 Random number generator +BCM2835/6368 Random number generator Required properties: -- compatible : should be "brcm,bcm2835-rng" or "brcm,bcm-nsp-rng" or - "brcm,bcm5301x-rng" +- compatible : should be one of + "brcm,bcm2835-rng" + "brcm,bcm-nsp-rng" + "brcm,bcm5301x-rng" or + "brcm,bcm6368-rng" - reg : Specifies base physical address and size of the registers. +Optional properties: + +- clocks : phandle to clock-controller plus clock-specifier pair +- clock-names : "ipsec" as a clock name + Example: rng { @@ -17,3 +25,11 @@ rng@18033000 { compatible = "brcm,bcm-nsp-rng"; reg = <0x18033000 0x14>; }; + +random: rng@10004180 { + compatible = "brcm,bcm6368-rng"; + reg = <0x10004180 0x14>; + + clocks = <_clk 18>; + clock-names = "ipsec"; +}; diff --git a/Documentation/devicetree/bindings/rng/brcm,bcm6368.txt b/Documentation/devicetree/bindings/rng/brcm,bcm6368.txt deleted file mode 100644 index 4b5ac600bfbd.. --- a/Documentation/devicetree/bindings/rng/brcm,bcm6368.txt +++ /dev/null @@ -1,17 +0,0 @@ -BCM6368 Random number generator - -Required properties: - -- compatible : should be "brcm,bcm6368-rng" -- reg : Specifies base physical address and size of the registers -- clocks : phandle to clock-controller plus clock-specifier pair -- clock-names : "ipsec" as a clock name - -Example: - random: rng@10004180 { - compatible = "brcm,bcm6368-rng"; - reg = <0x10004180 0x14>; - - clocks = <_clk 18>; - clock-names = "ipsec"; - }; -- 2.9.3
[PATCH 11/12] hwrng: bcm2835-rng: Enable BCM2835 RNG to work on BCM63xx platforms
We have now incorporated all necessary functionality for the BCM63xx platforms to successfully migrate over bcm2835-rng, so add the final bits: Kconfig selection and proper platform_device device type matching to keep the same platform device name for registration to work. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/Kconfig | 7 --- drivers/char/hw_random/bcm2835-rng.c | 11 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index 95a031e9eced..d0689cc8c7fc 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig @@ -87,12 +87,13 @@ config HW_RANDOM_BCM63XX If unusure, say Y. config HW_RANDOM_BCM2835 - tristate "Broadcom BCM2835 Random Number Generator support" - depends on ARCH_BCM2835 || ARCH_BCM_NSP || ARCH_BCM_5301X + tristate "Broadcom BCM2835/BCM63xx Random Number Generator support" + depends on ARCH_BCM2835 || ARCH_BCM_NSP || ARCH_BCM_5301X || \ + ARCH_BCM_63XX || BCM63XX || BMIPS_GENERIC default HW_RANDOM ---help--- This driver provides kernel-side support for the Random Number - Generator hardware found on the Broadcom BCM2835 SoCs. + Generator hardware found on the Broadcom BCM2835 and BCM63xx SoCs. To compile this driver as a module, choose M here: the module will be called bcm2835-rng diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 650e0033c273..d9ffe14f312b 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -131,6 +131,7 @@ static const struct of_device_id bcm2835_rng_of_match[] = { { .compatible = "brcm,bcm2835-rng"}, { .compatible = "brcm,bcm-nsp-rng", .data = _rng_of_data }, { .compatible = "brcm,bcm5301x-rng", .data = _rng_of_data }, + { .compatible = "brcm,bcm6368-rng"}, {}, }; @@ -164,7 +165,7 @@ static int bcm2835_rng_probe(struct platform_device *pdev) if (IS_ERR(priv->clk)) priv->clk = NULL; - priv->rng.name = "bcm2835-rng"; + priv->rng.name = pdev->id_entry->name; priv->rng.init = bcm2835_rng_init; priv->rng.read = bcm2835_rng_read; priv->rng.cleanup = bcm2835_rng_cleanup; @@ -190,12 +191,20 @@ static int bcm2835_rng_probe(struct platform_device *pdev) MODULE_DEVICE_TABLE(of, bcm2835_rng_of_match); +static struct platform_device_id bcm2835_rng_devtype[] = { + { .name = "bcm2835-rng" }, + { .name = "bcm63xx-rng" }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(platform, bcm2835_rng_devtype); + static struct platform_driver bcm2835_rng_driver = { .driver = { .name = "bcm2835-rng", .of_match_table = bcm2835_rng_of_match, }, .probe = bcm2835_rng_probe, + .id_table = bcm2835_rng_devtype, }; module_platform_driver(bcm2835_rng_driver); -- 2.9.3
[PATCH 12/12] hwrng: bcm63xx-rng: Remove since bcm2835-rng takes over
bcm2835-rng is now capable of supporting the BCM63xx hardware, so remove the driver which duplicates the same functionality. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/Kconfig | 13 --- drivers/char/hw_random/Makefile | 1 - drivers/char/hw_random/bcm63xx-rng.c | 154 --- 3 files changed, 168 deletions(-) delete mode 100644 drivers/char/hw_random/bcm63xx-rng.c diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index d0689cc8c7fc..2d3775b9c0c7 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig @@ -73,19 +73,6 @@ config HW_RANDOM_ATMEL If unsure, say Y. -config HW_RANDOM_BCM63XX - tristate "Broadcom BCM63xx Random Number Generator support" - depends on BCM63XX || BMIPS_GENERIC - default HW_RANDOM - ---help--- - This driver provides kernel-side support for the Random Number - Generator hardware found on the Broadcom BCM63xx SoCs. - - To compile this driver as a module, choose M here: the - module will be called bcm63xx-rng - - If unusure, say Y. - config HW_RANDOM_BCM2835 tristate "Broadcom BCM2835/BCM63xx Random Number Generator support" depends on ARCH_BCM2835 || ARCH_BCM_NSP || ARCH_BCM_5301X || \ diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile index 39a67defac67..470ea14ed6b7 100644 --- a/drivers/char/hw_random/Makefile +++ b/drivers/char/hw_random/Makefile @@ -8,7 +8,6 @@ obj-$(CONFIG_HW_RANDOM_TIMERIOMEM) += timeriomem-rng.o obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o obj-$(CONFIG_HW_RANDOM_ATMEL) += atmel-rng.o -obj-$(CONFIG_HW_RANDOM_BCM63XX)+= bcm63xx-rng.o obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o obj-$(CONFIG_HW_RANDOM_N2RNG) += n2-rng.o n2-rng-y := n2-drv.o n2-asm.o diff --git a/drivers/char/hw_random/bcm63xx-rng.c b/drivers/char/hw_random/bcm63xx-rng.c deleted file mode 100644 index 5132c9cde50d.. --- a/drivers/char/hw_random/bcm63xx-rng.c +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Broadcom BCM63xx Random Number Generator support - * - * Copyright (C) 2011, Florian Fainelli <flor...@openwrt.org> - * Copyright (C) 2009, Broadcom Corporation - * - */ -#include -#include -#include -#include -#include -#include -#include -#include - -#define RNG_CTRL 0x00 -#define RNG_EN (1 << 0) - -#define RNG_STAT 0x04 -#define RNG_AVAIL_MASK (0xff00) - -#define RNG_DATA 0x08 -#define RNG_THRES 0x0c -#define RNG_MASK 0x10 - -struct bcm63xx_rng_priv { - struct hwrng rng; - struct clk *clk; - void __iomem *regs; -}; - -#define to_rng_priv(rng) container_of(rng, struct bcm63xx_rng_priv, rng) - -static int bcm63xx_rng_init(struct hwrng *rng) -{ - struct bcm63xx_rng_priv *priv = to_rng_priv(rng); - u32 val; - int error; - - error = clk_prepare_enable(priv->clk); - if (error) - return error; - - val = __raw_readl(priv->regs + RNG_CTRL); - val |= RNG_EN; - __raw_writel(val, priv->regs + RNG_CTRL); - - return 0; -} - -static void bcm63xx_rng_cleanup(struct hwrng *rng) -{ - struct bcm63xx_rng_priv *priv = to_rng_priv(rng); - u32 val; - - val = __raw_readl(priv->regs + RNG_CTRL); - val &= ~RNG_EN; - __raw_writel(val, priv->regs + RNG_CTRL); - - clk_disable_unprepare(priv->clk); -} - -static int bcm63xx_rng_data_present(struct hwrng *rng, int wait) -{ - struct bcm63xx_rng_priv *priv = to_rng_priv(rng); - - return __raw_readl(priv->regs + RNG_STAT) & RNG_AVAIL_MASK; -} - -static int bcm63xx_rng_data_read(struct hwrng *rng, u32 *data) -{ - struct bcm63xx_rng_priv *priv = to_rng_priv(rng); - - *data = __raw_readl(priv->regs + RNG_DATA); - - return 4; -} - -static int bcm63xx_rng_probe(struct platform_device *pdev) -{ - struct resource *r; - int ret; - struct bcm63xx_rng_priv *priv; - - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!r) { - dev_err(>dev, "no iomem resource\n"); - return -ENXIO; - } - - priv = devm_kzalloc(>dev, sizeof(*priv), GFP_KERNEL); - if (!priv) - return -ENOMEM; - - priv->rng.name = pdev->name; - priv->rng.init = bcm63xx_rng_init; - priv->rng.cleanup = bcm63xx_rng_cleanup; - priv->rng.data_present = bcm63xx_rng_data_present; - priv->rng.data_read = bcm63xx_rng_data_read; - - priv->clk = devm_clk_get(>dev, "ipsec"); - if (IS_ERR(priv->clk)) { -
[PATCH 08/12] hwrng: bcm2835-rng: Abstract I/O accessors
In preparation for allowing BCM63xx to use this driver, we abstract I/O accessors such that we can easily change those later on. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/bcm2835-rng.c | 27 +++ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/drivers/char/hw_random/bcm2835-rng.c b/drivers/char/hw_random/bcm2835-rng.c index 35928efb52e7..500275d55044 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -42,6 +42,17 @@ static inline struct bcm2835_rng_priv *to_rng_priv(struct hwrng *rng) return container_of(rng, struct bcm2835_rng_priv, rng); } +static inline u32 rng_readl(struct bcm2835_rng_priv *priv, u32 offset) +{ + return readl(priv->base + offset); +} + +static inline void rng_writel(struct bcm2835_rng_priv *priv, u32 val, + u32 offset) +{ + writel(val, priv->base + offset); +} + static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, bool wait) { @@ -49,18 +60,18 @@ static int bcm2835_rng_read(struct hwrng *rng, void *buf, size_t max, u32 max_words = max / sizeof(u32); u32 num_words, count; - while ((__raw_readl(priv->base + RNG_STATUS) >> 24) == 0) { + while ((rng_readl(priv, RNG_STATUS) >> 24) == 0) { if (!wait) return 0; cpu_relax(); } - num_words = readl(priv->base + RNG_STATUS) >> 24; + num_words = rng_readl(priv, RNG_STATUS) >> 24; if (num_words > max_words) num_words = max_words; for (count = 0; count < num_words; count++) - ((u32 *)buf)[count] = readl(priv->base + RNG_DATA); + ((u32 *)buf)[count] = rng_readl(priv, RNG_DATA); return num_words * sizeof(u32); } @@ -77,14 +88,14 @@ static int bcm2835_rng_init(struct hwrng *rng) if (priv->mask_interrupts) { /* mask the interrupt */ - val = readl(priv->base + RNG_INT_MASK); + val = rng_readl(priv, RNG_INT_MASK); val |= RNG_INT_OFF; - writel(val, priv->base + RNG_INT_MASK); + rng_writel(priv, val, RNG_INT_MASK); } /* set warm-up count & enable */ - __raw_writel(RNG_WARMUP_COUNT, priv->base + RNG_STATUS); - __raw_writel(RNG_RBGEN, priv->base + RNG_CTRL); + rng_writel(priv, RNG_WARMUP_COUNT, RNG_STATUS); + rng_writel(priv, RNG_RBGEN, RNG_CTRL); return 0; } @@ -94,7 +105,7 @@ static void bcm2835_rng_cleanup(struct hwrng *rng) struct bcm2835_rng_priv *priv = to_rng_priv(rng); /* disable rng hardware */ - __raw_writel(0, priv->base + RNG_CTRL); + rng_writel(priv, 0, RNG_CTRL); clk_disable_unprepare(priv->clk); } -- 2.9.3
[PATCH 0/2] hwrng: iproc-rng200: Add support for BCM7278
Hi, This patch series adds support for the RNG200 block found on the BCM7278 SoC. This requires us to update the compatible string (and associated binding document) as well as the Kconfig option to make that driver selectable with ARCH_BRCMSTB gating the enabling of such SoCs. Thank you Florian Fainelli (2): dt-bindings: rng: Document BCM7278 RNG200 compatible hwrng: iproc-rng200: Add support for BCM7278 Documentation/devicetree/bindings/rng/brcm,iproc-rng200.txt | 4 +++- drivers/char/hw_random/Kconfig | 6 +++--- drivers/char/hw_random/iproc-rng200.c | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) -- 2.9.3
[PATCH 1/2] dt-bindings: rng: Document BCM7278 RNG200 compatible
BCM7278 includes a RGN200 hardware random number generator, document the compatible string for that version of the IP. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- Documentation/devicetree/bindings/rng/brcm,iproc-rng200.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/rng/brcm,iproc-rng200.txt b/Documentation/devicetree/bindings/rng/brcm,iproc-rng200.txt index e25a456664b9..0014da9145af 100644 --- a/Documentation/devicetree/bindings/rng/brcm,iproc-rng200.txt +++ b/Documentation/devicetree/bindings/rng/brcm,iproc-rng200.txt @@ -1,7 +1,9 @@ HWRNG support for the iproc-rng200 driver Required properties: -- compatible : "brcm,iproc-rng200" +- compatible : Must be one of: + "brcm,bcm7278-rng200" + "brcm,iproc-rng200" - reg : base address and size of control register block Example: -- 2.9.3
[PATCH 2/2] hwrng: iproc-rng200: Add support for BCM7278
BCM7278 features a RNG200 hardware random number generator block, add support for this chip by matching the chip-specific compatible string and extending the Kconfig dependencies to allow building on ARCH_BRCMSTB (base platform for 7278). Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/Kconfig| 6 +++--- drivers/char/hw_random/iproc-rng200.c | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index 95a031e9eced..f6e3e5abc117 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig @@ -100,12 +100,12 @@ config HW_RANDOM_BCM2835 If unsure, say Y. config HW_RANDOM_IPROC_RNG200 - tristate "Broadcom iProc RNG200 support" - depends on ARCH_BCM_IPROC + tristate "Broadcom iProc/STB RNG200 support" + depends on ARCH_BCM_IPROC || ARCH_BRCMSTB default HW_RANDOM ---help--- This driver provides kernel-side support for the RNG200 - hardware found on the Broadcom iProc SoCs. + hardware found on the Broadcom iProc and STB SoCs. To compile this driver as a module, choose M here: the module will be called iproc-rng200 diff --git a/drivers/char/hw_random/iproc-rng200.c b/drivers/char/hw_random/iproc-rng200.c index 3eaf7cb96d36..8b5a20b35293 100644 --- a/drivers/char/hw_random/iproc-rng200.c +++ b/drivers/char/hw_random/iproc-rng200.c @@ -220,6 +220,7 @@ static int iproc_rng200_probe(struct platform_device *pdev) } static const struct of_device_id iproc_rng200_of_match[] = { + { .compatible = "brcm,bcm7278-rng200", }, { .compatible = "brcm,iproc-rng200", }, {}, }; -- 2.9.3
Re: [PATCH 1/1] ARM: dts: NSP: Add crypto (SPU) to dtsi
On 03/06/2017 11:22 AM, Florian Fainelli wrote: > On 02/28/2017 12:31 PM, Florian Fainelli wrote: >> On 02/22/2017 01:22 PM, Steve Lin wrote: >>> Adds crypto hardware (SPU) to Northstar Plus device tree file. >>> >>> Signed-off-by: Steve Lin <steven.l...@broadcom.com> >> >> Applied, thanks! > > And dropped, since there is a dependency on "ARM: dts: NSP: Add mailbox > (PDC) to NSP" to be applied first. > > Let's wait for the mailbox maintainer to chime in before I apply the > following patches (in that order): > > ARM: dts: NSP: Add mailbox (PDC) to NSP > ARM: dts: NSP: Add crypto (SPU) to dtsi Applied again. -- Florian
Re: [PATCH 1/1] ARM: dts: NSP: Add crypto (SPU) to dtsi
On 02/28/2017 12:31 PM, Florian Fainelli wrote: > On 02/22/2017 01:22 PM, Steve Lin wrote: >> Adds crypto hardware (SPU) to Northstar Plus device tree file. >> >> Signed-off-by: Steve Lin <steven.l...@broadcom.com> > > Applied, thanks! And dropped, since there is a dependency on "ARM: dts: NSP: Add mailbox (PDC) to NSP" to be applied first. Let's wait for the mailbox maintainer to chime in before I apply the following patches (in that order): ARM: dts: NSP: Add mailbox (PDC) to NSP ARM: dts: NSP: Add crypto (SPU) to dtsi Thanks! -- Florian
Re: [PATCH 1/1] ARM: dts: NSP: Add crypto (SPU) to dtsi
On 02/22/2017 01:22 PM, Steve Lin wrote: > Adds crypto hardware (SPU) to Northstar Plus device tree file. > > Signed-off-by: Steve LinApplied, thanks! -- Florian
Re: [PATCH v4 0/3] Add Broadcom SPU Crypto Driver
On 02/13/2017 07:11 AM, Jon Mason wrote: > On Sat, Feb 11, 2017 at 5:54 AM, Herbert Xu> wrote: >> On Fri, Feb 03, 2017 at 12:55:31PM -0500, Rob Rice wrote: >>> Changes in v4: >>> - Added Rob Herring's Acked-by to patch 1/3 for bindings doc >>> - In response to Herbert's comment, in ahash_export() and >>> ahash_import(), only copy the hash state, not state params >>> related to cipher or aead algos. >>> - Noticed that hmac_offset in iproc_reqctx_s and spu_hash_params >>> wasn't really used. So removed. >> >> Patches 1-2 applied. Thanks. > > Thanks Herbert! > > Florian, could you please include patch #3 in your DT branch? Applied, thanks! -- Florian
Re: [PATCH v3 0/3] Add Broadcom SPU Crypto Driver
On 01/25/2017 08:44 AM, Rob Rice wrote: > Changes in v3: > - rebase to 4.10-rc3 in cryptodev-2.6 tree > - in bindings doc, list all valid compatibility strings > - rename DT nodes "crypto" rather than "spu-crypto" > - include a separate DT node for each SPU hardware block. Previously, > there was a single SPU node listing a register range for each > hw block. > - select hash algos in Kconfig. Driver HMAC implementation uses hash > sw algos for inner and outer hashes. > - Fix crash for AES CCM decrypt when AAD and data are both empty > > Change in v2: > - select CRYPTO_DES in Kconfig > > The Broadcom SPU crypto driver provides access to SPU hardware > for symmetric crypto offload. The driver supports ablkcipher, > ahash, and aead operations. The driver supports several > Broadcom SoCs with different revisions of the SPU hardware. > The driver supports SPU-M and SPU2 hardware revisions, and > a couple versions of each hw revision, each version with minor > differences. Herbert, can you take patches 1-2, and I will take patch 3 through my arm64-soc git pull requests? Thanks!! > > Rob Rice (3): > crypto: brcm: DT documentation for Broadcom SPU hardware > crypto: brcm: Add Broadcom SPU driver > arm64: dts: ns2: Add Broadcom SPU driver DT entry. > > .../devicetree/bindings/crypto/brcm,spu-crypto.txt | 22 + > arch/arm64/boot/dts/broadcom/ns2.dtsi | 24 + > drivers/crypto/Kconfig | 15 + > drivers/crypto/Makefile|2 + > drivers/crypto/bcm/Makefile| 15 + > drivers/crypto/bcm/cipher.c| 4955 > > drivers/crypto/bcm/cipher.h| 475 ++ > drivers/crypto/bcm/spu.c | 1252 + > drivers/crypto/bcm/spu.h | 288 ++ > drivers/crypto/bcm/spu2.c | 1402 ++ > drivers/crypto/bcm/spu2.h | 228 + > drivers/crypto/bcm/spum.h | 174 + > drivers/crypto/bcm/util.c | 581 +++ > drivers/crypto/bcm/util.h | 116 + > 14 files changed, 9549 insertions(+) > create mode 100644 > Documentation/devicetree/bindings/crypto/brcm,spu-crypto.txt > create mode 100644 drivers/crypto/bcm/Makefile > create mode 100644 drivers/crypto/bcm/cipher.c > create mode 100644 drivers/crypto/bcm/cipher.h > create mode 100644 drivers/crypto/bcm/spu.c > create mode 100644 drivers/crypto/bcm/spu.h > create mode 100644 drivers/crypto/bcm/spu2.c > create mode 100644 drivers/crypto/bcm/spu2.h > create mode 100644 drivers/crypto/bcm/spum.h > create mode 100644 drivers/crypto/bcm/util.c > create mode 100644 drivers/crypto/bcm/util.h > -- Florian -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] ARM: dts: BCM5301x: Add RNG Device Tree node
On 06/22/2016 05:27 PM, Florian Fainelli wrote: > Add the DT node for the random number generator peripheral. > > Signed-off-by: Florian Fainelli <f.faine...@gmail.com> Applied -- Florian -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/3] hw_random: bcm2835: Add support for Broadcom BCM5301x
On 06/24/2016 06:31 AM, Herbert Xu wrote: > On Wed, Jun 22, 2016 at 05:27:02PM -0700, Florian Fainelli wrote: >> The Broadcom BCM5301x SoCs (Northstar) utilize the same random number >> generator peripheral as Northstar Plus and BCM2835, but just like the >> NSP SoC, we need to enable the interrupt. >> >> Signed-off-by: Florian Fainelli <f.faine...@gmail.com> > > Patch applied. > Thanks! Do you mind taking patch 1 as well? I will take patch 3 via my arm-soc tree. -- Florian -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/3] ARM: dts: BCM5301x: Add RNG Device Tree node
Add the DT node for the random number generator peripheral. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- arch/arm/boot/dts/bcm5301x.dtsi | 5 + 1 file changed, 5 insertions(+) diff --git a/arch/arm/boot/dts/bcm5301x.dtsi b/arch/arm/boot/dts/bcm5301x.dtsi index 7d4d29bf0ed3..c67e451435f4 100644 --- a/arch/arm/boot/dts/bcm5301x.dtsi +++ b/arch/arm/boot/dts/bcm5301x.dtsi @@ -260,6 +260,11 @@ "sata2"; }; + rng: rng@18004000 { + compatible = "brcm,bcm5301x-rng"; + reg = <0x18004000 0x14>; + }; + nand: nand@18028000 { compatible = "brcm,nand-iproc", "brcm,brcmnand-v6.1", "brcm,brcmnand"; reg = <0x18028000 0x600>, <0x1811a408 0x600>, <0x18028f00 0x20>; -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 1/3] Documentation: devicetree: bindings: Add BCM5301x binding
Document the binding used by the Broadcom BCM5301x (Northstar) SoC random number generator. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- Documentation/devicetree/bindings/rng/brcm,bcm2835.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt b/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt index aa304d412058..26542690b578 100644 --- a/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt +++ b/Documentation/devicetree/bindings/rng/brcm,bcm2835.txt @@ -2,7 +2,8 @@ BCM2835 Random number generator Required properties: -- compatible : should be "brcm,bcm2835-rng" or "brcm,bcm-nsp-rng" +- compatible : should be "brcm,bcm2835-rng" or "brcm,bcm-nsp-rng" or + "brcm,bcm5301x-rng" - reg : Specifies base physical address and size of the registers. Example: -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/3] hw_random: bcm2835: Add support for Broadcom BCM5301x
The Broadcom BCM5301x SoCs (Northstar) utilize the same random number generator peripheral as Northstar Plus and BCM2835, but just like the NSP SoC, we need to enable the interrupt. Signed-off-by: Florian Fainelli <f.faine...@gmail.com> --- drivers/char/hw_random/Kconfig | 2 +- drivers/char/hw_random/bcm2835-rng.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index 51401100466b..56ad5a5936a9 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 || ARCH_BCM_NSP + depends on ARCH_BCM2835 || ARCH_BCM_NSP || ARCH_BCM_5301X 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 75ca820730be..af2149273fe0 100644 --- a/drivers/char/hw_random/bcm2835-rng.c +++ b/drivers/char/hw_random/bcm2835-rng.c @@ -70,6 +70,7 @@ static struct hwrng bcm2835_rng_ops = { static const struct of_device_id bcm2835_rng_of_match[] = { { .compatible = "brcm,bcm2835-rng"}, { .compatible = "brcm,bcm-nsp-rng", .data = nsp_rng_init}, + { .compatible = "brcm,bcm5301x-rng", .data = nsp_rng_init}, {}, }; -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 0/3] hw_random: bcm2835: Add support for Broadcom BCM5301x
Hi all, This patch series adds support for the Broadcom BCM5301x SoCs random number generator which is the same block as the one found in NSP and BCM2835. Florian Fainelli (3): Documentation: devicetree: bindings: Add BCM5301x binding hw_random: bcm2835: Add support for Broadcom BCM5301x ARM: dts: BCM5301x: Add RNG Device Tree node Documentation/devicetree/bindings/rng/brcm,bcm2835.txt | 3 ++- arch/arm/boot/dts/bcm5301x.dtsi| 5 + drivers/char/hw_random/Kconfig | 2 +- drivers/char/hw_random/bcm2835-rng.c | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) -- 2.7.4 -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 0/4] hw rng support for NSP SoC
On 05/31/2016 03:19 AM, Herbert Xu wrote: > On Fri, May 27, 2016 at 06:10:37AM -0400, Yendapally Reddy Dhananjaya Reddy > wrote: >> This patchset contains the hw random number generator support for the >> Broadcom's NSP SoC. The block is similar to the block available in >> bcm2835 with different default interrupt mask value. Due to lack of >> documentation, I cannot confirm the interrupt mask register details >> in bcm2835. In an effort to not break the existing functionality of >> bcm2835, I used a different compatible string to mask the interrupt >> for NSP SoC. Please let me know. Also supported providing requested >> number of random numbers instead of static size of four bytes. >> >> The first patch contains the documentation changes and the second patch >> contains the support for rng available in NSP SoC. The third patch >> contains the device tree changes for NSP SoC. The fourth patch contains >> the support for reading requested number of random numbers. >> >> This patch set has been tested on NSP bcm958625HR board. >> This patch set is based on v4.6.0-rc1 and is available from github >> repo: https://github.com/Broadcom/cygnus-linux.git >> branch: nsp-rng-v2 >> >> Changes since v1 > > All applied. FYI, ARM Device Tree patches usually go via ARM SoC pull requests, so it is best if this is planned in advance. Can you make sure you document that there could be a merge conflict in your pull request to Linus? Thanks -- Florian -- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 4/4] hw_random: bcm63xx-rng: use devm_* helpers
Simplify the driver's probe function and error handling by using the device managed allocators, while at it, drop the redundant out of memory messages since these are already printed by the allocator. Signed-off-by: Florian Fainelli f.faine...@gmail.com --- drivers/char/hw_random/bcm63xx-rng.c | 20 ++-- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/drivers/char/hw_random/bcm63xx-rng.c b/drivers/char/hw_random/bcm63xx-rng.c index c7f3af852599..27da00f68c8f 100644 --- a/drivers/char/hw_random/bcm63xx-rng.c +++ b/drivers/char/hw_random/bcm63xx-rng.c @@ -83,18 +83,16 @@ static int bcm63xx_rng_probe(struct platform_device *pdev) goto out; } - priv = kzalloc(sizeof(*priv), GFP_KERNEL); + priv = devm_kzalloc(pdev-dev, sizeof(*priv), GFP_KERNEL); if (!priv) { - dev_err(pdev-dev, no memory for private structure\n); ret = -ENOMEM; goto out; } - rng = kzalloc(sizeof(*rng), GFP_KERNEL); + rng = devm_kzalloc(pdev-dev, sizeof(*rng), GFP_KERNEL); if (!rng) { - dev_err(pdev-dev, no memory for rng structure\n); ret = -ENOMEM; - goto out_free_priv; + goto out; } platform_set_drvdata(pdev, rng); @@ -109,7 +107,7 @@ static int bcm63xx_rng_probe(struct platform_device *pdev) if (IS_ERR(clk)) { dev_err(pdev-dev, no clock for device\n); ret = PTR_ERR(clk); - goto out_free_rng; + goto out; } priv-clk = clk; @@ -118,7 +116,7 @@ static int bcm63xx_rng_probe(struct platform_device *pdev) resource_size(r), pdev-name)) { dev_err(pdev-dev, request mem failed); ret = -ENOMEM; - goto out_free_rng; + goto out; } priv-regs = devm_ioremap_nocache(pdev-dev, r-start, @@ -126,7 +124,7 @@ static int bcm63xx_rng_probe(struct platform_device *pdev) if (!priv-regs) { dev_err(pdev-dev, ioremap failed); ret = -ENOMEM; - goto out_free_rng; + goto out; } clk_enable(clk); @@ -143,10 +141,6 @@ static int bcm63xx_rng_probe(struct platform_device *pdev) out_clk_disable: clk_disable(clk); -out_free_rng: - kfree(rng); -out_free_priv: - kfree(priv); out: return ret; } @@ -158,8 +152,6 @@ static int bcm63xx_rng_remove(struct platform_device *pdev) hwrng_unregister(rng); clk_disable(priv-clk); - kfree(priv); - kfree(rng); return 0; } -- 2.1.0 -- To unsubscribe from this list: send the line unsubscribe linux-crypto in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 2/4] hw_random: bcm63xx-rng: move register definitions to driver
arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h contains the register definitions for this random number generator block, incorporate these register definitions directly into the bcm63xx-rng driver so we do not rely on this header to be provided. Signed-off-by: Florian Fainelli f.faine...@gmail.com --- drivers/char/hw_random/bcm63xx-rng.c | 10 +- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/char/hw_random/bcm63xx-rng.c b/drivers/char/hw_random/bcm63xx-rng.c index ed9b28b35a39..c7f3af852599 100644 --- a/drivers/char/hw_random/bcm63xx-rng.c +++ b/drivers/char/hw_random/bcm63xx-rng.c @@ -13,7 +13,15 @@ #include linux/platform_device.h #include linux/hw_random.h -#include bcm63xx_regs.h +#define RNG_CTRL 0x00 +#define RNG_EN (1 0) + +#define RNG_STAT 0x04 +#define RNG_AVAIL_MASK (0xff00) + +#define RNG_DATA 0x08 +#define RNG_THRES 0x0c +#define RNG_MASK 0x10 struct bcm63xx_rng_priv { struct clk *clk; -- 2.1.0 -- To unsubscribe from this list: send the line unsubscribe linux-crypto in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH 3/4] MIPS: BCM63xx: remove RSET_RNG register definitions
Now that these definitions have been moved to drivers/char/hw_random/bcm63xx-rng.c where they belong to make the driver standalone, we can safely remove these definitions from bcm63xx_regs.h. Signed-off-by: Florian Fainelli f.faine...@gmail.com --- arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h | 14 -- 1 file changed, 14 deletions(-) diff --git a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h index 4794067cb5a7..5035f09c5427 100644 --- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h @@ -1259,20 +1259,6 @@ #define M2M_DSTID_REG(x) ((x) * 0x40 + 0x18) /* - * _REG relative to RSET_RNG - */ - -#define RNG_CTRL 0x00 -#define RNG_EN (1 0) - -#define RNG_STAT 0x04 -#define RNG_AVAIL_MASK (0xff00) - -#define RNG_DATA 0x08 -#define RNG_THRES 0x0c -#define RNG_MASK 0x10 - -/* * _REG relative to RSET_SPI */ -- 2.1.0 -- To unsubscribe from this list: send the line unsubscribe linux-crypto in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html