Linux ACPI
 help / color / mirror / Atom feed
* [PATCH v1 0/2] iio: light: acpi-als: Use platform device for driver binding
@ 2026-03-04 18:31 Rafael J. Wysocki
  2026-03-04 18:32 ` [PATCH v1 1/2] iio: light: acpi-als: Register ACPI notify handler directly Rafael J. Wysocki
  2026-03-04 18:33 ` [PATCH v1 2/2] iio: light: acpi-als: Convert ACPI driver to a platform one Rafael J. Wysocki
  0 siblings, 2 replies; 6+ messages in thread
From: Rafael J. Wysocki @ 2026-03-04 18:31 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: LKML, Linux ACPI, Nuno Sá, Andy Shevchenko, linux-iio

Hi All,

This series is part of a larger effort to switch over all drivers using
the struct acpi_driver interface to the more common struct platform_driver
interface and eliminate the former.  The background is explained in
Documentation/driver-api/acpi/acpi-drivers.rst and in the changelog of
the patch that introduced the above document:

https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/

The bottom line is that the kernel would be better off without struct
acpi_driver and so it is better to get rid of it.

This series carries out driver conversion of the IIO ACPI Ambient Light
Sensor (ALS) driver.

Patch [1/2] updates the driver to install an ACPI notify handler by itself
instead of using the .notify() callback from struct acpi_driver, which is
requisite for the driver conversion.

Patch [2/2] converts the driver to using struct platform_driver for device
binding.

Thanks!




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

* [PATCH v1 1/2] iio: light: acpi-als: Register ACPI notify handler directly
  2026-03-04 18:31 [PATCH v1 0/2] iio: light: acpi-als: Use platform device for driver binding Rafael J. Wysocki
@ 2026-03-04 18:32 ` Rafael J. Wysocki
  2026-03-05  7:11   ` Andy Shevchenko
  2026-03-04 18:33 ` [PATCH v1 2/2] iio: light: acpi-als: Convert ACPI driver to a platform one Rafael J. Wysocki
  1 sibling, 1 reply; 6+ messages in thread
From: Rafael J. Wysocki @ 2026-03-04 18:32 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: LKML, Linux ACPI, Nuno Sá, Andy Shevchenko, linux-iio

From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>

To facilitate subsequent conversion of the driver to a platform one,
make it install an ACPI notify handler directly instead of using
a .notify() callback in struct acpi_driver.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/iio/light/acpi-als.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
index d5d1a8b9c035..2fe6b493c012 100644
--- a/drivers/iio/light/acpi-als.c
+++ b/drivers/iio/light/acpi-als.c
@@ -90,9 +90,9 @@ static int acpi_als_read_value(struct acpi_als *als, char *prop, s32 *val)
 	return 0;
 }
 
-static void acpi_als_notify(struct acpi_device *device, u32 event)
+static void acpi_als_notify(acpi_handle handle, u32 event, void *data)
 {
-	struct iio_dev *indio_dev = acpi_driver_data(device);
+	struct iio_dev *indio_dev = data;
 	struct acpi_als *als = iio_priv(indio_dev);
 
 	if (iio_buffer_enabled(indio_dev) && iio_trigger_using_own(indio_dev)) {
@@ -102,7 +102,7 @@ static void acpi_als_notify(struct acpi_device *device, u32 event)
 			break;
 		default:
 			/* Unhandled event */
-			dev_dbg(&device->dev,
+			dev_dbg(&als->device->dev,
 				"Unhandled ACPI ALS event (%08x)!\n",
 				event);
 		}
@@ -218,7 +218,17 @@ static int acpi_als_add(struct acpi_device *device)
 	if (ret)
 		return ret;
 
-	return devm_iio_device_register(dev, indio_dev);
+	ret = devm_iio_device_register(dev, indio_dev);
+	if (ret)
+		return ret;
+
+	return acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
+					       acpi_als_notify, indio_dev);
+}
+
+static void acpi_als_remove(struct acpi_device *device)
+{
+	acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, acpi_als_notify);
 }
 
 static const struct acpi_device_id acpi_als_device_ids[] = {
@@ -234,7 +244,7 @@ static struct acpi_driver acpi_als_driver = {
 	.ids	= acpi_als_device_ids,
 	.ops = {
 		.add	= acpi_als_add,
-		.notify	= acpi_als_notify,
+		.remove	= acpi_als_remove,
 	},
 };
 
-- 
2.51.0





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

* [PATCH v1 2/2] iio: light: acpi-als: Convert ACPI driver to a platform one
  2026-03-04 18:31 [PATCH v1 0/2] iio: light: acpi-als: Use platform device for driver binding Rafael J. Wysocki
  2026-03-04 18:32 ` [PATCH v1 1/2] iio: light: acpi-als: Register ACPI notify handler directly Rafael J. Wysocki
@ 2026-03-04 18:33 ` Rafael J. Wysocki
  2026-03-05  7:10   ` Andy Shevchenko
  1 sibling, 1 reply; 6+ messages in thread
From: Rafael J. Wysocki @ 2026-03-04 18:33 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: LKML, Linux ACPI, Nuno Sá, Andy Shevchenko, linux-iio

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 ACPI ambient light sensor driver to a
platform one.

After this change, the subordinate IIO device will be registered under
the platform device used for driver binding instead of its ACPI
companion.

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/iio/light/acpi-als.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/iio/light/acpi-als.c b/drivers/iio/light/acpi-als.c
index 2fe6b493c012..ef4fe708b271 100644
--- a/drivers/iio/light/acpi-als.c
+++ b/drivers/iio/light/acpi-als.c
@@ -18,6 +18,7 @@
 #include <linux/err.h>
 #include <linux/irq.h>
 #include <linux/mutex.h>
+#include <linux/platform_device.h>
 
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
@@ -175,9 +176,10 @@ static irqreturn_t acpi_als_trigger_handler(int irq, void *p)
 	return IRQ_HANDLED;
 }
 
-static int acpi_als_add(struct acpi_device *device)
+static int acpi_als_probe(struct platform_device *pdev)
 {
-	struct device *dev = &device->dev;
+	struct device *dev = &pdev->dev;
+	struct acpi_device *device = ACPI_COMPANION(dev);
 	struct iio_dev *indio_dev;
 	struct acpi_als *als;
 	int ret;
@@ -188,7 +190,6 @@ static int acpi_als_add(struct acpi_device *device)
 
 	als = iio_priv(indio_dev);
 
-	device->driver_data = indio_dev;
 	als->device = device;
 	mutex_init(&als->lock);
 
@@ -226,9 +227,10 @@ static int acpi_als_add(struct acpi_device *device)
 					       acpi_als_notify, indio_dev);
 }
 
-static void acpi_als_remove(struct acpi_device *device)
+static void acpi_als_remove(struct platform_device *pdev)
 {
-	acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, acpi_als_notify);
+	acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev),
+				       ACPI_DEVICE_NOTIFY, acpi_als_notify);
 }
 
 static const struct acpi_device_id acpi_als_device_ids[] = {
@@ -238,17 +240,16 @@ static const struct acpi_device_id acpi_als_device_ids[] = {
 
 MODULE_DEVICE_TABLE(acpi, acpi_als_device_ids);
 
-static struct acpi_driver acpi_als_driver = {
-	.name	= "acpi_als",
-	.class	= ACPI_ALS_CLASS,
-	.ids	= acpi_als_device_ids,
-	.ops = {
-		.add	= acpi_als_add,
-		.remove	= acpi_als_remove,
+static struct platform_driver acpi_als_driver = {
+	.probe = acpi_als_probe,
+	.remove = acpi_als_remove,
+	.driver = {
+		.name = "acpi_als",
+		.acpi_match_table = acpi_als_device_ids,
 	},
 };
 
-module_acpi_driver(acpi_als_driver);
+module_platform_driver(acpi_als_driver);
 
 MODULE_AUTHOR("Zhang Rui <rui.zhang@intel.com>");
 MODULE_AUTHOR("Martin Liska <marxin.liska@gmail.com>");
-- 
2.51.0





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

* Re: [PATCH v1 2/2] iio: light: acpi-als: Convert ACPI driver to a platform one
  2026-03-04 18:33 ` [PATCH v1 2/2] iio: light: acpi-als: Convert ACPI driver to a platform one Rafael J. Wysocki
@ 2026-03-05  7:10   ` Andy Shevchenko
  2026-03-07 12:20     ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-03-05  7:10 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Jonathan Cameron, LKML, Linux ACPI, Nuno Sá, linux-iio

On Wed, Mar 04, 2026 at 07:33:14PM +0100, Rafael J. Wysocki 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 ACPI ambient light sensor driver to a
> platform one.
> 
> After this change, the subordinate IIO device will be registered under
> the platform device used for driver binding instead of its ACPI
> companion.
> 
> While this is not expected to alter functionality, it changes sysfs
> layout and so it will be visible to user space.

...

> -static struct acpi_driver acpi_als_driver = {
> -	.name	= "acpi_als",
> -	.class	= ACPI_ALS_CLASS,
> -	.ids	= acpi_als_device_ids,
> -	.ops = {
> -		.add	= acpi_als_add,
> -		.remove	= acpi_als_remove,
> +static struct platform_driver acpi_als_driver = {
> +	.probe = acpi_als_probe,
> +	.remove = acpi_als_remove,
> +	.driver = {
> +		.name = "acpi_als",
> +		.acpi_match_table = acpi_als_device_ids,
>  	},
>  };

>  

You can also drop this unneeded blank line.

> -module_acpi_driver(acpi_als_driver);
> +module_platform_driver(acpi_als_driver);

Anyways, LGTM,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v1 1/2] iio: light: acpi-als: Register ACPI notify handler directly
  2026-03-04 18:32 ` [PATCH v1 1/2] iio: light: acpi-als: Register ACPI notify handler directly Rafael J. Wysocki
@ 2026-03-05  7:11   ` Andy Shevchenko
  0 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-03-05  7:11 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Jonathan Cameron, LKML, Linux ACPI, Nuno Sá, linux-iio

On Wed, Mar 04, 2026 at 07:32:26PM +0100, Rafael J. Wysocki wrote:

> To facilitate subsequent conversion of the driver to a platform one,
> make it install an ACPI notify handler directly instead of using
> a .notify() callback in struct acpi_driver.
> 
> No intentional functional impact.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH v1 2/2] iio: light: acpi-als: Convert ACPI driver to a platform one
  2026-03-05  7:10   ` Andy Shevchenko
@ 2026-03-07 12:20     ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2026-03-07 12:20 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Rafael J. Wysocki, LKML, Linux ACPI, Nuno Sá, linux-iio

On Thu, 5 Mar 2026 09:10:49 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> On Wed, Mar 04, 2026 at 07:33:14PM +0100, Rafael J. Wysocki 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 ACPI ambient light sensor driver to a
> > platform one.
> > 
> > After this change, the subordinate IIO device will be registered under
> > the platform device used for driver binding instead of its ACPI
> > companion.
> > 
> > While this is not expected to alter functionality, it changes sysfs
> > layout and so it will be visible to user space.  
> 
> ...
> 
> > -static struct acpi_driver acpi_als_driver = {
> > -	.name	= "acpi_als",
> > -	.class	= ACPI_ALS_CLASS,
> > -	.ids	= acpi_als_device_ids,
> > -	.ops = {
> > -		.add	= acpi_als_add,
> > -		.remove	= acpi_als_remove,
> > +static struct platform_driver acpi_als_driver = {
> > +	.probe = acpi_als_probe,
> > +	.remove = acpi_als_remove,
> > +	.driver = {
> > +		.name = "acpi_als",
> > +		.acpi_match_table = acpi_als_device_ids,
> >  	},
> >  };  
> 
> >    
> 
> You can also drop this unneeded blank line.
> 
> > -module_acpi_driver(acpi_als_driver);
> > +module_platform_driver(acpi_als_driver);  
> 
> Anyways, LGTM,
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Tweaked and applied to the testing branch of iio.git.

Thanks,

Jonathan

> 


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

end of thread, other threads:[~2026-03-07 12:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 18:31 [PATCH v1 0/2] iio: light: acpi-als: Use platform device for driver binding Rafael J. Wysocki
2026-03-04 18:32 ` [PATCH v1 1/2] iio: light: acpi-als: Register ACPI notify handler directly Rafael J. Wysocki
2026-03-05  7:11   ` Andy Shevchenko
2026-03-04 18:33 ` [PATCH v1 2/2] iio: light: acpi-als: Convert ACPI driver to a platform one Rafael J. Wysocki
2026-03-05  7:10   ` Andy Shevchenko
2026-03-07 12:20     ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox