blob: 7b086ddf7b2d84db0591f7e98143d5fecf567204 [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 }
Thomas Renningerda9a79b2010-05-21 16:18:10 +0200389 } else
390 printk(KERN_INFO "HP WMI: Unknown key code - 0x%x\n",
391 key_code);
Thomas Renninger751ae802010-05-21 16:18:09 +0200392 break;
393 case HPWMI_WIRELESS:
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100394 if (wifi_rfkill)
395 rfkill_set_states(wifi_rfkill,
396 hp_wmi_get_sw_state(HPWMI_WIFI),
397 hp_wmi_get_hw_state(HPWMI_WIFI));
398 if (bluetooth_rfkill)
399 rfkill_set_states(bluetooth_rfkill,
400 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
401 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
402 if (wwan_rfkill)
403 rfkill_set_states(wwan_rfkill,
404 hp_wmi_get_sw_state(HPWMI_WWAN),
405 hp_wmi_get_hw_state(HPWMI_WWAN));
Thomas Renninger751ae802010-05-21 16:18:09 +0200406 break;
407 default:
Thomas Renningerda9a79b2010-05-21 16:18:10 +0200408 printk(KERN_INFO "HP WMI: Unknown eventcode - %d\n",
409 eventcode);
Thomas Renninger751ae802010-05-21 16:18:09 +0200410 break;
411 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700412}
413
414static int __init hp_wmi_input_setup(void)
415{
416 struct key_entry *key;
417 int err;
418
419 hp_wmi_input_dev = input_allocate_device();
420
421 hp_wmi_input_dev->name = "HP WMI hotkeys";
422 hp_wmi_input_dev->phys = "wmi/input0";
423 hp_wmi_input_dev->id.bustype = BUS_HOST;
424 hp_wmi_input_dev->getkeycode = hp_wmi_getkeycode;
425 hp_wmi_input_dev->setkeycode = hp_wmi_setkeycode;
426
427 for (key = hp_wmi_keymap; key->type != KE_END; key++) {
428 switch (key->type) {
429 case KE_KEY:
430 set_bit(EV_KEY, hp_wmi_input_dev->evbit);
431 set_bit(key->keycode, hp_wmi_input_dev->keybit);
432 break;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700433 }
434 }
435
Matthew Garrett871043b2009-06-01 15:25:45 +0100436 set_bit(EV_SW, hp_wmi_input_dev->evbit);
437 set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
438 set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
439
440 /* Set initial hardware state */
441 input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state());
442 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
443 hp_wmi_tablet_state());
444 input_sync(hp_wmi_input_dev);
445
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700446 err = input_register_device(hp_wmi_input_dev);
447
448 if (err) {
449 input_free_device(hp_wmi_input_dev);
450 return err;
451 }
452
453 return 0;
454}
455
456static void cleanup_sysfs(struct platform_device *device)
457{
458 device_remove_file(&device->dev, &dev_attr_display);
459 device_remove_file(&device->dev, &dev_attr_hddtemp);
460 device_remove_file(&device->dev, &dev_attr_als);
461 device_remove_file(&device->dev, &dev_attr_dock);
Matthew Garrett871043b2009-06-01 15:25:45 +0100462 device_remove_file(&device->dev, &dev_attr_tablet);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700463}
464
Uwe Kleine-Königea796322010-02-04 20:56:52 +0100465static int __devinit hp_wmi_bios_setup(struct platform_device *device)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700466{
467 int err;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700468 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700469
470 err = device_create_file(&device->dev, &dev_attr_display);
471 if (err)
472 goto add_sysfs_error;
473 err = device_create_file(&device->dev, &dev_attr_hddtemp);
474 if (err)
475 goto add_sysfs_error;
476 err = device_create_file(&device->dev, &dev_attr_als);
477 if (err)
478 goto add_sysfs_error;
479 err = device_create_file(&device->dev, &dev_attr_dock);
480 if (err)
481 goto add_sysfs_error;
Matthew Garrett871043b2009-06-01 15:25:45 +0100482 err = device_create_file(&device->dev, &dev_attr_tablet);
483 if (err)
484 goto add_sysfs_error;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700485
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700486 if (wireless & 0x1) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200487 wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
488 RFKILL_TYPE_WLAN,
489 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100490 (void *) HPWMI_WIFI);
491 rfkill_init_sw_state(wifi_rfkill,
492 hp_wmi_get_sw_state(HPWMI_WIFI));
493 rfkill_set_hw_state(wifi_rfkill,
494 hp_wmi_get_hw_state(HPWMI_WIFI));
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800495 err = rfkill_register(wifi_rfkill);
496 if (err)
Johannes Berg19d337d2009-06-02 13:01:37 +0200497 goto register_wifi_error;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700498 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700499
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700500 if (wireless & 0x2) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200501 bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
502 RFKILL_TYPE_BLUETOOTH,
503 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100504 (void *) HPWMI_BLUETOOTH);
505 rfkill_init_sw_state(bluetooth_rfkill,
506 hp_wmi_get_sw_state(HPWMI_BLUETOOTH));
507 rfkill_set_hw_state(bluetooth_rfkill,
508 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800509 err = rfkill_register(bluetooth_rfkill);
Frans Pop6989d562009-01-29 14:25:14 -0800510 if (err)
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800511 goto register_bluetooth_error;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700512 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700513
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700514 if (wireless & 0x4) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200515 wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
516 RFKILL_TYPE_WWAN,
517 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100518 (void *) HPWMI_WWAN);
519 rfkill_init_sw_state(wwan_rfkill,
520 hp_wmi_get_sw_state(HPWMI_WWAN));
521 rfkill_set_hw_state(wwan_rfkill,
522 hp_wmi_get_hw_state(HPWMI_WWAN));
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800523 err = rfkill_register(wwan_rfkill);
524 if (err)
525 goto register_wwan_err;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700526 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700527
528 return 0;
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800529register_wwan_err:
Johannes Berg19d337d2009-06-02 13:01:37 +0200530 rfkill_destroy(wwan_rfkill);
Andrew Morton44f06062009-02-04 15:12:07 -0800531 if (bluetooth_rfkill)
532 rfkill_unregister(bluetooth_rfkill);
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800533register_bluetooth_error:
Johannes Berg19d337d2009-06-02 13:01:37 +0200534 rfkill_destroy(bluetooth_rfkill);
Andrew Morton44f06062009-02-04 15:12:07 -0800535 if (wifi_rfkill)
536 rfkill_unregister(wifi_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200537register_wifi_error:
538 rfkill_destroy(wifi_rfkill);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700539add_sysfs_error:
540 cleanup_sysfs(device);
541 return err;
542}
543
544static int __exit hp_wmi_bios_remove(struct platform_device *device)
545{
546 cleanup_sysfs(device);
547
Johannes Berg19d337d2009-06-02 13:01:37 +0200548 if (wifi_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700549 rfkill_unregister(wifi_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200550 rfkill_destroy(wifi_rfkill);
551 }
552 if (bluetooth_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700553 rfkill_unregister(bluetooth_rfkill);
Corentin Chary09729f02009-09-14 12:43:51 +0200554 rfkill_destroy(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200555 }
556 if (wwan_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700557 rfkill_unregister(wwan_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200558 rfkill_destroy(wwan_rfkill);
559 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700560
561 return 0;
562}
563
Frans Pop8dd2b422009-08-20 20:38:13 +0200564static int hp_wmi_resume_handler(struct device *device)
Frans Pop4c395bd2009-03-04 11:55:28 -0800565{
Frans Pop4c395bd2009-03-04 11:55:28 -0800566 /*
Matthew Garrett871043b2009-06-01 15:25:45 +0100567 * Hardware state may have changed while suspended, so trigger
568 * input events for the current state. As this is a switch,
Frans Pop4c395bd2009-03-04 11:55:28 -0800569 * the input layer will only actually pass it on if the state
570 * changed.
571 */
Frans Popdaed9532009-07-30 17:16:05 -0400572 if (hp_wmi_input_dev) {
573 input_report_switch(hp_wmi_input_dev, SW_DOCK,
574 hp_wmi_dock_state());
575 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
576 hp_wmi_tablet_state());
577 input_sync(hp_wmi_input_dev);
578 }
Frans Pop4c395bd2009-03-04 11:55:28 -0800579
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100580 if (wifi_rfkill)
581 rfkill_set_states(wifi_rfkill,
582 hp_wmi_get_sw_state(HPWMI_WIFI),
583 hp_wmi_get_hw_state(HPWMI_WIFI));
584 if (bluetooth_rfkill)
585 rfkill_set_states(bluetooth_rfkill,
586 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
587 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
588 if (wwan_rfkill)
589 rfkill_set_states(wwan_rfkill,
590 hp_wmi_get_sw_state(HPWMI_WWAN),
591 hp_wmi_get_hw_state(HPWMI_WWAN));
592
Frans Pop4c395bd2009-03-04 11:55:28 -0800593 return 0;
594}
595
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700596static int __init hp_wmi_init(void)
597{
598 int err;
599
600 if (wmi_has_guid(HPWMI_EVENT_GUID)) {
601 err = wmi_install_notify_handler(HPWMI_EVENT_GUID,
602 hp_wmi_notify, NULL);
Len Brownf2772572009-12-26 22:04:03 -0500603 if (ACPI_SUCCESS(err))
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700604 hp_wmi_input_setup();
605 }
606
607 if (wmi_has_guid(HPWMI_BIOS_GUID)) {
608 err = platform_driver_register(&hp_wmi_driver);
609 if (err)
610 return 0;
611 hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1);
612 if (!hp_wmi_platform_dev) {
613 platform_driver_unregister(&hp_wmi_driver);
614 return 0;
615 }
616 platform_device_add(hp_wmi_platform_dev);
617 }
618
619 return 0;
620}
621
622static void __exit hp_wmi_exit(void)
623{
624 if (wmi_has_guid(HPWMI_EVENT_GUID)) {
625 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
626 input_unregister_device(hp_wmi_input_dev);
627 }
628 if (hp_wmi_platform_dev) {
629 platform_device_del(hp_wmi_platform_dev);
630 platform_driver_unregister(&hp_wmi_driver);
631 }
632}
633
634module_init(hp_wmi_init);
635module_exit(hp_wmi_exit);