From 527eddedaaf4bed18766d016c7442a1e71655a2b Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Tue, 24 Apr 2012 10:08:14 +0800 Subject: Automatically switch USB charging mode Disable USB ports when system is down and set USB ports to standard downstream mode when system is up or sleeping. Signed-off-by: Vic Yang BUG=chrome-os-partner:9249 TEST=Plug in a phone and see it charge when system is on. Turn off the system and see it stop charging. Change-Id: I02850dee7051ed6589e0f176a933069203f0efdf --- common/usb_charge.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'common/usb_charge.c') diff --git a/common/usb_charge.c b/common/usb_charge.c index ace535fbe4..3f162a3f4d 100644 --- a/common/usb_charge.c +++ b/common/usb_charge.c @@ -6,6 +6,7 @@ /* USB charging control module for Chrome EC */ #include "board.h" +#include "chipset.h" #include "console.h" #include "gpio.h" #include "hooks.h" @@ -46,6 +47,22 @@ static void usb_charge_set_ilim(int port_id, int sel) } +int usb_charge_all_ports_on(void) +{ + usb_charge_set_mode(0, USB_CHARGE_MODE_DOWNSTREAM_500MA); + usb_charge_set_mode(1, USB_CHARGE_MODE_DOWNSTREAM_500MA); + return EC_SUCCESS; +} + + +int usb_charge_all_ports_off(void) +{ + usb_charge_set_mode(0, USB_CHARGE_MODE_DISABLED); + usb_charge_set_mode(1, USB_CHARGE_MODE_DISABLED); + return EC_SUCCESS; +} + + int usb_charge_set_mode(int port_id, enum usb_charge_mode mode) { if (port_id >= USB_CHARGE_PORT_COUNT) @@ -122,10 +139,10 @@ DECLARE_CONSOLE_COMMAND(usbchargemode, command_set_mode); static int usb_charge_init(void) { - int i; - - for (i = 0; i < USB_CHARGE_PORT_COUNT; ++i) - usb_charge_set_mode(i, USB_CHARGE_MODE_DOWNSTREAM_500MA); + if (chipset_in_state(CHIPSET_STATE_SOFT_OFF)) + usb_charge_all_ports_off(); + else + usb_charge_all_ports_on(); return EC_SUCCESS; } -- cgit v1.2.1