summaryrefslogtreecommitdiff
path: root/driver/battery/max17055.c
diff options
context:
space:
mode:
authorPhilip Chen <philipchen@google.com>2017-10-24 23:47:46 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-11-02 11:07:13 -0700
commitf28ab5c2ecd0549a72dc042564374faade58abcc (patch)
treed167220a1fc1254b938ff35e293428853c045129 /driver/battery/max17055.c
parent0deaaaa00302252c34f7c40bc6cf9aff13d5b9e8 (diff)
downloadchrome-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>
Diffstat (limited to 'driver/battery/max17055.c')
-rw-r--r--driver/battery/max17055.c50
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, &reg)) {
- CPRINTS("%s: failed to read reg %02x", __func__, REG_STATUS);
- return;
- }
+
+ MAX17055_READ_DEBUG(REG_STATUS, &reg);
/* Check for POR */
if (STATUS_POR & reg) {
/* Delay up to 800 ms until FSTAT.DNR bit == 0. */
while (--retries) {
- if (max17055_read(REG_FSTAT, &reg)) {
- CPRINTS("%s: failed to read reg %02x",
- __func__, REG_FSTAT);
- return;
- }
+ MAX17055_READ_DEBUG(REG_FSTAT, &reg);
if (!(FSTAT_DNR & reg))
break;
msleep(10);
@@ -372,24 +384,12 @@ static void max17055_init(void)
}
/* Clear POR bit */
- if (max17055_read(REG_STATUS, &reg)) {
- 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, &reg);
+ MAX17055_WRITE_DEBUG(REG_STATUS, (reg & ~STATUS_POR));
/* Set CONFIG.TSEL to measure temperature using external thermistor */
- if (max17055_read(REG_CONFIG, &reg)) {
- 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, &reg);
+ MAX17055_WRITE_DEBUG(REG_CONFIG, (reg | CONF_TSEL));
CPRINTS("max17055 configuration succeeded!");
}