blob: a2ad53e15874ebcbba5b82ba73e4bb3b7f32529e [file] [log] [blame]
Matthew Garrett62ec30d2008-07-25 01:45:39 -07001/*
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
37MODULE_AUTHOR("Matthew Garrett <mjg59@srcf.ucam.org>");
38MODULE_DESCRIPTION("HP laptop WMI hotkeys driver");
39MODULE_LICENSE("GPL");
40
41MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C");
42MODULE_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
Matthew Garrett871043b2009-06-01 15:25:45 +010050#define HPWMI_HARDWARE_QUERY 0x4
Matthew Garrett62ec30d2008-07-25 01:45:39 -070051#define HPWMI_WIRELESS_QUERY 0x5
Matthew Garretta8823ae2008-09-02 14:36:03 -070052#define HPWMI_HOTKEY_QUERY 0xc
Matthew Garrett62ec30d2008-07-25 01:45:39 -070053
54static int __init hp_wmi_bios_setup(struct platform_device *device);
55static int __exit hp_wmi_bios_remove(struct platform_device *device);
Frans Pop4c395bd2009-03-04 11:55:28 -080056static int hp_wmi_resume_handler(struct platform_device *device);
Matthew Garrett62ec30d2008-07-25 01:45:39 -070057
58struct bios_args {
59 u32 signature;
60 u32 command;
61 u32 commandtype;
62 u32 datasize;
63 u32 data;
64};
65
66struct bios_return {
67 u32 sigpass;
68 u32 return_code;
69 u32 value;
70};
71
72struct key_entry {
73 char type; /* See KE_* below */
Matthew Garretta8823ae2008-09-02 14:36:03 -070074 u16 code;
Matthew Garrett62ec30d2008-07-25 01:45:39 -070075 u16 keycode;
76};
77
Matthew Garrett871043b2009-06-01 15:25:45 +010078enum { KE_KEY, KE_END };
Matthew Garrett62ec30d2008-07-25 01:45:39 -070079
80static struct key_entry hp_wmi_keymap[] = {
Matthew Garrett62ec30d2008-07-25 01:45:39 -070081 {KE_KEY, 0x02, KEY_BRIGHTNESSUP},
82 {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN},
Matthew Garretta8823ae2008-09-02 14:36:03 -070083 {KE_KEY, 0x20e6, KEY_PROG1},
84 {KE_KEY, 0x2142, KEY_MEDIA},
Eric Piel5c624842008-10-18 20:27:28 -070085 {KE_KEY, 0x213b, KEY_INFO},
Matthew Garretta8823ae2008-09-02 14:36:03 -070086 {KE_KEY, 0x231b, KEY_HELP},
Matthew Garrett62ec30d2008-07-25 01:45:39 -070087 {KE_END, 0}
88};
89
90static struct input_dev *hp_wmi_input_dev;
91static struct platform_device *hp_wmi_platform_dev;
92
93static struct rfkill *wifi_rfkill;
94static struct rfkill *bluetooth_rfkill;
95static struct rfkill *wwan_rfkill;
96
97static struct platform_driver hp_wmi_driver = {
98 .driver = {
99 .name = "hp-wmi",
100 .owner = THIS_MODULE,
101 },
102 .probe = hp_wmi_bios_setup,
103 .remove = hp_wmi_bios_remove,
Frans Pop4c395bd2009-03-04 11:55:28 -0800104 .resume = hp_wmi_resume_handler,
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700105};
106
107static int hp_wmi_perform_query(int query, int write, int value)
108{
109 struct bios_return bios_return;
110 acpi_status status;
111 union acpi_object *obj;
112 struct bios_args args = {
113 .signature = 0x55434553,
114 .command = write ? 0x2 : 0x1,
115 .commandtype = query,
116 .datasize = write ? 0x4 : 0,
117 .data = value,
118 };
119 struct acpi_buffer input = { sizeof(struct bios_args), &args };
120 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
121
122 status = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output);
123
124 obj = output.pointer;
125
126 if (!obj || obj->type != ACPI_TYPE_BUFFER)
127 return -EINVAL;
128
129 bios_return = *((struct bios_return *)obj->buffer.pointer);
130 if (bios_return.return_code > 0)
131 return bios_return.return_code * -1;
132 else
133 return bios_return.value;
134}
135
136static int hp_wmi_display_state(void)
137{
138 return hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, 0);
139}
140
141static int hp_wmi_hddtemp_state(void)
142{
143 return hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, 0);
144}
145
146static int hp_wmi_als_state(void)
147{
148 return hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, 0);
149}
150
151static int hp_wmi_dock_state(void)
152{
Matthew Garrett871043b2009-06-01 15:25:45 +0100153 int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0);
154
155 if (ret < 0)
156 return ret;
157
158 return ret & 0x1;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700159}
160
Matthew Garrett871043b2009-06-01 15:25:45 +0100161static int hp_wmi_tablet_state(void)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700162{
Matthew Garrett871043b2009-06-01 15:25:45 +0100163 int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0);
164
165 if (ret < 0)
166 return ret;
167
168 return (ret & 0x4) ? 1 : 0;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700169}
170
Johannes Berg19d337d2009-06-02 13:01:37 +0200171static int hp_wmi_set_block(void *data, bool blocked)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700172{
Johannes Berg19d337d2009-06-02 13:01:37 +0200173 unsigned long b = (unsigned long) data;
Johannes Berg76d8b642009-06-29 10:53:53 +0200174 int query = BIT(b + 8) | ((!blocked) << b);
Johannes Berg19d337d2009-06-02 13:01:37 +0200175
176 return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700177}
178
Johannes Berg19d337d2009-06-02 13:01:37 +0200179static const struct rfkill_ops hp_wmi_rfkill_ops = {
180 .set_block = hp_wmi_set_block,
181};
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700182
Johannes Berg19d337d2009-06-02 13:01:37 +0200183static bool hp_wmi_wifi_state(void)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700184{
185 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
186
187 if (wireless & 0x100)
Johannes Berg19d337d2009-06-02 13:01:37 +0200188 return false;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700189 else
Johannes Berg19d337d2009-06-02 13:01:37 +0200190 return true;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700191}
192
Johannes Berg19d337d2009-06-02 13:01:37 +0200193static bool hp_wmi_bluetooth_state(void)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700194{
195 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
196
197 if (wireless & 0x10000)
Johannes Berg19d337d2009-06-02 13:01:37 +0200198 return false;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700199 else
Johannes Berg19d337d2009-06-02 13:01:37 +0200200 return true;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700201}
202
Johannes Berg19d337d2009-06-02 13:01:37 +0200203static bool hp_wmi_wwan_state(void)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700204{
205 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
206
207 if (wireless & 0x1000000)
Johannes Berg19d337d2009-06-02 13:01:37 +0200208 return false;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700209 else
Johannes Berg19d337d2009-06-02 13:01:37 +0200210 return true;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700211}
212
213static ssize_t show_display(struct device *dev, struct device_attribute *attr,
214 char *buf)
215{
216 int value = hp_wmi_display_state();
217 if (value < 0)
218 return -EINVAL;
219 return sprintf(buf, "%d\n", value);
220}
221
222static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr,
223 char *buf)
224{
225 int value = hp_wmi_hddtemp_state();
226 if (value < 0)
227 return -EINVAL;
228 return sprintf(buf, "%d\n", value);
229}
230
231static ssize_t show_als(struct device *dev, struct device_attribute *attr,
232 char *buf)
233{
234 int value = hp_wmi_als_state();
235 if (value < 0)
236 return -EINVAL;
237 return sprintf(buf, "%d\n", value);
238}
239
240static ssize_t show_dock(struct device *dev, struct device_attribute *attr,
241 char *buf)
242{
243 int value = hp_wmi_dock_state();
244 if (value < 0)
245 return -EINVAL;
246 return sprintf(buf, "%d\n", value);
247}
248
Matthew Garrett871043b2009-06-01 15:25:45 +0100249static ssize_t show_tablet(struct device *dev, struct device_attribute *attr,
250 char *buf)
251{
252 int value = hp_wmi_tablet_state();
253 if (value < 0)
254 return -EINVAL;
255 return sprintf(buf, "%d\n", value);
256}
257
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700258static ssize_t set_als(struct device *dev, struct device_attribute *attr,
259 const char *buf, size_t count)
260{
261 u32 tmp = simple_strtoul(buf, NULL, 10);
262 hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, tmp);
263 return count;
264}
265
266static DEVICE_ATTR(display, S_IRUGO, show_display, NULL);
267static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL);
268static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als);
269static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL);
Matthew Garrett871043b2009-06-01 15:25:45 +0100270static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700271
272static struct key_entry *hp_wmi_get_entry_by_scancode(int code)
273{
274 struct key_entry *key;
275
276 for (key = hp_wmi_keymap; key->type != KE_END; key++)
277 if (code == key->code)
278 return key;
279
280 return NULL;
281}
282
283static struct key_entry *hp_wmi_get_entry_by_keycode(int keycode)
284{
285 struct key_entry *key;
286
287 for (key = hp_wmi_keymap; key->type != KE_END; key++)
288 if (key->type == KE_KEY && keycode == key->keycode)
289 return key;
290
291 return NULL;
292}
293
294static int hp_wmi_getkeycode(struct input_dev *dev, int scancode, int *keycode)
295{
296 struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode);
297
298 if (key && key->type == KE_KEY) {
299 *keycode = key->keycode;
300 return 0;
301 }
302
303 return -EINVAL;
304}
305
306static int hp_wmi_setkeycode(struct input_dev *dev, int scancode, int keycode)
307{
308 struct key_entry *key;
309 int old_keycode;
310
311 if (keycode < 0 || keycode > KEY_MAX)
312 return -EINVAL;
313
314 key = hp_wmi_get_entry_by_scancode(scancode);
315 if (key && key->type == KE_KEY) {
316 old_keycode = key->keycode;
317 key->keycode = keycode;
318 set_bit(keycode, dev->keybit);
319 if (!hp_wmi_get_entry_by_keycode(old_keycode))
320 clear_bit(old_keycode, dev->keybit);
321 return 0;
322 }
323
324 return -EINVAL;
325}
326
Adrian Bunk88429a12008-10-15 22:05:17 -0700327static void hp_wmi_notify(u32 value, void *context)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700328{
329 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
330 static struct key_entry *key;
331 union acpi_object *obj;
332
333 wmi_get_event_data(value, &response);
334
335 obj = (union acpi_object *)response.pointer;
336
337 if (obj && obj->type == ACPI_TYPE_BUFFER && obj->buffer.length == 8) {
338 int eventcode = *((u8 *) obj->buffer.pointer);
Matthew Garretta8823ae2008-09-02 14:36:03 -0700339 if (eventcode == 0x4)
340 eventcode = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0,
341 0);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700342 key = hp_wmi_get_entry_by_scancode(eventcode);
343 if (key) {
344 switch (key->type) {
345 case KE_KEY:
346 input_report_key(hp_wmi_input_dev,
347 key->keycode, 1);
348 input_sync(hp_wmi_input_dev);
349 input_report_key(hp_wmi_input_dev,
350 key->keycode, 0);
351 input_sync(hp_wmi_input_dev);
352 break;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700353 }
Matthew Garrett871043b2009-06-01 15:25:45 +0100354 } else if (eventcode == 0x1) {
355 input_report_switch(hp_wmi_input_dev, SW_DOCK,
356 hp_wmi_dock_state());
357 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
358 hp_wmi_tablet_state());
359 input_sync(hp_wmi_input_dev);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700360 } else if (eventcode == 0x5) {
361 if (wifi_rfkill)
Johannes Berg19d337d2009-06-02 13:01:37 +0200362 rfkill_set_sw_state(wifi_rfkill,
363 hp_wmi_wifi_state());
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700364 if (bluetooth_rfkill)
Johannes Berg19d337d2009-06-02 13:01:37 +0200365 rfkill_set_sw_state(bluetooth_rfkill,
366 hp_wmi_bluetooth_state());
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700367 if (wwan_rfkill)
Johannes Berg19d337d2009-06-02 13:01:37 +0200368 rfkill_set_sw_state(wwan_rfkill,
369 hp_wmi_wwan_state());
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700370 } else
371 printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n",
372 eventcode);
373 } else
374 printk(KERN_INFO "HP WMI: Unknown response received\n");
375}
376
377static int __init hp_wmi_input_setup(void)
378{
379 struct key_entry *key;
380 int err;
381
382 hp_wmi_input_dev = input_allocate_device();
383
384 hp_wmi_input_dev->name = "HP WMI hotkeys";
385 hp_wmi_input_dev->phys = "wmi/input0";
386 hp_wmi_input_dev->id.bustype = BUS_HOST;
387 hp_wmi_input_dev->getkeycode = hp_wmi_getkeycode;
388 hp_wmi_input_dev->setkeycode = hp_wmi_setkeycode;
389
390 for (key = hp_wmi_keymap; key->type != KE_END; key++) {
391 switch (key->type) {
392 case KE_KEY:
393 set_bit(EV_KEY, hp_wmi_input_dev->evbit);
394 set_bit(key->keycode, hp_wmi_input_dev->keybit);
395 break;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700396 }
397 }
398
Matthew Garrett871043b2009-06-01 15:25:45 +0100399 set_bit(EV_SW, hp_wmi_input_dev->evbit);
400 set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
401 set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
402
403 /* Set initial hardware state */
404 input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state());
405 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
406 hp_wmi_tablet_state());
407 input_sync(hp_wmi_input_dev);
408
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700409 err = input_register_device(hp_wmi_input_dev);
410
411 if (err) {
412 input_free_device(hp_wmi_input_dev);
413 return err;
414 }
415
416 return 0;
417}
418
419static void cleanup_sysfs(struct platform_device *device)
420{
421 device_remove_file(&device->dev, &dev_attr_display);
422 device_remove_file(&device->dev, &dev_attr_hddtemp);
423 device_remove_file(&device->dev, &dev_attr_als);
424 device_remove_file(&device->dev, &dev_attr_dock);
Matthew Garrett871043b2009-06-01 15:25:45 +0100425 device_remove_file(&device->dev, &dev_attr_tablet);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700426}
427
428static int __init hp_wmi_bios_setup(struct platform_device *device)
429{
430 int err;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700431 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700432
433 err = device_create_file(&device->dev, &dev_attr_display);
434 if (err)
435 goto add_sysfs_error;
436 err = device_create_file(&device->dev, &dev_attr_hddtemp);
437 if (err)
438 goto add_sysfs_error;
439 err = device_create_file(&device->dev, &dev_attr_als);
440 if (err)
441 goto add_sysfs_error;
442 err = device_create_file(&device->dev, &dev_attr_dock);
443 if (err)
444 goto add_sysfs_error;
Matthew Garrett871043b2009-06-01 15:25:45 +0100445 err = device_create_file(&device->dev, &dev_attr_tablet);
446 if (err)
447 goto add_sysfs_error;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700448
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700449 if (wireless & 0x1) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200450 wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
451 RFKILL_TYPE_WLAN,
452 &hp_wmi_rfkill_ops,
453 (void *) 0);
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800454 err = rfkill_register(wifi_rfkill);
455 if (err)
Johannes Berg19d337d2009-06-02 13:01:37 +0200456 goto register_wifi_error;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700457 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700458
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700459 if (wireless & 0x2) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200460 bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
461 RFKILL_TYPE_BLUETOOTH,
462 &hp_wmi_rfkill_ops,
463 (void *) 1);
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800464 err = rfkill_register(bluetooth_rfkill);
Frans Pop6989d562009-01-29 14:25:14 -0800465 if (err)
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800466 goto register_bluetooth_error;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700467 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700468
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700469 if (wireless & 0x4) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200470 wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
471 RFKILL_TYPE_WWAN,
472 &hp_wmi_rfkill_ops,
473 (void *) 2);
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800474 err = rfkill_register(wwan_rfkill);
475 if (err)
476 goto register_wwan_err;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700477 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700478
479 return 0;
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800480register_wwan_err:
Johannes Berg19d337d2009-06-02 13:01:37 +0200481 rfkill_destroy(wwan_rfkill);
Andrew Morton44f06062009-02-04 15:12:07 -0800482 if (bluetooth_rfkill)
483 rfkill_unregister(bluetooth_rfkill);
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800484register_bluetooth_error:
Johannes Berg19d337d2009-06-02 13:01:37 +0200485 rfkill_destroy(bluetooth_rfkill);
Andrew Morton44f06062009-02-04 15:12:07 -0800486 if (wifi_rfkill)
487 rfkill_unregister(wifi_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200488register_wifi_error:
489 rfkill_destroy(wifi_rfkill);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700490add_sysfs_error:
491 cleanup_sysfs(device);
492 return err;
493}
494
495static int __exit hp_wmi_bios_remove(struct platform_device *device)
496{
497 cleanup_sysfs(device);
498
Johannes Berg19d337d2009-06-02 13:01:37 +0200499 if (wifi_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700500 rfkill_unregister(wifi_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200501 rfkill_destroy(wifi_rfkill);
502 }
503 if (bluetooth_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700504 rfkill_unregister(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200505 rfkill_destroy(wifi_rfkill);
506 }
507 if (wwan_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700508 rfkill_unregister(wwan_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200509 rfkill_destroy(wwan_rfkill);
510 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700511
512 return 0;
513}
514
Frans Pop4c395bd2009-03-04 11:55:28 -0800515static int hp_wmi_resume_handler(struct platform_device *device)
516{
Frans Pop4c395bd2009-03-04 11:55:28 -0800517 /*
Matthew Garrett871043b2009-06-01 15:25:45 +0100518 * Hardware state may have changed while suspended, so trigger
519 * input events for the current state. As this is a switch,
Frans Pop4c395bd2009-03-04 11:55:28 -0800520 * the input layer will only actually pass it on if the state
521 * changed.
522 */
Frans Popdaed9532009-07-30 17:16:05 -0400523 if (hp_wmi_input_dev) {
524 input_report_switch(hp_wmi_input_dev, SW_DOCK,
525 hp_wmi_dock_state());
526 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
527 hp_wmi_tablet_state());
528 input_sync(hp_wmi_input_dev);
529 }
Frans Pop4c395bd2009-03-04 11:55:28 -0800530
531 return 0;
532}
533
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700534static int __init hp_wmi_init(void)
535{
536 int err;
537
538 if (wmi_has_guid(HPWMI_EVENT_GUID)) {
539 err = wmi_install_notify_handler(HPWMI_EVENT_GUID,
540 hp_wmi_notify, NULL);
541 if (!err)
542 hp_wmi_input_setup();
543 }
544
545 if (wmi_has_guid(HPWMI_BIOS_GUID)) {
546 err = platform_driver_register(&hp_wmi_driver);
547 if (err)
548 return 0;
549 hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1);
550 if (!hp_wmi_platform_dev) {
551 platform_driver_unregister(&hp_wmi_driver);
552 return 0;
553 }
554 platform_device_add(hp_wmi_platform_dev);
555 }
556
557 return 0;
558}
559
560static void __exit hp_wmi_exit(void)
561{
562 if (wmi_has_guid(HPWMI_EVENT_GUID)) {
563 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
564 input_unregister_device(hp_wmi_input_dev);
565 }
566 if (hp_wmi_platform_dev) {
567 platform_device_del(hp_wmi_platform_dev);
568 platform_driver_unregister(&hp_wmi_driver);
569 }
570}
571
572module_init(hp_wmi_init);
573module_exit(hp_wmi_exit);