zephyr/drivers/entropy/entropy_litex.c
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00

66 lines
1.4 KiB
C

/*
* Copyright (c) 2019 Antmicro <www.antmicro.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT litex_prbs
#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_REG_ADDR(0))
#define PRBS_WIDTH DT_INST_REG_SIZE(0)
#define SUBREG_SIZE_BIT 8
static inline unsigned int prbs_read(volatile uint32_t *reg_status,
volatile uint32_t reg_width)
{
uint32_t shifted_data, shift, i;
uint32_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, uint8_t *buffer,
uint16_t length)
{
while (length > 0) {
size_t to_copy;
uint32_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, DT_INST_LABEL(0),
entropy_prbs_init, NULL, NULL,
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&entropy_prbs_api);