battery/max17055: Implement battery_status()

BUG=b:74841068
BRANCH=scarlet
TEST='/sys/class/power_supply/sbs-9-000b/status' shows
discharging/charging/full status correctly

Change-Id: I4216ba2d95ac82a9f600d8685d993cb5b37206d8
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/969747
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
This commit is contained in:
Philip Chen
2018-03-19 13:47:05 -07:00
committed by chrome-bot
parent 6e92603e06
commit 9aee2a19e8
2 changed files with 26 additions and 1 deletions

View File

@@ -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, &reg);
if (rv)
return rv;
if (reg & FSTAT_FQ)
*status |= BATTERY_FULLY_CHARGED;
rv = max17055_read(REG_CURRENT, &reg);
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

View File

@@ -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.