summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-07-30 06:37:59 +0800
committerChromeBot <chrome-bot@google.com>2013-07-29 19:50:59 -0700
commitcd89d523b1f6bb9488dd3aed2c9d0019709ad690 (patch)
treec624f54dab443f79d5a24528ee7b8db32d873255
parentf2c06dd945cc84238735763fb09ef7e9443e72e5 (diff)
downloadchrome-ec-cd89d523b1f6bb9488dd3aed2c9d0019709ad690.tar.gz
spring: Do not charge when cutting off the battery
If a charger is plugged in while we are cutting off the battery, the EC will be powered by external power, and the battery will be in a state where it doesn't charge. Let's stop charging in this case to get the battery into cut-off state properly and resume charging 5 seconds after. BUG=chrome-os-partner:21107 TEST=Plug in the charger while cutting off the battery. BRANCH=Spring Change-Id: I5505485be7872f9887efc725a2b3aa610c6b42b9 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/63647 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r--board/spring/board.h2
-rw-r--r--common/battery_spring.c14
-rw-r--r--common/pmu_tps65090_charger.c3
-rw-r--r--common/smart_battery_stub.c14
-rw-r--r--include/battery_pack.h7
5 files changed, 37 insertions, 3 deletions
diff --git a/board/spring/board.h b/board/spring/board.h
index 7f77d3268b..f82b0b8dc9 100644
--- a/board/spring/board.h
+++ b/board/spring/board.h
@@ -33,7 +33,7 @@
/* Auto battery cut-off */
#define BATTERY_CUT_OFF_MAH 10
-#define BATTERY_CUT_OFF_DELAY (11 * SECOND)
+#define BATTERY_CUT_OFF_DELAY (15 * SECOND)
/* use STOP mode when we have nothing to do */
#define CONFIG_LOW_POWER_IDLE
diff --git a/common/battery_spring.c b/common/battery_spring.c
index 840ed3fdfe..f86e91cd5d 100644
--- a/common/battery_spring.c
+++ b/common/battery_spring.c
@@ -26,6 +26,9 @@
#define BATTERY_CUT_OFF_DELAY 0
#endif
+static timestamp_t last_cutoff;
+static int has_cutoff;
+
int battery_cut_off(void)
{
int rv;
@@ -40,15 +43,26 @@ int battery_cut_off(void)
rv = i2c_xfer(I2C_PORT_BATTERY, BATTERY_ADDR, buf, 3, NULL, 0);
i2c_unlock();
+ has_cutoff = 1;
+ last_cutoff = get_time();
+
return rv;
}
+int battery_is_cut_off(void)
+{
+ return has_cutoff &&
+ get_time().val - last_cutoff.val < BATTERY_CUT_OFF_DELAY;
+}
+
int battery_check_cut_off(void)
{
int charge;
if (!BATTERY_CUT_OFF_MAH)
return 0;
+ if (battery_is_cut_off())
+ return 0;
if (chipset_in_state(CHIPSET_STATE_ON | CHIPSET_STATE_SUSPEND))
return 0;
if (battery_remaining_capacity(&charge))
diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c
index 6f057fbe39..1f357ad946 100644
--- a/common/pmu_tps65090_charger.c
+++ b/common/pmu_tps65090_charger.c
@@ -206,6 +206,9 @@ static int calc_next_state(int state)
return ST_IDLE;
}
+ if (battery_is_cut_off())
+ return ST_BAD_COND;
+
/* Stay in idle mode if charger overtemp */
if (pmu_is_charger_alarm())
return ST_BAD_COND;
diff --git a/common/smart_battery_stub.c b/common/smart_battery_stub.c
index f00cc921a7..cca438fc6f 100644
--- a/common/smart_battery_stub.c
+++ b/common/smart_battery_stub.c
@@ -5,6 +5,8 @@
* Functions needed by smart battery driver.
*/
+#include "battery_pack.h"
+#include "common.h"
#include "smart_battery.h"
#include "i2c.h"
@@ -15,7 +17,15 @@ int sbc_write(int cmd, int param)
{ return i2c_write16(I2C_PORT_CHARGER, CHARGER_ADDR, cmd, param); }
int sb_read(int cmd, int *param)
- { return i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); }
+{
+ if (battery_is_cut_off())
+ return EC_ERROR_INVAL;
+ return i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param);
+}
int sb_write(int cmd, int param)
- { return i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); }
+{
+ if (battery_is_cut_off())
+ return EC_ERROR_INVAL;
+ return i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param);
+}
diff --git a/include/battery_pack.h b/include/battery_pack.h
index 0a43619102..5e0593a75a 100644
--- a/include/battery_pack.h
+++ b/include/battery_pack.h
@@ -58,4 +58,11 @@ int battery_cut_off(void);
*/
int battery_check_cut_off(void);
+/**
+ * Check if the battery is already cut off.
+ *
+ * @return 1 if battery has been cut off.
+ */
+int battery_is_cut_off(void);
+
#endif