From 899f8967afd2f8af8fd1b20fc28ce876e2e8cc2d Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Fri, 8 Nov 2013 14:14:17 -0800 Subject: spring: add PWM limit Add a lower limit to the ILIM PWM. Signed-off-by: Vincent Palatin BRANCH=spring BUG=chrome-os-partner:23973 TEST=measure current on the power brick cable. Change-Id: I520bb5ecff82f8f443995c9144dfd9801a1142d6 Reviewed-on: https://chromium-review.googlesource.com/176253 Reviewed-by: Todd Broch Reviewed-by: Puneet Kumar Commit-Queue: Vincent Palatin Tested-by: Vincent Palatin --- board/spring/usb_charging.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c index 4032a63bee..e644715d83 100644 --- a/board/spring/usb_charging.c +++ b/board/spring/usb_charging.c @@ -60,6 +60,9 @@ #define I_LIMIT_2400MA MA_TO_PWM(2400) #define I_LIMIT_3000MA 0 +/* lower bound for PWM duty cycle : max charger current */ +#define I_LIMIT_MAX MA_TO_PWM(2500) + /* PWM control loop parameters */ #define PWM_CTRL_MAX_DUTY I_LIMIT_100MA /* Minimum current */ #define PWM_CTRL_BEGIN_OFFSET 90 @@ -357,8 +360,8 @@ int board_has_high_power_ac(void) void board_pwm_duty_cycle(int percent) { - if (percent < 0) - percent = 0; + if (percent < I_LIMIT_MAX) + percent = I_LIMIT_MAX; if (percent > 100) percent = 100; @@ -406,12 +409,15 @@ static int board_pwm_get_next_lower(void) if (current_pwm_duty > nominal_pwm_duty - PWM_CTRL_OC_MARGIN && current_pwm_duty > over_current_pwm_duty && - current_pwm_duty > 0) - return MAX(current_pwm_duty - PWM_CTRL_STEP_DOWN, 0); + current_pwm_duty > I_LIMIT_MAX) + return MAX(current_pwm_duty - PWM_CTRL_STEP_DOWN, + I_LIMIT_MAX); return -1; } else { - if (current_pwm_duty > nominal_pwm_duty && current_pwm_duty > 0) - return MAX(current_pwm_duty - PWM_CTRL_STEP_DOWN, 0); + if (current_pwm_duty > nominal_pwm_duty && + current_pwm_duty > I_LIMIT_MAX) + return MAX(current_pwm_duty - PWM_CTRL_STEP_DOWN, + I_LIMIT_MAX); else return -1; } @@ -466,7 +472,7 @@ static void board_pwm_tweak(void) CPRINTF("[%T PWM duty up %d%%]\n", current_pwm_duty); } else if (board_pwm_check_vbus_high(vbus)) { next = board_pwm_get_next_lower(); - if (next >= 0) { + if (next >= I_LIMIT_MAX) { board_pwm_duty_cycle(next); CPRINTF("[%T PWM duty down %d%%]\n", current_pwm_duty); } -- cgit v1.2.1