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
|
|
|
|
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/drivers/hwinfo.h>
|
2019-09-11 23:35:02 +08:00
|
|
|
#include <soc.h>
|
|
|
|
#include <string.h>
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/device.h>
|
|
|
|
#include <zephyr/sys/util.h>
|
2019-09-11 23:35:02 +08:00
|
|
|
|
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
|
|
|
{
|
2022-04-14 20:16:39 +08:00
|
|
|
uint32_t addr = DT_INST_REG_ADDR(0);
|
|
|
|
ssize_t end = MIN(length, DT_INST_REG_ADDR(0) / 4 *
|
|
|
|
CONFIG_LITEX_CSR_DATA_WIDTH / 8);
|
2019-09-11 23:35:02 +08:00
|
|
|
for (int i = 0; i < end; i++) {
|
2022-04-14 20:16:39 +08:00
|
|
|
#if CONFIG_LITEX_CSR_DATA_WIDTH == 8
|
|
|
|
buffer[i] = litex_read8(addr);
|
|
|
|
addr += 4;
|
|
|
|
#elif CONFIG_LITEX_CSR_DATA_WIDTH == 32
|
|
|
|
buffer[i] = (uint8_t)(litex_read32(addr) >> (addr % 4 * 8));
|
|
|
|
addr += 1;
|
|
|
|
#else
|
|
|
|
#error Unsupported CSR data width
|
|
|
|
#endif
|
2019-09-11 23:35:02 +08:00
|
|
|
}
|
|
|
|
return end;
|
|
|
|
}
|