diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2015-06-23 17:52:00 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-06-30 17:18:37 +0000 |
commit | 1ef8c7dc2096405e815797fd06dec628a39b4e33 (patch) | |
tree | 8c45cc6b372317d6b66dbdc11bc883802e208521 /board/honeybuns | |
parent | 4114b7f1fe2274c0d1321cba8182ade8180599d9 (diff) | |
download | chrome-ec-1ef8c7dc2096405e815797fd06dec628a39b4e33.tar.gz |
usb_mux: Add driver interface for USB-C muxes
In preparation for adding support for additional USB-C mux chips, add a
new high-level USB-C mux interface usb_mux.c. usb_mux functions are now
called from pd code instead of board-level functions. usb_mux calls down
into a mux chip-specific driver (currently pi3usb30532) or
board-specific drivers which toggle GPIOs (for legacy boards).
BUG=chrome-os-partner:41696
TEST=Manual on Glados in subsequent commit. Verify set() and get()
functions set and return consistent values. Verify that USB SS device
functions when muxes are set to dock or USB. Also, verify that DP
dongle and USB SS device are functional on both PD ports on samus_pd.
BRANCH=None
Change-Id: Ib6477f489310f3be1430585ea09fea26f57e3752
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/281435
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'board/honeybuns')
-rw-r--r-- | board/honeybuns/board.c | 57 | ||||
-rw-r--r-- | board/honeybuns/build.mk | 2 | ||||
-rw-r--r-- | board/honeybuns/usb_mux.c | 84 | ||||
-rw-r--r-- | board/honeybuns/usb_pd_policy.c | 3 |
4 files changed, 87 insertions, 59 deletions
diff --git a/board/honeybuns/board.c b/board/honeybuns/board.c index bdcedf5599..b16b9b6ed3 100644 --- a/board/honeybuns/board.c +++ b/board/honeybuns/board.c @@ -164,62 +164,6 @@ const void * const usb_strings[] = { }; BUILD_ASSERT(ARRAY_SIZE(usb_strings) == USB_STR_COUNT); -void board_set_usb_mux(int port, enum typec_mux mux, - enum usb_switch usb, int polarity) -{ - if (mux == TYPEC_MUX_NONE) { - /* put the mux in the high impedance state */ - gpio_set_level(GPIO_SS_MUX_OE_L, 1); - /* Disable display hardware */ - gpio_set_level(GPIO_BRIDGE_RESET_L, 0); - gpio_set_level(GPIO_SPLITTER_RESET_L, 0); - /* Put the USB hub under reset */ - hx3_enable(0); - return; - } - - /* Trigger USB Hub configuration */ - hx3_enable(1); - - if ((mux == TYPEC_MUX_DOCK) || (mux == TYPEC_MUX_USB)) { - /* Low selects USB Dock */ - gpio_set_level(GPIO_SS_MUX_SEL, 0); - } else if (mux == TYPEC_MUX_DP) { - /* high selects display port */ - gpio_set_level(GPIO_SS_MUX_SEL, 1); - } - - /* clear OE line to make mux active */ - gpio_set_level(GPIO_SS_MUX_OE_L, 0); - - if (mux != TYPEC_MUX_USB) { - /* Enable display hardware */ - gpio_set_level(GPIO_BRIDGE_RESET_L, 1); - gpio_set_level(GPIO_SPLITTER_RESET_L, 1); - } -} - -int board_get_usb_mux(int port, const char **dp_str, const char **usb_str) -{ - int oe_disabled = gpio_get_level(GPIO_SS_MUX_OE_L); - int dp_4lanes = gpio_get_level(GPIO_SS_MUX_SEL); - - if (oe_disabled) { - *usb_str = NULL; - *dp_str = NULL; - return 0; - } - - if (dp_4lanes) { - *dp_str = "DP_4LANE"; - *usb_str = NULL; - } else { - *dp_str = "DP_2LANE"; - *usb_str = "DOCK"; - } - return 1; -} - /** * USB configuration * Any type-C device with alternate mode capabilities must have the following @@ -279,4 +223,3 @@ const struct bos_context bos_ctx = { .descp = (void *)&bos_desc, .size = sizeof(struct my_bos), }; - diff --git a/board/honeybuns/build.mk b/board/honeybuns/build.mk index ff4b39a2ce..84b222d16a 100644 --- a/board/honeybuns/build.mk +++ b/board/honeybuns/build.mk @@ -11,4 +11,4 @@ CHIP_FAMILY:=stm32f0 CHIP_VARIANT:=stm32f07x board-y=board.o hx3.o -board-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o +board-$(CONFIG_USB_POWER_DELIVERY)+=usb_mux.o usb_pd_policy.o diff --git a/board/honeybuns/usb_mux.c b/board/honeybuns/usb_mux.c new file mode 100644 index 0000000000..ea8a56910f --- /dev/null +++ b/board/honeybuns/usb_mux.c @@ -0,0 +1,84 @@ +/* Copyright 2015 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. + */ + +/* Honeybuns-custom USB mux driver. */ + +#include "common.h" +#include "gpio.h" +#include "usb_mux.h" +#include "util.h" + +void board_set_usb_switches(int port, enum usb_switch setting) +{ + /* Not implemented */ +} + +static int board_init_usb_mux(int port) +{ + return EC_SUCCESS; +} + +static int board_set_usb_mux(int port, mux_state_t mux_state) +{ + if (!(mux_state & (MUX_USB_ENABLED | MUX_DP_ENABLED))) { + /* put the mux in the high impedance state */ + gpio_set_level(GPIO_SS_MUX_OE_L, 1); + /* Disable display hardware */ + gpio_set_level(GPIO_BRIDGE_RESET_L, 0); + gpio_set_level(GPIO_SPLITTER_RESET_L, 0); + /* Put the USB hub under reset */ + hx3_enable(0); + return EC_SUCCESS; + } + + /* Trigger USB Hub configuration */ + hx3_enable(1); + + if (mux_state & MUX_USB_ENABLED) + /* Low selects USB Dock */ + gpio_set_level(GPIO_SS_MUX_SEL, 0); + else + /* high selects display port */ + gpio_set_level(GPIO_SS_MUX_SEL, 1); + + /* clear OE line to make mux active */ + gpio_set_level(GPIO_SS_MUX_OE_L, 0); + + if (mux_state & MUX_DP_ENABLED) { + /* Enable display hardware */ + gpio_set_level(GPIO_BRIDGE_RESET_L, 1); + gpio_set_level(GPIO_SPLITTER_RESET_L, 1); + } + + return EC_SUCCESS; +} + +static int board_get_usb_mux(int port, mux_state_t *mux_state) +{ + int oe_disabled = gpio_get_level(GPIO_SS_MUX_OE_L); + int dp_4lanes = gpio_get_level(GPIO_SS_MUX_SEL); + + if (oe_disabled) + *mux_state = 0; + else if (dp_4lanes) + *mux_state = MUX_DP_ENABLED; + else + *mux_state = MUX_USB_ENABLED | MUX_DP_ENABLED; + + return EC_SUCCESS; +} + +const struct usb_mux_driver board_custom_usb_mux_driver = { + .init = board_init_usb_mux, + .set = board_set_usb_mux, + .get = board_get_usb_mux, +}; + +struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = { + { + .port_addr = 0, + .driver = &board_custom_usb_mux_driver, + }, +}; diff --git a/board/honeybuns/usb_pd_policy.c b/board/honeybuns/usb_pd_policy.c index 6f2f33505d..65c056f102 100644 --- a/board/honeybuns/usb_pd_policy.c +++ b/board/honeybuns/usb_pd_policy.c @@ -15,6 +15,7 @@ #include "timer.h" #include "util.h" #include "usb.h" +#include "usb_mux.h" #include "usb_pd.h" @@ -253,7 +254,7 @@ static int dp_config(int port, uint32_t *payload) if (PD_DP_CFG_DPON(payload[1])) gpio_set_level(GPIO_PD_SBU_ENABLE, 1); /* Get the DP lanes (or DP+USB SS depending on the mode) */ - board_set_usb_mux(port, mux, USB_SWITCH_CONNECT, pd_get_polarity(port)); + usb_mux_set(port, mux, USB_SWITCH_CONNECT, pd_get_polarity(port)); return 1; } |