From 1b68fd9680816e42b52c525a5fa3ee1ca8a10228 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Tue, 2 Apr 2013 17:35:46 +0800 Subject: spring: Retry when over current detected When we detect over current event, it might be a genuine over current event or the user messing with the charger. Let's add retry machinism to reduce the probability that a user re-plugging adapter causes charging current to be limited. BUG=chrome-os-partner:18527 TEST=Manual BRANCH=spring Original-Change-Id: I2b55a9eae39c56ada929e167cf09c4e91a32a55e Signed-off-by: Vic Yang Reviewed-on: https://gerrit.chromium.org/gerrit/47107 Reviewed-by: Vincent Palatin (cherry picked from commit 3c9827a64643008fbac1970871097512c6a24293) Change-Id: Ie791d2fdf0f2f33f723627e49b47a28ea3414bd9 Signed-off-by: Vic Yang Reviewed-on: https://gerrit.chromium.org/gerrit/47217 Reviewed-by: Vincent Palatin --- board/spring/usb_charging.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c index 10c834ee77..95449e796d 100644 --- a/board/spring/usb_charging.c +++ b/board/spring/usb_charging.c @@ -55,6 +55,7 @@ #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_STEP_UP 5 #define PWM_CTRL_VBUS_HARD_LOW 4400 @@ -116,6 +117,7 @@ struct { static timestamp_t power_removed_time[2]; static uint32_t power_removed_type[2]; static int power_removed_pwm_duty[2]; +static int oc_detect_retry[2] = {PWM_CTRL_OC_RETRY, PWM_CTRL_OC_RETRY}; /* PWM duty cycle limit based on over current event */ static int over_current_pwm_duty; @@ -415,8 +417,15 @@ static void usb_detect_overcurrent(int dev_type) int idx = !(dev_type == TSU6721_TYPE_VBUS_DEBOUNCED); timestamp_t now = get_time(); now.val -= power_removed_time[idx].val; - if (power_removed_type[idx] == dev_type && - now.val < PWM_CTRL_OC_DETECT_TIME) { + if (now.val >= PWM_CTRL_OC_DETECT_TIME) { + oc_detect_retry[idx] = PWM_CTRL_OC_RETRY; + return; + } + if (power_removed_type[idx] == dev_type) { + if (oc_detect_retry[idx] > 0) { + oc_detect_retry[idx]--; + return; + } over_current_pwm_duty = power_removed_pwm_duty[idx] + PWM_CTRL_OC_BACK_OFF; } -- cgit v1.2.1