summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2013-11-08 14:14:17 -0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-11-08 23:37:48 +0000
commit899f8967afd2f8af8fd1b20fc28ce876e2e8cc2d (patch)
treedcb4af1988bf81237b3726b6770887ab4c90dea7
parent655fe88024c5367cc66363fa32e470c78bdd5c45 (diff)
downloadchrome-ec-899f8967afd2f8af8fd1b20fc28ce876e2e8cc2d.tar.gz
spring: add PWM limit
Add a lower limit to the ILIM PWM. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> 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 <tbroch@chromium.org> Reviewed-by: Puneet Kumar <puneetster@chromium.org> Commit-Queue: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/spring/usb_charging.c20
1 files 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);
}