4 * Copyright (C) 2008 Red Hat <mjg@redhat.com>
5 * Copyright (C) 2010, 2011 Anssi Hannula <anssi.hannula@iki.fi>
7 * Portions based on wistron_btns.c:
8 * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
9 * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
10 * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/init.h>
32 #include <linux/slab.h>
33 #include <linux/types.h>
34 #include <linux/input.h>
35 #include <linux/input/sparse-keymap.h>
36 #include <linux/platform_device.h>
37 #include <linux/acpi.h>
38 #include <linux/rfkill.h>
39 #include <linux/string.h>
41 MODULE_AUTHOR("Matthew Garrett <mjg59@srcf.ucam.org>");
42 MODULE_DESCRIPTION("HP laptop WMI hotkeys driver");
43 MODULE_LICENSE("GPL");
45 MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C");
46 MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4");
48 #define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C"
49 #define HPWMI_BIOS_GUID "5FB7F034-2C63-45e9-BE91-3D44E2C707E4"
51 #define HPWMI_DISPLAY_QUERY 0x1
52 #define HPWMI_HDDTEMP_QUERY 0x2
53 #define HPWMI_ALS_QUERY 0x3
54 #define HPWMI_HARDWARE_QUERY 0x4
55 #define HPWMI_WIRELESS_QUERY 0x5
56 #define HPWMI_HOTKEY_QUERY 0xc
57 #define HPWMI_WIRELESS2_QUERY 0x1b
58 #define HPWMI_POSTCODEERROR_QUERY 0x2a
67 enum hp_wmi_event_ids {
70 HPWMI_SMART_ADAPTER = 3,
71 HPWMI_BEZEL_BUTTON = 4,
73 HPWMI_CPU_BATTERY_THROTTLE = 6,
74 HPWMI_LOCK_SWITCH = 7,
76 HPWMI_SCREEN_ROTATION = 9,
77 HPWMI_COOLSENSE_SYSTEM_MOBILE = 0x0A,
78 HPWMI_COOLSENSE_SYSTEM_HOT = 0x0B,
79 HPWMI_PROXIMITY_SENSOR = 0x0C,
80 HPWMI_BACKLIT_KB_BRIGHTNESS = 0x0D,
81 HPWMI_PEAKSHIFT_PERIOD = 0x0F,
82 HPWMI_BATTERY_CHARGE_PERIOD = 0x10,
98 enum hp_return_value {
99 HPWMI_RET_WRONG_SIGNATURE = 0x02,
100 HPWMI_RET_UNKNOWN_COMMAND = 0x03,
101 HPWMI_RET_UNKNOWN_CMDTYPE = 0x04,
102 HPWMI_RET_INVALID_PARAMETERS = 0x05,
105 enum hp_wireless2_bits {
106 HPWMI_POWER_STATE = 0x01,
107 HPWMI_POWER_SOFT = 0x02,
108 HPWMI_POWER_BIOS = 0x04,
109 HPWMI_POWER_HARD = 0x08,
112 #define IS_HWBLOCKED(x) ((x & (HPWMI_POWER_BIOS | HPWMI_POWER_HARD)) \
113 != (HPWMI_POWER_BIOS | HPWMI_POWER_HARD))
114 #define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT)
116 struct bios_rfkill2_device_state {
121 u16 subsys_vendor_id;
122 u16 subsys_product_id;
128 /* 7 devices fit into the 128 byte buffer */
129 #define HPWMI_MAX_RFKILL2_DEVICES 7
131 struct bios_rfkill2_state {
135 struct bios_rfkill2_device_state device[HPWMI_MAX_RFKILL2_DEVICES];
138 static const struct key_entry hp_wmi_keymap[] = {
139 { KE_KEY, 0x02, { KEY_BRIGHTNESSUP } },
140 { KE_KEY, 0x03, { KEY_BRIGHTNESSDOWN } },
141 { KE_KEY, 0x20e6, { KEY_PROG1 } },
142 { KE_KEY, 0x20e8, { KEY_MEDIA } },
143 { KE_KEY, 0x2142, { KEY_MEDIA } },
144 { KE_KEY, 0x213b, { KEY_INFO } },
145 { KE_KEY, 0x2169, { KEY_DIRECTION } },
146 { KE_KEY, 0x231b, { KEY_HELP } },
150 static struct input_dev *hp_wmi_input_dev;
151 static struct platform_device *hp_wmi_platform_dev;
153 static struct rfkill *wifi_rfkill;
154 static struct rfkill *bluetooth_rfkill;
155 static struct rfkill *wwan_rfkill;
156 static struct rfkill *gps_rfkill;
158 struct rfkill2_device {
161 struct rfkill *rfkill;
164 static int rfkill2_count;
165 static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES];
168 * hp_wmi_perform_query
170 * query: The commandtype -> What should be queried
171 * write: The command -> 0 read, 1 write, 3 ODM specific
172 * buffer: Buffer used as input and/or output
173 * insize: Size of input buffer
174 * outsize: Size of output buffer
176 * returns zero on success
177 * an HP WMI query specific error code (which is positive)
178 * -EINVAL if the query was not successful at all
179 * -EINVAL if the output buffer size exceeds buffersize
181 * Note: The buffersize must at least be the maximum of the input and output
182 * size. E.g. Battery info query (0x7) is defined to have 1 byte input
183 * and 128 byte output. The caller would do:
184 * buffer = kzalloc(128, GFP_KERNEL);
185 * ret = hp_wmi_perform_query(0x7, 0, buffer, 1, 128)
187 static int hp_wmi_perform_query(int query, int write, void *buffer,
188 int insize, int outsize)
190 struct bios_return *bios_return;
192 union acpi_object *obj;
193 struct bios_args args = {
194 .signature = 0x55434553,
195 .command = write ? 0x2 : 0x1,
196 .commandtype = query,
200 struct acpi_buffer input = { sizeof(struct bios_args), &args };
201 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
204 if (WARN_ON(insize > sizeof(args.data)))
206 memcpy(&args.data, buffer, insize);
208 wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output);
210 obj = output.pointer;
214 else if (obj->type != ACPI_TYPE_BUFFER) {
219 bios_return = (struct bios_return *)obj->buffer.pointer;
220 rc = bios_return->return_code;
223 if (rc != HPWMI_RET_UNKNOWN_CMDTYPE)
224 pr_warn("query 0x%x returned error 0x%x\n", query, rc);
230 /* ignore output data */
235 actual_outsize = min(outsize, (int)(obj->buffer.length - sizeof(*bios_return)));
236 memcpy(buffer, obj->buffer.pointer + sizeof(*bios_return), actual_outsize);
237 memset(buffer + actual_outsize, 0, outsize - actual_outsize);
242 static int hp_wmi_display_state(void)
245 int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, &state,
246 sizeof(state), sizeof(state));
252 static int hp_wmi_hddtemp_state(void)
255 int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, &state,
256 sizeof(state), sizeof(state));
262 static int hp_wmi_als_state(void)
265 int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, &state,
266 sizeof(state), sizeof(state));
272 static int hp_wmi_dock_state(void)
275 int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state,
276 sizeof(state), sizeof(state));
284 static int hp_wmi_tablet_state(void)
287 int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state,
288 sizeof(state), sizeof(state));
292 return (state & 0x4) ? 1 : 0;
295 static int hp_wmi_set_block(void *data, bool blocked)
297 enum hp_wmi_radio r = (enum hp_wmi_radio) data;
298 int query = BIT(r + 8) | ((!blocked) << r);
301 ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1,
302 &query, sizeof(query), 0);
308 static const struct rfkill_ops hp_wmi_rfkill_ops = {
309 .set_block = hp_wmi_set_block,
312 static bool hp_wmi_get_sw_state(enum hp_wmi_radio r)
316 hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0,
317 &wireless, sizeof(wireless),
319 /* TBD: Pass error */
321 mask = 0x200 << (r * 8);
329 static bool hp_wmi_get_hw_state(enum hp_wmi_radio r)
333 hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0,
334 &wireless, sizeof(wireless),
336 /* TBD: Pass error */
338 mask = 0x800 << (r * 8);
346 static int hp_wmi_rfkill2_set_block(void *data, bool blocked)
348 int rfkill_id = (int)(long)data;
349 char buffer[4] = { 0x01, 0x00, rfkill_id, !blocked };
351 if (hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, 1,
352 buffer, sizeof(buffer), 0))
357 static const struct rfkill_ops hp_wmi_rfkill2_ops = {
358 .set_block = hp_wmi_rfkill2_set_block,
361 static int hp_wmi_rfkill2_refresh(void)
364 struct bios_rfkill2_state state;
366 err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, 0, &state,
371 for (i = 0; i < rfkill2_count; i++) {
372 int num = rfkill2[i].num;
373 struct bios_rfkill2_device_state *devstate;
374 devstate = &state.device[num];
376 if (num >= state.count ||
377 devstate->rfkill_id != rfkill2[i].id) {
378 pr_warn("power configuration of the wireless devices unexpectedly changed\n");
382 rfkill_set_states(rfkill2[i].rfkill,
383 IS_SWBLOCKED(devstate->power),
384 IS_HWBLOCKED(devstate->power));
390 static int hp_wmi_post_code_state(void)
393 int ret = hp_wmi_perform_query(HPWMI_POSTCODEERROR_QUERY, 0, &state,
394 sizeof(state), sizeof(state));
400 static ssize_t show_display(struct device *dev, struct device_attribute *attr,
403 int value = hp_wmi_display_state();
406 return sprintf(buf, "%d\n", value);
409 static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr,
412 int value = hp_wmi_hddtemp_state();
415 return sprintf(buf, "%d\n", value);
418 static ssize_t show_als(struct device *dev, struct device_attribute *attr,
421 int value = hp_wmi_als_state();
424 return sprintf(buf, "%d\n", value);
427 static ssize_t show_dock(struct device *dev, struct device_attribute *attr,
430 int value = hp_wmi_dock_state();
433 return sprintf(buf, "%d\n", value);
436 static ssize_t show_tablet(struct device *dev, struct device_attribute *attr,
439 int value = hp_wmi_tablet_state();
442 return sprintf(buf, "%d\n", value);
445 static ssize_t show_postcode(struct device *dev, struct device_attribute *attr,
448 /* Get the POST error code of previous boot failure. */
449 int value = hp_wmi_post_code_state();
452 return sprintf(buf, "0x%x\n", value);
455 static ssize_t set_als(struct device *dev, struct device_attribute *attr,
456 const char *buf, size_t count)
458 u32 tmp = simple_strtoul(buf, NULL, 10);
459 int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, &tmp,
460 sizeof(tmp), sizeof(tmp));
467 static ssize_t set_postcode(struct device *dev, struct device_attribute *attr,
468 const char *buf, size_t count)
472 long unsigned int tmp2;
474 ret = kstrtoul(buf, 10, &tmp2);
475 if (ret || tmp2 != 1)
478 /* Clear the POST error code. It is kept until until cleared. */
480 ret = hp_wmi_perform_query(HPWMI_POSTCODEERROR_QUERY, 1, &tmp,
481 sizeof(tmp), sizeof(tmp));
488 static DEVICE_ATTR(display, S_IRUGO, show_display, NULL);
489 static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL);
490 static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als);
491 static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL);
492 static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL);
493 static DEVICE_ATTR(postcode, S_IRUGO | S_IWUSR, show_postcode, set_postcode);
495 static void hp_wmi_notify(u32 value, void *context)
497 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
498 union acpi_object *obj;
499 u32 event_id, event_data;
500 int key_code = 0, ret;
504 status = wmi_get_event_data(value, &response);
505 if (status != AE_OK) {
506 pr_info("bad event status 0x%x\n", status);
510 obj = (union acpi_object *)response.pointer;
514 if (obj->type != ACPI_TYPE_BUFFER) {
515 pr_info("Unknown response received %d\n", obj->type);
521 * Depending on ACPI version the concatenation of id and event data
522 * inside _WED function will result in a 8 or 16 byte buffer.
524 location = (u32 *)obj->buffer.pointer;
525 if (obj->buffer.length == 8) {
526 event_id = *location;
527 event_data = *(location + 1);
528 } else if (obj->buffer.length == 16) {
529 event_id = *location;
530 event_data = *(location + 2);
532 pr_info("Unknown buffer length %d\n", obj->buffer.length);
539 case HPWMI_DOCK_EVENT:
540 input_report_switch(hp_wmi_input_dev, SW_DOCK,
541 hp_wmi_dock_state());
542 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
543 hp_wmi_tablet_state());
544 input_sync(hp_wmi_input_dev);
548 case HPWMI_SMART_ADAPTER:
550 case HPWMI_BEZEL_BUTTON:
551 ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0,
558 if (!sparse_keymap_report_event(hp_wmi_input_dev,
560 pr_info("Unknown key code - 0x%x\n", key_code);
564 hp_wmi_rfkill2_refresh();
569 rfkill_set_states(wifi_rfkill,
570 hp_wmi_get_sw_state(HPWMI_WIFI),
571 hp_wmi_get_hw_state(HPWMI_WIFI));
572 if (bluetooth_rfkill)
573 rfkill_set_states(bluetooth_rfkill,
574 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
575 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
577 rfkill_set_states(wwan_rfkill,
578 hp_wmi_get_sw_state(HPWMI_WWAN),
579 hp_wmi_get_hw_state(HPWMI_WWAN));
581 rfkill_set_states(gps_rfkill,
582 hp_wmi_get_sw_state(HPWMI_GPS),
583 hp_wmi_get_hw_state(HPWMI_GPS));
585 case HPWMI_CPU_BATTERY_THROTTLE:
586 pr_info("Unimplemented CPU throttle because of 3 Cell battery event detected\n");
588 case HPWMI_LOCK_SWITCH:
590 case HPWMI_LID_SWITCH:
592 case HPWMI_SCREEN_ROTATION:
594 case HPWMI_COOLSENSE_SYSTEM_MOBILE:
596 case HPWMI_COOLSENSE_SYSTEM_HOT:
598 case HPWMI_PROXIMITY_SENSOR:
600 case HPWMI_BACKLIT_KB_BRIGHTNESS:
602 case HPWMI_PEAKSHIFT_PERIOD:
604 case HPWMI_BATTERY_CHARGE_PERIOD:
607 pr_info("Unknown event_id - %d - 0x%x\n", event_id, event_data);
612 static int __init hp_wmi_input_setup(void)
617 hp_wmi_input_dev = input_allocate_device();
618 if (!hp_wmi_input_dev)
621 hp_wmi_input_dev->name = "HP WMI hotkeys";
622 hp_wmi_input_dev->phys = "wmi/input0";
623 hp_wmi_input_dev->id.bustype = BUS_HOST;
625 __set_bit(EV_SW, hp_wmi_input_dev->evbit);
626 __set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
627 __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
629 err = sparse_keymap_setup(hp_wmi_input_dev, hp_wmi_keymap, NULL);
633 /* Set initial hardware state */
634 input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state());
635 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
636 hp_wmi_tablet_state());
637 input_sync(hp_wmi_input_dev);
639 status = wmi_install_notify_handler(HPWMI_EVENT_GUID, hp_wmi_notify, NULL);
640 if (ACPI_FAILURE(status)) {
642 goto err_free_keymap;
645 err = input_register_device(hp_wmi_input_dev);
647 goto err_uninstall_notifier;
651 err_uninstall_notifier:
652 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
654 sparse_keymap_free(hp_wmi_input_dev);
656 input_free_device(hp_wmi_input_dev);
660 static void hp_wmi_input_destroy(void)
662 wmi_remove_notify_handler(HPWMI_EVENT_GUID);
663 sparse_keymap_free(hp_wmi_input_dev);
664 input_unregister_device(hp_wmi_input_dev);
667 static void cleanup_sysfs(struct platform_device *device)
669 device_remove_file(&device->dev, &dev_attr_display);
670 device_remove_file(&device->dev, &dev_attr_hddtemp);
671 device_remove_file(&device->dev, &dev_attr_als);
672 device_remove_file(&device->dev, &dev_attr_dock);
673 device_remove_file(&device->dev, &dev_attr_tablet);
674 device_remove_file(&device->dev, &dev_attr_postcode);
677 static int hp_wmi_rfkill_setup(struct platform_device *device)
682 err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, &wireless,
683 sizeof(wireless), sizeof(wireless));
687 if (wireless & 0x1) {
688 wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
691 (void *) HPWMI_WIFI);
694 rfkill_init_sw_state(wifi_rfkill,
695 hp_wmi_get_sw_state(HPWMI_WIFI));
696 rfkill_set_hw_state(wifi_rfkill,
697 hp_wmi_get_hw_state(HPWMI_WIFI));
698 err = rfkill_register(wifi_rfkill);
700 goto register_wifi_error;
703 if (wireless & 0x2) {
704 bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
705 RFKILL_TYPE_BLUETOOTH,
707 (void *) HPWMI_BLUETOOTH);
708 if (!bluetooth_rfkill) {
710 goto register_wifi_error;
712 rfkill_init_sw_state(bluetooth_rfkill,
713 hp_wmi_get_sw_state(HPWMI_BLUETOOTH));
714 rfkill_set_hw_state(bluetooth_rfkill,
715 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
716 err = rfkill_register(bluetooth_rfkill);
718 goto register_bluetooth_error;
721 if (wireless & 0x4) {
722 wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
725 (void *) HPWMI_WWAN);
728 goto register_gps_error;
730 rfkill_init_sw_state(wwan_rfkill,
731 hp_wmi_get_sw_state(HPWMI_WWAN));
732 rfkill_set_hw_state(wwan_rfkill,
733 hp_wmi_get_hw_state(HPWMI_WWAN));
734 err = rfkill_register(wwan_rfkill);
736 goto register_wwan_err;
739 if (wireless & 0x8) {
740 gps_rfkill = rfkill_alloc("hp-gps", &device->dev,
746 goto register_bluetooth_error;
748 rfkill_init_sw_state(gps_rfkill,
749 hp_wmi_get_sw_state(HPWMI_GPS));
750 rfkill_set_hw_state(gps_rfkill,
751 hp_wmi_get_hw_state(HPWMI_GPS));
752 err = rfkill_register(gps_rfkill);
754 goto register_gps_error;
759 rfkill_destroy(wwan_rfkill);
762 rfkill_unregister(gps_rfkill);
764 rfkill_destroy(gps_rfkill);
766 if (bluetooth_rfkill)
767 rfkill_unregister(bluetooth_rfkill);
768 register_bluetooth_error:
769 rfkill_destroy(bluetooth_rfkill);
770 bluetooth_rfkill = NULL;
772 rfkill_unregister(wifi_rfkill);
774 rfkill_destroy(wifi_rfkill);
779 static int hp_wmi_rfkill2_setup(struct platform_device *device)
782 struct bios_rfkill2_state state;
783 err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, 0, &state,
788 if (state.count > HPWMI_MAX_RFKILL2_DEVICES) {
789 pr_warn("unable to parse 0x1b query output\n");
793 for (i = 0; i < state.count; i++) {
794 struct rfkill *rfkill;
795 enum rfkill_type type;
797 switch (state.device[i].radio_type) {
799 type = RFKILL_TYPE_WLAN;
802 case HPWMI_BLUETOOTH:
803 type = RFKILL_TYPE_BLUETOOTH;
804 name = "hp-bluetooth";
807 type = RFKILL_TYPE_WWAN;
811 type = RFKILL_TYPE_GPS;
815 pr_warn("unknown device type 0x%x\n",
816 state.device[i].radio_type);
820 if (!state.device[i].vendor_id) {
821 pr_warn("zero device %d while %d reported\n",
826 rfkill = rfkill_alloc(name, &device->dev, type,
827 &hp_wmi_rfkill2_ops, (void *)(long)i);
833 rfkill2[rfkill2_count].id = state.device[i].rfkill_id;
834 rfkill2[rfkill2_count].num = i;
835 rfkill2[rfkill2_count].rfkill = rfkill;
837 rfkill_init_sw_state(rfkill,
838 IS_SWBLOCKED(state.device[i].power));
839 rfkill_set_hw_state(rfkill,
840 IS_HWBLOCKED(state.device[i].power));
842 if (!(state.device[i].power & HPWMI_POWER_BIOS))
843 pr_info("device %s blocked by BIOS\n", name);
845 err = rfkill_register(rfkill);
847 rfkill_destroy(rfkill);
856 for (; rfkill2_count > 0; rfkill2_count--) {
857 rfkill_unregister(rfkill2[rfkill2_count - 1].rfkill);
858 rfkill_destroy(rfkill2[rfkill2_count - 1].rfkill);
863 static int __init hp_wmi_bios_setup(struct platform_device *device)
867 /* clear detected rfkill devices */
869 bluetooth_rfkill = NULL;
874 if (hp_wmi_rfkill_setup(device))
875 hp_wmi_rfkill2_setup(device);
877 err = device_create_file(&device->dev, &dev_attr_display);
879 goto add_sysfs_error;
880 err = device_create_file(&device->dev, &dev_attr_hddtemp);
882 goto add_sysfs_error;
883 err = device_create_file(&device->dev, &dev_attr_als);
885 goto add_sysfs_error;
886 err = device_create_file(&device->dev, &dev_attr_dock);
888 goto add_sysfs_error;
889 err = device_create_file(&device->dev, &dev_attr_tablet);
891 goto add_sysfs_error;
892 err = device_create_file(&device->dev, &dev_attr_postcode);
894 goto add_sysfs_error;
898 cleanup_sysfs(device);
902 static int __exit hp_wmi_bios_remove(struct platform_device *device)
905 cleanup_sysfs(device);
907 for (i = 0; i < rfkill2_count; i++) {
908 rfkill_unregister(rfkill2[i].rfkill);
909 rfkill_destroy(rfkill2[i].rfkill);
913 rfkill_unregister(wifi_rfkill);
914 rfkill_destroy(wifi_rfkill);
916 if (bluetooth_rfkill) {
917 rfkill_unregister(bluetooth_rfkill);
918 rfkill_destroy(bluetooth_rfkill);
921 rfkill_unregister(wwan_rfkill);
922 rfkill_destroy(wwan_rfkill);
925 rfkill_unregister(gps_rfkill);
926 rfkill_destroy(gps_rfkill);
932 static int hp_wmi_resume_handler(struct device *device)
935 * Hardware state may have changed while suspended, so trigger
936 * input events for the current state. As this is a switch,
937 * the input layer will only actually pass it on if the state
940 if (hp_wmi_input_dev) {
941 input_report_switch(hp_wmi_input_dev, SW_DOCK,
942 hp_wmi_dock_state());
943 input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
944 hp_wmi_tablet_state());
945 input_sync(hp_wmi_input_dev);
949 hp_wmi_rfkill2_refresh();
952 rfkill_set_states(wifi_rfkill,
953 hp_wmi_get_sw_state(HPWMI_WIFI),
954 hp_wmi_get_hw_state(HPWMI_WIFI));
955 if (bluetooth_rfkill)
956 rfkill_set_states(bluetooth_rfkill,
957 hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
958 hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
960 rfkill_set_states(wwan_rfkill,
961 hp_wmi_get_sw_state(HPWMI_WWAN),
962 hp_wmi_get_hw_state(HPWMI_WWAN));
964 rfkill_set_states(gps_rfkill,
965 hp_wmi_get_sw_state(HPWMI_GPS),
966 hp_wmi_get_hw_state(HPWMI_GPS));
971 static const struct dev_pm_ops hp_wmi_pm_ops = {
972 .resume = hp_wmi_resume_handler,
973 .restore = hp_wmi_resume_handler,
976 static struct platform_driver hp_wmi_driver = {
979 .owner = THIS_MODULE,
980 .pm = &hp_wmi_pm_ops,
982 .remove = __exit_p(hp_wmi_bios_remove),
985 static int __init hp_wmi_init(void)
988 int event_capable = wmi_has_guid(HPWMI_EVENT_GUID);
989 int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID);
991 if (!bios_capable && !event_capable)
995 err = hp_wmi_input_setup();
1001 hp_wmi_platform_dev =
1002 platform_device_register_simple("hp-wmi", -1, NULL, 0);
1003 if (IS_ERR(hp_wmi_platform_dev)) {
1004 err = PTR_ERR(hp_wmi_platform_dev);
1005 goto err_destroy_input;
1008 err = platform_driver_probe(&hp_wmi_driver, hp_wmi_bios_setup);
1010 goto err_unregister_device;
1015 err_unregister_device:
1016 platform_device_unregister(hp_wmi_platform_dev);
1019 hp_wmi_input_destroy();
1023 module_init(hp_wmi_init);
1025 static void __exit hp_wmi_exit(void)
1027 if (wmi_has_guid(HPWMI_EVENT_GUID))
1028 hp_wmi_input_destroy();
1030 if (hp_wmi_platform_dev) {
1031 platform_device_unregister(hp_wmi_platform_dev);
1032 platform_driver_unregister(&hp_wmi_driver);
1035 module_exit(hp_wmi_exit);