drivers: entropy: esp32c6: Add support
Add support of entropy (TRNG) driver for ESP32C6 Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
This commit is contained in:
parent
4c151ab67c
commit
b4148f17b7
2 changed files with 35 additions and 1 deletions
|
|
@ -12,7 +12,13 @@
|
|||
#include <esp_system.h>
|
||||
#include <soc.h>
|
||||
#include <esp_cpu.h>
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/drivers/entropy.h>
|
||||
#if defined(SOC_RNG_CLOCK_IS_INDEPENDENT)
|
||||
#include <zephyr/drivers/clock_control.h>
|
||||
#endif
|
||||
|
||||
LOG_MODULE_REGISTER(entropy, CONFIG_ENTROPY_LOG_LEVEL);
|
||||
|
||||
static inline uint32_t entropy_esp32_get_u32(void)
|
||||
{
|
||||
|
|
@ -58,8 +64,28 @@ static int entropy_esp32_get_entropy(const struct device *dev, uint8_t *buf,
|
|||
|
||||
static int entropy_esp32_init(const struct device *dev)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
#if defined(SOC_RNG_CLOCK_IS_INDEPENDENT)
|
||||
const struct device *clock_dev =
|
||||
DEVICE_DT_GET(DT_CLOCKS_CTLR(DT_NODELABEL(trng0)));
|
||||
clock_control_subsys_t clock_subsys =
|
||||
(clock_control_subsys_t)DT_CLOCKS_CELL(DT_NODELABEL(trng0), offset);
|
||||
|
||||
if (!device_is_ready(clock_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = clock_control_on(clock_dev, clock_subsys);
|
||||
|
||||
if (ret != 0) {
|
||||
LOG_ERR("Error enabling TRNG clock");
|
||||
}
|
||||
#else
|
||||
/* clock initialization handled by clock manager */
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct entropy_driver_api entropy_esp32_api_funcs = {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#size-cells = <1>;
|
||||
|
||||
chosen {
|
||||
zephyr,entropy = &trng0;
|
||||
zephyr,flash-controller = &flash;
|
||||
};
|
||||
|
||||
|
|
@ -101,6 +102,13 @@
|
|||
status = "disabled";
|
||||
};
|
||||
|
||||
trng0: trng@600b2808 {
|
||||
compatible = "espressif,esp32-trng";
|
||||
reg = <0x600B2808 0x4>;
|
||||
clocks = <&rtc ESP32_RNG_MODULE>;
|
||||
status = "disabled";
|
||||
};
|
||||
|
||||
spi2: spi@60081000 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
reg = <0x60081000 DT_SIZE_K(4)>;
|
||||
|
|
|
|||
Loading…
Reference in a new issue