summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2014-07-18 17:09:37 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-07-23 02:29:59 +0000
commitb9677a48c81cc3b5074c532902076ff4ac64fe03 (patch)
treef3b3b0adb850d70d320ab142e88129cf09a369c0 /driver
parent4eee9fe42688e77c6c845a3904adb531a75f569a (diff)
downloadchrome-ec-b9677a48c81cc3b5074c532902076ff4ac64fe03.tar.gz
samus: Kick battery out of disconnect state when AC is attached
The Samus battery can be placed into a disconnect state by asserting a disconnect input signal. In this state, the battery will not function until a charging current is applied. This patch adds detection of the disconnect state. If a battery in disconnect state is found, a current is force-applied to the battery to kick it out of disconnect. BRANCH=None TEST=Manual on Samus. 1. Put battery into disconnect state 2. Pull AC, then reattach AC 3. Verify "found battery in disconnect state" is seen on the EC console. 4. Pull AC and verify that EC console is still accessable Also verify that battery gets out of reset state: 1. Pull AC 2. Issue "i2cxfer w16 0 0x16 0x0 0x12" command on EC console 3. Re-attach AC 4. Pull AC and verify that EC console is still accessable BUG=chrome-os-partner:29465 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: Ib4268887fb483094ac4e641749200268160d3014 Reviewed-on: https://chromium-review.googlesource.com/209013 Reviewed-by: Alec Berg <alecaberg@chromium.org> Commit-Queue: Alec Berg <alecaberg@chromium.org> Tested-by: Alec Berg <alecaberg@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/battery/samus.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/driver/battery/samus.c b/driver/battery/samus.c
index de361b2d59..4c4f3480c4 100644
--- a/driver/battery/samus.c
+++ b/driver/battery/samus.c
@@ -5,9 +5,11 @@
* Battery pack vendor provided charging profile
*/
+#include "battery_smart.h"
#include "charge_state.h"
#include "console.h"
#include "ec_commands.h"
+#include "extpower.h"
#include "util.h"
static const struct battery_info info = {
@@ -152,3 +154,63 @@ DECLARE_CONSOLE_COMMAND(fastcharge, command_fastcharge,
NULL);
#endif /* CONFIG_CHARGER_PROFILE_OVERRIDE */
+
+#ifdef CONFIG_BATTERY_REVIVE_DISCONNECT
+/*
+ * Check if battery is in disconnect state, a state entered by pulling
+ * BATT_DISCONN_N low, and clear that state if we have external power plugged
+ * and no battery faults are detected. Disconnect state resembles battery
+ * shutdown mode, but extra steps must be taken to get the battery out of this
+ * mode.
+ */
+enum battery_disconnect_state battery_get_disconnect_state(void)
+{
+ uint8_t data[6];
+ int rv;
+ /*
+ * Take note if we find that the battery isn't in disconnect state,
+ * and always return NOT_DISCONNECTED without probing the battery.
+ * This assumes the battery will not go to disconnect state during
+ * runtime.
+ */
+ static int not_disconnected;
+
+ if (not_disconnected)
+ return BATTERY_NOT_DISCONNECTED;
+
+ if (extpower_is_present()) {
+ /* Check if battery charging + discharging is disabled. */
+ rv = sb_write(SB_MANUFACTURER_ACCESS, PARAM_OPERATION_STATUS);
+ if (rv)
+ return BATTERY_DISCONNECT_ERROR;
+
+ rv = sb_read_string(I2C_PORT_BATTERY, BATTERY_ADDR,
+ SB_ALT_MANUFACTURER_ACCESS, data, 6);
+
+ if (rv || !(data[3] & BATTERY_DISCHARGING_DISABLED) ||
+ !(data[3] & BATTERY_CHARGING_DISABLED)) {
+ not_disconnected = 1;
+ return BATTERY_NOT_DISCONNECTED;
+ }
+
+ /*
+ * Battery is neither charging nor discharging. Verify that
+ * we didn't enter this state due to a safety fault.
+ */
+ rv = sb_write(SB_MANUFACTURER_ACCESS, PARAM_SAFETY_STATUS);
+ if (rv)
+ return BATTERY_DISCONNECT_ERROR;
+
+ rv = sb_read_string(I2C_PORT_BATTERY, BATTERY_ADDR,
+ SB_ALT_MANUFACTURER_ACCESS, data, 6);
+
+ if (rv || data[2] || data[3] || data[4] || data[5])
+ return BATTERY_DISCONNECT_ERROR;
+ else
+ /* No safety fault -- clear disconnect state. */
+ return BATTERY_DISCONNECTED;
+ }
+ not_disconnected = 1;
+ return BATTERY_NOT_DISCONNECTED;
+}
+#endif /* CONFIG_BATTERY_REVIVE_DISCONNECT */