Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Dell WMI hotkeys |
| 3 | * |
| 4 | * Copyright (C) 2008 Red Hat <mjg@redhat.com> |
Pali Rohár | 595773a4 | 2016-01-04 22:26:35 +0100 | [diff] [blame] | 5 | * Copyright (C) 2014-2015 Pali Rohár <pali.rohar@gmail.com> |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 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 | |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 27 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 28 | |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 33 | #include <linux/types.h> |
| 34 | #include <linux/input.h> |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 35 | #include <linux/input/sparse-keymap.h> |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 36 | #include <linux/acpi.h> |
| 37 | #include <linux/string.h> |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 38 | #include <linux/dmi.h> |
Hans de Goede | 18bd769 | 2015-06-16 16:28:01 +0200 | [diff] [blame] | 39 | #include <acpi/video.h> |
Michał Kępień | e09c4d5 | 2016-03-04 14:09:08 +0100 | [diff] [blame] | 40 | #include "dell-smbios.h" |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 41 | |
| 42 | MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); |
Pali Rohár | 595773a4 | 2016-01-04 22:26:35 +0100 | [diff] [blame] | 43 | MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>"); |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 44 | MODULE_DESCRIPTION("Dell laptop WMI hotkeys driver"); |
| 45 | MODULE_LICENSE("GPL"); |
| 46 | |
| 47 | #define DELL_EVENT_GUID "9DBB5994-A997-11DA-B012-B622A1EF5492" |
Pali Rohár | 595773a4 | 2016-01-04 22:26:35 +0100 | [diff] [blame] | 48 | #define DELL_DESCRIPTOR_GUID "8D9DDCBC-A997-11DA-B012-B622A1EF5492" |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 49 | |
Pali Rohár | 595773a4 | 2016-01-04 22:26:35 +0100 | [diff] [blame] | 50 | static u32 dell_wmi_interface_version; |
Michał Kępień | e09c4d5 | 2016-03-04 14:09:08 +0100 | [diff] [blame] | 51 | static bool wmi_requires_smbios_request; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 52 | |
| 53 | MODULE_ALIAS("wmi:"DELL_EVENT_GUID); |
Pali Rohár | 595773a4 | 2016-01-04 22:26:35 +0100 | [diff] [blame] | 54 | MODULE_ALIAS("wmi:"DELL_DESCRIPTOR_GUID); |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 55 | |
Michał Kępień | e09c4d5 | 2016-03-04 14:09:08 +0100 | [diff] [blame] | 56 | static int __init dmi_matched(const struct dmi_system_id *dmi) |
| 57 | { |
| 58 | wmi_requires_smbios_request = 1; |
| 59 | return 1; |
| 60 | } |
| 61 | |
| 62 | static const struct dmi_system_id dell_wmi_smbios_list[] __initconst = { |
| 63 | { |
| 64 | .callback = dmi_matched, |
Michał Kępień | aaf3a5e | 2016-03-04 14:09:10 +0100 | [diff] [blame] | 65 | .ident = "Dell Inspiron M5110", |
| 66 | .matches = { |
| 67 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 68 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"), |
| 69 | }, |
| 70 | }, |
| 71 | { |
| 72 | .callback = dmi_matched, |
Michał Kępień | e09c4d5 | 2016-03-04 14:09:08 +0100 | [diff] [blame] | 73 | .ident = "Dell Vostro V131", |
| 74 | .matches = { |
| 75 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 76 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"), |
| 77 | }, |
| 78 | }, |
| 79 | { } |
| 80 | }; |
| 81 | |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 82 | /* |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 83 | * Keymap for WMI events of type 0x0000 |
| 84 | * |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 85 | * Certain keys are flagged as KE_IGNORE. All of these are either |
| 86 | * notifications (rather than requests for change) or are also sent |
| 87 | * via the keyboard controller so should not be sent again. |
| 88 | */ |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 89 | static const struct key_entry dell_wmi_keymap_type_0000[] __initconst = { |
Seth Forshee | f1566f0 | 2011-08-01 15:46:10 -0500 | [diff] [blame] | 90 | { KE_IGNORE, 0x003a, { KEY_CAPSLOCK } }, |
| 91 | |
Pali Rohár | 6a4d260 | 2016-06-15 21:49:11 +0200 | [diff] [blame] | 92 | /* Key code is followed by brightness level */ |
| 93 | { KE_KEY, 0xe005, { KEY_BRIGHTNESSDOWN } }, |
| 94 | { KE_KEY, 0xe006, { KEY_BRIGHTNESSUP } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 95 | |
| 96 | /* Battery health status button */ |
Pali Rohár | 6a4d260 | 2016-06-15 21:49:11 +0200 | [diff] [blame] | 97 | { KE_KEY, 0xe007, { KEY_BATTERY } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 98 | |
Pali Rohár | 6a4d260 | 2016-06-15 21:49:11 +0200 | [diff] [blame] | 99 | /* Radio devices state change, key code is followed by other values */ |
Gabriele Mazzotta | 8f8d75e | 2014-12-04 00:16:21 +0100 | [diff] [blame] | 100 | { KE_IGNORE, 0xe008, { KEY_RFKILL } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 101 | |
Pali Rohár | 6a4d260 | 2016-06-15 21:49:11 +0200 | [diff] [blame] | 102 | { KE_KEY, 0xe009, { KEY_EJECTCD } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 103 | |
Pali Rohár | 6a4d260 | 2016-06-15 21:49:11 +0200 | [diff] [blame] | 104 | /* Key code is followed by: next, active and attached devices */ |
| 105 | { KE_KEY, 0xe00b, { KEY_SWITCHVIDEOMODE } }, |
| 106 | |
| 107 | /* Key code is followed by keyboard illumination level */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 108 | { KE_IGNORE, 0xe00c, { KEY_KBDILLUMTOGGLE } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 109 | |
| 110 | /* BIOS error detected */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 111 | { KE_IGNORE, 0xe00d, { KEY_RESERVED } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 112 | |
Pali Rohár | 65a97a6 | 2016-07-27 09:34:42 +0200 | [diff] [blame] | 113 | /* Battery was removed or inserted */ |
| 114 | { KE_IGNORE, 0xe00e, { KEY_RESERVED } }, |
Pali Rohár | 3237a86 | 2016-06-15 21:49:12 +0200 | [diff] [blame] | 115 | |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 116 | /* Wifi Catcher */ |
Mario Limonciello | 915ac05 | 2016-07-28 12:53:47 -0500 | [diff] [blame] | 117 | { KE_KEY, 0xe011, { KEY_WLAN } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 118 | |
| 119 | /* Ambient light sensor toggle */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 120 | { KE_IGNORE, 0xe013, { KEY_RESERVED } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 121 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 122 | { KE_IGNORE, 0xe020, { KEY_MUTE } }, |
Seth Forshee | f1566f0 | 2011-08-01 15:46:10 -0500 | [diff] [blame] | 123 | |
Pali Rohár | 3237a86 | 2016-06-15 21:49:12 +0200 | [diff] [blame] | 124 | /* Unknown, defined in ACPI DSDT */ |
| 125 | /* { KE_IGNORE, 0xe023, { KEY_RESERVED } }, */ |
| 126 | |
| 127 | /* Untested, Dell Instant Launch key on Inspiron 7520 */ |
| 128 | /* { KE_IGNORE, 0xe024, { KEY_RESERVED } }, */ |
| 129 | |
Michał Kępień | aaf3a5e | 2016-03-04 14:09:10 +0100 | [diff] [blame] | 130 | /* Dell Instant Launch key */ |
Pali Rohár | 6a4d260 | 2016-06-15 21:49:11 +0200 | [diff] [blame] | 131 | { KE_KEY, 0xe025, { KEY_PROG4 } }, |
Michał Kępień | aaf3a5e | 2016-03-04 14:09:10 +0100 | [diff] [blame] | 132 | |
| 133 | /* Audio panel key */ |
Seth Forshee | f1566f0 | 2011-08-01 15:46:10 -0500 | [diff] [blame] | 134 | { KE_IGNORE, 0xe026, { KEY_RESERVED } }, |
| 135 | |
Alex Hung | ab9bb11c | 2016-06-17 11:44:27 +0800 | [diff] [blame] | 136 | /* LCD Display On/Off Control key */ |
| 137 | { KE_KEY, 0xe027, { KEY_DISPLAYTOGGLE } }, |
| 138 | |
Pali Rohár | 3237a86 | 2016-06-15 21:49:12 +0200 | [diff] [blame] | 139 | /* Untested, Multimedia key on Dell Vostro 3560 */ |
| 140 | /* { KE_IGNORE, 0xe028, { KEY_RESERVED } }, */ |
| 141 | |
Pali Rohár | 6a4d260 | 2016-06-15 21:49:11 +0200 | [diff] [blame] | 142 | /* Dell Instant Launch key */ |
| 143 | { KE_KEY, 0xe029, { KEY_PROG4 } }, |
| 144 | |
Pali Rohár | 3237a86 | 2016-06-15 21:49:12 +0200 | [diff] [blame] | 145 | /* Untested, Windows Mobility Center button on Inspiron 7520 */ |
| 146 | /* { KE_IGNORE, 0xe02a, { KEY_RESERVED } }, */ |
| 147 | |
| 148 | /* Unknown, defined in ACPI DSDT */ |
| 149 | /* { KE_IGNORE, 0xe02b, { KEY_RESERVED } }, */ |
| 150 | |
| 151 | /* Untested, Dell Audio With Preset Switch button on Inspiron 7520 */ |
| 152 | /* { KE_IGNORE, 0xe02c, { KEY_RESERVED } }, */ |
| 153 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 154 | { KE_IGNORE, 0xe02e, { KEY_VOLUMEDOWN } }, |
| 155 | { KE_IGNORE, 0xe030, { KEY_VOLUMEUP } }, |
| 156 | { KE_IGNORE, 0xe033, { KEY_KBDILLUMUP } }, |
| 157 | { KE_IGNORE, 0xe034, { KEY_KBDILLUMDOWN } }, |
| 158 | { KE_IGNORE, 0xe03a, { KEY_CAPSLOCK } }, |
Pali Rohár | 3de59bc | 2016-06-15 21:49:10 +0200 | [diff] [blame] | 159 | |
Pali Rohár | 3237a86 | 2016-06-15 21:49:12 +0200 | [diff] [blame] | 160 | /* NIC Link is Up */ |
| 161 | { KE_IGNORE, 0xe043, { KEY_RESERVED } }, |
| 162 | |
| 163 | /* NIC Link is Down */ |
| 164 | { KE_IGNORE, 0xe044, { KEY_RESERVED } }, |
| 165 | |
Pali Rohár | 3de59bc | 2016-06-15 21:49:10 +0200 | [diff] [blame] | 166 | /* |
| 167 | * This entry is very suspicious! |
| 168 | * Originally Matthew Garrett created this dell-wmi driver specially for |
| 169 | * "button with a picture of a battery" which has event code 0xe045. |
| 170 | * Later Mario Limonciello from Dell told us that event code 0xe045 is |
| 171 | * reported by Num Lock and should be ignored because key is send also |
| 172 | * by keyboard controller. |
| 173 | * So for now we will ignore this event to prevent potential double |
| 174 | * Num Lock key press. |
| 175 | */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 176 | { KE_IGNORE, 0xe045, { KEY_NUMLOCK } }, |
Pali Rohár | 3de59bc | 2016-06-15 21:49:10 +0200 | [diff] [blame] | 177 | |
Pali Rohár | 3237a86 | 2016-06-15 21:49:12 +0200 | [diff] [blame] | 178 | /* Scroll lock and also going to tablet mode on portable devices */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 179 | { KE_IGNORE, 0xe046, { KEY_SCROLLLOCK } }, |
Pali Rohár | 3237a86 | 2016-06-15 21:49:12 +0200 | [diff] [blame] | 180 | |
| 181 | /* Untested, going from tablet mode on portable devices */ |
| 182 | /* { KE_IGNORE, 0xe047, { KEY_RESERVED } }, */ |
| 183 | |
| 184 | /* Dell Support Center key */ |
| 185 | { KE_IGNORE, 0xe06e, { KEY_RESERVED } }, |
| 186 | |
Seth Forshee | f1566f0 | 2011-08-01 15:46:10 -0500 | [diff] [blame] | 187 | { KE_IGNORE, 0xe0f7, { KEY_MUTE } }, |
| 188 | { KE_IGNORE, 0xe0f8, { KEY_VOLUMEDOWN } }, |
| 189 | { KE_IGNORE, 0xe0f9, { KEY_VOLUMEUP } }, |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 190 | }; |
| 191 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 192 | struct dell_bios_keymap_entry { |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 193 | u16 scancode; |
| 194 | u16 keycode; |
| 195 | }; |
| 196 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 197 | struct dell_bios_hotkey_table { |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 198 | struct dmi_header header; |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 199 | struct dell_bios_keymap_entry keymap[]; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 200 | |
| 201 | }; |
| 202 | |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 203 | struct dell_dmi_results { |
| 204 | int err; |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 205 | int keymap_size; |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 206 | struct key_entry *keymap; |
| 207 | }; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 208 | |
Andy Lutomirski | cbc61f1 | 2015-11-30 17:02:01 -0800 | [diff] [blame] | 209 | /* Uninitialized entries here are KEY_RESERVED == 0. */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 210 | static const u16 bios_to_linux_keycode[256] __initconst = { |
Andy Lutomirski | 394cb77 | 2015-11-13 21:49:31 -0800 | [diff] [blame] | 211 | [0] = KEY_MEDIA, |
| 212 | [1] = KEY_NEXTSONG, |
| 213 | [2] = KEY_PLAYPAUSE, |
| 214 | [3] = KEY_PREVIOUSSONG, |
| 215 | [4] = KEY_STOPCD, |
| 216 | [5] = KEY_UNKNOWN, |
| 217 | [6] = KEY_UNKNOWN, |
| 218 | [7] = KEY_UNKNOWN, |
| 219 | [8] = KEY_WWW, |
| 220 | [9] = KEY_UNKNOWN, |
| 221 | [10] = KEY_VOLUMEDOWN, |
| 222 | [11] = KEY_MUTE, |
| 223 | [12] = KEY_VOLUMEUP, |
| 224 | [13] = KEY_UNKNOWN, |
| 225 | [14] = KEY_BATTERY, |
| 226 | [15] = KEY_EJECTCD, |
| 227 | [16] = KEY_UNKNOWN, |
| 228 | [17] = KEY_SLEEP, |
| 229 | [18] = KEY_PROG1, |
| 230 | [19] = KEY_BRIGHTNESSDOWN, |
| 231 | [20] = KEY_BRIGHTNESSUP, |
| 232 | [21] = KEY_UNKNOWN, |
| 233 | [22] = KEY_KBDILLUMTOGGLE, |
| 234 | [23] = KEY_UNKNOWN, |
| 235 | [24] = KEY_SWITCHVIDEOMODE, |
| 236 | [25] = KEY_UNKNOWN, |
| 237 | [26] = KEY_UNKNOWN, |
| 238 | [27] = KEY_SWITCHVIDEOMODE, |
| 239 | [28] = KEY_UNKNOWN, |
| 240 | [29] = KEY_UNKNOWN, |
| 241 | [30] = KEY_PROG2, |
| 242 | [31] = KEY_UNKNOWN, |
| 243 | [32] = KEY_UNKNOWN, |
| 244 | [33] = KEY_UNKNOWN, |
| 245 | [34] = KEY_UNKNOWN, |
| 246 | [35] = KEY_UNKNOWN, |
| 247 | [36] = KEY_UNKNOWN, |
| 248 | [37] = KEY_UNKNOWN, |
| 249 | [38] = KEY_MICMUTE, |
| 250 | [255] = KEY_PROG3, |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 251 | }; |
| 252 | |
Andy Lutomirski | a464afb | 2016-02-15 08:32:36 -0800 | [diff] [blame] | 253 | /* |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 254 | * Keymap for WMI events of type 0x0010 |
| 255 | * |
Andy Lutomirski | a464afb | 2016-02-15 08:32:36 -0800 | [diff] [blame] | 256 | * These are applied if the 0xB2 DMI hotkey table is present and doesn't |
| 257 | * override them. |
| 258 | */ |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 259 | static const struct key_entry dell_wmi_keymap_type_0010[] __initconst = { |
Andy Lutomirski | a464afb | 2016-02-15 08:32:36 -0800 | [diff] [blame] | 260 | /* Fn-lock */ |
| 261 | { KE_IGNORE, 0x151, { KEY_RESERVED } }, |
| 262 | |
| 263 | /* Change keyboard illumination */ |
| 264 | { KE_IGNORE, 0x152, { KEY_KBDILLUMTOGGLE } }, |
| 265 | |
| 266 | /* |
| 267 | * Radio disable (notify only -- there is no model for which the |
| 268 | * WMI event is supposed to trigger an action). |
| 269 | */ |
| 270 | { KE_IGNORE, 0x153, { KEY_RFKILL } }, |
| 271 | |
| 272 | /* RGB keyboard backlight control */ |
| 273 | { KE_IGNORE, 0x154, { KEY_RESERVED } }, |
| 274 | |
Andy Lutomirski | e4f2e3f | 2016-02-17 12:38:07 -0800 | [diff] [blame^] | 275 | /* |
| 276 | * Stealth mode toggle. This will "disable all lights and sounds". |
| 277 | * The action is performed by the BIOS and EC; the WMI event is just |
| 278 | * a notification. On the XPS 13 9350, this is Fn+F7, and there's |
| 279 | * a BIOS setting to enable and disable the hotkey. |
| 280 | */ |
Andy Lutomirski | a464afb | 2016-02-15 08:32:36 -0800 | [diff] [blame] | 281 | { KE_IGNORE, 0x155, { KEY_RESERVED } }, |
Mario Limonciello | 5dc444b | 2016-07-28 12:53:48 -0500 | [diff] [blame] | 282 | |
| 283 | /* Rugged magnetic dock attach/detach events */ |
| 284 | { KE_IGNORE, 0x156, { KEY_RESERVED } }, |
| 285 | { KE_IGNORE, 0x157, { KEY_RESERVED } }, |
| 286 | |
| 287 | /* Rugged programmable (P1/P2/P3 keys) */ |
| 288 | { KE_KEY, 0x850, { KEY_PROG1 } }, |
| 289 | { KE_KEY, 0x851, { KEY_PROG2 } }, |
| 290 | { KE_KEY, 0x852, { KEY_PROG3 } }, |
| 291 | |
Andy Lutomirski | a464afb | 2016-02-15 08:32:36 -0800 | [diff] [blame] | 292 | }; |
| 293 | |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 294 | /* |
| 295 | * Keymap for WMI events of type 0x0011 |
| 296 | */ |
| 297 | static const struct key_entry dell_wmi_keymap_type_0011[] __initconst = { |
| 298 | /* Battery unplugged */ |
| 299 | { KE_IGNORE, 0xfff0, { KEY_RESERVED } }, |
| 300 | |
| 301 | /* Battery inserted */ |
| 302 | { KE_IGNORE, 0xfff1, { KEY_RESERVED } }, |
| 303 | |
| 304 | /* Keyboard backlight level changed */ |
| 305 | { KE_IGNORE, 0x01e1, { KEY_RESERVED } }, |
| 306 | { KE_IGNORE, 0x02ea, { KEY_RESERVED } }, |
| 307 | { KE_IGNORE, 0x02eb, { KEY_RESERVED } }, |
| 308 | { KE_IGNORE, 0x02ec, { KEY_RESERVED } }, |
| 309 | { KE_IGNORE, 0x02f6, { KEY_RESERVED } }, |
| 310 | }; |
| 311 | |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 312 | static struct input_dev *dell_wmi_input_dev; |
| 313 | |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 314 | static void dell_wmi_process_key(int type, int code) |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 315 | { |
| 316 | const struct key_entry *key; |
| 317 | |
| 318 | key = sparse_keymap_entry_from_scancode(dell_wmi_input_dev, |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 319 | (type << 16) | code); |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 320 | if (!key) { |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 321 | pr_info("Unknown key with type 0x%04x and code 0x%04x pressed\n", |
| 322 | type, code); |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 323 | return; |
| 324 | } |
| 325 | |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 326 | pr_debug("Key with type 0x%04x and code 0x%04x pressed\n", type, code); |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 327 | |
| 328 | /* Don't report brightness notifications that will also come via ACPI */ |
| 329 | if ((key->keycode == KEY_BRIGHTNESSUP || |
Hans de Goede | 61679c7 | 2015-12-22 19:09:49 +0100 | [diff] [blame] | 330 | key->keycode == KEY_BRIGHTNESSDOWN) && |
| 331 | acpi_video_handles_brightness_key_presses()) |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 332 | return; |
| 333 | |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 334 | if (type == 0x0000 && code == 0xe025 && !wmi_requires_smbios_request) |
Michał Kępień | 13f5059 | 2016-03-04 14:09:09 +0100 | [diff] [blame] | 335 | return; |
| 336 | |
Hans de Goede | 9c656b0 | 2017-03-16 11:55:35 +0100 | [diff] [blame] | 337 | if (key->keycode == KEY_KBDILLUMTOGGLE) |
| 338 | dell_laptop_call_notifier( |
| 339 | DELL_LAPTOP_KBD_BACKLIGHT_BRIGHTNESS_CHANGED, NULL); |
| 340 | |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 341 | sparse_keymap_report_entry(dell_wmi_input_dev, key, 1, true); |
| 342 | } |
| 343 | |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 344 | static void dell_wmi_notify(u32 value, void *context) |
| 345 | { |
| 346 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 347 | union acpi_object *obj; |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 348 | acpi_status status; |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 349 | acpi_size buffer_size; |
| 350 | u16 *buffer_entry, *buffer_end; |
| 351 | int len, i; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 352 | |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 353 | status = wmi_get_event_data(value, &response); |
| 354 | if (status != AE_OK) { |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 355 | pr_warn("bad event status 0x%x\n", status); |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 356 | return; |
| 357 | } |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 358 | |
| 359 | obj = (union acpi_object *)response.pointer; |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 360 | if (!obj) { |
| 361 | pr_warn("no response\n"); |
| 362 | return; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 363 | } |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 364 | |
| 365 | if (obj->type != ACPI_TYPE_BUFFER) { |
| 366 | pr_warn("bad response type %x\n", obj->type); |
| 367 | kfree(obj); |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | pr_debug("Received WMI event (%*ph)\n", |
| 372 | obj->buffer.length, obj->buffer.pointer); |
| 373 | |
| 374 | buffer_entry = (u16 *)obj->buffer.pointer; |
| 375 | buffer_size = obj->buffer.length/2; |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 376 | buffer_end = buffer_entry + buffer_size; |
| 377 | |
Pali Rohár | 481fe5b | 2016-01-04 22:26:36 +0100 | [diff] [blame] | 378 | /* |
| 379 | * BIOS/ACPI on devices with WMI interface version 0 does not clear |
| 380 | * buffer before filling it. So next time when BIOS/ACPI send WMI event |
| 381 | * which is smaller as previous then it contains garbage in buffer from |
| 382 | * previous event. |
| 383 | * |
| 384 | * BIOS/ACPI on devices with WMI interface version 1 clears buffer and |
| 385 | * sometimes send more events in buffer at one call. |
| 386 | * |
| 387 | * So to prevent reading garbage from buffer we will process only first |
| 388 | * one event on devices with WMI interface version 0. |
| 389 | */ |
| 390 | if (dell_wmi_interface_version == 0 && buffer_entry < buffer_end) |
| 391 | if (buffer_end > buffer_entry + buffer_entry[0] + 1) |
| 392 | buffer_end = buffer_entry + buffer_entry[0] + 1; |
| 393 | |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 394 | while (buffer_entry < buffer_end) { |
| 395 | |
| 396 | len = buffer_entry[0]; |
| 397 | if (len == 0) |
| 398 | break; |
| 399 | |
| 400 | len++; |
| 401 | |
| 402 | if (buffer_entry + len > buffer_end) { |
| 403 | pr_warn("Invalid length of WMI event\n"); |
| 404 | break; |
| 405 | } |
| 406 | |
| 407 | pr_debug("Process buffer (%*ph)\n", len*2, buffer_entry); |
| 408 | |
| 409 | switch (buffer_entry[1]) { |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 410 | case 0x0000: /* One key pressed or event occurred */ |
| 411 | if (len > 2) |
| 412 | dell_wmi_process_key(0x0000, buffer_entry[2]); |
| 413 | /* Other entries could contain additional information */ |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 414 | break; |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 415 | case 0x0010: /* Sequence of keys pressed */ |
| 416 | case 0x0011: /* Sequence of events occurred */ |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 417 | for (i = 2; i < len; ++i) |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 418 | dell_wmi_process_key(buffer_entry[1], |
| 419 | buffer_entry[i]); |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 420 | break; |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 421 | default: /* Unknown event */ |
Pali Rohár | 83fc44c | 2014-11-11 20:21:22 +0100 | [diff] [blame] | 422 | pr_info("Unknown WMI event type 0x%x\n", |
| 423 | (int)buffer_entry[1]); |
| 424 | break; |
| 425 | } |
| 426 | |
| 427 | buffer_entry += len; |
| 428 | |
| 429 | } |
| 430 | |
Anisse Astier | 3e9b988 | 2009-12-04 10:10:09 +0100 | [diff] [blame] | 431 | kfree(obj); |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Andy Lutomirski | a464afb | 2016-02-15 08:32:36 -0800 | [diff] [blame] | 434 | static bool have_scancode(u32 scancode, const struct key_entry *keymap, int len) |
| 435 | { |
| 436 | int i; |
| 437 | |
| 438 | for (i = 0; i < len; i++) |
| 439 | if (keymap[i].code == scancode) |
| 440 | return true; |
| 441 | |
| 442 | return false; |
| 443 | } |
| 444 | |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 445 | static void __init handle_dmi_entry(const struct dmi_header *dm, |
| 446 | void *opaque) |
Andy Lutomirski | a464afb | 2016-02-15 08:32:36 -0800 | [diff] [blame] | 447 | |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 448 | { |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 449 | struct dell_dmi_results *results = opaque; |
| 450 | struct dell_bios_hotkey_table *table; |
Andy Lutomirski | a464afb | 2016-02-15 08:32:36 -0800 | [diff] [blame] | 451 | int hotkey_num, i, pos = 0; |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 452 | struct key_entry *keymap; |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 453 | |
| 454 | if (results->err || results->keymap) |
| 455 | return; /* We already found the hotkey table. */ |
| 456 | |
Andy Lutomirski | 074df51 | 2016-02-17 12:34:34 -0800 | [diff] [blame] | 457 | /* The Dell hotkey table is type 0xB2. Scan until we find it. */ |
Andy Lutomirski | b13de70 | 2016-02-15 08:32:35 -0800 | [diff] [blame] | 458 | if (dm->type != 0xb2) |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 459 | return; |
| 460 | |
| 461 | table = container_of(dm, struct dell_bios_hotkey_table, header); |
| 462 | |
Andy Lutomirski | b13de70 | 2016-02-15 08:32:35 -0800 | [diff] [blame] | 463 | hotkey_num = (table->header.length - |
| 464 | sizeof(struct dell_bios_hotkey_table)) / |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 465 | sizeof(struct dell_bios_keymap_entry); |
Andy Lutomirski | b13de70 | 2016-02-15 08:32:35 -0800 | [diff] [blame] | 466 | if (hotkey_num < 1) { |
| 467 | /* |
| 468 | * Historically, dell-wmi would ignore a DMI entry of |
| 469 | * fewer than 7 bytes. Sizes between 4 and 8 bytes are |
| 470 | * nonsensical (both the header and all entries are 4 |
| 471 | * bytes), so we approximate the old behavior by |
| 472 | * ignoring tables with fewer than one entry. |
| 473 | */ |
| 474 | return; |
| 475 | } |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 476 | |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 477 | keymap = kcalloc(hotkey_num, sizeof(struct key_entry), GFP_KERNEL); |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 478 | if (!keymap) { |
| 479 | results->err = -ENOMEM; |
| 480 | return; |
| 481 | } |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 482 | |
| 483 | for (i = 0; i < hotkey_num; i++) { |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 484 | const struct dell_bios_keymap_entry *bios_entry = |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 485 | &table->keymap[i]; |
Andy Lutomirski | cbc61f1 | 2015-11-30 17:02:01 -0800 | [diff] [blame] | 486 | |
| 487 | /* Uninitialized entries are 0 aka KEY_RESERVED. */ |
| 488 | u16 keycode = (bios_entry->keycode < |
| 489 | ARRAY_SIZE(bios_to_linux_keycode)) ? |
| 490 | bios_to_linux_keycode[bios_entry->keycode] : |
| 491 | KEY_RESERVED; |
| 492 | |
| 493 | /* |
| 494 | * Log if we find an entry in the DMI table that we don't |
| 495 | * understand. If this happens, we should figure out what |
| 496 | * the entry means and add it to bios_to_linux_keycode. |
| 497 | */ |
| 498 | if (keycode == KEY_RESERVED) { |
| 499 | pr_info("firmware scancode 0x%x maps to unrecognized keycode 0x%x\n", |
| 500 | bios_entry->scancode, bios_entry->keycode); |
| 501 | continue; |
| 502 | } |
Gabriele Mazzotta | 8cb8e63 | 2014-12-04 00:16:23 +0100 | [diff] [blame] | 503 | |
| 504 | if (keycode == KEY_KBDILLUMTOGGLE) |
Andy Lutomirski | a464afb | 2016-02-15 08:32:36 -0800 | [diff] [blame] | 505 | keymap[pos].type = KE_IGNORE; |
Gabriele Mazzotta | 8cb8e63 | 2014-12-04 00:16:23 +0100 | [diff] [blame] | 506 | else |
Andy Lutomirski | a464afb | 2016-02-15 08:32:36 -0800 | [diff] [blame] | 507 | keymap[pos].type = KE_KEY; |
| 508 | keymap[pos].code = bios_entry->scancode; |
| 509 | keymap[pos].keycode = keycode; |
| 510 | |
| 511 | pos++; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 512 | } |
| 513 | |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 514 | results->keymap = keymap; |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 515 | results->keymap_size = pos; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 516 | } |
| 517 | |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 518 | static int __init dell_wmi_input_setup(void) |
| 519 | { |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 520 | struct dell_dmi_results dmi_results = {}; |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 521 | struct key_entry *keymap; |
| 522 | int err, i, pos = 0; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 523 | |
| 524 | dell_wmi_input_dev = input_allocate_device(); |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 525 | if (!dell_wmi_input_dev) |
| 526 | return -ENOMEM; |
| 527 | |
| 528 | dell_wmi_input_dev->name = "Dell WMI hotkeys"; |
| 529 | dell_wmi_input_dev->phys = "wmi/input0"; |
| 530 | dell_wmi_input_dev->id.bustype = BUS_HOST; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 531 | |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 532 | if (dmi_walk(handle_dmi_entry, &dmi_results)) { |
| 533 | /* |
| 534 | * Historically, dell-wmi ignored dmi_walk errors. A failure |
| 535 | * is certainly surprising, but it probably just indicates |
| 536 | * a very old laptop. |
| 537 | */ |
| 538 | pr_warn("no DMI; using the old-style hotkey interface\n"); |
| 539 | } |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 540 | |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 541 | if (dmi_results.err) { |
| 542 | err = dmi_results.err; |
| 543 | goto err_free_dev; |
| 544 | } |
| 545 | |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 546 | keymap = kcalloc(dmi_results.keymap_size + |
| 547 | ARRAY_SIZE(dell_wmi_keymap_type_0000) + |
| 548 | ARRAY_SIZE(dell_wmi_keymap_type_0010) + |
| 549 | ARRAY_SIZE(dell_wmi_keymap_type_0011) + |
| 550 | 1, |
| 551 | sizeof(struct key_entry), GFP_KERNEL); |
| 552 | if (!keymap) { |
| 553 | kfree(dmi_results.keymap); |
| 554 | err = -ENOMEM; |
| 555 | goto err_free_dev; |
| 556 | } |
Andy Lutomirski | 18b6f80 | 2016-02-15 08:32:33 -0800 | [diff] [blame] | 557 | |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 558 | /* Append table with events of type 0x0010 which comes from DMI */ |
| 559 | for (i = 0; i < dmi_results.keymap_size; i++) { |
| 560 | keymap[pos] = dmi_results.keymap[i]; |
| 561 | keymap[pos].code |= (0x0010 << 16); |
| 562 | pos++; |
| 563 | } |
| 564 | |
| 565 | kfree(dmi_results.keymap); |
| 566 | |
| 567 | /* Append table with extra events of type 0x0010 which are not in DMI */ |
| 568 | for (i = 0; i < ARRAY_SIZE(dell_wmi_keymap_type_0010); i++) { |
| 569 | const struct key_entry *entry = &dell_wmi_keymap_type_0010[i]; |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 570 | |
| 571 | /* |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 572 | * Check if we've already found this scancode. This takes |
| 573 | * quadratic time, but it doesn't matter unless the list |
| 574 | * of extra keys gets very long. |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 575 | */ |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 576 | if (dmi_results.keymap_size && |
| 577 | have_scancode(entry->code | (0x0010 << 16), |
| 578 | keymap, dmi_results.keymap_size) |
| 579 | ) |
| 580 | continue; |
| 581 | |
| 582 | keymap[pos] = *entry; |
| 583 | keymap[pos].code |= (0x0010 << 16); |
| 584 | pos++; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 585 | } |
Pali Rohár | e075b3c | 2016-06-15 21:49:13 +0200 | [diff] [blame] | 586 | |
| 587 | /* Append table with events of type 0x0011 */ |
| 588 | for (i = 0; i < ARRAY_SIZE(dell_wmi_keymap_type_0011); i++) { |
| 589 | keymap[pos] = dell_wmi_keymap_type_0011[i]; |
| 590 | keymap[pos].code |= (0x0011 << 16); |
| 591 | pos++; |
| 592 | } |
| 593 | |
| 594 | /* |
| 595 | * Now append also table with "legacy" events of type 0x0000. Some of |
| 596 | * them are reported also on laptops which have scancodes in DMI. |
| 597 | */ |
| 598 | for (i = 0; i < ARRAY_SIZE(dell_wmi_keymap_type_0000); i++) { |
| 599 | keymap[pos] = dell_wmi_keymap_type_0000[i]; |
| 600 | pos++; |
| 601 | } |
| 602 | |
| 603 | keymap[pos].type = KE_END; |
| 604 | |
| 605 | err = sparse_keymap_setup(dell_wmi_input_dev, keymap, NULL); |
| 606 | /* |
| 607 | * Sparse keymap library makes a copy of keymap so we don't need the |
| 608 | * original one that was allocated. |
| 609 | */ |
| 610 | kfree(keymap); |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 611 | if (err) |
| 612 | goto err_free_dev; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 613 | |
| 614 | err = input_register_device(dell_wmi_input_dev); |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 615 | if (err) |
Michał Kępień | 815edfe | 2017-03-09 13:11:41 +0100 | [diff] [blame] | 616 | goto err_free_dev; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 617 | |
| 618 | return 0; |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 619 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 620 | err_free_dev: |
| 621 | input_free_device(dell_wmi_input_dev); |
| 622 | return err; |
| 623 | } |
| 624 | |
Pali Rohár | 595773a4 | 2016-01-04 22:26:35 +0100 | [diff] [blame] | 625 | /* |
| 626 | * Descriptor buffer is 128 byte long and contains: |
| 627 | * |
| 628 | * Name Offset Length Value |
| 629 | * Vendor Signature 0 4 "DELL" |
| 630 | * Object Signature 4 4 " WMI" |
| 631 | * WMI Interface Version 8 4 <version> |
| 632 | * WMI buffer length 12 4 4096 |
| 633 | */ |
| 634 | static int __init dell_wmi_check_descriptor_buffer(void) |
| 635 | { |
| 636 | struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 637 | union acpi_object *obj; |
| 638 | acpi_status status; |
| 639 | u32 *buffer; |
| 640 | |
| 641 | status = wmi_query_block(DELL_DESCRIPTOR_GUID, 0, &out); |
| 642 | if (ACPI_FAILURE(status)) { |
| 643 | pr_err("Cannot read Dell descriptor buffer - %d\n", status); |
| 644 | return status; |
| 645 | } |
| 646 | |
| 647 | obj = (union acpi_object *)out.pointer; |
| 648 | if (!obj) { |
| 649 | pr_err("Dell descriptor buffer is empty\n"); |
| 650 | return -EINVAL; |
| 651 | } |
| 652 | |
| 653 | if (obj->type != ACPI_TYPE_BUFFER) { |
| 654 | pr_err("Cannot read Dell descriptor buffer\n"); |
| 655 | kfree(obj); |
| 656 | return -EINVAL; |
| 657 | } |
| 658 | |
| 659 | if (obj->buffer.length != 128) { |
| 660 | pr_err("Dell descriptor buffer has invalid length (%d)\n", |
| 661 | obj->buffer.length); |
| 662 | if (obj->buffer.length < 16) { |
| 663 | kfree(obj); |
| 664 | return -EINVAL; |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | buffer = (u32 *)obj->buffer.pointer; |
| 669 | |
| 670 | if (buffer[0] != 0x4C4C4544 && buffer[1] != 0x494D5720) |
| 671 | pr_warn("Dell descriptor buffer has invalid signature (%*ph)\n", |
| 672 | 8, buffer); |
| 673 | |
| 674 | if (buffer[2] != 0 && buffer[2] != 1) |
| 675 | pr_warn("Dell descriptor buffer has unknown version (%d)\n", |
| 676 | buffer[2]); |
| 677 | |
| 678 | if (buffer[3] != 4096) |
| 679 | pr_warn("Dell descriptor buffer has invalid buffer length (%d)\n", |
| 680 | buffer[3]); |
| 681 | |
| 682 | dell_wmi_interface_version = buffer[2]; |
| 683 | |
| 684 | pr_info("Detected Dell WMI interface version %u\n", |
| 685 | dell_wmi_interface_version); |
| 686 | |
| 687 | kfree(obj); |
| 688 | return 0; |
| 689 | } |
| 690 | |
Michał Kępień | e09c4d5 | 2016-03-04 14:09:08 +0100 | [diff] [blame] | 691 | /* |
| 692 | * According to Dell SMBIOS documentation: |
| 693 | * |
| 694 | * 17 3 Application Program Registration |
| 695 | * |
| 696 | * cbArg1 Application ID 1 = 0x00010000 |
| 697 | * cbArg2 Application ID 2 |
| 698 | * QUICKSET/DCP = 0x51534554 "QSET" |
| 699 | * ALS Driver = 0x416c7353 "AlsS" |
| 700 | * Latitude ON = 0x4c6f6e52 "LonR" |
| 701 | * cbArg3 Application version or revision number |
| 702 | * cbArg4 0 = Unregister application |
| 703 | * 1 = Register application |
| 704 | * cbRes1 Standard return codes (0, -1, -2) |
| 705 | */ |
| 706 | |
| 707 | static int dell_wmi_events_set_enabled(bool enable) |
| 708 | { |
| 709 | struct calling_interface_buffer *buffer; |
| 710 | int ret; |
| 711 | |
| 712 | buffer = dell_smbios_get_buffer(); |
| 713 | buffer->input[0] = 0x10000; |
| 714 | buffer->input[1] = 0x51534554; |
| 715 | buffer->input[3] = enable; |
| 716 | dell_smbios_send_request(17, 3); |
| 717 | ret = buffer->output[0]; |
| 718 | dell_smbios_release_buffer(); |
| 719 | |
| 720 | return dell_smbios_error(ret); |
| 721 | } |
| 722 | |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 723 | static int __init dell_wmi_init(void) |
| 724 | { |
| 725 | int err; |
Len Brown | abb631b | 2009-12-26 21:51:38 -0500 | [diff] [blame] | 726 | acpi_status status; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 727 | |
Pali Rohár | 595773a4 | 2016-01-04 22:26:35 +0100 | [diff] [blame] | 728 | if (!wmi_has_guid(DELL_EVENT_GUID) || |
| 729 | !wmi_has_guid(DELL_DESCRIPTOR_GUID)) { |
| 730 | pr_warn("Dell WMI GUID were not found\n"); |
Dmitry Torokhov | 1fdd407 | 2009-12-17 22:19:42 -0800 | [diff] [blame] | 731 | return -ENODEV; |
| 732 | } |
| 733 | |
Pali Rohár | 595773a4 | 2016-01-04 22:26:35 +0100 | [diff] [blame] | 734 | err = dell_wmi_check_descriptor_buffer(); |
| 735 | if (err) |
| 736 | return err; |
| 737 | |
Dmitry Torokhov | 1fdd407 | 2009-12-17 22:19:42 -0800 | [diff] [blame] | 738 | err = dell_wmi_input_setup(); |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 739 | if (err) |
Dmitry Torokhov | 1fdd407 | 2009-12-17 22:19:42 -0800 | [diff] [blame] | 740 | return err; |
| 741 | |
Len Brown | abb631b | 2009-12-26 21:51:38 -0500 | [diff] [blame] | 742 | status = wmi_install_notify_handler(DELL_EVENT_GUID, |
Dmitry Torokhov | 1fdd407 | 2009-12-17 22:19:42 -0800 | [diff] [blame] | 743 | dell_wmi_notify, NULL); |
Len Brown | abb631b | 2009-12-26 21:51:38 -0500 | [diff] [blame] | 744 | if (ACPI_FAILURE(status)) { |
Michał Kępień | 815edfe | 2017-03-09 13:11:41 +0100 | [diff] [blame] | 745 | input_unregister_device(dell_wmi_input_dev); |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 746 | pr_err("Unable to register notify handler - %d\n", status); |
Len Brown | abb631b | 2009-12-26 21:51:38 -0500 | [diff] [blame] | 747 | return -ENODEV; |
Dmitry Torokhov | 1fdd407 | 2009-12-17 22:19:42 -0800 | [diff] [blame] | 748 | } |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 749 | |
Michał Kępień | e09c4d5 | 2016-03-04 14:09:08 +0100 | [diff] [blame] | 750 | dmi_check_system(dell_wmi_smbios_list); |
| 751 | |
| 752 | if (wmi_requires_smbios_request) { |
| 753 | err = dell_wmi_events_set_enabled(true); |
| 754 | if (err) { |
| 755 | pr_err("Failed to enable WMI events\n"); |
| 756 | wmi_remove_notify_handler(DELL_EVENT_GUID); |
Michał Kępień | 815edfe | 2017-03-09 13:11:41 +0100 | [diff] [blame] | 757 | input_unregister_device(dell_wmi_input_dev); |
Michał Kępień | e09c4d5 | 2016-03-04 14:09:08 +0100 | [diff] [blame] | 758 | return err; |
| 759 | } |
| 760 | } |
| 761 | |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 762 | return 0; |
| 763 | } |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 764 | module_init(dell_wmi_init); |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 765 | |
| 766 | static void __exit dell_wmi_exit(void) |
| 767 | { |
Michał Kępień | e09c4d5 | 2016-03-04 14:09:08 +0100 | [diff] [blame] | 768 | if (wmi_requires_smbios_request) |
| 769 | dell_wmi_events_set_enabled(false); |
Dmitry Torokhov | 1fdd407 | 2009-12-17 22:19:42 -0800 | [diff] [blame] | 770 | wmi_remove_notify_handler(DELL_EVENT_GUID); |
Michał Kępień | 815edfe | 2017-03-09 13:11:41 +0100 | [diff] [blame] | 771 | input_unregister_device(dell_wmi_input_dev); |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 772 | } |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 773 | module_exit(dell_wmi_exit); |