Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Cercueil <paul.cercueil@bootlin.com>
To: "Rafael J . Wysocki" <rafael@kernel.org>,
	Len Brown <lenb@kernel.org>, Russell King <linux@armlinux.org.uk>,
	Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
	Pawel Chmielewski <pawel.chmielewski@intel.com>
Cc: linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	acpica-devel@lists.linux.dev,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	Paul Cercueil <paul.cercueil@bootlin.com>
Subject: [PATCH v8 2/2] clk: Search clocks of ACPI device with its companion device
Date: Thu,  3 Dec 2026 10:02:21 +0100	[thread overview]
Message-ID: <20261203090221.8601-2-paul.cercueil@bootlin.com> (raw)
In-Reply-To: <20261203090221.8601-1-paul.cercueil@bootlin.com>

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@bootlin.com>
---

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 | 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



      reply	other threads:[~2026-12-03  9:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  9:02 [PATCH v8 1/2] ACPI: Add basic support for ACPI 6.5 fixed clock resources Paul Cercueil
2026-12-03  9:02 ` Paul Cercueil [this message]

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=20261203090221.8601-2-paul.cercueil@bootlin.com \
    --to=paul.cercueil@bootlin.com \
    --cc=acpica-devel@lists.linux.dev \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux@armlinux.org.uk \
    --cc=maciej.wieczor-retman@intel.com \
    --cc=pawel.chmielewski@intel.com \
    --cc=rafael@kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    /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