Skip to content

Commit c430670

Browse files
benpicconashif
authored andcommitted
drivers: hwinfo: add driver support for Atmel SAM0 device ID
Add driver support for Atmel SAM0 device ID, which is 16-bytes long. The device ID can simply be read from memory at a known location, but the location is only described in the data sheet, not in ASF. For SAMD2x it's 0x0080A00C, 0x0080A040, 0x0080A044 & 0x0080A048. For SAMD5x it's 0x008061FC, 0x00806010, 0x00806014 & 0x00806018. This adds a new property to the device tree to define the device ID registers for this SoC family. Signed-off-by: Benjamin Valentin <[email protected]>
1 parent f0c9852 commit c430670

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

drivers/hwinfo/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ zephyr_sources_ifdef(CONFIG_HWINFO_NRF hwinfo_nrf.c)
88
zephyr_sources_ifdef(CONFIG_HWINFO_MCUX_SIM hwinfo_mcux_sim.c)
99
zephyr_sources_ifdef(CONFIG_HWINFO_IMXRT hwinfo_imxrt.c)
1010
zephyr_sources_ifdef(CONFIG_HWINFO_SAM hwinfo_sam.c)
11+
zephyr_sources_ifdef(CONFIG_HWINFO_SAM0 hwinfo_sam0.c)
1112

1213
zephyr_sources_ifdef(CONFIG_HWINFO_SHELL hwinfo_shell.c)

drivers/hwinfo/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,11 @@ config HWINFO_SAM
5555
help
5656
Enable Atmel SAM hwinfo driver.
5757

58+
config HWINFO_SAM0
59+
bool "Atmel SAM0 device ID"
60+
default y
61+
depends on SOC_FAMILY_SAM0
62+
help
63+
Enable Atmel SAM0 hwinfo driver.
64+
5865
endif

drivers/hwinfo/hwinfo_sam0.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2019 ML!PA Consulting GmbH
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <soc.h>
8+
#include <hwinfo.h>
9+
#include <string.h>
10+
11+
struct sam0_uid {
12+
u32_t id[4];
13+
};
14+
15+
ssize_t z_impl_hwinfo_get_device_id(u8_t *buffer, size_t length)
16+
{
17+
struct sam0_uid dev_id;
18+
19+
dev_id.id[0] = *(const u32_t *) DT_ATMEL_SAM0_ID_0_BASE_ADDRESS_0;
20+
dev_id.id[1] = *(const u32_t *) DT_ATMEL_SAM0_ID_0_BASE_ADDRESS_1;
21+
dev_id.id[2] = *(const u32_t *) DT_ATMEL_SAM0_ID_0_BASE_ADDRESS_2;
22+
dev_id.id[3] = *(const u32_t *) DT_ATMEL_SAM0_ID_0_BASE_ADDRESS_3;
23+
24+
if (length > sizeof(dev_id.id)) {
25+
length = sizeof(dev_id.id);
26+
}
27+
28+
memcpy(buffer, dev_id.id, length);
29+
30+
return length;
31+
}

dts/arm/atmel/samd.dtsi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
reg = <0x20000000 0x8000>;
2626
};
2727

28+
id: device_id@0 {
29+
compatible = "atmel,sam0-id";
30+
reg = <0x0080A00C 0x4>,
31+
<0x0080A040 0x4>,
32+
<0x0080A044 0x4>,
33+
<0x0080A048 0x4>;
34+
};
35+
2836
soc {
2937
nvmctrl: nvmctrl@41004000 {
3038
compatible = "atmel,sam0-nvmctrl";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: Atmel Device ID (Serial Number) binding
3+
version: 0.1
4+
5+
description: >
6+
Binding for locating the Device ID (serial number) on Atmel SAM0 devices.
7+
8+
properties:
9+
compatible:
10+
type: string
11+
category: required
12+
description: compatible strings
13+
constraint: "atmel,sam0-id"
14+
generation: define
15+
16+
reg:
17+
type: array
18+
category: required
19+
description: Location of Device ID words in memory
20+
generation: define
21+
...

0 commit comments

Comments
 (0)