From 472a26a4bbb7fa67b782e9663a06b01a29468a79 Mon Sep 17 00:00:00 2001 From: Ting Shen Date: Wed, 3 Apr 2019 17:38:22 +0800 Subject: kukui: implement pogo discharge and extpower_present - checks pogo present in extpower_present() - implemented customized discharge_on_ac, we can't really discharge on pogo, so only set charge to NONE when force discharging. BUG=b:127767432,b:128386458 TEST=None BRANCH=None Change-Id: I2ffb6a69f102b9e10eff0a7794e04516055fac9d Signed-off-by: Ting Shen Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1549811 Tested-by: Ting Shen Commit-Queue: Ting Shen Auto-Submit: Ting Shen Reviewed-by: Yilun Lin --- board/kukui/board.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/board/kukui/board.c b/board/kukui/board.c index 285372e089..40a18c9729 100644 --- a/board/kukui/board.c +++ b/board/kukui/board.c @@ -197,10 +197,16 @@ static void board_pogo_charge_init(void) DECLARE_HOOK(HOOK_INIT, board_pogo_charge_init, HOOK_PRIO_CHARGE_MANAGER_INIT + 1); +static int force_discharge; + int board_set_active_charge_port(int charge_port) { CPRINTS("New chg p%d", charge_port); + /* ignore all request when discharge mode is on */ + if (force_discharge) + return EC_SUCCESS; + switch (charge_port) { case CHARGE_PORT_USB_C: /* Don't charge from a source port */ @@ -240,7 +246,22 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int board_discharge_on_ac(int enable) { - /* TODO(b:123268580): Implement POGO discharge logic. */ + int ret, port; + + if (enable) { + port = CHARGE_PORT_NONE; + } else { + /* restore the charge port state */ + port = charge_manager_get_override(); + if (port == OVERRIDE_OFF) + port = charge_manager_get_active_charge_port(); + } + + ret = board_set_active_charge_port(port); + if (ret) + return ret; + force_discharge = enable; + return charger_discharge_on_ac(enable); } @@ -250,11 +271,14 @@ int extpower_is_present(void) * The charger will indicate VBUS presence if we're sourcing 5V, * so exclude such ports. */ - /* TODO(b:127767432): Also need to check pogo_vbus_present. */ + int usb_c_extpower_present; + if (board_vbus_source_enabled(CHARGE_PORT_USB_C)) - return 0; + usb_c_extpower_present = 0; else - return tcpm_get_vbus_level(CHARGE_PORT_USB_C); + usb_c_extpower_present = tcpm_get_vbus_level(CHARGE_PORT_USB_C); + + return usb_c_extpower_present || gpio_get_level(GPIO_POGO_VBUS_PRESENT); } int pd_snk_is_vbus_provided(int port) -- cgit v1.2.1