2 * Driver for Dell laptop extras
4 * Copyright (c) Red Hat <mjg@redhat.com>
5 * Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com>
6 * Copyright (c) 2014 Pali Rohár <pali.rohar@gmail.com>
8 * Based on documentation in the libsmbios package:
9 * Copyright (C) 2005-2014 Dell Inc.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/platform_device.h>
22 #include <linux/backlight.h>
23 #include <linux/err.h>
24 #include <linux/dmi.h>
26 #include <linux/rfkill.h>
27 #include <linux/power_supply.h>
28 #include <linux/acpi.h>
30 #include <linux/i8042.h>
31 #include <linux/debugfs.h>
32 #include <linux/seq_file.h>
33 #include <acpi/video.h>
34 #include "dell-rbtn.h"
35 #include "dell-smbios.h"
37 #define BRIGHTNESS_TOKEN 0x7d
38 #define KBD_LED_OFF_TOKEN 0x01E1
39 #define KBD_LED_ON_TOKEN 0x01E2
40 #define KBD_LED_AUTO_TOKEN 0x01E3
41 #define KBD_LED_AUTO_25_TOKEN 0x02EA
42 #define KBD_LED_AUTO_50_TOKEN 0x02EB
43 #define KBD_LED_AUTO_75_TOKEN 0x02EC
44 #define KBD_LED_AUTO_100_TOKEN 0x02F6
48 u8 kbd_led_levels_off_1
;
50 int needs_kbd_timeouts
;
52 * Ordered list of timeouts expressed in seconds.
53 * The list must end with -1
58 static struct quirk_entry
*quirks
;
60 static struct quirk_entry quirk_dell_vostro_v130
= {
64 static int __init
dmi_matched(const struct dmi_system_id
*dmi
)
66 quirks
= dmi
->driver_data
;
71 * These values come from Windows utility provided by Dell. If any other value
72 * is used then BIOS silently set timeout to 0 without any error message.
74 static struct quirk_entry quirk_dell_xps13_9333
= {
75 .needs_kbd_timeouts
= 1,
76 .kbd_timeouts
= { 0, 5, 15, 60, 5 * 60, 15 * 60, -1 },
79 static struct quirk_entry quirk_dell_latitude_e6410
= {
80 .kbd_led_levels_off_1
= 1,
83 static struct platform_driver platform_driver
= {
85 .name
= "dell-laptop",
89 static struct platform_device
*platform_device
;
90 static struct backlight_device
*dell_backlight_device
;
91 static struct rfkill
*wifi_rfkill
;
92 static struct rfkill
*bluetooth_rfkill
;
93 static struct rfkill
*wwan_rfkill
;
94 static bool force_rfkill
;
96 module_param(force_rfkill
, bool, 0444);
97 MODULE_PARM_DESC(force_rfkill
, "enable rfkill on non whitelisted models");
99 static const struct dmi_system_id dell_device_table
[] __initconst
= {
101 .ident
= "Dell laptop",
103 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
104 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
109 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
110 DMI_MATCH(DMI_CHASSIS_TYPE
, "9"), /*Laptop*/
114 .ident
= "Dell Computer Corporation",
116 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer Corporation"),
117 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
122 MODULE_DEVICE_TABLE(dmi
, dell_device_table
);
124 static const struct dmi_system_id dell_quirks
[] __initconst
= {
126 .callback
= dmi_matched
,
127 .ident
= "Dell Vostro V130",
129 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
130 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V130"),
132 .driver_data
= &quirk_dell_vostro_v130
,
135 .callback
= dmi_matched
,
136 .ident
= "Dell Vostro V131",
138 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
139 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V131"),
141 .driver_data
= &quirk_dell_vostro_v130
,
144 .callback
= dmi_matched
,
145 .ident
= "Dell Vostro 3350",
147 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
148 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3350"),
150 .driver_data
= &quirk_dell_vostro_v130
,
153 .callback
= dmi_matched
,
154 .ident
= "Dell Vostro 3555",
156 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
157 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3555"),
159 .driver_data
= &quirk_dell_vostro_v130
,
162 .callback
= dmi_matched
,
163 .ident
= "Dell Inspiron N311z",
165 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
166 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron N311z"),
168 .driver_data
= &quirk_dell_vostro_v130
,
171 .callback
= dmi_matched
,
172 .ident
= "Dell Inspiron M5110",
174 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
175 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron M5110"),
177 .driver_data
= &quirk_dell_vostro_v130
,
180 .callback
= dmi_matched
,
181 .ident
= "Dell Vostro 3360",
183 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
184 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3360"),
186 .driver_data
= &quirk_dell_vostro_v130
,
189 .callback
= dmi_matched
,
190 .ident
= "Dell Vostro 3460",
192 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
193 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3460"),
195 .driver_data
= &quirk_dell_vostro_v130
,
198 .callback
= dmi_matched
,
199 .ident
= "Dell Vostro 3560",
201 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
202 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3560"),
204 .driver_data
= &quirk_dell_vostro_v130
,
207 .callback
= dmi_matched
,
208 .ident
= "Dell Vostro 3450",
210 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
211 DMI_MATCH(DMI_PRODUCT_NAME
, "Dell System Vostro 3450"),
213 .driver_data
= &quirk_dell_vostro_v130
,
216 .callback
= dmi_matched
,
217 .ident
= "Dell Inspiron 5420",
219 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
220 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5420"),
222 .driver_data
= &quirk_dell_vostro_v130
,
225 .callback
= dmi_matched
,
226 .ident
= "Dell Inspiron 5520",
228 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
229 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5520"),
231 .driver_data
= &quirk_dell_vostro_v130
,
234 .callback
= dmi_matched
,
235 .ident
= "Dell Inspiron 5720",
237 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
238 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5720"),
240 .driver_data
= &quirk_dell_vostro_v130
,
243 .callback
= dmi_matched
,
244 .ident
= "Dell Inspiron 7420",
246 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
247 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7420"),
249 .driver_data
= &quirk_dell_vostro_v130
,
252 .callback
= dmi_matched
,
253 .ident
= "Dell Inspiron 7520",
255 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
256 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7520"),
258 .driver_data
= &quirk_dell_vostro_v130
,
261 .callback
= dmi_matched
,
262 .ident
= "Dell Inspiron 7720",
264 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
265 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7720"),
267 .driver_data
= &quirk_dell_vostro_v130
,
270 .callback
= dmi_matched
,
271 .ident
= "Dell XPS13 9333",
273 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
274 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS13 9333"),
276 .driver_data
= &quirk_dell_xps13_9333
,
279 .callback
= dmi_matched
,
280 .ident
= "Dell Latitude E6410",
282 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
283 DMI_MATCH(DMI_PRODUCT_NAME
, "Latitude E6410"),
285 .driver_data
= &quirk_dell_latitude_e6410
,
291 * Derived from information in smbios-wireless-ctl:
293 * cbSelect 17, Value 11
295 * Return Wireless Info
296 * cbArg1, byte0 = 0x00
298 * cbRes1 Standard return codes (0, -1, -2)
299 * cbRes2 Info bit flags:
301 * 0 Hardware switch supported (1)
302 * 1 WiFi locator supported (1)
303 * 2 WLAN supported (1)
304 * 3 Bluetooth (BT) supported (1)
305 * 4 WWAN supported (1)
306 * 5 Wireless KBD supported (1)
307 * 6 Uw b supported (1)
308 * 7 WiGig supported (1)
309 * 8 WLAN installed (1)
311 * 10 WWAN installed (1)
312 * 11 Uw b installed (1)
313 * 12 WiGig installed (1)
315 * 16 Hardware (HW) switch is On (1)
316 * 17 WLAN disabled (1)
318 * 19 WWAN disabled (1)
319 * 20 Uw b disabled (1)
320 * 21 WiGig disabled (1)
323 * cbRes3 NVRAM size in bytes
324 * cbRes4, byte 0 NVRAM format version number
327 * Set QuickSet Radio Disable Flag
328 * cbArg1, byte0 = 0x01
337 * cbArg1, byte2 Flag bits:
338 * 0 QuickSet disables radio (1)
341 * cbRes1 Standard return codes (0, -1, -2)
342 * cbRes2 QuickSet (QS) radio disable bit map:
347 * 4 QS disables WIGIG
350 * Wireless Switch Configuration
351 * cbArg1, byte0 = 0x02
357 * 2 Set WiFi locator enable/disable
359 * Switch settings (if byte 1==1):
360 * 0 WLAN sw itch control (1)
361 * 1 BT sw itch control (1)
362 * 2 WWAN sw itch control (1)
363 * 3 UWB sw itch control (1)
364 * 4 WiGig sw itch control (1)
366 * cbArg1, byte2 Enable bits (if byte 1==2):
367 * 0 Enable WiFi locator (1)
369 * cbRes1 Standard return codes (0, -1, -2)
370 * cbRes2 QuickSet radio disable bit map:
371 * 0 WLAN controlled by sw itch (1)
372 * 1 BT controlled by sw itch (1)
373 * 2 WWAN controlled by sw itch (1)
374 * 3 UWB controlled by sw itch (1)
375 * 4 WiGig controlled by sw itch (1)
377 * 7 Wireless sw itch config locked (1)
378 * 8 WiFi locator enabled (1)
380 * 15 WiFi locator setting locked (1)
383 * Read Local Config Data (LCD)
384 * cbArg1, byte0 = 0x10
385 * cbArg1, byte1 NVRAM index low byte
386 * cbArg1, byte2 NVRAM index high byte
387 * cbRes1 Standard return codes (0, -1, -2)
388 * cbRes2 4 bytes read from LCD[index]
389 * cbRes3 4 bytes read from LCD[index+4]
390 * cbRes4 4 bytes read from LCD[index+8]
392 * Write Local Config Data (LCD)
393 * cbArg1, byte0 = 0x11
394 * cbArg1, byte1 NVRAM index low byte
395 * cbArg1, byte2 NVRAM index high byte
396 * cbArg2 4 bytes to w rite at LCD[index]
397 * cbArg3 4 bytes to w rite at LCD[index+4]
398 * cbArg4 4 bytes to w rite at LCD[index+8]
399 * cbRes1 Standard return codes (0, -1, -2)
401 * Populate Local Config Data from NVRAM
402 * cbArg1, byte0 = 0x12
403 * cbRes1 Standard return codes (0, -1, -2)
405 * Commit Local Config Data to NVRAM
406 * cbArg1, byte0 = 0x13
407 * cbRes1 Standard return codes (0, -1, -2)
410 static int dell_rfkill_set(void *data
, bool blocked
)
412 struct calling_interface_buffer
*buffer
;
413 int disable
= blocked
? 1 : 0;
414 unsigned long radio
= (unsigned long)data
;
415 int hwswitch_bit
= (unsigned long)data
- 1;
420 buffer
= dell_smbios_get_buffer();
422 dell_smbios_send_request(17, 11);
423 ret
= buffer
->output
[0];
424 status
= buffer
->output
[1];
429 dell_smbios_clear_buffer();
431 buffer
->input
[0] = 0x2;
432 dell_smbios_send_request(17, 11);
433 ret
= buffer
->output
[0];
434 hwswitch
= buffer
->output
[1];
436 /* If the hardware switch controls this radio, and the hardware
437 switch is disabled, always disable the radio */
438 if (ret
== 0 && (hwswitch
& BIT(hwswitch_bit
)) &&
439 (status
& BIT(0)) && !(status
& BIT(16)))
442 dell_smbios_clear_buffer();
444 buffer
->input
[0] = (1 | (radio
<<8) | (disable
<< 16));
445 dell_smbios_send_request(17, 11);
446 ret
= buffer
->output
[0];
449 dell_smbios_release_buffer();
450 return dell_smbios_error(ret
);
453 /* Must be called with the buffer held */
454 static void dell_rfkill_update_sw_state(struct rfkill
*rfkill
, int radio
,
456 struct calling_interface_buffer
*buffer
)
458 if (status
& BIT(0)) {
459 /* Has hw-switch, sync sw_state to BIOS */
460 int block
= rfkill_blocked(rfkill
);
461 dell_smbios_clear_buffer();
462 buffer
->input
[0] = (1 | (radio
<< 8) | (block
<< 16));
463 dell_smbios_send_request(17, 11);
465 /* No hw-switch, sync BIOS state to sw_state */
466 rfkill_set_sw_state(rfkill
, !!(status
& BIT(radio
+ 16)));
470 static void dell_rfkill_update_hw_state(struct rfkill
*rfkill
, int radio
,
471 int status
, int hwswitch
)
473 if (hwswitch
& (BIT(radio
- 1)))
474 rfkill_set_hw_state(rfkill
, !(status
& BIT(16)));
477 static void dell_rfkill_query(struct rfkill
*rfkill
, void *data
)
479 struct calling_interface_buffer
*buffer
;
480 int radio
= ((unsigned long)data
& 0xF);
485 buffer
= dell_smbios_get_buffer();
487 dell_smbios_send_request(17, 11);
488 ret
= buffer
->output
[0];
489 status
= buffer
->output
[1];
491 if (ret
!= 0 || !(status
& BIT(0))) {
492 dell_smbios_release_buffer();
496 dell_smbios_clear_buffer();
498 buffer
->input
[0] = 0x2;
499 dell_smbios_send_request(17, 11);
500 ret
= buffer
->output
[0];
501 hwswitch
= buffer
->output
[1];
503 dell_smbios_release_buffer();
508 dell_rfkill_update_hw_state(rfkill
, radio
, status
, hwswitch
);
511 static const struct rfkill_ops dell_rfkill_ops
= {
512 .set_block
= dell_rfkill_set
,
513 .query
= dell_rfkill_query
,
516 static struct dentry
*dell_laptop_dir
;
518 static int dell_debugfs_show(struct seq_file
*s
, void *data
)
520 struct calling_interface_buffer
*buffer
;
526 buffer
= dell_smbios_get_buffer();
528 dell_smbios_send_request(17, 11);
529 ret
= buffer
->output
[0];
530 status
= buffer
->output
[1];
532 dell_smbios_clear_buffer();
534 buffer
->input
[0] = 0x2;
535 dell_smbios_send_request(17, 11);
536 hwswitch_ret
= buffer
->output
[0];
537 hwswitch_state
= buffer
->output
[1];
539 dell_smbios_release_buffer();
541 seq_printf(s
, "return:\t%d\n", ret
);
542 seq_printf(s
, "status:\t0x%X\n", status
);
543 seq_printf(s
, "Bit 0 : Hardware switch supported: %lu\n",
545 seq_printf(s
, "Bit 1 : Wifi locator supported: %lu\n",
546 (status
& BIT(1)) >> 1);
547 seq_printf(s
, "Bit 2 : Wifi is supported: %lu\n",
548 (status
& BIT(2)) >> 2);
549 seq_printf(s
, "Bit 3 : Bluetooth is supported: %lu\n",
550 (status
& BIT(3)) >> 3);
551 seq_printf(s
, "Bit 4 : WWAN is supported: %lu\n",
552 (status
& BIT(4)) >> 4);
553 seq_printf(s
, "Bit 5 : Wireless keyboard supported: %lu\n",
554 (status
& BIT(5)) >> 5);
555 seq_printf(s
, "Bit 6 : UWB supported: %lu\n",
556 (status
& BIT(6)) >> 6);
557 seq_printf(s
, "Bit 7 : WiGig supported: %lu\n",
558 (status
& BIT(7)) >> 7);
559 seq_printf(s
, "Bit 8 : Wifi is installed: %lu\n",
560 (status
& BIT(8)) >> 8);
561 seq_printf(s
, "Bit 9 : Bluetooth is installed: %lu\n",
562 (status
& BIT(9)) >> 9);
563 seq_printf(s
, "Bit 10: WWAN is installed: %lu\n",
564 (status
& BIT(10)) >> 10);
565 seq_printf(s
, "Bit 11: UWB installed: %lu\n",
566 (status
& BIT(11)) >> 11);
567 seq_printf(s
, "Bit 12: WiGig installed: %lu\n",
568 (status
& BIT(12)) >> 12);
570 seq_printf(s
, "Bit 16: Hardware switch is on: %lu\n",
571 (status
& BIT(16)) >> 16);
572 seq_printf(s
, "Bit 17: Wifi is blocked: %lu\n",
573 (status
& BIT(17)) >> 17);
574 seq_printf(s
, "Bit 18: Bluetooth is blocked: %lu\n",
575 (status
& BIT(18)) >> 18);
576 seq_printf(s
, "Bit 19: WWAN is blocked: %lu\n",
577 (status
& BIT(19)) >> 19);
578 seq_printf(s
, "Bit 20: UWB is blocked: %lu\n",
579 (status
& BIT(20)) >> 20);
580 seq_printf(s
, "Bit 21: WiGig is blocked: %lu\n",
581 (status
& BIT(21)) >> 21);
583 seq_printf(s
, "\nhwswitch_return:\t%d\n", hwswitch_ret
);
584 seq_printf(s
, "hwswitch_state:\t0x%X\n", hwswitch_state
);
585 seq_printf(s
, "Bit 0 : Wifi controlled by switch: %lu\n",
586 hwswitch_state
& BIT(0));
587 seq_printf(s
, "Bit 1 : Bluetooth controlled by switch: %lu\n",
588 (hwswitch_state
& BIT(1)) >> 1);
589 seq_printf(s
, "Bit 2 : WWAN controlled by switch: %lu\n",
590 (hwswitch_state
& BIT(2)) >> 2);
591 seq_printf(s
, "Bit 3 : UWB controlled by switch: %lu\n",
592 (hwswitch_state
& BIT(3)) >> 3);
593 seq_printf(s
, "Bit 4 : WiGig controlled by switch: %lu\n",
594 (hwswitch_state
& BIT(4)) >> 4);
595 seq_printf(s
, "Bit 7 : Wireless switch config locked: %lu\n",
596 (hwswitch_state
& BIT(7)) >> 7);
597 seq_printf(s
, "Bit 8 : Wifi locator enabled: %lu\n",
598 (hwswitch_state
& BIT(8)) >> 8);
599 seq_printf(s
, "Bit 15: Wifi locator setting locked: %lu\n",
600 (hwswitch_state
& BIT(15)) >> 15);
605 static int dell_debugfs_open(struct inode
*inode
, struct file
*file
)
607 return single_open(file
, dell_debugfs_show
, inode
->i_private
);
610 static const struct file_operations dell_debugfs_fops
= {
611 .owner
= THIS_MODULE
,
612 .open
= dell_debugfs_open
,
615 .release
= single_release
,
618 static void dell_update_rfkill(struct work_struct
*ignored
)
620 struct calling_interface_buffer
*buffer
;
625 buffer
= dell_smbios_get_buffer();
627 dell_smbios_send_request(17, 11);
628 ret
= buffer
->output
[0];
629 status
= buffer
->output
[1];
634 dell_smbios_clear_buffer();
636 buffer
->input
[0] = 0x2;
637 dell_smbios_send_request(17, 11);
638 ret
= buffer
->output
[0];
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
, buffer
);
647 if (bluetooth_rfkill
) {
648 dell_rfkill_update_hw_state(bluetooth_rfkill
, 2, status
,
650 dell_rfkill_update_sw_state(bluetooth_rfkill
, 2, status
,
654 dell_rfkill_update_hw_state(wwan_rfkill
, 3, status
, hwswitch
);
655 dell_rfkill_update_sw_state(wwan_rfkill
, 3, status
, buffer
);
659 dell_smbios_release_buffer();
661 static DECLARE_DELAYED_WORK(dell_rfkill_work
, dell_update_rfkill
);
663 static bool dell_laptop_i8042_filter(unsigned char data
, unsigned char str
,
666 static bool extended
;
668 if (str
& I8042_STR_AUXDATA
)
671 if (unlikely(data
== 0xe0)) {
674 } else if (unlikely(extended
)) {
677 schedule_delayed_work(&dell_rfkill_work
,
678 round_jiffies_relative(HZ
/ 4));
687 static int (*dell_rbtn_notifier_register_func
)(struct notifier_block
*);
688 static int (*dell_rbtn_notifier_unregister_func
)(struct notifier_block
*);
690 static int dell_laptop_rbtn_notifier_call(struct notifier_block
*nb
,
691 unsigned long action
, void *data
)
693 schedule_delayed_work(&dell_rfkill_work
, 0);
697 static struct notifier_block dell_laptop_rbtn_notifier
= {
698 .notifier_call
= dell_laptop_rbtn_notifier_call
,
701 static int __init
dell_setup_rfkill(void)
703 struct calling_interface_buffer
*buffer
;
704 int status
, ret
, whitelisted
;
708 * rfkill support causes trouble on various models, mostly Inspirons.
709 * So we whitelist certain series, and don't support rfkill on others.
712 product
= dmi_get_system_info(DMI_PRODUCT_NAME
);
713 if (product
&& (strncmp(product
, "Latitude", 8) == 0 ||
714 strncmp(product
, "Precision", 9) == 0))
716 if (!force_rfkill
&& !whitelisted
)
719 buffer
= dell_smbios_get_buffer();
720 dell_smbios_send_request(17, 11);
721 ret
= buffer
->output
[0];
722 status
= buffer
->output
[1];
723 dell_smbios_release_buffer();
725 /* dell wireless info smbios call is not supported */
729 /* rfkill is only tested on laptops with a hwswitch */
730 if (!(status
& BIT(0)) && !force_rfkill
)
733 if ((status
& (1<<2|1<<8)) == (1<<2|1<<8)) {
734 wifi_rfkill
= rfkill_alloc("dell-wifi", &platform_device
->dev
,
736 &dell_rfkill_ops
, (void *) 1);
741 ret
= rfkill_register(wifi_rfkill
);
746 if ((status
& (1<<3|1<<9)) == (1<<3|1<<9)) {
747 bluetooth_rfkill
= rfkill_alloc("dell-bluetooth",
748 &platform_device
->dev
,
749 RFKILL_TYPE_BLUETOOTH
,
750 &dell_rfkill_ops
, (void *) 2);
751 if (!bluetooth_rfkill
) {
755 ret
= rfkill_register(bluetooth_rfkill
);
760 if ((status
& (1<<4|1<<10)) == (1<<4|1<<10)) {
761 wwan_rfkill
= rfkill_alloc("dell-wwan",
762 &platform_device
->dev
,
764 &dell_rfkill_ops
, (void *) 3);
769 ret
= rfkill_register(wwan_rfkill
);
775 * Dell Airplane Mode Switch driver (dell-rbtn) supports ACPI devices
776 * which can receive events from HW slider switch.
778 * Dell SMBIOS on whitelisted models supports controlling radio devices
779 * but does not support receiving HW button switch events. We can use
780 * i8042 filter hook function to receive keyboard data and handle
781 * keycode for HW button.
783 * So if it is possible we will use Dell Airplane Mode Switch ACPI
784 * driver for receiving HW events and Dell SMBIOS for setting rfkill
785 * states. If ACPI driver or device is not available we will fallback to
786 * i8042 filter hook function.
788 * To prevent duplicate rfkill devices which control and do same thing,
789 * dell-rbtn driver will automatically remove its own rfkill devices
790 * once function dell_rbtn_notifier_register() is called.
793 dell_rbtn_notifier_register_func
=
794 symbol_request(dell_rbtn_notifier_register
);
795 if (dell_rbtn_notifier_register_func
) {
796 dell_rbtn_notifier_unregister_func
=
797 symbol_request(dell_rbtn_notifier_unregister
);
798 if (!dell_rbtn_notifier_unregister_func
) {
799 symbol_put(dell_rbtn_notifier_register
);
800 dell_rbtn_notifier_register_func
= NULL
;
804 if (dell_rbtn_notifier_register_func
) {
805 ret
= dell_rbtn_notifier_register_func(
806 &dell_laptop_rbtn_notifier
);
807 symbol_put(dell_rbtn_notifier_register
);
808 dell_rbtn_notifier_register_func
= NULL
;
810 symbol_put(dell_rbtn_notifier_unregister
);
811 dell_rbtn_notifier_unregister_func
= NULL
;
814 pr_info("Symbols from dell-rbtn acpi driver are not available\n");
819 pr_info("Using dell-rbtn acpi driver for receiving events\n");
820 } else if (ret
!= -ENODEV
) {
821 pr_warn("Unable to register dell rbtn notifier\n");
824 ret
= i8042_install_filter(dell_laptop_i8042_filter
);
826 pr_warn("Unable to install key filter\n");
829 pr_info("Using i8042 filter function for receiving events\n");
835 rfkill_unregister(wwan_rfkill
);
837 rfkill_destroy(wwan_rfkill
);
838 if (bluetooth_rfkill
)
839 rfkill_unregister(bluetooth_rfkill
);
841 rfkill_destroy(bluetooth_rfkill
);
843 rfkill_unregister(wifi_rfkill
);
845 rfkill_destroy(wifi_rfkill
);
850 static void dell_cleanup_rfkill(void)
852 if (dell_rbtn_notifier_unregister_func
) {
853 dell_rbtn_notifier_unregister_func(&dell_laptop_rbtn_notifier
);
854 symbol_put(dell_rbtn_notifier_unregister
);
855 dell_rbtn_notifier_unregister_func
= NULL
;
857 i8042_remove_filter(dell_laptop_i8042_filter
);
859 cancel_delayed_work_sync(&dell_rfkill_work
);
861 rfkill_unregister(wifi_rfkill
);
862 rfkill_destroy(wifi_rfkill
);
864 if (bluetooth_rfkill
) {
865 rfkill_unregister(bluetooth_rfkill
);
866 rfkill_destroy(bluetooth_rfkill
);
869 rfkill_unregister(wwan_rfkill
);
870 rfkill_destroy(wwan_rfkill
);
874 static int dell_send_intensity(struct backlight_device
*bd
)
876 struct calling_interface_buffer
*buffer
;
877 struct calling_interface_token
*token
;
880 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
884 buffer
= dell_smbios_get_buffer();
885 buffer
->input
[0] = token
->location
;
886 buffer
->input
[1] = bd
->props
.brightness
;
888 if (power_supply_is_system_supplied() > 0)
889 dell_smbios_send_request(1, 2);
891 dell_smbios_send_request(1, 1);
893 ret
= dell_smbios_error(buffer
->output
[0]);
895 dell_smbios_release_buffer();
899 static int dell_get_intensity(struct backlight_device
*bd
)
901 struct calling_interface_buffer
*buffer
;
902 struct calling_interface_token
*token
;
905 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
909 buffer
= dell_smbios_get_buffer();
910 buffer
->input
[0] = token
->location
;
912 if (power_supply_is_system_supplied() > 0)
913 dell_smbios_send_request(0, 2);
915 dell_smbios_send_request(0, 1);
917 if (buffer
->output
[0])
918 ret
= dell_smbios_error(buffer
->output
[0]);
920 ret
= buffer
->output
[1];
922 dell_smbios_release_buffer();
926 static const struct backlight_ops dell_ops
= {
927 .get_brightness
= dell_get_intensity
,
928 .update_status
= dell_send_intensity
,
931 static void touchpad_led_on(void)
935 i8042_command(&data
, command
| 1 << 12);
938 static void touchpad_led_off(void)
942 i8042_command(&data
, command
| 1 << 12);
945 static void touchpad_led_set(struct led_classdev
*led_cdev
,
946 enum led_brightness value
)
954 static struct led_classdev touchpad_led
= {
955 .name
= "dell-laptop::touchpad",
956 .brightness_set
= touchpad_led_set
,
957 .flags
= LED_CORE_SUSPENDRESUME
,
960 static int __init
touchpad_led_init(struct device
*dev
)
962 return led_classdev_register(dev
, &touchpad_led
);
965 static void touchpad_led_exit(void)
967 led_classdev_unregister(&touchpad_led
);
971 * Derived from information in smbios-keyboard-ctl:
975 * Keyboard illumination
976 * cbArg1 determines the function to be performed
978 * cbArg1 0x0 = Get Feature Information
979 * cbRES1 Standard return codes (0, -1, -2)
980 * cbRES2, word0 Bitmap of user-selectable modes
981 * bit 0 Always off (All systems)
982 * bit 1 Always on (Travis ATG, Siberia)
983 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
984 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
985 * bit 4 Auto: Input-activity-based On; input-activity based Off
986 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
987 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
988 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
989 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
990 * bits 9-15 Reserved for future use
991 * cbRES2, byte2 Reserved for future use
992 * cbRES2, byte3 Keyboard illumination type
996 * 3-255 Reserved for future use
997 * cbRES3, byte0 Supported auto keyboard illumination trigger bitmap.
998 * bit 0 Any keystroke
999 * bit 1 Touchpad activity
1000 * bit 2 Pointing stick
1002 * bits 4-7 Reserved for future use
1003 * cbRES3, byte1 Supported timeout unit bitmap
1008 * bits 4-7 Reserved for future use
1009 * cbRES3, byte2 Number of keyboard light brightness levels
1010 * cbRES4, byte0 Maximum acceptable seconds value (0 if seconds not supported).
1011 * cbRES4, byte1 Maximum acceptable minutes value (0 if minutes not supported).
1012 * cbRES4, byte2 Maximum acceptable hours value (0 if hours not supported).
1013 * cbRES4, byte3 Maximum acceptable days value (0 if days not supported)
1015 * cbArg1 0x1 = Get Current State
1016 * cbRES1 Standard return codes (0, -1, -2)
1017 * cbRES2, word0 Bitmap of current mode state
1018 * bit 0 Always off (All systems)
1019 * bit 1 Always on (Travis ATG, Siberia)
1020 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
1021 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
1022 * bit 4 Auto: Input-activity-based On; input-activity based Off
1023 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
1024 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
1025 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
1026 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
1027 * bits 9-15 Reserved for future use
1028 * Note: Only One bit can be set
1029 * cbRES2, byte2 Currently active auto keyboard illumination triggers.
1030 * bit 0 Any keystroke
1031 * bit 1 Touchpad activity
1032 * bit 2 Pointing stick
1034 * bits 4-7 Reserved for future use
1035 * cbRES2, byte3 Current Timeout
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 byte
1043 * are set upon return from the [Get feature information] call.
1044 * cbRES3, byte0 Current setting of ALS value that turns the light on or off.
1045 * cbRES3, byte1 Current ALS reading
1046 * cbRES3, byte2 Current keyboard light level.
1048 * cbArg1 0x2 = Set New State
1049 * cbRES1 Standard return codes (0, -1, -2)
1050 * cbArg2, word0 Bitmap of current mode state
1051 * bit 0 Always off (All systems)
1052 * bit 1 Always on (Travis ATG, Siberia)
1053 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
1054 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
1055 * bit 4 Auto: Input-activity-based On; input-activity based Off
1056 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
1057 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
1058 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
1059 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
1060 * bits 9-15 Reserved for future use
1061 * Note: Only One bit can be set
1062 * cbArg2, byte2 Desired auto keyboard illumination triggers. Must remain inactive to allow
1063 * keyboard to turn off automatically.
1064 * bit 0 Any keystroke
1065 * bit 1 Touchpad activity
1066 * bit 2 Pointing stick
1068 * bits 4-7 Reserved for future use
1069 * cbArg2, byte3 Desired Timeout
1070 * bits 7:6 Timeout units indicator:
1075 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1076 * cbArg3, byte0 Desired setting of ALS value that turns the light on or off.
1077 * cbArg3, byte2 Desired keyboard light level.
1081 enum kbd_timeout_unit
{
1082 KBD_TIMEOUT_SECONDS
= 0,
1083 KBD_TIMEOUT_MINUTES
,
1089 KBD_MODE_BIT_OFF
= 0,
1092 KBD_MODE_BIT_TRIGGER_ALS
,
1093 KBD_MODE_BIT_TRIGGER
,
1094 KBD_MODE_BIT_TRIGGER_25
,
1095 KBD_MODE_BIT_TRIGGER_50
,
1096 KBD_MODE_BIT_TRIGGER_75
,
1097 KBD_MODE_BIT_TRIGGER_100
,
1100 #define kbd_is_als_mode_bit(bit) \
1101 ((bit) == KBD_MODE_BIT_ALS || (bit) == KBD_MODE_BIT_TRIGGER_ALS)
1102 #define kbd_is_trigger_mode_bit(bit) \
1103 ((bit) >= KBD_MODE_BIT_TRIGGER_ALS && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1104 #define kbd_is_level_mode_bit(bit) \
1105 ((bit) >= KBD_MODE_BIT_TRIGGER_25 && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1128 static const int kbd_tokens
[] = {
1130 KBD_LED_AUTO_25_TOKEN
,
1131 KBD_LED_AUTO_50_TOKEN
,
1132 KBD_LED_AUTO_75_TOKEN
,
1133 KBD_LED_AUTO_100_TOKEN
,
1137 static u16 kbd_token_bits
;
1139 static struct kbd_info kbd_info
;
1140 static bool kbd_als_supported
;
1141 static bool kbd_triggers_supported
;
1143 static u8 kbd_mode_levels
[16];
1144 static int kbd_mode_levels_count
;
1146 static u8 kbd_previous_level
;
1147 static u8 kbd_previous_mode_bit
;
1149 static bool kbd_led_present
;
1152 * NOTE: there are three ways to set the keyboard backlight level.
1153 * First, via kbd_state.mode_bit (assigning KBD_MODE_BIT_TRIGGER_* value).
1154 * Second, via kbd_state.level (assigning numerical value <= kbd_info.levels).
1155 * Third, via SMBIOS tokens (KBD_LED_* in kbd_tokens)
1157 * There are laptops which support only one of these methods. If we want to
1158 * support as many machines as possible we need to implement all three methods.
1159 * The first two methods use the kbd_state structure. The third uses SMBIOS
1160 * tokens. If kbd_info.levels == 0, the machine does not support setting the
1161 * keyboard backlight level via kbd_state.level.
1164 static int kbd_get_info(struct kbd_info
*info
)
1166 struct calling_interface_buffer
*buffer
;
1170 buffer
= dell_smbios_get_buffer();
1172 buffer
->input
[0] = 0x0;
1173 dell_smbios_send_request(4, 11);
1174 ret
= buffer
->output
[0];
1177 ret
= dell_smbios_error(ret
);
1181 info
->modes
= buffer
->output
[1] & 0xFFFF;
1182 info
->type
= (buffer
->output
[1] >> 24) & 0xFF;
1183 info
->triggers
= buffer
->output
[2] & 0xFF;
1184 units
= (buffer
->output
[2] >> 8) & 0xFF;
1185 info
->levels
= (buffer
->output
[2] >> 16) & 0xFF;
1187 if (quirks
&& quirks
->kbd_led_levels_off_1
&& info
->levels
)
1191 info
->seconds
= (buffer
->output
[3] >> 0) & 0xFF;
1193 info
->minutes
= (buffer
->output
[3] >> 8) & 0xFF;
1195 info
->hours
= (buffer
->output
[3] >> 16) & 0xFF;
1197 info
->days
= (buffer
->output
[3] >> 24) & 0xFF;
1200 dell_smbios_release_buffer();
1204 static unsigned int kbd_get_max_level(void)
1206 if (kbd_info
.levels
!= 0)
1207 return kbd_info
.levels
;
1208 if (kbd_mode_levels_count
> 0)
1209 return kbd_mode_levels_count
- 1;
1213 static int kbd_get_level(struct kbd_state
*state
)
1217 if (kbd_info
.levels
!= 0)
1218 return state
->level
;
1220 if (kbd_mode_levels_count
> 0) {
1221 for (i
= 0; i
< kbd_mode_levels_count
; ++i
)
1222 if (kbd_mode_levels
[i
] == state
->mode_bit
)
1230 static int kbd_set_level(struct kbd_state
*state
, u8 level
)
1232 if (kbd_info
.levels
!= 0) {
1234 kbd_previous_level
= level
;
1235 if (state
->level
== level
)
1237 state
->level
= level
;
1238 if (level
!= 0 && state
->mode_bit
== KBD_MODE_BIT_OFF
)
1239 state
->mode_bit
= kbd_previous_mode_bit
;
1240 else if (level
== 0 && state
->mode_bit
!= KBD_MODE_BIT_OFF
) {
1241 kbd_previous_mode_bit
= state
->mode_bit
;
1242 state
->mode_bit
= KBD_MODE_BIT_OFF
;
1247 if (kbd_mode_levels_count
> 0 && level
< kbd_mode_levels_count
) {
1249 kbd_previous_level
= level
;
1250 state
->mode_bit
= kbd_mode_levels
[level
];
1257 static int kbd_get_state(struct kbd_state
*state
)
1259 struct calling_interface_buffer
*buffer
;
1262 buffer
= dell_smbios_get_buffer();
1264 buffer
->input
[0] = 0x1;
1265 dell_smbios_send_request(4, 11);
1266 ret
= buffer
->output
[0];
1269 ret
= dell_smbios_error(ret
);
1273 state
->mode_bit
= ffs(buffer
->output
[1] & 0xFFFF);
1274 if (state
->mode_bit
!= 0)
1277 state
->triggers
= (buffer
->output
[1] >> 16) & 0xFF;
1278 state
->timeout_value
= (buffer
->output
[1] >> 24) & 0x3F;
1279 state
->timeout_unit
= (buffer
->output
[1] >> 30) & 0x3;
1280 state
->als_setting
= buffer
->output
[2] & 0xFF;
1281 state
->als_value
= (buffer
->output
[2] >> 8) & 0xFF;
1282 state
->level
= (buffer
->output
[2] >> 16) & 0xFF;
1285 dell_smbios_release_buffer();
1289 static int kbd_set_state(struct kbd_state
*state
)
1291 struct calling_interface_buffer
*buffer
;
1294 buffer
= dell_smbios_get_buffer();
1295 buffer
->input
[0] = 0x2;
1296 buffer
->input
[1] = BIT(state
->mode_bit
) & 0xFFFF;
1297 buffer
->input
[1] |= (state
->triggers
& 0xFF) << 16;
1298 buffer
->input
[1] |= (state
->timeout_value
& 0x3F) << 24;
1299 buffer
->input
[1] |= (state
->timeout_unit
& 0x3) << 30;
1300 buffer
->input
[2] = state
->als_setting
& 0xFF;
1301 buffer
->input
[2] |= (state
->level
& 0xFF) << 16;
1302 dell_smbios_send_request(4, 11);
1303 ret
= buffer
->output
[0];
1304 dell_smbios_release_buffer();
1306 return dell_smbios_error(ret
);
1309 static int kbd_set_state_safe(struct kbd_state
*state
, struct kbd_state
*old
)
1313 ret
= kbd_set_state(state
);
1318 * When setting the new state fails,try to restore the previous one.
1319 * This is needed on some machines where BIOS sets a default state when
1320 * setting a new state fails. This default state could be all off.
1323 if (kbd_set_state(old
))
1324 pr_err("Setting old previous keyboard state failed\n");
1329 static int kbd_set_token_bit(u8 bit
)
1331 struct calling_interface_buffer
*buffer
;
1332 struct calling_interface_token
*token
;
1335 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1338 token
= dell_smbios_find_token(kbd_tokens
[bit
]);
1342 buffer
= dell_smbios_get_buffer();
1343 buffer
->input
[0] = token
->location
;
1344 buffer
->input
[1] = token
->value
;
1345 dell_smbios_send_request(1, 0);
1346 ret
= buffer
->output
[0];
1347 dell_smbios_release_buffer();
1349 return dell_smbios_error(ret
);
1352 static int kbd_get_token_bit(u8 bit
)
1354 struct calling_interface_buffer
*buffer
;
1355 struct calling_interface_token
*token
;
1359 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1362 token
= dell_smbios_find_token(kbd_tokens
[bit
]);
1366 buffer
= dell_smbios_get_buffer();
1367 buffer
->input
[0] = token
->location
;
1368 dell_smbios_send_request(0, 0);
1369 ret
= buffer
->output
[0];
1370 val
= buffer
->output
[1];
1371 dell_smbios_release_buffer();
1374 return dell_smbios_error(ret
);
1376 return (val
== token
->value
);
1379 static int kbd_get_first_active_token_bit(void)
1384 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
) {
1385 ret
= kbd_get_token_bit(i
);
1393 static int kbd_get_valid_token_counts(void)
1395 return hweight16(kbd_token_bits
);
1398 static inline int kbd_init_info(void)
1400 struct kbd_state state
;
1404 ret
= kbd_get_info(&kbd_info
);
1408 kbd_get_state(&state
);
1410 /* NOTE: timeout value is stored in 6 bits so max value is 63 */
1411 if (kbd_info
.seconds
> 63)
1412 kbd_info
.seconds
= 63;
1413 if (kbd_info
.minutes
> 63)
1414 kbd_info
.minutes
= 63;
1415 if (kbd_info
.hours
> 63)
1416 kbd_info
.hours
= 63;
1417 if (kbd_info
.days
> 63)
1420 /* NOTE: On tested machines ON mode did not work and caused
1421 * problems (turned backlight off) so do not use it
1423 kbd_info
.modes
&= ~BIT(KBD_MODE_BIT_ON
);
1425 kbd_previous_level
= kbd_get_level(&state
);
1426 kbd_previous_mode_bit
= state
.mode_bit
;
1428 if (kbd_previous_level
== 0 && kbd_get_max_level() != 0)
1429 kbd_previous_level
= 1;
1431 if (kbd_previous_mode_bit
== KBD_MODE_BIT_OFF
) {
1432 kbd_previous_mode_bit
=
1433 ffs(kbd_info
.modes
& ~BIT(KBD_MODE_BIT_OFF
));
1434 if (kbd_previous_mode_bit
!= 0)
1435 kbd_previous_mode_bit
--;
1438 if (kbd_info
.modes
& (BIT(KBD_MODE_BIT_ALS
) |
1439 BIT(KBD_MODE_BIT_TRIGGER_ALS
)))
1440 kbd_als_supported
= true;
1442 if (kbd_info
.modes
& (
1443 BIT(KBD_MODE_BIT_TRIGGER_ALS
) | BIT(KBD_MODE_BIT_TRIGGER
) |
1444 BIT(KBD_MODE_BIT_TRIGGER_25
) | BIT(KBD_MODE_BIT_TRIGGER_50
) |
1445 BIT(KBD_MODE_BIT_TRIGGER_75
) | BIT(KBD_MODE_BIT_TRIGGER_100
)
1447 kbd_triggers_supported
= true;
1449 /* kbd_mode_levels[0] is reserved, see below */
1450 for (i
= 0; i
< 16; ++i
)
1451 if (kbd_is_level_mode_bit(i
) && (BIT(i
) & kbd_info
.modes
))
1452 kbd_mode_levels
[1 + kbd_mode_levels_count
++] = i
;
1455 * Find the first supported mode and assign to kbd_mode_levels[0].
1456 * This should be 0 (off), but we cannot depend on the BIOS to
1459 if (kbd_mode_levels_count
> 0) {
1460 for (i
= 0; i
< 16; ++i
) {
1461 if (BIT(i
) & kbd_info
.modes
) {
1462 kbd_mode_levels
[0] = i
;
1466 kbd_mode_levels_count
++;
1473 static inline void kbd_init_tokens(void)
1477 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
)
1478 if (dell_smbios_find_token(kbd_tokens
[i
]))
1479 kbd_token_bits
|= BIT(i
);
1482 static void kbd_init(void)
1486 ret
= kbd_init_info();
1489 if (kbd_token_bits
!= 0 || ret
== 0)
1490 kbd_led_present
= true;
1493 static ssize_t
kbd_led_timeout_store(struct device
*dev
,
1494 struct device_attribute
*attr
,
1495 const char *buf
, size_t count
)
1497 struct kbd_state new_state
;
1498 struct kbd_state state
;
1506 ret
= sscanf(buf
, "%d %c", &value
, &ch
);
1519 if (value
> kbd_info
.seconds
)
1521 unit
= KBD_TIMEOUT_SECONDS
;
1524 if (value
> kbd_info
.minutes
)
1526 unit
= KBD_TIMEOUT_MINUTES
;
1529 if (value
> kbd_info
.hours
)
1531 unit
= KBD_TIMEOUT_HOURS
;
1534 if (value
> kbd_info
.days
)
1536 unit
= KBD_TIMEOUT_DAYS
;
1542 if (quirks
&& quirks
->needs_kbd_timeouts
)
1546 /* Convert value from current units to seconds */
1548 case KBD_TIMEOUT_DAYS
:
1550 case KBD_TIMEOUT_HOURS
:
1552 case KBD_TIMEOUT_MINUTES
:
1554 unit
= KBD_TIMEOUT_SECONDS
;
1557 if (quirks
&& quirks
->needs_kbd_timeouts
) {
1558 for (i
= 0; quirks
->kbd_timeouts
[i
] != -1; i
++) {
1559 if (value
<= quirks
->kbd_timeouts
[i
]) {
1560 value
= quirks
->kbd_timeouts
[i
];
1566 if (value
<= kbd_info
.seconds
&& kbd_info
.seconds
) {
1567 unit
= KBD_TIMEOUT_SECONDS
;
1568 } else if (value
/ 60 <= kbd_info
.minutes
&& kbd_info
.minutes
) {
1570 unit
= KBD_TIMEOUT_MINUTES
;
1571 } else if (value
/ (60 * 60) <= kbd_info
.hours
&& kbd_info
.hours
) {
1573 unit
= KBD_TIMEOUT_HOURS
;
1574 } else if (value
/ (60 * 60 * 24) <= kbd_info
.days
&& kbd_info
.days
) {
1575 value
/= (60 * 60 * 24);
1576 unit
= KBD_TIMEOUT_DAYS
;
1582 ret
= kbd_get_state(&state
);
1587 new_state
.timeout_value
= value
;
1588 new_state
.timeout_unit
= unit
;
1590 ret
= kbd_set_state_safe(&new_state
, &state
);
1597 static ssize_t
kbd_led_timeout_show(struct device
*dev
,
1598 struct device_attribute
*attr
, char *buf
)
1600 struct kbd_state state
;
1604 ret
= kbd_get_state(&state
);
1608 len
= sprintf(buf
, "%d", state
.timeout_value
);
1610 switch (state
.timeout_unit
) {
1611 case KBD_TIMEOUT_SECONDS
:
1612 return len
+ sprintf(buf
+len
, "s\n");
1613 case KBD_TIMEOUT_MINUTES
:
1614 return len
+ sprintf(buf
+len
, "m\n");
1615 case KBD_TIMEOUT_HOURS
:
1616 return len
+ sprintf(buf
+len
, "h\n");
1617 case KBD_TIMEOUT_DAYS
:
1618 return len
+ sprintf(buf
+len
, "d\n");
1626 static DEVICE_ATTR(stop_timeout
, S_IRUGO
| S_IWUSR
,
1627 kbd_led_timeout_show
, kbd_led_timeout_store
);
1629 static const char * const kbd_led_triggers
[] = {
1632 /*"trackstick"*/ NULL
, /* NOTE: trackstick is just alias for touchpad */
1636 static ssize_t
kbd_led_triggers_store(struct device
*dev
,
1637 struct device_attribute
*attr
,
1638 const char *buf
, size_t count
)
1640 struct kbd_state new_state
;
1641 struct kbd_state state
;
1642 bool triggers_enabled
= false;
1643 int trigger_bit
= -1;
1647 ret
= sscanf(buf
, "%20s", trigger
);
1651 if (trigger
[0] != '+' && trigger
[0] != '-')
1654 ret
= kbd_get_state(&state
);
1658 if (kbd_triggers_supported
)
1659 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1661 if (kbd_triggers_supported
) {
1662 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1663 if (!(kbd_info
.triggers
& BIT(i
)))
1665 if (!kbd_led_triggers
[i
])
1667 if (strcmp(trigger
+1, kbd_led_triggers
[i
]) != 0)
1669 if (trigger
[0] == '+' &&
1670 triggers_enabled
&& (state
.triggers
& BIT(i
)))
1672 if (trigger
[0] == '-' &&
1673 (!triggers_enabled
|| !(state
.triggers
& BIT(i
))))
1680 if (trigger_bit
!= -1) {
1682 if (trigger
[0] == '+')
1683 new_state
.triggers
|= BIT(trigger_bit
);
1685 new_state
.triggers
&= ~BIT(trigger_bit
);
1686 /* NOTE: trackstick bit (2) must be disabled when
1687 * disabling touchpad bit (1), otherwise touchpad
1688 * bit (1) will not be disabled */
1689 if (trigger_bit
== 1)
1690 new_state
.triggers
&= ~BIT(2);
1692 if ((kbd_info
.triggers
& new_state
.triggers
) !=
1695 if (new_state
.triggers
&& !triggers_enabled
) {
1696 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1697 kbd_set_level(&new_state
, kbd_previous_level
);
1698 } else if (new_state
.triggers
== 0) {
1699 kbd_set_level(&new_state
, 0);
1701 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
)))
1703 ret
= kbd_set_state_safe(&new_state
, &state
);
1706 if (new_state
.mode_bit
!= KBD_MODE_BIT_OFF
)
1707 kbd_previous_mode_bit
= new_state
.mode_bit
;
1714 static ssize_t
kbd_led_triggers_show(struct device
*dev
,
1715 struct device_attribute
*attr
, char *buf
)
1717 struct kbd_state state
;
1718 bool triggers_enabled
;
1722 ret
= kbd_get_state(&state
);
1728 if (kbd_triggers_supported
) {
1729 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1730 level
= kbd_get_level(&state
);
1731 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1732 if (!(kbd_info
.triggers
& BIT(i
)))
1734 if (!kbd_led_triggers
[i
])
1736 if ((triggers_enabled
|| level
<= 0) &&
1737 (state
.triggers
& BIT(i
)))
1741 len
+= sprintf(buf
+len
, "%s ", kbd_led_triggers
[i
]);
1746 buf
[len
- 1] = '\n';
1751 static DEVICE_ATTR(start_triggers
, S_IRUGO
| S_IWUSR
,
1752 kbd_led_triggers_show
, kbd_led_triggers_store
);
1754 static ssize_t
kbd_led_als_enabled_store(struct device
*dev
,
1755 struct device_attribute
*attr
,
1756 const char *buf
, size_t count
)
1758 struct kbd_state new_state
;
1759 struct kbd_state state
;
1760 bool triggers_enabled
= false;
1764 ret
= kstrtoint(buf
, 0, &enable
);
1768 ret
= kbd_get_state(&state
);
1772 if (enable
== kbd_is_als_mode_bit(state
.mode_bit
))
1777 if (kbd_triggers_supported
)
1778 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1781 if (triggers_enabled
)
1782 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER_ALS
;
1784 new_state
.mode_bit
= KBD_MODE_BIT_ALS
;
1786 if (triggers_enabled
) {
1787 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1788 kbd_set_level(&new_state
, kbd_previous_level
);
1790 new_state
.mode_bit
= KBD_MODE_BIT_ON
;
1793 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
)))
1796 ret
= kbd_set_state_safe(&new_state
, &state
);
1799 kbd_previous_mode_bit
= new_state
.mode_bit
;
1804 static ssize_t
kbd_led_als_enabled_show(struct device
*dev
,
1805 struct device_attribute
*attr
,
1808 struct kbd_state state
;
1809 bool enabled
= false;
1812 ret
= kbd_get_state(&state
);
1815 enabled
= kbd_is_als_mode_bit(state
.mode_bit
);
1817 return sprintf(buf
, "%d\n", enabled
? 1 : 0);
1820 static DEVICE_ATTR(als_enabled
, S_IRUGO
| S_IWUSR
,
1821 kbd_led_als_enabled_show
, kbd_led_als_enabled_store
);
1823 static ssize_t
kbd_led_als_setting_store(struct device
*dev
,
1824 struct device_attribute
*attr
,
1825 const char *buf
, size_t count
)
1827 struct kbd_state state
;
1828 struct kbd_state new_state
;
1832 ret
= kstrtou8(buf
, 10, &setting
);
1836 ret
= kbd_get_state(&state
);
1841 new_state
.als_setting
= setting
;
1843 ret
= kbd_set_state_safe(&new_state
, &state
);
1850 static ssize_t
kbd_led_als_setting_show(struct device
*dev
,
1851 struct device_attribute
*attr
,
1854 struct kbd_state state
;
1857 ret
= kbd_get_state(&state
);
1861 return sprintf(buf
, "%d\n", state
.als_setting
);
1864 static DEVICE_ATTR(als_setting
, S_IRUGO
| S_IWUSR
,
1865 kbd_led_als_setting_show
, kbd_led_als_setting_store
);
1867 static struct attribute
*kbd_led_attrs
[] = {
1868 &dev_attr_stop_timeout
.attr
,
1869 &dev_attr_start_triggers
.attr
,
1873 static const struct attribute_group kbd_led_group
= {
1874 .attrs
= kbd_led_attrs
,
1877 static struct attribute
*kbd_led_als_attrs
[] = {
1878 &dev_attr_als_enabled
.attr
,
1879 &dev_attr_als_setting
.attr
,
1883 static const struct attribute_group kbd_led_als_group
= {
1884 .attrs
= kbd_led_als_attrs
,
1887 static const struct attribute_group
*kbd_led_groups
[] = {
1893 static enum led_brightness
kbd_led_level_get(struct led_classdev
*led_cdev
)
1897 struct kbd_state state
;
1899 if (kbd_get_max_level()) {
1900 ret
= kbd_get_state(&state
);
1903 ret
= kbd_get_level(&state
);
1909 if (kbd_get_valid_token_counts()) {
1910 ret
= kbd_get_first_active_token_bit();
1913 for (num
= kbd_token_bits
; num
!= 0 && ret
> 0; --ret
)
1914 num
&= num
- 1; /* clear the first bit set */
1917 return ffs(num
) - 1;
1920 pr_warn("Keyboard brightness level control not supported\n");
1924 static void kbd_led_level_set(struct led_classdev
*led_cdev
,
1925 enum led_brightness value
)
1927 struct kbd_state state
;
1928 struct kbd_state new_state
;
1931 if (kbd_get_max_level()) {
1932 if (kbd_get_state(&state
))
1935 if (kbd_set_level(&new_state
, value
))
1937 kbd_set_state_safe(&new_state
, &state
);
1941 if (kbd_get_valid_token_counts()) {
1942 for (num
= kbd_token_bits
; num
!= 0 && value
> 0; --value
)
1943 num
&= num
- 1; /* clear the first bit set */
1946 kbd_set_token_bit(ffs(num
) - 1);
1950 pr_warn("Keyboard brightness level control not supported\n");
1953 static struct led_classdev kbd_led
= {
1954 .name
= "dell::kbd_backlight",
1955 .brightness_set
= kbd_led_level_set
,
1956 .brightness_get
= kbd_led_level_get
,
1957 .groups
= kbd_led_groups
,
1960 static int __init
kbd_led_init(struct device
*dev
)
1963 if (!kbd_led_present
)
1965 if (!kbd_als_supported
)
1966 kbd_led_groups
[1] = NULL
;
1967 kbd_led
.max_brightness
= kbd_get_max_level();
1968 if (!kbd_led
.max_brightness
) {
1969 kbd_led
.max_brightness
= kbd_get_valid_token_counts();
1970 if (kbd_led
.max_brightness
)
1971 kbd_led
.max_brightness
--;
1973 return led_classdev_register(dev
, &kbd_led
);
1976 static void brightness_set_exit(struct led_classdev
*led_cdev
,
1977 enum led_brightness value
)
1979 /* Don't change backlight level on exit */
1982 static void kbd_led_exit(void)
1984 if (!kbd_led_present
)
1986 kbd_led
.brightness_set
= brightness_set_exit
;
1987 led_classdev_unregister(&kbd_led
);
1990 static int __init
dell_init(void)
1992 struct calling_interface_buffer
*buffer
;
1993 struct calling_interface_token
*token
;
1994 int max_intensity
= 0;
1997 if (!dmi_check_system(dell_device_table
))
2001 /* find if this machine support other functions */
2002 dmi_check_system(dell_quirks
);
2004 ret
= platform_driver_register(&platform_driver
);
2006 goto fail_platform_driver
;
2007 platform_device
= platform_device_alloc("dell-laptop", -1);
2008 if (!platform_device
) {
2010 goto fail_platform_device1
;
2012 ret
= platform_device_add(platform_device
);
2014 goto fail_platform_device2
;
2016 ret
= dell_setup_rfkill();
2019 pr_warn("Unable to setup rfkill\n");
2023 if (quirks
&& quirks
->touchpad_led
)
2024 touchpad_led_init(&platform_device
->dev
);
2026 kbd_led_init(&platform_device
->dev
);
2028 dell_laptop_dir
= debugfs_create_dir("dell_laptop", NULL
);
2029 if (dell_laptop_dir
!= NULL
)
2030 debugfs_create_file("rfkill", 0444, dell_laptop_dir
, NULL
,
2031 &dell_debugfs_fops
);
2033 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2036 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
2038 buffer
= dell_smbios_get_buffer();
2039 buffer
->input
[0] = token
->location
;
2040 dell_smbios_send_request(0, 2);
2041 if (buffer
->output
[0] == 0)
2042 max_intensity
= buffer
->output
[3];
2043 dell_smbios_release_buffer();
2046 if (max_intensity
) {
2047 struct backlight_properties props
;
2048 memset(&props
, 0, sizeof(struct backlight_properties
));
2049 props
.type
= BACKLIGHT_PLATFORM
;
2050 props
.max_brightness
= max_intensity
;
2051 dell_backlight_device
= backlight_device_register("dell_backlight",
2052 &platform_device
->dev
,
2057 if (IS_ERR(dell_backlight_device
)) {
2058 ret
= PTR_ERR(dell_backlight_device
);
2059 dell_backlight_device
= NULL
;
2060 goto fail_backlight
;
2063 dell_backlight_device
->props
.brightness
=
2064 dell_get_intensity(dell_backlight_device
);
2065 backlight_update_status(dell_backlight_device
);
2071 dell_cleanup_rfkill();
2073 platform_device_del(platform_device
);
2074 fail_platform_device2
:
2075 platform_device_put(platform_device
);
2076 fail_platform_device1
:
2077 platform_driver_unregister(&platform_driver
);
2078 fail_platform_driver
:
2082 static void __exit
dell_exit(void)
2084 debugfs_remove_recursive(dell_laptop_dir
);
2085 if (quirks
&& quirks
->touchpad_led
)
2086 touchpad_led_exit();
2088 backlight_device_unregister(dell_backlight_device
);
2089 dell_cleanup_rfkill();
2090 if (platform_device
) {
2091 platform_device_unregister(platform_device
);
2092 platform_driver_unregister(&platform_driver
);
2096 /* dell-rbtn.c driver export functions which will not work correctly (and could
2097 * cause kernel crash) if they are called before dell-rbtn.c init code. This is
2098 * not problem when dell-rbtn.c is compiled as external module. When both files
2099 * (dell-rbtn.c and dell-laptop.c) are compiled statically into kernel, then we
2100 * need to ensure that dell_init() will be called after initializing dell-rbtn.
2101 * This can be achieved by late_initcall() instead module_init().
2103 late_initcall(dell_init
);
2104 module_exit(dell_exit
);
2106 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
2107 MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
2108 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
2109 MODULE_DESCRIPTION("Dell laptop driver");
2110 MODULE_LICENSE("GPL");