Skip to content

Commit 7120e04

Browse files
asmellbyjhedberg
authored andcommitted
drivers: entropy: gecko_trng: Fully initialize on read
If the TRNG has been unretained, it's not sufficient to enable the clock, it must be fully reinitialized. This is a minimal fix to ensure entropy is accumulated after sleep. Long term, this driver should be made to use device power management with power domain awareness. Upstream-status: available Signed-off-by: Aksel Skauge Mellbye <[email protected]> (cherry picked from commit e61c04e)
1 parent e9e1bc4 commit 7120e04

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

drivers/entropy/entropy_gecko_trng.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@
4444
#endif /* _SILICON_LABS_32B_SERIES_2_CONFIG_* */
4545
#endif /* CONFIG_CRYPTO_ACC_GECKO_TRNG */
4646

47+
static int entropy_gecko_trng_init(const struct device *dev)
48+
{
49+
/* Enable the TRNG0 clock. */
50+
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
51+
CMU_ClockEnable(cmuClock_TRNG0, true);
52+
53+
/* Enable TRNG0. */
54+
TRNG0->CONTROL = TRNG_CONTROL_ENABLE;
55+
#else
56+
/* Enable the CRYPTO ACC clock. */
57+
CMU_ClockEnable(cmuClock_CRYPTOACC, true);
58+
59+
/* Enable TRNG */
60+
S2_CTRL |= S2_CTRL_ENABLE;
61+
#endif
62+
63+
return 0;
64+
}
65+
4766
static void entropy_gecko_trng_read(uint8_t *output, size_t len)
4867
{
4968
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
@@ -77,7 +96,7 @@ static int entropy_gecko_trng_get_entropy(const struct device *dev,
7796
ARG_UNUSED(dev);
7897

7998
#ifdef CONFIG_CRYPTO_ACC_GECKO_TRNG
80-
CMU_ClockEnable(cmuClock_CRYPTOACC, true);
99+
entropy_gecko_trng_init(dev);
81100
#endif
82101

83102
while (length) {
@@ -130,25 +149,6 @@ static int entropy_gecko_trng_get_entropy_isr(const struct device *dev,
130149
}
131150
}
132151

133-
static int entropy_gecko_trng_init(const struct device *dev)
134-
{
135-
/* Enable the TRNG0 clock. */
136-
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
137-
CMU_ClockEnable(cmuClock_TRNG0, true);
138-
139-
/* Enable TRNG0. */
140-
TRNG0->CONTROL = TRNG_CONTROL_ENABLE;
141-
#else
142-
/* Enable the CRYPTO ACC clock. */
143-
CMU_ClockEnable(cmuClock_CRYPTOACC, true);
144-
145-
/* Enable TRNG */
146-
S2_CTRL |= S2_CTRL_ENABLE;
147-
#endif
148-
149-
return 0;
150-
}
151-
152152
static DEVICE_API(entropy, entropy_gecko_trng_api_funcs) = {
153153
.get_entropy = entropy_gecko_trng_get_entropy,
154154
.get_entropy_isr = entropy_gecko_trng_get_entropy_isr

0 commit comments

Comments
 (0)