1 /*
2  * Copyright (c) 2019 ML!PA Consulting GmbH
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #define DT_DRV_COMPAT atmel_sam0_id
8 
9 #include <soc.h>
10 #include <zephyr/drivers/hwinfo.h>
11 #include <string.h>
12 #include <zephyr/sys/byteorder.h>
13 
14 struct sam0_uid {
15 	uint32_t id[4];
16 };
17 
z_impl_hwinfo_get_device_id(uint8_t * buffer,size_t length)18 ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
19 {
20 	struct sam0_uid dev_id;
21 
22 	dev_id.id[0] = sys_cpu_to_be32(*(const uint32_t *)
23 				       DT_INST_REG_ADDR_BY_IDX(0, 0));
24 	dev_id.id[1] = sys_cpu_to_be32(*(const uint32_t *)
25 				       DT_INST_REG_ADDR_BY_IDX(0, 1));
26 	dev_id.id[2] = sys_cpu_to_be32(*(const uint32_t *)
27 				       DT_INST_REG_ADDR_BY_IDX(0, 2));
28 	dev_id.id[3] = sys_cpu_to_be32(*(const uint32_t *)
29 				       DT_INST_REG_ADDR_BY_IDX(0, 3));
30 
31 	if (length > sizeof(dev_id.id)) {
32 		length = sizeof(dev_id.id);
33 	}
34 
35 	memcpy(buffer, dev_id.id, length);
36 
37 	return length;
38 }
39