summaryrefslogtreecommitdiff
path: root/chip/npcx/system-npcx9.c
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2022-09-21 14:10:01 -0700
committerTom Hughes <tomhughes@chromium.org>2022-09-22 12:49:33 -0700
commit2bcf863b492fe7ed8105c853814dba6ed32ba719 (patch)
treefcf6ce5810f9ff9e3c8cce434812dd75492269ed /chip/npcx/system-npcx9.c
parente5fb0b9ba488614b5684e640530f00821ab7b943 (diff)
parent28712dae9d7ed1e694f7622cc083afa71090d4d5 (diff)
downloadchrome-ec-2bcf863b492fe7ed8105c853814dba6ed32ba719.tar.gz
Merge remote-tracking branch cros/main into firmware-fpmcu-bloonchipper-releasefirmware-fpmcu-bloonchipper-release
Generated by: ./util/update_release_branch.py --board bloonchipper --relevant_paths_file ./util/fingerprint-relevant-paths.txt firmware- fpmcu-bloonchipper-release Relevant changes: git log --oneline e5fb0b9ba4..28712dae9d -- board/hatch_fp board/bloonchipper common/fpsensor docs/fingerprint driver/fingerprint util/getversion.sh ded9307b79 util/getversion.sh: Fix version when not in a git repo 956055e692 board: change Google USB vendor info 71b2ef709d Update license boilerplate text in source code files 33e11afda0 Revert "fpsensor: Build fpsensor source file with C++" c8d0360723 fpsensor: Build fpsensor source file with C++ bc113abd53 fpsensor: Fix g++ compiler error 150a58a0dc fpsensor: Fix fp_set_sensor_mode return type b33b5ce85b fpsensor: Remove nested designators for C++ compatibility 2e864b2539 tree-wide: const-ify argv for console commands 56d8b360f9 test: Add test for get ikm failure when seed not set 3a3d6c3690 test: Add test for fpsensor trivial key failure 233e6bbd08 fpsensor_crypto: Abstract calls to hmac_SHA256 0a041b285b docs/fingerprint: Typo correction c03fab67e2 docs/fingerprint: Fix the path of fputils.py 0b5d4baf5a util/getversion.sh: Fix empty file list handling 6e128fe760 FPMCU dev board environment with Satlab 3eb29b6aa5 builtin: Move ssize_t to sys/types.h 345d62ebd1 docs/fingerprint: Update power numbers for latest dartmonkey release c25ffdb316 common: Conditionally support printf %l and %i modifiers 9a3c514b45 test: Add a test to check if the debugger is connected 54e603413f Move standard library tests to their own file 43fa6b4bf8 docs/fingerprint: Update power numbers for latest bloonchipper release 25536f9a84 driver/fingerprint/fpc/bep/fpc_sensor_spi.c: Format with clang-format 4face99efd driver/fingerprint/fpc/libfp/fpc_sensor_pal.h: Format with clang-format 738de2b575 trng: Rename rand to trng_rand 14b8270edd docs/fingerprint: Update dragonclaw power numbers 0b268f93d1 driver/fingerprint/fpc/libfp/fpc_private.c: Format with clang-format f80da163f2 driver/fingerprint/fpc/libfp/fpc_private.h: Format with clang-format 5e9c85c9b1 driver/fingerprint/fpc/libfp/fpc_sensor_pal.c: Format with clang-format c1f9dd3cf8 driver/fingerprint/fpc/libfp/fpc_bio_algorithm.h: Format with clang-format eb1e1bed8d driver/fingerprint/fpc/libfp/fpc1145_private.h: Format with clang-format 6e7b611821 driver/fingerprint/fpc/bep/fpc_bio_algorithm.h: Format with clang-format e0589cd5e2 driver/fingerprint/fpc/bep/fpc1035_private.h: Format with clang-format 7905e556a0 common/fpsensor/fpsensor_crypto.c: Format with clang-format 21289d170c driver/fingerprint/fpc/bep/fpc1025_private.h: Format with clang-format 98a20f937e common/fpsensor/fpsensor_state.c: Format with clang-format a2d255d8af common/fpsensor/fpsensor.c: Format with clang-format 73055eeb3f driver/fingerprint/fpc/bep/fpc_private.c: Format with clang-format 0f7b5cb509 common/fpsensor/fpsensor_private.h: Format with clang-format 1ceade6e65 driver/fingerprint/fpc/bep/fpc_private.h: Format with clang-format dc3e9008b8 board/hatch_fp/board.h: Format with clang-format dca9d74321 Revert "trng: Rename rand to trng_rand" a6b0b3554f trng: Rename rand to trng_rand 28d0b75b70 third_party/boringssl: Remove unused header BRANCH=None BUG=b:246424843 b:234181908 b:244781166 b:234181908 b:244387210 BUG=b:242720240 chromium:1098010 b:180945056 b:236025198 b:234181908 BUG=b:234181908 b:237344361 b:131913998 b:236386294 b:234143158 BUG=b:234781655 b:215613183 b:242720910 TEST=`make -j buildall` TEST=./test/run_device_tests.py --board bloonchipper Test "aes": PASSED Test "cec": PASSED Test "cortexm_fpu": PASSED Test "crc": PASSED Test "flash_physical": PASSED Test "flash_write_protect": PASSED Test "fpsensor_hw": PASSED Test "fpsensor_spi_ro": PASSED Test "fpsensor_spi_rw": PASSED Test "fpsensor_uart_ro": PASSED Test "fpsensor_uart_rw": PASSED Test "mpu_ro": PASSED Test "mpu_rw": PASSED Test "mutex": PASSED Test "pingpong": PASSED Test "printf": PASSED Test "queue": PASSED Test "rollback_region0": PASSED Test "rollback_region1": PASSED Test "rollback_entropy": PASSED Test "rtc": PASSED Test "sha256": PASSED Test "sha256_unrolled": PASSED Test "static_if": PASSED Test "stdlib": PASSED Test "system_is_locked_wp_on": PASSED Test "system_is_locked_wp_off": PASSED Test "timer_dos": PASSED Test "utils": PASSED Test "utils_str": PASSED Test "stm32f_rtc": PASSED Test "panic_data_bloonchipper_v2.0.4277": PASSED Test "panic_data_bloonchipper_v2.0.5938": PASSED Force-Relevant-Builds: all Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I264ad0ffe7afcd507a1e483c6e934a9c4fea47c3
Diffstat (limited to 'chip/npcx/system-npcx9.c')
-rw-r--r--[l---------]chip/npcx/system-npcx9.c232
1 files changed, 231 insertions, 1 deletions
diff --git a/chip/npcx/system-npcx9.c b/chip/npcx/system-npcx9.c
index 48088614a0..5cacbec749 120000..100644
--- a/chip/npcx/system-npcx9.c
+++ b/chip/npcx/system-npcx9.c
@@ -1 +1,231 @@
-system-npcx7.c \ No newline at end of file
+/* Copyright 2017 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <stdnoreturn.h>
+
+/* System module driver depends on chip series for Chrome EC */
+#include "builtin/assert.h"
+#include "common.h"
+#include "console.h"
+#include "cpu.h"
+#include "ec_commands.h"
+#include "hooks.h"
+#include "lct_chip.h"
+#include "registers.h"
+#include "system.h"
+#include "task.h"
+#include "util.h"
+#include "gpio.h"
+#include "hwtimer_chip.h"
+#include "system_chip.h"
+#include "rom_chip.h"
+
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ##args)
+
+/* Macros for last 32K ram block */
+#define LAST_RAM_BLK ((NPCX_RAM_SIZE / (32 * 1024)) - 1)
+/* Higher bits are reserved and need to be masked */
+#define RAM_PD_MASK (~BIT(LAST_RAM_BLK))
+
+/*****************************************************************************/
+/* IC specific low-level driver depends on chip series */
+
+void system_mpu_config(void)
+{
+}
+
+#ifdef CONFIG_HIBERNATE_PSL
+#ifndef NPCX_PSL_MODE_SUPPORT
+#error "Do not enable CONFIG_HIBERNATE_PSL if npcx ec doesn't support PSL mode!"
+#endif
+
+static enum psl_pin_t system_gpio_to_psl(enum gpio_signal signal)
+{
+ enum psl_pin_t psl_no;
+ const struct gpio_info *g = gpio_list + signal;
+
+ if (g->port == GPIO_PORT_D && g->mask == MASK_PIN2) /* GPIOD2 */
+ psl_no = PSL_IN1;
+ else if (g->port == GPIO_PORT_0 && (g->mask & 0x07)) /* GPIO00/01/02 */
+ psl_no = GPIO_MASK_TO_NUM(g->mask) + 1;
+ else
+ psl_no = PSL_NONE;
+
+ return psl_no;
+}
+
+#if NPCX_FAMILY_VERSION >= NPCX_FAMILY_NPCX9
+void system_set_psl_gpo(int level)
+{
+ if (level)
+ SET_BIT(NPCX_GLUE_PSL_MCTL1, NPCX_GLUE_PSL_MCTL1_PSL_GPO_CTL);
+ else
+ CLEAR_BIT(NPCX_GLUE_PSL_MCTL1, NPCX_GLUE_PSL_MCTL1_PSL_GPO_CTL);
+}
+#endif
+
+void system_enter_psl_mode(void)
+{
+ /* Configure pins from GPIOs to PSL which rely on VSBY power rail. */
+ gpio_config_module(MODULE_PMU, 1);
+
+ /*
+ * In npcx7, only physical PSL_IN pins can pull PSL_OUT to high and
+ * reboot ec.
+ * In npcx9, LCT timeout event can also pull PSL_OUT.
+ * We won't decide the wake cause now but only mark we are entering
+ * hibernation via PSL.
+ * The actual wakeup cause will be checked by the PSL input event bits
+ * when ec reboots.
+ */
+ NPCX_BBRAM(BBRM_DATA_INDEX_WAKE) = HIBERNATE_WAKE_PSL;
+
+#if NPCX_FAMILY_VERSION >= NPCX_FAMILY_NPCX9
+ /*
+ * If pulse mode is enabled, the VCC power is turned off by the
+ * external component (Ex: PMIC) but PSL_OUT. So we can just return
+ * here.
+ */
+ if (IS_BIT_SET(NPCX_GLUE_PSL_MCTL1, NPCX_GLUE_PSL_MCTL1_PLS_EN))
+ return;
+#endif
+
+ /*
+ * Pull PSL_OUT (GPIO85) to low to cut off ec's VCC power rail by
+ * setting bit 5 of PDOUT(8).
+ */
+ SET_BIT(NPCX_PDOUT(GPIO_PORT_8), 5);
+}
+
+/* Hibernate function implemented by PSL (Power Switch Logic) mode. */
+noreturn void __keep __enter_hibernate_in_psl(void)
+{
+ system_enter_psl_mode();
+ /* Spin and wait for PSL cuts power; should never return */
+ while (1)
+ ;
+}
+
+static void system_psl_type_sel(enum psl_pin_t psl_pin, uint32_t flags)
+{
+ /* Set PSL input events' type as level or edge trigger */
+ if ((flags & GPIO_INT_F_HIGH) || (flags & GPIO_INT_F_LOW))
+ CLEAR_BIT(NPCX_GLUE_PSL_CTS, psl_pin + 4);
+ else if ((flags & GPIO_INT_F_RISING) || (flags & GPIO_INT_F_FALLING))
+ SET_BIT(NPCX_GLUE_PSL_CTS, psl_pin + 4);
+
+ /*
+ * Set PSL input events' polarity is low (high-to-low) active or
+ * high (low-to-high) active
+ */
+ if (flags & GPIO_HIB_WAKE_HIGH)
+ SET_BIT(NPCX_DEVALT(ALT_GROUP_D), 2 * psl_pin);
+ else
+ CLEAR_BIT(NPCX_DEVALT(ALT_GROUP_D), 2 * psl_pin);
+}
+
+int system_config_psl_mode(enum gpio_signal signal)
+{
+ enum psl_pin_t psl_no;
+ const struct gpio_info *g = gpio_list + signal;
+
+ psl_no = system_gpio_to_psl(signal);
+ if (psl_no == PSL_NONE)
+ return 0;
+
+ system_psl_type_sel(psl_no, g->flags);
+ return 1;
+}
+
+#else
+/**
+ * Hibernate function in last 32K ram block for npcx7 series.
+ * Do not use global variable since we also turn off data ram.
+ */
+noreturn void __keep __attribute__((section(".after_init")))
+__enter_hibernate_in_last_block(void)
+{
+ /*
+ * The hibernate utility is located in the last block of RAM. The size
+ * of each RAM block is 32KB. We turn off all blocks except last one
+ * for better power consumption.
+ */
+ NPCX_RAM_PD(0) = RAM_PD_MASK & 0xFF;
+#if defined(CHIP_FAMILY_NPCX7)
+ NPCX_RAM_PD(1) = (RAM_PD_MASK >> 8) & 0x0F;
+#elif defined(CHIP_FAMILY_NPCX9)
+ NPCX_RAM_PD(1) = (RAM_PD_MASK >> 8) & 0x7F;
+#endif
+
+ /* Set deep idle mode */
+ NPCX_PMCSR = 0x6;
+
+ /* Enter deep idle, wake-up by GPIOs or RTC */
+ asm volatile("wfi");
+
+ /* RTC wake-up */
+ if (IS_BIT_SET(NPCX_WTC, NPCX_WTC_PTO))
+ /*
+ * Mark wake-up reason for hibernate
+ * Do not call bbram_data_write directly cause of
+ * no stack.
+ */
+ NPCX_BBRAM(BBRM_DATA_INDEX_WAKE) = HIBERNATE_WAKE_MTC;
+#ifdef NPCX_LCT_SUPPORT
+ else if (IS_BIT_SET(NPCX_LCTSTAT, NPCX_LCTSTAT_EVST)) {
+ NPCX_BBRAM(BBRM_DATA_INDEX_WAKE) = HIBERNATE_WAKE_LCT;
+ /* Clear LCT event */
+ NPCX_LCTSTAT = BIT(NPCX_LCTSTAT_EVST);
+ }
+#endif
+ else
+ /* Otherwise, we treat it as GPIOs wake-up */
+ NPCX_BBRAM(BBRM_DATA_INDEX_WAKE) = HIBERNATE_WAKE_PIN;
+
+ /* Start a watchdog reset */
+ NPCX_WDCNT = 0x01;
+ /* Reload and restart Timer 0 */
+ SET_BIT(NPCX_T0CSR, NPCX_T0CSR_RST);
+ /* Wait for timer is loaded and restart */
+ while (IS_BIT_SET(NPCX_T0CSR, NPCX_T0CSR_RST))
+ ;
+
+ /* Spin and wait for reboot; should never return */
+ while (1)
+ ;
+}
+#endif
+
+/**
+ * Hibernate function for different Nuvoton chip series.
+ */
+void __hibernate_npcx_series(void)
+{
+#ifdef CONFIG_HIBERNATE_PSL
+ __enter_hibernate_in_psl();
+#else
+ /* Make sure this is located in the last 32K code RAM block */
+ ASSERT((uint32_t)(&__after_init_end) - CONFIG_PROGRAM_MEMORY_BASE <
+ (32 * 1024));
+
+ /* Execute hibernate func in last 32K block */
+ __enter_hibernate_in_last_block();
+#endif
+}
+
+#if defined(CONFIG_HIBERNATE_PSL)
+static void report_psl_wake_source(void)
+{
+ if (!(system_get_reset_flags() & EC_RESET_FLAG_HIBERNATE))
+ return;
+
+ CPRINTS("PSL_CTS: 0x%x", NPCX_GLUE_PSL_CTS & 0xf);
+#if NPCX_FAMILY_VERSION >= NPCX_FAMILY_NPCX9
+ CPRINTS("PSL_MCTL1 event: 0x%x", NPCX_GLUE_PSL_MCTL1 & 0x18);
+#endif
+}
+DECLARE_HOOK(HOOK_INIT, report_psl_wake_source, HOOK_PRIO_DEFAULT);
+#endif