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