mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-30 18:41:11 +00:00
spring: Add a host command for USB mux switching
To make test and bring-up easier, adds a host command for USB mux switching. BUG=chrome-os-partner:17111 TEST=manual BRANCH=none Change-Id: I9da43fe934881ce24f326275ef312c4e6a474f11 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/40586 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
This commit is contained in:
@@ -7,8 +7,11 @@
|
||||
|
||||
#include "board.h"
|
||||
#include "console.h"
|
||||
#include "ec_commands.h"
|
||||
#include "hooks.h"
|
||||
#include "host_command.h"
|
||||
#include "i2c.h"
|
||||
#include "system.h"
|
||||
#include "timer.h"
|
||||
#include "tsu6721.h"
|
||||
#include "uart.h"
|
||||
@@ -146,6 +149,9 @@ static void tsu6721_dump(void)
|
||||
ccprintf("\n");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Console commands */
|
||||
|
||||
static int command_usbmux(int argc, char **argv)
|
||||
{
|
||||
if (1 == argc) { /* dump all registers */
|
||||
@@ -173,3 +179,26 @@ DECLARE_CONSOLE_COMMAND(usbmux, command_usbmux,
|
||||
"[usb|uart1|uart2|auto]",
|
||||
"TSU6721 USB mux control",
|
||||
NULL);
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Host commands */
|
||||
|
||||
static int usb_command_mux(struct host_cmd_handler_args *args)
|
||||
{
|
||||
const struct ec_params_usb_mux *p = args->params;
|
||||
|
||||
if (system_is_locked())
|
||||
return EC_RES_ACCESS_DENIED;
|
||||
|
||||
/* Safety check */
|
||||
if (p->mux != TSU6721_MUX_NONE &&
|
||||
p->mux != TSU6721_MUX_USB &&
|
||||
p->mux != TSU6721_MUX_UART &&
|
||||
p->mux != TSU6721_MUX_AUDIO)
|
||||
return EC_RES_ERROR;
|
||||
|
||||
if (tsu6721_mux(p->mux))
|
||||
return EC_RES_ERROR;
|
||||
return EC_RES_SUCCESS;
|
||||
}
|
||||
DECLARE_HOST_COMMAND(EC_CMD_USB_MUX, usb_command_mux, EC_VER_MASK(0));
|
||||
|
||||
@@ -1198,6 +1198,18 @@ struct ec_params_force_idle {
|
||||
*/
|
||||
#define EC_CMD_BATTERY_CUT_OFF 0x99
|
||||
|
||||
/*****************************************************************************/
|
||||
/* USB port mux control. */
|
||||
|
||||
/*
|
||||
* Switch USB mux or return to automatic switching.
|
||||
*/
|
||||
#define EC_CMD_USB_MUX 0x9a
|
||||
|
||||
struct ec_params_usb_mux {
|
||||
uint8_t mux;
|
||||
} __packed;
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Temporary debug commands. TODO: remove this crosbug.com/p/13849 */
|
||||
|
||||
|
||||
@@ -138,6 +138,8 @@ const char help_str[] =
|
||||
" Get/set TMP006 calibration\n"
|
||||
" usbchargemode <port> <mode>\n"
|
||||
" Set USB charging mode\n"
|
||||
" usbmux <mux>\n"
|
||||
" Set USB mux switch state\n"
|
||||
" version\n"
|
||||
" Prints EC version\n"
|
||||
" wireless <mask>\n"
|
||||
@@ -1431,6 +1433,34 @@ int cmd_usb_charge_set_mode(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
int cmd_usb_mux(int argc, char *argv[])
|
||||
{
|
||||
struct ec_params_usb_mux p;
|
||||
char *e;
|
||||
int rv;
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Usage: %s <mux>\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
p.mux = strtol(argv[1], &e, 0);
|
||||
if (e && *e) {
|
||||
fprintf(stderr, "Bad mux value.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
rv = ec_command(EC_CMD_USB_MUX, 0,
|
||||
&p, sizeof(p), NULL, 0);
|
||||
if (rv < 0)
|
||||
return rv;
|
||||
|
||||
printf("Set USB mux to 0x%x.\n", p.mux);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int cmd_kbpress(int argc, char *argv[])
|
||||
{
|
||||
struct ec_params_mkbp_simulate_key p;
|
||||
@@ -2746,6 +2776,7 @@ const struct command commands[] = {
|
||||
{"thermalset", cmd_thermal_set_threshold},
|
||||
{"tmp006cal", cmd_tmp006cal},
|
||||
{"usbchargemode", cmd_usb_charge_set_mode},
|
||||
{"usbmux", cmd_usb_mux},
|
||||
{"version", cmd_version},
|
||||
{"wireless", cmd_wireless},
|
||||
{NULL, NULL}
|
||||
|
||||
Reference in New Issue
Block a user