drivers: entropy: Add driver for LiteX PRBS module
This adds PRBS ranom number generator driver for LiteX SoC builder with its bindings. Signed-off-by: Pawel Czarnecki <pczarnecki@internships.antmicro.com> Signed-off-by: Mateusz Holenko <mholenko@antmicro.com>
This commit is contained in:
parent
3b733b5282
commit
894b488b06
|
@ -128,6 +128,7 @@
|
||||||
/drivers/ps2/ @albertofloyd @franciscomunoz @scottwcpg
|
/drivers/ps2/ @albertofloyd @franciscomunoz @scottwcpg
|
||||||
/drivers/kscan/ @albertofloyd @franciscomunoz @scottwcpg
|
/drivers/kscan/ @albertofloyd @franciscomunoz @scottwcpg
|
||||||
/drivers/ethernet/ @jukkar @tbursztyka @pfalcon
|
/drivers/ethernet/ @jukkar @tbursztyka @pfalcon
|
||||||
|
/drivers/entropy/*litex* @mateusz-holenko @kgugala @pgielda
|
||||||
/drivers/flash/ @nashif @nvlsianpu
|
/drivers/flash/ @nashif @nvlsianpu
|
||||||
/drivers/flash/*nrf* @nvlsianpu
|
/drivers/flash/*nrf* @nvlsianpu
|
||||||
/drivers/flash/*spi_nor* @pabigot
|
/drivers/flash/*spi_nor* @pabigot
|
||||||
|
|
|
@ -9,6 +9,7 @@ zephyr_library_sources_ifdef(CONFIG_ENTROPY_MCUX_TRNG entropy_mcux_trng
|
||||||
zephyr_library_sources_ifdef(CONFIG_ENTROPY_NRF5_RNG entropy_nrf5.c)
|
zephyr_library_sources_ifdef(CONFIG_ENTROPY_NRF5_RNG entropy_nrf5.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_ENTROPY_SAM_RNG entropy_sam.c)
|
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_ENTROPY_STM32_RNG entropy_stm32.c)
|
||||||
|
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_FAKE_ENTROPY_NATIVE_POSIX fake_entropy_native_posix.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_USERSPACE entropy_handlers.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_RV32M1_TRNG entropy_rv32m1_trng.c)
|
||||||
|
|
|
@ -18,6 +18,7 @@ source "drivers/entropy/Kconfig.nrf5"
|
||||||
source "drivers/entropy/Kconfig.sam"
|
source "drivers/entropy/Kconfig.sam"
|
||||||
source "drivers/entropy/Kconfig.native_posix"
|
source "drivers/entropy/Kconfig.native_posix"
|
||||||
source "drivers/entropy/Kconfig.rv32m1"
|
source "drivers/entropy/Kconfig.rv32m1"
|
||||||
|
source "drivers/entropy/Kconfig.litex"
|
||||||
|
|
||||||
config ENTROPY_HAS_DRIVER
|
config ENTROPY_HAS_DRIVER
|
||||||
bool
|
bool
|
||||||
|
|
13
drivers/entropy/Kconfig.litex
Normal file
13
drivers/entropy/Kconfig.litex
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# LiteX PRBS entropy generator driver configuration
|
||||||
|
|
||||||
|
# Copyright (c) 2019 Antmicro <www.antmicro.com>
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
menuconfig ENTROPY_LITEX_RNG
|
||||||
|
bool "PRBS RNG driver"
|
||||||
|
depends on SOC_RISCV32_LITEX_VEXRISCV
|
||||||
|
select ENTROPY_HAS_DRIVER
|
||||||
|
help
|
||||||
|
This option enables the RNG module, which is an entropy number
|
||||||
|
generator, based on Pseudo-Random Binary Sequences (PRBS)
|
||||||
|
for LiteX SoC builder
|
64
drivers/entropy/entropy_litex.c
Normal file
64
drivers/entropy/entropy_litex.c
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 Antmicro <www.antmicro.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <device.h>
|
||||||
|
#include <drivers/entropy.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <init.h>
|
||||||
|
#include <soc.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <zephyr.h>
|
||||||
|
|
||||||
|
#define PRBS_STATUS ((volatile uint32_t *)DT_INST_0_LITEX_PRBS_BASE_ADDRESS)
|
||||||
|
#define PRBS_WIDTH DT_INST_0_LITEX_PRBS_SIZE
|
||||||
|
#define SUBREG_SIZE_BIT 8
|
||||||
|
|
||||||
|
static inline unsigned int prbs_read(volatile u32_t *reg_status,
|
||||||
|
volatile u32_t reg_width)
|
||||||
|
{
|
||||||
|
u32_t shifted_data, shift, i;
|
||||||
|
u32_t result = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < reg_width; ++i) {
|
||||||
|
shifted_data = *(reg_status + i);
|
||||||
|
shift = (reg_width - i - 1) * SUBREG_SIZE_BIT;
|
||||||
|
result |= (shifted_data << shift);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int entropy_prbs_get_entropy(struct device *dev, u8_t *buffer,
|
||||||
|
u16_t length)
|
||||||
|
{
|
||||||
|
while (length > 0) {
|
||||||
|
size_t to_copy;
|
||||||
|
u32_t value;
|
||||||
|
|
||||||
|
value = prbs_read(PRBS_STATUS, PRBS_WIDTH);
|
||||||
|
to_copy = MIN(length, sizeof(value));
|
||||||
|
|
||||||
|
memcpy(buffer, &value, to_copy);
|
||||||
|
buffer += to_copy;
|
||||||
|
length -= to_copy;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int entropy_prbs_init(struct device *dev)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct entropy_driver_api entropy_prbs_api = {
|
||||||
|
.get_entropy = entropy_prbs_get_entropy
|
||||||
|
};
|
||||||
|
|
||||||
|
DEVICE_AND_API_INIT(entropy_prbs, CONFIG_ENTROPY_NAME,
|
||||||
|
entropy_prbs_init, NULL, NULL,
|
||||||
|
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
|
||||||
|
&entropy_prbs_api);
|
||||||
|
|
12
dts/bindings/rng/litex,prbs.yaml
Normal file
12
dts/bindings/rng/litex,prbs.yaml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# Copyright (c) 2019 Antmicro <www.antmicro.com>
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
description: LiteX PRBS
|
||||||
|
|
||||||
|
compatible: "litex,prbs"
|
||||||
|
|
||||||
|
include: base.yaml
|
||||||
|
|
||||||
|
properties:
|
||||||
|
reg:
|
||||||
|
required: true
|
Loading…
Reference in a new issue