drivers/entropy/entropy_gecko_trng: support BG27
Add TRNG support for BG27, which has slightly different register definitions in HAL, compared to BG22. Signed-off-by: Roman Dobrodii <rdobrodii@antmicro.com>
This commit is contained in:
parent
56c38bd75d
commit
f9e2d064c4
2 changed files with 24 additions and 4 deletions
|
@ -10,6 +10,7 @@ config ENTROPY_GECKO_TRNG
|
||||||
depends on DT_HAS_SILABS_GECKO_TRNG_ENABLED
|
depends on DT_HAS_SILABS_GECKO_TRNG_ENABLED
|
||||||
select ENTROPY_HAS_DRIVER
|
select ENTROPY_HAS_DRIVER
|
||||||
select CRYPTO_ACC_GECKO_TRNG if SOC_SERIES_EFR32BG22
|
select CRYPTO_ACC_GECKO_TRNG if SOC_SERIES_EFR32BG22
|
||||||
|
select CRYPTO_ACC_GECKO_TRNG if SOC_SERIES_EFR32BG27
|
||||||
help
|
help
|
||||||
This option enables the true random number generator
|
This option enables the true random number generator
|
||||||
driver based on the TRNG.
|
driver based on the TRNG.
|
||||||
|
|
|
@ -11,6 +11,25 @@
|
||||||
#include "soc.h"
|
#include "soc.h"
|
||||||
#include "em_cmu.h"
|
#include "em_cmu.h"
|
||||||
|
|
||||||
|
#if defined(CONFIG_CRYPTO_ACC_GECKO_TRNG)
|
||||||
|
/**
|
||||||
|
* Series 2 SoCs have different TRNG register definitions
|
||||||
|
*/
|
||||||
|
#if defined(_SILICON_LABS_32B_SERIES_2_CONFIG_2) /* xG22 */
|
||||||
|
#define S2_FIFO_BASE (CRYPTOACC_RNGOUT_FIFO_S_MEM_BASE)
|
||||||
|
#define S2_FIFO_LEVEL (CRYPTOACC_RNGCTRL->FIFOLEVEL)
|
||||||
|
#define S2_CTRL (CRYPTOACC_RNGCTRL->RNGCTRL)
|
||||||
|
#define S2_CTRL_ENABLE (CRYPTOACC_RNGCTRL_ENABLE)
|
||||||
|
#elif defined(_SILICON_LABS_32B_SERIES_2_CONFIG_7) /* xG27 */
|
||||||
|
#define S2_FIFO_BASE (CRYPTOACC_RNGOUT_FIFO_S_MEM_BASE)
|
||||||
|
#define S2_FIFO_LEVEL (CRYPTOACC->NDRNG_FIFOLEVEL)
|
||||||
|
#define S2_CTRL (CRYPTOACC->NDRNG_CONTROL)
|
||||||
|
#define S2_CTRL_ENABLE (CRYPTOACC_NDRNG_CONTROL_ENABLE)
|
||||||
|
#else /* _SILICON_LABS_32B_SERIES_2_CONFIG_* */
|
||||||
|
#error "Building for unsupported Series 2 SoC"
|
||||||
|
#endif /* _SILICON_LABS_32B_SERIES_2_CONFIG_* */
|
||||||
|
#endif /* CONFIG_CRYPTO_ACC_GECKO_TRNG */
|
||||||
|
|
||||||
static void entropy_gecko_trng_read(uint8_t *output, size_t len)
|
static void entropy_gecko_trng_read(uint8_t *output, size_t len)
|
||||||
{
|
{
|
||||||
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
|
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
|
||||||
|
@ -30,7 +49,7 @@ static void entropy_gecko_trng_read(uint8_t *output, size_t len)
|
||||||
memcpy(data, (const uint8_t *) &tmp, len);
|
memcpy(data, (const uint8_t *) &tmp, len);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
memcpy(output, ((const uint8_t *) CRYPTOACC_RNGOUT_FIFO_S_MEM_BASE), len);
|
memcpy(output, ((const uint8_t *) S2_FIFO_BASE), len);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +66,7 @@ static int entropy_gecko_trng_get_entropy(const struct device *dev,
|
||||||
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
|
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
|
||||||
available = TRNG0->FIFOLEVEL * 4;
|
available = TRNG0->FIFOLEVEL * 4;
|
||||||
#else
|
#else
|
||||||
available = CRYPTOACC_RNGCTRL->FIFOLEVEL * 4;
|
available = S2_FIFO_LEVEL * 4;
|
||||||
#endif
|
#endif
|
||||||
if (available == 0) {
|
if (available == 0) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -74,7 +93,7 @@ static int entropy_gecko_trng_get_entropy_isr(const struct device *dev,
|
||||||
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
|
#ifndef CONFIG_CRYPTO_ACC_GECKO_TRNG
|
||||||
size_t available = TRNG0->FIFOLEVEL * 4;
|
size_t available = TRNG0->FIFOLEVEL * 4;
|
||||||
#else
|
#else
|
||||||
size_t available = CRYPTOACC_RNGCTRL->FIFOLEVEL * 4;
|
size_t available = S2_FIFO_LEVEL * 4;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (available == 0) {
|
if (available == 0) {
|
||||||
|
@ -109,7 +128,7 @@ static int entropy_gecko_trng_init(const struct device *dev)
|
||||||
CMU_ClockEnable(cmuClock_CRYPTOACC, true);
|
CMU_ClockEnable(cmuClock_CRYPTOACC, true);
|
||||||
|
|
||||||
/* Enable TRNG */
|
/* Enable TRNG */
|
||||||
CRYPTOACC_RNGCTRL->RNGCTRL |= CRYPTOACC_RNGCTRL_ENABLE;
|
S2_CTRL |= S2_CTRL_ENABLE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue