Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Eee PC WMI hotkey driver |
| 3 | * |
| 4 | * Copyright(C) 2010 Intel Corporation. |
| 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 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 26 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 27 | |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 28 | #include <linux/kernel.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/types.h> |
Tejun Heo | a32f392 | 2010-04-05 11:37:59 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 33 | #include <linux/input.h> |
| 34 | #include <linux/input/sparse-keymap.h> |
| 35 | #include <acpi/acpi_bus.h> |
| 36 | #include <acpi/acpi_drivers.h> |
| 37 | |
| 38 | MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>"); |
| 39 | MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver"); |
| 40 | MODULE_LICENSE("GPL"); |
| 41 | |
| 42 | #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000" |
| 43 | |
| 44 | MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID); |
| 45 | |
| 46 | #define NOTIFY_BRNUP_MIN 0x11 |
| 47 | #define NOTIFY_BRNUP_MAX 0x1f |
| 48 | #define NOTIFY_BRNDOWN_MIN 0x20 |
| 49 | #define NOTIFY_BRNDOWN_MAX 0x2e |
| 50 | |
| 51 | static const struct key_entry eeepc_wmi_keymap[] = { |
| 52 | /* Sleep already handled via generic ACPI code */ |
| 53 | { KE_KEY, 0x5d, { KEY_WLAN } }, |
| 54 | { KE_KEY, 0x32, { KEY_MUTE } }, |
| 55 | { KE_KEY, 0x31, { KEY_VOLUMEDOWN } }, |
| 56 | { KE_KEY, 0x30, { KEY_VOLUMEUP } }, |
| 57 | { KE_IGNORE, NOTIFY_BRNDOWN_MIN, { KEY_BRIGHTNESSDOWN } }, |
| 58 | { KE_IGNORE, NOTIFY_BRNUP_MIN, { KEY_BRIGHTNESSUP } }, |
| 59 | { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } }, |
| 60 | { KE_END, 0}, |
| 61 | }; |
| 62 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 63 | struct eeepc_wmi { |
| 64 | struct input_dev *inputdev; |
| 65 | }; |
| 66 | |
| 67 | static struct eeepc_wmi *eeepc; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 68 | |
| 69 | static void eeepc_wmi_notify(u32 value, void *context) |
| 70 | { |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 71 | struct eeepc_wmi *eeepc = context; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 72 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 73 | union acpi_object *obj; |
| 74 | acpi_status status; |
| 75 | int code; |
| 76 | |
| 77 | status = wmi_get_event_data(value, &response); |
| 78 | if (status != AE_OK) { |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 79 | pr_err("bad event status 0x%x\n", status); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 80 | return; |
| 81 | } |
| 82 | |
| 83 | obj = (union acpi_object *)response.pointer; |
| 84 | |
| 85 | if (obj && obj->type == ACPI_TYPE_INTEGER) { |
| 86 | code = obj->integer.value; |
| 87 | |
| 88 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) |
| 89 | code = NOTIFY_BRNUP_MIN; |
| 90 | else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) |
| 91 | code = NOTIFY_BRNDOWN_MIN; |
| 92 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 93 | if (!sparse_keymap_report_event(eeepc->inputdev, |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 94 | code, 1, true)) |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 95 | pr_info("Unknown key %x pressed\n", code); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | kfree(obj); |
| 99 | } |
| 100 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 101 | static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 102 | { |
| 103 | int err; |
| 104 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 105 | eeepc->inputdev = input_allocate_device(); |
| 106 | if (!eeepc->inputdev) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 107 | return -ENOMEM; |
| 108 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 109 | eeepc->inputdev->name = "Eee PC WMI hotkeys"; |
| 110 | eeepc->inputdev->phys = "wmi/input0"; |
| 111 | eeepc->inputdev->id.bustype = BUS_HOST; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 112 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 113 | err = sparse_keymap_setup(eeepc->inputdev, eeepc_wmi_keymap, NULL); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 114 | if (err) |
| 115 | goto err_free_dev; |
| 116 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 117 | err = input_register_device(eeepc->inputdev); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 118 | if (err) |
| 119 | goto err_free_keymap; |
| 120 | |
| 121 | return 0; |
| 122 | |
| 123 | err_free_keymap: |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 124 | sparse_keymap_free(eeepc->inputdev); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 125 | err_free_dev: |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 126 | input_free_device(eeepc->inputdev); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 127 | return err; |
| 128 | } |
| 129 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 130 | static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc) |
| 131 | { |
| 132 | if (eeepc->inputdev) { |
| 133 | sparse_keymap_free(eeepc->inputdev); |
| 134 | input_unregister_device(eeepc->inputdev); |
| 135 | } |
| 136 | |
| 137 | eeepc->inputdev = NULL; |
| 138 | } |
| 139 | |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 140 | static int __init eeepc_wmi_init(void) |
| 141 | { |
| 142 | int err; |
| 143 | acpi_status status; |
| 144 | |
| 145 | if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID)) { |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 146 | pr_warning("No known WMI GUID found\n"); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 147 | return -ENODEV; |
| 148 | } |
| 149 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 150 | eeepc = kzalloc(sizeof(struct eeepc_wmi), GFP_KERNEL); |
| 151 | if (!eeepc) |
| 152 | return -ENOMEM; |
| 153 | |
| 154 | err = eeepc_wmi_input_init(eeepc); |
| 155 | if (err) { |
| 156 | kfree(eeepc); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 157 | return err; |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 158 | } |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 159 | |
| 160 | status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID, |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 161 | eeepc_wmi_notify, eeepc); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 162 | if (ACPI_FAILURE(status)) { |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 163 | pr_err("Unable to register notify handler - %d\n", |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 164 | status); |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 165 | eeepc_wmi_input_exit(eeepc); |
| 166 | kfree(eeepc); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 167 | return -ENODEV; |
| 168 | } |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | static void __exit eeepc_wmi_exit(void) |
| 174 | { |
| 175 | wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame^] | 176 | eeepc_wmi_input_exit(eeepc); |
| 177 | kfree(eeepc); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | module_init(eeepc_wmi_init); |
| 181 | module_exit(eeepc_wmi_exit); |