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