From c5d978baacc44220445ad7b5641bbdb7b634cbfa Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Wed, 19 Jun 2013 10:46:43 +0800 Subject: [PATCH] spring: Hard-limit current draw from Toad The Toad cable is browning out from time to time. Let's limit its current in aggressive mode. Also fix a bug in hard current limit calculation. BUG=None TEST=Plug-in Toad cable and see PWM duty cycle starts higher. BRANCH=Spring Change-Id: I06d64418989aa32a99545986fe841914f054acde Signed-off-by: Vic Yang Reviewed-on: https://gerrit.chromium.org/gerrit/59161 Reviewed-by: Vincent Palatin --- common/extpower_usb.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/extpower_usb.c b/common/extpower_usb.c index 97034b1eec..5be7d2efc9 100644 --- a/common/extpower_usb.c +++ b/common/extpower_usb.c @@ -278,8 +278,14 @@ static int apple_charger_current(void) static int hard_current_limit(int limit) { + /* + * In aggressive mode, the PWM duty cycle goes lower than the nominal + * cycle for PWM_CTRL_OC_MARGIN. Therefore, increase duty cycle by + * PWM_CTRL_OC_MARGIN avoids going over the hard limit. + * (Note that lower PWM cycle translates to higher current) + */ if (current_limit_mode == LIMIT_AGGRESSIVE) - return limit - PWM_CTRL_OC_MARGIN; + return MIN(limit + PWM_CTRL_OC_MARGIN, 100); else return limit; } @@ -524,6 +530,8 @@ static void usb_update_ilim(int dev_type) current_limit = hard_current_limit(I_LIMIT_1500MA); else if (dev_type & TSU6721_TYPE_JIG_UART_ON) current_limit = hard_current_limit(I_LIMIT_2000MA); + else if (dev_type & TOAD_DEVICE_TYPE) + current_limit = hard_current_limit(I_LIMIT_500MA); pwm_nominal_duty_cycle(current_limit); } else {