mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rafael@kernel.org>
To: chrome-platform@lists.linux.dev
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linux ACPI <linux-acpi@vger.kernel.org>,
	Benson Leung <bleung@chromium.org>,
	Tzung-Bi Shih <tzungbi@kernel.org>,
	Enric Balletbo i Serra <eballetbo@kernel.org>,
	Ravi Chandra Sadineni <ravisadineni@chromium.org>
Subject: [PATCH v1 4/6] platform/chrome: chromeos_tbmc: Convert to a platform driver
Date: Wed, 04 Mar 2026 19:44:26 +0100	[thread overview]
Message-ID: <2553054.jE0xQCEvom@rafael.j.wysocki> (raw)
In-Reply-To: <2274474.Mh6RI2rZIc@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 ChromeOS tablet mode change (TBMC) ACPI
driver to a platform one.

After this change, the subordinate input device and wakeup source class
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/platform/chrome/chromeos_tbmc.c | 46 ++++++++++++-------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/drivers/platform/chrome/chromeos_tbmc.c b/drivers/platform/chrome/chromeos_tbmc.c
index 9c988e697d09..c018296420b1 100644
--- a/drivers/platform/chrome/chromeos_tbmc.c
+++ b/drivers/platform/chrome/chromeos_tbmc.c
@@ -16,6 +16,7 @@
 #include <linux/input.h>
 #include <linux/io.h>
 #include <linux/module.h>
+#include <linux/platform_device.h>
 #include <linux/printk.h>
 
 #define DRV_NAME "chromeos_tbmc"
@@ -40,22 +41,21 @@ static int chromeos_tbmc_query_switch(struct acpi_device *adev,
 
 static __maybe_unused int chromeos_tbmc_resume(struct device *dev)
 {
-	struct acpi_device *adev = to_acpi_device(dev);
-
-	return chromeos_tbmc_query_switch(adev, adev->driver_data);
+	return chromeos_tbmc_query_switch(ACPI_COMPANION(dev), dev_get_drvdata(dev));
 }
 
 static void chromeos_tbmc_notify(acpi_handle handle, u32 event, void *data)
 {
-	struct acpi_device *adev = data;
+	struct device *dev = data;
+	struct acpi_device *adev = ACPI_COMPANION(dev);
 
 	acpi_pm_wakeup_event(&adev->dev);
 	switch (event) {
 	case 0x80:
-		chromeos_tbmc_query_switch(adev, adev->driver_data);
+		chromeos_tbmc_query_switch(adev, dev_get_drvdata(dev));
 		break;
 	default:
-		dev_err(&adev->dev, "Unexpected event: 0x%08X\n", event);
+		dev_err(dev, "Unexpected event: 0x%08X\n", event);
 	}
 }
 
@@ -66,10 +66,11 @@ static int chromeos_tbmc_open(struct input_dev *idev)
 	return chromeos_tbmc_query_switch(adev, idev);
 }
 
-static int chromeos_tbmc_add(struct acpi_device *adev)
+static int chromeos_tbmc_probe(struct platform_device *pdev)
 {
 	struct input_dev *idev;
-	struct device *dev = &adev->dev;
+	struct device *dev = &pdev->dev;
+	struct acpi_device *adev = ACPI_COMPANION(dev);
 	int ret;
 
 	idev = devm_input_allocate_device(dev);
@@ -85,7 +86,7 @@ static int chromeos_tbmc_add(struct acpi_device *adev)
 	idev->open = chromeos_tbmc_open;
 
 	input_set_drvdata(idev, adev);
-	adev->driver_data = idev;
+	platform_set_drvdata(pdev, idev);
 
 	input_set_capability(idev, EV_SW, SW_TABLET_MODE);
 	ret = input_register_device(idev);
@@ -96,7 +97,7 @@ static int chromeos_tbmc_add(struct acpi_device *adev)
 	device_init_wakeup(dev, true);
 
 	ret = acpi_dev_install_notify_handler(adev, ACPI_DEVICE_NOTIFY,
-					      chromeos_tbmc_notify, adev);
+					      chromeos_tbmc_notify, dev);
 	if (ret) {
 		dev_err(dev, "cannot install ACPI notify handler\n");
 		device_init_wakeup(dev, false);
@@ -106,11 +107,11 @@ static int chromeos_tbmc_add(struct acpi_device *adev)
 	return 0;
 }
 
-static void chromeos_tbmc_remove(struct acpi_device *adev)
+static void chromeos_tbmc_remove(struct platform_device *pdev)
 {
-	acpi_dev_remove_notify_handler(adev, ACPI_DEVICE_NOTIFY,
-				       chromeos_tbmc_notify);
-	device_init_wakeup(&adev->dev, false);
+	acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev),
+				       ACPI_DEVICE_NOTIFY, chromeos_tbmc_notify);
+	device_init_wakeup(&pdev->dev, false);
 }
 
 static const struct acpi_device_id chromeos_tbmc_acpi_device_ids[] = {
@@ -122,18 +123,17 @@ MODULE_DEVICE_TABLE(acpi, chromeos_tbmc_acpi_device_ids);
 static SIMPLE_DEV_PM_OPS(chromeos_tbmc_pm_ops, NULL,
 		chromeos_tbmc_resume);
 
-static struct acpi_driver chromeos_tbmc_driver = {
-	.name = DRV_NAME,
-	.class = DRV_NAME,
-	.ids = chromeos_tbmc_acpi_device_ids,
-	.ops = {
-		.add = chromeos_tbmc_add,
-		.remove = chromeos_tbmc_remove,
+static struct platform_driver chromeos_tbmc_driver = {
+	.probe = chromeos_tbmc_probe,
+	.remove = chromeos_tbmc_remove,
+	.driver = {
+		.name = DRV_NAME,
+		.acpi_match_table = chromeos_tbmc_acpi_device_ids,
+		.pm = &chromeos_tbmc_pm_ops,
 	},
-	.drv.pm = &chromeos_tbmc_pm_ops,
 };
 
-module_acpi_driver(chromeos_tbmc_driver);
+module_platform_driver(chromeos_tbmc_driver);
 
 MODULE_LICENSE("GPL v2");
 MODULE_DESCRIPTION("ChromeOS ACPI tablet switch driver");
-- 
2.51.0





  parent reply	other threads:[~2026-03-04 18:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04 18:41 [PATCH v1 0/6] platform/chrome: Bind drivers to platform devices instead of ACPI ones Rafael J. Wysocki
2026-03-04 18:42 ` [PATCH v1 1/6] platform/chrome: Convert ChromeOS privacy-screen driver to platform Rafael J. Wysocki
2026-03-04 18:43 ` [PATCH v1 2/6] platform/chrome: chromeos_tbmc: Drop wakeup source on remove Rafael J. Wysocki
2026-03-05 15:29   ` Tzung-Bi Shih
2026-03-05 15:30     ` Rafael J. Wysocki
2026-03-04 18:43 ` [PATCH v1 3/6] platform/chrome: chromeos_tbmc: Register ACPI notify handler Rafael J. Wysocki
2026-03-04 18:44 ` Rafael J. Wysocki [this message]
2026-03-05 15:29   ` [PATCH v1 4/6] platform/chrome: chromeos_tbmc: Convert to a platform driver Tzung-Bi Shih
2026-03-05 15:34     ` Rafael J. Wysocki
2026-03-05 15:50       ` Tzung-Bi Shih
2026-03-05 15:52         ` Rafael J. Wysocki
2026-03-04 18:45 ` [PATCH v1 5/6] platform/chrome: wilco_ec: event: Register ACPI notify handler Rafael J. Wysocki
2026-03-04 18:45 ` [PATCH v1 6/6] platform/chrome: wilco_ec: event: Convert to a platform driver Rafael J. Wysocki

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=2553054.jE0xQCEvom@rafael.j.wysocki \
    --to=rafael@kernel.org \
    --cc=bleung@chromium.org \
    --cc=chrome-platform@lists.linux.dev \
    --cc=eballetbo@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ravisadineni@chromium.org \
    --cc=tzungbi@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

all inboxes | Powered by JetHome®