[PATCH v7 2/2] clk: Search clocks of ACPI device with its companion device

Paul Cercueil paul.cercueil at bootlin.com
Tue Dec 1 04:15:31 PST 2026


If the device passed as argument to clk_get() has a companion ACPI
device, use it to search the clocks. If we can't find our clock there,
fall back to the regular path.

The argument for this, is that ACPI clocks are registered to clkdev
using the companion ACPI device's name, before the regular device object
is created.

Signed-off-by: Paul Cercueil <paul.cercueil at bootlin.com>
---

v7:
- Search for the ACPI clock after the regular path.
- Do not recurse with the ACPI device, as we want to create the clk with
  the regular device and not the ACPI companion device.
- Only search clocks with the ACPI companion device if its name differs
  from the main device

v6: New patch
---
 drivers/clk/clkdev.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 919fc680ae4d..8bd7cd9b25e0 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -6,6 +6,7 @@
  *
  * Helper for the clk API to assist looking up a struct clk.
  */
+#include <linux/acpi.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/device.h>
@@ -100,7 +101,10 @@ EXPORT_SYMBOL(clk_get_sys);
 struct clk *clk_get(struct device *dev, const char *con_id)
 {
 	const char *dev_id = dev ? dev_name(dev) : NULL;
+	struct acpi_device *adev;
+	const char *acpi_dev_id;
 	struct clk_hw *hw;
+	struct clk *clk;
 
 	if (dev && dev->of_node) {
 		hw = of_clk_get_hw(dev->of_node, 0, con_id);
@@ -108,7 +112,17 @@ struct clk *clk_get(struct device *dev, const char *con_id)
 			return clk_hw_create_clk(dev, hw, dev_id, con_id, NULL);
 	}
 
-	return __clk_get_sys(dev, dev_id, con_id);
+	clk = __clk_get_sys(dev, dev_id, con_id);
+
+	if (PTR_ERR(clk) == -ENOENT && dev && has_acpi_companion(dev)) {
+		adev = ACPI_COMPANION(dev);
+		acpi_dev_id = acpi_dev_name(adev);
+
+		if (strcmp(dev_id, acpi_dev_id))
+			clk = __clk_get_sys(dev, acpi_dev_id, con_id);
+	}
+
+	return clk;
 }
 EXPORT_SYMBOL(clk_get);
 
-- 
2.47.3




More information about the linux-arm-kernel mailing list