diff options
author | H.J. Liao <h.j.liao@quantatw.com> | 2015-04-22 14:00:11 +0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-04-23 23:33:17 +0000 |
commit | 9bed2b4470307cc6d6c797571a616853ec553912 (patch) | |
tree | 1d8d6d492e6e6946c8ed5bb3666f639a6b892805 | |
parent | f08fe314c2d977ca3459f7b000b6942449a0db8f (diff) | |
download | chrome-ec-9bed2b4470307cc6d6c797571a616853ec553912.tar.gz |
Orco: support "ectool batterycutoff at-shutdown"
use "ectool batterycutoff at-shutdown" instead of "ectool
batterycutoff".
BRANCH=orco
BUG=chrome-os-partner:39356
TEST=Build F/W and run command "ectool batterycutoff
at-shutdown;poweroff". The system won't boot up until the AC plugin.
Change-Id: I97b8fdc62c1c10483f2c870151f76f303a565360
Signed-off-by: H.J. Liao <h.j.liao@quantatw.com>
Reviewed-on: https://chromium-review.googlesource.com/266857
Reviewed-by: Mohammed Habibulla <moch@google.com>
Commit-Queue: Keith Tzeng <keith.tzeng@quantatw.com>
Tested-by: Keith Tzeng <keith.tzeng@quantatw.com>
-rw-r--r-- | board/orco/battery.c | 52 | ||||
-rw-r--r-- | board/orco/board.h | 1 |
2 files changed, 37 insertions, 16 deletions
diff --git a/board/orco/battery.c b/board/orco/battery.c index a861a12c08..b6e15992a4 100644 --- a/board/orco/battery.c +++ b/board/orco/battery.c @@ -8,12 +8,20 @@ #include "battery.h" #include "battery_smart.h" #include "console.h" +#include "extpower.h" #include "gpio.h" +#include "hooks.h" #include "host_command.h" +#include "system.h" #include "util.h" -/* Shutdown mode parameter to write to manufacturer access register */ -#define SB_SHUTDOWN_DATA 0x0010 +/* FET ON/OFF cammand write to fet off register */ +#define SB_FET_OFF 0x34 +#define SB_FETOFF_DATA1 0x0000 +#define SB_FETOFF_DATA2 0x1000 +#define SB_FETON_DATA1 0x2000 +#define SB_FETON_DATA2 0x4000 +#define BATTERY_FETOFF 0x0100 static const struct battery_info info = { .voltage_max = 8600, /* mV */ @@ -33,31 +41,43 @@ const struct battery_info *battery_get_info(void) return &info; } +static void wakeup_deferred(void) +{ + int d; + + sb_read(SB_FET_OFF, &d); + + if (extpower_is_present() && (BATTERY_FETOFF == d)) { + sb_write(SB_FET_OFF, SB_FETON_DATA1); + sb_write(SB_FET_OFF, SB_FETON_DATA2); + } +} +DECLARE_DEFERRED(wakeup_deferred); + +static void wakeup(void) +{ + /* + * The deferred call ensures that wakeup_deferred is called from a + * task. This is required to talk to the battery over I2C. + */ + hook_call_deferred(wakeup_deferred, 0); +} +DECLARE_HOOK(HOOK_INIT, wakeup, HOOK_PRIO_DEFAULT); + static int cutoff(void) { int rv; /* Ship mode command must be sent twice to take effect */ - rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA); + rv = sb_write(SB_FET_OFF, SB_FETOFF_DATA1); if (rv != EC_SUCCESS) return rv; - return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA); -} - -static int battery_command_cut_off(struct host_cmd_handler_args *args) -{ - return cutoff() ? EC_RES_ERROR : EC_RES_SUCCESS; + return sb_write(SB_FET_OFF, SB_FETOFF_DATA2); } -DECLARE_HOST_COMMAND(EC_CMD_BATTERY_CUT_OFF, battery_command_cut_off, - EC_VER_MASK(0)); -static int command_battcutoff(int argc, char **argv) +int board_cut_off_battery(void) { return cutoff(); } -DECLARE_CONSOLE_COMMAND(battcutoff, command_battcutoff, - NULL, - "Enable battery cutoff (ship mode)", - NULL); diff --git a/board/orco/board.h b/board/orco/board.h index b7b9107555..378a296355 100644 --- a/board/orco/board.h +++ b/board/orco/board.h @@ -11,6 +11,7 @@ /* Optional features */ #define CONFIG_AP_HANG_DETECT #define CONFIG_BACKLIGHT_LID +#define CONFIG_BATTERY_CUT_OFF #define CONFIG_BATTERY_SMART #define CONFIG_BOARD_VERSION #define CONFIG_CHARGER |