Commit c0c61471 authored by Robin Murphy's avatar Robin Murphy Committed by Felipe Balbi

usb: dwc3: of-simple: Convert to bulk clk API

Now that the bulk API has a "get all of the clocks" helper to match
what this code wants, there's little reason not to switch over.
Signed-off-by: default avatarRobin Murphy <robin.murphy@arm.com>
Signed-off-by: default avatarFelipe Balbi <felipe.balbi@linux.intel.com>
parent b4c53b4a
...@@ -24,59 +24,13 @@ ...@@ -24,59 +24,13 @@
struct dwc3_of_simple { struct dwc3_of_simple {
struct device *dev; struct device *dev;
struct clk **clks; struct clk_bulk_data *clks;
int num_clocks; int num_clocks;
struct reset_control *resets; struct reset_control *resets;
bool pulse_resets; bool pulse_resets;
bool need_reset; 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) static int dwc3_of_simple_probe(struct platform_device *pdev)
{ {
struct dwc3_of_simple *simple; struct dwc3_of_simple *simple;
...@@ -84,7 +38,6 @@ static int dwc3_of_simple_probe(struct platform_device *pdev) ...@@ -84,7 +38,6 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
int ret; int ret;
int i;
bool shared_resets = false; bool shared_resets = false;
simple = devm_kzalloc(dev, sizeof(*simple), GFP_KERNEL); simple = devm_kzalloc(dev, sizeof(*simple), GFP_KERNEL);
...@@ -124,20 +77,18 @@ static int dwc3_of_simple_probe(struct platform_device *pdev) ...@@ -124,20 +77,18 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
goto err_resetc_put; goto err_resetc_put;
} }
ret = dwc3_of_simple_clk_init(simple, of_count_phandle_with_args(np, ret = clk_bulk_get_all(simple->dev, &simple->clks);
"clocks", "#clock-cells")); if (ret < 0)
goto err_resetc_assert;
simple->num_clocks = ret;
ret = clk_bulk_prepare_enable(simple->num_clocks, simple->clks);
if (ret) if (ret)
goto err_resetc_assert; goto err_resetc_assert;
ret = of_platform_populate(np, NULL, NULL, dev); ret = of_platform_populate(np, NULL, NULL, dev);
if (ret) { if (ret)
for (i = 0; i < simple->num_clocks; i++) { goto err_clk_put;
clk_disable_unprepare(simple->clks[i]);
clk_put(simple->clks[i]);
}
goto err_resetc_assert;
}
pm_runtime_set_active(dev); pm_runtime_set_active(dev);
pm_runtime_enable(dev); pm_runtime_enable(dev);
...@@ -145,6 +96,10 @@ static int dwc3_of_simple_probe(struct platform_device *pdev) ...@@ -145,6 +96,10 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
return 0; 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: err_resetc_assert:
if (!simple->pulse_resets) if (!simple->pulse_resets)
reset_control_assert(simple->resets); reset_control_assert(simple->resets);
...@@ -158,14 +113,11 @@ static int dwc3_of_simple_remove(struct platform_device *pdev) ...@@ -158,14 +113,11 @@ static int dwc3_of_simple_remove(struct platform_device *pdev)
{ {
struct dwc3_of_simple *simple = platform_get_drvdata(pdev); struct dwc3_of_simple *simple = platform_get_drvdata(pdev);
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
int i;
of_platform_depopulate(dev); of_platform_depopulate(dev);
for (i = 0; i < simple->num_clocks; i++) { clk_bulk_disable_unprepare(simple->num_clocks, simple->clks);
clk_disable_unprepare(simple->clks[i]); clk_bulk_put_all(simple->num_clocks, simple->clks);
clk_put(simple->clks[i]);
}
simple->num_clocks = 0; simple->num_clocks = 0;
if (!simple->pulse_resets) if (!simple->pulse_resets)
...@@ -183,10 +135,8 @@ static int dwc3_of_simple_remove(struct platform_device *pdev) ...@@ -183,10 +135,8 @@ static int dwc3_of_simple_remove(struct platform_device *pdev)
static int __maybe_unused dwc3_of_simple_runtime_suspend(struct device *dev) static int __maybe_unused dwc3_of_simple_runtime_suspend(struct device *dev)
{ {
struct dwc3_of_simple *simple = dev_get_drvdata(dev); struct dwc3_of_simple *simple = dev_get_drvdata(dev);
int i;
for (i = 0; i < simple->num_clocks; i++) clk_bulk_disable(simple->num_clocks, simple->clks);
clk_disable(simple->clks[i]);
return 0; return 0;
} }
...@@ -194,19 +144,8 @@ static int __maybe_unused dwc3_of_simple_runtime_suspend(struct device *dev) ...@@ -194,19 +144,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) static int __maybe_unused dwc3_of_simple_runtime_resume(struct device *dev)
{ {
struct dwc3_of_simple *simple = dev_get_drvdata(dev); struct dwc3_of_simple *simple = dev_get_drvdata(dev);
int ret;
int i;
for (i = 0; i < simple->num_clocks; i++) { return clk_bulk_enable(simple->num_clocks, simple->clks);
ret = clk_enable(simple->clks[i]);
if (ret < 0) {
while (--i >= 0)
clk_disable(simple->clks[i]);
return ret;
}
}
return 0;
} }
static int __maybe_unused dwc3_of_simple_suspend(struct device *dev) static int __maybe_unused dwc3_of_simple_suspend(struct device *dev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment