From 56c941e6c77977d0ecf0ceb5129f8c83f164723f Mon Sep 17 00:00:00 2001 From: Ting Shen Date: Wed, 5 Jan 2022 18:54:21 +0800 Subject: usb_mux: use cached mux state in host cmd EC_CMD_USB_PD_MUX_INFO There's a bug that if AP send EC_CMD_USB_PD_MUX_INFO when mux is in LPM, configure_mux() will wake the mux up and won't put it back to sleep again. This increases the devices power consumption. To fix this, use usb_get_mux instead because it handles LPM correctly. BUG=b:195517210, b:213296482 TEST=1) S3 power improved on Tomato 2) Add debug message in driver code, make sure mux is in sleep state. BRANCH=main Signed-off-by: Ting Shen Change-Id: I232820cbf4715b9c56836306a3e89728b88936e2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3367685 Reviewed-by: Rong Chang Commit-Queue: Ting Shen Tested-by: Ting Shen --- driver/usb_mux/usb_mux.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/driver/usb_mux/usb_mux.c b/driver/usb_mux/usb_mux.c index 4095846c30..58cc91a396 100644 --- a/driver/usb_mux/usb_mux.c +++ b/driver/usb_mux/usb_mux.c @@ -537,23 +537,29 @@ bool usb_mux_set_completed(int port) return !sets_pending; } -mux_state_t usb_mux_get(int port) +static enum ec_error_list try_usb_mux_get(int port, mux_state_t *mux_state) { - mux_state_t mux_state; - int rv; - - if (port >= board_get_usb_pd_port_count()) { - return USB_PD_MUX_NONE; - } + if (port >= board_get_usb_pd_port_count()) + return EC_ERROR_INVAL; /* 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; + if (flags[port] & USB_MUX_FLAG_IN_LPM) { + *mux_state = USB_PD_MUX_NONE; + return EC_SUCCESS; + } - rv = configure_mux(port, USB_MUX_GET_MODE, &mux_state); + return configure_mux(port, USB_MUX_GET_MODE, mux_state); +} + +mux_state_t usb_mux_get(int port) +{ + mux_state_t mux_state; + enum ec_status rv; + + rv = try_usb_mux_get(port, &mux_state); return rv ? USB_PD_MUX_NONE : mux_state; } @@ -725,9 +731,8 @@ static enum ec_status hc_usb_pd_mux_info(struct host_cmd_handler_args *args) if (port >= board_get_usb_pd_port_count()) return EC_RES_INVALID_PARAM; - if (configure_mux(port, USB_MUX_GET_MODE, &mux_state)) + if (try_usb_mux_get(port, &mux_state)) return EC_RES_ERROR; - r->flags = mux_state; /* Clear HPD IRQ event since we're about to inform host of it. */ -- cgit v1.2.1