summaryrefslogtreecommitdiff
path: root/baseboard/honeybuns
diff options
context:
space:
mode:
authorScott Collyer <scollyer@google.com>2021-03-24 13:09:09 -0700
committerCommit Bot <commit-bot@chromium.org>2021-04-17 22:05:23 +0000
commitfba31a3ae244b6dfd18e4b59508aa45387161d81 (patch)
tree907e84f3517aa617a5eadfdbc9871268aad112f4 /baseboard/honeybuns
parentc01b28e5da86b783917523beaa97b1b81d38019c (diff)
downloadchrome-ec-fba31a3ae244b6dfd18e4b59508aa45387161d81.tar.gz
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 <scollyer@google.com> Change-Id: I2f9500f7e58de674c6f7c12a95cebad45de166cc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2785198 Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org>
Diffstat (limited to 'baseboard/honeybuns')
-rw-r--r--baseboard/honeybuns/baseboard.c9
-rw-r--r--baseboard/honeybuns/baseboard.h17
-rw-r--r--baseboard/honeybuns/usbc_support.c47
3 files changed, 73 insertions, 0 deletions
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);
/*
@@ -253,6 +254,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
+