summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2019-06-21 13:30:25 -0700
committerCommit Bot <commit-bot@chromium.org>2019-07-02 21:10:49 +0000
commite94c21fe00169aba9fa374fd286a1b004049b6d1 (patch)
tree125af7cb344db80fa9a4f68d956392283e95ffd5
parent6b83e8b1cfbd7a9fd4b7e4e69113348c51efea4f (diff)
downloadchrome-ec-e94c21fe00169aba9fa374fd286a1b004049b6d1.tar.gz
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 <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1672211 Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r--driver/charger/isl9241.c56
-rw-r--r--driver/charger/isl9241.h10
2 files changed, 66 insertions, 0 deletions
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, &reg))
+ 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.
@@ -327,6 +335,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, &reg);
+ 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, &reg))
+ 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)
{
diff --git a/driver/charger/isl9241.h b/driver/charger/isl9241.h
index b0be2cb188..f2d4f1493d 100644
--- a/driver/charger/isl9241.h
+++ b/driver/charger/isl9241.h
@@ -34,7 +34,12 @@
#define ISL9241_REG_MAX_SYSTEM_VOLTAGE 0x15
#define ISL9241_REG_CONTROL7 0x38
+
+/* Configures various charger options */
#define ISL9241_REG_CONTROL0 0x39
+/* 2: Input Voltage Regulation (0 = Enable (default), 1 = Disable) */
+#define ISL9241_CONTROL0_INPUT_VTG_REGULATION BIT(2)
+
#define ISL9241_REG_INFORMATION1 0x3A
#define ISL9241_REG_ADAPTER_CUR_LIMIT2 0x3B
@@ -71,6 +76,8 @@
#define ISL9241_REG_DC_PROCHOT 0x48
#define ISL9241_REG_OTG_VOLTAGE 0x49
#define ISL9241_REG_OTG_CURRENT 0x4A
+
+/* VIN Voltage (ADP Min Voltage) (default 4.096V) */
#define ISL9241_REG_VIN_VOLTAGE 0x4B
/* Configures various charger options */
@@ -92,7 +99,10 @@
#define ISL9241_REG_NTC_ADC_RESULTS 0x80
#define ISL9241_REG_VBAT_ADC_RESULTS 0x81
#define ISL9241_REG_TJ_ADC_RESULTS 0x82
+
+/* ADC result for adapter current measurements, LSB = 22.2mA */
#define ISL9241_REG_IADP_ADC_RESULTS 0x83
+
#define ISL9241_REG_DC_ADC_RESULTS 0x84
#define ISL9241_REG_CC_ADC_RESULTS 0x85
#define ISL9241_REG_VSYS_ADC_RESULTS 0x86