2 * Driver for Dell laptop extras
4 * Copyright (c) Red Hat <mjg@redhat.com>
5 * Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
6 * Copyright (c) 2014 Pali Rohár <pali.rohar@gmail.com>
8 * Based on documentation in the libsmbios package:
9 * Copyright (C) 2005-2014 Dell Inc.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/platform_device.h>
22 #include <linux/backlight.h>
23 #include <linux/err.h>
24 #include <linux/dmi.h>
26 #include <linux/rfkill.h>
27 #include <linux/power_supply.h>
28 #include <linux/acpi.h>
30 #include <linux/i8042.h>
31 #include <linux/debugfs.h>
32 #include <linux/seq_file.h>
33 #include <acpi/video.h>
34 #include "dell-rbtn.h"
35 #include "dell-smbios.h"
39 bool kbd_led_levels_off_1
;
40 bool kbd_missing_ac_tag
;
42 bool needs_kbd_timeouts
;
44 * Ordered list of timeouts expressed in seconds.
45 * The list must end with -1
50 static struct quirk_entry
*quirks
;
52 static struct quirk_entry quirk_dell_vostro_v130
= {
56 static int __init
dmi_matched(const struct dmi_system_id
*dmi
)
58 quirks
= dmi
->driver_data
;
63 * These values come from Windows utility provided by Dell. If any other value
64 * is used then BIOS silently set timeout to 0 without any error message.
66 static struct quirk_entry quirk_dell_xps13_9333
= {
67 .needs_kbd_timeouts
= true,
68 .kbd_timeouts
= { 0, 5, 15, 60, 5 * 60, 15 * 60, -1 },
71 static struct quirk_entry quirk_dell_xps13_9370
= {
72 .kbd_missing_ac_tag
= true,
75 static struct quirk_entry quirk_dell_latitude_e6410
= {
76 .kbd_led_levels_off_1
= true,
79 static struct platform_driver platform_driver
= {
81 .name
= "dell-laptop",
85 static struct platform_device
*platform_device
;
86 static struct backlight_device
*dell_backlight_device
;
87 static struct rfkill
*wifi_rfkill
;
88 static struct rfkill
*bluetooth_rfkill
;
89 static struct rfkill
*wwan_rfkill
;
90 static bool force_rfkill
;
92 module_param(force_rfkill
, bool, 0444);
93 MODULE_PARM_DESC(force_rfkill
, "enable rfkill on non whitelisted models");
95 static const struct dmi_system_id dell_device_table
[] __initconst
= {
97 .ident
= "Dell laptop",
99 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
100 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
105 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
106 DMI_MATCH(DMI_CHASSIS_TYPE
, "9"), /*Laptop*/
111 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
112 DMI_MATCH(DMI_CHASSIS_TYPE
, "10"), /*Notebook*/
117 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
118 DMI_MATCH(DMI_CHASSIS_TYPE
, "30"), /*Tablet*/
123 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
124 DMI_MATCH(DMI_CHASSIS_TYPE
, "31"), /*Convertible*/
129 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
130 DMI_MATCH(DMI_CHASSIS_TYPE
, "32"), /*Detachable*/
134 .ident
= "Dell Computer Corporation",
136 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer Corporation"),
137 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
142 MODULE_DEVICE_TABLE(dmi
, dell_device_table
);
144 static const struct dmi_system_id dell_quirks
[] __initconst
= {
146 .callback
= dmi_matched
,
147 .ident
= "Dell Vostro V130",
149 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
150 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V130"),
152 .driver_data
= &quirk_dell_vostro_v130
,
155 .callback
= dmi_matched
,
156 .ident
= "Dell Vostro V131",
158 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
159 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V131"),
161 .driver_data
= &quirk_dell_vostro_v130
,
164 .callback
= dmi_matched
,
165 .ident
= "Dell Vostro 3350",
167 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
168 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3350"),
170 .driver_data
= &quirk_dell_vostro_v130
,
173 .callback
= dmi_matched
,
174 .ident
= "Dell Vostro 3555",
176 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
177 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3555"),
179 .driver_data
= &quirk_dell_vostro_v130
,
182 .callback
= dmi_matched
,
183 .ident
= "Dell Inspiron N311z",
185 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
186 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron N311z"),
188 .driver_data
= &quirk_dell_vostro_v130
,
191 .callback
= dmi_matched
,
192 .ident
= "Dell Inspiron M5110",
194 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
195 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron M5110"),
197 .driver_data
= &quirk_dell_vostro_v130
,
200 .callback
= dmi_matched
,
201 .ident
= "Dell Vostro 3360",
203 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
204 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3360"),
206 .driver_data
= &quirk_dell_vostro_v130
,
209 .callback
= dmi_matched
,
210 .ident
= "Dell Vostro 3460",
212 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
213 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3460"),
215 .driver_data
= &quirk_dell_vostro_v130
,
218 .callback
= dmi_matched
,
219 .ident
= "Dell Vostro 3560",
221 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
222 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3560"),
224 .driver_data
= &quirk_dell_vostro_v130
,
227 .callback
= dmi_matched
,
228 .ident
= "Dell Vostro 3450",
230 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
231 DMI_MATCH(DMI_PRODUCT_NAME
, "Dell System Vostro 3450"),
233 .driver_data
= &quirk_dell_vostro_v130
,
236 .callback
= dmi_matched
,
237 .ident
= "Dell Inspiron 5420",
239 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
240 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5420"),
242 .driver_data
= &quirk_dell_vostro_v130
,
245 .callback
= dmi_matched
,
246 .ident
= "Dell Inspiron 5520",
248 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
249 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5520"),
251 .driver_data
= &quirk_dell_vostro_v130
,
254 .callback
= dmi_matched
,
255 .ident
= "Dell Inspiron 5720",
257 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
258 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5720"),
260 .driver_data
= &quirk_dell_vostro_v130
,
263 .callback
= dmi_matched
,
264 .ident
= "Dell Inspiron 7420",
266 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
267 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7420"),
269 .driver_data
= &quirk_dell_vostro_v130
,
272 .callback
= dmi_matched
,
273 .ident
= "Dell Inspiron 7520",
275 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
276 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7520"),
278 .driver_data
= &quirk_dell_vostro_v130
,
281 .callback
= dmi_matched
,
282 .ident
= "Dell Inspiron 7720",
284 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
285 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7720"),
287 .driver_data
= &quirk_dell_vostro_v130
,
290 .callback
= dmi_matched
,
291 .ident
= "Dell XPS13 9333",
293 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
294 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS13 9333"),
296 .driver_data
= &quirk_dell_xps13_9333
,
299 .callback
= dmi_matched
,
300 .ident
= "Dell XPS 13 9370",
302 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
303 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS 13 9370"),
305 .driver_data
= &quirk_dell_xps13_9370
,
308 .callback
= dmi_matched
,
309 .ident
= "Dell Latitude E6410",
311 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
312 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude E6410"),
314 .driver_data
= &quirk_dell_latitude_e6410
,
319 static void dell_fill_request(struct calling_interface_buffer
*buffer
,
320 u32 arg0
, u32 arg1
, u32 arg2
, u32 arg3
)
322 memset(buffer
, 0, sizeof(struct calling_interface_buffer
));
323 buffer
->input
[0] = arg0
;
324 buffer
->input
[1] = arg1
;
325 buffer
->input
[2] = arg2
;
326 buffer
->input
[3] = arg3
;
329 static int dell_send_request(struct calling_interface_buffer
*buffer
,
330 u16
class, u16 select
)
334 buffer
->cmd_class
= class;
335 buffer
->cmd_select
= select
;
336 ret
= dell_smbios_call(buffer
);
339 return dell_smbios_error(buffer
->output
[0]);
343 * Derived from information in smbios-wireless-ctl:
345 * cbSelect 17, Value 11
347 * Return Wireless Info
348 * cbArg1, byte0 = 0x00
350 * cbRes1 Standard return codes (0, -1, -2)
351 * cbRes2 Info bit flags:
353 * 0 Hardware switch supported (1)
354 * 1 WiFi locator supported (1)
355 * 2 WLAN supported (1)
356 * 3 Bluetooth (BT) supported (1)
357 * 4 WWAN supported (1)
358 * 5 Wireless KBD supported (1)
359 * 6 Uw b supported (1)
360 * 7 WiGig supported (1)
361 * 8 WLAN installed (1)
363 * 10 WWAN installed (1)
364 * 11 Uw b installed (1)
365 * 12 WiGig installed (1)
367 * 16 Hardware (HW) switch is On (1)
368 * 17 WLAN disabled (1)
370 * 19 WWAN disabled (1)
371 * 20 Uw b disabled (1)
372 * 21 WiGig disabled (1)
375 * cbRes3 NVRAM size in bytes
376 * cbRes4, byte 0 NVRAM format version number
379 * Set QuickSet Radio Disable Flag
380 * cbArg1, byte0 = 0x01
389 * cbArg1, byte2 Flag bits:
390 * 0 QuickSet disables radio (1)
393 * cbRes1 Standard return codes (0, -1, -2)
394 * cbRes2 QuickSet (QS) radio disable bit map:
399 * 4 QS disables WIGIG
402 * Wireless Switch Configuration
403 * cbArg1, byte0 = 0x02
409 * 2 Set WiFi locator enable/disable
411 * Switch settings (if byte 1==1):
412 * 0 WLAN sw itch control (1)
413 * 1 BT sw itch control (1)
414 * 2 WWAN sw itch control (1)
415 * 3 UWB sw itch control (1)
416 * 4 WiGig sw itch control (1)
418 * cbArg1, byte2 Enable bits (if byte 1==2):
419 * 0 Enable WiFi locator (1)
421 * cbRes1 Standard return codes (0, -1, -2)
422 * cbRes2 QuickSet radio disable bit map:
423 * 0 WLAN controlled by sw itch (1)
424 * 1 BT controlled by sw itch (1)
425 * 2 WWAN controlled by sw itch (1)
426 * 3 UWB controlled by sw itch (1)
427 * 4 WiGig controlled by sw itch (1)
429 * 7 Wireless sw itch config locked (1)
430 * 8 WiFi locator enabled (1)
432 * 15 WiFi locator setting locked (1)
435 * Read Local Config Data (LCD)
436 * cbArg1, byte0 = 0x10
437 * cbArg1, byte1 NVRAM index low byte
438 * cbArg1, byte2 NVRAM index high byte
439 * cbRes1 Standard return codes (0, -1, -2)
440 * cbRes2 4 bytes read from LCD[index]
441 * cbRes3 4 bytes read from LCD[index+4]
442 * cbRes4 4 bytes read from LCD[index+8]
444 * Write Local Config Data (LCD)
445 * cbArg1, byte0 = 0x11
446 * cbArg1, byte1 NVRAM index low byte
447 * cbArg1, byte2 NVRAM index high byte
448 * cbArg2 4 bytes to w rite at LCD[index]
449 * cbArg3 4 bytes to w rite at LCD[index+4]
450 * cbArg4 4 bytes to w rite at LCD[index+8]
451 * cbRes1 Standard return codes (0, -1, -2)
453 * Populate Local Config Data from NVRAM
454 * cbArg1, byte0 = 0x12
455 * cbRes1 Standard return codes (0, -1, -2)
457 * Commit Local Config Data to NVRAM
458 * cbArg1, byte0 = 0x13
459 * cbRes1 Standard return codes (0, -1, -2)
462 static int dell_rfkill_set(void *data
, bool blocked
)
464 int disable
= blocked
? 1 : 0;
465 unsigned long radio
= (unsigned long)data
;
466 int hwswitch_bit
= (unsigned long)data
- 1;
467 struct calling_interface_buffer buffer
;
472 dell_fill_request(&buffer
, 0, 0, 0, 0);
473 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
476 status
= buffer
.output
[1];
478 dell_fill_request(&buffer
, 0x2, 0, 0, 0);
479 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
482 hwswitch
= buffer
.output
[1];
484 /* If the hardware switch controls this radio, and the hardware
485 switch is disabled, always disable the radio */
486 if (ret
== 0 && (hwswitch
& BIT(hwswitch_bit
)) &&
487 (status
& BIT(0)) && !(status
& BIT(16)))
490 dell_fill_request(&buffer
, 1 | (radio
<<8) | (disable
<< 16), 0, 0, 0);
491 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
495 static void dell_rfkill_update_sw_state(struct rfkill
*rfkill
, int radio
,
498 if (status
& BIT(0)) {
499 /* Has hw-switch, sync sw_state to BIOS */
500 struct calling_interface_buffer buffer
;
501 int block
= rfkill_blocked(rfkill
);
502 dell_fill_request(&buffer
,
503 1 | (radio
<< 8) | (block
<< 16), 0, 0, 0);
504 dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
506 /* No hw-switch, sync BIOS state to sw_state */
507 rfkill_set_sw_state(rfkill
, !!(status
& BIT(radio
+ 16)));
511 static void dell_rfkill_update_hw_state(struct rfkill
*rfkill
, int radio
,
512 int status
, int hwswitch
)
514 if (hwswitch
& (BIT(radio
- 1)))
515 rfkill_set_hw_state(rfkill
, !(status
& BIT(16)));
518 static void dell_rfkill_query(struct rfkill
*rfkill
, void *data
)
520 int radio
= ((unsigned long)data
& 0xF);
521 struct calling_interface_buffer buffer
;
526 dell_fill_request(&buffer
, 0, 0, 0, 0);
527 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
528 status
= buffer
.output
[1];
530 if (ret
!= 0 || !(status
& BIT(0))) {
534 dell_fill_request(&buffer
, 0x2, 0, 0, 0);
535 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
536 hwswitch
= buffer
.output
[1];
541 dell_rfkill_update_hw_state(rfkill
, radio
, status
, hwswitch
);
544 static const struct rfkill_ops dell_rfkill_ops
= {
545 .set_block
= dell_rfkill_set
,
546 .query
= dell_rfkill_query
,
549 static struct dentry
*dell_laptop_dir
;
551 static int dell_debugfs_show(struct seq_file
*s
, void *data
)
553 struct calling_interface_buffer buffer
;
559 dell_fill_request(&buffer
, 0, 0, 0, 0);
560 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
563 status
= buffer
.output
[1];
565 dell_fill_request(&buffer
, 0x2, 0, 0, 0);
566 hwswitch_ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
569 hwswitch_state
= buffer
.output
[1];
571 seq_printf(s
, "return:\t%d\n", ret
);
572 seq_printf(s
, "status:\t0x%X\n", status
);
573 seq_printf(s
, "Bit 0 : Hardware switch supported: %lu\n",
575 seq_printf(s
, "Bit 1 : Wifi locator supported: %lu\n",
576 (status
& BIT(1)) >> 1);
577 seq_printf(s
, "Bit 2 : Wifi is supported: %lu\n",
578 (status
& BIT(2)) >> 2);
579 seq_printf(s
, "Bit 3 : Bluetooth is supported: %lu\n",
580 (status
& BIT(3)) >> 3);
581 seq_printf(s
, "Bit 4 : WWAN is supported: %lu\n",
582 (status
& BIT(4)) >> 4);
583 seq_printf(s
, "Bit 5 : Wireless keyboard supported: %lu\n",
584 (status
& BIT(5)) >> 5);
585 seq_printf(s
, "Bit 6 : UWB supported: %lu\n",
586 (status
& BIT(6)) >> 6);
587 seq_printf(s
, "Bit 7 : WiGig supported: %lu\n",
588 (status
& BIT(7)) >> 7);
589 seq_printf(s
, "Bit 8 : Wifi is installed: %lu\n",
590 (status
& BIT(8)) >> 8);
591 seq_printf(s
, "Bit 9 : Bluetooth is installed: %lu\n",
592 (status
& BIT(9)) >> 9);
593 seq_printf(s
, "Bit 10: WWAN is installed: %lu\n",
594 (status
& BIT(10)) >> 10);
595 seq_printf(s
, "Bit 11: UWB installed: %lu\n",
596 (status
& BIT(11)) >> 11);
597 seq_printf(s
, "Bit 12: WiGig installed: %lu\n",
598 (status
& BIT(12)) >> 12);
600 seq_printf(s
, "Bit 16: Hardware switch is on: %lu\n",
601 (status
& BIT(16)) >> 16);
602 seq_printf(s
, "Bit 17: Wifi is blocked: %lu\n",
603 (status
& BIT(17)) >> 17);
604 seq_printf(s
, "Bit 18: Bluetooth is blocked: %lu\n",
605 (status
& BIT(18)) >> 18);
606 seq_printf(s
, "Bit 19: WWAN is blocked: %lu\n",
607 (status
& BIT(19)) >> 19);
608 seq_printf(s
, "Bit 20: UWB is blocked: %lu\n",
609 (status
& BIT(20)) >> 20);
610 seq_printf(s
, "Bit 21: WiGig is blocked: %lu\n",
611 (status
& BIT(21)) >> 21);
613 seq_printf(s
, "\nhwswitch_return:\t%d\n", hwswitch_ret
);
614 seq_printf(s
, "hwswitch_state:\t0x%X\n", hwswitch_state
);
615 seq_printf(s
, "Bit 0 : Wifi controlled by switch: %lu\n",
616 hwswitch_state
& BIT(0));
617 seq_printf(s
, "Bit 1 : Bluetooth controlled by switch: %lu\n",
618 (hwswitch_state
& BIT(1)) >> 1);
619 seq_printf(s
, "Bit 2 : WWAN controlled by switch: %lu\n",
620 (hwswitch_state
& BIT(2)) >> 2);
621 seq_printf(s
, "Bit 3 : UWB controlled by switch: %lu\n",
622 (hwswitch_state
& BIT(3)) >> 3);
623 seq_printf(s
, "Bit 4 : WiGig controlled by switch: %lu\n",
624 (hwswitch_state
& BIT(4)) >> 4);
625 seq_printf(s
, "Bit 7 : Wireless switch config locked: %lu\n",
626 (hwswitch_state
& BIT(7)) >> 7);
627 seq_printf(s
, "Bit 8 : Wifi locator enabled: %lu\n",
628 (hwswitch_state
& BIT(8)) >> 8);
629 seq_printf(s
, "Bit 15: Wifi locator setting locked: %lu\n",
630 (hwswitch_state
& BIT(15)) >> 15);
634 DEFINE_SHOW_ATTRIBUTE(dell_debugfs
);
636 static void dell_update_rfkill(struct work_struct
*ignored
)
638 struct calling_interface_buffer buffer
;
643 dell_fill_request(&buffer
, 0, 0, 0, 0);
644 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
645 status
= buffer
.output
[1];
650 dell_fill_request(&buffer
, 0x2, 0, 0, 0);
651 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
653 if (ret
== 0 && (status
& BIT(0)))
654 hwswitch
= buffer
.output
[1];
657 dell_rfkill_update_hw_state(wifi_rfkill
, 1, status
, hwswitch
);
658 dell_rfkill_update_sw_state(wifi_rfkill
, 1, status
);
660 if (bluetooth_rfkill
) {
661 dell_rfkill_update_hw_state(bluetooth_rfkill
, 2, status
,
663 dell_rfkill_update_sw_state(bluetooth_rfkill
, 2, status
);
666 dell_rfkill_update_hw_state(wwan_rfkill
, 3, status
, hwswitch
);
667 dell_rfkill_update_sw_state(wwan_rfkill
, 3, status
);
670 static DECLARE_DELAYED_WORK(dell_rfkill_work
, dell_update_rfkill
);
672 static bool dell_laptop_i8042_filter(unsigned char data
, unsigned char str
,
675 static bool extended
;
677 if (str
& I8042_STR_AUXDATA
)
680 if (unlikely(data
== 0xe0)) {
683 } else if (unlikely(extended
)) {
686 schedule_delayed_work(&dell_rfkill_work
,
687 round_jiffies_relative(HZ
/ 4));
696 static int (*dell_rbtn_notifier_register_func
)(struct notifier_block
*);
697 static int (*dell_rbtn_notifier_unregister_func
)(struct notifier_block
*);
699 static int dell_laptop_rbtn_notifier_call(struct notifier_block
*nb
,
700 unsigned long action
, void *data
)
702 schedule_delayed_work(&dell_rfkill_work
, 0);
706 static struct notifier_block dell_laptop_rbtn_notifier
= {
707 .notifier_call
= dell_laptop_rbtn_notifier_call
,
710 static int __init
dell_setup_rfkill(void)
712 struct calling_interface_buffer buffer
;
713 int status
, ret
, whitelisted
;
717 * rfkill support causes trouble on various models, mostly Inspirons.
718 * So we whitelist certain series, and don't support rfkill on others.
721 product
= dmi_get_system_info(DMI_PRODUCT_NAME
);
722 if (product
&& (strncmp(product
, "Latitude", 8) == 0 ||
723 strncmp(product
, "Precision", 9) == 0))
725 if (!force_rfkill
&& !whitelisted
)
728 dell_fill_request(&buffer
, 0, 0, 0, 0);
729 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
730 status
= buffer
.output
[1];
732 /* dell wireless info smbios call is not supported */
736 /* rfkill is only tested on laptops with a hwswitch */
737 if (!(status
& BIT(0)) && !force_rfkill
)
740 if ((status
& (1<<2|1<<8)) == (1<<2|1<<8)) {
741 wifi_rfkill
= rfkill_alloc("dell-wifi", &platform_device
->dev
,
743 &dell_rfkill_ops
, (void *) 1);
748 ret
= rfkill_register(wifi_rfkill
);
753 if ((status
& (1<<3|1<<9)) == (1<<3|1<<9)) {
754 bluetooth_rfkill
= rfkill_alloc("dell-bluetooth",
755 &platform_device
->dev
,
756 RFKILL_TYPE_BLUETOOTH
,
757 &dell_rfkill_ops
, (void *) 2);
758 if (!bluetooth_rfkill
) {
762 ret
= rfkill_register(bluetooth_rfkill
);
767 if ((status
& (1<<4|1<<10)) == (1<<4|1<<10)) {
768 wwan_rfkill
= rfkill_alloc("dell-wwan",
769 &platform_device
->dev
,
771 &dell_rfkill_ops
, (void *) 3);
776 ret
= rfkill_register(wwan_rfkill
);
782 * Dell Airplane Mode Switch driver (dell-rbtn) supports ACPI devices
783 * which can receive events from HW slider switch.
785 * Dell SMBIOS on whitelisted models supports controlling radio devices
786 * but does not support receiving HW button switch events. We can use
787 * i8042 filter hook function to receive keyboard data and handle
788 * keycode for HW button.
790 * So if it is possible we will use Dell Airplane Mode Switch ACPI
791 * driver for receiving HW events and Dell SMBIOS for setting rfkill
792 * states. If ACPI driver or device is not available we will fallback to
793 * i8042 filter hook function.
795 * To prevent duplicate rfkill devices which control and do same thing,
796 * dell-rbtn driver will automatically remove its own rfkill devices
797 * once function dell_rbtn_notifier_register() is called.
800 dell_rbtn_notifier_register_func
=
801 symbol_request(dell_rbtn_notifier_register
);
802 if (dell_rbtn_notifier_register_func
) {
803 dell_rbtn_notifier_unregister_func
=
804 symbol_request(dell_rbtn_notifier_unregister
);
805 if (!dell_rbtn_notifier_unregister_func
) {
806 symbol_put(dell_rbtn_notifier_register
);
807 dell_rbtn_notifier_register_func
= NULL
;
811 if (dell_rbtn_notifier_register_func
) {
812 ret
= dell_rbtn_notifier_register_func(
813 &dell_laptop_rbtn_notifier
);
814 symbol_put(dell_rbtn_notifier_register
);
815 dell_rbtn_notifier_register_func
= NULL
;
817 symbol_put(dell_rbtn_notifier_unregister
);
818 dell_rbtn_notifier_unregister_func
= NULL
;
821 pr_info("Symbols from dell-rbtn acpi driver are not available\n");
826 pr_info("Using dell-rbtn acpi driver for receiving events\n");
827 } else if (ret
!= -ENODEV
) {
828 pr_warn("Unable to register dell rbtn notifier\n");
831 ret
= i8042_install_filter(dell_laptop_i8042_filter
);
833 pr_warn("Unable to install key filter\n");
836 pr_info("Using i8042 filter function for receiving events\n");
842 rfkill_unregister(wwan_rfkill
);
844 rfkill_destroy(wwan_rfkill
);
845 if (bluetooth_rfkill
)
846 rfkill_unregister(bluetooth_rfkill
);
848 rfkill_destroy(bluetooth_rfkill
);
850 rfkill_unregister(wifi_rfkill
);
852 rfkill_destroy(wifi_rfkill
);
857 static void dell_cleanup_rfkill(void)
859 if (dell_rbtn_notifier_unregister_func
) {
860 dell_rbtn_notifier_unregister_func(&dell_laptop_rbtn_notifier
);
861 symbol_put(dell_rbtn_notifier_unregister
);
862 dell_rbtn_notifier_unregister_func
= NULL
;
864 i8042_remove_filter(dell_laptop_i8042_filter
);
866 cancel_delayed_work_sync(&dell_rfkill_work
);
868 rfkill_unregister(wifi_rfkill
);
869 rfkill_destroy(wifi_rfkill
);
871 if (bluetooth_rfkill
) {
872 rfkill_unregister(bluetooth_rfkill
);
873 rfkill_destroy(bluetooth_rfkill
);
876 rfkill_unregister(wwan_rfkill
);
877 rfkill_destroy(wwan_rfkill
);
881 static int dell_send_intensity(struct backlight_device
*bd
)
883 struct calling_interface_buffer buffer
;
884 struct calling_interface_token
*token
;
887 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
891 dell_fill_request(&buffer
,
892 token
->location
, bd
->props
.brightness
, 0, 0);
893 if (power_supply_is_system_supplied() > 0)
894 ret
= dell_send_request(&buffer
,
895 CLASS_TOKEN_WRITE
, SELECT_TOKEN_AC
);
897 ret
= dell_send_request(&buffer
,
898 CLASS_TOKEN_WRITE
, SELECT_TOKEN_BAT
);
903 static int dell_get_intensity(struct backlight_device
*bd
)
905 struct calling_interface_buffer buffer
;
906 struct calling_interface_token
*token
;
909 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
913 dell_fill_request(&buffer
, token
->location
, 0, 0, 0);
914 if (power_supply_is_system_supplied() > 0)
915 ret
= dell_send_request(&buffer
,
916 CLASS_TOKEN_READ
, SELECT_TOKEN_AC
);
918 ret
= dell_send_request(&buffer
,
919 CLASS_TOKEN_READ
, SELECT_TOKEN_BAT
);
922 ret
= buffer
.output
[1];
927 static const struct backlight_ops dell_ops
= {
928 .get_brightness
= dell_get_intensity
,
929 .update_status
= dell_send_intensity
,
932 static void touchpad_led_on(void)
936 i8042_command(&data
, command
| 1 << 12);
939 static void touchpad_led_off(void)
943 i8042_command(&data
, command
| 1 << 12);
946 static void touchpad_led_set(struct led_classdev
*led_cdev
,
947 enum led_brightness value
)
955 static struct led_classdev touchpad_led
= {
956 .name
= "dell-laptop::touchpad",
957 .brightness_set
= touchpad_led_set
,
958 .flags
= LED_CORE_SUSPENDRESUME
,
961 static int __init
touchpad_led_init(struct device
*dev
)
963 return led_classdev_register(dev
, &touchpad_led
);
966 static void touchpad_led_exit(void)
968 led_classdev_unregister(&touchpad_led
);
972 * Derived from information in smbios-keyboard-ctl:
976 * Keyboard illumination
977 * cbArg1 determines the function to be performed
979 * cbArg1 0x0 = Get Feature Information
980 * cbRES1 Standard return codes (0, -1, -2)
981 * cbRES2, word0 Bitmap of user-selectable modes
982 * bit 0 Always off (All systems)
983 * bit 1 Always on (Travis ATG, Siberia)
984 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
985 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
986 * bit 4 Auto: Input-activity-based On; input-activity based Off
987 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
988 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
989 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
990 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
991 * bits 9-15 Reserved for future use
992 * cbRES2, byte2 Reserved for future use
993 * cbRES2, byte3 Keyboard illumination type
997 * 3-255 Reserved for future use
998 * cbRES3, byte0 Supported auto keyboard illumination trigger bitmap.
999 * bit 0 Any keystroke
1000 * bit 1 Touchpad activity
1001 * bit 2 Pointing stick
1003 * bits 4-7 Reserved for future use
1004 * cbRES3, byte1 Supported timeout unit bitmap
1009 * bits 4-7 Reserved for future use
1010 * cbRES3, byte2 Number of keyboard light brightness levels
1011 * cbRES4, byte0 Maximum acceptable seconds value (0 if seconds not supported).
1012 * cbRES4, byte1 Maximum acceptable minutes value (0 if minutes not supported).
1013 * cbRES4, byte2 Maximum acceptable hours value (0 if hours not supported).
1014 * cbRES4, byte3 Maximum acceptable days value (0 if days not supported)
1016 * cbArg1 0x1 = Get Current State
1017 * cbRES1 Standard return codes (0, -1, -2)
1018 * cbRES2, word0 Bitmap of current mode state
1019 * bit 0 Always off (All systems)
1020 * bit 1 Always on (Travis ATG, Siberia)
1021 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
1022 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
1023 * bit 4 Auto: Input-activity-based On; input-activity based Off
1024 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
1025 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
1026 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
1027 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
1028 * bits 9-15 Reserved for future use
1029 * Note: Only One bit can be set
1030 * cbRES2, byte2 Currently active auto keyboard illumination triggers.
1031 * bit 0 Any keystroke
1032 * bit 1 Touchpad activity
1033 * bit 2 Pointing stick
1035 * bits 4-7 Reserved for future use
1036 * cbRES2, byte3 Current Timeout on battery
1037 * bits 7:6 Timeout units indicator:
1042 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1043 * NOTE: A value of 0 means always on (no timeout) if any bits of RES3 byte
1044 * are set upon return from the [Get feature information] call.
1045 * cbRES3, byte0 Current setting of ALS value that turns the light on or off.
1046 * cbRES3, byte1 Current ALS reading
1047 * cbRES3, byte2 Current keyboard light level.
1048 * cbRES3, byte3 Current timeout on AC Power
1049 * bits 7:6 Timeout units indicator:
1054 * Bits 5:0 Timeout value (0-63) in sec/min/hr/day
1055 * NOTE: A value of 0 means always on (no timeout) if any bits of RES3 byte2
1056 * are set upon return from the upon return from the [Get Feature information] call.
1058 * cbArg1 0x2 = Set New State
1059 * cbRES1 Standard return codes (0, -1, -2)
1060 * cbArg2, word0 Bitmap of current mode state
1061 * bit 0 Always off (All systems)
1062 * bit 1 Always on (Travis ATG, Siberia)
1063 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
1064 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
1065 * bit 4 Auto: Input-activity-based On; input-activity based Off
1066 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
1067 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
1068 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
1069 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
1070 * bits 9-15 Reserved for future use
1071 * Note: Only One bit can be set
1072 * cbArg2, byte2 Desired auto keyboard illumination triggers. Must remain inactive to allow
1073 * keyboard to turn off automatically.
1074 * bit 0 Any keystroke
1075 * bit 1 Touchpad activity
1076 * bit 2 Pointing stick
1078 * bits 4-7 Reserved for future use
1079 * cbArg2, byte3 Desired Timeout on battery
1080 * bits 7:6 Timeout units indicator:
1085 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1086 * cbArg3, byte0 Desired setting of ALS value that turns the light on or off.
1087 * cbArg3, byte2 Desired keyboard light level.
1088 * cbArg3, byte3 Desired Timeout on AC power
1089 * bits 7:6 Timeout units indicator:
1094 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1098 enum kbd_timeout_unit
{
1099 KBD_TIMEOUT_SECONDS
= 0,
1100 KBD_TIMEOUT_MINUTES
,
1106 KBD_MODE_BIT_OFF
= 0,
1109 KBD_MODE_BIT_TRIGGER_ALS
,
1110 KBD_MODE_BIT_TRIGGER
,
1111 KBD_MODE_BIT_TRIGGER_25
,
1112 KBD_MODE_BIT_TRIGGER_50
,
1113 KBD_MODE_BIT_TRIGGER_75
,
1114 KBD_MODE_BIT_TRIGGER_100
,
1117 #define kbd_is_als_mode_bit(bit) \
1118 ((bit) == KBD_MODE_BIT_ALS || (bit) == KBD_MODE_BIT_TRIGGER_ALS)
1119 #define kbd_is_trigger_mode_bit(bit) \
1120 ((bit) >= KBD_MODE_BIT_TRIGGER_ALS && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1121 #define kbd_is_level_mode_bit(bit) \
1122 ((bit) >= KBD_MODE_BIT_TRIGGER_25 && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1140 u8 timeout_value_ac
;
1147 static const int kbd_tokens
[] = {
1149 KBD_LED_AUTO_25_TOKEN
,
1150 KBD_LED_AUTO_50_TOKEN
,
1151 KBD_LED_AUTO_75_TOKEN
,
1152 KBD_LED_AUTO_100_TOKEN
,
1156 static u16 kbd_token_bits
;
1158 static struct kbd_info kbd_info
;
1159 static bool kbd_als_supported
;
1160 static bool kbd_triggers_supported
;
1161 static bool kbd_timeout_ac_supported
;
1163 static u8 kbd_mode_levels
[16];
1164 static int kbd_mode_levels_count
;
1166 static u8 kbd_previous_level
;
1167 static u8 kbd_previous_mode_bit
;
1169 static bool kbd_led_present
;
1170 static DEFINE_MUTEX(kbd_led_mutex
);
1171 static enum led_brightness kbd_led_level
;
1174 * NOTE: there are three ways to set the keyboard backlight level.
1175 * First, via kbd_state.mode_bit (assigning KBD_MODE_BIT_TRIGGER_* value).
1176 * Second, via kbd_state.level (assigning numerical value <= kbd_info.levels).
1177 * Third, via SMBIOS tokens (KBD_LED_* in kbd_tokens)
1179 * There are laptops which support only one of these methods. If we want to
1180 * support as many machines as possible we need to implement all three methods.
1181 * The first two methods use the kbd_state structure. The third uses SMBIOS
1182 * tokens. If kbd_info.levels == 0, the machine does not support setting the
1183 * keyboard backlight level via kbd_state.level.
1186 static int kbd_get_info(struct kbd_info
*info
)
1188 struct calling_interface_buffer buffer
;
1192 dell_fill_request(&buffer
, 0, 0, 0, 0);
1193 ret
= dell_send_request(&buffer
,
1194 CLASS_KBD_BACKLIGHT
, SELECT_KBD_BACKLIGHT
);
1198 info
->modes
= buffer
.output
[1] & 0xFFFF;
1199 info
->type
= (buffer
.output
[1] >> 24) & 0xFF;
1200 info
->triggers
= buffer
.output
[2] & 0xFF;
1201 units
= (buffer
.output
[2] >> 8) & 0xFF;
1202 info
->levels
= (buffer
.output
[2] >> 16) & 0xFF;
1204 if (quirks
&& quirks
->kbd_led_levels_off_1
&& info
->levels
)
1208 info
->seconds
= (buffer
.output
[3] >> 0) & 0xFF;
1210 info
->minutes
= (buffer
.output
[3] >> 8) & 0xFF;
1212 info
->hours
= (buffer
.output
[3] >> 16) & 0xFF;
1214 info
->days
= (buffer
.output
[3] >> 24) & 0xFF;
1219 static unsigned int kbd_get_max_level(void)
1221 if (kbd_info
.levels
!= 0)
1222 return kbd_info
.levels
;
1223 if (kbd_mode_levels_count
> 0)
1224 return kbd_mode_levels_count
- 1;
1228 static int kbd_get_level(struct kbd_state
*state
)
1232 if (kbd_info
.levels
!= 0)
1233 return state
->level
;
1235 if (kbd_mode_levels_count
> 0) {
1236 for (i
= 0; i
< kbd_mode_levels_count
; ++i
)
1237 if (kbd_mode_levels
[i
] == state
->mode_bit
)
1245 static int kbd_set_level(struct kbd_state
*state
, u8 level
)
1247 if (kbd_info
.levels
!= 0) {
1249 kbd_previous_level
= level
;
1250 if (state
->level
== level
)
1252 state
->level
= level
;
1253 if (level
!= 0 && state
->mode_bit
== KBD_MODE_BIT_OFF
)
1254 state
->mode_bit
= kbd_previous_mode_bit
;
1255 else if (level
== 0 && state
->mode_bit
!= KBD_MODE_BIT_OFF
) {
1256 kbd_previous_mode_bit
= state
->mode_bit
;
1257 state
->mode_bit
= KBD_MODE_BIT_OFF
;
1262 if (kbd_mode_levels_count
> 0 && level
< kbd_mode_levels_count
) {
1264 kbd_previous_level
= level
;
1265 state
->mode_bit
= kbd_mode_levels
[level
];
1272 static int kbd_get_state(struct kbd_state
*state
)
1274 struct calling_interface_buffer buffer
;
1277 dell_fill_request(&buffer
, 0x1, 0, 0, 0);
1278 ret
= dell_send_request(&buffer
,
1279 CLASS_KBD_BACKLIGHT
, SELECT_KBD_BACKLIGHT
);
1283 state
->mode_bit
= ffs(buffer
.output
[1] & 0xFFFF);
1284 if (state
->mode_bit
!= 0)
1287 state
->triggers
= (buffer
.output
[1] >> 16) & 0xFF;
1288 state
->timeout_value
= (buffer
.output
[1] >> 24) & 0x3F;
1289 state
->timeout_unit
= (buffer
.output
[1] >> 30) & 0x3;
1290 state
->als_setting
= buffer
.output
[2] & 0xFF;
1291 state
->als_value
= (buffer
.output
[2] >> 8) & 0xFF;
1292 state
->level
= (buffer
.output
[2] >> 16) & 0xFF;
1293 state
->timeout_value_ac
= (buffer
.output
[2] >> 24) & 0x3F;
1294 state
->timeout_unit_ac
= (buffer
.output
[2] >> 30) & 0x3;
1299 static int kbd_set_state(struct kbd_state
*state
)
1301 struct calling_interface_buffer buffer
;
1306 input1
= BIT(state
->mode_bit
) & 0xFFFF;
1307 input1
|= (state
->triggers
& 0xFF) << 16;
1308 input1
|= (state
->timeout_value
& 0x3F) << 24;
1309 input1
|= (state
->timeout_unit
& 0x3) << 30;
1310 input2
= state
->als_setting
& 0xFF;
1311 input2
|= (state
->level
& 0xFF) << 16;
1312 input2
|= (state
->timeout_value_ac
& 0x3F) << 24;
1313 input2
|= (state
->timeout_unit_ac
& 0x3) << 30;
1314 dell_fill_request(&buffer
, 0x2, input1
, input2
, 0);
1315 ret
= dell_send_request(&buffer
,
1316 CLASS_KBD_BACKLIGHT
, SELECT_KBD_BACKLIGHT
);
1321 static int kbd_set_state_safe(struct kbd_state
*state
, struct kbd_state
*old
)
1325 ret
= kbd_set_state(state
);
1330 * When setting the new state fails,try to restore the previous one.
1331 * This is needed on some machines where BIOS sets a default state when
1332 * setting a new state fails. This default state could be all off.
1335 if (kbd_set_state(old
))
1336 pr_err("Setting old previous keyboard state failed\n");
1341 static int kbd_set_token_bit(u8 bit
)
1343 struct calling_interface_buffer buffer
;
1344 struct calling_interface_token
*token
;
1347 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1350 token
= dell_smbios_find_token(kbd_tokens
[bit
]);
1354 dell_fill_request(&buffer
, token
->location
, token
->value
, 0, 0);
1355 ret
= dell_send_request(&buffer
, CLASS_TOKEN_WRITE
, SELECT_TOKEN_STD
);
1360 static int kbd_get_token_bit(u8 bit
)
1362 struct calling_interface_buffer buffer
;
1363 struct calling_interface_token
*token
;
1367 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1370 token
= dell_smbios_find_token(kbd_tokens
[bit
]);
1374 dell_fill_request(&buffer
, token
->location
, 0, 0, 0);
1375 ret
= dell_send_request(&buffer
, CLASS_TOKEN_READ
, SELECT_TOKEN_STD
);
1376 val
= buffer
.output
[1];
1381 return (val
== token
->value
);
1384 static int kbd_get_first_active_token_bit(void)
1389 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
) {
1390 ret
= kbd_get_token_bit(i
);
1398 static int kbd_get_valid_token_counts(void)
1400 return hweight16(kbd_token_bits
);
1403 static inline int kbd_init_info(void)
1405 struct kbd_state state
;
1409 ret
= kbd_get_info(&kbd_info
);
1413 /* NOTE: Old models without KBD_LED_AC_TOKEN token supports only one
1414 * timeout value which is shared for both battery and AC power
1415 * settings. So do not try to set AC values on old models.
1417 if ((quirks
&& quirks
->kbd_missing_ac_tag
) ||
1418 dell_smbios_find_token(KBD_LED_AC_TOKEN
))
1419 kbd_timeout_ac_supported
= true;
1421 kbd_get_state(&state
);
1423 /* NOTE: timeout value is stored in 6 bits so max value is 63 */
1424 if (kbd_info
.seconds
> 63)
1425 kbd_info
.seconds
= 63;
1426 if (kbd_info
.minutes
> 63)
1427 kbd_info
.minutes
= 63;
1428 if (kbd_info
.hours
> 63)
1429 kbd_info
.hours
= 63;
1430 if (kbd_info
.days
> 63)
1433 /* NOTE: On tested machines ON mode did not work and caused
1434 * problems (turned backlight off) so do not use it
1436 kbd_info
.modes
&= ~BIT(KBD_MODE_BIT_ON
);
1438 kbd_previous_level
= kbd_get_level(&state
);
1439 kbd_previous_mode_bit
= state
.mode_bit
;
1441 if (kbd_previous_level
== 0 && kbd_get_max_level() != 0)
1442 kbd_previous_level
= 1;
1444 if (kbd_previous_mode_bit
== KBD_MODE_BIT_OFF
) {
1445 kbd_previous_mode_bit
=
1446 ffs(kbd_info
.modes
& ~BIT(KBD_MODE_BIT_OFF
));
1447 if (kbd_previous_mode_bit
!= 0)
1448 kbd_previous_mode_bit
--;
1451 if (kbd_info
.modes
& (BIT(KBD_MODE_BIT_ALS
) |
1452 BIT(KBD_MODE_BIT_TRIGGER_ALS
)))
1453 kbd_als_supported
= true;
1455 if (kbd_info
.modes
& (
1456 BIT(KBD_MODE_BIT_TRIGGER_ALS
) | BIT(KBD_MODE_BIT_TRIGGER
) |
1457 BIT(KBD_MODE_BIT_TRIGGER_25
) | BIT(KBD_MODE_BIT_TRIGGER_50
) |
1458 BIT(KBD_MODE_BIT_TRIGGER_75
) | BIT(KBD_MODE_BIT_TRIGGER_100
)
1460 kbd_triggers_supported
= true;
1462 /* kbd_mode_levels[0] is reserved, see below */
1463 for (i
= 0; i
< 16; ++i
)
1464 if (kbd_is_level_mode_bit(i
) && (BIT(i
) & kbd_info
.modes
))
1465 kbd_mode_levels
[1 + kbd_mode_levels_count
++] = i
;
1468 * Find the first supported mode and assign to kbd_mode_levels[0].
1469 * This should be 0 (off), but we cannot depend on the BIOS to
1472 if (kbd_mode_levels_count
> 0) {
1473 for (i
= 0; i
< 16; ++i
) {
1474 if (BIT(i
) & kbd_info
.modes
) {
1475 kbd_mode_levels
[0] = i
;
1479 kbd_mode_levels_count
++;
1486 static inline void kbd_init_tokens(void)
1490 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
)
1491 if (dell_smbios_find_token(kbd_tokens
[i
]))
1492 kbd_token_bits
|= BIT(i
);
1495 static void kbd_init(void)
1499 ret
= kbd_init_info();
1503 * Only supports keyboard backlight when it has at least two modes.
1505 if ((ret
== 0 && (kbd_info
.levels
!= 0 || kbd_mode_levels_count
>= 2))
1506 || kbd_get_valid_token_counts() >= 2)
1507 kbd_led_present
= true;
1510 static ssize_t
kbd_led_timeout_store(struct device
*dev
,
1511 struct device_attribute
*attr
,
1512 const char *buf
, size_t count
)
1514 struct kbd_state new_state
;
1515 struct kbd_state state
;
1523 ret
= sscanf(buf
, "%d %c", &value
, &ch
);
1536 if (value
> kbd_info
.seconds
)
1538 unit
= KBD_TIMEOUT_SECONDS
;
1541 if (value
> kbd_info
.minutes
)
1543 unit
= KBD_TIMEOUT_MINUTES
;
1546 if (value
> kbd_info
.hours
)
1548 unit
= KBD_TIMEOUT_HOURS
;
1551 if (value
> kbd_info
.days
)
1553 unit
= KBD_TIMEOUT_DAYS
;
1559 if (quirks
&& quirks
->needs_kbd_timeouts
)
1563 /* Convert value from current units to seconds */
1565 case KBD_TIMEOUT_DAYS
:
1568 case KBD_TIMEOUT_HOURS
:
1571 case KBD_TIMEOUT_MINUTES
:
1573 unit
= KBD_TIMEOUT_SECONDS
;
1576 if (quirks
&& quirks
->needs_kbd_timeouts
) {
1577 for (i
= 0; quirks
->kbd_timeouts
[i
] != -1; i
++) {
1578 if (value
<= quirks
->kbd_timeouts
[i
]) {
1579 value
= quirks
->kbd_timeouts
[i
];
1585 if (value
<= kbd_info
.seconds
&& kbd_info
.seconds
) {
1586 unit
= KBD_TIMEOUT_SECONDS
;
1587 } else if (value
/ 60 <= kbd_info
.minutes
&& kbd_info
.minutes
) {
1589 unit
= KBD_TIMEOUT_MINUTES
;
1590 } else if (value
/ (60 * 60) <= kbd_info
.hours
&& kbd_info
.hours
) {
1592 unit
= KBD_TIMEOUT_HOURS
;
1593 } else if (value
/ (60 * 60 * 24) <= kbd_info
.days
&& kbd_info
.days
) {
1594 value
/= (60 * 60 * 24);
1595 unit
= KBD_TIMEOUT_DAYS
;
1601 mutex_lock(&kbd_led_mutex
);
1603 ret
= kbd_get_state(&state
);
1609 if (kbd_timeout_ac_supported
&& power_supply_is_system_supplied() > 0) {
1610 new_state
.timeout_value_ac
= value
;
1611 new_state
.timeout_unit_ac
= unit
;
1613 new_state
.timeout_value
= value
;
1614 new_state
.timeout_unit
= unit
;
1617 ret
= kbd_set_state_safe(&new_state
, &state
);
1623 mutex_unlock(&kbd_led_mutex
);
1627 static ssize_t
kbd_led_timeout_show(struct device
*dev
,
1628 struct device_attribute
*attr
, char *buf
)
1630 struct kbd_state state
;
1636 ret
= kbd_get_state(&state
);
1640 if (kbd_timeout_ac_supported
&& power_supply_is_system_supplied() > 0) {
1641 value
= state
.timeout_value_ac
;
1642 unit
= state
.timeout_unit_ac
;
1644 value
= state
.timeout_value
;
1645 unit
= state
.timeout_unit
;
1648 len
= sprintf(buf
, "%d", value
);
1651 case KBD_TIMEOUT_SECONDS
:
1652 return len
+ sprintf(buf
+len
, "s\n");
1653 case KBD_TIMEOUT_MINUTES
:
1654 return len
+ sprintf(buf
+len
, "m\n");
1655 case KBD_TIMEOUT_HOURS
:
1656 return len
+ sprintf(buf
+len
, "h\n");
1657 case KBD_TIMEOUT_DAYS
:
1658 return len
+ sprintf(buf
+len
, "d\n");
1666 static DEVICE_ATTR(stop_timeout
, S_IRUGO
| S_IWUSR
,
1667 kbd_led_timeout_show
, kbd_led_timeout_store
);
1669 static const char * const kbd_led_triggers
[] = {
1672 /*"trackstick"*/ NULL
, /* NOTE: trackstick is just alias for touchpad */
1676 static ssize_t
kbd_led_triggers_store(struct device
*dev
,
1677 struct device_attribute
*attr
,
1678 const char *buf
, size_t count
)
1680 struct kbd_state new_state
;
1681 struct kbd_state state
;
1682 bool triggers_enabled
= false;
1683 int trigger_bit
= -1;
1687 ret
= sscanf(buf
, "%20s", trigger
);
1691 if (trigger
[0] != '+' && trigger
[0] != '-')
1694 mutex_lock(&kbd_led_mutex
);
1696 ret
= kbd_get_state(&state
);
1700 if (kbd_triggers_supported
)
1701 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1703 if (kbd_triggers_supported
) {
1704 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1705 if (!(kbd_info
.triggers
& BIT(i
)))
1707 if (!kbd_led_triggers
[i
])
1709 if (strcmp(trigger
+1, kbd_led_triggers
[i
]) != 0)
1711 if (trigger
[0] == '+' &&
1712 triggers_enabled
&& (state
.triggers
& BIT(i
))) {
1716 if (trigger
[0] == '-' &&
1717 (!triggers_enabled
|| !(state
.triggers
& BIT(i
)))) {
1726 if (trigger_bit
== -1) {
1732 if (trigger
[0] == '+')
1733 new_state
.triggers
|= BIT(trigger_bit
);
1735 new_state
.triggers
&= ~BIT(trigger_bit
);
1737 * NOTE: trackstick bit (2) must be disabled when
1738 * disabling touchpad bit (1), otherwise touchpad
1739 * bit (1) will not be disabled
1741 if (trigger_bit
== 1)
1742 new_state
.triggers
&= ~BIT(2);
1744 if ((kbd_info
.triggers
& new_state
.triggers
) !=
1745 new_state
.triggers
) {
1749 if (new_state
.triggers
&& !triggers_enabled
) {
1750 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1751 kbd_set_level(&new_state
, kbd_previous_level
);
1752 } else if (new_state
.triggers
== 0) {
1753 kbd_set_level(&new_state
, 0);
1755 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
))) {
1759 ret
= kbd_set_state_safe(&new_state
, &state
);
1762 if (new_state
.mode_bit
!= KBD_MODE_BIT_OFF
)
1763 kbd_previous_mode_bit
= new_state
.mode_bit
;
1766 mutex_unlock(&kbd_led_mutex
);
1770 static ssize_t
kbd_led_triggers_show(struct device
*dev
,
1771 struct device_attribute
*attr
, char *buf
)
1773 struct kbd_state state
;
1774 bool triggers_enabled
;
1778 ret
= kbd_get_state(&state
);
1784 if (kbd_triggers_supported
) {
1785 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1786 level
= kbd_get_level(&state
);
1787 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1788 if (!(kbd_info
.triggers
& BIT(i
)))
1790 if (!kbd_led_triggers
[i
])
1792 if ((triggers_enabled
|| level
<= 0) &&
1793 (state
.triggers
& BIT(i
)))
1797 len
+= sprintf(buf
+len
, "%s ", kbd_led_triggers
[i
]);
1802 buf
[len
- 1] = '\n';
1807 static DEVICE_ATTR(start_triggers
, S_IRUGO
| S_IWUSR
,
1808 kbd_led_triggers_show
, kbd_led_triggers_store
);
1810 static ssize_t
kbd_led_als_enabled_store(struct device
*dev
,
1811 struct device_attribute
*attr
,
1812 const char *buf
, size_t count
)
1814 struct kbd_state new_state
;
1815 struct kbd_state state
;
1816 bool triggers_enabled
= false;
1820 ret
= kstrtoint(buf
, 0, &enable
);
1824 mutex_lock(&kbd_led_mutex
);
1826 ret
= kbd_get_state(&state
);
1830 if (enable
== kbd_is_als_mode_bit(state
.mode_bit
)) {
1837 if (kbd_triggers_supported
)
1838 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1841 if (triggers_enabled
)
1842 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER_ALS
;
1844 new_state
.mode_bit
= KBD_MODE_BIT_ALS
;
1846 if (triggers_enabled
) {
1847 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1848 kbd_set_level(&new_state
, kbd_previous_level
);
1850 new_state
.mode_bit
= KBD_MODE_BIT_ON
;
1853 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
))) {
1858 ret
= kbd_set_state_safe(&new_state
, &state
);
1861 kbd_previous_mode_bit
= new_state
.mode_bit
;
1865 mutex_unlock(&kbd_led_mutex
);
1869 static ssize_t
kbd_led_als_enabled_show(struct device
*dev
,
1870 struct device_attribute
*attr
,
1873 struct kbd_state state
;
1874 bool enabled
= false;
1877 ret
= kbd_get_state(&state
);
1880 enabled
= kbd_is_als_mode_bit(state
.mode_bit
);
1882 return sprintf(buf
, "%d\n", enabled
? 1 : 0);
1885 static DEVICE_ATTR(als_enabled
, S_IRUGO
| S_IWUSR
,
1886 kbd_led_als_enabled_show
, kbd_led_als_enabled_store
);
1888 static ssize_t
kbd_led_als_setting_store(struct device
*dev
,
1889 struct device_attribute
*attr
,
1890 const char *buf
, size_t count
)
1892 struct kbd_state state
;
1893 struct kbd_state new_state
;
1897 ret
= kstrtou8(buf
, 10, &setting
);
1901 mutex_lock(&kbd_led_mutex
);
1903 ret
= kbd_get_state(&state
);
1908 new_state
.als_setting
= setting
;
1910 ret
= kbd_set_state_safe(&new_state
, &state
);
1916 mutex_unlock(&kbd_led_mutex
);
1920 static ssize_t
kbd_led_als_setting_show(struct device
*dev
,
1921 struct device_attribute
*attr
,
1924 struct kbd_state state
;
1927 ret
= kbd_get_state(&state
);
1931 return sprintf(buf
, "%d\n", state
.als_setting
);
1934 static DEVICE_ATTR(als_setting
, S_IRUGO
| S_IWUSR
,
1935 kbd_led_als_setting_show
, kbd_led_als_setting_store
);
1937 static struct attribute
*kbd_led_attrs
[] = {
1938 &dev_attr_stop_timeout
.attr
,
1939 &dev_attr_start_triggers
.attr
,
1943 static const struct attribute_group kbd_led_group
= {
1944 .attrs
= kbd_led_attrs
,
1947 static struct attribute
*kbd_led_als_attrs
[] = {
1948 &dev_attr_als_enabled
.attr
,
1949 &dev_attr_als_setting
.attr
,
1953 static const struct attribute_group kbd_led_als_group
= {
1954 .attrs
= kbd_led_als_attrs
,
1957 static const struct attribute_group
*kbd_led_groups
[] = {
1963 static enum led_brightness
kbd_led_level_get(struct led_classdev
*led_cdev
)
1967 struct kbd_state state
;
1969 if (kbd_get_max_level()) {
1970 ret
= kbd_get_state(&state
);
1973 ret
= kbd_get_level(&state
);
1979 if (kbd_get_valid_token_counts()) {
1980 ret
= kbd_get_first_active_token_bit();
1983 for (num
= kbd_token_bits
; num
!= 0 && ret
> 0; --ret
)
1984 num
&= num
- 1; /* clear the first bit set */
1987 return ffs(num
) - 1;
1990 pr_warn("Keyboard brightness level control not supported\n");
1994 static int kbd_led_level_set(struct led_classdev
*led_cdev
,
1995 enum led_brightness value
)
1997 enum led_brightness new_value
= value
;
1998 struct kbd_state state
;
1999 struct kbd_state new_state
;
2003 mutex_lock(&kbd_led_mutex
);
2005 if (kbd_get_max_level()) {
2006 ret
= kbd_get_state(&state
);
2010 ret
= kbd_set_level(&new_state
, value
);
2013 ret
= kbd_set_state_safe(&new_state
, &state
);
2014 } else if (kbd_get_valid_token_counts()) {
2015 for (num
= kbd_token_bits
; num
!= 0 && value
> 0; --value
)
2016 num
&= num
- 1; /* clear the first bit set */
2020 ret
= kbd_set_token_bit(ffs(num
) - 1);
2022 pr_warn("Keyboard brightness level control not supported\n");
2028 kbd_led_level
= new_value
;
2030 mutex_unlock(&kbd_led_mutex
);
2034 static struct led_classdev kbd_led
= {
2035 .name
= "dell::kbd_backlight",
2036 .flags
= LED_BRIGHT_HW_CHANGED
,
2037 .brightness_set_blocking
= kbd_led_level_set
,
2038 .brightness_get
= kbd_led_level_get
,
2039 .groups
= kbd_led_groups
,
2042 static int __init
kbd_led_init(struct device
*dev
)
2047 if (!kbd_led_present
)
2049 if (!kbd_als_supported
)
2050 kbd_led_groups
[1] = NULL
;
2051 kbd_led
.max_brightness
= kbd_get_max_level();
2052 if (!kbd_led
.max_brightness
) {
2053 kbd_led
.max_brightness
= kbd_get_valid_token_counts();
2054 if (kbd_led
.max_brightness
)
2055 kbd_led
.max_brightness
--;
2058 kbd_led_level
= kbd_led_level_get(NULL
);
2060 ret
= led_classdev_register(dev
, &kbd_led
);
2062 kbd_led_present
= false;
2067 static void brightness_set_exit(struct led_classdev
*led_cdev
,
2068 enum led_brightness value
)
2070 /* Don't change backlight level on exit */
2073 static void kbd_led_exit(void)
2075 if (!kbd_led_present
)
2077 kbd_led
.brightness_set
= brightness_set_exit
;
2078 led_classdev_unregister(&kbd_led
);
2081 static int dell_laptop_notifier_call(struct notifier_block
*nb
,
2082 unsigned long action
, void *data
)
2084 bool changed
= false;
2085 enum led_brightness new_kbd_led_level
;
2088 case DELL_LAPTOP_KBD_BACKLIGHT_BRIGHTNESS_CHANGED
:
2089 if (!kbd_led_present
)
2092 mutex_lock(&kbd_led_mutex
);
2093 new_kbd_led_level
= kbd_led_level_get(&kbd_led
);
2094 if (kbd_led_level
!= new_kbd_led_level
) {
2095 kbd_led_level
= new_kbd_led_level
;
2098 mutex_unlock(&kbd_led_mutex
);
2101 led_classdev_notify_brightness_hw_changed(&kbd_led
,
2109 static struct notifier_block dell_laptop_notifier
= {
2110 .notifier_call
= dell_laptop_notifier_call
,
2113 static int micmute_led_set(struct led_classdev
*led_cdev
,
2114 enum led_brightness brightness
)
2116 struct calling_interface_buffer buffer
;
2117 struct calling_interface_token
*token
;
2118 int state
= brightness
!= LED_OFF
;
2121 token
= dell_smbios_find_token(GLOBAL_MIC_MUTE_DISABLE
);
2123 token
= dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE
);
2128 dell_fill_request(&buffer
, token
->location
, token
->value
, 0, 0);
2129 dell_send_request(&buffer
, CLASS_TOKEN_WRITE
, SELECT_TOKEN_STD
);
2134 static struct led_classdev micmute_led_cdev
= {
2135 .name
= "platform::micmute",
2136 .max_brightness
= 1,
2137 .brightness_set_blocking
= micmute_led_set
,
2138 .default_trigger
= "audio-micmute",
2141 static int __init
dell_init(void)
2143 struct calling_interface_token
*token
;
2144 int max_intensity
= 0;
2147 if (!dmi_check_system(dell_device_table
))
2151 /* find if this machine support other functions */
2152 dmi_check_system(dell_quirks
);
2154 ret
= platform_driver_register(&platform_driver
);
2156 goto fail_platform_driver
;
2157 platform_device
= platform_device_alloc("dell-laptop", -1);
2158 if (!platform_device
) {
2160 goto fail_platform_device1
;
2162 ret
= platform_device_add(platform_device
);
2164 goto fail_platform_device2
;
2166 ret
= dell_setup_rfkill();
2169 pr_warn("Unable to setup rfkill\n");
2173 if (quirks
&& quirks
->touchpad_led
)
2174 touchpad_led_init(&platform_device
->dev
);
2176 kbd_led_init(&platform_device
->dev
);
2178 dell_laptop_dir
= debugfs_create_dir("dell_laptop", NULL
);
2179 if (dell_laptop_dir
!= NULL
)
2180 debugfs_create_file("rfkill", 0444, dell_laptop_dir
, NULL
,
2181 &dell_debugfs_fops
);
2183 dell_laptop_register_notifier(&dell_laptop_notifier
);
2185 micmute_led_cdev
.brightness
= ledtrig_audio_get(LED_AUDIO_MICMUTE
);
2186 ret
= led_classdev_register(&platform_device
->dev
, &micmute_led_cdev
);
2190 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2193 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
2195 struct calling_interface_buffer buffer
;
2197 dell_fill_request(&buffer
, token
->location
, 0, 0, 0);
2198 ret
= dell_send_request(&buffer
,
2199 CLASS_TOKEN_READ
, SELECT_TOKEN_AC
);
2201 max_intensity
= buffer
.output
[3];
2204 if (max_intensity
) {
2205 struct backlight_properties props
;
2206 memset(&props
, 0, sizeof(struct backlight_properties
));
2207 props
.type
= BACKLIGHT_PLATFORM
;
2208 props
.max_brightness
= max_intensity
;
2209 dell_backlight_device
= backlight_device_register("dell_backlight",
2210 &platform_device
->dev
,
2215 if (IS_ERR(dell_backlight_device
)) {
2216 ret
= PTR_ERR(dell_backlight_device
);
2217 dell_backlight_device
= NULL
;
2218 goto fail_backlight
;
2221 dell_backlight_device
->props
.brightness
=
2222 dell_get_intensity(dell_backlight_device
);
2223 if (dell_backlight_device
->props
.brightness
< 0) {
2224 ret
= dell_backlight_device
->props
.brightness
;
2225 goto fail_get_brightness
;
2227 backlight_update_status(dell_backlight_device
);
2232 fail_get_brightness
:
2233 backlight_device_unregister(dell_backlight_device
);
2235 led_classdev_unregister(&micmute_led_cdev
);
2237 dell_cleanup_rfkill();
2239 platform_device_del(platform_device
);
2240 fail_platform_device2
:
2241 platform_device_put(platform_device
);
2242 fail_platform_device1
:
2243 platform_driver_unregister(&platform_driver
);
2244 fail_platform_driver
:
2248 static void __exit
dell_exit(void)
2250 dell_laptop_unregister_notifier(&dell_laptop_notifier
);
2251 debugfs_remove_recursive(dell_laptop_dir
);
2252 if (quirks
&& quirks
->touchpad_led
)
2253 touchpad_led_exit();
2255 backlight_device_unregister(dell_backlight_device
);
2256 led_classdev_unregister(&micmute_led_cdev
);
2257 dell_cleanup_rfkill();
2258 if (platform_device
) {
2259 platform_device_unregister(platform_device
);
2260 platform_driver_unregister(&platform_driver
);
2264 /* dell-rbtn.c driver export functions which will not work correctly (and could
2265 * cause kernel crash) if they are called before dell-rbtn.c init code. This is
2266 * not problem when dell-rbtn.c is compiled as external module. When both files
2267 * (dell-rbtn.c and dell-laptop.c) are compiled statically into kernel, then we
2268 * need to ensure that dell_init() will be called after initializing dell-rbtn.
2269 * This can be achieved by late_initcall() instead module_init().
2271 late_initcall(dell_init
);
2272 module_exit(dell_exit
);
2274 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
2275 MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
2276 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
2277 MODULE_DESCRIPTION("Dell laptop driver");
2278 MODULE_LICENSE("GPL");