Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / platform / x86 / dell-wmi.c
blobbbdb3e8608927d795c729b6f31995cb19981b297
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Dell WMI hotkeys
5 * Copyright (C) 2008 Red Hat <mjg@redhat.com>
6 * Copyright (C) 2014-2015 Pali Rohár <pali@kernel.org>
8 * Portions based on wistron_btns.c:
9 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
10 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
11 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/init.h>
19 #include <linux/slab.h>
20 #include <linux/types.h>
21 #include <linux/input.h>
22 #include <linux/input/sparse-keymap.h>
23 #include <linux/acpi.h>
24 #include <linux/string.h>
25 #include <linux/dmi.h>
26 #include <linux/wmi.h>
27 #include <acpi/video.h>
28 #include "dell-smbios.h"
29 #include "dell-wmi-descriptor.h"
31 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
32 MODULE_AUTHOR("Pali Rohár <pali@kernel.org>");
33 MODULE_DESCRIPTION("Dell laptop WMI hotkeys driver");
34 MODULE_LICENSE("GPL");
36 #define DELL_EVENT_GUID "9DBB5994-A997-11DA-B012-B622A1EF5492"
38 static bool wmi_requires_smbios_request;
40 struct dell_wmi_priv {
41 struct input_dev *input_dev;
42 u32 interface_version;
45 static int __init dmi_matched(const struct dmi_system_id *dmi)
47 wmi_requires_smbios_request = 1;
48 return 1;
51 static const struct dmi_system_id dell_wmi_smbios_list[] __initconst = {
53 .callback = dmi_matched,
54 .ident = "Dell Inspiron M5110",
55 .matches = {
56 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
57 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"),
61 .callback = dmi_matched,
62 .ident = "Dell Vostro V131",
63 .matches = {
64 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
65 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"),
68 { }
72 * Keymap for WMI events of type 0x0000
74 * Certain keys are flagged as KE_IGNORE. All of these are either
75 * notifications (rather than requests for change) or are also sent
76 * via the keyboard controller so should not be sent again.
78 static const struct key_entry dell_wmi_keymap_type_0000[] = {
79 { KE_IGNORE, 0x003a, { KEY_CAPSLOCK } },
81 /* Key code is followed by brightness level */
82 { KE_KEY, 0xe005, { KEY_BRIGHTNESSDOWN } },
83 { KE_KEY, 0xe006, { KEY_BRIGHTNESSUP } },
85 /* Battery health status button */
86 { KE_KEY, 0xe007, { KEY_BATTERY } },
88 /* Radio devices state change, key code is followed by other values */
89 { KE_IGNORE, 0xe008, { KEY_RFKILL } },
91 { KE_KEY, 0xe009, { KEY_EJECTCD } },
93 /* Key code is followed by: next, active and attached devices */
94 { KE_KEY, 0xe00b, { KEY_SWITCHVIDEOMODE } },
96 /* Key code is followed by keyboard illumination level */
97 { KE_IGNORE, 0xe00c, { KEY_KBDILLUMTOGGLE } },
99 /* BIOS error detected */
100 { KE_IGNORE, 0xe00d, { KEY_RESERVED } },
102 /* Battery was removed or inserted */
103 { KE_IGNORE, 0xe00e, { KEY_RESERVED } },
105 /* Wifi Catcher */
106 { KE_KEY, 0xe011, { KEY_WLAN } },
108 /* Ambient light sensor toggle */
109 { KE_IGNORE, 0xe013, { KEY_RESERVED } },
111 { KE_IGNORE, 0xe020, { KEY_MUTE } },
113 /* Unknown, defined in ACPI DSDT */
114 /* { KE_IGNORE, 0xe023, { KEY_RESERVED } }, */
116 /* Untested, Dell Instant Launch key on Inspiron 7520 */
117 /* { KE_IGNORE, 0xe024, { KEY_RESERVED } }, */
119 /* Dell Instant Launch key */
120 { KE_KEY, 0xe025, { KEY_PROG4 } },
122 /* Audio panel key */
123 { KE_IGNORE, 0xe026, { KEY_RESERVED } },
125 /* LCD Display On/Off Control key */
126 { KE_KEY, 0xe027, { KEY_DISPLAYTOGGLE } },
128 /* Untested, Multimedia key on Dell Vostro 3560 */
129 /* { KE_IGNORE, 0xe028, { KEY_RESERVED } }, */
131 /* Dell Instant Launch key */
132 { KE_KEY, 0xe029, { KEY_PROG4 } },
134 /* Untested, Windows Mobility Center button on Inspiron 7520 */
135 /* { KE_IGNORE, 0xe02a, { KEY_RESERVED } }, */
137 /* Unknown, defined in ACPI DSDT */
138 /* { KE_IGNORE, 0xe02b, { KEY_RESERVED } }, */
140 /* Untested, Dell Audio With Preset Switch button on Inspiron 7520 */
141 /* { KE_IGNORE, 0xe02c, { KEY_RESERVED } }, */
143 { KE_IGNORE, 0xe02e, { KEY_VOLUMEDOWN } },
144 { KE_IGNORE, 0xe030, { KEY_VOLUMEUP } },
145 { KE_IGNORE, 0xe033, { KEY_KBDILLUMUP } },
146 { KE_IGNORE, 0xe034, { KEY_KBDILLUMDOWN } },
147 { KE_IGNORE, 0xe03a, { KEY_CAPSLOCK } },
149 /* NIC Link is Up */
150 { KE_IGNORE, 0xe043, { KEY_RESERVED } },
152 /* NIC Link is Down */
153 { KE_IGNORE, 0xe044, { KEY_RESERVED } },
156 * This entry is very suspicious!
157 * Originally Matthew Garrett created this dell-wmi driver specially for
158 * "button with a picture of a battery" which has event code 0xe045.
159 * Later Mario Limonciello from Dell told us that event code 0xe045 is
160 * reported by Num Lock and should be ignored because key is send also
161 * by keyboard controller.
162 * So for now we will ignore this event to prevent potential double
163 * Num Lock key press.
165 { KE_IGNORE, 0xe045, { KEY_NUMLOCK } },
167 /* Scroll lock and also going to tablet mode on portable devices */
168 { KE_IGNORE, 0xe046, { KEY_SCROLLLOCK } },
170 /* Untested, going from tablet mode on portable devices */
171 /* { KE_IGNORE, 0xe047, { KEY_RESERVED } }, */
173 /* Dell Support Center key */
174 { KE_IGNORE, 0xe06e, { KEY_RESERVED } },
176 { KE_IGNORE, 0xe0f7, { KEY_MUTE } },
177 { KE_IGNORE, 0xe0f8, { KEY_VOLUMEDOWN } },
178 { KE_IGNORE, 0xe0f9, { KEY_VOLUMEUP } },
181 struct dell_bios_keymap_entry {
182 u16 scancode;
183 u16 keycode;
186 struct dell_bios_hotkey_table {
187 struct dmi_header header;
188 struct dell_bios_keymap_entry keymap[];
192 struct dell_dmi_results {
193 int err;
194 int keymap_size;
195 struct key_entry *keymap;
198 /* Uninitialized entries here are KEY_RESERVED == 0. */
199 static const u16 bios_to_linux_keycode[256] = {
200 [0] = KEY_MEDIA,
201 [1] = KEY_NEXTSONG,
202 [2] = KEY_PLAYPAUSE,
203 [3] = KEY_PREVIOUSSONG,
204 [4] = KEY_STOPCD,
205 [5] = KEY_UNKNOWN,
206 [6] = KEY_UNKNOWN,
207 [7] = KEY_UNKNOWN,
208 [8] = KEY_WWW,
209 [9] = KEY_UNKNOWN,
210 [10] = KEY_VOLUMEDOWN,
211 [11] = KEY_MUTE,
212 [12] = KEY_VOLUMEUP,
213 [13] = KEY_UNKNOWN,
214 [14] = KEY_BATTERY,
215 [15] = KEY_EJECTCD,
216 [16] = KEY_UNKNOWN,
217 [17] = KEY_SLEEP,
218 [18] = KEY_PROG1,
219 [19] = KEY_BRIGHTNESSDOWN,
220 [20] = KEY_BRIGHTNESSUP,
221 [21] = KEY_BRIGHTNESS_AUTO,
222 [22] = KEY_KBDILLUMTOGGLE,
223 [23] = KEY_UNKNOWN,
224 [24] = KEY_SWITCHVIDEOMODE,
225 [25] = KEY_UNKNOWN,
226 [26] = KEY_UNKNOWN,
227 [27] = KEY_SWITCHVIDEOMODE,
228 [28] = KEY_UNKNOWN,
229 [29] = KEY_UNKNOWN,
230 [30] = KEY_PROG2,
231 [31] = KEY_UNKNOWN,
232 [32] = KEY_UNKNOWN,
233 [33] = KEY_UNKNOWN,
234 [34] = KEY_UNKNOWN,
235 [35] = KEY_UNKNOWN,
236 [36] = KEY_UNKNOWN,
237 [37] = KEY_UNKNOWN,
238 [38] = KEY_MICMUTE,
239 [255] = KEY_PROG3,
243 * Keymap for WMI events of type 0x0010
245 * These are applied if the 0xB2 DMI hotkey table is present and doesn't
246 * override them.
248 static const struct key_entry dell_wmi_keymap_type_0010[] = {
249 /* Fn-lock switched to function keys */
250 { KE_IGNORE, 0x0, { KEY_RESERVED } },
252 /* Fn-lock switched to multimedia keys */
253 { KE_IGNORE, 0x1, { KEY_RESERVED } },
255 /* Keyboard backlight change notification */
256 { KE_IGNORE, 0x3f, { KEY_RESERVED } },
258 /* Backlight brightness level */
259 { KE_KEY, 0x57, { KEY_BRIGHTNESSDOWN } },
260 { KE_KEY, 0x58, { KEY_BRIGHTNESSUP } },
262 /* Mic mute */
263 { KE_KEY, 0x150, { KEY_MICMUTE } },
265 /* Fn-lock */
266 { KE_IGNORE, 0x151, { KEY_RESERVED } },
268 /* Change keyboard illumination */
269 { KE_IGNORE, 0x152, { KEY_KBDILLUMTOGGLE } },
272 * Radio disable (notify only -- there is no model for which the
273 * WMI event is supposed to trigger an action).
275 { KE_IGNORE, 0x153, { KEY_RFKILL } },
277 /* RGB keyboard backlight control */
278 { KE_IGNORE, 0x154, { KEY_RESERVED } },
281 * Stealth mode toggle. This will "disable all lights and sounds".
282 * The action is performed by the BIOS and EC; the WMI event is just
283 * a notification. On the XPS 13 9350, this is Fn+F7, and there's
284 * a BIOS setting to enable and disable the hotkey.
286 { KE_IGNORE, 0x155, { KEY_RESERVED } },
288 /* Rugged magnetic dock attach/detach events */
289 { KE_IGNORE, 0x156, { KEY_RESERVED } },
290 { KE_IGNORE, 0x157, { KEY_RESERVED } },
292 /* Rugged programmable (P1/P2/P3 keys) */
293 { KE_KEY, 0x850, { KEY_PROG1 } },
294 { KE_KEY, 0x851, { KEY_PROG2 } },
295 { KE_KEY, 0x852, { KEY_PROG3 } },
298 * Radio disable (notify only -- there is no model for which the
299 * WMI event is supposed to trigger an action).
301 { KE_IGNORE, 0xe008, { KEY_RFKILL } },
303 /* Fn-lock */
304 { KE_IGNORE, 0xe035, { KEY_RESERVED } },
308 * Keymap for WMI events of type 0x0011
310 static const struct key_entry dell_wmi_keymap_type_0011[] = {
311 /* Battery unplugged */
312 { KE_IGNORE, 0xfff0, { KEY_RESERVED } },
314 /* Battery inserted */
315 { KE_IGNORE, 0xfff1, { KEY_RESERVED } },
318 * Detachable keyboard detached / undocked
319 * Note SW_TABLET_MODE is already reported through the intel_vbtn
320 * driver for this, so we ignore it.
322 { KE_IGNORE, 0xfff2, { KEY_RESERVED } },
324 /* Detachable keyboard attached / docked */
325 { KE_IGNORE, 0xfff3, { KEY_RESERVED } },
327 /* Keyboard backlight level changed */
328 { KE_IGNORE, KBD_LED_OFF_TOKEN, { KEY_RESERVED } },
329 { KE_IGNORE, KBD_LED_ON_TOKEN, { KEY_RESERVED } },
330 { KE_IGNORE, KBD_LED_AUTO_TOKEN, { KEY_RESERVED } },
331 { KE_IGNORE, KBD_LED_AUTO_25_TOKEN, { KEY_RESERVED } },
332 { KE_IGNORE, KBD_LED_AUTO_50_TOKEN, { KEY_RESERVED } },
333 { KE_IGNORE, KBD_LED_AUTO_75_TOKEN, { KEY_RESERVED } },
334 { KE_IGNORE, KBD_LED_AUTO_100_TOKEN, { KEY_RESERVED } },
338 * Keymap for WMI events of type 0x0012
339 * They are events with extended data
341 static const struct key_entry dell_wmi_keymap_type_0012[] = {
342 /* Fn-lock button pressed */
343 { KE_IGNORE, 0xe035, { KEY_RESERVED } },
346 static void dell_wmi_process_key(struct wmi_device *wdev, int type, int code)
348 struct dell_wmi_priv *priv = dev_get_drvdata(&wdev->dev);
349 const struct key_entry *key;
351 key = sparse_keymap_entry_from_scancode(priv->input_dev,
352 (type << 16) | code);
353 if (!key) {
354 pr_info("Unknown key with type 0x%04x and code 0x%04x pressed\n",
355 type, code);
356 return;
359 pr_debug("Key with type 0x%04x and code 0x%04x pressed\n", type, code);
361 /* Don't report brightness notifications that will also come via ACPI */
362 if ((key->keycode == KEY_BRIGHTNESSUP ||
363 key->keycode == KEY_BRIGHTNESSDOWN) &&
364 acpi_video_handles_brightness_key_presses())
365 return;
367 if (type == 0x0000 && code == 0xe025 && !wmi_requires_smbios_request)
368 return;
370 if (key->keycode == KEY_KBDILLUMTOGGLE)
371 dell_laptop_call_notifier(
372 DELL_LAPTOP_KBD_BACKLIGHT_BRIGHTNESS_CHANGED, NULL);
374 sparse_keymap_report_entry(priv->input_dev, key, 1, true);
377 static void dell_wmi_notify(struct wmi_device *wdev,
378 union acpi_object *obj)
380 struct dell_wmi_priv *priv = dev_get_drvdata(&wdev->dev);
381 u16 *buffer_entry, *buffer_end;
382 acpi_size buffer_size;
383 int len, i;
385 if (obj->type != ACPI_TYPE_BUFFER) {
386 pr_warn("bad response type %x\n", obj->type);
387 return;
390 pr_debug("Received WMI event (%*ph)\n",
391 obj->buffer.length, obj->buffer.pointer);
393 buffer_entry = (u16 *)obj->buffer.pointer;
394 buffer_size = obj->buffer.length/2;
395 buffer_end = buffer_entry + buffer_size;
398 * BIOS/ACPI on devices with WMI interface version 0 does not clear
399 * buffer before filling it. So next time when BIOS/ACPI send WMI event
400 * which is smaller as previous then it contains garbage in buffer from
401 * previous event.
403 * BIOS/ACPI on devices with WMI interface version 1 clears buffer and
404 * sometimes send more events in buffer at one call.
406 * So to prevent reading garbage from buffer we will process only first
407 * one event on devices with WMI interface version 0.
409 if (priv->interface_version == 0 && buffer_entry < buffer_end)
410 if (buffer_end > buffer_entry + buffer_entry[0] + 1)
411 buffer_end = buffer_entry + buffer_entry[0] + 1;
413 while (buffer_entry < buffer_end) {
415 len = buffer_entry[0];
416 if (len == 0)
417 break;
419 len++;
421 if (buffer_entry + len > buffer_end) {
422 pr_warn("Invalid length of WMI event\n");
423 break;
426 pr_debug("Process buffer (%*ph)\n", len*2, buffer_entry);
428 switch (buffer_entry[1]) {
429 case 0x0000: /* One key pressed or event occurred */
430 case 0x0012: /* Event with extended data occurred */
431 if (len > 2)
432 dell_wmi_process_key(wdev, buffer_entry[1],
433 buffer_entry[2]);
434 /* Extended data is currently ignored */
435 break;
436 case 0x0010: /* Sequence of keys pressed */
437 case 0x0011: /* Sequence of events occurred */
438 for (i = 2; i < len; ++i)
439 dell_wmi_process_key(wdev, buffer_entry[1],
440 buffer_entry[i]);
441 break;
442 default: /* Unknown event */
443 pr_info("Unknown WMI event type 0x%x\n",
444 (int)buffer_entry[1]);
445 break;
448 buffer_entry += len;
454 static bool have_scancode(u32 scancode, const struct key_entry *keymap, int len)
456 int i;
458 for (i = 0; i < len; i++)
459 if (keymap[i].code == scancode)
460 return true;
462 return false;
465 static void handle_dmi_entry(const struct dmi_header *dm, void *opaque)
467 struct dell_dmi_results *results = opaque;
468 struct dell_bios_hotkey_table *table;
469 int hotkey_num, i, pos = 0;
470 struct key_entry *keymap;
472 if (results->err || results->keymap)
473 return; /* We already found the hotkey table. */
475 /* The Dell hotkey table is type 0xB2. Scan until we find it. */
476 if (dm->type != 0xb2)
477 return;
479 table = container_of(dm, struct dell_bios_hotkey_table, header);
481 hotkey_num = (table->header.length -
482 sizeof(struct dell_bios_hotkey_table)) /
483 sizeof(struct dell_bios_keymap_entry);
484 if (hotkey_num < 1) {
486 * Historically, dell-wmi would ignore a DMI entry of
487 * fewer than 7 bytes. Sizes between 4 and 8 bytes are
488 * nonsensical (both the header and all entries are 4
489 * bytes), so we approximate the old behavior by
490 * ignoring tables with fewer than one entry.
492 return;
495 keymap = kcalloc(hotkey_num, sizeof(struct key_entry), GFP_KERNEL);
496 if (!keymap) {
497 results->err = -ENOMEM;
498 return;
501 for (i = 0; i < hotkey_num; i++) {
502 const struct dell_bios_keymap_entry *bios_entry =
503 &table->keymap[i];
505 /* Uninitialized entries are 0 aka KEY_RESERVED. */
506 u16 keycode = (bios_entry->keycode <
507 ARRAY_SIZE(bios_to_linux_keycode)) ?
508 bios_to_linux_keycode[bios_entry->keycode] :
509 (bios_entry->keycode == 0xffff ? KEY_UNKNOWN : KEY_RESERVED);
512 * Log if we find an entry in the DMI table that we don't
513 * understand. If this happens, we should figure out what
514 * the entry means and add it to bios_to_linux_keycode.
516 if (keycode == KEY_RESERVED) {
517 pr_info("firmware scancode 0x%x maps to unrecognized keycode 0x%x\n",
518 bios_entry->scancode, bios_entry->keycode);
519 continue;
522 if (keycode == KEY_KBDILLUMTOGGLE)
523 keymap[pos].type = KE_IGNORE;
524 else
525 keymap[pos].type = KE_KEY;
526 keymap[pos].code = bios_entry->scancode;
527 keymap[pos].keycode = keycode;
529 pos++;
532 results->keymap = keymap;
533 results->keymap_size = pos;
536 static int dell_wmi_input_setup(struct wmi_device *wdev)
538 struct dell_wmi_priv *priv = dev_get_drvdata(&wdev->dev);
539 struct dell_dmi_results dmi_results = {};
540 struct key_entry *keymap;
541 int err, i, pos = 0;
543 priv->input_dev = input_allocate_device();
544 if (!priv->input_dev)
545 return -ENOMEM;
547 priv->input_dev->name = "Dell WMI hotkeys";
548 priv->input_dev->id.bustype = BUS_HOST;
549 priv->input_dev->dev.parent = &wdev->dev;
551 if (dmi_walk(handle_dmi_entry, &dmi_results)) {
553 * Historically, dell-wmi ignored dmi_walk errors. A failure
554 * is certainly surprising, but it probably just indicates
555 * a very old laptop.
557 pr_warn("no DMI; using the old-style hotkey interface\n");
560 if (dmi_results.err) {
561 err = dmi_results.err;
562 goto err_free_dev;
565 keymap = kcalloc(dmi_results.keymap_size +
566 ARRAY_SIZE(dell_wmi_keymap_type_0000) +
567 ARRAY_SIZE(dell_wmi_keymap_type_0010) +
568 ARRAY_SIZE(dell_wmi_keymap_type_0011) +
569 ARRAY_SIZE(dell_wmi_keymap_type_0012) +
571 sizeof(struct key_entry), GFP_KERNEL);
572 if (!keymap) {
573 kfree(dmi_results.keymap);
574 err = -ENOMEM;
575 goto err_free_dev;
578 /* Append table with events of type 0x0010 which comes from DMI */
579 for (i = 0; i < dmi_results.keymap_size; i++) {
580 keymap[pos] = dmi_results.keymap[i];
581 keymap[pos].code |= (0x0010 << 16);
582 pos++;
585 kfree(dmi_results.keymap);
587 /* Append table with extra events of type 0x0010 which are not in DMI */
588 for (i = 0; i < ARRAY_SIZE(dell_wmi_keymap_type_0010); i++) {
589 const struct key_entry *entry = &dell_wmi_keymap_type_0010[i];
592 * Check if we've already found this scancode. This takes
593 * quadratic time, but it doesn't matter unless the list
594 * of extra keys gets very long.
596 if (dmi_results.keymap_size &&
597 have_scancode(entry->code | (0x0010 << 16),
598 keymap, dmi_results.keymap_size)
600 continue;
602 keymap[pos] = *entry;
603 keymap[pos].code |= (0x0010 << 16);
604 pos++;
607 /* Append table with events of type 0x0011 */
608 for (i = 0; i < ARRAY_SIZE(dell_wmi_keymap_type_0011); i++) {
609 keymap[pos] = dell_wmi_keymap_type_0011[i];
610 keymap[pos].code |= (0x0011 << 16);
611 pos++;
614 /* Append table with events of type 0x0012 */
615 for (i = 0; i < ARRAY_SIZE(dell_wmi_keymap_type_0012); i++) {
616 keymap[pos] = dell_wmi_keymap_type_0012[i];
617 keymap[pos].code |= (0x0012 << 16);
618 pos++;
622 * Now append also table with "legacy" events of type 0x0000. Some of
623 * them are reported also on laptops which have scancodes in DMI.
625 for (i = 0; i < ARRAY_SIZE(dell_wmi_keymap_type_0000); i++) {
626 keymap[pos] = dell_wmi_keymap_type_0000[i];
627 pos++;
630 keymap[pos].type = KE_END;
632 err = sparse_keymap_setup(priv->input_dev, keymap, NULL);
634 * Sparse keymap library makes a copy of keymap so we don't need the
635 * original one that was allocated.
637 kfree(keymap);
638 if (err)
639 goto err_free_dev;
641 err = input_register_device(priv->input_dev);
642 if (err)
643 goto err_free_dev;
645 return 0;
647 err_free_dev:
648 input_free_device(priv->input_dev);
649 return err;
652 static void dell_wmi_input_destroy(struct wmi_device *wdev)
654 struct dell_wmi_priv *priv = dev_get_drvdata(&wdev->dev);
656 input_unregister_device(priv->input_dev);
660 * According to Dell SMBIOS documentation:
662 * 17 3 Application Program Registration
664 * cbArg1 Application ID 1 = 0x00010000
665 * cbArg2 Application ID 2
666 * QUICKSET/DCP = 0x51534554 "QSET"
667 * ALS Driver = 0x416c7353 "AlsS"
668 * Latitude ON = 0x4c6f6e52 "LonR"
669 * cbArg3 Application version or revision number
670 * cbArg4 0 = Unregister application
671 * 1 = Register application
672 * cbRes1 Standard return codes (0, -1, -2)
675 static int dell_wmi_events_set_enabled(bool enable)
677 struct calling_interface_buffer *buffer;
678 int ret;
680 buffer = kzalloc(sizeof(struct calling_interface_buffer), GFP_KERNEL);
681 if (!buffer)
682 return -ENOMEM;
683 buffer->cmd_class = CLASS_INFO;
684 buffer->cmd_select = SELECT_APP_REGISTRATION;
685 buffer->input[0] = 0x10000;
686 buffer->input[1] = 0x51534554;
687 buffer->input[3] = enable;
688 ret = dell_smbios_call(buffer);
689 if (ret == 0)
690 ret = buffer->output[0];
691 kfree(buffer);
693 return dell_smbios_error(ret);
696 static int dell_wmi_probe(struct wmi_device *wdev, const void *context)
698 struct dell_wmi_priv *priv;
699 int ret;
701 ret = dell_wmi_get_descriptor_valid();
702 if (ret)
703 return ret;
705 priv = devm_kzalloc(
706 &wdev->dev, sizeof(struct dell_wmi_priv), GFP_KERNEL);
707 if (!priv)
708 return -ENOMEM;
709 dev_set_drvdata(&wdev->dev, priv);
711 if (!dell_wmi_get_interface_version(&priv->interface_version))
712 return -EPROBE_DEFER;
714 return dell_wmi_input_setup(wdev);
717 static int dell_wmi_remove(struct wmi_device *wdev)
719 dell_wmi_input_destroy(wdev);
720 return 0;
722 static const struct wmi_device_id dell_wmi_id_table[] = {
723 { .guid_string = DELL_EVENT_GUID },
724 { },
727 static struct wmi_driver dell_wmi_driver = {
728 .driver = {
729 .name = "dell-wmi",
731 .id_table = dell_wmi_id_table,
732 .probe = dell_wmi_probe,
733 .remove = dell_wmi_remove,
734 .notify = dell_wmi_notify,
737 static int __init dell_wmi_init(void)
739 int err;
741 dmi_check_system(dell_wmi_smbios_list);
743 if (wmi_requires_smbios_request) {
744 err = dell_wmi_events_set_enabled(true);
745 if (err) {
746 pr_err("Failed to enable WMI events\n");
747 return err;
751 return wmi_driver_register(&dell_wmi_driver);
753 late_initcall(dell_wmi_init);
755 static void __exit dell_wmi_exit(void)
757 if (wmi_requires_smbios_request)
758 dell_wmi_events_set_enabled(false);
760 wmi_driver_unregister(&dell_wmi_driver);
762 module_exit(dell_wmi_exit);
764 MODULE_DEVICE_TABLE(wmi, dell_wmi_id_table);