summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--baseboard/zork/baseboard.c5
-rw-r--r--baseboard/zork/baseboard.h3
-rw-r--r--driver/build.mk1
-rw-r--r--driver/usb_mux/amd_fp5.c97
-rw-r--r--driver/usb_mux/amd_fp5.h21
-rw-r--r--include/config.h3
-rw-r--r--include/usb_mux.h1
7 files changed, 127 insertions, 4 deletions
diff --git a/baseboard/zork/baseboard.c b/baseboard/zork/baseboard.c
index 0bf187ee90..4f63cfb006 100644
--- a/baseboard/zork/baseboard.c
+++ b/baseboard/zork/baseboard.c
@@ -130,7 +130,7 @@ const struct i2c_port_t i2c_ports[] = {
},
{
.name = "mux",
- .port = I2C_PORT_MUX,
+ .port = I2C_PORT_USB_MUX,
.kbps = 400,
.scl = GPIO_EC_I2C_USBC_AP_MUX_SCL,
.sda = GPIO_EC_I2C_USBC_AP_MUX_SDA,
@@ -458,8 +458,7 @@ void bc12_interrupt(enum gpio_signal signal)
struct usb_mux usb_muxes[] = {
[USBC_PORT_C0] = {
- .driver = &tcpci_tcpm_usb_mux_driver,
- .hpd_update = &ps8xxx_tcpc_update_hpd_status,
+ .driver = &amd_fp5_usb_mux_driver,
},
[USBC_PORT_C1] = {
.driver = &tcpci_tcpm_usb_mux_driver,
diff --git a/baseboard/zork/baseboard.h b/baseboard/zork/baseboard.h
index 9f8ab6b8d4..af3f0f8d04 100644
--- a/baseboard/zork/baseboard.h
+++ b/baseboard/zork/baseboard.h
@@ -141,6 +141,7 @@
#define CONFIG_USBC_SS_MUX_DFP_ONLY
#define CONFIG_USBC_VCONN
#define CONFIG_USBC_VCONN_SWAP
+#define CONFIG_USB_MUX_AMD_FP5
#define PD_POWER_SUPPLY_TURN_ON_DELAY 30000 /* us */
#define PD_POWER_SUPPLY_TURN_OFF_DELAY 30000 /* us */
@@ -174,7 +175,7 @@
#define I2C_PORT_BATTERY NPCX_I2C_PORT2_0
#define I2C_PORT_CHARGER NPCX_I2C_PORT2_0
#define I2C_PORT_EEPROM NPCX_I2C_PORT2_0
-#define I2C_PORT_MUX NPCX_I2C_PORT3_0
+#define I2C_PORT_USB_MUX NPCX_I2C_PORT3_0
#define I2C_PORT_THERMAL NPCX_I2C_PORT4_1
#define I2C_PORT_SENSOR NPCX_I2C_PORT5_0
#define I2C_PORT_ACCEL NPCX_I2C_PORT5_0
diff --git a/driver/build.mk b/driver/build.mk
index 4af4264c22..b562d556a9 100644
--- a/driver/build.mk
+++ b/driver/build.mk
@@ -137,6 +137,7 @@ driver-$(CONFIG_USB_PD_RETIMER_INTEL_BB)+=retimer/bb_retimer.o
driver-$(CONFIG_USBC_SS_MUX)+=usb_mux/usb_mux.o
# USB muxes
+driver-$(CONFIG_USB_MUX_AMD_FP5)+=usb_mux/amd_fp5.o
driver-$(CONFIG_USB_MUX_IT5205)+=usb_mux/it5205.o
driver-$(CONFIG_USB_MUX_PI3USB30532)+=usb_mux/pi3usb30532.o
driver-$(CONFIG_USB_MUX_PS8740)+=usb_mux/ps874x.o
diff --git a/driver/usb_mux/amd_fp5.c b/driver/usb_mux/amd_fp5.c
new file mode 100644
index 0000000000..f88df52577
--- /dev/null
+++ b/driver/usb_mux/amd_fp5.c
@@ -0,0 +1,97 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * AMD FP5 USB/DP Mux.
+ */
+
+#include "amd_fp5.h"
+#include "common.h"
+#include "i2c.h"
+#include "usb_mux.h"
+
+static inline int amd_fp5_mux_read(int port, uint8_t *val)
+{
+ uint8_t buf[3] = { 0 };
+ int rv;
+
+ rv = i2c_xfer(I2C_PORT_USB_MUX, AMD_FP5_MUX_I2C_ADDR_FLAGS,
+ NULL, 0, buf, 3);
+ if (rv)
+ return rv;
+
+ *val = buf[port + 1];
+
+ return EC_SUCCESS;
+}
+
+static inline int amd_fp5_mux_write(int port, uint8_t val)
+{
+ return i2c_write8(I2C_PORT_USB_MUX, AMD_FP5_MUX_I2C_ADDR_FLAGS,
+ port, val);
+}
+
+static int amd_fp5_init(int port)
+{
+ return EC_SUCCESS;
+}
+
+static int amd_fp5_set_mux(int port, mux_state_t mux_state)
+{
+ uint8_t val = 0;
+
+ if ((mux_state & MUX_USB_ENABLED) && (mux_state & MUX_DP_ENABLED))
+ val = (mux_state & MUX_POLARITY_INVERTED)
+ ? AMD_FP5_MUX_DOCK_INVERTED : AMD_FP5_MUX_DOCK;
+ else if (mux_state & MUX_USB_ENABLED)
+ val = (mux_state & MUX_POLARITY_INVERTED)
+ ? AMD_FP5_MUX_USB_INVERTED : AMD_FP5_MUX_USB;
+ else if (mux_state & MUX_DP_ENABLED)
+ val = (mux_state & MUX_POLARITY_INVERTED)
+ ? AMD_FP5_MUX_DP_INVERTED : AMD_FP5_MUX_DP;
+
+ return amd_fp5_mux_write(port, val);
+}
+
+static int amd_fp5_get_mux(int port, mux_state_t *mux_state)
+{
+ uint8_t val = 0;
+ int rv;
+
+ rv = amd_fp5_mux_read(port, &val);
+ if (rv)
+ return rv;
+
+ switch (val) {
+ case AMD_FP5_MUX_USB:
+ *mux_state = MUX_USB_ENABLED;
+ break;
+ case AMD_FP5_MUX_USB_INVERTED:
+ *mux_state = MUX_USB_ENABLED | MUX_POLARITY_INVERTED;
+ break;
+ case AMD_FP5_MUX_DOCK:
+ *mux_state = MUX_USB_ENABLED | MUX_DP_ENABLED;
+ break;
+ case AMD_FP5_MUX_DOCK_INVERTED:
+ *mux_state = MUX_USB_ENABLED | MUX_DP_ENABLED
+ | MUX_POLARITY_INVERTED;
+ break;
+ case AMD_FP5_MUX_DP:
+ *mux_state = MUX_DP_ENABLED;
+ break;
+ case AMD_FP5_MUX_DP_INVERTED:
+ *mux_state = MUX_DP_ENABLED | MUX_POLARITY_INVERTED;
+ break;
+ default:
+ *mux_state = 0;
+ break;
+ }
+
+ return EC_SUCCESS;
+}
+
+const struct usb_mux_driver amd_fp5_usb_mux_driver = {
+ .init = amd_fp5_init,
+ .set = amd_fp5_set_mux,
+ .get = amd_fp5_get_mux,
+};
diff --git a/driver/usb_mux/amd_fp5.h b/driver/usb_mux/amd_fp5.h
new file mode 100644
index 0000000000..7534ea0d8a
--- /dev/null
+++ b/driver/usb_mux/amd_fp5.h
@@ -0,0 +1,21 @@
+/* Copyright 2019 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ *
+ * AMD FP5 USB/DP Mux.
+ */
+
+#ifndef __CROS_EC_USB_MUX_AMD_FP5_H
+#define __CROS_EC_USB_MUX_AMD_FP5_H
+
+#define AMD_FP5_MUX_I2C_ADDR_FLAGS 0x5C
+
+#define AMD_FP5_MUX_SAFE 0x00
+#define AMD_FP5_MUX_USB 0x02
+#define AMD_FP5_MUX_USB_INVERTED 0x11
+#define AMD_FP5_MUX_DOCK 0x06
+#define AMD_FP5_MUX_DOCK_INVERTED 0x19
+#define AMD_FP5_MUX_DP 0x0C
+#define AMD_FP5_MUX_DP_INVERTED 0x1C
+
+#endif /* __CROS_EC_USB_MUX_AMD_FP5_H */
diff --git a/include/config.h b/include/config.h
index 9ecd19abbb..c9754bc649 100644
--- a/include/config.h
+++ b/include/config.h
@@ -4102,6 +4102,9 @@
/******************************************************************************/
/* USB port switch */
+/* Support the AMD FP5 USB/DP Mux */
+#undef CONFIG_USB_MUX_AMD_FP5
+
/* Support the ITE IT5205 Type-C USB alternate mode mux. */
#undef CONFIG_USB_MUX_IT5205
diff --git a/include/usb_mux.h b/include/usb_mux.h
index 21d60337a8..88fb10b549 100644
--- a/include/usb_mux.h
+++ b/include/usb_mux.h
@@ -125,6 +125,7 @@ struct usb_mux {
};
/* Supported USB mux drivers */
+extern const struct usb_mux_driver amd_fp5_usb_mux_driver;
extern const struct usb_mux_driver it5205_usb_mux_driver;
extern const struct usb_mux_driver pi3usb30532_usb_mux_driver;
extern const struct usb_mux_driver ps874x_usb_mux_driver;