power: bq24617: Add support to report charging separately
authorGreg Meiste <w30289@motorola.com>
Tue, 7 Sep 2010 16:20:39 +0000 (11:20 -0500)
committerColin Cross <ccross@android.com>
Wed, 6 Oct 2010 23:51:07 +0000 (16:51 -0700)
Just because the charger is present, doesn't mean that the battery is
being charged.  For example, the battery can be overheating, which
will prevent charging.

Change-Id: If5d8dc325fc6dc507808216f1e45a180d74b5d73
Signed-off-by: Greg Meiste <w30289@motorola.com>
drivers/power/bq24617_charger.c

index e8888af6dd2438f3a8b32150a02d1fe0a7bb8aea..685b76ef0e1bb642e54cd8b6c0f0269d20731b4f 100644 (file)
@@ -32,7 +32,8 @@ struct bq24617_data {
        int ac_online;
 };
 
-static int bq24617_stat2_value;
+static int bq24617_stat1_value = 1; /* 0 = charging in progress */
+static int bq24617_stat2_value = 1; /* 0 = charge complete */
 
 static char *bq24617_supply_list[] = {
        "battery",
@@ -42,6 +43,11 @@ static enum power_supply_property bq24617_power_props[] = {
        POWER_SUPPLY_PROP_ONLINE,
 };
 
+int is_ac_charging(void)
+{
+       return (!bq24617_stat1_value || !bq24617_stat2_value);
+}
+
 int is_ac_charge_complete(void)
 {
        return !bq24617_stat2_value;
@@ -75,23 +81,23 @@ static void bq24617_work(struct work_struct *work)
 {
        struct bq24617_data *bq_data =
                container_of(work, struct bq24617_data, work);
-       int stat1;
        int detect = 0;
 
        /* STAT1 indicates charging, STAT2 indicates charge complete */
-       stat1 = gpio_get_value(irq_to_gpio(bq_data->stat1_irq));
+       bq24617_stat1_value = gpio_get_value(irq_to_gpio(bq_data->stat1_irq));
        bq24617_stat2_value = gpio_get_value(irq_to_gpio(bq_data->stat2_irq));
 
        if (bq_data->detect_irq >= 0)
                detect = gpio_get_value(irq_to_gpio(bq_data->detect_irq));
 
-       if (!stat1 || !bq24617_stat2_value || detect)
+       if (!bq24617_stat1_value || !bq24617_stat2_value || detect)
                bq_data->ac_online = 1;
        else
                bq_data->ac_online = 0;
 
        pr_info("%s: ac_online=%d (stat1=%d, stat2=%d, detect=%d)\n", __func__,
-               bq_data->ac_online, stat1, bq24617_stat2_value, detect);
+               bq_data->ac_online, bq24617_stat1_value, bq24617_stat2_value,
+               detect);
 
        power_supply_changed(&bq_data->ac);
        wake_unlock(&bq_data->wake_lock);