aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChen Yu <yu.c.chen@intel.com>2015-08-18 11:30:25 -0400
committerDarren Hart <dvhart@linux.intel.com>2015-08-26 03:21:27 -0400
commit2508a45a924dfa4a5f6e60675aa4732d888134a7 (patch)
tree94cf10510ec0c70de7b42fea8d0fd2ab0ecc8f2f
parentfc0bfacd045a17e385b4272dfe2387ba3a6d8745 (diff)
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 Tested-by: Ethan Schoonover <es@ethanschoonover.com> Tested-by: Peter Amidon <psa.pub.0@picnicpark.org> Tested-by: Donavan Lance <tusklahoma@gmail.com> Tested-by: Stephen Just <stephenjust@gmail.com> Signed-off-by: Chen Yu <yu.c.chen@intel.com> [dvhart@linux.intel.com: Formatting corrections in MAINTAINERS and Intel (c)] Signed-off-by: Darren Hart <dvhart@linux.intel.com>
-rw-r--r--MAINTAINERS6
-rw-r--r--drivers/platform/x86/Kconfig5
-rw-r--r--drivers/platform/x86/Makefile1
-rw-r--r--drivers/platform/x86/surfacepro3_button.c216
4 files changed, 228 insertions, 0 deletions
diff --git a/MAINTAINERS b/MAINTAINERS
index cbeb4c145d8f..884d39816286 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6709,6 +6709,12 @@ T: git git://git.monstr.eu/linux-2.6-microblaze.git
6709S: Supported 6709S: Supported
6710F: arch/microblaze/ 6710F: arch/microblaze/
6711 6711
6712MICROSOFT SURFACE PRO 3 BUTTON DRIVER
6713M: Chen Yu <yu.c.chen@intel.com>
6714L: platform-driver-x86@vger.kernel.org
6715S: Supported
6716F: drivers/platform/x86/surfacepro3_button.c
6717
6712MICROTEK X6 SCANNER 6718MICROTEK X6 SCANNER
6713M: Oliver Neukum <oliver@neukum.org> 6719M: Oliver Neukum <oliver@neukum.org>
6714S: Maintained 6720S: Maintained
diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 6dc13e4de396..c69bb703f483 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -919,4 +919,9 @@ config INTEL_PMC_IPC
919 The PMC is an ARC processor which defines IPC commands for communication 919 The PMC is an ARC processor which defines IPC commands for communication
920 with other entities in the CPU. 920 with other entities in the CPU.
921 921
922config SURFACE_PRO3_BUTTON
923 tristate "Power/home/volume buttons driver for Microsoft Surface Pro 3 tablet"
924 depends on ACPI && INPUT
925 ---help---
926 This driver handles the power/home/volume buttons on the Microsoft Surface Pro 3 tablet.
922endif # X86_PLATFORM_DEVICES 927endif # X86_PLATFORM_DEVICES
diff --git a/drivers/platform/x86/Makefile b/drivers/platform/x86/Makefile
index dda95a985321..ada512819028 100644
--- a/drivers/platform/x86/Makefile
+++ b/drivers/platform/x86/Makefile
@@ -60,3 +60,4 @@ obj-$(CONFIG_INTEL_SMARTCONNECT) += intel-smartconnect.o
60obj-$(CONFIG_PVPANIC) += pvpanic.o 60obj-$(CONFIG_PVPANIC) += pvpanic.o
61obj-$(CONFIG_ALIENWARE_WMI) += alienware-wmi.o 61obj-$(CONFIG_ALIENWARE_WMI) += alienware-wmi.o
62obj-$(CONFIG_INTEL_PMC_IPC) += intel_pmc_ipc.o 62obj-$(CONFIG_INTEL_PMC_IPC) += intel_pmc_ipc.o
63obj-$(CONFIG_SURFACE_PRO3_BUTTON) += surfacepro3_button.o
diff --git a/drivers/platform/x86/surfacepro3_button.c b/drivers/platform/x86/surfacepro3_button.c
new file mode 100644
index 000000000000..f7dade3fd2ab
--- /dev/null
+++ b/drivers/platform/x86/surfacepro3_button.c
@@ -0,0 +1,216 @@
1/*
2 * power/home/volume button support for
3 * Microsoft Surface Pro 3 tablet.
4 *
5 * Copyright (c) 2015 Intel Corporation.
6 * All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; version 2
11 * of the License.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/types.h>
18#include <linux/input.h>
19#include <linux/acpi.h>
20#include <acpi/button.h>
21
22#define SURFACE_BUTTON_HID "MSHW0028"
23#define SURFACE_BUTTON_OBJ_NAME "VGBI"
24#define SURFACE_BUTTON_DEVICE_NAME "Surface Pro 3 Buttons"
25
26#define SURFACE_BUTTON_NOTIFY_PRESS_POWER 0xc6
27#define SURFACE_BUTTON_NOTIFY_RELEASE_POWER 0xc7
28
29#define SURFACE_BUTTON_NOTIFY_PRESS_HOME 0xc4
30#define SURFACE_BUTTON_NOTIFY_RELEASE_HOME 0xc5
31
32#define SURFACE_BUTTON_NOTIFY_PRESS_VOLUME_UP 0xc0
33#define SURFACE_BUTTON_NOTIFY_RELEASE_VOLUME_UP 0xc1
34
35#define SURFACE_BUTTON_NOTIFY_PRESS_VOLUME_DOWN 0xc2
36#define SURFACE_BUTTON_NOTIFY_RELEASE_VOLUME_DOWN 0xc3
37
38ACPI_MODULE_NAME("surface pro 3 button");
39
40MODULE_AUTHOR("Chen Yu");
41MODULE_DESCRIPTION("Surface Pro3 Button Driver");
42MODULE_LICENSE("GPL v2");
43
44/*
45 * Power button, Home button, Volume buttons support is supposed to
46 * be covered by drivers/input/misc/soc_button_array.c, which is implemented
47 * according to "Windows ACPI Design Guide for SoC Platforms".
48 * However surface pro3 seems not to obey the specs, instead it uses
49 * device VGBI(MSHW0028) for dispatching the events.
50 * We choose acpi_driver rather than platform_driver/i2c_driver because
51 * although VGBI has an i2c resource connected to i2c controller, it
52 * is not embedded in any i2c controller's scope, thus neither platform_device
53 * will be created, nor i2c_client will be enumerated, we have to use
54 * acpi_driver.
55 */
56static const struct acpi_device_id surface_button_device_ids[] = {
57 {SURFACE_BUTTON_HID, 0},
58 {"", 0},
59};
60MODULE_DEVICE_TABLE(acpi, surface_button_device_ids);
61
62struct surface_button {
63 unsigned int type;
64 struct input_dev *input;
65 char phys[32]; /* for input device */
66 unsigned long pushed;
67 bool suspended;
68};
69
70static void surface_button_notify(struct acpi_device *device, u32 event)
71{
72 struct surface_button *button = acpi_driver_data(device);
73 struct input_dev *input;
74 int key_code = KEY_RESERVED;
75 bool pressed = false;
76
77 switch (event) {
78 /* Power button press,release handle */
79 case SURFACE_BUTTON_NOTIFY_PRESS_POWER:
80 pressed = true;
81 /*fall through*/
82 case SURFACE_BUTTON_NOTIFY_RELEASE_POWER:
83 key_code = KEY_POWER;
84 break;
85 /* Home button press,release handle */
86 case SURFACE_BUTTON_NOTIFY_PRESS_HOME:
87 pressed = true;
88 /*fall through*/
89 case SURFACE_BUTTON_NOTIFY_RELEASE_HOME:
90 key_code = KEY_LEFTMETA;
91 break;
92 /* Volume up button press,release handle */
93 case SURFACE_BUTTON_NOTIFY_PRESS_VOLUME_UP:
94 pressed = true;
95 /*fall through*/
96 case SURFACE_BUTTON_NOTIFY_RELEASE_VOLUME_UP:
97 key_code = KEY_VOLUMEUP;
98 break;
99 /* Volume down button press,release handle */
100 case SURFACE_BUTTON_NOTIFY_PRESS_VOLUME_DOWN:
101 pressed = true;
102 /*fall through*/
103 case SURFACE_BUTTON_NOTIFY_RELEASE_VOLUME_DOWN:
104 key_code = KEY_VOLUMEDOWN;
105 break;
106 default:
107 dev_info_ratelimited(&device->dev,
108 "Unsupported event [0x%x]\n", event);
109 break;
110 }
111 input = button->input;
112 if (KEY_RESERVED == key_code)
113 return;
114 if (pressed)
115 pm_wakeup_event(&device->dev, 0);
116 if (button->suspended)
117 return;
118 input_report_key(input, key_code, pressed?1:0);
119 input_sync(input);
120}
121
122#ifdef CONFIG_PM_SLEEP
123static int surface_button_suspend(struct device *dev)
124{
125 struct acpi_device *device = to_acpi_device(dev);
126 struct surface_button *button = acpi_driver_data(device);
127
128 button->suspended = true;
129 return 0;
130}
131
132static int surface_button_resume(struct device *dev)
133{
134 struct acpi_device *device = to_acpi_device(dev);
135 struct surface_button *button = acpi_driver_data(device);
136
137 button->suspended = false;
138 return 0;
139}
140#endif
141
142static int surface_button_add(struct acpi_device *device)
143{
144 struct surface_button *button;
145 struct input_dev *input;
146 const char *hid = acpi_device_hid(device);
147 char *name;
148 int error;
149
150 if (strncmp(acpi_device_bid(device), SURFACE_BUTTON_OBJ_NAME,
151 strlen(SURFACE_BUTTON_OBJ_NAME)))
152 return -ENODEV;
153
154 button = kzalloc(sizeof(struct surface_button), GFP_KERNEL);
155 if (!button)
156 return -ENOMEM;
157
158 device->driver_data = button;
159 button->input = input = input_allocate_device();
160 if (!input) {
161 error = -ENOMEM;
162 goto err_free_button;
163 }
164
165 name = acpi_device_name(device);
166 strcpy(name, SURFACE_BUTTON_DEVICE_NAME);
167 snprintf(button->phys, sizeof(button->phys), "%s/buttons", hid);
168
169 input->name = name;
170 input->phys = button->phys;
171 input->id.bustype = BUS_HOST;
172 input->dev.parent = &device->dev;
173 input_set_capability(input, EV_KEY, KEY_POWER);
174 input_set_capability(input, EV_KEY, KEY_LEFTMETA);
175 input_set_capability(input, EV_KEY, KEY_VOLUMEUP);
176 input_set_capability(input, EV_KEY, KEY_VOLUMEDOWN);
177
178 error = input_register_device(input);
179 if (error)
180 goto err_free_input;
181 dev_info(&device->dev,
182 "%s [%s]\n", name, acpi_device_bid(device));
183 return 0;
184
185 err_free_input:
186 input_free_device(input);
187 err_free_button:
188 kfree(button);
189 return error;
190}
191
192static int surface_button_remove(struct acpi_device *device)
193{
194 struct surface_button *button = acpi_driver_data(device);
195
196 input_unregister_device(button->input);
197 kfree(button);
198 return 0;
199}
200
201static SIMPLE_DEV_PM_OPS(surface_button_pm,
202 surface_button_suspend, surface_button_resume);
203
204static struct acpi_driver surface_button_driver = {
205 .name = "surface_pro3_button",
206 .class = "SurfacePro3",
207 .ids = surface_button_device_ids,
208 .ops = {
209 .add = surface_button_add,
210 .remove = surface_button_remove,
211 .notify = surface_button_notify,
212 },
213 .drv.pm = &surface_button_pm,
214};
215
216module_acpi_driver(surface_button_driver);