Skip to content

Commit

Permalink
hwrng: bcm2835 - Manage an optional clock
Browse files Browse the repository at this point in the history
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.fainelli@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
  • Loading branch information
Florian Fainelli authored and Herbert Xu committed Nov 29, 2017
1 parent 04b154f commit 791af4f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion drivers/char/hw_random/bcm2835-rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <linux/of_platform.h>
#include <linux/platform_device.h>
#include <linux/printk.h>
#include <linux/clk.h>

#define RNG_CTRL 0x0
#define RNG_STATUS 0x4
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 791af4f

Please sign in to comment.