diff options
author | Diana Z <dzigterman@chromium.org> | 2021-05-12 20:59:53 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-05-14 20:48:08 +0000 |
commit | 081b591bce6027ee308ab86f9fc1c82245fc7fba (patch) | |
tree | 2a487ea4837d8ebb4cf8ba20a0949488666e5442 /baseboard/mancomb | |
parent | f0927fd016694b7a7507bbb16b529cfa1154e3d1 (diff) | |
download | chrome-ec-081b591bce6027ee308ab86f9fc1c82245fc7fba.tar.gz |
Mancomb: Add BJ to charge manager and correct active charge port set
Register the BJ with the charge manager, and add a per-board callback to
determine the voltage and current associated with it.
Additionally, correct a couple of errors in the active charge port set
function. The BJ port is incapable of sourcing Vbus, and the ports to
be disabled should be all except the port being enabled.
BRANCH=None
BUG=b:187911213,b:187899192
TEST=on mancomb, plug in BJ and verify the correct voltage and current
are registered for it
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: I25369e18a56832a79421e179d267c4741916720b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2892183
Reviewed-by: Rob Barnes <robbarnes@google.com>
Commit-Queue: Rob Barnes <robbarnes@google.com>
Diffstat (limited to 'baseboard/mancomb')
-rw-r--r-- | baseboard/mancomb/base_gpio.inc | 2 | ||||
-rw-r--r-- | baseboard/mancomb/baseboard.c | 49 | ||||
-rw-r--r-- | baseboard/mancomb/baseboard.h | 4 | ||||
-rw-r--r-- | baseboard/mancomb/usb_pd_policy.c | 4 |
4 files changed, 57 insertions, 2 deletions
diff --git a/baseboard/mancomb/base_gpio.inc b/baseboard/mancomb/base_gpio.inc index 3417850762..239f08a115 100644 --- a/baseboard/mancomb/base_gpio.inc +++ b/baseboard/mancomb/base_gpio.inc @@ -24,7 +24,7 @@ GPIO_INT(PG_PCORE_S0_R_OD, PIN(B, 6), GPIO_INT_BOTH, power_signal_interrupt) GPIO_INT(EC_PCORE_INT_ODL, PIN(F, 0), GPIO_INT_BOTH | GPIO_PULL_UP, power_signal_interrupt) /* Power Core Interrupt */ GPIO_INT(PG_GROUPC_S0_OD, PIN(A, 3), GPIO_INT_BOTH, baseboard_en_pwr_pcore_s0) /* Power Group C S0 */ GPIO_INT(PG_DDR4_S3_OD, PIN(9, 5), GPIO_INT_BOTH, baseboard_en_pwr_pcore_s0) /* Power Group LPDDR4 S3 */ -GPIO(BJ_ADP_PRESENT_L, PIN(3, 0), GPIO_INPUT) /* Barrel Jack Adapter Present */ +GPIO_INT(BJ_ADP_PRESENT_L, PIN(3, 0), GPIO_INT_BOTH | GPIO_PULL_UP, baseboard_bj_connect_interrupt) /* Barrel Jack Adapter Present */ GPIO(EC_RECOVERY_BTN_ODL, PIN(3, 1), GPIO_INT_BOTH) GPIO(EN_PWR_S5, PIN(B, 7), GPIO_OUT_LOW) /* Enable S5 Power */ GPIO(EN_PWR_S0_R, PIN(F, 1), GPIO_OUT_LOW) diff --git a/baseboard/mancomb/baseboard.c b/baseboard/mancomb/baseboard.c index a7d66b885a..58083d606b 100644 --- a/baseboard/mancomb/baseboard.c +++ b/baseboard/mancomb/baseboard.c @@ -290,6 +290,9 @@ static void baseboard_interrupt_init(void) gpio_enable_interrupt(GPIO_USB_A2_FAULT_R_ODL); gpio_enable_interrupt(GPIO_USB_A1_FAULT_R_ODL); gpio_enable_interrupt(GPIO_USB_A0_FAULT_R_ODL); + + /* Enable BJ insertion interrupt */ + gpio_enable_interrupt(GPIO_BJ_ADP_PRESENT_L); } DECLARE_HOOK(HOOK_INIT, baseboard_interrupt_init, HOOK_PRIO_INIT_I2C + 1); @@ -445,6 +448,50 @@ static int fsusb42umx_set_mux(const struct usb_mux *me, mux_state_t mux_state) return EC_SUCCESS; } +#define BJ_DEBOUNCE_MS 1000 /* Debounce time for BJ plug/unplug */ + +static int8_t bj_connected = -1; + +static void bj_connect_deferred(void) +{ + struct charge_port_info pi = { 0 }; + int connected = !gpio_get_level(GPIO_BJ_ADP_PRESENT_L); + + /* Debounce */ + if (connected == bj_connected) + return; + + if (connected) + board_get_bj_power(&pi.voltage, &pi.current); + + charge_manager_update_charge(CHARGE_SUPPLIER_DEDICATED, + DEDICATED_CHARGE_PORT, &pi); + bj_connected = connected; +} +DECLARE_DEFERRED(bj_connect_deferred); + +/* IRQ for BJ plug/unplug. It shouldn't be called if BJ is the power source. */ +void baseboard_bj_connect_interrupt(enum gpio_signal signal) +{ + hook_call_deferred(&bj_connect_deferred_data, BJ_DEBOUNCE_MS * MSEC); +} + +static void charge_port_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. */ + bj_connect_deferred(); +} +DECLARE_HOOK(HOOK_INIT, charge_port_init, HOOK_PRIO_CHARGE_MANAGER_INIT + 1); + int board_set_active_charge_port(int port) { int rv, i; @@ -509,7 +556,7 @@ int board_set_active_charge_port(int port) if (i == port) continue; - rv = ppc_vbus_sink_enable(port, 0); + rv = ppc_vbus_sink_enable(i, 0); if (rv) { CPRINTSUSB("Failed to disable C%d sink path", i); return rv; diff --git a/baseboard/mancomb/baseboard.h b/baseboard/mancomb/baseboard.h index 841f71a95f..282c36e69d 100644 --- a/baseboard/mancomb/baseboard.h +++ b/baseboard/mancomb/baseboard.h @@ -308,6 +308,7 @@ enum mft_channel { }; /* Baseboard Interrupt handlers. */ +void baseboard_bj_connect_interrupt(enum gpio_signal signal); void baseboard_en_pwr_pcore_s0(enum gpio_signal signal); void baseboard_en_pwr_s0(enum gpio_signal signal); void baseboard_usb_fault_alert(enum gpio_signal signal); @@ -319,6 +320,9 @@ void ppc_interrupt(enum gpio_signal signal); void sbu_fault_interrupt(enum ioex_signal signal); void tcpc_alert_event(enum gpio_signal signal); +/* Required board functions */ +void board_get_bj_power(int *voltage, int *current); + #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BASEBOARD_H */ diff --git a/baseboard/mancomb/usb_pd_policy.c b/baseboard/mancomb/usb_pd_policy.c index ac92a6e0ad..66b565382b 100644 --- a/baseboard/mancomb/usb_pd_policy.c +++ b/baseboard/mancomb/usb_pd_policy.c @@ -73,5 +73,9 @@ int pd_set_power_supply_ready(int port) int board_vbus_source_enabled(int port) { + /* Answer is always "no" from the BJ port */ + if (port >= CONFIG_USB_PD_PORT_MAX_COUNT) + return 0; + return ppc_is_sourcing_vbus(port); } |