summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew Davenport <ddavenport@google.com>2021-11-09 16:46:58 -0700
committerCommit Bot <commit-bot@chromium.org>2021-11-12 22:17:27 +0000
commit98264cad7719487bf3ecbc4f45b80e900b174cf8 (patch)
treecccea390c0b0ff80e05915328db5f9cee72c9b36
parent7a544b16076115135a146a343d6d8b5c8cbebadb (diff)
downloadchrome-ec-98264cad7719487bf3ecbc4f45b80e900b174cf8.tar.gz
ectool: Add 'tsv' parameter to usbpdmuxinfo
The 'tsv' parameter can be used to output in tab-separated-value form, which is intended to be parsed in scripts or programs. Column definitions can be accessed in the ectool help command. BRANCH=none BUG=b:205858702 TEST=Run `ectool usbpdmuxinfo` with various arguments Change-Id: Ifcf3eb76815e071b2e43cf244a5345a40fc6771e Signed-off-by: Drew Davenport <ddavenport@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3278632 Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Drew Davenport <ddavenport@chromium.org> Tested-by: Drew Davenport <ddavenport@chromium.org>
-rw-r--r--util/ectool.c62
1 files changed, 49 insertions, 13 deletions
diff --git a/util/ectool.c b/util/ectool.c
index 8d4963c3d5..6e0a1f91cb 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -337,8 +337,12 @@ const char help_str[] =
"[toggle|toggle-off|sink|source] [none|usb|dp|dock] "
"[dr_swap|pr_swap|vconn_swap]>\n"
" Control USB PD/type-C [deprecated]\n"
- " usbpdmuxinfo\n"
- " Get USB-C SS mux info\n"
+ " usbpdmuxinfo [tsv]\n"
+ " Get USB-C SS mux info.\n"
+ " tsv: Output as tab separated values. Columns are defined "
+ "as:\n"
+ " Port, USB enabled, DP enabled, Polarity, HPD IRQ, "
+ "HPD LVL\n"
" usbpdpower [port]\n"
" Get USB PD power information\n"
" version\n"
@@ -6377,6 +6381,14 @@ int cmd_usb_pd_mux_info(int argc, char *argv[])
struct ec_params_usb_pd_mux_info p;
struct ec_response_usb_pd_mux_info r;
int num_ports, rv, i;
+ bool tsv = false;
+
+ if (argc == 2 && (strncmp(argv[1], "tsv", 4) == 0)) {
+ tsv = true;
+ } else if (argc >= 2) {
+ fprintf(stderr, "Usage: %s [tsv]\n", argv[0]);
+ return -1;
+ }
rv = ec_command(EC_CMD_USB_PD_PORTS, 0, NULL, 0,
ec_inbuf, ec_max_insize);
@@ -6392,17 +6404,41 @@ int cmd_usb_pd_mux_info(int argc, char *argv[])
if (rv < 0)
return rv;
- printf("Port %d: ", i);
- printf("USB=%d ", !!(r.flags & USB_PD_MUX_USB_ENABLED));
- printf("DP=%d ", !!(r.flags & USB_PD_MUX_DP_ENABLED));
- printf("POLARITY=%s ", r.flags & USB_PD_MUX_POLARITY_INVERTED ?
- "INVERTED" : "NORMAL");
- printf("HPD_IRQ=%d ", !!(r.flags & USB_PD_MUX_HPD_IRQ));
- printf("HPD_LVL=%d ", !!(r.flags & USB_PD_MUX_HPD_LVL));
- printf("SAFE=%d ", !!(r.flags & USB_PD_MUX_SAFE_MODE));
- printf("TBT=%d ", !!(r.flags & USB_PD_MUX_TBT_COMPAT_ENABLED));
- printf("USB4=%d ", !!(r.flags & USB_PD_MUX_USB4_ENABLED));
- printf("\n");
+ if (tsv) {
+ /*
+ * Machine-readable tab-separated values. This set of
+ * values is append-only. Columns should not be removed
+ * or repurposed. Update the documentation above if new
+ * columns are added.
+ */
+ printf("%d\t", i);
+ printf("%d\t", !!(r.flags & USB_PD_MUX_USB_ENABLED));
+ printf("%d\t", !!(r.flags & USB_PD_MUX_DP_ENABLED));
+ printf("%s\t",
+ r.flags & USB_PD_MUX_POLARITY_INVERTED ?
+ "INVERTED" : "NORMAL");
+ printf("%d\t", !!(r.flags & USB_PD_MUX_HPD_IRQ));
+ printf("%d\n", !!(r.flags & USB_PD_MUX_HPD_LVL));
+ } else {
+ /* Human-readable mux info. */
+ printf("Port %d: ", i);
+ printf("USB=%d ",
+ !!(r.flags & USB_PD_MUX_USB_ENABLED));
+ printf("DP=%d ", !!(r.flags & USB_PD_MUX_DP_ENABLED));
+ printf("POLARITY=%s",
+ r.flags & USB_PD_MUX_POLARITY_INVERTED ?
+ "INVERTED" : "NORMAL");
+ printf("HPD_IRQ=%d ",
+ !!(r.flags & USB_PD_MUX_HPD_IRQ));
+ printf("HPD_LVL=%d ",
+ !!(r.flags & USB_PD_MUX_HPD_LVL));
+ printf("SAFE=%d ", !!(r.flags & USB_PD_MUX_SAFE_MODE));
+ printf("TBT=%d ",
+ !!(r.flags & USB_PD_MUX_TBT_COMPAT_ENABLED));
+ printf("USB4=%d ",
+ !!(r.flags & USB_PD_MUX_USB4_ENABLED));
+ printf("\n");
+ }
}
return 0;