summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWonjoon Lee <woojoo.lee@samsung.com>2014-05-02 19:24:04 +0900
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-05-09 07:22:59 +0000
commite8131b8246fcce6447df1676e83e9ed08fc2849f (patch)
tree7956ca94559e4f21e16a6ae242efaff354759084
parent2403aad303338c0a866aaa77e2981bf0cd2a294d (diff)
downloadchrome-ec-e8131b8246fcce6447df1676e83e9ed08fc2849f.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: I731959803559881f51162ec4dd947436c3ee212c Original-Change-Id: Idd8ae2ab4ec164b11fe67413bbf647cad18bc481 Signed-off-by: Wonjoon Lee <woojoo.lee@samsung.com> Reviewed-on: https://chromium-review.googlesource.com/197990 Reviewed-by: Randall Spangler <rspangler@chromium.org> Commit-Queue: Doug Anderson <dianders@chromium.org> Tested-by: Doug Anderson <dianders@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/199004 Reviewed-by: Gabe Black <gabeblack@chromium.org> Commit-Queue: Gabe Black <gabeblack@chromium.org> Tested-by: Gabe Black <gabeblack@chromium.org>
-rw-r--r--driver/battery/smart.c42
-rw-r--r--include/battery.h7
2 files changed, 49 insertions, 0 deletions
diff --git a/driver/battery/smart.c b/driver/battery/smart.c
index 3fda584910..4f6c2f349d 100644
--- a/driver/battery/smart.c
+++ b/driver/battery/smart.c
@@ -7,11 +7,19 @@
#include "battery.h"
#include "battery_smart.h"
+#include "console.h"
#include "host_command.h"
#include "i2c.h"
#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)
+
test_mockable int sbc_read(int cmd, int *param)
{
return i2c_read16(I2C_PORT_CHARGER, CHARGER_ADDR, cmd, param);
@@ -304,6 +312,40 @@ void battery_get_params(struct batt_params *batt)
memcpy(batt, &batt_new, sizeof(*batt));
}
+/* 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_ERROR_NOT_POWERED;
+ }
+ msleep(25); /* clock stretching could hold 25ms */
+ }
+ CPRINTF("[%T battery wait stable timeout]\n");
+ return EC_ERROR_TIMEOUT;
+}
+
/*****************************************************************************/
/* Smart battery pass-through
*/
diff --git a/include/battery.h b/include/battery.h
index fc0c4bbcc5..c66b5f3064 100644
--- a/include/battery.h
+++ b/include/battery.h
@@ -280,4 +280,11 @@ int board_cut_off_battery(void);
*/
int battery_is_cut_off(void);
+/**
+ * Wait for battery stable.
+ *
+ * @return non-zero if error.
+ */
+int battery_wait_for_stable(void);
+
#endif /* __CROS_EC_BATTERY_H */