summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWonjoon Lee <woojoo.lee@samsung.com>2014-04-29 17:18:07 +0900
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-04-30 20:55:31 +0000
commit2dce1bf3390546d5ca0c98dcbf9004e2bc59a1eb (patch)
tree322b157dd2240453594e23701141ac994629ea4c
parent658a380b99fafcbb2120f581b0b1174e5e6115d6 (diff)
downloadchrome-ec-2dce1bf3390546d5ca0c98dcbf9004e2bc59a1eb.tar.gz
Adding waiting function when battery boot-up
Some battery uses clock stretching feature, and this could disturb PMU communication before battery going stable. AP does not know and will attempt PMU setting, and could get fail For various battery indicates usually 1s for stable (even if it is much less in real world 200ms~700ms) Let's checking 'battery is ready' when first pump-up power. BRANCH=ToT BUG=chrome-os-partner:28289 TEST=Going battery shipmode and plug-in AC, See booting and EC log Disconnect battery, and plug-in and see booting and EC log Change-Id: Id5c02c6e7ac36014e7a085af38ac8e3520d3e390 Signed-off-by: Wonjoon Lee <woojoo.lee@samsung.com> Signed-off-by: Doug Anderson <dianders@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/197463 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Katie Roberts-Hoffman <katierh@chromium.org> Tested-by: Katie Roberts-Hoffman <katierh@chromium.org>
-rw-r--r--common/smart_battery.c41
-rw-r--r--include/smart_battery.h5
2 files changed, 45 insertions, 1 deletions
diff --git a/common/smart_battery.c b/common/smart_battery.c
index 3991a2e270..b38853d8ec 100644
--- a/common/smart_battery.c
+++ b/common/smart_battery.c
@@ -11,6 +11,13 @@
#include "timer.h"
#include "util.h"
+/* Console output macros */
+#define CPUTS(outstr) cputs(CC_CHARGER, outstr)
+#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
+
+#define BATTERY_WAIT_TIMEOUT (2800*MSEC)
+#define BATTERY_NO_RESPONSE_TIMEOUT (1000*MSEC)
+
/* Read battery discharging current
* unit: mA
* negative value: charging
@@ -127,6 +134,40 @@ int battery_device_chemistry(char *device_chemistry, int buf_size)
SB_DEVICE_CHEMISTRY, device_chemistry, buf_size);
}
+/* Wait until battery is totally stable */
+int battery_wait_for_stable(void)
+{
+ int status, got_response;
+ uint64_t wait_timeout = get_time().val + BATTERY_WAIT_TIMEOUT;
+ uint64_t no_response_timeout = get_time().val +
+ BATTERY_NO_RESPONSE_TIMEOUT;
+
+ got_response = 0;
+
+ CPRINTF("[%T Wait for battery stabilized during %d\n",
+ BATTERY_WAIT_TIMEOUT);
+ while (get_time().val < wait_timeout) {
+ /* Starting pinging battery */
+ if (battery_status(&status) == EC_SUCCESS) {
+ got_response = 1;
+ /* Battery is stable */
+ if (status & STATUS_INITIALIZED) {
+ CPRINTF("[%T battery initialized]\n");
+ return EC_SUCCESS;
+ }
+ }
+ /* Assume no battery connected if no response for a while */
+ else if (!got_response &&
+ get_time().val > no_response_timeout) {
+ CPRINTF("[%T battery not responding]\n");
+ return EC_SUCCESS;
+ }
+ msleep(25); /* clock stretching could hold 25ms */
+ }
+ CPRINTF("[%T battery wait stable timeout]\n");
+ return EC_ERROR_TIMEOUT;
+}
+
/*****************************************************************************/
/* Console commands */
diff --git a/include/smart_battery.h b/include/smart_battery.h
index ef65cd9d0d..728dd11295 100644
--- a/include/smart_battery.h
+++ b/include/smart_battery.h
@@ -81,7 +81,7 @@
#define STATUS_FULLY_DISCHARGED (1 << 4)
#define STATUS_FULLY_CHARGED (1 << 5)
#define STATUS_DISCHARGING (1 << 6)
-#define STATUS_INITIALIZING (1 << 7)
+#define STATUS_INITIALIZED (1 << 7)
#define STATUS_REMAINING_TIME_ALARM (1 << 8)
#define STATUS_REMAINING_CAPACITY_ALARM (1 << 9)
#define STATUS_TERMINATE_DISCHARGE_ALARM (1 << 11)
@@ -238,5 +238,8 @@ int battery_time_at_rate(int rate, int *minutes);
/* Read manufacturer date */
int battery_manufacturer_date(int *year, int *month, int *day);
+/* Wait for battery stable when first boot-up */
+int battery_wait_for_stable(void);
+
#endif /* __CROS_EC_SMART_BATTERY_H */