diff options
author | Vic Yang <victoryang@chromium.org> | 2013-05-07 14:01:27 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-05-13 17:30:14 -0700 |
commit | e866084a5260e7866cf5bab74dd12a3a3721412c (patch) | |
tree | 9623e721e6d7abb540a7a08705a2872470f06ed8 | |
parent | 9d38b1b392b34f17b807c66e7b1a86605ccbf501 (diff) | |
download | chrome-ec-e866084a5260e7866cf5bab74dd12a3a3721412c.tar.gz |
spring: Improve charging current control
This includes:
- Increase overcurrent retry count from 1 to 2.
- Mark overcurrent event regardless of what current PWM duty cycle is.
- PWM duty cycle settles faster.
- PWM duty cycle starts from ~100%.
BUG=chrome-os-partner:19001, chrome-os-partner:19037
TEST=Manual
BRANCH=spring
Original-Change-Id: Idf007fb589fde3baef6c8975dfa1f2fc1ec6e95d
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/50262
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
(cherry picked from commit ac3488cd0b41ade3dd38ec61c4b07db6489f2260)
Change-Id: I0fee98efa05d0f7f801242ec129740c8f0e5f2f8
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/50964
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | board/spring/usb_charging.c | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c index 4c72866cc2..dba0447c8c 100644 --- a/board/spring/usb_charging.c +++ b/board/spring/usb_charging.c @@ -51,13 +51,14 @@ /* PWM control loop parameters */ #define PWM_CTRL_MAX_DUTY 96 /* Minimum current for dead battery */ -#define PWM_CTRL_BEGIN_OFFSET 30 +#define PWM_CTRL_BEGIN_OFFSET 90 #define PWM_CTRL_OC_MARGIN 15 #define PWM_CTRL_OC_DETECT_TIME (800 * MSEC) #define PWM_CTRL_OC_BACK_OFF 3 -#define PWM_CTRL_OC_RETRY 1 -#define PWM_CTRL_STEP_DOWN 2 +#define PWM_CTRL_OC_RETRY 2 +#define PWM_CTRL_STEP_DOWN 3 #define PWM_CTRL_STEP_UP 5 +#define PWM_CTRL_STEP_FAST_DOWN 15 #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 */ @@ -298,16 +299,29 @@ void board_pwm_init_limit(void) board_ilim_config(ILIM_CONFIG_MANUAL_ON); } -static int board_pwm_check_lower_bound(void) -{ - if (current_limit_mode == LIMIT_AGGRESSIVE) - return (current_pwm_duty > nominal_pwm_duty - - PWM_CTRL_OC_MARGIN && - current_pwm_duty > over_current_pwm_duty && - current_pwm_duty > 0); - else - return (current_pwm_duty > nominal_pwm_duty && - current_pwm_duty > 0); +/** + * Returns next lower PWM duty cycle, or -1 for unchanged duty cycle. + */ +static int board_pwm_get_next_lower(void) +{ + int fast_next = current_pwm_duty - PWM_CTRL_STEP_FAST_DOWN; + + if (current_limit_mode == LIMIT_AGGRESSIVE) { + if (fast_next >= nominal_pwm_duty - PWM_CTRL_OC_MARGIN && + fast_next >= over_current_pwm_duty) + return MAX(fast_next, 0); + 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); + return -1; + } else { + if (current_pwm_duty > nominal_pwm_duty && current_pwm_duty > 0) + return MAX(current_pwm_duty - PWM_CTRL_STEP_DOWN, 0); + else + return -1; + } } static int board_pwm_check_vbus_low(int vbus, int battery_current) @@ -321,6 +335,7 @@ static int board_pwm_check_vbus_low(int vbus, int battery_current) static void board_power_tweak(void) { int vbus, current; + int next; if (current_ilim_config != ILIM_CONFIG_PWM) return; @@ -356,9 +371,12 @@ static void board_power_tweak(void) 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()) { - board_pwm_duty_cycle(current_pwm_duty - PWM_CTRL_STEP_DOWN); - CPRINTF("[%T PWM duty down %d%%]\n", current_pwm_duty); + } else if (vbus > PWM_CTRL_VBUS_HIGH) { + next = board_pwm_get_next_lower(); + if (next >= 0) { + board_pwm_duty_cycle(next); + CPRINTF("[%T PWM duty down %d%%]\n", current_pwm_duty); + } } } DECLARE_HOOK(HOOK_SECOND, board_power_tweak, HOOK_PRIO_DEFAULT); @@ -474,11 +492,10 @@ static void usb_detect_overcurrent(int dev_type) power_removed_time[idx] = get_time(); power_removed_type[idx] = current_dev_type; /* - * Considering user may plug/unplug the charger too fast, we - * don't limit current to lower than nominal current limit. + * TODO(victoryang): Record the maximum current seen during + * retry? */ - power_removed_pwm_duty[idx] = MIN(current_pwm_duty, - nominal_pwm_duty); + power_removed_pwm_duty[idx] = current_pwm_duty; } else if (dev_type & TSU6721_TYPE_VBUS_DEBOUNCED) { int idx = !(dev_type == TSU6721_TYPE_VBUS_DEBOUNCED); timestamp_t now = get_time(); |