Support for buttons on newer MS Surface devices
Subsystems (3)
v3 cover Support for buttons on newer MS Surface devices
This series adds support for power and volume buttons on 5th and 6th generation Microsoft Surface devices. Specifically, it adds support for the power-button on the Surface Laptop 1 and Laptop 2, as well as support for power- and (on-device) volume-buttons on the Surface Pro 5 (2017), Pro 6, and Book 2.
These devices use the same MSHW0040 device as on the Surface Pro 4, however, whereas the Pro 4 uses an ACPI notify handler, the newer devices use GPIO interrupts to signal these events.
The first patch of this series ensures that the surfacepro3_button driver, used for MSHW0040 on the Pro 4, does not probe for the newer devices. The second patch adapts soc_button_array to implement the actual button support.
Changes in v3:
- [PATCH 1/2] platform/x86: surfacepro3_button: Fix device check
- Changed subject line to fit conventions.
- Added comments to clarify ACPI/DSM specific behavior.
- Change return type of introduced device check function to bool.
- [PATCH 1/2] Input: soc_button_array - Add support for newer surface devices
- Changed subject line to fit conventions.
- Explicitly require CONFIG_ACPI via Kconfig instead of guarding with #ifdef CONFIG_ACPI in code.
- Add supported Surface devices to module description in Kconfig.
- Allow -EPROBE_DEFER and other errors to be propagated from gpiod_get.
- Fix deferral process in case GPIO subsystem is not initialized.
Changes in v2:
- [PATCH 1/2] platform: Fix device check for surfacepro3_button No changes.
- [PATCH 2/2] input: soc_button_array for newer surface devices Ensure the patch compiles without CONFIG_ACPI.
Maximilian Luz (2):
platform/x86: surfacepro3_button: Fix device check
Input: soc_button_array - Add support for newer surface devices
drivers/input/misc/Kconfig | 6 +- drivers/input/misc/soc_button_array.c | 141 ++++++++++++++++++++-- drivers/platform/x86/surfacepro3_button.c | 47 ++++++++ 3 files changed, 178 insertions(+), 16 deletions(-)
Signature · 1 line
2.22.0
PATCH v3 1/2 platform/x86: surfacepro3_button: Fix device check
Do not use the surfacepro3_button driver on newer Microsoft Surface models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th and possibly future generations) use the same device as the Surface Pro 4 to represent their volume and power buttons (MSHW0040), but their actual implementation is significantly different. This patch ensures that the surfacepro3_button driver is only used on the Pro 3 and 4 models, allowing a different driver to bind on other models.
--- drivers/platform/x86/surfacepro3_button.c | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/platform/x86/surfacepro3_button.c +47 -0
@@ -20,6 +20,12 @@#define SURFACE_BUTTON_OBJ_NAME "VGBI"#define SURFACE_BUTTON_DEVICE_NAME "Surface Pro 3/4 Buttons" +#define MSHW0040_DSM_REVISION 0x01 +#define MSHW0040_DSM_GET_OMPR 0x02 // get OEM Platform Revision +static const guid_t MSHW0040_DSM_UUID = +GUID_INIT (0x6fd05c69 ,0xcde3 ,0x49f4 ,0x95 ,0xed ,0xab ,0x16 ,0x65 , +0x49 ,0x80 ,0x35 ); +#define SURFACE_BUTTON_NOTIFY_TABLET_MODE 0xc8#define SURFACE_BUTTON_NOTIFY_PRESS_POWER 0xc6
@@ -142,6 +148,44 @@ static int surface_button_resume(struct device *dev) }#endif +/* +* Surface Pro 4 and Surface Book 2 / Surface Pro 2017 use the same device +* ID (MSHW0040) for the power/volume buttons. Make sure this is the right +* device by checking for the _DSM method and OEM Platform Revision. +* +* 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) +{ +acpi_handle handle = dev->handle; +union acpi_object *result; +u64 oem_platform_rev =0 ;// valid revisions are nonzero + +// get OEM platform revision + result =acpi_evaluate_dsm_typed (handle, &MSHW0040_DSM_UUID , +MSHW0040_DSM_REVISION , +MSHW0040_DSM_GET_OMPR , +NULL ,ACPI_TYPE_INTEGER ); + +/* +* If evaluating the _DSM fails, the method is not present. This means +* that we have either MSHW0028 or MSHW0040 on Pro 4 or Book 1, so we +* should use this driver. We use revision 0 indicating it is +* unavailable. +*/ + +if (result) { + oem_platform_rev = result->integer.value; +ACPI_FREE (result); + } + +dev_dbg (&dev->dev,"OEM Platform Revision %llu\n" , oem_platform_rev); + +return oem_platform_rev ==0 ; +} + +static int surface_button_add (struct acpi_device *device) {struct surface_button *button;
@@ -154,6 +198,9 @@ static int surface_button_add(struct acpi_device *device) strlen(SURFACE_BUTTON_OBJ_NAME)))return -ENODEV ; +if (!surface_button_check_MSHW0040 (device)) +return -ENODEV ; + button =kzalloc (sizeof (struct surface_button ),GFP_KERNEL );if (!button)return -ENOMEM ;
Signature · 1 line
2.22.0
Re: [PATCH v3 1/2] platform/x86: surfacepro3_button: Fix device check
Quoted 9 lines · Maximilian Luz
Do not use the
surfacepro3_buttondriver on newer Microsoft Surface models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th and possibly future generations) use the same device as the Surface Pro 4 to represent their volume and power buttons (MSHW0040), but their actual implementation is significantly different. This patch ensures that thesurfacepro3_buttondriver is only used on the Pro 3 and 4 models, allowing a different driver to bind on other models.
assuming it will go thru Input subsystem.
Quoted 80 lines
Signed-off-by Maximilian Luz <[email protected]>--- drivers/platform/x86/surfacepro3_button.c | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+)drivers/platform/x86/surfacepro3_button.c +47
-1@@ -20,6 +20,12 @@#define SURFACE_BUTTON_OBJ_NAME "VGBI"#define SURFACE_BUTTON_DEVICE_NAME "Surface Pro 3/4 Buttons" +#define MSHW0040_DSM_REVISION 0x01 +#define MSHW0040_DSM_GET_OMPR 0x02 // get OEM Platform Revision +static const guid_t MSHW0040_DSM_UUID = +GUID_INIT (0x6fd05c69 ,0xcde3 ,0x49f4 ,0x95 ,0xed ,0xab ,0x16 ,0x65 , +0x49 ,0x80 ,0x35 ); +#define SURFACE_BUTTON_NOTIFY_TABLET_MODE 0xc8#define SURFACE_BUTTON_NOTIFY_PRESS_POWER 0xc6@@ -142,6 +148,44 @@ static int surface_button_resume(struct device *dev) }#endif +/* +* Surface Pro 4 and Surface Book 2 / Surface Pro 2017 use the same device +* ID (MSHW0040) for the power/volume buttons. Make sure this is the right +* device by checking for the _DSM method and OEM Platform Revision. +* +* 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) +{ +acpi_handle handle = dev->handle; +union acpi_object *result; +u64 oem_platform_rev =0 ;// valid revisions are nonzero + +// get OEM platform revision + result =acpi_evaluate_dsm_typed (handle, &MSHW0040_DSM_UUID , +MSHW0040_DSM_REVISION , +MSHW0040_DSM_GET_OMPR , +NULL ,ACPI_TYPE_INTEGER ); + +/* +* If evaluating the _DSM fails, the method is not present. This means +* that we have either MSHW0028 or MSHW0040 on Pro 4 or Book 1, so we +* should use this driver. We use revision 0 indicating it is +* unavailable. +*/ + +if (result) { + oem_platform_rev = result->integer.value; +ACPI_FREE (result); + } + +dev_dbg (&dev->dev,"OEM Platform Revision %llu\n" , oem_platform_rev); + +return oem_platform_rev ==0 ; +} + +static int surface_button_add (struct acpi_device *device) {struct surface_button *button;@@ -154,6 +198,9 @@ static int surface_button_add(struct acpi_device *device) strlen(SURFACE_BUTTON_OBJ_NAME)))return -ENODEV ; +if (!surface_button_check_MSHW0040 (device)) +return -ENODEV ; + button =kzalloc (sizeof (struct surface_button ),GFP_KERNEL );if (!button)return -ENOMEM ; --2.22.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Dmitry Torokhov
maintainerRe: [PATCH v3 1/2] platform/x86: surfacepro3_button: Fix device check
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Maximilian Luz
Do not use the
surfacepro3_buttondriver on newer Microsoft Surface models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th and possibly future generations) use the same device as the Surface Pro 4 to represent their volume and power buttons (MSHW0040), but their actual implementation is significantly different. This patch ensures that thesurfacepro3_buttondriver is only used on the Pro 3 and 4 models, allowing a different driver to bind on other models.
Quoted 3 lines
Acked-by Andy Shevchenko <[email protected]>assuming it will go thru Input subsystem.
I can take it, but I do not think it is dependent on the other change and thus can go through platform tree as well.
Thanks.
Signature · 1 line
Dmitry
Re: [PATCH v3 1/2] platform/x86: surfacepro3_button: Fix device check
Quoted 13 lines · Dmitry Torokhov
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Maximilian Luz
Do not use the
surfacepro3_buttondriver on newer Microsoft Surface models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th and possibly future generations) use the same device as the Surface Pro 4 to represent their volume and power buttons (MSHW0040), but their actual implementation is significantly different. This patch ensures that thesurfacepro3_buttondriver is only used on the Pro 3 and 4 models, allowing a different driver to bind on other models.
Quoted 6 lines
Quoted 3 lines
Acked-by Andy Shevchenko <[email protected]>assuming it will go thru Input subsystem.
I can take it, but I do not think it is dependent on the other change and thus can go through platform tree as well.
Pkease, take it. I do not expect any changes to the driver this cycle.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Dmitry Torokhov
maintainerRe: [PATCH v3 1/2] platform/x86: surfacepro3_button: Fix device check
Quoted 15 lines · Andy Shevchenko
Quoted 13 lines · Dmitry Torokhov
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Maximilian Luz
Do not use the
surfacepro3_buttondriver on newer Microsoft Surface models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th and possibly future generations) use the same device as the Surface Pro 4 to represent their volume and power buttons (MSHW0040), but their actual implementation is significantly different. This patch ensures that thesurfacepro3_buttondriver is only used on the Pro 3 and 4 models, allowing a different driver to bind on other models.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Acked-by Andy Shevchenko <[email protected]>assuming it will go thru Input subsystem.
I can take it, but I do not think it is dependent on the other change and thus can go through platform tree as well.
Pkease, take it. I do not expect any changes to the driver this cycle.
OK, applied, thank you.
Signature · 1 line
Dmitry
Re: [PATCH v3 1/2] platform/x86: surfacepro3_button: Fix device check
In reply to Maximilian LuzQuoted 10 lines · Maximilian Luz
Do not use the
surfacepro3_buttondriver on newer Microsoft Surface models, only use it on the Surface Pro 3 and 4. Newer models (5th, 6th and possibly future generations) use the same device as the Surface Pro 4 to represent their volume and power buttons (MSHW0040), but their actual implementation is significantly different. This patch ensures that thesurfacepro3_buttondriver is only used on the Pro 3 and 4 models, allowing a different driver to bind on other models.Signed-off-by Maximilian Luz <[email protected]>---
Thanks,
Chenyu
PATCH v3 2/2 Input: soc_button_array - Add support for newer surface devices
In reply to Maximilian LuzPower and volume button support for 5th and 6th generation Microsoft Surface devices via soc_button_array.
Note that these devices use the same MSHW0040 device as on the Surface Pro 4, however the implementation is different (GPIOs vs. ACPI notifications). Thus some checking is required to ensure we only load this driver on the correct devices.
--- drivers/input/misc/Kconfig | 6 +- drivers/input/misc/soc_button_array.c | 141 +++++++++++++++++++++++--- 2 files changed, 131 insertions(+), 16 deletions(-)
drivers/input/misc/Kconfig +3 -3
@@ -813,10 +813,10 @@ config INPUT_IDEAPAD_SLIDEBAR config INPUT_SOC_BUTTON_ARRAY tristate "Windows-compatible SoC Button Array" - depends on KEYBOARD_GPIO + depends on KEYBOARD_GPIO && ACPI help - Say Y here if you have a SoC-based tablet that originally - runs Windows 8. + Say Y here if you have a SoC-based tablet that originally runs + Windows 8 or a Microsoft Surface Book 2, Pro 5, Laptop 1 or later. To compile this driver as a module, choose M here: the module will be called soc_button_array.
drivers/input/misc/soc_button_array.c +128 -13
187 lines not on this page · raw message
Signature · 1 line
2.22.0
Re: [PATCH v3 2/2] Input: soc_button_array - Add support for newer surface devices
Quoted 7 lines · Maximilian Luz
Power and volume button support for 5th and 6th generation Microsoft Surface devices via
soc_button_array.Note that these devices use the same MSHW0040 device as on the Surface Pro 4, however the implementation is different (GPIOs vs. ACPI notifications). Thus some checking is required to ensure we only load this driver on the correct devices.
Could this also used on the older (pre pro4) devices (also using the gpios directly, and leave off acpi notifications) ?
--mtx
Signature · 3 lines
Enrico Weigelt, metux IT consult Free software and Linux embedded engineering [email protected] -- +49-151-27565287
Re: [PATCH v3 2/2] Input: soc_button_array - Add support for newer surface devices
Quoted 11 lines · metux IT consult
Quoted 7 lines · Maximilian Luz
Power and volume button support for 5th and 6th generation Microsoft Surface devices via
soc_button_array.Note that these devices use the same MSHW0040 device as on the Surface Pro 4, however the implementation is different (GPIOs vs. ACPI notifications). Thus some checking is required to ensure we only load this driver on the correct devices.
Could this also used on the older (pre pro4) devices (also using the gpios directly, and leave off acpi notifications) ?
As far as I can tell, no. The Pro 4 and Pro 3 don't have any GPIOs on MSHW0028/MSHW0040. Book 1 has GPIOs but for a different purpose. The Pro 2 has a standard PNP0C0C power button (no idea how the volume buttons are handled there, but also seems to be different from what I can gather from DSDT). I can't say anything for the Pro 1 and non-Pro devices.
Maximilian
Dmitry Torokhov
maintainerRe: [PATCH v3 2/2] Input: soc_button_array - Add support for newer surface devices
In reply to Maximilian LuzHi Maximilian,
Review
Quoted 5 lines · Maximilian Luz
(quoted diff) +0
-5- - error = gpiod_count(dev, NULL); - if (error < 0) { - dev_dbg(dev, "no GPIO attached, ignoring...\n"); - return -ENODEV;
I do not think we need to move this into individual "check" functions. It is needed in all cases so we should keep it here.
How about version below?
Input: soc_button_array - add support for newer surface devices
From: Maximilian Luz <[email protected]>
Power and volume button support for 5th and 6th generation Microsoft Surface devices via soc_button_array.
Note that these devices use the same MSHW0040 device as on the Surface Pro 4, however the implementation is different (GPIOs vs. ACPI notifications). Thus some checking is required to ensure we only load this driver on the correct devices.
--- drivers/input/misc/Kconfig | 6 +- drivers/input/misc/soc_button_array.c | 105 +++++++++++++++++++++++++++++---- 2 files changed, 96 insertions(+), 15 deletions(-)
drivers/input/misc/Kconfig +3 -3
@@ -813,10 +813,10 @@ config INPUT_IDEAPAD_SLIDEBAR config INPUT_SOC_BUTTON_ARRAY tristate "Windows-compatible SoC Button Array" - depends on KEYBOARD_GPIO + depends on KEYBOARD_GPIO && ACPI help - Say Y here if you have a SoC-based tablet that originally - runs Windows 8. + Say Y here if you have a SoC-based tablet that originally runs + Windows 8 or a Microsoft Surface Book 2, Pro 5, Laptop 1 or later. To compile this driver as a module, choose M here: the module will be called soc_button_array.
drivers/input/misc/soc_button_array.c +93 -12
153 lines not on this page · raw message
Signature · 1 line
Dmitry
Re: [PATCH v3 2/2] Input: soc_button_array - Add support for newer surface devices
Quoted 11 lines · Dmitry Torokhov
Review
Quoted 5 lines · Maximilian Luz
(quoted diff) +0
-5- - error = gpiod_count(dev, NULL); - if (error < 0) { - dev_dbg(dev, "no GPIO attached, ignoring...\n"); - return -ENODEV;I do not think we need to move this into individual "check" functions. It is needed in all cases so we should keep it here.
How about version below?
Makes sense, looks good to me!
Maximilian
Dmitry Torokhov
maintainerRe: [PATCH v3 2/2] Input: soc_button_array - Add support for newer surface devices
Quoted 11 lines · Maximilian Luz
Quoted 10 lines · Dmitry Torokhov
Review
Quoted 5 lines · Maximilian Luz
(quoted diff) +0
-5- - error = gpiod_count(dev, NULL); - if (error < 0) { - dev_dbg(dev, "no GPIO attached, ignoring...\n"); - return -ENODEV;I do not think we need to move this into individual "check" functions. It is needed in all cases so we should keep it here.
Quoted 3 lines
Quoted 1 line
How about version below?
Makes sense, looks good to me!
OK, great, applied.
Signature · 1 line
Dmitry