gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / crypto / allwinner / sun4i-ss / sun4i-ss-prng.c
blob729aafdbea84eada50c3964995c02352a4718ad4
1 #include "sun4i-ss.h"
3 int sun4i_ss_prng_seed(struct crypto_rng *tfm, const u8 *seed,
4 unsigned int slen)
6 struct sun4i_ss_alg_template *algt;
7 struct rng_alg *alg = crypto_rng_alg(tfm);
9 algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);
10 memcpy(algt->ss->seed, seed, slen);
12 return 0;
15 int sun4i_ss_prng_generate(struct crypto_rng *tfm, const u8 *src,
16 unsigned int slen, u8 *dst, unsigned int dlen)
18 struct sun4i_ss_alg_template *algt;
19 struct rng_alg *alg = crypto_rng_alg(tfm);
20 int i, err;
21 u32 v;
22 u32 *data = (u32 *)dst;
23 const u32 mode = SS_OP_PRNG | SS_PRNG_CONTINUE | SS_ENABLED;
24 size_t len;
25 struct sun4i_ss_ctx *ss;
26 unsigned int todo = (dlen / 4) * 4;
28 algt = container_of(alg, struct sun4i_ss_alg_template, alg.rng);
29 ss = algt->ss;
31 err = pm_runtime_get_sync(ss->dev);
32 if (err < 0)
33 return err;
35 spin_lock_bh(&ss->slock);
37 writel(mode, ss->base + SS_CTL);
39 while (todo > 0) {
40 /* write the seed */
41 for (i = 0; i < SS_SEED_LEN / BITS_PER_LONG; i++)
42 writel(ss->seed[i], ss->base + SS_KEY0 + i * 4);
44 /* Read the random data */
45 len = min_t(size_t, SS_DATA_LEN / BITS_PER_BYTE, todo);
46 readsl(ss->base + SS_TXFIFO, data, len / 4);
47 data += len / 4;
48 todo -= len;
50 /* Update the seed */
51 for (i = 0; i < SS_SEED_LEN / BITS_PER_LONG; i++) {
52 v = readl(ss->base + SS_KEY0 + i * 4);
53 ss->seed[i] = v;
57 writel(0, ss->base + SS_CTL);
58 spin_unlock_bh(&ss->slock);
60 pm_runtime_put(ss->dev);
62 return 0;