summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-11-14 14:13:29 -0700
committerCommit Bot <commit-bot@chromium.org>2019-11-21 23:20:55 +0000
commit154f597b8656fbcc16f6652f6fe8713943440939 (patch)
tree3ce5425b230126405511741d1d01e609d9e8188c
parent14e356b73ee9c40170c8c0042dd452ba83b5ead9 (diff)
downloadchrome-ec-154f597b8656fbcc16f6652f6fe8713943440939.tar.gz
usbc: add enter_low_power_mode for retimer mux
BUG=b:139428185 BRANCH=none TEST=verify mode is set correctly when switching devices Change-Id: I3e40e0321cb1026180b7edc0bfe99439c13acafb Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1922062
-rw-r--r--driver/retimer/pi3dpx1207.c34
-rw-r--r--driver/usb_mux/usb_mux.c25
-rw-r--r--include/usb_mux.h9
3 files changed, 62 insertions, 6 deletions
diff --git a/driver/retimer/pi3dpx1207.c b/driver/retimer/pi3dpx1207.c
index f1f1e19b54..8d57dcb6ef 100644
--- a/driver/retimer/pi3dpx1207.c
+++ b/driver/retimer/pi3dpx1207.c
@@ -18,6 +18,9 @@
/* Stack space is limited, so put the buffer somewhere else */
static uint8_t buf[PI3DPX1207_NUM_REGISTERS];
+/**
+ * Local utility functions
+ */
static int pi3dpx1207_i2c_write(int i2c_port,
uint16_t addr_flags,
uint8_t offset,
@@ -60,6 +63,32 @@ static int pi3dpx1207_i2c_write(int i2c_port,
return rv;
}
+static void pi3dpx1207_shutoff_power(int port)
+{
+ const int gpio_enable = usb_retimers[port].gpio_enable;
+ const int gpio_dp_enable = usb_retimers[port].gpio_dp_enable;
+
+ gpio_or_ioex_set_level(gpio_enable, 0);
+ gpio_or_ioex_set_level(gpio_dp_enable, 0);
+}
+
+/**
+ * Driver interface code
+ */
+static int pi3dpx1207_init(int port)
+{
+ const int gpio_enable = usb_retimers[port].gpio_enable;
+
+ gpio_or_ioex_set_level(gpio_enable, 1);
+ return EC_SUCCESS;
+}
+
+static int pi3dpx1207_enter_low_power_mode(int port)
+{
+ pi3dpx1207_shutoff_power(port);
+ return EC_SUCCESS;
+}
+
static int pi3dpx1207_set_mux(int port, mux_state_t mux_state)
{
int rv = EC_SUCCESS;
@@ -98,8 +127,7 @@ static int pi3dpx1207_set_mux(int port, mux_state_t mux_state)
}
/* Nothing enabled, power down the retimer */
else {
- gpio_or_ioex_set_level(gpio_enable, 0);
- gpio_or_ioex_set_level(gpio_dp_enable, 0);
+ pi3dpx1207_shutoff_power(port);
return EC_SUCCESS;
}
@@ -111,5 +139,7 @@ static int pi3dpx1207_set_mux(int port, mux_state_t mux_state)
}
const struct usb_retimer_driver pi3dpx1207_usb_retimer = {
+ .init = pi3dpx1207_init,
.set = pi3dpx1207_set_mux,
+ .enter_low_power_mode = pi3dpx1207_enter_low_power_mode,
};
diff --git a/driver/usb_mux/usb_mux.c b/driver/usb_mux/usb_mux.c
index be150c8741..0a33aef948 100644
--- a/driver/usb_mux/usb_mux.c
+++ b/driver/usb_mux/usb_mux.c
@@ -41,10 +41,24 @@ static void enter_low_power_mode(int port)
/* Apply any low power customization if present */
if (mux->driver->enter_low_power_mode) {
res = mux->driver->enter_low_power_mode(port);
+ if (res) {
+ CPRINTS("Err: %s mux port(%d): %d",
+ __func__, port, res);
+ return;
+ }
+ }
- if (res)
- CPRINTS("Err: enter_low_power_mode mux port(%d): %d",
- port, res);
+ if (IS_ENABLED(CONFIG_USBC_MUX_RETIMER)) {
+ const struct usb_retimer *retimer = &usb_retimers[port];
+
+ if (retimer->driver && retimer->driver->enter_low_power_mode) {
+ res = retimer->driver->enter_low_power_mode(port);
+ if (res) {
+ CPRINTS("Err: %s retimer port(%d): %d",
+ __func__, port, res);
+ return;
+ }
+ }
}
}
@@ -121,7 +135,10 @@ void usb_mux_set(int port, enum typec_mux mux_mode,
exit_low_power_mode(port);
/* Configure superspeed lanes */
- mux_state = polarity ? mux_mode | MUX_POLARITY_INVERTED : mux_mode;
+ mux_state = ((mux_mode != TYPEC_MUX_NONE) && polarity)
+ ? mux_mode | MUX_POLARITY_INVERTED
+ : mux_mode;
+
res = mux->driver->set(port, mux_state);
if (res) {
CPRINTS("Err: set mux port(%d): %d", port, res);
diff --git a/include/usb_mux.h b/include/usb_mux.h
index 126e7da4fa..0a5a19a338 100644
--- a/include/usb_mux.h
+++ b/include/usb_mux.h
@@ -156,6 +156,15 @@ struct usb_retimer_driver {
int (*init)(int port);
/**
+ * Put USB retimer in low power mode. This is called when the MUX
+ * is put into low power mode).
+ *
+ * @param port usb port of redriver (not port_addr)
+ * @return EC_SUCCESS on success, non-zero error code on failure.
+ */
+ int (*enter_low_power_mode)(int port);
+
+ /**
* Set USB retimer state.
*
* @param port usb port of retimer (not port_addr)