[PATCH v1] hpet: Convert ACPI driver to a platform one

Rafael J. Wysocki posted 1 patch 1 month, 1 week ago
drivers/char/hpet.c | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
[PATCH v1] hpet: Convert ACPI driver to a platform one
Posted by Rafael J. Wysocki 1 month, 1 week ago
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

In all cases in which a struct acpi_driver is used for binding a driver
to an ACPI device object, a corresponding platform device is created by
the ACPI core and that device is regarded as a proper representation of
underlying hardware.  Accordingly, a struct platform_driver should be
used by driver code to bind to that device.  There are multiple reasons
why drivers should not bind directly to ACPI device objects [1].

Overall, it is better to bind drivers to platform devices than to their
ACPI companions, so convert the HPET ACPI driver to a platform one.

While this is not expected to alter functionality, it changes sysfs
layout and so it will be visible to user space.

Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/char/hpet.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 60dd09a56f50..d396823e5e64 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -34,6 +34,7 @@
 #include <linux/io.h>
 #include <linux/acpi.h>
 #include <linux/hpet.h>
+#include <linux/platform_device.h>
 #include <asm/current.h>
 #include <asm/irq.h>
 #include <asm/div64.h>
@@ -971,8 +972,9 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)
 	return AE_OK;
 }
 
-static int hpet_acpi_add(struct acpi_device *device)
+static int hpet_acpi_probe(struct platform_device *pdev)
 {
+	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
 	acpi_status result;
 	struct hpet_data data;
 
@@ -1000,12 +1002,12 @@ static const struct acpi_device_id hpet_device_ids[] = {
 	{"", 0},
 };
 
-static struct acpi_driver hpet_acpi_driver = {
-	.name = "hpet",
-	.ids = hpet_device_ids,
-	.ops = {
-		.add = hpet_acpi_add,
-		},
+static struct platform_driver hpet_acpi_driver = {
+	.probe = hpet_acpi_probe,
+	.driver = {
+		.name = "hpet_acpi",
+		.acpi_match_table = hpet_device_ids,
+	},
 };
 
 static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops };
@@ -1020,7 +1022,7 @@ static int __init hpet_init(void)
 
 	sysctl_header = register_sysctl("dev/hpet", hpet_table);
 
-	result = acpi_bus_register_driver(&hpet_acpi_driver);
+	result = platform_driver_register(&hpet_acpi_driver);
 	if (result < 0) {
 		unregister_sysctl_table(sysctl_header);
 		misc_deregister(&hpet_misc);
-- 
2.51.0
Re: [PATCH v1] hpet: Convert ACPI driver to a platform one
Posted by Rafael J. Wysocki 3 weeks, 1 day ago
On Mon, Feb 23, 2026 at 4:49 PM Rafael J. Wysocki <rafael@kernel.org> wrote:
>
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
>
> In all cases in which a struct acpi_driver is used for binding a driver
> to an ACPI device object, a corresponding platform device is created by
> the ACPI core and that device is regarded as a proper representation of
> underlying hardware.  Accordingly, a struct platform_driver should be
> used by driver code to bind to that device.  There are multiple reasons
> why drivers should not bind directly to ACPI device objects [1].
>
> Overall, it is better to bind drivers to platform devices than to their
> ACPI companions, so convert the HPET ACPI driver to a platform one.
>
> While this is not expected to alter functionality, it changes sysfs
> layout and so it will be visible to user space.
>
> Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1]
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/char/hpet.c | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
> index 60dd09a56f50..d396823e5e64 100644
> --- a/drivers/char/hpet.c
> +++ b/drivers/char/hpet.c
> @@ -34,6 +34,7 @@
>  #include <linux/io.h>
>  #include <linux/acpi.h>
>  #include <linux/hpet.h>
> +#include <linux/platform_device.h>
>  #include <asm/current.h>
>  #include <asm/irq.h>
>  #include <asm/div64.h>
> @@ -971,8 +972,9 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)
>         return AE_OK;
>  }
>
> -static int hpet_acpi_add(struct acpi_device *device)
> +static int hpet_acpi_probe(struct platform_device *pdev)
>  {
> +       struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
>         acpi_status result;
>         struct hpet_data data;
>
> @@ -1000,12 +1002,12 @@ static const struct acpi_device_id hpet_device_ids[] = {
>         {"", 0},
>  };
>
> -static struct acpi_driver hpet_acpi_driver = {
> -       .name = "hpet",
> -       .ids = hpet_device_ids,
> -       .ops = {
> -               .add = hpet_acpi_add,
> -               },
> +static struct platform_driver hpet_acpi_driver = {
> +       .probe = hpet_acpi_probe,
> +       .driver = {
> +               .name = "hpet_acpi",
> +               .acpi_match_table = hpet_device_ids,
> +       },
>  };
>
>  static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops };
> @@ -1020,7 +1022,7 @@ static int __init hpet_init(void)
>
>         sysctl_header = register_sysctl("dev/hpet", hpet_table);
>
> -       result = acpi_bus_register_driver(&hpet_acpi_driver);
> +       result = platform_driver_register(&hpet_acpi_driver);
>         if (result < 0) {
>                 unregister_sysctl_table(sysctl_header);
>                 misc_deregister(&hpet_misc);
> --

If anyone has any objections or  concerns regarding this change,
please let me know.

In the absence of any, I'll queue it up for 7.1.

Thanks!