summaryrefslogtreecommitdiff
path: root/baseboard/kukui
diff options
context:
space:
mode:
authorEric Yilun Lin <yllin@chromium.org>2020-03-13 10:52:02 +0800
committerCommit Bot <commit-bot@chromium.org>2020-03-13 09:37:50 +0000
commit4af7de3a8a64e677b2d83119fcff7f094fcf9b74 (patch)
treedaa06007abb5f5596d5108757c76e4f152897436 /baseboard/kukui
parent9a5de6a2ae81c534356e0fbd2bf8cfee54856674 (diff)
downloadchrome-ec-4af7de3a8a64e677b2d83119fcff7f094fcf9b74.tar.gz
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 <yllin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2100370 Reviewed-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'baseboard/kukui')
-rw-r--r--baseboard/kukui/charger_mt6370.c24
1 files changed, 17 insertions, 7 deletions
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);
}