summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWonjoon Lee <woojoo.lee@samsung.com>2015-10-13 14:05:50 +0900
committerChromeOS bot <3su6n15k.default@developer.gserviceaccount.com>2015-10-26 18:44:29 +0000
commita13125fae44421aab2f5d1d7692935780b293969 (patch)
tree812d78088c90b4cf13f8c0bdb7072b3d71108f1c
parent61faba40e6885467e29ef2d6af19f79a4cf15bae (diff)
downloadchrome-ec-a13125fae44421aab2f5d1d7692935780b293969.tar.gz
bq24773: disable IDPM and AutoWake when battery is gone
Some USB3.0 HUB can make board not bootable because of leak current. Disabling IDPM, Autowake can get proper current at this moment. Monitoring BP pint as a mode trigger for mode change BUG=chrome-os-partner:46431 BRANCH=firmware-strago-7287.B TEST=See celes goes booting with NEXT-305U3 hub. Check S3/Wake-up also Change-Id: I2355fb2d8cb27f48d6d5753684081f7868eb3f0e Signed-off-by: Wonjoon Lee <woojoo.lee@samsung.com> Reviewed-on: https://chromium-review.googlesource.com/305611 Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--driver/charger/bq24773.c88
-rw-r--r--driver/charger/bq24773.h4
-rw-r--r--include/config.h5
3 files changed, 96 insertions, 1 deletions
diff --git a/driver/charger/bq24773.c b/driver/charger/bq24773.c
index 0c79f8acca..747bc9787c 100644
--- a/driver/charger/bq24773.c
+++ b/driver/charger/bq24773.c
@@ -5,13 +5,21 @@
* TI bq24773 battery charger driver.
*/
+#include "battery.h"
#include "battery_smart.h"
#include "bq24773.h"
#include "charger.h"
#include "console.h"
#include "common.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "timer.h"
#include "util.h"
+/* Console output macros */
+#define CPUTS(outstr) cputs(CC_CHARGER, outstr)
+#define CPRINTS(format, args...) cprints(CC_CHARGER, format, ## args)
+
/*
* on the I2C version of the charger,
* some registers are 8-bit only (eg input current)
@@ -42,6 +50,38 @@ static const struct charger_info bq2477x_charger_info = {
.input_current_step = REG_TO_CURRENT(INPUT_I_STEP, R_AC),
};
+#ifdef CONFIG_CHARGER_MONITOR_BP
+/* Disable IDPM, Auto Awake when battery is not there. See crosbug.com/p/46431 */
+static int bq24773_set_bp_mode(int bp)
+{
+ int rv;
+ int option0, option1;
+
+ rv = charger_get_option(&option0);
+ rv |= raw_read16(REG_CHARGE_OPTION1, &option1);
+
+ if (rv)
+ return rv;
+
+ if (bp == BP_YES) {
+ option0 &= ~OPTION0_CHARGE_INHIBIT;
+ option0 |= OPTION0_CHARGE_IDPM_ENABLE;
+ option1 |= OPTION1_AUTO_WAKEUP_ENABLE;
+ }
+ else if (bp == BP_NO) {
+ option0 |= OPTION0_CHARGE_INHIBIT;
+ option0 &= ~OPTION0_CHARGE_IDPM_ENABLE;
+ option1 &= ~OPTION1_AUTO_WAKEUP_ENABLE;
+ }
+ /* Do nothing when bp is BP_NOT_SURE */
+
+ rv = charger_set_option(option0);
+ rv |= raw_write16(REG_CHARGE_OPTION1, option1);
+
+ return rv;
+}
+#endif
+
/* chip specific interfaces */
int charger_set_input_current(int input_current)
@@ -185,6 +225,16 @@ int charger_post_init(void)
int option2;
#endif
+#ifdef CONFIG_CHARGER_MONITOR_BP
+ /*
+ * TODO : monitoring method needed when BP is not HW(GPIO here) detection
+ * Also need to get battery present. now aasume that it is called only GPIO
+ * interrupt and GPIO detection.
+ */
+ bq24773_set_bp_mode(battery_is_present());
+ gpio_enable_interrupt(GPIO_BAT_PRESENT_L);
+#endif
+
rv = charger_get_option(&option);
if (rv)
return rv;
@@ -248,3 +298,41 @@ int charger_discharge_on_ac(int enable)
return rv;
}
+
+/*****************************************************************************/
+/* Interrupt Handler */
+
+#ifdef CONFIG_CHARGER_MONITOR_BP
+#define BP_DEBOUNCE_US (30 * MSEC) /* Debounce time for bp pin */
+
+static int debounced_bp_changed; /* Debounced bp pin state */
+static volatile int battery_present_is_stable = 1;
+
+/**
+ * Handle debounced bp pin changing state.
+ */
+static void charger_battery_present_deferred(void)
+{
+ const int new_status = battery_is_present();
+
+ /* If bp pin hasn't changed state, nothing to do */
+ if (new_status == debounced_bp_changed) {
+ battery_present_is_stable = 1;
+ return;
+ }
+
+ debounced_bp_changed = new_status;
+ battery_present_is_stable = 1;
+
+ CPRINTS("battery detection pin %s", new_status ? "attached" : "released");
+ bq24773_set_bp_mode(new_status);
+}
+DECLARE_DEFERRED(charger_battery_present_deferred);
+
+void charger_battery_present_interrupt(enum gpio_signal signal)
+{
+ /* Reset bp pin debounce time */
+ battery_present_is_stable = 0;
+ hook_call_deferred(charger_battery_present_deferred, BP_DEBOUNCE_US);
+}
+#endif
diff --git a/driver/charger/bq24773.h b/driver/charger/bq24773.h
index 50723d145f..b8fdc28e53 100644
--- a/driver/charger/bq24773.h
+++ b/driver/charger/bq24773.h
@@ -42,8 +42,9 @@
/* Option bits */
#define OPTION0_CHARGE_INHIBIT (1 << 0)
+#define OPTION0_CHARGE_IDPM_ENABLE (1 << 1)
#define OPTION0_LEARN_ENABLE (1 << 5)
-
+#define OPTION1_AUTO_WAKEUP_ENABLE (1 << 0)
#define OPTION2_EN_EXTILIM (1 << 7)
/* Prochot Option bits */
@@ -119,4 +120,5 @@ static inline int raw_write16(int offset, int value)
return i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER, offset, value);
}
+void charger_battery_present_interrupt(enum gpio_signal signal);
#endif /* __CROS_EC_BQ24773_H */
diff --git a/include/config.h b/include/config.h
index e767b24d98..1c80144f6d 100644
--- a/include/config.h
+++ b/include/config.h
@@ -336,6 +336,11 @@
#undef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON
/*
+ * Monitoring Battery present so that control chager mode.
+ */
+#undef CONFIG_CHARGER_MONITOR_BP
+
+/*
* Equivalent of CONFIG_BATTERY_OVERRIDE_PARAMS for use with
* CONFIG_CHARGER_V2
*/