scarlet: Enable charge termination only when battery is present

If we enable charge termination when booting w/o battery,
charge termination would trigger and cut the power for max17055.

BUG=b:72697658
BRANCH=scarlet
TEST=Read rt946x reg 0x02, confirm charge termination is
disabled when booting w/o battery, and enabled otherwise.

Change-Id: I5780196ad993299ddfb37621bee5e941aa9b0d14
Signed-off-by: Philip Chen <philipchen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/989314
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Philip Chen <philipchen@chromium.org>
This commit is contained in:
Philip Chen
2018-03-29 20:23:20 -07:00
committed by chrome-bot
parent 1a38513538
commit f319a80975
3 changed files with 23 additions and 4 deletions

View File

@@ -14,6 +14,7 @@
#include "ec_commands.h"
#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
#include "util.h"
/*
@@ -244,6 +245,19 @@ int charger_profile_override(struct charge_state_data *curr)
return 0;
}
static void board_charge_termination(void)
{
static uint8_t te;
/* Enable charge termination when we are sure battery is present. */
if (!te && battery_is_present() == BP_YES) {
if (!rt946x_enable_charge_termination(1))
te = 1;
}
}
DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE,
board_charge_termination,
HOOK_PRIO_DEFAULT);
/* Customs options controllable by host command. */
#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0)

View File

@@ -397,10 +397,6 @@ static int rt946x_init_setting(void)
if (rv)
return rv;
rv = rt946x_set_iprec(batt_info->precharge_current);
if (rv)
return rv;
/* Enable charge current termination */
rv = rt946x_set_bit(RT946X_REG_CHGCTRL2, RT946X_MASK_TE);
if (rv)
return rv;
@@ -903,3 +899,9 @@ int rt946x_cutoff_battery(void)
{
return rt946x_set_bit(RT946X_REG_CHGCTRL2, RT946X_MASK_SHIP_MODE);
}
int rt946x_enable_charge_termination(int en)
{
return (en ? rt946x_set_bit : rt946x_clr_bit)
(RT946X_REG_CHGCTRL2, RT946X_MASK_TE);
}

View File

@@ -311,4 +311,7 @@ int rt946x_is_vbus_ready(void);
*/
int rt946x_cutoff_battery(void);
/* Enable/Disable charge temination */
int rt946x_enable_charge_termination(int en);
#endif /* __CROS_EC_RT946X_H */