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*/
110 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
111 DMI_MATCH(DMI_CHASSIS_TYPE
, "10"), /*Notebook*/
115 .ident
= "Dell Computer Corporation",
117 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer Corporation"),
118 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
123 MODULE_DEVICE_TABLE(dmi
, dell_device_table
);
125 static const struct dmi_system_id dell_quirks
[] __initconst
= {
127 .callback
= dmi_matched
,
128 .ident
= "Dell Vostro V130",
130 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
131 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V130"),
133 .driver_data
= &quirk_dell_vostro_v130
,
136 .callback
= dmi_matched
,
137 .ident
= "Dell Vostro V131",
139 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
140 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V131"),
142 .driver_data
= &quirk_dell_vostro_v130
,
145 .callback
= dmi_matched
,
146 .ident
= "Dell Vostro 3350",
148 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
149 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3350"),
151 .driver_data
= &quirk_dell_vostro_v130
,
154 .callback
= dmi_matched
,
155 .ident
= "Dell Vostro 3555",
157 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
158 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3555"),
160 .driver_data
= &quirk_dell_vostro_v130
,
163 .callback
= dmi_matched
,
164 .ident
= "Dell Inspiron N311z",
166 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
167 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron N311z"),
169 .driver_data
= &quirk_dell_vostro_v130
,
172 .callback
= dmi_matched
,
173 .ident
= "Dell Inspiron M5110",
175 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
176 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron M5110"),
178 .driver_data
= &quirk_dell_vostro_v130
,
181 .callback
= dmi_matched
,
182 .ident
= "Dell Vostro 3360",
184 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
185 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3360"),
187 .driver_data
= &quirk_dell_vostro_v130
,
190 .callback
= dmi_matched
,
191 .ident
= "Dell Vostro 3460",
193 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
194 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3460"),
196 .driver_data
= &quirk_dell_vostro_v130
,
199 .callback
= dmi_matched
,
200 .ident
= "Dell Vostro 3560",
202 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
203 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3560"),
205 .driver_data
= &quirk_dell_vostro_v130
,
208 .callback
= dmi_matched
,
209 .ident
= "Dell Vostro 3450",
211 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
212 DMI_MATCH(DMI_PRODUCT_NAME
, "Dell System Vostro 3450"),
214 .driver_data
= &quirk_dell_vostro_v130
,
217 .callback
= dmi_matched
,
218 .ident
= "Dell Inspiron 5420",
220 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
221 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5420"),
223 .driver_data
= &quirk_dell_vostro_v130
,
226 .callback
= dmi_matched
,
227 .ident
= "Dell Inspiron 5520",
229 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
230 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5520"),
232 .driver_data
= &quirk_dell_vostro_v130
,
235 .callback
= dmi_matched
,
236 .ident
= "Dell Inspiron 5720",
238 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
239 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5720"),
241 .driver_data
= &quirk_dell_vostro_v130
,
244 .callback
= dmi_matched
,
245 .ident
= "Dell Inspiron 7420",
247 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
248 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7420"),
250 .driver_data
= &quirk_dell_vostro_v130
,
253 .callback
= dmi_matched
,
254 .ident
= "Dell Inspiron 7520",
256 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
257 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7520"),
259 .driver_data
= &quirk_dell_vostro_v130
,
262 .callback
= dmi_matched
,
263 .ident
= "Dell Inspiron 7720",
265 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
266 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7720"),
268 .driver_data
= &quirk_dell_vostro_v130
,
271 .callback
= dmi_matched
,
272 .ident
= "Dell XPS13 9333",
274 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
275 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS13 9333"),
277 .driver_data
= &quirk_dell_xps13_9333
,
283 * Derived from information in smbios-wireless-ctl:
285 * cbSelect 17, Value 11
287 * Return Wireless Info
288 * cbArg1, byte0 = 0x00
290 * cbRes1 Standard return codes (0, -1, -2)
291 * cbRes2 Info bit flags:
293 * 0 Hardware switch supported (1)
294 * 1 WiFi locator supported (1)
295 * 2 WLAN supported (1)
296 * 3 Bluetooth (BT) supported (1)
297 * 4 WWAN supported (1)
298 * 5 Wireless KBD supported (1)
299 * 6 Uw b supported (1)
300 * 7 WiGig supported (1)
301 * 8 WLAN installed (1)
303 * 10 WWAN installed (1)
304 * 11 Uw b installed (1)
305 * 12 WiGig installed (1)
307 * 16 Hardware (HW) switch is On (1)
308 * 17 WLAN disabled (1)
310 * 19 WWAN disabled (1)
311 * 20 Uw b disabled (1)
312 * 21 WiGig disabled (1)
315 * cbRes3 NVRAM size in bytes
316 * cbRes4, byte 0 NVRAM format version number
319 * Set QuickSet Radio Disable Flag
320 * cbArg1, byte0 = 0x01
329 * cbArg1, byte2 Flag bits:
330 * 0 QuickSet disables radio (1)
333 * cbRes1 Standard return codes (0, -1, -2)
334 * cbRes2 QuickSet (QS) radio disable bit map:
339 * 4 QS disables WIGIG
342 * Wireless Switch Configuration
343 * cbArg1, byte0 = 0x02
349 * 2 Set WiFi locator enable/disable
351 * Switch settings (if byte 1==1):
352 * 0 WLAN sw itch control (1)
353 * 1 BT sw itch control (1)
354 * 2 WWAN sw itch control (1)
355 * 3 UWB sw itch control (1)
356 * 4 WiGig sw itch control (1)
358 * cbArg1, byte2 Enable bits (if byte 1==2):
359 * 0 Enable WiFi locator (1)
361 * cbRes1 Standard return codes (0, -1, -2)
362 * cbRes2 QuickSet radio disable bit map:
363 * 0 WLAN controlled by sw itch (1)
364 * 1 BT controlled by sw itch (1)
365 * 2 WWAN controlled by sw itch (1)
366 * 3 UWB controlled by sw itch (1)
367 * 4 WiGig controlled by sw itch (1)
369 * 7 Wireless sw itch config locked (1)
370 * 8 WiFi locator enabled (1)
372 * 15 WiFi locator setting locked (1)
375 * Read Local Config Data (LCD)
376 * cbArg1, byte0 = 0x10
377 * cbArg1, byte1 NVRAM index low byte
378 * cbArg1, byte2 NVRAM index high byte
379 * cbRes1 Standard return codes (0, -1, -2)
380 * cbRes2 4 bytes read from LCD[index]
381 * cbRes3 4 bytes read from LCD[index+4]
382 * cbRes4 4 bytes read from LCD[index+8]
384 * Write Local Config Data (LCD)
385 * cbArg1, byte0 = 0x11
386 * cbArg1, byte1 NVRAM index low byte
387 * cbArg1, byte2 NVRAM index high byte
388 * cbArg2 4 bytes to w rite at LCD[index]
389 * cbArg3 4 bytes to w rite at LCD[index+4]
390 * cbArg4 4 bytes to w rite at LCD[index+8]
391 * cbRes1 Standard return codes (0, -1, -2)
393 * Populate Local Config Data from NVRAM
394 * cbArg1, byte0 = 0x12
395 * cbRes1 Standard return codes (0, -1, -2)
397 * Commit Local Config Data to NVRAM
398 * cbArg1, byte0 = 0x13
399 * cbRes1 Standard return codes (0, -1, -2)
402 static int dell_rfkill_set(void *data
, bool blocked
)
404 struct calling_interface_buffer
*buffer
;
405 int disable
= blocked
? 1 : 0;
406 unsigned long radio
= (unsigned long)data
;
407 int hwswitch_bit
= (unsigned long)data
- 1;
412 buffer
= dell_smbios_get_buffer();
414 dell_smbios_send_request(17, 11);
415 ret
= buffer
->output
[0];
416 status
= buffer
->output
[1];
421 dell_smbios_clear_buffer();
423 buffer
->input
[0] = 0x2;
424 dell_smbios_send_request(17, 11);
425 ret
= buffer
->output
[0];
426 hwswitch
= buffer
->output
[1];
428 /* If the hardware switch controls this radio, and the hardware
429 switch is disabled, always disable the radio */
430 if (ret
== 0 && (hwswitch
& BIT(hwswitch_bit
)) &&
431 (status
& BIT(0)) && !(status
& BIT(16)))
434 dell_smbios_clear_buffer();
436 buffer
->input
[0] = (1 | (radio
<<8) | (disable
<< 16));
437 dell_smbios_send_request(17, 11);
438 ret
= buffer
->output
[0];
441 dell_smbios_release_buffer();
442 return dell_smbios_error(ret
);
445 /* Must be called with the buffer held */
446 static void dell_rfkill_update_sw_state(struct rfkill
*rfkill
, int radio
,
448 struct calling_interface_buffer
*buffer
)
450 if (status
& BIT(0)) {
451 /* Has hw-switch, sync sw_state to BIOS */
452 int block
= rfkill_blocked(rfkill
);
453 dell_smbios_clear_buffer();
454 buffer
->input
[0] = (1 | (radio
<< 8) | (block
<< 16));
455 dell_smbios_send_request(17, 11);
457 /* No hw-switch, sync BIOS state to sw_state */
458 rfkill_set_sw_state(rfkill
, !!(status
& BIT(radio
+ 16)));
462 static void dell_rfkill_update_hw_state(struct rfkill
*rfkill
, int radio
,
463 int status
, int hwswitch
)
465 if (hwswitch
& (BIT(radio
- 1)))
466 rfkill_set_hw_state(rfkill
, !(status
& BIT(16)));
469 static void dell_rfkill_query(struct rfkill
*rfkill
, void *data
)
471 struct calling_interface_buffer
*buffer
;
472 int radio
= ((unsigned long)data
& 0xF);
477 buffer
= dell_smbios_get_buffer();
479 dell_smbios_send_request(17, 11);
480 ret
= buffer
->output
[0];
481 status
= buffer
->output
[1];
483 if (ret
!= 0 || !(status
& BIT(0))) {
484 dell_smbios_release_buffer();
488 dell_smbios_clear_buffer();
490 buffer
->input
[0] = 0x2;
491 dell_smbios_send_request(17, 11);
492 ret
= buffer
->output
[0];
493 hwswitch
= buffer
->output
[1];
495 dell_smbios_release_buffer();
500 dell_rfkill_update_hw_state(rfkill
, radio
, status
, hwswitch
);
503 static const struct rfkill_ops dell_rfkill_ops
= {
504 .set_block
= dell_rfkill_set
,
505 .query
= dell_rfkill_query
,
508 static struct dentry
*dell_laptop_dir
;
510 static int dell_debugfs_show(struct seq_file
*s
, void *data
)
512 struct calling_interface_buffer
*buffer
;
518 buffer
= dell_smbios_get_buffer();
520 dell_smbios_send_request(17, 11);
521 ret
= buffer
->output
[0];
522 status
= buffer
->output
[1];
524 dell_smbios_clear_buffer();
526 buffer
->input
[0] = 0x2;
527 dell_smbios_send_request(17, 11);
528 hwswitch_ret
= buffer
->output
[0];
529 hwswitch_state
= buffer
->output
[1];
531 dell_smbios_release_buffer();
533 seq_printf(s
, "return:\t%d\n", ret
);
534 seq_printf(s
, "status:\t0x%X\n", status
);
535 seq_printf(s
, "Bit 0 : Hardware switch supported: %lu\n",
537 seq_printf(s
, "Bit 1 : Wifi locator supported: %lu\n",
538 (status
& BIT(1)) >> 1);
539 seq_printf(s
, "Bit 2 : Wifi is supported: %lu\n",
540 (status
& BIT(2)) >> 2);
541 seq_printf(s
, "Bit 3 : Bluetooth is supported: %lu\n",
542 (status
& BIT(3)) >> 3);
543 seq_printf(s
, "Bit 4 : WWAN is supported: %lu\n",
544 (status
& BIT(4)) >> 4);
545 seq_printf(s
, "Bit 5 : Wireless keyboard supported: %lu\n",
546 (status
& BIT(5)) >> 5);
547 seq_printf(s
, "Bit 6 : UWB supported: %lu\n",
548 (status
& BIT(6)) >> 6);
549 seq_printf(s
, "Bit 7 : WiGig supported: %lu\n",
550 (status
& BIT(7)) >> 7);
551 seq_printf(s
, "Bit 8 : Wifi is installed: %lu\n",
552 (status
& BIT(8)) >> 8);
553 seq_printf(s
, "Bit 9 : Bluetooth is installed: %lu\n",
554 (status
& BIT(9)) >> 9);
555 seq_printf(s
, "Bit 10: WWAN is installed: %lu\n",
556 (status
& BIT(10)) >> 10);
557 seq_printf(s
, "Bit 11: UWB installed: %lu\n",
558 (status
& BIT(11)) >> 11);
559 seq_printf(s
, "Bit 12: WiGig installed: %lu\n",
560 (status
& BIT(12)) >> 12);
562 seq_printf(s
, "Bit 16: Hardware switch is on: %lu\n",
563 (status
& BIT(16)) >> 16);
564 seq_printf(s
, "Bit 17: Wifi is blocked: %lu\n",
565 (status
& BIT(17)) >> 17);
566 seq_printf(s
, "Bit 18: Bluetooth is blocked: %lu\n",
567 (status
& BIT(18)) >> 18);
568 seq_printf(s
, "Bit 19: WWAN is blocked: %lu\n",
569 (status
& BIT(19)) >> 19);
570 seq_printf(s
, "Bit 20: UWB is blocked: %lu\n",
571 (status
& BIT(20)) >> 20);
572 seq_printf(s
, "Bit 21: WiGig is blocked: %lu\n",
573 (status
& BIT(21)) >> 21);
575 seq_printf(s
, "\nhwswitch_return:\t%d\n", hwswitch_ret
);
576 seq_printf(s
, "hwswitch_state:\t0x%X\n", hwswitch_state
);
577 seq_printf(s
, "Bit 0 : Wifi controlled by switch: %lu\n",
578 hwswitch_state
& BIT(0));
579 seq_printf(s
, "Bit 1 : Bluetooth controlled by switch: %lu\n",
580 (hwswitch_state
& BIT(1)) >> 1);
581 seq_printf(s
, "Bit 2 : WWAN controlled by switch: %lu\n",
582 (hwswitch_state
& BIT(2)) >> 2);
583 seq_printf(s
, "Bit 3 : UWB controlled by switch: %lu\n",
584 (hwswitch_state
& BIT(3)) >> 3);
585 seq_printf(s
, "Bit 4 : WiGig controlled by switch: %lu\n",
586 (hwswitch_state
& BIT(4)) >> 4);
587 seq_printf(s
, "Bit 7 : Wireless switch config locked: %lu\n",
588 (hwswitch_state
& BIT(7)) >> 7);
589 seq_printf(s
, "Bit 8 : Wifi locator enabled: %lu\n",
590 (hwswitch_state
& BIT(8)) >> 8);
591 seq_printf(s
, "Bit 15: Wifi locator setting locked: %lu\n",
592 (hwswitch_state
& BIT(15)) >> 15);
597 static int dell_debugfs_open(struct inode
*inode
, struct file
*file
)
599 return single_open(file
, dell_debugfs_show
, inode
->i_private
);
602 static const struct file_operations dell_debugfs_fops
= {
603 .owner
= THIS_MODULE
,
604 .open
= dell_debugfs_open
,
607 .release
= single_release
,
610 static void dell_update_rfkill(struct work_struct
*ignored
)
612 struct calling_interface_buffer
*buffer
;
617 buffer
= dell_smbios_get_buffer();
619 dell_smbios_send_request(17, 11);
620 ret
= buffer
->output
[0];
621 status
= buffer
->output
[1];
626 dell_smbios_clear_buffer();
628 buffer
->input
[0] = 0x2;
629 dell_smbios_send_request(17, 11);
630 ret
= buffer
->output
[0];
632 if (ret
== 0 && (status
& BIT(0)))
633 hwswitch
= buffer
->output
[1];
636 dell_rfkill_update_hw_state(wifi_rfkill
, 1, status
, hwswitch
);
637 dell_rfkill_update_sw_state(wifi_rfkill
, 1, status
, buffer
);
639 if (bluetooth_rfkill
) {
640 dell_rfkill_update_hw_state(bluetooth_rfkill
, 2, status
,
642 dell_rfkill_update_sw_state(bluetooth_rfkill
, 2, status
,
646 dell_rfkill_update_hw_state(wwan_rfkill
, 3, status
, hwswitch
);
647 dell_rfkill_update_sw_state(wwan_rfkill
, 3, status
, buffer
);
651 dell_smbios_release_buffer();
653 static DECLARE_DELAYED_WORK(dell_rfkill_work
, dell_update_rfkill
);
655 static bool dell_laptop_i8042_filter(unsigned char data
, unsigned char str
,
658 static bool extended
;
660 if (str
& I8042_STR_AUXDATA
)
663 if (unlikely(data
== 0xe0)) {
666 } else if (unlikely(extended
)) {
669 schedule_delayed_work(&dell_rfkill_work
,
670 round_jiffies_relative(HZ
/ 4));
679 static int (*dell_rbtn_notifier_register_func
)(struct notifier_block
*);
680 static int (*dell_rbtn_notifier_unregister_func
)(struct notifier_block
*);
682 static int dell_laptop_rbtn_notifier_call(struct notifier_block
*nb
,
683 unsigned long action
, void *data
)
685 schedule_delayed_work(&dell_rfkill_work
, 0);
689 static struct notifier_block dell_laptop_rbtn_notifier
= {
690 .notifier_call
= dell_laptop_rbtn_notifier_call
,
693 static int __init
dell_setup_rfkill(void)
695 struct calling_interface_buffer
*buffer
;
696 int status
, ret
, whitelisted
;
700 * rfkill support causes trouble on various models, mostly Inspirons.
701 * So we whitelist certain series, and don't support rfkill on others.
704 product
= dmi_get_system_info(DMI_PRODUCT_NAME
);
705 if (product
&& (strncmp(product
, "Latitude", 8) == 0 ||
706 strncmp(product
, "Precision", 9) == 0))
708 if (!force_rfkill
&& !whitelisted
)
711 buffer
= dell_smbios_get_buffer();
712 dell_smbios_send_request(17, 11);
713 ret
= buffer
->output
[0];
714 status
= buffer
->output
[1];
715 dell_smbios_release_buffer();
717 /* dell wireless info smbios call is not supported */
721 /* rfkill is only tested on laptops with a hwswitch */
722 if (!(status
& BIT(0)) && !force_rfkill
)
725 if ((status
& (1<<2|1<<8)) == (1<<2|1<<8)) {
726 wifi_rfkill
= rfkill_alloc("dell-wifi", &platform_device
->dev
,
728 &dell_rfkill_ops
, (void *) 1);
733 ret
= rfkill_register(wifi_rfkill
);
738 if ((status
& (1<<3|1<<9)) == (1<<3|1<<9)) {
739 bluetooth_rfkill
= rfkill_alloc("dell-bluetooth",
740 &platform_device
->dev
,
741 RFKILL_TYPE_BLUETOOTH
,
742 &dell_rfkill_ops
, (void *) 2);
743 if (!bluetooth_rfkill
) {
747 ret
= rfkill_register(bluetooth_rfkill
);
752 if ((status
& (1<<4|1<<10)) == (1<<4|1<<10)) {
753 wwan_rfkill
= rfkill_alloc("dell-wwan",
754 &platform_device
->dev
,
756 &dell_rfkill_ops
, (void *) 3);
761 ret
= rfkill_register(wwan_rfkill
);
767 * Dell Airplane Mode Switch driver (dell-rbtn) supports ACPI devices
768 * which can receive events from HW slider switch.
770 * Dell SMBIOS on whitelisted models supports controlling radio devices
771 * but does not support receiving HW button switch events. We can use
772 * i8042 filter hook function to receive keyboard data and handle
773 * keycode for HW button.
775 * So if it is possible we will use Dell Airplane Mode Switch ACPI
776 * driver for receiving HW events and Dell SMBIOS for setting rfkill
777 * states. If ACPI driver or device is not available we will fallback to
778 * i8042 filter hook function.
780 * To prevent duplicate rfkill devices which control and do same thing,
781 * dell-rbtn driver will automatically remove its own rfkill devices
782 * once function dell_rbtn_notifier_register() is called.
785 dell_rbtn_notifier_register_func
=
786 symbol_request(dell_rbtn_notifier_register
);
787 if (dell_rbtn_notifier_register_func
) {
788 dell_rbtn_notifier_unregister_func
=
789 symbol_request(dell_rbtn_notifier_unregister
);
790 if (!dell_rbtn_notifier_unregister_func
) {
791 symbol_put(dell_rbtn_notifier_register
);
792 dell_rbtn_notifier_register_func
= NULL
;
796 if (dell_rbtn_notifier_register_func
) {
797 ret
= dell_rbtn_notifier_register_func(
798 &dell_laptop_rbtn_notifier
);
799 symbol_put(dell_rbtn_notifier_register
);
800 dell_rbtn_notifier_register_func
= NULL
;
802 symbol_put(dell_rbtn_notifier_unregister
);
803 dell_rbtn_notifier_unregister_func
= NULL
;
806 pr_info("Symbols from dell-rbtn acpi driver are not available\n");
811 pr_info("Using dell-rbtn acpi driver for receiving events\n");
812 } else if (ret
!= -ENODEV
) {
813 pr_warn("Unable to register dell rbtn notifier\n");
816 ret
= i8042_install_filter(dell_laptop_i8042_filter
);
818 pr_warn("Unable to install key filter\n");
821 pr_info("Using i8042 filter function for receiving events\n");
827 rfkill_unregister(wwan_rfkill
);
829 rfkill_destroy(wwan_rfkill
);
830 if (bluetooth_rfkill
)
831 rfkill_unregister(bluetooth_rfkill
);
833 rfkill_destroy(bluetooth_rfkill
);
835 rfkill_unregister(wifi_rfkill
);
837 rfkill_destroy(wifi_rfkill
);
842 static void dell_cleanup_rfkill(void)
844 if (dell_rbtn_notifier_unregister_func
) {
845 dell_rbtn_notifier_unregister_func(&dell_laptop_rbtn_notifier
);
846 symbol_put(dell_rbtn_notifier_unregister
);
847 dell_rbtn_notifier_unregister_func
= NULL
;
849 i8042_remove_filter(dell_laptop_i8042_filter
);
851 cancel_delayed_work_sync(&dell_rfkill_work
);
853 rfkill_unregister(wifi_rfkill
);
854 rfkill_destroy(wifi_rfkill
);
856 if (bluetooth_rfkill
) {
857 rfkill_unregister(bluetooth_rfkill
);
858 rfkill_destroy(bluetooth_rfkill
);
861 rfkill_unregister(wwan_rfkill
);
862 rfkill_destroy(wwan_rfkill
);
866 static int dell_send_intensity(struct backlight_device
*bd
)
868 struct calling_interface_buffer
*buffer
;
869 struct calling_interface_token
*token
;
872 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
876 buffer
= dell_smbios_get_buffer();
877 buffer
->input
[0] = token
->location
;
878 buffer
->input
[1] = bd
->props
.brightness
;
880 if (power_supply_is_system_supplied() > 0)
881 dell_smbios_send_request(1, 2);
883 dell_smbios_send_request(1, 1);
885 ret
= dell_smbios_error(buffer
->output
[0]);
887 dell_smbios_release_buffer();
891 static int dell_get_intensity(struct backlight_device
*bd
)
893 struct calling_interface_buffer
*buffer
;
894 struct calling_interface_token
*token
;
897 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
901 buffer
= dell_smbios_get_buffer();
902 buffer
->input
[0] = token
->location
;
904 if (power_supply_is_system_supplied() > 0)
905 dell_smbios_send_request(0, 2);
907 dell_smbios_send_request(0, 1);
909 if (buffer
->output
[0])
910 ret
= dell_smbios_error(buffer
->output
[0]);
912 ret
= buffer
->output
[1];
914 dell_smbios_release_buffer();
918 static const struct backlight_ops dell_ops
= {
919 .get_brightness
= dell_get_intensity
,
920 .update_status
= dell_send_intensity
,
923 static void touchpad_led_on(void)
927 i8042_command(&data
, command
| 1 << 12);
930 static void touchpad_led_off(void)
934 i8042_command(&data
, command
| 1 << 12);
937 static void touchpad_led_set(struct led_classdev
*led_cdev
,
938 enum led_brightness value
)
946 static struct led_classdev touchpad_led
= {
947 .name
= "dell-laptop::touchpad",
948 .brightness_set
= touchpad_led_set
,
949 .flags
= LED_CORE_SUSPENDRESUME
,
952 static int __init
touchpad_led_init(struct device
*dev
)
954 return led_classdev_register(dev
, &touchpad_led
);
957 static void touchpad_led_exit(void)
959 led_classdev_unregister(&touchpad_led
);
963 * Derived from information in smbios-keyboard-ctl:
967 * Keyboard illumination
968 * cbArg1 determines the function to be performed
970 * cbArg1 0x0 = Get Feature Information
971 * cbRES1 Standard return codes (0, -1, -2)
972 * cbRES2, word0 Bitmap of user-selectable modes
973 * bit 0 Always off (All systems)
974 * bit 1 Always on (Travis ATG, Siberia)
975 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
976 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
977 * bit 4 Auto: Input-activity-based On; input-activity based Off
978 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
979 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
980 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
981 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
982 * bits 9-15 Reserved for future use
983 * cbRES2, byte2 Reserved for future use
984 * cbRES2, byte3 Keyboard illumination type
988 * 3-255 Reserved for future use
989 * cbRES3, byte0 Supported auto keyboard illumination trigger bitmap.
990 * bit 0 Any keystroke
991 * bit 1 Touchpad activity
992 * bit 2 Pointing stick
994 * bits 4-7 Reserved for future use
995 * cbRES3, byte1 Supported timeout unit bitmap
1000 * bits 4-7 Reserved for future use
1001 * cbRES3, byte2 Number of keyboard light brightness levels
1002 * cbRES4, byte0 Maximum acceptable seconds value (0 if seconds not supported).
1003 * cbRES4, byte1 Maximum acceptable minutes value (0 if minutes not supported).
1004 * cbRES4, byte2 Maximum acceptable hours value (0 if hours not supported).
1005 * cbRES4, byte3 Maximum acceptable days value (0 if days not supported)
1007 * cbArg1 0x1 = Get Current State
1008 * cbRES1 Standard return codes (0, -1, -2)
1009 * cbRES2, word0 Bitmap of current mode state
1010 * bit 0 Always off (All systems)
1011 * bit 1 Always on (Travis ATG, Siberia)
1012 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
1013 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
1014 * bit 4 Auto: Input-activity-based On; input-activity based Off
1015 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
1016 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
1017 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
1018 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
1019 * bits 9-15 Reserved for future use
1020 * Note: Only One bit can be set
1021 * cbRES2, byte2 Currently active auto keyboard illumination triggers.
1022 * bit 0 Any keystroke
1023 * bit 1 Touchpad activity
1024 * bit 2 Pointing stick
1026 * bits 4-7 Reserved for future use
1027 * cbRES2, byte3 Current Timeout
1028 * bits 7:6 Timeout units indicator:
1033 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1034 * NOTE: A value of 0 means always on (no timeout) if any bits of RES3 byte
1035 * are set upon return from the [Get feature information] call.
1036 * cbRES3, byte0 Current setting of ALS value that turns the light on or off.
1037 * cbRES3, byte1 Current ALS reading
1038 * cbRES3, byte2 Current keyboard light level.
1040 * cbArg1 0x2 = Set New State
1041 * cbRES1 Standard return codes (0, -1, -2)
1042 * cbArg2, word0 Bitmap of current mode state
1043 * bit 0 Always off (All systems)
1044 * bit 1 Always on (Travis ATG, Siberia)
1045 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
1046 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
1047 * bit 4 Auto: Input-activity-based On; input-activity based Off
1048 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
1049 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
1050 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
1051 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
1052 * bits 9-15 Reserved for future use
1053 * Note: Only One bit can be set
1054 * cbArg2, byte2 Desired auto keyboard illumination triggers. Must remain inactive to allow
1055 * keyboard to turn off automatically.
1056 * bit 0 Any keystroke
1057 * bit 1 Touchpad activity
1058 * bit 2 Pointing stick
1060 * bits 4-7 Reserved for future use
1061 * cbArg2, byte3 Desired Timeout
1062 * bits 7:6 Timeout units indicator:
1067 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
1068 * cbArg3, byte0 Desired setting of ALS value that turns the light on or off.
1069 * cbArg3, byte2 Desired keyboard light level.
1073 enum kbd_timeout_unit
{
1074 KBD_TIMEOUT_SECONDS
= 0,
1075 KBD_TIMEOUT_MINUTES
,
1081 KBD_MODE_BIT_OFF
= 0,
1084 KBD_MODE_BIT_TRIGGER_ALS
,
1085 KBD_MODE_BIT_TRIGGER
,
1086 KBD_MODE_BIT_TRIGGER_25
,
1087 KBD_MODE_BIT_TRIGGER_50
,
1088 KBD_MODE_BIT_TRIGGER_75
,
1089 KBD_MODE_BIT_TRIGGER_100
,
1092 #define kbd_is_als_mode_bit(bit) \
1093 ((bit) == KBD_MODE_BIT_ALS || (bit) == KBD_MODE_BIT_TRIGGER_ALS)
1094 #define kbd_is_trigger_mode_bit(bit) \
1095 ((bit) >= KBD_MODE_BIT_TRIGGER_ALS && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1096 #define kbd_is_level_mode_bit(bit) \
1097 ((bit) >= KBD_MODE_BIT_TRIGGER_25 && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1120 static const int kbd_tokens
[] = {
1122 KBD_LED_AUTO_25_TOKEN
,
1123 KBD_LED_AUTO_50_TOKEN
,
1124 KBD_LED_AUTO_75_TOKEN
,
1125 KBD_LED_AUTO_100_TOKEN
,
1129 static u16 kbd_token_bits
;
1131 static struct kbd_info kbd_info
;
1132 static bool kbd_als_supported
;
1133 static bool kbd_triggers_supported
;
1135 static u8 kbd_mode_levels
[16];
1136 static int kbd_mode_levels_count
;
1138 static u8 kbd_previous_level
;
1139 static u8 kbd_previous_mode_bit
;
1141 static bool kbd_led_present
;
1142 static DEFINE_MUTEX(kbd_led_mutex
);
1145 * NOTE: there are three ways to set the keyboard backlight level.
1146 * First, via kbd_state.mode_bit (assigning KBD_MODE_BIT_TRIGGER_* value).
1147 * Second, via kbd_state.level (assigning numerical value <= kbd_info.levels).
1148 * Third, via SMBIOS tokens (KBD_LED_* in kbd_tokens)
1150 * There are laptops which support only one of these methods. If we want to
1151 * support as many machines as possible we need to implement all three methods.
1152 * The first two methods use the kbd_state structure. The third uses SMBIOS
1153 * tokens. If kbd_info.levels == 0, the machine does not support setting the
1154 * keyboard backlight level via kbd_state.level.
1157 static int kbd_get_info(struct kbd_info
*info
)
1159 struct calling_interface_buffer
*buffer
;
1163 buffer
= dell_smbios_get_buffer();
1165 buffer
->input
[0] = 0x0;
1166 dell_smbios_send_request(4, 11);
1167 ret
= buffer
->output
[0];
1170 ret
= dell_smbios_error(ret
);
1174 info
->modes
= buffer
->output
[1] & 0xFFFF;
1175 info
->type
= (buffer
->output
[1] >> 24) & 0xFF;
1176 info
->triggers
= buffer
->output
[2] & 0xFF;
1177 units
= (buffer
->output
[2] >> 8) & 0xFF;
1178 info
->levels
= (buffer
->output
[2] >> 16) & 0xFF;
1181 info
->seconds
= (buffer
->output
[3] >> 0) & 0xFF;
1183 info
->minutes
= (buffer
->output
[3] >> 8) & 0xFF;
1185 info
->hours
= (buffer
->output
[3] >> 16) & 0xFF;
1187 info
->days
= (buffer
->output
[3] >> 24) & 0xFF;
1190 dell_smbios_release_buffer();
1194 static unsigned int kbd_get_max_level(void)
1196 if (kbd_info
.levels
!= 0)
1197 return kbd_info
.levels
;
1198 if (kbd_mode_levels_count
> 0)
1199 return kbd_mode_levels_count
- 1;
1203 static int kbd_get_level(struct kbd_state
*state
)
1207 if (kbd_info
.levels
!= 0)
1208 return state
->level
;
1210 if (kbd_mode_levels_count
> 0) {
1211 for (i
= 0; i
< kbd_mode_levels_count
; ++i
)
1212 if (kbd_mode_levels
[i
] == state
->mode_bit
)
1220 static int kbd_set_level(struct kbd_state
*state
, u8 level
)
1222 if (kbd_info
.levels
!= 0) {
1224 kbd_previous_level
= level
;
1225 if (state
->level
== level
)
1227 state
->level
= level
;
1228 if (level
!= 0 && state
->mode_bit
== KBD_MODE_BIT_OFF
)
1229 state
->mode_bit
= kbd_previous_mode_bit
;
1230 else if (level
== 0 && state
->mode_bit
!= KBD_MODE_BIT_OFF
) {
1231 kbd_previous_mode_bit
= state
->mode_bit
;
1232 state
->mode_bit
= KBD_MODE_BIT_OFF
;
1237 if (kbd_mode_levels_count
> 0 && level
< kbd_mode_levels_count
) {
1239 kbd_previous_level
= level
;
1240 state
->mode_bit
= kbd_mode_levels
[level
];
1247 static int kbd_get_state(struct kbd_state
*state
)
1249 struct calling_interface_buffer
*buffer
;
1252 buffer
= dell_smbios_get_buffer();
1254 buffer
->input
[0] = 0x1;
1255 dell_smbios_send_request(4, 11);
1256 ret
= buffer
->output
[0];
1259 ret
= dell_smbios_error(ret
);
1263 state
->mode_bit
= ffs(buffer
->output
[1] & 0xFFFF);
1264 if (state
->mode_bit
!= 0)
1267 state
->triggers
= (buffer
->output
[1] >> 16) & 0xFF;
1268 state
->timeout_value
= (buffer
->output
[1] >> 24) & 0x3F;
1269 state
->timeout_unit
= (buffer
->output
[1] >> 30) & 0x3;
1270 state
->als_setting
= buffer
->output
[2] & 0xFF;
1271 state
->als_value
= (buffer
->output
[2] >> 8) & 0xFF;
1272 state
->level
= (buffer
->output
[2] >> 16) & 0xFF;
1275 dell_smbios_release_buffer();
1279 static int kbd_set_state(struct kbd_state
*state
)
1281 struct calling_interface_buffer
*buffer
;
1284 buffer
= dell_smbios_get_buffer();
1285 buffer
->input
[0] = 0x2;
1286 buffer
->input
[1] = BIT(state
->mode_bit
) & 0xFFFF;
1287 buffer
->input
[1] |= (state
->triggers
& 0xFF) << 16;
1288 buffer
->input
[1] |= (state
->timeout_value
& 0x3F) << 24;
1289 buffer
->input
[1] |= (state
->timeout_unit
& 0x3) << 30;
1290 buffer
->input
[2] = state
->als_setting
& 0xFF;
1291 buffer
->input
[2] |= (state
->level
& 0xFF) << 16;
1292 dell_smbios_send_request(4, 11);
1293 ret
= buffer
->output
[0];
1294 dell_smbios_release_buffer();
1296 return dell_smbios_error(ret
);
1299 static int kbd_set_state_safe(struct kbd_state
*state
, struct kbd_state
*old
)
1303 ret
= kbd_set_state(state
);
1308 * When setting the new state fails,try to restore the previous one.
1309 * This is needed on some machines where BIOS sets a default state when
1310 * setting a new state fails. This default state could be all off.
1313 if (kbd_set_state(old
))
1314 pr_err("Setting old previous keyboard state failed\n");
1319 static int kbd_set_token_bit(u8 bit
)
1321 struct calling_interface_buffer
*buffer
;
1322 struct calling_interface_token
*token
;
1325 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1328 token
= dell_smbios_find_token(kbd_tokens
[bit
]);
1332 buffer
= dell_smbios_get_buffer();
1333 buffer
->input
[0] = token
->location
;
1334 buffer
->input
[1] = token
->value
;
1335 dell_smbios_send_request(1, 0);
1336 ret
= buffer
->output
[0];
1337 dell_smbios_release_buffer();
1339 return dell_smbios_error(ret
);
1342 static int kbd_get_token_bit(u8 bit
)
1344 struct calling_interface_buffer
*buffer
;
1345 struct calling_interface_token
*token
;
1349 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1352 token
= dell_smbios_find_token(kbd_tokens
[bit
]);
1356 buffer
= dell_smbios_get_buffer();
1357 buffer
->input
[0] = token
->location
;
1358 dell_smbios_send_request(0, 0);
1359 ret
= buffer
->output
[0];
1360 val
= buffer
->output
[1];
1361 dell_smbios_release_buffer();
1364 return dell_smbios_error(ret
);
1366 return (val
== token
->value
);
1369 static int kbd_get_first_active_token_bit(void)
1374 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
) {
1375 ret
= kbd_get_token_bit(i
);
1383 static int kbd_get_valid_token_counts(void)
1385 return hweight16(kbd_token_bits
);
1388 static inline int kbd_init_info(void)
1390 struct kbd_state state
;
1394 ret
= kbd_get_info(&kbd_info
);
1398 kbd_get_state(&state
);
1400 /* NOTE: timeout value is stored in 6 bits so max value is 63 */
1401 if (kbd_info
.seconds
> 63)
1402 kbd_info
.seconds
= 63;
1403 if (kbd_info
.minutes
> 63)
1404 kbd_info
.minutes
= 63;
1405 if (kbd_info
.hours
> 63)
1406 kbd_info
.hours
= 63;
1407 if (kbd_info
.days
> 63)
1410 /* NOTE: On tested machines ON mode did not work and caused
1411 * problems (turned backlight off) so do not use it
1413 kbd_info
.modes
&= ~BIT(KBD_MODE_BIT_ON
);
1415 kbd_previous_level
= kbd_get_level(&state
);
1416 kbd_previous_mode_bit
= state
.mode_bit
;
1418 if (kbd_previous_level
== 0 && kbd_get_max_level() != 0)
1419 kbd_previous_level
= 1;
1421 if (kbd_previous_mode_bit
== KBD_MODE_BIT_OFF
) {
1422 kbd_previous_mode_bit
=
1423 ffs(kbd_info
.modes
& ~BIT(KBD_MODE_BIT_OFF
));
1424 if (kbd_previous_mode_bit
!= 0)
1425 kbd_previous_mode_bit
--;
1428 if (kbd_info
.modes
& (BIT(KBD_MODE_BIT_ALS
) |
1429 BIT(KBD_MODE_BIT_TRIGGER_ALS
)))
1430 kbd_als_supported
= true;
1432 if (kbd_info
.modes
& (
1433 BIT(KBD_MODE_BIT_TRIGGER_ALS
) | BIT(KBD_MODE_BIT_TRIGGER
) |
1434 BIT(KBD_MODE_BIT_TRIGGER_25
) | BIT(KBD_MODE_BIT_TRIGGER_50
) |
1435 BIT(KBD_MODE_BIT_TRIGGER_75
) | BIT(KBD_MODE_BIT_TRIGGER_100
)
1437 kbd_triggers_supported
= true;
1439 /* kbd_mode_levels[0] is reserved, see below */
1440 for (i
= 0; i
< 16; ++i
)
1441 if (kbd_is_level_mode_bit(i
) && (BIT(i
) & kbd_info
.modes
))
1442 kbd_mode_levels
[1 + kbd_mode_levels_count
++] = i
;
1445 * Find the first supported mode and assign to kbd_mode_levels[0].
1446 * This should be 0 (off), but we cannot depend on the BIOS to
1449 if (kbd_mode_levels_count
> 0) {
1450 for (i
= 0; i
< 16; ++i
) {
1451 if (BIT(i
) & kbd_info
.modes
) {
1452 kbd_mode_levels
[0] = i
;
1456 kbd_mode_levels_count
++;
1463 static inline void kbd_init_tokens(void)
1467 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
)
1468 if (dell_smbios_find_token(kbd_tokens
[i
]))
1469 kbd_token_bits
|= BIT(i
);
1472 static void kbd_init(void)
1476 ret
= kbd_init_info();
1479 if (kbd_token_bits
!= 0 || ret
== 0)
1480 kbd_led_present
= true;
1483 static ssize_t
kbd_led_timeout_store(struct device
*dev
,
1484 struct device_attribute
*attr
,
1485 const char *buf
, size_t count
)
1487 struct kbd_state new_state
;
1488 struct kbd_state state
;
1496 ret
= sscanf(buf
, "%d %c", &value
, &ch
);
1509 if (value
> kbd_info
.seconds
)
1511 unit
= KBD_TIMEOUT_SECONDS
;
1514 if (value
> kbd_info
.minutes
)
1516 unit
= KBD_TIMEOUT_MINUTES
;
1519 if (value
> kbd_info
.hours
)
1521 unit
= KBD_TIMEOUT_HOURS
;
1524 if (value
> kbd_info
.days
)
1526 unit
= KBD_TIMEOUT_DAYS
;
1532 if (quirks
&& quirks
->needs_kbd_timeouts
)
1536 /* Convert value from current units to seconds */
1538 case KBD_TIMEOUT_DAYS
:
1540 case KBD_TIMEOUT_HOURS
:
1542 case KBD_TIMEOUT_MINUTES
:
1544 unit
= KBD_TIMEOUT_SECONDS
;
1547 if (quirks
&& quirks
->needs_kbd_timeouts
) {
1548 for (i
= 0; quirks
->kbd_timeouts
[i
] != -1; i
++) {
1549 if (value
<= quirks
->kbd_timeouts
[i
]) {
1550 value
= quirks
->kbd_timeouts
[i
];
1556 if (value
<= kbd_info
.seconds
&& kbd_info
.seconds
) {
1557 unit
= KBD_TIMEOUT_SECONDS
;
1558 } else if (value
/ 60 <= kbd_info
.minutes
&& kbd_info
.minutes
) {
1560 unit
= KBD_TIMEOUT_MINUTES
;
1561 } else if (value
/ (60 * 60) <= kbd_info
.hours
&& kbd_info
.hours
) {
1563 unit
= KBD_TIMEOUT_HOURS
;
1564 } else if (value
/ (60 * 60 * 24) <= kbd_info
.days
&& kbd_info
.days
) {
1565 value
/= (60 * 60 * 24);
1566 unit
= KBD_TIMEOUT_DAYS
;
1572 mutex_lock(&kbd_led_mutex
);
1574 ret
= kbd_get_state(&state
);
1579 new_state
.timeout_value
= value
;
1580 new_state
.timeout_unit
= unit
;
1582 ret
= kbd_set_state_safe(&new_state
, &state
);
1588 mutex_unlock(&kbd_led_mutex
);
1592 static ssize_t
kbd_led_timeout_show(struct device
*dev
,
1593 struct device_attribute
*attr
, char *buf
)
1595 struct kbd_state state
;
1599 ret
= kbd_get_state(&state
);
1603 len
= sprintf(buf
, "%d", state
.timeout_value
);
1605 switch (state
.timeout_unit
) {
1606 case KBD_TIMEOUT_SECONDS
:
1607 return len
+ sprintf(buf
+len
, "s\n");
1608 case KBD_TIMEOUT_MINUTES
:
1609 return len
+ sprintf(buf
+len
, "m\n");
1610 case KBD_TIMEOUT_HOURS
:
1611 return len
+ sprintf(buf
+len
, "h\n");
1612 case KBD_TIMEOUT_DAYS
:
1613 return len
+ sprintf(buf
+len
, "d\n");
1621 static DEVICE_ATTR(stop_timeout
, S_IRUGO
| S_IWUSR
,
1622 kbd_led_timeout_show
, kbd_led_timeout_store
);
1624 static const char * const kbd_led_triggers
[] = {
1627 /*"trackstick"*/ NULL
, /* NOTE: trackstick is just alias for touchpad */
1631 static ssize_t
kbd_led_triggers_store(struct device
*dev
,
1632 struct device_attribute
*attr
,
1633 const char *buf
, size_t count
)
1635 struct kbd_state new_state
;
1636 struct kbd_state state
;
1637 bool triggers_enabled
= false;
1638 int trigger_bit
= -1;
1642 ret
= sscanf(buf
, "%20s", trigger
);
1646 if (trigger
[0] != '+' && trigger
[0] != '-')
1649 mutex_lock(&kbd_led_mutex
);
1651 ret
= kbd_get_state(&state
);
1655 if (kbd_triggers_supported
)
1656 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1658 if (kbd_triggers_supported
) {
1659 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1660 if (!(kbd_info
.triggers
& BIT(i
)))
1662 if (!kbd_led_triggers
[i
])
1664 if (strcmp(trigger
+1, kbd_led_triggers
[i
]) != 0)
1666 if (trigger
[0] == '+' &&
1667 triggers_enabled
&& (state
.triggers
& BIT(i
))) {
1671 if (trigger
[0] == '-' &&
1672 (!triggers_enabled
|| !(state
.triggers
& BIT(i
)))) {
1681 if (trigger_bit
== -1) {
1687 if (trigger
[0] == '+')
1688 new_state
.triggers
|= BIT(trigger_bit
);
1690 new_state
.triggers
&= ~BIT(trigger_bit
);
1692 * NOTE: trackstick bit (2) must be disabled when
1693 * disabling touchpad bit (1), otherwise touchpad
1694 * bit (1) will not be disabled
1696 if (trigger_bit
== 1)
1697 new_state
.triggers
&= ~BIT(2);
1699 if ((kbd_info
.triggers
& new_state
.triggers
) !=
1700 new_state
.triggers
) {
1704 if (new_state
.triggers
&& !triggers_enabled
) {
1705 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1706 kbd_set_level(&new_state
, kbd_previous_level
);
1707 } else if (new_state
.triggers
== 0) {
1708 kbd_set_level(&new_state
, 0);
1710 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
))) {
1714 ret
= kbd_set_state_safe(&new_state
, &state
);
1717 if (new_state
.mode_bit
!= KBD_MODE_BIT_OFF
)
1718 kbd_previous_mode_bit
= new_state
.mode_bit
;
1721 mutex_unlock(&kbd_led_mutex
);
1725 static ssize_t
kbd_led_triggers_show(struct device
*dev
,
1726 struct device_attribute
*attr
, char *buf
)
1728 struct kbd_state state
;
1729 bool triggers_enabled
;
1733 ret
= kbd_get_state(&state
);
1739 if (kbd_triggers_supported
) {
1740 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1741 level
= kbd_get_level(&state
);
1742 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1743 if (!(kbd_info
.triggers
& BIT(i
)))
1745 if (!kbd_led_triggers
[i
])
1747 if ((triggers_enabled
|| level
<= 0) &&
1748 (state
.triggers
& BIT(i
)))
1752 len
+= sprintf(buf
+len
, "%s ", kbd_led_triggers
[i
]);
1757 buf
[len
- 1] = '\n';
1762 static DEVICE_ATTR(start_triggers
, S_IRUGO
| S_IWUSR
,
1763 kbd_led_triggers_show
, kbd_led_triggers_store
);
1765 static ssize_t
kbd_led_als_enabled_store(struct device
*dev
,
1766 struct device_attribute
*attr
,
1767 const char *buf
, size_t count
)
1769 struct kbd_state new_state
;
1770 struct kbd_state state
;
1771 bool triggers_enabled
= false;
1775 ret
= kstrtoint(buf
, 0, &enable
);
1779 mutex_lock(&kbd_led_mutex
);
1781 ret
= kbd_get_state(&state
);
1785 if (enable
== kbd_is_als_mode_bit(state
.mode_bit
)) {
1792 if (kbd_triggers_supported
)
1793 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1796 if (triggers_enabled
)
1797 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER_ALS
;
1799 new_state
.mode_bit
= KBD_MODE_BIT_ALS
;
1801 if (triggers_enabled
) {
1802 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1803 kbd_set_level(&new_state
, kbd_previous_level
);
1805 new_state
.mode_bit
= KBD_MODE_BIT_ON
;
1808 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
))) {
1813 ret
= kbd_set_state_safe(&new_state
, &state
);
1816 kbd_previous_mode_bit
= new_state
.mode_bit
;
1820 mutex_unlock(&kbd_led_mutex
);
1824 static ssize_t
kbd_led_als_enabled_show(struct device
*dev
,
1825 struct device_attribute
*attr
,
1828 struct kbd_state state
;
1829 bool enabled
= false;
1832 ret
= kbd_get_state(&state
);
1835 enabled
= kbd_is_als_mode_bit(state
.mode_bit
);
1837 return sprintf(buf
, "%d\n", enabled
? 1 : 0);
1840 static DEVICE_ATTR(als_enabled
, S_IRUGO
| S_IWUSR
,
1841 kbd_led_als_enabled_show
, kbd_led_als_enabled_store
);
1843 static ssize_t
kbd_led_als_setting_store(struct device
*dev
,
1844 struct device_attribute
*attr
,
1845 const char *buf
, size_t count
)
1847 struct kbd_state state
;
1848 struct kbd_state new_state
;
1852 ret
= kstrtou8(buf
, 10, &setting
);
1856 mutex_lock(&kbd_led_mutex
);
1858 ret
= kbd_get_state(&state
);
1863 new_state
.als_setting
= setting
;
1865 ret
= kbd_set_state_safe(&new_state
, &state
);
1871 mutex_unlock(&kbd_led_mutex
);
1875 static ssize_t
kbd_led_als_setting_show(struct device
*dev
,
1876 struct device_attribute
*attr
,
1879 struct kbd_state state
;
1882 ret
= kbd_get_state(&state
);
1886 return sprintf(buf
, "%d\n", state
.als_setting
);
1889 static DEVICE_ATTR(als_setting
, S_IRUGO
| S_IWUSR
,
1890 kbd_led_als_setting_show
, kbd_led_als_setting_store
);
1892 static struct attribute
*kbd_led_attrs
[] = {
1893 &dev_attr_stop_timeout
.attr
,
1894 &dev_attr_start_triggers
.attr
,
1898 static const struct attribute_group kbd_led_group
= {
1899 .attrs
= kbd_led_attrs
,
1902 static struct attribute
*kbd_led_als_attrs
[] = {
1903 &dev_attr_als_enabled
.attr
,
1904 &dev_attr_als_setting
.attr
,
1908 static const struct attribute_group kbd_led_als_group
= {
1909 .attrs
= kbd_led_als_attrs
,
1912 static const struct attribute_group
*kbd_led_groups
[] = {
1918 static enum led_brightness
kbd_led_level_get(struct led_classdev
*led_cdev
)
1922 struct kbd_state state
;
1924 if (kbd_get_max_level()) {
1925 ret
= kbd_get_state(&state
);
1928 ret
= kbd_get_level(&state
);
1934 if (kbd_get_valid_token_counts()) {
1935 ret
= kbd_get_first_active_token_bit();
1938 for (num
= kbd_token_bits
; num
!= 0 && ret
> 0; --ret
)
1939 num
&= num
- 1; /* clear the first bit set */
1942 return ffs(num
) - 1;
1945 pr_warn("Keyboard brightness level control not supported\n");
1949 static int kbd_led_level_set(struct led_classdev
*led_cdev
,
1950 enum led_brightness value
)
1952 struct kbd_state state
;
1953 struct kbd_state new_state
;
1957 mutex_lock(&kbd_led_mutex
);
1959 if (kbd_get_max_level()) {
1960 ret
= kbd_get_state(&state
);
1964 ret
= kbd_set_level(&new_state
, value
);
1967 ret
= kbd_set_state_safe(&new_state
, &state
);
1968 } else if (kbd_get_valid_token_counts()) {
1969 for (num
= kbd_token_bits
; num
!= 0 && value
> 0; --value
)
1970 num
&= num
- 1; /* clear the first bit set */
1974 ret
= kbd_set_token_bit(ffs(num
) - 1);
1976 pr_warn("Keyboard brightness level control not supported\n");
1981 mutex_unlock(&kbd_led_mutex
);
1985 static struct led_classdev kbd_led
= {
1986 .name
= "dell::kbd_backlight",
1987 .brightness_set_blocking
= kbd_led_level_set
,
1988 .brightness_get
= kbd_led_level_get
,
1989 .groups
= kbd_led_groups
,
1992 static int __init
kbd_led_init(struct device
*dev
)
1995 if (!kbd_led_present
)
1997 if (!kbd_als_supported
)
1998 kbd_led_groups
[1] = NULL
;
1999 kbd_led
.max_brightness
= kbd_get_max_level();
2000 if (!kbd_led
.max_brightness
) {
2001 kbd_led
.max_brightness
= kbd_get_valid_token_counts();
2002 if (kbd_led
.max_brightness
)
2003 kbd_led
.max_brightness
--;
2005 return led_classdev_register(dev
, &kbd_led
);
2008 static void brightness_set_exit(struct led_classdev
*led_cdev
,
2009 enum led_brightness value
)
2011 /* Don't change backlight level on exit */
2014 static void kbd_led_exit(void)
2016 if (!kbd_led_present
)
2018 kbd_led
.brightness_set
= brightness_set_exit
;
2019 led_classdev_unregister(&kbd_led
);
2022 static int __init
dell_init(void)
2024 struct calling_interface_buffer
*buffer
;
2025 struct calling_interface_token
*token
;
2026 int max_intensity
= 0;
2029 if (!dmi_check_system(dell_device_table
))
2033 /* find if this machine support other functions */
2034 dmi_check_system(dell_quirks
);
2036 ret
= platform_driver_register(&platform_driver
);
2038 goto fail_platform_driver
;
2039 platform_device
= platform_device_alloc("dell-laptop", -1);
2040 if (!platform_device
) {
2042 goto fail_platform_device1
;
2044 ret
= platform_device_add(platform_device
);
2046 goto fail_platform_device2
;
2048 ret
= dell_setup_rfkill();
2051 pr_warn("Unable to setup rfkill\n");
2055 if (quirks
&& quirks
->touchpad_led
)
2056 touchpad_led_init(&platform_device
->dev
);
2058 kbd_led_init(&platform_device
->dev
);
2060 dell_laptop_dir
= debugfs_create_dir("dell_laptop", NULL
);
2061 if (dell_laptop_dir
!= NULL
)
2062 debugfs_create_file("rfkill", 0444, dell_laptop_dir
, NULL
,
2063 &dell_debugfs_fops
);
2065 if (acpi_video_get_backlight_type() != acpi_backlight_vendor
)
2068 token
= dell_smbios_find_token(BRIGHTNESS_TOKEN
);
2070 buffer
= dell_smbios_get_buffer();
2071 buffer
->input
[0] = token
->location
;
2072 dell_smbios_send_request(0, 2);
2073 if (buffer
->output
[0] == 0)
2074 max_intensity
= buffer
->output
[3];
2075 dell_smbios_release_buffer();
2078 if (max_intensity
) {
2079 struct backlight_properties props
;
2080 memset(&props
, 0, sizeof(struct backlight_properties
));
2081 props
.type
= BACKLIGHT_PLATFORM
;
2082 props
.max_brightness
= max_intensity
;
2083 dell_backlight_device
= backlight_device_register("dell_backlight",
2084 &platform_device
->dev
,
2089 if (IS_ERR(dell_backlight_device
)) {
2090 ret
= PTR_ERR(dell_backlight_device
);
2091 dell_backlight_device
= NULL
;
2092 goto fail_backlight
;
2095 dell_backlight_device
->props
.brightness
=
2096 dell_get_intensity(dell_backlight_device
);
2097 backlight_update_status(dell_backlight_device
);
2103 dell_cleanup_rfkill();
2105 platform_device_del(platform_device
);
2106 fail_platform_device2
:
2107 platform_device_put(platform_device
);
2108 fail_platform_device1
:
2109 platform_driver_unregister(&platform_driver
);
2110 fail_platform_driver
:
2114 static void __exit
dell_exit(void)
2116 debugfs_remove_recursive(dell_laptop_dir
);
2117 if (quirks
&& quirks
->touchpad_led
)
2118 touchpad_led_exit();
2120 backlight_device_unregister(dell_backlight_device
);
2121 dell_cleanup_rfkill();
2122 if (platform_device
) {
2123 platform_device_unregister(platform_device
);
2124 platform_driver_unregister(&platform_driver
);
2128 /* dell-rbtn.c driver export functions which will not work correctly (and could
2129 * cause kernel crash) if they are called before dell-rbtn.c init code. This is
2130 * not problem when dell-rbtn.c is compiled as external module. When both files
2131 * (dell-rbtn.c and dell-laptop.c) are compiled statically into kernel, then we
2132 * need to ensure that dell_init() will be called after initializing dell-rbtn.
2133 * This can be achieved by late_initcall() instead module_init().
2135 late_initcall(dell_init
);
2136 module_exit(dell_exit
);
2138 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
2139 MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
2140 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
2141 MODULE_DESCRIPTION("Dell laptop driver");
2142 MODULE_LICENSE("GPL");