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 /common/battery.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 'common/battery.c')
-rw-r--r-- | common/battery.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/common/battery.c b/common/battery.c index b6e79bb383..20baa1e431 100644 --- a/common/battery.c +++ b/common/battery.c @@ -299,3 +299,69 @@ int battery_is_cut_off(void) return 0; /* Always return NOT cut off */ } #endif /* CONFIG_BATTERY_CUT_OFF */ + +#ifdef CONFIG_BATTERY_VENDOR_PARAM +static int console_command_battery_vendor_param(int argc, char **argv) +{ + uint32_t param; + uint32_t value; + char *e; + int rv; + + if (argc < 2) + return EC_ERROR_INVAL; + + param = strtoi(argv[1], &e, 0); + if (*e) { + ccputs("Invalid param\n"); + return EC_ERROR_INVAL; + } + + if (argc > 2) { + value = strtoi(argv[2], &e, 0); + if (*e) { + ccputs("Invalid value\n"); + return EC_ERROR_INVAL; + } + rv = battery_set_vendor_param(param, value); + if (rv != EC_SUCCESS) + return rv; + } + + rv = battery_get_vendor_param(param, &value); + if (rv != EC_SUCCESS) + return rv; + + ccprintf("0x%08x\n", value); + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(battparam, console_command_battery_vendor_param, + "<param> [value]", + "Get or set battery vendor parameters", + NULL); + +static int host_command_battery_vendor_param(struct host_cmd_handler_args *args) +{ + int rv; + const struct ec_params_battery_vendor_param *p = args->params; + struct ec_response_battery_vendor_param *r = args->response; + + args->response_size = sizeof(*r); + + if (p->mode != BATTERY_VENDOR_PARAM_MODE_GET && + p->mode != BATTERY_VENDOR_PARAM_MODE_SET) + return EC_RES_INVALID_PARAM; + + if (p->mode == BATTERY_VENDOR_PARAM_MODE_SET) { + rv = battery_set_vendor_param(p->param, p->value); + if (rv != EC_SUCCESS) + return rv; + } + + rv = battery_get_vendor_param(p->param, &r->value); + return rv; +} +DECLARE_HOST_COMMAND(EC_CMD_BATTERY_VENDOR_PARAM, + host_command_battery_vendor_param, + EC_VER_MASK(0)); +#endif /* CONFIG_BATTERY_VENDOR_PARAM */ |