summaryrefslogtreecommitdiff
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
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>
-rw-r--r--baseboard/honeybuns/baseboard.c9
-rw-r--r--baseboard/honeybuns/baseboard.h17
-rw-r--r--baseboard/honeybuns/usbc_support.c47
-rw-r--r--board/baklava/board.c45
-rw-r--r--board/baklava/board.h1
-rw-r--r--board/quiche/board.c44
-rw-r--r--board/quiche/board.h1
7 files changed, 79 insertions, 85 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
+
diff --git a/board/baklava/board.c b/board/baklava/board.c
index 158fefc416..11f80dbf81 100644
--- a/board/baklava/board.c
+++ b/board/baklava/board.c
@@ -60,23 +60,9 @@ void hpd_interrupt(enum gpio_signal signal)
usb_pd_hpd_edge_event(signal);
}
-void board_uf_manage_vbus(void)
-{
- int level = gpio_get_level(GPIO_USBC_UF_MUX_VBUS_EN);
-
- /*
- * GPIO_USBC_UF_MUX_VBUS_EN is an output from the PS8803 which tracks if
- * C1 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("C1: State = %s", level ? "Attached.SRC " : "Unattached.SRC");
-}
-DECLARE_DEFERRED(board_uf_manage_vbus);
-
static void board_uf_manage_vbus_interrupt(enum gpio_signal signal)
{
- hook_call_deferred(&board_uf_manage_vbus_data, 0);
+ baseboard_usb3_check_state();
}
static void board_pwr_btn_interrupt(enum gpio_signal signal)
@@ -238,30 +224,6 @@ enum pd_dual_role_states board_tc_get_initial_drp_mode(int port)
return pd_dual_role_init[port];
}
-static void board_config_usbc_uf_ppc(void)
-{
- int vbus_level;
-
- /*
- * This port is not usb-pd capable, but there is a ppc which must be
- * initialized, and keep the VBUS switch enabled.
- */
- ppc_init(USB_PD_PORT_USB3);
- vbus_level = gpio_get_level(GPIO_USBC_UF_MUX_VBUS_EN);
-
- CPRINTS("usbc: UF PPC configured. VBUS = %s",
- vbus_level ? "on" : "off");
-
- /*
- * Check initial state as there there may not be an edge event after
- * interrupts are enabled if the port is attached at EC reboot time.
- */
- ppc_vbus_source_enable(USB_PD_PORT_USB3, vbus_level);
-
- /* Enable VBUS control interrupt for C1 */
- gpio_enable_interrupt(GPIO_USBC_UF_MUX_VBUS_EN);
-}
-
__override uint8_t board_get_usb_pd_port_count(void)
{
/*
@@ -298,10 +260,7 @@ int dock_get_mf_preference(void)
static void board_init(void)
{
-#ifdef SECTION_IS_RW
- /* Initialize PPC and check usbc state */
- board_config_usbc_uf_ppc();
-#endif
+
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
diff --git a/board/baklava/board.h b/board/baklava/board.h
index 8e4d4d5036..1736b688d9 100644
--- a/board/baklava/board.h
+++ b/board/baklava/board.h
@@ -46,6 +46,7 @@
#include "registers.h"
#define GPIO_DP_HPD GPIO_DDI_MST_IN_HPD
+#define GPIO_USBC_UF_ATTACHED_SRC GPIO_USBC_UF_MUX_VBUS_EN
#define GPIO_TRIGGER_1 GPIO_TP41
#define GPIO_TRIGGER_2 GPIO_TP73
diff --git a/board/quiche/board.c b/board/quiche/board.c
index 1a3e6f058b..429c2257e9 100644
--- a/board/quiche/board.c
+++ b/board/quiche/board.c
@@ -80,23 +80,9 @@ void hpd_interrupt(enum gpio_signal signal)
usb_pd_hpd_edge_event(signal);
}
-void board_uf_manage_vbus(void)
-{
- int level = gpio_get_level(GPIO_USBC_UF_MUX_VBUS_EN);
-
- /*
- * 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(board_uf_manage_vbus);
-
static void board_uf_manage_vbus_interrupt(enum gpio_signal signal)
{
- hook_call_deferred(&board_uf_manage_vbus_data, 0);
+ baseboard_usb3_check_state();
}
static void board_pwr_btn_interrupt(enum gpio_signal signal)
@@ -289,30 +275,6 @@ enum pd_dual_role_states board_tc_get_initial_drp_mode(int port)
return pd_dual_role_init[port];
}
-static void board_config_usbc_uf_ppc(void)
-{
- int vbus_level;
-
- /*
- * This port is not usb-pd capable, but there is a ppc which must be
- * initialized, and keep the VBUS switch enabled.
- */
- ppc_init(USB_PD_PORT_USB3);
- vbus_level = gpio_get_level(GPIO_USBC_UF_MUX_VBUS_EN);
-
- CPRINTS("usbc: UF PPC configured. VBUS = %s",
- vbus_level ? "on" : "off");
-
- /*
- * Check initial state as there there may not be an edge event after
- * interrupts are enabled if the port is attached at EC reboot time.
- */
- ppc_vbus_source_enable(USB_PD_PORT_USB3, vbus_level);
-
- /* Enable VBUS control interrupt for C2 */
- gpio_enable_interrupt(GPIO_USBC_UF_MUX_VBUS_EN);
-}
-
__override uint8_t board_get_usb_pd_port_count(void)
{
/*
@@ -371,9 +333,7 @@ int dock_get_mf_preference(void)
static void board_init(void)
{
-#ifdef SECTION_IS_RW
- board_config_usbc_uf_ppc();
-#endif
+
}
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
diff --git a/board/quiche/board.h b/board/quiche/board.h
index ad9d57d271..70ed82474c 100644
--- a/board/quiche/board.h
+++ b/board/quiche/board.h
@@ -48,6 +48,7 @@
#include "registers.h"
#define GPIO_DP_HPD GPIO_DDI_MST_IN_HPD
+#define GPIO_USBC_UF_ATTACHED_SRC GPIO_USBC_UF_MUX_VBUS_EN
#define GPIO_TRIGGER_1 GPIO_TP41
#define GPIO_TRIGGER_2 GPIO_TP73