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/it83xx/system.c | |
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/it83xx/system.c')
-rw-r--r-- | chip/it83xx/system.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/chip/it83xx/system.c b/chip/it83xx/system.c index 32ab43231f..055c586cd8 100644 --- a/chip/it83xx/system.c +++ b/chip/it83xx/system.c @@ -226,25 +226,37 @@ const char *system_get_chip_revision(void) return buf; } -int system_get_vbnvcontext(uint8_t *block) +static int bram_idx_lookup(enum system_bbram_idx idx) { - int i; + if (idx >= SYSTEM_BBRAM_IDX_VBNVBLOCK0 && + idx <= SYSTEM_BBRAM_IDX_VBNVBLOCK15) + return BRAM_IDX_NVCONTEXT + + idx - SYSTEM_BBRAM_IDX_VBNVBLOCK0; + return -1; +} + +int system_get_bbram(enum system_bbram_idx idx, uint8_t *value) +{ + int bram_idx = bram_idx_lookup(idx); - for (i = 0; i < EC_VBNV_BLOCK_SIZE; i++) - block[i] = IT83XX_BRAM_BANK0((BRAM_IDX_NVCONTEXT + i)); + if (bram_idx < 0) + return EC_ERROR_INVAL; + *value = IT83XX_BRAM_BANK0(bram_idx); return EC_SUCCESS; } -int system_set_vbnvcontext(const uint8_t *block) +int system_set_bbram(enum system_bbram_idx idx, uint8_t value) { - int i; + int bram_idx = bram_idx_lookup(idx); - for (i = 0; i < EC_VBNV_BLOCK_SIZE; i++) - IT83XX_BRAM_BANK0((BRAM_IDX_NVCONTEXT + i)) = block[i]; + if (bram_idx < 0) + return EC_ERROR_INVAL; + IT83XX_BRAM_BANK0(bram_idx) = value; return EC_SUCCESS; } + #define BRAM_NVCONTEXT_SIZE (BRAM_IDX_NVCONTEXT_END - BRAM_IDX_NVCONTEXT + 1) BUILD_ASSERT(EC_VBNV_BLOCK_SIZE <= BRAM_NVCONTEXT_SIZE); |