diff options
author | Patryk Duda <pdk@semihalf.com> | 2021-01-15 12:39:02 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-27 06:53:23 +0000 |
commit | 5c6a14e956a2d66ecfa838ff9d7bc27fc0526b9c (patch) | |
tree | c69e7bb633d0dffa7be348ab657725feb25ecd36 /driver/usb_mux | |
parent | 2b8e109ef452b5419f64262c895816245b3496f4 (diff) | |
download | chrome-ec-5c6a14e956a2d66ecfa838ff9d7bc27fc0526b9c.tar.gz |
usb_mux: Check if muxer is initialized before taking action
Current code allows setting or getting muxer state without initializing
it. During mux initialization driver can prepare some internal
structures for use by other driver functions.
This patch implements checking if there was at least one mux
initialization before performing action.
BUG=b:151155658
BRANCH=none
TEST=Flash ToT EC on octopus (eg. ampton) board. Make sure that muxer
initialization is performed before performing any other muxer
action.
Signed-off-by: Patryk Duda <pdk@semihalf.com>
Change-Id: I2766305a49d377bd9a0ac91eea7988e58eb1059a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2633981
Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'driver/usb_mux')
-rw-r--r-- | driver/usb_mux/usb_mux.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/driver/usb_mux/usb_mux.c b/driver/usb_mux/usb_mux.c index 743b9a6203..884ccdf50a 100644 --- a/driver/usb_mux/usb_mux.c +++ b/driver/usb_mux/usb_mux.c @@ -37,6 +37,9 @@ static uint32_t flags[CONFIG_USB_PD_PORT_MAX_COUNT]; /* The following bit is used to configure virtual mux in disconnect mode */ #define USB_MUX_FLAG_DISCONNECT_LATCH BIT(1) +/* Device initialized at least once */ +#define USB_MUX_FLAG_INIT BIT(2) + enum mux_config_type { USB_MUX_INIT, USB_MUX_LOW_POWER, @@ -178,6 +181,9 @@ void usb_mux_init(int port) rv = configure_mux(port, USB_MUX_INIT, NULL); + if (rv == EC_SUCCESS) + flags[port] |= USB_MUX_FLAG_INIT; + /* * Mux may fail initialization if it's not powered. Mark this port * as in LPM mode to try initialization again. @@ -204,6 +210,10 @@ void usb_mux_set(int port, mux_state_t mux_mode, return; } + /* Perform initialization if not initialized yet */ + if (!(flags[port] & USB_MUX_FLAG_INIT)) + usb_mux_init(port); + /* Configure USB2.0 */ if (IS_ENABLED(CONFIG_USB_CHARGER)) usb_charger_set_switches(port, usb_mode); @@ -248,6 +258,10 @@ mux_state_t usb_mux_get(int port) return USB_PD_MUX_NONE; } + /* Perform initialization if not initialized yet */ + if (!(flags[port] & USB_MUX_FLAG_INIT)) + usb_mux_init(port); + if (flags[port] & USB_MUX_FLAG_IN_LPM) return USB_PD_MUX_NONE; @@ -293,6 +307,10 @@ void usb_mux_flip(int port) return; } + /* Perform initialization if not initialized yet */ + if (!(flags[port] & USB_MUX_FLAG_INIT)) + usb_mux_init(port); + exit_low_power_mode(port); if (configure_mux(port, USB_MUX_GET_MODE, &mux_state)) @@ -315,6 +333,10 @@ void usb_mux_hpd_update(int port, int hpd_lvl, int hpd_irq) return; } + /* Perform initialization if not initialized yet */ + if (!(flags[port] & USB_MUX_FLAG_INIT)) + usb_mux_init(port); + for (; mux_ptr; mux_ptr = mux_ptr->next_mux) if (mux_ptr->hpd_update) mux_ptr->hpd_update(mux_ptr, hpd_lvl, hpd_irq); |