blob: db10c5d007ec2f1953638144a87d09adc70a0c7d [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
Alan Jenkinse5fbba82009-07-21 12:14:01 +010054enum hp_wmi_radio {
55 HPWMI_WIFI = 0,
56 HPWMI_BLUETOOTH = 1,
57 HPWMI_WWAN = 2,
58};
59
Matthew Garrett62ec30d2008-07-25 01:45:39 -070060static int __init hp_wmi_bios_setup(struct platform_device *device);
61static int __exit hp_wmi_bios_remove(struct platform_device *device);
Frans Pop8dd2b422009-08-20 20:38:13 +020062static int hp_wmi_resume_handler(struct device *device);
Matthew Garrett62ec30d2008-07-25 01:45:39 -070063
64struct bios_args {
65 u32 signature;
66 u32 command;
67 u32 commandtype;
68 u32 datasize;
69 u32 data;
70};
71
72struct bios_return {
73 u32 sigpass;
74 u32 return_code;
75 u32 value;
76};
77
78struct key_entry {
79 char type; /* See KE_* below */
Matthew Garretta8823ae2008-09-02 14:36:03 -070080 u16 code;
Matthew Garrett62ec30d2008-07-25 01:45:39 -070081 u16 keycode;
82};
83
Matthew Garrett871043b2009-06-01 15:25:45 +010084enum { KE_KEY, KE_END };
Matthew Garrett62ec30d2008-07-25 01:45:39 -070085
86static struct key_entry hp_wmi_keymap[] = {
Matthew Garrett62ec30d2008-07-25 01:45:39 -070087 {KE_KEY, 0x02, KEY_BRIGHTNESSUP},
88 {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN},
Matthew Garretta8823ae2008-09-02 14:36:03 -070089 {KE_KEY, 0x20e6, KEY_PROG1},
90 {KE_KEY, 0x2142, KEY_MEDIA},
Eric Piel5c624842008-10-18 20:27:28 -070091 {KE_KEY, 0x213b, KEY_INFO},
Matthew Garretta8823ae2008-09-02 14:36:03 -070092 {KE_KEY, 0x231b, KEY_HELP},
Matthew Garrett62ec30d2008-07-25 01:45:39 -070093 {KE_END, 0}
94};
95
96static struct input_dev *hp_wmi_input_dev;
97static struct platform_device *hp_wmi_platform_dev;
98
99static struct rfkill *wifi_rfkill;
100static struct rfkill *bluetooth_rfkill;
101static struct rfkill *wwan_rfkill;
102
Alexey Dobriyan47145212009-12-14 18:00:08 -0800103static const struct dev_pm_ops hp_wmi_pm_ops = {
Frans Pop8dd2b422009-08-20 20:38:13 +0200104 .resume = hp_wmi_resume_handler,
105 .restore = hp_wmi_resume_handler,
106};
107
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700108static struct platform_driver hp_wmi_driver = {
109 .driver = {
Frans Pop8dd2b422009-08-20 20:38:13 +0200110 .name = "hp-wmi",
111 .owner = THIS_MODULE,
112 .pm = &hp_wmi_pm_ops,
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700113 },
114 .probe = hp_wmi_bios_setup,
115 .remove = hp_wmi_bios_remove,
116};
117
118static 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
137 if (!obj || obj->type != ACPI_TYPE_BUFFER)
138 return -EINVAL;
139
140 bios_return = *((struct bios_return *)obj->buffer.pointer);
141 if (bios_return.return_code > 0)
142 return bios_return.return_code * -1;
143 else
144 return bios_return.value;
145}
146
147static int hp_wmi_display_state(void)
148{
149 return hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, 0);
150}
151
152static int hp_wmi_hddtemp_state(void)
153{
154 return hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, 0);
155}
156
157static int hp_wmi_als_state(void)
158{
159 return hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, 0);
160}
161
162static int hp_wmi_dock_state(void)
163{
Matthew Garrett871043b2009-06-01 15:25:45 +0100164 int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0);
165
166 if (ret < 0)
167 return ret;
168
169 return ret & 0x1;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700170}
171
Matthew Garrett871043b2009-06-01 15:25:45 +0100172static int hp_wmi_tablet_state(void)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700173{
Matthew Garrett871043b2009-06-01 15:25:45 +0100174 int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0);
175
176 if (ret < 0)
177 return ret;
178
179 return (ret & 0x4) ? 1 : 0;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700180}
181
Johannes Berg19d337d2009-06-02 13:01:37 +0200182static int hp_wmi_set_block(void *data, bool blocked)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700183{
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100184 enum hp_wmi_radio r = (enum hp_wmi_radio) data;
185 int query = BIT(r + 8) | ((!blocked) << r);
Johannes Berg19d337d2009-06-02 13:01:37 +0200186
187 return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700188}
189
Johannes Berg19d337d2009-06-02 13:01:37 +0200190static const struct rfkill_ops hp_wmi_rfkill_ops = {
191 .set_block = hp_wmi_set_block,
192};
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700193
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100194static bool hp_wmi_get_sw_state(enum hp_wmi_radio r)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700195{
196 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100197 int mask = 0x200 << (r * 8);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700198
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100199 if (wireless & mask)
Johannes Berg19d337d2009-06-02 13:01:37 +0200200 return false;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700201 else
Johannes Berg19d337d2009-06-02 13:01:37 +0200202 return true;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700203}
204
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100205static bool hp_wmi_get_hw_state(enum hp_wmi_radio r)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700206{
207 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100208 int mask = 0x800 << (r * 8);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700209
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100210 if (wireless & mask)
Johannes Berg19d337d2009-06-02 13:01:37 +0200211 return false;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700212 else
Johannes Berg19d337d2009-06-02 13:01:37 +0200213 return true;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700214}
215
216static ssize_t show_display(struct device *dev, struct device_attribute *attr,
217 char *buf)
218{
219 int value = hp_wmi_display_state();
220 if (value < 0)
221 return -EINVAL;
222 return sprintf(buf, "%d\n", value);
223}
224
225static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr,
226 char *buf)
227{
228 int value = hp_wmi_hddtemp_state();
229 if (value < 0)
230 return -EINVAL;
231 return sprintf(buf, "%d\n", value);
232}
233
234static ssize_t show_als(struct device *dev, struct device_attribute *attr,
235 char *buf)
236{
237 int value = hp_wmi_als_state();
238 if (value < 0)
239 return -EINVAL;
240 return sprintf(buf, "%d\n", value);
241}
242
243static ssize_t show_dock(struct device *dev, struct device_attribute *attr,
244 char *buf)
245{
246 int value = hp_wmi_dock_state();
247 if (value < 0)
248 return -EINVAL;
249 return sprintf(buf, "%d\n", value);
250}
251
Matthew Garrett871043b2009-06-01 15:25:45 +0100252static ssize_t show_tablet(struct device *dev, struct device_attribute *attr,
253 char *buf)
254{
255 int value = hp_wmi_tablet_state();
256 if (value < 0)
257 return -EINVAL;
258 return sprintf(buf, "%d\n", value);
259}
260
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700261static ssize_t set_als(struct device *dev, struct device_attribute *attr,
262 const char *buf, size_t count)
263{
264 u32 tmp = simple_strtoul(buf, NULL, 10);
265 hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, tmp);
266 return count;
267}
268
269static DEVICE_ATTR(display, S_IRUGO, show_display, NULL);
270static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL);
271static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als);
272static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL);
Matthew Garrett871043b2009-06-01 15:25:45 +0100273static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700274
275static struct key_entry *hp_wmi_get_entry_by_scancode(int code)
276{
277 struct key_entry *key;
278
279 for (key = hp_wmi_keymap; key->type != KE_END; key++)
280 if (code == key->code)
281 return key;
282
283 return NULL;
284}
285
286static struct key_entry *hp_wmi_get_entry_by_keycode(int keycode)
287{
288 struct key_entry *key;
289
290 for (key = hp_wmi_keymap; key->type != KE_END; key++)
291 if (key->type == KE_KEY && keycode == key->keycode)
292 return key;
293
294 return NULL;
295}
296
297static int hp_wmi_getkeycode(struct input_dev *dev, int scancode, int *keycode)
298{
299 struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode);
300
301 if (key && key->type == KE_KEY) {
302 *keycode = key->keycode;
303 return 0;
304 }
305
306 return -EINVAL;
307}
308
309static int hp_wmi_setkeycode(struct input_dev *dev, int scancode, int keycode)
310{
311 struct key_entry *key;
312 int old_keycode;
313
314 if (keycode < 0 || keycode > KEY_MAX)
315 return -EINVAL;
316
317 key = hp_wmi_get_entry_by_scancode(scancode);
318 if (key && key->type == KE_KEY) {
319 old_keycode = key->keycode;
320 key->keycode = keycode;
321 set_bit(keycode, dev->keybit);
322 if (!hp_wmi_get_entry_by_keycode(old_keycode))
323 clear_bit(old_keycode, dev->keybit);
324 return 0;
325 }
326
327 return -EINVAL;
328}
329
Adrian Bunk88429a12008-10-15 22:05:17 -0700330static void hp_wmi_notify(u32 value, void *context)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700331{
332 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
333 static struct key_entry *key;
334 union acpi_object *obj;
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100335 int eventcode;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700336
337 wmi_get_event_data(value, &response);
338
339 obj = (union acpi_object *)response.pointer;
340
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100341 if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) {
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700342 printk(KERN_INFO "HP WMI: Unknown response received\n");
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100343 return;
344 }
345
346 eventcode = *((u8 *) obj->buffer.pointer);
347 if (eventcode == 0x4)
348 eventcode = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0,
349 0);
350 key = hp_wmi_get_entry_by_scancode(eventcode);
351 if (key) {
352 switch (key->type) {
353 case KE_KEY:
354 input_report_key(hp_wmi_input_dev,
355 key->keycode, 1);
356 input_sync(hp_wmi_input_dev);
357 input_report_key(hp_wmi_input_dev,
358 key->keycode, 0);
359 input_sync(hp_wmi_input_dev);
360 break;
361 }
362 } else if (eventcode == 0x1) {
363 input_report_switch(hp_wmi_input_dev, SW_DOCK,
364 hp_wmi_dock_state());
365 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
366 hp_wmi_tablet_state());
367 input_sync(hp_wmi_input_dev);
368 } else if (eventcode == 0x5) {
369 if (wifi_rfkill)
370 rfkill_set_states(wifi_rfkill,
371 hp_wmi_get_sw_state(HPWMI_WIFI),
372 hp_wmi_get_hw_state(HPWMI_WIFI));
373 if (bluetooth_rfkill)
374 rfkill_set_states(bluetooth_rfkill,
375 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
376 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
377 if (wwan_rfkill)
378 rfkill_set_states(wwan_rfkill,
379 hp_wmi_get_sw_state(HPWMI_WWAN),
380 hp_wmi_get_hw_state(HPWMI_WWAN));
381 } else
382 printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n",
383 eventcode);
Anisse Astier3e9b9882009-12-04 10:10:09 +0100384
385 kfree(obj);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700386}
387
388static int __init hp_wmi_input_setup(void)
389{
390 struct key_entry *key;
391 int err;
392
393 hp_wmi_input_dev = input_allocate_device();
394
395 hp_wmi_input_dev->name = "HP WMI hotkeys";
396 hp_wmi_input_dev->phys = "wmi/input0";
397 hp_wmi_input_dev->id.bustype = BUS_HOST;
398 hp_wmi_input_dev->getkeycode = hp_wmi_getkeycode;
399 hp_wmi_input_dev->setkeycode = hp_wmi_setkeycode;
400
401 for (key = hp_wmi_keymap; key->type != KE_END; key++) {
402 switch (key->type) {
403 case KE_KEY:
404 set_bit(EV_KEY, hp_wmi_input_dev->evbit);
405 set_bit(key->keycode, hp_wmi_input_dev->keybit);
406 break;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700407 }
408 }
409
Matthew Garrett871043b2009-06-01 15:25:45 +0100410 set_bit(EV_SW, hp_wmi_input_dev->evbit);
411 set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
412 set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
413
414 /* Set initial hardware state */
415 input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state());
416 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
417 hp_wmi_tablet_state());
418 input_sync(hp_wmi_input_dev);
419
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700420 err = input_register_device(hp_wmi_input_dev);
421
422 if (err) {
423 input_free_device(hp_wmi_input_dev);
424 return err;
425 }
426
427 return 0;
428}
429
430static void cleanup_sysfs(struct platform_device *device)
431{
432 device_remove_file(&device->dev, &dev_attr_display);
433 device_remove_file(&device->dev, &dev_attr_hddtemp);
434 device_remove_file(&device->dev, &dev_attr_als);
435 device_remove_file(&device->dev, &dev_attr_dock);
Matthew Garrett871043b2009-06-01 15:25:45 +0100436 device_remove_file(&device->dev, &dev_attr_tablet);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700437}
438
439static int __init hp_wmi_bios_setup(struct platform_device *device)
440{
441 int err;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700442 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700443
444 err = device_create_file(&device->dev, &dev_attr_display);
445 if (err)
446 goto add_sysfs_error;
447 err = device_create_file(&device->dev, &dev_attr_hddtemp);
448 if (err)
449 goto add_sysfs_error;
450 err = device_create_file(&device->dev, &dev_attr_als);
451 if (err)
452 goto add_sysfs_error;
453 err = device_create_file(&device->dev, &dev_attr_dock);
454 if (err)
455 goto add_sysfs_error;
Matthew Garrett871043b2009-06-01 15:25:45 +0100456 err = device_create_file(&device->dev, &dev_attr_tablet);
457 if (err)
458 goto add_sysfs_error;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700459
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700460 if (wireless & 0x1) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200461 wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
462 RFKILL_TYPE_WLAN,
463 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100464 (void *) HPWMI_WIFI);
465 rfkill_init_sw_state(wifi_rfkill,
466 hp_wmi_get_sw_state(HPWMI_WIFI));
467 rfkill_set_hw_state(wifi_rfkill,
468 hp_wmi_get_hw_state(HPWMI_WIFI));
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800469 err = rfkill_register(wifi_rfkill);
470 if (err)
Johannes Berg19d337d2009-06-02 13:01:37 +0200471 goto register_wifi_error;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700472 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700473
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700474 if (wireless & 0x2) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200475 bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
476 RFKILL_TYPE_BLUETOOTH,
477 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100478 (void *) HPWMI_BLUETOOTH);
479 rfkill_init_sw_state(bluetooth_rfkill,
480 hp_wmi_get_sw_state(HPWMI_BLUETOOTH));
481 rfkill_set_hw_state(bluetooth_rfkill,
482 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800483 err = rfkill_register(bluetooth_rfkill);
Frans Pop6989d562009-01-29 14:25:14 -0800484 if (err)
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800485 goto register_bluetooth_error;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700486 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700487
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700488 if (wireless & 0x4) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200489 wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
490 RFKILL_TYPE_WWAN,
491 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100492 (void *) HPWMI_WWAN);
493 rfkill_init_sw_state(wwan_rfkill,
494 hp_wmi_get_sw_state(HPWMI_WWAN));
495 rfkill_set_hw_state(wwan_rfkill,
496 hp_wmi_get_hw_state(HPWMI_WWAN));
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800497 err = rfkill_register(wwan_rfkill);
498 if (err)
499 goto register_wwan_err;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700500 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700501
502 return 0;
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800503register_wwan_err:
Johannes Berg19d337d2009-06-02 13:01:37 +0200504 rfkill_destroy(wwan_rfkill);
Andrew Morton44f06062009-02-04 15:12:07 -0800505 if (bluetooth_rfkill)
506 rfkill_unregister(bluetooth_rfkill);
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800507register_bluetooth_error:
Johannes Berg19d337d2009-06-02 13:01:37 +0200508 rfkill_destroy(bluetooth_rfkill);
Andrew Morton44f06062009-02-04 15:12:07 -0800509 if (wifi_rfkill)
510 rfkill_unregister(wifi_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200511register_wifi_error:
512 rfkill_destroy(wifi_rfkill);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700513add_sysfs_error:
514 cleanup_sysfs(device);
515 return err;
516}
517
518static int __exit hp_wmi_bios_remove(struct platform_device *device)
519{
520 cleanup_sysfs(device);
521
Johannes Berg19d337d2009-06-02 13:01:37 +0200522 if (wifi_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700523 rfkill_unregister(wifi_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200524 rfkill_destroy(wifi_rfkill);
525 }
526 if (bluetooth_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700527 rfkill_unregister(bluetooth_rfkill);
Corentin Chary09729f02009-09-14 12:43:51 +0200528 rfkill_destroy(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200529 }
530 if (wwan_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700531 rfkill_unregister(wwan_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200532 rfkill_destroy(wwan_rfkill);
533 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700534
535 return 0;
536}
537
Frans Pop8dd2b422009-08-20 20:38:13 +0200538static int hp_wmi_resume_handler(struct device *device)
Frans Pop4c395bd2009-03-04 11:55:28 -0800539{
Frans Pop4c395bd2009-03-04 11:55:28 -0800540 /*
Matthew Garrett871043b2009-06-01 15:25:45 +0100541 * Hardware state may have changed while suspended, so trigger
542 * input events for the current state. As this is a switch,
Frans Pop4c395bd2009-03-04 11:55:28 -0800543 * the input layer will only actually pass it on if the state
544 * changed.
545 */
Frans Popdaed9532009-07-30 17:16:05 -0400546 if (hp_wmi_input_dev) {
547 input_report_switch(hp_wmi_input_dev, SW_DOCK,
548 hp_wmi_dock_state());
549 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
550 hp_wmi_tablet_state());
551 input_sync(hp_wmi_input_dev);
552 }
Frans Pop4c395bd2009-03-04 11:55:28 -0800553
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100554 if (wifi_rfkill)
555 rfkill_set_states(wifi_rfkill,
556 hp_wmi_get_sw_state(HPWMI_WIFI),
557 hp_wmi_get_hw_state(HPWMI_WIFI));
558 if (bluetooth_rfkill)
559 rfkill_set_states(bluetooth_rfkill,
560 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
561 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
562 if (wwan_rfkill)
563 rfkill_set_states(wwan_rfkill,
564 hp_wmi_get_sw_state(HPWMI_WWAN),
565 hp_wmi_get_hw_state(HPWMI_WWAN));
566
Frans Pop4c395bd2009-03-04 11:55:28 -0800567 return 0;
568}
569
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700570static int __init hp_wmi_init(void)
571{
572 int err;
573
574 if (wmi_has_guid(HPWMI_EVENT_GUID)) {
575 err = wmi_install_notify_handler(HPWMI_EVENT_GUID,
576 hp_wmi_notify, NULL);
577 if (!err)
578 hp_wmi_input_setup();
579 }
580
581 if (wmi_has_guid(HPWMI_BIOS_GUID)) {
582 err = platform_driver_register(&hp_wmi_driver);
583 if (err)
584 return 0;
585 hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1);
586 if (!hp_wmi_platform_dev) {
587 platform_driver_unregister(&hp_wmi_driver);
588 return 0;
589 }
590 platform_device_add(hp_wmi_platform_dev);
591 }
592
593 return 0;
594}
595
596static void __exit hp_wmi_exit(void)
597{
598 if (wmi_has_guid(HPWMI_EVENT_GUID)) {
599 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
600 input_unregister_device(hp_wmi_input_dev);
601 }
602 if (hp_wmi_platform_dev) {
603 platform_device_del(hp_wmi_platform_dev);
604 platform_driver_unregister(&hp_wmi_driver);
605 }
606}
607
608module_init(hp_wmi_init);
609module_exit(hp_wmi_exit);