2019-09-11 23:35:02 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Antmicro <www.antmicro.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2020-03-25 04:58:31 +08:00
|
|
|
#define DT_DRV_COMPAT litex_dna0
|
|
|
|
|
2019-09-11 23:35:02 +08:00
|
|
|
#include <drivers/hwinfo.h>
|
|
|
|
#include <soc.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <device.h>
|
|
|
|
#include <sys/util.h>
|
|
|
|
|
2020-05-28 00:26:57 +08:00
|
|
|
ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
|
2019-09-11 23:35:02 +08:00
|
|
|
{
|
2020-05-28 00:26:57 +08:00
|
|
|
uint32_t volatile *ptr = (uint32_t volatile *)(DT_INST_REG_ADDR(0));
|
|
|
|
ssize_t end = MIN(length, (DT_INST_REG_SIZE(0) / sizeof(uint32_t)));
|
2019-09-11 23:35:02 +08:00
|
|
|
|
|
|
|
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 */
|
2020-05-28 00:26:57 +08:00
|
|
|
buffer[i] = (uint8_t)(ptr[i] & 0xff);
|
2019-09-11 23:35:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return end;
|
|
|
|
}
|