diff --git a/drivers/hwinfo/CMakeLists.txt b/drivers/hwinfo/CMakeLists.txt index 15b3b71f498..711aa4d8794 100644 --- a/drivers/hwinfo/CMakeLists.txt +++ b/drivers/hwinfo/CMakeLists.txt @@ -8,5 +8,6 @@ zephyr_sources_ifdef(CONFIG_HWINFO_NRF hwinfo_nrf.c) zephyr_sources_ifdef(CONFIG_HWINFO_MCUX_SIM hwinfo_mcux_sim.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_SHELL hwinfo_shell.c) diff --git a/drivers/hwinfo/Kconfig b/drivers/hwinfo/Kconfig index c6120cbd2a3..cd38b009b6d 100644 --- a/drivers/hwinfo/Kconfig +++ b/drivers/hwinfo/Kconfig @@ -55,4 +55,11 @@ config HWINFO_SAM help Enable Atmel SAM hwinfo driver. +config HWINFO_SAM0 + bool "Atmel SAM0 device ID" + default y + depends on SOC_FAMILY_SAM0 + help + Enable Atmel SAM0 hwinfo driver. + endif diff --git a/drivers/hwinfo/hwinfo_sam0.c b/drivers/hwinfo/hwinfo_sam0.c new file mode 100644 index 00000000000..be87d9939a8 --- /dev/null +++ b/drivers/hwinfo/hwinfo_sam0.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2019 ML!PA Consulting GmbH + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +struct sam0_uid { + u32_t id[4]; +}; + +ssize_t z_impl_hwinfo_get_device_id(u8_t *buffer, size_t length) +{ + struct sam0_uid dev_id; + + dev_id.id[0] = *(const u32_t *) DT_ATMEL_SAM0_ID_0_BASE_ADDRESS_0; + dev_id.id[1] = *(const u32_t *) DT_ATMEL_SAM0_ID_0_BASE_ADDRESS_1; + dev_id.id[2] = *(const u32_t *) DT_ATMEL_SAM0_ID_0_BASE_ADDRESS_2; + dev_id.id[3] = *(const u32_t *) DT_ATMEL_SAM0_ID_0_BASE_ADDRESS_3; + + if (length > sizeof(dev_id.id)) { + length = sizeof(dev_id.id); + } + + memcpy(buffer, dev_id.id, length); + + return length; +} diff --git a/dts/arm/atmel/samd.dtsi b/dts/arm/atmel/samd.dtsi index 80f58a49ebe..60f19b006e3 100644 --- a/dts/arm/atmel/samd.dtsi +++ b/dts/arm/atmel/samd.dtsi @@ -25,6 +25,14 @@ reg = <0x20000000 0x8000>; }; + id: device_id@0 { + compatible = "atmel,sam0-id"; + reg = <0x0080A00C 0x4>, + <0x0080A040 0x4>, + <0x0080A044 0x4>, + <0x0080A048 0x4>; + }; + soc { nvmctrl: nvmctrl@41004000 { compatible = "atmel,sam0-nvmctrl"; diff --git a/dts/bindings/arm/atmel,sam0-device_id.yaml b/dts/bindings/arm/atmel,sam0-device_id.yaml new file mode 100644 index 00000000000..8bc85ffef32 --- /dev/null +++ b/dts/bindings/arm/atmel,sam0-device_id.yaml @@ -0,0 +1,21 @@ +--- +title: Atmel Device ID (Serial Number) binding +version: 0.1 + +description: > + Binding for locating the Device ID (serial number) on Atmel SAM0 devices. + +properties: + compatible: + type: string + category: required + description: compatible strings + constraint: "atmel,sam0-id" + generation: define + + reg: + type: array + category: required + description: Location of Device ID words in memory + generation: define +...