From 33fd731ca10e72664acb20196c2cfb7573e4ae4c Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Tue, 22 Mar 2016 16:09:35 -0700 Subject: 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 Change-Id: I52f02de46fa92b66a9fbaddb94a062310688f028 Reviewed-on: https://chromium-review.googlesource.com/334312 Commit-Ready: Shawn N Tested-by: Shawn N Reviewed-by: Vincent Palatin --- board/chell/board.h | 2 +- board/glados/board.h | 2 +- board/kevin/board.h | 2 +- board/kunimitsu/board.h | 2 +- board/lars/board.h | 2 +- board/oak/board.h | 2 +- board/samus_pd/board.h | 2 +- board/strago/board.h | 2 +- board/wheatley/board.h | 2 +- common/charge_manager.c | 37 ++++++++++++++++++++++++++++++------- include/charge_manager.h | 6 ++++++ include/charge_ramp.h | 6 ------ 12 files changed, 45 insertions(+), 22 deletions(-) diff --git a/board/chell/board.h b/board/chell/board.h index 1f735d155e..02eacf5c9e 100644 --- a/board/chell/board.h +++ b/board/chell/board.h @@ -136,7 +136,7 @@ #undef CONFIG_CONSOLE_CMDHELP #undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 15 +#define DEFERRABLE_MAX_COUNT 16 #ifndef __ASSEMBLER__ diff --git a/board/glados/board.h b/board/glados/board.h index c1891cb0d9..b10d6238ea 100644 --- a/board/glados/board.h +++ b/board/glados/board.h @@ -145,7 +145,7 @@ #undef CONFIG_CONSOLE_CMDHELP #undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 16 +#define DEFERRABLE_MAX_COUNT 17 #ifndef __ASSEMBLER__ diff --git a/board/kevin/board.h b/board/kevin/board.h index 824e17396c..4828aed902 100644 --- a/board/kevin/board.h +++ b/board/kevin/board.h @@ -88,7 +88,7 @@ #undef CONFIG_LOW_POWER_IDLE /* Deep Sleep Support */ #undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 9 +#define DEFERRABLE_MAX_COUNT 10 #define I2C_PORT_TCPC0 NPCX_I2C_PORT0_0 #define I2C_PORT_TCPC1 NPCX_I2C_PORT0_1 diff --git a/board/kunimitsu/board.h b/board/kunimitsu/board.h index 126ce385e9..e3ac065e21 100644 --- a/board/kunimitsu/board.h +++ b/board/kunimitsu/board.h @@ -134,7 +134,7 @@ #define I2C_PORT_USB_CHARGER_2 MEC1322_I2C0_0 #undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 16 +#define DEFERRABLE_MAX_COUNT 17 #define CONFIG_ALS #define CONFIG_ALS_OPT3001 diff --git a/board/lars/board.h b/board/lars/board.h index 04b4f7b74f..6b8c72e67d 100644 --- a/board/lars/board.h +++ b/board/lars/board.h @@ -129,7 +129,7 @@ #define I2C_PORT_THERMAL MEC1322_I2C3 #undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 14 +#define DEFERRABLE_MAX_COUNT 15 /* Modules we want to exclude */ #undef CONFIG_CMD_ACCEL_INFO diff --git a/board/oak/board.h b/board/oak/board.h index 6e044b8f88..5905d3aa0d 100644 --- a/board/oak/board.h +++ b/board/oak/board.h @@ -119,7 +119,7 @@ #undef CONFIG_UART_RX_DMA #undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 12 +#define DEFERRABLE_MAX_COUNT 13 /* * Allow dangerous commands. diff --git a/board/samus_pd/board.h b/board/samus_pd/board.h index a7c5a5e1bb..a1f34546e5 100644 --- a/board/samus_pd/board.h +++ b/board/samus_pd/board.h @@ -91,7 +91,7 @@ /* Maximum number of deferrable functions */ #undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 9 +#define DEFERRABLE_MAX_COUNT 10 #ifndef __ASSEMBLER__ diff --git a/board/strago/board.h b/board/strago/board.h index 77f26afdb3..f16126d979 100644 --- a/board/strago/board.h +++ b/board/strago/board.h @@ -91,7 +91,7 @@ #define CONFIG_BUTTON_COUNT 2 #undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 12 +#define DEFERRABLE_MAX_COUNT 13 #define CONFIG_ADC diff --git a/board/wheatley/board.h b/board/wheatley/board.h index a98aae6b3c..6b3c6462a7 100644 --- a/board/wheatley/board.h +++ b/board/wheatley/board.h @@ -147,7 +147,7 @@ #undef CONFIG_CONSOLE_CMDHELP #undef DEFERRABLE_MAX_COUNT -#define DEFERRABLE_MAX_COUNT 14 +#define DEFERRABLE_MAX_COUNT 15 #ifndef __ASSEMBLER__ 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, @@ -662,6 +673,18 @@ static void charge_manager_make_change(enum charge_manager_change_type change, available_charge[supplier][port].voltage = charge->voltage; 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. diff --git a/include/charge_manager.h b/include/charge_manager.h index a47bf3a4d7..ec0e35a7b1 100644 --- a/include/charge_manager.h +++ b/include/charge_manager.h @@ -17,6 +17,12 @@ #define CHARGE_CURRENT_UNINITIALIZED -1 #define CHARGE_VOLTAGE_UNINITIALIZED -1 +/* + * Time to delay for detecting the charger type (must be long enough for BC1.2 + * driver to get supplier information and notify charge manager). + */ +#define CHARGE_DETECT_DELAY (2*SECOND) + /* Commonly-used charge suppliers listed in no particular order */ enum charge_supplier { CHARGE_SUPPLIER_PD, diff --git a/include/charge_ramp.h b/include/charge_ramp.h index e7cb74b74b..a957fa872a 100644 --- a/include/charge_ramp.h +++ b/include/charge_ramp.h @@ -10,12 +10,6 @@ #include "timer.h" -/* - * Time to delay for detecting the charger type (must be long enough for BC1.2 - * driver to get supplier information and notify charge manager). - */ -#define CHARGE_DETECT_DELAY (2*SECOND) - /* Charge ramp state used for checking VBUS */ enum chg_ramp_vbus_state { CHG_RAMP_VBUS_RAMPING, -- cgit v1.2.1