Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

driver: hwinfo: npcx: Add hwinfo driver support in npcx family. #32602

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions boards/arm/npcx7m6fb_evb/npcx7m6fb_evb_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions drivers/hwinfo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 8 additions & 0 deletions drivers/hwinfo/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
73 changes: 73 additions & 0 deletions drivers/hwinfo/hwinfo_npcx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2021 Nuvoton Technology Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <device.h>
#include <drivers/hwinfo.h>
#include <soc.h>
#include <string.h>

/* 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;
}