summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDivya Sasidharan <divya.s.sasidharan@intel.com>2017-05-16 10:59:17 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-08-11 20:10:22 -0700
commitd4a8c130f754bd4978e074d4a5c4c9d52283d334 (patch)
tree3a04b5a1ca31546c2c3344a5d682d43125d75abe
parent8d6da80f34cab49cd773e462d9720a210d4ce471 (diff)
downloadchrome-ec-d4a8c130f754bd4978e074d4a5c4c9d52283d334.tar.gz
usb_mux: Add driver support for PS8743 chip
Initial patch for supporting PS8743 USB Type-C Redriving Switch for USB Host / DisplayPort. BUG=b:64598680 BRANCH=glkrvp TEST=On GLKRVP, verify mux setting is correct with Apple dongle (VGA + USB) and Pluggable adapter. Change-Id: Ib45e328fc9ef6ccc410cef4550086be95ef17e8a Signed-off-by: Divya Sasidharan <divya.s.sasidharan@intel.com> Reviewed-on: https://chromium-review.googlesource.com/506810 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--driver/build.mk1
-rw-r--r--driver/ps8743.h40
-rw-r--r--driver/usb_mux_ps8743.c108
-rw-r--r--include/config.h3
-rw-r--r--include/usb_mux.h1
5 files changed, 153 insertions, 0 deletions
diff --git a/driver/build.mk b/driver/build.mk
index 25a2feaa56..b4d2638a57 100644
--- a/driver/build.mk
+++ b/driver/build.mk
@@ -102,6 +102,7 @@ driver-$(CONFIG_USBC_SS_MUX)+=usb_mux.o
# USB muxes
driver-$(CONFIG_USB_MUX_PI3USB30532)+=usb_mux_pi3usb30532.o
driver-$(CONFIG_USB_MUX_PS8740)+=usb_mux_ps8740.o
+driver-$(CONFIG_USB_MUX_PS8743)+=usb_mux_ps8743.o
driver-$(CONFIG_USB_MUX_VIRTUAL)+=usb_mux_virtual.o
# Firmware Update
diff --git a/driver/ps8743.h b/driver/ps8743.h
new file mode 100644
index 0000000000..1ab516bba4
--- /dev/null
+++ b/driver/ps8743.h
@@ -0,0 +1,40 @@
+/* Copyright 2017 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.
+ *
+ * Parade PS8743 USB Type-C Redriving Switch for USB Host / DisplayPort.
+ */
+
+#ifndef __CROS_EC_PS8743_H
+#define __CROS_EC_PS8743_H
+
+/* Mode register for setting mux */
+#define PS8743_REG_MODE 0x00
+#define PS8743_MODE_POLARITY_INVERTED (1 << 2)
+#define PS8743_MODE_FLIP_PIN_ENABLED (1 << 3)
+#define PS8743_MODE_USB_ENABLED (1 << 4)
+#define PS8743_MODE_CE_USB_ENABLED (1 << 5)
+#define PS8743_MODE_DP_ENABLED (1 << 6)
+#define PS8743_MODE_CE_DP_ENABLED (1 << 7)
+/* To reset the state machine to default */
+#define PS8743_MODE_POWER_DOWN (PS8743_MODE_CE_USB_ENABLED | \
+ PS8743_MODE_CE_DP_ENABLED)
+
+/* Status register for checking mux state */
+#define PS8743_REG_STATUS 0x09
+#define PS8743_STATUS_POLARITY_INVERTED (1 << 2)
+#define PS8743_STATUS_USB_ENABLED (1 << 3)
+#define PS8743_STATUS_DP_ENABLED (1 << 4)
+#define PS8743_STATUS_HPD_ASSERTED (1 << 7)
+
+/* Chip ID / revision registers and expected fused values */
+#define PS8743_REG_REVISION_ID1 0xf0
+#define PS8743_REVISION_ID1 0x01
+#define PS8743_REG_REVISION_ID2 0xf1
+#define PS8743_REVISION_ID2 0x0b
+#define PS8743_REG_CHIP_ID1 0xf2
+#define PS8743_CHIP_ID1 0x41
+#define PS8743_REG_CHIP_ID2 0xf3
+#define PS8743_CHIP_ID2 0x87
+
+#endif /* __CROS_EC_PS8743_H */
diff --git a/driver/usb_mux_ps8743.c b/driver/usb_mux_ps8743.c
new file mode 100644
index 0000000000..112bda40ee
--- /dev/null
+++ b/driver/usb_mux_ps8743.c
@@ -0,0 +1,108 @@
+/* Copyright 2017 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.
+ *
+ * Parade PS8743 USB Type-C Redriving Switch for USB Host / DisplayPort.
+ *
+ * TODO: Merge PS8743 & PS8740 as PS874X as both the drivers are almost same.
+ */
+
+#include "common.h"
+#include "i2c.h"
+#include "ps8743.h"
+#include "usb_mux.h"
+#include "util.h"
+
+static inline int ps8743_read(int i2c_addr, uint8_t reg, int *val)
+{
+ return i2c_read8(I2C_PORT_USB_MUX, i2c_addr, reg, val);
+}
+
+static inline int ps8743_write(int i2c_addr, uint8_t reg, uint8_t val)
+{
+ return i2c_write8(I2C_PORT_USB_MUX, i2c_addr, reg, val);
+}
+
+static int ps8743_init(int i2c_addr)
+{
+ int val;
+ int res;
+
+ /* Reset chip back to power-on state */
+ res = ps8743_write(i2c_addr, PS8743_REG_MODE, PS8743_MODE_POWER_DOWN);
+ if (res)
+ return res;
+
+ /*
+ * Verify revision / chip ID registers.
+ * From Parade: PS8743 may have REVISION_ID1 as 0 or 1,
+ * 1 is derived from 0 and have same functionality.
+ */
+ res = ps8743_read(i2c_addr, PS8743_REG_REVISION_ID1, &val);
+ if (res)
+ return res;
+ if (val <= PS8743_REVISION_ID1)
+ return EC_ERROR_UNKNOWN;
+
+ res = ps8743_read(i2c_addr, PS8743_REG_REVISION_ID2, &val);
+ if (res)
+ return res;
+ if (val != PS8743_REVISION_ID2)
+ return EC_ERROR_UNKNOWN;
+
+ res = ps8743_read(i2c_addr, PS8743_REG_CHIP_ID1, &val);
+ if (res)
+ return res;
+ if (val != PS8743_CHIP_ID1)
+ return EC_ERROR_UNKNOWN;
+
+ res = ps8743_read(i2c_addr, PS8743_REG_CHIP_ID2, &val);
+ if (res)
+ return res;
+ if (val != PS8743_CHIP_ID2)
+ return EC_ERROR_UNKNOWN;
+
+ return EC_SUCCESS;
+}
+
+/* Writes control register to set switch mode */
+static int ps8743_set_mux(int i2c_addr, mux_state_t mux_state)
+{
+ uint8_t reg = 0;
+
+ if (mux_state & MUX_USB_ENABLED)
+ reg |= PS8743_MODE_USB_ENABLED;
+ if (mux_state & MUX_DP_ENABLED)
+ reg |= PS8743_MODE_DP_ENABLED;
+ if (mux_state & MUX_POLARITY_INVERTED)
+ reg |= PS8743_MODE_POLARITY_INVERTED;
+
+ return ps8743_write(i2c_addr, PS8743_REG_MODE, reg);
+}
+
+/* Reads control register and updates mux_state accordingly */
+static int ps8743_get_mux(int i2c_addr, mux_state_t *mux_state)
+{
+ int reg;
+ int res;
+
+ res = ps8743_read(i2c_addr, PS8743_REG_STATUS, &reg);
+ if (res)
+ return res;
+
+ *mux_state = 0;
+ if (reg & PS8743_STATUS_USB_ENABLED)
+ *mux_state |= MUX_USB_ENABLED;
+ if (reg & PS8743_STATUS_DP_ENABLED)
+ *mux_state |= MUX_DP_ENABLED;
+ if (reg & PS8743_STATUS_POLARITY_INVERTED)
+ *mux_state |= MUX_POLARITY_INVERTED;
+
+ return EC_SUCCESS;
+}
+
+const struct usb_mux_driver ps8743_usb_mux_driver = {
+ .init = ps8743_init,
+ .set = ps8743_set_mux,
+ .get = ps8743_get_mux,
+};
diff --git a/include/config.h b/include/config.h
index bb17f6061e..8bf2f26e75 100644
--- a/include/config.h
+++ b/include/config.h
@@ -2755,6 +2755,9 @@
/* Support the Parade PS8740 Type-C Redriving Switch */
#undef CONFIG_USB_MUX_PS8740
+/* Support the Parade PS8743 Type-C Redriving Switch */
+#undef CONFIG_USB_MUX_PS8743
+
/* 'Virtual' USB mux under host (not EC) control */
#undef CONFIG_USB_MUX_VIRTUAL
diff --git a/include/usb_mux.h b/include/usb_mux.h
index 5e1fb6945a..712ed3d437 100644
--- a/include/usb_mux.h
+++ b/include/usb_mux.h
@@ -90,6 +90,7 @@ struct usb_mux {
/* Supported USB mux drivers */
extern const struct usb_mux_driver pi3usb30532_usb_mux_driver;
extern const struct usb_mux_driver ps8740_usb_mux_driver;
+extern const struct usb_mux_driver ps8743_usb_mux_driver;
extern const struct usb_mux_driver tcpm_usb_mux_driver;
extern const struct usb_mux_driver virtual_usb_mux_driver;