summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHank Xie <hank.xie@quanta.corp-partner.google.com>2022-06-08 03:36:54 -0400
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-08-08 06:19:09 +0000
commit9fc4b345d7067d795cd7ba6b420335862e43f3cd (patch)
tree0438d53c30b20659b1fc995c2157ca856e57aaf6
parent972d9480597de29e5783518fb012d1580cfe8721 (diff)
downloadchrome-ec-9fc4b345d7067d795cd7ba6b420335862e43f3cd.tar.gz
shotzo: Configure barrel jack adapter
There is a barrel jack adapter added to shotzo. Add features to bring up from barrel jack adapter as below: 1.Detecting barrel jack adapter plug in/out. 2.Identify barrel jack as power source. 3.Make function extpower_is_present() in dedede base board overridable, because we need to add barrel jack adapter as one of conditions. BUG=b:234665044 BRANCH=none TEST=plug barrel jack adapter and check shotzo works fine. Signed-off-by: Hank Xie <hank.xie@quanta.corp-partner.google.com> Change-Id: I8a84b852215996de8d805c8f6a7029ad770c1c90 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3688158 Reviewed-by: Zhuohao Lee <zhuohao@chromium.org>
-rw-r--r--baseboard/dedede/baseboard.c2
-rw-r--r--board/shotzo/board.c156
-rw-r--r--board/shotzo/board.h13
-rw-r--r--board/shotzo/gpio.inc6
-rw-r--r--board/shotzo/usb_pd_policy.c8
5 files changed, 169 insertions, 16 deletions
diff --git a/baseboard/dedede/baseboard.c b/baseboard/dedede/baseboard.c
index 5e3d5baf8a..98eba13f9f 100644
--- a/baseboard/dedede/baseboard.c
+++ b/baseboard/dedede/baseboard.c
@@ -294,7 +294,7 @@ int board_is_i2c_port_powered(int port)
return chipset_in_state(CHIPSET_STATE_ANY_OFF) ? 0 : 1;
}
-int extpower_is_present(void)
+__overridable int extpower_is_present(void)
{
int port;
int rv;
diff --git a/board/shotzo/board.c b/board/shotzo/board.c
index 23a732b1b6..b5c2821c52 100644
--- a/board/shotzo/board.c
+++ b/board/shotzo/board.c
@@ -84,6 +84,81 @@ static void c0_ccsbu_ovp_interrupt(enum gpio_signal s)
pd_handle_cc_overvoltage(0);
}
+/******************************************************************************/
+/*
+ * Barrel jack power supply handling
+ *
+ * EN_PPVAR_BJ_ADP_L must default active to ensure we can power on when the
+ * barrel jack is connected, and the USB-C port can bring the EC up fine in
+ * dead-battery mode. Both the USB-C and barrel jack switches do reverse
+ * protection, so we're safe to turn one on then the other off- but we should
+ * only do that if the system is off since it might still brown out.
+ */
+
+static int barrel_jack_adapter_is_present(void)
+{
+ /* Shotzo barrel jack adapter present pin is active low. */
+ return !gpio_get_level(GPIO_BJ_ADP_PRESENT_L);
+}
+
+/*
+ * Barrel-jack power adapter ratings.
+ */
+
+#define BJ_ADP_RATING_DEFAULT 0 /* BJ power ratings default */
+static const struct {
+ int voltage;
+ int current;
+} bj_power[] = {
+ { /* 0 - 90W (also default) */
+ .voltage = 19500,
+ .current = 4500 },
+};
+
+/* Debounced connection state of the barrel jack */
+static int8_t adp_connected = -1;
+static void adp_connect_deferred(void)
+{
+ struct charge_port_info pi = { 0 };
+ int connected = barrel_jack_adapter_is_present();
+
+ /* Debounce */
+ if (connected == adp_connected)
+ return;
+ if (connected) {
+ unsigned int bj = BJ_ADP_RATING_DEFAULT;
+
+ pi.voltage = bj_power[bj].voltage;
+ pi.current = bj_power[bj].current;
+ }
+ charge_manager_update_charge(CHARGE_SUPPLIER_DEDICATED,
+ DEDICATED_CHARGE_PORT, &pi);
+ adp_connected = connected;
+}
+DECLARE_DEFERRED(adp_connect_deferred);
+
+#define ADP_DEBOUNCE_MS 1000 /* Debounce time for BJ plug/unplug */
+/* IRQ for BJ plug/unplug. It shouldn't be called if BJ is the power source. */
+static void adp_connect_interrupt(enum gpio_signal signal)
+{
+ hook_call_deferred(&adp_connect_deferred_data, ADP_DEBOUNCE_MS * MSEC);
+}
+static void adp_state_init(void)
+{
+ /*
+ * Initialize all charge suppliers to 0. The charge manager waits until
+ * all ports have reported in before doing anything.
+ */
+ for (int i = 0; i < CHARGE_PORT_COUNT; i++) {
+ for (int j = 0; j < CHARGE_SUPPLIER_COUNT; j++)
+ charge_manager_update_charge(j, i, NULL);
+ }
+
+ /* Report charge state from the barrel jack. */
+ adp_connect_deferred();
+}
+DECLARE_HOOK(HOOK_INIT, adp_state_init, HOOK_PRIO_INIT_CHARGE_MANAGER + 1);
+
/* Must come after other header files and interrupt handler declarations */
#include "gpio_list.h"
@@ -148,6 +223,8 @@ void board_init(void)
{
int on;
+ gpio_enable_interrupt(GPIO_BJ_ADP_PRESENT_L);
+
gpio_enable_interrupt(GPIO_USB_C0_INT_ODL);
/* Store board version for use in determining charge limits */
@@ -235,30 +312,85 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma,
{
}
+__override int extpower_is_present(void)
+{
+ int port;
+ int rv;
+ bool acok;
+
+ for (port = 0; port < board_get_usb_pd_port_count(); port++) {
+ rv = sm5803_is_acok(port, &acok);
+ if ((rv == EC_SUCCESS) && acok)
+ return 1;
+ }
+
+ if (!gpio_get_level(GPIO_EN_PPVAR_BJ_ADP_L))
+ return 1;
+
+ CPRINTUSB("No external power present.");
+
+ return 0;
+}
+
int board_set_active_charge_port(int port)
{
- int is_valid_port = (port >= 0 && port < board_get_usb_pd_port_count());
+ CPRINTUSB("Requested charge port change to %d", port);
- if (!is_valid_port && port != CHARGE_PORT_NONE)
+ /*
+ * The charge manager may ask us to switch to no charger if we're
+ * running off USB-C only but upstream doesn't support PD. It requires
+ * that we accept this switch otherwise it triggers an assert and EC
+ * reset; it's not possible to boot the AP anyway, but we want to avoid
+ * resetting the EC so we can continue to do the "low power" LED blink.
+ */
+ if (port == CHARGE_PORT_NONE)
+ return EC_SUCCESS;
+
+ if (port < 0 || CHARGE_PORT_COUNT <= port)
return EC_ERROR_INVAL;
- if (port == CHARGE_PORT_NONE) {
- CPRINTUSB("Disabling all charge ports");
+ if (port == charge_manager_get_active_charge_port())
+ return EC_SUCCESS;
- sm5803_vbus_sink_enable(CHARGER_SOLO, 0);
+ /* Don't charge from a source port */
+ if (board_vbus_source_enabled(port))
+ return EC_ERROR_INVAL;
- return EC_SUCCESS;
+ if (!chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
+ int bj_active, bj_requested;
+
+ if (charge_manager_get_active_charge_port() != CHARGE_PORT_NONE)
+ /* Change is only permitted while the system is off */
+ return EC_ERROR_INVAL;
+
+ /*
+ * Current setting is no charge port but the AP is on, so the
+ * charge manager is out of sync (probably because we're
+ * reinitializing after sysjump). Reject requests that aren't
+ * in sync with our outputs.
+ */
+ bj_active = !gpio_get_level(GPIO_EN_PPVAR_BJ_ADP_L);
+ bj_requested = port == CHARGE_PORT_BARRELJACK;
+ if (bj_active != bj_requested)
+ return EC_ERROR_INVAL;
}
- CPRINTUSB("New chg p%d", port);
+ CPRINTUSB("New charger p%d", port);
- /*
- * Ensure other port is turned off, then enable new charge port
- */
- if (port == 0) {
+ switch (port) {
+ case CHARGE_PORT_TYPEC0:
sm5803_vbus_sink_enable(CHARGER_SOLO, 1);
- } else {
+ gpio_set_level(GPIO_EN_PPVAR_BJ_ADP_L, 1);
+ break;
+ case CHARGE_PORT_BARRELJACK:
+ /* Make sure BJ adapter is sourcing power */
+ if (!barrel_jack_adapter_is_present())
+ return EC_ERROR_INVAL;
+ gpio_set_level(GPIO_EN_PPVAR_BJ_ADP_L, 0);
sm5803_vbus_sink_enable(CHARGER_SOLO, 0);
+ break;
+ default:
+ return EC_ERROR_INVAL;
}
return EC_SUCCESS;
diff --git a/board/shotzo/board.h b/board/shotzo/board.h
index 42038b3b8d..0b2e1ffb8e 100644
--- a/board/shotzo/board.h
+++ b/board/shotzo/board.h
@@ -48,6 +48,11 @@
/* Buttons */
#define CONFIG_POWER_BUTTON_IGNORE_LID
+/* Dedicated barreljack charger port */
+#undef CONFIG_DEDICATED_CHARGE_PORT_COUNT
+#define CONFIG_DEDICATED_CHARGE_PORT_COUNT 1
+#define DEDICATED_CHARGE_PORT 1
+
/* Unused Features */
#undef CONFIG_BACKLIGHT_LID
#undef CONFIG_CMD_KEYBOARD
@@ -101,6 +106,14 @@ enum battery_type {
BATTERY_TYPE_COUNT,
};
+enum charge_port {
+ CHARGE_PORT_TYPEC0,
+ CHARGE_PORT_BARRELJACK,
+};
+
+/* Pin renaming */
+#define GPIO_AC_PRESENT GPIO_BJ_ADP_PRESENT_L
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/shotzo/gpio.inc b/board/shotzo/gpio.inc
index d957e8766d..a0d219bc53 100644
--- a/board/shotzo/gpio.inc
+++ b/board/shotzo/gpio.inc
@@ -34,6 +34,7 @@ GPIO_INT(USB_C0_CCSBU_OVP_ODL, PIN(K, 6), GPIO_INT_FALLING | GPIO_PULL_UP, c0_cc
/* Other interrupts */
GPIO_INT(EC_WP_OD, PIN(A, 6), GPIO_INT_BOTH, switch_interrupt)
+GPIO_INT(BJ_ADP_PRESENT_L, PIN(J, 1), GPIO_INT_BOTH | GPIO_PULL_UP, adp_connect_interrupt)
/* Power sequence GPIOs */
GPIO(EC_AP_RTCRST, PIN(K, 2), GPIO_OUT_LOW)
@@ -90,6 +91,8 @@ GPIO(EC_ENTERING_RW2, PIN(C, 7), GPIO_OUT_LOW)
GPIO(CCD_MODE_ODL, PIN(H, 5), GPIO_ODR_HIGH)
GPIO(EC_BATTERY_PRES_ODL, PIN(I, 4), GPIO_INPUT)
GPIO(ECH1_PACKET_MODE, PIN(H, 1), GPIO_OUT_LOW)
+GPIO(EN_PPVAR_BJ_ADP_L, PIN(J, 0), GPIO_OUT_LOW)
+GPIO(EN_VBUS_PWR, PIN(F, 3), GPIO_OUT_HIGH)
/* NC pins, enable internal pull-down to avoid floating state. */
GPIO(GPIOA0_NC, PIN(A, 0), GPIO_INPUT | GPIO_PULL_DOWN)
@@ -100,7 +103,6 @@ GPIO(GPIOC3_NC, PIN(C, 3), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOE6_NC, PIN(E, 6), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOF0_NC, PIN(F, 0), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOF1_NC, PIN(F, 1), GPIO_INPUT | GPIO_PULL_DOWN)
-GPIO(GPIOF3_NC, PIN(F, 3), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOG3_NC, PIN(G, 3), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOG4_NC, PIN(G, 4), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOG5_NC, PIN(G, 5), GPIO_INPUT | GPIO_PULL_DOWN)
@@ -108,8 +110,6 @@ GPIO(GPIOG6_NC, PIN(G, 6), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOG7_NC, PIN(G, 7), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOI6_NC, PIN(I, 6), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOI7_NC, PIN(I, 7), GPIO_INPUT | GPIO_PULL_DOWN)
-GPIO(GPIOJ0_NC, PIN(J, 0), GPIO_INPUT | GPIO_PULL_DOWN)
-GPIO(GPIOJ1_NC, PIN(J, 1), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOJ3_NC, PIN(J, 3), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOJ4_NC, PIN(J, 4), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOJ5_NC, PIN(J, 5), GPIO_INPUT | GPIO_PULL_DOWN)
diff --git a/board/shotzo/usb_pd_policy.c b/board/shotzo/usb_pd_policy.c
index 69984e9b6f..9098938476 100644
--- a/board/shotzo/usb_pd_policy.c
+++ b/board/shotzo/usb_pd_policy.c
@@ -72,3 +72,11 @@ int pd_snk_is_vbus_provided(int port)
{
return sm5803_is_vbus_present(port);
}
+
+int board_vbus_source_enabled(int port)
+{
+ /* Ignore non-PD ports (the barrel jack). */
+ if (port >= CONFIG_USB_PD_PORT_MAX_COUNT)
+ return 0;
+ return charger_is_sourcing_otg_power(port);
+}