summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2016-03-22 16:09:35 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-04-03 10:27:36 -0700
commit33fd731ca10e72664acb20196c2cfb7573e4ae4c (patch)
tree881280f00f4a29ba4807b2ddc0b8928298c406b3 /common
parentbe731e262cc1061ab6f8b5e648ed7bfc792b681a (diff)
downloadchrome-ec-33fd731ca10e72664acb20196c2cfb7573e4ae4c.tar.gz
charge_manager: Report UNKNOWN USB charger for 2 seconds after change
After a charger is attached, we may set a charge limit based upon BC1.2 or USB-C Rp before PD negotiation completes. Therefore, allow 2 seconds for all negotiation to complete. Previously this behavior was implicit when using SW charge ramp. BUG=chrome-os-partner:51280 BRANCH=glados TEST=Manual on chell. Insert stock charger, verify that it is detected as TYPE_UNKNOWN until timeout. Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I52f02de46fa92b66a9fbaddb94a062310688f028 Reviewed-on: https://chromium-review.googlesource.com/334312 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/charge_manager.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/common/charge_manager.c b/common/charge_manager.c
index 8782d398e3..7063d0540f 100644
--- a/common/charge_manager.c
+++ b/common/charge_manager.c
@@ -225,14 +225,15 @@ static void charge_manager_fill_power_info(int port,
}
r->meas.voltage_max = available_charge[sup][port].voltage;
- if (use_ramp_current) {
- /*
- * If charge_ramp has not detected charger yet,
- * then charger type is unknown.
- */
- if (!chg_ramp_is_detected())
- r->type = USB_CHG_TYPE_UNKNOWN;
+ /*
+ * Report unknown charger CHARGE_DETECT_DELAY after supplier
+ * change since PD negotiation may take time.
+ */
+ if (get_time().val < registration_time[port].val +
+ CHARGE_DETECT_DELAY)
+ r->type = USB_CHG_TYPE_UNKNOWN;
+ if (use_ramp_current) {
/* Current limit is output of ramp module */
r->meas.current_lim = chg_ramp_get_current_limit();
@@ -593,6 +594,16 @@ static void charge_override_timeout(void)
}
DECLARE_DEFERRED(charge_override_timeout);
+/**
+ * Called CHARGE_DETECT_DELAY after the most recent charge change on a port.
+ */
+static void charger_detect_debounced(void)
+{
+ /* Inform host that charger detection is debounced. */
+ pd_send_host_event(PD_EVENT_POWER_CHANGE);
+}
+DECLARE_DEFERRED(charger_detect_debounced);
+
static void charge_manager_make_change(enum charge_manager_change_type change,
int supplier,
int port,
@@ -663,6 +674,18 @@ static void charge_manager_make_change(enum charge_manager_change_type change,
registration_time[port] = get_time();
/*
+ * After CHARGE_DETECT_DELAY, inform the host that charger
+ * detection has been debounced. Since only one deferred
+ * routine exists for all ports, the deferred call for a given
+ * port may potentially be cancelled. This is mostly harmless
+ * since cancellation implies that PD_EVENT_POWER_CHANGE was
+ * just sent due to the power change on another port.
+ */
+ if (charge->current > 0)
+ hook_call_deferred(charger_detect_debounced,
+ CHARGE_DETECT_DELAY);
+
+ /*
* If we have a charge on our delayed override port within
* the deadline, make it our override port.
*/