summaryrefslogtreecommitdiff
path: root/driver/battery/max17055.c
diff options
context:
space:
mode:
Diffstat (limited to 'driver/battery/max17055.c')
-rw-r--r--driver/battery/max17055.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/driver/battery/max17055.c b/driver/battery/max17055.c
index 99662284a6..db8b798a3b 100644
--- a/driver/battery/max17055.c
+++ b/driver/battery/max17055.c
@@ -343,7 +343,7 @@ int battery_wait_for_stable(void)
}
/* Configured MAX17055 with the battery parameters for optimal performance. */
-static int max17055_init_config(void)
+static int max17055_load_batt_model(void)
{
int reg;
int hib_cfg;
@@ -452,15 +452,32 @@ static void max17055_init(void)
return;
}
- if (max17055_init_config()) {
+ if (max17055_load_batt_model()) {
CPRINTS("max17055 configuration failed!");
return;
}
- }
- /* Clear POR bit */
- MAX17055_READ_DEBUG(REG_STATUS, &reg);
- MAX17055_WRITE_DEBUG(REG_STATUS, (reg & ~STATUS_POR));
+ /* Clear POR bit */
+ MAX17055_READ_DEBUG(REG_STATUS, &reg);
+ MAX17055_WRITE_DEBUG(REG_STATUS, (reg & ~STATUS_POR));
+ } else {
+ const struct max17055_batt_profile *config;
+
+ config = max17055_get_batt_profile();
+ MAX17055_READ_DEBUG(REG_DESIGN_CAPACITY, &reg);
+
+ /*
+ * Reload the battery model if the current running one
+ * is wrong.
+ */
+ if (config->design_cap != reg) {
+ CPRINTS("max17055 reconfig...");
+ if (max17055_load_batt_model()) {
+ CPRINTS("max17055 configuration failed!");
+ return;
+ }
+ }
+ }
CPRINTS("max17055 configuration succeeded!");
}