diff options
Diffstat (limited to 'driver')
-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!"); } |