summaryrefslogtreecommitdiff
path: root/common/usb_charge.c
diff options
context:
space:
mode:
authorVic Yang <victoryang@google.com>2012-04-24 10:08:14 +0800
committerVic Yang <victoryang@chromium.org>2012-05-09 10:15:03 +0800
commit527eddedaaf4bed18766d016c7442a1e71655a2b (patch)
tree17c41099c845b53eb6d95e4ccd1799833b2a3408 /common/usb_charge.c
parent468e34d51df1ab4cc934267c80d7a1e18406c845 (diff)
downloadchrome-ec-527eddedaaf4bed18766d016c7442a1e71655a2b.tar.gz
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 <victoryang@google.com> 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
Diffstat (limited to 'common/usb_charge.c')
-rw-r--r--common/usb_charge.c25
1 files changed, 21 insertions, 4 deletions
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;
}