summaryrefslogtreecommitdiff
path: root/common/usb_pd_protocol.c
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2015-05-04 09:22:42 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-05-22 18:12:02 +0000
commit37a23855f7bba522f4cb300d8f4547764e5e3578 (patch)
tree5c17c6562bfb1231e164c75800e0d6ef3f3de5d0 /common/usb_pd_protocol.c
parent608fa5efd868325ce85fca1f777a89c0909ea032 (diff)
downloadchrome-ec-37a23855f7bba522f4cb300d8f4547764e5e3578.tar.gz
pd: add first version of TCPCI I2C interface
Add first version of TCPCI (type-C port controller interface), which is an I2C protocol for interfacing with TCPCs. This is roughly tracking version 0.56 of the PD Interface spec. BUG=none BRANCH=none TEST=tested on oak. modified oak EC to be TCPM and oak PD to be TCPC and tested we can negotiate with hoho and zinger. Change-Id: I83644ca83f2d3ce69d5d8356beca20a7ab155a87 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/270172
Diffstat (limited to 'common/usb_pd_protocol.c')
-rw-r--r--common/usb_pd_protocol.c81
1 files changed, 41 insertions, 40 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 0bd0b6169a..639c62e5f7 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -278,7 +278,7 @@ static void inc_id(int port)
static void pd_transmit_complete(int port, int status)
{
- if (status & TCPC_ALERT0_TX_SUCCESS)
+ if (status & TCPC_REG_ALERT1_TX_SUCCESS)
inc_id(port);
pd[port].tx_status = status;
@@ -301,7 +301,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_ALERT0_TX_SUCCESS ? 1 : -1;
+ return pd[port].tx_status & TCPC_REG_ALERT1_TX_SUCCESS ? 1 : -1;
}
static void pd_update_roles(int port)
@@ -1237,9 +1237,9 @@ static inline int get_typec_current_limit(int cc)
int charge;
/* Detect type C charger current limit based upon vbus voltage. */
- if (cc == TYPEC_CC_SNK_PWR_3_0)
+ if (cc == TYPEC_CC_VOLT_SRC_3_0)
charge = 3000;
- else if (cc == TYPEC_CC_SNK_PWR_1_5)
+ else if (cc == TYPEC_CC_VOLT_SRC_1_5)
charge = 1500;
else
charge = 0;
@@ -1345,7 +1345,7 @@ void pd_task(void)
/* process any potential incoming message */
incoming_packet = evt & PD_EVENT_RX;
if (incoming_packet) {
- head = tcpm_get_message(port, payload);
+ tcpm_get_message(port, payload, &head);
if (head > 0)
handle_request(port, head, payload);
}
@@ -1358,14 +1358,13 @@ void pd_task(void)
break;
case PD_STATE_SRC_DISCONNECTED:
timeout = 10*MSEC;
- cc1 = tcpm_get_cc(port, 0);
- cc2 = tcpm_get_cc(port, 1);
+ tcpm_get_cc(port, &cc1, &cc2);
/* Vnc monitoring */
- if ((cc1 == TYPEC_CC_SRC_RD ||
- cc2 == TYPEC_CC_SRC_RD) ||
- (cc1 == TYPEC_CC_SRC_RA &&
- cc2 == TYPEC_CC_SRC_RA)) {
+ if ((TYPEC_CC_IS_RD(cc1) ||
+ TYPEC_CC_IS_RD(cc2)) ||
+ (cc1 == TYPEC_CC_VOLT_RA &&
+ cc2 == TYPEC_CC_VOLT_RA)) {
#ifdef CONFIG_USBC_BACKWARDS_COMPATIBLE_DFP
/* Enable VBUS */
if (pd_set_power_supply_ready(port))
@@ -1391,18 +1390,17 @@ void pd_task(void)
break;
case PD_STATE_SRC_DISCONNECTED_DEBOUNCE:
timeout = 20*MSEC;
- cc1 = tcpm_get_cc(port, 0);
- cc2 = tcpm_get_cc(port, 1);
+ tcpm_get_cc(port, &cc1, &cc2);
- if (cc1 == TYPEC_CC_SRC_RD && cc2 == TYPEC_CC_SRC_RD) {
+ if (TYPEC_CC_IS_RD(cc1) && TYPEC_CC_IS_RD(cc2)) {
/* Debug accessory */
new_cc_state = PD_CC_DEBUG_ACC;
- } else if (cc1 == TYPEC_CC_SRC_RD ||
- cc2 == TYPEC_CC_SRC_RD) {
+ } else if (TYPEC_CC_IS_RD(cc1) ||
+ TYPEC_CC_IS_RD(cc2)) {
/* UFP attached */
new_cc_state = PD_CC_UFP_ATTACHED;
- } else if (cc1 == TYPEC_CC_SRC_RA &&
- cc2 == TYPEC_CC_SRC_RA) {
+ } else if (cc1 == TYPEC_CC_VOLT_RA &&
+ cc2 == TYPEC_CC_VOLT_RA) {
/* Audio accessory */
new_cc_state = PD_CC_AUDIO_ACC;
} else {
@@ -1429,7 +1427,7 @@ void pd_task(void)
/* Debounce complete */
/* UFP is attached */
if (new_cc_state == PD_CC_UFP_ATTACHED) {
- pd[port].polarity = (cc2 == TYPEC_CC_SRC_RD);
+ pd[port].polarity = (TYPEC_CC_IS_RD(cc2));
tcpm_set_polarity(port, pd[port].polarity);
/* initial data role for source is DFP */
@@ -1483,16 +1481,15 @@ void pd_task(void)
/* Combined audio / debug accessory state */
timeout = 100*MSEC;
- cc1 = tcpm_get_cc(port, 0);
- cc2 = tcpm_get_cc(port, 1);
+ tcpm_get_cc(port, &cc1, &cc2);
/* If accessory becomes detached */
if ((pd[port].cc_state == PD_CC_AUDIO_ACC &&
- (cc1 != TYPEC_CC_SRC_RA ||
- cc2 != TYPEC_CC_SRC_RA)) ||
+ (cc1 != TYPEC_CC_VOLT_RA ||
+ cc2 != TYPEC_CC_VOLT_RA)) ||
(pd[port].cc_state == PD_CC_DEBUG_ACC &&
- (cc1 != TYPEC_CC_SRC_RD ||
- cc2 != TYPEC_CC_SRC_RD))) {
+ (!TYPEC_CC_IS_RD(cc1) ||
+ !TYPEC_CC_IS_RD(cc2)))) {
set_state(port, PD_STATE_SRC_DISCONNECTED);
#ifdef CONFIG_CASE_CLOSED_DEBUG
ccd_set_mode(CCD_MODE_DISABLED);
@@ -1798,10 +1795,11 @@ void pd_task(void)
break;
case PD_STATE_SNK_DISCONNECTED:
timeout = 10*MSEC;
+ tcpm_get_cc(port, &cc1, &cc2);
/* Source connection monitoring */
- if (tcpm_get_cc(port, 0) != TYPEC_CC_SNK_OPEN ||
- tcpm_get_cc(port, 1) != TYPEC_CC_SNK_OPEN) {
+ if (cc1 != TYPEC_CC_VOLT_OPEN ||
+ cc2 != TYPEC_CC_VOLT_OPEN) {
pd[port].cc_state = PD_CC_NONE;
hard_reset_count = 0;
new_cc_state = PD_CC_DFP_ATTACHED;
@@ -1830,10 +1828,9 @@ void pd_task(void)
}
break;
case PD_STATE_SNK_DISCONNECTED_DEBOUNCE:
- cc1 = tcpm_get_cc(port, 0);
- cc2 = tcpm_get_cc(port, 1);
- if (cc1 == TYPEC_CC_SNK_OPEN &&
- cc2 == TYPEC_CC_SNK_OPEN) {
+ tcpm_get_cc(port, &cc1, &cc2);
+ if (cc1 == TYPEC_CC_VOLT_OPEN &&
+ cc2 == TYPEC_CC_VOLT_OPEN) {
/* No connection any more */
set_state(port, PD_STATE_SNK_DISCONNECTED);
timeout = 5*MSEC;
@@ -1848,7 +1845,7 @@ void pd_task(void)
break;
/* We are attached */
- pd[port].polarity = (cc2 != TYPEC_CC_SNK_OPEN);
+ pd[port].polarity = (cc2 != TYPEC_CC_VOLT_OPEN);
tcpm_set_polarity(port, pd[port].polarity);
/* reset message ID on connection */
pd[port].msg_id = 0;
@@ -1962,7 +1959,9 @@ void pd_task(void)
timeout = PD_T_SINK_ADJ - PD_T_DEBOUNCE;
/* Check if CC pull-up has changed */
- cc1 = tcpm_get_cc(port, pd[port].polarity);
+ tcpm_get_cc(port, &cc1, &cc2);
+ if (pd[port].polarity)
+ cc1 = cc2;
if (typec_curr != get_typec_current_limit(cc1)) {
/* debounce signal by requiring two reads */
if (typec_curr_change) {
@@ -2318,8 +2317,10 @@ void pd_task(void)
#endif
if (pd[port].power_role == PD_ROLE_SOURCE) {
/* Source: detect disconnect by monitoring CC */
- cc1 = tcpm_get_cc(port, pd[port].polarity);
- if (cc1 == TYPEC_CC_SRC_OPEN) {
+ tcpm_get_cc(port, &cc1, &cc2);
+ if (pd[port].polarity)
+ cc1 = cc2;
+ if (cc1 == TYPEC_CC_VOLT_OPEN) {
pd_power_supply_reset(port);
set_state(port, PD_STATE_SRC_DISCONNECTED);
/* Debouncing */
@@ -2350,18 +2351,18 @@ void tcpc_alert(void)
/* loop over ports and check alert status */
for (i = 0; i < PD_PORT_COUNT; i++) {
- status = tcpm_alert_status(i, TCPC_ALERT0);
- if (status & TCPC_ALERT0_CC_STATUS) {
+ 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(PORT_TO_TASK_ID(i), PD_EVENT_CC, 0);
- } else if (status & TCPC_ALERT0_RX_STATUS) {
+ } else if (status & TCPC_REG_ALERT1_RX_STATUS) {
/* message received */
task_set_event(PORT_TO_TASK_ID(i), PD_EVENT_RX, 0);
- } else if (status & TCPC_ALERT0_RX_HARD_RST) {
+ } else if (status & TCPC_REG_ALERT1_RX_HARD_RST) {
/* hard reset received */
execute_hard_reset(i);
task_wake(PORT_TO_TASK_ID(i));
- } else if (status & TCPC_ALERT0_TX_COMPLETE) {
+ } else if (status & TCPC_REG_ALERT1_TX_COMPLETE) {
/* transmit complete */
pd_transmit_complete(i, status);
}