2020-05-04 22:32:31 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Linaro Limited.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DT_DRV_COMPAT nxp_lpc_rng
|
|
|
|
|
|
|
|
#include <device.h>
|
|
|
|
#include <drivers/entropy.h>
|
|
|
|
#include <random/rand32.h>
|
|
|
|
#include <init.h>
|
|
|
|
|
|
|
|
#include "fsl_rng.h"
|
|
|
|
|
|
|
|
struct mcux_entropy_config {
|
|
|
|
RNG_Type *base;
|
|
|
|
};
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int entropy_mcux_rng_get_entropy(const struct device *dev,
|
|
|
|
uint8_t *buffer,
|
2020-05-28 00:26:57 +08:00
|
|
|
uint16_t length)
|
2020-05-04 22:32:31 +08:00
|
|
|
{
|
2020-05-29 02:44:16 +08:00
|
|
|
const struct mcux_entropy_config *config = dev->config;
|
2020-05-04 22:32:31 +08:00
|
|
|
status_t status;
|
|
|
|
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
|
|
|
status = RNG_GetRandomData(config->base, buffer, length);
|
|
|
|
__ASSERT_NO_MSG(!status);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct entropy_driver_api entropy_mcux_rng_api_funcs = {
|
|
|
|
.get_entropy = entropy_mcux_rng_get_entropy
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct mcux_entropy_config entropy_mcux_config = {
|
|
|
|
.base = (RNG_Type *)DT_INST_REG_ADDR(0)
|
|
|
|
};
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int entropy_mcux_rng_init(const struct device *);
|
2020-05-04 22:32:31 +08:00
|
|
|
|
2020-12-11 00:51:54 +08:00
|
|
|
DEVICE_DT_INST_DEFINE(0,
|
2021-04-28 16:39:21 +08:00
|
|
|
entropy_mcux_rng_init, NULL, NULL,
|
2020-12-11 00:51:54 +08:00
|
|
|
&entropy_mcux_config,
|
2021-10-20 05:14:27 +08:00
|
|
|
PRE_KERNEL_1, CONFIG_ENTROPY_INIT_PRIORITY,
|
2020-05-04 22:32:31 +08:00
|
|
|
&entropy_mcux_rng_api_funcs);
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int entropy_mcux_rng_init(const struct device *dev)
|
2020-05-04 22:32:31 +08:00
|
|
|
{
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
|
|
|
RNG_Init(entropy_mcux_config.base);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|