blob: f3ae911cbab9a781c3bbec70a7fa53f1019e6470 [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
Thomas Renningera2806c62010-05-21 16:18:11 +020055#define PREFIX "HP WMI: "
56
Alan Jenkinse5fbba82009-07-21 12:14:01 +010057enum hp_wmi_radio {
58 HPWMI_WIFI = 0,
59 HPWMI_BLUETOOTH = 1,
60 HPWMI_WWAN = 2,
61};
62
Thomas Renninger751ae802010-05-21 16:18:09 +020063enum hp_wmi_event_ids {
64 HPWMI_DOCK_EVENT = 1,
65 HPWMI_BEZEL_BUTTON = 4,
66 HPWMI_WIRELESS = 5,
67};
68
Uwe Kleine-Königea796322010-02-04 20:56:52 +010069static int __devinit hp_wmi_bios_setup(struct platform_device *device);
Matthew Garrett62ec30d2008-07-25 01:45:39 -070070static int __exit hp_wmi_bios_remove(struct platform_device *device);
Frans Pop8dd2b422009-08-20 20:38:13 +020071static int hp_wmi_resume_handler(struct device *device);
Matthew Garrett62ec30d2008-07-25 01:45:39 -070072
73struct bios_args {
74 u32 signature;
75 u32 command;
76 u32 commandtype;
77 u32 datasize;
78 u32 data;
79};
80
81struct bios_return {
82 u32 sigpass;
83 u32 return_code;
84 u32 value;
85};
86
87struct key_entry {
88 char type; /* See KE_* below */
Matthew Garretta8823ae2008-09-02 14:36:03 -070089 u16 code;
Matthew Garrett62ec30d2008-07-25 01:45:39 -070090 u16 keycode;
91};
92
Matthew Garrett871043b2009-06-01 15:25:45 +010093enum { KE_KEY, KE_END };
Matthew Garrett62ec30d2008-07-25 01:45:39 -070094
95static struct key_entry hp_wmi_keymap[] = {
Matthew Garrett62ec30d2008-07-25 01:45:39 -070096 {KE_KEY, 0x02, KEY_BRIGHTNESSUP},
97 {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN},
Matthew Garretta8823ae2008-09-02 14:36:03 -070098 {KE_KEY, 0x20e6, KEY_PROG1},
Thomas Renningerf6b2ff02010-05-21 16:18:12 +020099 {KE_KEY, 0x20e8, KEY_MEDIA},
Matthew Garretta8823ae2008-09-02 14:36:03 -0700100 {KE_KEY, 0x2142, KEY_MEDIA},
Eric Piel5c624842008-10-18 20:27:28 -0700101 {KE_KEY, 0x213b, KEY_INFO},
Matthew Garrettcaeacf52010-02-17 10:29:39 -0500102 {KE_KEY, 0x2169, KEY_DIRECTION},
Matthew Garretta8823ae2008-09-02 14:36:03 -0700103 {KE_KEY, 0x231b, KEY_HELP},
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700104 {KE_END, 0}
105};
106
107static struct input_dev *hp_wmi_input_dev;
108static struct platform_device *hp_wmi_platform_dev;
109
110static struct rfkill *wifi_rfkill;
111static struct rfkill *bluetooth_rfkill;
112static struct rfkill *wwan_rfkill;
113
Alexey Dobriyan47145212009-12-14 18:00:08 -0800114static const struct dev_pm_ops hp_wmi_pm_ops = {
Frans Pop8dd2b422009-08-20 20:38:13 +0200115 .resume = hp_wmi_resume_handler,
116 .restore = hp_wmi_resume_handler,
117};
118
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700119static struct platform_driver hp_wmi_driver = {
120 .driver = {
Frans Pop8dd2b422009-08-20 20:38:13 +0200121 .name = "hp-wmi",
122 .owner = THIS_MODULE,
123 .pm = &hp_wmi_pm_ops,
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700124 },
125 .probe = hp_wmi_bios_setup,
126 .remove = hp_wmi_bios_remove,
127};
128
129static int hp_wmi_perform_query(int query, int write, int value)
130{
131 struct bios_return bios_return;
132 acpi_status status;
133 union acpi_object *obj;
134 struct bios_args args = {
135 .signature = 0x55434553,
136 .command = write ? 0x2 : 0x1,
137 .commandtype = query,
138 .datasize = write ? 0x4 : 0,
139 .data = value,
140 };
141 struct acpi_buffer input = { sizeof(struct bios_args), &args };
142 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
143
144 status = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output);
145
146 obj = output.pointer;
147
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100148 if (!obj)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700149 return -EINVAL;
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100150 else if (obj->type != ACPI_TYPE_BUFFER) {
151 kfree(obj);
152 return -EINVAL;
153 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700154
155 bios_return = *((struct bios_return *)obj->buffer.pointer);
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100156 kfree(obj);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700157 if (bios_return.return_code > 0)
158 return bios_return.return_code * -1;
159 else
160 return bios_return.value;
161}
162
163static int hp_wmi_display_state(void)
164{
165 return hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, 0);
166}
167
168static int hp_wmi_hddtemp_state(void)
169{
170 return hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, 0);
171}
172
173static int hp_wmi_als_state(void)
174{
175 return hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, 0);
176}
177
178static int hp_wmi_dock_state(void)
179{
Matthew Garrett871043b2009-06-01 15:25:45 +0100180 int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0);
181
182 if (ret < 0)
183 return ret;
184
185 return ret & 0x1;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700186}
187
Matthew Garrett871043b2009-06-01 15:25:45 +0100188static int hp_wmi_tablet_state(void)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700189{
Matthew Garrett871043b2009-06-01 15:25:45 +0100190 int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0);
191
192 if (ret < 0)
193 return ret;
194
195 return (ret & 0x4) ? 1 : 0;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700196}
197
Johannes Berg19d337d2009-06-02 13:01:37 +0200198static int hp_wmi_set_block(void *data, bool blocked)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700199{
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100200 enum hp_wmi_radio r = (enum hp_wmi_radio) data;
201 int query = BIT(r + 8) | ((!blocked) << r);
Johannes Berg19d337d2009-06-02 13:01:37 +0200202
203 return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700204}
205
Johannes Berg19d337d2009-06-02 13:01:37 +0200206static const struct rfkill_ops hp_wmi_rfkill_ops = {
207 .set_block = hp_wmi_set_block,
208};
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700209
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100210static bool hp_wmi_get_sw_state(enum hp_wmi_radio r)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700211{
212 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100213 int mask = 0x200 << (r * 8);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700214
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100215 if (wireless & mask)
Johannes Berg19d337d2009-06-02 13:01:37 +0200216 return false;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700217 else
Johannes Berg19d337d2009-06-02 13:01:37 +0200218 return true;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700219}
220
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100221static bool hp_wmi_get_hw_state(enum hp_wmi_radio r)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700222{
223 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100224 int mask = 0x800 << (r * 8);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700225
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100226 if (wireless & mask)
Johannes Berg19d337d2009-06-02 13:01:37 +0200227 return false;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700228 else
Johannes Berg19d337d2009-06-02 13:01:37 +0200229 return true;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700230}
231
232static ssize_t show_display(struct device *dev, struct device_attribute *attr,
233 char *buf)
234{
235 int value = hp_wmi_display_state();
236 if (value < 0)
237 return -EINVAL;
238 return sprintf(buf, "%d\n", value);
239}
240
241static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr,
242 char *buf)
243{
244 int value = hp_wmi_hddtemp_state();
245 if (value < 0)
246 return -EINVAL;
247 return sprintf(buf, "%d\n", value);
248}
249
250static ssize_t show_als(struct device *dev, struct device_attribute *attr,
251 char *buf)
252{
253 int value = hp_wmi_als_state();
254 if (value < 0)
255 return -EINVAL;
256 return sprintf(buf, "%d\n", value);
257}
258
259static ssize_t show_dock(struct device *dev, struct device_attribute *attr,
260 char *buf)
261{
262 int value = hp_wmi_dock_state();
263 if (value < 0)
264 return -EINVAL;
265 return sprintf(buf, "%d\n", value);
266}
267
Matthew Garrett871043b2009-06-01 15:25:45 +0100268static ssize_t show_tablet(struct device *dev, struct device_attribute *attr,
269 char *buf)
270{
271 int value = hp_wmi_tablet_state();
272 if (value < 0)
273 return -EINVAL;
274 return sprintf(buf, "%d\n", value);
275}
276
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700277static ssize_t set_als(struct device *dev, struct device_attribute *attr,
278 const char *buf, size_t count)
279{
280 u32 tmp = simple_strtoul(buf, NULL, 10);
281 hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, tmp);
282 return count;
283}
284
285static DEVICE_ATTR(display, S_IRUGO, show_display, NULL);
286static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL);
287static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als);
288static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL);
Matthew Garrett871043b2009-06-01 15:25:45 +0100289static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700290
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800291static struct key_entry *hp_wmi_get_entry_by_scancode(unsigned int code)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700292{
293 struct key_entry *key;
294
295 for (key = hp_wmi_keymap; key->type != KE_END; key++)
296 if (code == key->code)
297 return key;
298
299 return NULL;
300}
301
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800302static struct key_entry *hp_wmi_get_entry_by_keycode(unsigned int keycode)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700303{
304 struct key_entry *key;
305
306 for (key = hp_wmi_keymap; key->type != KE_END; key++)
307 if (key->type == KE_KEY && keycode == key->keycode)
308 return key;
309
310 return NULL;
311}
312
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800313static int hp_wmi_getkeycode(struct input_dev *dev,
314 unsigned int scancode, unsigned int *keycode)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700315{
316 struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode);
317
318 if (key && key->type == KE_KEY) {
319 *keycode = key->keycode;
320 return 0;
321 }
322
323 return -EINVAL;
324}
325
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800326static int hp_wmi_setkeycode(struct input_dev *dev,
327 unsigned int scancode, unsigned int keycode)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700328{
329 struct key_entry *key;
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800330 unsigned int old_keycode;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700331
332 key = hp_wmi_get_entry_by_scancode(scancode);
333 if (key && key->type == KE_KEY) {
334 old_keycode = key->keycode;
335 key->keycode = keycode;
336 set_bit(keycode, dev->keybit);
337 if (!hp_wmi_get_entry_by_keycode(old_keycode))
338 clear_bit(old_keycode, dev->keybit);
339 return 0;
340 }
341
342 return -EINVAL;
343}
344
Adrian Bunk88429a12008-10-15 22:05:17 -0700345static void hp_wmi_notify(u32 value, void *context)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700346{
347 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
348 static struct key_entry *key;
349 union acpi_object *obj;
Thomas Renninger751ae802010-05-21 16:18:09 +0200350 int eventcode, key_code;
Len Brownfda11e62009-12-26 23:02:24 -0500351 acpi_status status;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700352
Len Brownfda11e62009-12-26 23:02:24 -0500353 status = wmi_get_event_data(value, &response);
354 if (status != AE_OK) {
Thomas Renningera2806c62010-05-21 16:18:11 +0200355 printk(KERN_INFO PREFIX "bad event status 0x%x\n", status);
Len Brownfda11e62009-12-26 23:02:24 -0500356 return;
357 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700358
359 obj = (union acpi_object *)response.pointer;
360
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100361 if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) {
Thomas Renningera2806c62010-05-21 16:18:11 +0200362 printk(KERN_INFO PREFIX "Unknown response received\n");
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100363 kfree(obj);
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100364 return;
365 }
366
367 eventcode = *((u8 *) obj->buffer.pointer);
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100368 kfree(obj);
Thomas Renninger751ae802010-05-21 16:18:09 +0200369 switch (eventcode) {
370 case HPWMI_DOCK_EVENT:
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100371 input_report_switch(hp_wmi_input_dev, SW_DOCK,
372 hp_wmi_dock_state());
373 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
374 hp_wmi_tablet_state());
375 input_sync(hp_wmi_input_dev);
Thomas Renninger751ae802010-05-21 16:18:09 +0200376 break;
377 case HPWMI_BEZEL_BUTTON:
378 key_code = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0,
379 0);
380 key = hp_wmi_get_entry_by_scancode(key_code);
381 if (key) {
382 switch (key->type) {
383 case KE_KEY:
384 input_report_key(hp_wmi_input_dev,
385 key->keycode, 1);
386 input_sync(hp_wmi_input_dev);
387 input_report_key(hp_wmi_input_dev,
388 key->keycode, 0);
389 input_sync(hp_wmi_input_dev);
390 break;
391 }
Thomas Renningerda9a79b2010-05-21 16:18:10 +0200392 } else
Thomas Renningera2806c62010-05-21 16:18:11 +0200393 printk(KERN_INFO PREFIX "Unknown key code - 0x%x\n",
Thomas Renningerda9a79b2010-05-21 16:18:10 +0200394 key_code);
Thomas Renninger751ae802010-05-21 16:18:09 +0200395 break;
396 case HPWMI_WIRELESS:
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100397 if (wifi_rfkill)
398 rfkill_set_states(wifi_rfkill,
399 hp_wmi_get_sw_state(HPWMI_WIFI),
400 hp_wmi_get_hw_state(HPWMI_WIFI));
401 if (bluetooth_rfkill)
402 rfkill_set_states(bluetooth_rfkill,
403 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
404 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
405 if (wwan_rfkill)
406 rfkill_set_states(wwan_rfkill,
407 hp_wmi_get_sw_state(HPWMI_WWAN),
408 hp_wmi_get_hw_state(HPWMI_WWAN));
Thomas Renninger751ae802010-05-21 16:18:09 +0200409 break;
410 default:
Thomas Renningera2806c62010-05-21 16:18:11 +0200411 printk(KERN_INFO PREFIX "Unknown eventcode - %d\n",
Thomas Renningerda9a79b2010-05-21 16:18:10 +0200412 eventcode);
Thomas Renninger751ae802010-05-21 16:18:09 +0200413 break;
414 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700415}
416
417static int __init hp_wmi_input_setup(void)
418{
419 struct key_entry *key;
420 int err;
421
422 hp_wmi_input_dev = input_allocate_device();
423
424 hp_wmi_input_dev->name = "HP WMI hotkeys";
425 hp_wmi_input_dev->phys = "wmi/input0";
426 hp_wmi_input_dev->id.bustype = BUS_HOST;
427 hp_wmi_input_dev->getkeycode = hp_wmi_getkeycode;
428 hp_wmi_input_dev->setkeycode = hp_wmi_setkeycode;
429
430 for (key = hp_wmi_keymap; key->type != KE_END; key++) {
431 switch (key->type) {
432 case KE_KEY:
433 set_bit(EV_KEY, hp_wmi_input_dev->evbit);
434 set_bit(key->keycode, hp_wmi_input_dev->keybit);
435 break;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700436 }
437 }
438
Matthew Garrett871043b2009-06-01 15:25:45 +0100439 set_bit(EV_SW, hp_wmi_input_dev->evbit);
440 set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
441 set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
442
443 /* Set initial hardware state */
444 input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state());
445 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
446 hp_wmi_tablet_state());
447 input_sync(hp_wmi_input_dev);
448
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700449 err = input_register_device(hp_wmi_input_dev);
450
451 if (err) {
452 input_free_device(hp_wmi_input_dev);
453 return err;
454 }
455
456 return 0;
457}
458
459static void cleanup_sysfs(struct platform_device *device)
460{
461 device_remove_file(&device->dev, &dev_attr_display);
462 device_remove_file(&device->dev, &dev_attr_hddtemp);
463 device_remove_file(&device->dev, &dev_attr_als);
464 device_remove_file(&device->dev, &dev_attr_dock);
Matthew Garrett871043b2009-06-01 15:25:45 +0100465 device_remove_file(&device->dev, &dev_attr_tablet);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700466}
467
Uwe Kleine-Königea796322010-02-04 20:56:52 +0100468static int __devinit hp_wmi_bios_setup(struct platform_device *device)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700469{
470 int err;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700471 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700472
473 err = device_create_file(&device->dev, &dev_attr_display);
474 if (err)
475 goto add_sysfs_error;
476 err = device_create_file(&device->dev, &dev_attr_hddtemp);
477 if (err)
478 goto add_sysfs_error;
479 err = device_create_file(&device->dev, &dev_attr_als);
480 if (err)
481 goto add_sysfs_error;
482 err = device_create_file(&device->dev, &dev_attr_dock);
483 if (err)
484 goto add_sysfs_error;
Matthew Garrett871043b2009-06-01 15:25:45 +0100485 err = device_create_file(&device->dev, &dev_attr_tablet);
486 if (err)
487 goto add_sysfs_error;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700488
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700489 if (wireless & 0x1) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200490 wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
491 RFKILL_TYPE_WLAN,
492 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100493 (void *) HPWMI_WIFI);
494 rfkill_init_sw_state(wifi_rfkill,
495 hp_wmi_get_sw_state(HPWMI_WIFI));
496 rfkill_set_hw_state(wifi_rfkill,
497 hp_wmi_get_hw_state(HPWMI_WIFI));
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800498 err = rfkill_register(wifi_rfkill);
499 if (err)
Johannes Berg19d337d2009-06-02 13:01:37 +0200500 goto register_wifi_error;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700501 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700502
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700503 if (wireless & 0x2) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200504 bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
505 RFKILL_TYPE_BLUETOOTH,
506 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100507 (void *) HPWMI_BLUETOOTH);
508 rfkill_init_sw_state(bluetooth_rfkill,
509 hp_wmi_get_sw_state(HPWMI_BLUETOOTH));
510 rfkill_set_hw_state(bluetooth_rfkill,
511 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800512 err = rfkill_register(bluetooth_rfkill);
Frans Pop6989d562009-01-29 14:25:14 -0800513 if (err)
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800514 goto register_bluetooth_error;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700515 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700516
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700517 if (wireless & 0x4) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200518 wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
519 RFKILL_TYPE_WWAN,
520 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100521 (void *) HPWMI_WWAN);
522 rfkill_init_sw_state(wwan_rfkill,
523 hp_wmi_get_sw_state(HPWMI_WWAN));
524 rfkill_set_hw_state(wwan_rfkill,
525 hp_wmi_get_hw_state(HPWMI_WWAN));
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800526 err = rfkill_register(wwan_rfkill);
527 if (err)
528 goto register_wwan_err;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700529 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700530
531 return 0;
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800532register_wwan_err:
Johannes Berg19d337d2009-06-02 13:01:37 +0200533 rfkill_destroy(wwan_rfkill);
Andrew Morton44f06062009-02-04 15:12:07 -0800534 if (bluetooth_rfkill)
535 rfkill_unregister(bluetooth_rfkill);
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800536register_bluetooth_error:
Johannes Berg19d337d2009-06-02 13:01:37 +0200537 rfkill_destroy(bluetooth_rfkill);
Andrew Morton44f06062009-02-04 15:12:07 -0800538 if (wifi_rfkill)
539 rfkill_unregister(wifi_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200540register_wifi_error:
541 rfkill_destroy(wifi_rfkill);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700542add_sysfs_error:
543 cleanup_sysfs(device);
544 return err;
545}
546
547static int __exit hp_wmi_bios_remove(struct platform_device *device)
548{
549 cleanup_sysfs(device);
550
Johannes Berg19d337d2009-06-02 13:01:37 +0200551 if (wifi_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700552 rfkill_unregister(wifi_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200553 rfkill_destroy(wifi_rfkill);
554 }
555 if (bluetooth_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700556 rfkill_unregister(bluetooth_rfkill);
Corentin Chary09729f02009-09-14 12:43:51 +0200557 rfkill_destroy(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200558 }
559 if (wwan_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700560 rfkill_unregister(wwan_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200561 rfkill_destroy(wwan_rfkill);
562 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700563
564 return 0;
565}
566
Frans Pop8dd2b422009-08-20 20:38:13 +0200567static int hp_wmi_resume_handler(struct device *device)
Frans Pop4c395bd2009-03-04 11:55:28 -0800568{
Frans Pop4c395bd2009-03-04 11:55:28 -0800569 /*
Matthew Garrett871043b2009-06-01 15:25:45 +0100570 * Hardware state may have changed while suspended, so trigger
571 * input events for the current state. As this is a switch,
Frans Pop4c395bd2009-03-04 11:55:28 -0800572 * the input layer will only actually pass it on if the state
573 * changed.
574 */
Frans Popdaed9532009-07-30 17:16:05 -0400575 if (hp_wmi_input_dev) {
576 input_report_switch(hp_wmi_input_dev, SW_DOCK,
577 hp_wmi_dock_state());
578 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
579 hp_wmi_tablet_state());
580 input_sync(hp_wmi_input_dev);
581 }
Frans Pop4c395bd2009-03-04 11:55:28 -0800582
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100583 if (wifi_rfkill)
584 rfkill_set_states(wifi_rfkill,
585 hp_wmi_get_sw_state(HPWMI_WIFI),
586 hp_wmi_get_hw_state(HPWMI_WIFI));
587 if (bluetooth_rfkill)
588 rfkill_set_states(bluetooth_rfkill,
589 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
590 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
591 if (wwan_rfkill)
592 rfkill_set_states(wwan_rfkill,
593 hp_wmi_get_sw_state(HPWMI_WWAN),
594 hp_wmi_get_hw_state(HPWMI_WWAN));
595
Frans Pop4c395bd2009-03-04 11:55:28 -0800596 return 0;
597}
598
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700599static int __init hp_wmi_init(void)
600{
601 int err;
602
603 if (wmi_has_guid(HPWMI_EVENT_GUID)) {
604 err = wmi_install_notify_handler(HPWMI_EVENT_GUID,
605 hp_wmi_notify, NULL);
Len Brownf2772572009-12-26 22:04:03 -0500606 if (ACPI_SUCCESS(err))
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700607 hp_wmi_input_setup();
608 }
609
610 if (wmi_has_guid(HPWMI_BIOS_GUID)) {
611 err = platform_driver_register(&hp_wmi_driver);
612 if (err)
613 return 0;
614 hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1);
615 if (!hp_wmi_platform_dev) {
616 platform_driver_unregister(&hp_wmi_driver);
617 return 0;
618 }
619 platform_device_add(hp_wmi_platform_dev);
620 }
621
622 return 0;
623}
624
625static void __exit hp_wmi_exit(void)
626{
627 if (wmi_has_guid(HPWMI_EVENT_GUID)) {
628 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
629 input_unregister_device(hp_wmi_input_dev);
630 }
631 if (hp_wmi_platform_dev) {
632 platform_device_del(hp_wmi_platform_dev);
633 platform_driver_unregister(&hp_wmi_driver);
634 }
635}
636
637module_init(hp_wmi_init);
638module_exit(hp_wmi_exit);