summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
Diffstat (limited to 'driver')
-rw-r--r--driver/tcpm/fusb302.c41
-rw-r--r--driver/tcpm/fusb302.h2
-rw-r--r--driver/tcpm/stub.c17
-rw-r--r--driver/tcpm/tcpci.c76
-rw-r--r--driver/tcpm/tcpci.h3
-rw-r--r--driver/tcpm/tcpm.h177
6 files changed, 255 insertions, 61 deletions
diff --git a/driver/tcpm/fusb302.c b/driver/tcpm/fusb302.c
index fc584ac339..11464bbab3 100644
--- a/driver/tcpm/fusb302.c
+++ b/driver/tcpm/fusb302.c
@@ -341,7 +341,7 @@ static int fusb302_send_message(int port, uint16_t header, const uint32_t *data,
return rv;
}
-int tcpm_init(int port)
+static int fusb302_tcpm_init(int port)
{
int reg;
@@ -410,7 +410,7 @@ int tcpm_init(int port)
return 0;
}
-int tcpm_get_cc(int port, int *cc1, int *cc2)
+static int fusb302_tcpm_get_cc(int port, int *cc1, int *cc2)
{
/*
* can't measure while doing DFP toggling -
@@ -436,7 +436,7 @@ int tcpm_get_cc(int port, int *cc1, int *cc2)
return 0;
}
-int tcpm_set_cc(int port, int pull)
+static int fusb302_tcpm_set_cc(int port, int pull)
{
int reg;
@@ -533,7 +533,7 @@ int tcpm_set_cc(int port, int pull)
return 0;
}
-int tcpm_set_polarity(int port, int polarity)
+static int fusb302_tcpm_set_polarity(int port, int polarity)
{
/* Port polarity : 0 => CC1 is CC line, 1 => CC2 is CC line */
int reg;
@@ -584,7 +584,7 @@ int tcpm_set_polarity(int port, int polarity)
return 0;
}
-int tcpm_set_vconn(int port, int enable)
+static int fusb302_tcpm_set_vconn(int port, int enable)
{
/*
* FUSB302 does not have dedicated VCONN Enable switch.
@@ -615,7 +615,7 @@ int tcpm_set_vconn(int port, int enable)
return 0;
}
-int tcpm_set_msg_header(int port, int power_role, int data_role)
+static int fusb302_tcpm_set_msg_header(int port, int power_role, int data_role)
{
int reg;
@@ -634,7 +634,7 @@ int tcpm_set_msg_header(int port, int power_role, int data_role)
return 0;
}
-int tcpm_set_rx_enable(int port, int enable)
+static int fusb302_tcpm_set_rx_enable(int port, int enable)
{
int reg;
@@ -689,7 +689,7 @@ int tcpm_set_rx_enable(int port, int enable)
return 0;
}
-int tcpm_get_message(int port, uint32_t *payload, int *head)
+static int fusb302_tcpm_get_message(int port, uint32_t *payload, int *head)
{
/*
* this is the buffer that will get the burst-read data
@@ -743,8 +743,8 @@ int tcpm_get_message(int port, uint32_t *payload, int *head)
return rv;
}
-int tcpm_transmit(int port, enum tcpm_transmit_type type, uint16_t header,
- const uint32_t *data)
+static int fusb302_tcpm_transmit(int port, enum tcpm_transmit_type type,
+ uint16_t header, const uint32_t *data)
{
/*
* this is the buffer that will be burst-written into the fusb302
@@ -803,7 +803,8 @@ int tcpm_transmit(int port, enum tcpm_transmit_type type, uint16_t header,
return 0;
}
-int tcpm_get_vbus_level(int port)
+#ifdef CONFIG_USB_PD_TCPM_VBUS
+static int fusb302_tcpm_get_vbus_level(int port)
{
int reg;
@@ -812,8 +813,9 @@ int tcpm_get_vbus_level(int port)
return (reg & TCPC_REG_STATUS0_VBUSOK) ? 1 : 0;
}
+#endif
-void tcpc_alert(int port)
+void fusb302_tcpc_alert(int port)
{
/* interrupt has been received */
int interrupt;
@@ -981,3 +983,18 @@ void tcpm_set_bist_test_data(int port)
}
}
+const struct tcpm_drv fusb302_tcpm_drv = {
+ .init = &fusb302_tcpm_init,
+ .get_cc = &fusb302_tcpm_get_cc,
+#ifdef CONFIG_USB_PD_TCPM_VBUS
+ .get_vbus_level = &fusb302_tcpm_get_vbus_level,
+#endif
+ .set_cc = &fusb302_tcpm_set_cc,
+ .set_polarity = &fusb302_tcpm_set_polarity,
+ .set_vconn = &fusb302_tcpm_set_vconn,
+ .set_msg_header = &fusb302_tcpm_set_msg_header,
+ .set_rx_enable = &fusb302_tcpm_set_rx_enable,
+ .get_message = &fusb302_tcpm_get_message,
+ .transmit = &fusb302_tcpm_transmit,
+ .tcpc_alert = &fusb302_tcpc_alert,
+};
diff --git a/driver/tcpm/fusb302.h b/driver/tcpm/fusb302.h
index 7537df909a..66ca7e5dbe 100644
--- a/driver/tcpm/fusb302.h
+++ b/driver/tcpm/fusb302.h
@@ -205,5 +205,7 @@ enum fusb302_txfifo_tokens {
FUSB302_TKN_TXOFF = 0xFE,
};
+extern const struct tcpm_drv fusb302_tcpm_drv;
+
#endif /* __CROS_EC_DRIVER_TCPM_FUSB302_H */
diff --git a/driver/tcpm/stub.c b/driver/tcpm/stub.c
index 08c5f37a35..91ac6638d7 100644
--- a/driver/tcpm/stub.c
+++ b/driver/tcpm/stub.c
@@ -7,6 +7,7 @@
#include "task.h"
#include "tcpci.h"
+#include "tcpm.h"
#include "usb_pd.h"
#include "usb_pd_tcpm.h"
@@ -38,14 +39,14 @@ static int init_alert_mask(int port)
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, mask);
+ rv = tcpc_alert_mask_set(port, mask);
return rv;
}
static int init_power_status_mask(int port)
{
- return tcpm_set_power_status_mask(port, 0);
+ return tcpc_set_power_status_mask(port, 0);
}
int tcpm_init(int port)
@@ -75,11 +76,6 @@ int tcpm_set_polarity(int port, int polarity)
return tcpc_set_polarity(port, polarity);
}
-int tcpm_set_power_status_mask(int port, uint8_t mask)
-{
- return tcpc_set_power_status_mask(port, mask);
-}
-
int tcpm_set_vconn(int port, int enable)
{
return tcpc_set_vconn(port, enable);
@@ -90,7 +86,7 @@ int tcpm_set_msg_header(int port, int power_role, int data_role)
return tcpc_set_msg_header(port, power_role, data_role);
}
-int tcpm_alert_status(int port, int *alert)
+static int tcpm_alert_status(int port, int *alert)
{
/* Read TCPC Alert register */
return tcpc_alert_status(port, alert);
@@ -101,11 +97,6 @@ int tcpm_set_rx_enable(int port, int enable)
return tcpc_set_rx_enable(port, enable);
}
-int tcpm_alert_mask_set(int port, uint16_t mask)
-{
- return tcpc_alert_mask_set(port, mask);
-}
-
int tcpm_get_message(int port, uint32_t *payload, int *head)
{
int ret = tcpc_get_message(port, payload, head);
diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c
index 375e56aa5c..09e8e291b3 100644
--- a/driver/tcpm/tcpci.c
+++ b/driver/tcpm/tcpci.c
@@ -34,7 +34,7 @@ static int init_alert_mask(int port)
#endif
;
/* Set the alert mask in TCPC */
- rv = tcpm_alert_mask_set(port, mask);
+ rv = tcpc_write16(port, TCPC_REG_ALERT_MASK, mask);
return rv;
}
@@ -49,12 +49,12 @@ static int init_power_status_mask(int port)
#else
mask = 0;
#endif
- rv = tcpm_set_power_status_mask(port, mask);
+ rv = tcpc_write(port, TCPC_REG_POWER_STATUS_MASK , mask);
return rv;
}
-int tcpm_get_cc(int port, int *cc1, int *cc2)
+static int tcpci_tcpm_get_cc(int port, int *cc1, int *cc2)
{
int status;
int rv;
@@ -80,12 +80,12 @@ int tcpm_get_cc(int port, int *cc1, int *cc2)
return rv;
}
-int tcpm_get_power_status(int port, int *status)
+static int tcpci_tcpm_get_power_status(int port, int *status)
{
return tcpc_read(port, TCPC_REG_POWER_STATUS, status);
}
-int tcpm_set_cc(int port, int pull)
+static int tcpci_tcpm_set_cc(int port, int pull)
{
/*
* Set manual control of Rp/Rd, and set both CC lines to the same
@@ -96,57 +96,45 @@ int tcpm_set_cc(int port, int pull)
TCPC_REG_ROLE_CTRL_SET(0, 0, pull, pull));
}
-int tcpm_set_polarity(int port, int polarity)
+static int tcpci_tcpm_set_polarity(int port, int polarity)
{
return tcpc_write(port, TCPC_REG_TCPC_CTRL,
TCPC_REG_TCPC_CTRL_SET(polarity));
}
-int tcpm_set_vconn(int port, int enable)
+static int tcpci_tcpm_set_vconn(int port, int enable)
{
return tcpc_write(port, TCPC_REG_POWER_CTRL,
TCPC_REG_POWER_CTRL_SET(enable));
}
-int tcpm_set_msg_header(int port, int power_role, int data_role)
+static int tcpci_tcpm_set_msg_header(int port, int power_role, int data_role)
{
return tcpc_write(port, TCPC_REG_MSG_HDR_INFO,
TCPC_REG_MSG_HDR_INFO_SET(data_role, power_role));
}
-int tcpm_alert_status(int port, int *alert)
+static int tcpm_alert_status(int port, int *alert)
{
/* Read TCPC Alert register */
return tcpc_read16(port, TCPC_REG_ALERT, alert);
}
-int tcpm_set_rx_enable(int port, int enable)
+static int tcpci_tcpm_set_rx_enable(int port, int enable)
{
/* If enable, then set RX detect for SOP and HRST */
return tcpc_write(port, TCPC_REG_RX_DETECT,
enable ? TCPC_REG_RX_DETECT_SOP_HRST_MASK : 0);
}
-int tcpm_set_power_status_mask(int port, uint8_t mask)
-{
- /* write to the Alert Mask register */
- return tcpc_write(port, TCPC_REG_POWER_STATUS_MASK , mask);
-}
-
-int tcpm_alert_mask_set(int port, uint16_t mask)
-{
- /* write to the Alert Mask register */
- return tcpc_write16(port, TCPC_REG_ALERT_MASK, mask);
-}
-
#ifdef CONFIG_USB_PD_TCPM_VBUS
-int tcpm_get_vbus_level(int port)
+static int tcpci_tcpm_get_vbus_level(int port)
{
return tcpc_vbus[port];
}
#endif
-int tcpm_get_message(int port, uint32_t *payload, int *head)
+static int tcpci_tcpm_get_message(int port, uint32_t *payload, int *head)
{
int rv, cnt, reg = TCPC_REG_RX_DATA;
@@ -168,8 +156,8 @@ int tcpm_get_message(int port, uint32_t *payload, int *head)
return rv;
}
-int tcpm_transmit(int port, enum tcpm_transmit_type type, uint16_t header,
- const uint32_t *data)
+static int tcpci_tcpm_transmit(int port, enum tcpm_transmit_type type,
+ uint16_t header, const uint32_t *data)
{
int reg = TCPC_REG_TX_DATA;
int rv, cnt = 4*PD_HEADER_CNT(header);
@@ -201,7 +189,7 @@ int tcpm_transmit(int port, enum tcpm_transmit_type type, uint16_t header,
return rv;
}
-void tcpc_alert(int port)
+void tcpci_tcpc_alert(int port)
{
int status;
@@ -234,7 +222,7 @@ void tcpc_alert(int port)
PD_EVENT_TCPC_RESET, 0);
} else {
/* Read Power Status register */
- tcpm_get_power_status(port, &reg);
+ tcpci_tcpm_get_power_status(port, &reg);
/* Update VBUS status */
tcpc_vbus[port] = reg &
TCPC_REG_POWER_STATUS_VBUS_PRES ? 1 : 0;
@@ -262,7 +250,7 @@ void tcpc_alert(int port)
}
}
-int tcpm_init(int port)
+int tcpci_tcpm_init(int port)
{
int rv;
int power_status;
@@ -290,12 +278,12 @@ int tcpm_init(int port)
#ifdef CONFIG_USB_PD_TCPM_MUX
-static int tcpm_mux_init(int i2c_addr)
+static int tcpci_tcpm_mux_init(int i2c_addr)
{
return EC_SUCCESS;
}
-static int tcpm_mux_set(int i2c_addr, mux_state_t mux_state)
+static int tcpci_tcpm_mux_set(int i2c_addr, mux_state_t mux_state)
{
int reg = 0;
int rv;
@@ -316,7 +304,7 @@ static int tcpm_mux_set(int i2c_addr, mux_state_t mux_state)
}
/* Reads control register and updates mux_state accordingly */
-static int tcpm_mux_get(int i2c_addr, mux_state_t *mux_state)
+static int tcpci_tcpm_mux_get(int i2c_addr, mux_state_t *mux_state)
{
int reg = 0;
int rv;
@@ -337,10 +325,26 @@ static int tcpm_mux_get(int i2c_addr, mux_state_t *mux_state)
}
-const struct usb_mux_driver tcpm_usb_mux_driver = {
- .init = tcpm_mux_init,
- .set = tcpm_mux_set,
- .get = tcpm_mux_get,
+const struct usb_mux_driver tcpci_tcpm_usb_mux_driver = {
+ .init = tcpci_tcpm_mux_init,
+ .set = tcpci_tcpm_mux_set,
+ .get = tcpci_tcpm_mux_get,
};
#endif /* CONFIG_USB_PD_TCPM_MUX */
+
+const struct tcpm_drv tcpci_tcpm_drv = {
+ .init = &tcpci_tcpm_init,
+ .get_cc = &tcpci_tcpm_get_cc,
+#ifdef CONFIG_USB_PD_TCPM_VBUS
+ .get_vbus_level = &tcpci_tcpm_get_vbus_level,
+#endif
+ .set_cc = &tcpci_tcpm_set_cc,
+ .set_polarity = &tcpci_tcpm_set_polarity,
+ .set_vconn = &tcpci_tcpm_set_vconn,
+ .set_msg_header = &tcpci_tcpm_set_msg_header,
+ .set_rx_enable = &tcpci_tcpm_set_rx_enable,
+ .get_message = &tcpci_tcpm_get_message,
+ .transmit = &tcpci_tcpm_transmit,
+ .tcpc_alert = &tcpci_tcpc_alert,
+};
diff --git a/driver/tcpm/tcpci.h b/driver/tcpm/tcpci.h
index eb87b7d0e2..744bbe6678 100644
--- a/driver/tcpm/tcpci.h
+++ b/driver/tcpm/tcpci.h
@@ -108,4 +108,7 @@
#define TCPC_REG_VBUS_VOLTAGE_ALARM_HI_CFG 0x76
#define TCPC_REG_VBUS_VOLTAGE_ALARM_LO_CFG 0x78
+extern const struct tcpm_drv tcpci_tcpm_drv;
+extern const struct usb_mux_driver tcpci_tcpm_usb_mux_driver;
+
#endif /* __CROS_EC_USB_PD_TCPM_TCPCI_H */
diff --git a/driver/tcpm/tcpm.h b/driver/tcpm/tcpm.h
index 4c4ff6c9a2..16cf879f72 100644
--- a/driver/tcpm/tcpm.h
+++ b/driver/tcpm/tcpm.h
@@ -8,9 +8,12 @@
#ifndef __CROS_EC_USB_PD_TCPM_TCPM_H
#define __CROS_EC_USB_PD_TCPM_TCPM_H
+#include "common.h"
+#include "gpio.h"
#include "i2c.h"
#include "usb_pd_tcpm.h"
+#ifndef CONFIG_USB_PD_TCPC
extern const struct tcpc_config_t tcpc_config[];
/* I2C wrapper functions - get I2C port / slave addr from config struct. */
@@ -59,4 +62,178 @@ static inline void tcpc_lock(int port, int lock)
i2c_lock(tcpc_config[port].i2c_host_port, lock);
}
+/* TCPM driver wrapper function */
+static inline int tcpm_init(int port)
+{
+ return tcpc_config[port].drv->init(port);
+}
+
+static inline int tcpm_get_cc(int port, int *cc1, int *cc2)
+{
+ return tcpc_config[port].drv->get_cc(port, cc1, cc2);
+}
+
+static inline int tcpm_get_vbus_level(int port)
+{
+ return tcpc_config[port].drv->get_vbus_level(port);
+}
+
+static inline int tcpm_set_cc(int port, int pull)
+{
+ return tcpc_config[port].drv->set_cc(port, pull);
+}
+
+static inline int tcpm_set_polarity(int port, int polarity)
+{
+ return tcpc_config[port].drv->set_polarity(port, polarity);
+}
+
+static inline int tcpm_set_vconn(int port, int enable)
+{
+ return tcpc_config[port].drv->set_vconn(port, enable);
+}
+
+static inline int tcpm_set_msg_header(int port, int power_role, int data_role)
+{
+ return tcpc_config[port].drv->set_msg_header(port, power_role,
+ data_role);
+}
+
+static inline int tcpm_set_rx_enable(int port, int enable)
+{
+ return tcpc_config[port].drv->set_rx_enable(port, enable);
+}
+
+static inline int tcpm_get_message(int port, uint32_t *payload, int *head)
+{
+ return tcpc_config[port].drv->get_message(port, payload, head);
+}
+
+static inline int tcpm_transmit(int port, enum tcpm_transmit_type type,
+ uint16_t header, const uint32_t *data)
+{
+ return tcpc_config[port].drv->transmit(port, type, header, data);
+}
+
+static inline void tcpc_alert(int port)
+{
+ tcpc_config[port].drv->tcpc_alert(port);
+}
+
+#else
+
+/**
+ * Initialize TCPM driver and wait for TCPC readiness.
+ *
+ * @param port Type-C port number
+ *
+ * @return EC_SUCCESS or error
+ */
+int tcpm_init(int port);
+
+/**
+ * Read the CC line status.
+ *
+ * @param port Type-C port number
+ * @param cc1 pointer to CC status for CC1
+ * @param cc2 pointer to CC status for CC2
+ *
+ * @return EC_SUCCESS or error
+ */
+int tcpm_get_cc(int port, int *cc1, int *cc2);
+
+/**
+ * Read VBUS
+ *
+ * @param port Type-C port number
+ *
+ * @return 0 => VBUS not detected, 1 => VBUS detected
+ */
+int tcpm_get_vbus_level(int port);
+
+/**
+ * Set the CC pull resistor. This sets our role as either source or sink.
+ *
+ * @param port Type-C port number
+ * @param pull One of enum tcpc_cc_pull
+ *
+ * @return EC_SUCCESS or error
+ */
+int tcpm_set_cc(int port, int pull);
+
+/**
+ * Set polarity
+ *
+ * @param port Type-C port number
+ * @param polarity 0=> transmit on CC1, 1=> transmit on CC2
+ *
+ * @return EC_SUCCESS or error
+ */
+int tcpm_set_polarity(int port, int polarity);
+
+/**
+ * Set Vconn.
+ *
+ * @param port Type-C port number
+ * @param polarity Polarity of the CC line to read
+ *
+ * @return EC_SUCCESS or error
+ */
+int tcpm_set_vconn(int port, int enable);
+
+/**
+ * Set PD message header to use for goodCRC
+ *
+ * @param port Type-C port number
+ * @param power_role Power role to use in header
+ * @param data_role Data role to use in header
+ *
+ * @return EC_SUCCESS or error
+ */
+int tcpm_set_msg_header(int port, int power_role, int data_role);
+
+/**
+ * Set RX enable flag
+ *
+ * @param port Type-C port number
+ * @enable true for enable, false for disable
+ *
+ * @return EC_SUCCESS or error
+ */
+int tcpm_set_rx_enable(int port, int enable);
+
+/**
+ * Read last received PD message.
+ *
+ * @param port Type-C port number
+ * @param payload Pointer to location to copy payload of message
+ * @param header of message
+ *
+ * @return EC_SUCCESS or error
+ */
+int tcpm_get_message(int port, uint32_t *payload, int *head);
+
+/**
+ * Transmit PD message
+ *
+ * @param port Type-C port number
+ * @param type Transmit type
+ * @param header Packet header
+ * @param cnt Number of bytes in payload
+ * @param data Payload
+ *
+ * @return EC_SUCCESS or error
+ */
+int tcpm_transmit(int port, enum tcpm_transmit_type type, uint16_t header,
+ const uint32_t *data);
+
+/**
+ * TCPC is asserting alert
+ *
+ * @param port Type-C port number
+ */
+void tcpc_alert(int port);
+
+#endif
+
#endif