summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Short <keithshort@chromium.org>2019-12-05 13:00:53 -0700
committerCommit Bot <commit-bot@chromium.org>2019-12-09 19:04:53 +0000
commit76daabfd0fc732ecbd577c5cb903137d13ce4b17 (patch)
treee91ee2dfc992856d066c7d62b63440b66115bf7a
parent37e7cd81880bc4ee25e5bcd085a3c217ad7b6eae (diff)
downloadchrome-ec-76daabfd0fc732ecbd577c5cb903137d13ce4b17.tar.gz
tcpci: add command to dump standard TCPCI registers
Add new console command "tcpci_dump", enabled with a new config option CONFIG_CMD_TCPCI_DUMP. Command consumes about 2 KiB of flash space in both the RO and RW images. Typical output: > tcpci_dump 0 TCPC_REG_VENDOR_ID (0x00) = 0x0451 TCPC_REG_PRODUCT_ID (0x02) = 0x0422 TCPC_REG_BCD_DEV (0x04) = 0x0100 TCPC_REG_TC_REV (0x06) = 0x0011 TCPC_REG_PD_REV (0x08) = 0x2011 TCPC_REG_PD_INT_REV (0x0a) = 0x1010 TCPC_REG_ALERT (0x10) = 0x0000 TCPC_REG_ALERT_MASK (0x12) = 0x007d TCPC_REG_CONFIG_STD_OUTPUT (0x18) = 0x60 TCPC_REG_TCPC_CTRL (0x19) = 0x01 TCPC_REG_ROLE_CTRL (0x1a) = 0x1a TCPC_REG_FAULT_CTRL (0x1b) = 0x06 TCPC_REG_POWER_CTRL (0x1c) = 0x70 TCPC_REG_CC_STATUS (0x1d) = 0x1c TCPC_REG_POWER_STATUS (0x1e) = 0x0c TCPC_REG_FAULT_STATUS (0x1f) = 0x00 TCPC_REG_ALERT_EXT (0x21) = 0x00 TCPC_REG_DEV_CAP_1 (0x24) = 0x1e98 TCPC_REG_DEV_CAP_2 (0x26) = 0x00c5 TCPC_REG_STD_INPUT_CAP (0x28) = 0x00 TCPC_REG_STD_OUTPUT_CAP (0x29) = 0x00 TCPC_REG_CONFIG_EXT_1 (0x2a) = 0x00 TCPC_REG_MSG_HDR_INFO (0x2e) = 0x02 TCPC_REG_RX_DETECT (0x2f) = 0x21 TCPC_REG_RX_BYTE_CNT (0x30) = 0x00 TCPC_REG_RX_BUF_FRAME_TYPE (0x31) = 0x00 TCPC_REG_TRANSMIT (0x50) = 0x00 TCPC_REG_VBUS_VOLTAGE (0x70) = 0x0000 TCPC_REG_VBUS_SINK_DISCONNECT_THRESH (0x72) = 0x0000 TCPC_REG_VBUS_STOP_DISCHARGE_THRESH (0x74) = 0x0000 TCPC_REG_VBUS_VOLTAGE_ALARM_HI_CFG (0x76) = 0x0000 TCPC_REG_VBUS_VOLTAGE_ALARM_LO_CFG (0x78) = 0x0000 BUG=none BRANCH=none TEST=make buildall TEST=Enable CONFIG_CMD_TCPCI_DUMP and run "tcpci 0" on a Volteer board. Change-Id: I231e6ece621e88722027186ec380a0e424ccb2c7 Signed-off-by: Keith Short <keithshort@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1955905 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
-rw-r--r--driver/tcpm/tcpci.c89
-rw-r--r--include/config.h1
2 files changed, 90 insertions, 0 deletions
diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c
index 74519ef18e..7e2f090ba4 100644
--- a/driver/tcpm/tcpci.c
+++ b/driver/tcpm/tcpci.c
@@ -1046,6 +1046,95 @@ const struct usb_mux_driver tcpci_tcpm_usb_mux_driver = {
#endif /* CONFIG_USB_PD_TCPM_MUX */
+#ifdef CONFIG_CMD_TCPCI_DUMP
+struct tcpci_reg {
+ const char *name;
+ uint8_t size;
+};
+
+#define TCPCI_REG(reg_name, reg_size) \
+ [reg_name] = { .name = #reg_name, .size = (reg_size) }
+
+static const struct tcpci_reg tcpci_regs[] = {
+ TCPCI_REG(TCPC_REG_VENDOR_ID, 2),
+ TCPCI_REG(TCPC_REG_PRODUCT_ID, 2),
+ TCPCI_REG(TCPC_REG_BCD_DEV, 2),
+ TCPCI_REG(TCPC_REG_TC_REV, 2),
+ TCPCI_REG(TCPC_REG_PD_REV, 2),
+ TCPCI_REG(TCPC_REG_PD_INT_REV, 2),
+ TCPCI_REG(TCPC_REG_ALERT, 2),
+ TCPCI_REG(TCPC_REG_ALERT_MASK, 2),
+ TCPCI_REG(TCPC_REG_CONFIG_STD_OUTPUT, 1),
+ TCPCI_REG(TCPC_REG_TCPC_CTRL, 1),
+ TCPCI_REG(TCPC_REG_ROLE_CTRL, 1),
+ TCPCI_REG(TCPC_REG_FAULT_CTRL, 1),
+ TCPCI_REG(TCPC_REG_POWER_CTRL, 1),
+ TCPCI_REG(TCPC_REG_CC_STATUS, 1),
+ TCPCI_REG(TCPC_REG_POWER_STATUS, 1),
+ TCPCI_REG(TCPC_REG_FAULT_STATUS, 1),
+ TCPCI_REG(TCPC_REG_ALERT_EXT, 1),
+ TCPCI_REG(TCPC_REG_DEV_CAP_1, 2),
+ TCPCI_REG(TCPC_REG_DEV_CAP_2, 2),
+ TCPCI_REG(TCPC_REG_STD_INPUT_CAP, 1),
+ TCPCI_REG(TCPC_REG_STD_OUTPUT_CAP, 1),
+ TCPCI_REG(TCPC_REG_CONFIG_EXT_1, 1),
+ TCPCI_REG(TCPC_REG_MSG_HDR_INFO, 1),
+ TCPCI_REG(TCPC_REG_RX_DETECT, 1),
+ TCPCI_REG(TCPC_REG_RX_BYTE_CNT, 1),
+ TCPCI_REG(TCPC_REG_RX_BUF_FRAME_TYPE, 1),
+ TCPCI_REG(TCPC_REG_TRANSMIT, 1),
+ TCPCI_REG(TCPC_REG_VBUS_VOLTAGE, 2),
+ TCPCI_REG(TCPC_REG_VBUS_SINK_DISCONNECT_THRESH, 2),
+ TCPCI_REG(TCPC_REG_VBUS_STOP_DISCHARGE_THRESH, 2),
+ TCPCI_REG(TCPC_REG_VBUS_VOLTAGE_ALARM_HI_CFG, 2),
+ TCPCI_REG(TCPC_REG_VBUS_VOLTAGE_ALARM_LO_CFG, 2),
+};
+
+static int command_tcpci_dump(int argc, char **argv)
+{
+ int port;
+ int i;
+ int val;
+
+ if (argc < 2)
+ return EC_ERROR_PARAM_COUNT;
+
+ port = atoi(argv[1]);
+ if ((port < 0) || (port >= board_get_usb_pd_port_count())) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
+ return EC_ERROR_INVAL;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(tcpci_regs); i++) {
+ switch (tcpci_regs[i].size) {
+ case 1:
+ tcpc_read(port, i, &val);
+ ccprintf(" %-38s(0x%02x) = 0x%02x\n",
+ tcpci_regs[i].name, i, (uint8_t)val);
+ break;
+ case 2:
+ tcpc_read16(port, i, &val);
+ ccprintf(" %-38s(0x%02x) = 0x%04x\n",
+ tcpci_regs[i].name, i, (uint16_t)val);
+ break;
+ default:
+ /*
+ * The tcpci_regs[] array is indexed by the register
+ * offset. Unused registers are zero initialized so we
+ * skip any entries that have the size field set to
+ * zero.
+ */
+ break;
+ }
+ }
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(tcpci_dump, command_tcpci_dump, "<Type-C port>",
+ "dump the TCPCI regs");
+#endif /* defined(CONFIG_CMD_TCPCI_DUMP) */
+
+
const struct tcpm_drv tcpci_tcpm_drv = {
.init = &tcpci_tcpm_init,
.release = &tcpci_tcpm_release,
diff --git a/include/config.h b/include/config.h
index 8a0d5edf1f..664a2aa8be 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1281,6 +1281,7 @@
#define CONFIG_CMD_SYSLOCK
#undef CONFIG_CMD_TASK_RESET
#undef CONFIG_CMD_TASKREADY
+#undef CONFIG_CMD_TCPCI_DUMP
#define CONFIG_CMD_TEMP_SENSOR
#define CONFIG_CMD_TIMERINFO
#define CONFIG_CMD_TYPEC