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
66 enum hp_wmi_event_ids
{
69 HPWMI_SMART_ADAPTER
= 3,
70 HPWMI_BEZEL_BUTTON
= 4,
72 HPWMI_CPU_BATTERY_THROTTLE
= 6,
73 HPWMI_LOCK_SWITCH
= 7,
75 HPWMI_SCREEN_ROTATION
= 9,
76 HPWMI_COOLSENSE_SYSTEM_MOBILE
= 0x0A,
77 HPWMI_COOLSENSE_SYSTEM_HOT
= 0x0B,
78 HPWMI_PROXIMITY_SENSOR
= 0x0C,
79 HPWMI_BACKLIT_KB_BRIGHTNESS
= 0x0D,
80 HPWMI_PEAKSHIFT_PERIOD
= 0x0F,
81 HPWMI_BATTERY_CHARGE_PERIOD
= 0x10,
97 enum hp_return_value
{
98 HPWMI_RET_WRONG_SIGNATURE
= 0x02,
99 HPWMI_RET_UNKNOWN_COMMAND
= 0x03,
100 HPWMI_RET_UNKNOWN_CMDTYPE
= 0x04,
101 HPWMI_RET_INVALID_PARAMETERS
= 0x05,
104 enum hp_wireless2_bits
{
105 HPWMI_POWER_STATE
= 0x01,
106 HPWMI_POWER_SOFT
= 0x02,
107 HPWMI_POWER_BIOS
= 0x04,
108 HPWMI_POWER_HARD
= 0x08,
111 #define IS_HWBLOCKED(x) ((x & (HPWMI_POWER_BIOS | HPWMI_POWER_HARD)) \
112 != (HPWMI_POWER_BIOS | HPWMI_POWER_HARD))
113 #define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT)
115 struct bios_rfkill2_device_state
{
120 u16 subsys_vendor_id
;
121 u16 subsys_product_id
;
127 /* 7 devices fit into the 128 byte buffer */
128 #define HPWMI_MAX_RFKILL2_DEVICES 7
130 struct bios_rfkill2_state
{
134 struct bios_rfkill2_device_state device
[HPWMI_MAX_RFKILL2_DEVICES
];
137 static const struct key_entry hp_wmi_keymap
[] = {
138 { KE_KEY
, 0x02, { KEY_BRIGHTNESSUP
} },
139 { KE_KEY
, 0x03, { KEY_BRIGHTNESSDOWN
} },
140 { KE_KEY
, 0x20e6, { KEY_PROG1
} },
141 { KE_KEY
, 0x20e8, { KEY_MEDIA
} },
142 { KE_KEY
, 0x2142, { KEY_MEDIA
} },
143 { KE_KEY
, 0x213b, { KEY_INFO
} },
144 { KE_KEY
, 0x2169, { KEY_DIRECTION
} },
145 { KE_KEY
, 0x231b, { KEY_HELP
} },
149 static struct input_dev
*hp_wmi_input_dev
;
150 static struct platform_device
*hp_wmi_platform_dev
;
152 static struct rfkill
*wifi_rfkill
;
153 static struct rfkill
*bluetooth_rfkill
;
154 static struct rfkill
*wwan_rfkill
;
155 static struct rfkill
*gps_rfkill
;
157 struct rfkill2_device
{
160 struct rfkill
*rfkill
;
163 static int rfkill2_count
;
164 static struct rfkill2_device rfkill2
[HPWMI_MAX_RFKILL2_DEVICES
];
167 * hp_wmi_perform_query
169 * query: The commandtype -> What should be queried
170 * write: The command -> 0 read, 1 write, 3 ODM specific
171 * buffer: Buffer used as input and/or output
172 * insize: Size of input buffer
173 * outsize: Size of output buffer
175 * returns zero on success
176 * an HP WMI query specific error code (which is positive)
177 * -EINVAL if the query was not successful at all
178 * -EINVAL if the output buffer size exceeds buffersize
180 * Note: The buffersize must at least be the maximum of the input and output
181 * size. E.g. Battery info query (0x7) is defined to have 1 byte input
182 * and 128 byte output. The caller would do:
183 * buffer = kzalloc(128, GFP_KERNEL);
184 * ret = hp_wmi_perform_query(0x7, 0, buffer, 1, 128)
186 static int hp_wmi_perform_query(int query
, int write
, void *buffer
,
187 int insize
, int outsize
)
189 struct bios_return
*bios_return
;
191 union acpi_object
*obj
;
192 struct bios_args args
= {
193 .signature
= 0x55434553,
194 .command
= write
? 0x2 : 0x1,
195 .commandtype
= query
,
199 struct acpi_buffer input
= { sizeof(struct bios_args
), &args
};
200 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
203 if (WARN_ON(insize
> sizeof(args
.data
)))
205 memcpy(&args
.data
, buffer
, insize
);
207 wmi_evaluate_method(HPWMI_BIOS_GUID
, 0, 0x3, &input
, &output
);
209 obj
= output
.pointer
;
213 else if (obj
->type
!= ACPI_TYPE_BUFFER
) {
218 bios_return
= (struct bios_return
*)obj
->buffer
.pointer
;
219 rc
= bios_return
->return_code
;
222 if (rc
!= HPWMI_RET_UNKNOWN_CMDTYPE
)
223 pr_warn("query 0x%x returned error 0x%x\n", query
, rc
);
229 /* ignore output data */
234 actual_outsize
= min(outsize
, (int)(obj
->buffer
.length
- sizeof(*bios_return
)));
235 memcpy(buffer
, obj
->buffer
.pointer
+ sizeof(*bios_return
), actual_outsize
);
236 memset(buffer
+ actual_outsize
, 0, outsize
- actual_outsize
);
241 static int hp_wmi_display_state(void)
244 int ret
= hp_wmi_perform_query(HPWMI_DISPLAY_QUERY
, 0, &state
,
245 sizeof(state
), sizeof(state
));
251 static int hp_wmi_hddtemp_state(void)
254 int ret
= hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY
, 0, &state
,
255 sizeof(state
), sizeof(state
));
261 static int hp_wmi_als_state(void)
264 int ret
= hp_wmi_perform_query(HPWMI_ALS_QUERY
, 0, &state
,
265 sizeof(state
), sizeof(state
));
271 static int hp_wmi_dock_state(void)
274 int ret
= hp_wmi_perform_query(HPWMI_HARDWARE_QUERY
, 0, &state
,
275 sizeof(state
), sizeof(state
));
283 static int hp_wmi_tablet_state(void)
286 int ret
= hp_wmi_perform_query(HPWMI_HARDWARE_QUERY
, 0, &state
,
287 sizeof(state
), sizeof(state
));
291 return (state
& 0x4) ? 1 : 0;
294 static int hp_wmi_set_block(void *data
, bool blocked
)
296 enum hp_wmi_radio r
= (enum hp_wmi_radio
) data
;
297 int query
= BIT(r
+ 8) | ((!blocked
) << r
);
300 ret
= hp_wmi_perform_query(HPWMI_WIRELESS_QUERY
, 1,
301 &query
, sizeof(query
), 0);
307 static const struct rfkill_ops hp_wmi_rfkill_ops
= {
308 .set_block
= hp_wmi_set_block
,
311 static bool hp_wmi_get_sw_state(enum hp_wmi_radio r
)
315 hp_wmi_perform_query(HPWMI_WIRELESS_QUERY
, 0,
316 &wireless
, sizeof(wireless
),
318 /* TBD: Pass error */
320 mask
= 0x200 << (r
* 8);
328 static bool hp_wmi_get_hw_state(enum hp_wmi_radio r
)
332 hp_wmi_perform_query(HPWMI_WIRELESS_QUERY
, 0,
333 &wireless
, sizeof(wireless
),
335 /* TBD: Pass error */
337 mask
= 0x800 << (r
* 8);
345 static int hp_wmi_rfkill2_set_block(void *data
, bool blocked
)
347 int rfkill_id
= (int)(long)data
;
348 char buffer
[4] = { 0x01, 0x00, rfkill_id
, !blocked
};
350 if (hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY
, 1,
351 buffer
, sizeof(buffer
), 0))
356 static const struct rfkill_ops hp_wmi_rfkill2_ops
= {
357 .set_block
= hp_wmi_rfkill2_set_block
,
360 static int hp_wmi_rfkill2_refresh(void)
363 struct bios_rfkill2_state state
;
365 err
= hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY
, 0, &state
,
370 for (i
= 0; i
< rfkill2_count
; i
++) {
371 int num
= rfkill2
[i
].num
;
372 struct bios_rfkill2_device_state
*devstate
;
373 devstate
= &state
.device
[num
];
375 if (num
>= state
.count
||
376 devstate
->rfkill_id
!= rfkill2
[i
].id
) {
377 pr_warn("power configuration of the wireless devices unexpectedly changed\n");
381 rfkill_set_states(rfkill2
[i
].rfkill
,
382 IS_SWBLOCKED(devstate
->power
),
383 IS_HWBLOCKED(devstate
->power
));
389 static ssize_t
show_display(struct device
*dev
, struct device_attribute
*attr
,
392 int value
= hp_wmi_display_state();
395 return sprintf(buf
, "%d\n", value
);
398 static ssize_t
show_hddtemp(struct device
*dev
, struct device_attribute
*attr
,
401 int value
= hp_wmi_hddtemp_state();
404 return sprintf(buf
, "%d\n", value
);
407 static ssize_t
show_als(struct device
*dev
, struct device_attribute
*attr
,
410 int value
= hp_wmi_als_state();
413 return sprintf(buf
, "%d\n", value
);
416 static ssize_t
show_dock(struct device
*dev
, struct device_attribute
*attr
,
419 int value
= hp_wmi_dock_state();
422 return sprintf(buf
, "%d\n", value
);
425 static ssize_t
show_tablet(struct device
*dev
, struct device_attribute
*attr
,
428 int value
= hp_wmi_tablet_state();
431 return sprintf(buf
, "%d\n", value
);
434 static ssize_t
set_als(struct device
*dev
, struct device_attribute
*attr
,
435 const char *buf
, size_t count
)
437 u32 tmp
= simple_strtoul(buf
, NULL
, 10);
438 int ret
= hp_wmi_perform_query(HPWMI_ALS_QUERY
, 1, &tmp
,
439 sizeof(tmp
), sizeof(tmp
));
446 static DEVICE_ATTR(display
, S_IRUGO
, show_display
, NULL
);
447 static DEVICE_ATTR(hddtemp
, S_IRUGO
, show_hddtemp
, NULL
);
448 static DEVICE_ATTR(als
, S_IRUGO
| S_IWUSR
, show_als
, set_als
);
449 static DEVICE_ATTR(dock
, S_IRUGO
, show_dock
, NULL
);
450 static DEVICE_ATTR(tablet
, S_IRUGO
, show_tablet
, NULL
);
452 static void hp_wmi_notify(u32 value
, void *context
)
454 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
455 union acpi_object
*obj
;
456 u32 event_id
, event_data
;
457 int key_code
= 0, ret
;
461 status
= wmi_get_event_data(value
, &response
);
462 if (status
!= AE_OK
) {
463 pr_info("bad event status 0x%x\n", status
);
467 obj
= (union acpi_object
*)response
.pointer
;
471 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
472 pr_info("Unknown response received %d\n", obj
->type
);
478 * Depending on ACPI version the concatenation of id and event data
479 * inside _WED function will result in a 8 or 16 byte buffer.
481 location
= (u32
*)obj
->buffer
.pointer
;
482 if (obj
->buffer
.length
== 8) {
483 event_id
= *location
;
484 event_data
= *(location
+ 1);
485 } else if (obj
->buffer
.length
== 16) {
486 event_id
= *location
;
487 event_data
= *(location
+ 2);
489 pr_info("Unknown buffer length %d\n", obj
->buffer
.length
);
496 case HPWMI_DOCK_EVENT
:
497 input_report_switch(hp_wmi_input_dev
, SW_DOCK
,
498 hp_wmi_dock_state());
499 input_report_switch(hp_wmi_input_dev
, SW_TABLET_MODE
,
500 hp_wmi_tablet_state());
501 input_sync(hp_wmi_input_dev
);
505 case HPWMI_SMART_ADAPTER
:
507 case HPWMI_BEZEL_BUTTON
:
508 ret
= hp_wmi_perform_query(HPWMI_HOTKEY_QUERY
, 0,
515 if (!sparse_keymap_report_event(hp_wmi_input_dev
,
517 pr_info("Unknown key code - 0x%x\n", key_code
);
521 hp_wmi_rfkill2_refresh();
526 rfkill_set_states(wifi_rfkill
,
527 hp_wmi_get_sw_state(HPWMI_WIFI
),
528 hp_wmi_get_hw_state(HPWMI_WIFI
));
529 if (bluetooth_rfkill
)
530 rfkill_set_states(bluetooth_rfkill
,
531 hp_wmi_get_sw_state(HPWMI_BLUETOOTH
),
532 hp_wmi_get_hw_state(HPWMI_BLUETOOTH
));
534 rfkill_set_states(wwan_rfkill
,
535 hp_wmi_get_sw_state(HPWMI_WWAN
),
536 hp_wmi_get_hw_state(HPWMI_WWAN
));
538 rfkill_set_states(gps_rfkill
,
539 hp_wmi_get_sw_state(HPWMI_GPS
),
540 hp_wmi_get_hw_state(HPWMI_GPS
));
542 case HPWMI_CPU_BATTERY_THROTTLE
:
543 pr_info("Unimplemented CPU throttle because of 3 Cell battery event detected\n");
545 case HPWMI_LOCK_SWITCH
:
547 case HPWMI_LID_SWITCH
:
549 case HPWMI_SCREEN_ROTATION
:
551 case HPWMI_COOLSENSE_SYSTEM_MOBILE
:
553 case HPWMI_COOLSENSE_SYSTEM_HOT
:
555 case HPWMI_PROXIMITY_SENSOR
:
557 case HPWMI_BACKLIT_KB_BRIGHTNESS
:
559 case HPWMI_PEAKSHIFT_PERIOD
:
561 case HPWMI_BATTERY_CHARGE_PERIOD
:
564 pr_info("Unknown event_id - %d - 0x%x\n", event_id
, event_data
);
569 static int __init
hp_wmi_input_setup(void)
574 hp_wmi_input_dev
= input_allocate_device();
575 if (!hp_wmi_input_dev
)
578 hp_wmi_input_dev
->name
= "HP WMI hotkeys";
579 hp_wmi_input_dev
->phys
= "wmi/input0";
580 hp_wmi_input_dev
->id
.bustype
= BUS_HOST
;
582 __set_bit(EV_SW
, hp_wmi_input_dev
->evbit
);
583 __set_bit(SW_DOCK
, hp_wmi_input_dev
->swbit
);
584 __set_bit(SW_TABLET_MODE
, hp_wmi_input_dev
->swbit
);
586 err
= sparse_keymap_setup(hp_wmi_input_dev
, hp_wmi_keymap
, NULL
);
590 /* Set initial hardware state */
591 input_report_switch(hp_wmi_input_dev
, SW_DOCK
, hp_wmi_dock_state());
592 input_report_switch(hp_wmi_input_dev
, SW_TABLET_MODE
,
593 hp_wmi_tablet_state());
594 input_sync(hp_wmi_input_dev
);
596 status
= wmi_install_notify_handler(HPWMI_EVENT_GUID
, hp_wmi_notify
, NULL
);
597 if (ACPI_FAILURE(status
)) {
599 goto err_free_keymap
;
602 err
= input_register_device(hp_wmi_input_dev
);
604 goto err_uninstall_notifier
;
608 err_uninstall_notifier
:
609 wmi_remove_notify_handler(HPWMI_EVENT_GUID
);
611 sparse_keymap_free(hp_wmi_input_dev
);
613 input_free_device(hp_wmi_input_dev
);
617 static void hp_wmi_input_destroy(void)
619 wmi_remove_notify_handler(HPWMI_EVENT_GUID
);
620 sparse_keymap_free(hp_wmi_input_dev
);
621 input_unregister_device(hp_wmi_input_dev
);
624 static void cleanup_sysfs(struct platform_device
*device
)
626 device_remove_file(&device
->dev
, &dev_attr_display
);
627 device_remove_file(&device
->dev
, &dev_attr_hddtemp
);
628 device_remove_file(&device
->dev
, &dev_attr_als
);
629 device_remove_file(&device
->dev
, &dev_attr_dock
);
630 device_remove_file(&device
->dev
, &dev_attr_tablet
);
633 static int hp_wmi_rfkill_setup(struct platform_device
*device
)
638 err
= hp_wmi_perform_query(HPWMI_WIRELESS_QUERY
, 0, &wireless
,
639 sizeof(wireless
), sizeof(wireless
));
643 if (wireless
& 0x1) {
644 wifi_rfkill
= rfkill_alloc("hp-wifi", &device
->dev
,
647 (void *) HPWMI_WIFI
);
650 rfkill_init_sw_state(wifi_rfkill
,
651 hp_wmi_get_sw_state(HPWMI_WIFI
));
652 rfkill_set_hw_state(wifi_rfkill
,
653 hp_wmi_get_hw_state(HPWMI_WIFI
));
654 err
= rfkill_register(wifi_rfkill
);
656 goto register_wifi_error
;
659 if (wireless
& 0x2) {
660 bluetooth_rfkill
= rfkill_alloc("hp-bluetooth", &device
->dev
,
661 RFKILL_TYPE_BLUETOOTH
,
663 (void *) HPWMI_BLUETOOTH
);
664 if (!bluetooth_rfkill
) {
666 goto register_wifi_error
;
668 rfkill_init_sw_state(bluetooth_rfkill
,
669 hp_wmi_get_sw_state(HPWMI_BLUETOOTH
));
670 rfkill_set_hw_state(bluetooth_rfkill
,
671 hp_wmi_get_hw_state(HPWMI_BLUETOOTH
));
672 err
= rfkill_register(bluetooth_rfkill
);
674 goto register_bluetooth_error
;
677 if (wireless
& 0x4) {
678 wwan_rfkill
= rfkill_alloc("hp-wwan", &device
->dev
,
681 (void *) HPWMI_WWAN
);
684 goto register_gps_error
;
686 rfkill_init_sw_state(wwan_rfkill
,
687 hp_wmi_get_sw_state(HPWMI_WWAN
));
688 rfkill_set_hw_state(wwan_rfkill
,
689 hp_wmi_get_hw_state(HPWMI_WWAN
));
690 err
= rfkill_register(wwan_rfkill
);
692 goto register_wwan_err
;
695 if (wireless
& 0x8) {
696 gps_rfkill
= rfkill_alloc("hp-gps", &device
->dev
,
702 goto register_bluetooth_error
;
704 rfkill_init_sw_state(gps_rfkill
,
705 hp_wmi_get_sw_state(HPWMI_GPS
));
706 rfkill_set_hw_state(bluetooth_rfkill
,
707 hp_wmi_get_hw_state(HPWMI_GPS
));
708 err
= rfkill_register(gps_rfkill
);
710 goto register_gps_error
;
715 rfkill_destroy(wwan_rfkill
);
718 rfkill_unregister(gps_rfkill
);
720 rfkill_destroy(gps_rfkill
);
722 if (bluetooth_rfkill
)
723 rfkill_unregister(bluetooth_rfkill
);
724 register_bluetooth_error
:
725 rfkill_destroy(bluetooth_rfkill
);
726 bluetooth_rfkill
= NULL
;
728 rfkill_unregister(wifi_rfkill
);
730 rfkill_destroy(wifi_rfkill
);
735 static int hp_wmi_rfkill2_setup(struct platform_device
*device
)
738 struct bios_rfkill2_state state
;
739 err
= hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY
, 0, &state
,
744 if (state
.count
> HPWMI_MAX_RFKILL2_DEVICES
) {
745 pr_warn("unable to parse 0x1b query output\n");
749 for (i
= 0; i
< state
.count
; i
++) {
750 struct rfkill
*rfkill
;
751 enum rfkill_type type
;
753 switch (state
.device
[i
].radio_type
) {
755 type
= RFKILL_TYPE_WLAN
;
758 case HPWMI_BLUETOOTH
:
759 type
= RFKILL_TYPE_BLUETOOTH
;
760 name
= "hp-bluetooth";
763 type
= RFKILL_TYPE_WWAN
;
767 type
= RFKILL_TYPE_GPS
;
771 pr_warn("unknown device type 0x%x\n",
772 state
.device
[i
].radio_type
);
776 if (!state
.device
[i
].vendor_id
) {
777 pr_warn("zero device %d while %d reported\n",
782 rfkill
= rfkill_alloc(name
, &device
->dev
, type
,
783 &hp_wmi_rfkill2_ops
, (void *)(long)i
);
789 rfkill2
[rfkill2_count
].id
= state
.device
[i
].rfkill_id
;
790 rfkill2
[rfkill2_count
].num
= i
;
791 rfkill2
[rfkill2_count
].rfkill
= rfkill
;
793 rfkill_init_sw_state(rfkill
,
794 IS_SWBLOCKED(state
.device
[i
].power
));
795 rfkill_set_hw_state(rfkill
,
796 IS_HWBLOCKED(state
.device
[i
].power
));
798 if (!(state
.device
[i
].power
& HPWMI_POWER_BIOS
))
799 pr_info("device %s blocked by BIOS\n", name
);
801 err
= rfkill_register(rfkill
);
803 rfkill_destroy(rfkill
);
812 for (; rfkill2_count
> 0; rfkill2_count
--) {
813 rfkill_unregister(rfkill2
[rfkill2_count
- 1].rfkill
);
814 rfkill_destroy(rfkill2
[rfkill2_count
- 1].rfkill
);
819 static int __init
hp_wmi_bios_setup(struct platform_device
*device
)
823 /* clear detected rfkill devices */
825 bluetooth_rfkill
= NULL
;
830 if (hp_wmi_rfkill_setup(device
))
831 hp_wmi_rfkill2_setup(device
);
833 err
= device_create_file(&device
->dev
, &dev_attr_display
);
835 goto add_sysfs_error
;
836 err
= device_create_file(&device
->dev
, &dev_attr_hddtemp
);
838 goto add_sysfs_error
;
839 err
= device_create_file(&device
->dev
, &dev_attr_als
);
841 goto add_sysfs_error
;
842 err
= device_create_file(&device
->dev
, &dev_attr_dock
);
844 goto add_sysfs_error
;
845 err
= device_create_file(&device
->dev
, &dev_attr_tablet
);
847 goto add_sysfs_error
;
851 cleanup_sysfs(device
);
855 static int __exit
hp_wmi_bios_remove(struct platform_device
*device
)
858 cleanup_sysfs(device
);
860 for (i
= 0; i
< rfkill2_count
; i
++) {
861 rfkill_unregister(rfkill2
[i
].rfkill
);
862 rfkill_destroy(rfkill2
[i
].rfkill
);
866 rfkill_unregister(wifi_rfkill
);
867 rfkill_destroy(wifi_rfkill
);
869 if (bluetooth_rfkill
) {
870 rfkill_unregister(bluetooth_rfkill
);
871 rfkill_destroy(bluetooth_rfkill
);
874 rfkill_unregister(wwan_rfkill
);
875 rfkill_destroy(wwan_rfkill
);
878 rfkill_unregister(gps_rfkill
);
879 rfkill_destroy(gps_rfkill
);
885 static int hp_wmi_resume_handler(struct device
*device
)
888 * Hardware state may have changed while suspended, so trigger
889 * input events for the current state. As this is a switch,
890 * the input layer will only actually pass it on if the state
893 if (hp_wmi_input_dev
) {
894 input_report_switch(hp_wmi_input_dev
, SW_DOCK
,
895 hp_wmi_dock_state());
896 input_report_switch(hp_wmi_input_dev
, SW_TABLET_MODE
,
897 hp_wmi_tablet_state());
898 input_sync(hp_wmi_input_dev
);
902 hp_wmi_rfkill2_refresh();
905 rfkill_set_states(wifi_rfkill
,
906 hp_wmi_get_sw_state(HPWMI_WIFI
),
907 hp_wmi_get_hw_state(HPWMI_WIFI
));
908 if (bluetooth_rfkill
)
909 rfkill_set_states(bluetooth_rfkill
,
910 hp_wmi_get_sw_state(HPWMI_BLUETOOTH
),
911 hp_wmi_get_hw_state(HPWMI_BLUETOOTH
));
913 rfkill_set_states(wwan_rfkill
,
914 hp_wmi_get_sw_state(HPWMI_WWAN
),
915 hp_wmi_get_hw_state(HPWMI_WWAN
));
917 rfkill_set_states(gps_rfkill
,
918 hp_wmi_get_sw_state(HPWMI_GPS
),
919 hp_wmi_get_hw_state(HPWMI_GPS
));
924 static const struct dev_pm_ops hp_wmi_pm_ops
= {
925 .resume
= hp_wmi_resume_handler
,
926 .restore
= hp_wmi_resume_handler
,
929 static struct platform_driver hp_wmi_driver
= {
932 .owner
= THIS_MODULE
,
933 .pm
= &hp_wmi_pm_ops
,
935 .remove
= __exit_p(hp_wmi_bios_remove
),
938 static int __init
hp_wmi_init(void)
941 int event_capable
= wmi_has_guid(HPWMI_EVENT_GUID
);
942 int bios_capable
= wmi_has_guid(HPWMI_BIOS_GUID
);
944 if (!bios_capable
&& !event_capable
)
948 err
= hp_wmi_input_setup();
954 hp_wmi_platform_dev
=
955 platform_device_register_simple("hp-wmi", -1, NULL
, 0);
956 if (IS_ERR(hp_wmi_platform_dev
)) {
957 err
= PTR_ERR(hp_wmi_platform_dev
);
958 goto err_destroy_input
;
961 err
= platform_driver_probe(&hp_wmi_driver
, hp_wmi_bios_setup
);
963 goto err_unregister_device
;
968 err_unregister_device
:
969 platform_device_unregister(hp_wmi_platform_dev
);
972 hp_wmi_input_destroy();
976 module_init(hp_wmi_init
);
978 static void __exit
hp_wmi_exit(void)
980 if (wmi_has_guid(HPWMI_EVENT_GUID
))
981 hp_wmi_input_destroy();
983 if (hp_wmi_platform_dev
) {
984 platform_device_unregister(hp_wmi_platform_dev
);
985 platform_driver_unregister(&hp_wmi_driver
);
988 module_exit(hp_wmi_exit
);