Skip to content

Commit

Permalink
hwrng: bcm2835 - Abstract I/O accessors
Browse files Browse the repository at this point in the history
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.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 791af4f commit abd4202
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions drivers/char/hw_random/bcm2835-rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,36 @@ 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)
{
struct bcm2835_rng_priv *priv = to_rng_priv(rng);
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);
}
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down

0 comments on commit abd4202

Please sign in to comment.