Linux has a devm_clk_bulk_get_all_enabled helper for drivers that just want to get and enable all clocks associated with a device.
Import it to barebox and make use of it where applicable, except for dwc3-of-simple.c: The upstream Linux driver doesn't make use of it and we will want to sync DWC3 against Linux anyway, so this will reduce churn a tiny little bit. Signed-off-by: Ahmad Fatoum <[email protected]> --- drivers/bus/simple-pm-bus.c | 6 +----- drivers/clk/clk-bulk.c | 19 +++++++++++++++++++ drivers/usb/dwc3/core.c | 6 +----- drivers/usb/host/ehci-hcd.c | 5 +---- include/linux/clk.h | 16 ++++++++++++++++ 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/drivers/bus/simple-pm-bus.c b/drivers/bus/simple-pm-bus.c index 8536982b69c4..caafee1e407e 100644 --- a/drivers/bus/simple-pm-bus.c +++ b/drivers/bus/simple-pm-bus.c @@ -16,13 +16,9 @@ static int simple_pm_bus_probe(struct device *dev) int num_clks; if (deep_probe_is_supported()) { - num_clks = clk_bulk_get_all(dev, &clks); + num_clks = clk_bulk_get_all_enabled(dev, &clks); if (num_clks < 0) return dev_err_probe(dev, num_clks, "failed to get clocks\n"); - - num_clks = clk_bulk_prepare_enable(num_clks, clks); - if (num_clks) - return dev_err_probe(dev, num_clks, "failed to enable clocks\n"); } of_platform_populate(np, NULL, dev); diff --git a/drivers/clk/clk-bulk.c b/drivers/clk/clk-bulk.c index db775dc40b39..c16fed282b21 100644 --- a/drivers/clk/clk-bulk.c +++ b/drivers/clk/clk-bulk.c @@ -153,6 +153,25 @@ int __must_check clk_bulk_get_all(struct device *dev, } EXPORT_SYMBOL(clk_bulk_get_all); +int __must_check clk_bulk_get_all_enabled(struct device *dev, + struct clk_bulk_data **clks) +{ + int ret, num_clks; + + num_clks = clk_bulk_get_all(dev, clks); + if (num_clks <= 0) + return num_clks; + + ret = clk_bulk_prepare_enable(num_clks, *clks); + if (ret < 0) { + clk_bulk_put_all(num_clks, *clks); + return ret; + } + + return num_clks; +} +EXPORT_SYMBOL_GPL(devm_clk_bulk_get_all_enabled); + /** * clk_bulk_disable - gate a set of clocks * @num_clks: the number of clk_bulk_data diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index cb22f19e39cc..747245f908a4 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1454,17 +1454,13 @@ int dwc3_core_probe(const struct dwc3_probe_data *data) if (!data->ignore_clocks_and_resets) { if (dev->of_node) { - ret = clk_bulk_get_all(dev, &dwc->clks); + ret = clk_bulk_get_all_enabled(dev, &dwc->clks); if (ret < 0) return ret; dwc->num_clks = ret; } - ret = clk_bulk_enable(dwc->num_clks, dwc->clks); - if (ret) - return ret; - dwc->reset = reset_control_get(dev, NULL); if (IS_ERR(dwc->reset)) { dev_err(dev, "Failed to get reset control: %pe\n", dwc->reset); diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c index 5fde8d2a4abd..51b9e52a4ffe 100644 --- a/drivers/usb/host/ehci-hcd.c +++ b/drivers/usb/host/ehci-hcd.c @@ -1442,14 +1442,11 @@ static int ehci_probe(struct device *dev) if (ret) return ret; - ret = clk_bulk_get_all(dev, &clks); + ret = clk_bulk_get_all_enabled(dev, &clks); if (ret < 0) return ret; num_clocks = ret; - ret = clk_bulk_enable(num_clocks, clks); - if (ret) - return ret; iores = dev_request_mem_resource(dev, 0); if (IS_ERR(iores)) diff --git a/include/linux/clk.h b/include/linux/clk.h index 526641927754..7673937a0a82 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -1032,6 +1032,22 @@ int __must_check clk_bulk_get_optional(struct device *dev, int num_clks, int __must_check clk_bulk_get_all(struct device *dev, struct clk_bulk_data **clks); +/** + * devm_clk_bulk_get_all_enabled - Get and enable all clocks of the consumer + * @dev: device for clock "consumer" + * @clks: pointer to the clk_bulk_data table of consumer + * + * Returns a positive value for the number of clocks obtained while the + * clock references are stored in the clk_bulk_data table in @clks field. + * Returns 0 if there're none and a negative value if something failed. + * + * This helper function allows drivers to get all clocks of the + * consumer and enables them in one operation. + */ + +int __must_check clk_bulk_get_all_enabled(struct device *dev, + struct clk_bulk_data **clks); + /** * clk_bulk_put - "free" the clock source * @num_clks: the number of clk_bulk_data -- 2.47.3
