From nobody Fri Apr 10 00:56:46 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35A233D5242; Wed, 4 Mar 2026 18:55:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772650541; cv=none; b=FS0lJattrsRNfaXMlJuhZstuQpgR/1BdaCY5aczivjeQOIKdbPTv82LBji+bmrtab25Lw3ytu4EsnvFSzwO1+gD9Aykbj0lncpYtn3tYLG4SFSWqUnCwG+V4w5IP7oN77wC9zu7Cz/1RXT0CeorsqL7DV60hen8wzObtzH3dS18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772650541; c=relaxed/simple; bh=xlOHgIlUqmA12gHHyGdbJEDXoCNvppKOR28aBmcxNto=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W4U43UQuactJ5012p8XWkaVRZk5dJUpCoUsPCbXzOegnXwTn8a/KHEaDY+bsmisoYpZoEmmGGtFh9KOZD/loRVvIi4+kPgFF1SuUWVFNI5xq9PIMGR0OpUazuYDQJCP+UEdfz7ZQsLS0OfHbaKFZrnYfGi4FNIVo6lf94mp5yWY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XR4rE5tw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XR4rE5tw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E8A3C2BC9E; Wed, 4 Mar 2026 18:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772650540; bh=xlOHgIlUqmA12gHHyGdbJEDXoCNvppKOR28aBmcxNto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XR4rE5twdqlrxeFlAxql36uzHVbcFdfwcf/we7RPyn5w9gWwNGjBQrTtpqcRzu357 ChcLldZdP7PTy0yy32CrzO0o74ScZ8E2Hxbxd61ufLqPK5pNGm8AknZo8NFM5lRERk thuwEArIxMNxOxwaLET/cuiV0ibudNUtDX5OBVTz5+a6aQ6jpPiPySa1LBllIib8Bw QNEhQi2aQ50L/SRXRzUuEkAaWI9IJ9CBKwAW+P4VdeZUrxJJX4HWfiLA3AAb2A0RwX zh89XS5jlR1VvKqN8o/pEj3RLPRvH1dfcFyRQA4akFCgNCeDeUKZ/LNhEZ1icFbVXF evAUrAa0H91CA== From: "Rafael J. Wysocki" To: Ilpo =?ISO-8859-1?Q?J=E4rvinen?= Cc: LKML , Linux ACPI , Hans de Goede , Maximilian Luz , platform-driver-x86@vger.kernel.org Subject: [PATCH v1 3/3] platform/surface: surfacepro3_button: Convert to a platform driver Date: Wed, 04 Mar 2026 19:55:28 +0100 Message-ID: <3207406.CbtlEUcBR6@rafael.j.wysocki> Organization: Linux Kernel Development In-Reply-To: <2909929.BEx9A2HvPv@rafael.j.wysocki> References: <2909929.BEx9A2HvPv@rafael.j.wysocki> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Rafael J. Wysocki" 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 Surface Pro 3 button 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 --- drivers/platform/surface/surfacepro3_button.c | 67 +++++++++---------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/drivers/platform/surface/surfacepro3_button.c b/drivers/platfo= rm/surface/surfacepro3_button.c index 6d394daf5bc4..0293bc517b54 100644 --- a/drivers/platform/surface/surfacepro3_button.c +++ b/drivers/platform/surface/surfacepro3_button.c @@ -14,6 +14,7 @@ #include #include #include +#include #include =20 #define SURFACE_PRO3_BUTTON_HID "MSHW0028" @@ -74,8 +75,8 @@ struct surface_button { =20 static void surface_button_notify(acpi_handle handle, u32 event, void *dat= a) { - struct acpi_device *device =3D data; - struct surface_button *button =3D acpi_driver_data(device); + struct device *dev =3D data; + struct surface_button *button =3D dev_get_drvdata(dev); struct input_dev *input; int key_code =3D KEY_RESERVED; bool pressed =3D false; @@ -110,18 +111,17 @@ static void surface_button_notify(acpi_handle handle,= u32 event, void *data) key_code =3D KEY_VOLUMEDOWN; break; case SURFACE_BUTTON_NOTIFY_TABLET_MODE: - dev_warn_once(&device->dev, "Tablet mode is not supported\n"); + dev_warn_once(dev, "Tablet mode is not supported\n"); break; default: - dev_info_ratelimited(&device->dev, - "Unsupported event [0x%x]\n", event); + dev_info_ratelimited(dev, "Unsupported event [0x%x]\n", event); break; } input =3D button->input; if (key_code =3D=3D KEY_RESERVED) return; if (pressed) - pm_wakeup_dev_event(&device->dev, 0, button->suspended); + pm_wakeup_dev_event(dev, 0, button->suspended); if (button->suspended) return; input_report_key(input, key_code, pressed?1:0); @@ -131,8 +131,7 @@ static void surface_button_notify(acpi_handle handle, u= 32 event, void *data) #ifdef CONFIG_PM_SLEEP static int surface_button_suspend(struct device *dev) { - struct acpi_device *device =3D to_acpi_device(dev); - struct surface_button *button =3D acpi_driver_data(device); + struct surface_button *button =3D dev_get_drvdata(dev); =20 button->suspended =3D true; return 0; @@ -140,8 +139,7 @@ static int surface_button_suspend(struct device *dev) =20 static int surface_button_resume(struct device *dev) { - struct acpi_device *device =3D to_acpi_device(dev); - struct surface_button *button =3D acpi_driver_data(device); + struct surface_button *button =3D dev_get_drvdata(dev); =20 button->suspended =3D false; return 0; @@ -156,9 +154,8 @@ static int surface_button_resume(struct device *dev) * Returns true if the driver should bind to this device, i.e. the device = is * either MSWH0028 (Pro 3) or MSHW0040 on a Pro 4 or Book 1. */ -static bool surface_button_check_MSHW0040(struct acpi_device *dev) +static bool surface_button_check_MSHW0040(struct device *dev, acpi_handle = handle) { - acpi_handle handle =3D dev->handle; union acpi_object *result; u64 oem_platform_rev =3D 0; // valid revisions are nonzero =20 @@ -180,14 +177,15 @@ static bool surface_button_check_MSHW0040(struct acpi= _device *dev) ACPI_FREE(result); } =20 - dev_dbg(&dev->dev, "OEM Platform Revision %llu\n", oem_platform_rev); + dev_dbg(dev, "OEM Platform Revision %llu\n", oem_platform_rev); =20 return oem_platform_rev =3D=3D 0; } =20 =20 -static int surface_button_add(struct acpi_device *device) +static int surface_button_probe(struct platform_device *pdev) { + struct acpi_device *device =3D ACPI_COMPANION(&pdev->dev); struct surface_button *button; struct input_dev *input; const char *hid =3D acpi_device_hid(device); @@ -197,14 +195,14 @@ static int surface_button_add(struct acpi_device *dev= ice) strlen(SURFACE_BUTTON_OBJ_NAME))) return -ENODEV; =20 - if (!surface_button_check_MSHW0040(device)) + if (!surface_button_check_MSHW0040(&pdev->dev, device->handle)) return -ENODEV; =20 button =3D kzalloc_obj(struct surface_button); if (!button) return -ENOMEM; =20 - device->driver_data =3D button; + platform_set_drvdata(pdev, button); button->input =3D input =3D input_allocate_device(); if (!input) { error =3D -ENOMEM; @@ -217,7 +215,7 @@ static int surface_button_add(struct acpi_device *devic= e) input->name =3D acpi_device_name(device); input->phys =3D button->phys; input->id.bustype =3D BUS_HOST; - input->dev.parent =3D &device->dev; + input->dev.parent =3D &pdev->dev; input_set_capability(input, EV_KEY, KEY_POWER); input_set_capability(input, EV_KEY, KEY_LEFTMETA); input_set_capability(input, EV_KEY, KEY_VOLUMEUP); @@ -227,17 +225,17 @@ static int surface_button_add(struct acpi_device *dev= ice) if (error) goto err_free_input; =20 - device_init_wakeup(&device->dev, true); + device_init_wakeup(&pdev->dev, true); =20 error =3D acpi_dev_install_notify_handler(device, ACPI_DEVICE_NOTIFY, - surface_button_notify, device); + surface_button_notify, &pdev->dev); if (error) { - device_init_wakeup(&device->dev, false); + device_init_wakeup(&pdev->dev, false); input_unregister_device(input); goto err_free_button; } =20 - dev_info(&device->dev, "%s [%s]\n", acpi_device_name(device), + dev_info(&pdev->dev, "%s [%s]\n", acpi_device_name(device), acpi_device_bid(device)); return 0; =20 @@ -248,13 +246,13 @@ static int surface_button_add(struct acpi_device *dev= ice) return error; } =20 -static void surface_button_remove(struct acpi_device *device) +static void surface_button_remove(struct platform_device *pdev) { - struct surface_button *button =3D acpi_driver_data(device); + struct surface_button *button =3D platform_get_drvdata(pdev); =20 - acpi_dev_remove_notify_handler(device, ACPI_DEVICE_NOTIFY, - surface_button_notify); - device_init_wakeup(&device->dev, false); + acpi_dev_remove_notify_handler(ACPI_COMPANION(&pdev->dev), + ACPI_DEVICE_NOTIFY, surface_button_notify); + device_init_wakeup(&pdev->dev, false); input_unregister_device(button->input); kfree(button); } @@ -262,15 +260,14 @@ static void surface_button_remove(struct acpi_device = *device) static SIMPLE_DEV_PM_OPS(surface_button_pm, surface_button_suspend, surface_button_resume); =20 -static struct acpi_driver surface_button_driver =3D { - .name =3D "surface_pro3_button", - .class =3D "SurfacePro3", - .ids =3D surface_button_device_ids, - .ops =3D { - .add =3D surface_button_add, - .remove =3D surface_button_remove, +static struct platform_driver surface_button_driver =3D { + .probe =3D surface_button_probe, + .remove =3D surface_button_remove, + .driver =3D { + .name =3D "surface_pro3_button", + .acpi_match_table =3D surface_button_device_ids, + .pm =3D &surface_button_pm, }, - .drv.pm =3D &surface_button_pm, }; =20 -module_acpi_driver(surface_button_driver); +module_platform_driver(surface_button_driver); --=20 2.51.0