diff options
author | Eric Yilun Lin <yllin@chromium.org> | 2020-12-01 17:06:56 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-12-08 06:28:52 +0000 |
commit | dd1942af2d0b308e0b2d6210bfabeadb053101da (patch) | |
tree | 17569960b331afe0e73585caaab638e930ebeedd | |
parent | 7ae129c1f3cd76722902da6582825f53e4aff344 (diff) | |
download | chrome-ec-dd1942af2d0b308e0b2d6210bfabeadb053101da.tar.gz |
charger: replace charger_get_input_current uses
Replace them with charger_get_input_current_limit which is
aligned to the old usage, no funcional changes.
Keep OCPC charger_get_input_current uses as was, since it
is its intended use.
Also, implement
- isl923x_get_input_current, raa48900_get_input_current
- sm5803_get_input_current_limit
BUG=b:171853295
TEST=1. grep "\<charger_get_input_current\>"; only ocpc uses the function.
2. make buildall
3. test with CL:2569086 on waddledee(sm5803), waddledoo(raa489000),
hayato(isl923x), pompom(isl923x), and ensure the output
of `curr 0|1` equalts to the report of power meter.
BRANCH=none
Change-Id: I71aca33cbc88dda9b0238cb71b1609665a9c9a7f
Signed-off-by: Eric Yilun Lin <yllin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2569085
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | baseboard/kukui/charger_mt6370.c | 2 | ||||
-rw-r--r-- | board/host/charger.c | 6 | ||||
-rw-r--r-- | common/charge_state_v2.c | 2 | ||||
-rw-r--r-- | common/charger.c | 4 | ||||
-rw-r--r-- | driver/charger/bd9995x.c | 6 | ||||
-rw-r--r-- | driver/charger/bq24715.c | 6 | ||||
-rw-r--r-- | driver/charger/bq24773.c | 6 | ||||
-rw-r--r-- | driver/charger/bq25710.c | 6 | ||||
-rw-r--r-- | driver/charger/isl923x.c | 50 | ||||
-rw-r--r-- | driver/charger/isl9241.c | 6 | ||||
-rw-r--r-- | driver/charger/rt946x.c | 10 | ||||
-rw-r--r-- | driver/charger/sm5803.c | 17 | ||||
-rw-r--r-- | include/charger.h | 9 |
13 files changed, 91 insertions, 39 deletions
diff --git a/baseboard/kukui/charger_mt6370.c b/baseboard/kukui/charger_mt6370.c index 5e78a100c5..327b567db6 100644 --- a/baseboard/kukui/charger_mt6370.c +++ b/baseboard/kukui/charger_mt6370.c @@ -117,7 +117,7 @@ static void battery_thermal_control(struct charge_state_data *curr) return; /* If we fail to read input curr limit, skip for this cycle. */ - if (charger_get_input_current(CHARGER_SOLO, &input_current)) + if (charger_get_input_current_limit(CHARGER_SOLO, &input_current)) return; /* diff --git a/board/host/charger.c b/board/host/charger.c index 1128f318d3..4db1f44351 100644 --- a/board/host/charger.c +++ b/board/host/charger.c @@ -120,8 +120,8 @@ static enum ec_error_list mock_device_id(int chgnum, int *id) return EC_SUCCESS; } - -static enum ec_error_list mock_get_input_current(int chgnum, int *input_current) +static enum ec_error_list mock_get_input_current_limit(int chgnum, + int *input_current) { *input_current = mock_input_current; return EC_SUCCESS; @@ -161,7 +161,7 @@ const struct charger_drv mock_drv = { .get_voltage = &mock_get_voltage, .set_voltage = &mock_set_voltage, .set_input_current_limit = &mock_set_input_current_limit, - .get_input_current = &mock_get_input_current, + .get_input_current_limit = &mock_get_input_current_limit, .manufacturer_id = &mock_manufacturer_id, .device_id = &mock_device_id, .get_option = &mock_get_option, diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index ecce4fbdb2..409d484dae 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -2449,7 +2449,7 @@ int charge_set_input_current_limit(int ma, int mv) int prev_input = 0; - charger_get_input_current(chgnum, &prev_input); + charger_get_input_current_limit(chgnum, &prev_input); #ifdef CONFIG_USB_POWER_DELIVERY #if ((PD_MAX_POWER_MW * 1000) / PD_MAX_VOLTAGE_MV != PD_MAX_CURRENT_MA) diff --git a/common/charger.c b/common/charger.c index 45ffafdec3..6e54f2289d 100644 --- a/common/charger.c +++ b/common/charger.c @@ -111,7 +111,7 @@ void charger_get_params(struct charger_params *chg) if (charger_get_voltage(chgnum, &chg->voltage)) chg->flags |= CHG_FLAG_BAD_VOLTAGE; - if (charger_get_input_current(chgnum, &chg->input_current)) + if (charger_get_input_current_limit(chgnum, &chg->input_current)) chg->flags |= CHG_FLAG_BAD_INPUT_CURRENT; if (charger_get_status(&chg->status)) @@ -172,7 +172,7 @@ void print_charger_debug(int chgnum) /* input current limit */ print_item_name("I_in:"); - if (check_print_error(charger_get_input_current(chgnum, &d))) + if (check_print_error(charger_get_input_current_limit(chgnum, &d))) ccprintf("%5d (%4d - %5d, %3d)\n", d, info->input_current_min, info->input_current_max, info->input_current_step); diff --git a/driver/charger/bd9995x.c b/driver/charger/bd9995x.c index b38776a574..6fd79b8d8f 100644 --- a/driver/charger/bd9995x.c +++ b/driver/charger/bd9995x.c @@ -634,8 +634,8 @@ static enum ec_error_list bd9995x_set_input_current_limit(int chgnum, BD9995X_BAT_CHG_COMMAND); } -static enum ec_error_list bd9995x_get_input_current(int chgnum, - int *input_current) +static enum ec_error_list bd9995x_get_input_current_limit(int chgnum, + int *input_current) { return ch_raw_read16(chgnum, BD9995X_CMD_CUR_ILIM_VAL, input_current, BD9995X_EXTENDED_COMMAND); @@ -1732,7 +1732,7 @@ const struct charger_drv bd9995x_drv = { .discharge_on_ac = &bd9995x_discharge_on_ac, .get_vbus_voltage = &bd9995x_get_vbus_voltage, .set_input_current_limit = &bd9995x_set_input_current_limit, - .get_input_current = &bd9995x_get_input_current, + .get_input_current_limit = &bd9995x_get_input_current_limit, .manufacturer_id = &bd9995x_manufacturer_id, .device_id = &bd9995x_device_id, .get_option = &bd9995x_get_option, diff --git a/driver/charger/bq24715.c b/driver/charger/bq24715.c index 8c83575c65..d2eb0e432a 100644 --- a/driver/charger/bq24715.c +++ b/driver/charger/bq24715.c @@ -56,8 +56,8 @@ static enum ec_error_list bq24715_set_input_current_limit(int chgnum, CURRENT_TO_REG(input_current, R_AC)); } -static enum ec_error_list bq24715_get_input_current(int chgnum, - int *input_current) +static enum ec_error_list bq24715_get_input_current_limit(int chgnum, + int *input_current) { int rv; int reg; @@ -244,7 +244,7 @@ const struct charger_drv bq24715_drv = { .set_voltage = &bq24715_set_voltage, .discharge_on_ac = &bq24715_discharge_on_ac, .set_input_current_limit = &bq24715_set_input_current_limit, - .get_input_current = &bq24715_get_input_current, + .get_input_current_limit = &bq24715_get_input_current_limit, .manufacturer_id = &bq24715_manufacturer_id, .device_id = &bq24715_device_id, .get_option = &bq24715_get_option, diff --git a/driver/charger/bq24773.c b/driver/charger/bq24773.c index b18c678b3a..d72faa3bed 100644 --- a/driver/charger/bq24773.c +++ b/driver/charger/bq24773.c @@ -103,8 +103,8 @@ static enum ec_error_list bq2477x_set_input_current_limit(int chgnum, #endif } -static enum ec_error_list bq2477x_get_input_current(int chgnum, - int *input_current) +static enum ec_error_list bq2477x_get_input_current_limit(int chgnum, + int *input_current) { int rv; int reg; @@ -309,7 +309,7 @@ const struct charger_drv bq2477x_drv = { .set_voltage = &bq2477x_set_voltage, .discharge_on_ac = &bq2477x_discharge_on_ac, .set_input_current_limit = &bq2477x_set_input_current_limit, - .get_input_current = &bq2477x_get_input_current, + .get_input_current_limit = &bq2477x_get_input_current_limit, .manufacturer_id = &bq2477x_manufacturer_id, .device_id = &bq2477x_device_id, .get_option = &bq2477x_get_option, diff --git a/driver/charger/bq25710.c b/driver/charger/bq25710.c index fdfacbaa35..77520be010 100644 --- a/driver/charger/bq25710.c +++ b/driver/charger/bq25710.c @@ -397,8 +397,8 @@ static enum ec_error_list bq25710_set_input_current_limit(int chgnum, BQ25710_CHARGE_IIN_BIT_0FFSET); } -static enum ec_error_list bq25710_get_input_current(int chgnum, - int *input_current) +static enum ec_error_list bq25710_get_input_current_limit(int chgnum, + int *input_current) { int rv, reg; @@ -670,7 +670,7 @@ const struct charger_drv bq25710_drv = { .discharge_on_ac = &bq25710_discharge_on_ac, .get_vbus_voltage = &bq25710_get_vbus_voltage, .set_input_current_limit = &bq25710_set_input_current_limit, - .get_input_current = &bq25710_get_input_current, + .get_input_current_limit = &bq25710_get_input_current_limit, .manufacturer_id = &bq25710_manufacturer_id, .device_id = &bq25710_device_id, .get_option = &bq25710_get_option, diff --git a/driver/charger/isl923x.c b/driver/charger/isl923x.c index 3d70ba6431..75bff01959 100644 --- a/driver/charger/isl923x.c +++ b/driver/charger/isl923x.c @@ -214,30 +214,55 @@ static int get_amon_bmon(int chgnum, enum isl923x_amon_bmon amon, } #endif -static enum ec_error_list isl923x_get_input_current(int chgnum, +static enum ec_error_list isl923x_get_input_current_limit(int chgnum, + int *input_current) +{ + int rv; + int regval; + + rv = raw_read16(chgnum, ISL923X_REG_ADAPTER_CURRENT_LIMIT1, ®val); + if (rv) + return rv; + + *input_current = AC_REG_TO_CURRENT(regval); + return EC_SUCCESS; +} + +#ifdef CONFIG_CHARGER_RAA489000 +static enum ec_error_list raa489000_get_input_current(int chgnum, int *input_current) { int rv; int regval; int reg; - if (IS_ENABLED(CONFIG_CHARGER_RAA489000)) - reg = RAA489000_REG_ADC_INPUT_CURRENT; - else - reg = ISL923X_REG_ADAPTER_CURRENT_LIMIT1; + reg = RAA489000_REG_ADC_INPUT_CURRENT; rv = raw_read16(chgnum, reg, ®val); if (rv) return rv; - if (IS_ENABLED(CONFIG_CHARGER_RAA489000)) { - /* LSB is 22.2mA */ - regval *= 22; - } + /* LSB is 22.2mA */ + regval *= 22; *input_current = AC_REG_TO_CURRENT(regval); return EC_SUCCESS; } +#elif defined(CONFIG_CMD_CHARGER_ADC_AMON_BMON) +static enum ec_error_list isl923x_get_input_current(int chgnum, + int *input_current) +{ + int rv, adc; + + rv = get_amon_bmon(chgnum, AMON, MON_CHARGE, &adc); + if (rv) + return rv; + + *input_current = adc / CONFIG_CHARGER_SENSE_RESISTOR_AC; + + return EC_SUCCESS; +} +#endif /* CONFIG_CHARGER_RAA489000 */ #if defined(CONFIG_CHARGER_OTG) && defined(CHARGER_ISL9238X) static enum ec_error_list isl923x_enable_otg_power(int chgnum, int enabled) @@ -913,7 +938,7 @@ static int isl923x_ramp_get_current_limit(int chgnum) */ int input_current; - if (isl923x_get_input_current(chgnum, &input_current) != EC_SUCCESS) + if (isl923x_get_input_current_limit(chgnum, &input_current)) return 0; return input_current; } @@ -1282,7 +1307,12 @@ const struct charger_drv isl923x_drv = { .discharge_on_ac = &isl923x_discharge_on_ac, .get_vbus_voltage = &isl923x_get_vbus_voltage, .set_input_current_limit = &isl923x_set_input_current_limit, + .get_input_current_limit = &isl923x_get_input_current_limit, +#ifdef CONFIG_CHARGER_RAA489000 + .get_input_current = &raa489000_get_input_current, +#elif defined(CONFIG_CMD_CHARGER_ADC_AMON_BMON) .get_input_current = &isl923x_get_input_current, +#endif .manufacturer_id = &isl923x_manufacturer_id, .device_id = &isl923x_device_id, .get_option = &isl923x_get_option, diff --git a/driver/charger/isl9241.c b/driver/charger/isl9241.c index 57b9f918e1..d0a8127b21 100644 --- a/driver/charger/isl9241.c +++ b/driver/charger/isl9241.c @@ -102,8 +102,8 @@ static enum ec_error_list isl9241_set_input_current_limit(int chgnum, return isl9241_write(chgnum, ISL9241_REG_ADAPTER_CUR_LIMIT2, reg); } -static enum ec_error_list isl9241_get_input_current(int chgnum, - int *input_current) +static enum ec_error_list isl9241_get_input_current_limit(int chgnum, + int *input_current) { int rv; @@ -539,7 +539,7 @@ const struct charger_drv isl9241_drv = { .discharge_on_ac = &isl9241_discharge_on_ac, .get_vbus_voltage = &isl9241_get_vbus_voltage, .set_input_current_limit = &isl9241_set_input_current_limit, - .get_input_current = &isl9241_get_input_current, + .get_input_current_limit = &isl9241_get_input_current_limit, .manufacturer_id = &isl9241_manufacturer_id, .device_id = &isl9241_device_id, .get_option = &isl9241_get_option, diff --git a/driver/charger/rt946x.c b/driver/charger/rt946x.c index e63a0f2338..71e38e8f75 100644 --- a/driver/charger/rt946x.c +++ b/driver/charger/rt946x.c @@ -712,8 +712,8 @@ static enum ec_error_list rt946x_set_input_current_limit(int chgnum, reg_iin << RT946X_SHIFT_AICR); } -static enum ec_error_list rt946x_get_input_current(int chgnum, - int *input_current) +static enum ec_error_list rt946x_get_input_current_limit(int chgnum, + int *input_current) { int rv; int val = 0; @@ -1061,7 +1061,7 @@ static int rt946x_ramp_get_current_limit(int chgnum) int rv; int input_current = 0; - rv = rt946x_get_input_current(chgnum, &input_current); + rv = rt946x_get_input_current_limit(chgnum, &input_current); return rv ? -1 : input_current; } @@ -1341,7 +1341,7 @@ int rt946x_get_adc(enum rt946x_adc_in_sel adc_sel, int *adc_val) goto out; if (adc_sel == MT6370_ADC_IBUS) { - rv = charger_get_input_current(CHARGER_SOLO, &aicr); + rv = charger_get_input_current_limit(CHARGER_SOLO, &aicr); if (rv) goto out; } @@ -1896,7 +1896,7 @@ const struct charger_drv rt946x_drv = { .discharge_on_ac = &rt946x_discharge_on_ac, .get_vbus_voltage = &rt946x_get_vbus_voltage, .set_input_current_limit = &rt946x_set_input_current_limit, - .get_input_current = &rt946x_get_input_current, + .get_input_current_limit = &rt946x_get_input_current_limit, .manufacturer_id = &rt946x_manufacturer_id, .device_id = &rt946x_device_id, .get_option = &rt946x_get_option, diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c index c5415eb260..541499b256 100644 --- a/driver/charger/sm5803.c +++ b/driver/charger/sm5803.c @@ -1277,6 +1277,20 @@ static enum ec_error_list sm5803_set_input_current_limit(int chgnum, return chg_write8(chgnum, SM5803_REG_CHG_ILIM, reg); } +static enum ec_error_list sm5803_get_input_current_limit(int chgnum, + int *input_current) +{ + int rv; + int val; + + rv = chg_read8(chgnum, SM5803_REG_CHG_ILIM, &val); + if (rv) + return rv; + + *input_current = SM5803_REG_TO_CURRENT(val & SM5803_CHG_ILIM_RAW); + return rv; +} + static enum ec_error_list sm5803_get_input_current(int chgnum, int *input_current) { @@ -1533,7 +1547,7 @@ static int sm5803_ramp_get_current_limit(int chgnum) int rv; int input_current = 0; - rv = sm5803_get_input_current(chgnum, &input_current); + rv = sm5803_get_input_current_limit(chgnum, &input_current); return rv ? -1 : input_current; } @@ -1601,6 +1615,7 @@ const struct charger_drv sm5803_drv = { .discharge_on_ac = &sm5803_discharge_on_ac, .get_vbus_voltage = &sm5803_get_vbus_voltage, .set_input_current_limit = &sm5803_set_input_current_limit, + .get_input_current_limit = &sm5803_get_input_current_limit, .get_input_current = &sm5803_get_input_current, .device_id = &sm5803_get_dev_id, .get_option = &sm5803_get_option, diff --git a/include/charger.h b/include/charger.h index 3806d3d91f..4f64b8f5c2 100644 --- a/include/charger.h +++ b/include/charger.h @@ -285,10 +285,17 @@ enum ec_error_list charger_set_input_current_limit(int chgnum, */ enum ec_error_list charger_get_input_current_limit(int chgnum, int *input_current); -/* + +/** * Get actual input current value. + * * Actual input current may be less than the desired input current set * due to current ratings of the wall adapter. + * + * @param chgnum charger IC index + * @param input_current The input current in mA. + * + * @return EC_SUCCESS on success, an error otherwise. */ enum ec_error_list charger_get_input_current(int chgnum, int *input_current); |