summaryrefslogtreecommitdiff
path: root/driver/retimer/nb7v904m.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 /driver/retimer/nb7v904m.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 'driver/retimer/nb7v904m.c')
-rw-r--r--driver/retimer/nb7v904m.c53
1 files changed, 27 insertions, 26 deletions
diff --git a/driver/retimer/nb7v904m.c b/driver/retimer/nb7v904m.c
index 81fd5abc93..e1cedede95 100644
--- a/driver/retimer/nb7v904m.c
+++ b/driver/retimer/nb7v904m.c
@@ -15,28 +15,28 @@
#define CPRINTS(format, args...) cprints(CC_USB, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USB, format, ## args)
-static int nb7v904m_write(int port, int offset, int data)
+static int nb7v904m_write(const struct usb_mux *me, int offset, int data)
{
- return i2c_write8(usb_retimers[port].i2c_port,
- usb_retimers[port].i2c_addr_flags,
+ return i2c_write8(me->i2c_port,
+ me->i2c_addr_flags,
offset, data);
}
-static int nb7v904m_read(int port, int offset, int *regval)
+static int nb7v904m_read(const struct usb_mux *me, int offset, int *regval)
{
- return i2c_read8(usb_retimers[port].i2c_port,
- usb_retimers[port].i2c_addr_flags,
+ return i2c_read8(me->i2c_port,
+ me->i2c_addr_flags,
offset, regval);
}
-static int set_low_power_mode(int port, bool enable)
+static int set_low_power_mode(const struct usb_mux *me, bool enable)
{
int regval;
int rv;
- rv = nb7v904m_read(port, NB7V904M_REG_GEN_DEV_SETTINGS, &regval);
+ rv = nb7v904m_read(me, NB7V904M_REG_GEN_DEV_SETTINGS, &regval);
if (rv)
return rv;
@@ -45,28 +45,29 @@ static int set_low_power_mode(int port, bool enable)
else
regval &= ~NB7V904M_CHIP_EN;
- return nb7v904m_write(port, NB7V904M_REG_GEN_DEV_SETTINGS, regval);
+ return nb7v904m_write(me, NB7V904M_REG_GEN_DEV_SETTINGS, regval);
}
-static int nb7v904m_enter_low_power_mode(int port)
+static int nb7v904m_enter_low_power_mode(const struct usb_mux *me)
{
- int rv = set_low_power_mode(port, 1);
+ int rv = set_low_power_mode(me, 1);
if (rv)
- CPRINTS("C%d: NB7V904M: Failed to enter low power mode!", port);
+ CPRINTS("C%d: NB7V904M: Failed to enter low power mode!",
+ me->usb_port);
return rv;
}
-static int nb7v904m_init(int port)
+static int nb7v904m_init(const struct usb_mux *me)
{
- int rv = set_low_power_mode(port, 0);
+ int rv = set_low_power_mode(me, 0);
if (rv)
- CPRINTS("C%d: NB7V904M: init failed!", port);
+ CPRINTS("C%d: NB7V904M: init failed!", me->usb_port);
return rv;
}
-static int nb7v904m_set_mux(int port, mux_state_t mux_state)
+static int nb7v904m_set_mux(const struct usb_mux *me, mux_state_t mux_state)
{
int rv = EC_SUCCESS;
int regval;
@@ -74,17 +75,17 @@ static int nb7v904m_set_mux(int port, mux_state_t mux_state)
/* Turn off redriver if it's not needed at all. */
if (mux_state == USB_PD_MUX_NONE)
- return nb7v904m_enter_low_power_mode(port);
+ return nb7v904m_enter_low_power_mode(me);
- rv = nb7v904m_init(port);
+ rv = nb7v904m_init(me);
if (rv)
return rv;
/* Clear operation mode field */
- rv = nb7v904m_read(port, NB7V904M_REG_GEN_DEV_SETTINGS, &regval);
+ rv = nb7v904m_read(me, NB7V904M_REG_GEN_DEV_SETTINGS, &regval);
if (rv) {
- CPRINTS("C%d %s: Failed to obtain dev settings!", port,
- __func__);
+ CPRINTS("C%d %s: Failed to obtain dev settings!",
+ me->usb_port, __func__);
return rv;
}
regval &= ~NB7V904M_OP_MODE_MASK;
@@ -108,14 +109,14 @@ static int nb7v904m_set_mux(int port, mux_state_t mux_state)
if (mux_state & USB_PD_MUX_DP_ENABLED) {
/* Connect AUX */
- rv = nb7v904m_write(port, NB7V904M_REG_AUX_CH_CTRL, flipped ?
+ rv = nb7v904m_write(me, NB7V904M_REG_AUX_CH_CTRL, flipped ?
NB7V904M_AUX_CH_FLIPPED :
NB7V904M_AUX_CH_NORMAL);
/* Enable all channels for DP */
regval |= NB7V904M_CH_EN_MASK;
} else {
/* Disconnect AUX since it's not being used. */
- rv = nb7v904m_write(port, NB7V904M_REG_AUX_CH_CTRL,
+ rv = nb7v904m_write(me, NB7V904M_REG_AUX_CH_CTRL,
NB7V904M_AUX_CH_HI_Z);
/* Disable the unused channels to save power */
@@ -129,14 +130,14 @@ static int nb7v904m_set_mux(int port, mux_state_t mux_state)
}
}
- rv |= nb7v904m_write(port, NB7V904M_REG_GEN_DEV_SETTINGS, regval);
+ rv |= nb7v904m_write(me, NB7V904M_REG_GEN_DEV_SETTINGS, regval);
if (rv)
- CPRINTS("C%d: %s failed!", port, __func__);
+ CPRINTS("C%d: %s failed!", me->usb_port, __func__);
return rv;
}
-const struct usb_retimer_driver nb7v904m_usb_redriver_drv = {
+const struct usb_mux_driver nb7v904m_usb_redriver_drv = {
.enter_low_power_mode = &nb7v904m_enter_low_power_mode,
.init = &nb7v904m_init,
.set = &nb7v904m_set_mux,