diff options
author | Scott Collyer <scollyer@google.com> | 2019-09-23 16:38:02 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-10-01 06:19:27 +0000 |
commit | 34b58efd6a434a6530a224458a00ec207ed9ba88 (patch) | |
tree | 2eb7ed91e26462e25158504eccae488174512f1b | |
parent | 56f611ffdc7a52f192f898cb15e1eb7e9e940ba2 (diff) | |
download | chrome-ec-34b58efd6a434a6530a224458a00ec207ed9ba88.tar.gz |
bq25710: Update ICO mode feature for charger hw ramp
This CL makes some modifications to how ICO mode is utilized to
support the input current hw ramp feature. ICO mode can't be used when
there is no battery present, so a check has been added for battery
presence. In addition, the input current limit should have been read
from the IIN_DPM register.
BRANCH=none
BUG=b:126229130
TEST=Tested variaous legacy chargers and verfied that ICO mode
completes and gives the expected current limit. Tested that when no
battery is present, ICO mode is not enabled.
Change-Id: Ib2dcff4c7bddea52c267d678b17c50daf1356b44
Signed-off-by: Scott Collyer <scollyer@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1827255
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Commit-Queue: Scott Collyer <scollyer@chromium.org>
-rw-r--r-- | driver/charger/bq25710.c | 47 | ||||
-rw-r--r-- | driver/charger/bq25710.h | 4 |
2 files changed, 33 insertions, 18 deletions
diff --git a/driver/charger/bq25710.c b/driver/charger/bq25710.c index e7bb4d3b66..8e418ea103 100644 --- a/driver/charger/bq25710.c +++ b/driver/charger/bq25710.c @@ -5,6 +5,7 @@ * TI bq25710 battery charger driver. */ +#include "battery.h" #include "battery_smart.h" #include "bq25710.h" #include "charge_ramp.h" @@ -443,13 +444,20 @@ static void bq25710_chg_ramp_handle(void) /* * Once the charge ramp is stable write back the stable ramp - * current to input current register. + * current to the host input current limit register */ + ramp_curr = chg_ramp_get_current_limit(); if (chg_ramp_is_stable()) { - ramp_curr = chg_ramp_get_current_limit(); if (ramp_curr && !charger_set_input_current(ramp_curr)) - CPRINTF("stable ramp current=%d\n", ramp_curr); + CPRINTF("bq25710: stable ramp current=%d\n", ramp_curr); + } else { + CPRINTF("bq25710: ICO stall, ramp current=%d\n", ramp_curr); } + /* + * Disable ICO mode. When ICO mode is active the input current limit is + * given by the value in register IIN_DPM (0x22) + */ + charger_set_hw_ramp(0); } DECLARE_DEFERRED(bq25710_chg_ramp_handle); @@ -465,6 +473,16 @@ int charger_set_hw_ramp(int enable) return rv; if (enable) { + /* + * ICO mode can only be used when a battery is present. If there + * is no battery, then enabling ICO mode will lead to VSYS + * dropping out. + */ + if (!battery_is_present()) { + CPRINTF("bq25710: no battery, skip ICO enable\n"); + return EC_ERROR_UNKNOWN; + } + /* Set InputVoltage register to BC1.2 minimum ramp voltage */ rv = raw_write16(BQ25710_REG_INPUT_VOLTAGE, BQ25710_BC12_MIN_VOLTAGE_MV); @@ -510,22 +528,15 @@ int chg_ramp_get_current_limit(void) { int reg, rv; - rv = bq25710_adc_start(BQ25710_ADC_OPTION_EN_ADC_IIN); - if (rv) - goto error; - - /* Read ADC value */ - rv = raw_read16(BQ25710_REG_ADC_CMPIN_IIN, ®); - if (rv) - goto error; - - /* LSB => 50mA */ - return (reg >> BQ25710_ADC_IIN_STEP_BIT_OFFSET) * - BQ25710_ADC_IIN_STEP_MA; + rv = raw_read16(BQ25710_REG_IIN_DPM, ®); + if (rv) { + CPRINTF("Could not read iin_dpm current limit! Error: %d\n", + rv); + return 0; + } -error: - CPRINTF("Could not read input current limit ADC! Error: %d\n", rv); - return 0; + return ((reg >> BQ25710_IIN_DPM_BIT_SHIFT) * BQ25710_IIN_DPM_STEP_MA + + BQ25710_IIN_DPM_STEP_MA); } #endif /* CONFIG_CHARGE_RAMP_HW */ diff --git a/driver/charger/bq25710.h b/driver/charger/bq25710.h index c3880be13c..014799a832 100644 --- a/driver/charger/bq25710.h +++ b/driver/charger/bq25710.h @@ -89,4 +89,8 @@ #define BQ25710_PROCHOT_PROFILE_VSYS BIT(2) #define BQ25710_PROCHOT_IDCHG_VTH_MASK 0xFC00 +/* IIN_DPM Register */ +#define BQ25710_IIN_DPM_BIT_SHIFT 8 +#define BQ25710_IIN_DPM_STEP_MA 50 + #endif /* __CROS_EC_BQ25710_H */ |