diff options
author | Dave Parker <dparker@chromium.org> | 2014-04-19 14:04:03 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-04-29 03:11:01 +0000 |
commit | 4e1472e3037602beec0eb5849ab76fb055d5a657 (patch) | |
tree | e5ff4c570920aaba20c252f305a431515890579e /util/ectool.c | |
parent | 5aeff69cdcf2c8ed897340c432afcc8a1284b939 (diff) | |
download | chrome-ec-4e1472e3037602beec0eb5849ab76fb055d5a657.tar.gz |
Add host command to set battery vendor parameters
Also adds 'battparam' console command.
BUG=chrome-os-partner:25145
BRANCH=ToT
TEST=Run 'ectool batteryparam set 0 0x1234'
'ectool batteryparam get 0'
and on the console:
'battparam 0'
'battparam 0 0x1234'
on a board that implements parameter 0.
Change-Id: I9cc54d001631f53dd39ae64cfdeececaa1747181
Original-Change-Id: Ib2812f57f2484309d613b23dab12ad43e0417bd2
Signed-off-by: Dave Parker <dparker@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/195824
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/197162
Diffstat (limited to 'util/ectool.c')
-rw-r--r-- | util/ectool.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/util/ectool.c b/util/ectool.c index 4d827f52af..1a1e5d5a43 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -36,6 +36,8 @@ const char help_str[] = " Prints battery info\n" " batterycutoff\n" " Cut off battery output power\n" + " batteryparam\n" + " Read or write board-specific battery parameter\n" " boardversion\n" " Prints the board version\n" " chargecurrentlimit\n" @@ -3325,6 +3327,60 @@ int cmd_battery_cut_off(int argc, char *argv[]) return rv; } +int cmd_battery_vendor_param(int argc, char *argv[]) +{ + struct ec_params_battery_vendor_param p; + struct ec_response_battery_vendor_param r; + char *e; + int rv; + + if (argc < 3) + goto cmd_battery_vendor_param_usage; + + if (!strcasecmp(argv[1], "get")) + p.mode = BATTERY_VENDOR_PARAM_MODE_GET; + else if (!strcasecmp(argv[1], "set")) + p.mode = BATTERY_VENDOR_PARAM_MODE_SET; + else + goto cmd_battery_vendor_param_usage; + + p.param = strtol(argv[2], &e, 0); + if (e && *e) { + fprintf(stderr, "Invalid param.\n"); + goto cmd_battery_vendor_param_usage; + } + + if (p.mode == BATTERY_VENDOR_PARAM_MODE_SET) { + if (argc != 4) { + fprintf(stderr, "Missing value.\n"); + goto cmd_battery_vendor_param_usage; + } + + p.value = strtol(argv[3], &e, 0); + if (e && *e) { + fprintf(stderr, "Invalid value.\n"); + goto cmd_battery_vendor_param_usage; + } + } + + rv = ec_command(EC_CMD_BATTERY_VENDOR_PARAM, 0, &p, sizeof(p), + &r, sizeof(r)); + + if (rv < 0) + return rv; + + printf("0x%08x\n", r.value); + + return 0; + +cmd_battery_vendor_param_usage: + fprintf(stderr, + "Usage:\t %s get <param>\n" + "\t %s set <param> <value>\n", + argv[0], argv[0]); + return -1; +} + int cmd_board_version(int argc, char *argv[]) { struct ec_response_board_version response; @@ -3922,6 +3978,7 @@ const struct command commands[] = { {"backlight", cmd_lcd_backlight}, {"battery", cmd_battery}, {"batterycutoff", cmd_battery_cut_off}, + {"batteryparam", cmd_battery_vendor_param}, {"boardversion", cmd_board_version}, {"chargecurrentlimit", cmd_charge_current_limit}, {"chargecontrol", cmd_charge_control}, |