diff options
author | Simon Glass <sjg@chromium.org> | 2023-05-09 10:51:12 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-05-09 22:29:27 +0000 |
commit | 1c5cf0545bafed8317025d903bccb8a4ac498bcf (patch) | |
tree | 46bbed87517c679f457706dd487fc7b21ba41e41 | |
parent | 24d911de09145dcb98644e811b1cdcbf1d3f1e85 (diff) | |
download | chrome-ec-1c5cf0545bafed8317025d903bccb8a4ac498bcf.tar.gz |
charger: Add a way to disable debugging at build time
Add a way to disable some debugging related to the chgstate command. It
is a small, but enough to reclaim 70 bytes for damu.
Use functions to avoid needing #ifdefs in the main body of the code.
Convert the value to a bool while we are here.
BUG=b:218332694
TEST=build on brya and see that the feature is still enabled
$ grep CONFIG_CHARGE_DEBUG build/brya/.config
CONFIG_CHARGE_DEBUG=y
Check damu is the same as before:
*** 12 bytes in flash and 10908 bytes in RAM still available on damu RO ****
Change-Id: I07d2453aa74ab53a29275bba76cd2e8003c5dc14
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4518028
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Commit-Queue: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
-rw-r--r-- | common/charge_state_v2.c | 48 | ||||
-rw-r--r-- | include/config.h | 4 | ||||
-rw-r--r-- | zephyr/Kconfig.charger | 10 | ||||
-rw-r--r-- | zephyr/shim/include/config_chip.h | 5 |
4 files changed, 57 insertions, 10 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index f3127c4330..2b54f5db3b 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -158,7 +158,6 @@ static int battery_seems_disconnected; static int battery_was_removed; static int problems_exist; -static int debugging; static const char *const prob_text[] = { "static update", "set voltage", "set current", "set mode", @@ -167,6 +166,26 @@ static const char *const prob_text[] = { }; BUILD_ASSERT(ARRAY_SIZE(prob_text) == NUM_PROBLEM_TYPES); +#ifdef CONFIG_CHARGE_DEBUG +static bool is_debugging; +#endif + +void set_debugging(bool val) +{ +#ifdef CONFIG_CHARGE_DEBUG + is_debugging = val; +#endif +} + +static bool debugging(void) +{ +#ifdef CONFIG_CHARGE_DEBUG + return is_debugging; +#else + return false; +#endif +} + /* * TODO(crosbug.com/p/27639): When do we decide a problem is real and not * just intermittent? And what do we do about it? @@ -652,7 +671,7 @@ static void base_charge_allocate_input_current_limit(void) db_policy.battery_power_smooth); base_battery_power = MIN(base_battery_power, base_battery_power_max); - if (debugging) { + if (debugging()) { CPRINTF("%s:\n", __func__); CPRINTF("total power: %d\n", total_power); CPRINTF("base battery power: %d (%d)\n", base_battery_power, @@ -684,7 +703,7 @@ static void base_charge_allocate_input_current_limit(void) /* Give everything else to the lid. */ CHG_ALLOCATE(power_lid, total_power, total_power); - if (debugging) + if (debugging()) CPRINTF("power: base %d mW / lid %d mW\n", power_base, power_lid); @@ -697,7 +716,7 @@ static void base_charge_allocate_input_current_limit(void) current_base = db_policy.max_lid_to_base_current; } - if (debugging) + if (debugging()) CPRINTF("current: base %d mA / lid %d mA\n", current_base, current_lid); @@ -705,7 +724,7 @@ static void base_charge_allocate_input_current_limit(void) } else { /* Discharging */ } - if (debugging) + if (debugging()) CPRINTF("====\n"); #endif /* CONFIG_EC_EC_COMM_BATTERY_CLIENT */ } @@ -853,7 +872,7 @@ static void dump_charge_state(void) ccprintf("battery_seems_disconnected = %d\n", battery_seems_disconnected); ccprintf("battery_was_removed = %d\n", battery_was_removed); - ccprintf("debug output = %s\n", debugging ? "on" : "off"); + ccprintf("debug output = %s\n", debugging() ? "on" : "off"); ccprintf("Battery sustainer = %s (%d%% ~ %d%%)\n", battery_sustainer_enabled() ? "on" : "off", sustain_soc.lower, sustain_soc.upper); @@ -924,7 +943,7 @@ static void show_charging_progress(void) CPRINTS("Base battery %d%%", charge_base); #endif - if (debugging) { + if (debugging()) { ccprintf("battery:\n"); print_battery_debug(); ccprintf("charger:\n"); @@ -2862,11 +2881,15 @@ static int command_chgstate(int argc, const char **argv) CHARGE_CONTROL_NORMAL); if (rv) return rv; - } else if (!strcasecmp(argv[1], "debug")) { + } else if (IS_ENABLED(CONFIG_CHARGE_DEBUG) && + !strcasecmp(argv[1], "debug")) { + int val; + if (argc <= 2) return EC_ERROR_PARAM_COUNT; - if (!parse_bool(argv[2], &debugging)) + if (!parse_bool(argv[2], &val)) return EC_ERROR_PARAM2; + set_debugging(val); } else if (!strcasecmp(argv[1], "sustain")) { int lower, upper; @@ -2889,8 +2912,13 @@ static int command_chgstate(int argc, const char **argv) dump_charge_state(); return EC_SUCCESS; } +#ifdef CONFIG_CHARGE_DEBUG +#define CHGSTATE_DEBUG_HELP "|debug on|off" +#else +#define CHGSTATE_DEBUG_HELP "" +#endif DECLARE_CONSOLE_COMMAND(chgstate, command_chgstate, - "[idle|discharge|debug on|off]" + "[idle|discharge" CHGSTATE_DEBUG_HELP "]" "\n[sustain <lower> <upper>]", "Get/set charge state machine status"); diff --git a/include/config.h b/include/config.h index 06d97d358d..1d31fae062 100644 --- a/include/config.h +++ b/include/config.h @@ -1636,6 +1636,10 @@ #undef CONFIG_CMD_CHARGEN #endif #define CONFIG_CMD_CHARGER + +/* Extra debugging info for the charger */ +#define CONFIG_CHARGE_DEBUG + #undef CONFIG_CMD_CHARGER_ADC_AMON_BMON #undef CONFIG_CMD_CHARGER_DUMP #undef CONFIG_CMD_CHARGER_PROFILE_OVERRIDE diff --git a/zephyr/Kconfig.charger b/zephyr/Kconfig.charger index 7c50f9fe31..e147d07a3c 100644 --- a/zephyr/Kconfig.charger +++ b/zephyr/Kconfig.charger @@ -71,6 +71,16 @@ config PLATFORM_EC_CHARGE_STATE_DEBUG this config will allow the EC_CMD_CHARGE_STATE host command to use the CHARGE_STATE_CMD_GET_PARAM command to query the current charge state. +config PLATFORM_EC_CHARGE_DEBUG + bool "Add a debug sub-command to the 'chgstate' command" + depends on PLATFORM_EC_CHARGE_MANAGER + default y + help + Enables the 'chgstate debug' command which allows extra debugging to + be shown when charging, or when a separate base (with battery) is + used. This adds a little to the code size, but can normally be safely + enabled. + config PLATFORM_EC_CMD_PWR_AVG bool "Enable the console command to print power average" depends on PLATFORM_EC_CHARGE_MANAGER diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h index 153b150293..132494d5f4 100644 --- a/zephyr/shim/include/config_chip.h +++ b/zephyr/shim/include/config_chip.h @@ -1153,6 +1153,11 @@ extern char mock_jump_data[CONFIG_PLATFORM_EC_PRESERVED_END_OF_RAM_SIZE]; #define CONFIG_CHARGE_STATE_DEBUG #endif +#undef CONFIG_CHARGE_DEBUG +#ifdef CONFIG_PLATFORM_EC_CHARGE_DEBUG +#define CONFIG_CHARGE_DEBUG +#endif + #undef CONFIG_CMD_PWR_AVG #ifdef CONFIG_PLATFORM_EC_CMD_PWR_AVG #define CONFIG_CMD_PWR_AVG |