diff options
author | Vic Yang <victoryang@chromium.org> | 2013-07-02 12:20:35 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-07-10 11:16:39 -0700 |
commit | ee4eedf29e8636c3f45333d0c3794356fc545ae6 (patch) | |
tree | 947817a1e6c22ef731a9da69c254a7ff2acc419a | |
parent | 913f227e365a225edb486ce6013132865ce8d110 (diff) | |
download | chrome-ec-ee4eedf29e8636c3f45333d0c3794356fc545ae6.tar.gz |
Improve over current detection
This includes:
- Capturing over-current event on transition from known device type to
unknown device type.
- Limiting current draw when device type is not determined yet.
- Shortening CABLE_DET delay to 0.6 seconds so that over-current event
for USB host has a 0.6-second window for the charger to recover.
BUG=chrome-os-partner:20648
TEST=Charge with Arrow
BRANCH=Spring
Original-Change-Id: Ie66ccd2d69adf8436a67e504f82da6eca3d0b14f
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/60730
(cherry picked from commit 03493a72db6ea5e12eda2a9488253d7fae6eec0b)
Change-Id: I5d3cf7054960f5d4f924bce76f87257af57ebdb8
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/61400
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | common/extpower_usb.c | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/common/extpower_usb.c b/common/extpower_usb.c index edc7ed8d7c..199bfa1b4d 100644 --- a/common/extpower_usb.c +++ b/common/extpower_usb.c @@ -59,6 +59,7 @@ enum ilim_config { #define MA_TO_PWM(curr) (((curr) - PWM_MAPPING_A) / PWM_MAPPING_B) /* PWM controlled current limit */ +#define I_LIMIT_100MA MA_TO_PWM(100) #define I_LIMIT_500MA MA_TO_PWM(500) #define I_LIMIT_1000MA MA_TO_PWM(1000) #define I_LIMIT_1500MA MA_TO_PWM(1500) @@ -88,7 +89,7 @@ enum ilim_config { #define DELAY_USB_DP_DN_MS 20 #define DELAY_ID_MUX_MS 30 #define CABLE_DET_POLL_MS 100 -#define CABLE_DET_POLL_COUNT 10 +#define CABLE_DET_POLL_COUNT 6 /* Current sense resistor values */ #define R_INPUT_MOHM 20 /* mOhm */ @@ -465,6 +466,26 @@ static void usb_boost_power_hook(int power_on) set_video_power(power_on); } +static int usb_charger_removed(int dev_type) +{ + if (!(current_dev_type & TSU6721_TYPE_VBUS_DEBOUNCED)) + return 0; + + /* Charger is removed */ + if (dev_type == TSU6721_TYPE_NONE) + return 1; + + /* + * Device type changed from known type to unknown type. Assuming + * it went away and came back. + */ + if ((current_dev_type != TSU6721_TYPE_VBUS_DEBOUNCED) && + (dev_type == TSU6721_TYPE_VBUS_DEBOUNCED)) + return 1; + + return 0; +} + /** * Detect over-current events. * @@ -474,8 +495,7 @@ static void usb_boost_power_hook(int power_on) */ static void usb_detect_overcurrent(int dev_type) { - if ((current_dev_type & TSU6721_TYPE_VBUS_DEBOUNCED) && - (dev_type == TSU6721_TYPE_NONE)) { + if (usb_charger_removed(dev_type)) { int idx = !(current_dev_type == TSU6721_TYPE_VBUS_DEBOUNCED); power_removed_time[idx] = get_time(); power_removed_type[idx] = current_dev_type; @@ -556,6 +576,8 @@ static void usb_update_ilim(int dev_type) current_limit = hard_current_limit(I_LIMIT_2000MA); else if (dev_type & TOAD_DEVICE_TYPE) current_limit = hard_current_limit(I_LIMIT_500MA); + else if (dev_type == TSU6721_TYPE_VBUS_DEBOUNCED) + current_limit = hard_current_limit(I_LIMIT_100MA); pwm_nominal_duty_cycle(current_limit); } else { |