From 3fe117d346e2a23d316cbdf038f95ccb62ac4565 Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Mon, 25 Sep 2017 10:47:57 -0700 Subject: samus_pd: Adjust input current limit downward to prevent OC Based on measurements, Samus can pull more current than desired, even taking into account the existing INPUT_CURRENT_LIMIT_OFFSET_MA adjustment. Decrease the programmed current limit by an additional factor, determined by taking the worst-case power measurements across 15 different Samus devices, to ensure that Samus never pulls more current than desired. BUG=chrome-os-partner:55297 BRANCH=samus TEST=Verify with debug prints that curr_lim_ma becomes 256 when negotiated current limit is 500mA and curr_lim_ma becomes 2556 when negotiated limit is 3000mA. Signed-off-by: Shawn Nematbakhsh Change-Id: I6912d987c5a519f55a831698873a69c4cac817b8 Reviewed-on: https://chromium-review.googlesource.com/684696 Commit-Ready: Shawn N Tested-by: Shawn N Reviewed-by: Shawn N --- board/samus_pd/board.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'board') diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c index f20afd7985..bad38ed435 100644 --- a/board/samus_pd/board.c +++ b/board/samus_pd/board.c @@ -30,9 +30,6 @@ #define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args) -/* Amount to offset the input current limit when sending to EC */ -#define INPUT_CURRENT_LIMIT_OFFSET_MA 192 - /* * When battery is high, system may not be pulling full current. Also, when * high AND input voltage is below boost bypass, then limit input current @@ -484,8 +481,8 @@ static int board_update_charge_limit(int charge_ma) pwm_set_duty(PWM_CH_ILIM, pwm_duty); #endif - pd_status.curr_lim_ma = MAX(0, charge_ma - - INPUT_CURRENT_LIMIT_OFFSET_MA); + pd_status.curr_lim_ma = charge_ma >= 500 ? + (charge_ma - 500) * 92 / 100 + 256 : 0; CPRINTS("New ilim %d", charge_ma); return 1; -- cgit v1.2.1