ACPI: platform: ACPI 6.5 fixed clock support
Subsystems (2)
v3 cover ACPI: platform: ACPI 6.5 fixed clock support
Hi Rafael, Russell,
Here's the v3 of my patchset that adds partial support for ACPI 6.5 clock resources.
The ACPI patch itself is unchanged since v2, I just added the clock patch originally sent as [1].
I originally thought that it was a good idea to send the ACPI patch and the CLK patch separately, since they could go to different trees. However by sending them separately the context was completely lost; Sashiko would complain in the ACPI patch about clk_get() not being able to find the fixed clocks (which was addressed by the clocks patch), and the clocks patch didn't provide the context of *why* it was needed.
Packing those two patches into one small patchset gives the proper context to both patches. Then each maintainer can choose to pick their own patch (or both can probably go through the ACPI tree).
Changelog:
v3:
- [1/2]: New patch
- [2/2]: No change
Best regards,
-Paul
[1]: https://lore.kernel.org/linux-arm-kernel/[email protected]/T/
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(-)
Signature · 1 line
2.47.3
PATCH v3 1/2 clkdev: Improve clock discovery with clk_find()
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.
---
v3: New patch. Imported from
https://lore.kernel.org/linux-arm-kernel/[email protected]/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(-)
drivers/clk/clkdev.c +3 -1
@@ -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 ; }
Signature · 1 line
2.47.3
PATCH v3 2/2 ACPI: platform: Add basic support for ACPI 6.5 fixed clock resources
In reply to Paul CercueilACPI 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).
---
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(+)
drivers/acpi/acpi_platform.c +64 -0
@@ -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, voireturn 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),"%s-%u" ,dev_name (dev), 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));
Signature · 1 line
2.47.3