charger/rt946x: Add an interface to check charge termination

After we set TE (CL:958295), rt946x terminates charging when
the charge current is below IEOC in constant-voltage mode.

Let's add an interface to check charge termination status.

BUG=b:77870927
BRANCH=scarlet
TEST=charge scarlet, confirm rt946x_is_charge_done() returns 0 when
battery is charging and returns 1 when charge terminates (battery is
full). Then keep AC plugged and wait, confirm rt946x_is_charge_done()
returns 0 when rt946x restarts charging.

Change-Id: I559d328aa0d7c5c4cd5bf7178370ea039aa80204
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1044768
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
This commit is contained in:
Philip Chen
2018-04-13 15:53:09 -07:00
committed by chrome-bot
parent fa6c5abae5
commit 492b1aceeb
2 changed files with 22 additions and 0 deletions

View File

@@ -63,6 +63,13 @@ enum rt946x_ilmtsel {
RT946X_ILMTSEL_LOWER_LEVEL, /* lower of above two */
};
enum rt946x_chg_stat {
RT946X_CHGSTAT_READY = 0,
RT946X_CHGSTAT_IN_PROGRESS,
RT946X_CHGSTAT_DONE,
RT946X_CHGSTAT_FAULT,
};
enum rt946x_adc_in_sel {
RT946X_ADC_VBUS_DIV5 = 1,
RT946X_ADC_VBUS_DIV2,
@@ -911,6 +918,18 @@ int rt946x_is_vbus_ready(void)
0 : !!(val & RT946X_MASK_PWR_RDY);
}
int rt946x_is_charge_done(void)
{
int val = 0;
if (rt946x_read8(RT946X_REG_CHGSTAT, &val))
return 0;
val = (val & RT946X_MASK_CHG_STAT) >> RT946X_SHIFT_CHG_STAT;
return val == RT946X_CHGSTAT_DONE;
}
int rt946x_cutoff_battery(void)
{
return rt946x_set_bit(RT946X_REG_CHGCTRL2, RT946X_MASK_SHIP_MODE);

View File

@@ -315,6 +315,9 @@ int rt946x_enable_charger_boost(int en);
*/
int rt946x_is_vbus_ready(void);
/* Return 1 if rt946x triggers charge termination due to full charge. */
int rt946x_is_charge_done(void);
/*
* Cut off the battery (force BATFET to turn off).
* Return 0 if it succeeds.