mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support
@ 2026-11-20 12:57 Paul Cercueil
  2026-11-20 12:57 ` [PATCH v4 1/2] clkdev: Improve clock discovery with clk_find() Paul Cercueil
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Paul Cercueil @ 2026-11-20 12:57 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown, Russell King
  Cc: linux-acpi, linux-kernel, linux-arm-kernel, Thomas Petazzoni,
	Paul Cercueil

Hi Rafael, Russell,

Here's the v4 of my patchset that adds partial support for ACPI 6.5
clock resources.

Sashiko complained about the clock names being too long still, as
ACPI device names can be up to 17 characters and the limit of clock
names is 16 characters; so I now name them "acpi-clkX".

Note that I expect warnings from Sashiko that I got on my v3 and didn't
correct, because they are bogus.

On the clkdev patch:
"When clk_find(dev_id, NULL) is called, does incrementing match here
give a (dev_id, con_id) entry a higher score than an exact
(dev_id, NULL) entry?"

My answer is that you call clk_find(dev_id, NULL) when you know you only
have one clock provided, so you don't need to care about matching
priorities.

On the ACPI patch:
"Should the con_id argument to devm_clk_hw_register_clkdev() be NULL
instead of name? [...] Setting con_id to "<dev_name>-<idx>" instead of
NULL prevents wildcard connection matching in clk_find(), so any
consumer driver calling clk_get(dev, con_id) with a non-NULL con_id
fails with -ENOENT."

That's completely ignoring the first patch, which addresses this issue.

So I consider that those two issues can be ignored.

Changelog since v3:

- [2/2]:
  - Change clock names to "acpi-clkX", because ACPI devices names can be
    up to 17 characters long, and our clock name must be 16 characters
    max.

Cheers,
-Paul

Paul Cercueil (2):
  clkdev: Improve clock discovery with clk_find()
  ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources

 drivers/acpi/acpi_platform.c | 64 ++++++++++++++++++++++++++++++++++++
 drivers/clk/clkdev.c         |  4 ++-
 2 files changed, 67 insertions(+), 1 deletion(-)

-- 
2.47.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v4 1/2] clkdev: Improve clock discovery with clk_find()
  2026-11-20 12:57 [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support Paul Cercueil
@ 2026-11-20 12:57 ` Paul Cercueil
  2026-11-20 12:57 ` [PATCH v4 2/2] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources Paul Cercueil
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Paul Cercueil @ 2026-11-20 12:57 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown, Russell King
  Cc: linux-acpi, linux-kernel, linux-arm-kernel, Thomas Petazzoni,
	Paul Cercueil

With a setup where a clock provider registers a clock with a device name
"mydev" and a clock name "myclk", calling clk_find("mydev", NULL) would
not actually return any match.

Update the code so that we can support this while maintaining the
existing behaviour:

- clk_find("dev", "con") matches in order of priority ("dev", "con"),
  ("dev", *) and (*, "con");
- clk_find(NULL, "con") matches (*, "con");
- clk_find("dev", NULL) matches the first case of ("dev", *).
  Note that in that case we don't handle wildcards for the device name
  or it would end up matching everything.

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

v4: No change

v3: New patch. Imported from
    https://lore.kernel.org/linux-arm-kernel/20261103084915.8405-1-paul.cercueil@bootlin.com/T/

    Originally sent separately to go through different trees, but the
    context was lost which didn't help reviewing.
---
 drivers/clk/clkdev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 919fc680ae4d..ee6c0afd6ec0 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -53,7 +53,9 @@ static struct clk_lookup *clk_find(const char *dev_id, const char *con_id)
 			match += 2;
 		}
 		if (p->con_id) {
-			if (!con_id || strcmp(p->con_id, con_id))
+			if (!con_id && !p->dev_id)
+				continue;
+			if (con_id && strcmp(p->con_id, con_id))
 				continue;
 			match += 1;
 		}
-- 
2.47.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v4 2/2] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources
  2026-11-20 12:57 [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support Paul Cercueil
  2026-11-20 12:57 ` [PATCH v4 1/2] clkdev: Improve clock discovery with clk_find() Paul Cercueil
@ 2026-11-20 12:57 ` Paul Cercueil
  2026-11-20 14:24 ` [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support Rafael J. Wysocki (Intel)
  2026-11-20 14:31 ` Rafael J. Wysocki (Intel)
  3 siblings, 0 replies; 7+ messages in thread
From: Paul Cercueil @ 2026-11-20 12:57 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown, Russell King
  Cc: linux-acpi, linux-kernel, linux-arm-kernel, Thomas Petazzoni,
	Paul Cercueil

ACPI 6.5 introduced a clock input resource descriptor, which allows to
specify in the ACPI tables what clocks are connected to a given device.

This patch adds support for the most basic clock resource, which is the
one that represents a fixed clock. The new code will then create a
clk_hw for each fixed clock resource, which is then made available to
the device drivers, that can obtain it through a regular call to
clk_get(NULL).

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

v4: Change clock names to "acpi-clkX", because ACPI devices names can be
    up to 17 characters long, and our clock name must be 16 characters
    max.

v3: No change

v2:
- Use the calculated clock name in devm_clk_hw_register_fixed_rate()
  instead of the device name
- Make sure clkres->scale is <= 2. The field is 2 bits but the value
  clkres->scale == 3 is not defined in the spec.
- Compute the fraction numerator using 64-bit math, to make sure it
  won't overflow on 32-bit systems.
- Initialize clocks only when the device_type matches
  ACPI_BUS_TYPE_DEVICE.
- Use a shorter name for clocks as the hard limit is 16 characters
  including the terminator.
---
 drivers/acpi/acpi_platform.c | 64 ++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
index 80ea7121744d..4e8824cc042d 100644
--- a/drivers/acpi/acpi_platform.c
+++ b/drivers/acpi/acpi_platform.c
@@ -10,17 +10,27 @@
 
 #include <linux/acpi.h>
 #include <linux/bits.h>
+#include <linux/clk-provider.h>
+#include <linux/clkdev.h>
 #include <linux/device.h>
 #include <linux/err.h>
 #include <linux/ioport.h>
+#include <linux/kconfig.h>
 #include <linux/kernel.h>
+#include <linux/list.h>
 #include <linux/module.h>
 #include <linux/dma-mapping.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/units.h>
 
 #include "internal.h"
 
+struct acpi_clk_data {
+	struct device *dev;
+	unsigned int idx;
+};
+
 /* Exclude devices that have no _CRS resources provided */
 #define ACPI_ALLOW_WO_RESOURCES		BIT(0)
 
@@ -130,6 +140,57 @@ static unsigned int acpi_platform_resource_count(struct acpi_resource *ares, voi
 	return AE_CTRL_TERMINATE;
 }
 
+static int acpi_add_fixed_clock(struct acpi_resource *res, void *d)
+{
+	static const unsigned long clk_scale[] = { 1, HZ_PER_KHZ, HZ_PER_MHZ };
+	struct acpi_resource_clock_input *clkres;
+	struct acpi_clk_data *data = d;
+	struct device *dev = data->dev;
+	struct clk_hw *clk;
+	unsigned long rate;
+	char name[64];
+	int err;
+
+	if (res->type == ACPI_RESOURCE_TYPE_CLOCK_INPUT) {
+		clkres = &res->data.clock_input;
+
+		if (clkres->mode) {
+			dev_warn(dev, "Only fixed rate clocks supported for now.\n");
+			return 1; /* keep going */
+		}
+
+		if (clkres->frequency_divisor == 0 || clkres->scale > 2)
+			return -EINVAL;
+
+		rate = DIV_ROUND_UP_ULL((u64)clkres->frequency_numerator * clk_scale[clkres->scale],
+					clkres->frequency_divisor);
+
+		snprintf(name, sizeof(name), "acpi-clk%u", data->idx++);
+
+		clk = devm_clk_hw_register_fixed_rate(dev, name, NULL, 0, rate);
+		if (IS_ERR(clk))
+			return PTR_ERR(clk);
+
+		err = devm_clk_hw_register_clkdev(dev, clk, name, dev_name(dev));
+		if (err)
+			return err;
+	}
+
+	return 1;
+}
+
+static void acpi_platform_init_clocks(struct acpi_device *adev)
+{
+	struct device *dev = &adev->dev;
+	struct acpi_clk_data data = { .dev = dev };
+	LIST_HEAD(list);
+	int ret;
+
+	ret = acpi_dev_get_resources(adev, &list, acpi_add_fixed_clock, &data);
+	if (ret < 0)
+		dev_err(dev, "Failed to add clock resources: %d\n", ret);
+}
+
 /**
  * acpi_create_platform_device - Create platform device for ACPI device node
  * @adev: ACPI device node to create a platform device for.
@@ -196,6 +257,9 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
 			}
 			acpi_dev_free_resource_list(&resource_list);
 		}
+
+		if (IS_ENABLED(CONFIG_COMMON_CLK))
+			acpi_platform_init_clocks(adev);
 	}
 
 	memset(&pdevinfo, 0, sizeof(pdevinfo));
-- 
2.47.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support
  2026-11-20 12:57 [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support Paul Cercueil
  2026-11-20 12:57 ` [PATCH v4 1/2] clkdev: Improve clock discovery with clk_find() Paul Cercueil
  2026-11-20 12:57 ` [PATCH v4 2/2] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources Paul Cercueil
@ 2026-11-20 14:24 ` Rafael J. Wysocki (Intel)
  2026-11-20 14:25   ` Rafael J. Wysocki (Intel)
  2026-11-20 14:31 ` Rafael J. Wysocki (Intel)
  3 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-20 14:24 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: Rafael J . Wysocki, Len Brown, Russell King, linux-acpi,
	linux-kernel, linux-arm-kernel, Thomas Petazzoni

On Fri, Nov 20, 2026 at 1:57 PM Paul Cercueil <paul.cercueil@bootlin.com> wrote:
>
> Hi Rafael, Russell,
>
> Here's the v4 of my patchset that adds partial support for ACPI 6.5
> clock resources.
>
> Sashiko complained about the clock names being too long still, as
> ACPI device names can be up to 17 characters and the limit of clock
> names is 16 characters; so I now name them "acpi-clkX".
>
> Note that I expect warnings from Sashiko that I got on my v3 and didn't
> correct, because they are bogus.
>
> On the clkdev patch:
> "When clk_find(dev_id, NULL) is called, does incrementing match here
> give a (dev_id, con_id) entry a higher score than an exact
> (dev_id, NULL) entry?"
>
> My answer is that you call clk_find(dev_id, NULL) when you know you only
> have one clock provided, so you don't need to care about matching
> priorities.
>
> On the ACPI patch:
> "Should the con_id argument to devm_clk_hw_register_clkdev() be NULL
> instead of name? [...] Setting con_id to "<dev_name>-<idx>" instead of
> NULL prevents wildcard connection matching in clk_find(), so any
> consumer driver calling clk_get(dev, con_id) with a non-NULL con_id
> fails with -ENOENT."
>
> That's completely ignoring the first patch, which addresses this issue.
>
> So I consider that those two issues can be ignored.
>
> Changelog since v3:
>
> - [2/2]:
>   - Change clock names to "acpi-clkX", because ACPI devices names can be
>     up to 17 characters long, and our clock name must be 16 characters
>     max.
>
> Cheers,
> -Paul
>
> Paul Cercueil (2):
>   clkdev: Improve clock discovery with clk_find()
>   ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources
>
>  drivers/acpi/acpi_platform.c | 64 ++++++++++++++++++++++++++++++++++++
>  drivers/clk/clkdev.c         |  4 ++-
>  2 files changed, 67 insertions(+), 1 deletion(-)
>
> --

Sashiko has feedback on this series:

https://sashiko.dev/#/patchset/20261120125722.209609-1-paul.cercueil%40bootlin.com

Please let me know what you think about it.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support
  2026-11-20 14:24 ` [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support Rafael J. Wysocki (Intel)
@ 2026-11-20 14:25   ` Rafael J. Wysocki (Intel)
  0 siblings, 0 replies; 7+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-20 14:25 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: Russell King, linux-acpi, linux-kernel, linux-arm-kernel,
	Thomas Petazzoni

On Fri, Nov 20, 2026 at 3:24 PM Rafael J. Wysocki (Intel)
<rafael@kernel.org> wrote:
>
> On Fri, Nov 20, 2026 at 1:57 PM Paul Cercueil <paul.cercueil@bootlin.com> wrote:
> >
> > Hi Rafael, Russell,
> >
> > Here's the v4 of my patchset that adds partial support for ACPI 6.5
> > clock resources.
> >
> > Sashiko complained about the clock names being too long still, as
> > ACPI device names can be up to 17 characters and the limit of clock
> > names is 16 characters; so I now name them "acpi-clkX".
> >
> > Note that I expect warnings from Sashiko that I got on my v3 and didn't
> > correct, because they are bogus.
> >
> > On the clkdev patch:
> > "When clk_find(dev_id, NULL) is called, does incrementing match here
> > give a (dev_id, con_id) entry a higher score than an exact
> > (dev_id, NULL) entry?"
> >
> > My answer is that you call clk_find(dev_id, NULL) when you know you only
> > have one clock provided, so you don't need to care about matching
> > priorities.
> >
> > On the ACPI patch:
> > "Should the con_id argument to devm_clk_hw_register_clkdev() be NULL
> > instead of name? [...] Setting con_id to "<dev_name>-<idx>" instead of
> > NULL prevents wildcard connection matching in clk_find(), so any
> > consumer driver calling clk_get(dev, con_id) with a non-NULL con_id
> > fails with -ENOENT."
> >
> > That's completely ignoring the first patch, which addresses this issue.
> >
> > So I consider that those two issues can be ignored.
> >
> > Changelog since v3:
> >
> > - [2/2]:
> >   - Change clock names to "acpi-clkX", because ACPI devices names can be
> >     up to 17 characters long, and our clock name must be 16 characters
> >     max.
> >
> > Cheers,
> > -Paul
> >
> > Paul Cercueil (2):
> >   clkdev: Improve clock discovery with clk_find()
> >   ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources
> >
> >  drivers/acpi/acpi_platform.c | 64 ++++++++++++++++++++++++++++++++++++
> >  drivers/clk/clkdev.c         |  4 ++-
> >  2 files changed, 67 insertions(+), 1 deletion(-)
> >
> > --
>
> Sashiko has feedback on this series:
>
> https://sashiko.dev/#/patchset/20261120125722.209609-1-paul.cercueil%40bootlin.com
>
> Please let me know what you think about it.

Ah, you've already done it, sorry for the noise!

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support
  2026-11-20 12:57 [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support Paul Cercueil
                   ` (2 preceding siblings ...)
  2026-11-20 14:24 ` [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support Rafael J. Wysocki (Intel)
@ 2026-11-20 14:31 ` Rafael J. Wysocki (Intel)
  2026-11-20 15:14   ` Paul Cercueil
  3 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-20 14:31 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: Rafael J . Wysocki, Len Brown, Russell King, linux-acpi,
	linux-kernel, linux-arm-kernel, Thomas Petazzoni

On Fri, Nov 20, 2026 at 1:57 PM Paul Cercueil <paul.cercueil@bootlin.com> wrote:
>
> Hi Rafael, Russell,
>
> Here's the v4 of my patchset that adds partial support for ACPI 6.5
> clock resources.
>
> Sashiko complained about the clock names being too long still, as
> ACPI device names can be up to 17 characters and the limit of clock
> names is 16 characters; so I now name them "acpi-clkX".
>
> Note that I expect warnings from Sashiko that I got on my v3 and didn't
> correct, because they are bogus.
>
> On the clkdev patch:
> "When clk_find(dev_id, NULL) is called, does incrementing match here
> give a (dev_id, con_id) entry a higher score than an exact
> (dev_id, NULL) entry?"
>
> My answer is that you call clk_find(dev_id, NULL) when you know you only
> have one clock provided, so you don't need to care about matching
> priorities.

Sashiko has a new comment on the first patch though:

https://sashiko.dev/#/patchset/20261120125722.209609-1-paul.cercueil%40bootlin.com

> On the ACPI patch:
> "Should the con_id argument to devm_clk_hw_register_clkdev() be NULL
> instead of name? [...] Setting con_id to "<dev_name>-<idx>" instead of
> NULL prevents wildcard connection matching in clk_find(), so any
> consumer driver calling clk_get(dev, con_id) with a non-NULL con_id
> fails with -ENOENT."

This time Sashiko complains about something else in this patch AFAICS
(link above).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support
  2026-11-20 14:31 ` Rafael J. Wysocki (Intel)
@ 2026-11-20 15:14   ` Paul Cercueil
  0 siblings, 0 replies; 7+ messages in thread
From: Paul Cercueil @ 2026-11-20 15:14 UTC (permalink / raw)
  To: Rafael J. Wysocki (Intel)
  Cc: Len Brown, Russell King, linux-acpi, linux-kernel,
	linux-arm-kernel, Thomas Petazzoni

Hi Rafael,

Le vendredi 20 novembre 2026 à 15:31 +0100, Rafael J. Wysocki (Intel) a écrit :
> On Fri, Nov 20, 2026 at 1:57 PM Paul Cercueil <paul.cercueil@bootlin.com>
> wrote:
> > 
> > Hi Rafael, Russell,
> > 
> > Here's the v4 of my patchset that adds partial support for ACPI 6.5
> > clock resources.
> > 
> > Sashiko complained about the clock names being too long still, as
> > ACPI device names can be up to 17 characters and the limit of clock
> > names is 16 characters; so I now name them "acpi-clkX".
> > 
> > Note that I expect warnings from Sashiko that I got on my v3 and didn't
> > correct, because they are bogus.
> > 
> > On the clkdev patch:
> > "When clk_find(dev_id, NULL) is called, does incrementing match here
> > give a (dev_id, con_id) entry a higher score than an exact
> > (dev_id, NULL) entry?"
> > 
> > My answer is that you call clk_find(dev_id, NULL) when you know you only
> > have one clock provided, so you don't need to care about matching
> > priorities.
> 
> Sashiko has a new comment on the first patch though:
> 
> https://sashiko.dev/#/patchset/20261120125722.209609-1-paul.cercueil%40bootlin.com

Yes, Sashiko came back to the charge with better arguments this time.

Sadly it seems to be correct, if I change the behaviour of clk_get(NULL) I will
break some drivers that rely on it not finding named clocks.

I can pass NULL as the con_id to clk_hw_register_clkdev() and then I can drop
the first patch. Then, I guess register any other clock for the same device with
the "acpi-clkX" con_id.

> > On the ACPI patch:
> > "Should the con_id argument to devm_clk_hw_register_clkdev() be NULL
> > instead of name? [...] Setting con_id to "<dev_name>-<idx>" instead of
> > NULL prevents wildcard connection matching in clk_find(), so any
> > consumer driver calling clk_get(dev, con_id) with a non-NULL con_id
> > fails with -ENOENT."
> 
> This time Sashiko complains about something else in this patch AFAICS
> (link above).

It looks like I need identifying names for devm_clk_hw_register_fixed_rate(),
and those don't need to be 16-chars long (that's only for clkdev) - so I'll
restore my "<ACPI_ID>-clkX" naming scheme there.

Cheers,
-Paul

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-11-20 15:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 12:57 [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support Paul Cercueil
2026-11-20 12:57 ` [PATCH v4 1/2] clkdev: Improve clock discovery with clk_find() Paul Cercueil
2026-11-20 12:57 ` [PATCH v4 2/2] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources Paul Cercueil
2026-11-20 14:24 ` [PATCH v4 0/2] ACPI: platform: ACPI 6.5 fixed clock support Rafael J. Wysocki (Intel)
2026-11-20 14:25   ` Rafael J. Wysocki (Intel)
2026-11-20 14:31 ` Rafael J. Wysocki (Intel)
2026-11-20 15:14   ` Paul Cercueil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®