Merge "USB charging control LPC command."

This commit is contained in:
Gerrit
2012-02-16 15:58:06 -08:00
committed by Gerrit Code Review
6 changed files with 105 additions and 1 deletions

View File

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

View File

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

View File

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

View File

@@ -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 */

View File

@@ -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 */

View File

@@ -40,6 +40,8 @@ const char help_str[] =
" Prints current fan RPM\n"
" pwmsetfanrpm <targetrpm>\n"
" Set target fan RPM\n"
" usbchargemode <port> <mode>\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 <port_id> <mode_id>\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]);