[PATCH v2 4/6] platform/chrome: chromeos_tbmc: Convert to a platform driver
From: Rafael J. Wysocki
Date: Thu Mar 05 2026 - 14:50:41 EST
From: "Rafael J. Wysocki" <rafael.j.wysocki@xxxxxxxxx>
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@xxxxxxxxx>
---
v1 -> v2:
* Pass dev to acpi_pm_wakeup_event() in chromeos_tbmc_notify() (Tzung-Bi Shih)
* Pass ACPI_COMPANION(dev) directly to chromeos_tbmc_query_switch in
chromeos_tbmc_notify()
---
drivers/platform/chrome/chromeos_tbmc.c | 47 ++++++++++++-------------
1 file changed, 23 insertions(+), 24 deletions(-)
diff --git a/drivers/platform/chrome/chromeos_tbmc.c b/drivers/platform/chrome/chromeos_tbmc.c
index 9c988e697d09..5133806b2d95 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,20 @@ 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;
- acpi_pm_wakeup_event(&adev->dev);
+ acpi_pm_wakeup_event(dev);
switch (event) {
case 0x80:
- chromeos_tbmc_query_switch(adev, adev->driver_data);
+ chromeos_tbmc_query_switch(ACPI_COMPANION(dev), 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 +65,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 +85,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 +96,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 +106,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 +122,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