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
49 int needs_kbd_timeouts
;
51 * Ordered list of timeouts expressed in seconds.
52 * The list must end with -1
57 static struct quirk_entry
*quirks
;
59 static struct quirk_entry quirk_dell_vostro_v130
= {
63 static int __init
dmi_matched(const struct dmi_system_id
*dmi
)
65 quirks
= dmi
->driver_data
;
70 * These values come from Windows utility provided by Dell. If any other value
71 * is used then BIOS silently set timeout to 0 without any error message.
73 static struct quirk_entry quirk_dell_xps13_9333
= {
74 .needs_kbd_timeouts
= 1,
75 .kbd_timeouts
= { 0, 5, 15, 60, 5 * 60, 15 * 60, -1 },
78 static struct platform_driver platform_driver
= {
80 .name
= "dell-laptop",
84 static struct platform_device
*platform_device
;
85 static struct backlight_device
*dell_backlight_device
;
86 static struct rfkill
*wifi_rfkill
;
87 static struct rfkill
*bluetooth_rfkill
;
88 static struct rfkill
*wwan_rfkill
;
89 static bool force_rfkill
;
91 module_param(force_rfkill
, bool, 0444);
92 MODULE_PARM_DESC(force_rfkill
, "enable rfkill on non whitelisted models");
94 static const struct dmi_system_id dell_device_table
[] __initconst
= {
96 .ident
= "Dell laptop",
98 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
99 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
104 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
105 DMI_MATCH(DMI_CHASSIS_TYPE
, "9"), /*Laptop*/
109 .ident
= "Dell Computer Corporation",
111 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer Corporation"),
112 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
117 MODULE_DEVICE_TABLE(dmi
, dell_device_table
);
119 static const struct dmi_system_id dell_quirks
[] __initconst
= {
121 .callback
= dmi_matched
,
122 .ident
= "Dell Vostro V130",
124 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
125 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V130"),
127 .driver_data
= &quirk_dell_vostro_v130
,
130 .callback
= dmi_matched
,
131 .ident
= "Dell Vostro V131",
133 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
134 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V131"),
136 .driver_data
= &quirk_dell_vostro_v130
,
139 .callback
= dmi_matched
,
140 .ident
= "Dell Vostro 3350",
142 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
143 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3350"),
145 .driver_data
= &quirk_dell_vostro_v130
,
148 .callback
= dmi_matched
,
149 .ident
= "Dell Vostro 3555",
151 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
152 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3555"),
154 .driver_data
= &quirk_dell_vostro_v130
,
157 .callback
= dmi_matched
,
158 .ident
= "Dell Inspiron N311z",
160 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
161 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron N311z"),
163 .driver_data
= &quirk_dell_vostro_v130
,
166 .callback
= dmi_matched
,
167 .ident
= "Dell Inspiron M5110",
169 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
170 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron M5110"),
172 .driver_data
= &quirk_dell_vostro_v130
,
175 .callback
= dmi_matched
,
176 .ident
= "Dell Vostro 3360",
178 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
179 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3360"),
181 .driver_data
= &quirk_dell_vostro_v130
,
184 .callback
= dmi_matched
,
185 .ident
= "Dell Vostro 3460",
187 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
188 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3460"),
190 .driver_data
= &quirk_dell_vostro_v130
,
193 .callback
= dmi_matched
,
194 .ident
= "Dell Vostro 3560",
196 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
197 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3560"),
199 .driver_data
= &quirk_dell_vostro_v130
,
202 .callback
= dmi_matched
,
203 .ident
= "Dell Vostro 3450",
205 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
206 DMI_MATCH(DMI_PRODUCT_NAME
, "Dell System Vostro 3450"),
208 .driver_data
= &quirk_dell_vostro_v130
,
211 .callback
= dmi_matched
,
212 .ident
= "Dell Inspiron 5420",
214 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
215 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5420"),
217 .driver_data
= &quirk_dell_vostro_v130
,
220 .callback
= dmi_matched
,
221 .ident
= "Dell Inspiron 5520",
223 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
224 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5520"),
226 .driver_data
= &quirk_dell_vostro_v130
,
229 .callback
= dmi_matched
,
230 .ident
= "Dell Inspiron 5720",
232 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
233 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5720"),
235 .driver_data
= &quirk_dell_vostro_v130
,
238 .callback
= dmi_matched
,
239 .ident
= "Dell Inspiron 7420",
241 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
242 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7420"),
244 .driver_data
= &quirk_dell_vostro_v130
,
247 .callback
= dmi_matched
,
248 .ident
= "Dell Inspiron 7520",
250 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
251 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7520"),
253 .driver_data
= &quirk_dell_vostro_v130
,
256 .callback
= dmi_matched
,
257 .ident
= "Dell Inspiron 7720",
259 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
260 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7720"),
262 .driver_data
= &quirk_dell_vostro_v130
,
265 .callback
= dmi_matched
,
266 .ident
= "Dell XPS13 9333",
268 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
269 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS13 9333"),
271 .driver_data
= &quirk_dell_xps13_9333
,
276 static inline int dell_smi_error(int value
)
279 case 0: /* Completed successfully */
281 case -1: /* Completed with error */
283 case -2: /* Function not supported */
285 default: /* Unknown error */
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 int disable
= blocked
? 1 : 0;
413 unsigned long radio
= (unsigned long)data
;
414 int hwswitch_bit
= (unsigned long)data
- 1;
421 dell_send_request(buffer
, 17, 11);
422 ret
= buffer
->output
[0];
423 status
= buffer
->output
[1];
430 buffer
->input
[0] = 0x2;
431 dell_send_request(buffer
, 17, 11);
432 ret
= buffer
->output
[0];
433 hwswitch
= buffer
->output
[1];
435 /* If the hardware switch controls this radio, and the hardware
436 switch is disabled, always disable the radio */
437 if (ret
== 0 && (hwswitch
& BIT(hwswitch_bit
)) &&
438 (status
& BIT(0)) && !(status
& BIT(16)))
443 buffer
->input
[0] = (1 | (radio
<<8) | (disable
<< 16));
444 dell_send_request(buffer
, 17, 11);
445 ret
= buffer
->output
[0];
449 return dell_smi_error(ret
);
452 /* Must be called with the buffer held */
453 static void dell_rfkill_update_sw_state(struct rfkill
*rfkill
, int radio
,
456 if (status
& BIT(0)) {
457 /* Has hw-switch, sync sw_state to BIOS */
458 int block
= rfkill_blocked(rfkill
);
460 buffer
->input
[0] = (1 | (radio
<< 8) | (block
<< 16));
461 dell_send_request(buffer
, 17, 11);
463 /* No hw-switch, sync BIOS state to sw_state */
464 rfkill_set_sw_state(rfkill
, !!(status
& BIT(radio
+ 16)));
468 static void dell_rfkill_update_hw_state(struct rfkill
*rfkill
, int radio
,
469 int status
, int hwswitch
)
471 if (hwswitch
& (BIT(radio
- 1)))
472 rfkill_set_hw_state(rfkill
, !(status
& BIT(16)));
475 static void dell_rfkill_query(struct rfkill
*rfkill
, void *data
)
477 int radio
= ((unsigned long)data
& 0xF);
484 dell_send_request(buffer
, 17, 11);
485 ret
= buffer
->output
[0];
486 status
= buffer
->output
[1];
488 if (ret
!= 0 || !(status
& BIT(0))) {
495 buffer
->input
[0] = 0x2;
496 dell_send_request(buffer
, 17, 11);
497 ret
= buffer
->output
[0];
498 hwswitch
= buffer
->output
[1];
505 dell_rfkill_update_hw_state(rfkill
, radio
, status
, hwswitch
);
508 static const struct rfkill_ops dell_rfkill_ops
= {
509 .set_block
= dell_rfkill_set
,
510 .query
= dell_rfkill_query
,
513 static struct dentry
*dell_laptop_dir
;
515 static int dell_debugfs_show(struct seq_file
*s
, void *data
)
524 dell_send_request(buffer
, 17, 11);
525 ret
= buffer
->output
[0];
526 status
= buffer
->output
[1];
530 buffer
->input
[0] = 0x2;
531 dell_send_request(buffer
, 17, 11);
532 hwswitch_ret
= buffer
->output
[0];
533 hwswitch_state
= buffer
->output
[1];
537 seq_printf(s
, "return:\t%d\n", ret
);
538 seq_printf(s
, "status:\t0x%X\n", status
);
539 seq_printf(s
, "Bit 0 : Hardware switch supported: %lu\n",
541 seq_printf(s
, "Bit 1 : Wifi locator supported: %lu\n",
542 (status
& BIT(1)) >> 1);
543 seq_printf(s
, "Bit 2 : Wifi is supported: %lu\n",
544 (status
& BIT(2)) >> 2);
545 seq_printf(s
, "Bit 3 : Bluetooth is supported: %lu\n",
546 (status
& BIT(3)) >> 3);
547 seq_printf(s
, "Bit 4 : WWAN is supported: %lu\n",
548 (status
& BIT(4)) >> 4);
549 seq_printf(s
, "Bit 5 : Wireless keyboard supported: %lu\n",
550 (status
& BIT(5)) >> 5);
551 seq_printf(s
, "Bit 6 : UWB supported: %lu\n",
552 (status
& BIT(6)) >> 6);
553 seq_printf(s
, "Bit 7 : WiGig supported: %lu\n",
554 (status
& BIT(7)) >> 7);
555 seq_printf(s
, "Bit 8 : Wifi is installed: %lu\n",
556 (status
& BIT(8)) >> 8);
557 seq_printf(s
, "Bit 9 : Bluetooth is installed: %lu\n",
558 (status
& BIT(9)) >> 9);
559 seq_printf(s
, "Bit 10: WWAN is installed: %lu\n",
560 (status
& BIT(10)) >> 10);
561 seq_printf(s
, "Bit 11: UWB installed: %lu\n",
562 (status
& BIT(11)) >> 11);
563 seq_printf(s
, "Bit 12: WiGig installed: %lu\n",
564 (status
& BIT(12)) >> 12);
566 seq_printf(s
, "Bit 16: Hardware switch is on: %lu\n",
567 (status
& BIT(16)) >> 16);
568 seq_printf(s
, "Bit 17: Wifi is blocked: %lu\n",
569 (status
& BIT(17)) >> 17);
570 seq_printf(s
, "Bit 18: Bluetooth is blocked: %lu\n",
571 (status
& BIT(18)) >> 18);
572 seq_printf(s
, "Bit 19: WWAN is blocked: %lu\n",
573 (status
& BIT(19)) >> 19);
574 seq_printf(s
, "Bit 20: UWB is blocked: %lu\n",
575 (status
& BIT(20)) >> 20);
576 seq_printf(s
, "Bit 21: WiGig is blocked: %lu\n",
577 (status
& BIT(21)) >> 21);
579 seq_printf(s
, "\nhwswitch_return:\t%d\n", hwswitch_ret
);
580 seq_printf(s
, "hwswitch_state:\t0x%X\n", hwswitch_state
);
581 seq_printf(s
, "Bit 0 : Wifi controlled by switch: %lu\n",
582 hwswitch_state
& BIT(0));
583 seq_printf(s
, "Bit 1 : Bluetooth controlled by switch: %lu\n",
584 (hwswitch_state
& BIT(1)) >> 1);
585 seq_printf(s
, "Bit 2 : WWAN controlled by switch: %lu\n",
586 (hwswitch_state
& BIT(2)) >> 2);
587 seq_printf(s
, "Bit 3 : UWB controlled by switch: %lu\n",
588 (hwswitch_state
& BIT(3)) >> 3);
589 seq_printf(s
, "Bit 4 : WiGig controlled by switch: %lu\n",
590 (hwswitch_state
& BIT(4)) >> 4);
591 seq_printf(s
, "Bit 7 : Wireless switch config locked: %lu\n",
592 (hwswitch_state
& BIT(7)) >> 7);
593 seq_printf(s
, "Bit 8 : Wifi locator enabled: %lu\n",
594 (hwswitch_state
& BIT(8)) >> 8);
595 seq_printf(s
, "Bit 15: Wifi locator setting locked: %lu\n",
596 (hwswitch_state
& BIT(15)) >> 15);
601 static int dell_debugfs_open(struct inode
*inode
, struct file
*file
)
603 return single_open(file
, dell_debugfs_show
, inode
->i_private
);
606 static const struct file_operations dell_debugfs_fops
= {
607 .owner
= THIS_MODULE
,
608 .open
= dell_debugfs_open
,
611 .release
= single_release
,
614 static void dell_update_rfkill(struct work_struct
*ignored
)
622 dell_send_request(buffer
, 17, 11);
623 ret
= buffer
->output
[0];
624 status
= buffer
->output
[1];
631 buffer
->input
[0] = 0x2;
632 dell_send_request(buffer
, 17, 11);
633 ret
= buffer
->output
[0];
635 if (ret
== 0 && (status
& BIT(0)))
636 hwswitch
= buffer
->output
[1];
639 dell_rfkill_update_hw_state(wifi_rfkill
, 1, status
, hwswitch
);
640 dell_rfkill_update_sw_state(wifi_rfkill
, 1, status
);
642 if (bluetooth_rfkill
) {
643 dell_rfkill_update_hw_state(bluetooth_rfkill
, 2, status
,
645 dell_rfkill_update_sw_state(bluetooth_rfkill
, 2, status
);
648 dell_rfkill_update_hw_state(wwan_rfkill
, 3, status
, hwswitch
);
649 dell_rfkill_update_sw_state(wwan_rfkill
, 3, status
);
655 static DECLARE_DELAYED_WORK(dell_rfkill_work
, dell_update_rfkill
);
657 static bool dell_laptop_i8042_filter(unsigned char data
, unsigned char str
,
660 static bool extended
;
662 if (str
& I8042_STR_AUXDATA
)
665 if (unlikely(data
== 0xe0)) {
668 } else if (unlikely(extended
)) {
671 schedule_delayed_work(&dell_rfkill_work
,
672 round_jiffies_relative(HZ
/ 4));
681 static int (*dell_rbtn_notifier_register_func
)(struct notifier_block
*);
682 static int (*dell_rbtn_notifier_unregister_func
)(struct notifier_block
*);
684 static int dell_laptop_rbtn_notifier_call(struct notifier_block
*nb
,
685 unsigned long action
, void *data
)
687 schedule_delayed_work(&dell_rfkill_work
, 0);
691 static struct notifier_block dell_laptop_rbtn_notifier
= {
692 .notifier_call
= dell_laptop_rbtn_notifier_call
,
695 static int __init
dell_setup_rfkill(void)
697 int status
, ret
, whitelisted
;
701 * rfkill support causes trouble on various models, mostly Inspirons.
702 * So we whitelist certain series, and don't support rfkill on others.
705 product
= dmi_get_system_info(DMI_PRODUCT_NAME
);
706 if (product
&& (strncmp(product
, "Latitude", 8) == 0 ||
707 strncmp(product
, "Precision", 9) == 0))
709 if (!force_rfkill
&& !whitelisted
)
713 dell_send_request(buffer
, 17, 11);
714 ret
= buffer
->output
[0];
715 status
= buffer
->output
[1];
718 /* dell wireless info smbios call is not supported */
722 /* rfkill is only tested on laptops with a hwswitch */
723 if (!(status
& BIT(0)) && !force_rfkill
)
726 if ((status
& (1<<2|1<<8)) == (1<<2|1<<8)) {
727 wifi_rfkill
= rfkill_alloc("dell-wifi", &platform_device
->dev
,
729 &dell_rfkill_ops
, (void *) 1);
734 ret
= rfkill_register(wifi_rfkill
);
739 if ((status
& (1<<3|1<<9)) == (1<<3|1<<9)) {
740 bluetooth_rfkill
= rfkill_alloc("dell-bluetooth",
741 &platform_device
->dev
,
742 RFKILL_TYPE_BLUETOOTH
,
743 &dell_rfkill_ops
, (void *) 2);
744 if (!bluetooth_rfkill
) {
748 ret
= rfkill_register(bluetooth_rfkill
);
753 if ((status
& (1<<4|1<<10)) == (1<<4|1<<10)) {
754 wwan_rfkill
= rfkill_alloc("dell-wwan",
755 &platform_device
->dev
,
757 &dell_rfkill_ops
, (void *) 3);
762 ret
= rfkill_register(wwan_rfkill
);
768 * Dell Airplane Mode Switch driver (dell-rbtn) supports ACPI devices
769 * which can receive events from HW slider switch.
771 * Dell SMBIOS on whitelisted models supports controlling radio devices
772 * but does not support receiving HW button switch events. We can use
773 * i8042 filter hook function to receive keyboard data and handle
774 * keycode for HW button.
776 * So if it is possible we will use Dell Airplane Mode Switch ACPI
777 * driver for receiving HW events and Dell SMBIOS for setting rfkill
778 * states. If ACPI driver or device is not available we will fallback to
779 * i8042 filter hook function.
781 * To prevent duplicate rfkill devices which control and do same thing,
782 * dell-rbtn driver will automatically remove its own rfkill devices
783 * once function dell_rbtn_notifier_register() is called.
786 dell_rbtn_notifier_register_func
=
787 symbol_request(dell_rbtn_notifier_register
);
788 if (dell_rbtn_notifier_register_func
) {
789 dell_rbtn_notifier_unregister_func
=
790 symbol_request(dell_rbtn_notifier_unregister
);
791 if (!dell_rbtn_notifier_unregister_func
) {
792 symbol_put(dell_rbtn_notifier_register
);
793 dell_rbtn_notifier_register_func
= NULL
;
797 if (dell_rbtn_notifier_register_func
) {
798 ret
= dell_rbtn_notifier_register_func(
799 &dell_laptop_rbtn_notifier
);
800 symbol_put(dell_rbtn_notifier_register
);
801 dell_rbtn_notifier_register_func
= NULL
;
803 symbol_put(dell_rbtn_notifier_unregister
);
804 dell_rbtn_notifier_unregister_func
= NULL
;
807 pr_info("Symbols from dell-rbtn acpi driver are not available\n");
812 pr_info("Using dell-rbtn acpi driver for receiving events\n");
813 } else if (ret
!= -ENODEV
) {
814 pr_warn("Unable to register dell rbtn notifier\n");
817 ret
= i8042_install_filter(dell_laptop_i8042_filter
);
819 pr_warn("Unable to install key filter\n");
822 pr_info("Using i8042 filter function for receiving events\n");
828 rfkill_unregister(wwan_rfkill
);
830 rfkill_destroy(wwan_rfkill
);
831 if (bluetooth_rfkill
)
832 rfkill_unregister(bluetooth_rfkill
);
834 rfkill_destroy(bluetooth_rfkill
);
836 rfkill_unregister(wifi_rfkill
);
838 rfkill_destroy(wifi_rfkill
);
843 static void dell_cleanup_rfkill(void)
845 if (dell_rbtn_notifier_unregister_func
) {
846 dell_rbtn_notifier_unregister_func(&dell_laptop_rbtn_notifier
);
847 symbol_put(dell_rbtn_notifier_unregister
);
848 dell_rbtn_notifier_unregister_func
= NULL
;
850 i8042_remove_filter(dell_laptop_i8042_filter
);
852 cancel_delayed_work_sync(&dell_rfkill_work
);
854 rfkill_unregister(wifi_rfkill
);
855 rfkill_destroy(wifi_rfkill
);
857 if (bluetooth_rfkill
) {
858 rfkill_unregister(bluetooth_rfkill
);
859 rfkill_destroy(bluetooth_rfkill
);
862 rfkill_unregister(wwan_rfkill
);
863 rfkill_destroy(wwan_rfkill
);
867 static int dell_send_intensity(struct backlight_device
*bd
)
872 token
= find_token_location(BRIGHTNESS_TOKEN
);
877 buffer
->input
[0] = token
;
878 buffer
->input
[1] = bd
->props
.brightness
;
880 if (power_supply_is_system_supplied() > 0)
881 dell_send_request(buffer
, 1, 2);
883 dell_send_request(buffer
, 1, 1);
885 ret
= dell_smi_error(buffer
->output
[0]);
891 static int dell_get_intensity(struct backlight_device
*bd
)
896 token
= find_token_location(BRIGHTNESS_TOKEN
);
901 buffer
->input
[0] = token
;
903 if (power_supply_is_system_supplied() > 0)
904 dell_send_request(buffer
, 0, 2);
906 dell_send_request(buffer
, 0, 1);
908 if (buffer
->output
[0])
909 ret
= dell_smi_error(buffer
->output
[0]);
911 ret
= buffer
->output
[1];
917 static const struct backlight_ops dell_ops
= {
918 .get_brightness
= dell_get_intensity
,
919 .update_status
= dell_send_intensity
,
922 static void touchpad_led_on(void)
926 i8042_command(&data
, command
| 1 << 12);
929 static void touchpad_led_off(void)
933 i8042_command(&data
, command
| 1 << 12);
936 static void touchpad_led_set(struct led_classdev
*led_cdev
,
937 enum led_brightness value
)
945 static struct led_classdev touchpad_led
= {
946 .name
= "dell-laptop::touchpad",
947 .brightness_set
= touchpad_led_set
,
948 .flags
= LED_CORE_SUSPENDRESUME
,
951 static int __init
touchpad_led_init(struct device
*dev
)
953 return led_classdev_register(dev
, &touchpad_led
);
956 static void touchpad_led_exit(void)
958 led_classdev_unregister(&touchpad_led
);
962 * Derived from information in smbios-keyboard-ctl:
966 * Keyboard illumination
967 * cbArg1 determines the function to be performed
969 * cbArg1 0x0 = Get Feature Information
970 * cbRES1 Standard return codes (0, -1, -2)
971 * cbRES2, word0 Bitmap of user-selectable modes
972 * bit 0 Always off (All systems)
973 * bit 1 Always on (Travis ATG, Siberia)
974 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
975 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
976 * bit 4 Auto: Input-activity-based On; input-activity based Off
977 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
978 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
979 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
980 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
981 * bits 9-15 Reserved for future use
982 * cbRES2, byte2 Reserved for future use
983 * cbRES2, byte3 Keyboard illumination type
987 * 3-255 Reserved for future use
988 * cbRES3, byte0 Supported auto keyboard illumination trigger bitmap.
989 * bit 0 Any keystroke
990 * bit 1 Touchpad activity
991 * bit 2 Pointing stick
993 * bits 4-7 Reserved for future use
994 * cbRES3, byte1 Supported timeout unit bitmap
999 * bits 4-7 Reserved for future use
1000 * cbRES3, byte2 Number of keyboard light brightness levels
1001 * cbRES4, byte0 Maximum acceptable seconds value (0 if seconds not supported).
1002 * cbRES4, byte1 Maximum acceptable minutes value (0 if minutes not supported).
1003 * cbRES4, byte2 Maximum acceptable hours value (0 if hours not supported).
1004 * cbRES4, byte3 Maximum acceptable days value (0 if days not supported)
1006 * cbArg1 0x1 = Get Current State
1007 * cbRES1 Standard return codes (0, -1, -2)
1008 * cbRES2, word0 Bitmap of current mode state
1009 * bit 0 Always off (All systems)
1010 * bit 1 Always on (Travis ATG, Siberia)
1011 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
1012 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
1013 * bit 4 Auto: Input-activity-based On; input-activity based Off
1014 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
1015 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
1016 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
1017 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
1018 * bits 9-15 Reserved for future use
1019 * Note: Only One bit can be set
1020 * cbRES2, byte2 Currently active auto keyboard illumination triggers.
1021 * bit 0 Any keystroke
1022 * bit 1 Touchpad activity
1023 * bit 2 Pointing stick
1025 * bits 4-7 Reserved for future use
1026 * cbRES2, byte3 Current Timeout
1027 * bits 7:6 Timeout units indicator:
1032 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1033 * NOTE: A value of 0 means always on (no timeout) if any bits of RES3 byte
1034 * are set upon return from the [Get feature information] call.
1035 * cbRES3, byte0 Current setting of ALS value that turns the light on or off.
1036 * cbRES3, byte1 Current ALS reading
1037 * cbRES3, byte2 Current keyboard light level.
1039 * cbArg1 0x2 = Set New State
1040 * cbRES1 Standard return codes (0, -1, -2)
1041 * cbArg2, word0 Bitmap of current mode state
1042 * bit 0 Always off (All systems)
1043 * bit 1 Always on (Travis ATG, Siberia)
1044 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
1045 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
1046 * bit 4 Auto: Input-activity-based On; input-activity based Off
1047 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
1048 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
1049 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
1050 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
1051 * bits 9-15 Reserved for future use
1052 * Note: Only One bit can be set
1053 * cbArg2, byte2 Desired auto keyboard illumination triggers. Must remain inactive to allow
1054 * keyboard to turn off automatically.
1055 * bit 0 Any keystroke
1056 * bit 1 Touchpad activity
1057 * bit 2 Pointing stick
1059 * bits 4-7 Reserved for future use
1060 * cbArg2, byte3 Desired Timeout
1061 * bits 7:6 Timeout units indicator:
1066 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1067 * cbArg3, byte0 Desired setting of ALS value that turns the light on or off.
1068 * cbArg3, byte2 Desired keyboard light level.
1072 enum kbd_timeout_unit
{
1073 KBD_TIMEOUT_SECONDS
= 0,
1074 KBD_TIMEOUT_MINUTES
,
1080 KBD_MODE_BIT_OFF
= 0,
1083 KBD_MODE_BIT_TRIGGER_ALS
,
1084 KBD_MODE_BIT_TRIGGER
,
1085 KBD_MODE_BIT_TRIGGER_25
,
1086 KBD_MODE_BIT_TRIGGER_50
,
1087 KBD_MODE_BIT_TRIGGER_75
,
1088 KBD_MODE_BIT_TRIGGER_100
,
1091 #define kbd_is_als_mode_bit(bit) \
1092 ((bit) == KBD_MODE_BIT_ALS || (bit) == KBD_MODE_BIT_TRIGGER_ALS)
1093 #define kbd_is_trigger_mode_bit(bit) \
1094 ((bit) >= KBD_MODE_BIT_TRIGGER_ALS && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1095 #define kbd_is_level_mode_bit(bit) \
1096 ((bit) >= KBD_MODE_BIT_TRIGGER_25 && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1119 static const int kbd_tokens
[] = {
1121 KBD_LED_AUTO_25_TOKEN
,
1122 KBD_LED_AUTO_50_TOKEN
,
1123 KBD_LED_AUTO_75_TOKEN
,
1124 KBD_LED_AUTO_100_TOKEN
,
1128 static u16 kbd_token_bits
;
1130 static struct kbd_info kbd_info
;
1131 static bool kbd_als_supported
;
1132 static bool kbd_triggers_supported
;
1134 static u8 kbd_mode_levels
[16];
1135 static int kbd_mode_levels_count
;
1137 static u8 kbd_previous_level
;
1138 static u8 kbd_previous_mode_bit
;
1140 static bool kbd_led_present
;
1143 * NOTE: there are three ways to set the keyboard backlight level.
1144 * First, via kbd_state.mode_bit (assigning KBD_MODE_BIT_TRIGGER_* value).
1145 * Second, via kbd_state.level (assigning numerical value <= kbd_info.levels).
1146 * Third, via SMBIOS tokens (KBD_LED_* in kbd_tokens)
1148 * There are laptops which support only one of these methods. If we want to
1149 * support as many machines as possible we need to implement all three methods.
1150 * The first two methods use the kbd_state structure. The third uses SMBIOS
1151 * tokens. If kbd_info.levels == 0, the machine does not support setting the
1152 * keyboard backlight level via kbd_state.level.
1155 static int kbd_get_info(struct kbd_info
*info
)
1162 buffer
->input
[0] = 0x0;
1163 dell_send_request(buffer
, 4, 11);
1164 ret
= buffer
->output
[0];
1167 ret
= dell_smi_error(ret
);
1171 info
->modes
= buffer
->output
[1] & 0xFFFF;
1172 info
->type
= (buffer
->output
[1] >> 24) & 0xFF;
1173 info
->triggers
= buffer
->output
[2] & 0xFF;
1174 units
= (buffer
->output
[2] >> 8) & 0xFF;
1175 info
->levels
= (buffer
->output
[2] >> 16) & 0xFF;
1178 info
->seconds
= (buffer
->output
[3] >> 0) & 0xFF;
1180 info
->minutes
= (buffer
->output
[3] >> 8) & 0xFF;
1182 info
->hours
= (buffer
->output
[3] >> 16) & 0xFF;
1184 info
->days
= (buffer
->output
[3] >> 24) & 0xFF;
1191 static unsigned int kbd_get_max_level(void)
1193 if (kbd_info
.levels
!= 0)
1194 return kbd_info
.levels
;
1195 if (kbd_mode_levels_count
> 0)
1196 return kbd_mode_levels_count
- 1;
1200 static int kbd_get_level(struct kbd_state
*state
)
1204 if (kbd_info
.levels
!= 0)
1205 return state
->level
;
1207 if (kbd_mode_levels_count
> 0) {
1208 for (i
= 0; i
< kbd_mode_levels_count
; ++i
)
1209 if (kbd_mode_levels
[i
] == state
->mode_bit
)
1217 static int kbd_set_level(struct kbd_state
*state
, u8 level
)
1219 if (kbd_info
.levels
!= 0) {
1221 kbd_previous_level
= level
;
1222 if (state
->level
== level
)
1224 state
->level
= level
;
1225 if (level
!= 0 && state
->mode_bit
== KBD_MODE_BIT_OFF
)
1226 state
->mode_bit
= kbd_previous_mode_bit
;
1227 else if (level
== 0 && state
->mode_bit
!= KBD_MODE_BIT_OFF
) {
1228 kbd_previous_mode_bit
= state
->mode_bit
;
1229 state
->mode_bit
= KBD_MODE_BIT_OFF
;
1234 if (kbd_mode_levels_count
> 0 && level
< kbd_mode_levels_count
) {
1236 kbd_previous_level
= level
;
1237 state
->mode_bit
= kbd_mode_levels
[level
];
1244 static int kbd_get_state(struct kbd_state
*state
)
1250 buffer
->input
[0] = 0x1;
1251 dell_send_request(buffer
, 4, 11);
1252 ret
= buffer
->output
[0];
1255 ret
= dell_smi_error(ret
);
1259 state
->mode_bit
= ffs(buffer
->output
[1] & 0xFFFF);
1260 if (state
->mode_bit
!= 0)
1263 state
->triggers
= (buffer
->output
[1] >> 16) & 0xFF;
1264 state
->timeout_value
= (buffer
->output
[1] >> 24) & 0x3F;
1265 state
->timeout_unit
= (buffer
->output
[1] >> 30) & 0x3;
1266 state
->als_setting
= buffer
->output
[2] & 0xFF;
1267 state
->als_value
= (buffer
->output
[2] >> 8) & 0xFF;
1268 state
->level
= (buffer
->output
[2] >> 16) & 0xFF;
1275 static int kbd_set_state(struct kbd_state
*state
)
1280 buffer
->input
[0] = 0x2;
1281 buffer
->input
[1] = BIT(state
->mode_bit
) & 0xFFFF;
1282 buffer
->input
[1] |= (state
->triggers
& 0xFF) << 16;
1283 buffer
->input
[1] |= (state
->timeout_value
& 0x3F) << 24;
1284 buffer
->input
[1] |= (state
->timeout_unit
& 0x3) << 30;
1285 buffer
->input
[2] = state
->als_setting
& 0xFF;
1286 buffer
->input
[2] |= (state
->level
& 0xFF) << 16;
1287 dell_send_request(buffer
, 4, 11);
1288 ret
= buffer
->output
[0];
1291 return dell_smi_error(ret
);
1294 static int kbd_set_state_safe(struct kbd_state
*state
, struct kbd_state
*old
)
1298 ret
= kbd_set_state(state
);
1303 * When setting the new state fails,try to restore the previous one.
1304 * This is needed on some machines where BIOS sets a default state when
1305 * setting a new state fails. This default state could be all off.
1308 if (kbd_set_state(old
))
1309 pr_err("Setting old previous keyboard state failed\n");
1314 static int kbd_set_token_bit(u8 bit
)
1319 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1322 id
= find_token_id(kbd_tokens
[bit
]);
1327 buffer
->input
[0] = da_tokens
[id
].location
;
1328 buffer
->input
[1] = da_tokens
[id
].value
;
1329 dell_send_request(buffer
, 1, 0);
1330 ret
= buffer
->output
[0];
1333 return dell_smi_error(ret
);
1336 static int kbd_get_token_bit(u8 bit
)
1342 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1345 id
= find_token_id(kbd_tokens
[bit
]);
1350 buffer
->input
[0] = da_tokens
[id
].location
;
1351 dell_send_request(buffer
, 0, 0);
1352 ret
= buffer
->output
[0];
1353 val
= buffer
->output
[1];
1357 return dell_smi_error(ret
);
1359 return (val
== da_tokens
[id
].value
);
1362 static int kbd_get_first_active_token_bit(void)
1367 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
) {
1368 ret
= kbd_get_token_bit(i
);
1376 static int kbd_get_valid_token_counts(void)
1378 return hweight16(kbd_token_bits
);
1381 static inline int kbd_init_info(void)
1383 struct kbd_state state
;
1387 ret
= kbd_get_info(&kbd_info
);
1391 kbd_get_state(&state
);
1393 /* NOTE: timeout value is stored in 6 bits so max value is 63 */
1394 if (kbd_info
.seconds
> 63)
1395 kbd_info
.seconds
= 63;
1396 if (kbd_info
.minutes
> 63)
1397 kbd_info
.minutes
= 63;
1398 if (kbd_info
.hours
> 63)
1399 kbd_info
.hours
= 63;
1400 if (kbd_info
.days
> 63)
1403 /* NOTE: On tested machines ON mode did not work and caused
1404 * problems (turned backlight off) so do not use it
1406 kbd_info
.modes
&= ~BIT(KBD_MODE_BIT_ON
);
1408 kbd_previous_level
= kbd_get_level(&state
);
1409 kbd_previous_mode_bit
= state
.mode_bit
;
1411 if (kbd_previous_level
== 0 && kbd_get_max_level() != 0)
1412 kbd_previous_level
= 1;
1414 if (kbd_previous_mode_bit
== KBD_MODE_BIT_OFF
) {
1415 kbd_previous_mode_bit
=
1416 ffs(kbd_info
.modes
& ~BIT(KBD_MODE_BIT_OFF
));
1417 if (kbd_previous_mode_bit
!= 0)
1418 kbd_previous_mode_bit
--;
1421 if (kbd_info
.modes
& (BIT(KBD_MODE_BIT_ALS
) |
1422 BIT(KBD_MODE_BIT_TRIGGER_ALS
)))
1423 kbd_als_supported
= true;
1425 if (kbd_info
.modes
& (
1426 BIT(KBD_MODE_BIT_TRIGGER_ALS
) | BIT(KBD_MODE_BIT_TRIGGER
) |
1427 BIT(KBD_MODE_BIT_TRIGGER_25
) | BIT(KBD_MODE_BIT_TRIGGER_50
) |
1428 BIT(KBD_MODE_BIT_TRIGGER_75
) | BIT(KBD_MODE_BIT_TRIGGER_100
)
1430 kbd_triggers_supported
= true;
1432 /* kbd_mode_levels[0] is reserved, see below */
1433 for (i
= 0; i
< 16; ++i
)
1434 if (kbd_is_level_mode_bit(i
) && (BIT(i
) & kbd_info
.modes
))
1435 kbd_mode_levels
[1 + kbd_mode_levels_count
++] = i
;
1438 * Find the first supported mode and assign to kbd_mode_levels[0].
1439 * This should be 0 (off), but we cannot depend on the BIOS to
1442 if (kbd_mode_levels_count
> 0) {
1443 for (i
= 0; i
< 16; ++i
) {
1444 if (BIT(i
) & kbd_info
.modes
) {
1445 kbd_mode_levels
[0] = i
;
1449 kbd_mode_levels_count
++;
1456 static inline void kbd_init_tokens(void)
1460 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
)
1461 if (find_token_id(kbd_tokens
[i
]) != -1)
1462 kbd_token_bits
|= BIT(i
);
1465 static void kbd_init(void)
1469 ret
= kbd_init_info();
1472 if (kbd_token_bits
!= 0 || ret
== 0)
1473 kbd_led_present
= true;
1476 static ssize_t
kbd_led_timeout_store(struct device
*dev
,
1477 struct device_attribute
*attr
,
1478 const char *buf
, size_t count
)
1480 struct kbd_state new_state
;
1481 struct kbd_state state
;
1489 ret
= sscanf(buf
, "%d %c", &value
, &ch
);
1502 if (value
> kbd_info
.seconds
)
1504 unit
= KBD_TIMEOUT_SECONDS
;
1507 if (value
> kbd_info
.minutes
)
1509 unit
= KBD_TIMEOUT_MINUTES
;
1512 if (value
> kbd_info
.hours
)
1514 unit
= KBD_TIMEOUT_HOURS
;
1517 if (value
> kbd_info
.days
)
1519 unit
= KBD_TIMEOUT_DAYS
;
1525 if (quirks
&& quirks
->needs_kbd_timeouts
)
1529 /* Convert value from current units to seconds */
1531 case KBD_TIMEOUT_DAYS
:
1533 case KBD_TIMEOUT_HOURS
:
1535 case KBD_TIMEOUT_MINUTES
:
1537 unit
= KBD_TIMEOUT_SECONDS
;
1540 if (quirks
&& quirks
->needs_kbd_timeouts
) {
1541 for (i
= 0; quirks
->kbd_timeouts
[i
] != -1; i
++) {
1542 if (value
<= quirks
->kbd_timeouts
[i
]) {
1543 value
= quirks
->kbd_timeouts
[i
];
1549 if (value
<= kbd_info
.seconds
&& kbd_info
.seconds
) {
1550 unit
= KBD_TIMEOUT_SECONDS
;
1551 } else if (value
/ 60 <= kbd_info
.minutes
&& kbd_info
.minutes
) {
1553 unit
= KBD_TIMEOUT_MINUTES
;
1554 } else if (value
/ (60 * 60) <= kbd_info
.hours
&& kbd_info
.hours
) {
1556 unit
= KBD_TIMEOUT_HOURS
;
1557 } else if (value
/ (60 * 60 * 24) <= kbd_info
.days
&& kbd_info
.days
) {
1558 value
/= (60 * 60 * 24);
1559 unit
= KBD_TIMEOUT_DAYS
;
1565 ret
= kbd_get_state(&state
);
1570 new_state
.timeout_value
= value
;
1571 new_state
.timeout_unit
= unit
;
1573 ret
= kbd_set_state_safe(&new_state
, &state
);
1580 static ssize_t
kbd_led_timeout_show(struct device
*dev
,
1581 struct device_attribute
*attr
, char *buf
)
1583 struct kbd_state state
;
1587 ret
= kbd_get_state(&state
);
1591 len
= sprintf(buf
, "%d", state
.timeout_value
);
1593 switch (state
.timeout_unit
) {
1594 case KBD_TIMEOUT_SECONDS
:
1595 return len
+ sprintf(buf
+len
, "s\n");
1596 case KBD_TIMEOUT_MINUTES
:
1597 return len
+ sprintf(buf
+len
, "m\n");
1598 case KBD_TIMEOUT_HOURS
:
1599 return len
+ sprintf(buf
+len
, "h\n");
1600 case KBD_TIMEOUT_DAYS
:
1601 return len
+ sprintf(buf
+len
, "d\n");
1609 static DEVICE_ATTR(stop_timeout
, S_IRUGO
| S_IWUSR
,
1610 kbd_led_timeout_show
, kbd_led_timeout_store
);
1612 static const char * const kbd_led_triggers
[] = {
1615 /*"trackstick"*/ NULL
, /* NOTE: trackstick is just alias for touchpad */
1619 static ssize_t
kbd_led_triggers_store(struct device
*dev
,
1620 struct device_attribute
*attr
,
1621 const char *buf
, size_t count
)
1623 struct kbd_state new_state
;
1624 struct kbd_state state
;
1625 bool triggers_enabled
= false;
1626 int trigger_bit
= -1;
1630 ret
= sscanf(buf
, "%20s", trigger
);
1634 if (trigger
[0] != '+' && trigger
[0] != '-')
1637 ret
= kbd_get_state(&state
);
1641 if (kbd_triggers_supported
)
1642 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1644 if (kbd_triggers_supported
) {
1645 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1646 if (!(kbd_info
.triggers
& BIT(i
)))
1648 if (!kbd_led_triggers
[i
])
1650 if (strcmp(trigger
+1, kbd_led_triggers
[i
]) != 0)
1652 if (trigger
[0] == '+' &&
1653 triggers_enabled
&& (state
.triggers
& BIT(i
)))
1655 if (trigger
[0] == '-' &&
1656 (!triggers_enabled
|| !(state
.triggers
& BIT(i
))))
1663 if (trigger_bit
!= -1) {
1665 if (trigger
[0] == '+')
1666 new_state
.triggers
|= BIT(trigger_bit
);
1668 new_state
.triggers
&= ~BIT(trigger_bit
);
1669 /* NOTE: trackstick bit (2) must be disabled when
1670 * disabling touchpad bit (1), otherwise touchpad
1671 * bit (1) will not be disabled */
1672 if (trigger_bit
== 1)
1673 new_state
.triggers
&= ~BIT(2);
1675 if ((kbd_info
.triggers
& new_state
.triggers
) !=
1678 if (new_state
.triggers
&& !triggers_enabled
) {
1679 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1680 kbd_set_level(&new_state
, kbd_previous_level
);
1681 } else if (new_state
.triggers
== 0) {
1682 kbd_set_level(&new_state
, 0);
1684 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
)))
1686 ret
= kbd_set_state_safe(&new_state
, &state
);
1689 if (new_state
.mode_bit
!= KBD_MODE_BIT_OFF
)
1690 kbd_previous_mode_bit
= new_state
.mode_bit
;
1697 static ssize_t
kbd_led_triggers_show(struct device
*dev
,
1698 struct device_attribute
*attr
, char *buf
)
1700 struct kbd_state state
;
1701 bool triggers_enabled
;
1705 ret
= kbd_get_state(&state
);
1711 if (kbd_triggers_supported
) {
1712 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1713 level
= kbd_get_level(&state
);
1714 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1715 if (!(kbd_info
.triggers
& BIT(i
)))
1717 if (!kbd_led_triggers
[i
])
1719 if ((triggers_enabled
|| level
<= 0) &&
1720 (state
.triggers
& BIT(i
)))
1724 len
+= sprintf(buf
+len
, "%s ", kbd_led_triggers
[i
]);
1729 buf
[len
- 1] = '\n';
1734 static DEVICE_ATTR(start_triggers
, S_IRUGO
| S_IWUSR
,
1735 kbd_led_triggers_show
, kbd_led_triggers_store
);
1737 static ssize_t
kbd_led_als_enabled_store(struct device
*dev
,
1738 struct device_attribute
*attr
,
1739 const char *buf
, size_t count
)
1741 struct kbd_state new_state
;
1742 struct kbd_state state
;
1743 bool triggers_enabled
= false;
1747 ret
= kstrtoint(buf
, 0, &enable
);
1751 ret
= kbd_get_state(&state
);
1755 if (enable
== kbd_is_als_mode_bit(state
.mode_bit
))
1760 if (kbd_triggers_supported
)
1761 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1764 if (triggers_enabled
)
1765 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER_ALS
;
1767 new_state
.mode_bit
= KBD_MODE_BIT_ALS
;
1769 if (triggers_enabled
) {
1770 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1771 kbd_set_level(&new_state
, kbd_previous_level
);
1773 new_state
.mode_bit
= KBD_MODE_BIT_ON
;
1776 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
)))
1779 ret
= kbd_set_state_safe(&new_state
, &state
);
1782 kbd_previous_mode_bit
= new_state
.mode_bit
;
1787 static ssize_t
kbd_led_als_enabled_show(struct device
*dev
,
1788 struct device_attribute
*attr
,
1791 struct kbd_state state
;
1792 bool enabled
= false;
1795 ret
= kbd_get_state(&state
);
1798 enabled
= kbd_is_als_mode_bit(state
.mode_bit
);
1800 return sprintf(buf
, "%d\n", enabled
? 1 : 0);
1803 static DEVICE_ATTR(als_enabled
, S_IRUGO
| S_IWUSR
,
1804 kbd_led_als_enabled_show
, kbd_led_als_enabled_store
);
1806 static ssize_t
kbd_led_als_setting_store(struct device
*dev
,
1807 struct device_attribute
*attr
,
1808 const char *buf
, size_t count
)
1810 struct kbd_state state
;
1811 struct kbd_state new_state
;
1815 ret
= kstrtou8(buf
, 10, &setting
);
1819 ret
= kbd_get_state(&state
);
1824 new_state
.als_setting
= setting
;
1826 ret
= kbd_set_state_safe(&new_state
, &state
);
1833 static ssize_t
kbd_led_als_setting_show(struct device
*dev
,
1834 struct device_attribute
*attr
,
1837 struct kbd_state state
;
1840 ret
= kbd_get_state(&state
);
1844 return sprintf(buf
, "%d\n", state
.als_setting
);
1847 static DEVICE_ATTR(als_setting
, S_IRUGO
| S_IWUSR
,
1848 kbd_led_als_setting_show
, kbd_led_als_setting_store
);
1850 static struct attribute
*kbd_led_attrs
[] = {
1851 &dev_attr_stop_timeout
.attr
,
1852 &dev_attr_start_triggers
.attr
,
1856 static const struct attribute_group kbd_led_group
= {
1857 .attrs
= kbd_led_attrs
,
1860 static struct attribute
*kbd_led_als_attrs
[] = {
1861 &dev_attr_als_enabled
.attr
,
1862 &dev_attr_als_setting
.attr
,
1866 static const struct attribute_group kbd_led_als_group
= {
1867 .attrs
= kbd_led_als_attrs
,
1870 static const struct attribute_group
*kbd_led_groups
[] = {
1876 static enum led_brightness
kbd_led_level_get(struct led_classdev
*led_cdev
)
1880 struct kbd_state state
;
1882 if (kbd_get_max_level()) {
1883 ret
= kbd_get_state(&state
);
1886 ret
= kbd_get_level(&state
);
1892 if (kbd_get_valid_token_counts()) {
1893 ret
= kbd_get_first_active_token_bit();
1896 for (num
= kbd_token_bits
; num
!= 0 && ret
> 0; --ret
)
1897 num
&= num
- 1; /* clear the first bit set */
1900 return ffs(num
) - 1;
1903 pr_warn("Keyboard brightness level control not supported\n");
1907 static void kbd_led_level_set(struct led_classdev
*led_cdev
,
1908 enum led_brightness value
)
1910 struct kbd_state state
;
1911 struct kbd_state new_state
;
1914 if (kbd_get_max_level()) {
1915 if (kbd_get_state(&state
))
1918 if (kbd_set_level(&new_state
, value
))
1920 kbd_set_state_safe(&new_state
, &state
);
1924 if (kbd_get_valid_token_counts()) {
1925 for (num
= kbd_token_bits
; num
!= 0 && value
> 0; --value
)
1926 num
&= num
- 1; /* clear the first bit set */
1929 kbd_set_token_bit(ffs(num
) - 1);
1933 pr_warn("Keyboard brightness level control not supported\n");
1936 static struct led_classdev kbd_led
= {
1937 .name
= "dell::kbd_backlight",
1938 .brightness_set
= kbd_led_level_set
,
1939 .brightness_get
= kbd_led_level_get
,
1940 .groups
= kbd_led_groups
,
1943 static int __init
kbd_led_init(struct device
*dev
)
1946 if (!kbd_led_present
)
1948 if (!kbd_als_supported
)
1949 kbd_led_groups
[1] = NULL
;
1950 kbd_led
.max_brightness
= kbd_get_max_level();
1951 if (!kbd_led
.max_brightness
) {
1952 kbd_led
.max_brightness
= kbd_get_valid_token_counts();
1953 if (kbd_led
.max_brightness
)
1954 kbd_led
.max_brightness
--;
1956 return led_classdev_register(dev
, &kbd_led
);
1959 static void brightness_set_exit(struct led_classdev
*led_cdev
,
1960 enum led_brightness value
)
1962 /* Don't change backlight level on exit */
1965 static void kbd_led_exit(void)
1967 if (!kbd_led_present
)
1969 kbd_led
.brightness_set
= brightness_set_exit
;
1970 led_classdev_unregister(&kbd_led
);
1973 static int __init
dell_init(void)
1975 int max_intensity
= 0;
1979 if (!dmi_check_system(dell_device_table
))
1983 /* find if this machine support other functions */
1984 dmi_check_system(dell_quirks
);
1986 ret
= platform_driver_register(&platform_driver
);
1988 goto fail_platform_driver
;
1989 platform_device
= platform_device_alloc("dell-laptop", -1);
1990 if (!platform_device
) {
1992 goto fail_platform_device1
;
1994 ret
= platform_device_add(platform_device
);
1996 goto fail_platform_device2
;
1998 ret
= dell_setup_rfkill();
2001 pr_warn("Unable to setup rfkill\n");
2005 if (quirks
&& quirks
->touchpad_led
)
2006 touchpad_led_init(&platform_device
->dev
);
2008 kbd_led_init(&platform_device
->dev
);
2010 dell_laptop_dir
= debugfs_create_dir("dell_laptop", NULL
);
2011 if (dell_laptop_dir
!= NULL
)
2012 debugfs_create_file("rfkill", 0444, dell_laptop_dir
, NULL
,
2013 &dell_debugfs_fops
);
2015 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2018 token
= find_token_location(BRIGHTNESS_TOKEN
);
2021 buffer
->input
[0] = token
;
2022 dell_send_request(buffer
, 0, 2);
2023 if (buffer
->output
[0] == 0)
2024 max_intensity
= buffer
->output
[3];
2028 if (max_intensity
) {
2029 struct backlight_properties props
;
2030 memset(&props
, 0, sizeof(struct backlight_properties
));
2031 props
.type
= BACKLIGHT_PLATFORM
;
2032 props
.max_brightness
= max_intensity
;
2033 dell_backlight_device
= backlight_device_register("dell_backlight",
2034 &platform_device
->dev
,
2039 if (IS_ERR(dell_backlight_device
)) {
2040 ret
= PTR_ERR(dell_backlight_device
);
2041 dell_backlight_device
= NULL
;
2042 goto fail_backlight
;
2045 dell_backlight_device
->props
.brightness
=
2046 dell_get_intensity(dell_backlight_device
);
2047 backlight_update_status(dell_backlight_device
);
2053 dell_cleanup_rfkill();
2055 platform_device_del(platform_device
);
2056 fail_platform_device2
:
2057 platform_device_put(platform_device
);
2058 fail_platform_device1
:
2059 platform_driver_unregister(&platform_driver
);
2060 fail_platform_driver
:
2064 static void __exit
dell_exit(void)
2066 debugfs_remove_recursive(dell_laptop_dir
);
2067 if (quirks
&& quirks
->touchpad_led
)
2068 touchpad_led_exit();
2070 backlight_device_unregister(dell_backlight_device
);
2071 dell_cleanup_rfkill();
2072 if (platform_device
) {
2073 platform_device_unregister(platform_device
);
2074 platform_driver_unregister(&platform_driver
);
2078 /* dell-rbtn.c driver export functions which will not work correctly (and could
2079 * cause kernel crash) if they are called before dell-rbtn.c init code. This is
2080 * not problem when dell-rbtn.c is compiled as external module. When both files
2081 * (dell-rbtn.c and dell-laptop.c) are compiled statically into kernel, then we
2082 * need to ensure that dell_init() will be called after initializing dell-rbtn.
2083 * This can be achieved by late_initcall() instead module_init().
2085 late_initcall(dell_init
);
2086 module_exit(dell_exit
);
2088 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
2089 MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
2090 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
2091 MODULE_DESCRIPTION("Dell laptop driver");
2092 MODULE_LICENSE("GPL");