From 99dba155820737065fc83749bc0e15f79b785546 Mon Sep 17 00:00:00 2001 From: Terry Chen Date: Thu, 12 Nov 2020 15:29:48 +0800 Subject: eldrid: modify charger configuration BUG=b:166728543 BRANCH=firmware-volteer-13521.B-master TEST=make buildall Signed-off-by: Terry Chen Change-Id: I1a918326a625f294fe6cd9a2ec8e2c5b2af43569 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2534231 Tested-by: Scott Chao Reviewed-by: Keith Short Commit-Queue: Abe Levkoy --- driver/charger/isl9241.c | 35 ++++++++++++++++++++++++++++++++++- driver/charger/isl9241.h | 19 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) (limited to 'driver') diff --git a/driver/charger/isl9241.c b/driver/charger/isl9241.c index 626c84fe07..4fd92e6c08 100644 --- a/driver/charger/isl9241.c +++ b/driver/charger/isl9241.c @@ -323,7 +323,19 @@ static enum ec_error_list isl9241_discharge_on_ac(int chgnum, int enable) int isl9241_set_ac_prochot(int chgnum, int ma) { int rv; - uint16_t reg = AC_CURRENT_TO_REG(ma); + uint16_t reg; + + /* + * The register reserves bits [6:0] and bits [15:13]. + * This routine should ensure these bits are not set + * before writing the register. + */ + if (ma > AC_REG_TO_CURRENT(ISL9241_AC_PROCHOT_CURRENT_MAX)) + reg = ISL9241_AC_PROCHOT_CURRENT_MAX; + else if (ma < AC_REG_TO_CURRENT(ISL9241_AC_PROCHOT_CURRENT_MIN)) + reg = ISL9241_AC_PROCHOT_CURRENT_MIN; + else + reg = AC_CURRENT_TO_REG(ma); rv = isl9241_write(chgnum, ISL9241_REG_AC_PROCHOT, reg); if (rv) @@ -332,6 +344,27 @@ int isl9241_set_ac_prochot(int chgnum, int ma) return rv; } +int isl9241_set_dc_prochot(int chgnum, int ma) +{ + int rv; + + /* + * The register reserves bits [7:0] and bits [15:14]. + * This routine should ensure these bits are not set + * before writing the register. + */ + if (ma > ISL9241_DC_PROCHOT_CURRENT_MAX) + ma = ISL9241_DC_PROCHOT_CURRENT_MAX; + else if (ma < ISL9241_DC_PROCHOT_CURRENT_MIN) + ma = ISL9241_DC_PROCHOT_CURRENT_MIN; + + rv = isl9241_write(chgnum, ISL9241_REG_DC_PROCHOT, ma); + if (rv) + CPRINTF("set_dc_prochot failed (%d)\n", rv); + + return rv; +} + /*****************************************************************************/ /* ISL-9241 initialization */ static void isl9241_init(int chgnum) diff --git a/driver/charger/isl9241.h b/driver/charger/isl9241.h index b29a300fb2..0717a6237d 100644 --- a/driver/charger/isl9241.h +++ b/driver/charger/isl9241.h @@ -48,6 +48,7 @@ /* Configures various charger options */ #define ISL9241_REG_CONTROL1 0x3C +#define ISL9241_CONTROL1_PSYS BIT(3) #define ISL9241_CONTROL1_LEARN_MODE BIT(12) /* Configures various charger options */ @@ -67,6 +68,8 @@ /* 12 - Two-Level Adapter Current Limit */ #define ISL9241_CONTROL2_TWO_LEVEL_ADP_CURR BIT(12) /* 10:9 PROCHOT# debounce time in uS */ +#define ISL9241_CONTROL2_PROCHOT_DEBOUNCE_MASK GENMASK(10, 9) +#define ISL9241_CONTROL2_PROCHOT_DEBOUNCE_500 (2 << 9) #define ISL9241_CONTROL2_PROCHOT_DEBOUNCE_1000 (3 << 9) /* MinSystemVoltage [13:6] 8-bit (0x0000h = disables all battery charging) */ @@ -100,6 +103,8 @@ #define ISL9241_INFORMATION2_ACOK_PIN BIT(14) #define ISL9241_REG_CONTROL4 0x4E +/* 11: Rsense (Rs1:Rs2) ratio for PSYS (0 - 2:1, 1 - 1:1) */ +#define ISL9241_CONTROL4_PSYS_RSENSE_RATIO BIT(11) /* 13: Enable VSYS slew rate control (0 - disable, 1 - enable) */ #define ISL9241_CONTROL4_SLEW_RATE_CTRL BIT(13) @@ -134,4 +139,18 @@ extern const struct charger_drv isl9241_drv; */ int isl9241_set_ac_prochot(int chgnum, int ma); +/** + * Set DC prochot threshold + * + * @param chgnum: Index into charger chips + * @param ma: DC prochot threshold current in mA, multiple of 256mA + * @return EC_SUCCESS or error + */ +int isl9241_set_dc_prochot(int chgnum, int ma); + +#define ISL9241_AC_PROCHOT_CURRENT_MIN 128 /* mA */ +#define ISL9241_AC_PROCHOT_CURRENT_MAX 6400 /* mA */ +#define ISL9241_DC_PROCHOT_CURRENT_MIN 256 /* mA */ +#define ISL9241_DC_PROCHOT_CURRENT_MAX 12800 /* mA */ + #endif /* __CROS_EC_ISL9241_H */ -- cgit v1.2.1