drivers: entropy: add openisa/RV32M1 entropy driver

Wrapper for openisa/RV32M1 TRNG driver

Signed-off-by: George Stefan <george.stefan@nxp.com>
This commit is contained in:
George Stefan 2019-04-08 18:12:40 +03:00 committed by Carles Cufí
parent 94106a8ff3
commit cb03eba697
5 changed files with 78 additions and 0 deletions

View file

@ -121,6 +121,7 @@
/drivers/dma/*sam0* @Sizurka
/drivers/dma/dma_stm32* @cybertale
/drivers/eeprom/ @henrikbrixandersen
/drivers/entropy/*rv32m1* @MaureenHelm
/drivers/espi/ @albertofloyd @franciscomunoz @scottwcpg
/drivers/ps2/ @albertofloyd @franciscomunoz @scottwcpg
/drivers/kscan/ @albertofloyd @franciscomunoz @scottwcpg

View file

@ -11,3 +11,4 @@ zephyr_library_sources_ifdef(CONFIG_ENTROPY_SAM_RNG entropy_sam.c)
zephyr_library_sources_ifdef(CONFIG_ENTROPY_STM32_RNG entropy_stm32.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)

View file

@ -17,6 +17,7 @@ source "drivers/entropy/Kconfig.esp32"
source "drivers/entropy/Kconfig.nrf5"
source "drivers/entropy/Kconfig.sam"
source "drivers/entropy/Kconfig.native_posix"
source "drivers/entropy/Kconfig.rv32m1"
config ENTROPY_HAS_DRIVER
bool

View file

@ -0,0 +1,13 @@
# Kconfig.rv32m1 - RV32M1 entropy generator driver configuration
#
# Copyright 2019 NXP
#
# SPDX-License-Identifier: Apache-2.0
menuconfig ENTROPY_RV32M1_TRNG
bool "RV32M1 TRNG driver"
depends on ENTROPY_GENERATOR && SOC_OPENISA_RV32M1_RISCV32
select ENTROPY_HAS_DRIVER
help
This option enables the true random number generator (TRNG)
driver based on the RV32M1 TRNG driver.

View file

@ -0,0 +1,62 @@
/*
* Copyright 2019 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <device.h>
#include <entropy.h>
#include <random/rand32.h>
#include <init.h>
#include "fsl_trng.h"
struct rv32m1_entropy_config {
TRNG_Type *base;
};
static int entropy_rv32m1_trng_get_entropy(struct device *dev, u8_t *buffer,
u16_t length)
{
const struct rv32m1_entropy_config *config = dev->config->config_info;
status_t status;
ARG_UNUSED(dev);
status = TRNG_GetRandomData(config->base, buffer, length);
__ASSERT_NO_MSG(!status);
return 0;
}
static const struct entropy_driver_api entropy_rv32m1_trng_api_funcs = {
.get_entropy = entropy_rv32m1_trng_get_entropy
};
static struct rv32m1_entropy_config entropy_rv32m1_config = {
.base = TRNG
};
static int entropy_rv32m1_trng_init(struct device *);
DEVICE_AND_API_INIT(entropy_rv32m1_trng, CONFIG_ENTROPY_NAME,
entropy_rv32m1_trng_init, NULL, &entropy_rv32m1_config,
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&entropy_rv32m1_trng_api_funcs);
static int entropy_rv32m1_trng_init(struct device *dev)
{
const struct rv32m1_entropy_config *config = dev->config->config_info;
trng_config_t conf;
status_t status;
ARG_UNUSED(dev);
status = TRNG_GetDefaultConfig(&conf);
__ASSERT_NO_MSG(!status);
status = TRNG_Init(config->base, &conf);
__ASSERT_NO_MSG(!status);
return 0;
}