1 // SPDX-License-Identifier: GPL-2.0
3 * sl3516-ce-rng.c - hardware cryptographic offloader for SL3516 SoC.
5 * Copyright (C) 2021 Corentin Labbe <clabbe@baylibre.com>
7 * This file handle the RNG found in the SL3516 crypto engine
10 #include <linux/pm_runtime.h>
11 #include <linux/hw_random.h>
13 static int sl3516_ce_rng_read(struct hwrng
*rng
, void *buf
, size_t max
, bool wait
)
15 struct sl3516_ce_dev
*ce
;
20 ce
= container_of(rng
, struct sl3516_ce_dev
, trng
);
22 #ifdef CONFIG_CRYPTO_DEV_SL3516_DEBUG
24 ce
->hwrng_stat_bytes
+= max
;
27 err
= pm_runtime_get_sync(ce
->dev
);
29 pm_runtime_put_noidle(ce
->dev
);
34 *data
= readl(ce
->base
+ IPSEC_RAND_NUM_REG
);
39 pm_runtime_put(ce
->dev
);
44 int sl3516_ce_rng_register(struct sl3516_ce_dev
*ce
)
48 ce
->trng
.name
= "SL3516 Crypto Engine RNG";
49 ce
->trng
.read
= sl3516_ce_rng_read
;
50 ce
->trng
.quality
= 700;
52 ret
= hwrng_register(&ce
->trng
);
54 dev_err(ce
->dev
, "Fail to register the RNG\n");
58 void sl3516_ce_rng_unregister(struct sl3516_ce_dev
*ce
)
60 hwrng_unregister(&ce
->trng
);