From 05f0f8bdc779e26b661cd6460309e3c3a8acefa0 Mon Sep 17 00:00:00 2001 From: Wealian Liao Date: Thu, 8 Jul 2021 17:16:48 +0800 Subject: zephyr: Move BBRAM access functions to common system.c NPCX & IT8xxx2 series are both use BBRAM for scratchpad/reset_flags access. cros_bbram API already handles the chip-specific code. This CL moves scratchpad/reset_flags access functions to the common system.c to avoid duplicate those functions. BUG=none BRANCH=none TEST=zmake testall TEST=check reset cause on lazor & npcx_evb Signed-off-by: Wealian Liao Change-Id: I0a394e5fbf784ec2e3caea77f194c88ae9d5542e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3067156 Reviewed-by: Yuval Peress Commit-Queue: Yuval Peress --- zephyr/shim/chip/it8xxx2/system.c | 79 --------------------------------------- 1 file changed, 79 deletions(-) (limited to 'zephyr/shim/chip/it8xxx2') diff --git a/zephyr/shim/chip/it8xxx2/system.c b/zephyr/shim/chip/it8xxx2/system.c index e40c49d137..d9dcd7ccfb 100644 --- a/zephyr/shim/chip/it8xxx2/system.c +++ b/zephyr/shim/chip/it8xxx2/system.c @@ -3,87 +3,8 @@ * found in the LICENSE file. */ -#include -#include - #include "system.h" -#define GET_BBRAM_OFFSET(node) \ - DT_PROP(DT_PATH(named_bbram_regions, node), offset) -#define GET_BBRAM_SIZE(node) DT_PROP(DT_PATH(named_bbram_regions, node), size) - -LOG_MODULE_REGISTER(shim_ite_system, LOG_LEVEL_ERR); - -const struct device *bbram_dev; - -void chip_save_reset_flags(uint32_t flags) -{ - if (bbram_dev == NULL) { - LOG_ERR("bbram_dev doesn't have a binding"); - return; - } - - cros_bbram_write(bbram_dev, GET_BBRAM_OFFSET(saved_reset_flags), - GET_BBRAM_SIZE(saved_reset_flags), (uint8_t *)&flags); -} - -uint32_t chip_read_reset_flags(void) -{ - uint32_t flags = 0; - - if (bbram_dev == NULL) { - LOG_ERR("bbram_dev doesn't have a binding"); - return 0; - } - - cros_bbram_read(bbram_dev, GET_BBRAM_OFFSET(saved_reset_flags), - GET_BBRAM_SIZE(saved_reset_flags), (uint8_t *)&flags); - - return flags; -} - -int system_set_scratchpad(uint32_t value) -{ - if (bbram_dev == NULL) { - LOG_ERR("bbram_dev doesn't have a binding"); - return 0; - } - - cros_bbram_write(bbram_dev, GET_BBRAM_OFFSET(scratchpad), - GET_BBRAM_SIZE(scratchpad), (uint8_t *)&value); - - return EC_SUCCESS; -} - -uint32_t system_get_scratchpad(void) -{ - uint32_t value = 0; - - if (bbram_dev == NULL) { - LOG_ERR("bbram_dev doesn't have a binding"); - return 0; - } - - cros_bbram_read(bbram_dev, GET_BBRAM_OFFSET(scratchpad), - GET_BBRAM_SIZE(scratchpad), (uint8_t *)&value); - - return value; -} - -static int chip_system_init(const struct device *unused) -{ - ARG_UNUSED(unused); - - bbram_dev = DEVICE_DT_GET(DT_NODELABEL(bbram)); - if (!device_is_ready(bbram_dev)) { - LOG_ERR("Error: device %s is not ready", bbram_dev->name); - return -1; - } - - return 0; -} -SYS_INIT(chip_system_init, PRE_KERNEL_1, 15); - uintptr_t system_get_fw_reset_vector(uintptr_t base) { /* -- cgit v1.2.1