From 4af7de3a8a64e677b2d83119fcff7f094fcf9b74 Mon Sep 17 00:00:00 2001 From: Eric Yilun Lin Date: Fri, 13 Mar 2020 10:52:02 +0800 Subject: kukui/dynamic-pdo: setting input current limit correctly While the input current is restricted when charger throttling, we should consider the previous set current limit, rather than just only the PD_MAX_CURRENT_MA. Otherwise, the power source's ability would be ignored, and will request more than the power source can provide. BRANCH=kukui BUG=b:147852834 b:141903096 TEST=Plug 9V/2A PD charger, and ensure krane drains under 2A. Change-Id: I8a0c99cad1c61e556af13ca166fdd0e3664af55d Signed-off-by: Eric Yilun Lin Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2100370 Reviewed-by: Ting Shen --- baseboard/kukui/charger_mt6370.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'baseboard/kukui') diff --git a/baseboard/kukui/charger_mt6370.c b/baseboard/kukui/charger_mt6370.c index b2c1e90935..d876c41fc2 100644 --- a/baseboard/kukui/charger_mt6370.c +++ b/baseboard/kukui/charger_mt6370.c @@ -58,7 +58,7 @@ static timestamp_t thermal_wait_until; /* input current bound when charger throttled */ static int throttled_ma = PD_MAX_CURRENT_MA; /* charge_ma in last board_set_charge_limit call */ -static int prev_charge_ma; +static int prev_charge_limit; /* charge_mv in last board_set_charge_limit call */ static int prev_charge_mv; @@ -99,7 +99,8 @@ static void battery_thermal_control(struct charge_state_data *curr) skip_reset = 1; thermal_wait_until.val = 0; throttled_ma = PD_MAX_CURRENT_MA; - board_set_charge_limit_throttle(prev_charge_ma, prev_charge_mv); + board_set_charge_limit_throttle(prev_charge_limit, + prev_charge_mv); return; } @@ -136,10 +137,19 @@ static void battery_thermal_control(struct charge_state_data *curr) * PID algorithm (https://en.wikipedia.org/wiki/PID_controller), * and operates on only P value. */ - throttled_ma = - MIN(PD_MAX_CURRENT_MA, - input_current + k_p * (thermal_bound.target - jc_temp)); - board_set_charge_limit_throttle(throttled_ma, prev_charge_mv); + throttled_ma = MIN( + PD_MAX_CURRENT_MA, + /* + * Should not pass the previously set input current by + * charger manager. This value might be related the charger's + * capability. + */ + MIN(prev_charge_limit, + input_current + k_p * (thermal_bound.target - jc_temp))); + + /* If the input current doesn't change, just skip. */ + if (throttled_ma != input_current) + board_set_charge_limit_throttle(throttled_ma, prev_charge_mv); thermal_exit: thermal_wait_until.val = get_time().val + (3 * SECOND); @@ -350,7 +360,7 @@ DECLARE_HOOK(HOOK_BATTERY_SOC_CHANGE, void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma, int charge_mv) { - prev_charge_ma = charge_ma; + prev_charge_limit = charge_ma; prev_charge_mv = charge_mv; board_set_charge_limit_throttle(charge_ma, charge_mv); } -- cgit v1.2.1