summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-04-02 17:35:46 +0800
committerChromeBot <chrome-bot@google.com>2013-04-02 20:42:47 -0700
commit3c9827a64643008fbac1970871097512c6a24293 (patch)
tree88b99954f19dfbd600a30bcb433405b24d1340ec
parent23bbebaeb98b2c8da7e8c24414e0f1cc068cda52 (diff)
downloadchrome-ec-3c9827a64643008fbac1970871097512c6a24293.tar.gz
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 Change-Id: I2b55a9eae39c56ada929e167cf09c4e91a32a55e Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/47107 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/spring/usb_charging.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/board/spring/usb_charging.c b/board/spring/usb_charging.c
index 45babf5eb8..752d67c1bf 100644
--- a/board/spring/usb_charging.c
+++ b/board/spring/usb_charging.c
@@ -52,6 +52,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
@@ -105,6 +106,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;
@@ -397,8 +399,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;
}