Merge tag 'drm-next-2019-05-09' of git://anongit.freedesktop.org/drm/drm
[linux-2.6-block.git] / drivers / usb / dwc3 / dwc3-of-simple.c
index 67ce2037472d8a39fe37c57974a41f66f752dd7e..bdac3e7d7b1841fdf7dadd20ed01c56e3ce6962c 100644 (file)
 
 struct dwc3_of_simple {
        struct device           *dev;
-       struct clk              **clks;
+       struct clk_bulk_data    *clks;
        int                     num_clocks;
        struct reset_control    *resets;
        bool                    pulse_resets;
        bool                    need_reset;
 };
 
-static int dwc3_of_simple_clk_init(struct dwc3_of_simple *simple, int count)
-{
-       struct device           *dev = simple->dev;
-       struct device_node      *np = dev->of_node;
-       int                     i;
-
-       simple->num_clocks = count;
-
-       if (!count)
-               return 0;
-
-       simple->clks = devm_kcalloc(dev, simple->num_clocks,
-                       sizeof(struct clk *), GFP_KERNEL);
-       if (!simple->clks)
-               return -ENOMEM;
-
-       for (i = 0; i < simple->num_clocks; i++) {
-               struct clk      *clk;
-               int             ret;
-
-               clk = of_clk_get(np, i);
-               if (IS_ERR(clk)) {
-                       while (--i >= 0) {
-                               clk_disable_unprepare(simple->clks[i]);
-                               clk_put(simple->clks[i]);
-                       }
-                       return PTR_ERR(clk);
-               }
-
-               ret = clk_prepare_enable(clk);
-               if (ret < 0) {
-                       while (--i >= 0) {
-                               clk_disable_unprepare(simple->clks[i]);
-                               clk_put(simple->clks[i]);
-                       }
-                       clk_put(clk);
-
-                       return ret;
-               }
-
-               simple->clks[i] = clk;
-       }
-
-       return 0;
-}
-
 static int dwc3_of_simple_probe(struct platform_device *pdev)
 {
        struct dwc3_of_simple   *simple;
@@ -84,7 +38,6 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
        struct device_node      *np = dev->of_node;
 
        int                     ret;
-       int                     i;
        bool                    shared_resets = false;
 
        simple = devm_kzalloc(dev, sizeof(*simple), GFP_KERNEL);
@@ -125,20 +78,18 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
                        goto err_resetc_put;
        }
 
-       ret = dwc3_of_simple_clk_init(simple, of_count_phandle_with_args(np,
-                                               "clocks", "#clock-cells"));
+       ret = clk_bulk_get_all(simple->dev, &simple->clks);
+       if (ret < 0)
+               goto err_resetc_assert;
+
+       simple->num_clocks = ret;
+       ret = clk_bulk_prepare_enable(simple->num_clocks, simple->clks);
        if (ret)
                goto err_resetc_assert;
 
        ret = of_platform_populate(np, NULL, NULL, dev);
-       if (ret) {
-               for (i = 0; i < simple->num_clocks; i++) {
-                       clk_disable_unprepare(simple->clks[i]);
-                       clk_put(simple->clks[i]);
-               }
-
-               goto err_resetc_assert;
-       }
+       if (ret)
+               goto err_clk_put;
 
        pm_runtime_set_active(dev);
        pm_runtime_enable(dev);
@@ -146,6 +97,10 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
 
        return 0;
 
+err_clk_put:
+       clk_bulk_disable_unprepare(simple->num_clocks, simple->clks);
+       clk_bulk_put_all(simple->num_clocks, simple->clks);
+
 err_resetc_assert:
        if (!simple->pulse_resets)
                reset_control_assert(simple->resets);
@@ -159,14 +114,11 @@ static int dwc3_of_simple_remove(struct platform_device *pdev)
 {
        struct dwc3_of_simple   *simple = platform_get_drvdata(pdev);
        struct device           *dev = &pdev->dev;
-       int                     i;
 
        of_platform_depopulate(dev);
 
-       for (i = 0; i < simple->num_clocks; i++) {
-               clk_disable_unprepare(simple->clks[i]);
-               clk_put(simple->clks[i]);
-       }
+       clk_bulk_disable_unprepare(simple->num_clocks, simple->clks);
+       clk_bulk_put_all(simple->num_clocks, simple->clks);
        simple->num_clocks = 0;
 
        if (!simple->pulse_resets)
@@ -184,10 +136,8 @@ static int dwc3_of_simple_remove(struct platform_device *pdev)
 static int __maybe_unused dwc3_of_simple_runtime_suspend(struct device *dev)
 {
        struct dwc3_of_simple   *simple = dev_get_drvdata(dev);
-       int                     i;
 
-       for (i = 0; i < simple->num_clocks; i++)
-               clk_disable(simple->clks[i]);
+       clk_bulk_disable(simple->num_clocks, simple->clks);
 
        return 0;
 }
@@ -195,19 +145,8 @@ static int __maybe_unused dwc3_of_simple_runtime_suspend(struct device *dev)
 static int __maybe_unused dwc3_of_simple_runtime_resume(struct device *dev)
 {
        struct dwc3_of_simple   *simple = dev_get_drvdata(dev);
-       int                     ret;
-       int                     i;
-
-       for (i = 0; i < simple->num_clocks; i++) {
-               ret = clk_enable(simple->clks[i]);
-               if (ret < 0) {
-                       while (--i >= 0)
-                               clk_disable(simple->clks[i]);
-                       return ret;
-               }
-       }
 
-       return 0;
+       return clk_bulk_enable(simple->num_clocks, simple->clks);
 }
 
 static int __maybe_unused dwc3_of_simple_suspend(struct device *dev)