diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2016-06-22 17:55:38 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-06-24 17:23:14 -0700 |
commit | 203063609b52f4125ee91c474cf5f58178572050 (patch) | |
tree | cf8560d8304a59b558efca9eb90649019b7dbba4 /driver | |
parent | 3bc0223b48a73a9fcc70cdbec886f22dd6c35cd3 (diff) | |
download | chrome-ec-203063609b52f4125ee91c474cf5f58178572050.tar.gz |
usb_mux: Add support for host-controlled 'virtual' USB mux
For designs where the host SOC is responsible for setting the USB-C SS
mux, the EC must track the desired mux state and inform the host when
the desired state changes. Then, the host must ask the EC for the new
desired state and set the mux accordingly.
BUG=chrome-os-partner:52639
BRANCH=None
TEST=Manual on gru with subsequent commit.
Attach USB dongle in port 1 and DP dongle in port 0, then verify `ectool
usbpdmuxinfo` output:
Port 0: DP
Port 1: USB
Flip DP dongle and verify output changes:
Port 0: DP INV
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: I6a99ce93a76c3197f9195cfaa25c5217d09aeb75
Reviewed-on: https://chromium-review.googlesource.com/355281
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/build.mk | 1 | ||||
-rw-r--r-- | driver/usb_mux.c | 22 | ||||
-rw-r--r-- | driver/usb_mux_virtual.c | 49 |
3 files changed, 72 insertions, 0 deletions
diff --git a/driver/build.mk b/driver/build.mk index e3d17ecb74..cfa8781fc4 100644 --- a/driver/build.mk +++ b/driver/build.mk @@ -92,6 +92,7 @@ driver-$(CONFIG_USBC_SS_MUX)+=usb_mux.o # USB muxes driver-$(CONFIG_USB_MUX_PI3USB30532)+=usb_mux_pi3usb30532.o driver-$(CONFIG_USB_MUX_PS8740)+=usb_mux_ps8740.o +driver-$(CONFIG_USB_MUX_VIRTUAL)+=usb_mux_virtual.o # Firmware Update driver-$(CONFIG_SB_FIRMWARE_UPDATE)+=battery/sb_fw_update.o diff --git a/driver/usb_mux.c b/driver/usb_mux.c index 619c32ba21..db2a03bdd2 100644 --- a/driver/usb_mux.c +++ b/driver/usb_mux.c @@ -7,6 +7,7 @@ #include "common.h" #include "console.h" +#include "host_command.h" #include "usb_mux.h" #include "util.h" @@ -154,3 +155,24 @@ DECLARE_CONSOLE_COMMAND(typec, command_typec, "Control type-C connector muxing", NULL); #endif + +static int hc_usb_pd_mux_info(struct host_cmd_handler_args *args) +{ + const struct ec_params_usb_pd_mux_info *p = args->params; + struct ec_response_usb_pd_mux_info *r = args->response; + int port = p->port; + const struct usb_mux *mux; + + if (port >= CONFIG_USB_PD_PORT_COUNT) + return EC_RES_INVALID_PARAM; + + mux = &usb_muxes[port]; + if (mux->driver->get(mux->port_addr, &r->flags) != EC_SUCCESS) + return EC_RES_ERROR; + + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_USB_PD_MUX_INFO, + hc_usb_pd_mux_info, + EC_VER_MASK(0)); diff --git a/driver/usb_mux_virtual.c b/driver/usb_mux_virtual.c new file mode 100644 index 0000000000..564bff952b --- /dev/null +++ b/driver/usb_mux_virtual.c @@ -0,0 +1,49 @@ +/* Copyright 2016 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Virtual USB mux driver for host-controlled USB muxes. + */ + +#include "common.h" +#include "console.h" +#include "host_command.h" +#include "usb_mux.h" +#include "util.h" + +static mux_state_t virtual_mux_state[CONFIG_USB_PD_PORT_COUNT]; + +static int virtual_init(int port) +{ + return EC_SUCCESS; +} + +/* + * Set the state of our 'virtual' mux. The EC does not actually control this + * mux, so update the desired state, then notify the host of the update. + */ +static int virtual_set_mux(int port, mux_state_t mux_state) +{ + if (virtual_mux_state[port] != mux_state) { + virtual_mux_state[port] = mux_state; + host_set_single_event(EC_HOST_EVENT_USB_MUX); + } + return EC_SUCCESS; +} + +/* + * Get the state of our 'virtual' mux. Since we the EC does not actually + * control this mux, and the EC has no way of knowing its actual status, + * we return the desired state here. + */ +static int virtual_get_mux(int port, mux_state_t *mux_state) +{ + *mux_state = virtual_mux_state[port]; + return EC_SUCCESS; +} + +const struct usb_mux_driver virtual_usb_mux_driver = { + .init = virtual_init, + .set = virtual_set_mux, + .get = virtual_get_mux, +}; |