summaryrefslogtreecommitdiff
path: root/baseboard/zork/baseboard.c
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2020-02-21 14:21:05 -0700
committerCommit Bot <commit-bot@chromium.org>2020-02-28 22:47:11 +0000
commit9c194fd057558a1dfadee419e92aca31953a86fc (patch)
tree001ae7c162a4152312a180574ae58e19a3763eb8 /baseboard/zork/baseboard.c
parentab35b456ad8c52f336ea793b17155cfc796c4e44 (diff)
downloadchrome-ec-9c194fd057558a1dfadee419e92aca31953a86fc.tar.gz
usb_mux: retimer: mux as chained mux and retimer
This makes retimers appear as generic muxes. By allowing a chain of muxes they can be stacked up to the new configurations that zork requires and will continue to work as they did before on configurations that only have a single mux. The code used to have two different arrays, 1) muxes and 2) retimers. On one of the zork configurations the processor MUX stopped being the primary mux and the retimer took its place. In a different configuration of that same platform it left the primary and secondary alone but the mux_set FLIP operation had to be ignored. Since the same interfaces needed to be available for both it stopped making sense to have two different structures and two different methods of handling them. This consolodates the two into one. The platforms that do not have retimers, this change will not make any difference. For platforms like zork, it will remove the retimers and make them chained muxes. So testing on trembyle makes sense to verify, BUG=b:147593660 BRANCH=none TEST=verify USB still works on trembyle Change-Id: I286cf1e302f9bd3dd7e81098ec08514a2a009fe3 Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2066794 Commit-Queue: Jett Rink <jettrink@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'baseboard/zork/baseboard.c')
-rw-r--r--baseboard/zork/baseboard.c175
1 files changed, 107 insertions, 68 deletions
diff --git a/baseboard/zork/baseboard.c b/baseboard/zork/baseboard.c
index f64a911f94..69a61681ff 100644
--- a/baseboard/zork/baseboard.c
+++ b/baseboard/zork/baseboard.c
@@ -23,7 +23,6 @@
#include "driver/retimer/pi3dpx1207.h"
#include "driver/retimer/ps8802.h"
#include "driver/retimer/ps8818.h"
-#include "driver/tcpm/ps8xxx.h"
#include "driver/tcpm/nct38xx.h"
#include "driver/temp_sensor/sb_tsi.h"
#include "driver/usb_mux/amd_fp5.h"
@@ -440,19 +439,19 @@ void bc12_interrupt(enum gpio_signal signal)
* PS8802 set mux tuning.
* Adds in board specific gain and DP lane count configuration
*/
-static int ps8802_tune_mux(int port, mux_state_t mux_state)
+static int ps8802_mux_set(const struct usb_mux *me, mux_state_t mux_state)
{
int rv = EC_SUCCESS;
/* Make sure the PS8802 is awake */
- rv = ps8802_i2c_wake(port);
+ rv = ps8802_i2c_wake(me);
if (rv)
return rv;
/* USB specific config */
if (mux_state & USB_PD_MUX_USB_ENABLED) {
/* Boost the USB gain */
- rv = ps8802_i2c_field_update16(port,
+ rv = ps8802_i2c_field_update16(me,
PS8802_REG_PAGE2,
PS8802_REG2_USB_SSEQ_LEVEL,
PS8802_USBEQ_LEVEL_UP_MASK,
@@ -464,7 +463,7 @@ static int ps8802_tune_mux(int port, mux_state_t mux_state)
/* DP specific config */
if (mux_state & USB_PD_MUX_DP_ENABLED) {
/* Boost the DP gain */
- rv = ps8802_i2c_field_update8(port,
+ rv = ps8802_i2c_field_update8(me,
PS8802_REG_PAGE2,
PS8802_REG2_DPEQ_LEVEL,
PS8802_DPEQ_LEVEL_UP_MASK,
@@ -486,14 +485,14 @@ static int ps8802_tune_mux(int port, mux_state_t mux_state)
* PS8818 set mux tuning.
* Adds in board specific gain and DP lane count configuration
*/
-static int ps8818_tune_mux(int port, mux_state_t mux_state)
+static int ps8818_mux_set(const struct usb_mux *me, mux_state_t mux_state)
{
int rv = EC_SUCCESS;
/* USB specific config */
if (mux_state & USB_PD_MUX_USB_ENABLED) {
/* Boost the USB gain */
- rv = ps8818_i2c_field_update8(port,
+ rv = ps8818_i2c_field_update8(me,
PS8818_REG_PAGE1,
PS8818_REG1_APTX1EQ_10G_LEVEL,
PS8818_EQ_LEVEL_UP_MASK,
@@ -501,7 +500,7 @@ static int ps8818_tune_mux(int port, mux_state_t mux_state)
if (rv)
return rv;
- rv = ps8818_i2c_field_update8(port,
+ rv = ps8818_i2c_field_update8(me,
PS8818_REG_PAGE1,
PS8818_REG1_APTX2EQ_10G_LEVEL,
PS8818_EQ_LEVEL_UP_MASK,
@@ -509,7 +508,7 @@ static int ps8818_tune_mux(int port, mux_state_t mux_state)
if (rv)
return rv;
- rv = ps8818_i2c_field_update8(port,
+ rv = ps8818_i2c_field_update8(me,
PS8818_REG_PAGE1,
PS8818_REG1_APTX1EQ_5G_LEVEL,
PS8818_EQ_LEVEL_UP_MASK,
@@ -517,7 +516,7 @@ static int ps8818_tune_mux(int port, mux_state_t mux_state)
if (rv)
return rv;
- rv = ps8818_i2c_field_update8(port,
+ rv = ps8818_i2c_field_update8(me,
PS8818_REG_PAGE1,
PS8818_REG1_APTX2EQ_5G_LEVEL,
PS8818_EQ_LEVEL_UP_MASK,
@@ -529,7 +528,7 @@ static int ps8818_tune_mux(int port, mux_state_t mux_state)
/* DP specific config */
if (mux_state & USB_PD_MUX_DP_ENABLED) {
/* Boost the DP gain */
- rv = ps8818_i2c_field_update8(port,
+ rv = ps8818_i2c_field_update8(me,
PS8818_REG_PAGE1,
PS8818_REG1_DPEQ_LEVEL,
PS8818_DPEQ_LEVEL_UP_MASK,
@@ -548,47 +547,15 @@ static int ps8818_tune_mux(int port, mux_state_t mux_state)
}
/*
- * FP5 is a true MUX but being used as a secondary MUX. Don't want to
- * send FLIP or this will cause a double flip
- */
-static int zork_c1_retimer_set_mux(int port, mux_state_t mux_state)
-{
- return amd_fp5_usb_retimer.set(port,
- mux_state & ~USB_PD_MUX_POLARITY_INVERTED);
-}
-
-const struct usb_retimer_driver zork_c1_usb_retimer = {
- /* Secondary MUX/Retimer only needs the set mux interface */
- .set = zork_c1_retimer_set_mux,
-};
-
-struct usb_retimer usb_retimers[] = {
- [USBC_PORT_C0] = {
- .driver = &pi3dpx1207_usb_retimer,
- .i2c_port = I2C_PORT_TCPC0,
- .i2c_addr_flags = PI3DPX1207_I2C_ADDR_FLAGS,
- },
- [USBC_PORT_C1] = {
- /*
- * The driver is left off until we detect the
- * hardware present. Once the hardware has been
- * detected, the driver will be set to the
- * detected hardware driver table.
- */
- .i2c_port = I2C_PORT_TCPC1,
- },
-};
-BUILD_ASSERT(ARRAY_SIZE(usb_retimers) == USBC_PORT_COUNT);
-
-/*
* To support both OPT1 DB with PS8818 retimer, and OPT3 DB with PS8802
* retimer, Try both, and remember the first one that succeeds.
- *
- * TODO(b:147593660) Cleanup of retimers as muxes in a more
- * generalized mechanism
*/
+const struct usb_mux usbc1_ps8802;
+const struct usb_mux usbc1_ps8818;
+struct usb_mux usbc1_amd_fp5_usb_mux;
+
enum zork_c1_retimer zork_c1_retimer = C1_RETIMER_UNKNOWN;
-static int zork_c1_detect(int port, int err_if_power_off)
+static int zork_c1_detect(const struct usb_mux *me, int err_if_power_off)
{
int rv;
@@ -604,29 +571,30 @@ static int zork_c1_detect(int port, int err_if_power_off)
* Identifying a PS8818 is faster than the PS8802,
* so do it first.
*/
- usb_retimers[port].i2c_addr_flags = PS8818_I2C_ADDR_FLAGS;
- rv = ps8818_detect(port);
+ rv = ps8818_detect(&usbc1_ps8818);
if (rv == EC_SUCCESS) {
zork_c1_retimer = C1_RETIMER_PS8818;
ccprints("C1 PS8818 detected");
/* Main MUX is FP5, secondary MUX is PS8818 */
- usb_muxes[USBC_PORT_C1].driver = &amd_fp5_usb_mux_driver;
- usb_retimers[USBC_PORT_C1].driver = &ps8818_usb_retimer;
- usb_retimers[USBC_PORT_C1].tune = &ps8818_tune_mux;
+ memcpy(&usb_muxes[USBC_PORT_C1],
+ &usbc1_amd_fp5_usb_mux,
+ sizeof(struct usb_mux));
+ usb_muxes[USBC_PORT_C1].next_mux = &usbc1_ps8818;
return rv;
}
- usb_retimers[port].i2c_addr_flags = PS8802_I2C_ADDR_FLAGS;
- rv = ps8802_detect(port);
+ rv = ps8802_detect(&usbc1_ps8802);
if (rv == EC_SUCCESS) {
zork_c1_retimer = C1_RETIMER_PS8802;
ccprints("C1 PS8802 detected");
/* Main MUX is PS8802, secondary MUX is modified FP5 */
- usb_muxes[USBC_PORT_C1].driver = &ps8802_usb_mux_driver;
- usb_retimers[USBC_PORT_C1].driver = &zork_c1_usb_retimer;
- usb_retimers[USBC_PORT_C1].tune = &ps8802_tune_mux;
+ memcpy(&usb_muxes[USBC_PORT_C1],
+ &usbc1_ps8802,
+ sizeof(struct usb_mux));
+ usb_muxes[USBC_PORT_C1].next_mux = &usbc1_amd_fp5_usb_mux;
+ usbc1_amd_fp5_usb_mux.flags = USB_MUX_FLAG_SET_WITHOUT_FLIP;
}
return rv;
@@ -637,14 +605,36 @@ static int zork_c1_detect(int port, int err_if_power_off)
* the interface to be this special primary MUX driver in order to
* determine the actual hardware and then we patch the jump tables
* to go to the actual drivers instead.
+ *
+ * "me" will always point to usb_muxes[0]. If detection is made
+ * on the real device, then detect will change the tables so the
+ * content of me is the real driver configuration and will setup
+ * next_mux appropriately. So all we have to do on detection is
+ * perform the actual call for this entry and then let the generic
+ * chain traverse mechanism in usb_mux.c do any following calls.
*/
-static int zork_c1_init_mux(int port)
+static int zork_c1_init_mux(const struct usb_mux *me)
{
+ int rv;
+
/* Try to detect, but don't give an error if no power */
- return zork_c1_detect(port, 0);
+ rv = zork_c1_detect(me, 0);
+ if (rv)
+ return rv;
+
+ /*
+ * If we detected the hardware, then call the real routine.
+ * We only do this one time, after that time we will go direct
+ * and avoid this special driver.
+ */
+ if (zork_c1_retimer != C1_RETIMER_UNKNOWN)
+ if (me->driver && me->driver->init)
+ rv = me->driver->init(me);
+
+ return rv;
}
-static int zork_c1_set_mux(int port, mux_state_t mux_state)
+static int zork_c1_set_mux(const struct usb_mux *me, mux_state_t mux_state)
{
int rv;
@@ -652,7 +642,7 @@ static int zork_c1_set_mux(int port, mux_state_t mux_state)
* Try to detect, give an error if we are setting to a
* MUX value that is not NONE when we have no power.
*/
- rv = zork_c1_detect(port, mux_state != USB_PD_MUX_NONE);
+ rv = zork_c1_detect(me, mux_state != USB_PD_MUX_NONE);
if (rv)
return rv;
@@ -661,18 +651,35 @@ static int zork_c1_set_mux(int port, mux_state_t mux_state)
* We only do this one time, after that time we will go direct
* and avoid this special driver.
*/
- if (zork_c1_retimer != C1_RETIMER_UNKNOWN)
- rv = usb_muxes[port].driver->set(port, mux_state);
+ if (zork_c1_retimer != C1_RETIMER_UNKNOWN) {
+ const struct usb_mux_driver *drv = me->driver;
+
+ if (drv && drv->set) {
+ mux_state_t state = mux_state;
+
+ if (me->flags & USB_MUX_FLAG_SET_WITHOUT_FLIP)
+ state &= ~USB_PD_MUX_POLARITY_INVERTED;
+
+ /* Apply Driver generic settings */
+ rv = drv->set(me, state);
+ if (rv)
+ return rv;
+
+ /* Apply Board specific settings */
+ if (me->board_set)
+ rv = me->board_set(me, state);
+ }
+ }
return rv;
}
-static int zork_c1_get_mux(int port, mux_state_t *mux_state)
+static int zork_c1_get_mux(const struct usb_mux *me, mux_state_t *mux_state)
{
int rv;
/* Try to detect the hardware */
- rv = zork_c1_detect(port, 1);
+ rv = zork_c1_detect(me, 1);
if (rv) {
/*
* Not powered is MUX_NONE, so change the values
@@ -691,7 +698,8 @@ static int zork_c1_get_mux(int port, mux_state_t *mux_state)
* and avoid this special driver.
*/
if (zork_c1_retimer != C1_RETIMER_UNKNOWN)
- rv = usb_muxes[port].driver->get(port, mux_state);
+ if (me->driver && me->driver->get)
+ rv = me->driver->get(me, mux_state);
return rv;
}
@@ -714,9 +722,37 @@ const struct usb_mux_driver zork_c1_usb_mux_driver = {
.get = zork_c1_get_mux,
};
+const struct usb_mux usbc0_pi3dpx1207_usb_retimer = {
+ .usb_port = USBC_PORT_C0,
+ .i2c_port = I2C_PORT_TCPC0,
+ .i2c_addr_flags = PI3DPX1207_I2C_ADDR_FLAGS,
+ .driver = &pi3dpx1207_usb_retimer,
+};
+
+const struct usb_mux usbc1_ps8802 = {
+ .usb_port = USBC_PORT_C1,
+ .i2c_port = I2C_PORT_TCPC1,
+ .i2c_addr_flags = PS8802_I2C_ADDR_FLAGS,
+ .driver = &ps8802_usb_mux_driver,
+ .board_set = &ps8802_mux_set,
+};
+const struct usb_mux usbc1_ps8818 = {
+ .usb_port = USBC_PORT_C1,
+ .i2c_port = I2C_PORT_TCPC1,
+ .i2c_addr_flags = PS8818_I2C_ADDR_FLAGS,
+ .driver = &ps8818_usb_retimer_driver,
+ .board_set = &ps8818_mux_set,
+};
+struct usb_mux usbc1_amd_fp5_usb_mux = {
+ .usb_port = USBC_PORT_C1,
+ .driver = &amd_fp5_usb_mux_driver,
+};
+
struct usb_mux usb_muxes[] = {
[USBC_PORT_C0] = {
+ .usb_port = USBC_PORT_C0,
.driver = &amd_fp5_usb_mux_driver,
+ .next_mux = &usbc0_pi3dpx1207_usb_retimer,
},
[USBC_PORT_C1] = {
/*
@@ -724,11 +760,14 @@ struct usb_mux usb_muxes[] = {
* has been detected, the driver will change to the
* detected hardware driver table.
*/
+ .usb_port = USBC_PORT_C1,
+ .i2c_port = I2C_PORT_TCPC1,
.driver = &zork_c1_usb_mux_driver,
- },
+ }
};
BUILD_ASSERT(ARRAY_SIZE(usb_muxes) == USBC_PORT_COUNT);
+
struct ioexpander_config_t ioex_config[] = {
[USBC_PORT_C0] = {
.i2c_host_port = I2C_PORT_TCPC0,