summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-11-19 16:51:37 -0800
committerchrome-bot <chrome-bot@chromium.org>2015-11-25 12:59:17 -0800
commit767e132d133b6f1216d630bd3b59e893a59bcffa (patch)
treecd42c82ce7d2246484f3980a1dc7e9966e57e633
parent9665d0b1df2edf954e2c3578c4905d5ca8138edc (diff)
downloadchrome-ec-767e132d133b6f1216d630bd3b59e893a59bcffa.tar.gz
pd: Add support for multiple distinct TCPC alert signals
If multiple TCPCs are present on a system then we may have multiple alert signals, each of which alerts us to the status of a different TCPC. Make boards with external non cros-ec TCPCs define tcpc_get_alert_status, which returns alert status based upon any alert GPIOs present, and then service only ports which are alerting. BUG=chromium:551683,chrome-os-partner:47851 TEST=Verify snoball PDCMD task sleeps appropriately when no devices are inserted, and verify ports go to PD_DISCOVERY state when we attach samus. Also verify that glados / glados_pd can still negotiate PD. BRANCH=None Change-Id: Iae6c4e1ef4d6685cb5bf7feef713505925a07c8c Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/313209 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r--board/pdeval-stm32f072/board.c14
-rw-r--r--board/snoball/board.c14
-rw-r--r--board/snoball/gpio.inc2
-rw-r--r--common/host_command_pd.c26
-rw-r--r--include/usb_pd_tcpm.h8
5 files changed, 53 insertions, 11 deletions
diff --git a/board/pdeval-stm32f072/board.c b/board/pdeval-stm32f072/board.c
index 6fd472eee5..ab476d006e 100644
--- a/board/pdeval-stm32f072/board.c
+++ b/board/pdeval-stm32f072/board.c
@@ -61,3 +61,17 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
{I2C_PORT_TCPC, TCPC2_I2C_ADDR},
#endif
};
+
+uint16_t tcpc_get_alert_status(void)
+{
+ uint16_t status = 0;
+
+ if (!gpio_get_level(GPIO_PD_MCU_INT)) {
+ status = PD_STATUS_TCPC_ALERT_0;
+#if CONFIG_USB_PD_PORT_COUNT >= 2
+ status |= PD_STATUS_TCPC_ALERT_1;
+#endif
+ }
+
+ return status;
+}
diff --git a/board/snoball/board.c b/board/snoball/board.c
index a081bab8c3..d4d05f13ea 100644
--- a/board/snoball/board.c
+++ b/board/snoball/board.c
@@ -41,6 +41,20 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
{STM32_I2C2_PORT, FUSB302_I2C_SLAVE_ADDR + 2},
};
+uint16_t tcpc_get_alert_status(void)
+{
+ uint16_t status = 0;
+
+ if (!gpio_get_level(GPIO_TCPC1_INT))
+ status |= PD_STATUS_TCPC_ALERT_0;
+ if (!gpio_get_level(GPIO_TCPC2_INT))
+ status |= PD_STATUS_TCPC_ALERT_1;
+ if (!gpio_get_level(GPIO_TCPC3_INT))
+ status |= PD_STATUS_TCPC_ALERT_2;
+
+ return status;
+}
+
/* ADC channels */
const struct adc_t adc_channels[] = {
/* Current sensing. Converted to mA (6600mV/4096). */
diff --git a/board/snoball/gpio.inc b/board/snoball/gpio.inc
index 776d42934c..cd0b71825e 100644
--- a/board/snoball/gpio.inc
+++ b/board/snoball/gpio.inc
@@ -39,8 +39,6 @@ GPIO(OPTO_OUT, PIN(A, 8), GPIO_OUT_LOW)
/* Unimplemented signals which we need to emulate for now */
UNIMPLEMENTED(ENTERING_RW)
UNIMPLEMENTED(WP_L)
-/* TODO(crbug.com/551683): Add support for multiple alert GPIOs */
-UNIMPLEMENTED(PD_MCU_INT)
/* Alternate functions */
#if 0
diff --git a/common/host_command_pd.c b/common/host_command_pd.c
index 477b602796..70178bf933 100644
--- a/common/host_command_pd.c
+++ b/common/host_command_pd.c
@@ -133,16 +133,25 @@ static void pd_check_chg_status(struct ec_response_pd_status *pd_status)
#endif /* CONFIG_HOSTCMD_PD */
#ifdef USB_TCPM_WITH_OFF_CHIP_TCPC
-static void pd_check_tcpc_alert(struct ec_response_pd_status *pd_status)
+static void pd_service_tcpc_ports(uint16_t port_status)
{
int i;
for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++) {
- if (!pd_status ||
- (pd_status->status & (PD_STATUS_TCPC_ALERT_0 << i)))
+ if (port_status & (PD_STATUS_TCPC_ALERT_0 << i))
tcpc_alert(i);
}
}
+
+static int pd_get_alert(void)
+{
+#ifdef CONFIG_HOSTCMD_PD
+ return !gpio_get_level(GPIO_PD_MCU_INT);
+#else
+ return !!tcpc_get_alert_status();
+#endif
+}
+
#endif /* USB_TCPM_WITH_OFF_CHIP_TCPC */
static void pd_exchange_status(uint32_t ec_state)
@@ -179,16 +188,15 @@ static void pd_exchange_status(uint32_t ec_state)
#ifdef USB_TCPM_WITH_OFF_CHIP_TCPC
#ifdef CONFIG_HOSTCMD_PD
- pd_check_tcpc_alert(&pd_status);
+ pd_service_tcpc_ports(pd_status.status);
#else
- pd_check_tcpc_alert(NULL);
+ pd_service_tcpc_ports(tcpc_get_alert_status());
#endif
- if (!first_exchange) {
+ if (!first_exchange)
usleep(50*MSEC);
- first_exchange = 0;
- }
- } while (!gpio_get_level(GPIO_PD_MCU_INT));
+ first_exchange = 0;
+ } while (pd_get_alert());
#endif /* USB_TCPM_WITH_OFF_CHIP_TCPC */
}
diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h
index 6b1180cafd..4e1b04249e 100644
--- a/include/usb_pd_tcpm.h
+++ b/include/usb_pd_tcpm.h
@@ -57,6 +57,14 @@ struct tcpc_config_t {
};
/**
+ * Returns the PD_STATUS_TCPC_ALERT_* mask corresponding to the TCPC ports
+ * that are currently asserting ALERT.
+ *
+ * @return PD_STATUS_TCPC_ALERT_* mask.
+ */
+uint16_t tcpc_get_alert_status(void);
+
+/**
* Initialize TCPM driver and wait for TCPC readiness.
*
* @param port Type-C port number