diff options
author | Aaron Weng <aaron.weng@quantatw.com> | 2014-05-28 14:03:50 +0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-05-30 16:06:28 +0000 |
commit | 14c61a69d1f94da798fa8276fb22e3956e047986 (patch) | |
tree | dcb4a86347b2efdf4ac5cc0032f903d6f253f1d4 | |
parent | de99f933f5b0108987d6ed572a5ae308681caa27 (diff) | |
download | chrome-ec-14c61a69d1f94da798fa8276fb22e3956e047986.tar.gz |
Swanky: To implement battery shipping mode.
According Battery pack SPEC, the battery shipping mode
set condition must be meet below items.
1.AC adaptor attached.
2.The each cell voltage is under 4000mV.
BUG=chrome-os-partner:29077
BRANCH=rambi
TEST=The battery pack can be set shipping mode and wake up
from shipping mode success by ectool batterycutoff command.
Change-Id: I80439040021a82e5635c22546f725a70b47a863f
Signed-off-by: Aaron Weng <aaron.weng@quantatw.com>
Reviewed-on: https://chromium-review.googlesource.com/201815
Reviewed-by: Dave Parker <dparker@chromium.org>
-rw-r--r-- | board/swanky/battery.c | 82 |
1 files changed, 76 insertions, 6 deletions
diff --git a/board/swanky/battery.c b/board/swanky/battery.c index f5f995b636..783fd923bd 100644 --- a/board/swanky/battery.c +++ b/board/swanky/battery.c @@ -8,12 +8,28 @@ #include "battery.h" #include "battery_smart.h" #include "console.h" +#include "extpower.h" #include "gpio.h" #include "host_command.h" #include "util.h" +#include "hooks.h" + +/* Console output macros */ +#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args) + +/* Battery FET ON/OFF command write to FET off register */ +#define SB_CELLS_VOLTAGE_MAX 4000 /* mV */ +#define SB_CELL_1_VOLTAGE_REG 0x3F +#define SB_CELL_2_VOLTAGE_REG 0x3E +#define SB_CELL_3_VOLTAGE_REG 0x3D +#define SB_FET_ONOFF_REG 0x35 +#define SB_FET_ON_DATA 0x0003 +#define SB_FET_OFF_DATA 0x0004 +#define SB_FET_STATUS_REG 0x34 +#define SB_FET_ONOFF_STATUS 0x0004 +#define SB_FET_OFF_STATUS 0x0004 +#define SB_FET_ON_STATUS 0x0000 -/* Shutdown mode parameter to write to manufacturer access register */ -#define SB_SHUTDOWN_DATA 0x0010 static const struct battery_info info = { .voltage_max = 12600, /* mV */ @@ -33,17 +49,71 @@ const struct battery_info *battery_get_info(void) return &info; } +static void wakeup_deferred(void) +{ + int tmp; + if (extpower_is_present()) { + sb_read(SB_FET_STATUS_REG, &tmp); + if ((tmp & SB_FET_ONOFF_STATUS) == SB_FET_OFF_STATUS) { + sb_write(SB_FET_ONOFF_REG, SB_FET_ON_DATA); + CPRINTF("[%T Battery wakeup]\n"); + } + } +} +DECLARE_DEFERRED(wakeup_deferred); + +static void wakeup(void) +{ + /* + * The deferred call ensures thet 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; + int rv, tmp, cell_voltage; + + /* To check AC adaptor is present or not */ + if (!extpower_is_present()) { + CPRINTF("[%T AC Adaptor is not present]\n"); + return EC_ERROR_UNKNOWN; + } + + /* To check the cell voltage of battery pack */ + sb_read(SB_CELL_1_VOLTAGE_REG, &cell_voltage); + if (cell_voltage >= SB_CELLS_VOLTAGE_MAX) { + CPRINTF("[%T Battery cell 1 voltage is too high]\n"); + return EC_ERROR_UNKNOWN; + } - /* Ship mode command must be sent twice to take effect */ - rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA); + sb_read(SB_CELL_2_VOLTAGE_REG, &cell_voltage); + if (cell_voltage >= SB_CELLS_VOLTAGE_MAX) { + CPRINTF("[%T Battery cell 2 voltage is too high]\n"); + return EC_ERROR_UNKNOWN; + } + + sb_read(SB_CELL_3_VOLTAGE_REG, &cell_voltage); + if (cell_voltage >= SB_CELLS_VOLTAGE_MAX) { + CPRINTF("[%T Battery cell 3 voltage is too high]\n"); + return EC_ERROR_UNKNOWN; + } + + /* Ship mode command must be sent to take effect */ + rv = sb_write(SB_FET_ONOFF_REG, SB_FET_OFF_DATA); if (rv != EC_SUCCESS) return rv; - return sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA); + sb_read(SB_FET_STATUS_REG, &tmp); + if ((tmp & SB_FET_ONOFF_STATUS) == SB_FET_OFF_STATUS) { + CPRINTF("[%T Battery cut off]\n"); + return EC_SUCCESS; + } + + return EC_ERROR_UNKNOWN; } static int battery_command_cut_off(struct host_cmd_handler_args *args) |