From 1cf09901eb2b923e3d39a60e0194f0b537efbfa1 Mon Sep 17 00:00:00 2001 From: Marco Chen Date: Tue, 21 May 2019 20:41:44 +0800 Subject: bobba: add blorb and droid into the support of controlling USB Type-A power. Blorb and droid are first projects we are tyring to enable the control of USB Type-A power in the run time. This CL set inhibit_charging_in_suspend to USB_DISALLOW_SUSPEND_CHARGE in default and relies on OS to change this flag based on the status of USB device on the USB Type-A port. BUG=b:130767435 BRANCH=octopus TEST=1. `make BOARD=bobba -j4` 2. check power of USB Type-A port is disabled when OS gets into S0iX and no any USB device is ever connected to DUT. Change-Id: I19ff69df89a857cd3feb594641b6562f20356879 Signed-off-by: Marco Chen Reviewed-on: https://chromium-review.googlesource.com/1621451 Commit-Ready: ChromeOS CL Exonerator Bot Legacy-Commit-Queue: Commit Bot Reviewed-by: Diana Z (cherry picked from commit 3462b178484efa2e643b89291b3961e6aafca655) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1630327 --- board/bobba/board.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/board/bobba/board.c b/board/bobba/board.c index 15cf0c3003..32b79e886e 100644 --- a/board/bobba/board.c +++ b/board/bobba/board.c @@ -39,6 +39,7 @@ #include "tcpci.h" #include "temp_sensor.h" #include "thermistor.h" +#include "usb_charge.h" #include "usb_mux.h" #include "usbc_ppc.h" #include "util.h" @@ -301,6 +302,39 @@ static void board_update_no_keypad_config_from_sku(void) } } +static void board_usb_charge_mode_init(void) +{ + int i; + + /* + * Only overriding the USB_DISALLOW_SUSPEND_CHARGE in RO is enough because + * USB_SYSJUMP_TAG preserves the settings to RW. And we should honor to it. + */ + if (system_jumped_to_this_image()) + return; + + /* Currently only blorb and droid support this feature. */ + if ((sku_id < 32 || sku_id > 39) && (sku_id < 40 || sku_id > 47)) + return; + + /* + * By default, turn the charging off when system suspends. + * If system power on with connecting a USB device, + * the OS must send an event to EC to clear the + * inhibit_charging_in_suspend. + */ + for (i = 0; i < CONFIG_USB_PORT_POWER_SMART_PORT_COUNT; i++) + usb_charge_set_mode(i, CONFIG_USB_PORT_POWER_SMART_DEFAULT_MODE, + USB_DISALLOW_SUSPEND_CHARGE); +} +/* + * usb_charge_init() is hooked in HOOK_PRIO_DEFAULT and set inhibit_charge to + * USB_ALLOW_SUSPEND_CHARGE. As a result, in order to override this default + * setting to USB_DISALLOW_SUSPEND_CHARGE this function should be hooked after + * calling usb_charge_init(). + */ +DECLARE_HOOK(HOOK_INIT, board_usb_charge_mode_init, HOOK_PRIO_DEFAULT + 1); + /* Read CBI from i2c eeprom and initialize variables for board variants */ static void cbi_init(void) { -- cgit v1.2.1