diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-09-25 16:34:39 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-09-26 11:31:31 -0700 |
commit | 194ad20c5b327e2c7690dc0f082883703158eae5 (patch) | |
tree | 9fa8c30229c7800699f72ca1fea25a09e61143f0 | |
parent | 5943e6c1f5ca86c96cfa38926651466d929278d2 (diff) | |
download | chrome-ec-194ad20c5b327e2c7690dc0f082883703158eae5.tar.gz |
link: Re-enable USB ports on resume
Previously, ports were only enabled on S5->S3, not S3->S0. Seems like
they should always get re-enabled on resume.
This also consolidates the USB code into a single file, cleans up the
debug output, and prints the current USB charge state when the
usbchargemode command is run without args.
BUG=chrome-os-partner:12904
BRANCH=link
TEST=manual
- Boot system
- At ec console, 'usb' should print port 0 and 1 are in mode 1.
- At a root shell, 'ectool chargemode 0 0'
- At a root shell, 'ectool chargemode 1 0'
- Suspend system
- At ec console, 'usb' should print port are in mode 0.
- Resume system
- At ec console, 'usb' should print port 0 and 1 are in mode 1.
Change-Id: I3875a104338fb64db503929a018b8577d6f970e4
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/34062
Reviewed-by: Vic Yang <victoryang@chromium.org>
-rw-r--r-- | common/build.mk | 2 | ||||
-rw-r--r-- | common/usb_charge.c | 49 | ||||
-rw-r--r-- | common/usb_charge_commands.c | 35 |
3 files changed, 38 insertions, 48 deletions
diff --git a/common/build.mk b/common/build.mk index af69df4287..0b8ecc30ea 100644 --- a/common/build.mk +++ b/common/build.mk @@ -32,7 +32,7 @@ common-$(CONFIG_TASK_TEMPSENSOR)+=temp_sensor.o temp_sensor_commands.o common-$(CONFIG_TASK_THERMAL)+=thermal.o thermal_commands.o common-$(CONFIG_TASK_X86POWER)+=x86_power.o common-$(CONFIG_TMP006)+=tmp006.o -common-$(CONFIG_USB_CHARGE)+=usb_charge.o usb_charge_commands.o +common-$(CONFIG_USB_CHARGE)+=usb_charge.o # verified boot stuff VBOOT_SOURCE?=/usr/src/vboot diff --git a/common/usb_charge.c b/common/usb_charge.c index 67c9b369cf..6f95d91101 100644 --- a/common/usb_charge.c +++ b/common/usb_charge.c @@ -5,15 +5,18 @@ /* USB charging control module for Chrome EC */ -#include "board.h" #include "chipset.h" +#include "common.h" #include "console.h" #include "gpio.h" #include "hooks.h" +#include "host_command.h" #include "system.h" #include "usb_charge.h" #include "util.h" +#define CPUTS(outstr) cputs(CC_USBCHARGE, outstr) +#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) #define USB_SYSJUMP_TAG 0x5550 /* "UP" - Usb Port */ #define USB_HOOK_VERSION 1 @@ -78,27 +81,28 @@ static int usb_charge_all_ports_off(void) 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); + if (port_id >= USB_CHARGE_PORT_COUNT) return EC_ERROR_INVAL; - if (mode == USB_CHARGE_MODE_DISABLED) { - usb_charge_set_enabled(port_id, 0); - return EC_SUCCESS; - } - else - usb_charge_set_enabled(port_id, 1); - switch (mode) { + case USB_CHARGE_MODE_DISABLED: + usb_charge_set_enabled(port_id, 0); + break; case USB_CHARGE_MODE_SDP2: usb_charge_set_control_mode(port_id, 7); usb_charge_set_ilim(port_id, 0); + usb_charge_set_enabled(port_id, 1); break; case USB_CHARGE_MODE_CDP: usb_charge_set_control_mode(port_id, 7); usb_charge_set_ilim(port_id, 1); + usb_charge_set_enabled(port_id, 1); break; case USB_CHARGE_MODE_DCP_SHORT: usb_charge_set_control_mode(port_id, 4); + usb_charge_set_enabled(port_id, 1); break; default: return EC_ERROR_UNKNOWN; @@ -118,6 +122,12 @@ static int command_set_mode(int argc, char **argv) int mode = -1; char *e; + if (argc == 1) { + ccprintf("Port 0: %d\nPort 1: %d\n", + charge_mode[0], charge_mode[1]); + return EC_SUCCESS; + } + if (argc != 3) return EC_ERROR_PARAM_COUNT; @@ -132,13 +142,28 @@ static int command_set_mode(int argc, char **argv) return usb_charge_set_mode(port_id, mode); } DECLARE_CONSOLE_COMMAND(usbchargemode, command_set_mode, - "<port> <0 | 1 | 2 | 3>", + "[<port> <0 | 1 | 2 | 3>]", "Set USB charge mode", "Modes: 0=Disabled.\n" " 1=Standard downstream port.\n" " 2=Charging downstream port, BC 1.2.\n" " 3=Dedicated charging port, BC 1.2.\n"); +/*****************************************************************************/ +/* Host commands */ + +static int usb_charge_command_set_mode(struct host_cmd_handler_args *args) +{ + const struct ec_params_usb_charge_set_mode *p = args->params; + + if (usb_charge_set_mode(p->usb_port_id, p->mode) != EC_SUCCESS) + return EC_RES_ERROR; + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_USB_CHARGE_SET_MODE, + usb_charge_command_set_mode, + EC_VER_MASK(0)); /*****************************************************************************/ /* Hooks */ @@ -175,13 +200,13 @@ static int usb_charge_init(void) DECLARE_HOOK(HOOK_INIT, usb_charge_init, HOOK_PRIO_DEFAULT); -static int usb_charge_startup(void) +static int usb_charge_resume(void) { - /* Turn on USB ports on as we go into S3 or S0. */ + /* Turn on USB ports on as we go into S0 from S3 or S5. */ usb_charge_all_ports_on(); return EC_SUCCESS; } -DECLARE_HOOK(HOOK_CHIPSET_STARTUP, usb_charge_startup, HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_CHIPSET_RESUME, usb_charge_resume, HOOK_PRIO_DEFAULT); static int usb_charge_shutdown(void) diff --git a/common/usb_charge_commands.c b/common/usb_charge_commands.c deleted file mode 100644 index 0915ab064d..0000000000 --- a/common/usb_charge_commands.c +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/* USB charging control commands for Chrome EC */ - -#include "common.h" -#include "console.h" -#include "host_command.h" -#include "usb_charge.h" -#include "util.h" - -/* Console output macros */ -#define CPUTS(outstr) cputs(CC_USBCHARGE, outstr) -#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) - -static int usb_charge_command_set_mode(struct host_cmd_handler_args *args) -{ - const struct ec_params_usb_charge_set_mode *p = args->params; - int rv; - - CPRINTF("[%T USB setting port %d to mode %d]\n", - p->usb_port_id, p->mode); - - rv = usb_charge_set_mode(p->usb_port_id, p->mode); - - if (rv != EC_SUCCESS) - return EC_RES_ERROR; - - return EC_RES_SUCCESS; -} -DECLARE_HOST_COMMAND(EC_CMD_USB_CHARGE_SET_MODE, - usb_charge_command_set_mode, - EC_VER_MASK(0)); |