diff options
-rw-r--r-- | board/amenia/battery.c | 6 | ||||
-rw-r--r-- | board/amenia/board.c | 42 | ||||
-rw-r--r-- | 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; |