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 7/7] platform/x86: toshiba_haps: Convert ACPI driver to a platform one
Date: Tue, 24 Mar 2026 21:03:01 +0100	[thread overview]
Message-ID: <2045343.PYKUYFuaPT@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 HDD Active Protection Sensor
driver from an 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.

Note that the sysfs attributes in haps_attr_group will still be there
in the sysfs directory of the ACPI companion of the platform device
used for driver binding in case there are tools in user space expecting
them to be present there.

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_haps.c | 40 +++++++++++++++--------------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/drivers/platform/x86/toshiba_haps.c b/drivers/platform/x86/toshiba_haps.c
index 6eac306cf92a..1486252b5983 100644
--- a/drivers/platform/x86/toshiba_haps.c
+++ b/drivers/platform/x86/toshiba_haps.c
@@ -12,6 +12,7 @@
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/acpi.h>
+#include <linux/platform_device.h>
 
 MODULE_AUTHOR("Azael Avalos <coproscefalo@gmail.com>");
 MODULE_DESCRIPTION("Toshiba HDD Active Protection Sensor");
@@ -140,8 +141,10 @@ static void toshiba_haps_notify(acpi_handle handle, u32 event, void *data)
 					event, 0);
 }
 
-static void toshiba_haps_remove(struct acpi_device *device)
+static void toshiba_haps_remove(struct platform_device *pdev)
 {
+	struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
+
 	acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY,
 				       toshiba_haps_notify);
 
@@ -149,6 +152,8 @@ static void toshiba_haps_remove(struct acpi_device *device)
 
 	if (toshiba_haps)
 		toshiba_haps = NULL;
+
+	dev_set_drvdata(&device->dev, NULL);
 }
 
 /* Helper function */
@@ -175,8 +180,9 @@ static int toshiba_haps_available(acpi_handle handle)
 	return 1;
 }
 
-static int toshiba_haps_add(struct acpi_device *acpi_dev)
+static int toshiba_haps_probe(struct platform_device *pdev)
 {
+	struct acpi_device *acpi_dev = ACPI_COMPANION(&pdev->dev);
 	struct toshiba_haps_dev *haps;
 	int ret;
 
@@ -188,14 +194,15 @@ static int toshiba_haps_add(struct acpi_device *acpi_dev)
 
 	pr_info("Toshiba HDD Active Protection Sensor device\n");
 
-	haps = devm_kzalloc(&acpi_dev->dev, sizeof(*haps), GFP_KERNEL);
+	haps = devm_kzalloc(&pdev->dev, sizeof(*haps), GFP_KERNEL);
 	if (!haps)
 		return -ENOMEM;
 
 	haps->acpi_dev = acpi_dev;
 	haps->protection_level = 2;
-	acpi_dev->driver_data = haps;
+
 	dev_set_drvdata(&acpi_dev->dev, haps);
+	platform_set_drvdata(pdev, haps);
 
 	/* Set the protection level, currently at level 2 (Medium) */
 	ret = toshiba_haps_protection_level(acpi_dev->handle, 2);
@@ -223,11 +230,9 @@ static int toshiba_haps_add(struct acpi_device *acpi_dev)
 #ifdef CONFIG_PM_SLEEP
 static int toshiba_haps_suspend(struct device *device)
 {
-	struct toshiba_haps_dev *haps;
+	struct toshiba_haps_dev *haps = dev_get_drvdata(device);
 	int ret;
 
-	haps = acpi_driver_data(to_acpi_device(device));
-
 	/* Deactivate the protection on suspend */
 	ret = toshiba_haps_protection_level(haps->acpi_dev->handle, 0);
 
@@ -236,11 +241,9 @@ static int toshiba_haps_suspend(struct device *device)
 
 static int toshiba_haps_resume(struct device *device)
 {
-	struct toshiba_haps_dev *haps;
+	struct toshiba_haps_dev *haps = dev_get_drvdata(device);
 	int ret;
 
-	haps = acpi_driver_data(to_acpi_device(device));
-
 	/* Set the stored protection level */
 	ret = toshiba_haps_protection_level(haps->acpi_dev->handle,
 					    haps->protection_level);
@@ -263,15 +266,14 @@ static const struct acpi_device_id haps_device_ids[] = {
 };
 MODULE_DEVICE_TABLE(acpi, haps_device_ids);
 
-static struct acpi_driver toshiba_haps_driver = {
-	.name = "Toshiba HAPS",
-	.ids = haps_device_ids,
-	.flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
-	.ops = {
-		.add =		toshiba_haps_add,
-		.remove =	toshiba_haps_remove,
+static struct platform_driver toshiba_haps_driver = {
+	.probe = toshiba_haps_probe,
+	.remove = toshiba_haps_remove,
+	.driver = {
+		.name = "Toshiba HAPS",
+		.acpi_match_table = haps_device_ids,
+		.pm = &toshiba_haps_pm,
 	},
-	.drv.pm = &toshiba_haps_pm,
 };
 
-module_acpi_driver(toshiba_haps_driver);
+module_platform_driver(toshiba_haps_driver);
-- 
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 ` [PATCH v1 3/7] platform/x86: toshiba_acpi: Convert ACPI driver to a platform one Rafael J. Wysocki
2026-03-24 20:00 ` [PATCH v1 4/7] platform/x86: toshiba_bluetooth: Register ACPI notify handler directly 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 ` Rafael J. Wysocki [this message]
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=2045343.PYKUYFuaPT@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