diff options
-rw-r--r-- | board/chell/board.c | 5 | ||||
-rw-r--r-- | board/elm/board.c | 5 | ||||
-rw-r--r-- | board/glados/board.c | 5 | ||||
-rw-r--r-- | board/kevin/board.c | 4 | ||||
-rw-r--r-- | board/kunimitsu/board.c | 5 | ||||
-rw-r--r-- | board/lars/board.c | 3 | ||||
-rw-r--r-- | board/oak/board.c | 5 | ||||
-rw-r--r-- | board/pdeval-stm32f072/board.c | 5 | ||||
-rw-r--r-- | board/snoball/board.c | 6 | ||||
-rw-r--r-- | board/strago/board.c | 3 | ||||
-rw-r--r-- | board/strago/board.h | 4 | ||||
-rw-r--r-- | board/wheatley/board.c | 5 | ||||
-rw-r--r-- | common/host_command_pd.c | 1 | ||||
-rw-r--r-- | common/usb_pd_protocol.c | 1 | ||||
-rw-r--r-- | common/usb_pd_tcpc.c | 1 | ||||
-rw-r--r-- | driver/tcpm/fusb302.c | 41 | ||||
-rw-r--r-- | driver/tcpm/fusb302.h | 2 | ||||
-rw-r--r-- | driver/tcpm/stub.c | 17 | ||||
-rw-r--r-- | driver/tcpm/tcpci.c | 76 | ||||
-rw-r--r-- | driver/tcpm/tcpci.h | 3 | ||||
-rw-r--r-- | driver/tcpm/tcpm.h | 177 | ||||
-rw-r--r-- | include/usb_pd_tcpm.h | 256 |
22 files changed, 407 insertions, 223 deletions
diff --git a/board/chell/board.c b/board/chell/board.c index 3b47301806..cb80a448e7 100644 --- a/board/chell/board.c +++ b/board/chell/board.c @@ -29,6 +29,7 @@ #include "switch.h" #include "system.h" #include "task.h" +#include "tcpci.h" #include "temp_sensor.h" #include "timer.h" #include "uart.h" @@ -116,8 +117,8 @@ const struct i2c_port_t i2c_ports[] = { const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR}, - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR + 2}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR, &tcpci_tcpm_drv}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR + 2, &tcpci_tcpm_drv}, }; /* SPI devices */ diff --git a/board/elm/board.c b/board/elm/board.c index 13366f7cb1..8d02e76dca 100644 --- a/board/elm/board.c +++ b/board/elm/board.c @@ -17,6 +17,7 @@ #include "console.h" #include "driver/accel_kionix.h" #include "driver/accel_kx022.h" +#include "driver/tcpm/tcpci.h" #include "driver/temp_sensor/tmp432.h" #include "extpower.h" #include "gpio.h" @@ -111,7 +112,7 @@ const unsigned int spi_devices_used = ARRAY_SIZE(spi_devices); /* TCPC */ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR, &tcpci_tcpm_drv}, }; struct pi3usb9281_config pi3usb9281_chips[] = { @@ -156,7 +157,7 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = { /* TODO: 7688 support MUX Control 00b and 10b? */ { .port_addr = 0, /* port idx */ - .driver = &tcpm_usb_mux_driver, + .driver = &tcpci_tcpm_usb_mux_driver, }, }; diff --git a/board/glados/board.c b/board/glados/board.c index 892d5ed425..08ed832fa6 100644 --- a/board/glados/board.c +++ b/board/glados/board.c @@ -18,6 +18,7 @@ #include "driver/accel_kionix.h" #include "driver/accel_kx022.h" #include "driver/accelgyro_bmi160.h" +#include "driver/tcpm/tcpci.h" #include "extpower.h" #include "gpio.h" #include "hooks.h" @@ -127,8 +128,8 @@ const struct i2c_port_t i2c_ports[] = { const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR}, - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR + 2}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR, &tcpci_tcpm_drv}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR + 2, &tcpci_tcpm_drv}, }; /* SPI devices */ diff --git a/board/kevin/board.c b/board/kevin/board.c index 8c61aff0f1..6ab36d5824 100644 --- a/board/kevin/board.c +++ b/board/kevin/board.c @@ -112,8 +112,8 @@ const struct button_config buttons[CONFIG_BUTTON_COUNT] = { }; const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { - {I2C_PORT_TCPC0, FUSB302_I2C_SLAVE_ADDR}, - {I2C_PORT_TCPC1, FUSB302_I2C_SLAVE_ADDR}, + {I2C_PORT_TCPC0, FUSB302_I2C_SLAVE_ADDR, &fusb302_tcpm_drv}, + {I2C_PORT_TCPC1, FUSB302_I2C_SLAVE_ADDR, &fusb302_tcpm_drv}, }; void board_reset_pd_mcu(void) diff --git a/board/kunimitsu/board.c b/board/kunimitsu/board.c index 1a1072c909..75e8ecab0f 100644 --- a/board/kunimitsu/board.c +++ b/board/kunimitsu/board.c @@ -17,6 +17,7 @@ #include "driver/als_opt3001.h" #include "driver/gyro_l3gd20h.h" #include "driver/pmic_tps650830.h" +#include "driver/tcpm/tcpci.h" #include "driver/temp_sensor/tmp432.h" #include "extpower.h" #include "fan.h" @@ -130,8 +131,8 @@ const struct i2c_port_t i2c_ports[] = { const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR}, - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR + 2}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR, &tcpci_tcpm_drv}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR + 2, &tcpci_tcpm_drv}, }; /* Physical fans. These are logically separate from pwm_channels. */ diff --git a/board/lars/board.c b/board/lars/board.c index ec06604c56..55e00b24a6 100644 --- a/board/lars/board.c +++ b/board/lars/board.c @@ -10,6 +10,7 @@ #include "charger.h" #include "console.h" #include "driver/pmic_tps650830.h" +#include "driver/tcpm/tcpci.h" #include "driver/temp_sensor/tmp432.h" #include "extpower.h" #include "fan.h" @@ -116,7 +117,7 @@ const struct i2c_port_t i2c_ports[] = { const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR, &tcpci_tcpm_drv}, }; /* Physical fans. These are logically separate from pwm_channels. */ diff --git a/board/oak/board.c b/board/oak/board.c index 4ab2c5c217..9f770d8865 100644 --- a/board/oak/board.c +++ b/board/oak/board.c @@ -20,6 +20,7 @@ #include "driver/accel_kx022.h" #include "driver/accelgyro_bmi160.h" #include "driver/als_opt3001.h" +#include "driver/tcpm/tcpci.h" #include "driver/temp_sensor/tmp432.h" #include "extpower.h" #include "gpio.h" @@ -112,8 +113,8 @@ const unsigned int spi_devices_used = ARRAY_SIZE(spi_devices); #endif const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR}, - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR + 2}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR, &tcpci_tcpm_drv}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR + 2, &tcpci_tcpm_drv}, }; struct mutex pericom_mux_lock; diff --git a/board/pdeval-stm32f072/board.c b/board/pdeval-stm32f072/board.c index ab476d006e..f5aa26d10b 100644 --- a/board/pdeval-stm32f072/board.c +++ b/board/pdeval-stm32f072/board.c @@ -12,6 +12,7 @@ #include "i2c.h" #include "registers.h" #include "task.h" +#include "tcpci.h" #include "usb_descriptor.h" #include "usb_pd.h" #include "usb_pd_tcpm.h" @@ -56,9 +57,9 @@ const struct i2c_port_t i2c_ports[] = { const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { - {I2C_PORT_TCPC, TCPC1_I2C_ADDR}, + {I2C_PORT_TCPC, TCPC1_I2C_ADDR, &tcpci_tcpm_drv}, #if CONFIG_USB_PD_PORT_COUNT >= 2 - {I2C_PORT_TCPC, TCPC2_I2C_ADDR}, + {I2C_PORT_TCPC, TCPC2_I2C_ADDR, &tcpci_tcpm_drv}, #endif }; diff --git a/board/snoball/board.c b/board/snoball/board.c index 5eaf722946..7efa5b314b 100644 --- a/board/snoball/board.c +++ b/board/snoball/board.c @@ -37,10 +37,10 @@ const struct i2c_port_t i2c_ports[] = { const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { - {STM32_I2C1_PORT, FUSB302_I2C_SLAVE_ADDR}, - {STM32_I2C2_PORT, FUSB302_I2C_SLAVE_ADDR}, + {STM32_I2C1_PORT, FUSB302_I2C_SLAVE_ADDR, &fusb302_tcpm_drv}, + {STM32_I2C2_PORT, FUSB302_I2C_SLAVE_ADDR, &fusb302_tcpm_drv}, /* TODO: Verify secondary slave addr, or use i2c mux */ - {STM32_I2C2_PORT, FUSB302_I2C_SLAVE_ADDR + 2}, + {STM32_I2C2_PORT, FUSB302_I2C_SLAVE_ADDR + 2, &fusb302_tcpm_drv}, }; uint16_t tcpc_get_alert_status(void) diff --git a/board/strago/board.c b/board/strago/board.c index fb40fb9a18..32ca7aa4a8 100644 --- a/board/strago/board.c +++ b/board/strago/board.c @@ -15,6 +15,7 @@ #include "driver/accel_kionix.h" #include "driver/accel_kxcj9.h" #include "driver/als_isl29035.h" +#include "driver/tcpm/tcpci.h" #include "driver/temp_sensor/tmp432.h" #include "extpower.h" #include "gpio.h" @@ -105,7 +106,7 @@ const struct i2c_port_t i2c_ports[] = { const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR, &tcpci_tcpm_drv}, }; /* SPI master ports */ diff --git a/board/strago/board.h b/board/strago/board.h index f16126d979..2fd14e0ad6 100644 --- a/board/strago/board.h +++ b/board/strago/board.h @@ -29,6 +29,10 @@ #define CONFIG_POWER_SHUTDOWN_PAUSE_IN_S5 #define CONFIG_EXTPOWER_GPIO +/* All data won't fit in data RAM. So, moving boundary slightly. */ +#undef CONFIG_RO_SIZE +#define CONFIG_RO_SIZE (104 * 1024) + #define CONFIG_USB_CHARGER #define CONFIG_USB_MUX_PI3USB30532 #define CONFIG_USB_POWER_DELIVERY diff --git a/board/wheatley/board.c b/board/wheatley/board.c index a276d4344d..ba6fce0f7f 100644 --- a/board/wheatley/board.c +++ b/board/wheatley/board.c @@ -18,6 +18,7 @@ #include "driver/accel_kionix.h" #include "driver/accel_kx022.h" #include "driver/accelgyro_bmi160.h" +#include "driver/tcpm/tcpci.h" #include "extpower.h" #include "gpio.h" #include "hooks.h" @@ -127,8 +128,8 @@ const struct i2c_port_t i2c_ports[] = { const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = { - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR}, - {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR + 2}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR, &tcpci_tcpm_drv}, + {I2C_PORT_TCPC, CONFIG_TCPC_I2C_BASE_ADDR + 2, &tcpci_tcpm_drv}, }; const enum gpio_signal hibernate_wake_pins[] = { diff --git a/common/host_command_pd.c b/common/host_command_pd.c index a6883dcfd8..1042b2f232 100644 --- a/common/host_command_pd.c +++ b/common/host_command_pd.c @@ -14,6 +14,7 @@ #include "panic.h" #include "system.h" #include "task.h" +#include "tcpm.h" #include "timer.h" #include "usb_pd_tcpm.h" #include "util.h" diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 358660d5d4..e8540d9dca 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -24,6 +24,7 @@ #include "usb_mux.h" #include "usb_pd.h" #include "usb_pd_tcpm.h" +#include "tcpm.h" #include "version.h" #ifdef CONFIG_COMMON_RUNTIME diff --git a/common/usb_pd_tcpc.c b/common/usb_pd_tcpc.c index e38d9e24db..a7ed832a0c 100644 --- a/common/usb_pd_tcpc.c +++ b/common/usb_pd_tcpc.c @@ -16,6 +16,7 @@ #include "system.h" #include "task.h" #include "tcpci.h" +#include "tcpm.h" #include "timer.h" #include "util.h" #include "usb_pd.h" 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, ®); + tcpci_tcpm_get_power_status(port, ®); /* 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 diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h index 4e1b04249e..90dae03fd2 100644 --- a/include/usb_pd_tcpm.h +++ b/include/usb_pd_tcpm.h @@ -47,13 +47,124 @@ enum tcpc_transmit_complete { TCPC_TX_COMPLETE_FAILED = 2, }; +struct tcpm_drv { + /** + * Initialize TCPM driver and wait for TCPC readiness. + * + * @param port Type-C port number + * + * @return EC_SUCCESS or error + */ + int (*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 (*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 (*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 (*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 (*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 (*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 (*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 (*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 (*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 (*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); +}; + struct tcpc_config_t { int i2c_host_port; int i2c_slave_addr; - /* - * TODO: Consider adding driver struct / function pointers to support - * different TCPM drivers on the same board. - */ + const struct tcpm_drv *drv; }; /** @@ -65,15 +176,6 @@ struct tcpc_config_t { uint16_t tcpc_get_alert_status(void); /** - * Initialize TCPM driver and wait for TCPC readiness. - * - * @param port Type-C port number - * - * @return EC_SUCCESS or error - */ -int tcpm_init(int port); - -/** * Initialize TCPC. * * @param port Type-C port number @@ -85,7 +187,6 @@ void tcpc_init(int port); * * @param port Type-C port number */ -void tcpc_alert(int port); void tcpc_alert_clear(int port); /** @@ -97,131 +198,4 @@ void tcpc_alert_clear(int port); */ int tcpc_run(int port, int evt); - -/** - * Read TCPC alert status - * - * @param port Type-C port number - * @param alert Pointer to location to store alert status - - * @return EC_SUCCESS or error - */ -int tcpm_alert_status(int port, int *alert); - -/** - * Write TCPC Alert Mask register - * - * @param port Type-C port number - * @param mask bits to be set in Alert Mask register - - * @return EC_SUCCESS or error - */ -int tcpm_alert_mask_set(int port, uint16_t mask); - -/** - * 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 TCPC Power Status Mask - * - * @param port Type-C port number - * @param mask => new mask value - * - * @return EC_SUCCESS or error - */ -int tcpm_set_power_status_mask(int port, uint8_t mask); - -/** - * 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); - #endif /* __CROS_EC_USB_PD_TCPM_H */ |