From 58f790b2c19cc95a07ac72fa4d7df1974619f785 Mon Sep 17 00:00:00 2001 From: Jett Rink Date: Mon, 23 Apr 2018 10:42:42 -0600 Subject: [PATCH] mux: add mode for TCPCI mux that is not the TCPC We need to use the PS8751 as the USB mux without configuring it as the TCPC. Add mode that allows passing in i2c port and address instead using tcpc_config_t values. BRANCH=none BUG=b:78341944 TEST=build using bip Change-Id: I45b420ef890dfa8c5e5052864b7a2bb66d8734d6 Signed-off-by: Jett Rink Reviewed-on: https://chromium-review.googlesource.com/1024486 --- driver/tcpm/tcpci.c | 27 +++++++++++++++++++-------- include/config.h | 8 ++++++++ include/usb_mux.h | 5 +++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c index 96d6e5ba68..3c1234810f 100644 --- a/driver/tcpm/tcpci.c +++ b/driver/tcpm/tcpci.c @@ -496,13 +496,18 @@ int tcpci_tcpm_mux_init(int i2c_addr) return EC_SUCCESS; } -int tcpci_tcpm_mux_set(int i2c_addr, mux_state_t mux_state) +int tcpci_tcpm_mux_set(int i2c_port_addr, mux_state_t mux_state) { int reg = 0; int rv; - int port = i2c_addr; /* use port index in port_addr field */ - - rv = tcpc_read(port, TCPC_REG_CONFIG_STD_OUTPUT, ®); +#ifdef CONFIG_USB_PD_TCPM_TCPCI_MUX_ONLY + int port = MUX_PORT(i2c_port_addr); + int addr = MUX_ADDR(i2c_port_addr); +#else + int port = tcpc_config[i2c_port_addr].i2c_host_port; + int addr = tcpc_config[i2c_port_addr].i2c_slave_addr; +#endif + rv = i2c_read8(port, addr, TCPC_REG_CONFIG_STD_OUTPUT, ®); if (rv != EC_SUCCESS) return rv; @@ -515,18 +520,24 @@ int tcpci_tcpm_mux_set(int i2c_addr, mux_state_t mux_state) if (mux_state & MUX_POLARITY_INVERTED) reg |= TCPC_REG_CONFIG_STD_OUTPUT_CONNECTOR_FLIPPED; - return tcpc_write(port, TCPC_REG_CONFIG_STD_OUTPUT, reg); + return i2c_write8(port, addr, TCPC_REG_CONFIG_STD_OUTPUT, reg); } /* Reads control register and updates mux_state accordingly */ -int tcpci_tcpm_mux_get(int i2c_addr, mux_state_t *mux_state) +int tcpci_tcpm_mux_get(int i2c_port_addr, mux_state_t *mux_state) { int reg = 0; int rv; - int port = i2c_addr; /* use port index in port_addr field */ +#ifdef CONFIG_USB_PD_TCPM_TCPCI_MUX_ONLY + int port = MUX_PORT(i2c_port_addr); + int addr = MUX_ADDR(i2c_port_addr); +#else + int port = tcpc_config[i2c_port_addr].i2c_host_port; + int addr = tcpc_config[i2c_port_addr].i2c_slave_addr; +#endif *mux_state = 0; - rv = tcpc_read(port, TCPC_REG_CONFIG_STD_OUTPUT, ®); + rv = i2c_read8(port, addr, TCPC_REG_CONFIG_STD_OUTPUT, ®); if (rv != EC_SUCCESS) return rv; diff --git a/include/config.h b/include/config.h index a42ad59081..0dc58f6f98 100644 --- a/include/config.h +++ b/include/config.h @@ -2886,6 +2886,14 @@ */ #undef CONFIG_USB_PD_TCPM_MUX +/* + * Use this option if any TCPC/MUX chip is only being used as a mux and the + * board's tcpc_config_t does not specify the chip. When this option is defined, + * all TPCPI mux drivers must use the MUX_PORT_AND_ADDR define to pack the port + * and address together. + */ +#undef CONFIG_USB_PD_TCPM_TCPCI_MUX_ONLY + /* * The TCPM must know whether VBUS is present in order to make proper state * transitions. In addition, charge_manager must know about VBUS presence in diff --git a/include/usb_mux.h b/include/usb_mux.h index 151c397995..71ed1140ae 100644 --- a/include/usb_mux.h +++ b/include/usb_mux.h @@ -15,6 +15,11 @@ /* USB-C mux state */ typedef uint8_t mux_state_t; +/* Packing and Unpacking defines used with CONFIG_USB_PD_TCPM_TCPCI_MUX_ONLY */ +#define MUX_PORT_AND_ADDR(port, addr) ((port << 8) | (addr & 0xFF)) +#define MUX_PORT(port_addr) (port_addr >> 8) +#define MUX_ADDR(port_addr) (port_addr & 0xFF) + /* Mux state attributes */ /* TODO: Directly use USB_PD_MUX_* everywhere and remove these 3 defines */ #define MUX_USB_ENABLED USB_PD_MUX_USB_ENABLED