regulator: remove use of __devexit_p
[linux-3.10.git] / drivers / regulator / da9052-regulator.c
index 2678cbe..9caa6e6 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
 #ifdef CONFIG_OF
+#include <linux/of.h>
 #include <linux/regulator/of_regulator.h>
 #endif
 
@@ -69,8 +70,6 @@ struct da9052_regulator_info {
        int step_uV;
        int min_uV;
        int max_uV;
-       unsigned char volt_shift;
-       unsigned char en_bit;
        unsigned char activate_bit;
 };
 
@@ -89,42 +88,6 @@ static int verify_range(struct da9052_regulator_info *info,
        return 0;
 }
 
-static int da9052_regulator_enable(struct regulator_dev *rdev)
-{
-       struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
-       struct da9052_regulator_info *info = regulator->info;
-       int offset = rdev_get_id(rdev);
-
-       return da9052_reg_update(regulator->da9052,
-                                DA9052_BUCKCORE_REG + offset,
-                                1 << info->en_bit, 1 << info->en_bit);
-}
-
-static int da9052_regulator_disable(struct regulator_dev *rdev)
-{
-       struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
-       struct da9052_regulator_info *info = regulator->info;
-       int offset = rdev_get_id(rdev);
-
-       return da9052_reg_update(regulator->da9052,
-                                DA9052_BUCKCORE_REG + offset,
-                                1 << info->en_bit, 0);
-}
-
-static int da9052_regulator_is_enabled(struct regulator_dev *rdev)
-{
-       struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
-       struct da9052_regulator_info *info = regulator->info;
-       int offset = rdev_get_id(rdev);
-       int ret;
-
-       ret = da9052_reg_read(regulator->da9052, DA9052_BUCKCORE_REG + offset);
-       if (ret < 0)
-               return ret;
-
-       return ret & (1 << info->en_bit);
-}
-
 static int da9052_dcdc_get_current_limit(struct regulator_dev *rdev)
 {
        struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
@@ -170,8 +133,8 @@ static int da9052_dcdc_set_current_limit(struct regulator_dev *rdev, int min_uA,
            max_uA < da9052_current_limits[row][DA9052_MIN_UA])
                return -EINVAL;
 
-       for (i = 0; i < DA9052_CURRENT_RANGE; i++) {
-               if (min_uA <= da9052_current_limits[row][i]) {
+       for (i = DA9052_CURRENT_RANGE - 1; i >= 0; i--) {
+               if (da9052_current_limits[row][i] <= max_uA) {
                        reg_val = i;
                        break;
                }
@@ -216,14 +179,13 @@ static int da9052_list_voltage(struct regulator_dev *rdev,
        return volt_uV;
 }
 
-static int da9052_regulator_set_voltage(struct regulator_dev *rdev,
-                                            int min_uV, int max_uV,
-                                            unsigned int *selector)
+static int da9052_map_voltage(struct regulator_dev *rdev,
+                             int min_uV, int max_uV)
 {
        struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
        struct da9052_regulator_info *info = regulator->info;
        int id = rdev_get_id(rdev);
-       int ret;
+       int ret, sel;
 
        ret = verify_range(info, min_uV, max_uV);
        if (ret < 0)
@@ -234,20 +196,30 @@ static int da9052_regulator_set_voltage(struct regulator_dev *rdev,
 
        if ((id == DA9052_ID_BUCK4) && (regulator->da9052->chip_id == DA9052)
                && (min_uV >= DA9052_CONST_3uV)) {
-                       *selector = DA9052_BUCK_PERI_REG_MAP_UPTO_3uV +
-                                   DIV_ROUND_UP(min_uV - DA9052_CONST_3uV,
-                                                DA9052_BUCK_PERI_3uV_STEP);
+                       sel = DA9052_BUCK_PERI_REG_MAP_UPTO_3uV +
+                             DIV_ROUND_UP(min_uV - DA9052_CONST_3uV,
+                                          DA9052_BUCK_PERI_3uV_STEP);
        } else {
-               *selector = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
+               sel = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV);
        }
 
-       ret = da9052_list_voltage(rdev, *selector);
+       ret = da9052_list_voltage(rdev, sel);
        if (ret < 0)
                return ret;
 
-       ret = da9052_reg_update(regulator->da9052,
-                                DA9052_BUCKCORE_REG + id,
-                                (1 << info->volt_shift) - 1, *selector);
+       return sel;
+}
+
+static int da9052_regulator_set_voltage_sel(struct regulator_dev *rdev,
+                                           unsigned int selector)
+{
+       struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
+       struct da9052_regulator_info *info = regulator->info;
+       int id = rdev_get_id(rdev);
+       int ret;
+
+       ret = da9052_reg_update(regulator->da9052, rdev->desc->vsel_reg,
+                               rdev->desc->vsel_mask, selector);
        if (ret < 0)
                return ret;
 
@@ -268,42 +240,27 @@ static int da9052_regulator_set_voltage(struct regulator_dev *rdev,
        return ret;
 }
 
-static int da9052_get_regulator_voltage_sel(struct regulator_dev *rdev)
-{
-       struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
-       struct da9052_regulator_info *info = regulator->info;
-       int offset = rdev_get_id(rdev);
-       int ret;
-
-       ret = da9052_reg_read(regulator->da9052, DA9052_BUCKCORE_REG + offset);
-       if (ret < 0)
-               return ret;
-
-       ret &= ((1 << info->volt_shift) - 1);
-
-       return ret;
-}
-
 static struct regulator_ops da9052_dcdc_ops = {
-       .set_voltage = da9052_regulator_set_voltage,
        .get_current_limit = da9052_dcdc_get_current_limit,
        .set_current_limit = da9052_dcdc_set_current_limit,
 
        .list_voltage = da9052_list_voltage,
-       .get_voltage_sel = da9052_get_regulator_voltage_sel,
-       .is_enabled = da9052_regulator_is_enabled,
-       .enable = da9052_regulator_enable,
-       .disable = da9052_regulator_disable,
+       .map_voltage = da9052_map_voltage,
+       .get_voltage_sel = regulator_get_voltage_sel_regmap,
+       .set_voltage_sel = da9052_regulator_set_voltage_sel,
+       .is_enabled = regulator_is_enabled_regmap,
+       .enable = regulator_enable_regmap,
+       .disable = regulator_disable_regmap,
 };
 
 static struct regulator_ops da9052_ldo_ops = {
-       .set_voltage = da9052_regulator_set_voltage,
-
        .list_voltage = da9052_list_voltage,
-       .get_voltage_sel = da9052_get_regulator_voltage_sel,
-       .is_enabled = da9052_regulator_is_enabled,
-       .enable = da9052_regulator_enable,
-       .disable = da9052_regulator_disable,
+       .map_voltage = da9052_map_voltage,
+       .get_voltage_sel = regulator_get_voltage_sel_regmap,
+       .set_voltage_sel = da9052_regulator_set_voltage_sel,
+       .is_enabled = regulator_is_enabled_regmap,
+       .enable = regulator_enable_regmap,
+       .disable = regulator_disable_regmap,
 };
 
 #define DA9052_LDO(_id, step, min, max, sbits, ebits, abits) \
@@ -315,12 +272,14 @@ static struct regulator_ops da9052_ldo_ops = {
                .id = DA9052_ID_##_id,\
                .n_voltages = (max - min) / step + 1, \
                .owner = THIS_MODULE,\
+               .vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
+               .vsel_mask = (1 << (sbits)) - 1,\
+               .enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
+               .enable_mask = 1 << (ebits),\
        },\
        .min_uV = (min) * 1000,\
        .max_uV = (max) * 1000,\
        .step_uV = (step) * 1000,\
-       .volt_shift = (sbits),\
-       .en_bit = (ebits),\
        .activate_bit = (abits),\
 }
 
@@ -333,12 +292,14 @@ static struct regulator_ops da9052_ldo_ops = {
                .id = DA9052_ID_##_id,\
                .n_voltages = (max - min) / step + 1, \
                .owner = THIS_MODULE,\
+               .vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
+               .vsel_mask = (1 << (sbits)) - 1,\
+               .enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \
+               .enable_mask = 1 << (ebits),\
        },\
        .min_uV = (min) * 1000,\
        .max_uV = (max) * 1000,\
        .step_uV = (step) * 1000,\
-       .volt_shift = (sbits),\
-       .en_bit = (ebits),\
        .activate_bit = (abits),\
 }
 
@@ -429,6 +390,7 @@ static int __devinit da9052_regulator_probe(struct platform_device *pdev)
 
        config.dev = &pdev->dev;
        config.driver_data = regulator;
+       config.regmap = da9052->regmap;
        if (pdata && pdata->regulators) {
                config.init_data = pdata->regulators[pdev->id];
        } else {
@@ -443,12 +405,12 @@ static int __devinit da9052_regulator_probe(struct platform_device *pdev)
                if (!nproot)
                        return -ENODEV;
 
-               for (np = of_get_next_child(nproot, NULL); !np;
-                    np = of_get_next_child(nproot, np)) {
+               for_each_child_of_node(nproot, np) {
                        if (!of_node_cmp(np->name,
                                         regulator->info->reg_desc.name)) {
                                config.init_data = of_get_regulator_init_data(
                                        &pdev->dev, np);
+                               config.of_node = np;
                                break;
                        }
                }
@@ -478,7 +440,7 @@ static int __devexit da9052_regulator_remove(struct platform_device *pdev)
 
 static struct platform_driver da9052_regulator_driver = {
        .probe = da9052_regulator_probe,
-       .remove = __devexit_p(da9052_regulator_remove),
+       .remove = da9052_regulator_remove,
        .driver = {
                .name = "da9052-regulator",
                .owner = THIS_MODULE,