From fba31a3ae244b6dfd18e4b59508aa45387161d81 Mon Sep 17 00:00:00 2001 From: Scott Collyer Date: Wed, 24 Mar 2021 13:09:09 -0700 Subject: honeybuns: Add C2 initialization with power button on/off This CL refactors code required for the user facing usbc port. This port was only being initialized at init time and therefore would not function properly following a power button off/on. To avoid duplicating code, the functions used to initialize this port and control VBUS were moved to usbc_support in baseboard so they can be common and are now guarded by a GPIO macro so this can be board specific for variants which don't have a PPC to control on this port. BUG=b:164157329 BRANCH=quiche TEST=Verifed that port C2 attaches as expected following power button off/on sequence. Signed-off-by: Scott Collyer Change-Id: I2f9500f7e58de674c6f7c12a95cebad45de166cc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2785198 Reviewed-by: Diana Z Commit-Queue: Scott Collyer Tested-by: Scott Collyer --- baseboard/honeybuns/baseboard.c | 9 ++++++++ baseboard/honeybuns/baseboard.h | 17 ++++++++++++++ baseboard/honeybuns/usbc_support.c | 47 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+) (limited to 'baseboard/honeybuns') diff --git a/baseboard/honeybuns/baseboard.c b/baseboard/honeybuns/baseboard.c index 3425417b81..394a0bae28 100644 --- a/baseboard/honeybuns/baseboard.c +++ b/baseboard/honeybuns/baseboard.c @@ -200,6 +200,11 @@ static void baseboard_init(void) baseboard_set_mst_lane_control(dock_mf); } +#ifdef GPIO_USBC_UF_ATTACHED_SRC + /* Configure UF usbc ppc and check usbc state */ + baseboard_config_usbc_usb3_ppc(); +#endif /* GPIO_USBC_UF_ATTACHED_SRC */ + /* Enable power button interrupt */ gpio_enable_interrupt(GPIO_PWR_BTN); /* Set dock mf preference LED */ @@ -248,6 +253,10 @@ static void baseboard_power_on(void) } /* Enable usbc interrupts */ board_enable_usbc_interrupts(); + +#ifdef GPIO_USBC_UF_ATTACHED_SRC + baseboard_config_usbc_usb3_ppc(); +#endif } static void baseboard_power_off(void) diff --git a/baseboard/honeybuns/baseboard.h b/baseboard/honeybuns/baseboard.h index a8b8e9e902..01b0e4e686 100644 --- a/baseboard/honeybuns/baseboard.h +++ b/baseboard/honeybuns/baseboard.h @@ -234,6 +234,7 @@ enum adc_channel { extern const struct power_seq board_power_seq[]; extern const size_t board_power_seq_count; + void baseboard_power_button_evt(int level); /* @@ -252,6 +253,22 @@ int baseboard_usbc_init(int port); */ int dock_get_mf_preference(void); +/* + * Initialize and configure PPC used for USB3 only port + * + * @return EC success if PPC initialization is successful + */ +int baseboard_config_usbc_usb3_ppc(void); + +/* + * Called from interrupt handler for PS8803 attached.src gpio. This gpio signal + * will be set high by the PS8803 when it's in the attached.src state and low + * otherwise. For boards wich have a PPC on this port, this signal is used to + * enable/disable VBUS in the PPC. + */ +void baseboard_usb3_check_state(void); + + /* * Set MST_LANE_CONTROL gpio to match the DP pin configuration selected * by the host in the DP Configure SVDM message. diff --git a/baseboard/honeybuns/usbc_support.c b/baseboard/honeybuns/usbc_support.c index baa22a65dc..1ca7be6fe3 100644 --- a/baseboard/honeybuns/usbc_support.c +++ b/baseboard/honeybuns/usbc_support.c @@ -20,6 +20,8 @@ #include "registers.h" #include "ucpd-stm32gx.h" +#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args) +#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args) static void baseboard_ucpd_apply_rd(int port) { @@ -135,3 +137,48 @@ int baseboard_usbc_init(int port) return rv; } +#if defined(GPIO_USBC_UF_ATTACHED_SRC) && defined(SECTION_IS_RW) +static void baseboard_usb3_manage_vbus(void) +{ + int level = gpio_get_level(GPIO_USBC_UF_ATTACHED_SRC); + + /* + * GPIO_USBC_UF_MUX_VBUS_EN is an output from the PS8803 which tracks if + * C2 is attached. When it's attached, this signal will be high. Use + * this level to control PPC VBUS on/off. + */ + ppc_vbus_source_enable(USB_PD_PORT_USB3, level); + CPRINTS("C2: State = %s", level ? "Attached.SRC " : "Unattached.SRC"); +} +DECLARE_DEFERRED(baseboard_usb3_manage_vbus); + +void baseboard_usb3_check_state(void) +{ + hook_call_deferred(&baseboard_usb3_manage_vbus_data, 0); +} + +int baseboard_config_usbc_usb3_ppc(void) +{ + int rv; + + /* + * This port is not usb-pd capable, but there is a ppc which must be + * initialized, and keep the VBUS switch enabled. + */ + rv = ppc_init(USB_PD_PORT_USB3); + if (rv) + return rv; + + /* Need to set current limit to 3A to match advertised value */ + ppc_set_vbus_source_current_limit(USB_PD_PORT_USB3, TYPEC_RP_3A0); + + /* Check state at init time */ + baseboard_usb3_manage_vbus(); + + /* Enable VBUS control interrupt for C2 */ + gpio_enable_interrupt(GPIO_USBC_UF_ATTACHED_SRC); + + return EC_SUCCESS; +} +#endif + -- cgit v1.2.1