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>
This commit is contained in:
Shawn Nematbakhsh
2016-03-22 16:09:35 -07:00
committed by chrome-bot
parent be731e262c
commit 33fd731ca1
12 changed files with 45 additions and 22 deletions

View File

@@ -136,7 +136,7 @@
#undef CONFIG_CONSOLE_CMDHELP
#undef DEFERRABLE_MAX_COUNT
#define DEFERRABLE_MAX_COUNT 15
#define DEFERRABLE_MAX_COUNT 16
#ifndef __ASSEMBLER__

View File

@@ -145,7 +145,7 @@
#undef CONFIG_CONSOLE_CMDHELP
#undef DEFERRABLE_MAX_COUNT
#define DEFERRABLE_MAX_COUNT 16
#define DEFERRABLE_MAX_COUNT 17
#ifndef __ASSEMBLER__

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View File

@@ -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__

View File

@@ -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

View File

@@ -147,7 +147,7 @@
#undef CONFIG_CONSOLE_CMDHELP
#undef DEFERRABLE_MAX_COUNT
#define DEFERRABLE_MAX_COUNT 14
#define DEFERRABLE_MAX_COUNT 15
#ifndef __ASSEMBLER__

View File

@@ -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.

View File

@@ -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,

View File

@@ -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,