diff options
author | Vic Yang <victoryang@chromium.org> | 2013-03-05 12:16:15 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-03-05 18:42:26 -0800 |
commit | fa144d8ac007c3333435f0f419c6a5b511118988 (patch) | |
tree | f5c20274d7098a8bb2c2ed4402b0d466ce95de92 | |
parent | 03a1da3b657e20764bd171fcb321196fef031571 (diff) | |
download | chrome-ec-fa144d8ac007c3333435f0f419c6a5b511118988.tar.gz |
spring: avoid AC bad when load suddenly increase
To avoid AC bad condition when system load suddenly increase, we should:
- Keep VBUS voltage at reasonable level on battery assist
- Allow PWM to bring VBUS voltage up before asserting AC bad
BUG=chrome-os-partner:14319
TEST=Manual
BRANCH=none
Change-Id: I8058ffba9f91550f22408ea25911a1dded835584
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/44612
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | board/spring/board.c | 19 | ||||
-rw-r--r-- | board/spring/usb_charging.c | 16 |
2 files changed, 28 insertions, 7 deletions
diff --git a/board/spring/board.c b/board/spring/board.c index d7e7224bd2..5cf3fcf914 100644 --- a/board/spring/board.c +++ b/board/spring/board.c @@ -304,9 +304,22 @@ int board_pmu_init(void) int board_get_ac(void) { - /* UVLO is 4.1V. We consider AC bad when its voltage drops below 4.3V */ - return gpio_get_level(GPIO_BOOST_EN) && - adc_read_channel(ADC_CH_USB_VBUS_SNS) >= 4300; + static int last_vbus; + int vbus, vbus_good; + + if (!gpio_get_level(GPIO_BOOST_EN)) + return 0; + + /* + * UVLO is 4.1V. We consider AC bad when its voltage drops below 4.2V + * for two consecutive samples. This is to give PWM a chance to bring + * voltage up. + */ + vbus = adc_read_channel(ADC_CH_USB_VBUS_SNS); + vbus_good = (vbus >= 4200 || last_vbus >= 4200); + last_vbus = vbus; + + return vbus_good; } int board_led_breathing(int enabled) diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c index 08b7eba1ac..1c90de6455 100644 --- a/board/spring/usb_charging.c +++ b/board/spring/usb_charging.c @@ -46,6 +46,7 @@ #define PWM_CTRL_OC_BACK_OFF 3 #define PWM_CTRL_STEP_DOWN 2 #define PWM_CTRL_STEP_UP 5 +#define PWM_CTRL_VBUS_HARD_LOW 4400 #define PWM_CTRL_VBUS_LOW 4500 #define PWM_CTRL_VBUS_HIGH 4700 /* Must be higher than 4.5V */ @@ -214,6 +215,14 @@ static int board_pwm_check_lower_bound(void) current_pwm_duty > 0); } +static int board_pwm_check_vbus_low(int vbus, int battery_current) +{ + if (battery_current >= 0) + return vbus < PWM_CTRL_VBUS_LOW && current_pwm_duty < 100; + else + return vbus < PWM_CTRL_VBUS_HARD_LOW && current_pwm_duty < 100; +} + static void board_pwm_tweak(void) { int vbus, current; @@ -227,14 +236,13 @@ static void board_pwm_tweak(void) /* * If VBUS voltage is too low: * - If battery is discharging, throttling more is going to draw - * more current from the battery, so do nothing in this case. + * more current from the battery, so do nothing unless VBUS is + * about to be lower than AC good threshold. * - Otherwise, throttle input current to raise VBUS voltage. * If VBUS voltage is high enough, allow more current until we hit * current limit target. */ - if (vbus < PWM_CTRL_VBUS_LOW && - current_pwm_duty < 100 && - current >= 0) { + if (board_pwm_check_vbus_low(vbus, current)) { board_pwm_duty_cycle(current_pwm_duty + PWM_CTRL_STEP_UP); CPRINTF("[%T PWM duty up %d%%]\n", current_pwm_duty); } else if (vbus > PWM_CTRL_VBUS_HIGH && board_pwm_check_lower_bound()) { |