summaryrefslogtreecommitdiff
path: root/driver/tcpm/tcpci.h
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-12-11 16:04:03 -0700
committerCommit Bot <commit-bot@chromium.org>2020-01-08 17:15:04 +0000
commitb560141a1d8ce034ae5b85718c163fb7ab83c24f (patch)
tree1b0505d2eeaa5bc7c1f521e6fed1015e9ab2d023 /driver/tcpm/tcpci.h
parent5750cc926d64033fe7f19b760165011120915ab0 (diff)
downloadchrome-ec-b560141a1d8ce034ae5b85718c163fb7ab83c24f.tar.gz
tcpci: Only drive one CC line when attached
Some of the NCT38XX driver code was more generic TCPCI than specific to the chip. So moved a number of the functions over to be generically handled. In doing this I propagated the idea of tri-state polarity. It is now either NORMAL, FLIPPED, or NONE for unattached. This is needed for the generic handling of correctly setting CC. This required changing the polarity from NONE to the appropriate detected polarity when in auto toggle. tcpci_tcpm_set_cc will now only set a single CC line when attached and both when unattached. BUG=b:146003980, chromium:951681 BRANCH=none TEST=Charging works with both plug orientations with AP on TEST=Device works with both plug orientations with AP on TEST=Charging works with both plug orientations with AP off Change-Id: Ie4b5cc998902a346a4f4a2c1480204b3a81017dd Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1967932 Commit-Queue: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Diffstat (limited to 'driver/tcpm/tcpci.h')
-rw-r--r--driver/tcpm/tcpci.h41
1 files changed, 31 insertions, 10 deletions
diff --git a/driver/tcpm/tcpci.h b/driver/tcpm/tcpci.h
index 566e7905e9..c6b392ba66 100644
--- a/driver/tcpm/tcpci.h
+++ b/driver/tcpm/tcpci.h
@@ -8,6 +8,7 @@
#ifndef __CROS_EC_USB_PD_TCPM_TCPCI_H
#define __CROS_EC_USB_PD_TCPM_TCPCI_H
+#include "config.h"
#include "tcpm.h"
#include "usb_mux.h"
#include "usb_pd_tcpm.h"
@@ -55,13 +56,20 @@
#define TCPC_REG_TCPC_CTRL_POLARITY(reg) ((reg) & 0x1)
#define TCPC_REG_ROLE_CTRL 0x1a
+#define TCPC_REG_ROLE_CTRL_DRP_MASK BIT(6)
+#define TCPC_REG_ROLE_CTRL_RP_MASK (BIT(5)|BIT(4))
+#define TCPC_REG_ROLE_CTRL_CC2_MASK (BIT(3)|BIT(2))
+#define TCPC_REG_ROLE_CTRL_CC1_MASK (BIT(1)|BIT(0))
#define TCPC_REG_ROLE_CTRL_SET(drp, rp, cc1, cc2) \
((drp) << 6 | (rp) << 4 | (cc2) << 2 | (cc1))
-#define TCPC_REG_ROLE_CTRL_DRP(reg) (((reg) & 0x40) >> 6)
-#define TCPC_REG_ROLE_CTRL_RP_MASK 0x30
-#define TCPC_REG_ROLE_CTRL_RP(reg) (((reg) & TCPC_REG_ROLE_CTRL_RP_MASK) >> 4)
-#define TCPC_REG_ROLE_CTRL_CC2(reg) (((reg) & 0xc) >> 2)
-#define TCPC_REG_ROLE_CTRL_CC1(reg) ((reg) & 0x3)
+#define TCPC_REG_ROLE_CTRL_DRP(reg) \
+ (((reg) & TCPC_REG_ROLE_CTRL_DRP_MASK) >> 6)
+#define TCPC_REG_ROLE_CTRL_RP(reg) \
+ (((reg) & TCPC_REG_ROLE_CTRL_RP_MASK) >> 4)
+#define TCPC_REG_ROLE_CTRL_CC2(reg) \
+ (((reg) & TCPC_REG_ROLE_CTRL_CC2_MASK) >> 2)
+#define TCPC_REG_ROLE_CTRL_CC1(reg) \
+ ((reg) & TCPC_REG_ROLE_CTRL_CC1_MASK)
#define TCPC_REG_FAULT_CTRL 0x1b
#define TCPC_REG_FAULT_CTRL_VBUS_OVP_FAULT_DIS BIT(1)
@@ -75,12 +83,20 @@
#define TCPC_REG_POWER_CTRL_VCONN(reg) ((reg) & 0x1)
#define TCPC_REG_CC_STATUS 0x1d
-#define TCPC_REG_CC_STATUS_LOOK4CONNECTION(reg) ((reg & 0x20) >> 5)
+#define TCPC_REG_CC_STATUS_LOOK4CONNECTION_MASK BIT(5)
+#define TCPC_REG_CC_STATUS_CONNECT_RESULT_MASK BIT(4)
+#define TCPC_REG_CC_STATUS_CC2_STATE_MASK (BIT(3)|BIT(2))
+#define TCPC_REG_CC_STATUS_CC1_STATE_MASK (BIT(1)|BIT(0))
#define TCPC_REG_CC_STATUS_SET(term, cc1, cc2) \
((term) << 4 | ((cc2) & 0x3) << 2 | ((cc1) & 0x3))
-#define TCPC_REG_CC_STATUS_TERM(reg) (((reg) & 0x10) >> 4)
-#define TCPC_REG_CC_STATUS_CC2(reg) (((reg) & 0xc) >> 2)
-#define TCPC_REG_CC_STATUS_CC1(reg) ((reg) & 0x3)
+#define TCPC_REG_CC_STATUS_LOOK4CONNECTION(reg) \
+ ((reg & TCPC_REG_CC_STATUS_LOOK4CONNECTION_MASK) >> 5)
+#define TCPC_REG_CC_STATUS_TERM(reg) \
+ (((reg) & TCPC_REG_CC_STATUS_CONNECT_RESULT_MASK) >> 4)
+#define TCPC_REG_CC_STATUS_CC2(reg) \
+ (((reg) & TCPC_REG_CC_STATUS_CC2_STATE_MASK) >> 2)
+#define TCPC_REG_CC_STATUS_CC1(reg) \
+ ((reg) & TCPC_REG_CC_STATUS_CC1_STATE_MASK)
#define TCPC_REG_POWER_STATUS 0x1e
#define TCPC_REG_POWER_STATUS_MASK_ALL 0xff
@@ -158,6 +174,11 @@
extern const struct tcpm_drv tcpci_tcpm_drv;
extern const struct usb_mux_driver tcpci_tcpm_usb_mux_driver;
+void tcpci_set_cached_rp(int port, int rp);
+int tcpci_get_cached_rp(int port);
+void tcpci_set_cached_pull(int port, enum tcpc_cc_pull pull);
+enum tcpc_cc_pull tcpci_get_cached_pull(int port);
+
void tcpci_tcpc_alert(int port);
int tcpci_tcpm_init(int port);
int tcpci_tcpm_get_cc(int port, enum tcpc_cc_voltage_status *cc1,
@@ -165,7 +186,7 @@ int tcpci_tcpm_get_cc(int port, enum tcpc_cc_voltage_status *cc1,
int tcpci_tcpm_get_vbus_level(int port);
int tcpci_tcpm_select_rp_value(int port, int rp);
int tcpci_tcpm_set_cc(int port, int pull);
-int tcpci_tcpm_set_polarity(int port, int polarity);
+int tcpci_tcpm_set_polarity(int port, enum tcpc_cc_polarity polarity);
int tcpci_tcpm_set_vconn(int port, int enable);
int tcpci_tcpm_set_msg_header(int port, int power_role, int data_role);
int tcpci_tcpm_set_rx_enable(int port, int enable);