drivers: hwinfo: andes: Improve hwinfo_andes driver
Check the driver's readiness at boot and in each function that depends on the syscon driver. Signed-off-by: Wei-Tai Lee <wtlee@andestech.com>
This commit is contained in:
parent
9ca543d7ae
commit
5f6ceefb8e
|
@ -8,6 +8,7 @@
|
|||
#include <zephyr/drivers/hwinfo.h>
|
||||
#include <zephyr/drivers/syscon.h>
|
||||
#include <string.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
|
||||
/*
|
||||
* SMU(System Management Unit) Registers for hwinfo driver
|
||||
|
@ -26,13 +27,18 @@
|
|||
|
||||
#define ANDES_RESET_STATUS_MASK BIT_MASK(5)
|
||||
|
||||
static const struct device *const syscon_dev =
|
||||
DEVICE_DT_GET(DT_NODELABEL(syscon));
|
||||
|
||||
ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
|
||||
{
|
||||
int ret = 0;
|
||||
uint8_t id[3];
|
||||
uint32_t ver;
|
||||
const struct device *const syscon_dev =
|
||||
DEVICE_DT_GET(DT_NODELABEL(syscon));
|
||||
|
||||
if (!device_is_ready(syscon_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = syscon_read_reg(syscon_dev, SMU_SYSTEMVER, &ver);
|
||||
if (ret < 0) {
|
||||
|
@ -43,9 +49,7 @@ ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
|
|||
length = sizeof(id);
|
||||
}
|
||||
|
||||
id[0] = (uint8_t)(ver >> 16);
|
||||
id[1] = (uint8_t)(ver >> 8);
|
||||
id[2] = (uint8_t)(ver >> 0);
|
||||
sys_put_le24(ver, id);
|
||||
|
||||
memcpy(buffer, id, length);
|
||||
|
||||
|
@ -56,8 +60,10 @@ int z_impl_hwinfo_get_reset_cause(uint32_t *cause)
|
|||
{
|
||||
int ret = 0;
|
||||
uint32_t reason, flags = 0;
|
||||
const struct device *const syscon_dev =
|
||||
DEVICE_DT_GET(DT_NODELABEL(syscon));
|
||||
|
||||
if (!device_is_ready(syscon_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = syscon_read_reg(syscon_dev, SMU_WRSR, &reason);
|
||||
if (ret < 0) {
|
||||
|
@ -89,8 +95,10 @@ int z_impl_hwinfo_clear_reset_cause(void)
|
|||
{
|
||||
int ret = 0;
|
||||
uint32_t reason;
|
||||
const struct device *const syscon_dev =
|
||||
DEVICE_DT_GET(DT_NODELABEL(syscon));
|
||||
|
||||
if (!device_is_ready(syscon_dev)) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = syscon_write_reg(syscon_dev, SMU_WRSR, ANDES_RESET_STATUS_MASK);
|
||||
if (ret < 0) {
|
||||
|
|
Loading…
Reference in a new issue