From e94c21fe00169aba9fa374fd286a1b004049b6d1 Mon Sep 17 00:00:00 2001 From: Vijay Hiremath Date: Fri, 21 Jun 2019 13:30:25 -0700 Subject: isl9241: Enable support for hardware charge ramp The input voltage regulation register 0x4B contains the voltage limit at which the input voltage loop tries to regulate when the input voltage is dropping. When the ADP is browning out or weak, the input voltage can droop and the input voltage loop tries to regulate to this setting by reducing battery charging current and then system power to try to hold up the input voltage. BUG=b:136198519 BRANCH=none TEST=Able to verify BC1.2 charge ramping on INTELRVP Change-Id: I0f712215c9323a75de71342d5ae5341c3e4e1fa6 Signed-off-by: Vijay Hiremath Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1672211 Reviewed-by: Jett Rink --- driver/charger/isl9241.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'driver/charger/isl9241.c') diff --git a/driver/charger/isl9241.c b/driver/charger/isl9241.c index de6110a02b..41d649d1c3 100644 --- a/driver/charger/isl9241.c +++ b/driver/charger/isl9241.c @@ -308,6 +308,14 @@ static void isl9241_init(void) reg | ISL9241_CONTROL3_ACLIM_RELOAD)) goto init_fail; +#ifndef CONFIG_CHARGE_RAMP_HW + if (isl9241_read(ISL9241_REG_CONTROL0, ®)) + goto init_fail; + if (isl9241_write(ISL9241_REG_CONTROL0, + reg | ISL9241_CONTROL0_INPUT_VTG_REGULATION)) + goto init_fail; +#endif + /* * No need to proceed with the rest of init if we sysjump'd to this * image as the input current limit has already been set. @@ -326,6 +334,54 @@ init_fail: } DECLARE_HOOK(HOOK_INIT, isl9241_init, HOOK_PRIO_INIT_I2C + 1); +/*****************************************************************************/ +/* Hardware current ramping */ + +#ifdef CONFIG_CHARGE_RAMP_HW +int charger_set_hw_ramp(int enable) +{ + int rv, reg; + + rv = isl9241_read(ISL9241_REG_CONTROL0, ®); + if (rv) + return rv; + + /* HW ramp is controlled by input voltage regulation reference bits */ + if (enable) + reg &= ~ISL9241_CONTROL0_INPUT_VTG_REGULATION; + else + reg |= ISL9241_CONTROL0_INPUT_VTG_REGULATION; + + return isl9241_write(ISL9241_REG_CONTROL0, reg); +} + +int chg_ramp_is_stable(void) +{ + /* + * Since ISL cannot read the current limit that the ramp has settled + * on, then we can never consider the ramp stable, because we never + * know what the stable limit is. + */ + return 0; +} + +int chg_ramp_is_detected(void) +{ + return 1; +} + +int chg_ramp_get_current_limit(void) +{ + int reg; + + if (isl9241_read(ISL9241_REG_IADP_ADC_RESULTS, ®)) + return 0; + + /* LSB value of register = 22.2mA */ + return (reg * 222) / 10; +} +#endif /* CONFIG_CHARGE_RAMP_HW */ + /*****************************************************************************/ #ifdef CONFIG_CMD_CHARGER_DUMP static void dump_reg_range(int low, int high) -- cgit v1.2.1