diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2017-02-16 14:26:46 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-02-24 15:23:24 -0800 |
commit | f0b564b4a031fdc974a98a13308a62a460ae4a69 (patch) | |
tree | 4a98eb323e3771fb38f575462fd83fbe2a13ce1a /chip/stm32 | |
parent | fb8e36631af8395d45d3bef79822c03dd6298ca3 (diff) | |
download | chrome-ec-f0b564b4a031fdc974a98a13308a62a460ae4a69.tar.gz |
system: Add generic bbram read / write routines
Add generic routines to read or write a byte to battery-backed RAM, and
implement vbnvcontext get/set using these routines.
BUG=chrome-os-partner:62952
BRANCH=reef
TEST=On reef, with subsequent commit, run "cutoff" on the console,
reattach AC, and verify device successfully wakes. Also verify Rp is
dropped on console 'reboot' and F3 + power from RW.
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I14691923f2e5198e901b6b5199e92c58c68cd18d
Reviewed-on: https://chromium-review.googlesource.com/444444
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'chip/stm32')
-rw-r--r-- | chip/stm32/system.c | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/chip/stm32/system.c b/chip/stm32/system.c index d296a90fa5..458b90402f 100644 --- a/chip/stm32/system.c +++ b/chip/stm32/system.c @@ -336,36 +336,47 @@ const char *system_get_chip_revision(void) return ""; } -int system_get_vbnvcontext(uint8_t *block) +static int bkpdata_index_lookup(enum system_bbram_idx idx, int *msb) { - enum bkpdata_index i; - uint16_t value; - - for (i = BKPDATA_INDEX_VBNV_CONTEXT0; - i <= BKPDATA_INDEX_VBNV_CONTEXT7; i++) { - value = bkpdata_read(i); - *block++ = (uint8_t)(value & 0xff); - *block++ = (uint8_t)(value >> 8); + *msb = 0; + + if (idx >= SYSTEM_BBRAM_IDX_VBNVBLOCK0 && + idx <= SYSTEM_BBRAM_IDX_VBNVBLOCK15) { + *msb = (idx - SYSTEM_BBRAM_IDX_VBNVBLOCK0) % 2; + return BKPDATA_INDEX_VBNV_CONTEXT0 + + (idx - SYSTEM_BBRAM_IDX_VBNVBLOCK0) / 2; } + return -1; +} + +int system_get_bbram(enum system_bbram_idx idx, uint8_t *value) +{ + int msb = 0; + int bkpdata_index = bkpdata_index_lookup(idx, &msb); + + if (bkpdata_index < 0) + return EC_ERROR_INVAL; + *value = (bkpdata_read(bkpdata_index) >> (8 * msb)) & 0xff; return EC_SUCCESS; } -int system_set_vbnvcontext(const uint8_t *block) +int system_set_bbram(enum system_bbram_idx idx, uint8_t value) { - enum bkpdata_index i; - uint16_t value; - int err; - - for (i = BKPDATA_INDEX_VBNV_CONTEXT0; - i <= BKPDATA_INDEX_VBNV_CONTEXT7; i++) { - value = *block++; - value |= ((uint16_t)*block++) << 8; - err = bkpdata_write(i, value); - if (err) - return err; - } + uint16_t read; + int msb = 0; + int bkpdata_index = bkpdata_index_lookup(idx, &msb); + + if (bkpdata_index < 0) + return EC_ERROR_INVAL; + + read = bkpdata_read(bkpdata_index); + if (msb) + read = (read & 0xff) | (value << 8); + else + read = (read & 0xff00) | value; + bkpdata_write(bkpdata_index, read); return EC_SUCCESS; } |