surface pro 3: Add support driver for Surface Pro 3 buttons
PATCH v2 1/1 surface pro 3: Add support driver for Surface Pro 3 buttons
Since Surface Pro 3 does not follow the specs of "Windows ACPI Design Guide for SoC Platform", code in drivers/input/misc/soc_array.c can not detect these buttons on it. According to bios implementation, Surface Pro 3 encapsulates these buttons in a device named "VGBI", with _HID "MSHW0028". When any of the buttons is pressed, a specify ACPI notification code for this button will be delivered to "VGBI". For example, if power button is pressed down, ACPI notification code of 0xc6 will be sent by Notify(VGBI, 0xc6).
This patch leverages "VGBI" to distinguish different ACPI notification code from Power button, Home button, Volume button, then dispatches these code to input layer. Lid is already covered by acpi button driver, so there's no need to rewrite.
Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=84651
--- MAINTAINERS | 5 + drivers/platform/x86/Kconfig | 5 + drivers/platform/x86/Makefile | 1 + drivers/platform/x86/surfacepro3_button.c | 197 ++++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 drivers/platform/x86/surfacepro3_button.c
MAINTAINERS +5 -0
@@ -6712,6 +6712,11 @@ T: git git://git.monstr.eu/linux-2.6-microblaze.git S: Supported F: arch/microblaze/ +MICROSOFT SURFACE PRO 3 BUTTON DRIVER +M: Chen Yu <[email protected]> +S: Supported +F: drivers/platform/x86/surfacepro3_button.c + MICROTEK X6 SCANNER M: Oliver Neukum <[email protected]> S: Maintained
drivers/platform/x86/Kconfig +5 -0
@@ -919,4 +919,9 @@ config INTEL_PMC_IPC The PMC is an ARC processor which defines IPC commands for communication with other entities in the CPU. +config SURFACE_PRO3_BUTTON + tristate "Power/home/volume buttons driver for Microsoft Surface Pro 3 tablet" + depends on ACPI && INPUT + ---help--- + This driver handles the power/home/volume buttons on the Microsoft Surface Pro 3 tablet. endif # X86_PLATFORM_DEVICES
drivers/platform/x86/Makefile +1 -0
@@ -60,3 +60,4 @@ obj-$(CONFIG_INTEL_SMARTCONNECT) += intel-smartconnect.o obj-$(CONFIG_PVPANIC) += pvpanic.o obj-$(CONFIG_ALIENWARE_WMI) += alienware-wmi.o obj-$(CONFIG_INTEL_PMC_IPC) += intel_pmc_ipc.o +obj-$(CONFIG_SURFACE_PRO3_BUTTON) += surfacepro3_button.o
drivers/platform/x86/surfacepro3_button.c new file +197 -0
197 lines not on this page · raw message
Signature · 1 line
1.8.4.2
Quoted 3 lines · Chen Yu
Since Surface Pro 3 does not follow the specs of "Windows ACPI Design Guide for SoC Platform", code in
drivers/input/misc/soc_array.ccan not detect these buttons on it.
The comments below are all just style trivia
and can be ignored entirely.
drivers/platform/x86/surfacepro3_button.c
Quoted 1 line
drivers/platform/x86/surfacepro3_button.c +0
-0
[]
drivers/platform/x86/surfacepro3_button.c line 80
Quoted 13 lines
drivers/platform/x86/surfacepro3_button.c +13
-0+#define handle_surface_button_notify (type, code) \ +({ \ + int ret = 0; \ + if (SURFACE_BUTTON_NOTIFY_PRESS_##type == event) \ + pressed = true; \ + if (pressed || \ + (SURFACE_BUTTON_NOTIFY_RELEASE_##type == event)) { \ + key_code = code; \ + ret = 1; \ + } else \ + ret = 0; \ + ret; \ +})
This seems a bit complicated.
The else ret = 0 isn't necessary as it's initialized to 0. bool might be better than int.
drivers/platform/x86/surfacepro3_button.c line 94
Quoted 13 lines
drivers/platform/x86/surfacepro3_button.c +13
-0+static void surface_button_notify (struct acpi_device *device,u32 event) +{ +struct surface_button *button =acpi_driver_data (device); +struct input_dev *input; +int key_code =KEY_RESERVED ; +bool pressed = false; + +if (!handle_surface_button_notify (POWER ,KEY_POWER ) && + !handle_surface_button_notify (HOME ,KEY_LEFTMETA ) && + !handle_surface_button_notify (VOLUME_UP ,KEY_VOLUMEUP ) && + !handle_surface_button_notify (VOLUME_DOWN ,KEY_VOLUMEDOWN )) +dev_info_ratelimited (&device->dev, +"Unsupported event [0x%x]\n" , event);
Some might prefer alignment to the open parenthesis:
if (!handle_surface_button_notify(POWER, KEY_POWER) && !handle_surface_button_notify(HOME, KEY_LEFTMETA) && !handle_surface_button_notify(VOLUME_UP, KEY_VOLUMEUP) && !handle_surface_button_notify(VOLUME_DOWN, KEY_VOLUMEDOWN))
I think the older switch/case was easier to understand.
Quoted 9 lines · Joe Perches
On Fri, 2015-08-07 at 15:57 +0800, Chen Yu wrote: \
drivers/platform/x86/surfacepro3_button.c line 80
Quoted 2 lines
drivers/platform/x86/surfacepro3_button.c new file +2
-0+ ret; \ +})This seems a bit complicated.
The else ret = 0 isn't necessary as it's initialized to 0. bool might be better than int.
Got.
Quoted 16 lines
drivers/platform/x86/surfacepro3_button.c line 94
Quoted 13 lines
drivers/platform/x86/surfacepro3_button.c new file +13
-0+static void surface_button_notify (struct acpi_device *device,u32 event) +{ +struct surface_button *button =acpi_driver_data (device); +struct input_dev *input; +int key_code =KEY_RESERVED ; +bool pressed = false; + +if (!handle_surface_button_notify (POWER ,KEY_POWER ) && + !handle_surface_button_notify (HOME ,KEY_LEFTMETA ) && + !handle_surface_button_notify (VOLUME_UP ,KEY_VOLUMEUP ) && + !handle_surface_button_notify (VOLUME_DOWN ,KEY_VOLUMEDOWN )) +dev_info_ratelimited (&device->dev, +"Unsupported event [0x%x]\n" , event);Some might prefer alignment to the open parenthesis:
Quoted 7 lines
if (!handle_surface_button_notify(POWER, KEY_POWER) && !handle_surface_button_notify(HOME, KEY_LEFTMETA) && !handle_surface_button_notify(VOLUME_UP, KEY_VOLUMEUP) && !handle_surface_button_notify(VOLUME_DOWN, KEY_VOLUMEDOWN))I think the older switch/case was easier to understand.
OK, then let's keep the switch/case.
thanks.
Best Regards,
Yu
Quoted 32 lines · Yu C
Quoted 9 lines · Joe Perches
On Fri, 2015-08-07 at 15:57 +0800, Chen Yu wrote: \
drivers/platform/x86/surfacepro3_button.c line 80
Quoted 2 lines
drivers/platform/x86/surfacepro3_button.c new file +2
-0+ ret; \ +})This seems a bit complicated.
The else ret = 0 isn't necessary as it's initialized to 0. bool might be better than int.
Got.
Quoted 21 lines
drivers/platform/x86/surfacepro3_button.c line 94
Quoted 13 lines
drivers/platform/x86/surfacepro3_button.c new file +13
-0+static void surface_button_notify (struct acpi_device *device,u32 event) +{ +struct surface_button *button =acpi_driver_data (device); +struct input_dev *input; +int key_code =KEY_RESERVED ; +bool pressed = false; + +if (!handle_surface_button_notify (POWER ,KEY_POWER ) && + !handle_surface_button_notify (HOME ,KEY_LEFTMETA ) && + !handle_surface_button_notify (VOLUME_UP ,KEY_VOLUMEUP ) && + !handle_surface_button_notify (VOLUME_DOWN ,KEY_VOLUMEDOWN )) +dev_info_ratelimited (&device->dev, +"Unsupported event [0x%x]\n" , event);Some might prefer alignment to the open parenthesis:
if (!handle_surface_button_notify(POWER, KEY_POWER) && !handle_surface_button_notify(HOME, KEY_LEFTMETA) && !handle_surface_button_notify(VOLUME_UP, KEY_VOLUMEUP) && !handle_surface_button_notify(VOLUME_DOWN, KEY_VOLUMEDOWN))
Quoted 4 lines
Quoted 2 lines
I think the older switch/case was easier to understand.
OK, then let's keep the switch/case.
thanks.
Agreed.
Signature · 2 lines
Darren Hart Intel Open Source Technology Center
Quoted 11 lines · Darren Hart
Quoted 7 lines · Yu C
Quoted 4 lines · Joe Perches
On Fri, 2015-08-07 at 15:57 +0800, Chen Yu wrote: \
I think the older switch/case was easier to understand.
OK, then let's keep the switch/case.
thanks.Agreed.
Hi, Darren and Joe, I'll send a V4 of this patch to add a method to exclude the load of Surface 3(no Pro), since Surface 3 also has a device name of MSHW0028, but it is not used for buttons.
Thanks
Best Regards,
Yu