From 4a9170c8c4c4f7e82d48ba3d0a328c96a1882fd3 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Fri, 1 Mar 2019 11:30:30 -0800 Subject: usbpd: Remove pd_state_names if not used Currently, pd_state_names is included in all builds. This change makes it included only in such builds as: - CONFIG_USB_PD_DEBUG_LEVEL is defined to 1+ OR - CONFIG_USB_PD_DEBUG_LEVEL is not defined The 'pd dump' console command will continue to print & change debug level in a normal build. If CONFIG_USB_PD_DEBUG_LEVEL is explicitly defined, the command will only print the current debug level (as expected). Enum pd_state doesn't have to be different between different configurations (DRP, no-DRP, etc.). Actually, we should just stick to a single definition (and append more to the tail to grow) so that the consumers can translate the numbers to the names. After the change with CONFIG_USB_PD_DEBUG_LEVEL = 0, 93520 Mar 11 12:53 build/flapjack/RO/ec.RO.flat 104836 Mar 11 12:54 build/flapjack/RW/ec.RW.flat After the change with CONFIG_USB_PD_DEBUG_LEVEL = 2, 94672 Mar 11 12:54 build/flapjack/RO/ec.RO.flat 106004 Mar 11 12:55 build/flapjack/RW/ec.RW.flat Whatever script, test, daemon, etc. is relying on the text representation of the PD state needs to be fixed as well. Signed-off-by: Daisuke Nojiri BUG=chromium:937427 BRANCH=none TEST=buildall. Verify 'pd dump' works like bofore in a normal build. Change-Id: Id66634240050103253d69f257ee6f717252fc417 Reviewed-on: https://chromium-review.googlesource.com/1496770 Commit-Ready: Daisuke Nojiri Tested-by: Daisuke Nojiri Reviewed-by: Diana Z --- common/usb_pd_protocol.c | 41 +++++++++++++++++++++-------------------- include/usb_pd.h | 16 ---------------- 2 files changed, 21 insertions(+), 36 deletions(-) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 2615d9089e..34e91ae2f7 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -254,29 +254,21 @@ static struct pd_protocol { #ifdef CONFIG_COMMON_RUNTIME static const char * const pd_state_names[] = { "DISABLED", "SUSPENDED", -#ifdef CONFIG_USB_PD_DUAL_ROLE "SNK_DISCONNECTED", "SNK_DISCONNECTED_DEBOUNCE", "SNK_HARD_RESET_RECOVER", "SNK_DISCOVERY", "SNK_REQUESTED", "SNK_TRANSITION", "SNK_READY", "SNK_SWAP_INIT", "SNK_SWAP_SNK_DISABLE", "SNK_SWAP_SRC_DISABLE", "SNK_SWAP_STANDBY", "SNK_SWAP_COMPLETE", -#endif /* CONFIG_USB_PD_DUAL_ROLE */ "SRC_DISCONNECTED", "SRC_DISCONNECTED_DEBOUNCE", "SRC_HARD_RESET_RECOVER", "SRC_STARTUP", "SRC_DISCOVERY", "SRC_NEGOCIATE", "SRC_ACCEPTED", "SRC_POWERED", "SRC_TRANSITION", "SRC_READY", "SRC_GET_SNK_CAP", "DR_SWAP", -#ifdef CONFIG_USB_PD_DUAL_ROLE "SRC_SWAP_INIT", "SRC_SWAP_SNK_DISABLE", "SRC_SWAP_SRC_DISABLE", "SRC_SWAP_STANDBY", -#ifdef CONFIG_USBC_VCONN_SWAP "VCONN_SWAP_SEND", "VCONN_SWAP_INIT", "VCONN_SWAP_READY", -#endif /* CONFIG_USBC_VCONN_SWAP */ -#endif /* CONFIG_USB_PD_DUAL_ROLE */ "SOFT_RESET", "HARD_RESET_SEND", "HARD_RESET_EXECUTE", "BIST_RX", "BIST_TX", -#ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE "DRP_AUTO_TOGGLE", -#endif }; BUILD_ASSERT(ARRAY_SIZE(pd_state_names) == PD_STATE_COUNT); #endif @@ -772,7 +764,7 @@ static inline void set_state(int port, enum pd_states next_state) disable_sleep(SLEEP_MASK_USB_PD); #endif - if (debug_level >= 1) + if (debug_level > 0) CPRINTF("C%d st%d %s\n", port, next_state, pd_state_names[next_state]); else @@ -4627,20 +4619,21 @@ static int command_pd(int argc, char **argv) return EC_ERROR_PARAM_COUNT; if (!strcasecmp(argv[1], "dump")) { -#ifndef CONFIG_USB_PD_DEBUG_LEVEL - int level; - if (argc >= 3) { - level = strtoi(argv[2], &e, 10); +#ifdef CONFIG_USB_PD_DEBUG_LEVEL + return EC_ERROR_PARAM2; +#else + int level = strtoi(argv[2], &e, 10); if (*e) return EC_ERROR_PARAM2; debug_level = level; - } else #endif - ccprintf("dump level: %d\n", debug_level); + } + ccprintf("debug=%d\n", debug_level); return EC_SUCCESS; } + #ifdef CONFIG_CMD_PD #ifdef CONFIG_CMD_PD_DEV_DUMP_INFO else if (!strncasecmp(argv[1], "rwhashtable", 3)) { @@ -4820,13 +4813,15 @@ static int command_pd(int argc, char **argv) #endif if (!strncasecmp(argv[2], "state", 5)) { ccprintf("Port C%d CC%d, %s - Role: %s-%s%s " - "State: %s, Flags: 0x%04x\n", + "State: %d(%s), Flags: 0x%04x\n", port, pd[port].polarity + 1, pd_comm_is_enabled(port) ? "Ena" : "Dis", pd[port].power_role == PD_ROLE_SOURCE ? "SRC" : "SNK", pd[port].data_role == PD_ROLE_DFP ? "DFP" : "UFP", (pd[port].flags & PD_FLAGS_VCONN_ON) ? "-VC" : "", - pd_state_names[pd[port].task_state], + pd[port].task_state, + debug_level > 0 ? + pd_state_names[pd[port].task_state] : "", pd[port].flags); } else { return EC_ERROR_PARAM1; @@ -4963,10 +4958,16 @@ static int hc_usb_pd_control(struct host_cmd_handler_args *args) ((pd[p->port].flags & PD_FLAGS_PARTNER_EXTPOWER) ? PD_CTRL_RESP_ROLE_EXT_POWERED : 0); r_v2->polarity = pd[p->port].polarity; - strzcpy(r_v2->state, - pd_state_names[pd[p->port].task_state], - sizeof(r_v2->state)); + + if (debug_level > 0) + strzcpy(r_v2->state, + pd_state_names[pd[p->port].task_state], + sizeof(r_v2->state)); + else + r_v2->state[0] = '\0'; + r_v2->cc_state = pd[p->port].cc_state; + if (args->version == 1) args->response_size = sizeof(*r_v1); else diff --git a/include/usb_pd.h b/include/usb_pd.h index 7cc1a58021..435b2c6e3f 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -657,7 +657,6 @@ struct pd_policy { enum pd_states { PD_STATE_DISABLED, PD_STATE_SUSPENDED, -#ifdef CONFIG_USB_PD_DUAL_ROLE PD_STATE_SNK_DISCONNECTED, PD_STATE_SNK_DISCONNECTED_DEBOUNCE, PD_STATE_SNK_HARD_RESET_RECOVER, @@ -665,14 +664,11 @@ enum pd_states { PD_STATE_SNK_REQUESTED, PD_STATE_SNK_TRANSITION, PD_STATE_SNK_READY, - PD_STATE_SNK_SWAP_INIT, PD_STATE_SNK_SWAP_SNK_DISABLE, PD_STATE_SNK_SWAP_SRC_DISABLE, PD_STATE_SNK_SWAP_STANDBY, PD_STATE_SNK_SWAP_COMPLETE, -#endif /* CONFIG_USB_PD_DUAL_ROLE */ - PD_STATE_SRC_DISCONNECTED, PD_STATE_SRC_DISCONNECTED_DEBOUNCE, PD_STATE_SRC_HARD_RESET_RECOVER, @@ -685,31 +681,19 @@ enum pd_states { PD_STATE_SRC_READY, PD_STATE_SRC_GET_SINK_CAP, PD_STATE_DR_SWAP, - -#ifdef CONFIG_USB_PD_DUAL_ROLE PD_STATE_SRC_SWAP_INIT, PD_STATE_SRC_SWAP_SNK_DISABLE, PD_STATE_SRC_SWAP_SRC_DISABLE, PD_STATE_SRC_SWAP_STANDBY, - -#ifdef CONFIG_USBC_VCONN_SWAP PD_STATE_VCONN_SWAP_SEND, PD_STATE_VCONN_SWAP_INIT, PD_STATE_VCONN_SWAP_READY, -#endif /* CONFIG_USBC_VCONN_SWAP */ -#endif /* CONFIG_USB_PD_DUAL_ROLE */ - PD_STATE_SOFT_RESET, PD_STATE_HARD_RESET_SEND, PD_STATE_HARD_RESET_EXECUTE, -#ifdef CONFIG_COMMON_RUNTIME PD_STATE_BIST_RX, PD_STATE_BIST_TX, -#endif - -#ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE PD_STATE_DRP_AUTO_TOGGLE, -#endif /* Number of states. Not an actual state. */ PD_STATE_COUNT, }; -- cgit v1.2.1