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