regulator: ab8500-ext: Register as a device in its own right
authorLee Jones <lee.jones@linaro.org>
Fri, 7 Jun 2013 16:11:26 +0000 (17:11 +0100)
committerMark Brown <broonielinaro.org>
Tue, 11 Jun 2013 11:50:00 +0000 (12:50 +0100)
Some platforms don't support the AB8500 external regulators, so instead
of having a list of is_<platform>() calls prior to calling
ab8500_ext_regulator_init() from ab8500_regulator_probe(), we can only
register as a platform device on platforms which require them. It means
we also have more control over them when booting with Device Tree.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Mark Brown <broonielinaro.org>
drivers/regulator/ab8500-ext.c
drivers/regulator/ab8500.c
include/linux/regulator/ab8500.h

index e4975bc61e810c5846d8495dd6cd9c463394c3e3..95f495f51d001ec89a058e718e3778d7bd037e71 100644 (file)
@@ -333,7 +333,7 @@ static struct ab8500_ext_regulator_info
        },
 };
 
-int ab8500_ext_regulator_init(struct platform_device *pdev)
+int ab8500_ext_regulator_probe(struct platform_device *pdev)
 {
        struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
        struct ab8500_platform_data *ppdata;
@@ -409,7 +409,7 @@ int ab8500_ext_regulator_init(struct platform_device *pdev)
        return 0;
 }
 
-void ab8500_ext_regulator_exit(struct platform_device *pdev)
+int ab8500_ext_regulator_remove(struct platform_device *pdev)
 {
        int i;
 
@@ -422,7 +422,36 @@ void ab8500_ext_regulator_exit(struct platform_device *pdev)
 
                regulator_unregister(info->rdev);
        }
+
+       return 0;
+}
+
+static struct platform_driver ab8500_ext_regulator_driver = {
+       .probe = ab8500_ext_regulator_probe,
+       .remove = ab8500_ext_regulator_remove,
+       .driver         = {
+               .name   = "ab8500-ext-regulator",
+               .owner  = THIS_MODULE,
+       },
+};
+
+static int __init ab8500_ext_regulator_init(void)
+{
+       int ret;
+
+       ret = platform_driver_register(&ab8500_ext_regulator_driver);
+       if (ret)
+               pr_err("Failed to register ab8500 ext regulator: %d\n", ret);
+
+       return ret;
+}
+subsys_initcall(ab8500_ext_regulator_init);
+
+static void __exit ab8500_ext_regulator_exit(void)
+{
+       platform_driver_unregister(&ab8500_ext_regulator_driver);
 }
+module_exit(ab8500_ext_regulator_exit);
 
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Bengt Jonsson <bengt.g.jonsson@stericsson.com>");
index f6656b8c28b606f49cbecc8d47a63d9d61832a47..dfc790196b34ae744ffd76ba78750fa2ab111423 100644 (file)
@@ -3156,22 +3156,12 @@ static int ab8500_regulator_probe(struct platform_device *pdev)
                        return err;
        }
 
-       if (!is_ab8505(ab8500)) {
-               /* register external regulators (before Vaux1, 2 and 3) */
-               err = ab8500_ext_regulator_init(pdev);
-               if (err)
-                       return err;
-       }
-
        /* register all regulators */
        for (i = 0; i < abx500_regulator.info_size; i++) {
                err = ab8500_regulator_register(pdev, &pdata->regulator[i],
                                                i, NULL);
-               if (err < 0) {
-                       if (!is_ab8505(ab8500))
-                               ab8500_ext_regulator_exit(pdev);
+               if (err < 0)
                        return err;
-               }
        }
 
        return 0;
@@ -3180,7 +3170,6 @@ static int ab8500_regulator_probe(struct platform_device *pdev)
 static int ab8500_regulator_remove(struct platform_device *pdev)
 {
        int i, err;
-       struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
 
        for (i = 0; i < abx500_regulator.info_size; i++) {
                struct ab8500_regulator_info *info = NULL;
@@ -3192,10 +3181,6 @@ static int ab8500_regulator_remove(struct platform_device *pdev)
                regulator_unregister(info->regulator);
        }
 
-       /* remove external regulators (after Vaux1, 2 and 3) */
-       if (!is_ab8505(ab8500))
-               ab8500_ext_regulator_exit(pdev);
-
        /* remove regulator debug */
        err = ab8500_regulator_debug_exit(pdev);
        if (err)
index 7c5ff0c55773c41b076216d80aa5d26e59fae61e..75307447cef966eb3d168de7542c84181c849d63 100644 (file)
@@ -336,8 +336,4 @@ static inline int ab8500_regulator_debug_exit(struct platform_device *pdev)
 }
 #endif
 
-/* AB8500 external regulator functions. */
-int ab8500_ext_regulator_init(struct platform_device *pdev);
-void ab8500_ext_regulator_exit(struct platform_device *pdev);
-
 #endif