diff --git a/driver/battery/max17055.c b/driver/battery/max17055.c index 9be2a14651..e02a4aaa42 100644 --- a/driver/battery/max17055.c +++ b/driver/battery/max17055.c @@ -197,7 +197,24 @@ int battery_get_mode(int *mode) int battery_status(int *status) { - return EC_ERROR_UNIMPLEMENTED; + int rv; + int reg; + + *status = 0; + + rv = max17055_read(REG_FSTAT, ®); + if (rv) + return rv; + if (reg & FSTAT_FQ) + *status |= BATTERY_FULLY_CHARGED; + + rv = max17055_read(REG_CURRENT, ®); + if (rv) + return rv; + if (reg >> 15) + *status |= BATTERY_DISCHARGING; + + return EC_SUCCESS; } enum battery_present battery_is_present(void) @@ -267,6 +284,9 @@ void battery_get_params(struct batt_params *batt) batt->desired_current && batt->state_of_charge < BATTERY_LEVEL_FULL) batt->flags |= BATT_FLAG_WANT_CHARGE; + + if (battery_status(&batt->status)) + batt->flags |= BATT_FLAG_BAD_STATUS; } #ifdef CONFIG_CMD_PWR_AVG diff --git a/driver/battery/max17055.h b/driver/battery/max17055.h index fb49e69c22..be070e9896 100644 --- a/driver/battery/max17055.h +++ b/driver/battery/max17055.h @@ -54,11 +54,16 @@ /* FStat reg (0x3d) flags */ #define FSTAT_DNR 0x0001 +#define FSTAT_FQ 0x0080 /* ModelCfg reg (0xdb) flags */ #define MODELCFG_REFRESH 0x8000 #define MODELCFG_VCHG 0x0400 +/* Smart battery status bits (sbs reg 0x16) */ +#define BATTERY_DISCHARGING 0x40 +#define BATTERY_FULLY_CHARGED 0x20 + /* * Before we have the battery fully characterized, we use these macros to * convert basic battery parameters to max17055 reg values for ez config.