diff options
author | Eric Yilun Lin <yllin@chromium.org> | 2021-10-14 17:00:38 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-15 02:26:08 +0000 |
commit | 537def8417e4cdf7f381474c57ec93f6cb963a3c (patch) | |
tree | 58e1ae34b0358bd2fce96a768199674f1c1017b3 /common/charge_state_v2.c | |
parent | 4438e19d17265fad22e51f2c597cb16f055703ed (diff) | |
download | chrome-ec-537def8417e4cdf7f381474c57ec93f6cb963a3c.tar.gz |
charge: respect PDO current maximum limit
The current input limit setting doesn't respect the PDO's
current limit (e.g. when the current limit is less than
CONFIG_INPUT_CURRENT_LIMIT) and this might cause the over-draining
the charger.
BUG=b:172878439
TEST=1) make buildall
2) modified servo-v4 which only broadcast PDOs with 250mA current
limit and ensure the goroh won't sink more than 250mA.
(while the CONFIG_INPUT_CURRENT_LIMIT is 512mA)
BRANCH=main
Change-Id: I09f8e6fb39a072ee38ea09a5c9898984f4122513
Signed-off-by: Eric Yilun Lin <yllin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3220037
Commit-Queue: Eric Yilun Lin <yllin@google.com>
Tested-by: Eric Yilun Lin <yllin@google.com>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'common/charge_state_v2.c')
-rw-r--r-- | common/charge_state_v2.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 59f38edee8..abfabda7a3 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -2694,6 +2694,19 @@ int charge_set_input_current_limit(int ma, int mv) /* Limit input current limit to max limit for this board */ ma = MIN(ma, CONFIG_CHARGER_MAX_INPUT_CURRENT); #endif + + if (IS_ENABLED(CONFIG_CHARGE_MANAGER)) { + int pd_current_uncapped = + charge_manager_get_pd_current_uncapped(); + + /* + * clamp the input current to not exceeded the PD's limitation. + */ + if (pd_current_uncapped != CHARGE_CURRENT_UNINITIALIZED && + ma > pd_current_uncapped) + ma = pd_current_uncapped; + } + curr.desired_input_current = ma; #ifdef CONFIG_EC_EC_COMM_BATTERY_CLIENT /* Wake up charger task to allocate current between lid and base. */ |