mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources
@ 2026-11-03  8:47 Paul Cercueil
  2026-11-10 17:18 ` Rafael J. Wysocki (Intel)
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Cercueil @ 2026-11-03  8:47 UTC (permalink / raw)
  To: Rafael J. Wysocki, Len Brown
  Cc: linux-acpi, linux-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>
---
 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..bae6a2eacd71 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)
+			return -EINVAL;
+
+		rate = DIV_ROUND_UP(clkres->frequency_numerator * clk_scale[clkres->scale],
+				    clkres->frequency_divisor);
+
+		clk = devm_clk_hw_register_fixed_rate(dev, dev_name(dev), NULL, 0, rate);
+		if (IS_ERR(clk))
+			return PTR_ERR(clk);
+
+		snprintf(name, sizeof(name), "%s-clk%u", dev_name(dev), data->idx++);
+
+		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.
@@ -217,6 +278,9 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
 	else
 		pdevinfo.dma_mask = 0;
 
+	if (IS_ENABLED(CONFIG_COMMON_CLK))
+		acpi_platform_init_clocks(adev);
+
 	pdev = platform_device_register_full(&pdevinfo);
 	if (IS_ERR(pdev))
 		dev_err(&adev->dev, "platform device creation failed: %ld\n",
-- 
2.47.3


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

* Re: [PATCH] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources
  2026-11-03  8:47 [PATCH] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources Paul Cercueil
@ 2026-11-10 17:18 ` Rafael J. Wysocki (Intel)
  2026-11-11  8:36   ` Paul Cercueil
  0 siblings, 1 reply; 3+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-10 17:18 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: Rafael J. Wysocki, Len Brown, linux-acpi, linux-kernel, Thomas Petazzoni

On Tue, Nov 3, 2026 at 9:47 AM Paul Cercueil <paul.cercueil@bootlin.com> wrote:
>
> 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>

You need to look at Sashiko's feedback on this:

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

> ---
>  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..bae6a2eacd71 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)
> +                       return -EINVAL;
> +
> +               rate = DIV_ROUND_UP(clkres->frequency_numerator * clk_scale[clkres->scale],
> +                                   clkres->frequency_divisor);
> +
> +               clk = devm_clk_hw_register_fixed_rate(dev, dev_name(dev), NULL, 0, rate);
> +               if (IS_ERR(clk))
> +                       return PTR_ERR(clk);
> +
> +               snprintf(name, sizeof(name), "%s-clk%u", dev_name(dev), data->idx++);
> +
> +               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.
> @@ -217,6 +278,9 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev,
>         else
>                 pdevinfo.dma_mask = 0;
>
> +       if (IS_ENABLED(CONFIG_COMMON_CLK))
> +               acpi_platform_init_clocks(adev);
> +
>         pdev = platform_device_register_full(&pdevinfo);
>         if (IS_ERR(pdev))
>                 dev_err(&adev->dev, "platform device creation failed: %ld\n",
> --

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

* Re: [PATCH] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources
  2026-11-10 17:18 ` Rafael J. Wysocki (Intel)
@ 2026-11-11  8:36   ` Paul Cercueil
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Cercueil @ 2026-11-11  8:36 UTC (permalink / raw)
  To: Rafael J. Wysocki (Intel)
  Cc: Len Brown, linux-acpi, linux-kernel, Thomas Petazzoni

Hi Rafael,

Le mardi 10 novembre 2026 à 18:18 +0100, Rafael J. Wysocki (Intel) a écrit :
> On Tue, Nov 3, 2026 at 9:47 AM Paul Cercueil <paul.cercueil@bootlin.com>
> wrote:
> > 
> > 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>
> 
> You need to look at Sashiko's feedback on this:
> 
> https://sashiko.dev/#/patchset/20261103084718.8222-1-paul.cercueil%40bootlin.com

I was expecting Sashiko to send me an email, but it didn't?

I'll v2 with the feedback addressed.

Cheers,
-Paul

> > ---
> >  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..bae6a2eacd71 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)
> > +                       return -EINVAL;
> > +
> > +               rate = DIV_ROUND_UP(clkres->frequency_numerator *
> > clk_scale[clkres->scale],
> > +                                   clkres->frequency_divisor);
> > +
> > +               clk = devm_clk_hw_register_fixed_rate(dev, dev_name(dev),
> > NULL, 0, rate);
> > +               if (IS_ERR(clk))
> > +                       return PTR_ERR(clk);
> > +
> > +               snprintf(name, sizeof(name), "%s-clk%u", dev_name(dev),
> > data->idx++);
> > +
> > +               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.
> > @@ -217,6 +278,9 @@ struct platform_device
> > *acpi_create_platform_device(struct acpi_device *adev,
> >         else
> >                 pdevinfo.dma_mask = 0;
> > 
> > +       if (IS_ENABLED(CONFIG_COMMON_CLK))
> > +               acpi_platform_init_clocks(adev);
> > +
> >         pdev = platform_device_register_full(&pdevinfo);
> >         if (IS_ERR(pdev))
> >                 dev_err(&adev->dev, "platform device creation failed:
> > %ld\n",
> > --

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

end of thread, other threads:[~2026-11-11  8:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03  8:47 [PATCH] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources Paul Cercueil
2026-11-10 17:18 ` Rafael J. Wysocki (Intel)
2026-11-11  8:36   ` 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®