drivers: hwinfo: Adds Ambiq hwinfo support
This commit adds support for the hwinfo for Apollo4P SoCs Signed-off-by: Richard Wheatley <richard.wheatley@ambiq.com>
This commit is contained in:
parent
2e072ad017
commit
e1e78a5f08
6 changed files with 154 additions and 1 deletions
|
@ -14,6 +14,7 @@ supported:
|
||||||
- gpio
|
- gpio
|
||||||
- spi
|
- spi
|
||||||
- i2c
|
- i2c
|
||||||
|
- hwinfo
|
||||||
testing:
|
testing:
|
||||||
ignore_tags:
|
ignore_tags:
|
||||||
- net
|
- net
|
||||||
|
|
|
@ -29,3 +29,4 @@ zephyr_library_sources_ifdef(CONFIG_HWINFO_SMARTBOND hwinfo_smartbond.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_HWINFO_STM32 hwinfo_stm32.c)
|
zephyr_library_sources_ifdef(CONFIG_HWINFO_STM32 hwinfo_stm32.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_HWINFO_ANDES hwinfo_andes.c)
|
zephyr_library_sources_ifdef(CONFIG_HWINFO_ANDES hwinfo_andes.c)
|
||||||
zephyr_library_sources_ifdef(CONFIG_HWINFO_RW61X hwinfo_rw61x.c)
|
zephyr_library_sources_ifdef(CONFIG_HWINFO_RW61X hwinfo_rw61x.c)
|
||||||
|
zephyr_library_sources_ifdef(CONFIG_HWINFO_AMBIQ hwinfo_ambiq.c)
|
||||||
|
|
|
@ -200,4 +200,13 @@ config HWINFO_RW61X
|
||||||
help
|
help
|
||||||
Enable RW61X hwinfo driver
|
Enable RW61X hwinfo driver
|
||||||
|
|
||||||
|
config HWINFO_AMBIQ
|
||||||
|
bool "AMBIQ hwinfo"
|
||||||
|
default y
|
||||||
|
depends on SOC_SERIES_APOLLO4X
|
||||||
|
select AMBIQ_HAL
|
||||||
|
select AMBIQ_HAL_USE_HWINFO
|
||||||
|
help
|
||||||
|
Enable AMBIQ hwinfo driver
|
||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
137
drivers/hwinfo/hwinfo_ambiq.c
Normal file
137
drivers/hwinfo/hwinfo_ambiq.c
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Ambiq
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <am_mcu_apollo.h>
|
||||||
|
#include <zephyr/drivers/hwinfo.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <zephyr/sys/byteorder.h>
|
||||||
|
|
||||||
|
ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length)
|
||||||
|
{
|
||||||
|
|
||||||
|
struct ambiq_hwinfo {
|
||||||
|
/* Ambiq Chip ID0 */
|
||||||
|
uint32_t chip_id_0;
|
||||||
|
/* Ambiq Chip ID1 */
|
||||||
|
uint32_t chip_id_1;
|
||||||
|
/* Ambiq Factory Trim Revision */
|
||||||
|
/* Can be used in Ambiq HAL for additional code support */
|
||||||
|
uint32_t factory_trim_version;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ambiq_hwinfo dev_hw_info = {0};
|
||||||
|
|
||||||
|
/* Contains the HAL hardware information about the device. */
|
||||||
|
am_hal_mcuctrl_device_t mcu_ctrl_device;
|
||||||
|
|
||||||
|
am_hal_mram_info_read(1, AM_REG_INFO1_TRIM_REV_O / 4, 1, &dev_hw_info.factory_trim_version);
|
||||||
|
am_hal_mcuctrl_info_get(AM_HAL_MCUCTRL_INFO_DEVICEID, &mcu_ctrl_device);
|
||||||
|
|
||||||
|
dev_hw_info.chip_id_0 = mcu_ctrl_device.ui32ChipID0;
|
||||||
|
dev_hw_info.chip_id_1 = mcu_ctrl_device.ui32ChipID1;
|
||||||
|
|
||||||
|
if (length > sizeof(dev_hw_info)) {
|
||||||
|
length = sizeof(dev_hw_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
dev_hw_info.chip_id_0 = BSWAP_32(dev_hw_info.chip_id_0);
|
||||||
|
dev_hw_info.chip_id_1 = BSWAP_32(dev_hw_info.chip_id_1);
|
||||||
|
dev_hw_info.factory_trim_version = BSWAP_32(dev_hw_info.factory_trim_version);
|
||||||
|
memcpy(buffer, &dev_hw_info, length);
|
||||||
|
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
int z_impl_hwinfo_get_reset_cause(uint32_t *cause)
|
||||||
|
{
|
||||||
|
uint32_t flags = 0;
|
||||||
|
uint32_t reset_status = 0;
|
||||||
|
am_hal_reset_status_t status = {0};
|
||||||
|
|
||||||
|
/* Print out reset status register upon entry */
|
||||||
|
am_hal_reset_status_get(&status);
|
||||||
|
reset_status = status.eStatus;
|
||||||
|
|
||||||
|
/* EXTERNAL PIN */
|
||||||
|
if (reset_status & AM_HAL_RESET_STATUS_EXTERNAL) {
|
||||||
|
flags |= RESET_PIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* POWER CYCLE */
|
||||||
|
if (reset_status & AM_HAL_RESET_STATUS_POR) {
|
||||||
|
flags |= RESET_POR;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* BROWNOUT DETECTOR */
|
||||||
|
if (reset_status & AM_HAL_RESET_STATUS_BOD) {
|
||||||
|
flags |= RESET_BROWNOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SOFTWARE POR */
|
||||||
|
if (reset_status & AM_HAL_RESET_STATUS_SWPOR) {
|
||||||
|
flags |= RESET_SOFTWARE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SOFTWARE POI */
|
||||||
|
if (reset_status & AM_HAL_RESET_STATUS_SWPOI) {
|
||||||
|
flags |= RESET_SOFTWARE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DEBUGGER */
|
||||||
|
if (reset_status & AM_HAL_RESET_STATUS_DEBUGGER) {
|
||||||
|
flags |= RESET_DEBUG;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* WATCHDOG */
|
||||||
|
if (reset_status & AM_HAL_RESET_STATUS_WDT) {
|
||||||
|
flags |= RESET_WATCHDOG;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* BOUNREG */
|
||||||
|
if (reset_status & AM_HAL_RESET_STATUS_BOUNREG) {
|
||||||
|
flags |= RESET_HARDWARE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* BOCORE */
|
||||||
|
if (reset_status & AM_HAL_RESET_STATUS_BOCORE) {
|
||||||
|
flags |= RESET_HARDWARE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* BOMEM */
|
||||||
|
if (reset_status & AM_HAL_RESET_STATUS_BOMEM) {
|
||||||
|
flags |= RESET_HARDWARE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* BOHPMEM */
|
||||||
|
if (reset_status & AM_HAL_RESET_STATUS_BOHPMEM) {
|
||||||
|
flags |= RESET_HARDWARE;
|
||||||
|
}
|
||||||
|
|
||||||
|
*cause = flags;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int z_impl_hwinfo_clear_reset_cause(void)
|
||||||
|
{
|
||||||
|
/* SBL maintains the RSTGEN->STAT register in
|
||||||
|
* INFO1 space even upon clearing RSTGEN->STAT
|
||||||
|
* register.
|
||||||
|
* - INFO1_RESETSTATUS
|
||||||
|
*/
|
||||||
|
|
||||||
|
return -ENOSYS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int z_impl_hwinfo_get_supported_reset_cause(uint32_t *supported)
|
||||||
|
{
|
||||||
|
*supported = RESET_PIN
|
||||||
|
| RESET_SOFTWARE
|
||||||
|
| RESET_POR
|
||||||
|
| RESET_WATCHDOG
|
||||||
|
| RESET_HARDWARE
|
||||||
|
| RESET_BROWNOUT;
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -45,4 +45,9 @@ config AMBIQ_HAL_USE_MSPI
|
||||||
help
|
help
|
||||||
Use the MSPI driver from Ambiq HAL
|
Use the MSPI driver from Ambiq HAL
|
||||||
|
|
||||||
|
config AMBIQ_HAL_USE_HWINFO
|
||||||
|
bool
|
||||||
|
help
|
||||||
|
Use the HWINFO driver from Ambiq HAL
|
||||||
|
|
||||||
endif # AMBIQ_HAL
|
endif # AMBIQ_HAL
|
||||||
|
|
2
west.yml
2
west.yml
|
@ -142,7 +142,7 @@ manifest:
|
||||||
groups:
|
groups:
|
||||||
- hal
|
- hal
|
||||||
- name: hal_ambiq
|
- name: hal_ambiq
|
||||||
revision: 705f1cbb1ccbdaac7613eb7b27c208c8f592e0c4
|
revision: f6858cb3fe3d44945a23d114b7feeeac22ce71cf
|
||||||
path: modules/hal/ambiq
|
path: modules/hal/ambiq
|
||||||
groups:
|
groups:
|
||||||
- hal
|
- hal
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue