summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce <Bruce.Wan@quantatw.com>2016-10-27 14:16:09 +0800
committerchrome-bot <chrome-bot@chromium.org>2016-10-31 14:21:27 -0700
commit49ed82eaa7cfb872ada0e72088a1618e5b5c0c03 (patch)
tree3fe6b98a01637ba807f6b6bf5f2c8d4523a2fdbb
parent3c39ccabdae49928a97dbb56e02e2a800bfd5d72 (diff)
downloadchrome-ec-49ed82eaa7cfb872ada0e72088a1618e5b5c0c03.tar.gz
Pyro: Add firmware for shipping mode follow Pyro battery spec.
Add firmware for shipping mode follow Pyro battery spec. BUG=None BRANCH=None TEST=The battery could enter shipping mode and wake up Change-Id: If1b6e88192ad0a59b19b6b6b664b46780596fa18 Signed-off-by: Bruce.Wan <Bruce.Wan@quantatw.com> Reviewed-on: https://chromium-review.googlesource.com/403731 Commit-Ready: Keith Tzeng <keith.tzeng@quantatw.com> Tested-by: Keith Tzeng <keith.tzeng@quantatw.com> Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--board/pyro/battery.c59
1 files changed, 45 insertions, 14 deletions
diff --git a/board/pyro/battery.c b/board/pyro/battery.c
index 7e2f975a4e..83931a0822 100644
--- a/board/pyro/battery.c
+++ b/board/pyro/battery.c
@@ -12,9 +12,22 @@
#include "ec_commands.h"
#include "extpower.h"
#include "gpio.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "system.h"
#include "i2c.h"
#include "util.h"
+/* 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
+
+#define GREEN_BOOK_SUPPORT (1 << 2)
+
/* Shutdown mode parameter to write to manufacturer access register */
#define PARAM_CUT_OFF_LOW 0x10
#define PARAM_CUT_OFF_HIGH 0x00
@@ -47,24 +60,42 @@ const struct battery_info *battery_get_info(void)
return &info;
}
-int board_cut_off_battery(void)
+static void wakeup(void)
+{
+ int d;
+ int mode;
+
+ /* Add Green Book support */
+ if (sb_read(SB_BATTERY_MODE, &mode) == EC_RES_SUCCESS) {
+ mode |= GREEN_BOOK_SUPPORT;
+ sb_write(SB_BATTERY_MODE, mode);
+ }
+
+ if (sb_read(SB_FET_OFF, &d) == EC_RES_SUCCESS) {
+ if (extpower_is_present() && (d == BATTERY_FETOFF)) {
+ sb_write(SB_FET_OFF, SB_FETON_DATA1);
+ sb_write(SB_FET_OFF, SB_FETON_DATA2);
+ }
+ }
+}
+DECLARE_HOOK(HOOK_INIT, wakeup, HOOK_PRIO_DEFAULT);
+
+static int cutoff(void)
{
int rv;
- uint8_t buf[3];
/* Ship mode command must be sent twice to take effect */
- buf[0] = SB_MANUFACTURER_ACCESS & 0xff;
- buf[1] = PARAM_CUT_OFF_LOW;
- buf[2] = PARAM_CUT_OFF_HIGH;
-
- i2c_lock(I2C_PORT_BATTERY, 1);
- rv = i2c_xfer(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
- I2C_XFER_SINGLE);
- rv |= i2c_xfer(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0,
- I2C_XFER_SINGLE);
- i2c_lock(I2C_PORT_BATTERY, 0);
-
- return rv;
+ rv = sb_write(SB_FET_OFF, SB_FETOFF_DATA1);
+
+ if (rv != EC_SUCCESS)
+ return rv;
+
+ return sb_write(SB_FET_OFF, SB_FETOFF_DATA2);
+}
+
+int board_cut_off_battery(void)
+{
+ return cutoff();
}
enum battery_disconnect_state battery_get_disconnect_state(void)