diff options
author | Alec Berg <alecaberg@chromium.org> | 2015-06-04 11:30:34 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-06-05 22:35:05 +0000 |
commit | 58719e30730e6420533514dabd27c188e60ae607 (patch) | |
tree | 8015dd22c5808e88b648cd52463bf59a34b0a734 | |
parent | bdc680d8ed7ea24cdfb1b5498f73a1008c71ad37 (diff) | |
download | chrome-ec-58719e30730e6420533514dabd27c188e60ae607.tar.gz |
pd: use pdcmd task to handle tcpc interrupt
Use the PDCMD task to handle PD MCU interrupts, and use it
to trigger the tcpc_alert().
Note this fixes bug on Glados and Oak that could cause watchdog
reset because tcpc_alert() which uses i2c to talk to tcpc was
called from hooks task and can delay tickling watchdog.
BUG=chrome-os-partner:40920
BRANCH=none
TEST=load on glados and plug zinger into both ports many times.
make sure we get a stable contract and no watchdog reset.
Change-Id: I37625fae2ca0057d2ee8fa1eea6974f2d26d1b91
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/275296
Reviewed-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r-- | board/glados/board.c | 4 | ||||
-rw-r--r-- | board/glados_pd/board.c | 17 | ||||
-rw-r--r-- | board/samus/board.h | 1 | ||||
-rw-r--r-- | common/host_command_pd.c | 23 | ||||
-rw-r--r-- | common/usb_pd_protocol.c | 3 | ||||
-rw-r--r-- | include/config.h | 6 |
6 files changed, 45 insertions, 9 deletions
diff --git a/board/glados/board.c b/board/glados/board.c index 9f0ce37f88..a1f8e9dd5f 100644 --- a/board/glados/board.c +++ b/board/glados/board.c @@ -11,6 +11,7 @@ #include "extpower.h" #include "gpio.h" #include "hooks.h" +#include "host_command.h" #include "i2c.h" #include "lid_switch.h" #include "motion_sense.h" @@ -33,7 +34,8 @@ /* Exchange status with PD MCU. */ static void pd_mcu_interrupt(enum gpio_signal signal) { - hook_call_deferred(tcpc_alert, 0); + /* Exchange status with PD MCU to determine interrupt cause */ + host_command_pd_send_status(0); } void vbus0_evt(enum gpio_signal signal) diff --git a/board/glados_pd/board.c b/board/glados_pd/board.c index da6fc82525..776e30a29b 100644 --- a/board/glados_pd/board.c +++ b/board/glados_pd/board.c @@ -101,3 +101,20 @@ DECLARE_CONSOLE_COMMAND(ecint, command_ec_int, "", "Toggle EC interrupt line", NULL); + +static int ec_status_host_cmd(struct host_cmd_handler_args *args) +{ + struct ec_response_pd_status *r = args->response; + + /* + * TODO: use state here to notify EC of host events, tcpc port + * 0 alert and tcpc port 1 alert. + */ + r->status = 0; + args->response_size = sizeof(*r); + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_PD_EXCHANGE_STATUS, ec_status_host_cmd, + EC_VER_MASK(1)); + diff --git a/board/samus/board.h b/board/samus/board.h index 8d78c03cef..3c81e403d8 100644 --- a/board/samus/board.h +++ b/board/samus/board.h @@ -69,6 +69,7 @@ #define CONFIG_TEMP_SENSOR_TMP006 #define CONFIG_TEMP_SENSOR_POWER_GPIO GPIO_PP3300_DSW_GATED_EN #define CONFIG_UART_HOST 2 +#define CONFIG_USB_PD_MCU_CHG_CTRL #define CONFIG_USB_PORT_POWER_SMART #define CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE USB_CHARGE_MODE_CDP #define CONFIG_USB_PORT_POWER_SMART_INVERTED diff --git a/common/host_command_pd.c b/common/host_command_pd.c index 140c71ea4e..33bdb52745 100644 --- a/common/host_command_pd.c +++ b/common/host_command_pd.c @@ -14,32 +14,37 @@ #include "system.h" #include "task.h" #include "timer.h" +#include "usb_pd_tcpm.h" #include "util.h" #define CPRINTS(format, args...) cprints(CC_PD_HOST_CMD, format, ## args) #define TASK_EVENT_EXCHANGE_PD_STATUS TASK_EVENT_CUSTOM(1) +#ifdef CONFIG_USB_PD_MCU_CHG_CTRL /* By default allow 5V charging only for the dead battery case */ static enum pd_charge_state charge_state = PD_CHARGE_5V; #define CHARGE_PORT_UNINITIALIZED -2 static int charge_port = CHARGE_PORT_UNINITIALIZED; +int pd_get_active_charge_port(void) +{ + return charge_port; +} +#endif + void host_command_pd_send_status(enum pd_charge_state new_chg_state) { +#ifdef CONFIG_USB_PD_MCU_CHG_CTRL /* Update PD MCU charge state if necessary */ if (new_chg_state != PD_CHARGE_NO_CHANGE) charge_state = new_chg_state; +#endif /* Wake PD HC task to send status */ task_set_event(TASK_ID_PDCMD, TASK_EVENT_EXCHANGE_PD_STATUS, 0); } -int pd_get_active_charge_port(void) -{ - return charge_port; -} - static void pd_exchange_status(void) { struct ec_params_pd_status ec_status; @@ -50,7 +55,9 @@ static void pd_exchange_status(void) #endif /* Send PD charge state and battery state of charge */ +#ifdef CONFIG_USB_PD_MCU_CHG_CTRL ec_status.charge_state = charge_state; +#endif if (charge_get_flags() & CHARGE_FLAG_BATT_RESPONSIVE) ec_status.batt_soc = charge_get_percent(); else @@ -86,6 +93,7 @@ static void pd_exchange_status(void) } #endif +#ifdef CONFIG_USB_PD_MCU_CHG_CTRL #ifdef HAS_TASK_LIGHTBAR /* * If charge port has changed, and it was initialized, then show @@ -109,10 +117,15 @@ static void pd_exchange_status(void) CONFIG_CHARGER_INPUT_CURRENT)); if (rv < 0) CPRINTS("Failed to set input current limit from PD MCU"); +#endif /* CONFIG_USB_PD_MCU_CHG_CTRL */ /* If PD is signalling host event, then pass it up to AP */ if (pd_status.status & PD_STATUS_HOST_EVENT) host_set_single_event(EC_HOST_EVENT_PD_MCU); + +#ifdef CONFIG_USB_PD_TCPM_TCPCI + tcpc_alert(); +#endif } void pd_command_task(void) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index b1e8a103c1..9dd27fcd95 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -2396,9 +2396,6 @@ void tcpc_alert(void) } } } -#ifndef CONFIG_USB_PD_TCPC -DECLARE_DEFERRED(tcpc_alert); -#endif #ifdef CONFIG_USB_PD_DUAL_ROLE static void dual_role_on(void) diff --git a/include/config.h b/include/config.h index b867a440ab..63371dcd6c 100644 --- a/include/config.h +++ b/include/config.h @@ -1328,6 +1328,12 @@ /* The size in bytes of the FIFO used for PD events logging */ #undef CONFIG_USB_PD_LOG_SIZE +/* + * Use if PD MCU controls charging (selecting charging port and input + * current limit). + */ +#undef CONFIG_USB_PD_MCU_CHG_CTRL + /* Define if USB-PD device has no way of detecting USB VBUS */ #undef CONFIG_USB_PD_NO_VBUS_DETECT |