summaryrefslogtreecommitdiff
path: root/driver/retimer
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2020-02-14 12:56:04 -0700
committerCommit Bot <commit-bot@chromium.org>2020-02-25 23:03:49 +0000
commit2696c706b8b97f28dfc5448687f168e9225cc61f (patch)
tree839c0c998f507ee2ee0333547b686463f34d61e6 /driver/retimer
parent1707e1ea83a9df8162c18321fc5a529d38f58870 (diff)
downloadchrome-ec-2696c706b8b97f28dfc5448687f168e9225cc61f.tar.gz
TUSB544: Add driver
Driver code for the TUSB544 redriver BRANCH=None BUG=b:149561847 TEST=builds Change-Id: I391d6d264ff9d326c2d45569124dd1366f892812 Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2062766 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/retimer')
-rw-r--r--driver/retimer/tusb544.c93
-rw-r--r--driver/retimer/tusb544.h49
2 files changed, 142 insertions, 0 deletions
diff --git a/driver/retimer/tusb544.c b/driver/retimer/tusb544.c
new file mode 100644
index 0000000000..3d8cb9119e
--- /dev/null
+++ b/driver/retimer/tusb544.c
@@ -0,0 +1,93 @@
+/* Copyright 2020 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.
+ *
+ * TI TUSB544 USB Type-C Multi-Protocol Linear Redriver
+ */
+#include "i2c.h"
+#include "tusb544.h"
+#include "usb_mux.h"
+
+static int tusb544_write(int port, int offset, int data)
+{
+ return i2c_write8(usb_retimers[port].i2c_port,
+ usb_retimers[port].i2c_addr_flags,
+ offset, data);
+}
+
+static int tusb544_read(int port, int offset, int *data)
+{
+ return i2c_read8(usb_retimers[port].i2c_port,
+ usb_retimers[port].i2c_addr_flags,
+ offset, data);
+}
+
+static int tusb544_enter_low_power_mode(int port)
+{
+ int reg;
+ int rv;
+
+ rv = tusb544_read(port, TUSB544_REG_GENERAL4, &reg);
+ if (rv)
+ return rv;
+
+ /* Setting CTL_SEL[0,1] to 0 powers down, per Table 5 */
+ reg &= ~TUSB544_GEN4_CTL_SEL;
+
+ return tusb544_write(port, TUSB544_REG_GENERAL4, reg);
+}
+
+static int tusb544_init(int port)
+{
+ return EC_SUCCESS;
+}
+
+static int tusb544_set_mux(int port, mux_state_t mux_state)
+{
+ int reg;
+ int rv;
+
+ if (mux_state == USB_PD_MUX_NONE)
+ return tusb544_enter_low_power_mode(port);
+
+ rv = tusb544_read(port, TUSB544_REG_GENERAL4, &reg);
+ if (rv)
+ return rv;
+
+ if (mux_state & USB_PD_MUX_POLARITY_INVERTED)
+ reg |= TUSB544_GEN4_FLIP_SEL;
+ else
+ reg &= ~TUSB544_GEN4_FLIP_SEL;
+
+ reg &= ~TUSB544_GEN4_CTL_SEL;
+
+ if ((mux_state & USB_PD_MUX_USB_ENABLED) &&
+ (mux_state & USB_PD_MUX_DP_ENABLED))
+ reg |= TUSB544_CTL_SEL_DP_USB;
+ else if (mux_state & USB_PD_MUX_DP_ENABLED)
+ reg |= TUSB544_CTL_SEL_DP_ONLY;
+ else if (mux_state & USB_PD_MUX_USB_ENABLED)
+ reg |= TUSB544_CTL_SEL_USB_ONLY;
+
+ rv = tusb544_write(port, TUSB544_REG_GENERAL4, reg);
+ if (rv)
+ return rv;
+
+ rv = tusb544_read(port, TUSB544_REG_GENERAL6, &reg);
+ if (rv)
+ return rv;
+
+ reg &= ~TUSB544_GEN6_DIR_SEL;
+ if (pd_get_power_role(port) == PD_ROLE_SOURCE)
+ reg |= TUSB544_DIR_SEL_USB_DP_SRC;
+ else
+ reg |= TUSB544_DIR_SEL_USB_DP_SNK;
+
+ return tusb544_write(port, TUSB544_REG_GENERAL6, reg);
+}
+
+const struct usb_retimer_driver tusb544_usb_redriver_drv = {
+ .enter_low_power_mode = &tusb544_enter_low_power_mode,
+ .init = &tusb544_init,
+ .set = &tusb544_set_mux,
+};
diff --git a/driver/retimer/tusb544.h b/driver/retimer/tusb544.h
new file mode 100644
index 0000000000..7a1b0a82cd
--- /dev/null
+++ b/driver/retimer/tusb544.h
@@ -0,0 +1,49 @@
+/* Copyright 2020 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.
+ *
+ * TI TUSB544 USB Type-C Multi-Protocol Linear Redriver
+ */
+
+#ifndef __CROS_EC_USB_REDRIVER_TUSB544_H
+#define __CROS_EC_USB_REDRIVER_TUSB544_H
+
+#define TUSB544_ADDR_FLAGS0 0x44
+
+#define TUSB544_REG_GENERAL4 0x0A
+#define TUSB544_GEN4_CTL_SEL GENMASK(1, 0)
+#define TUSB544_GEN4_FLIP_SEL BIT(2)
+#define TUSB544_GEN4_HPDIN BIT(3)
+#define TUSB544_GEN4_EQ_OVRD BIT(4)
+#define TUSB544_GEN4_SWAP_SEL BIT(5)
+
+enum tusb544_ct_sel {
+ TUSB544_CTL_SEL_DISABLED,
+ TUSB544_CTL_SEL_USB_ONLY,
+ TUSB544_CTL_SEL_DP_ONLY,
+ TUSB544_CTL_SEL_DP_USB,
+};
+
+#define TUSB544_REG_GENERAL6 0x0C
+#define TUSB544_GEN6_DIR_SEL GENMASK(1, 0)
+
+enum tusb544_dir_sel {
+ TUSB544_DIR_SEL_USB_DP_SRC,
+ TUSB544_DIR_SEL_USB_DP_SNK,
+ TUSB544_DIR_SEL_CUSTOM_SRC,
+ TUSB544_DIS_SEL_CUSTOM_SNK,
+};
+
+/*
+ * Note: TUSB544 automatically snoops DP lanes to enable, but may be manually
+ * directed which lanes to turn on when snoop is disabled
+ */
+#define TUSB544_REG_DP4 0x13
+#define TUSB544_DP4_DP0_DISABLE BIT(0)
+#define TUSB544_DP4_DP1_DISABLE BIT(1)
+#define TUSB544_DP4_DP2_DISABLE BIT(2)
+#define TUSB544_DP4_DP3_DISABLE BIT(3)
+#define TUSB544_DP4_AUX_SBU_OVR GENMASK(5, 4)
+#define TUSB544_DP4_AUX_SNOOP_DISABLE BIT(7)
+
+#endif