power: bq2419x: Smooth charging ramp-up
Syed Rafiuddin [Thu, 18 Apr 2013 05:05:24 +0000 (10:05 +0530)]
Add support to have a smooth charging current ramp-up.

Bug 1262682

Change-Id: Ia1987172d416d17fde39ec2d428ca7b28f4a28c4
Signed-off-by: Pradeep Goudagunta <pgoudagunta@nvidia.com>
Signed-off-by: Syed Rafiuddin <srafiuddin@nvidia.com>
Reviewed-on: http://git-master/r/219614
(cherry picked from commit 54bcefe32147b03ff2ba69a386339867b4eafa03)
Reviewed-on: http://git-master/r/228391
Reviewed-by: Riham Haidar <rhaidar@nvidia.com>
Tested-by: Riham Haidar <rhaidar@nvidia.com>

drivers/power/bq2419x-charger.c
include/linux/power/bq2419x-charger.h

index 7021967..d82a99a 100644 (file)
@@ -217,38 +217,41 @@ static int bq2419x_usb_get_property(struct power_supply *psy,
 
 static int bq2419x_init(struct bq2419x_chip *bq2419x)
 {
-       int val, ret = 0;
+       int val = 0;
+       int ret = 0;
+       int floor = 0;
+
+       /* Configure input voltage to 4.52 in case of NV charger */
+       if (bq2419x->in_current_limit == 2000)
+               val |= BQ2419x_NVCHARGER_INPUT_VOL_SEL;
+       else
+               val |= BQ2419x_DEFAULT_INPUT_VOL_SEL;
 
        /* Clear EN_HIZ */
-       ret = regmap_update_bits(bq2419x->regmap,
-                       BQ2419X_INPUT_SRC_REG, BQ2419X_EN_HIZ, 0);
+       ret = regmap_update_bits(bq2419x->regmap, BQ2419X_INPUT_SRC_REG,
+                       BQ2419X_EN_HIZ | BQ2419x_INPUT_VOLTAGE_MASK, val);
        if (ret < 0) {
-               dev_err(bq2419x->dev, "error reading reg: 0x%x\n",
-                       BQ2419X_INPUT_SRC_REG);
+               dev_err(bq2419x->dev, "INPUT_SRC_REG update failed %d\n", ret);
                return ret;
        }
 
        /* Configure input current limit */
        val = current_to_reg(iinlim, ARRAY_SIZE(iinlim),
                                bq2419x->in_current_limit);
-       if (val < 0)
-               return 0;
 
-       val &= ~(BQ2419x_INPUT_VOLTAGE_MASK);
-       /* Configure inout voltage to 4.52 in case of NV
-       *  NV charger.
-       */
-       if (bq2419x->in_current_limit == 2000)
-               val |= BQ2419x_NVCHARGER_INPUT_VOL_SEL;
-       else
-               val |= BQ2419x_DEFAULT_INPUT_VOL_SEL;
+       /* Start from 500mA and then step to val */
+       floor = current_to_reg(iinlim, ARRAY_SIZE(iinlim), 500);
+       if (val < 0 || floor < 0)
+               return 0;
 
-       ret = regmap_update_bits(bq2419x->regmap,
-                       BQ2419X_INPUT_SRC_REG, BQ2419x_CONFIG_MASK |
-                       BQ2419x_INPUT_VOLTAGE_MASK, val);
-       if (ret < 0)
-               dev_err(bq2419x->dev, "error reading reg: 0x%x\n",
-                       BQ2419X_INPUT_SRC_REG);
+       for (; floor <= val; floor++) {
+               udelay(BQ2419x_CHARGING_CURRENT_STEP_DELAY_US);
+               ret = regmap_update_bits(bq2419x->regmap, BQ2419X_INPUT_SRC_REG,
+                               BQ2419x_CONFIG_MASK, floor);
+               if (ret < 0)
+                       dev_err(bq2419x->dev,
+                               "INPUT_SRC_REG update failed: %d\n", ret);
+       }
        return ret;
 }
 
index 30b72e7..21812ca 100644 (file)
@@ -84,6 +84,8 @@
 #define BQ2419x_NVCHARGER_INPUT_VOL_SEL        0x40
 #define BQ2419x_DEFAULT_INPUT_VOL_SEL  0x30
 
+#define BQ2419x_CHARGING_CURRENT_STEP_DELAY_US 1000
+
 #define BQ2419X_MAX_REGS               (BQ2419X_REVISION_REG + 1)
 
 /*