Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'platform-drivers-x86-v3.19-2' of git://git.infradead.org/users/dvhart/linux-platform-drivers-x86

Pull platform driver fix from Darren Hart:
"Revert keyboard backlight sysfs support and documentation.

The support for the dell-laptop keyboard backlight was flawed and the
fix:

https://lkml.org/lkml/2015/1/14/539

was more invasive that I felt comfortable sending at RC5.

This series reverts the support for the dell-laptop keyboard backlight
as well as the documentation for the newly created sysfs attributes.

We'll get this implemented correctly for 3.20"

* tag 'platform-drivers-x86-v3.19-2' of git://git.infradead.org/users/dvhart/linux-platform-drivers-x86:
Revert "platform: x86: dell-laptop: Add support for keyboard backlight"
Revert "Documentation: Add entry for dell-laptop sysfs interface"

+6 -1109
-60
Documentation/ABI/testing/sysfs-platform-dell-laptop
··· 1 - What: /sys/class/leds/dell::kbd_backlight/als_setting 2 - Date: December 2014 3 - KernelVersion: 3.19 4 - Contact: Gabriele Mazzotta <gabriele.mzt@gmail.com>, 5 - Pali Rohár <pali.rohar@gmail.com> 6 - Description: 7 - This file allows to control the automatic keyboard 8 - illumination mode on some systems that have an ambient 9 - light sensor. Write 1 to this file to enable the auto 10 - mode, 0 to disable it. 11 - 12 - What: /sys/class/leds/dell::kbd_backlight/start_triggers 13 - Date: December 2014 14 - KernelVersion: 3.19 15 - Contact: Gabriele Mazzotta <gabriele.mzt@gmail.com>, 16 - Pali Rohár <pali.rohar@gmail.com> 17 - Description: 18 - This file allows to control the input triggers that 19 - turn on the keyboard backlight illumination that is 20 - disabled because of inactivity. 21 - Read the file to see the triggers available. The ones 22 - enabled are preceded by '+', those disabled by '-'. 23 - 24 - To enable a trigger, write its name preceded by '+' to 25 - this file. To disable a trigger, write its name preceded 26 - by '-' instead. 27 - 28 - For example, to enable the keyboard as trigger run: 29 - echo +keyboard > /sys/class/leds/dell::kbd_backlight/start_triggers 30 - To disable it: 31 - echo -keyboard > /sys/class/leds/dell::kbd_backlight/start_triggers 32 - 33 - Note that not all the available triggers can be configured. 34 - 35 - What: /sys/class/leds/dell::kbd_backlight/stop_timeout 36 - Date: December 2014 37 - KernelVersion: 3.19 38 - Contact: Gabriele Mazzotta <gabriele.mzt@gmail.com>, 39 - Pali Rohár <pali.rohar@gmail.com> 40 - Description: 41 - This file allows to specify the interval after which the 42 - keyboard illumination is disabled because of inactivity. 43 - The timeouts are expressed in seconds, minutes, hours and 44 - days, for which the symbols are 's', 'm', 'h' and 'd' 45 - respectively. 46 - 47 - To configure the timeout, write to this file a value along 48 - with any the above units. If no unit is specified, the value 49 - is assumed to be expressed in seconds. 50 - 51 - For example, to set the timeout to 10 minutes run: 52 - echo 10m > /sys/class/leds/dell::kbd_backlight/stop_timeout 53 - 54 - Note that when this file is read, the returned value might be 55 - expressed in a different unit than the one used when the timeout 56 - was set. 57 - 58 - Also note that only some timeouts are supported and that 59 - some systems might fall back to a specific timeout in case 60 - an invalid timeout is written to this file.
+6 -1049
drivers/platform/x86/dell-laptop.c
··· 2 2 * Driver for Dell laptop extras 3 3 * 4 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> 7 5 * 8 - * Based on documentation in the libsmbios package: 9 - * Copyright (C) 2005-2014 Dell Inc. 6 + * Based on documentation in the libsmbios package, Copyright (C) 2005 Dell 7 + * Inc. 10 8 * 11 9 * This program is free software; you can redistribute it and/or modify 12 10 * it under the terms of the GNU General Public License version 2 as ··· 32 34 #include "../../firmware/dcdbas.h" 33 35 34 36 #define BRIGHTNESS_TOKEN 0x7d 35 - #define KBD_LED_OFF_TOKEN 0x01E1 36 - #define KBD_LED_ON_TOKEN 0x01E2 37 - #define KBD_LED_AUTO_TOKEN 0x01E3 38 - #define KBD_LED_AUTO_25_TOKEN 0x02EA 39 - #define KBD_LED_AUTO_50_TOKEN 0x02EB 40 - #define KBD_LED_AUTO_75_TOKEN 0x02EC 41 - #define KBD_LED_AUTO_100_TOKEN 0x02F6 42 37 43 38 /* This structure will be modified by the firmware when we enter 44 39 * system management mode, hence the volatiles */ ··· 62 71 63 72 struct quirk_entry { 64 73 u8 touchpad_led; 65 - 66 - int needs_kbd_timeouts; 67 - /* 68 - * Ordered list of timeouts expressed in seconds. 69 - * The list must end with -1 70 - */ 71 - int kbd_timeouts[]; 72 74 }; 73 75 74 76 static struct quirk_entry *quirks; ··· 75 91 quirks = dmi->driver_data; 76 92 return 1; 77 93 } 78 - 79 - /* 80 - * These values come from Windows utility provided by Dell. If any other value 81 - * is used then BIOS silently set timeout to 0 without any error message. 82 - */ 83 - static struct quirk_entry quirk_dell_xps13_9333 = { 84 - .needs_kbd_timeouts = 1, 85 - .kbd_timeouts = { 0, 5, 15, 60, 5 * 60, 15 * 60, -1 }, 86 - }; 87 94 88 95 static int da_command_address; 89 96 static int da_command_code; ··· 267 292 }, 268 293 .driver_data = &quirk_dell_vostro_v130, 269 294 }, 270 - { 271 - .callback = dmi_matched, 272 - .ident = "Dell XPS13 9333", 273 - .matches = { 274 - DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 275 - DMI_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"), 276 - }, 277 - .driver_data = &quirk_dell_xps13_9333, 278 - }, 279 295 { } 280 296 }; 281 297 ··· 331 365 } 332 366 } 333 367 334 - static int find_token_id(int tokenid) 368 + static int find_token_location(int tokenid) 335 369 { 336 370 int i; 337 - 338 371 for (i = 0; i < da_num_tokens; i++) { 339 372 if (da_tokens[i].tokenID == tokenid) 340 - return i; 373 + return da_tokens[i].location; 341 374 } 342 375 343 376 return -1; 344 - } 345 - 346 - static int find_token_location(int tokenid) 347 - { 348 - int id; 349 - 350 - id = find_token_id(tokenid); 351 - if (id == -1) 352 - return -1; 353 - 354 - return da_tokens[id].location; 355 377 } 356 378 357 379 static struct calling_interface_buffer * ··· 360 406 dcdbas_smi_request(&command); 361 407 362 408 return buffer; 363 - } 364 - 365 - static inline int dell_smi_error(int value) 366 - { 367 - switch (value) { 368 - case 0: /* Completed successfully */ 369 - return 0; 370 - case -1: /* Completed with error */ 371 - return -EIO; 372 - case -2: /* Function not supported */ 373 - return -ENXIO; 374 - default: /* Unknown error */ 375 - return -EINVAL; 376 - } 377 409 } 378 410 379 411 /* Derived from information in DellWirelessCtl.cpp: ··· 716 776 else 717 777 dell_send_request(buffer, 1, 1); 718 778 719 - out: 779 + out: 720 780 release_buffer(); 721 781 return ret; 722 782 } ··· 740 800 741 801 ret = buffer->output[1]; 742 802 743 - out: 803 + out: 744 804 release_buffer(); 745 805 return ret; 746 806 } ··· 787 847 static void touchpad_led_exit(void) 788 848 { 789 849 led_classdev_unregister(&touchpad_led); 790 - } 791 - 792 - /* 793 - * Derived from information in smbios-keyboard-ctl: 794 - * 795 - * cbClass 4 796 - * cbSelect 11 797 - * Keyboard illumination 798 - * cbArg1 determines the function to be performed 799 - * 800 - * cbArg1 0x0 = Get Feature Information 801 - * cbRES1 Standard return codes (0, -1, -2) 802 - * cbRES2, word0 Bitmap of user-selectable modes 803 - * bit 0 Always off (All systems) 804 - * bit 1 Always on (Travis ATG, Siberia) 805 - * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG) 806 - * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off 807 - * bit 4 Auto: Input-activity-based On; input-activity based Off 808 - * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off 809 - * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off 810 - * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off 811 - * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off 812 - * bits 9-15 Reserved for future use 813 - * cbRES2, byte2 Reserved for future use 814 - * cbRES2, byte3 Keyboard illumination type 815 - * 0 Reserved 816 - * 1 Tasklight 817 - * 2 Backlight 818 - * 3-255 Reserved for future use 819 - * cbRES3, byte0 Supported auto keyboard illumination trigger bitmap. 820 - * bit 0 Any keystroke 821 - * bit 1 Touchpad activity 822 - * bit 2 Pointing stick 823 - * bit 3 Any mouse 824 - * bits 4-7 Reserved for future use 825 - * cbRES3, byte1 Supported timeout unit bitmap 826 - * bit 0 Seconds 827 - * bit 1 Minutes 828 - * bit 2 Hours 829 - * bit 3 Days 830 - * bits 4-7 Reserved for future use 831 - * cbRES3, byte2 Number of keyboard light brightness levels 832 - * cbRES4, byte0 Maximum acceptable seconds value (0 if seconds not supported). 833 - * cbRES4, byte1 Maximum acceptable minutes value (0 if minutes not supported). 834 - * cbRES4, byte2 Maximum acceptable hours value (0 if hours not supported). 835 - * cbRES4, byte3 Maximum acceptable days value (0 if days not supported) 836 - * 837 - * cbArg1 0x1 = Get Current State 838 - * cbRES1 Standard return codes (0, -1, -2) 839 - * cbRES2, word0 Bitmap of current mode state 840 - * bit 0 Always off (All systems) 841 - * bit 1 Always on (Travis ATG, Siberia) 842 - * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG) 843 - * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off 844 - * bit 4 Auto: Input-activity-based On; input-activity based Off 845 - * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off 846 - * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off 847 - * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off 848 - * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off 849 - * bits 9-15 Reserved for future use 850 - * Note: Only One bit can be set 851 - * cbRES2, byte2 Currently active auto keyboard illumination triggers. 852 - * bit 0 Any keystroke 853 - * bit 1 Touchpad activity 854 - * bit 2 Pointing stick 855 - * bit 3 Any mouse 856 - * bits 4-7 Reserved for future use 857 - * cbRES2, byte3 Current Timeout 858 - * bits 7:6 Timeout units indicator: 859 - * 00b Seconds 860 - * 01b Minutes 861 - * 10b Hours 862 - * 11b Days 863 - * bits 5:0 Timeout value (0-63) in sec/min/hr/day 864 - * NOTE: A value of 0 means always on (no timeout) if any bits of RES3 byte 865 - * are set upon return from the [Get feature information] call. 866 - * cbRES3, byte0 Current setting of ALS value that turns the light on or off. 867 - * cbRES3, byte1 Current ALS reading 868 - * cbRES3, byte2 Current keyboard light level. 869 - * 870 - * cbArg1 0x2 = Set New State 871 - * cbRES1 Standard return codes (0, -1, -2) 872 - * cbArg2, word0 Bitmap of current mode state 873 - * bit 0 Always off (All systems) 874 - * bit 1 Always on (Travis ATG, Siberia) 875 - * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG) 876 - * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off 877 - * bit 4 Auto: Input-activity-based On; input-activity based Off 878 - * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off 879 - * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off 880 - * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off 881 - * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off 882 - * bits 9-15 Reserved for future use 883 - * Note: Only One bit can be set 884 - * cbArg2, byte2 Desired auto keyboard illumination triggers. Must remain inactive to allow 885 - * keyboard to turn off automatically. 886 - * bit 0 Any keystroke 887 - * bit 1 Touchpad activity 888 - * bit 2 Pointing stick 889 - * bit 3 Any mouse 890 - * bits 4-7 Reserved for future use 891 - * cbArg2, byte3 Desired Timeout 892 - * bits 7:6 Timeout units indicator: 893 - * 00b Seconds 894 - * 01b Minutes 895 - * 10b Hours 896 - * 11b Days 897 - * bits 5:0 Timeout value (0-63) in sec/min/hr/day 898 - * cbArg3, byte0 Desired setting of ALS value that turns the light on or off. 899 - * cbArg3, byte2 Desired keyboard light level. 900 - */ 901 - 902 - 903 - enum kbd_timeout_unit { 904 - KBD_TIMEOUT_SECONDS = 0, 905 - KBD_TIMEOUT_MINUTES, 906 - KBD_TIMEOUT_HOURS, 907 - KBD_TIMEOUT_DAYS, 908 - }; 909 - 910 - enum kbd_mode_bit { 911 - KBD_MODE_BIT_OFF = 0, 912 - KBD_MODE_BIT_ON, 913 - KBD_MODE_BIT_ALS, 914 - KBD_MODE_BIT_TRIGGER_ALS, 915 - KBD_MODE_BIT_TRIGGER, 916 - KBD_MODE_BIT_TRIGGER_25, 917 - KBD_MODE_BIT_TRIGGER_50, 918 - KBD_MODE_BIT_TRIGGER_75, 919 - KBD_MODE_BIT_TRIGGER_100, 920 - }; 921 - 922 - #define kbd_is_als_mode_bit(bit) \ 923 - ((bit) == KBD_MODE_BIT_ALS || (bit) == KBD_MODE_BIT_TRIGGER_ALS) 924 - #define kbd_is_trigger_mode_bit(bit) \ 925 - ((bit) >= KBD_MODE_BIT_TRIGGER_ALS && (bit) <= KBD_MODE_BIT_TRIGGER_100) 926 - #define kbd_is_level_mode_bit(bit) \ 927 - ((bit) >= KBD_MODE_BIT_TRIGGER_25 && (bit) <= KBD_MODE_BIT_TRIGGER_100) 928 - 929 - struct kbd_info { 930 - u16 modes; 931 - u8 type; 932 - u8 triggers; 933 - u8 levels; 934 - u8 seconds; 935 - u8 minutes; 936 - u8 hours; 937 - u8 days; 938 - }; 939 - 940 - struct kbd_state { 941 - u8 mode_bit; 942 - u8 triggers; 943 - u8 timeout_value; 944 - u8 timeout_unit; 945 - u8 als_setting; 946 - u8 als_value; 947 - u8 level; 948 - }; 949 - 950 - static const int kbd_tokens[] = { 951 - KBD_LED_OFF_TOKEN, 952 - KBD_LED_AUTO_25_TOKEN, 953 - KBD_LED_AUTO_50_TOKEN, 954 - KBD_LED_AUTO_75_TOKEN, 955 - KBD_LED_AUTO_100_TOKEN, 956 - KBD_LED_ON_TOKEN, 957 - }; 958 - 959 - static u16 kbd_token_bits; 960 - 961 - static struct kbd_info kbd_info; 962 - static bool kbd_als_supported; 963 - static bool kbd_triggers_supported; 964 - 965 - static u8 kbd_mode_levels[16]; 966 - static int kbd_mode_levels_count; 967 - 968 - static u8 kbd_previous_level; 969 - static u8 kbd_previous_mode_bit; 970 - 971 - static bool kbd_led_present; 972 - 973 - /* 974 - * NOTE: there are three ways to set the keyboard backlight level. 975 - * First, via kbd_state.mode_bit (assigning KBD_MODE_BIT_TRIGGER_* value). 976 - * Second, via kbd_state.level (assigning numerical value <= kbd_info.levels). 977 - * Third, via SMBIOS tokens (KBD_LED_* in kbd_tokens) 978 - * 979 - * There are laptops which support only one of these methods. If we want to 980 - * support as many machines as possible we need to implement all three methods. 981 - * The first two methods use the kbd_state structure. The third uses SMBIOS 982 - * tokens. If kbd_info.levels == 0, the machine does not support setting the 983 - * keyboard backlight level via kbd_state.level. 984 - */ 985 - 986 - static int kbd_get_info(struct kbd_info *info) 987 - { 988 - u8 units; 989 - int ret; 990 - 991 - get_buffer(); 992 - 993 - buffer->input[0] = 0x0; 994 - dell_send_request(buffer, 4, 11); 995 - ret = buffer->output[0]; 996 - 997 - if (ret) { 998 - ret = dell_smi_error(ret); 999 - goto out; 1000 - } 1001 - 1002 - info->modes = buffer->output[1] & 0xFFFF; 1003 - info->type = (buffer->output[1] >> 24) & 0xFF; 1004 - info->triggers = buffer->output[2] & 0xFF; 1005 - units = (buffer->output[2] >> 8) & 0xFF; 1006 - info->levels = (buffer->output[2] >> 16) & 0xFF; 1007 - 1008 - if (units & BIT(0)) 1009 - info->seconds = (buffer->output[3] >> 0) & 0xFF; 1010 - if (units & BIT(1)) 1011 - info->minutes = (buffer->output[3] >> 8) & 0xFF; 1012 - if (units & BIT(2)) 1013 - info->hours = (buffer->output[3] >> 16) & 0xFF; 1014 - if (units & BIT(3)) 1015 - info->days = (buffer->output[3] >> 24) & 0xFF; 1016 - 1017 - out: 1018 - release_buffer(); 1019 - return ret; 1020 - } 1021 - 1022 - static unsigned int kbd_get_max_level(void) 1023 - { 1024 - if (kbd_info.levels != 0) 1025 - return kbd_info.levels; 1026 - if (kbd_mode_levels_count > 0) 1027 - return kbd_mode_levels_count - 1; 1028 - return 0; 1029 - } 1030 - 1031 - static int kbd_get_level(struct kbd_state *state) 1032 - { 1033 - int i; 1034 - 1035 - if (kbd_info.levels != 0) 1036 - return state->level; 1037 - 1038 - if (kbd_mode_levels_count > 0) { 1039 - for (i = 0; i < kbd_mode_levels_count; ++i) 1040 - if (kbd_mode_levels[i] == state->mode_bit) 1041 - return i; 1042 - return 0; 1043 - } 1044 - 1045 - return -EINVAL; 1046 - } 1047 - 1048 - static int kbd_set_level(struct kbd_state *state, u8 level) 1049 - { 1050 - if (kbd_info.levels != 0) { 1051 - if (level != 0) 1052 - kbd_previous_level = level; 1053 - if (state->level == level) 1054 - return 0; 1055 - state->level = level; 1056 - if (level != 0 && state->mode_bit == KBD_MODE_BIT_OFF) 1057 - state->mode_bit = kbd_previous_mode_bit; 1058 - else if (level == 0 && state->mode_bit != KBD_MODE_BIT_OFF) { 1059 - kbd_previous_mode_bit = state->mode_bit; 1060 - state->mode_bit = KBD_MODE_BIT_OFF; 1061 - } 1062 - return 0; 1063 - } 1064 - 1065 - if (kbd_mode_levels_count > 0 && level < kbd_mode_levels_count) { 1066 - if (level != 0) 1067 - kbd_previous_level = level; 1068 - state->mode_bit = kbd_mode_levels[level]; 1069 - return 0; 1070 - } 1071 - 1072 - return -EINVAL; 1073 - } 1074 - 1075 - static int kbd_get_state(struct kbd_state *state) 1076 - { 1077 - int ret; 1078 - 1079 - get_buffer(); 1080 - 1081 - buffer->input[0] = 0x1; 1082 - dell_send_request(buffer, 4, 11); 1083 - ret = buffer->output[0]; 1084 - 1085 - if (ret) { 1086 - ret = dell_smi_error(ret); 1087 - goto out; 1088 - } 1089 - 1090 - state->mode_bit = ffs(buffer->output[1] & 0xFFFF); 1091 - if (state->mode_bit != 0) 1092 - state->mode_bit--; 1093 - 1094 - state->triggers = (buffer->output[1] >> 16) & 0xFF; 1095 - state->timeout_value = (buffer->output[1] >> 24) & 0x3F; 1096 - state->timeout_unit = (buffer->output[1] >> 30) & 0x3; 1097 - state->als_setting = buffer->output[2] & 0xFF; 1098 - state->als_value = (buffer->output[2] >> 8) & 0xFF; 1099 - state->level = (buffer->output[2] >> 16) & 0xFF; 1100 - 1101 - out: 1102 - release_buffer(); 1103 - return ret; 1104 - } 1105 - 1106 - static int kbd_set_state(struct kbd_state *state) 1107 - { 1108 - int ret; 1109 - 1110 - get_buffer(); 1111 - buffer->input[0] = 0x2; 1112 - buffer->input[1] = BIT(state->mode_bit) & 0xFFFF; 1113 - buffer->input[1] |= (state->triggers & 0xFF) << 16; 1114 - buffer->input[1] |= (state->timeout_value & 0x3F) << 24; 1115 - buffer->input[1] |= (state->timeout_unit & 0x3) << 30; 1116 - buffer->input[2] = state->als_setting & 0xFF; 1117 - buffer->input[2] |= (state->level & 0xFF) << 16; 1118 - dell_send_request(buffer, 4, 11); 1119 - ret = buffer->output[0]; 1120 - release_buffer(); 1121 - 1122 - return dell_smi_error(ret); 1123 - } 1124 - 1125 - static int kbd_set_state_safe(struct kbd_state *state, struct kbd_state *old) 1126 - { 1127 - int ret; 1128 - 1129 - ret = kbd_set_state(state); 1130 - if (ret == 0) 1131 - return 0; 1132 - 1133 - /* 1134 - * When setting the new state fails,try to restore the previous one. 1135 - * This is needed on some machines where BIOS sets a default state when 1136 - * setting a new state fails. This default state could be all off. 1137 - */ 1138 - 1139 - if (kbd_set_state(old)) 1140 - pr_err("Setting old previous keyboard state failed\n"); 1141 - 1142 - return ret; 1143 - } 1144 - 1145 - static int kbd_set_token_bit(u8 bit) 1146 - { 1147 - int id; 1148 - int ret; 1149 - 1150 - if (bit >= ARRAY_SIZE(kbd_tokens)) 1151 - return -EINVAL; 1152 - 1153 - id = find_token_id(kbd_tokens[bit]); 1154 - if (id == -1) 1155 - return -EINVAL; 1156 - 1157 - get_buffer(); 1158 - buffer->input[0] = da_tokens[id].location; 1159 - buffer->input[1] = da_tokens[id].value; 1160 - dell_send_request(buffer, 1, 0); 1161 - ret = buffer->output[0]; 1162 - release_buffer(); 1163 - 1164 - return dell_smi_error(ret); 1165 - } 1166 - 1167 - static int kbd_get_token_bit(u8 bit) 1168 - { 1169 - int id; 1170 - int ret; 1171 - int val; 1172 - 1173 - if (bit >= ARRAY_SIZE(kbd_tokens)) 1174 - return -EINVAL; 1175 - 1176 - id = find_token_id(kbd_tokens[bit]); 1177 - if (id == -1) 1178 - return -EINVAL; 1179 - 1180 - get_buffer(); 1181 - buffer->input[0] = da_tokens[id].location; 1182 - dell_send_request(buffer, 0, 0); 1183 - ret = buffer->output[0]; 1184 - val = buffer->output[1]; 1185 - release_buffer(); 1186 - 1187 - if (ret) 1188 - return dell_smi_error(ret); 1189 - 1190 - return (val == da_tokens[id].value); 1191 - } 1192 - 1193 - static int kbd_get_first_active_token_bit(void) 1194 - { 1195 - int i; 1196 - int ret; 1197 - 1198 - for (i = 0; i < ARRAY_SIZE(kbd_tokens); ++i) { 1199 - ret = kbd_get_token_bit(i); 1200 - if (ret == 1) 1201 - return i; 1202 - } 1203 - 1204 - return ret; 1205 - } 1206 - 1207 - static int kbd_get_valid_token_counts(void) 1208 - { 1209 - return hweight16(kbd_token_bits); 1210 - } 1211 - 1212 - static inline int kbd_init_info(void) 1213 - { 1214 - struct kbd_state state; 1215 - int ret; 1216 - int i; 1217 - 1218 - ret = kbd_get_info(&kbd_info); 1219 - if (ret) 1220 - return ret; 1221 - 1222 - kbd_get_state(&state); 1223 - 1224 - /* NOTE: timeout value is stored in 6 bits so max value is 63 */ 1225 - if (kbd_info.seconds > 63) 1226 - kbd_info.seconds = 63; 1227 - if (kbd_info.minutes > 63) 1228 - kbd_info.minutes = 63; 1229 - if (kbd_info.hours > 63) 1230 - kbd_info.hours = 63; 1231 - if (kbd_info.days > 63) 1232 - kbd_info.days = 63; 1233 - 1234 - /* NOTE: On tested machines ON mode did not work and caused 1235 - * problems (turned backlight off) so do not use it 1236 - */ 1237 - kbd_info.modes &= ~BIT(KBD_MODE_BIT_ON); 1238 - 1239 - kbd_previous_level = kbd_get_level(&state); 1240 - kbd_previous_mode_bit = state.mode_bit; 1241 - 1242 - if (kbd_previous_level == 0 && kbd_get_max_level() != 0) 1243 - kbd_previous_level = 1; 1244 - 1245 - if (kbd_previous_mode_bit == KBD_MODE_BIT_OFF) { 1246 - kbd_previous_mode_bit = 1247 - ffs(kbd_info.modes & ~BIT(KBD_MODE_BIT_OFF)); 1248 - if (kbd_previous_mode_bit != 0) 1249 - kbd_previous_mode_bit--; 1250 - } 1251 - 1252 - if (kbd_info.modes & (BIT(KBD_MODE_BIT_ALS) | 1253 - BIT(KBD_MODE_BIT_TRIGGER_ALS))) 1254 - kbd_als_supported = true; 1255 - 1256 - if (kbd_info.modes & ( 1257 - BIT(KBD_MODE_BIT_TRIGGER_ALS) | BIT(KBD_MODE_BIT_TRIGGER) | 1258 - BIT(KBD_MODE_BIT_TRIGGER_25) | BIT(KBD_MODE_BIT_TRIGGER_50) | 1259 - BIT(KBD_MODE_BIT_TRIGGER_75) | BIT(KBD_MODE_BIT_TRIGGER_100) 1260 - )) 1261 - kbd_triggers_supported = true; 1262 - 1263 - /* kbd_mode_levels[0] is reserved, see below */ 1264 - for (i = 0; i < 16; ++i) 1265 - if (kbd_is_level_mode_bit(i) && (BIT(i) & kbd_info.modes)) 1266 - kbd_mode_levels[1 + kbd_mode_levels_count++] = i; 1267 - 1268 - /* 1269 - * Find the first supported mode and assign to kbd_mode_levels[0]. 1270 - * This should be 0 (off), but we cannot depend on the BIOS to 1271 - * support 0. 1272 - */ 1273 - if (kbd_mode_levels_count > 0) { 1274 - for (i = 0; i < 16; ++i) { 1275 - if (BIT(i) & kbd_info.modes) { 1276 - kbd_mode_levels[0] = i; 1277 - break; 1278 - } 1279 - } 1280 - kbd_mode_levels_count++; 1281 - } 1282 - 1283 - return 0; 1284 - 1285 - } 1286 - 1287 - static inline void kbd_init_tokens(void) 1288 - { 1289 - int i; 1290 - 1291 - for (i = 0; i < ARRAY_SIZE(kbd_tokens); ++i) 1292 - if (find_token_id(kbd_tokens[i]) != -1) 1293 - kbd_token_bits |= BIT(i); 1294 - } 1295 - 1296 - static void kbd_init(void) 1297 - { 1298 - int ret; 1299 - 1300 - ret = kbd_init_info(); 1301 - kbd_init_tokens(); 1302 - 1303 - if (kbd_token_bits != 0 || ret == 0) 1304 - kbd_led_present = true; 1305 - } 1306 - 1307 - static ssize_t kbd_led_timeout_store(struct device *dev, 1308 - struct device_attribute *attr, 1309 - const char *buf, size_t count) 1310 - { 1311 - struct kbd_state new_state; 1312 - struct kbd_state state; 1313 - bool convert; 1314 - int value; 1315 - int ret; 1316 - char ch; 1317 - u8 unit; 1318 - int i; 1319 - 1320 - ret = sscanf(buf, "%d %c", &value, &ch); 1321 - if (ret < 1) 1322 - return -EINVAL; 1323 - else if (ret == 1) 1324 - ch = 's'; 1325 - 1326 - if (value < 0) 1327 - return -EINVAL; 1328 - 1329 - convert = false; 1330 - 1331 - switch (ch) { 1332 - case 's': 1333 - if (value > kbd_info.seconds) 1334 - convert = true; 1335 - unit = KBD_TIMEOUT_SECONDS; 1336 - break; 1337 - case 'm': 1338 - if (value > kbd_info.minutes) 1339 - convert = true; 1340 - unit = KBD_TIMEOUT_MINUTES; 1341 - break; 1342 - case 'h': 1343 - if (value > kbd_info.hours) 1344 - convert = true; 1345 - unit = KBD_TIMEOUT_HOURS; 1346 - break; 1347 - case 'd': 1348 - if (value > kbd_info.days) 1349 - convert = true; 1350 - unit = KBD_TIMEOUT_DAYS; 1351 - break; 1352 - default: 1353 - return -EINVAL; 1354 - } 1355 - 1356 - if (quirks && quirks->needs_kbd_timeouts) 1357 - convert = true; 1358 - 1359 - if (convert) { 1360 - /* Convert value from current units to seconds */ 1361 - switch (unit) { 1362 - case KBD_TIMEOUT_DAYS: 1363 - value *= 24; 1364 - case KBD_TIMEOUT_HOURS: 1365 - value *= 60; 1366 - case KBD_TIMEOUT_MINUTES: 1367 - value *= 60; 1368 - unit = KBD_TIMEOUT_SECONDS; 1369 - } 1370 - 1371 - if (quirks && quirks->needs_kbd_timeouts) { 1372 - for (i = 0; quirks->kbd_timeouts[i] != -1; i++) { 1373 - if (value <= quirks->kbd_timeouts[i]) { 1374 - value = quirks->kbd_timeouts[i]; 1375 - break; 1376 - } 1377 - } 1378 - } 1379 - 1380 - if (value <= kbd_info.seconds && kbd_info.seconds) { 1381 - unit = KBD_TIMEOUT_SECONDS; 1382 - } else if (value / 60 <= kbd_info.minutes && kbd_info.minutes) { 1383 - value /= 60; 1384 - unit = KBD_TIMEOUT_MINUTES; 1385 - } else if (value / (60 * 60) <= kbd_info.hours && kbd_info.hours) { 1386 - value /= (60 * 60); 1387 - unit = KBD_TIMEOUT_HOURS; 1388 - } else if (value / (60 * 60 * 24) <= kbd_info.days && kbd_info.days) { 1389 - value /= (60 * 60 * 24); 1390 - unit = KBD_TIMEOUT_DAYS; 1391 - } else { 1392 - return -EINVAL; 1393 - } 1394 - } 1395 - 1396 - ret = kbd_get_state(&state); 1397 - if (ret) 1398 - return ret; 1399 - 1400 - new_state = state; 1401 - new_state.timeout_value = value; 1402 - new_state.timeout_unit = unit; 1403 - 1404 - ret = kbd_set_state_safe(&new_state, &state); 1405 - if (ret) 1406 - return ret; 1407 - 1408 - return count; 1409 - } 1410 - 1411 - static ssize_t kbd_led_timeout_show(struct device *dev, 1412 - struct device_attribute *attr, char *buf) 1413 - { 1414 - struct kbd_state state; 1415 - int ret; 1416 - int len; 1417 - 1418 - ret = kbd_get_state(&state); 1419 - if (ret) 1420 - return ret; 1421 - 1422 - len = sprintf(buf, "%d", state.timeout_value); 1423 - 1424 - switch (state.timeout_unit) { 1425 - case KBD_TIMEOUT_SECONDS: 1426 - return len + sprintf(buf+len, "s\n"); 1427 - case KBD_TIMEOUT_MINUTES: 1428 - return len + sprintf(buf+len, "m\n"); 1429 - case KBD_TIMEOUT_HOURS: 1430 - return len + sprintf(buf+len, "h\n"); 1431 - case KBD_TIMEOUT_DAYS: 1432 - return len + sprintf(buf+len, "d\n"); 1433 - default: 1434 - return -EINVAL; 1435 - } 1436 - 1437 - return len; 1438 - } 1439 - 1440 - static DEVICE_ATTR(stop_timeout, S_IRUGO | S_IWUSR, 1441 - kbd_led_timeout_show, kbd_led_timeout_store); 1442 - 1443 - static const char * const kbd_led_triggers[] = { 1444 - "keyboard", 1445 - "touchpad", 1446 - /*"trackstick"*/ NULL, /* NOTE: trackstick is just alias for touchpad */ 1447 - "mouse", 1448 - }; 1449 - 1450 - static ssize_t kbd_led_triggers_store(struct device *dev, 1451 - struct device_attribute *attr, 1452 - const char *buf, size_t count) 1453 - { 1454 - struct kbd_state new_state; 1455 - struct kbd_state state; 1456 - bool triggers_enabled = false; 1457 - bool als_enabled = false; 1458 - bool disable_als = false; 1459 - bool enable_als = false; 1460 - int trigger_bit = -1; 1461 - char trigger[21]; 1462 - int i, ret; 1463 - 1464 - ret = sscanf(buf, "%20s", trigger); 1465 - if (ret != 1) 1466 - return -EINVAL; 1467 - 1468 - if (trigger[0] != '+' && trigger[0] != '-') 1469 - return -EINVAL; 1470 - 1471 - ret = kbd_get_state(&state); 1472 - if (ret) 1473 - return ret; 1474 - 1475 - if (kbd_als_supported) 1476 - als_enabled = kbd_is_als_mode_bit(state.mode_bit); 1477 - 1478 - if (kbd_triggers_supported) 1479 - triggers_enabled = kbd_is_trigger_mode_bit(state.mode_bit); 1480 - 1481 - if (kbd_als_supported) { 1482 - if (strcmp(trigger, "+als") == 0) { 1483 - if (als_enabled) 1484 - return count; 1485 - enable_als = true; 1486 - } else if (strcmp(trigger, "-als") == 0) { 1487 - if (!als_enabled) 1488 - return count; 1489 - disable_als = true; 1490 - } 1491 - } 1492 - 1493 - if (enable_als || disable_als) { 1494 - new_state = state; 1495 - if (enable_als) { 1496 - if (triggers_enabled) 1497 - new_state.mode_bit = KBD_MODE_BIT_TRIGGER_ALS; 1498 - else 1499 - new_state.mode_bit = KBD_MODE_BIT_ALS; 1500 - } else { 1501 - if (triggers_enabled) { 1502 - new_state.mode_bit = KBD_MODE_BIT_TRIGGER; 1503 - kbd_set_level(&new_state, kbd_previous_level); 1504 - } else { 1505 - new_state.mode_bit = KBD_MODE_BIT_ON; 1506 - } 1507 - } 1508 - if (!(kbd_info.modes & BIT(new_state.mode_bit))) 1509 - return -EINVAL; 1510 - ret = kbd_set_state_safe(&new_state, &state); 1511 - if (ret) 1512 - return ret; 1513 - kbd_previous_mode_bit = new_state.mode_bit; 1514 - return count; 1515 - } 1516 - 1517 - if (kbd_triggers_supported) { 1518 - for (i = 0; i < ARRAY_SIZE(kbd_led_triggers); ++i) { 1519 - if (!(kbd_info.triggers & BIT(i))) 1520 - continue; 1521 - if (!kbd_led_triggers[i]) 1522 - continue; 1523 - if (strcmp(trigger+1, kbd_led_triggers[i]) != 0) 1524 - continue; 1525 - if (trigger[0] == '+' && 1526 - triggers_enabled && (state.triggers & BIT(i))) 1527 - return count; 1528 - if (trigger[0] == '-' && 1529 - (!triggers_enabled || !(state.triggers & BIT(i)))) 1530 - return count; 1531 - trigger_bit = i; 1532 - break; 1533 - } 1534 - } 1535 - 1536 - if (trigger_bit != -1) { 1537 - new_state = state; 1538 - if (trigger[0] == '+') 1539 - new_state.triggers |= BIT(trigger_bit); 1540 - else { 1541 - new_state.triggers &= ~BIT(trigger_bit); 1542 - /* NOTE: trackstick bit (2) must be disabled when 1543 - * disabling touchpad bit (1), otherwise touchpad 1544 - * bit (1) will not be disabled */ 1545 - if (trigger_bit == 1) 1546 - new_state.triggers &= ~BIT(2); 1547 - } 1548 - if ((kbd_info.triggers & new_state.triggers) != 1549 - new_state.triggers) 1550 - return -EINVAL; 1551 - if (new_state.triggers && !triggers_enabled) { 1552 - if (als_enabled) 1553 - new_state.mode_bit = KBD_MODE_BIT_TRIGGER_ALS; 1554 - else { 1555 - new_state.mode_bit = KBD_MODE_BIT_TRIGGER; 1556 - kbd_set_level(&new_state, kbd_previous_level); 1557 - } 1558 - } else if (new_state.triggers == 0) { 1559 - if (als_enabled) 1560 - new_state.mode_bit = KBD_MODE_BIT_ALS; 1561 - else 1562 - kbd_set_level(&new_state, 0); 1563 - } 1564 - if (!(kbd_info.modes & BIT(new_state.mode_bit))) 1565 - return -EINVAL; 1566 - ret = kbd_set_state_safe(&new_state, &state); 1567 - if (ret) 1568 - return ret; 1569 - if (new_state.mode_bit != KBD_MODE_BIT_OFF) 1570 - kbd_previous_mode_bit = new_state.mode_bit; 1571 - return count; 1572 - } 1573 - 1574 - return -EINVAL; 1575 - } 1576 - 1577 - static ssize_t kbd_led_triggers_show(struct device *dev, 1578 - struct device_attribute *attr, char *buf) 1579 - { 1580 - struct kbd_state state; 1581 - bool triggers_enabled; 1582 - int level, i, ret; 1583 - int len = 0; 1584 - 1585 - ret = kbd_get_state(&state); 1586 - if (ret) 1587 - return ret; 1588 - 1589 - len = 0; 1590 - 1591 - if (kbd_triggers_supported) { 1592 - triggers_enabled = kbd_is_trigger_mode_bit(state.mode_bit); 1593 - level = kbd_get_level(&state); 1594 - for (i = 0; i < ARRAY_SIZE(kbd_led_triggers); ++i) { 1595 - if (!(kbd_info.triggers & BIT(i))) 1596 - continue; 1597 - if (!kbd_led_triggers[i]) 1598 - continue; 1599 - if ((triggers_enabled || level <= 0) && 1600 - (state.triggers & BIT(i))) 1601 - buf[len++] = '+'; 1602 - else 1603 - buf[len++] = '-'; 1604 - len += sprintf(buf+len, "%s ", kbd_led_triggers[i]); 1605 - } 1606 - } 1607 - 1608 - if (kbd_als_supported) { 1609 - if (kbd_is_als_mode_bit(state.mode_bit)) 1610 - len += sprintf(buf+len, "+als "); 1611 - else 1612 - len += sprintf(buf+len, "-als "); 1613 - } 1614 - 1615 - if (len) 1616 - buf[len - 1] = '\n'; 1617 - 1618 - return len; 1619 - } 1620 - 1621 - static DEVICE_ATTR(start_triggers, S_IRUGO | S_IWUSR, 1622 - kbd_led_triggers_show, kbd_led_triggers_store); 1623 - 1624 - static ssize_t kbd_led_als_store(struct device *dev, 1625 - struct device_attribute *attr, 1626 - const char *buf, size_t count) 1627 - { 1628 - struct kbd_state state; 1629 - struct kbd_state new_state; 1630 - u8 setting; 1631 - int ret; 1632 - 1633 - ret = kstrtou8(buf, 10, &setting); 1634 - if (ret) 1635 - return ret; 1636 - 1637 - ret = kbd_get_state(&state); 1638 - if (ret) 1639 - return ret; 1640 - 1641 - new_state = state; 1642 - new_state.als_setting = setting; 1643 - 1644 - ret = kbd_set_state_safe(&new_state, &state); 1645 - if (ret) 1646 - return ret; 1647 - 1648 - return count; 1649 - } 1650 - 1651 - static ssize_t kbd_led_als_show(struct device *dev, 1652 - struct device_attribute *attr, char *buf) 1653 - { 1654 - struct kbd_state state; 1655 - int ret; 1656 - 1657 - ret = kbd_get_state(&state); 1658 - if (ret) 1659 - return ret; 1660 - 1661 - return sprintf(buf, "%d\n", state.als_setting); 1662 - } 1663 - 1664 - static DEVICE_ATTR(als_setting, S_IRUGO | S_IWUSR, 1665 - kbd_led_als_show, kbd_led_als_store); 1666 - 1667 - static struct attribute *kbd_led_attrs[] = { 1668 - &dev_attr_stop_timeout.attr, 1669 - &dev_attr_start_triggers.attr, 1670 - &dev_attr_als_setting.attr, 1671 - NULL, 1672 - }; 1673 - ATTRIBUTE_GROUPS(kbd_led); 1674 - 1675 - static enum led_brightness kbd_led_level_get(struct led_classdev *led_cdev) 1676 - { 1677 - int ret; 1678 - u16 num; 1679 - struct kbd_state state; 1680 - 1681 - if (kbd_get_max_level()) { 1682 - ret = kbd_get_state(&state); 1683 - if (ret) 1684 - return 0; 1685 - ret = kbd_get_level(&state); 1686 - if (ret < 0) 1687 - return 0; 1688 - return ret; 1689 - } 1690 - 1691 - if (kbd_get_valid_token_counts()) { 1692 - ret = kbd_get_first_active_token_bit(); 1693 - if (ret < 0) 1694 - return 0; 1695 - for (num = kbd_token_bits; num != 0 && ret > 0; --ret) 1696 - num &= num - 1; /* clear the first bit set */ 1697 - if (num == 0) 1698 - return 0; 1699 - return ffs(num) - 1; 1700 - } 1701 - 1702 - pr_warn("Keyboard brightness level control not supported\n"); 1703 - return 0; 1704 - } 1705 - 1706 - static void kbd_led_level_set(struct led_classdev *led_cdev, 1707 - enum led_brightness value) 1708 - { 1709 - struct kbd_state state; 1710 - struct kbd_state new_state; 1711 - u16 num; 1712 - 1713 - if (kbd_get_max_level()) { 1714 - if (kbd_get_state(&state)) 1715 - return; 1716 - new_state = state; 1717 - if (kbd_set_level(&new_state, value)) 1718 - return; 1719 - kbd_set_state_safe(&new_state, &state); 1720 - return; 1721 - } 1722 - 1723 - if (kbd_get_valid_token_counts()) { 1724 - for (num = kbd_token_bits; num != 0 && value > 0; --value) 1725 - num &= num - 1; /* clear the first bit set */ 1726 - if (num == 0) 1727 - return; 1728 - kbd_set_token_bit(ffs(num) - 1); 1729 - return; 1730 - } 1731 - 1732 - pr_warn("Keyboard brightness level control not supported\n"); 1733 - } 1734 - 1735 - static struct led_classdev kbd_led = { 1736 - .name = "dell::kbd_backlight", 1737 - .brightness_set = kbd_led_level_set, 1738 - .brightness_get = kbd_led_level_get, 1739 - .groups = kbd_led_groups, 1740 - }; 1741 - 1742 - static int __init kbd_led_init(struct device *dev) 1743 - { 1744 - kbd_init(); 1745 - if (!kbd_led_present) 1746 - return -ENODEV; 1747 - kbd_led.max_brightness = kbd_get_max_level(); 1748 - if (!kbd_led.max_brightness) { 1749 - kbd_led.max_brightness = kbd_get_valid_token_counts(); 1750 - if (kbd_led.max_brightness) 1751 - kbd_led.max_brightness--; 1752 - } 1753 - return led_classdev_register(dev, &kbd_led); 1754 - } 1755 - 1756 - static void brightness_set_exit(struct led_classdev *led_cdev, 1757 - enum led_brightness value) 1758 - { 1759 - /* Don't change backlight level on exit */ 1760 - }; 1761 - 1762 - static void kbd_led_exit(void) 1763 - { 1764 - if (!kbd_led_present) 1765 - return; 1766 - kbd_led.brightness_set = brightness_set_exit; 1767 - led_classdev_unregister(&kbd_led); 1768 850 } 1769 851 1770 852 static int __init dell_init(void) ··· 840 1878 841 1879 if (quirks && quirks->touchpad_led) 842 1880 touchpad_led_init(&platform_device->dev); 843 - 844 - kbd_led_init(&platform_device->dev); 845 1881 846 1882 dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL); 847 1883 if (dell_laptop_dir != NULL) ··· 908 1948 debugfs_remove_recursive(dell_laptop_dir); 909 1949 if (quirks && quirks->touchpad_led) 910 1950 touchpad_led_exit(); 911 - kbd_led_exit(); 912 1951 i8042_remove_filter(dell_laptop_i8042_filter); 913 1952 cancel_delayed_work_sync(&dell_rfkill_work); 914 1953 backlight_device_unregister(dell_backlight_device); ··· 924 1965 module_exit(dell_exit); 925 1966 926 1967 MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); 927 - MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>"); 928 - MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>"); 929 1968 MODULE_DESCRIPTION("Dell laptop driver"); 930 1969 MODULE_LICENSE("GPL");