mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v5 0/1] ACPI: platform: ACPI 6.5 fixed clock support
@ 2026-11-20 16:10 Paul Cercueil
  2026-11-20 16:10 ` [PATCH v5 1/1] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources Paul Cercueil
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Cercueil @ 2026-11-20 16:10 UTC (permalink / raw)
  To: Rafael J . Wysocki, Len Brown
  Cc: linux-acpi, linux-kernel, Thomas Petazzoni, Paul Cercueil

Hi Rafael,

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

I don't modify clk_find() anymore. Instead, the first clock is now
registered without a connection name (con_id is NULL) which means that
it can be obtained with clk_get(NULL). Every subsequent ACPI fixed clock
found will have a name, "acpi-clkX".

Each clock is also now registered to the clk core using a system-wide
identifier derived from the ACPI device name.

Changelog since v4:

- Old patch [1/2] "clkdev: Improve clock discovery with clk_find()" is
  gone.

- [1/1] (previously [2/2]):
    Register fixed clock as "<ACPI_ID>-clkX" because we need a
    system-wide identifier there, and we don't have the 16-characters
    limit there.
    Register the first clock to clkdev without a name, so that
    clk_get(NULL) will obtain it.
    Register every other clock for that ACPI device with a "acpi-clkX"
    name.

Cheers,
-Paul

Paul Cercueil (1):
  ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources

 drivers/acpi/acpi_platform.c | 75 ++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

-- 
2.47.3


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

* [PATCH v5 1/1] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources
  2026-11-20 16:10 [PATCH v5 0/1] ACPI: platform: ACPI 6.5 fixed clock support Paul Cercueil
@ 2026-11-20 16:10 ` Paul Cercueil
  2026-11-25 20:22   ` Rafael J. Wysocki (Intel)
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Cercueil @ 2026-11-20 16:10 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>
---

v5: Register fixed clock as "<ACPI_ID>-clkX" because we need a
    system-wide identifier there, and we don't have the 16-characters
    limit there.
    Register the first clock to clkdev without a name, so that
    clk_get(NULL) will obtain it.
    Register every other clock for that ACPI device with a "acpi-clkX"
    name.

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

diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
index 80ea7121744d..b4f2ccf3e51f 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,68 @@ 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;
+	const char *name = NULL;
+	struct clk_hw *clk;
+	unsigned long rate;
+	unsigned int idx;
+	char buf[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);
+
+		idx = data->idx++;
+
+		/* When registering a clk_hw the name must be unique across all devs */
+		snprintf(buf, sizeof(buf), "%s-clk%u", dev_name(dev), idx);
+
+		clk = devm_clk_hw_register_fixed_rate(dev, buf, NULL, 0, rate);
+		if (IS_ERR(clk))
+			return PTR_ERR(clk);
+
+		if (idx > 0) {
+			/* When registering a clkdev the name must be <= 16 characters */
+			snprintf(buf, sizeof(buf), "acpi-clk%u", idx);
+			name = buf;
+		}
+
+		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 +268,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 v5 1/1] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources
  2026-11-20 16:10 ` [PATCH v5 1/1] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources Paul Cercueil
@ 2026-11-25 20:22   ` Rafael J. Wysocki (Intel)
  2026-11-27 10:04     ` Paul Cercueil
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-25 20:22 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: Rafael J . Wysocki, Len Brown, linux-acpi, linux-kernel,
	Thomas Petazzoni

On Fri, Nov 20, 2026 at 5:10 PM 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>
> ---
>
> v5: Register fixed clock as "<ACPI_ID>-clkX" because we need a
>     system-wide identifier there, and we don't have the 16-characters
>     limit there.
>     Register the first clock to clkdev without a name, so that
>     clk_get(NULL) will obtain it.
>     Register every other clock for that ACPI device with a "acpi-clkX"
>     name.
>
> 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 | 75 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 75 insertions(+)
>
> diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
> index 80ea7121744d..b4f2ccf3e51f 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,68 @@ static unsigned int acpi_platform_resource_count(struct acpi_resource *ares, voi
>         return AE_CTRL_TERMINATE;
>  }

First off, will clocks only be needed for platform devices?  If not,
acpi_add_fixed_clock() should be defined in drivers/acpi/resource.c.

> +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;
> +       const char *name = NULL;
> +       struct clk_hw *clk;
> +       unsigned long rate;
> +       unsigned int idx;
> +       char buf[64];
> +       int err;
> +
> +       if (res->type == ACPI_RESOURCE_TYPE_CLOCK_INPUT) {

Maybe

if (res->type != ACPI_RESOURCE_TYPE_CLOCK_INPUT)
        return 1;

> +               clkres = &res->data.clock_input;
> +
> +               if (clkres->mode) {
> +                       dev_warn(dev, "Only fixed rate clocks supported for now.\n");

_warn() is likely overkill here and it would be better to print this
relative to an ACPI handle, so use acpi_handle_info().

> +                       return 1; /* keep going */
> +               }
> +
> +               if (clkres->frequency_divisor == 0 || clkres->scale > 2)
> +                       return -EINVAL;

This is firmware providing bad data, so not -EINVAL.

> +
> +               rate = DIV_ROUND_UP_ULL((u64)clkres->frequency_numerator * clk_scale[clkres->scale],
> +                                       clkres->frequency_divisor);
> +
> +               idx = data->idx++;
> +
> +               /* When registering a clk_hw the name must be unique across all devs */
> +               snprintf(buf, sizeof(buf), "%s-clk%u", dev_name(dev), idx);
> +
> +               clk = devm_clk_hw_register_fixed_rate(dev, buf, NULL, 0, rate);

Why devm_?  This is called at the device creation time, not in probe,
so how/when is clk going to be unregistered?

Also, devm_ doesn't work with struct acpi_device which are never
probed and drivers are never removed from them.

> +               if (IS_ERR(clk))
> +                       return PTR_ERR(clk);
> +
> +               if (idx > 0) {
> +                       /* When registering a clkdev the name must be <= 16 characters */
> +                       snprintf(buf, sizeof(buf), "acpi-clk%u", idx);
> +                       name = buf;
> +               }
> +
> +               err = devm_clk_hw_register_clkdev(dev, clk, name, dev_name(dev));

Same thing about devm_.

> +               if (err)
> +                       return err;
> +       }
> +
> +       return 1;
> +}
> +
> +static void acpi_platform_init_clocks(struct acpi_device *adev)
> +{
> +       struct device *dev = &adev->dev;

Note that &adev->dev is not a real device.  It is a "firmware node",
quite like a DT one, but I guess it may be used for registering
clocks.

How is a platform device driver going to use those clocks though?

> +       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 +268,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));
> --

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

* Re: [PATCH v5 1/1] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources
  2026-11-25 20:22   ` Rafael J. Wysocki (Intel)
@ 2026-11-27 10:04     ` Paul Cercueil
  2026-11-27 12:43       ` Rafael J. Wysocki (Intel)
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Cercueil @ 2026-11-27 10:04 UTC (permalink / raw)
  To: Rafael J. Wysocki (Intel)
  Cc: Len Brown, linux-acpi, linux-kernel, Thomas Petazzoni

Hi Rafael,

Le mercredi 25 novembre 2026 à 21:22 +0100, Rafael J. Wysocki (Intel) a écrit :
> On Fri, Nov 20, 2026 at 5:10 PM 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>
> > ---
> > 
> > v5: Register fixed clock as "<ACPI_ID>-clkX" because we need a
> >     system-wide identifier there, and we don't have the 16-characters
> >     limit there.
> >     Register the first clock to clkdev without a name, so that
> >     clk_get(NULL) will obtain it.
> >     Register every other clock for that ACPI device with a "acpi-clkX"
> >     name.
> > 
> > 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 | 75 ++++++++++++++++++++++++++++++++++++
> >  1 file changed, 75 insertions(+)
> > 
> > diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
> > index 80ea7121744d..b4f2ccf3e51f 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,68 @@ static unsigned int acpi_platform_resource_count(struct
> > acpi_resource *ares, voi
> >         return AE_CTRL_TERMINATE;
> >  }
> 
> First off, will clocks only be needed for platform devices?  If not,
> acpi_add_fixed_clock() should be defined in drivers/acpi/resource.c.
> 
> > +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;
> > +       const char *name = NULL;
> > +       struct clk_hw *clk;
> > +       unsigned long rate;
> > +       unsigned int idx;
> > +       char buf[64];
> > +       int err;
> > +
> > +       if (res->type == ACPI_RESOURCE_TYPE_CLOCK_INPUT) {
> 
> Maybe
> 
> if (res->type != ACPI_RESOURCE_TYPE_CLOCK_INPUT)
>         return 1;
> 
> > +               clkres = &res->data.clock_input;
> > +
> > +               if (clkres->mode) {
> > +                       dev_warn(dev, "Only fixed rate clocks supported for
> > now.\n");
> 
> _warn() is likely overkill here and it would be better to print this
> relative to an ACPI handle, so use acpi_handle_info().
> 
> > +                       return 1; /* keep going */
> > +               }
> > +
> > +               if (clkres->frequency_divisor == 0 || clkres->scale > 2)
> > +                       return -EINVAL;
> 
> This is firmware providing bad data, so not -EINVAL.

Right, that's a -EFAULT.

> 
> > +
> > +               rate = DIV_ROUND_UP_ULL((u64)clkres->frequency_numerator *
> > clk_scale[clkres->scale],
> > +                                       clkres->frequency_divisor);
> > +
> > +               idx = data->idx++;
> > +
> > +               /* When registering a clk_hw the name must be unique across
> > all devs */
> > +               snprintf(buf, sizeof(buf), "%s-clk%u", dev_name(dev), idx);
> > +
> > +               clk = devm_clk_hw_register_fixed_rate(dev, buf, NULL, 0,
> > rate);
> 
> Why devm_?  This is called at the device creation time, not in probe,
> so how/when is clk going to be unregistered?
> 
> Also, devm_ doesn't work with struct acpi_device which are never
> probed and drivers are never removed from them.

Ah, good point. That's going to complicate things.

> > +               if (IS_ERR(clk))
> > +                       return PTR_ERR(clk);
> > +
> > +               if (idx > 0) {
> > +                       /* When registering a clkdev the name must be <= 16
> > characters */
> > +                       snprintf(buf, sizeof(buf), "acpi-clk%u", idx);
> > +                       name = buf;
> > +               }
> > +
> > +               err = devm_clk_hw_register_clkdev(dev, clk, name,
> > dev_name(dev));
> 
> Same thing about devm_.
> 
> > +               if (err)
> > +                       return err;
> > +       }
> > +
> > +       return 1;
> > +}
> > +
> > +static void acpi_platform_init_clocks(struct acpi_device *adev)
> > +{
> > +       struct device *dev = &adev->dev;
> 
> Note that &adev->dev is not a real device.  It is a "firmware node",
> quite like a DT one, but I guess it may be used for registering
> clocks.
> 
> How is a platform device driver going to use those clocks though?

They just use clk_get(). It searches the clock by device name, which works here,
I guess because the "firmware node" device has the same name as the real device.

Cheers,
-Paul

> > +       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 +268,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));
> > --

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

* Re: [PATCH v5 1/1] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources
  2026-11-27 10:04     ` Paul Cercueil
@ 2026-11-27 12:43       ` Rafael J. Wysocki (Intel)
  2026-11-27 14:20         ` Paul Cercueil
  0 siblings, 1 reply; 7+ messages in thread
From: Rafael J. Wysocki (Intel) @ 2026-11-27 12:43 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: Rafael J. Wysocki (Intel),
	Len Brown, linux-acpi, linux-kernel, Thomas Petazzoni

On Fri, Nov 27, 2026 at 11:05 AM Paul Cercueil
<paul.cercueil@bootlin.com> wrote:
>
> Hi Rafael,
>
> Le mercredi 25 novembre 2026 à 21:22 +0100, Rafael J. Wysocki (Intel) a écrit :
> > On Fri, Nov 20, 2026 at 5:10 PM 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>
> > > ---
> > >
> > > v5: Register fixed clock as "<ACPI_ID>-clkX" because we need a
> > >     system-wide identifier there, and we don't have the 16-characters
> > >     limit there.
> > >     Register the first clock to clkdev without a name, so that
> > >     clk_get(NULL) will obtain it.
> > >     Register every other clock for that ACPI device with a "acpi-clkX"
> > >     name.
> > >
> > > 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 | 75 ++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 75 insertions(+)
> > >
> > > diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c
> > > index 80ea7121744d..b4f2ccf3e51f 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,68 @@ static unsigned int acpi_platform_resource_count(struct
> > > acpi_resource *ares, voi
> > >         return AE_CTRL_TERMINATE;
> > >  }
> >
> > First off, will clocks only be needed for platform devices?  If not,
> > acpi_add_fixed_clock() should be defined in drivers/acpi/resource.c.
> >
> > > +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;
> > > +       const char *name = NULL;
> > > +       struct clk_hw *clk;
> > > +       unsigned long rate;
> > > +       unsigned int idx;
> > > +       char buf[64];
> > > +       int err;
> > > +
> > > +       if (res->type == ACPI_RESOURCE_TYPE_CLOCK_INPUT) {
> >
> > Maybe
> >
> > if (res->type != ACPI_RESOURCE_TYPE_CLOCK_INPUT)
> >         return 1;
> >
> > > +               clkres = &res->data.clock_input;
> > > +
> > > +               if (clkres->mode) {
> > > +                       dev_warn(dev, "Only fixed rate clocks supported for
> > > now.\n");
> >
> > _warn() is likely overkill here and it would be better to print this
> > relative to an ACPI handle, so use acpi_handle_info().
> >
> > > +                       return 1; /* keep going */
> > > +               }
> > > +
> > > +               if (clkres->frequency_divisor == 0 || clkres->scale > 2)
> > > +                       return -EINVAL;
> >
> > This is firmware providing bad data, so not -EINVAL.
>
> Right, that's a -EFAULT.
>
> >
> > > +
> > > +               rate = DIV_ROUND_UP_ULL((u64)clkres->frequency_numerator *
> > > clk_scale[clkres->scale],
> > > +                                       clkres->frequency_divisor);
> > > +
> > > +               idx = data->idx++;
> > > +
> > > +               /* When registering a clk_hw the name must be unique across
> > > all devs */
> > > +               snprintf(buf, sizeof(buf), "%s-clk%u", dev_name(dev), idx);
> > > +
> > > +               clk = devm_clk_hw_register_fixed_rate(dev, buf, NULL, 0,
> > > rate);
> >
> > Why devm_?  This is called at the device creation time, not in probe,
> > so how/when is clk going to be unregistered?
> >
> > Also, devm_ doesn't work with struct acpi_device which are never
> > probed and drivers are never removed from them.
>
> Ah, good point. That's going to complicate things.
>
> > > +               if (IS_ERR(clk))
> > > +                       return PTR_ERR(clk);
> > > +
> > > +               if (idx > 0) {
> > > +                       /* When registering a clkdev the name must be <= 16
> > > characters */
> > > +                       snprintf(buf, sizeof(buf), "acpi-clk%u", idx);
> > > +                       name = buf;
> > > +               }
> > > +
> > > +               err = devm_clk_hw_register_clkdev(dev, clk, name,
> > > dev_name(dev));
> >
> > Same thing about devm_.
> >
> > > +               if (err)
> > > +                       return err;
> > > +       }
> > > +
> > > +       return 1;
> > > +}
> > > +
> > > +static void acpi_platform_init_clocks(struct acpi_device *adev)
> > > +{
> > > +       struct device *dev = &adev->dev;
> >
> > Note that &adev->dev is not a real device.  It is a "firmware node",
> > quite like a DT one, but I guess it may be used for registering
> > clocks.
> >
> > How is a platform device driver going to use those clocks though?
>
> They just use clk_get(). It searches the clock by device name, which works here,

And they would pass the platform device as dev I suppose?

> I guess because the "firmware node" device has the same name as the real device.

For platform devices created by acpi_create_platform_device(), yes, it
does, but if that is going to be relied on, that assumption needs to
be documented in a very visible way.

Generally speaking though, they should rather pass the ACPI companion
of the platform device as dev, in which case that the name equality
doesn't matter, and so the clkdev could be created during the struct
acpi_device registration (and the corresponding cleanup would occur
during the struct acpi_device removal which is rare).

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

* Re: [PATCH v5 1/1] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources
  2026-11-27 12:43       ` Rafael J. Wysocki (Intel)
@ 2026-11-27 14:20         ` Paul Cercueil
  2026-11-27 14:24           ` Rafael J. Wysocki (Intel)
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Cercueil @ 2026-11-27 14:20 UTC (permalink / raw)
  To: Rafael J. Wysocki (Intel)
  Cc: Len Brown, linux-acpi, linux-kernel, Thomas Petazzoni

[...]

> > > > +static void acpi_platform_init_clocks(struct acpi_device *adev)
> > > > +{
> > > > +       struct device *dev = &adev->dev;
> > > 
> > > Note that &adev->dev is not a real device.  It is a "firmware node",
> > > quite like a DT one, but I guess it may be used for registering
> > > clocks.
> > > 
> > > How is a platform device driver going to use those clocks though?
> > 
> > They just use clk_get(). It searches the clock by device name, which works
> > here,
> 
> And they would pass the platform device as dev I suppose?

Yes, I like the fact that it does not change the API - on the driver side you
just use clk_get(&pdev->dev, NULL) or clk_get(&pdev->dev, "acpi-clk1") like you
would do with a clock resource from DT.

> > I guess because the "firmware node" device has the same name as the real
> > device.
> 
> For platform devices created by acpi_create_platform_device(), yes, it
> does, but if that is going to be relied on, that assumption needs to
> be documented in a very visible way.
> 
> Generally speaking though, they should rather pass the ACPI companion
> of the platform device as dev, in which case that the name equality
> doesn't matter, and so the clkdev could be created during the struct
> acpi_device registration (and the corresponding cleanup would occur
> during the struct acpi_device removal which is rare).

I think I should update clk_get() then.

It gets passed a "struct device" pointer, if it has an ACPI companion, I can
just recurse on the ACPI companion's device struct.

Btw - I'm working on the v6 and I added the cleanup on acpi_device removal. Is
there a way to test a ACPI device removal from userspace? Looking at
Documentation/ABI/testing/sysfs-bus-acpi it seems to only be for ACPI devices
which have a _AJ0 method?

Cheers,
-Paul

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

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

On Fri, Nov 27, 2026 at 3:20 PM Paul Cercueil <paul.cercueil@bootlin.com> wrote:
>
> [...]
>
> > > > > +static void acpi_platform_init_clocks(struct acpi_device *adev)
> > > > > +{
> > > > > +       struct device *dev = &adev->dev;
> > > >
> > > > Note that &adev->dev is not a real device.  It is a "firmware node",
> > > > quite like a DT one, but I guess it may be used for registering
> > > > clocks.
> > > >
> > > > How is a platform device driver going to use those clocks though?
> > >
> > > They just use clk_get(). It searches the clock by device name, which works
> > > here,
> >
> > And they would pass the platform device as dev I suppose?
>
> Yes, I like the fact that it does not change the API - on the driver side you
> just use clk_get(&pdev->dev, NULL) or clk_get(&pdev->dev, "acpi-clk1") like you
> would do with a clock resource from DT.
>
> > > I guess because the "firmware node" device has the same name as the real
> > > device.
> >
> > For platform devices created by acpi_create_platform_device(), yes, it
> > does, but if that is going to be relied on, that assumption needs to
> > be documented in a very visible way.
> >
> > Generally speaking though, they should rather pass the ACPI companion
> > of the platform device as dev, in which case that the name equality
> > doesn't matter, and so the clkdev could be created during the struct
> > acpi_device registration (and the corresponding cleanup would occur
> > during the struct acpi_device removal which is rare).
>
> I think I should update clk_get() then.
>
> It gets passed a "struct device" pointer, if it has an ACPI companion, I can
> just recurse on the ACPI companion's device struct.
>
> Btw - I'm working on the v6 and I added the cleanup on acpi_device removal. Is
> there a way to test a ACPI device removal from userspace? Looking at
> Documentation/ABI/testing/sysfs-bus-acpi it seems to only be for ACPI devices
> which have a _AJ0 method?

The only way to remove a struct acpi_device is to unload the table
containing its definition, so you'd need to load a test SSDT via
configfs and then unload it.

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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20 16:10 [PATCH v5 0/1] ACPI: platform: ACPI 6.5 fixed clock support Paul Cercueil
2026-11-20 16:10 ` [PATCH v5 1/1] ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources Paul Cercueil
2026-11-25 20:22   ` Rafael J. Wysocki (Intel)
2026-11-27 10:04     ` Paul Cercueil
2026-11-27 12:43       ` Rafael J. Wysocki (Intel)
2026-11-27 14:20         ` Paul Cercueil
2026-11-27 14:24           ` Rafael J. Wysocki (Intel)

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®