drivers: entropy: gecko: add entropy driver based on GECKO TRNG

Add entropy driver based on GECKO TRNG module along with device
tree support for EFM32PG and EFR32MG SOCs.

Signed-off-by: Pooja Karanjekar <pooja.karanjekar@lemonbeat.com>
This commit is contained in:
Pooja Karanjekar 2020-02-21 15:22:05 +01:00 committed by Maureen Helm
parent 6574efa232
commit b49501e3c9
19 changed files with 148 additions and 0 deletions

View file

@ -142,6 +142,7 @@
/drivers/eeprom/ @henrikbrixandersen
/drivers/eeprom/eeprom_stm32.c @KwonTae-young
/drivers/entropy/*rv32m1* @MaureenHelm
/drivers/entropy/*gecko* @chrta
/drivers/espi/ @albertofloyd @franciscomunoz @scottwcpg
/drivers/ps2/ @albertofloyd @franciscomunoz @scottwcpg
/drivers/kscan/ @albertofloyd @franciscomunoz @scottwcpg

View file

@ -61,6 +61,8 @@ The efm32pg_stk3402a board configuration supports the following hardware feature
+-----------+------------+-------------------------------------+
| WATCHDOG | on-chip | watchdog |
+-----------+------------+-------------------------------------+
| TRNG | on-chip | true random number generator |
+-----------+------------+-------------------------------------+
The default configuration can be found in the defconfig file:

View file

@ -113,3 +113,7 @@
};
};
&trng0 {
status = "okay";
};

View file

@ -79,6 +79,8 @@ The efr32mg_sltb004a board configuration supports the following hardware feature
+-----------+------------+-------------------------------------+
| WATCHDOG | on-chip | watchdog |
+-----------+------------+-------------------------------------+
| TRNG | on-chip | true random number generator |
+-----------+------------+-------------------------------------+
The default configuration can be found in the defconfig file:
``boards/arm/efr32mg_sltb004a/efr32mg_sltb004a_defconfig``.

View file

@ -146,3 +146,7 @@
};
};
&trng0 {
status = "okay";
};

View file

@ -13,3 +13,4 @@ zephyr_library_sources_ifdef(CONFIG_ENTROPY_LITEX_RNG entropy_litex.c)
zephyr_library_sources_ifdef(CONFIG_FAKE_ENTROPY_NATIVE_POSIX fake_entropy_native_posix.c)
zephyr_library_sources_ifdef(CONFIG_USERSPACE entropy_handlers.c)
zephyr_library_sources_ifdef(CONFIG_ENTROPY_RV32M1_TRNG entropy_rv32m1_trng.c)
zephyr_library_sources_ifdef(CONFIG_ENTROPY_GECKO_TRNG entropy_gecko_trng.c)

View file

@ -19,6 +19,7 @@ source "drivers/entropy/Kconfig.sam"
source "drivers/entropy/Kconfig.native_posix"
source "drivers/entropy/Kconfig.rv32m1"
source "drivers/entropy/Kconfig.litex"
source "drivers/entropy/Kconfig.gecko"
config ENTROPY_HAS_DRIVER
bool

View file

@ -0,0 +1,14 @@
# gecko entropy generator driver configuration
# Copyright (c) 2020 Lemonbeat GmbH
# SPDX-License-Identifier: Apache-2.0
config ENTROPY_GECKO_TRNG
bool "GECKO TRNG driver"
depends on SOC_GECKO_TRNG
select ENTROPY_HAS_DRIVER
select HAS_DTS_ENTROPY
default y
help
This option enables the true random number generator
driver based on the TRNG.

View file

@ -0,0 +1,71 @@
/*
* Copyright (c) 2020 Lemonbeat GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <drivers/entropy.h>
#include <string.h>
#include "soc.h"
#include "em_cmu.h"
static void entropy_gecko_trng_read(u8_t *output, size_t len)
{
u32_t tmp;
u32_t *data = (u32_t *) output;
/* Read known good available data. */
while (len >= 4) {
*data++ = TRNG0->FIFO;
len -= 4;
}
if (len > 0) {
/* Handle the case where len is not a multiple of 4
* and FIFO data is available.
*/
tmp = TRNG0->FIFO;
memcpy(data, (const u8_t *) &tmp, len);
}
}
static int entropy_gecko_trng_get_entropy(struct device *dev, u8_t *buffer,
u16_t length)
{
size_t count = 0;
size_t available;
ARG_UNUSED(dev);
while (length) {
available = TRNG0->FIFOLEVEL * 4;
if (available == 0) {
return -EINVAL;
}
count = SL_MIN(length, available);
entropy_gecko_trng_read(buffer, count);
buffer += count;
length -= count;
}
return 0;
}
static int entropy_gecko_trng_init(struct device *device)
{
/* Enable the TRNG0 clock. */
CMU_ClockEnable(cmuClock_TRNG0, true);
/* Enable TRNG0. */
TRNG0->CONTROL = TRNG_CONTROL_ENABLE;
return 0;
}
static struct entropy_driver_api entropy_gecko_trng_api_funcs = {
.get_entropy = entropy_gecko_trng_get_entropy
};
DEVICE_AND_API_INIT(entropy_gecko_trng, CONFIG_ENTROPY_NAME,
entropy_gecko_trng_init, NULL, NULL,
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&entropy_gecko_trng_api_funcs);

View file

@ -218,6 +218,14 @@
interrupts = <3 0>;
status = "disabled";
};
trng0: trng@4001d000 {
compatible = "silabs,gecko-trng";
reg = <0x4001d000 0x400>;
interrupts = <49 0>;
label = "TRNG0";
status = "disabled";
};
};
};
};

View file

@ -210,6 +210,14 @@
interrupts = <3 0>;
status = "disabled";
};
trng0: trng@4001d000 {
compatible = "silabs,gecko-trng";
reg = <0x4001d000 0x400>;
interrupts = <49 0>;
label = "TRNG0";
status = "disabled";
};
};
};

View file

@ -0,0 +1,21 @@
# Copyright (c) 2020, Lemonbeat GmbH
# SPDX-License-Identifier: Apache-2.0
description: |
GECKO TRNG (True Random Number Generator).
The TRNG module is a non-deterministic randomnumber generator based on a full hardware solution.
compatible: "silabs,gecko-trng"
include: base.yaml
properties:
reg:
required: true
interrupts:
required: true
label:
required: true

View file

@ -97,6 +97,11 @@ config SOC_GECKO_WDOG
help
Set if the Watchdog Timer (WDOG) HAL module is used.
config SOC_GECKO_TRNG
bool
help
Set if the SoC has a True Random Number Generator (TRNG) module.
config SOC_GECKO_EMU_DCDC
bool "Enable SoC DC/DC regulator"
select SOC_GECKO_EMU

View file

@ -18,5 +18,6 @@ config SOC_SERIES_EFM32JG12B
select SOC_GECKO_CMU
select SOC_GECKO_EMU
select SOC_GECKO_GPIO
select SOC_GECKO_TRNG
help
Enable support for EFM32 JadeGecko MCU series

View file

@ -31,5 +31,6 @@
#define DT_WDT_0_NAME DT_INST_0_SILABS_GECKO_WDOG_LABEL
#define DT_WDT_1_NAME DT_INST_1_SILABS_GECKO_WDOG_LABEL
#define CONFIG_ENTROPY_NAME DT_SILABS_GECKO_TRNG_4001D000_LABEL
/* End of SoC Level DTS fixup file */

View file

@ -20,5 +20,6 @@ config SOC_SERIES_EFM32PG12B
select SOC_GECKO_CMU
select SOC_GECKO_EMU
select SOC_GECKO_GPIO
select SOC_GECKO_TRNG
help
Enable support for EFM32 PearlGecko MCU series

View file

@ -31,5 +31,6 @@
#define DT_WDT_0_NAME DT_INST_0_SILABS_GECKO_WDOG_LABEL
#define DT_WDT_1_NAME DT_INST_1_SILABS_GECKO_WDOG_LABEL
#define CONFIG_ENTROPY_NAME DT_SILABS_GECKO_TRNG_4001D000_LABEL
/* End of SoC Level DTS fixup file */

View file

@ -21,5 +21,6 @@ config SOC_SERIES_EFR32MG12P
select SOC_GECKO_CMU
select SOC_GECKO_EMU
select SOC_GECKO_GPIO
select SOC_GECKO_TRNG
help
Enable support for EFR32 Mighty Gecko MCU series

View file

@ -32,5 +32,6 @@
#define DT_WDT_0_NAME DT_INST_0_SILABS_GECKO_WDOG_LABEL
#define DT_WDT_1_NAME DT_INST_1_SILABS_GECKO_WDOG_LABEL
#define CONFIG_ENTROPY_NAME DT_SILABS_GECKO_TRNG_4001D000_LABEL
/* End of SoC Level DTS fixup file */