diff options
author | Philip Chen <philipchen@google.com> | 2017-10-24 23:47:46 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-11-02 11:07:13 -0700 |
commit | f28ab5c2ecd0549a72dc042564374faade58abcc (patch) | |
tree | d167220a1fc1254b938ff35e293428853c045129 | |
parent | 0deaaaa00302252c34f7c40bc6cf9aff13d5b9e8 (diff) | |
download | chrome-ec-f28ab5c2ecd0549a72dc042564374faade58abcc.tar.gz |
battery/max17055: Use macros to clean up duplicate code
BUG=none
BRANCH=none
TEST=manually test on Scarlet rev2 and confirm max17055 still
initializes and works by 'battery' command
Change-Id: I3f553a1392cc1c4364ac605111564501bd706ec2
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/737712
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Philip Chen <philipchen@chromium.org>
-rw-r--r-- | driver/battery/max17055.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/driver/battery/max17055.c b/driver/battery/max17055.c index b425e828b4..405ebdf975 100644 --- a/driver/battery/max17055.c +++ b/driver/battery/max17055.c @@ -78,6 +78,24 @@ /* Percentage reg value to 1% */ #define PERCENTAGE_CONV(REG) (REG >> 8) +/* Useful macros */ +#define MAX17055_READ_DEBUG(offset, ptr_reg) \ + do { \ + if (max17055_read(offset, ptr_reg)) { \ + CPRINTS("%s: failed to read reg %02x", \ + __func__, offset); \ + return; \ + } \ + } while (0) +#define MAX17055_WRITE_DEBUG(offset, reg) \ + do { \ + if (max17055_write(offset, reg)) { \ + CPRINTS("%s: failed to read reg %02x", \ + __func__, offset); \ + return; \ + } \ + } while (0) + static int fake_state_of_charge = -1; static int max17055_read(int offset, int *data) @@ -341,20 +359,14 @@ static void max17055_init(void) CPRINTS("Wrong max17055 id!"); return; } - if (max17055_read(REG_STATUS, ®)) { - CPRINTS("%s: failed to read reg %02x", __func__, REG_STATUS); - return; - } + + MAX17055_READ_DEBUG(REG_STATUS, ®); /* Check for POR */ if (STATUS_POR & reg) { /* Delay up to 800 ms until FSTAT.DNR bit == 0. */ while (--retries) { - if (max17055_read(REG_FSTAT, ®)) { - CPRINTS("%s: failed to read reg %02x", - __func__, REG_FSTAT); - return; - } + MAX17055_READ_DEBUG(REG_FSTAT, ®); if (!(FSTAT_DNR & reg)) break; msleep(10); @@ -372,24 +384,12 @@ static void max17055_init(void) } /* Clear POR bit */ - if (max17055_read(REG_STATUS, ®)) { - CPRINTS("%s: failed to read reg %02x", __func__, REG_STATUS); - return; - } - if (max17055_write(REG_STATUS, (reg & ~STATUS_POR))) { - CPRINTS("%s: failed to write reg %02x", __func__, REG_STATUS); - return; - } + MAX17055_READ_DEBUG(REG_STATUS, ®); + MAX17055_WRITE_DEBUG(REG_STATUS, (reg & ~STATUS_POR)); /* Set CONFIG.TSEL to measure temperature using external thermistor */ - if (max17055_read(REG_CONFIG, ®)) { - CPRINTS("%s: failed to read reg %02x", __func__, REG_CONFIG); - return; - } - if (max17055_write(REG_CONFIG, (reg | CONF_TSEL))) { - CPRINTS("%s: failed to write reg %02x", __func__, REG_CONFIG); - return; - } + MAX17055_READ_DEBUG(REG_CONFIG, ®); + MAX17055_WRITE_DEBUG(REG_CONFIG, (reg | CONF_TSEL)); CPRINTS("max17055 configuration succeeded!"); } |