zephyr/drivers/entropy/entropy_mcux_rng.c
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00

58 lines
1.2 KiB
C

/*
* 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;
};
static int entropy_mcux_rng_get_entropy(const struct device *dev,
uint8_t *buffer,
uint16_t length)
{
const struct mcux_entropy_config *config = dev->config;
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)
};
static int entropy_mcux_rng_init(const struct device *);
DEVICE_AND_API_INIT(entropy_mcux_rng, DT_INST_LABEL(0),
entropy_mcux_rng_init, NULL, &entropy_mcux_config,
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&entropy_mcux_rng_api_funcs);
static int entropy_mcux_rng_init(const struct device *dev)
{
ARG_UNUSED(dev);
RNG_Init(entropy_mcux_config.base);
return 0;
}