diff options
author | Wealian Liao <whliao@nuvoton.corp-partner.google.com> | 2021-07-08 17:16:48 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-08-04 18:11:55 +0000 |
commit | 05f0f8bdc779e26b661cd6460309e3c3a8acefa0 (patch) | |
tree | 923cecab68190e0aad5ff01bf55bfe19864107a6 /zephyr/shim/src/system.c | |
parent | 9b779dd2ce02e7b43b5bf835c09aff4f3ea3a21f (diff) | |
download | chrome-ec-05f0f8bdc779e26b661cd6460309e3c3a8acefa0.tar.gz |
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 <whliao@nuvoton.corp-partner.google.com>
Change-Id: I0a394e5fbf784ec2e3caea77f194c88ae9d5542e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3067156
Reviewed-by: Yuval Peress <peress@chromium.org>
Commit-Queue: Yuval Peress <peress@chromium.org>
Diffstat (limited to 'zephyr/shim/src/system.c')
-rw-r--r-- | zephyr/shim/src/system.c | 85 |
1 files changed, 68 insertions, 17 deletions
diff --git a/zephyr/shim/src/system.c b/zephyr/shim/src/system.c index 55fe5183b8..5a9612fa26 100644 --- a/zephyr/shim/src/system.c +++ b/zephyr/shim/src/system.c @@ -20,28 +20,15 @@ #define BBRAM_REGION_PD2 DT_PATH(named_bbram_regions, pd2) #define BBRAM_REGION_TRY_SLOT DT_PATH(named_bbram_regions, try_slot) +#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_system, LOG_LEVEL_ERR); STATIC_IF_NOT(CONFIG_ZTEST) const struct device *bbram_dev; static const struct device *sys_dev; -#if DT_NODE_EXISTS(DT_NODELABEL(bbram)) -static int 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(system_init, PRE_KERNEL_1, 50); -#endif - /* Map idx to a bbram offset/size, or return -1 on invalid idx */ static int bbram_lookup(enum system_bbram_idx idx, int *offset_out, int *size_out) @@ -85,6 +72,62 @@ int system_get_bbram(enum system_bbram_idx idx, uint8_t *value) return rc ? EC_ERROR_INVAL : EC_SUCCESS; } +void chip_save_reset_flags(uint32_t flags) +{ + if (bbram_dev == NULL) { + LOG_ERR("bbram_dev doesn't 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; + + if (bbram_dev == NULL) { + LOG_ERR("bbram_dev doesn't 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 binding"); + return -EC_ERROR_INVAL; + } + + return cros_bbram_write(bbram_dev, GET_BBRAM_OFFSET(scratchpad), + GET_BBRAM_SIZE(scratchpad), (uint8_t *)&value); +} + +uint32_t system_get_scratchpad(void) +{ + uint32_t value; + + if (bbram_dev == NULL) { + LOG_ERR("bbram_dev doesn't binding"); + /* + * TODO(b/195481980): Seperate the scratchpad value & API + * status. + */ + return 0; + } + + cros_bbram_read(bbram_dev, GET_BBRAM_OFFSET(scratchpad), + GET_BBRAM_SIZE(scratchpad), (uint8_t *)&value); + + return value; +} + void system_hibernate(uint32_t seconds, uint32_t microseconds) { const struct device *sys_dev = device_get_binding("CROS_SYSTEM"); @@ -282,6 +325,14 @@ static int system_preinitialize(const struct device *unused) { ARG_UNUSED(unused); +#if DT_NODE_EXISTS(DT_NODELABEL(bbram)) + 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; + } +#endif + sys_dev = device_get_binding("CROS_SYSTEM"); if (!sys_dev) { /* |