blob: 5db9efbde5b9332e127893f099b9ff0f491c1808 [file] [log] [blame]
Matthew Garrett0b3f6102009-01-09 20:17:11 +00001/*
2 * Dell WMI hotkeys
3 *
4 * Copyright (C) 2008 Red Hat <mjg@redhat.com>
Pali Rohár595773a42016-01-04 22:26:35 +01005 * Copyright (C) 2014-2015 Pali Rohár <pali.rohar@gmail.com>
Matthew Garrett0b3f6102009-01-09 20:17:11 +00006 *
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
Joe Percheseb889522011-03-29 15:21:37 -070027#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
Matthew Garrett0b3f6102009-01-09 20:17:11 +000029#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/init.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Matthew Garrett0b3f6102009-01-09 20:17:11 +000033#include <linux/types.h>
34#include <linux/input.h>
Dmitry Torokhov890a7c82010-08-04 22:30:08 -070035#include <linux/input/sparse-keymap.h>
Matthew Garrett0b3f6102009-01-09 20:17:11 +000036#include <linux/acpi.h>
37#include <linux/string.h>
Rezwanul Kabir5ea25592009-11-02 12:00:42 -050038#include <linux/dmi.h>
Hans de Goede18bd7692015-06-16 16:28:01 +020039#include <acpi/video.h>
Matthew Garrett0b3f6102009-01-09 20:17:11 +000040
41MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
Pali Rohár595773a42016-01-04 22:26:35 +010042MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
Matthew Garrett0b3f6102009-01-09 20:17:11 +000043MODULE_DESCRIPTION("Dell laptop WMI hotkeys driver");
44MODULE_LICENSE("GPL");
45
46#define DELL_EVENT_GUID "9DBB5994-A997-11DA-B012-B622A1EF5492"
Pali Rohár595773a42016-01-04 22:26:35 +010047#define DELL_DESCRIPTOR_GUID "8D9DDCBC-A997-11DA-B012-B622A1EF5492"
Matthew Garrett0b3f6102009-01-09 20:17:11 +000048
Rezwanul Kabir5ea25592009-11-02 12:00:42 -050049static int acpi_video;
Pali Rohár595773a42016-01-04 22:26:35 +010050static u32 dell_wmi_interface_version;
Rezwanul Kabir5ea25592009-11-02 12:00:42 -050051
Matthew Garrett0b3f6102009-01-09 20:17:11 +000052MODULE_ALIAS("wmi:"DELL_EVENT_GUID);
Pali Rohár595773a42016-01-04 22:26:35 +010053MODULE_ALIAS("wmi:"DELL_DESCRIPTOR_GUID);
Matthew Garrett0b3f6102009-01-09 20:17:11 +000054
Mario Limonciello5cab0092009-06-10 19:40:47 +000055/*
56 * Certain keys are flagged as KE_IGNORE. All of these are either
57 * notifications (rather than requests for change) or are also sent
58 * via the keyboard controller so should not be sent again.
59 */
Matthew Garrett0b3f6102009-01-09 20:17:11 +000060
Dmitry Torokhov890a7c82010-08-04 22:30:08 -070061static const struct key_entry dell_wmi_legacy_keymap[] __initconst = {
Seth Forsheef1566f02011-08-01 15:46:10 -050062 { KE_IGNORE, 0x003a, { KEY_CAPSLOCK } },
63
Dmitry Torokhov890a7c82010-08-04 22:30:08 -070064 { KE_KEY, 0xe045, { KEY_PROG1 } },
65 { KE_KEY, 0xe009, { KEY_EJECTCD } },
Mario Limonciello5cab0092009-06-10 19:40:47 +000066
67 /* These also contain the brightness level at offset 6 */
Dmitry Torokhov890a7c82010-08-04 22:30:08 -070068 { KE_KEY, 0xe006, { KEY_BRIGHTNESSUP } },
69 { KE_KEY, 0xe005, { KEY_BRIGHTNESSDOWN } },
Mario Limonciello5cab0092009-06-10 19:40:47 +000070
71 /* Battery health status button */
Dmitry Torokhov890a7c82010-08-04 22:30:08 -070072 { KE_KEY, 0xe007, { KEY_BATTERY } },
Mario Limonciello5cab0092009-06-10 19:40:47 +000073
Gabriele Mazzotta8f8d75e2014-12-04 00:16:21 +010074 /* Radio devices state change */
75 { KE_IGNORE, 0xe008, { KEY_RFKILL } },
Mario Limonciello5cab0092009-06-10 19:40:47 +000076
77 /* The next device is at offset 6, the active devices are at
78 offset 8 and the attached devices at offset 10 */
Dmitry Torokhov890a7c82010-08-04 22:30:08 -070079 { KE_KEY, 0xe00b, { KEY_SWITCHVIDEOMODE } },
Mario Limonciello5cab0092009-06-10 19:40:47 +000080
Dmitry Torokhov890a7c82010-08-04 22:30:08 -070081 { KE_IGNORE, 0xe00c, { KEY_KBDILLUMTOGGLE } },
Mario Limonciello5cab0092009-06-10 19:40:47 +000082
83 /* BIOS error detected */
Dmitry Torokhov890a7c82010-08-04 22:30:08 -070084 { KE_IGNORE, 0xe00d, { KEY_RESERVED } },
Mario Limonciello5cab0092009-06-10 19:40:47 +000085
86 /* Wifi Catcher */
Dmitry Torokhov890a7c82010-08-04 22:30:08 -070087 { KE_KEY, 0xe011, {KEY_PROG2 } },
Mario Limonciello5cab0092009-06-10 19:40:47 +000088
89 /* Ambient light sensor toggle */
Dmitry Torokhov890a7c82010-08-04 22:30:08 -070090 { KE_IGNORE, 0xe013, { KEY_RESERVED } },
Mario Limonciello5cab0092009-06-10 19:40:47 +000091
Dmitry Torokhov890a7c82010-08-04 22:30:08 -070092 { KE_IGNORE, 0xe020, { KEY_MUTE } },
Seth Forsheef1566f02011-08-01 15:46:10 -050093
94 /* Shortcut and audio panel keys */
95 { KE_IGNORE, 0xe025, { KEY_RESERVED } },
96 { KE_IGNORE, 0xe026, { KEY_RESERVED } },
97
Dmitry Torokhov890a7c82010-08-04 22:30:08 -070098 { KE_IGNORE, 0xe02e, { KEY_VOLUMEDOWN } },
99 { KE_IGNORE, 0xe030, { KEY_VOLUMEUP } },
100 { KE_IGNORE, 0xe033, { KEY_KBDILLUMUP } },
101 { KE_IGNORE, 0xe034, { KEY_KBDILLUMDOWN } },
102 { KE_IGNORE, 0xe03a, { KEY_CAPSLOCK } },
103 { KE_IGNORE, 0xe045, { KEY_NUMLOCK } },
104 { KE_IGNORE, 0xe046, { KEY_SCROLLLOCK } },
Seth Forsheef1566f02011-08-01 15:46:10 -0500105 { KE_IGNORE, 0xe0f7, { KEY_MUTE } },
106 { KE_IGNORE, 0xe0f8, { KEY_VOLUMEDOWN } },
107 { KE_IGNORE, 0xe0f9, { KEY_VOLUMEUP } },
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700108 { KE_END, 0 }
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000109};
110
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500111static bool dell_new_hk_type;
112
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700113struct dell_bios_keymap_entry {
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500114 u16 scancode;
115 u16 keycode;
116};
117
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700118struct dell_bios_hotkey_table {
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500119 struct dmi_header header;
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700120 struct dell_bios_keymap_entry keymap[];
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500121
122};
123
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700124static const struct dell_bios_hotkey_table *dell_bios_hotkey_table;
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500125
Andy Lutomirskicbc61f12015-11-30 17:02:01 -0800126/* Uninitialized entries here are KEY_RESERVED == 0. */
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700127static const u16 bios_to_linux_keycode[256] __initconst = {
Andy Lutomirski394cb772015-11-13 21:49:31 -0800128 [0] = KEY_MEDIA,
129 [1] = KEY_NEXTSONG,
130 [2] = KEY_PLAYPAUSE,
131 [3] = KEY_PREVIOUSSONG,
132 [4] = KEY_STOPCD,
133 [5] = KEY_UNKNOWN,
134 [6] = KEY_UNKNOWN,
135 [7] = KEY_UNKNOWN,
136 [8] = KEY_WWW,
137 [9] = KEY_UNKNOWN,
138 [10] = KEY_VOLUMEDOWN,
139 [11] = KEY_MUTE,
140 [12] = KEY_VOLUMEUP,
141 [13] = KEY_UNKNOWN,
142 [14] = KEY_BATTERY,
143 [15] = KEY_EJECTCD,
144 [16] = KEY_UNKNOWN,
145 [17] = KEY_SLEEP,
146 [18] = KEY_PROG1,
147 [19] = KEY_BRIGHTNESSDOWN,
148 [20] = KEY_BRIGHTNESSUP,
149 [21] = KEY_UNKNOWN,
150 [22] = KEY_KBDILLUMTOGGLE,
151 [23] = KEY_UNKNOWN,
152 [24] = KEY_SWITCHVIDEOMODE,
153 [25] = KEY_UNKNOWN,
154 [26] = KEY_UNKNOWN,
155 [27] = KEY_SWITCHVIDEOMODE,
156 [28] = KEY_UNKNOWN,
157 [29] = KEY_UNKNOWN,
158 [30] = KEY_PROG2,
159 [31] = KEY_UNKNOWN,
160 [32] = KEY_UNKNOWN,
161 [33] = KEY_UNKNOWN,
162 [34] = KEY_UNKNOWN,
163 [35] = KEY_UNKNOWN,
164 [36] = KEY_UNKNOWN,
165 [37] = KEY_UNKNOWN,
166 [38] = KEY_MICMUTE,
167 [255] = KEY_PROG3,
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500168};
169
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000170static struct input_dev *dell_wmi_input_dev;
171
Pali Rohár83fc44c2014-11-11 20:21:22 +0100172static void dell_wmi_process_key(int reported_key)
173{
174 const struct key_entry *key;
175
176 key = sparse_keymap_entry_from_scancode(dell_wmi_input_dev,
177 reported_key);
178 if (!key) {
Andy Lutomirskicbc61f12015-11-30 17:02:01 -0800179 pr_info("Unknown key with scancode 0x%x pressed\n",
180 reported_key);
Pali Rohár83fc44c2014-11-11 20:21:22 +0100181 return;
182 }
183
184 pr_debug("Key %x pressed\n", reported_key);
185
186 /* Don't report brightness notifications that will also come via ACPI */
187 if ((key->keycode == KEY_BRIGHTNESSUP ||
188 key->keycode == KEY_BRIGHTNESSDOWN) && acpi_video)
189 return;
190
191 sparse_keymap_report_entry(dell_wmi_input_dev, key, 1, true);
192}
193
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000194static void dell_wmi_notify(u32 value, void *context)
195{
196 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000197 union acpi_object *obj;
Len Brownfda11e62009-12-26 23:02:24 -0500198 acpi_status status;
Pali Rohár83fc44c2014-11-11 20:21:22 +0100199 acpi_size buffer_size;
200 u16 *buffer_entry, *buffer_end;
201 int len, i;
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000202
Len Brownfda11e62009-12-26 23:02:24 -0500203 status = wmi_get_event_data(value, &response);
204 if (status != AE_OK) {
Pali Rohár83fc44c2014-11-11 20:21:22 +0100205 pr_warn("bad event status 0x%x\n", status);
Len Brownfda11e62009-12-26 23:02:24 -0500206 return;
207 }
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000208
209 obj = (union acpi_object *)response.pointer;
Pali Rohár83fc44c2014-11-11 20:21:22 +0100210 if (!obj) {
211 pr_warn("no response\n");
212 return;
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000213 }
Pali Rohár83fc44c2014-11-11 20:21:22 +0100214
215 if (obj->type != ACPI_TYPE_BUFFER) {
216 pr_warn("bad response type %x\n", obj->type);
217 kfree(obj);
218 return;
219 }
220
221 pr_debug("Received WMI event (%*ph)\n",
222 obj->buffer.length, obj->buffer.pointer);
223
224 buffer_entry = (u16 *)obj->buffer.pointer;
225 buffer_size = obj->buffer.length/2;
226
227 if (!dell_new_hk_type) {
228 if (buffer_size >= 3 && buffer_entry[1] == 0x0)
229 dell_wmi_process_key(buffer_entry[2]);
230 else if (buffer_size >= 2)
231 dell_wmi_process_key(buffer_entry[1]);
232 else
233 pr_info("Received unknown WMI event\n");
234 kfree(obj);
235 return;
236 }
237
238 buffer_end = buffer_entry + buffer_size;
239
Pali Rohár481fe5b2016-01-04 22:26:36 +0100240 /*
241 * BIOS/ACPI on devices with WMI interface version 0 does not clear
242 * buffer before filling it. So next time when BIOS/ACPI send WMI event
243 * which is smaller as previous then it contains garbage in buffer from
244 * previous event.
245 *
246 * BIOS/ACPI on devices with WMI interface version 1 clears buffer and
247 * sometimes send more events in buffer at one call.
248 *
249 * So to prevent reading garbage from buffer we will process only first
250 * one event on devices with WMI interface version 0.
251 */
252 if (dell_wmi_interface_version == 0 && buffer_entry < buffer_end)
253 if (buffer_end > buffer_entry + buffer_entry[0] + 1)
254 buffer_end = buffer_entry + buffer_entry[0] + 1;
255
Pali Rohár83fc44c2014-11-11 20:21:22 +0100256 while (buffer_entry < buffer_end) {
257
258 len = buffer_entry[0];
259 if (len == 0)
260 break;
261
262 len++;
263
264 if (buffer_entry + len > buffer_end) {
265 pr_warn("Invalid length of WMI event\n");
266 break;
267 }
268
269 pr_debug("Process buffer (%*ph)\n", len*2, buffer_entry);
270
271 switch (buffer_entry[1]) {
272 case 0x00:
273 for (i = 2; i < len; ++i) {
274 switch (buffer_entry[i]) {
275 case 0xe043:
276 /* NIC Link is Up */
277 pr_debug("NIC Link is Up\n");
278 break;
279 case 0xe044:
280 /* NIC Link is Down */
281 pr_debug("NIC Link is Down\n");
282 break;
283 case 0xe045:
284 /* Unknown event but defined in DSDT */
285 default:
286 /* Unknown event */
287 pr_info("Unknown WMI event type 0x00: "
288 "0x%x\n", (int)buffer_entry[i]);
289 break;
290 }
291 }
292 break;
293 case 0x10:
294 /* Keys pressed */
295 for (i = 2; i < len; ++i)
296 dell_wmi_process_key(buffer_entry[i]);
297 break;
298 case 0x11:
299 for (i = 2; i < len; ++i) {
300 switch (buffer_entry[i]) {
301 case 0xfff0:
302 /* Battery unplugged */
303 pr_debug("Battery unplugged\n");
304 break;
305 case 0xfff1:
306 /* Battery inserted */
307 pr_debug("Battery inserted\n");
308 break;
309 case 0x01e1:
310 case 0x02ea:
311 case 0x02eb:
312 case 0x02ec:
313 case 0x02f6:
314 /* Keyboard backlight level changed */
315 pr_debug("Keyboard backlight level "
316 "changed\n");
317 break;
318 default:
319 /* Unknown event */
320 pr_info("Unknown WMI event type 0x11: "
321 "0x%x\n", (int)buffer_entry[i]);
322 break;
323 }
324 }
325 break;
326 default:
327 /* Unknown event */
328 pr_info("Unknown WMI event type 0x%x\n",
329 (int)buffer_entry[1]);
330 break;
331 }
332
333 buffer_entry += len;
334
335 }
336
Anisse Astier3e9b9882009-12-04 10:10:09 +0100337 kfree(obj);
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000338}
339
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700340static const struct key_entry * __init dell_wmi_prepare_new_keymap(void)
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500341{
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700342 int hotkey_num = (dell_bios_hotkey_table->header.length - 4) /
343 sizeof(struct dell_bios_keymap_entry);
344 struct key_entry *keymap;
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500345 int i;
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500346
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700347 keymap = kcalloc(hotkey_num + 1, sizeof(struct key_entry), GFP_KERNEL);
348 if (!keymap)
349 return NULL;
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500350
351 for (i = 0; i < hotkey_num; i++) {
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700352 const struct dell_bios_keymap_entry *bios_entry =
353 &dell_bios_hotkey_table->keymap[i];
Andy Lutomirskicbc61f12015-11-30 17:02:01 -0800354
355 /* Uninitialized entries are 0 aka KEY_RESERVED. */
356 u16 keycode = (bios_entry->keycode <
357 ARRAY_SIZE(bios_to_linux_keycode)) ?
358 bios_to_linux_keycode[bios_entry->keycode] :
359 KEY_RESERVED;
360
361 /*
362 * Log if we find an entry in the DMI table that we don't
363 * understand. If this happens, we should figure out what
364 * the entry means and add it to bios_to_linux_keycode.
365 */
366 if (keycode == KEY_RESERVED) {
367 pr_info("firmware scancode 0x%x maps to unrecognized keycode 0x%x\n",
368 bios_entry->scancode, bios_entry->keycode);
369 continue;
370 }
Gabriele Mazzotta8cb8e632014-12-04 00:16:23 +0100371
372 if (keycode == KEY_KBDILLUMTOGGLE)
373 keymap[i].type = KE_IGNORE;
374 else
375 keymap[i].type = KE_KEY;
376 keymap[i].code = bios_entry->scancode;
377 keymap[i].keycode = keycode;
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500378 }
379
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700380 keymap[hotkey_num].type = KE_END;
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500381
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700382 return keymap;
Rezwanul Kabir5ea25592009-11-02 12:00:42 -0500383}
384
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000385static int __init dell_wmi_input_setup(void)
386{
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000387 int err;
388
389 dell_wmi_input_dev = input_allocate_device();
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000390 if (!dell_wmi_input_dev)
391 return -ENOMEM;
392
393 dell_wmi_input_dev->name = "Dell WMI hotkeys";
394 dell_wmi_input_dev->phys = "wmi/input0";
395 dell_wmi_input_dev->id.bustype = BUS_HOST;
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000396
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700397 if (dell_new_hk_type) {
398 const struct key_entry *keymap = dell_wmi_prepare_new_keymap();
399 if (!keymap) {
400 err = -ENOMEM;
401 goto err_free_dev;
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000402 }
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700403
404 err = sparse_keymap_setup(dell_wmi_input_dev, keymap, NULL);
405
406 /*
407 * Sparse keymap library makes a copy of keymap so we
408 * don't need the original one that was allocated.
409 */
410 kfree(keymap);
411 } else {
412 err = sparse_keymap_setup(dell_wmi_input_dev,
413 dell_wmi_legacy_keymap, NULL);
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000414 }
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700415 if (err)
416 goto err_free_dev;
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000417
418 err = input_register_device(dell_wmi_input_dev);
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700419 if (err)
420 goto err_free_keymap;
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000421
422 return 0;
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700423
424 err_free_keymap:
425 sparse_keymap_free(dell_wmi_input_dev);
426 err_free_dev:
427 input_free_device(dell_wmi_input_dev);
428 return err;
429}
430
431static void dell_wmi_input_destroy(void)
432{
433 sparse_keymap_free(dell_wmi_input_dev);
434 input_unregister_device(dell_wmi_input_dev);
435}
436
437static void __init find_hk_type(const struct dmi_header *dm, void *dummy)
438{
439 if (dm->type == 0xb2 && dm->length > 6) {
440 dell_new_hk_type = true;
441 dell_bios_hotkey_table =
442 container_of(dm, struct dell_bios_hotkey_table, header);
443 }
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000444}
445
Pali Rohár595773a42016-01-04 22:26:35 +0100446/*
447 * Descriptor buffer is 128 byte long and contains:
448 *
449 * Name Offset Length Value
450 * Vendor Signature 0 4 "DELL"
451 * Object Signature 4 4 " WMI"
452 * WMI Interface Version 8 4 <version>
453 * WMI buffer length 12 4 4096
454 */
455static int __init dell_wmi_check_descriptor_buffer(void)
456{
457 struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
458 union acpi_object *obj;
459 acpi_status status;
460 u32 *buffer;
461
462 status = wmi_query_block(DELL_DESCRIPTOR_GUID, 0, &out);
463 if (ACPI_FAILURE(status)) {
464 pr_err("Cannot read Dell descriptor buffer - %d\n", status);
465 return status;
466 }
467
468 obj = (union acpi_object *)out.pointer;
469 if (!obj) {
470 pr_err("Dell descriptor buffer is empty\n");
471 return -EINVAL;
472 }
473
474 if (obj->type != ACPI_TYPE_BUFFER) {
475 pr_err("Cannot read Dell descriptor buffer\n");
476 kfree(obj);
477 return -EINVAL;
478 }
479
480 if (obj->buffer.length != 128) {
481 pr_err("Dell descriptor buffer has invalid length (%d)\n",
482 obj->buffer.length);
483 if (obj->buffer.length < 16) {
484 kfree(obj);
485 return -EINVAL;
486 }
487 }
488
489 buffer = (u32 *)obj->buffer.pointer;
490
491 if (buffer[0] != 0x4C4C4544 && buffer[1] != 0x494D5720)
492 pr_warn("Dell descriptor buffer has invalid signature (%*ph)\n",
493 8, buffer);
494
495 if (buffer[2] != 0 && buffer[2] != 1)
496 pr_warn("Dell descriptor buffer has unknown version (%d)\n",
497 buffer[2]);
498
499 if (buffer[3] != 4096)
500 pr_warn("Dell descriptor buffer has invalid buffer length (%d)\n",
501 buffer[3]);
502
503 dell_wmi_interface_version = buffer[2];
504
505 pr_info("Detected Dell WMI interface version %u\n",
506 dell_wmi_interface_version);
507
508 kfree(obj);
509 return 0;
510}
511
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000512static int __init dell_wmi_init(void)
513{
514 int err;
Len Brownabb631b2009-12-26 21:51:38 -0500515 acpi_status status;
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000516
Pali Rohár595773a42016-01-04 22:26:35 +0100517 if (!wmi_has_guid(DELL_EVENT_GUID) ||
518 !wmi_has_guid(DELL_DESCRIPTOR_GUID)) {
519 pr_warn("Dell WMI GUID were not found\n");
Dmitry Torokhov1fdd4072009-12-17 22:19:42 -0800520 return -ENODEV;
521 }
522
Pali Rohár595773a42016-01-04 22:26:35 +0100523 err = dell_wmi_check_descriptor_buffer();
524 if (err)
525 return err;
526
Dmitry Torokhov1fdd4072009-12-17 22:19:42 -0800527 dmi_walk(find_hk_type, NULL);
Hans de Goede18bd7692015-06-16 16:28:01 +0200528 acpi_video = acpi_video_get_backlight_type() != acpi_backlight_vendor;
Dmitry Torokhov1fdd4072009-12-17 22:19:42 -0800529
530 err = dell_wmi_input_setup();
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700531 if (err)
Dmitry Torokhov1fdd4072009-12-17 22:19:42 -0800532 return err;
533
Len Brownabb631b2009-12-26 21:51:38 -0500534 status = wmi_install_notify_handler(DELL_EVENT_GUID,
Dmitry Torokhov1fdd4072009-12-17 22:19:42 -0800535 dell_wmi_notify, NULL);
Len Brownabb631b2009-12-26 21:51:38 -0500536 if (ACPI_FAILURE(status)) {
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700537 dell_wmi_input_destroy();
Joe Percheseb889522011-03-29 15:21:37 -0700538 pr_err("Unable to register notify handler - %d\n", status);
Len Brownabb631b2009-12-26 21:51:38 -0500539 return -ENODEV;
Dmitry Torokhov1fdd4072009-12-17 22:19:42 -0800540 }
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000541
542 return 0;
543}
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700544module_init(dell_wmi_init);
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000545
546static void __exit dell_wmi_exit(void)
547{
Dmitry Torokhov1fdd4072009-12-17 22:19:42 -0800548 wmi_remove_notify_handler(DELL_EVENT_GUID);
Dmitry Torokhov890a7c82010-08-04 22:30:08 -0700549 dell_wmi_input_destroy();
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000550}
Matthew Garrett0b3f6102009-01-09 20:17:11 +0000551module_exit(dell_wmi_exit);