Skip to content

Commit b36a31f

Browse files
msierszulskifabiobaltieri
authored andcommitted
drivers: entropy: Add Gecko trng driver for EFR32BG22
This commit enables entropy driver on EFR32BG22 SoC. Signed-off-by: Mateusz Sierszulski <[email protected]>
1 parent 5f9eb21 commit b36a31f

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

boards/arm/efr32bg_sltb010a/efr32bg_sltb010a.dts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,7 @@
115115
&stimer0 {
116116
status = "okay";
117117
};
118+
119+
&trng {
120+
status = "okay";
121+
};

drivers/entropy/Kconfig.gecko

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ config ENTROPY_GECKO_TRNG
99
default y
1010
depends on DT_HAS_SILABS_GECKO_TRNG_ENABLED
1111
select ENTROPY_HAS_DRIVER
12+
select CRYPTO_ACC_GECKO_TRNG if SOC_SERIES_EFR32BG22
1213
help
1314
This option enables the true random number generator
1415
driver based on the TRNG.

drivers/entropy/entropy_gecko_trng.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
static void entropy_gecko_trng_read(uint8_t *output, size_t len)
1515
{
16+
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
1617
uint32_t tmp;
1718
uint32_t *data = (uint32_t *) output;
1819

@@ -28,6 +29,9 @@ static void entropy_gecko_trng_read(uint8_t *output, size_t len)
2829
tmp = TRNG0->FIFO;
2930
memcpy(data, (const uint8_t *) &tmp, len);
3031
}
32+
#else
33+
memcpy(output, ((const uint8_t *) CRYPTOACC_RNGOUT_FIFO_S_MEM_BASE), len);
34+
#endif
3135
}
3236

3337
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,
4044
ARG_UNUSED(dev);
4145

4246
while (length) {
47+
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
4348
available = TRNG0->FIFOLEVEL * 4;
49+
#else
50+
available = CRYPTOACC_RNGCTRL->FIFOLEVEL * 4;
51+
#endif
4452
if (available == 0) {
4553
return -EINVAL;
4654
}
@@ -63,7 +71,11 @@ static int entropy_gecko_trng_get_entropy_isr(const struct device *dev,
6371

6472
/* No busy wait; return whatever data is available. */
6573
size_t count;
74+
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
6675
size_t available = TRNG0->FIFOLEVEL * 4;
76+
#else
77+
size_t available = CRYPTOACC_RNGCTRL->FIFOLEVEL * 4;
78+
#endif
6779

6880
if (available == 0) {
6981
return -ENODATA;
@@ -87,10 +99,19 @@ static int entropy_gecko_trng_get_entropy_isr(const struct device *dev,
8799
static int entropy_gecko_trng_init(const struct device *dev)
88100
{
89101
/* Enable the TRNG0 clock. */
102+
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
90103
CMU_ClockEnable(cmuClock_TRNG0, true);
91104

92105
/* Enable TRNG0. */
93106
TRNG0->CONTROL = TRNG_CONTROL_ENABLE;
107+
#else
108+
/* Enable the CRYPTO ACC clock. */
109+
CMU_ClockEnable(cmuClock_CRYPTOACC, true);
110+
111+
/* Enable TRNG */
112+
CRYPTOACC_RNGCTRL->RNGCTRL |= CRYPTOACC_RNGCTRL_ENABLE;
113+
#endif
114+
94115
return 0;
95116
}
96117

dts/arm/silabs/efr32bg22.dtsi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/ {
1414
chosen {
1515
zephyr,flash-controller = &msc;
16+
zephyr,entropy = &trng;
1617
};
1718

1819
power-states {
@@ -69,6 +70,13 @@
6970
status = "disabled";
7071
};
7172

73+
trng: trng@4c021000 {
74+
compatible = "silabs,gecko-trng";
75+
reg = <0x4C021000 0x1000>;
76+
status = "disabled";
77+
interrupts = <0x1 0x0>;
78+
};
79+
7280
i2c0: i2c@5a010000 {
7381
compatible = "silabs,gecko-i2c";
7482
clock-frequency = <I2C_BITRATE_STANDARD>;

soc/arm/silabs_exx32/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ choice SOC_GECKO_EMU_DCDC_MODE
134134
bool "Bypass"
135135
endchoice
136136

137+
config CRYPTO_ACC_GECKO_TRNG
138+
bool
139+
help
140+
Enable Entropy driver based on the CRYPTO_ACC module for Silicon Labs
141+
Gecko chips.
142+
137143
config SOC_GECKO_DEV_INIT
138144
bool
139145
help

0 commit comments

Comments
 (0)