From 6a60a7fbdc83e3b5b8e8534353d30fb0966a5303 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Thu, 16 Feb 2012 12:43:22 -0800 Subject: [PATCH] USB charging control LPC command. Add a LPC command to control USB charging mode. Also add the command to ectool. BUG=chrome-os-partner:7476 TEST=Manually test on link proto-0. Change-Id: Ica87d0a690bc86e28844bd695f31641398b21939 Signed-off-by: Vic Yang --- common/build.mk | 2 +- common/host_command.c | 4 ++++ common/usb_charge_commands.c | 33 +++++++++++++++++++++++++++++++ include/lpc_commands.h | 11 +++++++++++ include/usb_charge_commands.h | 19 ++++++++++++++++++ util/ectool.c | 37 +++++++++++++++++++++++++++++++++++ 6 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 common/usb_charge_commands.c create mode 100644 include/usb_charge_commands.h diff --git a/common/build.mk b/common/build.mk index 48c7daa753..a04fe3c11a 100644 --- a/common/build.mk +++ b/common/build.mk @@ -5,7 +5,7 @@ # Common files build # -common-y=main.o util.o console.o vboot.o uart_buffering.o +common-y=main.o util.o console.o vboot.o uart_buffering.o usb_charge_commands.o common-y+=memory_commands.o shared_mem.o system.o usb_charge.o common-y+=gpio_commands.o common-$(CONFIG_LPC)+=port80.o diff --git a/common/host_command.c b/common/host_command.c index 5cebed2131..0ed1802977 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -11,6 +11,7 @@ #include "host_command.h" #include "temp_sensor_commands.h" #include "pwm_commands.h" +#include "usb_charge_commands.h" #include "lpc.h" #include "lpc_commands.h" #include "system.h" @@ -183,6 +184,9 @@ static void command_process(int slot) case EC_LPC_COMMAND_PWM_SET_FAN_TARGET_RPM: lpc_send_host_response(slot, pwm_command_set_fan_target_rpm(data)); return; + case EC_LPC_COMMAND_USB_CHARGE_SET_MODE: + lpc_send_host_response(slot, usb_charge_command_set_mode(data)); + return; default: lpc_send_host_response(slot, EC_LPC_STATUS_INVALID_COMMAND); } diff --git a/common/usb_charge_commands.c b/common/usb_charge_commands.c new file mode 100644 index 0000000000..6d72f48742 --- /dev/null +++ b/common/usb_charge_commands.c @@ -0,0 +1,33 @@ +/* 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 "console.h" +#include "usb_charge.h" +#include "usb_charge_commands.h" +#include "lpc_commands.h" +#include "uart.h" +#include "util.h" + + +/*****************************************************************************/ +/* Host commands */ + +enum lpc_status usb_charge_command_set_mode(uint8_t *data) +{ + struct lpc_params_usb_charge_set_mode *p = + (struct lpc_params_usb_charge_set_mode *)data; + int rv; + + uart_printf("[Setting USB 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_LPC_STATUS_ERROR; + + return EC_LPC_STATUS_SUCCESS; +} diff --git a/include/lpc_commands.h b/include/lpc_commands.h index 16936cf043..28acb4f6c1 100644 --- a/include/lpc_commands.h +++ b/include/lpc_commands.h @@ -235,4 +235,15 @@ struct lpc_response_temp_sensor_get_readings { uint32_t value; } __attribute__ ((packed)); + +/*****************************************************************************/ +/* USB charging control commands */ + +/* Set USB port charging mode */ +#define EC_LPC_COMMAND_USB_CHARGE_SET_MODE 0x40 +struct lpc_params_usb_charge_set_mode { + uint8_t usb_port_id; + uint8_t mode; +} __attribute__ ((packed)); + #endif /* __CROS_EC_LPC_COMMANDS_H */ diff --git a/include/usb_charge_commands.h b/include/usb_charge_commands.h new file mode 100644 index 0000000000..8871fdd294 --- /dev/null +++ b/include/usb_charge_commands.h @@ -0,0 +1,19 @@ +/* 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 */ + +#ifndef __CROS_EC_USB_CHARGE_COMMANDS_H +#define __CROS_EC_USB_CHARGE_COMMANDS_H + +#include "common.h" + +/* Initializes the module. */ +int usb_charge_commands_init(void); + +/* Host command handlers. */ +enum lpc_status usb_charge_command_set_mode(uint8_t *data); + +#endif /* __CROS_EC_USB_CHARGE_COMMANDS_H */ diff --git a/util/ectool.c b/util/ectool.c index 49785ac1a1..127f357208 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -40,6 +40,8 @@ const char help_str[] = " Prints current fan RPM\n" " pwmsetfanrpm \n" " Set target fan RPM\n" + " usbchargemode \n" + " Set USB charging mode\n" "\n" "Not working for you? Make sure LPC I/O is configured:\n" " pci_write32 0 0x1f 0 0x88 0x00fc0801\n" @@ -506,6 +508,39 @@ int cmd_pwm_set_fan_rpm(int argc, char *argv[]) return 0; } +int cmd_usb_charge_set_mode(int argc, char *argv[]) +{ + struct lpc_params_usb_charge_set_mode p; + char *e; + int rv; + + if (argc != 2) { + fprintf(stderr, + "Usage: usbchargemode \n"); + return -1; + } + p.usb_port_id = strtol(argv[0], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad port ID.\n"); + return -1; + } + p.mode = strtol(argv[1], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad mode ID.\n"); + return -1; + } + + printf("Setting port %d to mode %d...\n", p.usb_port_id, p.mode); + + rv = ec_command(EC_LPC_COMMAND_USB_CHARGE_SET_MODE, + &p, sizeof(p), NULL, 0); + if (rv) + return rv; + + printf("USB charging mode set.\n"); + return 0; +} + int main(int argc, char *argv[]) { if (argc < 2 || !strcasecmp(argv[1], "-?") || @@ -543,6 +578,8 @@ int main(int argc, char *argv[]) return cmd_pwm_get_fan_rpm(); if (!strcasecmp(argv[1], "pwmsetfanrpm")) return cmd_pwm_set_fan_rpm(argc - 2, argv + 2); + if (!strcasecmp(argv[1], "usbchargemode")) + return cmd_usb_charge_set_mode(argc - 2, argv + 2); /* If we're still here, command was unknown */ fprintf(stderr, "Unknown command '%s'\n\n", argv[1]);