summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaveh Jalali <caveh@chromium.org>2021-06-10 01:30:39 -0700
committerCommit Bot <commit-bot@chromium.org>2021-06-16 05:48:46 +0000
commitadb8ca2325f4768251d3e6584ecd7b3841419571 (patch)
treeb5533968c336841fc7f08436e70c8fdb1dac17b7
parent65fb698e83dda45b1f5c657053ea6224a0275303 (diff)
downloadchrome-ec-stabilize-14031.B-main.tar.gz
usb_mux: Avoid accessing unavailable muxesstabilize-14031.B-main
This adds additional checks to avoid mux device accesses when the generic mux driver knows that the device has not been initialized or is in low power mode. This avoids spurious I2C transaction failures when attempting to access unavailable devices. BRANCH=none BUG=none TEST=observed "C0: Retimer I2C write err=1" messages are gone Signed-off-by: Caveh Jalali <caveh@chromium.org> Change-Id: I762a878f2cab91ca98fd7a602e0b20be8b85ccd8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2955610 Reviewed-by: Diana Z <dzigterman@chromium.org>
-rw-r--r--driver/usb_mux/usb_mux.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/driver/usb_mux/usb_mux.c b/driver/usb_mux/usb_mux.c
index c50189bb40..ad347c284f 100644
--- a/driver/usb_mux/usb_mux.c
+++ b/driver/usb_mux/usb_mux.c
@@ -164,11 +164,23 @@ static void enter_low_power_mode(int port)
configure_mux(port, USB_MUX_LOW_POWER, NULL);
}
-static inline void exit_low_power_mode(int port)
+static int exit_low_power_mode(int port)
{
/* If we are in low power, initialize device (which clears LPM flag) */
if (flags[port] & USB_MUX_FLAG_IN_LPM)
usb_mux_init(port);
+
+ if (!(flags[port] & USB_MUX_FLAG_INIT)) {
+ CPRINTS("C%d: USB_MUX_FLAG_INIT not set", port);
+ return EC_ERROR_UNKNOWN;
+ }
+
+ if (flags[port] & USB_MUX_FLAG_IN_LPM) {
+ CPRINTS("C%d: USB_MUX_FLAG_IN_LPM not cleared", port);
+ return EC_ERROR_NOT_POWERED;
+ }
+
+ return EC_SUCCESS;
}
void usb_mux_init(int port)
@@ -228,7 +240,8 @@ void usb_mux_set(int port, mux_state_t mux_mode,
if (should_enter_low_power_mode && (flags[port] & USB_MUX_FLAG_IN_LPM))
return;
- exit_low_power_mode(port);
+ if (exit_low_power_mode(port) != EC_SUCCESS)
+ return;
/* Configure superspeed lanes */
mux_state = ((mux_mode != USB_PD_MUX_NONE) && polarity)
@@ -313,7 +326,8 @@ void usb_mux_flip(int port)
if (!(flags[port] & USB_MUX_FLAG_INIT))
usb_mux_init(port);
- exit_low_power_mode(port);
+ if (exit_low_power_mode(port) != EC_SUCCESS)
+ return;
if (configure_mux(port, USB_MUX_GET_MODE, &mux_state))
return;
@@ -339,6 +353,9 @@ void usb_mux_hpd_update(int port, int hpd_lvl, int hpd_irq)
if (!(flags[port] & USB_MUX_FLAG_INIT))
usb_mux_init(port);
+ if (exit_low_power_mode(port) != EC_SUCCESS)
+ return;
+
for (; mux_ptr; mux_ptr = mux_ptr->next_mux)
if (mux_ptr->hpd_update)
mux_ptr->hpd_update(mux_ptr, hpd_lvl, hpd_irq);