summaryrefslogtreecommitdiff
path: root/common/usb_pd_protocol.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/usb_pd_protocol.c')
-rw-r--r--common/usb_pd_protocol.c83
1 files changed, 52 insertions, 31 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index f87e5010a5..deeb683630 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -304,7 +304,7 @@ static void inc_id(int port)
static void pd_transmit_complete(int port, int status)
{
- if (status & TCPC_REG_ALERT1_TX_SUCCESS)
+ if (status & TCPC_REG_ALERT_TX_SUCCESS)
inc_id(port);
pd[port].tx_status = status;
@@ -329,7 +329,7 @@ static int pd_transmit(int port, enum tcpm_transmit_type type,
return -1;
/* TODO: give different error condition for failed vs discarded */
- return pd[port].tx_status & TCPC_REG_ALERT1_TX_SUCCESS ? 1 : -1;
+ return pd[port].tx_status & TCPC_REG_ALERT_TX_SUCCESS ? 1 : -1;
}
static void pd_update_roles(int port)
@@ -1299,6 +1299,25 @@ void pd_set_new_power_request(int port)
#error "Backwards compatible DFP does not support USB"
#endif
+int tcpm_init_alert_mask(int port)
+{
+ uint16_t mask;
+ int rv;
+
+ /*
+ * Create mask of alert events that will cause the TCPC to
+ * signal the TCPM via the Alert# gpio line.
+ */
+ mask = TCPC_REG_ALERT_TX_SUCCESS | TCPC_REG_ALERT_TX_FAILED |
+ TCPC_REG_ALERT_TX_DISCARDED | TCPC_REG_ALERT_RX_STATUS |
+ TCPC_REG_ALERT_RX_HARD_RST | TCPC_REG_ALERT_CC_STATUS;
+ /* Set the alert mask in TCPC */
+ rv = tcpm_alert_mask_set(port, TCPC_REG_ALERT_MASK, mask);
+
+ return rv;
+}
+
+
void pd_task(void)
{
int head;
@@ -1330,6 +1349,9 @@ void pd_task(void)
tcpm_init(port);
CPRINTF("[%T TCPC p%d ready]\n", port);
+ /* Initialize TCPC alert mask register via the TCPM */
+ tcpm_init_alert_mask(port);
+
/* Disable TCPC RX until connection is established */
tcpm_set_rx_enable(port, 0);
@@ -2389,39 +2411,38 @@ void pd_task(void)
}
}
-void tcpc_alert(void)
+void tcpc_alert(int port)
{
- int status, i;
+ int status;
- /* loop over ports and check alert status */
- for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++) {
- tcpm_alert_status(i, TCPC_REG_ALERT1, (uint8_t *)&status);
- if (status & TCPC_REG_ALERT1_CC_STATUS) {
- /* CC status changed, wake task */
- task_set_event(PD_PORT_TO_TASK_ID(i), PD_EVENT_CC, 0);
- }
- if (status & TCPC_REG_ALERT1_RX_STATUS) {
- /* message received */
- /*
- * If TCPC is compiled in, then we will have already
- * received PD_EVENT_RX from phy layer in
- * pd_rx_event(), so we don't need to set another
- * event. If TCPC is not running on this MCU, then
- * this needs to wake the PD task.
- */
+ /* Read the Alert register from the TCPC */
+ tcpm_alert_status(port, TCPC_REG_ALERT, (uint16_t *)&status);
+
+ if (status & TCPC_REG_ALERT_CC_STATUS) {
+ /* CC status changed, wake task */
+ task_set_event(PD_PORT_TO_TASK_ID(port), PD_EVENT_CC, 0);
+ }
+ if (status & TCPC_REG_ALERT_RX_STATUS) {
+ /* message received */
+ /*
+ * If TCPC is compiled in, then we will have already
+ * received PD_EVENT_RX from phy layer in
+ * pd_rx_event(), so we don't need to set another
+ * event. If TCPC is not running on this MCU, then
+ * this needs to wake the PD task.
+ */
#ifndef CONFIG_USB_PD_TCPC
- task_set_event(PD_PORT_TO_TASK_ID(i), PD_EVENT_RX, 0);
+ task_set_event(PD_PORT_TO_TASK_ID(port), PD_EVENT_RX, 0);
#endif
- }
- if (status & TCPC_REG_ALERT1_RX_HARD_RST) {
- /* hard reset received */
- execute_hard_reset(i);
- task_wake(PD_PORT_TO_TASK_ID(i));
- }
- if (status & TCPC_REG_ALERT1_TX_COMPLETE) {
- /* transmit complete */
- pd_transmit_complete(i, status);
- }
+ }
+ if (status & TCPC_REG_ALERT_RX_HARD_RST) {
+ /* hard reset received */
+ execute_hard_reset(port);
+ task_wake(PD_PORT_TO_TASK_ID(port));
+ }
+ if (status & TCPC_REG_ALERT_TX_COMPLETE) {
+ /* transmit complete */
+ pd_transmit_complete(port, status);
}
}