From c5d11aceccde54cd025e78c0b7ab090d6e1e03bb Mon Sep 17 00:00:00 2001 From: Mulin Chao Date: Tue, 23 Feb 2021 19:45:37 -0800 Subject: [PATCH] driver: hwinfo: npcx: Add hwinfo driver support in npcx family. Add hwinfo driver support in npcx family. Signed-off-by: Mulin Chao --- .../arm/npcx7m6fb_evb/npcx7m6fb_evb_defconfig | 3 + drivers/hwinfo/CMakeLists.txt | 1 + drivers/hwinfo/Kconfig | 8 ++ drivers/hwinfo/hwinfo_npcx.c | 73 +++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 drivers/hwinfo/hwinfo_npcx.c diff --git a/boards/arm/npcx7m6fb_evb/npcx7m6fb_evb_defconfig b/boards/arm/npcx7m6fb_evb/npcx7m6fb_evb_defconfig index 3cc7f5bc2db7a5..535b54bacdcd5d 100644 --- a/boards/arm/npcx7m6fb_evb/npcx7m6fb_evb_defconfig +++ b/boards/arm/npcx7m6fb_evb/npcx7m6fb_evb_defconfig @@ -48,6 +48,9 @@ CONFIG_ESPI=y # I2C Driver CONFIG_I2C=y +# HWINFO Driver +CONFIG_HWINFO=y + # Console Driver CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y diff --git a/drivers/hwinfo/CMakeLists.txt b/drivers/hwinfo/CMakeLists.txt index 099b1361221b09..c837d90d10269b 100644 --- a/drivers/hwinfo/CMakeLists.txt +++ b/drivers/hwinfo/CMakeLists.txt @@ -14,4 +14,5 @@ zephyr_sources_ifdef(CONFIG_HWINFO_SAM0 hwinfo_sam0.c) zephyr_sources_ifdef(CONFIG_HWINFO_LITEX hwinfo_litex.c) zephyr_sources_ifdef(CONFIG_HWINFO_PSOC6 hwinfo_psoc6.c) zephyr_sources_ifdef(CONFIG_HWINFO_GECKO hwinfo_gecko.c) +zephyr_sources_ifdef(CONFIG_HWINFO_NPCX hwinfo_npcx.c) zephyr_sources_ifdef(CONFIG_HWINFO_SHELL hwinfo_shell.c) diff --git a/drivers/hwinfo/Kconfig b/drivers/hwinfo/Kconfig index bbdc04e8cd7d08..ec5773bda6b9ce 100644 --- a/drivers/hwinfo/Kconfig +++ b/drivers/hwinfo/Kconfig @@ -108,4 +108,12 @@ config HWINFO_GECKO help Enable Silabs GECKO hwinfo driver. +config HWINFO_NPCX + bool "Nuvoton NPCX embedded controller (EC) hwinfo driver" + default y + depends on SOC_FAMILY_NPCX + select HWINFO_HAS_DRIVER + help + Enable hwinfo driver for NPCX family of processors. + endif diff --git a/drivers/hwinfo/hwinfo_npcx.c b/drivers/hwinfo/hwinfo_npcx.c new file mode 100644 index 00000000000000..2804ce61da9159 --- /dev/null +++ b/drivers/hwinfo/hwinfo_npcx.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021 Nuvoton Technology Corporation. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +/* host module instances for hardware info */ +static struct mswc_reg *const inst_mswc = (struct mswc_reg *) + DT_REG_ADDR_BY_NAME(DT_INST(0, nuvoton_npcx_host_sub), mswc); + +/** + * @brief Receive 8-bit value that identifies a family of devices with similar + * functionality. + * + * @retval value that identifies a family of devices with similar functionality. + */ +static uint8_t npcx_hwinfo_family_id(void) +{ + return inst_mswc->SID_CR; +} + +/** + * @brief Receive 8-bit value that identifies a device group of the family. + * + * @retval value that identifies a device group of the family. + */ +static uint8_t npcx_hwinfo_chip_id(void) +{ + return inst_mswc->SRID_CR; +} + +/** + * @brief Receive 8-bit value that identifies a specific device of a group. + * + * @retval value that identifies a specific device of a group. + */ +static uint8_t npcx_hwinfo_device_id(void) +{ + return inst_mswc->DEVICE_ID_CR; +} + +/** + * @brief Receive 8-bit value that identifies the device revision. + * + * @retval value that identifies the device revision. + */ +static uint8_t npcx_hwinfo_revision(void) +{ + return inst_mswc->CHPREV_CR; +} + +ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length) +{ + uint8_t chip_info[4]; + + chip_info[0] = npcx_hwinfo_family_id(); + chip_info[1] = npcx_hwinfo_chip_id(); + chip_info[2] = npcx_hwinfo_device_id(); + chip_info[3] = npcx_hwinfo_revision(); + + if (length > sizeof(chip_info)) { + length = sizeof(chip_info); + } + + memcpy(buffer, chip_info, length); + + return length; +}