2019-07-19 21:22:22 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Antmicro <www.antmicro.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2020-03-25 04:58:31 +08:00
|
|
|
#define DT_DRV_COMPAT litex_prbs
|
|
|
|
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/device.h>
|
|
|
|
#include <zephyr/drivers/entropy.h>
|
2019-07-19 21:22:22 +08:00
|
|
|
#include <errno.h>
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/init.h>
|
2019-07-19 21:22:22 +08:00
|
|
|
#include <soc.h>
|
|
|
|
#include <string.h>
|
includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.
The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.
NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-25 15:58:46 +08:00
|
|
|
#include <zephyr/kernel.h>
|
2019-07-19 21:22:22 +08:00
|
|
|
|
2022-04-11 23:24:18 +08:00
|
|
|
#define PRBS_STATUS DT_INST_REG_ADDR(0)
|
2020-03-25 04:58:31 +08:00
|
|
|
#define PRBS_WIDTH DT_INST_REG_SIZE(0)
|
2019-07-19 21:22:22 +08:00
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int entropy_prbs_get_entropy(const struct device *dev, uint8_t *buffer,
|
2020-05-28 00:26:57 +08:00
|
|
|
uint16_t length)
|
2019-07-19 21:22:22 +08:00
|
|
|
{
|
|
|
|
while (length > 0) {
|
|
|
|
size_t to_copy;
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t value;
|
2019-07-19 21:22:22 +08:00
|
|
|
|
2022-04-11 23:24:18 +08:00
|
|
|
value = litex_read(PRBS_STATUS, PRBS_WIDTH);
|
2019-07-19 21:22:22 +08:00
|
|
|
to_copy = MIN(length, sizeof(value));
|
|
|
|
|
|
|
|
memcpy(buffer, &value, to_copy);
|
|
|
|
buffer += to_copy;
|
|
|
|
length -= to_copy;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-01 02:33:38 +08:00
|
|
|
static int entropy_prbs_init(const struct device *dev)
|
2019-07-19 21:22:22 +08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct entropy_driver_api entropy_prbs_api = {
|
|
|
|
.get_entropy = entropy_prbs_get_entropy
|
|
|
|
};
|
|
|
|
|
2020-12-11 00:51:54 +08:00
|
|
|
DEVICE_DT_INST_DEFINE(0,
|
2021-04-28 16:39:21 +08:00
|
|
|
entropy_prbs_init, NULL, NULL, NULL,
|
2021-10-20 05:14:27 +08:00
|
|
|
PRE_KERNEL_1, CONFIG_ENTROPY_INIT_PRIORITY,
|
2019-07-19 21:22:22 +08:00
|
|
|
&entropy_prbs_api);
|