zephyr/drivers/entropy/entropy_mcux_trng.c
Tomasz Bursztyka 97326c0445 device: Fix structure attributes access
Since struct devconfig was merged earlier into struct device, let's fix
accessing config_info, name, ... attributes everywhere via:

grep -rlZ 'dev->config->' | xargs -0 sed -i 's/dev->config->/dev->/g'

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-05-08 23:07:44 +02:00

65 lines
1.4 KiB
C

/*
* Copyright (c) 2017 Linaro Limited.
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT nxp_kinetis_trng
#include <device.h>
#include <drivers/entropy.h>
#include <random/rand32.h>
#include <init.h>
#include "fsl_trng.h"
struct mcux_entropy_config {
TRNG_Type *base;
};
static int entropy_mcux_trng_get_entropy(struct device *dev, u8_t *buffer,
u16_t length)
{
const struct mcux_entropy_config *config = dev->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_mcux_trng_api_funcs = {
.get_entropy = entropy_mcux_trng_get_entropy
};
static struct mcux_entropy_config entropy_mcux_config = {
.base = (TRNG_Type *)DT_INST_REG_ADDR(0)
};
static int entropy_mcux_trng_init(struct device *);
DEVICE_AND_API_INIT(entropy_mcux_trng, DT_INST_LABEL(0),
entropy_mcux_trng_init, NULL, &entropy_mcux_config,
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&entropy_mcux_trng_api_funcs);
static int entropy_mcux_trng_init(struct device *dev)
{
const struct mcux_entropy_config *config = dev->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;
}