power: bq2419x: Clear EN_HIZ bit
Syed Rafiuddin [Mon, 18 Feb 2013 10:00:58 +0000 (15:00 +0530)]
HIZ disables USBFET and stops battery charging.
WAR is to clear this bit on every hotplug event.

Bug 1237492

Change-Id: I5ec69d58a5187d223a723e848ab6ef8fa2360bf6
Signed-off-by: Anshul Jain <anshulj@nvidia.com>
Signed-off-by: Syed Rafiuddin <srafiuddin@nvidia.com>
Reviewed-on: http://git-master/r/201363
Reviewed-by: Mandar Padmawar <mpadmawar@nvidia.com>
Tested-by: Mandar Padmawar <mpadmawar@nvidia.com>

drivers/power/bq2419x-charger.c

index a09657a..71ba78b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * bq2419x-charger.c - Battery charger driver
  *
- * Copyright (c) 2012, NVIDIA Corporation.
+ * Copyright (c) 2013, NVIDIA CORPORATION.  All rights reserved.
  *
  * Author: Laxman Dewangan <ldewangan@nvidia.com>
  *
@@ -49,8 +49,7 @@ struct bq2419x_charger {
        int                     usb_online;
        int                     gpio_status;
        int                     gpio_interrupt;
-       int                     usb_in_current_limit;
-       int                     ac_in_current_limit;
+       int                     in_current_limit;
        unsigned                use_mains:1;
        unsigned                use_usb:1;
        int status;
@@ -135,31 +134,25 @@ static int bq2419x_init(struct bq2419x_charger *charger)
        }
        mutex_unlock(&charger->mutex);
 
-       if (charger->usb_online) {
-               val = current_to_reg(iinlim, ARRAY_SIZE(iinlim),
-                                       charger->usb_in_current_limit);
-               if (val < 0)
-                       return 0;
-
-               ret = regmap_update_bits(charger->chip->regmap,
-                       BQ2419X_INPUT_SRC_REG, BQ2419x_CONFIG_MASK, val);
-               if (ret < 0)
-                       dev_err(charger->dev, "error reading reg: 0x%x\n",
-                               BQ2419X_INPUT_SRC_REG);
+       /* Clear EN_HIZ */
+       ret = regmap_update_bits(charger->chip->regmap,
+                       BQ2419X_INPUT_SRC_REG, BQ2419X_EN_HIZ, 0);
+       if (ret < 0) {
+               dev_err(charger->dev, "error reading reg: 0x%x\n",
+                       BQ2419X_INPUT_SRC_REG);
+               return ret;
        }
+       /* Configure input current limit */
+       val = current_to_reg(iinlim, ARRAY_SIZE(iinlim),
+                               charger->in_current_limit);
+       if (val < 0)
+               return 0;
 
-       if (charger->ac_online) {
-               val = current_to_reg(iinlim, ARRAY_SIZE(iinlim),
-                                       charger->ac_in_current_limit);
-               if (val < 0)
-                       return 0;
-
-               ret = regmap_update_bits(charger->chip->regmap,
+       ret = regmap_update_bits(charger->chip->regmap,
                        BQ2419X_INPUT_SRC_REG, BQ2419x_CONFIG_MASK, val);
-               if (ret < 0)
-                       dev_err(charger->dev, "error reading reg: 0x%x\n",
-                               BQ2419X_INPUT_SRC_REG);
-       }
+       if (ret < 0)
+               dev_err(charger->dev, "error reading reg: 0x%x\n",
+                       BQ2419X_INPUT_SRC_REG);
        return ret;
 }
 
@@ -192,7 +185,7 @@ static int bq2419x_enable_charger(struct regulator_dev *rdev,
        if ((val & BQ2419x_VBUS_STAT) == BQ2419x_VBUS_UNKNOWN) {
                bq_charger->status = 0;
                bq_charger->usb_online = 0;
-               bq_charger->usb_in_current_limit = 500;
+               bq_charger->in_current_limit = 500;
                ret = bq2419x_init(bq_charger);
                if (ret < 0)
                        goto error;
@@ -202,7 +195,7 @@ static int bq2419x_enable_charger(struct regulator_dev *rdev,
        } else if ((val & BQ2419x_VBUS_STAT) == BQ2419x_VBUS_USB) {
                bq_charger->status = 1;
                bq_charger->usb_online = 1;
-               bq_charger->usb_in_current_limit = max_uA/1000;
+               bq_charger->in_current_limit = max_uA/1000;
                ret = bq2419x_init(bq_charger);
                if (ret < 0)
                        goto error;
@@ -212,7 +205,7 @@ static int bq2419x_enable_charger(struct regulator_dev *rdev,
        } else if ((val & BQ2419x_VBUS_STAT) == BQ2419x_VBUS_AC) {
                bq_charger->status = 1;
                bq_charger->ac_online = 1;
-               bq_charger->ac_in_current_limit = max_uA/1000;
+               bq_charger->in_current_limit = max_uA/1000;
                ret = bq2419x_init(bq_charger);
                if (ret < 0)
                        goto error;