diff options
author | Louis Yung-Chieh Lo <yjlou@chromium.org> | 2012-08-27 22:14:09 +0800 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-08-28 04:39:56 -0700 |
commit | b0542c587c68cca3fe94bc56865e73310d19f7db (patch) | |
tree | 05269a5facfa658ca59f66c1acfaca84a5080e1f | |
parent | 38454d7a161b28319bfa111e5ca8a89009699ae1 (diff) | |
download | chrome-ec-b0542c587c68cca3fe94bc56865e73310d19f7db.tar.gz |
Support battery cut-off mechanism for factory.
The cut-off command is manufacturer-specific. Thus the logic is implemented
in gas gauge IC code. For those boards using this gas gauge, define
the CONFIG_BATTERY_BQ20Z453 in board.h.
BUG=chrome-os-partner:12962,
BRANCH=snow
Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
TEST=Tested on snow
ectool batterycutoff ; expect system is off immediately
; if AC power is not connected.
Change-Id: Idd290c76439f3263c1c812b236b79623878f73b2
Reviewed-on: https://gerrit.chromium.org/gerrit/31466
Reviewed-by: Rong Chang <rongchang@chromium.org>
Commit-Ready: Yung-Chieh Lo <yjlou@chromium.org>
Tested-by: Yung-Chieh Lo <yjlou@chromium.org>
-rw-r--r-- | board/snow/board.h | 3 | ||||
-rw-r--r-- | common/battery_bq20z453.c | 38 | ||||
-rw-r--r-- | common/build.mk | 1 | ||||
-rw-r--r-- | include/ec_commands.h | 8 | ||||
-rw-r--r-- | util/ectool.c | 27 |
5 files changed, 77 insertions, 0 deletions
diff --git a/board/snow/board.h b/board/snow/board.h index 434304c6bf..27eb5d7c6d 100644 --- a/board/snow/board.h +++ b/board/snow/board.h @@ -59,6 +59,9 @@ #define CONFIG_CMD_PMU +/* Battery */ +#define CONFIG_BATTERY_BQ20Z453 + /* GPIO signal list */ enum gpio_signal { /* Inputs with interrupt handlers are first for efficiency */ diff --git a/common/battery_bq20z453.c b/common/battery_bq20z453.c new file mode 100644 index 0000000000..bcfeb2536f --- /dev/null +++ b/common/battery_bq20z453.c @@ -0,0 +1,38 @@ +/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Smart battery driver for BQ20Z453. + */ + +#include "host_command.h" +#include "smart_battery.h" +#include "timer.h" + +#define PARAM_CUT_OFF 0x0010 + +int battery_command_cut_off(struct host_cmd_handler_args *args) +{ + /* + * TODO: Since this is a host command, the i2c bus is claimed by host. + * Thus, we would send back the response in advanced so that + * the host can release the bus and then EC can send command to + * battery. + * + * Refactoring this via task is a way. However, it is wasteful. + * Need a light-weight solution. + */ + args->result = EC_RES_SUCCESS; + host_send_response(args); + + /* This function would try to claim i2c and then send to battery. */ + sb_write(SB_MANUFACTURER_ACCESS, PARAM_CUT_OFF); + + return EC_RES_SUCCESS; + /* + * Not sure if there is a side-effect since this could send result + * back to host TWICE. + */ +} +DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off, + EC_VER_MASK(0)); diff --git a/common/build.mk b/common/build.mk index 3bfe81210d..af69df4287 100644 --- a/common/build.mk +++ b/common/build.mk @@ -9,6 +9,7 @@ common-y=main.o util.o console_output.o uart_buffering.o common-y+=memory_commands.o shared_mem.o system_common.o hooks.o common-y+=gpio_commands.o version.o printf.o queue.o +common-$(CONFIG_BATTERY_BQ20Z453)+=battery_bq20z453.o common-$(CONFIG_BATTERY_LINK)+=battery_link.o common-$(CONFIG_CHARGER_BQ24725)+=charger_bq24725.o common-$(CONFIG_PMU_TPS65090)+=pmu_tps65090.o pmu_tps65090_charger.o diff --git a/include/ec_commands.h b/include/ec_commands.h index b5d9ef24fe..ecf0f1394e 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -963,6 +963,14 @@ struct ec_params_force_idle { */ #define EC_CMD_CONSOLE_READ 0x98 +/* + * Cut off battery power output if the battery supports. + * + * For unsupported battery, just don't implement this command and lets EC + * return EC_RES_INVALID_COMMAND. + */ +#define EC_CMD_BATTERY_CUT_OFF 0x99 + /*****************************************************************************/ /* System commands */ diff --git a/util/ectool.c b/util/ectool.c index 9b40bf68cf..0623dc7e7f 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -32,6 +32,8 @@ const char help_str[] = " Enable/disable LCD backlight\n" " battery\n" " Prints battery info\n" + " batterycutoff\n" + " Cut off battery output power\n" " chargeforceidle\n" " Force charge state machine to stop in idle mode\n" " chipinfo\n" @@ -1912,6 +1914,30 @@ cmd_error: return -1; } +int cmd_battery_cut_off(int argc, char *argv[]) +{ + int rv; + + rv = ec_command(EC_CMD_BATTERY_CUT_OFF, 0, NULL, 0, NULL, 0); + rv = (rv < 0 ? rv : 0); + + if (rv < 0) { + fprintf(stderr, "Failed to cut off battery, rv=%d\n", rv); + fprintf(stderr, "It is expected if the rv is -%d " + "(EC_RES_INVALID_COMMAND) if the battery " + "doesn't support cut-off function.\n", + EC_RES_INVALID_COMMAND); + } else { + printf("\n"); + printf("SUCCESS. The battery has arranged a cut-off and\n"); + printf("the system should be shutdown immediately.\n"); + printf("\n"); + printf("If the system is still alive, you could remove\n"); + printf("the AC power and try again.\n"); + } + return rv; +} + int cmd_chipinfo(int argc, char *argv[]) { struct ec_response_get_chip_info info; @@ -2130,6 +2156,7 @@ const struct command commands[] = { {"autofanctrl", cmd_thermal_auto_fan_ctrl}, {"backlight", cmd_lcd_backlight}, {"battery", cmd_battery}, + {"batterycutoff", cmd_battery_cut_off}, {"chargeforceidle", cmd_charge_force_idle}, {"chipinfo", cmd_chipinfo}, {"cmdversions", cmd_cmdversions}, |