summaryrefslogtreecommitdiff
path: root/board/brask
diff options
context:
space:
mode:
authorDavid Huang <david.huang@quanta.corp-partner.google.com>2021-09-02 10:14:40 +0800
committerCommit Bot <commit-bot@chromium.org>2021-09-30 10:08:02 +0000
commit6e58199d7eed776f9bebf14d31e8e655f74385f5 (patch)
tree4ef1e6b5849175e53f8d81c3d7c84e9e8666b70a /board/brask
parentda8f0623cba717ad383fef871f9a640499d1cc90 (diff)
downloadchrome-ec-6e58199d7eed776f9bebf14d31e8e655f74385f5.tar.gz
brask: Add Barrel jack power supply handling
Add Barrel jack power supply handling from puff. BUG=b:197514362 BRANCH=None TEST=booted on hardware, verified chgsup output with barrel jack Signed-off-by: David Huang <david.huang@quanta.corp-partner.google.com> Change-Id: Ifc138c8c9938d489044125437e515b898e01f362 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3139614 Reviewed-by: Zhuohao Lee <zhuohao@chromium.org> Reviewed-by: caveh jalali <caveh@chromium.org> Commit-Queue: caveh jalali <caveh@chromium.org>
Diffstat (limited to 'board/brask')
-rw-r--r--board/brask/board.c159
-rw-r--r--board/brask/board.h20
-rw-r--r--board/brask/gpio.inc4
3 files changed, 180 insertions, 3 deletions
diff --git a/board/brask/board.c b/board/brask/board.c
index a9c6b57ec5..8b53f63eec 100644
--- a/board/brask/board.c
+++ b/board/brask/board.c
@@ -3,15 +3,21 @@
* found in the LICENSE file.
*/
+#include "assert.h"
+#include "charge_manager.h"
+#include "charge_state_v2.h"
#include "common.h"
#include "compile_time_macros.h"
#include "console.h"
+#include "cros_board_info.h"
#include "gpio.h"
#include "gpio_signal.h"
#include "power_button.h"
+#include "hooks.h"
#include "power.h"
#include "switch.h"
#include "throttle_ap.h"
+#include "usbc_config.h"
#include "gpio_list.h" /* Must come after other header files. */
@@ -31,7 +37,65 @@ BUILD_ASSERT(ARRAY_SIZE(usb_port_enable) == USB_PORT_COUNT);
int board_set_active_charge_port(int port)
{
- /* TODO(b/197514362): set either barreljack or typec port */
+ CPRINTS("Requested charge port change to %d", port);
+
+ /*
+ * 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_manager_get_active_charge_port())
+ return EC_SUCCESS;
+
+ /* Don't charge from a source port */
+ if (board_vbus_source_enabled(port))
+ return EC_ERROR_INVAL;
+
+ 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;
+ }
+
+ CPRINTS("New charger p%d", port);
+
+ switch (port) {
+ case CHARGE_PORT_TYPEC0:
+ case CHARGE_PORT_TYPEC1:
+ case CHARGE_PORT_TYPEC2:
+ gpio_set_level(GPIO_EN_PPVAR_BJ_ADP_L, 1);
+ break;
+ case CHARGE_PORT_BARRELJACK:
+ /* Make sure BJ adapter is sourcing power */
+ if (gpio_get_level(GPIO_BJ_ADP_PRESENT_ODL))
+ return EC_ERROR_INVAL;
+ gpio_set_level(GPIO_EN_PPVAR_BJ_ADP_L, 0);
+ break;
+ default:
+ return EC_ERROR_INVAL;
+ }
+
return EC_SUCCESS;
}
@@ -39,3 +103,96 @@ void board_set_charge_limit(int port, int supplier, int charge_ma,
int max_ma, int charge_mv)
{
}
+
+/******************************************************************************/
+/*
+ * 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.
+ */
+
+/*
+ * Barrel-jack power adapter ratings.
+ */
+static const struct {
+ int voltage;
+ int current;
+} bj_power[] = {
+ { /* 0 - 135W (also default) */
+ .voltage = 19500,
+ .current = 6920
+ },
+ { /* 1 - 230W */
+ .voltage = 19500,
+ .current = 11800
+ },
+};
+
+static unsigned int ec_config_get_bj_power(void)
+{
+ uint32_t fw_config;
+ unsigned int bj;
+
+ cbi_get_fw_config(&fw_config);
+ bj = (fw_config & EC_CFG_BJ_POWER_MASK) >> EC_CFG_BJ_POWER_L;
+ /* Out of range value defaults to 0 */
+ if (bj >= ARRAY_SIZE(bj_power))
+ bj = 0;
+ return bj;
+}
+
+#define ADP_DEBOUNCE_MS 1000 /* Debounce time for BJ plug/unplug */
+/* 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 = !gpio_get_level(GPIO_BJ_ADP_PRESENT_ODL);
+
+ /* Debounce */
+ if (connected == adp_connected)
+ return;
+ if (connected) {
+ unsigned int bj = ec_config_get_bj_power();
+
+ 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);
+
+/* IRQ for BJ plug/unplug. It shouldn't be called if BJ is the power source. */
+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)
+{
+ ASSERT(CHARGE_PORT_ENUM_COUNT == CHARGE_PORT_COUNT);
+ /*
+ * 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_CHARGE_MANAGER_INIT + 1);
+
+static void board_init(void)
+{
+ gpio_enable_interrupt(GPIO_BJ_ADP_PRESENT_ODL);
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
diff --git a/board/brask/board.h b/board/brask/board.h
index 0d92b2c07f..0f7af27f79 100644
--- a/board/brask/board.h
+++ b/board/brask/board.h
@@ -154,6 +154,14 @@
#include "registers.h"
#include "usbc_config.h"
+enum charge_port {
+ CHARGE_PORT_TYPEC0,
+ CHARGE_PORT_TYPEC1,
+ CHARGE_PORT_TYPEC2,
+ CHARGE_PORT_BARRELJACK,
+ CHARGE_PORT_ENUM_COUNT
+};
+
enum adc_channel {
ADC_TEMP_SENSOR_1_CPU,
ADC_TEMP_SENSOR_2_CPU_VR,
@@ -194,6 +202,18 @@ enum mft_channel {
MFT_CH_COUNT
};
+/*
+ * firmware config fields
+ */
+/*
+ * Barrel-jack power (4 bits).
+ */
+#define EC_CFG_BJ_POWER_L 0
+#define EC_CFG_BJ_POWER_H 3
+#define EC_CFG_BJ_POWER_MASK GENMASK(EC_CFG_BJ_POWER_H, EC_CFG_BJ_POWER_L)
+
+extern void adp_connect_interrupt(enum gpio_signal signal);
+
#endif /* !__ASSEMBLER__ */
#endif /* __CROS_EC_BOARD_H */
diff --git a/board/brask/gpio.inc b/board/brask/gpio.inc
index 01b82a2b74..1e73ae1d03 100644
--- a/board/brask/gpio.inc
+++ b/board/brask/gpio.inc
@@ -26,6 +26,7 @@ GPIO_INT(USB_C1_TCPC_INT_ODL, PIN(A, 2), GPIO_INT_FALLING, tcpc_alert_eve
GPIO_INT(USB_C2_BC12_INT_ODL, PIN(8, 3), GPIO_INT_FALLING, bc12_interrupt)
GPIO_INT(USB_C2_PPC_INT_ODL, PIN(7, 0), GPIO_INT_FALLING, ppc_interrupt)
GPIO_INT(USB_C2_RT_INT_ODL, PIN(4, 1), GPIO_INT_FALLING, retimer_interrupt)
+GPIO_INT(BJ_ADP_PRESENT_ODL, PIN(8, 2), GPIO_INT_BOTH | GPIO_PULL_UP, adp_connect_interrupt)
/* CCD */
GPIO(CCD_MODE_ODL, PIN(E, 5), GPIO_INPUT)
@@ -45,8 +46,7 @@ GPIO(DP_CONN_OC_ODL, PIN(2, 5), GPIO_INPUT)
GPIO(HDMI_CONN_OC_ODL, PIN(2, 4), GPIO_INPUT)
/* BarrelJack */
-GPIO(EN_PPVAR_BJ_ADP_L, PIN(0, 7), GPIO_INPUT)
-GPIO(BJ_ADP_PRESENT_ODL, PIN(8, 2), GPIO_INPUT)
+GPIO(EN_PPVAR_BJ_ADP_L, PIN(0, 7), GPIO_OUT_LOW)
/* Chipset PCH */
GPIO(EC_PCHHOT_ODL, PIN(7, 4), GPIO_INPUT)