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/slab.h>
32 #include <linux/debugfs.h>
33 #include <linux/seq_file.h>
34 #include "../../firmware/dcdbas.h"
36 #define BRIGHTNESS_TOKEN 0x7d
37 #define KBD_LED_OFF_TOKEN 0x01E1
38 #define KBD_LED_ON_TOKEN 0x01E2
39 #define KBD_LED_AUTO_TOKEN 0x01E3
40 #define KBD_LED_AUTO_25_TOKEN 0x02EA
41 #define KBD_LED_AUTO_50_TOKEN 0x02EB
42 #define KBD_LED_AUTO_75_TOKEN 0x02EC
43 #define KBD_LED_AUTO_100_TOKEN 0x02F6
45 /* This structure will be modified by the firmware when we enter
46 * system management mode, hence the volatiles */
48 struct calling_interface_buffer
{
51 volatile u32 input
[4];
52 volatile u32 output
[4];
55 struct calling_interface_token
{
64 struct calling_interface_structure
{
65 struct dmi_header header
;
69 struct calling_interface_token tokens
[];
75 int needs_kbd_timeouts
;
77 * Ordered list of timeouts expressed in seconds.
78 * The list must end with -1
83 static struct quirk_entry
*quirks
;
85 static struct quirk_entry quirk_dell_vostro_v130
= {
89 static int __init
dmi_matched(const struct dmi_system_id
*dmi
)
91 quirks
= dmi
->driver_data
;
96 * These values come from Windows utility provided by Dell. If any other value
97 * is used then BIOS silently set timeout to 0 without any error message.
99 static struct quirk_entry quirk_dell_xps13_9333
= {
100 .needs_kbd_timeouts
= 1,
101 .kbd_timeouts
= { 0, 5, 15, 60, 5 * 60, 15 * 60, -1 },
104 static int da_command_address
;
105 static int da_command_code
;
106 static int da_num_tokens
;
107 static struct calling_interface_token
*da_tokens
;
109 static struct platform_driver platform_driver
= {
111 .name
= "dell-laptop",
115 static struct platform_device
*platform_device
;
116 static struct backlight_device
*dell_backlight_device
;
117 static struct rfkill
*wifi_rfkill
;
118 static struct rfkill
*bluetooth_rfkill
;
119 static struct rfkill
*wwan_rfkill
;
120 static bool force_rfkill
;
122 module_param(force_rfkill
, bool, 0444);
123 MODULE_PARM_DESC(force_rfkill
, "enable rfkill on non whitelisted models");
125 static const struct dmi_system_id dell_device_table
[] __initconst
= {
127 .ident
= "Dell laptop",
129 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
130 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
135 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
136 DMI_MATCH(DMI_CHASSIS_TYPE
, "9"), /*Laptop*/
140 .ident
= "Dell Computer Corporation",
142 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Computer Corporation"),
143 DMI_MATCH(DMI_CHASSIS_TYPE
, "8"),
148 MODULE_DEVICE_TABLE(dmi
, dell_device_table
);
150 static const struct dmi_system_id dell_quirks
[] __initconst
= {
152 .callback
= dmi_matched
,
153 .ident
= "Dell Vostro V130",
155 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
156 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V130"),
158 .driver_data
= &quirk_dell_vostro_v130
,
161 .callback
= dmi_matched
,
162 .ident
= "Dell Vostro V131",
164 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
165 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro V131"),
167 .driver_data
= &quirk_dell_vostro_v130
,
170 .callback
= dmi_matched
,
171 .ident
= "Dell Vostro 3350",
173 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
174 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3350"),
176 .driver_data
= &quirk_dell_vostro_v130
,
179 .callback
= dmi_matched
,
180 .ident
= "Dell Vostro 3555",
182 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
183 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3555"),
185 .driver_data
= &quirk_dell_vostro_v130
,
188 .callback
= dmi_matched
,
189 .ident
= "Dell Inspiron N311z",
191 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
192 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron N311z"),
194 .driver_data
= &quirk_dell_vostro_v130
,
197 .callback
= dmi_matched
,
198 .ident
= "Dell Inspiron M5110",
200 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
201 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron M5110"),
203 .driver_data
= &quirk_dell_vostro_v130
,
206 .callback
= dmi_matched
,
207 .ident
= "Dell Vostro 3360",
209 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
210 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3360"),
212 .driver_data
= &quirk_dell_vostro_v130
,
215 .callback
= dmi_matched
,
216 .ident
= "Dell Vostro 3460",
218 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
219 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3460"),
221 .driver_data
= &quirk_dell_vostro_v130
,
224 .callback
= dmi_matched
,
225 .ident
= "Dell Vostro 3560",
227 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
228 DMI_MATCH(DMI_PRODUCT_NAME
, "Vostro 3560"),
230 .driver_data
= &quirk_dell_vostro_v130
,
233 .callback
= dmi_matched
,
234 .ident
= "Dell Vostro 3450",
236 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
237 DMI_MATCH(DMI_PRODUCT_NAME
, "Dell System Vostro 3450"),
239 .driver_data
= &quirk_dell_vostro_v130
,
242 .callback
= dmi_matched
,
243 .ident
= "Dell Inspiron 5420",
245 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
246 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5420"),
248 .driver_data
= &quirk_dell_vostro_v130
,
251 .callback
= dmi_matched
,
252 .ident
= "Dell Inspiron 5520",
254 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
255 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5520"),
257 .driver_data
= &quirk_dell_vostro_v130
,
260 .callback
= dmi_matched
,
261 .ident
= "Dell Inspiron 5720",
263 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
264 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 5720"),
266 .driver_data
= &quirk_dell_vostro_v130
,
269 .callback
= dmi_matched
,
270 .ident
= "Dell Inspiron 7420",
272 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
273 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7420"),
275 .driver_data
= &quirk_dell_vostro_v130
,
278 .callback
= dmi_matched
,
279 .ident
= "Dell Inspiron 7520",
281 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
282 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7520"),
284 .driver_data
= &quirk_dell_vostro_v130
,
287 .callback
= dmi_matched
,
288 .ident
= "Dell Inspiron 7720",
290 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
291 DMI_MATCH(DMI_PRODUCT_NAME
, "Inspiron 7720"),
293 .driver_data
= &quirk_dell_vostro_v130
,
296 .callback
= dmi_matched
,
297 .ident
= "Dell XPS13 9333",
299 DMI_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
300 DMI_MATCH(DMI_PRODUCT_NAME
, "XPS13 9333"),
302 .driver_data
= &quirk_dell_xps13_9333
,
307 static struct calling_interface_buffer
*buffer
;
308 static DEFINE_MUTEX(buffer_mutex
);
310 static int hwswitch_state
;
312 static void get_buffer(void)
314 mutex_lock(&buffer_mutex
);
315 memset(buffer
, 0, sizeof(struct calling_interface_buffer
));
318 static void release_buffer(void)
320 mutex_unlock(&buffer_mutex
);
323 static void __init
parse_da_table(const struct dmi_header
*dm
)
325 /* Final token is a terminator, so we don't want to copy it */
326 int tokens
= (dm
->length
-11)/sizeof(struct calling_interface_token
)-1;
327 struct calling_interface_token
*new_da_tokens
;
328 struct calling_interface_structure
*table
=
329 container_of(dm
, struct calling_interface_structure
, header
);
331 /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least
337 da_command_address
= table
->cmdIOAddress
;
338 da_command_code
= table
->cmdIOCode
;
340 new_da_tokens
= krealloc(da_tokens
, (da_num_tokens
+ tokens
) *
341 sizeof(struct calling_interface_token
),
346 da_tokens
= new_da_tokens
;
348 memcpy(da_tokens
+da_num_tokens
, table
->tokens
,
349 sizeof(struct calling_interface_token
) * tokens
);
351 da_num_tokens
+= tokens
;
354 static void __init
find_tokens(const struct dmi_header
*dm
, void *dummy
)
357 case 0xd4: /* Indexed IO */
358 case 0xd5: /* Protected Area Type 1 */
359 case 0xd6: /* Protected Area Type 2 */
361 case 0xda: /* Calling interface */
367 static int find_token_id(int tokenid
)
371 for (i
= 0; i
< da_num_tokens
; i
++) {
372 if (da_tokens
[i
].tokenID
== tokenid
)
379 static int find_token_location(int tokenid
)
383 id
= find_token_id(tokenid
);
387 return da_tokens
[id
].location
;
390 static struct calling_interface_buffer
*
391 dell_send_request(struct calling_interface_buffer
*buffer
, int class,
394 struct smi_cmd command
;
396 command
.magic
= SMI_CMD_MAGIC
;
397 command
.command_address
= da_command_address
;
398 command
.command_code
= da_command_code
;
399 command
.ebx
= virt_to_phys(buffer
);
400 command
.ecx
= 0x42534931;
402 buffer
->class = class;
403 buffer
->select
= select
;
405 dcdbas_smi_request(&command
);
410 static inline int dell_smi_error(int value
)
413 case 0: /* Completed successfully */
415 case -1: /* Completed with error */
417 case -2: /* Function not supported */
419 default: /* Unknown error */
424 /* Derived from information in DellWirelessCtl.cpp:
425 Class 17, select 11 is radio control. It returns an array of 32-bit values.
427 Input byte 0 = 0: Wireless information
429 result[0]: return code
431 Bit 0: Hardware switch supported
432 Bit 1: Wifi locator supported
433 Bit 2: Wifi is supported
434 Bit 3: Bluetooth is supported
435 Bit 4: WWAN is supported
436 Bit 5: Wireless keyboard supported
438 Bit 8: Wifi is installed
439 Bit 9: Bluetooth is installed
440 Bit 10: WWAN is installed
442 Bit 16: Hardware switch is on
443 Bit 17: Wifi is blocked
444 Bit 18: Bluetooth is blocked
445 Bit 19: WWAN is blocked
447 result[2]: NVRAM size in bytes
448 result[3]: NVRAM format version number
450 Input byte 0 = 2: Wireless switch configuration
451 result[0]: return code
453 Bit 0: Wifi controlled by switch
454 Bit 1: Bluetooth controlled by switch
455 Bit 2: WWAN controlled by switch
457 Bit 7: Wireless switch config locked
458 Bit 8: Wifi locator enabled
460 Bit 15: Wifi locator setting locked
464 static int dell_rfkill_set(void *data
, bool blocked
)
466 int disable
= blocked
? 1 : 0;
467 unsigned long radio
= (unsigned long)data
;
468 int hwswitch_bit
= (unsigned long)data
- 1;
471 dell_send_request(buffer
, 17, 11);
473 /* If the hardware switch controls this radio, and the hardware
474 switch is disabled, always disable the radio */
475 if ((hwswitch_state
& BIT(hwswitch_bit
)) &&
476 !(buffer
->output
[1] & BIT(16)))
479 buffer
->input
[0] = (1 | (radio
<<8) | (disable
<< 16));
480 dell_send_request(buffer
, 17, 11);
486 /* Must be called with the buffer held */
487 static void dell_rfkill_update_sw_state(struct rfkill
*rfkill
, int radio
,
490 if (status
& BIT(0)) {
491 /* Has hw-switch, sync sw_state to BIOS */
492 int block
= rfkill_blocked(rfkill
);
493 buffer
->input
[0] = (1 | (radio
<< 8) | (block
<< 16));
494 dell_send_request(buffer
, 17, 11);
496 /* No hw-switch, sync BIOS state to sw_state */
497 rfkill_set_sw_state(rfkill
, !!(status
& BIT(radio
+ 16)));
501 static void dell_rfkill_update_hw_state(struct rfkill
*rfkill
, int radio
,
504 if (hwswitch_state
& (BIT(radio
- 1)))
505 rfkill_set_hw_state(rfkill
, !(status
& BIT(16)));
508 static void dell_rfkill_query(struct rfkill
*rfkill
, void *data
)
513 dell_send_request(buffer
, 17, 11);
514 status
= buffer
->output
[1];
516 dell_rfkill_update_hw_state(rfkill
, (unsigned long)data
, status
);
521 static const struct rfkill_ops dell_rfkill_ops
= {
522 .set_block
= dell_rfkill_set
,
523 .query
= dell_rfkill_query
,
526 static struct dentry
*dell_laptop_dir
;
528 static int dell_debugfs_show(struct seq_file
*s
, void *data
)
533 dell_send_request(buffer
, 17, 11);
534 status
= buffer
->output
[1];
537 seq_printf(s
, "status:\t0x%X\n", status
);
538 seq_printf(s
, "Bit 0 : Hardware switch supported: %lu\n",
540 seq_printf(s
, "Bit 1 : Wifi locator supported: %lu\n",
541 (status
& BIT(1)) >> 1);
542 seq_printf(s
, "Bit 2 : Wifi is supported: %lu\n",
543 (status
& BIT(2)) >> 2);
544 seq_printf(s
, "Bit 3 : Bluetooth is supported: %lu\n",
545 (status
& BIT(3)) >> 3);
546 seq_printf(s
, "Bit 4 : WWAN is supported: %lu\n",
547 (status
& BIT(4)) >> 4);
548 seq_printf(s
, "Bit 5 : Wireless keyboard supported: %lu\n",
549 (status
& BIT(5)) >> 5);
550 seq_printf(s
, "Bit 8 : Wifi is installed: %lu\n",
551 (status
& BIT(8)) >> 8);
552 seq_printf(s
, "Bit 9 : Bluetooth is installed: %lu\n",
553 (status
& BIT(9)) >> 9);
554 seq_printf(s
, "Bit 10: WWAN is installed: %lu\n",
555 (status
& BIT(10)) >> 10);
556 seq_printf(s
, "Bit 16: Hardware switch is on: %lu\n",
557 (status
& BIT(16)) >> 16);
558 seq_printf(s
, "Bit 17: Wifi is blocked: %lu\n",
559 (status
& BIT(17)) >> 17);
560 seq_printf(s
, "Bit 18: Bluetooth is blocked: %lu\n",
561 (status
& BIT(18)) >> 18);
562 seq_printf(s
, "Bit 19: WWAN is blocked: %lu\n",
563 (status
& BIT(19)) >> 19);
565 seq_printf(s
, "\nhwswitch_state:\t0x%X\n", hwswitch_state
);
566 seq_printf(s
, "Bit 0 : Wifi controlled by switch: %lu\n",
567 hwswitch_state
& BIT(0));
568 seq_printf(s
, "Bit 1 : Bluetooth controlled by switch: %lu\n",
569 (hwswitch_state
& BIT(1)) >> 1);
570 seq_printf(s
, "Bit 2 : WWAN controlled by switch: %lu\n",
571 (hwswitch_state
& BIT(2)) >> 2);
572 seq_printf(s
, "Bit 7 : Wireless switch config locked: %lu\n",
573 (hwswitch_state
& BIT(7)) >> 7);
574 seq_printf(s
, "Bit 8 : Wifi locator enabled: %lu\n",
575 (hwswitch_state
& BIT(8)) >> 8);
576 seq_printf(s
, "Bit 15: Wifi locator setting locked: %lu\n",
577 (hwswitch_state
& BIT(15)) >> 15);
582 static int dell_debugfs_open(struct inode
*inode
, struct file
*file
)
584 return single_open(file
, dell_debugfs_show
, inode
->i_private
);
587 static const struct file_operations dell_debugfs_fops
= {
588 .owner
= THIS_MODULE
,
589 .open
= dell_debugfs_open
,
592 .release
= single_release
,
595 static void dell_update_rfkill(struct work_struct
*ignored
)
600 dell_send_request(buffer
, 17, 11);
601 status
= buffer
->output
[1];
604 dell_rfkill_update_hw_state(wifi_rfkill
, 1, status
);
605 dell_rfkill_update_sw_state(wifi_rfkill
, 1, status
);
607 if (bluetooth_rfkill
) {
608 dell_rfkill_update_hw_state(bluetooth_rfkill
, 2, status
);
609 dell_rfkill_update_sw_state(bluetooth_rfkill
, 2, status
);
612 dell_rfkill_update_hw_state(wwan_rfkill
, 3, status
);
613 dell_rfkill_update_sw_state(wwan_rfkill
, 3, status
);
618 static DECLARE_DELAYED_WORK(dell_rfkill_work
, dell_update_rfkill
);
620 static bool dell_laptop_i8042_filter(unsigned char data
, unsigned char str
,
623 static bool extended
;
625 if (str
& I8042_STR_AUXDATA
)
628 if (unlikely(data
== 0xe0)) {
631 } else if (unlikely(extended
)) {
634 schedule_delayed_work(&dell_rfkill_work
,
635 round_jiffies_relative(HZ
/ 4));
644 static int __init
dell_setup_rfkill(void)
646 int status
, ret
, whitelisted
;
650 * rfkill support causes trouble on various models, mostly Inspirons.
651 * So we whitelist certain series, and don't support rfkill on others.
654 product
= dmi_get_system_info(DMI_PRODUCT_NAME
);
655 if (product
&& (strncmp(product
, "Latitude", 8) == 0 ||
656 strncmp(product
, "Precision", 9) == 0))
658 if (!force_rfkill
&& !whitelisted
)
662 dell_send_request(buffer
, 17, 11);
663 status
= buffer
->output
[1];
664 buffer
->input
[0] = 0x2;
665 dell_send_request(buffer
, 17, 11);
666 hwswitch_state
= buffer
->output
[1];
669 if (!(status
& BIT(0))) {
671 /* No hwsitch, clear all hw-controlled bits */
672 hwswitch_state
&= ~7;
674 /* rfkill is only tested on laptops with a hwswitch */
679 if ((status
& (1<<2|1<<8)) == (1<<2|1<<8)) {
680 wifi_rfkill
= rfkill_alloc("dell-wifi", &platform_device
->dev
,
682 &dell_rfkill_ops
, (void *) 1);
687 ret
= rfkill_register(wifi_rfkill
);
692 if ((status
& (1<<3|1<<9)) == (1<<3|1<<9)) {
693 bluetooth_rfkill
= rfkill_alloc("dell-bluetooth",
694 &platform_device
->dev
,
695 RFKILL_TYPE_BLUETOOTH
,
696 &dell_rfkill_ops
, (void *) 2);
697 if (!bluetooth_rfkill
) {
701 ret
= rfkill_register(bluetooth_rfkill
);
706 if ((status
& (1<<4|1<<10)) == (1<<4|1<<10)) {
707 wwan_rfkill
= rfkill_alloc("dell-wwan",
708 &platform_device
->dev
,
710 &dell_rfkill_ops
, (void *) 3);
715 ret
= rfkill_register(wwan_rfkill
);
720 ret
= i8042_install_filter(dell_laptop_i8042_filter
);
722 pr_warn("Unable to install key filter\n");
729 rfkill_unregister(wwan_rfkill
);
731 rfkill_destroy(wwan_rfkill
);
732 if (bluetooth_rfkill
)
733 rfkill_unregister(bluetooth_rfkill
);
735 rfkill_destroy(bluetooth_rfkill
);
737 rfkill_unregister(wifi_rfkill
);
739 rfkill_destroy(wifi_rfkill
);
744 static void dell_cleanup_rfkill(void)
747 rfkill_unregister(wifi_rfkill
);
748 rfkill_destroy(wifi_rfkill
);
750 if (bluetooth_rfkill
) {
751 rfkill_unregister(bluetooth_rfkill
);
752 rfkill_destroy(bluetooth_rfkill
);
755 rfkill_unregister(wwan_rfkill
);
756 rfkill_destroy(wwan_rfkill
);
760 static int dell_send_intensity(struct backlight_device
*bd
)
765 buffer
->input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
766 buffer
->input
[1] = bd
->props
.brightness
;
768 if (buffer
->input
[0] == -1) {
773 if (power_supply_is_system_supplied() > 0)
774 dell_send_request(buffer
, 1, 2);
776 dell_send_request(buffer
, 1, 1);
783 static int dell_get_intensity(struct backlight_device
*bd
)
788 buffer
->input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
790 if (buffer
->input
[0] == -1) {
795 if (power_supply_is_system_supplied() > 0)
796 dell_send_request(buffer
, 0, 2);
798 dell_send_request(buffer
, 0, 1);
800 ret
= buffer
->output
[1];
807 static const struct backlight_ops dell_ops
= {
808 .get_brightness
= dell_get_intensity
,
809 .update_status
= dell_send_intensity
,
812 static void touchpad_led_on(void)
816 i8042_command(&data
, command
| 1 << 12);
819 static void touchpad_led_off(void)
823 i8042_command(&data
, command
| 1 << 12);
826 static void touchpad_led_set(struct led_classdev
*led_cdev
,
827 enum led_brightness value
)
835 static struct led_classdev touchpad_led
= {
836 .name
= "dell-laptop::touchpad",
837 .brightness_set
= touchpad_led_set
,
838 .flags
= LED_CORE_SUSPENDRESUME
,
841 static int __init
touchpad_led_init(struct device
*dev
)
843 return led_classdev_register(dev
, &touchpad_led
);
846 static void touchpad_led_exit(void)
848 led_classdev_unregister(&touchpad_led
);
852 * Derived from information in smbios-keyboard-ctl:
856 * Keyboard illumination
857 * cbArg1 determines the function to be performed
859 * cbArg1 0x0 = Get Feature Information
860 * cbRES1 Standard return codes (0, -1, -2)
861 * cbRES2, word0 Bitmap of user-selectable modes
862 * bit 0 Always off (All systems)
863 * bit 1 Always on (Travis ATG, Siberia)
864 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
865 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
866 * bit 4 Auto: Input-activity-based On; input-activity based Off
867 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
868 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
869 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
870 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
871 * bits 9-15 Reserved for future use
872 * cbRES2, byte2 Reserved for future use
873 * cbRES2, byte3 Keyboard illumination type
877 * 3-255 Reserved for future use
878 * cbRES3, byte0 Supported auto keyboard illumination trigger bitmap.
879 * bit 0 Any keystroke
880 * bit 1 Touchpad activity
881 * bit 2 Pointing stick
883 * bits 4-7 Reserved for future use
884 * cbRES3, byte1 Supported timeout unit bitmap
889 * bits 4-7 Reserved for future use
890 * cbRES3, byte2 Number of keyboard light brightness levels
891 * cbRES4, byte0 Maximum acceptable seconds value (0 if seconds not supported).
892 * cbRES4, byte1 Maximum acceptable minutes value (0 if minutes not supported).
893 * cbRES4, byte2 Maximum acceptable hours value (0 if hours not supported).
894 * cbRES4, byte3 Maximum acceptable days value (0 if days not supported)
896 * cbArg1 0x1 = Get Current State
897 * cbRES1 Standard return codes (0, -1, -2)
898 * cbRES2, word0 Bitmap of current mode state
899 * bit 0 Always off (All systems)
900 * bit 1 Always on (Travis ATG, Siberia)
901 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
902 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
903 * bit 4 Auto: Input-activity-based On; input-activity based Off
904 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
905 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
906 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
907 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
908 * bits 9-15 Reserved for future use
909 * Note: Only One bit can be set
910 * cbRES2, byte2 Currently active auto keyboard illumination triggers.
911 * bit 0 Any keystroke
912 * bit 1 Touchpad activity
913 * bit 2 Pointing stick
915 * bits 4-7 Reserved for future use
916 * cbRES2, byte3 Current Timeout
917 * bits 7:6 Timeout units indicator:
922 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
923 * NOTE: A value of 0 means always on (no timeout) if any bits of RES3 byte
924 * are set upon return from the [Get feature information] call.
925 * cbRES3, byte0 Current setting of ALS value that turns the light on or off.
926 * cbRES3, byte1 Current ALS reading
927 * cbRES3, byte2 Current keyboard light level.
929 * cbArg1 0x2 = Set New State
930 * cbRES1 Standard return codes (0, -1, -2)
931 * cbArg2, word0 Bitmap of current mode state
932 * bit 0 Always off (All systems)
933 * bit 1 Always on (Travis ATG, Siberia)
934 * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG)
935 * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off
936 * bit 4 Auto: Input-activity-based On; input-activity based Off
937 * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off
938 * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off
939 * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off
940 * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off
941 * bits 9-15 Reserved for future use
942 * Note: Only One bit can be set
943 * cbArg2, byte2 Desired auto keyboard illumination triggers. Must remain inactive to allow
944 * keyboard to turn off automatically.
945 * bit 0 Any keystroke
946 * bit 1 Touchpad activity
947 * bit 2 Pointing stick
949 * bits 4-7 Reserved for future use
950 * cbArg2, byte3 Desired Timeout
951 * bits 7:6 Timeout units indicator:
956 * bits 5:0 Timeout value (0-63) in sec/min/hr/day
957 * cbArg3, byte0 Desired setting of ALS value that turns the light on or off.
958 * cbArg3, byte2 Desired keyboard light level.
962 enum kbd_timeout_unit
{
963 KBD_TIMEOUT_SECONDS
= 0,
970 KBD_MODE_BIT_OFF
= 0,
973 KBD_MODE_BIT_TRIGGER_ALS
,
974 KBD_MODE_BIT_TRIGGER
,
975 KBD_MODE_BIT_TRIGGER_25
,
976 KBD_MODE_BIT_TRIGGER_50
,
977 KBD_MODE_BIT_TRIGGER_75
,
978 KBD_MODE_BIT_TRIGGER_100
,
981 #define kbd_is_als_mode_bit(bit) \
982 ((bit) == KBD_MODE_BIT_ALS || (bit) == KBD_MODE_BIT_TRIGGER_ALS)
983 #define kbd_is_trigger_mode_bit(bit) \
984 ((bit) >= KBD_MODE_BIT_TRIGGER_ALS && (bit) <= KBD_MODE_BIT_TRIGGER_100)
985 #define kbd_is_level_mode_bit(bit) \
986 ((bit) >= KBD_MODE_BIT_TRIGGER_25 && (bit) <= KBD_MODE_BIT_TRIGGER_100)
1009 static const int kbd_tokens
[] = {
1011 KBD_LED_AUTO_25_TOKEN
,
1012 KBD_LED_AUTO_50_TOKEN
,
1013 KBD_LED_AUTO_75_TOKEN
,
1014 KBD_LED_AUTO_100_TOKEN
,
1018 static u16 kbd_token_bits
;
1020 static struct kbd_info kbd_info
;
1021 static bool kbd_als_supported
;
1022 static bool kbd_triggers_supported
;
1024 static u8 kbd_mode_levels
[16];
1025 static int kbd_mode_levels_count
;
1027 static u8 kbd_previous_level
;
1028 static u8 kbd_previous_mode_bit
;
1030 static bool kbd_led_present
;
1033 * NOTE: there are three ways to set the keyboard backlight level.
1034 * First, via kbd_state.mode_bit (assigning KBD_MODE_BIT_TRIGGER_* value).
1035 * Second, via kbd_state.level (assigning numerical value <= kbd_info.levels).
1036 * Third, via SMBIOS tokens (KBD_LED_* in kbd_tokens)
1038 * There are laptops which support only one of these methods. If we want to
1039 * support as many machines as possible we need to implement all three methods.
1040 * The first two methods use the kbd_state structure. The third uses SMBIOS
1041 * tokens. If kbd_info.levels == 0, the machine does not support setting the
1042 * keyboard backlight level via kbd_state.level.
1045 static int kbd_get_info(struct kbd_info
*info
)
1052 buffer
->input
[0] = 0x0;
1053 dell_send_request(buffer
, 4, 11);
1054 ret
= buffer
->output
[0];
1057 ret
= dell_smi_error(ret
);
1061 info
->modes
= buffer
->output
[1] & 0xFFFF;
1062 info
->type
= (buffer
->output
[1] >> 24) & 0xFF;
1063 info
->triggers
= buffer
->output
[2] & 0xFF;
1064 units
= (buffer
->output
[2] >> 8) & 0xFF;
1065 info
->levels
= (buffer
->output
[2] >> 16) & 0xFF;
1068 info
->seconds
= (buffer
->output
[3] >> 0) & 0xFF;
1070 info
->minutes
= (buffer
->output
[3] >> 8) & 0xFF;
1072 info
->hours
= (buffer
->output
[3] >> 16) & 0xFF;
1074 info
->days
= (buffer
->output
[3] >> 24) & 0xFF;
1081 static unsigned int kbd_get_max_level(void)
1083 if (kbd_info
.levels
!= 0)
1084 return kbd_info
.levels
;
1085 if (kbd_mode_levels_count
> 0)
1086 return kbd_mode_levels_count
- 1;
1090 static int kbd_get_level(struct kbd_state
*state
)
1094 if (kbd_info
.levels
!= 0)
1095 return state
->level
;
1097 if (kbd_mode_levels_count
> 0) {
1098 for (i
= 0; i
< kbd_mode_levels_count
; ++i
)
1099 if (kbd_mode_levels
[i
] == state
->mode_bit
)
1107 static int kbd_set_level(struct kbd_state
*state
, u8 level
)
1109 if (kbd_info
.levels
!= 0) {
1111 kbd_previous_level
= level
;
1112 if (state
->level
== level
)
1114 state
->level
= level
;
1115 if (level
!= 0 && state
->mode_bit
== KBD_MODE_BIT_OFF
)
1116 state
->mode_bit
= kbd_previous_mode_bit
;
1117 else if (level
== 0 && state
->mode_bit
!= KBD_MODE_BIT_OFF
) {
1118 kbd_previous_mode_bit
= state
->mode_bit
;
1119 state
->mode_bit
= KBD_MODE_BIT_OFF
;
1124 if (kbd_mode_levels_count
> 0 && level
< kbd_mode_levels_count
) {
1126 kbd_previous_level
= level
;
1127 state
->mode_bit
= kbd_mode_levels
[level
];
1134 static int kbd_get_state(struct kbd_state
*state
)
1140 buffer
->input
[0] = 0x1;
1141 dell_send_request(buffer
, 4, 11);
1142 ret
= buffer
->output
[0];
1145 ret
= dell_smi_error(ret
);
1149 state
->mode_bit
= ffs(buffer
->output
[1] & 0xFFFF);
1150 if (state
->mode_bit
!= 0)
1153 state
->triggers
= (buffer
->output
[1] >> 16) & 0xFF;
1154 state
->timeout_value
= (buffer
->output
[1] >> 24) & 0x3F;
1155 state
->timeout_unit
= (buffer
->output
[1] >> 30) & 0x3;
1156 state
->als_setting
= buffer
->output
[2] & 0xFF;
1157 state
->als_value
= (buffer
->output
[2] >> 8) & 0xFF;
1158 state
->level
= (buffer
->output
[2] >> 16) & 0xFF;
1165 static int kbd_set_state(struct kbd_state
*state
)
1170 buffer
->input
[0] = 0x2;
1171 buffer
->input
[1] = BIT(state
->mode_bit
) & 0xFFFF;
1172 buffer
->input
[1] |= (state
->triggers
& 0xFF) << 16;
1173 buffer
->input
[1] |= (state
->timeout_value
& 0x3F) << 24;
1174 buffer
->input
[1] |= (state
->timeout_unit
& 0x3) << 30;
1175 buffer
->input
[2] = state
->als_setting
& 0xFF;
1176 buffer
->input
[2] |= (state
->level
& 0xFF) << 16;
1177 dell_send_request(buffer
, 4, 11);
1178 ret
= buffer
->output
[0];
1181 return dell_smi_error(ret
);
1184 static int kbd_set_state_safe(struct kbd_state
*state
, struct kbd_state
*old
)
1188 ret
= kbd_set_state(state
);
1193 * When setting the new state fails,try to restore the previous one.
1194 * This is needed on some machines where BIOS sets a default state when
1195 * setting a new state fails. This default state could be all off.
1198 if (kbd_set_state(old
))
1199 pr_err("Setting old previous keyboard state failed\n");
1204 static int kbd_set_token_bit(u8 bit
)
1209 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1212 id
= find_token_id(kbd_tokens
[bit
]);
1217 buffer
->input
[0] = da_tokens
[id
].location
;
1218 buffer
->input
[1] = da_tokens
[id
].value
;
1219 dell_send_request(buffer
, 1, 0);
1220 ret
= buffer
->output
[0];
1223 return dell_smi_error(ret
);
1226 static int kbd_get_token_bit(u8 bit
)
1232 if (bit
>= ARRAY_SIZE(kbd_tokens
))
1235 id
= find_token_id(kbd_tokens
[bit
]);
1240 buffer
->input
[0] = da_tokens
[id
].location
;
1241 dell_send_request(buffer
, 0, 0);
1242 ret
= buffer
->output
[0];
1243 val
= buffer
->output
[1];
1247 return dell_smi_error(ret
);
1249 return (val
== da_tokens
[id
].value
);
1252 static int kbd_get_first_active_token_bit(void)
1257 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
) {
1258 ret
= kbd_get_token_bit(i
);
1266 static int kbd_get_valid_token_counts(void)
1268 return hweight16(kbd_token_bits
);
1271 static inline int kbd_init_info(void)
1273 struct kbd_state state
;
1277 ret
= kbd_get_info(&kbd_info
);
1281 kbd_get_state(&state
);
1283 /* NOTE: timeout value is stored in 6 bits so max value is 63 */
1284 if (kbd_info
.seconds
> 63)
1285 kbd_info
.seconds
= 63;
1286 if (kbd_info
.minutes
> 63)
1287 kbd_info
.minutes
= 63;
1288 if (kbd_info
.hours
> 63)
1289 kbd_info
.hours
= 63;
1290 if (kbd_info
.days
> 63)
1293 /* NOTE: On tested machines ON mode did not work and caused
1294 * problems (turned backlight off) so do not use it
1296 kbd_info
.modes
&= ~BIT(KBD_MODE_BIT_ON
);
1298 kbd_previous_level
= kbd_get_level(&state
);
1299 kbd_previous_mode_bit
= state
.mode_bit
;
1301 if (kbd_previous_level
== 0 && kbd_get_max_level() != 0)
1302 kbd_previous_level
= 1;
1304 if (kbd_previous_mode_bit
== KBD_MODE_BIT_OFF
) {
1305 kbd_previous_mode_bit
=
1306 ffs(kbd_info
.modes
& ~BIT(KBD_MODE_BIT_OFF
));
1307 if (kbd_previous_mode_bit
!= 0)
1308 kbd_previous_mode_bit
--;
1311 if (kbd_info
.modes
& (BIT(KBD_MODE_BIT_ALS
) |
1312 BIT(KBD_MODE_BIT_TRIGGER_ALS
)))
1313 kbd_als_supported
= true;
1315 if (kbd_info
.modes
& (
1316 BIT(KBD_MODE_BIT_TRIGGER_ALS
) | BIT(KBD_MODE_BIT_TRIGGER
) |
1317 BIT(KBD_MODE_BIT_TRIGGER_25
) | BIT(KBD_MODE_BIT_TRIGGER_50
) |
1318 BIT(KBD_MODE_BIT_TRIGGER_75
) | BIT(KBD_MODE_BIT_TRIGGER_100
)
1320 kbd_triggers_supported
= true;
1322 /* kbd_mode_levels[0] is reserved, see below */
1323 for (i
= 0; i
< 16; ++i
)
1324 if (kbd_is_level_mode_bit(i
) && (BIT(i
) & kbd_info
.modes
))
1325 kbd_mode_levels
[1 + kbd_mode_levels_count
++] = i
;
1328 * Find the first supported mode and assign to kbd_mode_levels[0].
1329 * This should be 0 (off), but we cannot depend on the BIOS to
1332 if (kbd_mode_levels_count
> 0) {
1333 for (i
= 0; i
< 16; ++i
) {
1334 if (BIT(i
) & kbd_info
.modes
) {
1335 kbd_mode_levels
[0] = i
;
1339 kbd_mode_levels_count
++;
1346 static inline void kbd_init_tokens(void)
1350 for (i
= 0; i
< ARRAY_SIZE(kbd_tokens
); ++i
)
1351 if (find_token_id(kbd_tokens
[i
]) != -1)
1352 kbd_token_bits
|= BIT(i
);
1355 static void kbd_init(void)
1359 ret
= kbd_init_info();
1362 if (kbd_token_bits
!= 0 || ret
== 0)
1363 kbd_led_present
= true;
1366 static ssize_t
kbd_led_timeout_store(struct device
*dev
,
1367 struct device_attribute
*attr
,
1368 const char *buf
, size_t count
)
1370 struct kbd_state new_state
;
1371 struct kbd_state state
;
1379 ret
= sscanf(buf
, "%d %c", &value
, &ch
);
1392 if (value
> kbd_info
.seconds
)
1394 unit
= KBD_TIMEOUT_SECONDS
;
1397 if (value
> kbd_info
.minutes
)
1399 unit
= KBD_TIMEOUT_MINUTES
;
1402 if (value
> kbd_info
.hours
)
1404 unit
= KBD_TIMEOUT_HOURS
;
1407 if (value
> kbd_info
.days
)
1409 unit
= KBD_TIMEOUT_DAYS
;
1415 if (quirks
&& quirks
->needs_kbd_timeouts
)
1419 /* Convert value from current units to seconds */
1421 case KBD_TIMEOUT_DAYS
:
1423 case KBD_TIMEOUT_HOURS
:
1425 case KBD_TIMEOUT_MINUTES
:
1427 unit
= KBD_TIMEOUT_SECONDS
;
1430 if (quirks
&& quirks
->needs_kbd_timeouts
) {
1431 for (i
= 0; quirks
->kbd_timeouts
[i
] != -1; i
++) {
1432 if (value
<= quirks
->kbd_timeouts
[i
]) {
1433 value
= quirks
->kbd_timeouts
[i
];
1439 if (value
<= kbd_info
.seconds
&& kbd_info
.seconds
) {
1440 unit
= KBD_TIMEOUT_SECONDS
;
1441 } else if (value
/ 60 <= kbd_info
.minutes
&& kbd_info
.minutes
) {
1443 unit
= KBD_TIMEOUT_MINUTES
;
1444 } else if (value
/ (60 * 60) <= kbd_info
.hours
&& kbd_info
.hours
) {
1446 unit
= KBD_TIMEOUT_HOURS
;
1447 } else if (value
/ (60 * 60 * 24) <= kbd_info
.days
&& kbd_info
.days
) {
1448 value
/= (60 * 60 * 24);
1449 unit
= KBD_TIMEOUT_DAYS
;
1455 ret
= kbd_get_state(&state
);
1460 new_state
.timeout_value
= value
;
1461 new_state
.timeout_unit
= unit
;
1463 ret
= kbd_set_state_safe(&new_state
, &state
);
1470 static ssize_t
kbd_led_timeout_show(struct device
*dev
,
1471 struct device_attribute
*attr
, char *buf
)
1473 struct kbd_state state
;
1477 ret
= kbd_get_state(&state
);
1481 len
= sprintf(buf
, "%d", state
.timeout_value
);
1483 switch (state
.timeout_unit
) {
1484 case KBD_TIMEOUT_SECONDS
:
1485 return len
+ sprintf(buf
+len
, "s\n");
1486 case KBD_TIMEOUT_MINUTES
:
1487 return len
+ sprintf(buf
+len
, "m\n");
1488 case KBD_TIMEOUT_HOURS
:
1489 return len
+ sprintf(buf
+len
, "h\n");
1490 case KBD_TIMEOUT_DAYS
:
1491 return len
+ sprintf(buf
+len
, "d\n");
1499 static DEVICE_ATTR(stop_timeout
, S_IRUGO
| S_IWUSR
,
1500 kbd_led_timeout_show
, kbd_led_timeout_store
);
1502 static const char * const kbd_led_triggers
[] = {
1505 /*"trackstick"*/ NULL
, /* NOTE: trackstick is just alias for touchpad */
1509 static ssize_t
kbd_led_triggers_store(struct device
*dev
,
1510 struct device_attribute
*attr
,
1511 const char *buf
, size_t count
)
1513 struct kbd_state new_state
;
1514 struct kbd_state state
;
1515 bool triggers_enabled
= false;
1516 int trigger_bit
= -1;
1520 ret
= sscanf(buf
, "%20s", trigger
);
1524 if (trigger
[0] != '+' && trigger
[0] != '-')
1527 ret
= kbd_get_state(&state
);
1531 if (kbd_triggers_supported
)
1532 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1534 if (kbd_triggers_supported
) {
1535 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1536 if (!(kbd_info
.triggers
& BIT(i
)))
1538 if (!kbd_led_triggers
[i
])
1540 if (strcmp(trigger
+1, kbd_led_triggers
[i
]) != 0)
1542 if (trigger
[0] == '+' &&
1543 triggers_enabled
&& (state
.triggers
& BIT(i
)))
1545 if (trigger
[0] == '-' &&
1546 (!triggers_enabled
|| !(state
.triggers
& BIT(i
))))
1553 if (trigger_bit
!= -1) {
1555 if (trigger
[0] == '+')
1556 new_state
.triggers
|= BIT(trigger_bit
);
1558 new_state
.triggers
&= ~BIT(trigger_bit
);
1559 /* NOTE: trackstick bit (2) must be disabled when
1560 * disabling touchpad bit (1), otherwise touchpad
1561 * bit (1) will not be disabled */
1562 if (trigger_bit
== 1)
1563 new_state
.triggers
&= ~BIT(2);
1565 if ((kbd_info
.triggers
& new_state
.triggers
) !=
1568 if (new_state
.triggers
&& !triggers_enabled
) {
1569 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1570 kbd_set_level(&new_state
, kbd_previous_level
);
1571 } else if (new_state
.triggers
== 0) {
1572 kbd_set_level(&new_state
, 0);
1574 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
)))
1576 ret
= kbd_set_state_safe(&new_state
, &state
);
1579 if (new_state
.mode_bit
!= KBD_MODE_BIT_OFF
)
1580 kbd_previous_mode_bit
= new_state
.mode_bit
;
1587 static ssize_t
kbd_led_triggers_show(struct device
*dev
,
1588 struct device_attribute
*attr
, char *buf
)
1590 struct kbd_state state
;
1591 bool triggers_enabled
;
1595 ret
= kbd_get_state(&state
);
1601 if (kbd_triggers_supported
) {
1602 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1603 level
= kbd_get_level(&state
);
1604 for (i
= 0; i
< ARRAY_SIZE(kbd_led_triggers
); ++i
) {
1605 if (!(kbd_info
.triggers
& BIT(i
)))
1607 if (!kbd_led_triggers
[i
])
1609 if ((triggers_enabled
|| level
<= 0) &&
1610 (state
.triggers
& BIT(i
)))
1614 len
+= sprintf(buf
+len
, "%s ", kbd_led_triggers
[i
]);
1619 buf
[len
- 1] = '\n';
1624 static DEVICE_ATTR(start_triggers
, S_IRUGO
| S_IWUSR
,
1625 kbd_led_triggers_show
, kbd_led_triggers_store
);
1627 static ssize_t
kbd_led_als_enabled_store(struct device
*dev
,
1628 struct device_attribute
*attr
,
1629 const char *buf
, size_t count
)
1631 struct kbd_state new_state
;
1632 struct kbd_state state
;
1633 bool triggers_enabled
= false;
1637 ret
= kstrtoint(buf
, 0, &enable
);
1641 ret
= kbd_get_state(&state
);
1645 if (enable
== kbd_is_als_mode_bit(state
.mode_bit
))
1650 if (kbd_triggers_supported
)
1651 triggers_enabled
= kbd_is_trigger_mode_bit(state
.mode_bit
);
1654 if (triggers_enabled
)
1655 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER_ALS
;
1657 new_state
.mode_bit
= KBD_MODE_BIT_ALS
;
1659 if (triggers_enabled
) {
1660 new_state
.mode_bit
= KBD_MODE_BIT_TRIGGER
;
1661 kbd_set_level(&new_state
, kbd_previous_level
);
1663 new_state
.mode_bit
= KBD_MODE_BIT_ON
;
1666 if (!(kbd_info
.modes
& BIT(new_state
.mode_bit
)))
1669 ret
= kbd_set_state_safe(&new_state
, &state
);
1672 kbd_previous_mode_bit
= new_state
.mode_bit
;
1677 static ssize_t
kbd_led_als_enabled_show(struct device
*dev
,
1678 struct device_attribute
*attr
,
1681 struct kbd_state state
;
1682 bool enabled
= false;
1685 ret
= kbd_get_state(&state
);
1688 enabled
= kbd_is_als_mode_bit(state
.mode_bit
);
1690 return sprintf(buf
, "%d\n", enabled
? 1 : 0);
1693 static DEVICE_ATTR(als_enabled
, S_IRUGO
| S_IWUSR
,
1694 kbd_led_als_enabled_show
, kbd_led_als_enabled_store
);
1696 static ssize_t
kbd_led_als_setting_store(struct device
*dev
,
1697 struct device_attribute
*attr
,
1698 const char *buf
, size_t count
)
1700 struct kbd_state state
;
1701 struct kbd_state new_state
;
1705 ret
= kstrtou8(buf
, 10, &setting
);
1709 ret
= kbd_get_state(&state
);
1714 new_state
.als_setting
= setting
;
1716 ret
= kbd_set_state_safe(&new_state
, &state
);
1723 static ssize_t
kbd_led_als_setting_show(struct device
*dev
,
1724 struct device_attribute
*attr
,
1727 struct kbd_state state
;
1730 ret
= kbd_get_state(&state
);
1734 return sprintf(buf
, "%d\n", state
.als_setting
);
1737 static DEVICE_ATTR(als_setting
, S_IRUGO
| S_IWUSR
,
1738 kbd_led_als_setting_show
, kbd_led_als_setting_store
);
1740 static struct attribute
*kbd_led_attrs
[] = {
1741 &dev_attr_stop_timeout
.attr
,
1742 &dev_attr_start_triggers
.attr
,
1746 static const struct attribute_group kbd_led_group
= {
1747 .attrs
= kbd_led_attrs
,
1750 static struct attribute
*kbd_led_als_attrs
[] = {
1751 &dev_attr_als_enabled
.attr
,
1752 &dev_attr_als_setting
.attr
,
1756 static const struct attribute_group kbd_led_als_group
= {
1757 .attrs
= kbd_led_als_attrs
,
1760 static const struct attribute_group
*kbd_led_groups
[] = {
1766 static enum led_brightness
kbd_led_level_get(struct led_classdev
*led_cdev
)
1770 struct kbd_state state
;
1772 if (kbd_get_max_level()) {
1773 ret
= kbd_get_state(&state
);
1776 ret
= kbd_get_level(&state
);
1782 if (kbd_get_valid_token_counts()) {
1783 ret
= kbd_get_first_active_token_bit();
1786 for (num
= kbd_token_bits
; num
!= 0 && ret
> 0; --ret
)
1787 num
&= num
- 1; /* clear the first bit set */
1790 return ffs(num
) - 1;
1793 pr_warn("Keyboard brightness level control not supported\n");
1797 static void kbd_led_level_set(struct led_classdev
*led_cdev
,
1798 enum led_brightness value
)
1800 struct kbd_state state
;
1801 struct kbd_state new_state
;
1804 if (kbd_get_max_level()) {
1805 if (kbd_get_state(&state
))
1808 if (kbd_set_level(&new_state
, value
))
1810 kbd_set_state_safe(&new_state
, &state
);
1814 if (kbd_get_valid_token_counts()) {
1815 for (num
= kbd_token_bits
; num
!= 0 && value
> 0; --value
)
1816 num
&= num
- 1; /* clear the first bit set */
1819 kbd_set_token_bit(ffs(num
) - 1);
1823 pr_warn("Keyboard brightness level control not supported\n");
1826 static struct led_classdev kbd_led
= {
1827 .name
= "dell::kbd_backlight",
1828 .brightness_set
= kbd_led_level_set
,
1829 .brightness_get
= kbd_led_level_get
,
1830 .groups
= kbd_led_groups
,
1833 static int __init
kbd_led_init(struct device
*dev
)
1836 if (!kbd_led_present
)
1838 if (!kbd_als_supported
)
1839 kbd_led_groups
[1] = NULL
;
1840 kbd_led
.max_brightness
= kbd_get_max_level();
1841 if (!kbd_led
.max_brightness
) {
1842 kbd_led
.max_brightness
= kbd_get_valid_token_counts();
1843 if (kbd_led
.max_brightness
)
1844 kbd_led
.max_brightness
--;
1846 return led_classdev_register(dev
, &kbd_led
);
1849 static void brightness_set_exit(struct led_classdev
*led_cdev
,
1850 enum led_brightness value
)
1852 /* Don't change backlight level on exit */
1855 static void kbd_led_exit(void)
1857 if (!kbd_led_present
)
1859 kbd_led
.brightness_set
= brightness_set_exit
;
1860 led_classdev_unregister(&kbd_led
);
1863 static int __init
dell_init(void)
1865 int max_intensity
= 0;
1868 if (!dmi_check_system(dell_device_table
))
1872 /* find if this machine support other functions */
1873 dmi_check_system(dell_quirks
);
1875 dmi_walk(find_tokens
, NULL
);
1878 pr_info("Unable to find dmi tokens\n");
1882 ret
= platform_driver_register(&platform_driver
);
1884 goto fail_platform_driver
;
1885 platform_device
= platform_device_alloc("dell-laptop", -1);
1886 if (!platform_device
) {
1888 goto fail_platform_device1
;
1890 ret
= platform_device_add(platform_device
);
1892 goto fail_platform_device2
;
1895 * Allocate buffer below 4GB for SMI data--only 32-bit physical addr
1896 * is passed to SMI handler.
1898 buffer
= (void *)__get_free_page(GFP_KERNEL
| GFP_DMA32
);
1904 ret
= dell_setup_rfkill();
1907 pr_warn("Unable to setup rfkill\n");
1911 if (quirks
&& quirks
->touchpad_led
)
1912 touchpad_led_init(&platform_device
->dev
);
1914 kbd_led_init(&platform_device
->dev
);
1916 dell_laptop_dir
= debugfs_create_dir("dell_laptop", NULL
);
1917 if (dell_laptop_dir
!= NULL
)
1918 debugfs_create_file("rfkill", 0444, dell_laptop_dir
, NULL
,
1919 &dell_debugfs_fops
);
1922 /* In the event of an ACPI backlight being available, don't
1923 * register the platform controller.
1925 if (acpi_video_backlight_support())
1930 buffer
->input
[0] = find_token_location(BRIGHTNESS_TOKEN
);
1931 if (buffer
->input
[0] != -1) {
1932 dell_send_request(buffer
, 0, 2);
1933 max_intensity
= buffer
->output
[3];
1937 if (max_intensity
) {
1938 struct backlight_properties props
;
1939 memset(&props
, 0, sizeof(struct backlight_properties
));
1940 props
.type
= BACKLIGHT_PLATFORM
;
1941 props
.max_brightness
= max_intensity
;
1942 dell_backlight_device
= backlight_device_register("dell_backlight",
1943 &platform_device
->dev
,
1948 if (IS_ERR(dell_backlight_device
)) {
1949 ret
= PTR_ERR(dell_backlight_device
);
1950 dell_backlight_device
= NULL
;
1951 goto fail_backlight
;
1954 dell_backlight_device
->props
.brightness
=
1955 dell_get_intensity(dell_backlight_device
);
1956 backlight_update_status(dell_backlight_device
);
1962 i8042_remove_filter(dell_laptop_i8042_filter
);
1963 cancel_delayed_work_sync(&dell_rfkill_work
);
1964 dell_cleanup_rfkill();
1966 free_page((unsigned long)buffer
);
1968 platform_device_del(platform_device
);
1969 fail_platform_device2
:
1970 platform_device_put(platform_device
);
1971 fail_platform_device1
:
1972 platform_driver_unregister(&platform_driver
);
1973 fail_platform_driver
:
1978 static void __exit
dell_exit(void)
1980 debugfs_remove_recursive(dell_laptop_dir
);
1981 if (quirks
&& quirks
->touchpad_led
)
1982 touchpad_led_exit();
1984 i8042_remove_filter(dell_laptop_i8042_filter
);
1985 cancel_delayed_work_sync(&dell_rfkill_work
);
1986 backlight_device_unregister(dell_backlight_device
);
1987 dell_cleanup_rfkill();
1988 if (platform_device
) {
1989 platform_device_unregister(platform_device
);
1990 platform_driver_unregister(&platform_driver
);
1993 free_page((unsigned long)buffer
);
1996 module_init(dell_init
);
1997 module_exit(dell_exit
);
1999 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
2000 MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>");
2001 MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>");
2002 MODULE_DESCRIPTION("Dell laptop driver");
2003 MODULE_LICENSE("GPL");