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

Paul Cercueil paul.cercueil at bootlin.com
Fri Dec 4 01:02:10 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 the clock using
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.

Note that a wildcard clkdev entry with dev_id == NULL shadowing a clock
registered for the ACPI companion device is not really a concern: those
clocks are named "acpi-clkX" so if it happens it would be on purpose.

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

v9:
- Search for the ACPI clock *before* the regular path. As we now search
  the clock with the ACPI companion device only if its name differs, we
  won't be shadowing an entry with the same con_id provided elsewhere.
  This makes sure that we respect the precedence of an entry's dev_id
  over con_id.
- Only use the ACPI companion's name to find the hw_clk, then create
  the clock using the regular device name.

v8: Reword commit message

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 | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 919fc680ae4d..23cf7396db72 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,6 +101,8 @@ 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;
 
 	if (dev && dev->of_node) {
@@ -108,6 +111,17 @@ struct clk *clk_get(struct device *dev, const char *con_id)
 			return clk_hw_create_clk(dev, hw, dev_id, con_id, NULL);
 	}
 
+	if (dev && has_acpi_companion(dev)) {
+		adev = ACPI_COMPANION(dev);
+		acpi_dev_id = acpi_dev_name(adev);
+
+		if (strcmp(dev_id, acpi_dev_id)) {
+			hw = clk_find_hw(acpi_dev_id, con_id);
+			if (!IS_ERR(hw))
+				return clk_hw_create_clk(dev, hw, dev_id, con_id, NULL);
+		}
+	}
+
 	return __clk_get_sys(dev, dev_id, con_id);
 }
 EXPORT_SYMBOL(clk_get);
-- 
2.47.3




More information about the linux-arm-kernel mailing list