diff options
-rw-r--r-- | board/rambi/board.h | 1 | ||||
-rw-r--r-- | common/usb_port_power_smart.c | 13 | ||||
-rw-r--r-- | include/config.h | 6 | ||||
-rw-r--r-- | include/usb_charge.h | 8 | ||||
-rw-r--r-- | power/baytrail.c | 15 |
5 files changed, 43 insertions, 0 deletions
diff --git a/board/rambi/board.h b/board/rambi/board.h index 62c0784ffe..bebe44e570 100644 --- a/board/rambi/board.h +++ b/board/rambi/board.h @@ -36,6 +36,7 @@ #define CONFIG_SCI_GPIO GPIO_PCH_SCI_L #define CONFIG_TEMP_SENSOR #define CONFIG_TEMP_SENSOR_TMP432 +#define CONFIG_USB_PORT_POWER_IN_S3 #define CONFIG_USB_PORT_POWER_SMART #define CONFIG_USB_PORT_POWER_SMART_SIMPLE #define CONFIG_VBOOT_HASH diff --git a/common/usb_port_power_smart.c b/common/usb_port_power_smart.c index 9a47d78326..89f72c7339 100644 --- a/common/usb_port_power_smart.c +++ b/common/usb_port_power_smart.c @@ -85,6 +85,19 @@ static void usb_charge_all_ports_off(void) usb_charge_set_mode(1, USB_CHARGE_MODE_DISABLED); } +int usb_charge_ports_enabled(void) +{ + int mask = 0; + + if (gpio_get_level(GPIO_USB1_ENABLE)) + mask |= (1 << 0); + + if (gpio_get_level(GPIO_USB2_ENABLE)) + mask |= (1 << 1); + + return mask; +} + int usb_charge_set_mode(int port_id, enum usb_charge_mode mode) { CPRINTF("[%T USB charge p%d m%d]\n", port_id, mode); diff --git a/include/config.h b/include/config.h index abf183151c..58f68e2b33 100644 --- a/include/config.h +++ b/include/config.h @@ -728,6 +728,12 @@ #undef CONFIG_USB_PORT_POWER_DUMB /* + * Support supplying USB power in S3, if the host leaves the port enabled when + * entering S3. + */ +#undef CONFIG_USB_PORT_POWER_IN_S3 + +/* * Support smart power control to the device's USB ports, using * dedicated power control chips. This potentially enables automatic * negotiation of supplying more power to peripherals. diff --git a/include/usb_charge.h b/include/usb_charge.h index 66e6611985..e67aba482e 100644 --- a/include/usb_charge.h +++ b/include/usb_charge.h @@ -34,4 +34,12 @@ enum usb_charge_mode { */ int usb_charge_set_mode(int usb_port_id, enum usb_charge_mode mode); +/** + * Return a bitmask of which USB ports are enabled. + * + * If bit (1 << i) is set, port <i> is enabled. If it is clear, port <i> is + * in USB_CHARGE_MODE_DISABLED. + */ +int usb_charge_ports_enabled(void); + #endif /* __CROS_EC_USB_CHARGE_H */ diff --git a/power/baytrail.c b/power/baytrail.c index e938f9298e..8615964705 100644 --- a/power/baytrail.c +++ b/power/baytrail.c @@ -16,6 +16,7 @@ #include "power.h" #include "system.h" #include "timer.h" +#include "usb_charge.h" #include "util.h" #include "wireless.h" @@ -315,13 +316,27 @@ enum power_state power_handle_state(enum power_state state) /* Turn off power rails */ gpio_set_level(GPIO_PP3300_DX_EN, 0); + +#ifdef CONFIG_USB_PORT_POWER_IN_S3 + /* + * Disable the 5V rail if all USB ports are disabled. Else + * leave 5V enabled so the ports will continue to work in S3. + */ + if (!usb_charge_ports_enabled()) + gpio_set_level(GPIO_PP5000_EN, 0); +#else gpio_set_level(GPIO_PP5000_EN, 0); +#endif + return POWER_S3; case POWER_S3S5: /* Call hooks before we remove power rails */ hook_notify(HOOK_CHIPSET_SHUTDOWN); + /* Turn off 5V rail (if it wasn't turned off in S3) */ + gpio_set_level(GPIO_PP5000_EN, 0); + /* Disable wireless */ wireless_enable(0); |