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> |
| 5 | * |
| 6 | * Portions based on wistron_btns.c: |
| 7 | * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz> |
| 8 | * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org> |
| 9 | * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | */ |
| 25 | |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 26 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 27 | |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 28 | #include <linux/kernel.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 32 | #include <linux/types.h> |
| 33 | #include <linux/input.h> |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 34 | #include <linux/input/sparse-keymap.h> |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 35 | #include <linux/acpi.h> |
| 36 | #include <linux/string.h> |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 37 | #include <linux/dmi.h> |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 38 | |
| 39 | MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); |
| 40 | MODULE_DESCRIPTION("Dell laptop WMI hotkeys driver"); |
| 41 | MODULE_LICENSE("GPL"); |
| 42 | |
| 43 | #define DELL_EVENT_GUID "9DBB5994-A997-11DA-B012-B622A1EF5492" |
| 44 | |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 45 | static int acpi_video; |
| 46 | |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 47 | MODULE_ALIAS("wmi:"DELL_EVENT_GUID); |
| 48 | |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 49 | /* |
| 50 | * Certain keys are flagged as KE_IGNORE. All of these are either |
| 51 | * notifications (rather than requests for change) or are also sent |
| 52 | * via the keyboard controller so should not be sent again. |
| 53 | */ |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 54 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 55 | static const struct key_entry dell_wmi_legacy_keymap[] __initconst = { |
Seth Forshee | f1566f0 | 2011-08-01 15:46:10 -0500 | [diff] [blame] | 56 | { KE_IGNORE, 0x003a, { KEY_CAPSLOCK } }, |
| 57 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 58 | { KE_KEY, 0xe045, { KEY_PROG1 } }, |
| 59 | { KE_KEY, 0xe009, { KEY_EJECTCD } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 60 | |
| 61 | /* These also contain the brightness level at offset 6 */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 62 | { KE_KEY, 0xe006, { KEY_BRIGHTNESSUP } }, |
| 63 | { KE_KEY, 0xe005, { KEY_BRIGHTNESSDOWN } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 64 | |
| 65 | /* Battery health status button */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 66 | { KE_KEY, 0xe007, { KEY_BATTERY } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 67 | |
| 68 | /* This is actually for all radios. Although physically a |
| 69 | * switch, the notification does not provide an indication of |
| 70 | * state and so it should be reported as a key */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 71 | { KE_KEY, 0xe008, { KEY_WLAN } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 72 | |
| 73 | /* The next device is at offset 6, the active devices are at |
| 74 | offset 8 and the attached devices at offset 10 */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 75 | { KE_KEY, 0xe00b, { KEY_SWITCHVIDEOMODE } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 76 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 77 | { KE_IGNORE, 0xe00c, { KEY_KBDILLUMTOGGLE } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 78 | |
| 79 | /* BIOS error detected */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 80 | { KE_IGNORE, 0xe00d, { KEY_RESERVED } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 81 | |
| 82 | /* Wifi Catcher */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 83 | { KE_KEY, 0xe011, {KEY_PROG2 } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 84 | |
| 85 | /* Ambient light sensor toggle */ |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 86 | { KE_IGNORE, 0xe013, { KEY_RESERVED } }, |
Mario Limonciello | 5cab009 | 2009-06-10 19:40:47 +0000 | [diff] [blame] | 87 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 88 | { KE_IGNORE, 0xe020, { KEY_MUTE } }, |
Seth Forshee | f1566f0 | 2011-08-01 15:46:10 -0500 | [diff] [blame] | 89 | |
| 90 | /* Shortcut and audio panel keys */ |
| 91 | { KE_IGNORE, 0xe025, { KEY_RESERVED } }, |
| 92 | { KE_IGNORE, 0xe026, { KEY_RESERVED } }, |
| 93 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 94 | { KE_IGNORE, 0xe02e, { KEY_VOLUMEDOWN } }, |
| 95 | { KE_IGNORE, 0xe030, { KEY_VOLUMEUP } }, |
| 96 | { KE_IGNORE, 0xe033, { KEY_KBDILLUMUP } }, |
| 97 | { KE_IGNORE, 0xe034, { KEY_KBDILLUMDOWN } }, |
| 98 | { KE_IGNORE, 0xe03a, { KEY_CAPSLOCK } }, |
| 99 | { KE_IGNORE, 0xe045, { KEY_NUMLOCK } }, |
| 100 | { KE_IGNORE, 0xe046, { KEY_SCROLLLOCK } }, |
Seth Forshee | f1566f0 | 2011-08-01 15:46:10 -0500 | [diff] [blame] | 101 | { KE_IGNORE, 0xe0f7, { KEY_MUTE } }, |
| 102 | { KE_IGNORE, 0xe0f8, { KEY_VOLUMEDOWN } }, |
| 103 | { KE_IGNORE, 0xe0f9, { KEY_VOLUMEUP } }, |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 104 | { KE_END, 0 } |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 107 | static bool dell_new_hk_type; |
| 108 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 109 | struct dell_bios_keymap_entry { |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 110 | u16 scancode; |
| 111 | u16 keycode; |
| 112 | }; |
| 113 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 114 | struct dell_bios_hotkey_table { |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 115 | struct dmi_header header; |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 116 | struct dell_bios_keymap_entry keymap[]; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 117 | |
| 118 | }; |
| 119 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 120 | static const struct dell_bios_hotkey_table *dell_bios_hotkey_table; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 121 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 122 | static const u16 bios_to_linux_keycode[256] __initconst = { |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 123 | |
| 124 | KEY_MEDIA, KEY_NEXTSONG, KEY_PLAYPAUSE, KEY_PREVIOUSSONG, |
| 125 | KEY_STOPCD, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 126 | KEY_WWW, KEY_UNKNOWN, KEY_VOLUMEDOWN, KEY_MUTE, |
| 127 | KEY_VOLUMEUP, KEY_UNKNOWN, KEY_BATTERY, KEY_EJECTCD, |
| 128 | KEY_UNKNOWN, KEY_SLEEP, KEY_PROG1, KEY_BRIGHTNESSDOWN, |
| 129 | KEY_BRIGHTNESSUP, KEY_UNKNOWN, KEY_KBDILLUMTOGGLE, |
| 130 | KEY_UNKNOWN, KEY_SWITCHVIDEOMODE, KEY_UNKNOWN, KEY_UNKNOWN, |
| 131 | KEY_SWITCHVIDEOMODE, KEY_UNKNOWN, KEY_UNKNOWN, KEY_PROG2, |
Alex Hung | cfb743b | 2013-11-12 11:09:22 +0800 | [diff] [blame] | 132 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, |
| 133 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_MICMUTE, |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 134 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 135 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 136 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 137 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 138 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 139 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 140 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 141 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
Alex Hung | cfb743b | 2013-11-12 11:09:22 +0800 | [diff] [blame] | 142 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 143 | 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_PROG3 |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 144 | }; |
| 145 | |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 146 | static struct input_dev *dell_wmi_input_dev; |
| 147 | |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 148 | static void dell_wmi_notify(u32 value, void *context) |
| 149 | { |
| 150 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 151 | union acpi_object *obj; |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 152 | acpi_status status; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 153 | |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 154 | status = wmi_get_event_data(value, &response); |
| 155 | if (status != AE_OK) { |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 156 | pr_info("bad event status 0x%x\n", status); |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 157 | return; |
| 158 | } |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 159 | |
| 160 | obj = (union acpi_object *)response.pointer; |
| 161 | |
| 162 | if (obj && obj->type == ACPI_TYPE_BUFFER) { |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 163 | const struct key_entry *key; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 164 | int reported_key; |
| 165 | u16 *buffer_entry = (u16 *)obj->buffer.pointer; |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 166 | |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 167 | if (dell_new_hk_type && (buffer_entry[1] != 0x10)) { |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 168 | pr_info("Received unknown WMI event (0x%x)\n", |
| 169 | buffer_entry[1]); |
Yong Wang | a0624a9 | 2010-04-05 21:09:40 +0800 | [diff] [blame] | 170 | kfree(obj); |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 171 | return; |
| 172 | } |
| 173 | |
Islam Amer | d5164db | 2010-06-24 13:39:47 -0400 | [diff] [blame] | 174 | if (dell_new_hk_type || buffer_entry[1] == 0x0) |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 175 | reported_key = (int)buffer_entry[2]; |
| 176 | else |
| 177 | reported_key = (int)buffer_entry[1] & 0xffff; |
| 178 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 179 | key = sparse_keymap_entry_from_scancode(dell_wmi_input_dev, |
| 180 | reported_key); |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 181 | if (!key) { |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 182 | pr_info("Unknown key %x pressed\n", reported_key); |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 183 | } else if ((key->keycode == KEY_BRIGHTNESSUP || |
| 184 | key->keycode == KEY_BRIGHTNESSDOWN) && acpi_video) { |
| 185 | /* Don't report brightness notifications that will also |
| 186 | * come via ACPI */ |
Yong Wang | a0624a9 | 2010-04-05 21:09:40 +0800 | [diff] [blame] | 187 | ; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 188 | } else { |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 189 | sparse_keymap_report_entry(dell_wmi_input_dev, key, |
| 190 | 1, true); |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 191 | } |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 192 | } |
Anisse Astier | 3e9b988 | 2009-12-04 10:10:09 +0100 | [diff] [blame] | 193 | kfree(obj); |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 196 | static const struct key_entry * __init dell_wmi_prepare_new_keymap(void) |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 197 | { |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 198 | int hotkey_num = (dell_bios_hotkey_table->header.length - 4) / |
| 199 | sizeof(struct dell_bios_keymap_entry); |
| 200 | struct key_entry *keymap; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 201 | int i; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 202 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 203 | keymap = kcalloc(hotkey_num + 1, sizeof(struct key_entry), GFP_KERNEL); |
| 204 | if (!keymap) |
| 205 | return NULL; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 206 | |
| 207 | for (i = 0; i < hotkey_num; i++) { |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 208 | const struct dell_bios_keymap_entry *bios_entry = |
| 209 | &dell_bios_hotkey_table->keymap[i]; |
| 210 | keymap[i].type = KE_KEY; |
| 211 | keymap[i].code = bios_entry->scancode; |
| 212 | keymap[i].keycode = bios_entry->keycode < 256 ? |
| 213 | bios_to_linux_keycode[bios_entry->keycode] : |
| 214 | KEY_RESERVED; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 215 | } |
| 216 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 217 | keymap[hotkey_num].type = KE_END; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 218 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 219 | return keymap; |
Rezwanul Kabir | 5ea2559 | 2009-11-02 12:00:42 -0500 | [diff] [blame] | 220 | } |
| 221 | |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 222 | static int __init dell_wmi_input_setup(void) |
| 223 | { |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 224 | int err; |
| 225 | |
| 226 | dell_wmi_input_dev = input_allocate_device(); |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 227 | if (!dell_wmi_input_dev) |
| 228 | return -ENOMEM; |
| 229 | |
| 230 | dell_wmi_input_dev->name = "Dell WMI hotkeys"; |
| 231 | dell_wmi_input_dev->phys = "wmi/input0"; |
| 232 | dell_wmi_input_dev->id.bustype = BUS_HOST; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 233 | |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 234 | if (dell_new_hk_type) { |
| 235 | const struct key_entry *keymap = dell_wmi_prepare_new_keymap(); |
| 236 | if (!keymap) { |
| 237 | err = -ENOMEM; |
| 238 | goto err_free_dev; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 239 | } |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 240 | |
| 241 | err = sparse_keymap_setup(dell_wmi_input_dev, keymap, NULL); |
| 242 | |
| 243 | /* |
| 244 | * Sparse keymap library makes a copy of keymap so we |
| 245 | * don't need the original one that was allocated. |
| 246 | */ |
| 247 | kfree(keymap); |
| 248 | } else { |
| 249 | err = sparse_keymap_setup(dell_wmi_input_dev, |
| 250 | dell_wmi_legacy_keymap, NULL); |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 251 | } |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 252 | if (err) |
| 253 | goto err_free_dev; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 254 | |
| 255 | err = input_register_device(dell_wmi_input_dev); |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 256 | if (err) |
| 257 | goto err_free_keymap; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 258 | |
| 259 | return 0; |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 260 | |
| 261 | err_free_keymap: |
| 262 | sparse_keymap_free(dell_wmi_input_dev); |
| 263 | err_free_dev: |
| 264 | input_free_device(dell_wmi_input_dev); |
| 265 | return err; |
| 266 | } |
| 267 | |
| 268 | static void dell_wmi_input_destroy(void) |
| 269 | { |
| 270 | sparse_keymap_free(dell_wmi_input_dev); |
| 271 | input_unregister_device(dell_wmi_input_dev); |
| 272 | } |
| 273 | |
| 274 | static void __init find_hk_type(const struct dmi_header *dm, void *dummy) |
| 275 | { |
| 276 | if (dm->type == 0xb2 && dm->length > 6) { |
| 277 | dell_new_hk_type = true; |
| 278 | dell_bios_hotkey_table = |
| 279 | container_of(dm, struct dell_bios_hotkey_table, header); |
| 280 | } |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | static int __init dell_wmi_init(void) |
| 284 | { |
| 285 | int err; |
Len Brown | abb631b | 2009-12-26 21:51:38 -0500 | [diff] [blame] | 286 | acpi_status status; |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 287 | |
Dmitry Torokhov | 7a9568f | 2009-12-25 11:49:35 -0800 | [diff] [blame] | 288 | if (!wmi_has_guid(DELL_EVENT_GUID)) { |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 289 | pr_warn("No known WMI GUID found\n"); |
Dmitry Torokhov | 1fdd407 | 2009-12-17 22:19:42 -0800 | [diff] [blame] | 290 | return -ENODEV; |
| 291 | } |
| 292 | |
| 293 | dmi_walk(find_hk_type, NULL); |
| 294 | acpi_video = acpi_video_backlight_support(); |
| 295 | |
| 296 | err = dell_wmi_input_setup(); |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 297 | if (err) |
Dmitry Torokhov | 1fdd407 | 2009-12-17 22:19:42 -0800 | [diff] [blame] | 298 | return err; |
| 299 | |
Len Brown | abb631b | 2009-12-26 21:51:38 -0500 | [diff] [blame] | 300 | status = wmi_install_notify_handler(DELL_EVENT_GUID, |
Dmitry Torokhov | 1fdd407 | 2009-12-17 22:19:42 -0800 | [diff] [blame] | 301 | dell_wmi_notify, NULL); |
Len Brown | abb631b | 2009-12-26 21:51:38 -0500 | [diff] [blame] | 302 | if (ACPI_FAILURE(status)) { |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 303 | dell_wmi_input_destroy(); |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 304 | pr_err("Unable to register notify handler - %d\n", status); |
Len Brown | abb631b | 2009-12-26 21:51:38 -0500 | [diff] [blame] | 305 | return -ENODEV; |
Dmitry Torokhov | 1fdd407 | 2009-12-17 22:19:42 -0800 | [diff] [blame] | 306 | } |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 307 | |
| 308 | return 0; |
| 309 | } |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 310 | module_init(dell_wmi_init); |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 311 | |
| 312 | static void __exit dell_wmi_exit(void) |
| 313 | { |
Dmitry Torokhov | 1fdd407 | 2009-12-17 22:19:42 -0800 | [diff] [blame] | 314 | wmi_remove_notify_handler(DELL_EVENT_GUID); |
Dmitry Torokhov | 890a7c8 | 2010-08-04 22:30:08 -0700 | [diff] [blame] | 315 | dell_wmi_input_destroy(); |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 316 | } |
Matthew Garrett | 0b3f610 | 2009-01-09 20:17:11 +0000 | [diff] [blame] | 317 | module_exit(dell_wmi_exit); |