mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/5] clk: implement and use clk_bulk_get_all_enabled helper
Date: Mon,  5 Jan 2026 20:12:54 +0100	[thread overview]
Message-ID: <20260105191410.615318-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260105191410.615318-1-a.fatoum@pengutronix.de>

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 <a.fatoum@pengutronix.de>
---
 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




  parent reply	other threads:[~2026-01-05 19:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05 19:12 [PATCH 0/5] usb: dwc3: add fsl,ls1028a-dwc3 glue driver Ahmad Fatoum
2026-01-05 19:12 ` [PATCH 1/5] usb: dwc3: export dwc3_core_probe/dwc3_core_remove like Linux Ahmad Fatoum
2026-01-05 19:12 ` [PATCH 2/5] usb: dwc3: add support for Global SoC Bus Configuration Register Ahmad Fatoum
2026-01-05 19:12 ` Ahmad Fatoum [this message]
2026-01-05 19:12 ` [PATCH 4/5] usb: dwc3: add DesignWare USB3 generic platform driver Ahmad Fatoum
2026-01-05 19:12 ` [PATCH 5/5] Revert "ARM64: dts: Layerscape: workaround v6.19-rc1 DT sync DWC3 breakage" Ahmad Fatoum
2026-01-06  8:12 ` [PATCH 0/5] usb: dwc3: add fsl,ls1028a-dwc3 glue driver Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260105191410.615318-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox