mfd: Add tps6507x board data structure
[safe/jmp/linux-2.6] / drivers / regulator / wm8400-regulator.c
index 48b372e..924c7eb 100644 (file)
@@ -43,6 +43,18 @@ static int wm8400_ldo_disable(struct regulator_dev *dev)
                               WM8400_LDO1_ENA, 0);
 }
 
+static int wm8400_ldo_list_voltage(struct regulator_dev *dev,
+                                  unsigned selector)
+{
+       if (selector > WM8400_LDO1_VSEL_MASK)
+               return -EINVAL;
+
+       if (selector < 15)
+               return 900000 + (selector * 50000);
+       else
+               return 1600000 + ((selector - 14) * 100000);
+}
+
 static int wm8400_ldo_get_voltage(struct regulator_dev *dev)
 {
        struct wm8400 *wm8400 = rdev_get_drvdata(dev);
@@ -51,10 +63,7 @@ static int wm8400_ldo_get_voltage(struct regulator_dev *dev)
        val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev));
        val &= WM8400_LDO1_VSEL_MASK;
 
-       if (val < 15)
-               return 900000 + (val * 50000);
-       else
-               return 1600000 + ((val - 14) * 100000);
+       return wm8400_ldo_list_voltage(dev, val);
 }
 
 static int wm8400_ldo_set_voltage(struct regulator_dev *dev,
@@ -92,6 +101,7 @@ static struct regulator_ops wm8400_ldo_ops = {
        .is_enabled = wm8400_ldo_is_enabled,
        .enable = wm8400_ldo_enable,
        .disable = wm8400_ldo_disable,
+       .list_voltage = wm8400_ldo_list_voltage,
        .get_voltage = wm8400_ldo_get_voltage,
        .set_voltage = wm8400_ldo_set_voltage,
 };
@@ -124,6 +134,15 @@ static int wm8400_dcdc_disable(struct regulator_dev *dev)
                               WM8400_DC1_ENA, 0);
 }
 
+static int wm8400_dcdc_list_voltage(struct regulator_dev *dev,
+                                   unsigned selector)
+{
+       if (selector > WM8400_DC1_VSEL_MASK)
+               return -EINVAL;
+
+       return 850000 + (selector * 25000);
+}
+
 static int wm8400_dcdc_get_voltage(struct regulator_dev *dev)
 {
        struct wm8400 *wm8400 = rdev_get_drvdata(dev);
@@ -237,6 +256,7 @@ static struct regulator_ops wm8400_dcdc_ops = {
        .is_enabled = wm8400_dcdc_is_enabled,
        .enable = wm8400_dcdc_enable,
        .disable = wm8400_dcdc_disable,
+       .list_voltage = wm8400_dcdc_list_voltage,
        .get_voltage = wm8400_dcdc_get_voltage,
        .set_voltage = wm8400_dcdc_set_voltage,
        .get_mode = wm8400_dcdc_get_mode,
@@ -249,6 +269,7 @@ static struct regulator_desc regulators[] = {
                .name = "LDO1",
                .id = WM8400_LDO1,
                .ops = &wm8400_ldo_ops,
+               .n_voltages = WM8400_LDO1_VSEL_MASK + 1,
                .type = REGULATOR_VOLTAGE,
                .owner = THIS_MODULE,
        },
@@ -256,6 +277,7 @@ static struct regulator_desc regulators[] = {
                .name = "LDO2",
                .id = WM8400_LDO2,
                .ops = &wm8400_ldo_ops,
+               .n_voltages = WM8400_LDO2_VSEL_MASK + 1,
                .type = REGULATOR_VOLTAGE,
                .owner = THIS_MODULE,
        },
@@ -263,6 +285,7 @@ static struct regulator_desc regulators[] = {
                .name = "LDO3",
                .id = WM8400_LDO3,
                .ops = &wm8400_ldo_ops,
+               .n_voltages = WM8400_LDO3_VSEL_MASK + 1,
                .type = REGULATOR_VOLTAGE,
                .owner = THIS_MODULE,
        },
@@ -270,6 +293,7 @@ static struct regulator_desc regulators[] = {
                .name = "LDO4",
                .id = WM8400_LDO4,
                .ops = &wm8400_ldo_ops,
+               .n_voltages = WM8400_LDO4_VSEL_MASK + 1,
                .type = REGULATOR_VOLTAGE,
                .owner = THIS_MODULE,
        },
@@ -277,6 +301,7 @@ static struct regulator_desc regulators[] = {
                .name = "DCDC1",
                .id = WM8400_DCDC1,
                .ops = &wm8400_dcdc_ops,
+               .n_voltages = WM8400_DC1_VSEL_MASK + 1,
                .type = REGULATOR_VOLTAGE,
                .owner = THIS_MODULE,
        },
@@ -284,21 +309,25 @@ static struct regulator_desc regulators[] = {
                .name = "DCDC2",
                .id = WM8400_DCDC2,
                .ops = &wm8400_dcdc_ops,
+               .n_voltages = WM8400_DC2_VSEL_MASK + 1,
                .type = REGULATOR_VOLTAGE,
                .owner = THIS_MODULE,
        },
 };
 
-static int __init wm8400_regulator_probe(struct platform_device *pdev)
+static int __devinit wm8400_regulator_probe(struct platform_device *pdev)
 {
+       struct wm8400 *wm8400 = container_of(pdev, struct wm8400, regulators[pdev->id]);
        struct regulator_dev *rdev;
 
        rdev = regulator_register(&regulators[pdev->id], &pdev->dev,
-               pdev->dev.driver_data);
+                                 pdev->dev.platform_data, wm8400);
 
        if (IS_ERR(rdev))
                return PTR_ERR(rdev);
 
+       platform_set_drvdata(pdev, rdev);
+
        return 0;
 }
 
@@ -306,6 +335,7 @@ static int __devexit wm8400_regulator_remove(struct platform_device *pdev)
 {
        struct regulator_dev *rdev = platform_get_drvdata(pdev);
 
+       platform_set_drvdata(pdev, NULL);
        regulator_unregister(rdev);
 
        return 0;
@@ -333,7 +363,7 @@ static struct platform_driver wm8400_regulator_driver = {
 int wm8400_register_regulator(struct device *dev, int reg,
                              struct regulator_init_data *initdata)
 {
-       struct wm8400 *wm8400 = dev->driver_data;
+       struct wm8400 *wm8400 = dev_get_drvdata(dev);
 
        if (wm8400->regulators[reg].name)
                return -EBUSY;
@@ -343,7 +373,6 @@ int wm8400_register_regulator(struct device *dev, int reg,
        wm8400->regulators[reg].name = "wm8400-regulator";
        wm8400->regulators[reg].id = reg;
        wm8400->regulators[reg].dev.parent = dev;
-       wm8400->regulators[reg].dev.driver_data = wm8400;
        wm8400->regulators[reg].dev.platform_data = initdata;
 
        return platform_device_register(&wm8400->regulators[reg]);
@@ -354,7 +383,7 @@ static int __init wm8400_regulator_init(void)
 {
        return platform_driver_register(&wm8400_regulator_driver);
 }
-module_init(wm8400_regulator_init);
+subsys_initcall(wm8400_regulator_init);
 
 static void __exit wm8400_regulator_exit(void)
 {