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/dell-led.h>
33 #include <linux/seq_file.h>
34 #include <acpi/video.h>
35 #include "dell-rbtn.h"
36 #include "dell-smbios.h"
40 bool kbd_led_levels_off_1
;
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_latitude_e6410
= {
72 .kbd_led_levels_off_1
= true,
75 static struct platform_driver platform_driver
= {
77 .name
= "dell-laptop",
81 static struct platform_device
*platform_device
;
82 static struct backlight_device
*dell_backlight_device
;
83 static struct rfkill
*wifi_rfkill
;
84 static struct rfkill
*bluetooth_rfkill
;
85 static struct rfkill
*wwan_rfkill
;
86 static bool force_rfkill
;
88 module_param(force_rfkill
, bool, 0444);
89 MODULE_PARM_DESC(force_rfkill
, "enable rfkill on non whitelisted models");
91 static const struct dmi_system_id dell_device_table
[] __initconst
= {
93 .ident
= "Dell laptop",
95 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
96 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
101 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
102 DMI_MATCH(DMI_CHASSIS_TYPE
, "9"), /*Laptop*/
107 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
108 DMI_MATCH(DMI_CHASSIS_TYPE
, "10"), /*Notebook*/
113 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
114 DMI_MATCH(DMI_CHASSIS_TYPE
, "30"), /*Tablet*/
119 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
120 DMI_MATCH(DMI_CHASSIS_TYPE
, "31"), /*Convertible*/
125 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
126 DMI_MATCH(DMI_CHASSIS_TYPE
, "32"), /*Detachable*/
131 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
132 DMI_MATCH(DMI_CHASSIS_TYPE
, "30"), /*Tablet*/
137 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
138 DMI_MATCH(DMI_CHASSIS_TYPE
, "31"), /*Convertible*/
143 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
144 DMI_MATCH(DMI_CHASSIS_TYPE
, "32"), /*Detachable*/
148 .ident
= "Dell Computer Corporation",
150 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer Corporation"),
151 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
156 MODULE_DEVICE_TABLE(dmi
, dell_device_table
);
158 static const struct dmi_system_id dell_quirks
[] __initconst
= {
160 .callback
= dmi_matched
,
161 .ident
= "Dell Vostro V130",
163 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
164 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V130"),
166 .driver_data
= &quirk_dell_vostro_v130
,
169 .callback
= dmi_matched
,
170 .ident
= "Dell Vostro V131",
172 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
173 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V131"),
175 .driver_data
= &quirk_dell_vostro_v130
,
178 .callback
= dmi_matched
,
179 .ident
= "Dell Vostro 3350",
181 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
182 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3350"),
184 .driver_data
= &quirk_dell_vostro_v130
,
187 .callback
= dmi_matched
,
188 .ident
= "Dell Vostro 3555",
190 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
191 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3555"),
193 .driver_data
= &quirk_dell_vostro_v130
,
196 .callback
= dmi_matched
,
197 .ident
= "Dell Inspiron N311z",
199 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
200 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron N311z"),
202 .driver_data
= &quirk_dell_vostro_v130
,
205 .callback
= dmi_matched
,
206 .ident
= "Dell Inspiron M5110",
208 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
209 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron M5110"),
211 .driver_data
= &quirk_dell_vostro_v130
,
214 .callback
= dmi_matched
,
215 .ident
= "Dell Vostro 3360",
217 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
218 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3360"),
220 .driver_data
= &quirk_dell_vostro_v130
,
223 .callback
= dmi_matched
,
224 .ident
= "Dell Vostro 3460",
226 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
227 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3460"),
229 .driver_data
= &quirk_dell_vostro_v130
,
232 .callback
= dmi_matched
,
233 .ident
= "Dell Vostro 3560",
235 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
236 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3560"),
238 .driver_data
= &quirk_dell_vostro_v130
,
241 .callback
= dmi_matched
,
242 .ident
= "Dell Vostro 3450",
244 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
245 DMI_MATCH(DMI_PRODUCT_NAME
, "Dell System Vostro 3450"),
247 .driver_data
= &quirk_dell_vostro_v130
,
250 .callback
= dmi_matched
,
251 .ident
= "Dell Inspiron 5420",
253 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
254 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5420"),
256 .driver_data
= &quirk_dell_vostro_v130
,
259 .callback
= dmi_matched
,
260 .ident
= "Dell Inspiron 5520",
262 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
263 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5520"),
265 .driver_data
= &quirk_dell_vostro_v130
,
268 .callback
= dmi_matched
,
269 .ident
= "Dell Inspiron 5720",
271 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
272 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5720"),
274 .driver_data
= &quirk_dell_vostro_v130
,
277 .callback
= dmi_matched
,
278 .ident
= "Dell Inspiron 7420",
280 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
281 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7420"),
283 .driver_data
= &quirk_dell_vostro_v130
,
286 .callback
= dmi_matched
,
287 .ident
= "Dell Inspiron 7520",
289 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
290 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7520"),
292 .driver_data
= &quirk_dell_vostro_v130
,
295 .callback
= dmi_matched
,
296 .ident
= "Dell Inspiron 7720",
298 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
299 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7720"),
301 .driver_data
= &quirk_dell_vostro_v130
,
304 .callback
= dmi_matched
,
305 .ident
= "Dell XPS13 9333",
307 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
308 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS13 9333"),
310 .driver_data
= &quirk_dell_xps13_9333
,
313 .callback
= dmi_matched
,
314 .ident
= "Dell Latitude E6410",
316 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
317 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude E6410"),
319 .driver_data
= &quirk_dell_latitude_e6410
,
324 static void dell_fill_request(struct calling_interface_buffer
*buffer
,
325 u32 arg0
, u32 arg1
, u32 arg2
, u32 arg3
)
327 memset(buffer
, 0, sizeof(struct calling_interface_buffer
));
328 buffer
->input
[0] = arg0
;
329 buffer
->input
[1] = arg1
;
330 buffer
->input
[2] = arg2
;
331 buffer
->input
[3] = arg3
;
334 static int dell_send_request(struct calling_interface_buffer
*buffer
,
335 u16
class, u16 select
)
339 buffer
->cmd_class
= class;
340 buffer
->cmd_select
= select
;
341 ret
= dell_smbios_call(buffer
);
344 return dell_smbios_error(buffer
->output
[0]);
348 * Derived from information in smbios-wireless-ctl:
350 * cbSelect 17, Value 11
352 * Return Wireless Info
353 * cbArg1, byte0 = 0x00
355 * cbRes1 Standard return codes (0, -1, -2)
356 * cbRes2 Info bit flags:
358 * 0 Hardware switch supported (1)
359 * 1 WiFi locator supported (1)
360 * 2 WLAN supported (1)
361 * 3 Bluetooth (BT) supported (1)
362 * 4 WWAN supported (1)
363 * 5 Wireless KBD supported (1)
364 * 6 Uw b supported (1)
365 * 7 WiGig supported (1)
366 * 8 WLAN installed (1)
368 * 10 WWAN installed (1)
369 * 11 Uw b installed (1)
370 * 12 WiGig installed (1)
372 * 16 Hardware (HW) switch is On (1)
373 * 17 WLAN disabled (1)
375 * 19 WWAN disabled (1)
376 * 20 Uw b disabled (1)
377 * 21 WiGig disabled (1)
380 * cbRes3 NVRAM size in bytes
381 * cbRes4, byte 0 NVRAM format version number
384 * Set QuickSet Radio Disable Flag
385 * cbArg1, byte0 = 0x01
394 * cbArg1, byte2 Flag bits:
395 * 0 QuickSet disables radio (1)
398 * cbRes1 Standard return codes (0, -1, -2)
399 * cbRes2 QuickSet (QS) radio disable bit map:
404 * 4 QS disables WIGIG
407 * Wireless Switch Configuration
408 * cbArg1, byte0 = 0x02
414 * 2 Set WiFi locator enable/disable
416 * Switch settings (if byte 1==1):
417 * 0 WLAN sw itch control (1)
418 * 1 BT sw itch control (1)
419 * 2 WWAN sw itch control (1)
420 * 3 UWB sw itch control (1)
421 * 4 WiGig sw itch control (1)
423 * cbArg1, byte2 Enable bits (if byte 1==2):
424 * 0 Enable WiFi locator (1)
426 * cbRes1 Standard return codes (0, -1, -2)
427 * cbRes2 QuickSet radio disable bit map:
428 * 0 WLAN controlled by sw itch (1)
429 * 1 BT controlled by sw itch (1)
430 * 2 WWAN controlled by sw itch (1)
431 * 3 UWB controlled by sw itch (1)
432 * 4 WiGig controlled by sw itch (1)
434 * 7 Wireless sw itch config locked (1)
435 * 8 WiFi locator enabled (1)
437 * 15 WiFi locator setting locked (1)
440 * Read Local Config Data (LCD)
441 * cbArg1, byte0 = 0x10
442 * cbArg1, byte1 NVRAM index low byte
443 * cbArg1, byte2 NVRAM index high byte
444 * cbRes1 Standard return codes (0, -1, -2)
445 * cbRes2 4 bytes read from LCD[index]
446 * cbRes3 4 bytes read from LCD[index+4]
447 * cbRes4 4 bytes read from LCD[index+8]
449 * Write Local Config Data (LCD)
450 * cbArg1, byte0 = 0x11
451 * cbArg1, byte1 NVRAM index low byte
452 * cbArg1, byte2 NVRAM index high byte
453 * cbArg2 4 bytes to w rite at LCD[index]
454 * cbArg3 4 bytes to w rite at LCD[index+4]
455 * cbArg4 4 bytes to w rite at LCD[index+8]
456 * cbRes1 Standard return codes (0, -1, -2)
458 * Populate Local Config Data from NVRAM
459 * cbArg1, byte0 = 0x12
460 * cbRes1 Standard return codes (0, -1, -2)
462 * Commit Local Config Data to NVRAM
463 * cbArg1, byte0 = 0x13
464 * cbRes1 Standard return codes (0, -1, -2)
467 static int dell_rfkill_set(void *data
, bool blocked
)
469 int disable
= blocked
? 1 : 0;
470 unsigned long radio
= (unsigned long)data
;
471 int hwswitch_bit
= (unsigned long)data
- 1;
472 struct calling_interface_buffer buffer
;
477 dell_fill_request(&buffer
, 0, 0, 0, 0);
478 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
481 status
= buffer
.output
[1];
483 dell_fill_request(&buffer
, 0x2, 0, 0, 0);
484 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
487 hwswitch
= buffer
.output
[1];
489 /* If the hardware switch controls this radio, and the hardware
490 switch is disabled, always disable the radio */
491 if (ret
== 0 && (hwswitch
& BIT(hwswitch_bit
)) &&
492 (status
& BIT(0)) && !(status
& BIT(16)))
495 dell_fill_request(&buffer
, 1 | (radio
<<8) | (disable
<< 16), 0, 0, 0);
496 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
500 static void dell_rfkill_update_sw_state(struct rfkill
*rfkill
, int radio
,
503 if (status
& BIT(0)) {
504 /* Has hw-switch, sync sw_state to BIOS */
505 struct calling_interface_buffer buffer
;
506 int block
= rfkill_blocked(rfkill
);
507 dell_fill_request(&buffer
,
508 1 | (radio
<< 8) | (block
<< 16), 0, 0, 0);
509 dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
511 /* No hw-switch, sync BIOS state to sw_state */
512 rfkill_set_sw_state(rfkill
, !!(status
& BIT(radio
+ 16)));
516 static void dell_rfkill_update_hw_state(struct rfkill
*rfkill
, int radio
,
517 int status
, int hwswitch
)
519 if (hwswitch
& (BIT(radio
- 1)))
520 rfkill_set_hw_state(rfkill
, !(status
& BIT(16)));
523 static void dell_rfkill_query(struct rfkill
*rfkill
, void *data
)
525 int radio
= ((unsigned long)data
& 0xF);
526 struct calling_interface_buffer buffer
;
531 dell_fill_request(&buffer
, 0, 0, 0, 0);
532 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
533 status
= buffer
.output
[1];
535 if (ret
!= 0 || !(status
& BIT(0))) {
539 dell_fill_request(&buffer
, 0, 0x2, 0, 0);
540 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
541 hwswitch
= buffer
.output
[1];
546 dell_rfkill_update_hw_state(rfkill
, radio
, status
, hwswitch
);
549 static const struct rfkill_ops dell_rfkill_ops
= {
550 .set_block
= dell_rfkill_set
,
551 .query
= dell_rfkill_query
,
554 static struct dentry
*dell_laptop_dir
;
556 static int dell_debugfs_show(struct seq_file
*s
, void *data
)
558 struct calling_interface_buffer buffer
;
564 dell_fill_request(&buffer
, 0, 0, 0, 0);
565 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
568 status
= buffer
.output
[1];
570 dell_fill_request(&buffer
, 0, 0x2, 0, 0);
571 hwswitch_ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
574 hwswitch_state
= buffer
.output
[1];
576 seq_printf(s
, "return:\t%d\n", ret
);
577 seq_printf(s
, "status:\t0x%X\n", status
);
578 seq_printf(s
, "Bit 0 : Hardware switch supported: %lu\n",
580 seq_printf(s
, "Bit 1 : Wifi locator supported: %lu\n",
581 (status
& BIT(1)) >> 1);
582 seq_printf(s
, "Bit 2 : Wifi is supported: %lu\n",
583 (status
& BIT(2)) >> 2);
584 seq_printf(s
, "Bit 3 : Bluetooth is supported: %lu\n",
585 (status
& BIT(3)) >> 3);
586 seq_printf(s
, "Bit 4 : WWAN is supported: %lu\n",
587 (status
& BIT(4)) >> 4);
588 seq_printf(s
, "Bit 5 : Wireless keyboard supported: %lu\n",
589 (status
& BIT(5)) >> 5);
590 seq_printf(s
, "Bit 6 : UWB supported: %lu\n",
591 (status
& BIT(6)) >> 6);
592 seq_printf(s
, "Bit 7 : WiGig supported: %lu\n",
593 (status
& BIT(7)) >> 7);
594 seq_printf(s
, "Bit 8 : Wifi is installed: %lu\n",
595 (status
& BIT(8)) >> 8);
596 seq_printf(s
, "Bit 9 : Bluetooth is installed: %lu\n",
597 (status
& BIT(9)) >> 9);
598 seq_printf(s
, "Bit 10: WWAN is installed: %lu\n",
599 (status
& BIT(10)) >> 10);
600 seq_printf(s
, "Bit 11: UWB installed: %lu\n",
601 (status
& BIT(11)) >> 11);
602 seq_printf(s
, "Bit 12: WiGig installed: %lu\n",
603 (status
& BIT(12)) >> 12);
605 seq_printf(s
, "Bit 16: Hardware switch is on: %lu\n",
606 (status
& BIT(16)) >> 16);
607 seq_printf(s
, "Bit 17: Wifi is blocked: %lu\n",
608 (status
& BIT(17)) >> 17);
609 seq_printf(s
, "Bit 18: Bluetooth is blocked: %lu\n",
610 (status
& BIT(18)) >> 18);
611 seq_printf(s
, "Bit 19: WWAN is blocked: %lu\n",
612 (status
& BIT(19)) >> 19);
613 seq_printf(s
, "Bit 20: UWB is blocked: %lu\n",
614 (status
& BIT(20)) >> 20);
615 seq_printf(s
, "Bit 21: WiGig is blocked: %lu\n",
616 (status
& BIT(21)) >> 21);
618 seq_printf(s
, "\nhwswitch_return:\t%d\n", hwswitch_ret
);
619 seq_printf(s
, "hwswitch_state:\t0x%X\n", hwswitch_state
);
620 seq_printf(s
, "Bit 0 : Wifi controlled by switch: %lu\n",
621 hwswitch_state
& BIT(0));
622 seq_printf(s
, "Bit 1 : Bluetooth controlled by switch: %lu\n",
623 (hwswitch_state
& BIT(1)) >> 1);
624 seq_printf(s
, "Bit 2 : WWAN controlled by switch: %lu\n",
625 (hwswitch_state
& BIT(2)) >> 2);
626 seq_printf(s
, "Bit 3 : UWB controlled by switch: %lu\n",
627 (hwswitch_state
& BIT(3)) >> 3);
628 seq_printf(s
, "Bit 4 : WiGig controlled by switch: %lu\n",
629 (hwswitch_state
& BIT(4)) >> 4);
630 seq_printf(s
, "Bit 7 : Wireless switch config locked: %lu\n",
631 (hwswitch_state
& BIT(7)) >> 7);
632 seq_printf(s
, "Bit 8 : Wifi locator enabled: %lu\n",
633 (hwswitch_state
& BIT(8)) >> 8);
634 seq_printf(s
, "Bit 15: Wifi locator setting locked: %lu\n",
635 (hwswitch_state
& BIT(15)) >> 15);
639 DEFINE_SHOW_ATTRIBUTE(dell_debugfs
);
641 static void dell_update_rfkill(struct work_struct
*ignored
)
643 struct calling_interface_buffer buffer
;
648 dell_fill_request(&buffer
, 0, 0, 0, 0);
649 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
650 status
= buffer
.output
[1];
655 dell_fill_request(&buffer
, 0, 0x2, 0, 0);
656 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
658 if (ret
== 0 && (status
& BIT(0)))
659 hwswitch
= buffer
.output
[1];
662 dell_rfkill_update_hw_state(wifi_rfkill
, 1, status
, hwswitch
);
663 dell_rfkill_update_sw_state(wifi_rfkill
, 1, status
);
665 if (bluetooth_rfkill
) {
666 dell_rfkill_update_hw_state(bluetooth_rfkill
, 2, status
,
668 dell_rfkill_update_sw_state(bluetooth_rfkill
, 2, status
);
671 dell_rfkill_update_hw_state(wwan_rfkill
, 3, status
, hwswitch
);
672 dell_rfkill_update_sw_state(wwan_rfkill
, 3, status
);
675 static DECLARE_DELAYED_WORK(dell_rfkill_work
, dell_update_rfkill
);
677 static bool dell_laptop_i8042_filter(unsigned char data
, unsigned char str
,
680 static bool extended
;
682 if (str
& I8042_STR_AUXDATA
)
685 if (unlikely(data
== 0xe0)) {
688 } else if (unlikely(extended
)) {
691 schedule_delayed_work(&dell_rfkill_work
,
692 round_jiffies_relative(HZ
/ 4));
701 static int (*dell_rbtn_notifier_register_func
)(struct notifier_block
*);
702 static int (*dell_rbtn_notifier_unregister_func
)(struct notifier_block
*);
704 static int dell_laptop_rbtn_notifier_call(struct notifier_block
*nb
,
705 unsigned long action
, void *data
)
707 schedule_delayed_work(&dell_rfkill_work
, 0);
711 static struct notifier_block dell_laptop_rbtn_notifier
= {
712 .notifier_call
= dell_laptop_rbtn_notifier_call
,
715 static int __init
dell_setup_rfkill(void)
717 struct calling_interface_buffer buffer
;
718 int status
, ret
, whitelisted
;
722 * rfkill support causes trouble on various models, mostly Inspirons.
723 * So we whitelist certain series, and don't support rfkill on others.
726 product
= dmi_get_system_info(DMI_PRODUCT_NAME
);
727 if (product
&& (strncmp(product
, "Latitude", 8) == 0 ||
728 strncmp(product
, "Precision", 9) == 0))
730 if (!force_rfkill
&& !whitelisted
)
733 dell_fill_request(&buffer
, 0, 0, 0, 0);
734 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
735 status
= buffer
.output
[1];
737 /* dell wireless info smbios call is not supported */
741 /* rfkill is only tested on laptops with a hwswitch */
742 if (!(status
& BIT(0)) && !force_rfkill
)
745 if ((status
& (1<<2|1<<8)) == (1<<2|1<<8)) {
746 wifi_rfkill
= rfkill_alloc("dell-wifi", &platform_device
->dev
,
748 &dell_rfkill_ops
, (void *) 1);
753 ret
= rfkill_register(wifi_rfkill
);
758 if ((status
& (1<<3|1<<9)) == (1<<3|1<<9)) {
759 bluetooth_rfkill
= rfkill_alloc("dell-bluetooth",
760 &platform_device
->dev
,
761 RFKILL_TYPE_BLUETOOTH
,
762 &dell_rfkill_ops
, (void *) 2);
763 if (!bluetooth_rfkill
) {
767 ret
= rfkill_register(bluetooth_rfkill
);
772 if ((status
& (1<<4|1<<10)) == (1<<4|1<<10)) {
773 wwan_rfkill
= rfkill_alloc("dell-wwan",
774 &platform_device
->dev
,
776 &dell_rfkill_ops
, (void *) 3);
781 ret
= rfkill_register(wwan_rfkill
);
787 * Dell Airplane Mode Switch driver (dell-rbtn) supports ACPI devices
788 * which can receive events from HW slider switch.
790 * Dell SMBIOS on whitelisted models supports controlling radio devices
791 * but does not support receiving HW button switch events. We can use
792 * i8042 filter hook function to receive keyboard data and handle
793 * keycode for HW button.
795 * So if it is possible we will use Dell Airplane Mode Switch ACPI
796 * driver for receiving HW events and Dell SMBIOS for setting rfkill
797 * states. If ACPI driver or device is not available we will fallback to
798 * i8042 filter hook function.
800 * To prevent duplicate rfkill devices which control and do same thing,
801 * dell-rbtn driver will automatically remove its own rfkill devices
802 * once function dell_rbtn_notifier_register() is called.
805 dell_rbtn_notifier_register_func
=
806 symbol_request(dell_rbtn_notifier_register
);
807 if (dell_rbtn_notifier_register_func
) {
808 dell_rbtn_notifier_unregister_func
=
809 symbol_request(dell_rbtn_notifier_unregister
);
810 if (!dell_rbtn_notifier_unregister_func
) {
811 symbol_put(dell_rbtn_notifier_register
);
812 dell_rbtn_notifier_register_func
= NULL
;
816 if (dell_rbtn_notifier_register_func
) {
817 ret
= dell_rbtn_notifier_register_func(
818 &dell_laptop_rbtn_notifier
);
819 symbol_put(dell_rbtn_notifier_register
);
820 dell_rbtn_notifier_register_func
= NULL
;
822 symbol_put(dell_rbtn_notifier_unregister
);
823 dell_rbtn_notifier_unregister_func
= NULL
;
826 pr_info("Symbols from dell-rbtn acpi driver are not available\n");
831 pr_info("Using dell-rbtn acpi driver for receiving events\n");
832 } else if (ret
!= -ENODEV
) {
833 pr_warn("Unable to register dell rbtn notifier\n");
836 ret
= i8042_install_filter(dell_laptop_i8042_filter
);
838 pr_warn("Unable to install key filter\n");
841 pr_info("Using i8042 filter function for receiving events\n");
847 rfkill_unregister(wwan_rfkill
);
849 rfkill_destroy(wwan_rfkill
);
850 if (bluetooth_rfkill
)
851 rfkill_unregister(bluetooth_rfkill
);
853 rfkill_destroy(bluetooth_rfkill
);
855 rfkill_unregister(wifi_rfkill
);
857 rfkill_destroy(wifi_rfkill
);
862 static void dell_cleanup_rfkill(void)
864 if (dell_rbtn_notifier_unregister_func
) {
865 dell_rbtn_notifier_unregister_func(&dell_laptop_rbtn_notifier
);
866 symbol_put(dell_rbtn_notifier_unregister
);
867 dell_rbtn_notifier_unregister_func
= NULL
;
869 i8042_remove_filter(dell_laptop_i8042_filter
);
871 cancel_delayed_work_sync(&dell_rfkill_work
);
873 rfkill_unregister(wifi_rfkill
);
874 rfkill_destroy(wifi_rfkill
);
876 if (bluetooth_rfkill
) {
877 rfkill_unregister(bluetooth_rfkill
);
878 rfkill_destroy(bluetooth_rfkill
);
881 rfkill_unregister(wwan_rfkill
);
882 rfkill_destroy(wwan_rfkill
);
886 static int dell_send_intensity(struct backlight_device
*bd
)
888 struct calling_interface_buffer buffer
;
889 struct calling_interface_token
*token
;
892 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
896 dell_fill_request(&buffer
,
897 token
->location
, bd
->props
.brightness
, 0, 0);
898 if (power_supply_is_system_supplied() > 0)
899 ret
= dell_send_request(&buffer
,
900 CLASS_TOKEN_WRITE
, SELECT_TOKEN_AC
);
902 ret
= dell_send_request(&buffer
,
903 CLASS_TOKEN_WRITE
, SELECT_TOKEN_BAT
);
908 static int dell_get_intensity(struct backlight_device
*bd
)
910 struct calling_interface_buffer buffer
;
911 struct calling_interface_token
*token
;
914 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
918 dell_fill_request(&buffer
, token
->location
, 0, 0, 0);
919 if (power_supply_is_system_supplied() > 0)
920 ret
= dell_send_request(&buffer
,
921 CLASS_TOKEN_READ
, SELECT_TOKEN_AC
);
923 ret
= dell_send_request(&buffer
,
924 CLASS_TOKEN_READ
, SELECT_TOKEN_BAT
);
927 ret
= buffer
.output
[1];
932 static const struct backlight_ops dell_ops
= {
933 .get_brightness
= dell_get_intensity
,
934 .update_status
= dell_send_intensity
,
937 static void touchpad_led_on(void)
941 i8042_command(&data
, command
| 1 << 12);
944 static void touchpad_led_off(void)
948 i8042_command(&data
, command
| 1 << 12);
951 static void touchpad_led_set(struct led_classdev
*led_cdev
,
952 enum led_brightness value
)
960 static struct led_classdev touchpad_led
= {
961 .name
= "dell-laptop::touchpad",
962 .brightness_set
= touchpad_led_set
,
963 .flags
= LED_CORE_SUSPENDRESUME
,
966 static int __init
touchpad_led_init(struct device
*dev
)
968 return led_classdev_register(dev
, &touchpad_led
);
971 static void touchpad_led_exit(void)
973 led_classdev_unregister(&touchpad_led
);
977 * Derived from information in smbios-keyboard-ctl:
981 * Keyboard illumination
982 * cbArg1 determines the function to be performed
984 * cbArg1 0x0 = Get Feature Information
985 * cbRES1 Standard return codes (0, -1, -2)
986 * cbRES2, word0 Bitmap of user-selectable modes
987 * bit 0 Always off (All systems)
988 * bit 1 Always on (Travis ATG, Siberia)
989 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
990 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
991 * bit 4 Auto: Input-activity-based On; input-activity based Off
992 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
993 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
994 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
995 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
996 * bits 9-15 Reserved for future use
997 * cbRES2, byte2 Reserved for future use
998 * cbRES2, byte3 Keyboard illumination type
1002 * 3-255 Reserved for future use
1003 * cbRES3, byte0 Supported auto keyboard illumination trigger bitmap.
1004 * bit 0 Any keystroke
1005 * bit 1 Touchpad activity
1006 * bit 2 Pointing stick
1008 * bits 4-7 Reserved for future use
1009 * cbRES3, byte1 Supported timeout unit bitmap
1014 * bits 4-7 Reserved for future use
1015 * cbRES3, byte2 Number of keyboard light brightness levels
1016 * cbRES4, byte0 Maximum acceptable seconds value (0 if seconds not supported).
1017 * cbRES4, byte1 Maximum acceptable minutes value (0 if minutes not supported).
1018 * cbRES4, byte2 Maximum acceptable hours value (0 if hours not supported).
1019 * cbRES4, byte3 Maximum acceptable days value (0 if days not supported)
1021 * cbArg1 0x1 = Get Current State
1022 * cbRES1 Standard return codes (0, -1, -2)
1023 * cbRES2, word0 Bitmap of current mode state
1024 * bit 0 Always off (All systems)
1025 * bit 1 Always on (Travis ATG, Siberia)
1026 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
1027 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
1028 * bit 4 Auto: Input-activity-based On; input-activity based Off
1029 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
1030 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
1031 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
1032 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
1033 * bits 9-15 Reserved for future use
1034 * Note: Only One bit can be set
1035 * cbRES2, byte2 Currently active auto keyboard illumination triggers.
1036 * bit 0 Any keystroke
1037 * bit 1 Touchpad activity
1038 * bit 2 Pointing stick
1040 * bits 4-7 Reserved for future use
1041 * cbRES2, byte3 Current Timeout on battery
1042 * bits 7:6 Timeout units indicator:
1047 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1048 * NOTE: A value of 0 means always on (no timeout) if any bits of RES3 byte
1049 * are set upon return from the [Get feature information] call.
1050 * cbRES3, byte0 Current setting of ALS value that turns the light on or off.
1051 * cbRES3, byte1 Current ALS reading
1052 * cbRES3, byte2 Current keyboard light level.
1053 * cbRES3, byte3 Current timeout on AC Power
1054 * bits 7:6 Timeout units indicator:
1059 * Bits 5:0 Timeout value (0-63) in sec/min/hr/day
1060 * NOTE: A value of 0 means always on (no timeout) if any bits of RES3 byte2
1061 * are set upon return from the upon return from the [Get Feature information] call.
1063 * cbArg1 0x2 = Set New State
1064 * cbRES1 Standard return codes (0, -1, -2)
1065 * cbArg2, word0 Bitmap of current mode state
1066 * bit 0 Always off (All systems)
1067 * bit 1 Always on (Travis ATG, Siberia)
1068 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
1069 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
1070 * bit 4 Auto: Input-activity-based On; input-activity based Off
1071 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
1072 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
1073 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
1074 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
1075 * bits 9-15 Reserved for future use
1076 * Note: Only One bit can be set
1077 * cbArg2, byte2 Desired auto keyboard illumination triggers. Must remain inactive to allow
1078 * keyboard to turn off automatically.
1079 * bit 0 Any keystroke
1080 * bit 1 Touchpad activity
1081 * bit 2 Pointing stick
1083 * bits 4-7 Reserved for future use
1084 * cbArg2, byte3 Desired Timeout on battery
1085 * bits 7:6 Timeout units indicator:
1090 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1091 * cbArg3, byte0 Desired setting of ALS value that turns the light on or off.
1092 * cbArg3, byte2 Desired keyboard light level.
1093 * cbArg3, byte3 Desired Timeout on AC power
1094 * bits 7:6 Timeout units indicator:
1099 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1103 enum kbd_timeout_unit
{
1104 KBD_TIMEOUT_SECONDS
= 0,
1105 KBD_TIMEOUT_MINUTES
,
1111 KBD_MODE_BIT_OFF
= 0,
1114 KBD_MODE_BIT_TRIGGER_ALS
,
1115 KBD_MODE_BIT_TRIGGER
,
1116 KBD_MODE_BIT_TRIGGER_25
,
1117 KBD_MODE_BIT_TRIGGER_50
,
1118 KBD_MODE_BIT_TRIGGER_75
,
1119 KBD_MODE_BIT_TRIGGER_100
,
1122 #define kbd_is_als_mode_bit(bit) \
1123 ((bit) == KBD_MODE_BIT_ALS || (bit) == KBD_MODE_BIT_TRIGGER_ALS)
1124 #define kbd_is_trigger_mode_bit(bit) \
1125 ((bit) >= KBD_MODE_BIT_TRIGGER_ALS && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1126 #define kbd_is_level_mode_bit(bit) \
1127 ((bit) >= KBD_MODE_BIT_TRIGGER_25 && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1145 u8 timeout_value_ac
;
1152 static const int kbd_tokens
[] = {
1154 KBD_LED_AUTO_25_TOKEN
,
1155 KBD_LED_AUTO_50_TOKEN
,
1156 KBD_LED_AUTO_75_TOKEN
,
1157 KBD_LED_AUTO_100_TOKEN
,
1161 static u16 kbd_token_bits
;
1163 static struct kbd_info kbd_info
;
1164 static bool kbd_als_supported
;
1165 static bool kbd_triggers_supported
;
1166 static bool kbd_timeout_ac_supported
;
1168 static u8 kbd_mode_levels
[16];
1169 static int kbd_mode_levels_count
;
1171 static u8 kbd_previous_level
;
1172 static u8 kbd_previous_mode_bit
;
1174 static bool kbd_led_present
;
1175 static DEFINE_MUTEX(kbd_led_mutex
);
1176 static enum led_brightness kbd_led_level
;
1179 * NOTE: there are three ways to set the keyboard backlight level.
1180 * First, via kbd_state.mode_bit (assigning KBD_MODE_BIT_TRIGGER_* value).
1181 * Second, via kbd_state.level (assigning numerical value <= kbd_info.levels).
1182 * Third, via SMBIOS tokens (KBD_LED_* in kbd_tokens)
1184 * There are laptops which support only one of these methods. If we want to
1185 * support as many machines as possible we need to implement all three methods.
1186 * The first two methods use the kbd_state structure. The third uses SMBIOS
1187 * tokens. If kbd_info.levels == 0, the machine does not support setting the
1188 * keyboard backlight level via kbd_state.level.
1191 static int kbd_get_info(struct kbd_info
*info
)
1193 struct calling_interface_buffer buffer
;
1197 dell_fill_request(&buffer
, 0, 0, 0, 0);
1198 ret
= dell_send_request(&buffer
,
1199 CLASS_KBD_BACKLIGHT
, SELECT_KBD_BACKLIGHT
);
1203 info
->modes
= buffer
.output
[1] & 0xFFFF;
1204 info
->type
= (buffer
.output
[1] >> 24) & 0xFF;
1205 info
->triggers
= buffer
.output
[2] & 0xFF;
1206 units
= (buffer
.output
[2] >> 8) & 0xFF;
1207 info
->levels
= (buffer
.output
[2] >> 16) & 0xFF;
1209 if (quirks
&& quirks
->kbd_led_levels_off_1
&& info
->levels
)
1213 info
->seconds
= (buffer
.output
[3] >> 0) & 0xFF;
1215 info
->minutes
= (buffer
.output
[3] >> 8) & 0xFF;
1217 info
->hours
= (buffer
.output
[3] >> 16) & 0xFF;
1219 info
->days
= (buffer
.output
[3] >> 24) & 0xFF;
1224 static unsigned int kbd_get_max_level(void)
1226 if (kbd_info
.levels
!= 0)
1227 return kbd_info
.levels
;
1228 if (kbd_mode_levels_count
> 0)
1229 return kbd_mode_levels_count
- 1;
1233 static int kbd_get_level(struct kbd_state
*state
)
1237 if (kbd_info
.levels
!= 0)
1238 return state
->level
;
1240 if (kbd_mode_levels_count
> 0) {
1241 for (i
= 0; i
< kbd_mode_levels_count
; ++i
)
1242 if (kbd_mode_levels
[i
] == state
->mode_bit
)
1250 static int kbd_set_level(struct kbd_state
*state
, u8 level
)
1252 if (kbd_info
.levels
!= 0) {
1254 kbd_previous_level
= level
;
1255 if (state
->level
== level
)
1257 state
->level
= level
;
1258 if (level
!= 0 && state
->mode_bit
== KBD_MODE_BIT_OFF
)
1259 state
->mode_bit
= kbd_previous_mode_bit
;
1260 else if (level
== 0 && state
->mode_bit
!= KBD_MODE_BIT_OFF
) {
1261 kbd_previous_mode_bit
= state
->mode_bit
;
1262 state
->mode_bit
= KBD_MODE_BIT_OFF
;
1267 if (kbd_mode_levels_count
> 0 && level
< kbd_mode_levels_count
) {
1269 kbd_previous_level
= level
;
1270 state
->mode_bit
= kbd_mode_levels
[level
];
1277 static int kbd_get_state(struct kbd_state
*state
)
1279 struct calling_interface_buffer buffer
;
1282 dell_fill_request(&buffer
, 0, 0, 0, 0);
1283 ret
= dell_send_request(&buffer
,
1284 CLASS_KBD_BACKLIGHT
, SELECT_KBD_BACKLIGHT
);
1288 state
->mode_bit
= ffs(buffer
.output
[1] & 0xFFFF);
1289 if (state
->mode_bit
!= 0)
1292 state
->triggers
= (buffer
.output
[1] >> 16) & 0xFF;
1293 state
->timeout_value
= (buffer
.output
[1] >> 24) & 0x3F;
1294 state
->timeout_unit
= (buffer
.output
[1] >> 30) & 0x3;
1295 state
->als_setting
= buffer
.output
[2] & 0xFF;
1296 state
->als_value
= (buffer
.output
[2] >> 8) & 0xFF;
1297 state
->level
= (buffer
.output
[2] >> 16) & 0xFF;
1298 state
->timeout_value_ac
= (buffer
.output
[2] >> 24) & 0x3F;
1299 state
->timeout_unit_ac
= (buffer
.output
[2] >> 30) & 0x3;
1304 static int kbd_set_state(struct kbd_state
*state
)
1306 struct calling_interface_buffer buffer
;
1311 input1
= BIT(state
->mode_bit
) & 0xFFFF;
1312 input1
|= (state
->triggers
& 0xFF) << 16;
1313 input1
|= (state
->timeout_value
& 0x3F) << 24;
1314 input1
|= (state
->timeout_unit
& 0x3) << 30;
1315 input2
= state
->als_setting
& 0xFF;
1316 input2
|= (state
->level
& 0xFF) << 16;
1317 input2
|= (state
->timeout_value_ac
& 0x3F) << 24;
1318 input2
|= (state
->timeout_unit_ac
& 0x3) << 30;
1319 dell_fill_request(&buffer
, 0x2, input1
, input2
, 0);
1320 ret
= dell_send_request(&buffer
,
1321 CLASS_KBD_BACKLIGHT
, SELECT_KBD_BACKLIGHT
);
1326 static int kbd_set_state_safe(struct kbd_state
*state
, struct kbd_state
*old
)
1330 ret
= kbd_set_state(state
);
1335 * When setting the new state fails,try to restore the previous one.
1336 * This is needed on some machines where BIOS sets a default state when
1337 * setting a new state fails. This default state could be all off.
1340 if (kbd_set_state(old
))
1341 pr_err("Setting old previous keyboard state failed\n");
1346 static int kbd_set_token_bit(u8 bit
)
1348 struct calling_interface_buffer buffer
;
1349 struct calling_interface_token
*token
;
1352 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1355 token
= dell_smbios_find_token(kbd_tokens
[bit
]);
1359 dell_fill_request(&buffer
, token
->location
, token
->value
, 0, 0);
1360 ret
= dell_send_request(&buffer
, CLASS_TOKEN_WRITE
, SELECT_TOKEN_STD
);
1365 static int kbd_get_token_bit(u8 bit
)
1367 struct calling_interface_buffer buffer
;
1368 struct calling_interface_token
*token
;
1372 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1375 token
= dell_smbios_find_token(kbd_tokens
[bit
]);
1379 dell_fill_request(&buffer
, token
->location
, 0, 0, 0);
1380 ret
= dell_send_request(&buffer
, CLASS_TOKEN_READ
, SELECT_TOKEN_STD
);
1381 val
= buffer
.output
[1];
1386 return (val
== token
->value
);
1389 static int kbd_get_first_active_token_bit(void)
1394 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
) {
1395 ret
= kbd_get_token_bit(i
);
1403 static int kbd_get_valid_token_counts(void)
1405 return hweight16(kbd_token_bits
);
1408 static inline int kbd_init_info(void)
1410 struct kbd_state state
;
1414 ret
= kbd_get_info(&kbd_info
);
1418 /* NOTE: Old models without KBD_LED_AC_TOKEN token supports only one
1419 * timeout value which is shared for both battery and AC power
1420 * settings. So do not try to set AC values on old models.
1422 if (dell_smbios_find_token(KBD_LED_AC_TOKEN
))
1423 kbd_timeout_ac_supported
= true;
1425 kbd_get_state(&state
);
1427 /* NOTE: timeout value is stored in 6 bits so max value is 63 */
1428 if (kbd_info
.seconds
> 63)
1429 kbd_info
.seconds
= 63;
1430 if (kbd_info
.minutes
> 63)
1431 kbd_info
.minutes
= 63;
1432 if (kbd_info
.hours
> 63)
1433 kbd_info
.hours
= 63;
1434 if (kbd_info
.days
> 63)
1437 /* NOTE: On tested machines ON mode did not work and caused
1438 * problems (turned backlight off) so do not use it
1440 kbd_info
.modes
&= ~BIT(KBD_MODE_BIT_ON
);
1442 kbd_previous_level
= kbd_get_level(&state
);
1443 kbd_previous_mode_bit
= state
.mode_bit
;
1445 if (kbd_previous_level
== 0 && kbd_get_max_level() != 0)
1446 kbd_previous_level
= 1;
1448 if (kbd_previous_mode_bit
== KBD_MODE_BIT_OFF
) {
1449 kbd_previous_mode_bit
=
1450 ffs(kbd_info
.modes
& ~BIT(KBD_MODE_BIT_OFF
));
1451 if (kbd_previous_mode_bit
!= 0)
1452 kbd_previous_mode_bit
--;
1455 if (kbd_info
.modes
& (BIT(KBD_MODE_BIT_ALS
) |
1456 BIT(KBD_MODE_BIT_TRIGGER_ALS
)))
1457 kbd_als_supported
= true;
1459 if (kbd_info
.modes
& (
1460 BIT(KBD_MODE_BIT_TRIGGER_ALS
) | BIT(KBD_MODE_BIT_TRIGGER
) |
1461 BIT(KBD_MODE_BIT_TRIGGER_25
) | BIT(KBD_MODE_BIT_TRIGGER_50
) |
1462 BIT(KBD_MODE_BIT_TRIGGER_75
) | BIT(KBD_MODE_BIT_TRIGGER_100
)
1464 kbd_triggers_supported
= true;
1466 /* kbd_mode_levels[0] is reserved, see below */
1467 for (i
= 0; i
< 16; ++i
)
1468 if (kbd_is_level_mode_bit(i
) && (BIT(i
) & kbd_info
.modes
))
1469 kbd_mode_levels
[1 + kbd_mode_levels_count
++] = i
;
1472 * Find the first supported mode and assign to kbd_mode_levels[0].
1473 * This should be 0 (off), but we cannot depend on the BIOS to
1476 if (kbd_mode_levels_count
> 0) {
1477 for (i
= 0; i
< 16; ++i
) {
1478 if (BIT(i
) & kbd_info
.modes
) {
1479 kbd_mode_levels
[0] = i
;
1483 kbd_mode_levels_count
++;
1490 static inline void kbd_init_tokens(void)
1494 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
)
1495 if (dell_smbios_find_token(kbd_tokens
[i
]))
1496 kbd_token_bits
|= BIT(i
);
1499 static void kbd_init(void)
1503 ret
= kbd_init_info();
1507 * Only supports keyboard backlight when it has at least two modes.
1509 if ((ret
== 0 && (kbd_info
.levels
!= 0 || kbd_mode_levels_count
>= 2))
1510 || kbd_get_valid_token_counts() >= 2)
1511 kbd_led_present
= true;
1514 static ssize_t
kbd_led_timeout_store(struct device
*dev
,
1515 struct device_attribute
*attr
,
1516 const char *buf
, size_t count
)
1518 struct kbd_state new_state
;
1519 struct kbd_state state
;
1527 ret
= sscanf(buf
, "%d %c", &value
, &ch
);
1540 if (value
> kbd_info
.seconds
)
1542 unit
= KBD_TIMEOUT_SECONDS
;
1545 if (value
> kbd_info
.minutes
)
1547 unit
= KBD_TIMEOUT_MINUTES
;
1550 if (value
> kbd_info
.hours
)
1552 unit
= KBD_TIMEOUT_HOURS
;
1555 if (value
> kbd_info
.days
)
1557 unit
= KBD_TIMEOUT_DAYS
;
1563 if (quirks
&& quirks
->needs_kbd_timeouts
)
1567 /* Convert value from current units to seconds */
1569 case KBD_TIMEOUT_DAYS
:
1571 case KBD_TIMEOUT_HOURS
:
1573 case KBD_TIMEOUT_MINUTES
:
1575 unit
= KBD_TIMEOUT_SECONDS
;
1578 if (quirks
&& quirks
->needs_kbd_timeouts
) {
1579 for (i
= 0; quirks
->kbd_timeouts
[i
] != -1; i
++) {
1580 if (value
<= quirks
->kbd_timeouts
[i
]) {
1581 value
= quirks
->kbd_timeouts
[i
];
1587 if (value
<= kbd_info
.seconds
&& kbd_info
.seconds
) {
1588 unit
= KBD_TIMEOUT_SECONDS
;
1589 } else if (value
/ 60 <= kbd_info
.minutes
&& kbd_info
.minutes
) {
1591 unit
= KBD_TIMEOUT_MINUTES
;
1592 } else if (value
/ (60 * 60) <= kbd_info
.hours
&& kbd_info
.hours
) {
1594 unit
= KBD_TIMEOUT_HOURS
;
1595 } else if (value
/ (60 * 60 * 24) <= kbd_info
.days
&& kbd_info
.days
) {
1596 value
/= (60 * 60 * 24);
1597 unit
= KBD_TIMEOUT_DAYS
;
1603 mutex_lock(&kbd_led_mutex
);
1605 ret
= kbd_get_state(&state
);
1611 if (kbd_timeout_ac_supported
&& power_supply_is_system_supplied() > 0) {
1612 new_state
.timeout_value_ac
= value
;
1613 new_state
.timeout_unit_ac
= unit
;
1615 new_state
.timeout_value
= value
;
1616 new_state
.timeout_unit
= unit
;
1619 ret
= kbd_set_state_safe(&new_state
, &state
);
1625 mutex_unlock(&kbd_led_mutex
);
1629 static ssize_t
kbd_led_timeout_show(struct device
*dev
,
1630 struct device_attribute
*attr
, char *buf
)
1632 struct kbd_state state
;
1638 ret
= kbd_get_state(&state
);
1642 if (kbd_timeout_ac_supported
&& power_supply_is_system_supplied() > 0) {
1643 value
= state
.timeout_value_ac
;
1644 unit
= state
.timeout_unit_ac
;
1646 value
= state
.timeout_value
;
1647 unit
= state
.timeout_unit
;
1650 len
= sprintf(buf
, "%d", value
);
1653 case KBD_TIMEOUT_SECONDS
:
1654 return len
+ sprintf(buf
+len
, "s\n");
1655 case KBD_TIMEOUT_MINUTES
:
1656 return len
+ sprintf(buf
+len
, "m\n");
1657 case KBD_TIMEOUT_HOURS
:
1658 return len
+ sprintf(buf
+len
, "h\n");
1659 case KBD_TIMEOUT_DAYS
:
1660 return len
+ sprintf(buf
+len
, "d\n");
1668 static DEVICE_ATTR(stop_timeout
, S_IRUGO
| S_IWUSR
,
1669 kbd_led_timeout_show
, kbd_led_timeout_store
);
1671 static const char * const kbd_led_triggers
[] = {
1674 /*"trackstick"*/ NULL
, /* NOTE: trackstick is just alias for touchpad */
1678 static ssize_t
kbd_led_triggers_store(struct device
*dev
,
1679 struct device_attribute
*attr
,
1680 const char *buf
, size_t count
)
1682 struct kbd_state new_state
;
1683 struct kbd_state state
;
1684 bool triggers_enabled
= false;
1685 int trigger_bit
= -1;
1689 ret
= sscanf(buf
, "%20s", trigger
);
1693 if (trigger
[0] != '+' && trigger
[0] != '-')
1696 mutex_lock(&kbd_led_mutex
);
1698 ret
= kbd_get_state(&state
);
1702 if (kbd_triggers_supported
)
1703 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1705 if (kbd_triggers_supported
) {
1706 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1707 if (!(kbd_info
.triggers
& BIT(i
)))
1709 if (!kbd_led_triggers
[i
])
1711 if (strcmp(trigger
+1, kbd_led_triggers
[i
]) != 0)
1713 if (trigger
[0] == '+' &&
1714 triggers_enabled
&& (state
.triggers
& BIT(i
))) {
1718 if (trigger
[0] == '-' &&
1719 (!triggers_enabled
|| !(state
.triggers
& BIT(i
)))) {
1728 if (trigger_bit
== -1) {
1734 if (trigger
[0] == '+')
1735 new_state
.triggers
|= BIT(trigger_bit
);
1737 new_state
.triggers
&= ~BIT(trigger_bit
);
1739 * NOTE: trackstick bit (2) must be disabled when
1740 * disabling touchpad bit (1), otherwise touchpad
1741 * bit (1) will not be disabled
1743 if (trigger_bit
== 1)
1744 new_state
.triggers
&= ~BIT(2);
1746 if ((kbd_info
.triggers
& new_state
.triggers
) !=
1747 new_state
.triggers
) {
1751 if (new_state
.triggers
&& !triggers_enabled
) {
1752 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1753 kbd_set_level(&new_state
, kbd_previous_level
);
1754 } else if (new_state
.triggers
== 0) {
1755 kbd_set_level(&new_state
, 0);
1757 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
))) {
1761 ret
= kbd_set_state_safe(&new_state
, &state
);
1764 if (new_state
.mode_bit
!= KBD_MODE_BIT_OFF
)
1765 kbd_previous_mode_bit
= new_state
.mode_bit
;
1768 mutex_unlock(&kbd_led_mutex
);
1772 static ssize_t
kbd_led_triggers_show(struct device
*dev
,
1773 struct device_attribute
*attr
, char *buf
)
1775 struct kbd_state state
;
1776 bool triggers_enabled
;
1780 ret
= kbd_get_state(&state
);
1786 if (kbd_triggers_supported
) {
1787 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1788 level
= kbd_get_level(&state
);
1789 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1790 if (!(kbd_info
.triggers
& BIT(i
)))
1792 if (!kbd_led_triggers
[i
])
1794 if ((triggers_enabled
|| level
<= 0) &&
1795 (state
.triggers
& BIT(i
)))
1799 len
+= sprintf(buf
+len
, "%s ", kbd_led_triggers
[i
]);
1804 buf
[len
- 1] = '\n';
1809 static DEVICE_ATTR(start_triggers
, S_IRUGO
| S_IWUSR
,
1810 kbd_led_triggers_show
, kbd_led_triggers_store
);
1812 static ssize_t
kbd_led_als_enabled_store(struct device
*dev
,
1813 struct device_attribute
*attr
,
1814 const char *buf
, size_t count
)
1816 struct kbd_state new_state
;
1817 struct kbd_state state
;
1818 bool triggers_enabled
= false;
1822 ret
= kstrtoint(buf
, 0, &enable
);
1826 mutex_lock(&kbd_led_mutex
);
1828 ret
= kbd_get_state(&state
);
1832 if (enable
== kbd_is_als_mode_bit(state
.mode_bit
)) {
1839 if (kbd_triggers_supported
)
1840 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1843 if (triggers_enabled
)
1844 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER_ALS
;
1846 new_state
.mode_bit
= KBD_MODE_BIT_ALS
;
1848 if (triggers_enabled
) {
1849 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1850 kbd_set_level(&new_state
, kbd_previous_level
);
1852 new_state
.mode_bit
= KBD_MODE_BIT_ON
;
1855 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
))) {
1860 ret
= kbd_set_state_safe(&new_state
, &state
);
1863 kbd_previous_mode_bit
= new_state
.mode_bit
;
1867 mutex_unlock(&kbd_led_mutex
);
1871 static ssize_t
kbd_led_als_enabled_show(struct device
*dev
,
1872 struct device_attribute
*attr
,
1875 struct kbd_state state
;
1876 bool enabled
= false;
1879 ret
= kbd_get_state(&state
);
1882 enabled
= kbd_is_als_mode_bit(state
.mode_bit
);
1884 return sprintf(buf
, "%d\n", enabled
? 1 : 0);
1887 static DEVICE_ATTR(als_enabled
, S_IRUGO
| S_IWUSR
,
1888 kbd_led_als_enabled_show
, kbd_led_als_enabled_store
);
1890 static ssize_t
kbd_led_als_setting_store(struct device
*dev
,
1891 struct device_attribute
*attr
,
1892 const char *buf
, size_t count
)
1894 struct kbd_state state
;
1895 struct kbd_state new_state
;
1899 ret
= kstrtou8(buf
, 10, &setting
);
1903 mutex_lock(&kbd_led_mutex
);
1905 ret
= kbd_get_state(&state
);
1910 new_state
.als_setting
= setting
;
1912 ret
= kbd_set_state_safe(&new_state
, &state
);
1918 mutex_unlock(&kbd_led_mutex
);
1922 static ssize_t
kbd_led_als_setting_show(struct device
*dev
,
1923 struct device_attribute
*attr
,
1926 struct kbd_state state
;
1929 ret
= kbd_get_state(&state
);
1933 return sprintf(buf
, "%d\n", state
.als_setting
);
1936 static DEVICE_ATTR(als_setting
, S_IRUGO
| S_IWUSR
,
1937 kbd_led_als_setting_show
, kbd_led_als_setting_store
);
1939 static struct attribute
*kbd_led_attrs
[] = {
1940 &dev_attr_stop_timeout
.attr
,
1941 &dev_attr_start_triggers
.attr
,
1945 static const struct attribute_group kbd_led_group
= {
1946 .attrs
= kbd_led_attrs
,
1949 static struct attribute
*kbd_led_als_attrs
[] = {
1950 &dev_attr_als_enabled
.attr
,
1951 &dev_attr_als_setting
.attr
,
1955 static const struct attribute_group kbd_led_als_group
= {
1956 .attrs
= kbd_led_als_attrs
,
1959 static const struct attribute_group
*kbd_led_groups
[] = {
1965 static enum led_brightness
kbd_led_level_get(struct led_classdev
*led_cdev
)
1969 struct kbd_state state
;
1971 if (kbd_get_max_level()) {
1972 ret
= kbd_get_state(&state
);
1975 ret
= kbd_get_level(&state
);
1981 if (kbd_get_valid_token_counts()) {
1982 ret
= kbd_get_first_active_token_bit();
1985 for (num
= kbd_token_bits
; num
!= 0 && ret
> 0; --ret
)
1986 num
&= num
- 1; /* clear the first bit set */
1989 return ffs(num
) - 1;
1992 pr_warn("Keyboard brightness level control not supported\n");
1996 static int kbd_led_level_set(struct led_classdev
*led_cdev
,
1997 enum led_brightness value
)
1999 enum led_brightness new_value
= value
;
2000 struct kbd_state state
;
2001 struct kbd_state new_state
;
2005 mutex_lock(&kbd_led_mutex
);
2007 if (kbd_get_max_level()) {
2008 ret
= kbd_get_state(&state
);
2012 ret
= kbd_set_level(&new_state
, value
);
2015 ret
= kbd_set_state_safe(&new_state
, &state
);
2016 } else if (kbd_get_valid_token_counts()) {
2017 for (num
= kbd_token_bits
; num
!= 0 && value
> 0; --value
)
2018 num
&= num
- 1; /* clear the first bit set */
2022 ret
= kbd_set_token_bit(ffs(num
) - 1);
2024 pr_warn("Keyboard brightness level control not supported\n");
2030 kbd_led_level
= new_value
;
2032 mutex_unlock(&kbd_led_mutex
);
2036 static struct led_classdev kbd_led
= {
2037 .name
= "dell::kbd_backlight",
2038 .flags
= LED_BRIGHT_HW_CHANGED
,
2039 .brightness_set_blocking
= kbd_led_level_set
,
2040 .brightness_get
= kbd_led_level_get
,
2041 .groups
= kbd_led_groups
,
2044 static int __init
kbd_led_init(struct device
*dev
)
2049 if (!kbd_led_present
)
2051 if (!kbd_als_supported
)
2052 kbd_led_groups
[1] = NULL
;
2053 kbd_led
.max_brightness
= kbd_get_max_level();
2054 if (!kbd_led
.max_brightness
) {
2055 kbd_led
.max_brightness
= kbd_get_valid_token_counts();
2056 if (kbd_led
.max_brightness
)
2057 kbd_led
.max_brightness
--;
2060 kbd_led_level
= kbd_led_level_get(NULL
);
2062 ret
= led_classdev_register(dev
, &kbd_led
);
2064 kbd_led_present
= false;
2069 static void brightness_set_exit(struct led_classdev
*led_cdev
,
2070 enum led_brightness value
)
2072 /* Don't change backlight level on exit */
2075 static void kbd_led_exit(void)
2077 if (!kbd_led_present
)
2079 kbd_led
.brightness_set
= brightness_set_exit
;
2080 led_classdev_unregister(&kbd_led
);
2083 static int dell_laptop_notifier_call(struct notifier_block
*nb
,
2084 unsigned long action
, void *data
)
2086 bool changed
= false;
2087 enum led_brightness new_kbd_led_level
;
2090 case DELL_LAPTOP_KBD_BACKLIGHT_BRIGHTNESS_CHANGED
:
2091 if (!kbd_led_present
)
2094 mutex_lock(&kbd_led_mutex
);
2095 new_kbd_led_level
= kbd_led_level_get(&kbd_led
);
2096 if (kbd_led_level
!= new_kbd_led_level
) {
2097 kbd_led_level
= new_kbd_led_level
;
2100 mutex_unlock(&kbd_led_mutex
);
2103 led_classdev_notify_brightness_hw_changed(&kbd_led
,
2111 static struct notifier_block dell_laptop_notifier
= {
2112 .notifier_call
= dell_laptop_notifier_call
,
2115 int dell_micmute_led_set(int state
)
2117 struct calling_interface_buffer buffer
;
2118 struct calling_interface_token
*token
;
2121 token
= dell_smbios_find_token(GLOBAL_MIC_MUTE_DISABLE
);
2122 else if (state
== 1)
2123 token
= dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE
);
2130 dell_fill_request(&buffer
, token
->location
, token
->value
, 0, 0);
2131 dell_send_request(&buffer
, CLASS_TOKEN_WRITE
, SELECT_TOKEN_STD
);
2135 EXPORT_SYMBOL_GPL(dell_micmute_led_set
);
2137 static int __init
dell_init(void)
2139 struct calling_interface_token
*token
;
2140 int max_intensity
= 0;
2143 if (!dmi_check_system(dell_device_table
))
2147 /* find if this machine support other functions */
2148 dmi_check_system(dell_quirks
);
2150 ret
= platform_driver_register(&platform_driver
);
2152 goto fail_platform_driver
;
2153 platform_device
= platform_device_alloc("dell-laptop", -1);
2154 if (!platform_device
) {
2156 goto fail_platform_device1
;
2158 ret
= platform_device_add(platform_device
);
2160 goto fail_platform_device2
;
2162 ret
= dell_setup_rfkill();
2165 pr_warn("Unable to setup rfkill\n");
2169 if (quirks
&& quirks
->touchpad_led
)
2170 touchpad_led_init(&platform_device
->dev
);
2172 kbd_led_init(&platform_device
->dev
);
2174 dell_laptop_dir
= debugfs_create_dir("dell_laptop", NULL
);
2175 if (dell_laptop_dir
!= NULL
)
2176 debugfs_create_file("rfkill", 0444, dell_laptop_dir
, NULL
,
2177 &dell_debugfs_fops
);
2179 dell_laptop_register_notifier(&dell_laptop_notifier
);
2181 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2184 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
2186 struct calling_interface_buffer buffer
;
2188 dell_fill_request(&buffer
, token
->location
, 0, 0, 0);
2189 ret
= dell_send_request(&buffer
,
2190 CLASS_TOKEN_READ
, SELECT_TOKEN_AC
);
2192 max_intensity
= buffer
.output
[3];
2195 if (max_intensity
) {
2196 struct backlight_properties props
;
2197 memset(&props
, 0, sizeof(struct backlight_properties
));
2198 props
.type
= BACKLIGHT_PLATFORM
;
2199 props
.max_brightness
= max_intensity
;
2200 dell_backlight_device
= backlight_device_register("dell_backlight",
2201 &platform_device
->dev
,
2206 if (IS_ERR(dell_backlight_device
)) {
2207 ret
= PTR_ERR(dell_backlight_device
);
2208 dell_backlight_device
= NULL
;
2209 goto fail_backlight
;
2212 dell_backlight_device
->props
.brightness
=
2213 dell_get_intensity(dell_backlight_device
);
2214 if (dell_backlight_device
->props
.brightness
< 0) {
2215 ret
= dell_backlight_device
->props
.brightness
;
2216 goto fail_get_brightness
;
2218 backlight_update_status(dell_backlight_device
);
2223 fail_get_brightness
:
2224 backlight_device_unregister(dell_backlight_device
);
2226 dell_cleanup_rfkill();
2228 platform_device_del(platform_device
);
2229 fail_platform_device2
:
2230 platform_device_put(platform_device
);
2231 fail_platform_device1
:
2232 platform_driver_unregister(&platform_driver
);
2233 fail_platform_driver
:
2237 static void __exit
dell_exit(void)
2239 dell_laptop_unregister_notifier(&dell_laptop_notifier
);
2240 debugfs_remove_recursive(dell_laptop_dir
);
2241 if (quirks
&& quirks
->touchpad_led
)
2242 touchpad_led_exit();
2244 backlight_device_unregister(dell_backlight_device
);
2245 dell_cleanup_rfkill();
2246 if (platform_device
) {
2247 platform_device_unregister(platform_device
);
2248 platform_driver_unregister(&platform_driver
);
2252 /* dell-rbtn.c driver export functions which will not work correctly (and could
2253 * cause kernel crash) if they are called before dell-rbtn.c init code. This is
2254 * not problem when dell-rbtn.c is compiled as external module. When both files
2255 * (dell-rbtn.c and dell-laptop.c) are compiled statically into kernel, then we
2256 * need to ensure that dell_init() will be called after initializing dell-rbtn.
2257 * This can be achieved by late_initcall() instead module_init().
2259 late_initcall(dell_init
);
2260 module_exit(dell_exit
);
2262 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
2263 MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
2264 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
2265 MODULE_DESCRIPTION("Dell laptop driver");
2266 MODULE_LICENSE("GPL");