* [PATCH v6 0/2] ACPI: Add ACPI 6.5 fixed clock support
@ 2026-11-30 12:28 Paul Cercueil
2026-11-30 12:28 ` [PATCH v6 1/2] ACPI: Add basic support for ACPI 6.5 fixed clock resources Paul Cercueil
2026-11-30 12:28 ` [PATCH v6 2/2] clk: Search clocks of ACPI device with its companion device Paul Cercueil
0 siblings, 2 replies; 4+ messages in thread
From: Paul Cercueil @ 2026-11-30 12:28 UTC (permalink / raw)
To: Rafael J . Wysocki, Len Brown, Russell King,
Maciej Wieczor-Retman, Pawel Chmielewski
Cc: linux-acpi, linux-arm-kernel, acpica-devel, linux-kernel,
Thomas Petazzoni, Paul Cercueil
Hi Rafael, Russell,
Here's the v6 of my patchset that adds partial support for ACPI 6.5
clock resources.
This v6 adds a patch to clkdev, which updates clk_get() to use the ACPI
companion device if available, and fall back to the regular path if the
clock wasn't found there.
It also reworks the main patch, with quite a lot of changes, most
notably the switch from using devm functions which can't be used there.
This patchset was tested both for devices that are probed at boot, and
also through hot-plugging of ACPI tables using configfs. The ACPI
clocks are correctly probed when a new ACPI device is discovered, before
the driver probes, and are correctly unregistered when the hot-plugged
ACPI table is unloaded, after the driver is removed.
Changes in v6:
- [1/2]:
- Return -EFAULT instead of -EINVAL on bad firmware data
- Invert condition "res->type != ACPI_RESOURCE_TYPE_CLOCK_INPUT"
- Rename acpi_platform_init_clocks() to acpi_dev_init_clocks(), and
move it to drivers/acpi/resource.c
- Make sure clock index is incremented even for non-fixed clocks
- Use non-devm variants of the clk/clkdev APIs
- Keep a list of the acpi_device's clk/clkdev data so that they can be
unregistered on device removal
- acpi_dev_init_clocks() is now called from acpi_bus_attach()
- Add function acpi_dev_remove_clocks() to unregister the ACPI clocks,
called on ACPI device removal
- Add documentation for these two functions
- Use acpi_handle_info() instead of dev_warn()
- [2/2]:
- New patch
Cheers,
-Paul
Paul Cercueil (2):
ACPI: Add basic support for ACPI 6.5 fixed clock resources
clk: Search clocks of ACPI device with its companion device
drivers/acpi/resource.c | 132 ++++++++++++++++++++++++++++++++++++++++
drivers/acpi/scan.c | 6 ++
drivers/clk/clkdev.c | 10 +++
include/acpi/acpi_bus.h | 1 +
include/linux/acpi.h | 3 +
5 files changed, 152 insertions(+)
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v6 1/2] ACPI: Add basic support for ACPI 6.5 fixed clock resources
2026-11-30 12:28 [PATCH v6 0/2] ACPI: Add ACPI 6.5 fixed clock support Paul Cercueil
@ 2026-11-30 12:28 ` Paul Cercueil
2026-11-30 12:28 ` [PATCH v6 2/2] clk: Search clocks of ACPI device with its companion device Paul Cercueil
1 sibling, 0 replies; 4+ messages in thread
From: Paul Cercueil @ 2026-11-30 12:28 UTC (permalink / raw)
To: Rafael J . Wysocki, Len Brown, Russell King,
Maciej Wieczor-Retman, Pawel Chmielewski
Cc: linux-acpi, linux-arm-kernel, acpica-devel, 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>
---
v6:
- Return -EFAULT instead of -EINVAL on bad firmware data
- Invert condition "res->type != ACPI_RESOURCE_TYPE_CLOCK_INPUT"
- Rename acpi_platform_init_clocks() to acpi_dev_init_clocks(), and move
it to drivers/acpi/resource.c
- Make sure clock index is incremented even for non-fixed clocks
- Use non-devm variants of the clk/clkdev APIs
- Keep a list of the acpi_device's clk/clkdev data so that they can be
unregistered on device removal
- acpi_dev_init_clocks() is now called from acpi_bus_attach()
- Add function acpi_dev_remove_clocks() to unregister the ACPI clocks,
called on ACPI device removal
- Add documentation for these two functions
- Use acpi_handle_info() instead of dev_warn()
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.
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/resource.c | 132 ++++++++++++++++++++++++++++++++++++++++
drivers/acpi/scan.c | 6 ++
include/acpi/acpi_bus.h | 1 +
include/linux/acpi.h | 3 +
4 files changed, 142 insertions(+)
diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index 56df4599d360..45c056990ff7 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -11,13 +11,29 @@
*/
#include <linux/acpi.h>
+#include <linux/clk-provider.h>
+#include <linux/clkdev.h>
#include <linux/device.h>
#include <linux/export.h>
#include <linux/ioport.h>
+#include <linux/kconfig.h>
+#include <linux/list.h>
#include <linux/slab.h>
#include <linux/irq.h>
#include <linux/dmi.h>
#include <linux/string_choices.h>
+#include <linux/units.h>
+
+struct acpi_clk_data {
+ struct acpi_device *adev;
+ unsigned int idx;
+};
+
+struct acpi_clk {
+ struct list_head list;
+ struct clk_lookup *lookup;
+ struct clk_hw *clk;
+};
#ifdef CONFIG_X86
#define valid_IRQ(i) (((i) != 0) && ((i) != 2))
@@ -1172,3 +1188,119 @@ struct acpi_device *acpi_resource_consumer(struct resource *res)
acpi_get_devices(NULL, acpi_res_consumer_cb, res, (void **) &consumer);
return consumer;
}
+
+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 acpi_device *adev = data->adev;
+ struct device *dev = &adev->dev;
+ struct clk_lookup *lookup;
+ const char *name = NULL;
+ struct acpi_clk *aclk;
+ struct clk_hw *clk;
+ unsigned long rate;
+ unsigned int idx;
+ char buf[64];
+
+ if (res->type != ACPI_RESOURCE_TYPE_CLOCK_INPUT)
+ return 1;
+
+ clkres = &res->data.clock_input;
+ idx = data->idx++;
+
+ if (clkres->mode) {
+ acpi_handle_info(adev->handle, "Only fixed rate clocks supported for now.\n");
+ return 1; /* keep going */
+ }
+
+ if (clkres->frequency_divisor == 0 || clkres->scale > 2)
+ return -EFAULT;
+
+ rate = DIV_ROUND_UP_ULL((u64)clkres->frequency_numerator * clk_scale[clkres->scale],
+ clkres->frequency_divisor);
+
+ /* 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 = 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;
+ }
+
+ lookup = clkdev_hw_create(clk, name, "%s", dev_name(dev));
+ if (!lookup)
+ goto err_unregister_clk_hw;
+
+ aclk = kzalloc_obj(*aclk);
+ if (!aclk)
+ goto err_unregister_clkdev;
+
+ INIT_LIST_HEAD(&aclk->list);
+ aclk->lookup = lookup;
+ aclk->clk = clk;
+
+ list_add_tail(&aclk->list, &adev->clk_list);
+
+ return 1;
+
+err_unregister_clkdev:
+ clkdev_drop(lookup);
+err_unregister_clk_hw:
+ clk_hw_unregister_fixed_rate(clk);
+ return -ENOMEM;
+}
+
+/**
+ * acpi_dev_init_clocks - Register ACPI clocks of a device
+ * @adev: ACPI device node.
+ *
+ * This function will register the clock resources of the ACPI device against
+ * the common clock framework.
+ *
+ * Returns a negative errno code on error, zero on success.
+ */
+int acpi_dev_init_clocks(struct acpi_device *adev)
+{
+ struct acpi_clk_data data = { .adev = adev };
+ LIST_HEAD(list);
+ int err = 0;
+
+ if (IS_ENABLED(CONFIG_COMMON_CLK)) {
+ err = acpi_dev_get_resources(adev, &list, acpi_add_fixed_clock, &data);
+ if (err)
+ acpi_dev_remove_clocks(adev);
+ }
+
+ return err;
+}
+
+/**
+ * acpi_dev_remove_clocks - Unregister ACPI clocks of a device
+ * @adev: ACPI device node.
+ *
+ * This function will unregister any ACPI clock previously registered against
+ * the common clock framework by acpi_dev_init_clocks().
+ */
+void acpi_dev_remove_clocks(struct acpi_device *adev)
+{
+ struct list_head *list, *tmp;
+ struct acpi_clk *aclk;
+
+ if (IS_ENABLED(CONFIG_COMMON_CLK)) {
+ list_for_each_safe(list, tmp, &adev->clk_list) {
+ aclk = container_of(list, struct acpi_clk, list);
+
+ list_del(&aclk->list);
+ clkdev_drop(aclk->lookup);
+ clk_hw_unregister_fixed_rate(aclk->clk);
+ kfree(aclk);
+ }
+ }
+}
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 9218264f8da1..e162e5d23874 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -621,6 +621,8 @@ static void acpi_device_del(struct acpi_device *device)
if (device->remove)
device->remove(device);
+ acpi_dev_remove_clocks(device);
+
device_del(&device->dev);
}
@@ -816,6 +818,7 @@ int acpi_device_add(struct acpi_device *device)
INIT_LIST_HEAD(&device->wakeup_list);
INIT_LIST_HEAD(&device->physical_node_list);
INIT_LIST_HEAD(&device->del_list);
+ INIT_LIST_HEAD(&device->clk_list);
mutex_init(&device->physical_node_lock);
mutex_lock(&acpi_device_lock);
@@ -2444,6 +2447,9 @@ static int acpi_bus_attach(struct acpi_device *device, void *first_pass)
return 0;
}
+ if (!device->flags.visited && device->device_type == ACPI_BUS_TYPE_DEVICE)
+ acpi_dev_init_clocks(device);
+
if (device->handler)
goto ok;
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index fad52a96d613..5b0710057465 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -466,6 +466,7 @@ struct acpi_device {
struct list_head physical_node_list;
struct mutex physical_node_lock;
void (*remove)(struct acpi_device *);
+ struct list_head clk_list;
};
/* Non-device subnode */
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 9d3f039ebd94..7c05a119388b 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -571,6 +571,9 @@ int acpi_check_region(resource_size_t start, resource_size_t n,
int acpi_resources_are_enforced(void);
+int acpi_dev_init_clocks(struct acpi_device *adev);
+void acpi_dev_remove_clocks(struct acpi_device *adev);
+
#ifdef CONFIG_HIBERNATION
extern int acpi_check_s4_hw_signature;
#endif
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v6 2/2] clk: Search clocks of ACPI device with its companion device
2026-11-30 12:28 [PATCH v6 0/2] ACPI: Add ACPI 6.5 fixed clock support Paul Cercueil
2026-11-30 12:28 ` [PATCH v6 1/2] ACPI: Add basic support for ACPI 6.5 fixed clock resources Paul Cercueil
@ 2026-11-30 12:28 ` Paul Cercueil
2026-11-30 16:44 ` kernel test robot
1 sibling, 1 reply; 4+ messages in thread
From: Paul Cercueil @ 2026-11-30 12:28 UTC (permalink / raw)
To: Rafael J . Wysocki, Len Brown, Russell King,
Maciej Wieczor-Retman, Pawel Chmielewski
Cc: linux-acpi, linux-arm-kernel, acpica-devel, linux-kernel,
Thomas Petazzoni, Paul Cercueil
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 our clock there,
fall back to 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.
Signed-off-by: Paul Cercueil <paul.cercueil@bootlin.com>
---
v6: New patch
---
drivers/clk/clkdev.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 919fc680ae4d..396715f30ff0 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,9 @@ 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;
struct clk_hw *hw;
+ struct clk *clk;
if (dev && dev->of_node) {
hw = of_clk_get_hw(dev->of_node, 0, con_id);
@@ -108,6 +111,13 @@ 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);
+ clk = clk_get(&adev->dev, con_id);
+ if (!IS_ERR(clk) || PTR_ERR(clk) != -ENOENT)
+ return clk;
+ }
+
return __clk_get_sys(dev, dev_id, con_id);
}
EXPORT_SYMBOL(clk_get);
--
2.47.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v6 2/2] clk: Search clocks of ACPI device with its companion device
2026-11-30 12:28 ` [PATCH v6 2/2] clk: Search clocks of ACPI device with its companion device Paul Cercueil
@ 2026-11-30 16:44 ` kernel test robot
0 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-11-30 16:44 UTC (permalink / raw)
To: Paul Cercueil, Rafael J . Wysocki, Len Brown, Russell King,
Maciej Wieczor-Retman, Pawel Chmielewski
Cc: llvm, oe-kbuild-all, linux-acpi, linux-arm-kernel, acpica-devel,
linux-kernel, Thomas Petazzoni, Paul Cercueil
Hi Paul,
kernel test robot noticed the following build errors:
[auto build test ERROR on rafael-pm/linux-next]
[also build test ERROR on rafael-pm/bleeding-edge linus/master v7.4-rc5 next-20261127]
[cannot apply to arm/for-next arm/fixes rmk-arm/clkdev]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Paul-Cercueil/ACPI-Add-basic-support-for-ACPI-6-5-fixed-clock-resources/20261130-132826
base: https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git linux-next
patch link: https://lore.kernel.org/r/20261130122827.157946-3-paul.cercueil%40bootlin.com
patch subject: [PATCH v6 2/2] clk: Search clocks of ACPI device with its companion device
config: arm-allnoconfig (https://download.01.org/0day-ci/archive/20261201/20261201003418.VGtmNGd5-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261201/20261201003418.VGtmNGd5-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/20261201003418.VGtmNGd5-lkp@intel.com/
All errors (new ones prefixed by >>):
>> drivers/clk/clkdev.c:116:22: error: incomplete definition of type 'struct acpi_device'
116 | clk = clk_get(&adev->dev, con_id);
| ~~~~^
include/linux/device/bus.h:222:8: note: forward declaration of 'struct acpi_device'
222 | struct acpi_device;
| ^
1 error generated.
vim +116 drivers/clk/clkdev.c
100
101 struct clk *clk_get(struct device *dev, const char *con_id)
102 {
103 const char *dev_id = dev ? dev_name(dev) : NULL;
104 struct acpi_device *adev;
105 struct clk_hw *hw;
106 struct clk *clk;
107
108 if (dev && dev->of_node) {
109 hw = of_clk_get_hw(dev->of_node, 0, con_id);
110 if (!IS_ERR(hw) || PTR_ERR(hw) == -EPROBE_DEFER)
111 return clk_hw_create_clk(dev, hw, dev_id, con_id, NULL);
112 }
113
114 if (dev && has_acpi_companion(dev)) {
115 adev = ACPI_COMPANION(dev);
> 116 clk = clk_get(&adev->dev, con_id);
117 if (!IS_ERR(clk) || PTR_ERR(clk) != -ENOENT)
118 return clk;
119 }
120
121 return __clk_get_sys(dev, dev_id, con_id);
122 }
123 EXPORT_SYMBOL(clk_get);
124
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-30 16:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 12:28 [PATCH v6 0/2] ACPI: Add ACPI 6.5 fixed clock support Paul Cercueil
2026-11-30 12:28 ` [PATCH v6 1/2] ACPI: Add basic support for ACPI 6.5 fixed clock resources Paul Cercueil
2026-11-30 12:28 ` [PATCH v6 2/2] clk: Search clocks of ACPI device with its companion device Paul Cercueil
2026-11-30 16:44 ` kernel test robot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox