summaryrefslogtreecommitdiff
path: root/include/usb_mux.h
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2018-08-30 16:13:26 -0600
committerchrome-bot <chrome-bot@chromium.org>2018-09-05 16:11:04 -0700
commitdaed130e62e7332037e46c70277816e0630ad04a (patch)
treec43f204a27f41a41a46c41905957f104123934c0 /include/usb_mux.h
parent4173a851603b2e00b241150092292b5a29ba3be2 (diff)
downloadchrome-ec-daed130e62e7332037e46c70277816e0630ad04a.tar.gz
ss-mux: update semantics for TCPC/MUX only used as MUX
This converts the compile time option of CONFIG_USB_PD_TCPM_TCPCI_MUX_ONLY into a runtime option to better support draggon egg designs and reduce CONFIG complexity in general. Introduce new mux_read/write to read from tcpc_config_t or mux driver depending on new flag setting. Audited all mux drivers for any use of tcpc_read/write and updated to mux_read/write. BRANCH=none BUG=b:110937880 TEST=On Bip with CL stack: Verified by connecting DP monitor at boot; Verified plug / unplug of DP cable works; Change-Id: I968893b886ff0ccc4074beae5ec42973814ae77c Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1200062 Commit-Ready: Gaggery Tsai <gaggery.tsai@intel.corp-partner.google.com> Reviewed-by: Scott Collyer <scollyer@chromium.org>
Diffstat (limited to 'include/usb_mux.h')
-rw-r--r--include/usb_mux.h70
1 files changed, 57 insertions, 13 deletions
diff --git a/include/usb_mux.h b/include/usb_mux.h
index 8944c4b774..7c3f5ae55f 100644
--- a/include/usb_mux.h
+++ b/include/usb_mux.h
@@ -9,6 +9,7 @@
#define __CROS_EC_USB_MUX_H
#include "ec_commands.h"
+#include "tcpm.h"
#include "usb_charge.h"
#include "usb_pd.h"
@@ -20,10 +21,13 @@
*/
typedef uint8_t mux_state_t;
-/* Packing and Unpacking defines used with CONFIG_USB_PD_TCPM_TCPCI_MUX_ONLY */
+/*
+ * Packing and Unpacking defines used with USB_MUX_FLAG_NOT_TCPC
+ * MUX_PORT takes in a USB-C port number and returns the I2C port number
+ */
#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)
+#define MUX_PORT(port) (usb_muxes[port].port_addr >> 8)
+#define MUX_ADDR(port) (usb_muxes[port].port_addr & 0xFF)
/* Mux state attributes */
/* TODO: Directly use USB_PD_MUX_* everywhere and remove these 3 defines */
@@ -46,28 +50,28 @@ struct usb_mux_driver {
* Initialize USB mux. This is called every time the MUX is access after
* being put in a fully disconnected state (low power mode).
*
- * @param port_addr Port/address driver-defined parameter.
+ * @param port usb port of mux (not port_addr)
* @return EC_SUCCESS on success, non-zero error code on failure.
*/
- int (*init)(int port_addr);
+ int (*init)(int port);
/**
* Set USB mux state.
*
- * @param port_addr Port/address driver-defined parameter.
+ * @param port usb port of mux (not port_addr)
* @param mux_state State to set mux to.
* @return EC_SUCCESS on success, non-zero error code on failure.
*/
- int (*set)(int port_addr, mux_state_t mux_state);
+ int (*set)(int port, mux_state_t mux_state);
/**
* Get current state of USB mux.
*
- * @param port_addr Port / address driver-defined parameter.
+ * @param port usb port of mux (not port_addr)
* @param mux_state Gets set to current state of mux.
* @return EC_SUCCESS on success, non-zero error code on failure.
*/
- int (*get)(int port_addr, mux_state_t *mux_state);
+ int (*get)(int port, mux_state_t *mux_state);
/**
* Optional method that is called after the mux fully disconnects.
@@ -76,12 +80,15 @@ struct usb_mux_driver {
* where the TCPC is actively used since the PD state machine
* will put the chip into lower power mode.
*
- * @param mux USB mux to put into low power.
+ * @param port usb port of mux (not port_addr)
* @return EC_SUCCESS on success, non-zero error code on failure.
*/
- int (*enter_low_power_mode)(int port_addr);
+ int (*enter_low_power_mode)(int port);
};
+/* Flags used for usb_mux.flags */
+#define USB_MUX_FLAG_NOT_TCPC (1 << 0) /* TCPC/MUX device used only as MUX */
+
/* Describes a USB mux present in the system */
struct usb_mux {
/*
@@ -90,16 +97,19 @@ struct usb_mux {
*/
const int port_addr;
+ /* Run-time flags with prefix USB_MUX_FLAG_ */
+ const uint32_t flags;
+
/* Mux driver */
const struct usb_mux_driver *driver;
/**
* Optional method for tuning for USB mux during mux->driver->init().
*
- * @param mux USB mux to tune
+ * @param port usb port of mux (not port_addr)
* @return EC_SUCCESS on success, non-zero error code on failure.
*/
- int (*board_init)(const struct usb_mux *mux);
+ int (*board_init)(int port);
/*
* USB Type-C DP alt mode support. Notify Type-C controller
@@ -122,6 +132,40 @@ void virtual_hpd_update(int port, int hpd_lvl, int hpd_irq);
/* USB muxes present in system, ordered by PD port #, defined at board-level */
extern struct usb_mux usb_muxes[];
+/*
+ * Helper methods that either use tcpc communication or direct i2c
+ * communication depending on how the TCPC/MUX device is configured.
+ */
+#ifdef CONFIG_USB_PD_TCPM_MUX
+static inline int mux_write(int port, int reg, int val)
+{
+ return usb_muxes[port].flags & USB_MUX_FLAG_NOT_TCPC
+ ? i2c_write8(MUX_PORT(port), MUX_ADDR(port), reg, val)
+ : tcpc_write(port, reg, val);
+}
+
+static inline int mux_read(int port, int reg, int *val)
+{
+ return usb_muxes[port].flags & USB_MUX_FLAG_NOT_TCPC
+ ? i2c_read8(MUX_PORT(port), MUX_ADDR(port), reg, val)
+ : tcpc_read(port, reg, val);
+}
+
+static inline int mux_write16(int port, int reg, int val)
+{
+ return usb_muxes[port].flags & USB_MUX_FLAG_NOT_TCPC
+ ? i2c_write16(MUX_PORT(port), MUX_ADDR(port), reg, val)
+ : tcpc_write16(port, reg, val);
+}
+
+static inline int mux_read16(int port, int reg, int *val)
+{
+ return usb_muxes[port].flags & USB_MUX_FLAG_NOT_TCPC
+ ? i2c_read16(MUX_PORT(port), MUX_ADDR(port), reg, val)
+ : tcpc_read16(port, reg, val);
+}
+#endif /* CONFIG_USB_PD_TCPM_MUX */
+
/**
* Initialize USB mux to its default state.
*