1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * WMI hotkeys support for Dell All-In-One series
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/types.h>
12 #include <linux/input.h>
13 #include <linux/input/sparse-keymap.h>
14 #include <linux/acpi.h>
15 #include <linux/string.h>
17 MODULE_DESCRIPTION("WMI hotkeys driver for Dell All-In-One series");
18 MODULE_LICENSE("GPL");
20 #define EVENT_GUID1 "284A0E6B-380E-472A-921F-E52786257FB4"
21 #define EVENT_GUID2 "02314822-307C-4F66-BF0E-48AEAEB26CC8"
23 struct dell_wmi_event
{
25 /* 0x000: A hot key pressed or an event occurred
26 * 0x00F: A sequence of hot keys are pressed */
31 static const char *dell_wmi_aio_guids
[] = {
37 MODULE_ALIAS("wmi:"EVENT_GUID1
);
38 MODULE_ALIAS("wmi:"EVENT_GUID2
);
40 static const struct key_entry dell_wmi_aio_keymap
[] = {
41 { KE_KEY
, 0xc0, { KEY_VOLUMEUP
} },
42 { KE_KEY
, 0xc1, { KEY_VOLUMEDOWN
} },
43 { KE_KEY
, 0xe030, { KEY_VOLUMEUP
} },
44 { KE_KEY
, 0xe02e, { KEY_VOLUMEDOWN
} },
45 { KE_KEY
, 0xe020, { KEY_MUTE
} },
46 { KE_KEY
, 0xe027, { KEY_DISPLAYTOGGLE
} },
47 { KE_KEY
, 0xe006, { KEY_BRIGHTNESSUP
} },
48 { KE_KEY
, 0xe005, { KEY_BRIGHTNESSDOWN
} },
49 { KE_KEY
, 0xe00b, { KEY_SWITCHVIDEOMODE
} },
53 static struct input_dev
*dell_wmi_aio_input_dev
;
56 * The new WMI event data format will follow the dell_wmi_event structure
57 * So, we will check if the buffer matches the format
59 static bool dell_wmi_aio_event_check(u8
*buffer
, int length
)
61 struct dell_wmi_event
*event
= (struct dell_wmi_event
*)buffer
;
63 if (event
== NULL
|| length
< 6)
66 if ((event
->type
== 0 || event
->type
== 0xf) &&
73 static void dell_wmi_aio_notify(u32 value
, void *context
)
75 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
76 union acpi_object
*obj
;
77 struct dell_wmi_event
*event
;
80 status
= wmi_get_event_data(value
, &response
);
81 if (status
!= AE_OK
) {
82 pr_info("bad event status 0x%x\n", status
);
86 obj
= (union acpi_object
*)response
.pointer
;
88 unsigned int scancode
= 0;
91 case ACPI_TYPE_INTEGER
:
92 /* Most All-In-One correctly return integer scancode */
93 scancode
= obj
->integer
.value
;
94 sparse_keymap_report_event(dell_wmi_aio_input_dev
,
97 case ACPI_TYPE_BUFFER
:
98 if (dell_wmi_aio_event_check(obj
->buffer
.pointer
,
99 obj
->buffer
.length
)) {
100 event
= (struct dell_wmi_event
*)
102 scancode
= event
->event
[0];
104 /* Broken machines return the scancode in a
106 if (obj
->buffer
.pointer
&&
107 obj
->buffer
.length
> 0)
108 scancode
= obj
->buffer
.pointer
[0];
111 sparse_keymap_report_event(
112 dell_wmi_aio_input_dev
,
120 static int __init
dell_wmi_aio_input_setup(void)
124 dell_wmi_aio_input_dev
= input_allocate_device();
126 if (!dell_wmi_aio_input_dev
)
129 dell_wmi_aio_input_dev
->name
= "Dell AIO WMI hotkeys";
130 dell_wmi_aio_input_dev
->phys
= "wmi/input0";
131 dell_wmi_aio_input_dev
->id
.bustype
= BUS_HOST
;
133 err
= sparse_keymap_setup(dell_wmi_aio_input_dev
,
134 dell_wmi_aio_keymap
, NULL
);
136 pr_err("Unable to setup input device keymap\n");
139 err
= input_register_device(dell_wmi_aio_input_dev
);
141 pr_info("Unable to register input device\n");
147 input_free_device(dell_wmi_aio_input_dev
);
151 static const char *dell_wmi_aio_find(void)
155 for (i
= 0; dell_wmi_aio_guids
[i
] != NULL
; i
++)
156 if (wmi_has_guid(dell_wmi_aio_guids
[i
]))
157 return dell_wmi_aio_guids
[i
];
162 static int __init
dell_wmi_aio_init(void)
167 guid
= dell_wmi_aio_find();
169 pr_warn("No known WMI GUID found\n");
173 err
= dell_wmi_aio_input_setup();
177 err
= wmi_install_notify_handler(guid
, dell_wmi_aio_notify
, NULL
);
179 pr_err("Unable to register notify handler - %d\n", err
);
180 input_unregister_device(dell_wmi_aio_input_dev
);
187 static void __exit
dell_wmi_aio_exit(void)
191 guid
= dell_wmi_aio_find();
192 wmi_remove_notify_handler(guid
);
193 input_unregister_device(dell_wmi_aio_input_dev
);
196 module_init(dell_wmi_aio_init
);
197 module_exit(dell_wmi_aio_exit
);