OSDN Git Service

eeepc-wmi: add extra keymaps for EP121
[android-x86/kernel.git] / drivers / platform / x86 / eeepc-wmi.c
1 /*
2  * Eee PC WMI hotkey driver
3  *
4  * Copyright(C) 2010 Intel Corporation.
5  * Copyright(C) 2010-2011 Corentin Chary <corentin.chary@gmail.com>
6  *
7  * Portions based on wistron_btns.c:
8  * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
9  * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
10  * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
11  *
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25  */
26
27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/input.h>
33 #include <linux/input/sparse-keymap.h>
34 #include <linux/dmi.h>
35 #include <acpi/acpi_bus.h>
36
37 #include "asus-wmi.h"
38
39 #define EEEPC_WMI_FILE  "eeepc-wmi"
40
41 MODULE_AUTHOR("Corentin Chary <corentincj@iksaif.net>");
42 MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver");
43 MODULE_LICENSE("GPL");
44
45 #define EEEPC_ACPI_HID          "ASUS010" /* old _HID used in eeepc-laptop */
46
47 #define EEEPC_WMI_EVENT_GUID    "ABBC0F72-8EA1-11D1-00A0-C90629100000"
48
49 MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID);
50
51 static bool hotplug_wireless;
52
53 module_param(hotplug_wireless, bool, 0444);
54 MODULE_PARM_DESC(hotplug_wireless,
55                  "Enable hotplug for wireless device. "
56                  "If your laptop needs that, please report to "
57                  "acpi4asus-user@lists.sourceforge.net.");
58
59 /* Values for T101MT "Home" key */
60 #define HOME_PRESS      0xe4
61 #define HOME_HOLD       0xea
62 #define HOME_RELEASE    0xe5
63
64 static const struct key_entry eeepc_wmi_keymap[] = {
65         /* Sleep already handled via generic ACPI code */
66         { KE_KEY, 0x30, { KEY_VOLUMEUP } },
67         { KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
68         { KE_KEY, 0x32, { KEY_MUTE } },
69         { KE_KEY, 0x5c, { KEY_F15 } }, /* Power Gear key */
70         { KE_KEY, 0x5d, { KEY_WLAN } },
71         { KE_KEY, 0x6b, { KEY_TOUCHPAD_TOGGLE } }, /* Toggle Touchpad */
72         { KE_KEY, 0x82, { KEY_CAMERA } },
73         { KE_KEY, 0x83, { KEY_CAMERA_ZOOMIN } },
74         { KE_KEY, 0x88, { KEY_WLAN } },
75         { KE_KEY, 0xbd, { KEY_CAMERA } },
76         { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
77         { KE_KEY, 0xe0, { KEY_PROG1 } }, /* Task Manager */
78         { KE_KEY, 0xe1, { KEY_F14 } }, /* Change Resolution */
79         { KE_KEY, HOME_PRESS, { KEY_CONFIG } }, /* Home/Express gate key */
80         { KE_KEY, 0xe8, { KEY_SCREENLOCK } },
81         { KE_KEY, 0xe9, { KEY_BRIGHTNESS_ZERO } },
82         { KE_KEY, 0xeb, { KEY_CAMERA_ZOOMOUT } },
83         { KE_KEY, 0xec, { KEY_CAMERA_UP } },
84         { KE_KEY, 0xed, { KEY_CAMERA_DOWN } },
85         { KE_KEY, 0xee, { KEY_CAMERA_LEFT } },
86         { KE_KEY, 0xef, { KEY_CAMERA_RIGHT } },
87         { KE_KEY, 0xf3, { KEY_MENU } },
88         { KE_KEY, 0xf5, { KEY_HOMEPAGE } },
89         { KE_KEY, 0xf6, { KEY_ESC } },
90         { KE_END, 0},
91 };
92
93 static void eeepc_wmi_key_filter(struct asus_wmi_driver *asus_wmi, int *code,
94                                  unsigned int *value, bool *autorelease)
95 {
96         switch (*code) {
97         case HOME_PRESS:
98                 *value = 1;
99                 *autorelease = 0;
100                 break;
101         case HOME_HOLD:
102                 *code = ASUS_WMI_KEY_IGNORE;
103                 break;
104         case HOME_RELEASE:
105                 *code = HOME_PRESS;
106                 *value = 0;
107                 *autorelease = 0;
108                 break;
109         }
110 }
111
112 static acpi_status eeepc_wmi_parse_device(acpi_handle handle, u32 level,
113                                                  void *context, void **retval)
114 {
115         pr_warn("Found legacy ATKD device (%s)\n", EEEPC_ACPI_HID);
116         *(bool *)context = true;
117         return AE_CTRL_TERMINATE;
118 }
119
120 static int eeepc_wmi_check_atkd(void)
121 {
122         acpi_status status;
123         bool found = false;
124
125         status = acpi_get_devices(EEEPC_ACPI_HID, eeepc_wmi_parse_device,
126                                   &found, NULL);
127
128         if (ACPI_FAILURE(status) || !found)
129                 return 0;
130         return -1;
131 }
132
133 static int eeepc_wmi_probe(struct platform_device *pdev)
134 {
135         if (eeepc_wmi_check_atkd()) {
136                 pr_warn("WMI device present, but legacy ATKD device is also "
137                         "present and enabled\n");
138                 pr_warn("You probably booted with acpi_osi=\"Linux\" or "
139                         "acpi_osi=\"!Windows 2009\"\n");
140                 pr_warn("Can't load eeepc-wmi, use default acpi_osi "
141                         "(preferred) or eeepc-laptop\n");
142                 return -EBUSY;
143         }
144         return 0;
145 }
146
147 static void eeepc_dmi_check(struct asus_wmi_driver *driver)
148 {
149         const char *model;
150
151         model = dmi_get_system_info(DMI_PRODUCT_NAME);
152         if (!model)
153                 return;
154
155         /*
156          * Whitelist for wlan hotplug
157          *
158          * Asus 1000H needs the current hotplug code to handle
159          * Fn+F2 correctly. We may add other Asus here later, but
160          * it seems that most of the laptops supported by asus-wmi
161          * don't need to be on this list
162          */
163         if (strcmp(model, "1000H") == 0) {
164                 driver->hotplug_wireless = true;
165                 pr_info("wlan hotplug enabled\n");
166         }
167 }
168
169 static void eeepc_wmi_quirks(struct asus_wmi_driver *driver)
170 {
171         driver->hotplug_wireless = hotplug_wireless;
172         driver->wapf = -1;
173         eeepc_dmi_check(driver);
174 }
175
176 static struct asus_wmi_driver asus_wmi_driver = {
177         .name = EEEPC_WMI_FILE,
178         .owner = THIS_MODULE,
179         .event_guid = EEEPC_WMI_EVENT_GUID,
180         .keymap = eeepc_wmi_keymap,
181         .input_name = "Eee PC WMI hotkeys",
182         .input_phys = EEEPC_WMI_FILE "/input0",
183         .key_filter = eeepc_wmi_key_filter,
184         .probe = eeepc_wmi_probe,
185         .quirks = eeepc_wmi_quirks,
186 };
187
188
189 static int __init eeepc_wmi_init(void)
190 {
191         return asus_wmi_register_driver(&asus_wmi_driver);
192 }
193
194 static void __exit eeepc_wmi_exit(void)
195 {
196         asus_wmi_unregister_driver(&asus_wmi_driver);
197 }
198
199 module_init(eeepc_wmi_init);
200 module_exit(eeepc_wmi_exit);