drivers: hwinfo: Add LiteX DNA driver
This commit adds driver supporting reading DNA ID value for LiteX SoC builder. Signed-off-by: Jakub Wegnerowski <jwegnerowski@internships.antmicro.com> Signed-off-by: Mateusz Holenko <mholenko@antmicro.com>
This commit is contained in:
parent
d57a3634f7
commit
ab1ba3d4cf
4 changed files with 52 additions and 1 deletions
|
@ -10,5 +10,5 @@ zephyr_sources_ifdef(CONFIG_HWINFO_ESP32 hwinfo_esp32.c)
|
|||
zephyr_sources_ifdef(CONFIG_HWINFO_IMXRT hwinfo_imxrt.c)
|
||||
zephyr_sources_ifdef(CONFIG_HWINFO_SAM hwinfo_sam.c)
|
||||
zephyr_sources_ifdef(CONFIG_HWINFO_SAM0 hwinfo_sam0.c)
|
||||
|
||||
zephyr_sources_ifdef(CONFIG_HWINFO_LITEX hwinfo_litex.c)
|
||||
zephyr_sources_ifdef(CONFIG_HWINFO_SHELL hwinfo_shell.c)
|
||||
|
|
|
@ -69,4 +69,10 @@ config HWINFO_ESP32
|
|||
help
|
||||
Enable ESP32 hwinfo driver.
|
||||
|
||||
config HWINFO_LITEX
|
||||
bool "LiteX device ID"
|
||||
default y
|
||||
depends on SOC_RISCV32_LITEX_VEXRISCV
|
||||
help
|
||||
Enable LiteX hwinfo driver
|
||||
endif
|
||||
|
|
25
drivers/hwinfo/hwinfo_litex.c
Normal file
25
drivers/hwinfo/hwinfo_litex.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Antmicro <www.antmicro.com>
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <drivers/hwinfo.h>
|
||||
#include <soc.h>
|
||||
#include <string.h>
|
||||
#include <device.h>
|
||||
#include <sys/util.h>
|
||||
|
||||
ssize_t z_impl_hwinfo_get_device_id(u8_t *buffer, size_t length)
|
||||
{
|
||||
u32_t volatile *ptr = (u32_t volatile *)(DT_INST_0_LITEX_DNA0_BASE_ADDRESS);
|
||||
ssize_t end = MIN(length, (DT_INST_0_LITEX_DNA0_SIZE / sizeof(u32_t)));
|
||||
|
||||
for (int i = 0; i < end; i++) {
|
||||
/* In LiteX even though registers are 32-bit wide, each one
|
||||
contains meaningful data only in the lowest 8 bits */
|
||||
buffer[i] = (u8_t)(ptr[i] & 0xff);
|
||||
}
|
||||
|
||||
return end;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue