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*/
130 .ident
= "Dell Computer Corporation",
132 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer Corporation"),
133 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
138 MODULE_DEVICE_TABLE(dmi
, dell_device_table
);
140 static const struct dmi_system_id dell_quirks
[] __initconst
= {
142 .callback
= dmi_matched
,
143 .ident
= "Dell Vostro V130",
145 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
146 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V130"),
148 .driver_data
= &quirk_dell_vostro_v130
,
151 .callback
= dmi_matched
,
152 .ident
= "Dell Vostro V131",
154 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
155 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V131"),
157 .driver_data
= &quirk_dell_vostro_v130
,
160 .callback
= dmi_matched
,
161 .ident
= "Dell Vostro 3350",
163 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
164 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3350"),
166 .driver_data
= &quirk_dell_vostro_v130
,
169 .callback
= dmi_matched
,
170 .ident
= "Dell Vostro 3555",
172 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
173 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3555"),
175 .driver_data
= &quirk_dell_vostro_v130
,
178 .callback
= dmi_matched
,
179 .ident
= "Dell Inspiron N311z",
181 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
182 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron N311z"),
184 .driver_data
= &quirk_dell_vostro_v130
,
187 .callback
= dmi_matched
,
188 .ident
= "Dell Inspiron M5110",
190 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
191 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron M5110"),
193 .driver_data
= &quirk_dell_vostro_v130
,
196 .callback
= dmi_matched
,
197 .ident
= "Dell Vostro 3360",
199 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
200 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3360"),
202 .driver_data
= &quirk_dell_vostro_v130
,
205 .callback
= dmi_matched
,
206 .ident
= "Dell Vostro 3460",
208 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
209 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3460"),
211 .driver_data
= &quirk_dell_vostro_v130
,
214 .callback
= dmi_matched
,
215 .ident
= "Dell Vostro 3560",
217 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
218 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3560"),
220 .driver_data
= &quirk_dell_vostro_v130
,
223 .callback
= dmi_matched
,
224 .ident
= "Dell Vostro 3450",
226 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
227 DMI_MATCH(DMI_PRODUCT_NAME
, "Dell System Vostro 3450"),
229 .driver_data
= &quirk_dell_vostro_v130
,
232 .callback
= dmi_matched
,
233 .ident
= "Dell Inspiron 5420",
235 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
236 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5420"),
238 .driver_data
= &quirk_dell_vostro_v130
,
241 .callback
= dmi_matched
,
242 .ident
= "Dell Inspiron 5520",
244 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
245 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5520"),
247 .driver_data
= &quirk_dell_vostro_v130
,
250 .callback
= dmi_matched
,
251 .ident
= "Dell Inspiron 5720",
253 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
254 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5720"),
256 .driver_data
= &quirk_dell_vostro_v130
,
259 .callback
= dmi_matched
,
260 .ident
= "Dell Inspiron 7420",
262 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
263 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7420"),
265 .driver_data
= &quirk_dell_vostro_v130
,
268 .callback
= dmi_matched
,
269 .ident
= "Dell Inspiron 7520",
271 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
272 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7520"),
274 .driver_data
= &quirk_dell_vostro_v130
,
277 .callback
= dmi_matched
,
278 .ident
= "Dell Inspiron 7720",
280 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
281 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7720"),
283 .driver_data
= &quirk_dell_vostro_v130
,
286 .callback
= dmi_matched
,
287 .ident
= "Dell XPS13 9333",
289 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
290 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS13 9333"),
292 .driver_data
= &quirk_dell_xps13_9333
,
295 .callback
= dmi_matched
,
296 .ident
= "Dell Latitude E6410",
298 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
299 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude E6410"),
301 .driver_data
= &quirk_dell_latitude_e6410
,
306 static void dell_fill_request(struct calling_interface_buffer
*buffer
,
307 u32 arg0
, u32 arg1
, u32 arg2
, u32 arg3
)
309 memset(buffer
, 0, sizeof(struct calling_interface_buffer
));
310 buffer
->input
[0] = arg0
;
311 buffer
->input
[1] = arg1
;
312 buffer
->input
[2] = arg2
;
313 buffer
->input
[3] = arg3
;
316 static int dell_send_request(struct calling_interface_buffer
*buffer
,
317 u16
class, u16 select
)
321 buffer
->cmd_class
= class;
322 buffer
->cmd_select
= select
;
323 ret
= dell_smbios_call(buffer
);
326 return dell_smbios_error(buffer
->output
[0]);
330 * Derived from information in smbios-wireless-ctl:
332 * cbSelect 17, Value 11
334 * Return Wireless Info
335 * cbArg1, byte0 = 0x00
337 * cbRes1 Standard return codes (0, -1, -2)
338 * cbRes2 Info bit flags:
340 * 0 Hardware switch supported (1)
341 * 1 WiFi locator supported (1)
342 * 2 WLAN supported (1)
343 * 3 Bluetooth (BT) supported (1)
344 * 4 WWAN supported (1)
345 * 5 Wireless KBD supported (1)
346 * 6 Uw b supported (1)
347 * 7 WiGig supported (1)
348 * 8 WLAN installed (1)
350 * 10 WWAN installed (1)
351 * 11 Uw b installed (1)
352 * 12 WiGig installed (1)
354 * 16 Hardware (HW) switch is On (1)
355 * 17 WLAN disabled (1)
357 * 19 WWAN disabled (1)
358 * 20 Uw b disabled (1)
359 * 21 WiGig disabled (1)
362 * cbRes3 NVRAM size in bytes
363 * cbRes4, byte 0 NVRAM format version number
366 * Set QuickSet Radio Disable Flag
367 * cbArg1, byte0 = 0x01
376 * cbArg1, byte2 Flag bits:
377 * 0 QuickSet disables radio (1)
380 * cbRes1 Standard return codes (0, -1, -2)
381 * cbRes2 QuickSet (QS) radio disable bit map:
386 * 4 QS disables WIGIG
389 * Wireless Switch Configuration
390 * cbArg1, byte0 = 0x02
396 * 2 Set WiFi locator enable/disable
398 * Switch settings (if byte 1==1):
399 * 0 WLAN sw itch control (1)
400 * 1 BT sw itch control (1)
401 * 2 WWAN sw itch control (1)
402 * 3 UWB sw itch control (1)
403 * 4 WiGig sw itch control (1)
405 * cbArg1, byte2 Enable bits (if byte 1==2):
406 * 0 Enable WiFi locator (1)
408 * cbRes1 Standard return codes (0, -1, -2)
409 * cbRes2 QuickSet radio disable bit map:
410 * 0 WLAN controlled by sw itch (1)
411 * 1 BT controlled by sw itch (1)
412 * 2 WWAN controlled by sw itch (1)
413 * 3 UWB controlled by sw itch (1)
414 * 4 WiGig controlled by sw itch (1)
416 * 7 Wireless sw itch config locked (1)
417 * 8 WiFi locator enabled (1)
419 * 15 WiFi locator setting locked (1)
422 * Read Local Config Data (LCD)
423 * cbArg1, byte0 = 0x10
424 * cbArg1, byte1 NVRAM index low byte
425 * cbArg1, byte2 NVRAM index high byte
426 * cbRes1 Standard return codes (0, -1, -2)
427 * cbRes2 4 bytes read from LCD[index]
428 * cbRes3 4 bytes read from LCD[index+4]
429 * cbRes4 4 bytes read from LCD[index+8]
431 * Write Local Config Data (LCD)
432 * cbArg1, byte0 = 0x11
433 * cbArg1, byte1 NVRAM index low byte
434 * cbArg1, byte2 NVRAM index high byte
435 * cbArg2 4 bytes to w rite at LCD[index]
436 * cbArg3 4 bytes to w rite at LCD[index+4]
437 * cbArg4 4 bytes to w rite at LCD[index+8]
438 * cbRes1 Standard return codes (0, -1, -2)
440 * Populate Local Config Data from NVRAM
441 * cbArg1, byte0 = 0x12
442 * cbRes1 Standard return codes (0, -1, -2)
444 * Commit Local Config Data to NVRAM
445 * cbArg1, byte0 = 0x13
446 * cbRes1 Standard return codes (0, -1, -2)
449 static int dell_rfkill_set(void *data
, bool blocked
)
451 int disable
= blocked
? 1 : 0;
452 unsigned long radio
= (unsigned long)data
;
453 int hwswitch_bit
= (unsigned long)data
- 1;
454 struct calling_interface_buffer buffer
;
459 dell_fill_request(&buffer
, 0, 0, 0, 0);
460 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
463 status
= buffer
.output
[1];
465 dell_fill_request(&buffer
, 0x2, 0, 0, 0);
466 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
469 hwswitch
= buffer
.output
[1];
471 /* If the hardware switch controls this radio, and the hardware
472 switch is disabled, always disable the radio */
473 if (ret
== 0 && (hwswitch
& BIT(hwswitch_bit
)) &&
474 (status
& BIT(0)) && !(status
& BIT(16)))
477 dell_fill_request(&buffer
, 1 | (radio
<<8) | (disable
<< 16), 0, 0, 0);
478 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
482 static void dell_rfkill_update_sw_state(struct rfkill
*rfkill
, int radio
,
485 if (status
& BIT(0)) {
486 /* Has hw-switch, sync sw_state to BIOS */
487 struct calling_interface_buffer buffer
;
488 int block
= rfkill_blocked(rfkill
);
489 dell_fill_request(&buffer
,
490 1 | (radio
<< 8) | (block
<< 16), 0, 0, 0);
491 dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
493 /* No hw-switch, sync BIOS state to sw_state */
494 rfkill_set_sw_state(rfkill
, !!(status
& BIT(radio
+ 16)));
498 static void dell_rfkill_update_hw_state(struct rfkill
*rfkill
, int radio
,
499 int status
, int hwswitch
)
501 if (hwswitch
& (BIT(radio
- 1)))
502 rfkill_set_hw_state(rfkill
, !(status
& BIT(16)));
505 static void dell_rfkill_query(struct rfkill
*rfkill
, void *data
)
507 int radio
= ((unsigned long)data
& 0xF);
508 struct calling_interface_buffer buffer
;
513 dell_fill_request(&buffer
, 0, 0, 0, 0);
514 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
515 status
= buffer
.output
[1];
517 if (ret
!= 0 || !(status
& BIT(0))) {
521 dell_fill_request(&buffer
, 0, 0x2, 0, 0);
522 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
523 hwswitch
= buffer
.output
[1];
528 dell_rfkill_update_hw_state(rfkill
, radio
, status
, hwswitch
);
531 static const struct rfkill_ops dell_rfkill_ops
= {
532 .set_block
= dell_rfkill_set
,
533 .query
= dell_rfkill_query
,
536 static struct dentry
*dell_laptop_dir
;
538 static int dell_debugfs_show(struct seq_file
*s
, void *data
)
540 struct calling_interface_buffer buffer
;
546 dell_fill_request(&buffer
, 0, 0, 0, 0);
547 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
550 status
= buffer
.output
[1];
552 dell_fill_request(&buffer
, 0, 0x2, 0, 0);
553 hwswitch_ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
556 hwswitch_state
= buffer
.output
[1];
558 seq_printf(s
, "return:\t%d\n", ret
);
559 seq_printf(s
, "status:\t0x%X\n", status
);
560 seq_printf(s
, "Bit 0 : Hardware switch supported: %lu\n",
562 seq_printf(s
, "Bit 1 : Wifi locator supported: %lu\n",
563 (status
& BIT(1)) >> 1);
564 seq_printf(s
, "Bit 2 : Wifi is supported: %lu\n",
565 (status
& BIT(2)) >> 2);
566 seq_printf(s
, "Bit 3 : Bluetooth is supported: %lu\n",
567 (status
& BIT(3)) >> 3);
568 seq_printf(s
, "Bit 4 : WWAN is supported: %lu\n",
569 (status
& BIT(4)) >> 4);
570 seq_printf(s
, "Bit 5 : Wireless keyboard supported: %lu\n",
571 (status
& BIT(5)) >> 5);
572 seq_printf(s
, "Bit 6 : UWB supported: %lu\n",
573 (status
& BIT(6)) >> 6);
574 seq_printf(s
, "Bit 7 : WiGig supported: %lu\n",
575 (status
& BIT(7)) >> 7);
576 seq_printf(s
, "Bit 8 : Wifi is installed: %lu\n",
577 (status
& BIT(8)) >> 8);
578 seq_printf(s
, "Bit 9 : Bluetooth is installed: %lu\n",
579 (status
& BIT(9)) >> 9);
580 seq_printf(s
, "Bit 10: WWAN is installed: %lu\n",
581 (status
& BIT(10)) >> 10);
582 seq_printf(s
, "Bit 11: UWB installed: %lu\n",
583 (status
& BIT(11)) >> 11);
584 seq_printf(s
, "Bit 12: WiGig installed: %lu\n",
585 (status
& BIT(12)) >> 12);
587 seq_printf(s
, "Bit 16: Hardware switch is on: %lu\n",
588 (status
& BIT(16)) >> 16);
589 seq_printf(s
, "Bit 17: Wifi is blocked: %lu\n",
590 (status
& BIT(17)) >> 17);
591 seq_printf(s
, "Bit 18: Bluetooth is blocked: %lu\n",
592 (status
& BIT(18)) >> 18);
593 seq_printf(s
, "Bit 19: WWAN is blocked: %lu\n",
594 (status
& BIT(19)) >> 19);
595 seq_printf(s
, "Bit 20: UWB is blocked: %lu\n",
596 (status
& BIT(20)) >> 20);
597 seq_printf(s
, "Bit 21: WiGig is blocked: %lu\n",
598 (status
& BIT(21)) >> 21);
600 seq_printf(s
, "\nhwswitch_return:\t%d\n", hwswitch_ret
);
601 seq_printf(s
, "hwswitch_state:\t0x%X\n", hwswitch_state
);
602 seq_printf(s
, "Bit 0 : Wifi controlled by switch: %lu\n",
603 hwswitch_state
& BIT(0));
604 seq_printf(s
, "Bit 1 : Bluetooth controlled by switch: %lu\n",
605 (hwswitch_state
& BIT(1)) >> 1);
606 seq_printf(s
, "Bit 2 : WWAN controlled by switch: %lu\n",
607 (hwswitch_state
& BIT(2)) >> 2);
608 seq_printf(s
, "Bit 3 : UWB controlled by switch: %lu\n",
609 (hwswitch_state
& BIT(3)) >> 3);
610 seq_printf(s
, "Bit 4 : WiGig controlled by switch: %lu\n",
611 (hwswitch_state
& BIT(4)) >> 4);
612 seq_printf(s
, "Bit 7 : Wireless switch config locked: %lu\n",
613 (hwswitch_state
& BIT(7)) >> 7);
614 seq_printf(s
, "Bit 8 : Wifi locator enabled: %lu\n",
615 (hwswitch_state
& BIT(8)) >> 8);
616 seq_printf(s
, "Bit 15: Wifi locator setting locked: %lu\n",
617 (hwswitch_state
& BIT(15)) >> 15);
621 DEFINE_SHOW_ATTRIBUTE(dell_debugfs
);
623 static void dell_update_rfkill(struct work_struct
*ignored
)
625 struct calling_interface_buffer buffer
;
630 dell_fill_request(&buffer
, 0, 0, 0, 0);
631 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
632 status
= buffer
.output
[1];
637 dell_fill_request(&buffer
, 0, 0x2, 0, 0);
638 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
640 if (ret
== 0 && (status
& BIT(0)))
641 hwswitch
= buffer
.output
[1];
644 dell_rfkill_update_hw_state(wifi_rfkill
, 1, status
, hwswitch
);
645 dell_rfkill_update_sw_state(wifi_rfkill
, 1, status
);
647 if (bluetooth_rfkill
) {
648 dell_rfkill_update_hw_state(bluetooth_rfkill
, 2, status
,
650 dell_rfkill_update_sw_state(bluetooth_rfkill
, 2, status
);
653 dell_rfkill_update_hw_state(wwan_rfkill
, 3, status
, hwswitch
);
654 dell_rfkill_update_sw_state(wwan_rfkill
, 3, status
);
657 static DECLARE_DELAYED_WORK(dell_rfkill_work
, dell_update_rfkill
);
659 static bool dell_laptop_i8042_filter(unsigned char data
, unsigned char str
,
662 static bool extended
;
664 if (str
& I8042_STR_AUXDATA
)
667 if (unlikely(data
== 0xe0)) {
670 } else if (unlikely(extended
)) {
673 schedule_delayed_work(&dell_rfkill_work
,
674 round_jiffies_relative(HZ
/ 4));
683 static int (*dell_rbtn_notifier_register_func
)(struct notifier_block
*);
684 static int (*dell_rbtn_notifier_unregister_func
)(struct notifier_block
*);
686 static int dell_laptop_rbtn_notifier_call(struct notifier_block
*nb
,
687 unsigned long action
, void *data
)
689 schedule_delayed_work(&dell_rfkill_work
, 0);
693 static struct notifier_block dell_laptop_rbtn_notifier
= {
694 .notifier_call
= dell_laptop_rbtn_notifier_call
,
697 static int __init
dell_setup_rfkill(void)
699 struct calling_interface_buffer buffer
;
700 int status
, ret
, whitelisted
;
704 * rfkill support causes trouble on various models, mostly Inspirons.
705 * So we whitelist certain series, and don't support rfkill on others.
708 product
= dmi_get_system_info(DMI_PRODUCT_NAME
);
709 if (product
&& (strncmp(product
, "Latitude", 8) == 0 ||
710 strncmp(product
, "Precision", 9) == 0))
712 if (!force_rfkill
&& !whitelisted
)
715 dell_fill_request(&buffer
, 0, 0, 0, 0);
716 ret
= dell_send_request(&buffer
, CLASS_INFO
, SELECT_RFKILL
);
717 status
= buffer
.output
[1];
719 /* dell wireless info smbios call is not supported */
723 /* rfkill is only tested on laptops with a hwswitch */
724 if (!(status
& BIT(0)) && !force_rfkill
)
727 if ((status
& (1<<2|1<<8)) == (1<<2|1<<8)) {
728 wifi_rfkill
= rfkill_alloc("dell-wifi", &platform_device
->dev
,
730 &dell_rfkill_ops
, (void *) 1);
735 ret
= rfkill_register(wifi_rfkill
);
740 if ((status
& (1<<3|1<<9)) == (1<<3|1<<9)) {
741 bluetooth_rfkill
= rfkill_alloc("dell-bluetooth",
742 &platform_device
->dev
,
743 RFKILL_TYPE_BLUETOOTH
,
744 &dell_rfkill_ops
, (void *) 2);
745 if (!bluetooth_rfkill
) {
749 ret
= rfkill_register(bluetooth_rfkill
);
754 if ((status
& (1<<4|1<<10)) == (1<<4|1<<10)) {
755 wwan_rfkill
= rfkill_alloc("dell-wwan",
756 &platform_device
->dev
,
758 &dell_rfkill_ops
, (void *) 3);
763 ret
= rfkill_register(wwan_rfkill
);
769 * Dell Airplane Mode Switch driver (dell-rbtn) supports ACPI devices
770 * which can receive events from HW slider switch.
772 * Dell SMBIOS on whitelisted models supports controlling radio devices
773 * but does not support receiving HW button switch events. We can use
774 * i8042 filter hook function to receive keyboard data and handle
775 * keycode for HW button.
777 * So if it is possible we will use Dell Airplane Mode Switch ACPI
778 * driver for receiving HW events and Dell SMBIOS for setting rfkill
779 * states. If ACPI driver or device is not available we will fallback to
780 * i8042 filter hook function.
782 * To prevent duplicate rfkill devices which control and do same thing,
783 * dell-rbtn driver will automatically remove its own rfkill devices
784 * once function dell_rbtn_notifier_register() is called.
787 dell_rbtn_notifier_register_func
=
788 symbol_request(dell_rbtn_notifier_register
);
789 if (dell_rbtn_notifier_register_func
) {
790 dell_rbtn_notifier_unregister_func
=
791 symbol_request(dell_rbtn_notifier_unregister
);
792 if (!dell_rbtn_notifier_unregister_func
) {
793 symbol_put(dell_rbtn_notifier_register
);
794 dell_rbtn_notifier_register_func
= NULL
;
798 if (dell_rbtn_notifier_register_func
) {
799 ret
= dell_rbtn_notifier_register_func(
800 &dell_laptop_rbtn_notifier
);
801 symbol_put(dell_rbtn_notifier_register
);
802 dell_rbtn_notifier_register_func
= NULL
;
804 symbol_put(dell_rbtn_notifier_unregister
);
805 dell_rbtn_notifier_unregister_func
= NULL
;
808 pr_info("Symbols from dell-rbtn acpi driver are not available\n");
813 pr_info("Using dell-rbtn acpi driver for receiving events\n");
814 } else if (ret
!= -ENODEV
) {
815 pr_warn("Unable to register dell rbtn notifier\n");
818 ret
= i8042_install_filter(dell_laptop_i8042_filter
);
820 pr_warn("Unable to install key filter\n");
823 pr_info("Using i8042 filter function for receiving events\n");
829 rfkill_unregister(wwan_rfkill
);
831 rfkill_destroy(wwan_rfkill
);
832 if (bluetooth_rfkill
)
833 rfkill_unregister(bluetooth_rfkill
);
835 rfkill_destroy(bluetooth_rfkill
);
837 rfkill_unregister(wifi_rfkill
);
839 rfkill_destroy(wifi_rfkill
);
844 static void dell_cleanup_rfkill(void)
846 if (dell_rbtn_notifier_unregister_func
) {
847 dell_rbtn_notifier_unregister_func(&dell_laptop_rbtn_notifier
);
848 symbol_put(dell_rbtn_notifier_unregister
);
849 dell_rbtn_notifier_unregister_func
= NULL
;
851 i8042_remove_filter(dell_laptop_i8042_filter
);
853 cancel_delayed_work_sync(&dell_rfkill_work
);
855 rfkill_unregister(wifi_rfkill
);
856 rfkill_destroy(wifi_rfkill
);
858 if (bluetooth_rfkill
) {
859 rfkill_unregister(bluetooth_rfkill
);
860 rfkill_destroy(bluetooth_rfkill
);
863 rfkill_unregister(wwan_rfkill
);
864 rfkill_destroy(wwan_rfkill
);
868 static int dell_send_intensity(struct backlight_device
*bd
)
870 struct calling_interface_buffer buffer
;
871 struct calling_interface_token
*token
;
874 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
878 dell_fill_request(&buffer
,
879 token
->location
, bd
->props
.brightness
, 0, 0);
880 if (power_supply_is_system_supplied() > 0)
881 ret
= dell_send_request(&buffer
,
882 CLASS_TOKEN_WRITE
, SELECT_TOKEN_AC
);
884 ret
= dell_send_request(&buffer
,
885 CLASS_TOKEN_WRITE
, SELECT_TOKEN_BAT
);
890 static int dell_get_intensity(struct backlight_device
*bd
)
892 struct calling_interface_buffer buffer
;
893 struct calling_interface_token
*token
;
896 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
900 dell_fill_request(&buffer
, token
->location
, 0, 0, 0);
901 if (power_supply_is_system_supplied() > 0)
902 ret
= dell_send_request(&buffer
,
903 CLASS_TOKEN_READ
, SELECT_TOKEN_AC
);
905 ret
= dell_send_request(&buffer
,
906 CLASS_TOKEN_READ
, SELECT_TOKEN_BAT
);
909 ret
= buffer
.output
[1];
914 static const struct backlight_ops dell_ops
= {
915 .get_brightness
= dell_get_intensity
,
916 .update_status
= dell_send_intensity
,
919 static void touchpad_led_on(void)
923 i8042_command(&data
, command
| 1 << 12);
926 static void touchpad_led_off(void)
930 i8042_command(&data
, command
| 1 << 12);
933 static void touchpad_led_set(struct led_classdev
*led_cdev
,
934 enum led_brightness value
)
942 static struct led_classdev touchpad_led
= {
943 .name
= "dell-laptop::touchpad",
944 .brightness_set
= touchpad_led_set
,
945 .flags
= LED_CORE_SUSPENDRESUME
,
948 static int __init
touchpad_led_init(struct device
*dev
)
950 return led_classdev_register(dev
, &touchpad_led
);
953 static void touchpad_led_exit(void)
955 led_classdev_unregister(&touchpad_led
);
959 * Derived from information in smbios-keyboard-ctl:
963 * Keyboard illumination
964 * cbArg1 determines the function to be performed
966 * cbArg1 0x0 = Get Feature Information
967 * cbRES1 Standard return codes (0, -1, -2)
968 * cbRES2, word0 Bitmap of user-selectable modes
969 * bit 0 Always off (All systems)
970 * bit 1 Always on (Travis ATG, Siberia)
971 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
972 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
973 * bit 4 Auto: Input-activity-based On; input-activity based Off
974 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
975 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
976 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
977 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
978 * bits 9-15 Reserved for future use
979 * cbRES2, byte2 Reserved for future use
980 * cbRES2, byte3 Keyboard illumination type
984 * 3-255 Reserved for future use
985 * cbRES3, byte0 Supported auto keyboard illumination trigger bitmap.
986 * bit 0 Any keystroke
987 * bit 1 Touchpad activity
988 * bit 2 Pointing stick
990 * bits 4-7 Reserved for future use
991 * cbRES3, byte1 Supported timeout unit bitmap
996 * bits 4-7 Reserved for future use
997 * cbRES3, byte2 Number of keyboard light brightness levels
998 * cbRES4, byte0 Maximum acceptable seconds value (0 if seconds not supported).
999 * cbRES4, byte1 Maximum acceptable minutes value (0 if minutes not supported).
1000 * cbRES4, byte2 Maximum acceptable hours value (0 if hours not supported).
1001 * cbRES4, byte3 Maximum acceptable days value (0 if days not supported)
1003 * cbArg1 0x1 = Get Current State
1004 * cbRES1 Standard return codes (0, -1, -2)
1005 * cbRES2, word0 Bitmap of current mode state
1006 * bit 0 Always off (All systems)
1007 * bit 1 Always on (Travis ATG, Siberia)
1008 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
1009 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
1010 * bit 4 Auto: Input-activity-based On; input-activity based Off
1011 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
1012 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
1013 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
1014 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
1015 * bits 9-15 Reserved for future use
1016 * Note: Only One bit can be set
1017 * cbRES2, byte2 Currently active auto keyboard illumination triggers.
1018 * bit 0 Any keystroke
1019 * bit 1 Touchpad activity
1020 * bit 2 Pointing stick
1022 * bits 4-7 Reserved for future use
1023 * cbRES2, byte3 Current Timeout on battery
1024 * bits 7:6 Timeout units indicator:
1029 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1030 * NOTE: A value of 0 means always on (no timeout) if any bits of RES3 byte
1031 * are set upon return from the [Get feature information] call.
1032 * cbRES3, byte0 Current setting of ALS value that turns the light on or off.
1033 * cbRES3, byte1 Current ALS reading
1034 * cbRES3, byte2 Current keyboard light level.
1035 * cbRES3, byte3 Current timeout on AC Power
1036 * bits 7:6 Timeout units indicator:
1041 * Bits 5:0 Timeout value (0-63) in sec/min/hr/day
1042 * NOTE: A value of 0 means always on (no timeout) if any bits of RES3 byte2
1043 * are set upon return from the upon return from the [Get Feature information] call.
1045 * cbArg1 0x2 = Set New State
1046 * cbRES1 Standard return codes (0, -1, -2)
1047 * cbArg2, word0 Bitmap of current mode state
1048 * bit 0 Always off (All systems)
1049 * bit 1 Always on (Travis ATG, Siberia)
1050 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
1051 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
1052 * bit 4 Auto: Input-activity-based On; input-activity based Off
1053 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
1054 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
1055 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
1056 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
1057 * bits 9-15 Reserved for future use
1058 * Note: Only One bit can be set
1059 * cbArg2, byte2 Desired auto keyboard illumination triggers. Must remain inactive to allow
1060 * keyboard to turn off automatically.
1061 * bit 0 Any keystroke
1062 * bit 1 Touchpad activity
1063 * bit 2 Pointing stick
1065 * bits 4-7 Reserved for future use
1066 * cbArg2, byte3 Desired Timeout on battery
1067 * bits 7:6 Timeout units indicator:
1072 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1073 * cbArg3, byte0 Desired setting of ALS value that turns the light on or off.
1074 * cbArg3, byte2 Desired keyboard light level.
1075 * cbArg3, byte3 Desired Timeout on AC power
1076 * bits 7:6 Timeout units indicator:
1081 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1085 enum kbd_timeout_unit
{
1086 KBD_TIMEOUT_SECONDS
= 0,
1087 KBD_TIMEOUT_MINUTES
,
1093 KBD_MODE_BIT_OFF
= 0,
1096 KBD_MODE_BIT_TRIGGER_ALS
,
1097 KBD_MODE_BIT_TRIGGER
,
1098 KBD_MODE_BIT_TRIGGER_25
,
1099 KBD_MODE_BIT_TRIGGER_50
,
1100 KBD_MODE_BIT_TRIGGER_75
,
1101 KBD_MODE_BIT_TRIGGER_100
,
1104 #define kbd_is_als_mode_bit(bit) \
1105 ((bit) == KBD_MODE_BIT_ALS || (bit) == KBD_MODE_BIT_TRIGGER_ALS)
1106 #define kbd_is_trigger_mode_bit(bit) \
1107 ((bit) >= KBD_MODE_BIT_TRIGGER_ALS && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1108 #define kbd_is_level_mode_bit(bit) \
1109 ((bit) >= KBD_MODE_BIT_TRIGGER_25 && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1127 u8 timeout_value_ac
;
1134 static const int kbd_tokens
[] = {
1136 KBD_LED_AUTO_25_TOKEN
,
1137 KBD_LED_AUTO_50_TOKEN
,
1138 KBD_LED_AUTO_75_TOKEN
,
1139 KBD_LED_AUTO_100_TOKEN
,
1143 static u16 kbd_token_bits
;
1145 static struct kbd_info kbd_info
;
1146 static bool kbd_als_supported
;
1147 static bool kbd_triggers_supported
;
1148 static bool kbd_timeout_ac_supported
;
1150 static u8 kbd_mode_levels
[16];
1151 static int kbd_mode_levels_count
;
1153 static u8 kbd_previous_level
;
1154 static u8 kbd_previous_mode_bit
;
1156 static bool kbd_led_present
;
1157 static DEFINE_MUTEX(kbd_led_mutex
);
1158 static enum led_brightness kbd_led_level
;
1161 * NOTE: there are three ways to set the keyboard backlight level.
1162 * First, via kbd_state.mode_bit (assigning KBD_MODE_BIT_TRIGGER_* value).
1163 * Second, via kbd_state.level (assigning numerical value <= kbd_info.levels).
1164 * Third, via SMBIOS tokens (KBD_LED_* in kbd_tokens)
1166 * There are laptops which support only one of these methods. If we want to
1167 * support as many machines as possible we need to implement all three methods.
1168 * The first two methods use the kbd_state structure. The third uses SMBIOS
1169 * tokens. If kbd_info.levels == 0, the machine does not support setting the
1170 * keyboard backlight level via kbd_state.level.
1173 static int kbd_get_info(struct kbd_info
*info
)
1175 struct calling_interface_buffer buffer
;
1179 dell_fill_request(&buffer
, 0, 0, 0, 0);
1180 ret
= dell_send_request(&buffer
,
1181 CLASS_KBD_BACKLIGHT
, SELECT_KBD_BACKLIGHT
);
1185 info
->modes
= buffer
.output
[1] & 0xFFFF;
1186 info
->type
= (buffer
.output
[1] >> 24) & 0xFF;
1187 info
->triggers
= buffer
.output
[2] & 0xFF;
1188 units
= (buffer
.output
[2] >> 8) & 0xFF;
1189 info
->levels
= (buffer
.output
[2] >> 16) & 0xFF;
1191 if (quirks
&& quirks
->kbd_led_levels_off_1
&& info
->levels
)
1195 info
->seconds
= (buffer
.output
[3] >> 0) & 0xFF;
1197 info
->minutes
= (buffer
.output
[3] >> 8) & 0xFF;
1199 info
->hours
= (buffer
.output
[3] >> 16) & 0xFF;
1201 info
->days
= (buffer
.output
[3] >> 24) & 0xFF;
1206 static unsigned int kbd_get_max_level(void)
1208 if (kbd_info
.levels
!= 0)
1209 return kbd_info
.levels
;
1210 if (kbd_mode_levels_count
> 0)
1211 return kbd_mode_levels_count
- 1;
1215 static int kbd_get_level(struct kbd_state
*state
)
1219 if (kbd_info
.levels
!= 0)
1220 return state
->level
;
1222 if (kbd_mode_levels_count
> 0) {
1223 for (i
= 0; i
< kbd_mode_levels_count
; ++i
)
1224 if (kbd_mode_levels
[i
] == state
->mode_bit
)
1232 static int kbd_set_level(struct kbd_state
*state
, u8 level
)
1234 if (kbd_info
.levels
!= 0) {
1236 kbd_previous_level
= level
;
1237 if (state
->level
== level
)
1239 state
->level
= level
;
1240 if (level
!= 0 && state
->mode_bit
== KBD_MODE_BIT_OFF
)
1241 state
->mode_bit
= kbd_previous_mode_bit
;
1242 else if (level
== 0 && state
->mode_bit
!= KBD_MODE_BIT_OFF
) {
1243 kbd_previous_mode_bit
= state
->mode_bit
;
1244 state
->mode_bit
= KBD_MODE_BIT_OFF
;
1249 if (kbd_mode_levels_count
> 0 && level
< kbd_mode_levels_count
) {
1251 kbd_previous_level
= level
;
1252 state
->mode_bit
= kbd_mode_levels
[level
];
1259 static int kbd_get_state(struct kbd_state
*state
)
1261 struct calling_interface_buffer buffer
;
1264 dell_fill_request(&buffer
, 0x1, 0, 0, 0);
1265 ret
= dell_send_request(&buffer
,
1266 CLASS_KBD_BACKLIGHT
, SELECT_KBD_BACKLIGHT
);
1270 state
->mode_bit
= ffs(buffer
.output
[1] & 0xFFFF);
1271 if (state
->mode_bit
!= 0)
1274 state
->triggers
= (buffer
.output
[1] >> 16) & 0xFF;
1275 state
->timeout_value
= (buffer
.output
[1] >> 24) & 0x3F;
1276 state
->timeout_unit
= (buffer
.output
[1] >> 30) & 0x3;
1277 state
->als_setting
= buffer
.output
[2] & 0xFF;
1278 state
->als_value
= (buffer
.output
[2] >> 8) & 0xFF;
1279 state
->level
= (buffer
.output
[2] >> 16) & 0xFF;
1280 state
->timeout_value_ac
= (buffer
.output
[2] >> 24) & 0x3F;
1281 state
->timeout_unit_ac
= (buffer
.output
[2] >> 30) & 0x3;
1286 static int kbd_set_state(struct kbd_state
*state
)
1288 struct calling_interface_buffer buffer
;
1293 input1
= BIT(state
->mode_bit
) & 0xFFFF;
1294 input1
|= (state
->triggers
& 0xFF) << 16;
1295 input1
|= (state
->timeout_value
& 0x3F) << 24;
1296 input1
|= (state
->timeout_unit
& 0x3) << 30;
1297 input2
= state
->als_setting
& 0xFF;
1298 input2
|= (state
->level
& 0xFF) << 16;
1299 input2
|= (state
->timeout_value_ac
& 0x3F) << 24;
1300 input2
|= (state
->timeout_unit_ac
& 0x3) << 30;
1301 dell_fill_request(&buffer
, 0x2, input1
, input2
, 0);
1302 ret
= dell_send_request(&buffer
,
1303 CLASS_KBD_BACKLIGHT
, SELECT_KBD_BACKLIGHT
);
1308 static int kbd_set_state_safe(struct kbd_state
*state
, struct kbd_state
*old
)
1312 ret
= kbd_set_state(state
);
1317 * When setting the new state fails,try to restore the previous one.
1318 * This is needed on some machines where BIOS sets a default state when
1319 * setting a new state fails. This default state could be all off.
1322 if (kbd_set_state(old
))
1323 pr_err("Setting old previous keyboard state failed\n");
1328 static int kbd_set_token_bit(u8 bit
)
1330 struct calling_interface_buffer buffer
;
1331 struct calling_interface_token
*token
;
1334 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1337 token
= dell_smbios_find_token(kbd_tokens
[bit
]);
1341 dell_fill_request(&buffer
, token
->location
, token
->value
, 0, 0);
1342 ret
= dell_send_request(&buffer
, CLASS_TOKEN_WRITE
, SELECT_TOKEN_STD
);
1347 static int kbd_get_token_bit(u8 bit
)
1349 struct calling_interface_buffer buffer
;
1350 struct calling_interface_token
*token
;
1354 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1357 token
= dell_smbios_find_token(kbd_tokens
[bit
]);
1361 dell_fill_request(&buffer
, token
->location
, 0, 0, 0);
1362 ret
= dell_send_request(&buffer
, CLASS_TOKEN_READ
, SELECT_TOKEN_STD
);
1363 val
= buffer
.output
[1];
1368 return (val
== token
->value
);
1371 static int kbd_get_first_active_token_bit(void)
1376 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
) {
1377 ret
= kbd_get_token_bit(i
);
1385 static int kbd_get_valid_token_counts(void)
1387 return hweight16(kbd_token_bits
);
1390 static inline int kbd_init_info(void)
1392 struct kbd_state state
;
1396 ret
= kbd_get_info(&kbd_info
);
1400 /* NOTE: Old models without KBD_LED_AC_TOKEN token supports only one
1401 * timeout value which is shared for both battery and AC power
1402 * settings. So do not try to set AC values on old models.
1404 if (dell_smbios_find_token(KBD_LED_AC_TOKEN
))
1405 kbd_timeout_ac_supported
= true;
1407 kbd_get_state(&state
);
1409 /* NOTE: timeout value is stored in 6 bits so max value is 63 */
1410 if (kbd_info
.seconds
> 63)
1411 kbd_info
.seconds
= 63;
1412 if (kbd_info
.minutes
> 63)
1413 kbd_info
.minutes
= 63;
1414 if (kbd_info
.hours
> 63)
1415 kbd_info
.hours
= 63;
1416 if (kbd_info
.days
> 63)
1419 /* NOTE: On tested machines ON mode did not work and caused
1420 * problems (turned backlight off) so do not use it
1422 kbd_info
.modes
&= ~BIT(KBD_MODE_BIT_ON
);
1424 kbd_previous_level
= kbd_get_level(&state
);
1425 kbd_previous_mode_bit
= state
.mode_bit
;
1427 if (kbd_previous_level
== 0 && kbd_get_max_level() != 0)
1428 kbd_previous_level
= 1;
1430 if (kbd_previous_mode_bit
== KBD_MODE_BIT_OFF
) {
1431 kbd_previous_mode_bit
=
1432 ffs(kbd_info
.modes
& ~BIT(KBD_MODE_BIT_OFF
));
1433 if (kbd_previous_mode_bit
!= 0)
1434 kbd_previous_mode_bit
--;
1437 if (kbd_info
.modes
& (BIT(KBD_MODE_BIT_ALS
) |
1438 BIT(KBD_MODE_BIT_TRIGGER_ALS
)))
1439 kbd_als_supported
= true;
1441 if (kbd_info
.modes
& (
1442 BIT(KBD_MODE_BIT_TRIGGER_ALS
) | BIT(KBD_MODE_BIT_TRIGGER
) |
1443 BIT(KBD_MODE_BIT_TRIGGER_25
) | BIT(KBD_MODE_BIT_TRIGGER_50
) |
1444 BIT(KBD_MODE_BIT_TRIGGER_75
) | BIT(KBD_MODE_BIT_TRIGGER_100
)
1446 kbd_triggers_supported
= true;
1448 /* kbd_mode_levels[0] is reserved, see below */
1449 for (i
= 0; i
< 16; ++i
)
1450 if (kbd_is_level_mode_bit(i
) && (BIT(i
) & kbd_info
.modes
))
1451 kbd_mode_levels
[1 + kbd_mode_levels_count
++] = i
;
1454 * Find the first supported mode and assign to kbd_mode_levels[0].
1455 * This should be 0 (off), but we cannot depend on the BIOS to
1458 if (kbd_mode_levels_count
> 0) {
1459 for (i
= 0; i
< 16; ++i
) {
1460 if (BIT(i
) & kbd_info
.modes
) {
1461 kbd_mode_levels
[0] = i
;
1465 kbd_mode_levels_count
++;
1472 static inline void kbd_init_tokens(void)
1476 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
)
1477 if (dell_smbios_find_token(kbd_tokens
[i
]))
1478 kbd_token_bits
|= BIT(i
);
1481 static void kbd_init(void)
1485 ret
= kbd_init_info();
1489 * Only supports keyboard backlight when it has at least two modes.
1491 if ((ret
== 0 && (kbd_info
.levels
!= 0 || kbd_mode_levels_count
>= 2))
1492 || kbd_get_valid_token_counts() >= 2)
1493 kbd_led_present
= true;
1496 static ssize_t
kbd_led_timeout_store(struct device
*dev
,
1497 struct device_attribute
*attr
,
1498 const char *buf
, size_t count
)
1500 struct kbd_state new_state
;
1501 struct kbd_state state
;
1509 ret
= sscanf(buf
, "%d %c", &value
, &ch
);
1522 if (value
> kbd_info
.seconds
)
1524 unit
= KBD_TIMEOUT_SECONDS
;
1527 if (value
> kbd_info
.minutes
)
1529 unit
= KBD_TIMEOUT_MINUTES
;
1532 if (value
> kbd_info
.hours
)
1534 unit
= KBD_TIMEOUT_HOURS
;
1537 if (value
> kbd_info
.days
)
1539 unit
= KBD_TIMEOUT_DAYS
;
1545 if (quirks
&& quirks
->needs_kbd_timeouts
)
1549 /* Convert value from current units to seconds */
1551 case KBD_TIMEOUT_DAYS
:
1553 case KBD_TIMEOUT_HOURS
:
1555 case KBD_TIMEOUT_MINUTES
:
1557 unit
= KBD_TIMEOUT_SECONDS
;
1560 if (quirks
&& quirks
->needs_kbd_timeouts
) {
1561 for (i
= 0; quirks
->kbd_timeouts
[i
] != -1; i
++) {
1562 if (value
<= quirks
->kbd_timeouts
[i
]) {
1563 value
= quirks
->kbd_timeouts
[i
];
1569 if (value
<= kbd_info
.seconds
&& kbd_info
.seconds
) {
1570 unit
= KBD_TIMEOUT_SECONDS
;
1571 } else if (value
/ 60 <= kbd_info
.minutes
&& kbd_info
.minutes
) {
1573 unit
= KBD_TIMEOUT_MINUTES
;
1574 } else if (value
/ (60 * 60) <= kbd_info
.hours
&& kbd_info
.hours
) {
1576 unit
= KBD_TIMEOUT_HOURS
;
1577 } else if (value
/ (60 * 60 * 24) <= kbd_info
.days
&& kbd_info
.days
) {
1578 value
/= (60 * 60 * 24);
1579 unit
= KBD_TIMEOUT_DAYS
;
1585 mutex_lock(&kbd_led_mutex
);
1587 ret
= kbd_get_state(&state
);
1593 if (kbd_timeout_ac_supported
&& power_supply_is_system_supplied() > 0) {
1594 new_state
.timeout_value_ac
= value
;
1595 new_state
.timeout_unit_ac
= unit
;
1597 new_state
.timeout_value
= value
;
1598 new_state
.timeout_unit
= unit
;
1601 ret
= kbd_set_state_safe(&new_state
, &state
);
1607 mutex_unlock(&kbd_led_mutex
);
1611 static ssize_t
kbd_led_timeout_show(struct device
*dev
,
1612 struct device_attribute
*attr
, char *buf
)
1614 struct kbd_state state
;
1620 ret
= kbd_get_state(&state
);
1624 if (kbd_timeout_ac_supported
&& power_supply_is_system_supplied() > 0) {
1625 value
= state
.timeout_value_ac
;
1626 unit
= state
.timeout_unit_ac
;
1628 value
= state
.timeout_value
;
1629 unit
= state
.timeout_unit
;
1632 len
= sprintf(buf
, "%d", value
);
1635 case KBD_TIMEOUT_SECONDS
:
1636 return len
+ sprintf(buf
+len
, "s\n");
1637 case KBD_TIMEOUT_MINUTES
:
1638 return len
+ sprintf(buf
+len
, "m\n");
1639 case KBD_TIMEOUT_HOURS
:
1640 return len
+ sprintf(buf
+len
, "h\n");
1641 case KBD_TIMEOUT_DAYS
:
1642 return len
+ sprintf(buf
+len
, "d\n");
1650 static DEVICE_ATTR(stop_timeout
, S_IRUGO
| S_IWUSR
,
1651 kbd_led_timeout_show
, kbd_led_timeout_store
);
1653 static const char * const kbd_led_triggers
[] = {
1656 /*"trackstick"*/ NULL
, /* NOTE: trackstick is just alias for touchpad */
1660 static ssize_t
kbd_led_triggers_store(struct device
*dev
,
1661 struct device_attribute
*attr
,
1662 const char *buf
, size_t count
)
1664 struct kbd_state new_state
;
1665 struct kbd_state state
;
1666 bool triggers_enabled
= false;
1667 int trigger_bit
= -1;
1671 ret
= sscanf(buf
, "%20s", trigger
);
1675 if (trigger
[0] != '+' && trigger
[0] != '-')
1678 mutex_lock(&kbd_led_mutex
);
1680 ret
= kbd_get_state(&state
);
1684 if (kbd_triggers_supported
)
1685 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1687 if (kbd_triggers_supported
) {
1688 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1689 if (!(kbd_info
.triggers
& BIT(i
)))
1691 if (!kbd_led_triggers
[i
])
1693 if (strcmp(trigger
+1, kbd_led_triggers
[i
]) != 0)
1695 if (trigger
[0] == '+' &&
1696 triggers_enabled
&& (state
.triggers
& BIT(i
))) {
1700 if (trigger
[0] == '-' &&
1701 (!triggers_enabled
|| !(state
.triggers
& BIT(i
)))) {
1710 if (trigger_bit
== -1) {
1716 if (trigger
[0] == '+')
1717 new_state
.triggers
|= BIT(trigger_bit
);
1719 new_state
.triggers
&= ~BIT(trigger_bit
);
1721 * NOTE: trackstick bit (2) must be disabled when
1722 * disabling touchpad bit (1), otherwise touchpad
1723 * bit (1) will not be disabled
1725 if (trigger_bit
== 1)
1726 new_state
.triggers
&= ~BIT(2);
1728 if ((kbd_info
.triggers
& new_state
.triggers
) !=
1729 new_state
.triggers
) {
1733 if (new_state
.triggers
&& !triggers_enabled
) {
1734 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1735 kbd_set_level(&new_state
, kbd_previous_level
);
1736 } else if (new_state
.triggers
== 0) {
1737 kbd_set_level(&new_state
, 0);
1739 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
))) {
1743 ret
= kbd_set_state_safe(&new_state
, &state
);
1746 if (new_state
.mode_bit
!= KBD_MODE_BIT_OFF
)
1747 kbd_previous_mode_bit
= new_state
.mode_bit
;
1750 mutex_unlock(&kbd_led_mutex
);
1754 static ssize_t
kbd_led_triggers_show(struct device
*dev
,
1755 struct device_attribute
*attr
, char *buf
)
1757 struct kbd_state state
;
1758 bool triggers_enabled
;
1762 ret
= kbd_get_state(&state
);
1768 if (kbd_triggers_supported
) {
1769 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1770 level
= kbd_get_level(&state
);
1771 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1772 if (!(kbd_info
.triggers
& BIT(i
)))
1774 if (!kbd_led_triggers
[i
])
1776 if ((triggers_enabled
|| level
<= 0) &&
1777 (state
.triggers
& BIT(i
)))
1781 len
+= sprintf(buf
+len
, "%s ", kbd_led_triggers
[i
]);
1786 buf
[len
- 1] = '\n';
1791 static DEVICE_ATTR(start_triggers
, S_IRUGO
| S_IWUSR
,
1792 kbd_led_triggers_show
, kbd_led_triggers_store
);
1794 static ssize_t
kbd_led_als_enabled_store(struct device
*dev
,
1795 struct device_attribute
*attr
,
1796 const char *buf
, size_t count
)
1798 struct kbd_state new_state
;
1799 struct kbd_state state
;
1800 bool triggers_enabled
= false;
1804 ret
= kstrtoint(buf
, 0, &enable
);
1808 mutex_lock(&kbd_led_mutex
);
1810 ret
= kbd_get_state(&state
);
1814 if (enable
== kbd_is_als_mode_bit(state
.mode_bit
)) {
1821 if (kbd_triggers_supported
)
1822 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1825 if (triggers_enabled
)
1826 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER_ALS
;
1828 new_state
.mode_bit
= KBD_MODE_BIT_ALS
;
1830 if (triggers_enabled
) {
1831 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1832 kbd_set_level(&new_state
, kbd_previous_level
);
1834 new_state
.mode_bit
= KBD_MODE_BIT_ON
;
1837 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
))) {
1842 ret
= kbd_set_state_safe(&new_state
, &state
);
1845 kbd_previous_mode_bit
= new_state
.mode_bit
;
1849 mutex_unlock(&kbd_led_mutex
);
1853 static ssize_t
kbd_led_als_enabled_show(struct device
*dev
,
1854 struct device_attribute
*attr
,
1857 struct kbd_state state
;
1858 bool enabled
= false;
1861 ret
= kbd_get_state(&state
);
1864 enabled
= kbd_is_als_mode_bit(state
.mode_bit
);
1866 return sprintf(buf
, "%d\n", enabled
? 1 : 0);
1869 static DEVICE_ATTR(als_enabled
, S_IRUGO
| S_IWUSR
,
1870 kbd_led_als_enabled_show
, kbd_led_als_enabled_store
);
1872 static ssize_t
kbd_led_als_setting_store(struct device
*dev
,
1873 struct device_attribute
*attr
,
1874 const char *buf
, size_t count
)
1876 struct kbd_state state
;
1877 struct kbd_state new_state
;
1881 ret
= kstrtou8(buf
, 10, &setting
);
1885 mutex_lock(&kbd_led_mutex
);
1887 ret
= kbd_get_state(&state
);
1892 new_state
.als_setting
= setting
;
1894 ret
= kbd_set_state_safe(&new_state
, &state
);
1900 mutex_unlock(&kbd_led_mutex
);
1904 static ssize_t
kbd_led_als_setting_show(struct device
*dev
,
1905 struct device_attribute
*attr
,
1908 struct kbd_state state
;
1911 ret
= kbd_get_state(&state
);
1915 return sprintf(buf
, "%d\n", state
.als_setting
);
1918 static DEVICE_ATTR(als_setting
, S_IRUGO
| S_IWUSR
,
1919 kbd_led_als_setting_show
, kbd_led_als_setting_store
);
1921 static struct attribute
*kbd_led_attrs
[] = {
1922 &dev_attr_stop_timeout
.attr
,
1923 &dev_attr_start_triggers
.attr
,
1927 static const struct attribute_group kbd_led_group
= {
1928 .attrs
= kbd_led_attrs
,
1931 static struct attribute
*kbd_led_als_attrs
[] = {
1932 &dev_attr_als_enabled
.attr
,
1933 &dev_attr_als_setting
.attr
,
1937 static const struct attribute_group kbd_led_als_group
= {
1938 .attrs
= kbd_led_als_attrs
,
1941 static const struct attribute_group
*kbd_led_groups
[] = {
1947 static enum led_brightness
kbd_led_level_get(struct led_classdev
*led_cdev
)
1951 struct kbd_state state
;
1953 if (kbd_get_max_level()) {
1954 ret
= kbd_get_state(&state
);
1957 ret
= kbd_get_level(&state
);
1963 if (kbd_get_valid_token_counts()) {
1964 ret
= kbd_get_first_active_token_bit();
1967 for (num
= kbd_token_bits
; num
!= 0 && ret
> 0; --ret
)
1968 num
&= num
- 1; /* clear the first bit set */
1971 return ffs(num
) - 1;
1974 pr_warn("Keyboard brightness level control not supported\n");
1978 static int kbd_led_level_set(struct led_classdev
*led_cdev
,
1979 enum led_brightness value
)
1981 enum led_brightness new_value
= value
;
1982 struct kbd_state state
;
1983 struct kbd_state new_state
;
1987 mutex_lock(&kbd_led_mutex
);
1989 if (kbd_get_max_level()) {
1990 ret
= kbd_get_state(&state
);
1994 ret
= kbd_set_level(&new_state
, value
);
1997 ret
= kbd_set_state_safe(&new_state
, &state
);
1998 } else if (kbd_get_valid_token_counts()) {
1999 for (num
= kbd_token_bits
; num
!= 0 && value
> 0; --value
)
2000 num
&= num
- 1; /* clear the first bit set */
2004 ret
= kbd_set_token_bit(ffs(num
) - 1);
2006 pr_warn("Keyboard brightness level control not supported\n");
2012 kbd_led_level
= new_value
;
2014 mutex_unlock(&kbd_led_mutex
);
2018 static struct led_classdev kbd_led
= {
2019 .name
= "dell::kbd_backlight",
2020 .flags
= LED_BRIGHT_HW_CHANGED
,
2021 .brightness_set_blocking
= kbd_led_level_set
,
2022 .brightness_get
= kbd_led_level_get
,
2023 .groups
= kbd_led_groups
,
2026 static int __init
kbd_led_init(struct device
*dev
)
2031 if (!kbd_led_present
)
2033 if (!kbd_als_supported
)
2034 kbd_led_groups
[1] = NULL
;
2035 kbd_led
.max_brightness
= kbd_get_max_level();
2036 if (!kbd_led
.max_brightness
) {
2037 kbd_led
.max_brightness
= kbd_get_valid_token_counts();
2038 if (kbd_led
.max_brightness
)
2039 kbd_led
.max_brightness
--;
2042 kbd_led_level
= kbd_led_level_get(NULL
);
2044 ret
= led_classdev_register(dev
, &kbd_led
);
2046 kbd_led_present
= false;
2051 static void brightness_set_exit(struct led_classdev
*led_cdev
,
2052 enum led_brightness value
)
2054 /* Don't change backlight level on exit */
2057 static void kbd_led_exit(void)
2059 if (!kbd_led_present
)
2061 kbd_led
.brightness_set
= brightness_set_exit
;
2062 led_classdev_unregister(&kbd_led
);
2065 static int dell_laptop_notifier_call(struct notifier_block
*nb
,
2066 unsigned long action
, void *data
)
2068 bool changed
= false;
2069 enum led_brightness new_kbd_led_level
;
2072 case DELL_LAPTOP_KBD_BACKLIGHT_BRIGHTNESS_CHANGED
:
2073 if (!kbd_led_present
)
2076 mutex_lock(&kbd_led_mutex
);
2077 new_kbd_led_level
= kbd_led_level_get(&kbd_led
);
2078 if (kbd_led_level
!= new_kbd_led_level
) {
2079 kbd_led_level
= new_kbd_led_level
;
2082 mutex_unlock(&kbd_led_mutex
);
2085 led_classdev_notify_brightness_hw_changed(&kbd_led
,
2093 static struct notifier_block dell_laptop_notifier
= {
2094 .notifier_call
= dell_laptop_notifier_call
,
2097 int dell_micmute_led_set(int state
)
2099 struct calling_interface_buffer buffer
;
2100 struct calling_interface_token
*token
;
2103 token
= dell_smbios_find_token(GLOBAL_MIC_MUTE_DISABLE
);
2104 else if (state
== 1)
2105 token
= dell_smbios_find_token(GLOBAL_MIC_MUTE_ENABLE
);
2112 dell_fill_request(&buffer
, token
->location
, token
->value
, 0, 0);
2113 dell_send_request(&buffer
, CLASS_TOKEN_WRITE
, SELECT_TOKEN_STD
);
2117 EXPORT_SYMBOL_GPL(dell_micmute_led_set
);
2119 static int __init
dell_init(void)
2121 struct calling_interface_token
*token
;
2122 int max_intensity
= 0;
2125 if (!dmi_check_system(dell_device_table
))
2129 /* find if this machine support other functions */
2130 dmi_check_system(dell_quirks
);
2132 ret
= platform_driver_register(&platform_driver
);
2134 goto fail_platform_driver
;
2135 platform_device
= platform_device_alloc("dell-laptop", -1);
2136 if (!platform_device
) {
2138 goto fail_platform_device1
;
2140 ret
= platform_device_add(platform_device
);
2142 goto fail_platform_device2
;
2144 ret
= dell_setup_rfkill();
2147 pr_warn("Unable to setup rfkill\n");
2151 if (quirks
&& quirks
->touchpad_led
)
2152 touchpad_led_init(&platform_device
->dev
);
2154 kbd_led_init(&platform_device
->dev
);
2156 dell_laptop_dir
= debugfs_create_dir("dell_laptop", NULL
);
2157 if (dell_laptop_dir
!= NULL
)
2158 debugfs_create_file("rfkill", 0444, dell_laptop_dir
, NULL
,
2159 &dell_debugfs_fops
);
2161 dell_laptop_register_notifier(&dell_laptop_notifier
);
2163 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2166 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
2168 struct calling_interface_buffer buffer
;
2170 dell_fill_request(&buffer
, token
->location
, 0, 0, 0);
2171 ret
= dell_send_request(&buffer
,
2172 CLASS_TOKEN_READ
, SELECT_TOKEN_AC
);
2174 max_intensity
= buffer
.output
[3];
2177 if (max_intensity
) {
2178 struct backlight_properties props
;
2179 memset(&props
, 0, sizeof(struct backlight_properties
));
2180 props
.type
= BACKLIGHT_PLATFORM
;
2181 props
.max_brightness
= max_intensity
;
2182 dell_backlight_device
= backlight_device_register("dell_backlight",
2183 &platform_device
->dev
,
2188 if (IS_ERR(dell_backlight_device
)) {
2189 ret
= PTR_ERR(dell_backlight_device
);
2190 dell_backlight_device
= NULL
;
2191 goto fail_backlight
;
2194 dell_backlight_device
->props
.brightness
=
2195 dell_get_intensity(dell_backlight_device
);
2196 if (dell_backlight_device
->props
.brightness
< 0) {
2197 ret
= dell_backlight_device
->props
.brightness
;
2198 goto fail_get_brightness
;
2200 backlight_update_status(dell_backlight_device
);
2205 fail_get_brightness
:
2206 backlight_device_unregister(dell_backlight_device
);
2208 dell_cleanup_rfkill();
2210 platform_device_del(platform_device
);
2211 fail_platform_device2
:
2212 platform_device_put(platform_device
);
2213 fail_platform_device1
:
2214 platform_driver_unregister(&platform_driver
);
2215 fail_platform_driver
:
2219 static void __exit
dell_exit(void)
2221 dell_laptop_unregister_notifier(&dell_laptop_notifier
);
2222 debugfs_remove_recursive(dell_laptop_dir
);
2223 if (quirks
&& quirks
->touchpad_led
)
2224 touchpad_led_exit();
2226 backlight_device_unregister(dell_backlight_device
);
2227 dell_cleanup_rfkill();
2228 if (platform_device
) {
2229 platform_device_unregister(platform_device
);
2230 platform_driver_unregister(&platform_driver
);
2234 /* dell-rbtn.c driver export functions which will not work correctly (and could
2235 * cause kernel crash) if they are called before dell-rbtn.c init code. This is
2236 * not problem when dell-rbtn.c is compiled as external module. When both files
2237 * (dell-rbtn.c and dell-laptop.c) are compiled statically into kernel, then we
2238 * need to ensure that dell_init() will be called after initializing dell-rbtn.
2239 * This can be achieved by late_initcall() instead module_init().
2241 late_initcall(dell_init
);
2242 module_exit(dell_exit
);
2244 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
2245 MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
2246 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
2247 MODULE_DESCRIPTION("Dell laptop driver");
2248 MODULE_LICENSE("GPL");