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
This commit is contained in:
Vic Yang
2012-04-24 10:08:14 +08:00
committed by Vic Yang
parent 468e34d51d
commit 527eddedaa
3 changed files with 35 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -16,6 +16,7 @@
#include "system.h"
#include "task.h"
#include "timer.h"
#include "usb_charge.h"
#include "util.h"
#include "x86_power.h"
@@ -329,6 +330,9 @@ void x86_power_task(void)
/* Wait 5ms for SUSCLK to stabilize */
usleep(5000);
/* Turn off USB ports. */
usb_charge_all_ports_off();
state = X86_S5;
break;
@@ -342,6 +346,9 @@ void x86_power_task(void)
gpio_set_level(GPIO_ENABLE_TOUCHPAD, 1);
gpio_set_level(GPIO_TOUCHSCREEN_RESETn, 1);
/* Turn on USB ports as we go into S3 or S0. */
usb_charge_all_ports_on();
state = X86_S3;
break;
@@ -421,6 +428,9 @@ void x86_power_task(void)
/* Turn off power to RAM */
gpio_set_level(GPIO_ENABLE_1_5V_DDR, 0);
/* Turn off USB ports. */
usb_charge_all_ports_off();
state = X86_S5;
break;

View File

@@ -27,6 +27,10 @@ enum usb_charge_mode {
USB_CHARGE_MODE_COUNT
};
int usb_charge_all_ports_on(void);
int usb_charge_all_ports_off(void);
int usb_charge_set_mode(int usb_port_id, enum usb_charge_mode);
#endif /* __CROS_EC_USB_CHARGE_H */