From 2bb7b28c8c85f4fef18730eb835325775c2fb8c5 Mon Sep 17 00:00:00 2001 From: Vic Yang Date: Mon, 10 Sep 2012 16:34:41 +0800 Subject: Add host command to dump charge state machine context This is a temporary debug command and will be reverted once unnecessary. BUG=chrome-os-partner:12801 TEST=Manual BRANCH=link Original-Change-Id: Ib1b4221db31ed2521762ee32748bd9d2e177229d Signed-off-by: Vic Yang Reviewed-on: https://gerrit.chromium.org/gerrit/32696 Reviewed-by: Rong Chang (cherry picked from commit c23dc460731cac6f6377a026b9986fc20527feb9) Change-Id: I394e745c6bbd672213667972f054db69b46a15ea Signed-off-by: Vic Yang Reviewed-on: https://gerrit.chromium.org/gerrit/33034 --- common/charge_state.c | 17 +++++++++++++++++ include/ec_commands.h | 10 ++++++++++ util/ectool.c | 23 +++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/common/charge_state.c b/common/charge_state.c index 5c02f59253..caa9caa6b6 100644 --- a/common/charge_state.c +++ b/common/charge_state.c @@ -707,3 +707,20 @@ static int charge_command_force_idle(struct host_cmd_handler_args *args) } DECLARE_HOST_COMMAND(EC_CMD_CHARGE_FORCE_IDLE, charge_command_force_idle, EC_VER_MASK(0)); + +static int charge_command_dump(struct host_cmd_handler_args *args) +{ + char *dest = (char *)args->response; + + if (system_is_locked()) + return EC_RES_ACCESS_DENIED; + + ASSERT(sizeof(task_ctx) <= args->response_max); + + memcpy(dest, &task_ctx, sizeof(task_ctx)); + args->response_size = sizeof(task_ctx); + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_CHARGE_DUMP, charge_command_dump, + EC_VER_MASK(0)); diff --git a/include/ec_commands.h b/include/ec_commands.h index ecf0f1394e..61b9457594 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -971,6 +971,16 @@ struct ec_params_force_idle { */ #define EC_CMD_BATTERY_CUT_OFF 0x99 +/*****************************************************************************/ +/* Temporary debug commands. TODO: remove this crosbug.com/p/13849 */ + +/* + * Dump charge state machine context. + * + * Response is a binary dump of charge state machine context. + */ +#define EC_CMD_CHARGE_DUMP 0xa0 + /*****************************************************************************/ /* System commands */ diff --git a/util/ectool.c b/util/ectool.c index 0623dc7e7f..898a3ddc20 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -34,6 +34,8 @@ const char help_str[] = " Prints battery info\n" " batterycutoff\n" " Cut off battery output power\n" + " chargedump\n" + " Dump the context of charge state machine\n" " chargeforceidle\n" " Force charge state machine to stop in idle mode\n" " chipinfo\n" @@ -1797,6 +1799,26 @@ int cmd_charge_force_idle(int argc, char *argv[]) } +int cmd_charge_dump(int argc, char *argv[]) +{ + unsigned char out[EC_HOST_PARAM_SIZE]; + int rv, i; + + rv = ec_command(EC_CMD_CHARGE_DUMP, 0, NULL, 0, out, sizeof(out)); + + if (rv < 0) + return rv; + + for (i = 0; i < rv; ++i) { + printf("%02X", out[i]); + if ((i & 31) == 31) + printf("\n"); + } + printf("\n"); + return 0; +} + + int cmd_gpio_get(int argc, char *argv[]) { struct ec_params_gpio_get p; @@ -2157,6 +2179,7 @@ const struct command commands[] = { {"backlight", cmd_lcd_backlight}, {"battery", cmd_battery}, {"batterycutoff", cmd_battery_cut_off}, + {"chargedump", cmd_charge_dump}, {"chargeforceidle", cmd_charge_force_idle}, {"chipinfo", cmd_chipinfo}, {"cmdversions", cmd_cmdversions}, -- cgit v1.2.1