From 0349a5b6d95308141754523708a2d11d8bacce4c Mon Sep 17 00:00:00 2001 From: Scott Collyer Date: Wed, 17 Nov 2021 13:24:36 -0800 Subject: honeybuns: Add board level USB_PD_CONNECT hooks This CL moves the board specific parts of USB_PD_CONNECT hook to board.c file as there are different GPIOs that must be changed between quiche/gingerbread. For Gingerbread, the USB Hubs are held in reset until there is a usbc attach event. quiche/baklava don't require USB hub resets to be controlled, but do have a separate GPIO indicator the MST hub. BUG=b:206059703 BRANCH=quiche TEST=verified GPIO signal levels for signals affected by this CL on quiche and gingerbread. Signed-off-by: Scott Collyer Change-Id: I88ef6ddfe5026fc75384507920368681d28a21f9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3291133 Commit-Queue: Scott Collyer Tested-by: Scott Collyer Reviewed-by: Aseda Aboagye --- baseboard/honeybuns/usb_pd_policy.c | 18 +++++------------- board/baklava/board.c | 25 +++++++++++++++++++++++++ board/gingerbread/board.c | 28 ++++++++++++++++++++++++++++ board/quiche/board.c | 24 ++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 13 deletions(-) diff --git a/baseboard/honeybuns/usb_pd_policy.c b/baseboard/honeybuns/usb_pd_policy.c index ef2350a03d..faaef9083f 100644 --- a/baseboard/honeybuns/usb_pd_policy.c +++ b/baseboard/honeybuns/usb_pd_policy.c @@ -369,20 +369,16 @@ static void usb_tc_connect(void) { int port = TASK_ID_TO_PD_PORT(task_get_current()); + /* Clear data role swap attempt counter at each usbc attach */ + pd_dr_swap_attempt_count[port] = 0; + /* * The EC needs to indicate to the USB hub when the host port is * attached so that the USB-EP can be properly enumerated. GPIO_BPWR_DET * is used for this purpose. */ - if (port == USB_PD_PORT_HOST) { + if (port == USB_PD_PORT_HOST) gpio_set_level(GPIO_BPWR_DET, 1); -#ifdef GPIO_UFP_PLUG_DET - gpio_set_level(GPIO_UFP_PLUG_DET, 0); -#endif - } - - /* Clear data role swap attempt counter at each usbc attach */ - pd_dr_swap_attempt_count[port] = 0; } DECLARE_HOOK(HOOK_USB_PD_CONNECT, usb_tc_connect, HOOK_PRIO_DEFAULT); @@ -391,12 +387,8 @@ static void usb_tc_disconnect(void) int port = TASK_ID_TO_PD_PORT(task_get_current()); /* Only the host port disconnect is relevant */ - if (port == USB_PD_PORT_HOST) { + if (port == USB_PD_PORT_HOST) gpio_set_level(GPIO_BPWR_DET, 0); -#ifdef GPIO_UFP_PLUG_DET - gpio_set_level(GPIO_UFP_PLUG_DET, 1); -#endif - } } DECLARE_HOOK(HOOK_USB_PD_DISCONNECT, usb_tc_disconnect, HOOK_PRIO_DEFAULT); diff --git a/board/baklava/board.c b/board/baklava/board.c index 35a27d0c21..12365e0ff6 100644 --- a/board/baklava/board.c +++ b/board/baklava/board.c @@ -262,6 +262,31 @@ int dock_get_mf_preference(void) { return MF_ON; } + +static void board_usb_tc_connect(void) +{ + int port = TASK_ID_TO_PD_PORT(task_get_current()); + + /* + * The EC needs to indicate to the MST hub when the host port is + * attached. GPIO_UFP_PLUG_DET is used for this purpose. + */ + if (port == USB_PD_PORT_HOST) + gpio_set_level(GPIO_UFP_PLUG_DET, 0); +} +DECLARE_HOOK(HOOK_USB_PD_CONNECT, board_usb_tc_connect, HOOK_PRIO_DEFAULT); + +static void board_usb_tc_disconnect(void) +{ + int port = TASK_ID_TO_PD_PORT(task_get_current()); + + /* Only the host port disconnect is relevant */ + if (port == USB_PD_PORT_HOST) + gpio_set_level(GPIO_UFP_PLUG_DET, 1); +} +DECLARE_HOOK(HOOK_USB_PD_DISCONNECT, board_usb_tc_disconnect, \ + HOOK_PRIO_DEFAULT); + #endif /* SECTION_IS_RW */ static void board_init(void) diff --git a/board/gingerbread/board.c b/board/gingerbread/board.c index ce7a18ee4f..4c4911dbf2 100644 --- a/board/gingerbread/board.c +++ b/board/gingerbread/board.c @@ -326,6 +326,34 @@ int dock_get_mf_preference(void) return mf; } +static void board_usb_tc_connect(void) +{ + int port = TASK_ID_TO_PD_PORT(task_get_current()); + + /* + * The EC needs to keep the USB hubs in reset until the host port is + * attached so that the USB-EP can be properly enumerated. + */ + if (port == USB_PD_PORT_HOST) { + gpio_set_level(GPIO_EC_HUB1_RESET_L, 1); + gpio_set_level(GPIO_EC_HUB2_RESET_L, 1); + } +} +DECLARE_HOOK(HOOK_USB_PD_CONNECT, board_usb_tc_connect, HOOK_PRIO_DEFAULT); + +static void board_usb_tc_disconnect(void) +{ + int port = TASK_ID_TO_PD_PORT(task_get_current()); + + /* Only the host port disconnect is relevant */ + if (port == USB_PD_PORT_HOST) { + gpio_set_level(GPIO_EC_HUB1_RESET_L, 0); + gpio_set_level(GPIO_EC_HUB2_RESET_L, 0); + } +} +DECLARE_HOOK(HOOK_USB_PD_DISCONNECT, board_usb_tc_disconnect, \ + HOOK_PRIO_DEFAULT); + #endif /* SECTION_IS_RW */ static void board_init(void) diff --git a/board/quiche/board.c b/board/quiche/board.c index e49b2e1b1a..76004ee37e 100644 --- a/board/quiche/board.c +++ b/board/quiche/board.c @@ -345,6 +345,30 @@ int dock_get_mf_preference(void) return mf; } +static void board_usb_tc_connect(void) +{ + int port = TASK_ID_TO_PD_PORT(task_get_current()); + + /* + * The EC needs to indicate to the MST hub when the host port is + * attached. GPIO_UFP_PLUG_DET is used for this purpose. + */ + if (port == USB_PD_PORT_HOST) + gpio_set_level(GPIO_UFP_PLUG_DET, 0); +} +DECLARE_HOOK(HOOK_USB_PD_CONNECT, board_usb_tc_connect, HOOK_PRIO_DEFAULT); + +static void board_usb_tc_disconnect(void) +{ + int port = TASK_ID_TO_PD_PORT(task_get_current()); + + /* Only the host port disconnect is relevant */ + if (port == USB_PD_PORT_HOST) + gpio_set_level(GPIO_UFP_PLUG_DET, 1); +} +DECLARE_HOOK(HOOK_USB_PD_DISCONNECT, board_usb_tc_disconnect, \ + HOOK_PRIO_DEFAULT); + #endif /* SECTION_IS_RW */ static void board_init(void) -- cgit v1.2.1