diff options
author | Vic Yang <victoryang@chromium.org> | 2013-07-02 14:24:45 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-07-10 11:16:37 -0700 |
commit | 0d362effd7c29e274b890122a8783929d9615383 (patch) | |
tree | e3a2309a05ebc60c339e988dd1252dbc6c00287f | |
parent | a8e15b27bf171a542cfdeaa6eb6b45d93c38aed1 (diff) | |
download | chrome-ec-0d362effd7c29e274b890122a8783929d9615383.tar.gz |
spring: Fix a bug of PWM duty cycle upper bound
The return value from battery_current() is non-zero if there's an error.
Also rewrite the condition to make it more readable.
BUG=None
TEST=Check PWM duty cycle can be set to 100%
BRANCH=Spring
Original-Change-Id: If13a295d87a1abd2e67f1bb216dc58d3f3d29ba4
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/60735
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
(cherry picked from commit 29a157e5276a4f0ed004aaab365ad9e32b68c250)
Change-Id: I7383bfd49931c8555f92a74e5960bd7e40102fa6
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/61398
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | common/extpower_usb.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/common/extpower_usb.c b/common/extpower_usb.c index 8b20d79145..4402ad697b 100644 --- a/common/extpower_usb.c +++ b/common/extpower_usb.c @@ -412,13 +412,18 @@ static int pwm_check_vbus_high(int vbus) static void pwm_nominal_duty_cycle(int percent) { int dummy; + int new_percent = percent; + new_percent += PWM_CTRL_BEGIN_OFFSET; + + /* + * If the battery is dead, leave a minimum amount of current + * input to sustain the system. + */ if (battery_current(&dummy)) - set_pwm_duty_cycle(percent); - else if (percent + PWM_CTRL_BEGIN_OFFSET > PWM_CTRL_MAX_DUTY) - set_pwm_duty_cycle(PWM_CTRL_MAX_DUTY); - else - set_pwm_duty_cycle(percent + PWM_CTRL_BEGIN_OFFSET); + new_percent = MIN(new_percent, PWM_CTRL_MAX_DUTY); + + set_pwm_duty_cycle(new_percent); nominal_pwm_duty = percent; pwm_fast_mode = 1; } |