Linux ACPI
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linux ACPI <linux-acpi@vger.kernel.org>,
	Hans de Goede <hansg@kernel.org>,
	platform-driver-x86@vger.kernel.org,
	Azael Avalos <coproscefalo@gmail.com>
Subject: [PATCH v1 3/7] platform/x86: toshiba_acpi: Convert ACPI driver to a platform one
Date: Tue, 24 Mar 2026 21:00:03 +0100	[thread overview]
Message-ID: <2269772.irdbgypaU6@rafael.j.wysocki> (raw)
In-Reply-To: <6262981.lOV4Wx5bFT@rafael.j.wysocki>

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 Toshiba Laptop ACPI Extras driver from
an ACPI driver to a platform one.

After this change, all of the subordinate hwmon, IIO, and LED class
devices 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.

However, the sysfs attributes in toshiba_attr_group will still be there
in the sysfs directory of the ACPI companion of the platform device used
for driver binding to maintain backwards compatibility with possibly
existing user space utilities depending on the presence of those
attributes.

Link: https://lore.kernel.org/all/2396510.ElGaqSPkdT@rafael.j.wysocki/ [1]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/platform/x86/toshiba_acpi.c | 50 ++++++++++++++++-------------
 1 file changed, 27 insertions(+), 23 deletions(-)

diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c
index b839f62ec9cc..35d899c01740 100644
--- a/drivers/platform/x86/toshiba_acpi.c
+++ b/drivers/platform/x86/toshiba_acpi.c
@@ -44,6 +44,7 @@
 #include <linux/rfkill.h>
 #include <linux/hwmon.h>
 #include <linux/iio/iio.h>
+#include <linux/platform_device.h>
 #include <linux/toshiba.h>
 #include <acpi/battery.h>
 #include <acpi/video.h>
@@ -3255,16 +3256,17 @@ static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *data)
 					dev->last_key_event : 0);
 }
 
-static void toshiba_acpi_remove(struct acpi_device *acpi_dev)
+static void toshiba_acpi_remove(struct platform_device *pdev)
 {
-	struct toshiba_acpi_dev *dev = acpi_driver_data(acpi_dev);
+	struct toshiba_acpi_dev *dev = platform_get_drvdata(pdev);
 
 	misc_deregister(&dev->miscdev);
 
 	remove_toshiba_proc_entries(dev);
 
 	if (dev->notify_handler_installed)
-		acpi_dev_remove_notify_handler(acpi_dev, ACPI_DEVICE_NOTIFY,
+		acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev),
+					       ACPI_DEVICE_NOTIFY,
 					       toshiba_acpi_notify);
 
 #if IS_ENABLED(CONFIG_HWMON)
@@ -3306,6 +3308,8 @@ static void toshiba_acpi_remove(struct acpi_device *acpi_dev)
 	if (toshiba_acpi)
 		toshiba_acpi = NULL;
 
+	dev_set_drvdata(&dev->acpi_dev->dev, NULL);
+
 	kfree(dev);
 }
 
@@ -3368,8 +3372,9 @@ static const struct dmi_system_id toshiba_dmi_quirks[] __initconst = {
 	{ }
 };
 
-static int toshiba_acpi_add(struct acpi_device *acpi_dev)
+static int toshiba_acpi_probe(struct platform_device *pdev)
 {
+	struct acpi_device *acpi_dev = ACPI_COMPANION(&pdev->dev);
 	struct toshiba_acpi_dev *dev;
 	const char *hci_method;
 	u32 dummy;
@@ -3403,7 +3408,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 		return ret;
 	}
 
-	acpi_dev->driver_data = dev;
+	platform_set_drvdata(pdev, dev);
 	dev_set_drvdata(&acpi_dev->dev, dev);
 
 	/* Query the BIOS for supported features */
@@ -3434,7 +3439,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 		dev->led_dev.max_brightness = 1;
 		dev->led_dev.brightness_set = toshiba_illumination_set;
 		dev->led_dev.brightness_get = toshiba_illumination_get;
-		led_classdev_register(&acpi_dev->dev, &dev->led_dev);
+		led_classdev_register(&pdev->dev, &dev->led_dev);
 	}
 
 	toshiba_eco_mode_available(dev);
@@ -3443,7 +3448,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 		dev->eco_led.max_brightness = 1;
 		dev->eco_led.brightness_set = toshiba_eco_mode_set_status;
 		dev->eco_led.brightness_get = toshiba_eco_mode_get_status;
-		led_classdev_register(&dev->acpi_dev->dev, &dev->eco_led);
+		led_classdev_register(&pdev->dev, &dev->eco_led);
 	}
 
 	toshiba_kbd_illum_available(dev);
@@ -3459,7 +3464,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 		dev->kbd_led.max_brightness = 1;
 		dev->kbd_led.brightness_set = toshiba_kbd_backlight_set;
 		dev->kbd_led.brightness_get = toshiba_kbd_backlight_get;
-		led_classdev_register(&dev->acpi_dev->dev, &dev->kbd_led);
+		led_classdev_register(&pdev->dev, &dev->kbd_led);
 	}
 
 	ret = toshiba_touchpad_get(dev, &dummy);
@@ -3467,7 +3472,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 
 	toshiba_accelerometer_available(dev);
 	if (dev->accelerometer_supported) {
-		dev->indio_dev = iio_device_alloc(&acpi_dev->dev, sizeof(*dev));
+		dev->indio_dev = iio_device_alloc(&pdev->dev, sizeof(*dev));
 		if (!dev->indio_dev) {
 			pr_err("Unable to allocate iio device\n");
 			goto iio_error;
@@ -3516,7 +3521,7 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 #if IS_ENABLED(CONFIG_HWMON)
 	if (dev->fan_rpm_supported) {
 		dev->hwmon_device = hwmon_device_register_with_info(
-			&dev->acpi_dev->dev, "toshiba_acpi_sensors", NULL,
+			&pdev->dev, "toshiba_acpi_sensors", NULL,
 			&toshiba_acpi_hwmon_chip_info, NULL);
 		if (IS_ERR(dev->hwmon_device)) {
 			dev->hwmon_device = NULL;
@@ -3564,14 +3569,14 @@ static int toshiba_acpi_add(struct acpi_device *acpi_dev)
 	return 0;
 
 error:
-	toshiba_acpi_remove(acpi_dev);
+	toshiba_acpi_remove(pdev);
 	return ret;
 }
 
 #ifdef CONFIG_PM_SLEEP
 static int toshiba_acpi_suspend(struct device *device)
 {
-	struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
+	struct toshiba_acpi_dev *dev = dev_get_drvdata(device);
 
 	if (dev->hotkey_dev) {
 		u32 result;
@@ -3586,7 +3591,7 @@ static int toshiba_acpi_suspend(struct device *device)
 
 static int toshiba_acpi_resume(struct device *device)
 {
-	struct toshiba_acpi_dev *dev = acpi_driver_data(to_acpi_device(device));
+	struct toshiba_acpi_dev *dev = dev_get_drvdata(device);
 
 	if (dev->hotkey_dev) {
 		if (toshiba_acpi_enable_hotkeys(dev))
@@ -3608,15 +3613,14 @@ static int toshiba_acpi_resume(struct device *device)
 static SIMPLE_DEV_PM_OPS(toshiba_acpi_pm,
 			 toshiba_acpi_suspend, toshiba_acpi_resume);
 
-static struct acpi_driver toshiba_acpi_driver = {
-	.name	= "Toshiba ACPI driver",
-	.ids	= toshiba_device_ids,
-	.flags	= ACPI_DRIVER_ALL_NOTIFY_EVENTS,
-	.ops	= {
-		.add		= toshiba_acpi_add,
-		.remove		= toshiba_acpi_remove,
+static struct platform_driver toshiba_acpi_driver = {
+	.probe = toshiba_acpi_probe,
+	.remove = toshiba_acpi_remove,
+	.driver = {
+		.name = "Toshiba ACPI driver",
+		.acpi_match_table = toshiba_device_ids,
+		.pm = &toshiba_acpi_pm,
 	},
-	.drv.pm	= &toshiba_acpi_pm,
 };
 
 static void __init toshiba_dmi_init(void)
@@ -3646,7 +3650,7 @@ static int __init toshiba_acpi_init(void)
 		return -ENODEV;
 	}
 
-	ret = acpi_bus_register_driver(&toshiba_acpi_driver);
+	ret = platform_driver_register(&toshiba_acpi_driver);
 	if (ret) {
 		pr_err("Failed to register ACPI driver: %d\n", ret);
 		remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
@@ -3657,7 +3661,7 @@ static int __init toshiba_acpi_init(void)
 
 static void __exit toshiba_acpi_exit(void)
 {
-	acpi_bus_unregister_driver(&toshiba_acpi_driver);
+	platform_driver_unregister(&toshiba_acpi_driver);
 	if (toshiba_proc_dir)
 		remove_proc_entry(PROC_TOSHIBA, acpi_root_dir);
 }
-- 
2.51.0





  parent reply	other threads:[~2026-03-24 20:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-24 19:57 [PATCH v1 0/7] platform/x86: toshiba: Bind to platform devices instead of ACPI ones Rafael J. Wysocki
2026-03-24 19:58 ` [PATCH v1 1/7] platform/x86: toshiba_acpi: Reorder code to avoid forward declaration Rafael J. Wysocki
2026-03-24 19:58 ` [PATCH v1 2/7] platform/x86: toshiba_acpi: Register ACPI notify handler directly Rafael J. Wysocki
2026-03-24 20:00 ` Rafael J. Wysocki [this message]
2026-03-24 20:00 ` [PATCH v1 4/7] platform/x86: toshiba_bluetooth: " Rafael J. Wysocki
2026-03-24 20:01 ` [PATCH v1 5/7] platform/x86: toshiba_bluetooth: Convert ACPI driver to a platform one Rafael J. Wysocki
2026-03-24 20:02 ` [PATCH v1 6/7] platform/x86: toshiba_haps: Register ACPI notify handler directly Rafael J. Wysocki
2026-03-24 20:03 ` [PATCH v1 7/7] platform/x86: toshiba_haps: Convert ACPI driver to a platform one Rafael J. Wysocki
2026-03-31 16:41 ` [PATCH v1 0/7] platform/x86: toshiba: Bind to platform devices instead of ACPI ones Ilpo Järvinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2269772.irdbgypaU6@rafael.j.wysocki \
    --to=rafael@kernel.org \
    --cc=coproscefalo@gmail.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox