summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Palatin <vpalatin@chromium.org>2012-11-07 09:39:33 -0800
committerVincent Palatin <vpalatin@chromium.org>2012-11-07 22:26:39 -0800
commitd07166aa819e437a28cd84531ca3f6f6fcdfd144 (patch)
tree250b0ffbff997971e8fec75f21bcd89dc87449e2
parenteb955e728a0765e0e34291b2bbc0422e1dc2db4d (diff)
downloadchrome-ec-d07166aa819e437a28cd84531ca3f6f6fcdfd144.tar.gz
link: allow to decrease maximum battery charging current
Add an interface to allow the CPU to cap the maximum battery charging current. The maximum is removed every time the machine goes to S3 or S5. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=link BUG=chrome-os-partner:16041 TEST=on Link, plug AC to charge the battery, then run "ectool chargecurrentlimit 1200" and see the charging current in "power-supply-info" decreasing to 1.2 A. Change-Id: I3490ac8134d9dde8f41809faa440360886dd208c Reviewed-on: https://gerrit.chromium.org/gerrit/37530 Reviewed-by: Sameer Nanda <snanda@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Rong Chang <rongchang@chromium.org>
-rw-r--r--common/charge_state.c23
-rw-r--r--include/ec_commands.h9
-rw-r--r--util/ectool.c26
3 files changed, 58 insertions, 0 deletions
diff --git a/common/charge_state.c b/common/charge_state.c
index b1219c8089..60f4c4de79 100644
--- a/common/charge_state.c
+++ b/common/charge_state.c
@@ -39,6 +39,8 @@ static const char * const state_name[] = POWER_STATE_NAME_TABLE;
static int state_machine_force_idle = 0;
+static unsigned user_current_limit = -1U;
+
/* Current power state context */
static struct power_state_context task_ctx;
@@ -276,6 +278,8 @@ static int state_common(struct power_state_context *ctx)
if (batt->desired_current > CONFIG_CHARGING_CURRENT_LIMIT)
batt->desired_current = CONFIG_CHARGING_CURRENT_LIMIT;
#endif
+ if (batt->desired_current > user_current_limit)
+ batt->desired_current = user_current_limit;
rv = battery_get_battery_mode(&d);
if (rv) {
@@ -837,3 +841,22 @@ static int charge_command_dump(struct host_cmd_handler_args *args)
}
DECLARE_HOST_COMMAND(EC_CMD_CHARGE_DUMP, charge_command_dump,
EC_VER_MASK(0));
+
+static int reset_current_limit(void)
+{
+ user_current_limit = -1;
+ return EC_SUCCESS;
+}
+DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, reset_current_limit, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, reset_current_limit, HOOK_PRIO_DEFAULT);
+
+static int charge_command_current_limit(struct host_cmd_handler_args *args)
+{
+ const struct ec_params_current_limit *p = args->params;
+
+ user_current_limit = p->limit;
+
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_CHARGE_CURRENT_LIMIT, charge_command_current_limit,
+ EC_VER_MASK(0));
diff --git a/include/ec_commands.h b/include/ec_commands.h
index 32fc237e40..1507b752db 100644
--- a/include/ec_commands.h
+++ b/include/ec_commands.h
@@ -1051,6 +1051,15 @@ struct ec_params_force_idle {
*/
#define EC_CMD_CHARGE_DUMP 0xa0
+/*
+ * Set maximum battery charging current.
+ */
+#define EC_CMD_CHARGE_CURRENT_LIMIT 0xa1
+
+struct ec_params_current_limit {
+ uint32_t limit;
+} __packed;
+
/*****************************************************************************/
/* System commands */
diff --git a/util/ectool.c b/util/ectool.c
index ec74c3644f..f83ae0f3d5 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -31,6 +31,8 @@ const char help_str[] =
" Enable/disable LCD backlight\n"
" battery\n"
" Prints battery info\n"
+ " chargecurrentlimit\n"
+ " Set the maximum battery charging current\n"
" chargedump\n"
" Dump the context of charge state machine\n"
" chargeforceidle\n"
@@ -1962,6 +1964,29 @@ int cmd_lcd_backlight(int argc, char *argv[])
}
+int cmd_charge_current_limit(int argc, char *argv[])
+{
+ struct ec_params_current_limit p;
+ int rv;
+ char *e;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <max_current_mA>\n", argv[0]);
+ return -1;
+ }
+
+ p.limit = strtol(argv[1], &e, 0);
+ if (e && *e) {
+ fprintf(stderr, "Bad value.\n");
+ return -1;
+ }
+
+ rv = ec_command(EC_CMD_CHARGE_CURRENT_LIMIT, 0, &p, sizeof(p),
+ NULL, 0);
+ return rv;
+}
+
+
int cmd_charge_force_idle(int argc, char *argv[])
{
struct ec_params_force_idle p;
@@ -2476,6 +2501,7 @@ const struct command commands[] = {
{"autofanctrl", cmd_thermal_auto_fan_ctrl},
{"backlight", cmd_lcd_backlight},
{"battery", cmd_battery},
+ {"chargecurrentlimit", cmd_charge_current_limit},
{"chargedump", cmd_charge_dump},
{"chargeforceidle", cmd_charge_force_idle},
{"chipinfo", cmd_chipinfo},