summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/battery.c66
-rw-r--r--include/battery.h22
-rw-r--r--include/config.h7
-rw-r--r--include/ec_commands.h27
-rw-r--r--util/ectool.c57
5 files changed, 179 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 */
diff --git a/include/battery.h b/include/battery.h
index 61c9dee20f..9743a451e5 100644
--- a/include/battery.h
+++ b/include/battery.h
@@ -268,4 +268,26 @@ int battery_device_chemistry(char *dest, int size);
*/
int battery_manufacturer_date(int *year, int *month, int *day);
+/**
+ * Read battery vendor parameter.
+ *
+ * Vendor parameter handlers are implemented in a board-specific battery.c
+ *
+ * @param param Parameter identifier.
+ * @param value Location to store retrieved value.
+ * @return non-zero if error.
+ */
+int battery_get_vendor_param(uint32_t param, uint32_t *value);
+
+/**
+ * Write battery vendor parameter.
+ *
+ * Vendor parameter handlers are implemented in a board-specific battery.c
+ *
+ * @param param Parameter identifier.
+ * @param value Value to write to the battery.
+ * @return non-zero if error.
+ */
+int battery_set_vendor_param(uint32_t param, uint32_t value);
+
#endif /* __CROS_EC_BATTERY_H */
diff --git a/include/config.h b/include/config.h
index 9b8d5e362c..c49e8d244a 100644
--- a/include/config.h
+++ b/include/config.h
@@ -126,6 +126,13 @@
*/
#undef CONFIG_BATTERY_VENDOR_PARAMS
+/*
+ * The board-specific battery.c implements get and set functions to read and
+ * write arbirary vendor-specific parameters stored in the battery.
+ * See include/battery.h for prototypes.
+ */
+#undef CONFIG_BATTERY_VENDOR_PARAM
+
/*****************************************************************************/
/*
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 14efc3eb68..04cc3e5e79 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1879,6 +1879,33 @@ struct ec_params_sb_wr_block {
uint16_t data[32];
} __packed;
+
+/*****************************************************************************/
+/* Battery vendor parameters
+ *
+ * Get or set vendor-specific parameters in the battery. Implementations may
+ * differ between boards or batteries. On a set operation, the response
+ * contains the actual value set, which may be rounded or clipped from the
+ * requested value.
+ */
+
+#define EC_CMD_BATTERY_VENDOR_PARAM 0xb4
+
+enum ec_battery_vendor_param_mode {
+ BATTERY_VENDOR_PARAM_MODE_GET = 0,
+ BATTERY_VENDOR_PARAM_MODE_SET,
+};
+
+struct ec_params_battery_vendor_param {
+ uint32_t param;
+ uint32_t value;
+ uint8_t mode;
+} __packed;
+
+struct ec_response_battery_vendor_param {
+ uint32_t value;
+} __packed;
+
/*****************************************************************************/
/* System commands */
diff --git a/util/ectool.c b/util/ectool.c
index abe05e7dcb..f8d93ec25d 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"
@@ -2944,6 +2946,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;
@@ -3541,6 +3597,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},
{"chargedump", cmd_charge_dump},