From 30287d4757f754d1feeebf45ea0af914eef60ead Mon Sep 17 00:00:00 2001 From: Ryan Zhang Date: Fri, 1 Sep 2017 14:12:57 +0800 Subject: [PATCH] charger: Add CONFIG_CHARGE_STATE_DEBUG Servo / Suzy-Q related debugging methods is a big challenge in factory especially after servo debug header is removed. Expose some information to OS from EC will do a great help for massive production. + expose charge/battery related state to ectool 1. chg_ctl_mode 2. manual_mode 3. battery_seems_to_be_dead 4. battery_seems_to_be_disconnected 5. battery_was_removed 6. disch_on_ac (learn mode state) BUG=b:65265543 BRANCH=master TEST=`ectool chargestate param 0x20000~0x20006 get correct state` Change-Id: Ic2ed38e2eb9def01be29729fa1fe1959eb73fe43 Signed-off-by: Ryan Zhang Reviewed-on: https://chromium-review.googlesource.com/646412 Reviewed-by: Shawn N --- common/charge_state_v2.c | 36 ++++++++++++++++++++++++++++++++++++ include/charge_state_v2.h | 11 +++++++++++ include/config.h | 6 ++++++ include/ec_commands.h | 9 +++++++++ 4 files changed, 62 insertions(+) diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 5f5db0be47..61dbaf21a5 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -1208,6 +1208,14 @@ static int charge_command_charge_state(struct host_cmd_handler_args *args) rv = charger_profile_override_get_param( in->get_param.param, &val); } else +#endif +#ifdef CONFIG_CHARGE_STATE_DEBUG + /* debug params */ + if (in->get_param.param >= CS_PARAM_DEBUG_MIN && + in->get_param.param <= CS_PARAM_DEBUG_MAX) { + rv = charge_get_charge_state_debug( + in->get_param.param, &val); + } else #endif /* standard params */ switch (in->get_param.param) { @@ -1357,3 +1365,31 @@ static int command_chgstate(int argc, char **argv) DECLARE_CONSOLE_COMMAND(chgstate, command_chgstate, "[idle|discharge|debug on|off]", "Get/set charge state machine status"); + +#ifdef CONFIG_CHARGE_STATE_DEBUG +int charge_get_charge_state_debug(int param, uint32_t *value) +{ + switch (param) { + case CS_PARAM_DEBUG_CTL_MODE: + *value = chg_ctl_mode; + break; + case CS_PARAM_DEBUG_MANUAL_MODE: + *value = manual_mode; + break; + case CS_PARAM_DEBUG_SEEMS_DEAD: + *value = battery_seems_to_be_dead; + break; + case CS_PARAM_DEBUG_SEEMS_DISCONNECTED: + *value = battery_seems_to_be_disconnected; + break; + case CS_PARAM_DEBUG_BATT_REMOVED: + *value = battery_was_removed; + break; + default: + *value = 0; + return EC_ERROR_INVAL; + } + + return EC_SUCCESS; +} +#endif diff --git a/include/charge_state_v2.h b/include/charge_state_v2.h index e908758371..1c85323a60 100644 --- a/include/charge_state_v2.h +++ b/include/charge_state_v2.h @@ -50,5 +50,16 @@ struct charge_state_data { */ int charge_set_input_current_limit(int ma, int mv); +/* + * Expose charge/battery related state + * + * @param param command to get corresponding data + * @param value the corresponding data + * @return EC_SUCCESS or error + */ +#ifdef CONFIG_CHARGE_STATE_DEBUG +int charge_get_charge_state_debug(int param, uint32_t *value); +#endif /* CONFIG_CHARGE_STATE_DEBUG */ + #endif /* __CROS_EC_CHARGE_STATE_V2_H */ diff --git a/include/config.h b/include/config.h index 4c47b4634d..2df3bdd413 100644 --- a/include/config.h +++ b/include/config.h @@ -318,6 +318,12 @@ */ #undef CONFIG_BATTERY_LEVEL_NEAR_FULL +/* + * Expose some data when it is needed. + * For example, battery disconnect state + */ +#undef CONFIG_CHARGE_STATE_DEBUG + /* Include support for Bluetooth LE */ #undef CONFIG_BLUETOOTH_LE diff --git a/include/ec_commands.h b/include/ec_commands.h index 633640defd..413e2afb39 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -3473,6 +3473,15 @@ enum charge_state_params { CS_PARAM_CUSTOM_PROFILE_MIN = 0x10000, CS_PARAM_CUSTOM_PROFILE_MAX = 0x1ffff, + /* Range for CONFIG_CHARGE_STATE_DEBUG params */ + CS_PARAM_DEBUG_MIN = 0x20000, + CS_PARAM_DEBUG_CTL_MODE = 0x20000, + CS_PARAM_DEBUG_MANUAL_MODE, + CS_PARAM_DEBUG_SEEMS_DEAD, + CS_PARAM_DEBUG_SEEMS_DISCONNECTED, + CS_PARAM_DEBUG_BATT_REMOVED, + CS_PARAM_DEBUG_MAX = 0x2ffff, + /* Other custom param ranges go here... */ };