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"
53 HPWMI_BLUETOOTH
= 0x1,
58 enum hp_wmi_event_ids
{
59 HPWMI_DOCK_EVENT
= 0x01,
60 HPWMI_PARK_HDD
= 0x02,
61 HPWMI_SMART_ADAPTER
= 0x03,
62 HPWMI_BEZEL_BUTTON
= 0x04,
63 HPWMI_WIRELESS
= 0x05,
64 HPWMI_CPU_BATTERY_THROTTLE
= 0x06,
65 HPWMI_LOCK_SWITCH
= 0x07,
66 HPWMI_LID_SWITCH
= 0x08,
67 HPWMI_SCREEN_ROTATION
= 0x09,
68 HPWMI_COOLSENSE_SYSTEM_MOBILE
= 0x0A,
69 HPWMI_COOLSENSE_SYSTEM_HOT
= 0x0B,
70 HPWMI_PROXIMITY_SENSOR
= 0x0C,
71 HPWMI_BACKLIT_KB_BRIGHTNESS
= 0x0D,
72 HPWMI_PEAKSHIFT_PERIOD
= 0x0F,
73 HPWMI_BATTERY_CHARGE_PERIOD
= 0x10,
84 enum hp_wmi_commandtype
{
85 HPWMI_DISPLAY_QUERY
= 0x01,
86 HPWMI_HDDTEMP_QUERY
= 0x02,
87 HPWMI_ALS_QUERY
= 0x03,
88 HPWMI_HARDWARE_QUERY
= 0x04,
89 HPWMI_WIRELESS_QUERY
= 0x05,
90 HPWMI_BATTERY_QUERY
= 0x07,
91 HPWMI_BIOS_QUERY
= 0x09,
92 HPWMI_FEATURE_QUERY
= 0x0b,
93 HPWMI_HOTKEY_QUERY
= 0x0c,
94 HPWMI_FEATURE2_QUERY
= 0x0d,
95 HPWMI_WIRELESS2_QUERY
= 0x1b,
96 HPWMI_POSTCODEERROR_QUERY
= 0x2a,
105 enum hp_wmi_hardware_mask
{
106 HPWMI_DOCK_MASK
= 0x01,
107 HPWMI_TABLET_MASK
= 0x04,
115 enum hp_return_value
{
116 HPWMI_RET_WRONG_SIGNATURE
= 0x02,
117 HPWMI_RET_UNKNOWN_COMMAND
= 0x03,
118 HPWMI_RET_UNKNOWN_CMDTYPE
= 0x04,
119 HPWMI_RET_INVALID_PARAMETERS
= 0x05,
122 enum hp_wireless2_bits
{
123 HPWMI_POWER_STATE
= 0x01,
124 HPWMI_POWER_SOFT
= 0x02,
125 HPWMI_POWER_BIOS
= 0x04,
126 HPWMI_POWER_HARD
= 0x08,
129 #define IS_HWBLOCKED(x) ((x & (HPWMI_POWER_BIOS | HPWMI_POWER_HARD)) \
130 != (HPWMI_POWER_BIOS | HPWMI_POWER_HARD))
131 #define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT)
133 struct bios_rfkill2_device_state
{
138 u16 subsys_vendor_id
;
139 u16 subsys_product_id
;
145 /* 7 devices fit into the 128 byte buffer */
146 #define HPWMI_MAX_RFKILL2_DEVICES 7
148 struct bios_rfkill2_state
{
152 struct bios_rfkill2_device_state device
[HPWMI_MAX_RFKILL2_DEVICES
];
155 static const struct key_entry hp_wmi_keymap
[] = {
156 { KE_KEY
, 0x02, { KEY_BRIGHTNESSUP
} },
157 { KE_KEY
, 0x03, { KEY_BRIGHTNESSDOWN
} },
158 { KE_KEY
, 0x20e6, { KEY_PROG1
} },
159 { KE_KEY
, 0x20e8, { KEY_MEDIA
} },
160 { KE_KEY
, 0x2142, { KEY_MEDIA
} },
161 { KE_KEY
, 0x213b, { KEY_INFO
} },
162 { KE_KEY
, 0x2169, { KEY_ROTATE_DISPLAY
} },
163 { KE_KEY
, 0x216a, { KEY_SETUP
} },
164 { KE_KEY
, 0x231b, { KEY_HELP
} },
168 static struct input_dev
*hp_wmi_input_dev
;
169 static struct platform_device
*hp_wmi_platform_dev
;
171 static struct rfkill
*wifi_rfkill
;
172 static struct rfkill
*bluetooth_rfkill
;
173 static struct rfkill
*wwan_rfkill
;
175 struct rfkill2_device
{
178 struct rfkill
*rfkill
;
181 static int rfkill2_count
;
182 static struct rfkill2_device rfkill2
[HPWMI_MAX_RFKILL2_DEVICES
];
184 /* map output size to the corresponding WMI method id */
185 static inline int encode_outsize_for_pvsz(int outsize
)
201 * hp_wmi_perform_query
203 * query: The commandtype (enum hp_wmi_commandtype)
204 * write: The command (enum hp_wmi_command)
205 * buffer: Buffer used as input and/or output
206 * insize: Size of input buffer
207 * outsize: Size of output buffer
209 * returns zero on success
210 * an HP WMI query specific error code (which is positive)
211 * -EINVAL if the query was not successful at all
212 * -EINVAL if the output buffer size exceeds buffersize
214 * Note: The buffersize must at least be the maximum of the input and output
215 * size. E.g. Battery info query is defined to have 1 byte input
216 * and 128 byte output. The caller would do:
217 * buffer = kzalloc(128, GFP_KERNEL);
218 * ret = hp_wmi_perform_query(HPWMI_BATTERY_QUERY, HPWMI_READ, buffer, 1, 128)
220 static int hp_wmi_perform_query(int query
, enum hp_wmi_command command
,
221 void *buffer
, int insize
, int outsize
)
224 struct bios_return
*bios_return
;
226 union acpi_object
*obj
;
227 struct bios_args args
= {
228 .signature
= 0x55434553,
230 .commandtype
= query
,
234 struct acpi_buffer input
= { sizeof(struct bios_args
), &args
};
235 struct acpi_buffer output
= { ACPI_ALLOCATE_BUFFER
, NULL
};
238 mid
= encode_outsize_for_pvsz(outsize
);
239 if (WARN_ON(mid
< 0))
242 if (WARN_ON(insize
> sizeof(args
.data
)))
244 memcpy(&args
.data
, buffer
, insize
);
246 wmi_evaluate_method(HPWMI_BIOS_GUID
, 0, mid
, &input
, &output
);
248 obj
= output
.pointer
;
253 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
258 bios_return
= (struct bios_return
*)obj
->buffer
.pointer
;
259 ret
= bios_return
->return_code
;
262 if (ret
!= HPWMI_RET_UNKNOWN_CMDTYPE
)
263 pr_warn("query 0x%x returned error 0x%x\n", query
, ret
);
267 /* Ignore output data of zero size */
271 actual_outsize
= min(outsize
, (int)(obj
->buffer
.length
- sizeof(*bios_return
)));
272 memcpy(buffer
, obj
->buffer
.pointer
+ sizeof(*bios_return
), actual_outsize
);
273 memset(buffer
+ actual_outsize
, 0, outsize
- actual_outsize
);
280 static int hp_wmi_read_int(int query
)
284 ret
= hp_wmi_perform_query(query
, HPWMI_READ
, &val
,
285 sizeof(val
), sizeof(val
));
288 return ret
< 0 ? ret
: -EINVAL
;
293 static int hp_wmi_hw_state(int mask
)
295 int state
= hp_wmi_read_int(HPWMI_HARDWARE_QUERY
);
300 return !!(state
& mask
);
303 static int __init
hp_wmi_bios_2008_later(void)
306 int ret
= hp_wmi_perform_query(HPWMI_FEATURE_QUERY
, HPWMI_READ
, &state
,
307 sizeof(state
), sizeof(state
));
311 return (ret
== HPWMI_RET_UNKNOWN_CMDTYPE
) ? 0 : -ENXIO
;
314 static int __init
hp_wmi_bios_2009_later(void)
317 int ret
= hp_wmi_perform_query(HPWMI_FEATURE2_QUERY
, HPWMI_READ
, &state
,
318 sizeof(state
), sizeof(state
));
322 return (ret
== HPWMI_RET_UNKNOWN_CMDTYPE
) ? 0 : -ENXIO
;
325 static int __init
hp_wmi_enable_hotkeys(void)
328 int ret
= hp_wmi_perform_query(HPWMI_BIOS_QUERY
, HPWMI_WRITE
, &value
,
331 return ret
<= 0 ? ret
: -EINVAL
;
334 static int hp_wmi_set_block(void *data
, bool blocked
)
336 enum hp_wmi_radio r
= (enum hp_wmi_radio
) data
;
337 int query
= BIT(r
+ 8) | ((!blocked
) << r
);
340 ret
= hp_wmi_perform_query(HPWMI_WIRELESS_QUERY
, HPWMI_WRITE
,
341 &query
, sizeof(query
), 0);
343 return ret
<= 0 ? ret
: -EINVAL
;
346 static const struct rfkill_ops hp_wmi_rfkill_ops
= {
347 .set_block
= hp_wmi_set_block
,
350 static bool hp_wmi_get_sw_state(enum hp_wmi_radio r
)
352 int mask
= 0x200 << (r
* 8);
354 int wireless
= hp_wmi_read_int(HPWMI_WIRELESS_QUERY
);
356 /* TBD: Pass error */
357 WARN_ONCE(wireless
< 0, "error executing HPWMI_WIRELESS_QUERY");
359 return !(wireless
& mask
);
362 static bool hp_wmi_get_hw_state(enum hp_wmi_radio r
)
364 int mask
= 0x800 << (r
* 8);
366 int wireless
= hp_wmi_read_int(HPWMI_WIRELESS_QUERY
);
368 /* TBD: Pass error */
369 WARN_ONCE(wireless
< 0, "error executing HPWMI_WIRELESS_QUERY");
371 return !(wireless
& mask
);
374 static int hp_wmi_rfkill2_set_block(void *data
, bool blocked
)
376 int rfkill_id
= (int)(long)data
;
377 char buffer
[4] = { 0x01, 0x00, rfkill_id
, !blocked
};
380 ret
= hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY
, HPWMI_WRITE
,
381 buffer
, sizeof(buffer
), 0);
383 return ret
<= 0 ? ret
: -EINVAL
;
386 static const struct rfkill_ops hp_wmi_rfkill2_ops
= {
387 .set_block
= hp_wmi_rfkill2_set_block
,
390 static int hp_wmi_rfkill2_refresh(void)
392 struct bios_rfkill2_state state
;
395 err
= hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY
, HPWMI_READ
, &state
,
400 for (i
= 0; i
< rfkill2_count
; i
++) {
401 int num
= rfkill2
[i
].num
;
402 struct bios_rfkill2_device_state
*devstate
;
403 devstate
= &state
.device
[num
];
405 if (num
>= state
.count
||
406 devstate
->rfkill_id
!= rfkill2
[i
].id
) {
407 pr_warn("power configuration of the wireless devices unexpectedly changed\n");
411 rfkill_set_states(rfkill2
[i
].rfkill
,
412 IS_SWBLOCKED(devstate
->power
),
413 IS_HWBLOCKED(devstate
->power
));
419 static ssize_t
display_show(struct device
*dev
, struct device_attribute
*attr
,
422 int value
= hp_wmi_read_int(HPWMI_DISPLAY_QUERY
);
425 return sprintf(buf
, "%d\n", value
);
428 static ssize_t
hddtemp_show(struct device
*dev
, struct device_attribute
*attr
,
431 int value
= hp_wmi_read_int(HPWMI_HDDTEMP_QUERY
);
434 return sprintf(buf
, "%d\n", value
);
437 static ssize_t
als_show(struct device
*dev
, struct device_attribute
*attr
,
440 int value
= hp_wmi_read_int(HPWMI_ALS_QUERY
);
443 return sprintf(buf
, "%d\n", value
);
446 static ssize_t
dock_show(struct device
*dev
, struct device_attribute
*attr
,
449 int value
= hp_wmi_hw_state(HPWMI_DOCK_MASK
);
452 return sprintf(buf
, "%d\n", value
);
455 static ssize_t
tablet_show(struct device
*dev
, struct device_attribute
*attr
,
458 int value
= hp_wmi_hw_state(HPWMI_TABLET_MASK
);
461 return sprintf(buf
, "%d\n", value
);
464 static ssize_t
postcode_show(struct device
*dev
, struct device_attribute
*attr
,
467 /* Get the POST error code of previous boot failure. */
468 int value
= hp_wmi_read_int(HPWMI_POSTCODEERROR_QUERY
);
471 return sprintf(buf
, "0x%x\n", value
);
474 static ssize_t
als_store(struct device
*dev
, struct device_attribute
*attr
,
475 const char *buf
, size_t count
)
477 u32 tmp
= simple_strtoul(buf
, NULL
, 10);
478 int ret
= hp_wmi_perform_query(HPWMI_ALS_QUERY
, HPWMI_WRITE
, &tmp
,
479 sizeof(tmp
), sizeof(tmp
));
481 return ret
< 0 ? ret
: -EINVAL
;
486 static ssize_t
postcode_store(struct device
*dev
, struct device_attribute
*attr
,
487 const char *buf
, size_t count
)
489 long unsigned int tmp2
;
493 ret
= kstrtoul(buf
, 10, &tmp2
);
494 if (!ret
&& tmp2
!= 1)
499 /* Clear the POST error code. It is kept until until cleared. */
501 ret
= hp_wmi_perform_query(HPWMI_POSTCODEERROR_QUERY
, HPWMI_WRITE
, &tmp
,
502 sizeof(tmp
), sizeof(tmp
));
506 return ret
< 0 ? ret
: -EINVAL
;
511 static DEVICE_ATTR_RO(display
);
512 static DEVICE_ATTR_RO(hddtemp
);
513 static DEVICE_ATTR_RW(als
);
514 static DEVICE_ATTR_RO(dock
);
515 static DEVICE_ATTR_RO(tablet
);
516 static DEVICE_ATTR_RW(postcode
);
518 static void hp_wmi_notify(u32 value
, void *context
)
520 struct acpi_buffer response
= { ACPI_ALLOCATE_BUFFER
, NULL
};
521 u32 event_id
, event_data
;
522 union acpi_object
*obj
;
527 status
= wmi_get_event_data(value
, &response
);
528 if (status
!= AE_OK
) {
529 pr_info("bad event status 0x%x\n", status
);
533 obj
= (union acpi_object
*)response
.pointer
;
537 if (obj
->type
!= ACPI_TYPE_BUFFER
) {
538 pr_info("Unknown response received %d\n", obj
->type
);
544 * Depending on ACPI version the concatenation of id and event data
545 * inside _WED function will result in a 8 or 16 byte buffer.
547 location
= (u32
*)obj
->buffer
.pointer
;
548 if (obj
->buffer
.length
== 8) {
549 event_id
= *location
;
550 event_data
= *(location
+ 1);
551 } else if (obj
->buffer
.length
== 16) {
552 event_id
= *location
;
553 event_data
= *(location
+ 2);
555 pr_info("Unknown buffer length %d\n", obj
->buffer
.length
);
562 case HPWMI_DOCK_EVENT
:
563 if (test_bit(SW_DOCK
, hp_wmi_input_dev
->swbit
))
564 input_report_switch(hp_wmi_input_dev
, SW_DOCK
,
565 hp_wmi_hw_state(HPWMI_DOCK_MASK
));
566 if (test_bit(SW_TABLET_MODE
, hp_wmi_input_dev
->swbit
))
567 input_report_switch(hp_wmi_input_dev
, SW_TABLET_MODE
,
568 hp_wmi_hw_state(HPWMI_TABLET_MASK
));
569 input_sync(hp_wmi_input_dev
);
573 case HPWMI_SMART_ADAPTER
:
575 case HPWMI_BEZEL_BUTTON
:
576 key_code
= hp_wmi_read_int(HPWMI_HOTKEY_QUERY
);
580 if (!sparse_keymap_report_event(hp_wmi_input_dev
,
582 pr_info("Unknown key code - 0x%x\n", key_code
);
586 hp_wmi_rfkill2_refresh();
591 rfkill_set_states(wifi_rfkill
,
592 hp_wmi_get_sw_state(HPWMI_WIFI
),
593 hp_wmi_get_hw_state(HPWMI_WIFI
));
594 if (bluetooth_rfkill
)
595 rfkill_set_states(bluetooth_rfkill
,
596 hp_wmi_get_sw_state(HPWMI_BLUETOOTH
),
597 hp_wmi_get_hw_state(HPWMI_BLUETOOTH
));
599 rfkill_set_states(wwan_rfkill
,
600 hp_wmi_get_sw_state(HPWMI_WWAN
),
601 hp_wmi_get_hw_state(HPWMI_WWAN
));
603 case HPWMI_CPU_BATTERY_THROTTLE
:
604 pr_info("Unimplemented CPU throttle because of 3 Cell battery event detected\n");
606 case HPWMI_LOCK_SWITCH
:
608 case HPWMI_LID_SWITCH
:
610 case HPWMI_SCREEN_ROTATION
:
612 case HPWMI_COOLSENSE_SYSTEM_MOBILE
:
614 case HPWMI_COOLSENSE_SYSTEM_HOT
:
616 case HPWMI_PROXIMITY_SENSOR
:
618 case HPWMI_BACKLIT_KB_BRIGHTNESS
:
620 case HPWMI_PEAKSHIFT_PERIOD
:
622 case HPWMI_BATTERY_CHARGE_PERIOD
:
625 pr_info("Unknown event_id - %d - 0x%x\n", event_id
, event_data
);
630 static int __init
hp_wmi_input_setup(void)
635 hp_wmi_input_dev
= input_allocate_device();
636 if (!hp_wmi_input_dev
)
639 hp_wmi_input_dev
->name
= "HP WMI hotkeys";
640 hp_wmi_input_dev
->phys
= "wmi/input0";
641 hp_wmi_input_dev
->id
.bustype
= BUS_HOST
;
643 __set_bit(EV_SW
, hp_wmi_input_dev
->evbit
);
646 val
= hp_wmi_hw_state(HPWMI_DOCK_MASK
);
648 __set_bit(SW_DOCK
, hp_wmi_input_dev
->swbit
);
649 input_report_switch(hp_wmi_input_dev
, SW_DOCK
, val
);
653 val
= hp_wmi_hw_state(HPWMI_TABLET_MASK
);
655 __set_bit(SW_TABLET_MODE
, hp_wmi_input_dev
->swbit
);
656 input_report_switch(hp_wmi_input_dev
, SW_TABLET_MODE
, val
);
659 err
= sparse_keymap_setup(hp_wmi_input_dev
, hp_wmi_keymap
, NULL
);
663 /* Set initial hardware state */
664 input_sync(hp_wmi_input_dev
);
666 if (!hp_wmi_bios_2009_later() && hp_wmi_bios_2008_later())
667 hp_wmi_enable_hotkeys();
669 status
= wmi_install_notify_handler(HPWMI_EVENT_GUID
, hp_wmi_notify
, NULL
);
670 if (ACPI_FAILURE(status
)) {
675 err
= input_register_device(hp_wmi_input_dev
);
677 goto err_uninstall_notifier
;
681 err_uninstall_notifier
:
682 wmi_remove_notify_handler(HPWMI_EVENT_GUID
);
684 input_free_device(hp_wmi_input_dev
);
688 static void hp_wmi_input_destroy(void)
690 wmi_remove_notify_handler(HPWMI_EVENT_GUID
);
691 input_unregister_device(hp_wmi_input_dev
);
694 static void cleanup_sysfs(struct platform_device
*device
)
696 device_remove_file(&device
->dev
, &dev_attr_display
);
697 device_remove_file(&device
->dev
, &dev_attr_hddtemp
);
698 device_remove_file(&device
->dev
, &dev_attr_als
);
699 device_remove_file(&device
->dev
, &dev_attr_dock
);
700 device_remove_file(&device
->dev
, &dev_attr_tablet
);
701 device_remove_file(&device
->dev
, &dev_attr_postcode
);
704 static int __init
hp_wmi_rfkill_setup(struct platform_device
*device
)
708 wireless
= hp_wmi_read_int(HPWMI_WIRELESS_QUERY
);
712 err
= hp_wmi_perform_query(HPWMI_WIRELESS_QUERY
, HPWMI_WRITE
, &wireless
,
713 sizeof(wireless
), 0);
717 if (wireless
& 0x1) {
718 wifi_rfkill
= rfkill_alloc("hp-wifi", &device
->dev
,
721 (void *) HPWMI_WIFI
);
724 rfkill_init_sw_state(wifi_rfkill
,
725 hp_wmi_get_sw_state(HPWMI_WIFI
));
726 rfkill_set_hw_state(wifi_rfkill
,
727 hp_wmi_get_hw_state(HPWMI_WIFI
));
728 err
= rfkill_register(wifi_rfkill
);
730 goto register_wifi_error
;
733 if (wireless
& 0x2) {
734 bluetooth_rfkill
= rfkill_alloc("hp-bluetooth", &device
->dev
,
735 RFKILL_TYPE_BLUETOOTH
,
737 (void *) HPWMI_BLUETOOTH
);
738 if (!bluetooth_rfkill
) {
740 goto register_bluetooth_error
;
742 rfkill_init_sw_state(bluetooth_rfkill
,
743 hp_wmi_get_sw_state(HPWMI_BLUETOOTH
));
744 rfkill_set_hw_state(bluetooth_rfkill
,
745 hp_wmi_get_hw_state(HPWMI_BLUETOOTH
));
746 err
= rfkill_register(bluetooth_rfkill
);
748 goto register_bluetooth_error
;
751 if (wireless
& 0x4) {
752 wwan_rfkill
= rfkill_alloc("hp-wwan", &device
->dev
,
755 (void *) HPWMI_WWAN
);
758 goto register_wwan_error
;
760 rfkill_init_sw_state(wwan_rfkill
,
761 hp_wmi_get_sw_state(HPWMI_WWAN
));
762 rfkill_set_hw_state(wwan_rfkill
,
763 hp_wmi_get_hw_state(HPWMI_WWAN
));
764 err
= rfkill_register(wwan_rfkill
);
766 goto register_wwan_error
;
772 rfkill_destroy(wwan_rfkill
);
774 if (bluetooth_rfkill
)
775 rfkill_unregister(bluetooth_rfkill
);
776 register_bluetooth_error
:
777 rfkill_destroy(bluetooth_rfkill
);
778 bluetooth_rfkill
= NULL
;
780 rfkill_unregister(wifi_rfkill
);
782 rfkill_destroy(wifi_rfkill
);
787 static int __init
hp_wmi_rfkill2_setup(struct platform_device
*device
)
789 struct bios_rfkill2_state state
;
792 err
= hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY
, HPWMI_READ
, &state
,
795 return err
< 0 ? err
: -EINVAL
;
797 if (state
.count
> HPWMI_MAX_RFKILL2_DEVICES
) {
798 pr_warn("unable to parse 0x1b query output\n");
802 for (i
= 0; i
< state
.count
; i
++) {
803 struct rfkill
*rfkill
;
804 enum rfkill_type type
;
806 switch (state
.device
[i
].radio_type
) {
808 type
= RFKILL_TYPE_WLAN
;
811 case HPWMI_BLUETOOTH
:
812 type
= RFKILL_TYPE_BLUETOOTH
;
813 name
= "hp-bluetooth";
816 type
= RFKILL_TYPE_WWAN
;
820 type
= RFKILL_TYPE_GPS
;
824 pr_warn("unknown device type 0x%x\n",
825 state
.device
[i
].radio_type
);
829 if (!state
.device
[i
].vendor_id
) {
830 pr_warn("zero device %d while %d reported\n",
835 rfkill
= rfkill_alloc(name
, &device
->dev
, type
,
836 &hp_wmi_rfkill2_ops
, (void *)(long)i
);
842 rfkill2
[rfkill2_count
].id
= state
.device
[i
].rfkill_id
;
843 rfkill2
[rfkill2_count
].num
= i
;
844 rfkill2
[rfkill2_count
].rfkill
= rfkill
;
846 rfkill_init_sw_state(rfkill
,
847 IS_SWBLOCKED(state
.device
[i
].power
));
848 rfkill_set_hw_state(rfkill
,
849 IS_HWBLOCKED(state
.device
[i
].power
));
851 if (!(state
.device
[i
].power
& HPWMI_POWER_BIOS
))
852 pr_info("device %s blocked by BIOS\n", name
);
854 err
= rfkill_register(rfkill
);
856 rfkill_destroy(rfkill
);
865 for (; rfkill2_count
> 0; rfkill2_count
--) {
866 rfkill_unregister(rfkill2
[rfkill2_count
- 1].rfkill
);
867 rfkill_destroy(rfkill2
[rfkill2_count
- 1].rfkill
);
872 static int __init
hp_wmi_bios_setup(struct platform_device
*device
)
876 /* clear detected rfkill devices */
878 bluetooth_rfkill
= NULL
;
882 if (hp_wmi_rfkill_setup(device
))
883 hp_wmi_rfkill2_setup(device
);
885 err
= device_create_file(&device
->dev
, &dev_attr_display
);
887 goto add_sysfs_error
;
888 err
= device_create_file(&device
->dev
, &dev_attr_hddtemp
);
890 goto add_sysfs_error
;
891 err
= device_create_file(&device
->dev
, &dev_attr_als
);
893 goto add_sysfs_error
;
894 err
= device_create_file(&device
->dev
, &dev_attr_dock
);
896 goto add_sysfs_error
;
897 err
= device_create_file(&device
->dev
, &dev_attr_tablet
);
899 goto add_sysfs_error
;
900 err
= device_create_file(&device
->dev
, &dev_attr_postcode
);
902 goto add_sysfs_error
;
906 cleanup_sysfs(device
);
910 static int __exit
hp_wmi_bios_remove(struct platform_device
*device
)
913 cleanup_sysfs(device
);
915 for (i
= 0; i
< rfkill2_count
; i
++) {
916 rfkill_unregister(rfkill2
[i
].rfkill
);
917 rfkill_destroy(rfkill2
[i
].rfkill
);
921 rfkill_unregister(wifi_rfkill
);
922 rfkill_destroy(wifi_rfkill
);
924 if (bluetooth_rfkill
) {
925 rfkill_unregister(bluetooth_rfkill
);
926 rfkill_destroy(bluetooth_rfkill
);
929 rfkill_unregister(wwan_rfkill
);
930 rfkill_destroy(wwan_rfkill
);
936 static int hp_wmi_resume_handler(struct device
*device
)
939 * Hardware state may have changed while suspended, so trigger
940 * input events for the current state. As this is a switch,
941 * the input layer will only actually pass it on if the state
944 if (hp_wmi_input_dev
) {
945 if (test_bit(SW_DOCK
, hp_wmi_input_dev
->swbit
))
946 input_report_switch(hp_wmi_input_dev
, SW_DOCK
,
947 hp_wmi_hw_state(HPWMI_DOCK_MASK
));
948 if (test_bit(SW_TABLET_MODE
, hp_wmi_input_dev
->swbit
))
949 input_report_switch(hp_wmi_input_dev
, SW_TABLET_MODE
,
950 hp_wmi_hw_state(HPWMI_TABLET_MASK
));
951 input_sync(hp_wmi_input_dev
);
955 hp_wmi_rfkill2_refresh();
958 rfkill_set_states(wifi_rfkill
,
959 hp_wmi_get_sw_state(HPWMI_WIFI
),
960 hp_wmi_get_hw_state(HPWMI_WIFI
));
961 if (bluetooth_rfkill
)
962 rfkill_set_states(bluetooth_rfkill
,
963 hp_wmi_get_sw_state(HPWMI_BLUETOOTH
),
964 hp_wmi_get_hw_state(HPWMI_BLUETOOTH
));
966 rfkill_set_states(wwan_rfkill
,
967 hp_wmi_get_sw_state(HPWMI_WWAN
),
968 hp_wmi_get_hw_state(HPWMI_WWAN
));
973 static const struct dev_pm_ops hp_wmi_pm_ops
= {
974 .resume
= hp_wmi_resume_handler
,
975 .restore
= hp_wmi_resume_handler
,
978 static struct platform_driver hp_wmi_driver
= {
981 .pm
= &hp_wmi_pm_ops
,
983 .remove
= __exit_p(hp_wmi_bios_remove
),
986 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
);
992 if (!bios_capable
&& !event_capable
)
996 err
= hp_wmi_input_setup();
1002 hp_wmi_platform_dev
=
1003 platform_device_register_simple("hp-wmi", -1, NULL
, 0);
1004 if (IS_ERR(hp_wmi_platform_dev
)) {
1005 err
= PTR_ERR(hp_wmi_platform_dev
);
1006 goto err_destroy_input
;
1009 err
= platform_driver_probe(&hp_wmi_driver
, hp_wmi_bios_setup
);
1011 goto err_unregister_device
;
1016 err_unregister_device
:
1017 platform_device_unregister(hp_wmi_platform_dev
);
1020 hp_wmi_input_destroy();
1024 module_init(hp_wmi_init
);
1026 static void __exit
hp_wmi_exit(void)
1028 if (wmi_has_guid(HPWMI_EVENT_GUID
))
1029 hp_wmi_input_destroy();
1031 if (hp_wmi_platform_dev
) {
1032 platform_device_unregister(hp_wmi_platform_dev
);
1033 platform_driver_unregister(&hp_wmi_driver
);
1036 module_exit(hp_wmi_exit
);