From 8f9fd8def52833ae6b74d5ac4f97ed8b41060f6a Mon Sep 17 00:00:00 2001 From: Scott Collyer Date: Wed, 17 Nov 2021 11:44:43 -0800 Subject: usb_mux: tusb1064: Add method to set DP Rx EQ gain This CL adds a method to set DP Rx EQ gain. The previous version of the driver was enabling a 10 dB gain by default in the init function. This CL removes setting both gain and EQ_OVERRIDE by default. A separate CL in the stack moves the 10dB gain setting to the board.c file for the only other board that currently is using the TUSB1064. BUG=b:206059703 BRANCH=quiche TEST=Verified on gingerbread that both EQ_OVERRIDE is set and the gain is set in both registers as expected. Signed-off-by: Scott Collyer Change-Id: Id2dc6127d27304d8149f7c51a8d527e046595baf Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3291129 Tested-by: Scott Collyer Reviewed-by: Diana Z Commit-Queue: Scott Collyer --- driver/usb_mux/tusb1064.c | 65 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 21 deletions(-) (limited to 'driver/usb_mux/tusb1064.c') diff --git a/driver/usb_mux/tusb1064.c b/driver/usb_mux/tusb1064.c index c236e3d1ab..6a82aca68f 100644 --- a/driver/usb_mux/tusb1064.c +++ b/driver/usb_mux/tusb1064.c @@ -14,12 +14,6 @@ #error "Must choose CONFIG_USB_MUX_TUSB1044 or CONFIG_USB_MUX_TUSB1064" #endif -/* - * configuration bits which never change in the General Register - * e.g. REG_GENERAL_DP_EN_CTRL or REG_GENERAL_EQ_OVERRIDE - */ -#define REG_GENERAL_STATIC_BITS REG_GENERAL_EQ_OVERRIDE - static int tusb1064_read(const struct usb_mux *me, uint8_t reg, uint8_t *val) { int buffer = 0xee; @@ -60,11 +54,54 @@ void tusb1044_hpd_update(const struct usb_mux *me, mux_state_t mux_state) } #endif +int tusb1064_set_dp_rx_eq(const struct usb_mux *me, int db) +{ + uint8_t reg; + int rv; + + if (db < TUSB1064_DP_EQ_RX_NEG_0_3_DB || db > TUSB1064_DP_EQ_RX_12_1_DB) + return EC_ERROR_INVAL; + + /* Set the requested gain values */ + reg = TUSB1064_DP1EQ(db) | TUSB1064_DP3EQ(db); + rv = tusb1064_write(me, TUSB1064_REG_DP1DP3EQ_SEL, reg); + if (rv) + return rv; + + reg = TUSB1064_DP0EQ(db) | TUSB1064_DP2EQ(db); + rv = tusb1064_write(me, TUSB1064_REG_DP0DP2EQ_SEL, reg); + if (rv) + return rv; + + /* Enable EQ_OVERRIDE so the gain registers are used */ + rv = tusb1064_read(me, TUSB1064_REG_GENERAL, ®); + if (rv) + return rv; + + reg |= REG_GENERAL_EQ_OVERRIDE; + + return tusb1064_write(me, TUSB1064_REG_GENERAL, reg); +} + /* Writes control register to set switch mode */ static int tusb1064_set_mux(const struct usb_mux *me, mux_state_t mux_state, bool *ack_required) { - int reg = REG_GENERAL_STATIC_BITS; + uint8_t reg; + int rv; + int mask; + + rv = tusb1064_read(me, TUSB1064_REG_GENERAL, ®); + if (rv) + return rv; + + /* Mask bits that may be set in this function */ + mask = REG_GENERAL_CTLSEL_USB3 | REG_GENERAL_CTLSEL_ANYDP | + REG_GENERAL_FLIPSEL; +#ifdef CONFIG_USB_MUX_TUSB1044 + mask |= REG_GENERAL_HPDIN_OVERRIDE; +#endif + reg &= ~mask; /* This driver does not use host command ACKs */ *ack_required = false; @@ -112,22 +149,8 @@ static int tusb1064_get_mux(const struct usb_mux *me, mux_state_t *mux_state) static int tusb1064_init(const struct usb_mux *me) { int res; - uint8_t reg; bool unused; - /* Default to "Floating Pin" DP Equalization */ - reg = TUSB1064_DP1EQ(TUSB1064_DP_EQ_RX_10_0_DB) | - TUSB1064_DP3EQ(TUSB1064_DP_EQ_RX_10_0_DB); - res = tusb1064_write(me, TUSB1064_REG_DP1DP3EQ_SEL, reg); - if (res) - return res; - - reg = TUSB1064_DP0EQ(TUSB1064_DP_EQ_RX_10_0_DB) | - TUSB1064_DP2EQ(TUSB1064_DP_EQ_RX_10_0_DB); - res = tusb1064_write(me, TUSB1064_REG_DP0DP2EQ_SEL, reg); - if (res) - return res; - /* * Note that bypassing the usb_mux API is okay for internal driver calls * since the task calling init already holds this port's mux lock. -- cgit v1.2.1 From 18f6c4d3b2a56635ce880788047083115637885c Mon Sep 17 00:00:00 2001 From: Diana Z Date: Mon, 18 Oct 2021 15:27:01 -0600 Subject: USB MUX: Wait on ACK for HPD changes when required In order to correctly sequence HPD sets with the AP, allow the HPD set to wait on an ACK from the AP before proceeding. BRANCH=None BUG=b:202137658 TEST=on brya, validate retimer and virtual mux are kept in sync as expected Signed-off-by: Diana Z Change-Id: I368c3290b69d627829a70847876d7b47a8c36948 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3232293 Reviewed-by: Abe Levkoy --- driver/usb_mux/tusb1064.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'driver/usb_mux/tusb1064.c') diff --git a/driver/usb_mux/tusb1064.c b/driver/usb_mux/tusb1064.c index 6a82aca68f..d0e8678039 100644 --- a/driver/usb_mux/tusb1064.c +++ b/driver/usb_mux/tusb1064.c @@ -30,11 +30,15 @@ static int tusb1064_write(const struct usb_mux *me, uint8_t reg, uint8_t val) } #if defined(CONFIG_USB_MUX_TUSB1044) -void tusb1044_hpd_update(const struct usb_mux *me, mux_state_t mux_state) +void tusb1044_hpd_update(const struct usb_mux *me, mux_state_t mux_state, + bool *ack_required) { int res; uint8_t reg; + /* This driver does not use host command ACKs */ + *ack_required = false; + res = tusb1064_read(me, TUSB1064_REG_GENERAL, ®); if (res) return; -- cgit v1.2.1