summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/tsu6721.c29
-rw-r--r--include/ec_commands.h12
-rw-r--r--util/ectool.c31
3 files changed, 72 insertions, 0 deletions
diff --git a/common/tsu6721.c b/common/tsu6721.c
index d6fc67ce23..ba6d3ad4b0 100644
--- a/common/tsu6721.c
+++ b/common/tsu6721.c
@@ -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));
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 9dc5566e92..9459800693 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1199,6 +1199,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 */
/*
diff --git a/util/ectool.c b/util/ectool.c
index b8f7d45226..34eeb3df94 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -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}