Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * HP 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 | |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 30 | #include <linux/types.h> |
| 31 | #include <linux/input.h> |
| 32 | #include <acpi/acpi_drivers.h> |
| 33 | #include <linux/platform_device.h> |
| 34 | #include <linux/acpi.h> |
| 35 | #include <linux/rfkill.h> |
| 36 | #include <linux/string.h> |
| 37 | |
| 38 | MODULE_AUTHOR("Matthew Garrett <mjg59@srcf.ucam.org>"); |
| 39 | MODULE_DESCRIPTION("HP laptop WMI hotkeys driver"); |
| 40 | MODULE_LICENSE("GPL"); |
| 41 | |
| 42 | MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C"); |
| 43 | MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4"); |
| 44 | |
| 45 | #define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C" |
| 46 | #define HPWMI_BIOS_GUID "5FB7F034-2C63-45e9-BE91-3D44E2C707E4" |
| 47 | |
| 48 | #define HPWMI_DISPLAY_QUERY 0x1 |
| 49 | #define HPWMI_HDDTEMP_QUERY 0x2 |
| 50 | #define HPWMI_ALS_QUERY 0x3 |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 51 | #define HPWMI_HARDWARE_QUERY 0x4 |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 52 | #define HPWMI_WIRELESS_QUERY 0x5 |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 53 | #define HPWMI_HOTKEY_QUERY 0xc |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 54 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 55 | enum hp_wmi_radio { |
| 56 | HPWMI_WIFI = 0, |
| 57 | HPWMI_BLUETOOTH = 1, |
| 58 | HPWMI_WWAN = 2, |
| 59 | }; |
| 60 | |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame^] | 61 | enum hp_wmi_event_ids { |
| 62 | HPWMI_DOCK_EVENT = 1, |
| 63 | HPWMI_BEZEL_BUTTON = 4, |
| 64 | HPWMI_WIRELESS = 5, |
| 65 | }; |
| 66 | |
Uwe Kleine-König | ea79632 | 2010-02-04 20:56:52 +0100 | [diff] [blame] | 67 | static int __devinit hp_wmi_bios_setup(struct platform_device *device); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 68 | static int __exit hp_wmi_bios_remove(struct platform_device *device); |
Frans Pop | 8dd2b42 | 2009-08-20 20:38:13 +0200 | [diff] [blame] | 69 | static int hp_wmi_resume_handler(struct device *device); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 70 | |
| 71 | struct bios_args { |
| 72 | u32 signature; |
| 73 | u32 command; |
| 74 | u32 commandtype; |
| 75 | u32 datasize; |
| 76 | u32 data; |
| 77 | }; |
| 78 | |
| 79 | struct bios_return { |
| 80 | u32 sigpass; |
| 81 | u32 return_code; |
| 82 | u32 value; |
| 83 | }; |
| 84 | |
| 85 | struct key_entry { |
| 86 | char type; /* See KE_* below */ |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 87 | u16 code; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 88 | u16 keycode; |
| 89 | }; |
| 90 | |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 91 | enum { KE_KEY, KE_END }; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 92 | |
| 93 | static struct key_entry hp_wmi_keymap[] = { |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 94 | {KE_KEY, 0x02, KEY_BRIGHTNESSUP}, |
| 95 | {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN}, |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 96 | {KE_KEY, 0x20e6, KEY_PROG1}, |
| 97 | {KE_KEY, 0x2142, KEY_MEDIA}, |
Eric Piel | 5c62484 | 2008-10-18 20:27:28 -0700 | [diff] [blame] | 98 | {KE_KEY, 0x213b, KEY_INFO}, |
Matthew Garrett | caeacf5 | 2010-02-17 10:29:39 -0500 | [diff] [blame] | 99 | {KE_KEY, 0x2169, KEY_DIRECTION}, |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 100 | {KE_KEY, 0x231b, KEY_HELP}, |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 101 | {KE_END, 0} |
| 102 | }; |
| 103 | |
| 104 | static struct input_dev *hp_wmi_input_dev; |
| 105 | static struct platform_device *hp_wmi_platform_dev; |
| 106 | |
| 107 | static struct rfkill *wifi_rfkill; |
| 108 | static struct rfkill *bluetooth_rfkill; |
| 109 | static struct rfkill *wwan_rfkill; |
| 110 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 111 | static const struct dev_pm_ops hp_wmi_pm_ops = { |
Frans Pop | 8dd2b42 | 2009-08-20 20:38:13 +0200 | [diff] [blame] | 112 | .resume = hp_wmi_resume_handler, |
| 113 | .restore = hp_wmi_resume_handler, |
| 114 | }; |
| 115 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 116 | static struct platform_driver hp_wmi_driver = { |
| 117 | .driver = { |
Frans Pop | 8dd2b42 | 2009-08-20 20:38:13 +0200 | [diff] [blame] | 118 | .name = "hp-wmi", |
| 119 | .owner = THIS_MODULE, |
| 120 | .pm = &hp_wmi_pm_ops, |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 121 | }, |
| 122 | .probe = hp_wmi_bios_setup, |
| 123 | .remove = hp_wmi_bios_remove, |
| 124 | }; |
| 125 | |
| 126 | static int hp_wmi_perform_query(int query, int write, int value) |
| 127 | { |
| 128 | struct bios_return bios_return; |
| 129 | acpi_status status; |
| 130 | union acpi_object *obj; |
| 131 | struct bios_args args = { |
| 132 | .signature = 0x55434553, |
| 133 | .command = write ? 0x2 : 0x1, |
| 134 | .commandtype = query, |
| 135 | .datasize = write ? 0x4 : 0, |
| 136 | .data = value, |
| 137 | }; |
| 138 | struct acpi_buffer input = { sizeof(struct bios_args), &args }; |
| 139 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 140 | |
| 141 | status = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output); |
| 142 | |
| 143 | obj = output.pointer; |
| 144 | |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 145 | if (!obj) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 146 | return -EINVAL; |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 147 | else if (obj->type != ACPI_TYPE_BUFFER) { |
| 148 | kfree(obj); |
| 149 | return -EINVAL; |
| 150 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 151 | |
| 152 | bios_return = *((struct bios_return *)obj->buffer.pointer); |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 153 | kfree(obj); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 154 | if (bios_return.return_code > 0) |
| 155 | return bios_return.return_code * -1; |
| 156 | else |
| 157 | return bios_return.value; |
| 158 | } |
| 159 | |
| 160 | static int hp_wmi_display_state(void) |
| 161 | { |
| 162 | return hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, 0); |
| 163 | } |
| 164 | |
| 165 | static int hp_wmi_hddtemp_state(void) |
| 166 | { |
| 167 | return hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, 0); |
| 168 | } |
| 169 | |
| 170 | static int hp_wmi_als_state(void) |
| 171 | { |
| 172 | return hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, 0); |
| 173 | } |
| 174 | |
| 175 | static int hp_wmi_dock_state(void) |
| 176 | { |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 177 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0); |
| 178 | |
| 179 | if (ret < 0) |
| 180 | return ret; |
| 181 | |
| 182 | return ret & 0x1; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 185 | static int hp_wmi_tablet_state(void) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 186 | { |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 187 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0); |
| 188 | |
| 189 | if (ret < 0) |
| 190 | return ret; |
| 191 | |
| 192 | return (ret & 0x4) ? 1 : 0; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 195 | static int hp_wmi_set_block(void *data, bool blocked) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 196 | { |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 197 | enum hp_wmi_radio r = (enum hp_wmi_radio) data; |
| 198 | int query = BIT(r + 8) | ((!blocked) << r); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 199 | |
| 200 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 203 | static const struct rfkill_ops hp_wmi_rfkill_ops = { |
| 204 | .set_block = hp_wmi_set_block, |
| 205 | }; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 206 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 207 | static bool hp_wmi_get_sw_state(enum hp_wmi_radio r) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 208 | { |
| 209 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 210 | int mask = 0x200 << (r * 8); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 211 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 212 | if (wireless & mask) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 213 | return false; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 214 | else |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 215 | return true; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 218 | static bool hp_wmi_get_hw_state(enum hp_wmi_radio r) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 219 | { |
| 220 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 221 | int mask = 0x800 << (r * 8); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 222 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 223 | if (wireless & mask) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 224 | return false; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 225 | else |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 226 | return true; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, |
| 230 | char *buf) |
| 231 | { |
| 232 | int value = hp_wmi_display_state(); |
| 233 | if (value < 0) |
| 234 | return -EINVAL; |
| 235 | return sprintf(buf, "%d\n", value); |
| 236 | } |
| 237 | |
| 238 | static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr, |
| 239 | char *buf) |
| 240 | { |
| 241 | int value = hp_wmi_hddtemp_state(); |
| 242 | if (value < 0) |
| 243 | return -EINVAL; |
| 244 | return sprintf(buf, "%d\n", value); |
| 245 | } |
| 246 | |
| 247 | static ssize_t show_als(struct device *dev, struct device_attribute *attr, |
| 248 | char *buf) |
| 249 | { |
| 250 | int value = hp_wmi_als_state(); |
| 251 | if (value < 0) |
| 252 | return -EINVAL; |
| 253 | return sprintf(buf, "%d\n", value); |
| 254 | } |
| 255 | |
| 256 | static ssize_t show_dock(struct device *dev, struct device_attribute *attr, |
| 257 | char *buf) |
| 258 | { |
| 259 | int value = hp_wmi_dock_state(); |
| 260 | if (value < 0) |
| 261 | return -EINVAL; |
| 262 | return sprintf(buf, "%d\n", value); |
| 263 | } |
| 264 | |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 265 | static ssize_t show_tablet(struct device *dev, struct device_attribute *attr, |
| 266 | char *buf) |
| 267 | { |
| 268 | int value = hp_wmi_tablet_state(); |
| 269 | if (value < 0) |
| 270 | return -EINVAL; |
| 271 | return sprintf(buf, "%d\n", value); |
| 272 | } |
| 273 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 274 | static ssize_t set_als(struct device *dev, struct device_attribute *attr, |
| 275 | const char *buf, size_t count) |
| 276 | { |
| 277 | u32 tmp = simple_strtoul(buf, NULL, 10); |
| 278 | hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, tmp); |
| 279 | return count; |
| 280 | } |
| 281 | |
| 282 | static DEVICE_ATTR(display, S_IRUGO, show_display, NULL); |
| 283 | static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL); |
| 284 | static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als); |
| 285 | static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL); |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 286 | static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 287 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 288 | static struct key_entry *hp_wmi_get_entry_by_scancode(unsigned int code) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 289 | { |
| 290 | struct key_entry *key; |
| 291 | |
| 292 | for (key = hp_wmi_keymap; key->type != KE_END; key++) |
| 293 | if (code == key->code) |
| 294 | return key; |
| 295 | |
| 296 | return NULL; |
| 297 | } |
| 298 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 299 | static struct key_entry *hp_wmi_get_entry_by_keycode(unsigned int keycode) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 300 | { |
| 301 | struct key_entry *key; |
| 302 | |
| 303 | for (key = hp_wmi_keymap; key->type != KE_END; key++) |
| 304 | if (key->type == KE_KEY && keycode == key->keycode) |
| 305 | return key; |
| 306 | |
| 307 | return NULL; |
| 308 | } |
| 309 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 310 | static int hp_wmi_getkeycode(struct input_dev *dev, |
| 311 | unsigned int scancode, unsigned int *keycode) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 312 | { |
| 313 | struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode); |
| 314 | |
| 315 | if (key && key->type == KE_KEY) { |
| 316 | *keycode = key->keycode; |
| 317 | return 0; |
| 318 | } |
| 319 | |
| 320 | return -EINVAL; |
| 321 | } |
| 322 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 323 | static int hp_wmi_setkeycode(struct input_dev *dev, |
| 324 | unsigned int scancode, unsigned int keycode) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 325 | { |
| 326 | struct key_entry *key; |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 327 | unsigned int old_keycode; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 328 | |
| 329 | key = hp_wmi_get_entry_by_scancode(scancode); |
| 330 | if (key && key->type == KE_KEY) { |
| 331 | old_keycode = key->keycode; |
| 332 | key->keycode = keycode; |
| 333 | set_bit(keycode, dev->keybit); |
| 334 | if (!hp_wmi_get_entry_by_keycode(old_keycode)) |
| 335 | clear_bit(old_keycode, dev->keybit); |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | return -EINVAL; |
| 340 | } |
| 341 | |
Adrian Bunk | 88429a1 | 2008-10-15 22:05:17 -0700 | [diff] [blame] | 342 | static void hp_wmi_notify(u32 value, void *context) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 343 | { |
| 344 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 345 | static struct key_entry *key; |
| 346 | union acpi_object *obj; |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame^] | 347 | int eventcode, key_code; |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 348 | acpi_status status; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 349 | |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 350 | status = wmi_get_event_data(value, &response); |
| 351 | if (status != AE_OK) { |
| 352 | printk(KERN_INFO "hp-wmi: bad event status 0x%x\n", status); |
| 353 | return; |
| 354 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 355 | |
| 356 | obj = (union acpi_object *)response.pointer; |
| 357 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 358 | if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) { |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 359 | printk(KERN_INFO "HP WMI: Unknown response received\n"); |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 360 | kfree(obj); |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 361 | return; |
| 362 | } |
| 363 | |
| 364 | eventcode = *((u8 *) obj->buffer.pointer); |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 365 | kfree(obj); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame^] | 366 | switch (eventcode) { |
| 367 | case HPWMI_DOCK_EVENT: |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 368 | input_report_switch(hp_wmi_input_dev, SW_DOCK, |
| 369 | hp_wmi_dock_state()); |
| 370 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
| 371 | hp_wmi_tablet_state()); |
| 372 | input_sync(hp_wmi_input_dev); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame^] | 373 | break; |
| 374 | case HPWMI_BEZEL_BUTTON: |
| 375 | key_code = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, |
| 376 | 0); |
| 377 | key = hp_wmi_get_entry_by_scancode(key_code); |
| 378 | if (key) { |
| 379 | switch (key->type) { |
| 380 | case KE_KEY: |
| 381 | input_report_key(hp_wmi_input_dev, |
| 382 | key->keycode, 1); |
| 383 | input_sync(hp_wmi_input_dev); |
| 384 | input_report_key(hp_wmi_input_dev, |
| 385 | key->keycode, 0); |
| 386 | input_sync(hp_wmi_input_dev); |
| 387 | break; |
| 388 | } |
| 389 | } |
| 390 | break; |
| 391 | case HPWMI_WIRELESS: |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 392 | if (wifi_rfkill) |
| 393 | rfkill_set_states(wifi_rfkill, |
| 394 | hp_wmi_get_sw_state(HPWMI_WIFI), |
| 395 | hp_wmi_get_hw_state(HPWMI_WIFI)); |
| 396 | if (bluetooth_rfkill) |
| 397 | rfkill_set_states(bluetooth_rfkill, |
| 398 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH), |
| 399 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); |
| 400 | if (wwan_rfkill) |
| 401 | rfkill_set_states(wwan_rfkill, |
| 402 | hp_wmi_get_sw_state(HPWMI_WWAN), |
| 403 | hp_wmi_get_hw_state(HPWMI_WWAN)); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame^] | 404 | break; |
| 405 | default: |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 406 | printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n", |
| 407 | eventcode); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame^] | 408 | break; |
| 409 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | static int __init hp_wmi_input_setup(void) |
| 413 | { |
| 414 | struct key_entry *key; |
| 415 | int err; |
| 416 | |
| 417 | hp_wmi_input_dev = input_allocate_device(); |
| 418 | |
| 419 | hp_wmi_input_dev->name = "HP WMI hotkeys"; |
| 420 | hp_wmi_input_dev->phys = "wmi/input0"; |
| 421 | hp_wmi_input_dev->id.bustype = BUS_HOST; |
| 422 | hp_wmi_input_dev->getkeycode = hp_wmi_getkeycode; |
| 423 | hp_wmi_input_dev->setkeycode = hp_wmi_setkeycode; |
| 424 | |
| 425 | for (key = hp_wmi_keymap; key->type != KE_END; key++) { |
| 426 | switch (key->type) { |
| 427 | case KE_KEY: |
| 428 | set_bit(EV_KEY, hp_wmi_input_dev->evbit); |
| 429 | set_bit(key->keycode, hp_wmi_input_dev->keybit); |
| 430 | break; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 434 | set_bit(EV_SW, hp_wmi_input_dev->evbit); |
| 435 | set_bit(SW_DOCK, hp_wmi_input_dev->swbit); |
| 436 | set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit); |
| 437 | |
| 438 | /* Set initial hardware state */ |
| 439 | input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state()); |
| 440 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
| 441 | hp_wmi_tablet_state()); |
| 442 | input_sync(hp_wmi_input_dev); |
| 443 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 444 | err = input_register_device(hp_wmi_input_dev); |
| 445 | |
| 446 | if (err) { |
| 447 | input_free_device(hp_wmi_input_dev); |
| 448 | return err; |
| 449 | } |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | static void cleanup_sysfs(struct platform_device *device) |
| 455 | { |
| 456 | device_remove_file(&device->dev, &dev_attr_display); |
| 457 | device_remove_file(&device->dev, &dev_attr_hddtemp); |
| 458 | device_remove_file(&device->dev, &dev_attr_als); |
| 459 | device_remove_file(&device->dev, &dev_attr_dock); |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 460 | device_remove_file(&device->dev, &dev_attr_tablet); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Uwe Kleine-König | ea79632 | 2010-02-04 20:56:52 +0100 | [diff] [blame] | 463 | static int __devinit hp_wmi_bios_setup(struct platform_device *device) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 464 | { |
| 465 | int err; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 466 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 467 | |
| 468 | err = device_create_file(&device->dev, &dev_attr_display); |
| 469 | if (err) |
| 470 | goto add_sysfs_error; |
| 471 | err = device_create_file(&device->dev, &dev_attr_hddtemp); |
| 472 | if (err) |
| 473 | goto add_sysfs_error; |
| 474 | err = device_create_file(&device->dev, &dev_attr_als); |
| 475 | if (err) |
| 476 | goto add_sysfs_error; |
| 477 | err = device_create_file(&device->dev, &dev_attr_dock); |
| 478 | if (err) |
| 479 | goto add_sysfs_error; |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 480 | err = device_create_file(&device->dev, &dev_attr_tablet); |
| 481 | if (err) |
| 482 | goto add_sysfs_error; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 483 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 484 | if (wireless & 0x1) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 485 | wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev, |
| 486 | RFKILL_TYPE_WLAN, |
| 487 | &hp_wmi_rfkill_ops, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 488 | (void *) HPWMI_WIFI); |
| 489 | rfkill_init_sw_state(wifi_rfkill, |
| 490 | hp_wmi_get_sw_state(HPWMI_WIFI)); |
| 491 | rfkill_set_hw_state(wifi_rfkill, |
| 492 | hp_wmi_get_hw_state(HPWMI_WIFI)); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 493 | err = rfkill_register(wifi_rfkill); |
| 494 | if (err) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 495 | goto register_wifi_error; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 496 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 497 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 498 | if (wireless & 0x2) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 499 | bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev, |
| 500 | RFKILL_TYPE_BLUETOOTH, |
| 501 | &hp_wmi_rfkill_ops, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 502 | (void *) HPWMI_BLUETOOTH); |
| 503 | rfkill_init_sw_state(bluetooth_rfkill, |
| 504 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH)); |
| 505 | rfkill_set_hw_state(bluetooth_rfkill, |
| 506 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 507 | err = rfkill_register(bluetooth_rfkill); |
Frans Pop | 6989d56 | 2009-01-29 14:25:14 -0800 | [diff] [blame] | 508 | if (err) |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 509 | goto register_bluetooth_error; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 510 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 511 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 512 | if (wireless & 0x4) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 513 | wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev, |
| 514 | RFKILL_TYPE_WWAN, |
| 515 | &hp_wmi_rfkill_ops, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 516 | (void *) HPWMI_WWAN); |
| 517 | rfkill_init_sw_state(wwan_rfkill, |
| 518 | hp_wmi_get_sw_state(HPWMI_WWAN)); |
| 519 | rfkill_set_hw_state(wwan_rfkill, |
| 520 | hp_wmi_get_hw_state(HPWMI_WWAN)); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 521 | err = rfkill_register(wwan_rfkill); |
| 522 | if (err) |
| 523 | goto register_wwan_err; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 524 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 525 | |
| 526 | return 0; |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 527 | register_wwan_err: |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 528 | rfkill_destroy(wwan_rfkill); |
Andrew Morton | 44f0606 | 2009-02-04 15:12:07 -0800 | [diff] [blame] | 529 | if (bluetooth_rfkill) |
| 530 | rfkill_unregister(bluetooth_rfkill); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 531 | register_bluetooth_error: |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 532 | rfkill_destroy(bluetooth_rfkill); |
Andrew Morton | 44f0606 | 2009-02-04 15:12:07 -0800 | [diff] [blame] | 533 | if (wifi_rfkill) |
| 534 | rfkill_unregister(wifi_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 535 | register_wifi_error: |
| 536 | rfkill_destroy(wifi_rfkill); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 537 | add_sysfs_error: |
| 538 | cleanup_sysfs(device); |
| 539 | return err; |
| 540 | } |
| 541 | |
| 542 | static int __exit hp_wmi_bios_remove(struct platform_device *device) |
| 543 | { |
| 544 | cleanup_sysfs(device); |
| 545 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 546 | if (wifi_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 547 | rfkill_unregister(wifi_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 548 | rfkill_destroy(wifi_rfkill); |
| 549 | } |
| 550 | if (bluetooth_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 551 | rfkill_unregister(bluetooth_rfkill); |
Corentin Chary | 09729f0 | 2009-09-14 12:43:51 +0200 | [diff] [blame] | 552 | rfkill_destroy(bluetooth_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 553 | } |
| 554 | if (wwan_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 555 | rfkill_unregister(wwan_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 556 | rfkill_destroy(wwan_rfkill); |
| 557 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
Frans Pop | 8dd2b42 | 2009-08-20 20:38:13 +0200 | [diff] [blame] | 562 | static int hp_wmi_resume_handler(struct device *device) |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 563 | { |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 564 | /* |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 565 | * Hardware state may have changed while suspended, so trigger |
| 566 | * input events for the current state. As this is a switch, |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 567 | * the input layer will only actually pass it on if the state |
| 568 | * changed. |
| 569 | */ |
Frans Pop | daed953 | 2009-07-30 17:16:05 -0400 | [diff] [blame] | 570 | if (hp_wmi_input_dev) { |
| 571 | input_report_switch(hp_wmi_input_dev, SW_DOCK, |
| 572 | hp_wmi_dock_state()); |
| 573 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
| 574 | hp_wmi_tablet_state()); |
| 575 | input_sync(hp_wmi_input_dev); |
| 576 | } |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 577 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 578 | if (wifi_rfkill) |
| 579 | rfkill_set_states(wifi_rfkill, |
| 580 | hp_wmi_get_sw_state(HPWMI_WIFI), |
| 581 | hp_wmi_get_hw_state(HPWMI_WIFI)); |
| 582 | if (bluetooth_rfkill) |
| 583 | rfkill_set_states(bluetooth_rfkill, |
| 584 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH), |
| 585 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); |
| 586 | if (wwan_rfkill) |
| 587 | rfkill_set_states(wwan_rfkill, |
| 588 | hp_wmi_get_sw_state(HPWMI_WWAN), |
| 589 | hp_wmi_get_hw_state(HPWMI_WWAN)); |
| 590 | |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 591 | return 0; |
| 592 | } |
| 593 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 594 | static int __init hp_wmi_init(void) |
| 595 | { |
| 596 | int err; |
| 597 | |
| 598 | if (wmi_has_guid(HPWMI_EVENT_GUID)) { |
| 599 | err = wmi_install_notify_handler(HPWMI_EVENT_GUID, |
| 600 | hp_wmi_notify, NULL); |
Len Brown | f277257 | 2009-12-26 22:04:03 -0500 | [diff] [blame] | 601 | if (ACPI_SUCCESS(err)) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 602 | hp_wmi_input_setup(); |
| 603 | } |
| 604 | |
| 605 | if (wmi_has_guid(HPWMI_BIOS_GUID)) { |
| 606 | err = platform_driver_register(&hp_wmi_driver); |
| 607 | if (err) |
| 608 | return 0; |
| 609 | hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1); |
| 610 | if (!hp_wmi_platform_dev) { |
| 611 | platform_driver_unregister(&hp_wmi_driver); |
| 612 | return 0; |
| 613 | } |
| 614 | platform_device_add(hp_wmi_platform_dev); |
| 615 | } |
| 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | static void __exit hp_wmi_exit(void) |
| 621 | { |
| 622 | if (wmi_has_guid(HPWMI_EVENT_GUID)) { |
| 623 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); |
| 624 | input_unregister_device(hp_wmi_input_dev); |
| 625 | } |
| 626 | if (hp_wmi_platform_dev) { |
| 627 | platform_device_del(hp_wmi_platform_dev); |
| 628 | platform_driver_unregister(&hp_wmi_driver); |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | module_init(hp_wmi_init); |
| 633 | module_exit(hp_wmi_exit); |