drivers: entropy: Add Gecko trng driver for EFR32BG22
This commit enables entropy driver on EFR32BG22 SoC. Signed-off-by: Mateusz Sierszulski <msierszulski@antmicro.com>
This commit is contained in:
parent
5f9eb210f7
commit
b36a31fd7a
|
@ -115,3 +115,7 @@
|
|||
&stimer0 {
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&trng {
|
||||
status = "okay";
|
||||
};
|
||||
|
|
|
@ -9,6 +9,7 @@ config ENTROPY_GECKO_TRNG
|
|||
default y
|
||||
depends on DT_HAS_SILABS_GECKO_TRNG_ENABLED
|
||||
select ENTROPY_HAS_DRIVER
|
||||
select CRYPTO_ACC_GECKO_TRNG if SOC_SERIES_EFR32BG22
|
||||
help
|
||||
This option enables the true random number generator
|
||||
driver based on the TRNG.
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
static void entropy_gecko_trng_read(uint8_t *output, size_t len)
|
||||
{
|
||||
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
|
||||
uint32_t tmp;
|
||||
uint32_t *data = (uint32_t *) output;
|
||||
|
||||
|
@ -28,6 +29,9 @@ static void entropy_gecko_trng_read(uint8_t *output, size_t len)
|
|||
tmp = TRNG0->FIFO;
|
||||
memcpy(data, (const uint8_t *) &tmp, len);
|
||||
}
|
||||
#else
|
||||
memcpy(output, ((const uint8_t *) CRYPTOACC_RNGOUT_FIFO_S_MEM_BASE), len);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int entropy_gecko_trng_get_entropy(const struct device *dev,
|
||||
|
@ -40,7 +44,11 @@ static int entropy_gecko_trng_get_entropy(const struct device *dev,
|
|||
ARG_UNUSED(dev);
|
||||
|
||||
while (length) {
|
||||
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
|
||||
available = TRNG0->FIFOLEVEL * 4;
|
||||
#else
|
||||
available = CRYPTOACC_RNGCTRL->FIFOLEVEL * 4;
|
||||
#endif
|
||||
if (available == 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -63,7 +71,11 @@ static int entropy_gecko_trng_get_entropy_isr(const struct device *dev,
|
|||
|
||||
/* No busy wait; return whatever data is available. */
|
||||
size_t count;
|
||||
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
|
||||
size_t available = TRNG0->FIFOLEVEL * 4;
|
||||
#else
|
||||
size_t available = CRYPTOACC_RNGCTRL->FIFOLEVEL * 4;
|
||||
#endif
|
||||
|
||||
if (available == 0) {
|
||||
return -ENODATA;
|
||||
|
@ -87,10 +99,19 @@ static int entropy_gecko_trng_get_entropy_isr(const struct device *dev,
|
|||
static int entropy_gecko_trng_init(const struct device *dev)
|
||||
{
|
||||
/* Enable the TRNG0 clock. */
|
||||
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
|
||||
CMU_ClockEnable(cmuClock_TRNG0, true);
|
||||
|
||||
/* Enable TRNG0. */
|
||||
TRNG0->CONTROL = TRNG_CONTROL_ENABLE;
|
||||
#else
|
||||
/* Enable the CRYPTO ACC clock. */
|
||||
CMU_ClockEnable(cmuClock_CRYPTOACC, true);
|
||||
|
||||
/* Enable TRNG */
|
||||
CRYPTOACC_RNGCTRL->RNGCTRL |= CRYPTOACC_RNGCTRL_ENABLE;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
/ {
|
||||
chosen {
|
||||
zephyr,flash-controller = &msc;
|
||||
zephyr,entropy = &trng;
|
||||
};
|
||||
|
||||
power-states {
|
||||
|
@ -69,6 +70,13 @@
|
|||
status = "disabled";
|
||||
};
|
||||
|
||||
trng: trng@4c021000 {
|
||||
compatible = "silabs,gecko-trng";
|
||||
reg = <0x4C021000 0x1000>;
|
||||
status = "disabled";
|
||||
interrupts = <0x1 0x0>;
|
||||
};
|
||||
|
||||
i2c0: i2c@5a010000 {
|
||||
compatible = "silabs,gecko-i2c";
|
||||
clock-frequency = <I2C_BITRATE_STANDARD>;
|
||||
|
|
|
@ -134,6 +134,12 @@ choice SOC_GECKO_EMU_DCDC_MODE
|
|||
bool "Bypass"
|
||||
endchoice
|
||||
|
||||
config CRYPTO_ACC_GECKO_TRNG
|
||||
bool
|
||||
help
|
||||
Enable Entropy driver based on the CRYPTO_ACC module for Silicon Labs
|
||||
Gecko chips.
|
||||
|
||||
config SOC_GECKO_DEV_INIT
|
||||
bool
|
||||
help
|
||||
|
|
Loading…
Reference in New Issue