diff options
Diffstat (limited to 'common')
-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 1f8b757929..5195bc7cf1 100644 --- a/common/battery.c +++ b/common/battery.c @@ -237,3 +237,69 @@ DECLARE_CONSOLE_COMMAND(battery, command_battery, "<repeat_count> <sleep_ms>", "Print battery info", NULL); + +#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 */ |