mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-13 03:15:06 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user