blob: 51c07a05a7bca4056b548ecdbb7b06afaf3cfad3 [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
Uwe Kleine-Königea796322010-02-04 20:56:52 +010061static int __devinit hp_wmi_bios_setup(struct platform_device *device);
Matthew Garrett62ec30d2008-07-25 01:45:39 -070062static int __exit hp_wmi_bios_remove(struct platform_device *device);
Frans Pop8dd2b422009-08-20 20:38:13 +020063static int hp_wmi_resume_handler(struct device *device);
Matthew Garrett62ec30d2008-07-25 01:45:39 -070064
65struct bios_args {
66 u32 signature;
67 u32 command;
68 u32 commandtype;
69 u32 datasize;
70 u32 data;
71};
72
73struct bios_return {
74 u32 sigpass;
75 u32 return_code;
76 u32 value;
77};
78
79struct key_entry {
80 char type; /* See KE_* below */
Matthew Garretta8823ae2008-09-02 14:36:03 -070081 u16 code;
Matthew Garrett62ec30d2008-07-25 01:45:39 -070082 u16 keycode;
83};
84
Matthew Garrett871043b2009-06-01 15:25:45 +010085enum { KE_KEY, KE_END };
Matthew Garrett62ec30d2008-07-25 01:45:39 -070086
87static struct key_entry hp_wmi_keymap[] = {
Matthew Garrett62ec30d2008-07-25 01:45:39 -070088 {KE_KEY, 0x02, KEY_BRIGHTNESSUP},
89 {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN},
Matthew Garretta8823ae2008-09-02 14:36:03 -070090 {KE_KEY, 0x20e6, KEY_PROG1},
91 {KE_KEY, 0x2142, KEY_MEDIA},
Eric Piel5c624842008-10-18 20:27:28 -070092 {KE_KEY, 0x213b, KEY_INFO},
Matthew Garrettcaeacf52010-02-17 10:29:39 -050093 {KE_KEY, 0x2169, KEY_DIRECTION},
Matthew Garretta8823ae2008-09-02 14:36:03 -070094 {KE_KEY, 0x231b, KEY_HELP},
Matthew Garrett62ec30d2008-07-25 01:45:39 -070095 {KE_END, 0}
96};
97
98static struct input_dev *hp_wmi_input_dev;
99static struct platform_device *hp_wmi_platform_dev;
100
101static struct rfkill *wifi_rfkill;
102static struct rfkill *bluetooth_rfkill;
103static struct rfkill *wwan_rfkill;
104
Alexey Dobriyan47145212009-12-14 18:00:08 -0800105static const struct dev_pm_ops hp_wmi_pm_ops = {
Frans Pop8dd2b422009-08-20 20:38:13 +0200106 .resume = hp_wmi_resume_handler,
107 .restore = hp_wmi_resume_handler,
108};
109
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700110static struct platform_driver hp_wmi_driver = {
111 .driver = {
Frans Pop8dd2b422009-08-20 20:38:13 +0200112 .name = "hp-wmi",
113 .owner = THIS_MODULE,
114 .pm = &hp_wmi_pm_ops,
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700115 },
116 .probe = hp_wmi_bios_setup,
117 .remove = hp_wmi_bios_remove,
118};
119
120static int hp_wmi_perform_query(int query, int write, int value)
121{
122 struct bios_return bios_return;
123 acpi_status status;
124 union acpi_object *obj;
125 struct bios_args args = {
126 .signature = 0x55434553,
127 .command = write ? 0x2 : 0x1,
128 .commandtype = query,
129 .datasize = write ? 0x4 : 0,
130 .data = value,
131 };
132 struct acpi_buffer input = { sizeof(struct bios_args), &args };
133 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
134
135 status = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output);
136
137 obj = output.pointer;
138
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100139 if (!obj)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700140 return -EINVAL;
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100141 else if (obj->type != ACPI_TYPE_BUFFER) {
142 kfree(obj);
143 return -EINVAL;
144 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700145
146 bios_return = *((struct bios_return *)obj->buffer.pointer);
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100147 kfree(obj);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700148 if (bios_return.return_code > 0)
149 return bios_return.return_code * -1;
150 else
151 return bios_return.value;
152}
153
154static int hp_wmi_display_state(void)
155{
156 return hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, 0);
157}
158
159static int hp_wmi_hddtemp_state(void)
160{
161 return hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, 0);
162}
163
164static int hp_wmi_als_state(void)
165{
166 return hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, 0);
167}
168
169static int hp_wmi_dock_state(void)
170{
Matthew Garrett871043b2009-06-01 15:25:45 +0100171 int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0);
172
173 if (ret < 0)
174 return ret;
175
176 return ret & 0x1;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700177}
178
Matthew Garrett871043b2009-06-01 15:25:45 +0100179static int hp_wmi_tablet_state(void)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700180{
Matthew Garrett871043b2009-06-01 15:25:45 +0100181 int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0);
182
183 if (ret < 0)
184 return ret;
185
186 return (ret & 0x4) ? 1 : 0;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700187}
188
Johannes Berg19d337d2009-06-02 13:01:37 +0200189static int hp_wmi_set_block(void *data, bool blocked)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700190{
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100191 enum hp_wmi_radio r = (enum hp_wmi_radio) data;
192 int query = BIT(r + 8) | ((!blocked) << r);
Johannes Berg19d337d2009-06-02 13:01:37 +0200193
194 return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700195}
196
Johannes Berg19d337d2009-06-02 13:01:37 +0200197static const struct rfkill_ops hp_wmi_rfkill_ops = {
198 .set_block = hp_wmi_set_block,
199};
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700200
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100201static bool hp_wmi_get_sw_state(enum hp_wmi_radio r)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700202{
203 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100204 int mask = 0x200 << (r * 8);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700205
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100206 if (wireless & mask)
Johannes Berg19d337d2009-06-02 13:01:37 +0200207 return false;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700208 else
Johannes Berg19d337d2009-06-02 13:01:37 +0200209 return true;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700210}
211
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100212static bool hp_wmi_get_hw_state(enum hp_wmi_radio r)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700213{
214 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100215 int mask = 0x800 << (r * 8);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700216
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100217 if (wireless & mask)
Johannes Berg19d337d2009-06-02 13:01:37 +0200218 return false;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700219 else
Johannes Berg19d337d2009-06-02 13:01:37 +0200220 return true;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700221}
222
223static ssize_t show_display(struct device *dev, struct device_attribute *attr,
224 char *buf)
225{
226 int value = hp_wmi_display_state();
227 if (value < 0)
228 return -EINVAL;
229 return sprintf(buf, "%d\n", value);
230}
231
232static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr,
233 char *buf)
234{
235 int value = hp_wmi_hddtemp_state();
236 if (value < 0)
237 return -EINVAL;
238 return sprintf(buf, "%d\n", value);
239}
240
241static ssize_t show_als(struct device *dev, struct device_attribute *attr,
242 char *buf)
243{
244 int value = hp_wmi_als_state();
245 if (value < 0)
246 return -EINVAL;
247 return sprintf(buf, "%d\n", value);
248}
249
250static ssize_t show_dock(struct device *dev, struct device_attribute *attr,
251 char *buf)
252{
253 int value = hp_wmi_dock_state();
254 if (value < 0)
255 return -EINVAL;
256 return sprintf(buf, "%d\n", value);
257}
258
Matthew Garrett871043b2009-06-01 15:25:45 +0100259static ssize_t show_tablet(struct device *dev, struct device_attribute *attr,
260 char *buf)
261{
262 int value = hp_wmi_tablet_state();
263 if (value < 0)
264 return -EINVAL;
265 return sprintf(buf, "%d\n", value);
266}
267
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700268static ssize_t set_als(struct device *dev, struct device_attribute *attr,
269 const char *buf, size_t count)
270{
271 u32 tmp = simple_strtoul(buf, NULL, 10);
272 hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, tmp);
273 return count;
274}
275
276static DEVICE_ATTR(display, S_IRUGO, show_display, NULL);
277static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL);
278static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als);
279static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL);
Matthew Garrett871043b2009-06-01 15:25:45 +0100280static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700281
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800282static struct key_entry *hp_wmi_get_entry_by_scancode(unsigned int code)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700283{
284 struct key_entry *key;
285
286 for (key = hp_wmi_keymap; key->type != KE_END; key++)
287 if (code == key->code)
288 return key;
289
290 return NULL;
291}
292
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800293static struct key_entry *hp_wmi_get_entry_by_keycode(unsigned int keycode)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700294{
295 struct key_entry *key;
296
297 for (key = hp_wmi_keymap; key->type != KE_END; key++)
298 if (key->type == KE_KEY && keycode == key->keycode)
299 return key;
300
301 return NULL;
302}
303
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800304static int hp_wmi_getkeycode(struct input_dev *dev,
305 unsigned int scancode, unsigned int *keycode)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700306{
307 struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode);
308
309 if (key && key->type == KE_KEY) {
310 *keycode = key->keycode;
311 return 0;
312 }
313
314 return -EINVAL;
315}
316
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800317static int hp_wmi_setkeycode(struct input_dev *dev,
318 unsigned int scancode, unsigned int keycode)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700319{
320 struct key_entry *key;
Dmitry Torokhov58b93992010-03-08 22:37:10 -0800321 unsigned int old_keycode;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700322
323 key = hp_wmi_get_entry_by_scancode(scancode);
324 if (key && key->type == KE_KEY) {
325 old_keycode = key->keycode;
326 key->keycode = keycode;
327 set_bit(keycode, dev->keybit);
328 if (!hp_wmi_get_entry_by_keycode(old_keycode))
329 clear_bit(old_keycode, dev->keybit);
330 return 0;
331 }
332
333 return -EINVAL;
334}
335
Adrian Bunk88429a12008-10-15 22:05:17 -0700336static void hp_wmi_notify(u32 value, void *context)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700337{
338 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
339 static struct key_entry *key;
340 union acpi_object *obj;
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100341 int eventcode;
Len Brownfda11e62009-12-26 23:02:24 -0500342 acpi_status status;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700343
Len Brownfda11e62009-12-26 23:02:24 -0500344 status = wmi_get_event_data(value, &response);
345 if (status != AE_OK) {
346 printk(KERN_INFO "hp-wmi: bad event status 0x%x\n", status);
347 return;
348 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700349
350 obj = (union acpi_object *)response.pointer;
351
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100352 if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) {
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700353 printk(KERN_INFO "HP WMI: Unknown response received\n");
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100354 kfree(obj);
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100355 return;
356 }
357
358 eventcode = *((u8 *) obj->buffer.pointer);
Thomas Renninger44ef00e2009-12-18 15:29:23 +0100359 kfree(obj);
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100360 if (eventcode == 0x4)
361 eventcode = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0,
362 0);
363 key = hp_wmi_get_entry_by_scancode(eventcode);
364 if (key) {
365 switch (key->type) {
366 case KE_KEY:
367 input_report_key(hp_wmi_input_dev,
368 key->keycode, 1);
369 input_sync(hp_wmi_input_dev);
370 input_report_key(hp_wmi_input_dev,
371 key->keycode, 0);
372 input_sync(hp_wmi_input_dev);
373 break;
374 }
375 } else if (eventcode == 0x1) {
376 input_report_switch(hp_wmi_input_dev, SW_DOCK,
377 hp_wmi_dock_state());
378 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
379 hp_wmi_tablet_state());
380 input_sync(hp_wmi_input_dev);
381 } else if (eventcode == 0x5) {
382 if (wifi_rfkill)
383 rfkill_set_states(wifi_rfkill,
384 hp_wmi_get_sw_state(HPWMI_WIFI),
385 hp_wmi_get_hw_state(HPWMI_WIFI));
386 if (bluetooth_rfkill)
387 rfkill_set_states(bluetooth_rfkill,
388 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
389 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
390 if (wwan_rfkill)
391 rfkill_set_states(wwan_rfkill,
392 hp_wmi_get_sw_state(HPWMI_WWAN),
393 hp_wmi_get_hw_state(HPWMI_WWAN));
394 } else
395 printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n",
396 eventcode);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700397}
398
399static int __init hp_wmi_input_setup(void)
400{
401 struct key_entry *key;
402 int err;
403
404 hp_wmi_input_dev = input_allocate_device();
405
406 hp_wmi_input_dev->name = "HP WMI hotkeys";
407 hp_wmi_input_dev->phys = "wmi/input0";
408 hp_wmi_input_dev->id.bustype = BUS_HOST;
409 hp_wmi_input_dev->getkeycode = hp_wmi_getkeycode;
410 hp_wmi_input_dev->setkeycode = hp_wmi_setkeycode;
411
412 for (key = hp_wmi_keymap; key->type != KE_END; key++) {
413 switch (key->type) {
414 case KE_KEY:
415 set_bit(EV_KEY, hp_wmi_input_dev->evbit);
416 set_bit(key->keycode, hp_wmi_input_dev->keybit);
417 break;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700418 }
419 }
420
Matthew Garrett871043b2009-06-01 15:25:45 +0100421 set_bit(EV_SW, hp_wmi_input_dev->evbit);
422 set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
423 set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
424
425 /* Set initial hardware state */
426 input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state());
427 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
428 hp_wmi_tablet_state());
429 input_sync(hp_wmi_input_dev);
430
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700431 err = input_register_device(hp_wmi_input_dev);
432
433 if (err) {
434 input_free_device(hp_wmi_input_dev);
435 return err;
436 }
437
438 return 0;
439}
440
441static void cleanup_sysfs(struct platform_device *device)
442{
443 device_remove_file(&device->dev, &dev_attr_display);
444 device_remove_file(&device->dev, &dev_attr_hddtemp);
445 device_remove_file(&device->dev, &dev_attr_als);
446 device_remove_file(&device->dev, &dev_attr_dock);
Matthew Garrett871043b2009-06-01 15:25:45 +0100447 device_remove_file(&device->dev, &dev_attr_tablet);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700448}
449
Uwe Kleine-Königea796322010-02-04 20:56:52 +0100450static int __devinit hp_wmi_bios_setup(struct platform_device *device)
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700451{
452 int err;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700453 int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700454
455 err = device_create_file(&device->dev, &dev_attr_display);
456 if (err)
457 goto add_sysfs_error;
458 err = device_create_file(&device->dev, &dev_attr_hddtemp);
459 if (err)
460 goto add_sysfs_error;
461 err = device_create_file(&device->dev, &dev_attr_als);
462 if (err)
463 goto add_sysfs_error;
464 err = device_create_file(&device->dev, &dev_attr_dock);
465 if (err)
466 goto add_sysfs_error;
Matthew Garrett871043b2009-06-01 15:25:45 +0100467 err = device_create_file(&device->dev, &dev_attr_tablet);
468 if (err)
469 goto add_sysfs_error;
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700470
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700471 if (wireless & 0x1) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200472 wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
473 RFKILL_TYPE_WLAN,
474 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100475 (void *) HPWMI_WIFI);
476 rfkill_init_sw_state(wifi_rfkill,
477 hp_wmi_get_sw_state(HPWMI_WIFI));
478 rfkill_set_hw_state(wifi_rfkill,
479 hp_wmi_get_hw_state(HPWMI_WIFI));
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800480 err = rfkill_register(wifi_rfkill);
481 if (err)
Johannes Berg19d337d2009-06-02 13:01:37 +0200482 goto register_wifi_error;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700483 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700484
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700485 if (wireless & 0x2) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200486 bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
487 RFKILL_TYPE_BLUETOOTH,
488 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100489 (void *) HPWMI_BLUETOOTH);
490 rfkill_init_sw_state(bluetooth_rfkill,
491 hp_wmi_get_sw_state(HPWMI_BLUETOOTH));
492 rfkill_set_hw_state(bluetooth_rfkill,
493 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800494 err = rfkill_register(bluetooth_rfkill);
Frans Pop6989d562009-01-29 14:25:14 -0800495 if (err)
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800496 goto register_bluetooth_error;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700497 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700498
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700499 if (wireless & 0x4) {
Johannes Berg19d337d2009-06-02 13:01:37 +0200500 wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
501 RFKILL_TYPE_WWAN,
502 &hp_wmi_rfkill_ops,
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100503 (void *) HPWMI_WWAN);
504 rfkill_init_sw_state(wwan_rfkill,
505 hp_wmi_get_sw_state(HPWMI_WWAN));
506 rfkill_set_hw_state(wwan_rfkill,
507 hp_wmi_get_hw_state(HPWMI_WWAN));
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800508 err = rfkill_register(wwan_rfkill);
509 if (err)
510 goto register_wwan_err;
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700511 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700512
513 return 0;
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800514register_wwan_err:
Johannes Berg19d337d2009-06-02 13:01:37 +0200515 rfkill_destroy(wwan_rfkill);
Andrew Morton44f06062009-02-04 15:12:07 -0800516 if (bluetooth_rfkill)
517 rfkill_unregister(bluetooth_rfkill);
Larry Fingerfe8e4e02009-01-09 16:40:54 -0800518register_bluetooth_error:
Johannes Berg19d337d2009-06-02 13:01:37 +0200519 rfkill_destroy(bluetooth_rfkill);
Andrew Morton44f06062009-02-04 15:12:07 -0800520 if (wifi_rfkill)
521 rfkill_unregister(wifi_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200522register_wifi_error:
523 rfkill_destroy(wifi_rfkill);
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700524add_sysfs_error:
525 cleanup_sysfs(device);
526 return err;
527}
528
529static int __exit hp_wmi_bios_remove(struct platform_device *device)
530{
531 cleanup_sysfs(device);
532
Johannes Berg19d337d2009-06-02 13:01:37 +0200533 if (wifi_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700534 rfkill_unregister(wifi_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200535 rfkill_destroy(wifi_rfkill);
536 }
537 if (bluetooth_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700538 rfkill_unregister(bluetooth_rfkill);
Corentin Chary09729f02009-09-14 12:43:51 +0200539 rfkill_destroy(bluetooth_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200540 }
541 if (wwan_rfkill) {
Matthew Garrett3f6e2f12008-09-02 14:36:00 -0700542 rfkill_unregister(wwan_rfkill);
Johannes Berg19d337d2009-06-02 13:01:37 +0200543 rfkill_destroy(wwan_rfkill);
544 }
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700545
546 return 0;
547}
548
Frans Pop8dd2b422009-08-20 20:38:13 +0200549static int hp_wmi_resume_handler(struct device *device)
Frans Pop4c395bd2009-03-04 11:55:28 -0800550{
Frans Pop4c395bd2009-03-04 11:55:28 -0800551 /*
Matthew Garrett871043b2009-06-01 15:25:45 +0100552 * Hardware state may have changed while suspended, so trigger
553 * input events for the current state. As this is a switch,
Frans Pop4c395bd2009-03-04 11:55:28 -0800554 * the input layer will only actually pass it on if the state
555 * changed.
556 */
Frans Popdaed9532009-07-30 17:16:05 -0400557 if (hp_wmi_input_dev) {
558 input_report_switch(hp_wmi_input_dev, SW_DOCK,
559 hp_wmi_dock_state());
560 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
561 hp_wmi_tablet_state());
562 input_sync(hp_wmi_input_dev);
563 }
Frans Pop4c395bd2009-03-04 11:55:28 -0800564
Alan Jenkinse5fbba82009-07-21 12:14:01 +0100565 if (wifi_rfkill)
566 rfkill_set_states(wifi_rfkill,
567 hp_wmi_get_sw_state(HPWMI_WIFI),
568 hp_wmi_get_hw_state(HPWMI_WIFI));
569 if (bluetooth_rfkill)
570 rfkill_set_states(bluetooth_rfkill,
571 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
572 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
573 if (wwan_rfkill)
574 rfkill_set_states(wwan_rfkill,
575 hp_wmi_get_sw_state(HPWMI_WWAN),
576 hp_wmi_get_hw_state(HPWMI_WWAN));
577
Frans Pop4c395bd2009-03-04 11:55:28 -0800578 return 0;
579}
580
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700581static int __init hp_wmi_init(void)
582{
583 int err;
584
585 if (wmi_has_guid(HPWMI_EVENT_GUID)) {
586 err = wmi_install_notify_handler(HPWMI_EVENT_GUID,
587 hp_wmi_notify, NULL);
Len Brownf2772572009-12-26 22:04:03 -0500588 if (ACPI_SUCCESS(err))
Matthew Garrett62ec30d2008-07-25 01:45:39 -0700589 hp_wmi_input_setup();
590 }
591
592 if (wmi_has_guid(HPWMI_BIOS_GUID)) {
593 err = platform_driver_register(&hp_wmi_driver);
594 if (err)
595 return 0;
596 hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1);
597 if (!hp_wmi_platform_dev) {
598 platform_driver_unregister(&hp_wmi_driver);
599 return 0;
600 }
601 platform_device_add(hp_wmi_platform_dev);
602 }
603
604 return 0;
605}
606
607static void __exit hp_wmi_exit(void)
608{
609 if (wmi_has_guid(HPWMI_EVENT_GUID)) {
610 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
611 input_unregister_device(hp_wmi_input_dev);
612 }
613 if (hp_wmi_platform_dev) {
614 platform_device_del(hp_wmi_platform_dev);
615 platform_driver_unregister(&hp_wmi_driver);
616 }
617}
618
619module_init(hp_wmi_init);
620module_exit(hp_wmi_exit);