From 96fbb356871b3cf33efecf0936175cffb442c5b4 Mon Sep 17 00:00:00 2001 From: Vijay Hiremath Date: Fri, 10 Jun 2016 11:08:40 -0700 Subject: [PATCH] amenia: reject charge port on init till battery is initialized Ported from the below patch Change-Id: I981f9dbf3d84390550bb696e561f5fa51ffc573a Reviewed-on: https://chromium-review.googlesource.com/351224 BUG=chrome-os-partner:54058 BRANCH=none TEST=Amenia system does not reboot before booting to OS. Active port is set once battery is available. Change-Id: If8fd84f82f5a7fb7ca3736031a161d90e5e77c12 Signed-off-by: Vijay Hiremath Reviewed-on: https://chromium-review.googlesource.com/349853 Commit-Ready: Kevin K Wong Tested-by: Vijay P Hiremath Reviewed-by: Shawn N --- board/amenia/battery.c | 6 +++--- board/amenia/board.c | 42 +++++++++++++++++++++++++++++++++--- board/amenia/usb_pd_policy.c | 5 ----- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/board/amenia/battery.c b/board/amenia/battery.c index a931ff3d91..9363bbde93 100644 --- a/board/amenia/battery.c +++ b/board/amenia/battery.c @@ -72,7 +72,7 @@ int board_cut_off_battery(void) enum battery_present battery_is_present(void) { enum battery_present batt_pres; - const struct batt_params *batt = charger_current_battery_params(); + int batt_status; /* The GPIO is low when the battery is physically present */ batt_pres = gpio_get_level(GPIO_BAT_PRESENT_L) ? BP_NO : BP_YES; @@ -86,8 +86,8 @@ enum battery_present battery_is_present(void) * The device will wake up when a voltage is applied to PACK. * Battery status will be inactive until it is initialized. */ - if (batt_pres == BP_YES && !(batt->flags & BATT_FLAG_BAD_STATUS)) - if (!(batt->status & STATUS_INITIALIZED)) + if (batt_pres == BP_YES && !battery_status(&batt_status)) + if (!(batt_status & STATUS_INITIALIZED)) batt_pres = BP_NO; return batt_pres; diff --git a/board/amenia/board.c b/board/amenia/board.c index 6895c868f3..9dbf78e825 100644 --- a/board/amenia/board.c +++ b/board/amenia/board.c @@ -245,6 +245,12 @@ const struct button_config buttons[CONFIG_BUTTON_COUNT] = { 30 * MSEC, 0}, }; +static const enum bd99955_charge_port + pd_port_to_bd99955_port[CONFIG_USB_PD_PORT_COUNT] = { + [0] = BD99955_CHARGE_PORT_VBUS, + [1] = BD99955_CHARGE_PORT_VCC, +}; + /* Called by APL power state machine when transitioning from G3 to S5 */ static void chipset_pre_init(void) { @@ -270,6 +276,23 @@ static void board_init(void) } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); +int pd_snk_is_vbus_provided(int port) +{ + enum bd99955_charge_port bd99955_port; + + switch (port) { + case 0: + case 1: + bd99955_port = pd_port_to_bd99955_port[port]; + break; + default: + panic("Invalid charge port\n"); + break; + } + + return bd99955_is_vbus_provided(bd99955_port); +} + /** * Set active charge port -- only one port can be active at a time. * @@ -281,6 +304,7 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); int board_set_active_charge_port(int charge_port) { enum bd99955_charge_port bd99955_port; + static int initialized; /* charge port is a realy physical port */ int is_real_port = (charge_port >= 0 && @@ -293,14 +317,24 @@ int board_set_active_charge_port(int charge_port) return EC_ERROR_INVAL; } + /* + * Reject charge port disable if our battery is critical and we + * have yet to initialize a charge port - continue to charge using + * charger ROM / POR settings. + */ + if (!initialized && + charge_port == CHARGE_PORT_NONE && + charge_get_percent() < 2) { + CPRINTS("Battery critical, don't disable charging"); + return -1; + } + CPRINTS("New chg p%d", charge_port); switch (charge_port) { case 0: - bd99955_port = BD99955_CHARGE_PORT_VBUS; - break; case 1: - bd99955_port = BD99955_CHARGE_PORT_VCC; + bd99955_port = pd_port_to_bd99955_port[charge_port]; break; case CHARGE_PORT_NONE: bd99955_port = BD99955_CHARGE_PORT_NONE; @@ -310,6 +344,8 @@ int board_set_active_charge_port(int charge_port) break; } + initialized = 1; + return bd99955_select_input_port(bd99955_port); } diff --git a/board/amenia/usb_pd_policy.c b/board/amenia/usb_pd_policy.c index 821272beb0..f1c3b99326 100644 --- a/board/amenia/usb_pd_policy.c +++ b/board/amenia/usb_pd_policy.c @@ -103,11 +103,6 @@ void typec_set_input_current_limit(int port, uint32_t max_ma, pd_send_host_event(PD_EVENT_POWER_CHANGE); } -int pd_snk_is_vbus_provided(int port) -{ - return bd99955_is_vbus_provided(port); -} - int pd_board_checks(void) { return EC_SUCCESS;