regulator: Convert max8997 to get_voltage_sel
authorAxel Lin <axel.lin@gmail.com>
Wed, 11 Apr 2012 14:56:11 +0000 (22:56 +0800)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Tue, 17 Apr 2012 14:25:10 +0000 (15:25 +0100)
Also rename get_current_limit and set_current_limit callbacks
to max8997_get_current_limit and max8997_set_current_limit for
better readability.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
drivers/regulator/max8997.c

index db09244bb3edb2305d8765cffd270ba5f5a00586..56402e87925e35fee44cbe157d83d2e393786a15 100644 (file)
@@ -382,7 +382,7 @@ static int max8997_get_voltage_register(struct regulator_dev *rdev,
        return 0;
 }
 
-static int max8997_get_voltage(struct regulator_dev *rdev)
+static int max8997_get_voltage_sel(struct regulator_dev *rdev)
 {
        struct max8997_data *max8997 = rdev_get_drvdata(rdev);
        struct i2c_client *i2c = max8997->iodev->i2c;
@@ -400,15 +400,7 @@ static int max8997_get_voltage(struct regulator_dev *rdev)
        val >>= shift;
        val &= mask;
 
-       if (rdev->desc && rdev->desc->ops && rdev->desc->ops->list_voltage)
-               return rdev->desc->ops->list_voltage(rdev, val);
-
-       /*
-        * max8997_list_voltage returns value for any rdev with voltage_map,
-        * which works for "CHARGER" and "CHARGER TOPOFF" that do not have
-        * list_voltage ops (they are current regulators).
-        */
-       return max8997_list_voltage(rdev, val);
+       return val;
 }
 
 static inline int max8997_get_voltage_proper_val(
@@ -786,7 +778,7 @@ static struct regulator_ops max8997_ldo_ops = {
        .is_enabled             = max8997_reg_is_enabled,
        .enable                 = max8997_reg_enable,
        .disable                = max8997_reg_disable,
-       .get_voltage            = max8997_get_voltage,
+       .get_voltage_sel        = max8997_get_voltage_sel,
        .set_voltage            = max8997_set_voltage_ldobuck,
        .set_suspend_enable     = max8997_reg_enable_suspend,
        .set_suspend_disable    = max8997_reg_disable_suspend,
@@ -797,7 +789,7 @@ static struct regulator_ops max8997_buck_ops = {
        .is_enabled             = max8997_reg_is_enabled,
        .enable                 = max8997_reg_enable,
        .disable                = max8997_reg_disable,
-       .get_voltage            = max8997_get_voltage,
+       .get_voltage_sel        = max8997_get_voltage_sel,
        .set_voltage            = max8997_set_voltage_buck,
        .set_suspend_enable     = max8997_reg_enable_suspend,
        .set_suspend_disable    = max8997_reg_disable_suspend,
@@ -817,7 +809,7 @@ static struct regulator_ops max8997_safeout_ops = {
        .is_enabled             = max8997_reg_is_enabled,
        .enable                 = max8997_reg_enable,
        .disable                = max8997_reg_disable,
-       .get_voltage            = max8997_get_voltage,
+       .get_voltage_sel        = max8997_get_voltage_sel,
        .set_voltage            = max8997_set_voltage_safeout,
        .set_suspend_enable     = max8997_reg_enable_suspend,
        .set_suspend_disable    = max8997_reg_disable_suspend,
@@ -825,31 +817,50 @@ static struct regulator_ops max8997_safeout_ops = {
 
 static struct regulator_ops max8997_fixedstate_ops = {
        .list_voltage           = max8997_list_voltage_charger_cv,
-       .get_voltage            = max8997_get_voltage,
+       .get_voltage_sel        = max8997_get_voltage_sel,
        .set_voltage            = max8997_set_voltage_charger_cv,
 };
 
-static int max8997_set_voltage_ldobuck_wrap(struct regulator_dev *rdev,
-               int min_uV, int max_uV)
+static int max8997_set_current_limit(struct regulator_dev *rdev,
+                                    int min_uA, int max_uA)
 {
        unsigned dummy;
+       int rid = rdev_get_id(rdev);
+
+       if (rid != MAX8997_CHARGER && rid != MAX8997_CHARGER_TOPOFF)
+               return -EINVAL;
 
-       return max8997_set_voltage_ldobuck(rdev, min_uV, max_uV, &dummy);
+       /* Reuse max8997_set_voltage_ldobuck to set current_limit. */
+       return max8997_set_voltage_ldobuck(rdev, min_uA, max_uA, &dummy);
 }
 
+static int max8997_get_current_limit(struct regulator_dev *rdev)
+{
+       int sel, rid = rdev_get_id(rdev);
+
+       if (rid != MAX8997_CHARGER && rid != MAX8997_CHARGER_TOPOFF)
+               return -EINVAL;
+
+       sel = max8997_get_voltage_sel(rdev);
+       if (sel < 0)
+               return sel;
+
+       /* Reuse max8997_list_voltage to get current_limit. */
+       return max8997_list_voltage(rdev, sel);
+}
 
 static struct regulator_ops max8997_charger_ops = {
        .is_enabled             = max8997_reg_is_enabled,
        .enable                 = max8997_reg_enable,
        .disable                = max8997_reg_disable,
-       .get_current_limit      = max8997_get_voltage,
-       .set_current_limit      = max8997_set_voltage_ldobuck_wrap,
+       .get_current_limit      = max8997_get_current_limit,
+       .set_current_limit      = max8997_set_current_limit,
 };
 
 static struct regulator_ops max8997_charger_fixedstate_ops = {
        .is_enabled             = max8997_reg_is_enabled,
-       .get_current_limit      = max8997_get_voltage,
-       .set_current_limit      = max8997_set_voltage_ldobuck_wrap,
+       .get_current_limit      = max8997_get_current_limit,
+       .set_current_limit      = max8997_set_current_limit,
 };
 
 #define MAX8997_VOLTAGE_REGULATOR(_name, _ops) {\