power: supply: bq24190_charger: Handle fault before status on interrupt
authorLiam Breck <liam@networkimprov.net>
Wed, 18 Jan 2017 17:26:54 +0000 (09:26 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 14 May 2017 11:32:54 +0000 (13:32 +0200)
commit ba52e75718784fda1b683ee0bfded72a0b83b047 upstream.

Reading both fault and status registers and logging any fault should
take priority over handling status register update.

Fix by moving the status handling to later in interrupt routine.

Fixes: d7bf353fd0aa3 ("bq24190_charger: Add support for TI BQ24190 Battery Charger")
Signed-off-by: Liam Breck <kernel@networkimprov.net>
Acked-by: Mark Greer <mgreer@animalcreek.com>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/power/bq24190_charger.c

index 2f552637901a3dbfeeeb7806fdcca61f6d9a46ce..f05d2773fe00ccff87a55a177b1d27d71befabbf 100644 (file)
@@ -1175,29 +1175,6 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
                goto out;
        }
 
-       if (ss_reg != bdi->ss_reg) {
-               /*
-                * The device is in host mode so when PG_STAT goes from 1->0
-                * (i.e., power removed) HIZ needs to be disabled.
-                */
-               if ((bdi->ss_reg & BQ24190_REG_SS_PG_STAT_MASK) &&
-                               !(ss_reg & BQ24190_REG_SS_PG_STAT_MASK)) {
-                       ret = bq24190_write_mask(bdi, BQ24190_REG_ISC,
-                                       BQ24190_REG_ISC_EN_HIZ_MASK,
-                                       BQ24190_REG_ISC_EN_HIZ_SHIFT,
-                                       0);
-                       if (ret < 0)
-                               dev_err(bdi->dev, "Can't access ISC reg: %d\n",
-                                       ret);
-               }
-
-               if ((bdi->ss_reg & battery_mask_ss) != (ss_reg & battery_mask_ss))
-                       alert_battery = true;
-               if ((bdi->ss_reg & ~battery_mask_ss) != (ss_reg & ~battery_mask_ss))
-                       alert_charger = true;
-               bdi->ss_reg = ss_reg;
-       }
-
        i = 0;
        do {
                ret = bq24190_read(bdi, BQ24190_REG_F, &f_reg);
@@ -1224,6 +1201,29 @@ static irqreturn_t bq24190_irq_handler_thread(int irq, void *data)
                mutex_unlock(&bdi->f_reg_lock);
        }
 
+       if (ss_reg != bdi->ss_reg) {
+               /*
+                * The device is in host mode so when PG_STAT goes from 1->0
+                * (i.e., power removed) HIZ needs to be disabled.
+                */
+               if ((bdi->ss_reg & BQ24190_REG_SS_PG_STAT_MASK) &&
+                               !(ss_reg & BQ24190_REG_SS_PG_STAT_MASK)) {
+                       ret = bq24190_write_mask(bdi, BQ24190_REG_ISC,
+                                       BQ24190_REG_ISC_EN_HIZ_MASK,
+                                       BQ24190_REG_ISC_EN_HIZ_SHIFT,
+                                       0);
+                       if (ret < 0)
+                               dev_err(bdi->dev, "Can't access ISC reg: %d\n",
+                                       ret);
+               }
+
+               if ((bdi->ss_reg & battery_mask_ss) != (ss_reg & battery_mask_ss))
+                       alert_battery = true;
+               if ((bdi->ss_reg & ~battery_mask_ss) != (ss_reg & ~battery_mask_ss))
+                       alert_charger = true;
+               bdi->ss_reg = ss_reg;
+       }
+
        if (alert_charger)
                power_supply_changed(bdi->charger);
        if (alert_battery)