]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/platform/x86/eeepc-wmi.c
asus-wmi: add scalar board brightness adj. support
[karo-tx-linux.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 struct quirk_entry *quirks;
52 static bool hotplug_wireless;
53
54 module_param(hotplug_wireless, bool, 0444);
55 MODULE_PARM_DESC(hotplug_wireless,
56                  "Enable hotplug for wireless device. "
57                  "If your laptop needs that, please report to "
58                  "acpi4asus-user@lists.sourceforge.net.");
59
60 /* Values for T101MT "Home" key */
61 #define HOME_PRESS      0xe4
62 #define HOME_HOLD       0xea
63 #define HOME_RELEASE    0xe5
64
65 static const struct key_entry eeepc_wmi_keymap[] = {
66         /* Sleep already handled via generic ACPI code */
67         { KE_KEY, 0x30, { KEY_VOLUMEUP } },
68         { KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
69         { KE_KEY, 0x32, { KEY_MUTE } },
70         { KE_KEY, 0x5c, { KEY_F15 } }, /* Power Gear key */
71         { KE_KEY, 0x5d, { KEY_WLAN } },
72         { KE_KEY, 0x6b, { KEY_TOUCHPAD_TOGGLE } }, /* Toggle Touchpad */
73         { KE_KEY, 0x82, { KEY_CAMERA } },
74         { KE_KEY, 0x83, { KEY_CAMERA_ZOOMIN } },
75         { KE_KEY, 0x88, { KEY_WLAN } },
76         { KE_KEY, 0xbd, { KEY_CAMERA } },
77         { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
78         { KE_KEY, 0xe0, { KEY_PROG1 } }, /* Task Manager */
79         { KE_KEY, 0xe1, { KEY_F14 } }, /* Change Resolution */
80         { KE_KEY, HOME_PRESS, { KEY_CONFIG } }, /* Home/Express gate key */
81         { KE_KEY, 0xe8, { KEY_SCREENLOCK } },
82         { KE_KEY, 0xe9, { KEY_BRIGHTNESS_ZERO } },
83         { KE_KEY, 0xeb, { KEY_CAMERA_ZOOMOUT } },
84         { KE_KEY, 0xec, { KEY_CAMERA_UP } },
85         { KE_KEY, 0xed, { KEY_CAMERA_DOWN } },
86         { KE_KEY, 0xee, { KEY_CAMERA_LEFT } },
87         { KE_KEY, 0xef, { KEY_CAMERA_RIGHT } },
88         { KE_KEY, 0xf3, { KEY_MENU } },
89         { KE_KEY, 0xf5, { KEY_HOMEPAGE } },
90         { KE_KEY, 0xf6, { KEY_ESC } },
91         { KE_END, 0},
92 };
93
94 static struct quirk_entry quirk_asus_unknown = {
95 };
96
97 static struct quirk_entry quirk_asus_1000h = {
98         .hotplug_wireless = true,
99 };
100
101 static struct quirk_entry quirk_asus_et2012_type3 = {
102         .scalar_panel_brightness = true,
103 };
104
105 static int dmi_matched(const struct dmi_system_id *dmi)
106 {
107         char *model;
108         quirks = dmi->driver_data;
109
110         model = (char *)dmi->matches[1].substr;
111         if (unlikely(strncmp(model, "ET2012", 6) == 0)) {
112                 const struct dmi_device *dev = NULL;
113                 char oemstring[30];
114                 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL,
115                                               dev))) {
116                         if (sscanf(dev->name, "AEMS%24c", oemstring) == 1) {
117                                 if (oemstring[18] == '3')
118                                         quirks = &quirk_asus_et2012_type3;
119                                 break;
120                         }
121                 }
122         }
123         return 1;
124 }
125
126 static struct dmi_system_id asus_quirks[] = {
127         {
128                 .callback = dmi_matched,
129                 .ident = "ASUSTeK Computer INC. 1000H",
130                 .matches = {
131                         DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
132                         DMI_MATCH(DMI_PRODUCT_NAME, "1000H"),
133                 },
134                 .driver_data = &quirk_asus_1000h,
135         },
136         {
137                 .callback = dmi_matched,
138                 .ident = "ASUSTeK Computer INC. ET2012E/I",
139                 .matches = {
140                         DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
141                         DMI_MATCH(DMI_PRODUCT_NAME, "ET2012"),
142                 },
143                 .driver_data = &quirk_asus_unknown,
144         },
145         {},
146 };
147
148 static void eeepc_wmi_key_filter(struct asus_wmi_driver *asus_wmi, int *code,
149                                  unsigned int *value, bool *autorelease)
150 {
151         switch (*code) {
152         case HOME_PRESS:
153                 *value = 1;
154                 *autorelease = 0;
155                 break;
156         case HOME_HOLD:
157                 *code = ASUS_WMI_KEY_IGNORE;
158                 break;
159         case HOME_RELEASE:
160                 *code = HOME_PRESS;
161                 *value = 0;
162                 *autorelease = 0;
163                 break;
164         }
165 }
166
167 static acpi_status eeepc_wmi_parse_device(acpi_handle handle, u32 level,
168                                                  void *context, void **retval)
169 {
170         pr_warn("Found legacy ATKD device (%s)\n", EEEPC_ACPI_HID);
171         *(bool *)context = true;
172         return AE_CTRL_TERMINATE;
173 }
174
175 static int eeepc_wmi_check_atkd(void)
176 {
177         acpi_status status;
178         bool found = false;
179
180         status = acpi_get_devices(EEEPC_ACPI_HID, eeepc_wmi_parse_device,
181                                   &found, NULL);
182
183         if (ACPI_FAILURE(status) || !found)
184                 return 0;
185         return -1;
186 }
187
188 static int eeepc_wmi_probe(struct platform_device *pdev)
189 {
190         if (eeepc_wmi_check_atkd()) {
191                 pr_warn("WMI device present, but legacy ATKD device is also "
192                         "present and enabled\n");
193                 pr_warn("You probably booted with acpi_osi=\"Linux\" or "
194                         "acpi_osi=\"!Windows 2009\"\n");
195                 pr_warn("Can't load eeepc-wmi, use default acpi_osi "
196                         "(preferred) or eeepc-laptop\n");
197                 return -EBUSY;
198         }
199         return 0;
200 }
201
202 static void eeepc_wmi_quirks(struct asus_wmi_driver *driver)
203 {
204         driver->wapf = -1;
205         driver->quirks = &quirk_asus_unknown;
206         driver->quirks->hotplug_wireless = hotplug_wireless;
207         dmi_check_system(asus_quirks);
208         driver->quirks = quirks;
209 }
210
211 static struct asus_wmi_driver asus_wmi_driver = {
212         .name = EEEPC_WMI_FILE,
213         .owner = THIS_MODULE,
214         .event_guid = EEEPC_WMI_EVENT_GUID,
215         .keymap = eeepc_wmi_keymap,
216         .input_name = "Eee PC WMI hotkeys",
217         .input_phys = EEEPC_WMI_FILE "/input0",
218         .key_filter = eeepc_wmi_key_filter,
219         .probe = eeepc_wmi_probe,
220         .detect_quirks = eeepc_wmi_quirks,
221 };
222
223
224 static int __init eeepc_wmi_init(void)
225 {
226         return asus_wmi_register_driver(&asus_wmi_driver);
227 }
228
229 static void __exit eeepc_wmi_exit(void)
230 {
231         asus_wmi_unregister_driver(&asus_wmi_driver);
232 }
233
234 module_init(eeepc_wmi_init);
235 module_exit(eeepc_wmi_exit);