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
Subject: [PATCH v1 4/4] platform/x86: xo15-ebook: Convert ACPI driver to a platform one
Date: Fri, 08 May 2026 19:44:58 +0200 [thread overview]
Message-ID: <8688586.T7Z3S40VBb@rafael.j.wysocki> (raw)
In-Reply-To: <2420444.ElGaqSPkdT@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 OLPC XO-1.5 ebook switch driver from an
ACPI driver to a platform one.
After this change, the input device registered by the driver will appear
under the platform device used for driver binding.
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/x86/xo15-ebook.c | 44 ++++++++++++++++---------------
1 file changed, 23 insertions(+), 21 deletions(-)
diff --git a/drivers/platform/x86/xo15-ebook.c b/drivers/platform/x86/xo15-ebook.c
index 8af1b9078db8..2ca15f04b2d9 100644
--- a/drivers/platform/x86/xo15-ebook.c
+++ b/drivers/platform/x86/xo15-ebook.c
@@ -15,6 +15,7 @@
#include <linux/types.h>
#include <linux/input.h>
#include <linux/acpi.h>
+#include <linux/platform_device.h>
#define MODULE_NAME "xo15-ebook"
@@ -41,13 +42,13 @@ struct ebook_switch {
bool gpe_enabled;
};
-static int ebook_send_state(struct acpi_device *device)
+static int ebook_send_state(struct device *dev)
{
- struct ebook_switch *button = acpi_driver_data(device);
+ struct ebook_switch *button = dev_get_drvdata(dev);
unsigned long long state;
acpi_status status;
- status = acpi_evaluate_integer(device->handle, "EBK", NULL, &state);
+ status = acpi_evaluate_integer(ACPI_HANDLE(dev), "EBK", NULL, &state);
if (ACPI_FAILURE(status))
return -EIO;
@@ -73,14 +74,15 @@ static void ebook_switch_notify(acpi_handle handle, u32 event, void *data)
#ifdef CONFIG_PM_SLEEP
static int ebook_switch_resume(struct device *dev)
{
- return ebook_send_state(to_acpi_device(dev));
+ return ebook_send_state(dev);
}
#endif
static SIMPLE_DEV_PM_OPS(ebook_switch_pm, NULL, ebook_switch_resume);
-static int ebook_switch_add(struct acpi_device *device)
+static int ebook_switch_probe(struct platform_device *pdev)
{
+ struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
const struct acpi_device_id *id;
struct ebook_switch *button;
struct input_dev *input;
@@ -90,7 +92,7 @@ static int ebook_switch_add(struct acpi_device *device)
if (!button)
return -ENOMEM;
- device->driver_data = button;
+ platform_set_drvdata(pdev, button);
button->input = input = input_allocate_device();
if (!input) {
@@ -100,7 +102,7 @@ static int ebook_switch_add(struct acpi_device *device)
id = acpi_match_acpi_device(ebook_device_ids, device);
if (!id) {
- dev_err(&device->dev, "Unsupported hid\n");
+ dev_err(&pdev->dev, "Unsupported hid\n");
error = -ENODEV;
goto err_free_input;
}
@@ -113,7 +115,7 @@ static int ebook_switch_add(struct acpi_device *device)
input->name = acpi_device_name(device);
input->phys = button->phys;
input->id.bustype = BUS_HOST;
- input->dev.parent = &device->dev;
+ input->dev.parent = &pdev->dev;
input->evbit[0] = BIT_MASK(EV_SW);
set_bit(SW_TABLET_MODE, input->swbit);
@@ -123,11 +125,11 @@ static int ebook_switch_add(struct acpi_device *device)
goto err_free_input;
error = acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY,
- ebook_switch_notify, device);
+ ebook_switch_notify, &pdev->dev);
if (error)
goto err_unregister_input;
- ebook_send_state(device);
+ ebook_send_state(&pdev->dev);
if (device->wakeup.flags.valid) {
/* Button's GPE is run-wake GPE */
@@ -149,9 +151,10 @@ static int ebook_switch_add(struct acpi_device *device)
goto err_free_button;
}
-static void ebook_switch_remove(struct acpi_device *device)
+static void ebook_switch_remove(struct platform_device *pdev)
{
- struct ebook_switch *button = acpi_driver_data(device);
+ struct ebook_switch *button = platform_get_drvdata(pdev);
+ struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
if (button->gpe_enabled)
acpi_disable_gpe(device->wakeup.gpe_device,
@@ -163,14 +166,13 @@ static void ebook_switch_remove(struct acpi_device *device)
kfree(button);
}
-static struct acpi_driver xo15_ebook_driver = {
- .name = MODULE_NAME,
- .class = XO15_EBOOK_CLASS,
- .ids = ebook_device_ids,
- .ops = {
- .add = ebook_switch_add,
- .remove = ebook_switch_remove,
+static struct platform_driver xo15_ebook_driver = {
+ .probe = ebook_switch_probe,
+ .remove = ebook_switch_remove,
+ .driver = {
+ .name = MODULE_NAME,
+ .acpi_match_table = ebook_device_ids,
+ .pm = &ebook_switch_pm,
},
- .drv.pm = &ebook_switch_pm,
};
-module_acpi_driver(xo15_ebook_driver);
+module_platform_driver(xo15_ebook_driver);
prev parent reply other threads:[~2026-05-08 17:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 17:38 [PATCH v1 0/4] platform/x86: xo15-ebook: Bind to a platform device instead of an ACPI one Rafael J. Wysocki
2026-05-08 17:40 ` [PATCH v1 1/4] platform/x86: xo15-ebook: Fix wakeup source and GPE handling Rafael J. Wysocki
2026-05-08 17:41 ` [PATCH v1 2/4] platform/x86: xo15-ebook: Fix formatting of labels Rafael J. Wysocki
2026-05-08 17:43 ` [PATCH v1 3/4] platform/x86: xo15-ebook: Register ACPI notify handler directly Rafael J. Wysocki
2026-05-11 13:59 ` Ilpo Järvinen
2026-05-11 14:43 ` Rafael J. Wysocki
2026-05-11 16:13 ` Ilpo Järvinen
2026-05-11 16:37 ` Rafael J. Wysocki
2026-05-11 16:44 ` Ilpo Järvinen
2026-05-11 17:02 ` Rafael J. Wysocki
2026-05-08 17:44 ` Rafael J. Wysocki [this message]
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=8688586.T7Z3S40VBb@rafael.j.wysocki \
--to=rafael@kernel.org \
--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