drivers: entropy: introduce new Telink B91 Entropy driver

Entropy driver basic support for new Telink B91 platform.

Signed-off-by: Yuriy Vynnychek <yura.vynnychek@telink-semi.com>
This commit is contained in:
Yuriy Vynnychek 2021-07-26 11:27:10 +03:00 committed by Carles Cufí
commit 3e4e9496a1
5 changed files with 85 additions and 0 deletions

View file

@ -2,6 +2,7 @@
zephyr_library()
zephyr_library_sources_ifdef(CONFIG_ENTROPY_TELINK_B91_TRNG entropy_b91_trng.c)
zephyr_library_sources_ifdef(CONFIG_ENTROPY_CC13XX_CC26XX_RNG entropy_cc13xx_cc26xx.c)
zephyr_library_sources_ifdef(CONFIG_ENTROPY_ESP32_RNG entropy_esp32.c)
zephyr_library_sources_ifdef(CONFIG_ENTROPY_MCUX_RNG entropy_mcux_rng.c)

View file

@ -10,6 +10,7 @@ menuconfig ENTROPY_GENERATOR
if ENTROPY_GENERATOR
source "drivers/entropy/Kconfig.b91"
source "drivers/entropy/Kconfig.cc13xx_cc26xx"
source "drivers/entropy/Kconfig.mcux"
source "drivers/entropy/Kconfig.stm32"

View file

@ -0,0 +1,11 @@
# Copyright (c) 2021 Telink Semiconductor
# SPDX-License-Identifier: Apache-2.0
# Telink B91 GPIO configuration options
config ENTROPY_TELINK_B91_TRNG
bool "Telink B91 Entropy driver"
depends on SOC_RISCV_TELINK_B91
select ENTROPY_HAS_DRIVER
help
Enable the B91 Entropy driver.

View file

@ -0,0 +1,71 @@
/*
* Copyright (c) 2021 Telink Semiconductor
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT telink_b91_trng
#include <trng.h>
#include <drivers/entropy.h>
#include <string.h>
/* API implementation: driver initialization */
static int entropy_b91_trng_init(const struct device *dev)
{
ARG_UNUSED(dev);
trng_init();
return 0;
}
/* API implementation: get_entropy */
static int entropy_b91_trng_get_entropy(const struct device *dev,
uint8_t *buffer, uint16_t length)
{
ARG_UNUSED(dev);
uint32_t value = 0;
while (length) {
value = trng_rand();
if (length >= sizeof(value)) {
memcpy(buffer, &value, sizeof(value));
buffer += sizeof(value);
length -= sizeof(value);
} else {
memcpy(buffer, &value, length);
break;
}
}
return 0;
}
/* API implementation: get_entropy_isr */
static int entropy_b91_trng_get_entropy_isr(const struct device *dev,
uint8_t *buffer, uint16_t length,
uint32_t flags)
{
ARG_UNUSED(flags);
/* No specific handling in case of running from ISR, just call standard API */
entropy_b91_trng_get_entropy(dev, buffer, length);
return 0;
}
/* Entropy driver APIs structure */
static const struct entropy_driver_api entropy_b91_trng_api = {
.get_entropy = entropy_b91_trng_get_entropy,
.get_entropy_isr = entropy_b91_trng_get_entropy_isr
};
/* Entropy driver registration */
DEVICE_DT_INST_DEFINE(0, entropy_b91_trng_init,
NULL, NULL, NULL,
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&entropy_b91_trng_api);