From ab1ba3d4cfb1fc1490c80e7b6af1eb5d3a5133c0 Mon Sep 17 00:00:00 2001 From: Jakub Wegnerowski Date: Wed, 11 Sep 2019 17:35:02 +0200 Subject: [PATCH] drivers: hwinfo: Add LiteX DNA driver This commit adds driver supporting reading DNA ID value for LiteX SoC builder. Signed-off-by: Jakub Wegnerowski Signed-off-by: Mateusz Holenko --- drivers/hwinfo/CMakeLists.txt | 2 +- drivers/hwinfo/Kconfig | 6 ++++++ drivers/hwinfo/hwinfo_litex.c | 25 +++++++++++++++++++++++++ dts/bindings/hwinfo/litex,dna0.yaml | 20 ++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 drivers/hwinfo/hwinfo_litex.c create mode 100644 dts/bindings/hwinfo/litex,dna0.yaml diff --git a/drivers/hwinfo/CMakeLists.txt b/drivers/hwinfo/CMakeLists.txt index 36fe7ed8b13..3fa1b484c9f 100644 --- a/drivers/hwinfo/CMakeLists.txt +++ b/drivers/hwinfo/CMakeLists.txt @@ -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) diff --git a/drivers/hwinfo/Kconfig b/drivers/hwinfo/Kconfig index e660411d6b2..77b65313d10 100644 --- a/drivers/hwinfo/Kconfig +++ b/drivers/hwinfo/Kconfig @@ -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 diff --git a/drivers/hwinfo/hwinfo_litex.c b/drivers/hwinfo/hwinfo_litex.c new file mode 100644 index 00000000000..354a45c1e2a --- /dev/null +++ b/drivers/hwinfo/hwinfo_litex.c @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2019 Antmicro + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +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; +} diff --git a/dts/bindings/hwinfo/litex,dna0.yaml b/dts/bindings/hwinfo/litex,dna0.yaml new file mode 100644 index 00000000000..48e29d226bc --- /dev/null +++ b/dts/bindings/hwinfo/litex,dna0.yaml @@ -0,0 +1,20 @@ +# +# Copyright (c) 2019 Antmicro +# +# SPDX-License-Identifier: Apache-2.0 +# + +title: LiteX DNA +description: > + This binding gives a base representation of the LiteX DNA +inherits: + !include base.yaml + +properties: + compatible: + constraint: "litex,dna0" + + reg: + category: required + +