power: max77660-charger-extcon: Set charging current with correct functions
Darbha Sriharsha [Thu, 25 Jul 2013 08:42:24 +0000 (13:42 +0530)]
Use the full_charging_current_enable and charging_current_disable
functions to set and disable charging current in the regulator
function

Bug 1284514

Signed-off-by: Darbha Sriharsha <dsriharsha@nvidia.com>
Reviewed-on: http://git-master/r/239690
(cherry picked from commit 650c8a8431f443aac6b44641aee987134a23b6c5)

Change-Id: I1433ac3e379238df33535454780e31a965b87a01
Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com>
Reviewed-on: http://git-master/r/253356
Reviewed-by: Automatic_Commit_Validation_User

drivers/power/max77660-charger-extcon.c

index fb0fe22..dc91307 100644 (file)
@@ -271,6 +271,56 @@ static int max77660_charger_init(struct max77660_chg_extcon *chip, int enable)
        return 0;
 }
 
+int max77660_full_current_enable(struct max77660_chg_extcon *chip)
+{
+       int ret;
+
+       ret = max77660_charger_init(chip, true);
+       if (ret < 0) {
+               dev_err(chip->dev,
+                       "Failed to initialise full current charging\n");
+               return ret;
+       }
+
+       chip->charging_state = ENABLED_FULL_IBAT;
+
+       return 0;
+}
+
+int max77660_half_current_enable(struct max77660_chg_extcon *chip)
+{
+       int ret;
+       int temp;
+
+       temp = chip->charger->in_current_lim;
+       chip->charger->in_current_lim = chip->charger->in_current_lim/2;
+       ret = max77660_charger_init(chip, true);
+       if (ret < 0) {
+               dev_err(chip->dev,
+                       "Failed to initialise full current charging\n");
+               return ret;
+       }
+       chip->charger->in_current_lim = temp;
+       chip->charging_state = ENABLED_HALF_IBAT;
+
+       return 0;
+}
+
+int max77660_charging_disable(struct max77660_chg_extcon *chip)
+{
+       int ret;
+
+       ret = max77660_charger_init(chip, false);
+       if (ret < 0) {
+               dev_err(chip->dev,
+                       "Failed to disable charging\n");
+               return ret;
+       }
+       chip->charging_state = DISABLED;
+
+       return 0;
+}
+
 static int max77660_set_charging_current(struct regulator_dev *rdev,
                int min_uA, int max_uA)
 {
@@ -300,14 +350,15 @@ static int max77660_set_charging_current(struct regulator_dev *rdev,
                return 0;
 
        if (charger->in_current_lim == 0) {
-               ret = max77660_charger_init(chip, false);
+               chip->cable_connected = 0;
+               ret = max77660_charging_disable(chip);
                if (ret < 0)
                        goto error;
                battery_charging_status_update(chip->bc_dev,
                                        BATTERY_DISCHARGING);
        } else {
                charger->status = BATTERY_CHARGING;
-               ret = max77660_charger_init(chip, true);
+               ret = max77660_full_current_enable(chip);
                if (ret < 0)
                        goto error;
                battery_charging_status_update(chip->bc_dev,