blob: f1c186245f983446cb9eef03c419a0a5196b69eb [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Matthew Garrett62ec30d2008-07-25 01:45:39 -070030#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
38MODULE_AUTHOR("Matthew Garrett <mjg59@srcf.ucam.org>");
39MODULE_DESCRIPTION("HP laptop WMI hotkeys driver");
40MODULE_LICENSE("GPL");
41
42MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C");
43MODULE_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 Garrett871043b2009-06-01 15:25:45 +010051#define HPWMI_HARDWARE_QUERY 0x4
Matthew Garrett62ec30d2008-07-25 01:45:39 -070052#define HPWMI_WIRELESS_QUERY 0x5
Matthew Garretta8823ae2008-09-02 14:36:03 -070053#define HPWMI_HOTKEY_QUERY 0xc
Matthew Garrett62ec30d2008-07-25 01:45:39 -070054
Alan Jenkinse5fbba82009-07-21 12:14:01 +010055enum hp_wmi_radio {
56 HPWMI_WIFI = 0,
57 HPWMI_BLUETOOTH = 1,
58 HPWMI_WWAN = 2,
59};
60
Thomas Renninger751ae802010-05-21 16:18:09 +020061enum hp_wmi_event_ids {
62 HPWMI_DOCK_EVENT = 1,
63 HPWMI_BEZEL_BUTTON = 4,
64 HPWMI_WIRELESS = 5,
65};
66
Uwe Kleine-Königea796322010-02-04 20:56:52 +010067static int __devinit hp_wmi_bios_setup(struct platform_device *device);
Matthew Garrett62ec30d2008-07-25 01:45:39 -070068static int __exit hp_wmi_bios_remove(struct platform_device *device);
Frans Pop8dd2b422009-08-20 20:38:13 +020069static int hp_wmi_resume_handler(struct device *device);
Matthew Garrett62ec30d2008-07-25 01:45:39 -070070
71struct bios_args {
72 u32 signature;
73 u32 command;
74 u32 commandtype;
75 u32 datasize;
76 u32 data;
77};
78
79struct bios_return {
80 u32 sigpass;
81 u32 return_code;
82 u32 value;
83};
84
85struct key_entry {
86 char type; /* See KE_* below */
Matthew Garretta8823ae2008-09-02 14:36:03 -070087 u16 code;
Matthew Garrett62ec30d2008-07-25 01:45:39 -070088 u16 keycode;
89};
90
Matthew Garrett871043b2009-06-01 15:25:45 +010091enum { KE_KEY, KE_END };
Matthew Garrett62ec30d2008-07-25 01:45:39 -070092
93static struct key_entry hp_wmi_keymap[] = {
Matthew Garrett62ec30d2008-07-25 01:45:39 -070094 {KE_KEY, 0x02, KEY_BRIGHTNESSUP},
95 {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN},
Matthew Garretta8823ae2008-09-02 14:36:03 -070096 {KE_KEY, 0x20e6, KEY_PROG1},
97 {KE_KEY, 0x2142, KEY_MEDIA},
Eric Piel5c624842008-10-18 20:27:28 -070098 {KE_KEY, 0x213b, KEY_INFO},
Matthew Garrettcaeacf52010-02-17 10:29:39 -050099 {KE_KEY, 0x2169, KEY_DIRECTION},
Matthew Garretta8823ae2008-09-02 14:36:03 -0700100 {KE_KEY, 0x231b, KEY_HELP},
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700101 {KE_END, 0}
102};
103
104static struct input_dev *hp_wmi_input_dev;
105static struct platform_device *hp_wmi_platform_dev;
106
107static struct rfkill *wifi_rfkill;
108static struct rfkill *bluetooth_rfkill;
109static struct rfkill *wwan_rfkill;
110
Alexey Dobriyan47145212009-12-14 18:00:08 -0800111static const struct dev_pm_ops hp_wmi_pm_ops = {
Frans Pop8dd2b422009-08-20 20:38:13 +0200112 .resume = hp_wmi_resume_handler,
113 .restore = hp_wmi_resume_handler,
114};
115
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700116static struct platform_driver hp_wmi_driver = {
117 .driver = {
Frans Pop8dd2b422009-08-20 20:38:13 +0200118 .name = "hp-wmi",
119 .owner = THIS_MODULE,
120 .pm = &hp_wmi_pm_ops,
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700121 },
122 .probe = hp_wmi_bios_setup,
123 .remove = hp_wmi_bios_remove,
124};
125
126static 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 Renninger44ef00e2009-12-18 15:29:23 +0100145 if (!obj)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700146 return -EINVAL;
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100147 else if (obj->type != ACPI_TYPE_BUFFER) {
148 kfree(obj);
149 return -EINVAL;
150 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700151
152 bios_return = *((struct bios_return *)obj->buffer.pointer);
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100153 kfree(obj);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700154 if (bios_return.return_code > 0)
155 return bios_return.return_code * -1;
156 else
157 return bios_return.value;
158}
159
160static int hp_wmi_display_state(void)
161{
162 return hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, 0);
163}
164
165static int hp_wmi_hddtemp_state(void)
166{
167 return hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, 0);
168}
169
170static int hp_wmi_als_state(void)
171{
172 return hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, 0);
173}
174
175static int hp_wmi_dock_state(void)
176{
Matthew Garrett871043b2009-06-01 15:25:45 +0100177 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 Garrett62ec30d2008-07-25 01:45:39 -0700183}
184
Matthew Garrett871043b2009-06-01 15:25:45 +0100185static int hp_wmi_tablet_state(void)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700186{
Matthew Garrett871043b2009-06-01 15:25:45 +0100187 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 Garrett62ec30d2008-07-25 01:45:39 -0700193}
194
Johannes Berg19d337d2009-06-02 13:01:37 +0200195static int hp_wmi_set_block(void *data, bool blocked)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700196{
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100197 enum hp_wmi_radio r = (enum hp_wmi_radio) data;
198 int query = BIT(r + 8) | ((!blocked) << r);
Johannes Berg19d337d2009-06-02 13:01:37 +0200199
200 return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700201}
202
Johannes Berg19d337d2009-06-02 13:01:37 +0200203static const struct rfkill_ops hp_wmi_rfkill_ops = {
204 .set_block = hp_wmi_set_block,
205};
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700206
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100207static bool hp_wmi_get_sw_state(enum hp_wmi_radio r)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700208{
209 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100210 int mask = 0x200 << (r * 8);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700211
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100212 if (wireless & mask)
Johannes Berg19d337d2009-06-02 13:01:37 +0200213 return false;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700214 else
Johannes Berg19d337d2009-06-02 13:01:37 +0200215 return true;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700216}
217
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100218static bool hp_wmi_get_hw_state(enum hp_wmi_radio r)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700219{
220 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100221 int mask = 0x800 << (r * 8);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700222
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100223 if (wireless & mask)
Johannes Berg19d337d2009-06-02 13:01:37 +0200224 return false;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700225 else
Johannes Berg19d337d2009-06-02 13:01:37 +0200226 return true;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700227}
228
229static 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
238static 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
247static 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
256static 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 Garrett871043b2009-06-01 15:25:45 +0100265static 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 Garrett62ec30d2008-07-25 01:45:39 -0700274static 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
282static DEVICE_ATTR(display, S_IRUGO, show_display, NULL);
283static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL);
284static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als);
285static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL);
Matthew Garrett871043b2009-06-01 15:25:45 +0100286static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700287
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800288static struct key_entry *hp_wmi_get_entry_by_scancode(unsigned int code)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700289{
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 Torokhov58b93992010-03-08 22:37:10 -0800299static struct key_entry *hp_wmi_get_entry_by_keycode(unsigned int keycode)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700300{
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 Torokhov58b93992010-03-08 22:37:10 -0800310static int hp_wmi_getkeycode(struct input_dev *dev,
311 unsigned int scancode, unsigned int *keycode)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700312{
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 Torokhov58b93992010-03-08 22:37:10 -0800323static int hp_wmi_setkeycode(struct input_dev *dev,
324 unsigned int scancode, unsigned int keycode)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700325{
326 struct key_entry *key;
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800327 unsigned int old_keycode;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700328
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 Bunk88429a12008-10-15 22:05:17 -0700342static void hp_wmi_notify(u32 value, void *context)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700343{
344 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
345 static struct key_entry *key;
346 union acpi_object *obj;
Thomas Renninger751ae802010-05-21 16:18:09 +0200347 int eventcode, key_code;
Len Brownfda11e62009-12-26 23:02:24 -0500348 acpi_status status;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700349
Len Brownfda11e62009-12-26 23:02:24 -0500350 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 Garrett62ec30d2008-07-25 01:45:39 -0700355
356 obj = (union acpi_object *)response.pointer;
357
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100358 if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) {
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700359 printk(KERN_INFO "HP WMI: Unknown response received\n");
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100360 kfree(obj);
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100361 return;
362 }
363
364 eventcode = *((u8 *) obj->buffer.pointer);
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100365 kfree(obj);
Thomas Renninger751ae802010-05-21 16:18:09 +0200366 switch (eventcode) {
367 case HPWMI_DOCK_EVENT:
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100368 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 Renninger751ae802010-05-21 16:18:09 +0200373 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 Jenkinse5fbba82009-07-21 12:14:01 +0100392 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 Renninger751ae802010-05-21 16:18:09 +0200404 break;
405 default:
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100406 printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n",
407 eventcode);
Thomas Renninger751ae802010-05-21 16:18:09 +0200408 break;
409 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700410}
411
412static 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 Garrett62ec30d2008-07-25 01:45:39 -0700431 }
432 }
433
Matthew Garrett871043b2009-06-01 15:25:45 +0100434 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 Garrett62ec30d2008-07-25 01:45:39 -0700444 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
454static 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 Garrett871043b2009-06-01 15:25:45 +0100460 device_remove_file(&device->dev, &dev_attr_tablet);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700461}
462
Uwe Kleine-Königea796322010-02-04 20:56:52 +0100463static int __devinit hp_wmi_bios_setup(struct platform_device *device)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700464{
465 int err;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700466 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700467
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 Garrett871043b2009-06-01 15:25:45 +0100480 err = device_create_file(&device->dev, &dev_attr_tablet);
481 if (err)
482 goto add_sysfs_error;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700483
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700484 if (wireless & 0x1) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200485 wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
486 RFKILL_TYPE_WLAN,
487 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100488 (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 Fingerfe8e4e02009-01-09 16:40:54 -0800493 err = rfkill_register(wifi_rfkill);
494 if (err)
Johannes Berg19d337d2009-06-02 13:01:37 +0200495 goto register_wifi_error;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700496 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700497
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700498 if (wireless & 0x2) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200499 bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
500 RFKILL_TYPE_BLUETOOTH,
501 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100502 (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 Fingerfe8e4e02009-01-09 16:40:54 -0800507 err = rfkill_register(bluetooth_rfkill);
Frans Pop6989d562009-01-29 14:25:14 -0800508 if (err)
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800509 goto register_bluetooth_error;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700510 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700511
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700512 if (wireless & 0x4) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200513 wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
514 RFKILL_TYPE_WWAN,
515 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100516 (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 Fingerfe8e4e02009-01-09 16:40:54 -0800521 err = rfkill_register(wwan_rfkill);
522 if (err)
523 goto register_wwan_err;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700524 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700525
526 return 0;
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800527register_wwan_err:
Johannes Berg19d337d2009-06-02 13:01:37 +0200528 rfkill_destroy(wwan_rfkill);
Andrew Morton44f06062009-02-04 15:12:07 -0800529 if (bluetooth_rfkill)
530 rfkill_unregister(bluetooth_rfkill);
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800531register_bluetooth_error:
Johannes Berg19d337d2009-06-02 13:01:37 +0200532 rfkill_destroy(bluetooth_rfkill);
Andrew Morton44f06062009-02-04 15:12:07 -0800533 if (wifi_rfkill)
534 rfkill_unregister(wifi_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200535register_wifi_error:
536 rfkill_destroy(wifi_rfkill);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700537add_sysfs_error:
538 cleanup_sysfs(device);
539 return err;
540}
541
542static int __exit hp_wmi_bios_remove(struct platform_device *device)
543{
544 cleanup_sysfs(device);
545
Johannes Berg19d337d2009-06-02 13:01:37 +0200546 if (wifi_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700547 rfkill_unregister(wifi_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200548 rfkill_destroy(wifi_rfkill);
549 }
550 if (bluetooth_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700551 rfkill_unregister(bluetooth_rfkill);
Corentin Chary09729f02009-09-14 12:43:51 +0200552 rfkill_destroy(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200553 }
554 if (wwan_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700555 rfkill_unregister(wwan_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200556 rfkill_destroy(wwan_rfkill);
557 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700558
559 return 0;
560}
561
Frans Pop8dd2b422009-08-20 20:38:13 +0200562static int hp_wmi_resume_handler(struct device *device)
Frans Pop4c395bd2009-03-04 11:55:28 -0800563{
Frans Pop4c395bd2009-03-04 11:55:28 -0800564 /*
Matthew Garrett871043b2009-06-01 15:25:45 +0100565 * Hardware state may have changed while suspended, so trigger
566 * input events for the current state. As this is a switch,
Frans Pop4c395bd2009-03-04 11:55:28 -0800567 * the input layer will only actually pass it on if the state
568 * changed.
569 */
Frans Popdaed9532009-07-30 17:16:05 -0400570 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 Pop4c395bd2009-03-04 11:55:28 -0800577
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100578 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 Pop4c395bd2009-03-04 11:55:28 -0800591 return 0;
592}
593
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700594static 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 Brownf2772572009-12-26 22:04:03 -0500601 if (ACPI_SUCCESS(err))
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700602 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
620static 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
632module_init(hp_wmi_init);
633module_exit(hp_wmi_exit);