diff options
Diffstat (limited to 'chip/mec1322')
-rw-r--r-- | chip/mec1322/system.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/chip/mec1322/system.c b/chip/mec1322/system.c index 54ff2f45c8..4b2738e969 100644 --- a/chip/mec1322/system.c +++ b/chip/mec1322/system.c @@ -24,6 +24,8 @@ enum hibdata_index { HIBDATA_INDEX_SCRATCHPAD = 0, /* General-purpose scratchpad */ HIBDATA_INDEX_SAVED_RESET_FLAGS, /* Saved reset flags */ + HIBDATA_INDEX_PD0, /* USB-PD0 saved port state */ + HIBDATA_INDEX_PD1, /* USB-PD1 saved port state */ }; static void check_reset_cause(void) @@ -166,14 +168,26 @@ const char *system_get_chip_revision(void) return buf; } -int system_get_bbram(enum system_bbram_idx idx, uint8_t *value) +static int bbram_idx_lookup(enum system_bbram_idx idx) { - enum hibdata_index hibdata; - switch (idx) { +#ifdef CONFIG_USB_PD_DUAL_ROLE + case SYSTEM_BBRAM_IDX_PD0: + return HIBDATA_INDEX_PD0; + case SYSTEM_BBRAM_IDX_PD1: + return HIBDATA_INDEX_PD1; +#endif default: - return EC_ERROR_UNIMPLEMENTED; + return -1; } +} + +int system_get_bbram(enum system_bbram_idx idx, uint8_t *value) +{ + int hibdata = bbram_idx_lookup(idx); + + if (hibdata < 0) + return EC_ERROR_UNIMPLEMENTED; *value = MEC1322_VBAT_RAM(hibdata); return EC_SUCCESS; @@ -181,12 +195,10 @@ int system_get_bbram(enum system_bbram_idx idx, uint8_t *value) int system_set_bbram(enum system_bbram_idx idx, uint8_t value) { - enum hibdata_index hibdata; + int hibdata = bbram_idx_lookup(idx); - switch (idx) { - default: + if (hibdata < 0) return EC_ERROR_UNIMPLEMENTED; - } MEC1322_VBAT_RAM(hibdata) = value; return EC_SUCCESS; |