Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Driver for Dell laptop extras |
| 3 | * |
| 4 | * Copyright (c) Red Hat <mjg@redhat.com> |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 5 | * Copyright (c) 2014 Gabriele Mazzotta <gabriele.mzt@gmail.com> |
| 6 | * Copyright (c) 2014 Pali Rohár <pali.rohar@gmail.com> |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 7 | * |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 8 | * Based on documentation in the libsmbios package: |
| 9 | * Copyright (C) 2005-2014 Dell Inc. |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 10 | * |
| 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. |
| 14 | */ |
| 15 | |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 16 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 17 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 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> |
| 25 | #include <linux/io.h> |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 26 | #include <linux/rfkill.h> |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 27 | #include <linux/power_supply.h> |
| 28 | #include <linux/acpi.h> |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 29 | #include <linux/mm.h> |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 30 | #include <linux/i8042.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 32 | #include <linux/debugfs.h> |
| 33 | #include <linux/seq_file.h> |
Len Brown | cad7312 | 2009-01-09 17:23:38 -0500 | [diff] [blame] | 34 | #include "../../firmware/dcdbas.h" |
Pali Rohár | f835857 | 2015-06-06 10:23:30 +0200 | [diff] [blame] | 35 | #include "dell-rbtn.h" |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 36 | |
| 37 | #define BRIGHTNESS_TOKEN 0x7d |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 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 |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 45 | |
| 46 | /* This structure will be modified by the firmware when we enter |
| 47 | * system management mode, hence the volatiles */ |
| 48 | |
| 49 | struct calling_interface_buffer { |
| 50 | u16 class; |
| 51 | u16 select; |
| 52 | volatile u32 input[4]; |
| 53 | volatile u32 output[4]; |
| 54 | } __packed; |
| 55 | |
| 56 | struct calling_interface_token { |
| 57 | u16 tokenID; |
| 58 | u16 location; |
| 59 | union { |
| 60 | u16 value; |
| 61 | u16 stringlength; |
| 62 | }; |
| 63 | }; |
| 64 | |
| 65 | struct calling_interface_structure { |
| 66 | struct dmi_header header; |
| 67 | u16 cmdIOAddress; |
| 68 | u8 cmdIOCode; |
| 69 | u32 supportedCmds; |
| 70 | struct calling_interface_token tokens[]; |
| 71 | } __packed; |
| 72 | |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 73 | struct quirk_entry { |
| 74 | u8 touchpad_led; |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 75 | |
| 76 | int needs_kbd_timeouts; |
| 77 | /* |
| 78 | * Ordered list of timeouts expressed in seconds. |
| 79 | * The list must end with -1 |
| 80 | */ |
| 81 | int kbd_timeouts[]; |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | static struct quirk_entry *quirks; |
| 85 | |
| 86 | static struct quirk_entry quirk_dell_vostro_v130 = { |
| 87 | .touchpad_led = 1, |
| 88 | }; |
| 89 | |
Mathias Krause | 681480c | 2014-07-16 19:43:09 +0200 | [diff] [blame] | 90 | static int __init dmi_matched(const struct dmi_system_id *dmi) |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 91 | { |
| 92 | quirks = dmi->driver_data; |
| 93 | return 1; |
| 94 | } |
| 95 | |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 96 | /* |
| 97 | * These values come from Windows utility provided by Dell. If any other value |
| 98 | * is used then BIOS silently set timeout to 0 without any error message. |
| 99 | */ |
| 100 | static struct quirk_entry quirk_dell_xps13_9333 = { |
| 101 | .needs_kbd_timeouts = 1, |
| 102 | .kbd_timeouts = { 0, 5, 15, 60, 5 * 60, 15 * 60, -1 }, |
| 103 | }; |
| 104 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 105 | static int da_command_address; |
| 106 | static int da_command_code; |
| 107 | static int da_num_tokens; |
| 108 | static struct calling_interface_token *da_tokens; |
| 109 | |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 110 | static struct platform_driver platform_driver = { |
| 111 | .driver = { |
| 112 | .name = "dell-laptop", |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 113 | } |
| 114 | }; |
| 115 | |
| 116 | static struct platform_device *platform_device; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 117 | static struct backlight_device *dell_backlight_device; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 118 | static struct rfkill *wifi_rfkill; |
| 119 | static struct rfkill *bluetooth_rfkill; |
| 120 | static struct rfkill *wwan_rfkill; |
Hans de Goede | 8e0e668d | 2013-11-17 14:00:26 +0100 | [diff] [blame] | 121 | static bool force_rfkill; |
| 122 | |
| 123 | module_param(force_rfkill, bool, 0444); |
| 124 | MODULE_PARM_DESC(force_rfkill, "enable rfkill on non whitelisted models"); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 125 | |
Uwe Kleine-König | 145047d | 2012-03-30 22:05:04 +0200 | [diff] [blame] | 126 | static const struct dmi_system_id dell_device_table[] __initconst = { |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 127 | { |
| 128 | .ident = "Dell laptop", |
| 129 | .matches = { |
| 130 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 131 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), |
| 132 | }, |
| 133 | }, |
Erik Andren | cb6a793 | 2010-02-14 11:53:23 -0500 | [diff] [blame] | 134 | { |
Rezwanul Kabir | 410d44c | 2010-06-23 12:02:43 -0500 | [diff] [blame] | 135 | .matches = { |
| 136 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 137 | DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /*Laptop*/ |
| 138 | }, |
| 139 | }, |
| 140 | { |
Erik Andren | cb6a793 | 2010-02-14 11:53:23 -0500 | [diff] [blame] | 141 | .ident = "Dell Computer Corporation", |
| 142 | .matches = { |
| 143 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), |
| 144 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), |
| 145 | }, |
| 146 | }, |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 147 | { } |
| 148 | }; |
Dmitry Torokhov | 35ae64f | 2011-11-14 00:25:00 -0800 | [diff] [blame] | 149 | MODULE_DEVICE_TABLE(dmi, dell_device_table); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 150 | |
Mathias Krause | 681480c | 2014-07-16 19:43:09 +0200 | [diff] [blame] | 151 | static const struct dmi_system_id dell_quirks[] __initconst = { |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 152 | { |
| 153 | .callback = dmi_matched, |
| 154 | .ident = "Dell Vostro V130", |
| 155 | .matches = { |
| 156 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 157 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V130"), |
| 158 | }, |
| 159 | .driver_data = &quirk_dell_vostro_v130, |
| 160 | }, |
| 161 | { |
| 162 | .callback = dmi_matched, |
| 163 | .ident = "Dell Vostro V131", |
| 164 | .matches = { |
| 165 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 166 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"), |
| 167 | }, |
| 168 | .driver_data = &quirk_dell_vostro_v130, |
| 169 | }, |
AceLan Kao | 2a74885 | 2011-11-17 15:30:42 +0800 | [diff] [blame] | 170 | { |
| 171 | .callback = dmi_matched, |
Ang Way Chuang | 57b31b2 | 2012-04-12 13:11:27 +0800 | [diff] [blame] | 172 | .ident = "Dell Vostro 3350", |
| 173 | .matches = { |
| 174 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 175 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3350"), |
| 176 | }, |
| 177 | .driver_data = &quirk_dell_vostro_v130, |
| 178 | }, |
| 179 | { |
| 180 | .callback = dmi_matched, |
AceLan Kao | 2a74885 | 2011-11-17 15:30:42 +0800 | [diff] [blame] | 181 | .ident = "Dell Vostro 3555", |
| 182 | .matches = { |
| 183 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 184 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3555"), |
| 185 | }, |
| 186 | .driver_data = &quirk_dell_vostro_v130, |
| 187 | }, |
| 188 | { |
| 189 | .callback = dmi_matched, |
| 190 | .ident = "Dell Inspiron N311z", |
| 191 | .matches = { |
| 192 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 193 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N311z"), |
| 194 | }, |
| 195 | .driver_data = &quirk_dell_vostro_v130, |
| 196 | }, |
| 197 | { |
| 198 | .callback = dmi_matched, |
| 199 | .ident = "Dell Inspiron M5110", |
| 200 | .matches = { |
| 201 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 202 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"), |
| 203 | }, |
| 204 | .driver_data = &quirk_dell_vostro_v130, |
| 205 | }, |
AceLan Kao | 7f83922 | 2012-04-20 11:47:26 +0800 | [diff] [blame] | 206 | { |
| 207 | .callback = dmi_matched, |
| 208 | .ident = "Dell Vostro 3360", |
| 209 | .matches = { |
| 210 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 211 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"), |
| 212 | }, |
| 213 | .driver_data = &quirk_dell_vostro_v130, |
| 214 | }, |
| 215 | { |
| 216 | .callback = dmi_matched, |
| 217 | .ident = "Dell Vostro 3460", |
| 218 | .matches = { |
| 219 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 220 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3460"), |
| 221 | }, |
| 222 | .driver_data = &quirk_dell_vostro_v130, |
| 223 | }, |
| 224 | { |
| 225 | .callback = dmi_matched, |
| 226 | .ident = "Dell Vostro 3560", |
| 227 | .matches = { |
| 228 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 229 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3560"), |
| 230 | }, |
| 231 | .driver_data = &quirk_dell_vostro_v130, |
| 232 | }, |
AceLan Kao | d0e0a477 | 2012-05-22 12:38:51 +0800 | [diff] [blame] | 233 | { |
| 234 | .callback = dmi_matched, |
| 235 | .ident = "Dell Vostro 3450", |
| 236 | .matches = { |
| 237 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 238 | DMI_MATCH(DMI_PRODUCT_NAME, "Dell System Vostro 3450"), |
| 239 | }, |
| 240 | .driver_data = &quirk_dell_vostro_v130, |
| 241 | }, |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 242 | { |
| 243 | .callback = dmi_matched, |
| 244 | .ident = "Dell Inspiron 5420", |
| 245 | .matches = { |
| 246 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 247 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5420"), |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 248 | }, |
| 249 | .driver_data = &quirk_dell_vostro_v130, |
| 250 | }, |
| 251 | { |
| 252 | .callback = dmi_matched, |
| 253 | .ident = "Dell Inspiron 5520", |
| 254 | .matches = { |
| 255 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 256 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5520"), |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 257 | }, |
| 258 | .driver_data = &quirk_dell_vostro_v130, |
| 259 | }, |
| 260 | { |
| 261 | .callback = dmi_matched, |
| 262 | .ident = "Dell Inspiron 5720", |
| 263 | .matches = { |
| 264 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 265 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5720"), |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 266 | }, |
| 267 | .driver_data = &quirk_dell_vostro_v130, |
| 268 | }, |
| 269 | { |
| 270 | .callback = dmi_matched, |
| 271 | .ident = "Dell Inspiron 7420", |
| 272 | .matches = { |
| 273 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 274 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7420"), |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 275 | }, |
| 276 | .driver_data = &quirk_dell_vostro_v130, |
| 277 | }, |
| 278 | { |
| 279 | .callback = dmi_matched, |
| 280 | .ident = "Dell Inspiron 7520", |
| 281 | .matches = { |
| 282 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 283 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7520"), |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 284 | }, |
| 285 | .driver_data = &quirk_dell_vostro_v130, |
| 286 | }, |
| 287 | { |
| 288 | .callback = dmi_matched, |
| 289 | .ident = "Dell Inspiron 7720", |
| 290 | .matches = { |
| 291 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 292 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"), |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 293 | }, |
| 294 | .driver_data = &quirk_dell_vostro_v130, |
| 295 | }, |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 296 | { |
| 297 | .callback = dmi_matched, |
| 298 | .ident = "Dell XPS13 9333", |
| 299 | .matches = { |
| 300 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 301 | DMI_MATCH(DMI_PRODUCT_NAME, "XPS13 9333"), |
| 302 | }, |
| 303 | .driver_data = &quirk_dell_xps13_9333, |
| 304 | }, |
Martin Nyhus | d62d421 | 2012-03-15 18:25:48 +0100 | [diff] [blame] | 305 | { } |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 306 | }; |
| 307 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 308 | static struct calling_interface_buffer *buffer; |
Ingo Molnar | 94d8f78 | 2010-03-01 09:43:52 -0500 | [diff] [blame] | 309 | static struct page *bufferpage; |
| 310 | static DEFINE_MUTEX(buffer_mutex); |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 311 | |
Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame] | 312 | static int hwswitch_state; |
| 313 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 314 | static void get_buffer(void) |
| 315 | { |
| 316 | mutex_lock(&buffer_mutex); |
| 317 | memset(buffer, 0, sizeof(struct calling_interface_buffer)); |
| 318 | } |
| 319 | |
| 320 | static void release_buffer(void) |
| 321 | { |
| 322 | mutex_unlock(&buffer_mutex); |
| 323 | } |
| 324 | |
Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 325 | static void __init parse_da_table(const struct dmi_header *dm) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 326 | { |
| 327 | /* Final token is a terminator, so we don't want to copy it */ |
| 328 | int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1; |
David Woodhouse | fe9ab00 | 2013-03-14 13:21:00 +0000 | [diff] [blame] | 329 | struct calling_interface_token *new_da_tokens; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 330 | struct calling_interface_structure *table = |
| 331 | container_of(dm, struct calling_interface_structure, header); |
| 332 | |
| 333 | /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least |
| 334 | 6 bytes of entry */ |
| 335 | |
| 336 | if (dm->length < 17) |
| 337 | return; |
| 338 | |
| 339 | da_command_address = table->cmdIOAddress; |
| 340 | da_command_code = table->cmdIOCode; |
| 341 | |
David Woodhouse | fe9ab00 | 2013-03-14 13:21:00 +0000 | [diff] [blame] | 342 | new_da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) * |
| 343 | sizeof(struct calling_interface_token), |
| 344 | GFP_KERNEL); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 345 | |
David Woodhouse | fe9ab00 | 2013-03-14 13:21:00 +0000 | [diff] [blame] | 346 | if (!new_da_tokens) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 347 | return; |
David Woodhouse | fe9ab00 | 2013-03-14 13:21:00 +0000 | [diff] [blame] | 348 | da_tokens = new_da_tokens; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 349 | |
| 350 | memcpy(da_tokens+da_num_tokens, table->tokens, |
| 351 | sizeof(struct calling_interface_token) * tokens); |
| 352 | |
| 353 | da_num_tokens += tokens; |
| 354 | } |
| 355 | |
Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 356 | static void __init find_tokens(const struct dmi_header *dm, void *dummy) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 357 | { |
| 358 | switch (dm->type) { |
| 359 | case 0xd4: /* Indexed IO */ |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 360 | case 0xd5: /* Protected Area Type 1 */ |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 361 | case 0xd6: /* Protected Area Type 2 */ |
| 362 | break; |
| 363 | case 0xda: /* Calling interface */ |
| 364 | parse_da_table(dm); |
| 365 | break; |
| 366 | } |
| 367 | } |
| 368 | |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 369 | static int find_token_id(int tokenid) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 370 | { |
| 371 | int i; |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 372 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 373 | for (i = 0; i < da_num_tokens; i++) { |
| 374 | if (da_tokens[i].tokenID == tokenid) |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 375 | return i; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | return -1; |
| 379 | } |
| 380 | |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 381 | static int find_token_location(int tokenid) |
| 382 | { |
| 383 | int id; |
| 384 | |
| 385 | id = find_token_id(tokenid); |
| 386 | if (id == -1) |
| 387 | return -1; |
| 388 | |
| 389 | return da_tokens[id].location; |
| 390 | } |
| 391 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 392 | static struct calling_interface_buffer * |
| 393 | dell_send_request(struct calling_interface_buffer *buffer, int class, |
| 394 | int select) |
| 395 | { |
| 396 | struct smi_cmd command; |
| 397 | |
| 398 | command.magic = SMI_CMD_MAGIC; |
| 399 | command.command_address = da_command_address; |
| 400 | command.command_code = da_command_code; |
| 401 | command.ebx = virt_to_phys(buffer); |
| 402 | command.ecx = 0x42534931; |
| 403 | |
| 404 | buffer->class = class; |
| 405 | buffer->select = select; |
| 406 | |
| 407 | dcdbas_smi_request(&command); |
| 408 | |
| 409 | return buffer; |
| 410 | } |
| 411 | |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 412 | static inline int dell_smi_error(int value) |
| 413 | { |
| 414 | switch (value) { |
| 415 | case 0: /* Completed successfully */ |
| 416 | return 0; |
| 417 | case -1: /* Completed with error */ |
| 418 | return -EIO; |
| 419 | case -2: /* Function not supported */ |
| 420 | return -ENXIO; |
| 421 | default: /* Unknown error */ |
| 422 | return -EINVAL; |
| 423 | } |
| 424 | } |
| 425 | |
Pali Rohár | f992efb | 2015-06-21 10:39:26 +0200 | [diff] [blame^] | 426 | /* |
| 427 | * Derived from information in smbios-wireless-ctl: |
| 428 | * |
| 429 | * cbSelect 17, Value 11 |
| 430 | * |
| 431 | * Return Wireless Info |
| 432 | * cbArg1, byte0 = 0x00 |
| 433 | * |
| 434 | * cbRes1 Standard return codes (0, -1, -2) |
| 435 | * cbRes2 Info bit flags: |
| 436 | * |
| 437 | * 0 Hardware switch supported (1) |
| 438 | * 1 WiFi locator supported (1) |
| 439 | * 2 WLAN supported (1) |
| 440 | * 3 Bluetooth (BT) supported (1) |
| 441 | * 4 WWAN supported (1) |
| 442 | * 5 Wireless KBD supported (1) |
| 443 | * 6 Uw b supported (1) |
| 444 | * 7 WiGig supported (1) |
| 445 | * 8 WLAN installed (1) |
| 446 | * 9 BT installed (1) |
| 447 | * 10 WWAN installed (1) |
| 448 | * 11 Uw b installed (1) |
| 449 | * 12 WiGig installed (1) |
| 450 | * 13-15 Reserved (0) |
| 451 | * 16 Hardware (HW) switch is On (1) |
| 452 | * 17 WLAN disabled (1) |
| 453 | * 18 BT disabled (1) |
| 454 | * 19 WWAN disabled (1) |
| 455 | * 20 Uw b disabled (1) |
| 456 | * 21 WiGig disabled (1) |
| 457 | * 20-31 Reserved (0) |
| 458 | * |
| 459 | * cbRes3 NVRAM size in bytes |
| 460 | * cbRes4, byte 0 NVRAM format version number |
| 461 | * |
| 462 | * |
| 463 | * Set QuickSet Radio Disable Flag |
| 464 | * cbArg1, byte0 = 0x01 |
| 465 | * cbArg1, byte1 |
| 466 | * Radio ID value: |
| 467 | * 0 Radio Status |
| 468 | * 1 WLAN ID |
| 469 | * 2 BT ID |
| 470 | * 3 WWAN ID |
| 471 | * 4 UWB ID |
| 472 | * 5 WIGIG ID |
| 473 | * cbArg1, byte2 Flag bits: |
| 474 | * 0 QuickSet disables radio (1) |
| 475 | * 1-7 Reserved (0) |
| 476 | * |
| 477 | * cbRes1 Standard return codes (0, -1, -2) |
| 478 | * cbRes2 QuickSet (QS) radio disable bit map: |
| 479 | * 0 QS disables WLAN |
| 480 | * 1 QS disables BT |
| 481 | * 2 QS disables WWAN |
| 482 | * 3 QS disables UWB |
| 483 | * 4 QS disables WIGIG |
| 484 | * 5-31 Reserved (0) |
| 485 | * |
| 486 | * Wireless Switch Configuration |
| 487 | * cbArg1, byte0 = 0x02 |
| 488 | * |
| 489 | * cbArg1, byte1 |
| 490 | * Subcommand: |
| 491 | * 0 Get config |
| 492 | * 1 Set config |
| 493 | * 2 Set WiFi locator enable/disable |
| 494 | * cbArg1,byte2 |
| 495 | * Switch settings (if byte 1==1): |
| 496 | * 0 WLAN sw itch control (1) |
| 497 | * 1 BT sw itch control (1) |
| 498 | * 2 WWAN sw itch control (1) |
| 499 | * 3 UWB sw itch control (1) |
| 500 | * 4 WiGig sw itch control (1) |
| 501 | * 5-7 Reserved (0) |
| 502 | * cbArg1, byte2 Enable bits (if byte 1==2): |
| 503 | * 0 Enable WiFi locator (1) |
| 504 | * |
| 505 | * cbRes1 Standard return codes (0, -1, -2) |
| 506 | * cbRes2 QuickSet radio disable bit map: |
| 507 | * 0 WLAN controlled by sw itch (1) |
| 508 | * 1 BT controlled by sw itch (1) |
| 509 | * 2 WWAN controlled by sw itch (1) |
| 510 | * 3 UWB controlled by sw itch (1) |
| 511 | * 4 WiGig controlled by sw itch (1) |
| 512 | * 5-6 Reserved (0) |
| 513 | * 7 Wireless sw itch config locked (1) |
| 514 | * 8 WiFi locator enabled (1) |
| 515 | * 9-14 Reserved (0) |
| 516 | * 15 WiFi locator setting locked (1) |
| 517 | * 16-31 Reserved (0) |
| 518 | * |
| 519 | * Read Local Config Data (LCD) |
| 520 | * cbArg1, byte0 = 0x10 |
| 521 | * cbArg1, byte1 NVRAM index low byte |
| 522 | * cbArg1, byte2 NVRAM index high byte |
| 523 | * cbRes1 Standard return codes (0, -1, -2) |
| 524 | * cbRes2 4 bytes read from LCD[index] |
| 525 | * cbRes3 4 bytes read from LCD[index+4] |
| 526 | * cbRes4 4 bytes read from LCD[index+8] |
| 527 | * |
| 528 | * Write Local Config Data (LCD) |
| 529 | * cbArg1, byte0 = 0x11 |
| 530 | * cbArg1, byte1 NVRAM index low byte |
| 531 | * cbArg1, byte2 NVRAM index high byte |
| 532 | * cbArg2 4 bytes to w rite at LCD[index] |
| 533 | * cbArg3 4 bytes to w rite at LCD[index+4] |
| 534 | * cbArg4 4 bytes to w rite at LCD[index+8] |
| 535 | * cbRes1 Standard return codes (0, -1, -2) |
| 536 | * |
| 537 | * Populate Local Config Data from NVRAM |
| 538 | * cbArg1, byte0 = 0x12 |
| 539 | * cbRes1 Standard return codes (0, -1, -2) |
| 540 | * |
| 541 | * Commit Local Config Data to NVRAM |
| 542 | * cbArg1, byte0 = 0x13 |
| 543 | * cbRes1 Standard return codes (0, -1, -2) |
| 544 | */ |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 545 | |
| 546 | static int dell_rfkill_set(void *data, bool blocked) |
| 547 | { |
| 548 | int disable = blocked ? 1 : 0; |
| 549 | unsigned long radio = (unsigned long)data; |
| 550 | int hwswitch_bit = (unsigned long)data - 1; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 551 | |
| 552 | get_buffer(); |
| 553 | dell_send_request(buffer, 17, 11); |
| 554 | |
| 555 | /* If the hardware switch controls this radio, and the hardware |
Hans de Goede | ed11289 | 2013-11-17 14:00:24 +0100 | [diff] [blame] | 556 | switch is disabled, always disable the radio */ |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 557 | if ((hwswitch_state & BIT(hwswitch_bit)) && |
Hans de Goede | 4d39d88 | 2013-11-17 14:00:22 +0100 | [diff] [blame] | 558 | !(buffer->output[1] & BIT(16))) |
Hans de Goede | ed11289 | 2013-11-17 14:00:24 +0100 | [diff] [blame] | 559 | disable = 1; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 560 | |
| 561 | buffer->input[0] = (1 | (radio<<8) | (disable << 16)); |
| 562 | dell_send_request(buffer, 17, 11); |
| 563 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 564 | release_buffer(); |
Hans de Goede | 4d39d88 | 2013-11-17 14:00:22 +0100 | [diff] [blame] | 565 | return 0; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 566 | } |
| 567 | |
Hans de Goede | 04c9a3a | 2013-11-17 14:00:23 +0100 | [diff] [blame] | 568 | /* Must be called with the buffer held */ |
Hans de Goede | 33f9359 | 2013-11-17 14:00:20 +0100 | [diff] [blame] | 569 | static void dell_rfkill_update_sw_state(struct rfkill *rfkill, int radio, |
| 570 | int status) |
Hans de Goede | d038880 | 2013-11-17 14:00:19 +0100 | [diff] [blame] | 571 | { |
Hans de Goede | 04c9a3a | 2013-11-17 14:00:23 +0100 | [diff] [blame] | 572 | if (status & BIT(0)) { |
| 573 | /* Has hw-switch, sync sw_state to BIOS */ |
| 574 | int block = rfkill_blocked(rfkill); |
| 575 | buffer->input[0] = (1 | (radio << 8) | (block << 16)); |
| 576 | dell_send_request(buffer, 17, 11); |
| 577 | } else { |
Hans de Goede | 3f56588 | 2013-11-17 14:00:21 +0100 | [diff] [blame] | 578 | /* No hw-switch, sync BIOS state to sw_state */ |
| 579 | rfkill_set_sw_state(rfkill, !!(status & BIT(radio + 16))); |
| 580 | } |
Hans de Goede | 33f9359 | 2013-11-17 14:00:20 +0100 | [diff] [blame] | 581 | } |
Hans de Goede | d038880 | 2013-11-17 14:00:19 +0100 | [diff] [blame] | 582 | |
Hans de Goede | 33f9359 | 2013-11-17 14:00:20 +0100 | [diff] [blame] | 583 | static void dell_rfkill_update_hw_state(struct rfkill *rfkill, int radio, |
| 584 | int status) |
| 585 | { |
Hans de Goede | d038880 | 2013-11-17 14:00:19 +0100 | [diff] [blame] | 586 | if (hwswitch_state & (BIT(radio - 1))) |
| 587 | rfkill_set_hw_state(rfkill, !(status & BIT(16))); |
| 588 | } |
| 589 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 590 | static void dell_rfkill_query(struct rfkill *rfkill, void *data) |
| 591 | { |
| 592 | int status; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 593 | |
| 594 | get_buffer(); |
| 595 | dell_send_request(buffer, 17, 11); |
| 596 | status = buffer->output[1]; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 597 | |
Hans de Goede | 33f9359 | 2013-11-17 14:00:20 +0100 | [diff] [blame] | 598 | dell_rfkill_update_hw_state(rfkill, (unsigned long)data, status); |
Hans de Goede | 04c9a3a | 2013-11-17 14:00:23 +0100 | [diff] [blame] | 599 | |
| 600 | release_buffer(); |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static const struct rfkill_ops dell_rfkill_ops = { |
| 604 | .set_block = dell_rfkill_set, |
| 605 | .query = dell_rfkill_query, |
| 606 | }; |
| 607 | |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 608 | static struct dentry *dell_laptop_dir; |
| 609 | |
| 610 | static int dell_debugfs_show(struct seq_file *s, void *data) |
| 611 | { |
| 612 | int status; |
| 613 | |
| 614 | get_buffer(); |
| 615 | dell_send_request(buffer, 17, 11); |
| 616 | status = buffer->output[1]; |
| 617 | release_buffer(); |
| 618 | |
| 619 | seq_printf(s, "status:\t0x%X\n", status); |
| 620 | seq_printf(s, "Bit 0 : Hardware switch supported: %lu\n", |
| 621 | status & BIT(0)); |
| 622 | seq_printf(s, "Bit 1 : Wifi locator supported: %lu\n", |
| 623 | (status & BIT(1)) >> 1); |
| 624 | seq_printf(s, "Bit 2 : Wifi is supported: %lu\n", |
| 625 | (status & BIT(2)) >> 2); |
| 626 | seq_printf(s, "Bit 3 : Bluetooth is supported: %lu\n", |
| 627 | (status & BIT(3)) >> 3); |
| 628 | seq_printf(s, "Bit 4 : WWAN is supported: %lu\n", |
| 629 | (status & BIT(4)) >> 4); |
| 630 | seq_printf(s, "Bit 5 : Wireless keyboard supported: %lu\n", |
| 631 | (status & BIT(5)) >> 5); |
| 632 | seq_printf(s, "Bit 8 : Wifi is installed: %lu\n", |
| 633 | (status & BIT(8)) >> 8); |
| 634 | seq_printf(s, "Bit 9 : Bluetooth is installed: %lu\n", |
| 635 | (status & BIT(9)) >> 9); |
| 636 | seq_printf(s, "Bit 10: WWAN is installed: %lu\n", |
| 637 | (status & BIT(10)) >> 10); |
| 638 | seq_printf(s, "Bit 16: Hardware switch is on: %lu\n", |
| 639 | (status & BIT(16)) >> 16); |
| 640 | seq_printf(s, "Bit 17: Wifi is blocked: %lu\n", |
| 641 | (status & BIT(17)) >> 17); |
| 642 | seq_printf(s, "Bit 18: Bluetooth is blocked: %lu\n", |
| 643 | (status & BIT(18)) >> 18); |
| 644 | seq_printf(s, "Bit 19: WWAN is blocked: %lu\n", |
| 645 | (status & BIT(19)) >> 19); |
| 646 | |
| 647 | seq_printf(s, "\nhwswitch_state:\t0x%X\n", hwswitch_state); |
| 648 | seq_printf(s, "Bit 0 : Wifi controlled by switch: %lu\n", |
| 649 | hwswitch_state & BIT(0)); |
| 650 | seq_printf(s, "Bit 1 : Bluetooth controlled by switch: %lu\n", |
| 651 | (hwswitch_state & BIT(1)) >> 1); |
| 652 | seq_printf(s, "Bit 2 : WWAN controlled by switch: %lu\n", |
| 653 | (hwswitch_state & BIT(2)) >> 2); |
| 654 | seq_printf(s, "Bit 7 : Wireless switch config locked: %lu\n", |
| 655 | (hwswitch_state & BIT(7)) >> 7); |
| 656 | seq_printf(s, "Bit 8 : Wifi locator enabled: %lu\n", |
| 657 | (hwswitch_state & BIT(8)) >> 8); |
| 658 | seq_printf(s, "Bit 15: Wifi locator setting locked: %lu\n", |
| 659 | (hwswitch_state & BIT(15)) >> 15); |
| 660 | |
| 661 | return 0; |
| 662 | } |
| 663 | |
| 664 | static int dell_debugfs_open(struct inode *inode, struct file *file) |
| 665 | { |
| 666 | return single_open(file, dell_debugfs_show, inode->i_private); |
| 667 | } |
| 668 | |
| 669 | static const struct file_operations dell_debugfs_fops = { |
| 670 | .owner = THIS_MODULE, |
| 671 | .open = dell_debugfs_open, |
| 672 | .read = seq_read, |
| 673 | .llseek = seq_lseek, |
| 674 | .release = single_release, |
| 675 | }; |
| 676 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 677 | static void dell_update_rfkill(struct work_struct *ignored) |
| 678 | { |
Hans de Goede | d038880 | 2013-11-17 14:00:19 +0100 | [diff] [blame] | 679 | int status; |
| 680 | |
| 681 | get_buffer(); |
| 682 | dell_send_request(buffer, 17, 11); |
| 683 | status = buffer->output[1]; |
Hans de Goede | d038880 | 2013-11-17 14:00:19 +0100 | [diff] [blame] | 684 | |
Hans de Goede | 33f9359 | 2013-11-17 14:00:20 +0100 | [diff] [blame] | 685 | if (wifi_rfkill) { |
| 686 | dell_rfkill_update_hw_state(wifi_rfkill, 1, status); |
| 687 | dell_rfkill_update_sw_state(wifi_rfkill, 1, status); |
| 688 | } |
| 689 | if (bluetooth_rfkill) { |
| 690 | dell_rfkill_update_hw_state(bluetooth_rfkill, 2, status); |
| 691 | dell_rfkill_update_sw_state(bluetooth_rfkill, 2, status); |
| 692 | } |
| 693 | if (wwan_rfkill) { |
| 694 | dell_rfkill_update_hw_state(wwan_rfkill, 3, status); |
| 695 | dell_rfkill_update_sw_state(wwan_rfkill, 3, status); |
| 696 | } |
Hans de Goede | 04c9a3a | 2013-11-17 14:00:23 +0100 | [diff] [blame] | 697 | |
| 698 | release_buffer(); |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 699 | } |
| 700 | static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill); |
| 701 | |
Hans de Goede | 97f440c | 2013-12-24 20:34:01 +0100 | [diff] [blame] | 702 | static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str, |
| 703 | struct serio *port) |
| 704 | { |
| 705 | static bool extended; |
| 706 | |
Giedrius Statkevičius | 9828037 | 2014-10-18 02:57:20 +0300 | [diff] [blame] | 707 | if (str & I8042_STR_AUXDATA) |
Hans de Goede | 97f440c | 2013-12-24 20:34:01 +0100 | [diff] [blame] | 708 | return false; |
| 709 | |
| 710 | if (unlikely(data == 0xe0)) { |
| 711 | extended = true; |
| 712 | return false; |
| 713 | } else if (unlikely(extended)) { |
| 714 | switch (data) { |
| 715 | case 0x8: |
| 716 | schedule_delayed_work(&dell_rfkill_work, |
| 717 | round_jiffies_relative(HZ / 4)); |
| 718 | break; |
| 719 | } |
| 720 | extended = false; |
| 721 | } |
| 722 | |
| 723 | return false; |
| 724 | } |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 725 | |
Pali Rohár | f835857 | 2015-06-06 10:23:30 +0200 | [diff] [blame] | 726 | static int (*dell_rbtn_notifier_register_func)(struct notifier_block *); |
| 727 | static int (*dell_rbtn_notifier_unregister_func)(struct notifier_block *); |
| 728 | |
| 729 | static int dell_laptop_rbtn_notifier_call(struct notifier_block *nb, |
| 730 | unsigned long action, void *data) |
| 731 | { |
| 732 | schedule_delayed_work(&dell_rfkill_work, 0); |
| 733 | return NOTIFY_OK; |
| 734 | } |
| 735 | |
| 736 | static struct notifier_block dell_laptop_rbtn_notifier = { |
| 737 | .notifier_call = dell_laptop_rbtn_notifier_call, |
| 738 | }; |
| 739 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 740 | static int __init dell_setup_rfkill(void) |
| 741 | { |
Hans de Goede | ba5194f | 2013-12-06 12:17:27 +0100 | [diff] [blame] | 742 | int status, ret, whitelisted; |
Hans de Goede | 2a92551 | 2013-11-17 14:00:17 +0100 | [diff] [blame] | 743 | const char *product; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 744 | |
Hans de Goede | 2a92551 | 2013-11-17 14:00:17 +0100 | [diff] [blame] | 745 | /* |
Hans de Goede | ba5194f | 2013-12-06 12:17:27 +0100 | [diff] [blame] | 746 | * rfkill support causes trouble on various models, mostly Inspirons. |
| 747 | * So we whitelist certain series, and don't support rfkill on others. |
Hans de Goede | 2a92551 | 2013-11-17 14:00:17 +0100 | [diff] [blame] | 748 | */ |
Hans de Goede | ba5194f | 2013-12-06 12:17:27 +0100 | [diff] [blame] | 749 | whitelisted = 0; |
Hans de Goede | 2a92551 | 2013-11-17 14:00:17 +0100 | [diff] [blame] | 750 | product = dmi_get_system_info(DMI_PRODUCT_NAME); |
Hans de Goede | ba5194f | 2013-12-06 12:17:27 +0100 | [diff] [blame] | 751 | if (product && (strncmp(product, "Latitude", 8) == 0 || |
| 752 | strncmp(product, "Precision", 9) == 0)) |
| 753 | whitelisted = 1; |
| 754 | if (!force_rfkill && !whitelisted) |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 755 | return 0; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 756 | |
| 757 | get_buffer(); |
| 758 | dell_send_request(buffer, 17, 11); |
| 759 | status = buffer->output[1]; |
| 760 | buffer->input[0] = 0x2; |
| 761 | dell_send_request(buffer, 17, 11); |
| 762 | hwswitch_state = buffer->output[1]; |
| 763 | release_buffer(); |
| 764 | |
Hans de Goede | 2bd4ac1 | 2013-11-17 14:00:27 +0100 | [diff] [blame] | 765 | if (!(status & BIT(0))) { |
| 766 | if (force_rfkill) { |
| 767 | /* No hwsitch, clear all hw-controlled bits */ |
| 768 | hwswitch_state &= ~7; |
| 769 | } else { |
| 770 | /* rfkill is only tested on laptops with a hwswitch */ |
| 771 | return 0; |
| 772 | } |
| 773 | } |
| 774 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 775 | if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) { |
| 776 | wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev, |
| 777 | RFKILL_TYPE_WLAN, |
| 778 | &dell_rfkill_ops, (void *) 1); |
| 779 | if (!wifi_rfkill) { |
| 780 | ret = -ENOMEM; |
| 781 | goto err_wifi; |
| 782 | } |
| 783 | ret = rfkill_register(wifi_rfkill); |
| 784 | if (ret) |
| 785 | goto err_wifi; |
| 786 | } |
| 787 | |
| 788 | if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) { |
| 789 | bluetooth_rfkill = rfkill_alloc("dell-bluetooth", |
| 790 | &platform_device->dev, |
| 791 | RFKILL_TYPE_BLUETOOTH, |
| 792 | &dell_rfkill_ops, (void *) 2); |
| 793 | if (!bluetooth_rfkill) { |
| 794 | ret = -ENOMEM; |
| 795 | goto err_bluetooth; |
| 796 | } |
| 797 | ret = rfkill_register(bluetooth_rfkill); |
| 798 | if (ret) |
| 799 | goto err_bluetooth; |
| 800 | } |
| 801 | |
| 802 | if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) { |
| 803 | wwan_rfkill = rfkill_alloc("dell-wwan", |
| 804 | &platform_device->dev, |
| 805 | RFKILL_TYPE_WWAN, |
| 806 | &dell_rfkill_ops, (void *) 3); |
| 807 | if (!wwan_rfkill) { |
| 808 | ret = -ENOMEM; |
| 809 | goto err_wwan; |
| 810 | } |
| 811 | ret = rfkill_register(wwan_rfkill); |
| 812 | if (ret) |
| 813 | goto err_wwan; |
| 814 | } |
| 815 | |
Pali Rohár | f835857 | 2015-06-06 10:23:30 +0200 | [diff] [blame] | 816 | /* |
| 817 | * Dell Airplane Mode Switch driver (dell-rbtn) supports ACPI devices |
| 818 | * which can receive events from HW slider switch. |
| 819 | * |
| 820 | * Dell SMBIOS on whitelisted models supports controlling radio devices |
| 821 | * but does not support receiving HW button switch events. We can use |
| 822 | * i8042 filter hook function to receive keyboard data and handle |
| 823 | * keycode for HW button. |
| 824 | * |
| 825 | * So if it is possible we will use Dell Airplane Mode Switch ACPI |
| 826 | * driver for receiving HW events and Dell SMBIOS for setting rfkill |
| 827 | * states. If ACPI driver or device is not available we will fallback to |
| 828 | * i8042 filter hook function. |
| 829 | * |
| 830 | * To prevent duplicate rfkill devices which control and do same thing, |
| 831 | * dell-rbtn driver will automatically remove its own rfkill devices |
| 832 | * once function dell_rbtn_notifier_register() is called. |
| 833 | */ |
| 834 | |
| 835 | dell_rbtn_notifier_register_func = |
| 836 | symbol_request(dell_rbtn_notifier_register); |
| 837 | if (dell_rbtn_notifier_register_func) { |
| 838 | dell_rbtn_notifier_unregister_func = |
| 839 | symbol_request(dell_rbtn_notifier_unregister); |
| 840 | if (!dell_rbtn_notifier_unregister_func) { |
| 841 | symbol_put(dell_rbtn_notifier_register); |
| 842 | dell_rbtn_notifier_register_func = NULL; |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | if (dell_rbtn_notifier_register_func) { |
| 847 | ret = dell_rbtn_notifier_register_func( |
| 848 | &dell_laptop_rbtn_notifier); |
| 849 | symbol_put(dell_rbtn_notifier_register); |
| 850 | dell_rbtn_notifier_register_func = NULL; |
| 851 | if (ret != 0) { |
| 852 | symbol_put(dell_rbtn_notifier_unregister); |
| 853 | dell_rbtn_notifier_unregister_func = NULL; |
| 854 | } |
| 855 | } else { |
| 856 | pr_info("Symbols from dell-rbtn acpi driver are not available\n"); |
| 857 | ret = -ENODEV; |
| 858 | } |
| 859 | |
| 860 | if (ret == 0) { |
| 861 | pr_info("Using dell-rbtn acpi driver for receiving events\n"); |
| 862 | } else if (ret != -ENODEV) { |
| 863 | pr_warn("Unable to register dell rbtn notifier\n"); |
Hans de Goede | 97f440c | 2013-12-24 20:34:01 +0100 | [diff] [blame] | 864 | goto err_filter; |
Pali Rohár | f835857 | 2015-06-06 10:23:30 +0200 | [diff] [blame] | 865 | } else { |
| 866 | ret = i8042_install_filter(dell_laptop_i8042_filter); |
| 867 | if (ret) { |
| 868 | pr_warn("Unable to install key filter\n"); |
| 869 | goto err_filter; |
| 870 | } |
| 871 | pr_info("Using i8042 filter function for receiving events\n"); |
Hans de Goede | 97f440c | 2013-12-24 20:34:01 +0100 | [diff] [blame] | 872 | } |
| 873 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 874 | return 0; |
Hans de Goede | 97f440c | 2013-12-24 20:34:01 +0100 | [diff] [blame] | 875 | err_filter: |
| 876 | if (wwan_rfkill) |
| 877 | rfkill_unregister(wwan_rfkill); |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 878 | err_wwan: |
| 879 | rfkill_destroy(wwan_rfkill); |
| 880 | if (bluetooth_rfkill) |
| 881 | rfkill_unregister(bluetooth_rfkill); |
| 882 | err_bluetooth: |
| 883 | rfkill_destroy(bluetooth_rfkill); |
| 884 | if (wifi_rfkill) |
| 885 | rfkill_unregister(wifi_rfkill); |
| 886 | err_wifi: |
| 887 | rfkill_destroy(wifi_rfkill); |
| 888 | |
| 889 | return ret; |
| 890 | } |
| 891 | |
| 892 | static void dell_cleanup_rfkill(void) |
| 893 | { |
Pali Rohár | f835857 | 2015-06-06 10:23:30 +0200 | [diff] [blame] | 894 | if (dell_rbtn_notifier_unregister_func) { |
| 895 | dell_rbtn_notifier_unregister_func(&dell_laptop_rbtn_notifier); |
| 896 | symbol_put(dell_rbtn_notifier_unregister); |
| 897 | dell_rbtn_notifier_unregister_func = NULL; |
| 898 | } else { |
| 899 | i8042_remove_filter(dell_laptop_i8042_filter); |
| 900 | } |
| 901 | cancel_delayed_work_sync(&dell_rfkill_work); |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 902 | if (wifi_rfkill) { |
| 903 | rfkill_unregister(wifi_rfkill); |
| 904 | rfkill_destroy(wifi_rfkill); |
| 905 | } |
| 906 | if (bluetooth_rfkill) { |
| 907 | rfkill_unregister(bluetooth_rfkill); |
| 908 | rfkill_destroy(bluetooth_rfkill); |
| 909 | } |
| 910 | if (wwan_rfkill) { |
| 911 | rfkill_unregister(wwan_rfkill); |
| 912 | rfkill_destroy(wwan_rfkill); |
| 913 | } |
| 914 | } |
| 915 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 916 | static int dell_send_intensity(struct backlight_device *bd) |
| 917 | { |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 918 | int ret = 0; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 919 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 920 | get_buffer(); |
| 921 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); |
| 922 | buffer->input[1] = bd->props.brightness; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 923 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 924 | if (buffer->input[0] == -1) { |
| 925 | ret = -ENODEV; |
| 926 | goto out; |
| 927 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 928 | |
| 929 | if (power_supply_is_system_supplied() > 0) |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 930 | dell_send_request(buffer, 1, 2); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 931 | else |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 932 | dell_send_request(buffer, 1, 1); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 933 | |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 934 | out: |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 935 | release_buffer(); |
Wei Yongjun | 7da8fb2 | 2013-11-23 21:02:51 +0800 | [diff] [blame] | 936 | return ret; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | static int dell_get_intensity(struct backlight_device *bd) |
| 940 | { |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 941 | int ret = 0; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 942 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 943 | get_buffer(); |
| 944 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 945 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 946 | if (buffer->input[0] == -1) { |
| 947 | ret = -ENODEV; |
| 948 | goto out; |
| 949 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 950 | |
| 951 | if (power_supply_is_system_supplied() > 0) |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 952 | dell_send_request(buffer, 0, 2); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 953 | else |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 954 | dell_send_request(buffer, 0, 1); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 955 | |
Jose Alonso | b486742 | 2011-07-10 15:46:51 -0300 | [diff] [blame] | 956 | ret = buffer->output[1]; |
| 957 | |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 958 | out: |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 959 | release_buffer(); |
Jose Alonso | b486742 | 2011-07-10 15:46:51 -0300 | [diff] [blame] | 960 | return ret; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 961 | } |
| 962 | |
Lionel Debroux | acc2472 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 963 | static const struct backlight_ops dell_ops = { |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 964 | .get_brightness = dell_get_intensity, |
| 965 | .update_status = dell_send_intensity, |
| 966 | }; |
| 967 | |
Randy Dunlap | 869f8df | 2011-11-16 18:20:51 -0800 | [diff] [blame] | 968 | static void touchpad_led_on(void) |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 969 | { |
| 970 | int command = 0x97; |
| 971 | char data = 1; |
| 972 | i8042_command(&data, command | 1 << 12); |
| 973 | } |
| 974 | |
Randy Dunlap | 869f8df | 2011-11-16 18:20:51 -0800 | [diff] [blame] | 975 | static void touchpad_led_off(void) |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 976 | { |
| 977 | int command = 0x97; |
| 978 | char data = 2; |
| 979 | i8042_command(&data, command | 1 << 12); |
| 980 | } |
| 981 | |
| 982 | static void touchpad_led_set(struct led_classdev *led_cdev, |
| 983 | enum led_brightness value) |
| 984 | { |
| 985 | if (value > 0) |
| 986 | touchpad_led_on(); |
| 987 | else |
| 988 | touchpad_led_off(); |
| 989 | } |
| 990 | |
| 991 | static struct led_classdev touchpad_led = { |
| 992 | .name = "dell-laptop::touchpad", |
| 993 | .brightness_set = touchpad_led_set, |
AceLan Kao | 2d5de9e | 2012-01-17 16:18:06 +0800 | [diff] [blame] | 994 | .flags = LED_CORE_SUSPENDRESUME, |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 995 | }; |
| 996 | |
Mathias Krause | 681480c | 2014-07-16 19:43:09 +0200 | [diff] [blame] | 997 | static int __init touchpad_led_init(struct device *dev) |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 998 | { |
| 999 | return led_classdev_register(dev, &touchpad_led); |
| 1000 | } |
| 1001 | |
| 1002 | static void touchpad_led_exit(void) |
| 1003 | { |
| 1004 | led_classdev_unregister(&touchpad_led); |
| 1005 | } |
| 1006 | |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 1007 | /* |
| 1008 | * Derived from information in smbios-keyboard-ctl: |
| 1009 | * |
| 1010 | * cbClass 4 |
| 1011 | * cbSelect 11 |
| 1012 | * Keyboard illumination |
| 1013 | * cbArg1 determines the function to be performed |
| 1014 | * |
| 1015 | * cbArg1 0x0 = Get Feature Information |
| 1016 | * cbRES1 Standard return codes (0, -1, -2) |
| 1017 | * cbRES2, word0 Bitmap of user-selectable modes |
| 1018 | * bit 0 Always off (All systems) |
| 1019 | * bit 1 Always on (Travis ATG, Siberia) |
| 1020 | * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG) |
| 1021 | * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off |
| 1022 | * bit 4 Auto: Input-activity-based On; input-activity based Off |
| 1023 | * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off |
| 1024 | * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off |
| 1025 | * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off |
| 1026 | * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off |
| 1027 | * bits 9-15 Reserved for future use |
| 1028 | * cbRES2, byte2 Reserved for future use |
| 1029 | * cbRES2, byte3 Keyboard illumination type |
| 1030 | * 0 Reserved |
| 1031 | * 1 Tasklight |
| 1032 | * 2 Backlight |
| 1033 | * 3-255 Reserved for future use |
| 1034 | * cbRES3, byte0 Supported auto keyboard illumination trigger bitmap. |
| 1035 | * bit 0 Any keystroke |
| 1036 | * bit 1 Touchpad activity |
| 1037 | * bit 2 Pointing stick |
| 1038 | * bit 3 Any mouse |
| 1039 | * bits 4-7 Reserved for future use |
| 1040 | * cbRES3, byte1 Supported timeout unit bitmap |
| 1041 | * bit 0 Seconds |
| 1042 | * bit 1 Minutes |
| 1043 | * bit 2 Hours |
| 1044 | * bit 3 Days |
| 1045 | * bits 4-7 Reserved for future use |
| 1046 | * cbRES3, byte2 Number of keyboard light brightness levels |
| 1047 | * cbRES4, byte0 Maximum acceptable seconds value (0 if seconds not supported). |
| 1048 | * cbRES4, byte1 Maximum acceptable minutes value (0 if minutes not supported). |
| 1049 | * cbRES4, byte2 Maximum acceptable hours value (0 if hours not supported). |
| 1050 | * cbRES4, byte3 Maximum acceptable days value (0 if days not supported) |
| 1051 | * |
| 1052 | * cbArg1 0x1 = Get Current State |
| 1053 | * cbRES1 Standard return codes (0, -1, -2) |
| 1054 | * cbRES2, word0 Bitmap of current mode state |
| 1055 | * bit 0 Always off (All systems) |
| 1056 | * bit 1 Always on (Travis ATG, Siberia) |
| 1057 | * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG) |
| 1058 | * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off |
| 1059 | * bit 4 Auto: Input-activity-based On; input-activity based Off |
| 1060 | * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off |
| 1061 | * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off |
| 1062 | * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off |
| 1063 | * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off |
| 1064 | * bits 9-15 Reserved for future use |
| 1065 | * Note: Only One bit can be set |
| 1066 | * cbRES2, byte2 Currently active auto keyboard illumination triggers. |
| 1067 | * bit 0 Any keystroke |
| 1068 | * bit 1 Touchpad activity |
| 1069 | * bit 2 Pointing stick |
| 1070 | * bit 3 Any mouse |
| 1071 | * bits 4-7 Reserved for future use |
| 1072 | * cbRES2, byte3 Current Timeout |
| 1073 | * bits 7:6 Timeout units indicator: |
| 1074 | * 00b Seconds |
| 1075 | * 01b Minutes |
| 1076 | * 10b Hours |
| 1077 | * 11b Days |
| 1078 | * bits 5:0 Timeout value (0-63) in sec/min/hr/day |
| 1079 | * NOTE: A value of 0 means always on (no timeout) if any bits of RES3 byte |
| 1080 | * are set upon return from the [Get feature information] call. |
| 1081 | * cbRES3, byte0 Current setting of ALS value that turns the light on or off. |
| 1082 | * cbRES3, byte1 Current ALS reading |
| 1083 | * cbRES3, byte2 Current keyboard light level. |
| 1084 | * |
| 1085 | * cbArg1 0x2 = Set New State |
| 1086 | * cbRES1 Standard return codes (0, -1, -2) |
| 1087 | * cbArg2, word0 Bitmap of current mode state |
| 1088 | * bit 0 Always off (All systems) |
| 1089 | * bit 1 Always on (Travis ATG, Siberia) |
| 1090 | * bit 2 Auto: ALS-based On; ALS-based Off (Travis ATG) |
| 1091 | * bit 3 Auto: ALS- and input-activity-based On; input-activity based Off |
| 1092 | * bit 4 Auto: Input-activity-based On; input-activity based Off |
| 1093 | * bit 5 Auto: Input-activity-based On (illumination level 25%); input-activity based Off |
| 1094 | * bit 6 Auto: Input-activity-based On (illumination level 50%); input-activity based Off |
| 1095 | * bit 7 Auto: Input-activity-based On (illumination level 75%); input-activity based Off |
| 1096 | * bit 8 Auto: Input-activity-based On (illumination level 100%); input-activity based Off |
| 1097 | * bits 9-15 Reserved for future use |
| 1098 | * Note: Only One bit can be set |
| 1099 | * cbArg2, byte2 Desired auto keyboard illumination triggers. Must remain inactive to allow |
| 1100 | * keyboard to turn off automatically. |
| 1101 | * bit 0 Any keystroke |
| 1102 | * bit 1 Touchpad activity |
| 1103 | * bit 2 Pointing stick |
| 1104 | * bit 3 Any mouse |
| 1105 | * bits 4-7 Reserved for future use |
| 1106 | * cbArg2, byte3 Desired Timeout |
| 1107 | * bits 7:6 Timeout units indicator: |
| 1108 | * 00b Seconds |
| 1109 | * 01b Minutes |
| 1110 | * 10b Hours |
| 1111 | * 11b Days |
| 1112 | * bits 5:0 Timeout value (0-63) in sec/min/hr/day |
| 1113 | * cbArg3, byte0 Desired setting of ALS value that turns the light on or off. |
| 1114 | * cbArg3, byte2 Desired keyboard light level. |
| 1115 | */ |
| 1116 | |
| 1117 | |
| 1118 | enum kbd_timeout_unit { |
| 1119 | KBD_TIMEOUT_SECONDS = 0, |
| 1120 | KBD_TIMEOUT_MINUTES, |
| 1121 | KBD_TIMEOUT_HOURS, |
| 1122 | KBD_TIMEOUT_DAYS, |
| 1123 | }; |
| 1124 | |
| 1125 | enum kbd_mode_bit { |
| 1126 | KBD_MODE_BIT_OFF = 0, |
| 1127 | KBD_MODE_BIT_ON, |
| 1128 | KBD_MODE_BIT_ALS, |
| 1129 | KBD_MODE_BIT_TRIGGER_ALS, |
| 1130 | KBD_MODE_BIT_TRIGGER, |
| 1131 | KBD_MODE_BIT_TRIGGER_25, |
| 1132 | KBD_MODE_BIT_TRIGGER_50, |
| 1133 | KBD_MODE_BIT_TRIGGER_75, |
| 1134 | KBD_MODE_BIT_TRIGGER_100, |
| 1135 | }; |
| 1136 | |
| 1137 | #define kbd_is_als_mode_bit(bit) \ |
| 1138 | ((bit) == KBD_MODE_BIT_ALS || (bit) == KBD_MODE_BIT_TRIGGER_ALS) |
| 1139 | #define kbd_is_trigger_mode_bit(bit) \ |
| 1140 | ((bit) >= KBD_MODE_BIT_TRIGGER_ALS && (bit) <= KBD_MODE_BIT_TRIGGER_100) |
| 1141 | #define kbd_is_level_mode_bit(bit) \ |
| 1142 | ((bit) >= KBD_MODE_BIT_TRIGGER_25 && (bit) <= KBD_MODE_BIT_TRIGGER_100) |
| 1143 | |
| 1144 | struct kbd_info { |
| 1145 | u16 modes; |
| 1146 | u8 type; |
| 1147 | u8 triggers; |
| 1148 | u8 levels; |
| 1149 | u8 seconds; |
| 1150 | u8 minutes; |
| 1151 | u8 hours; |
| 1152 | u8 days; |
| 1153 | }; |
| 1154 | |
| 1155 | struct kbd_state { |
| 1156 | u8 mode_bit; |
| 1157 | u8 triggers; |
| 1158 | u8 timeout_value; |
| 1159 | u8 timeout_unit; |
| 1160 | u8 als_setting; |
| 1161 | u8 als_value; |
| 1162 | u8 level; |
| 1163 | }; |
| 1164 | |
| 1165 | static const int kbd_tokens[] = { |
| 1166 | KBD_LED_OFF_TOKEN, |
| 1167 | KBD_LED_AUTO_25_TOKEN, |
| 1168 | KBD_LED_AUTO_50_TOKEN, |
| 1169 | KBD_LED_AUTO_75_TOKEN, |
| 1170 | KBD_LED_AUTO_100_TOKEN, |
| 1171 | KBD_LED_ON_TOKEN, |
| 1172 | }; |
| 1173 | |
| 1174 | static u16 kbd_token_bits; |
| 1175 | |
| 1176 | static struct kbd_info kbd_info; |
| 1177 | static bool kbd_als_supported; |
| 1178 | static bool kbd_triggers_supported; |
| 1179 | |
| 1180 | static u8 kbd_mode_levels[16]; |
| 1181 | static int kbd_mode_levels_count; |
| 1182 | |
| 1183 | static u8 kbd_previous_level; |
| 1184 | static u8 kbd_previous_mode_bit; |
| 1185 | |
| 1186 | static bool kbd_led_present; |
| 1187 | |
| 1188 | /* |
| 1189 | * NOTE: there are three ways to set the keyboard backlight level. |
| 1190 | * First, via kbd_state.mode_bit (assigning KBD_MODE_BIT_TRIGGER_* value). |
| 1191 | * Second, via kbd_state.level (assigning numerical value <= kbd_info.levels). |
| 1192 | * Third, via SMBIOS tokens (KBD_LED_* in kbd_tokens) |
| 1193 | * |
| 1194 | * There are laptops which support only one of these methods. If we want to |
| 1195 | * support as many machines as possible we need to implement all three methods. |
| 1196 | * The first two methods use the kbd_state structure. The third uses SMBIOS |
| 1197 | * tokens. If kbd_info.levels == 0, the machine does not support setting the |
| 1198 | * keyboard backlight level via kbd_state.level. |
| 1199 | */ |
| 1200 | |
| 1201 | static int kbd_get_info(struct kbd_info *info) |
| 1202 | { |
| 1203 | u8 units; |
| 1204 | int ret; |
| 1205 | |
| 1206 | get_buffer(); |
| 1207 | |
| 1208 | buffer->input[0] = 0x0; |
| 1209 | dell_send_request(buffer, 4, 11); |
| 1210 | ret = buffer->output[0]; |
| 1211 | |
| 1212 | if (ret) { |
| 1213 | ret = dell_smi_error(ret); |
| 1214 | goto out; |
| 1215 | } |
| 1216 | |
| 1217 | info->modes = buffer->output[1] & 0xFFFF; |
| 1218 | info->type = (buffer->output[1] >> 24) & 0xFF; |
| 1219 | info->triggers = buffer->output[2] & 0xFF; |
| 1220 | units = (buffer->output[2] >> 8) & 0xFF; |
| 1221 | info->levels = (buffer->output[2] >> 16) & 0xFF; |
| 1222 | |
| 1223 | if (units & BIT(0)) |
| 1224 | info->seconds = (buffer->output[3] >> 0) & 0xFF; |
| 1225 | if (units & BIT(1)) |
| 1226 | info->minutes = (buffer->output[3] >> 8) & 0xFF; |
| 1227 | if (units & BIT(2)) |
| 1228 | info->hours = (buffer->output[3] >> 16) & 0xFF; |
| 1229 | if (units & BIT(3)) |
| 1230 | info->days = (buffer->output[3] >> 24) & 0xFF; |
| 1231 | |
| 1232 | out: |
| 1233 | release_buffer(); |
| 1234 | return ret; |
| 1235 | } |
| 1236 | |
| 1237 | static unsigned int kbd_get_max_level(void) |
| 1238 | { |
| 1239 | if (kbd_info.levels != 0) |
| 1240 | return kbd_info.levels; |
| 1241 | if (kbd_mode_levels_count > 0) |
| 1242 | return kbd_mode_levels_count - 1; |
| 1243 | return 0; |
| 1244 | } |
| 1245 | |
| 1246 | static int kbd_get_level(struct kbd_state *state) |
| 1247 | { |
| 1248 | int i; |
| 1249 | |
| 1250 | if (kbd_info.levels != 0) |
| 1251 | return state->level; |
| 1252 | |
| 1253 | if (kbd_mode_levels_count > 0) { |
| 1254 | for (i = 0; i < kbd_mode_levels_count; ++i) |
| 1255 | if (kbd_mode_levels[i] == state->mode_bit) |
| 1256 | return i; |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
| 1260 | return -EINVAL; |
| 1261 | } |
| 1262 | |
| 1263 | static int kbd_set_level(struct kbd_state *state, u8 level) |
| 1264 | { |
| 1265 | if (kbd_info.levels != 0) { |
| 1266 | if (level != 0) |
| 1267 | kbd_previous_level = level; |
| 1268 | if (state->level == level) |
| 1269 | return 0; |
| 1270 | state->level = level; |
| 1271 | if (level != 0 && state->mode_bit == KBD_MODE_BIT_OFF) |
| 1272 | state->mode_bit = kbd_previous_mode_bit; |
| 1273 | else if (level == 0 && state->mode_bit != KBD_MODE_BIT_OFF) { |
| 1274 | kbd_previous_mode_bit = state->mode_bit; |
| 1275 | state->mode_bit = KBD_MODE_BIT_OFF; |
| 1276 | } |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
| 1280 | if (kbd_mode_levels_count > 0 && level < kbd_mode_levels_count) { |
| 1281 | if (level != 0) |
| 1282 | kbd_previous_level = level; |
| 1283 | state->mode_bit = kbd_mode_levels[level]; |
| 1284 | return 0; |
| 1285 | } |
| 1286 | |
| 1287 | return -EINVAL; |
| 1288 | } |
| 1289 | |
| 1290 | static int kbd_get_state(struct kbd_state *state) |
| 1291 | { |
| 1292 | int ret; |
| 1293 | |
| 1294 | get_buffer(); |
| 1295 | |
| 1296 | buffer->input[0] = 0x1; |
| 1297 | dell_send_request(buffer, 4, 11); |
| 1298 | ret = buffer->output[0]; |
| 1299 | |
| 1300 | if (ret) { |
| 1301 | ret = dell_smi_error(ret); |
| 1302 | goto out; |
| 1303 | } |
| 1304 | |
| 1305 | state->mode_bit = ffs(buffer->output[1] & 0xFFFF); |
| 1306 | if (state->mode_bit != 0) |
| 1307 | state->mode_bit--; |
| 1308 | |
| 1309 | state->triggers = (buffer->output[1] >> 16) & 0xFF; |
| 1310 | state->timeout_value = (buffer->output[1] >> 24) & 0x3F; |
| 1311 | state->timeout_unit = (buffer->output[1] >> 30) & 0x3; |
| 1312 | state->als_setting = buffer->output[2] & 0xFF; |
| 1313 | state->als_value = (buffer->output[2] >> 8) & 0xFF; |
| 1314 | state->level = (buffer->output[2] >> 16) & 0xFF; |
| 1315 | |
| 1316 | out: |
| 1317 | release_buffer(); |
| 1318 | return ret; |
| 1319 | } |
| 1320 | |
| 1321 | static int kbd_set_state(struct kbd_state *state) |
| 1322 | { |
| 1323 | int ret; |
| 1324 | |
| 1325 | get_buffer(); |
| 1326 | buffer->input[0] = 0x2; |
| 1327 | buffer->input[1] = BIT(state->mode_bit) & 0xFFFF; |
| 1328 | buffer->input[1] |= (state->triggers & 0xFF) << 16; |
| 1329 | buffer->input[1] |= (state->timeout_value & 0x3F) << 24; |
| 1330 | buffer->input[1] |= (state->timeout_unit & 0x3) << 30; |
| 1331 | buffer->input[2] = state->als_setting & 0xFF; |
| 1332 | buffer->input[2] |= (state->level & 0xFF) << 16; |
| 1333 | dell_send_request(buffer, 4, 11); |
| 1334 | ret = buffer->output[0]; |
| 1335 | release_buffer(); |
| 1336 | |
| 1337 | return dell_smi_error(ret); |
| 1338 | } |
| 1339 | |
| 1340 | static int kbd_set_state_safe(struct kbd_state *state, struct kbd_state *old) |
| 1341 | { |
| 1342 | int ret; |
| 1343 | |
| 1344 | ret = kbd_set_state(state); |
| 1345 | if (ret == 0) |
| 1346 | return 0; |
| 1347 | |
| 1348 | /* |
| 1349 | * When setting the new state fails,try to restore the previous one. |
| 1350 | * This is needed on some machines where BIOS sets a default state when |
| 1351 | * setting a new state fails. This default state could be all off. |
| 1352 | */ |
| 1353 | |
| 1354 | if (kbd_set_state(old)) |
| 1355 | pr_err("Setting old previous keyboard state failed\n"); |
| 1356 | |
| 1357 | return ret; |
| 1358 | } |
| 1359 | |
| 1360 | static int kbd_set_token_bit(u8 bit) |
| 1361 | { |
| 1362 | int id; |
| 1363 | int ret; |
| 1364 | |
| 1365 | if (bit >= ARRAY_SIZE(kbd_tokens)) |
| 1366 | return -EINVAL; |
| 1367 | |
| 1368 | id = find_token_id(kbd_tokens[bit]); |
| 1369 | if (id == -1) |
| 1370 | return -EINVAL; |
| 1371 | |
| 1372 | get_buffer(); |
| 1373 | buffer->input[0] = da_tokens[id].location; |
| 1374 | buffer->input[1] = da_tokens[id].value; |
| 1375 | dell_send_request(buffer, 1, 0); |
| 1376 | ret = buffer->output[0]; |
| 1377 | release_buffer(); |
| 1378 | |
| 1379 | return dell_smi_error(ret); |
| 1380 | } |
| 1381 | |
| 1382 | static int kbd_get_token_bit(u8 bit) |
| 1383 | { |
| 1384 | int id; |
| 1385 | int ret; |
| 1386 | int val; |
| 1387 | |
| 1388 | if (bit >= ARRAY_SIZE(kbd_tokens)) |
| 1389 | return -EINVAL; |
| 1390 | |
| 1391 | id = find_token_id(kbd_tokens[bit]); |
| 1392 | if (id == -1) |
| 1393 | return -EINVAL; |
| 1394 | |
| 1395 | get_buffer(); |
| 1396 | buffer->input[0] = da_tokens[id].location; |
| 1397 | dell_send_request(buffer, 0, 0); |
| 1398 | ret = buffer->output[0]; |
| 1399 | val = buffer->output[1]; |
| 1400 | release_buffer(); |
| 1401 | |
| 1402 | if (ret) |
| 1403 | return dell_smi_error(ret); |
| 1404 | |
| 1405 | return (val == da_tokens[id].value); |
| 1406 | } |
| 1407 | |
| 1408 | static int kbd_get_first_active_token_bit(void) |
| 1409 | { |
| 1410 | int i; |
| 1411 | int ret; |
| 1412 | |
| 1413 | for (i = 0; i < ARRAY_SIZE(kbd_tokens); ++i) { |
| 1414 | ret = kbd_get_token_bit(i); |
| 1415 | if (ret == 1) |
| 1416 | return i; |
| 1417 | } |
| 1418 | |
| 1419 | return ret; |
| 1420 | } |
| 1421 | |
| 1422 | static int kbd_get_valid_token_counts(void) |
| 1423 | { |
| 1424 | return hweight16(kbd_token_bits); |
| 1425 | } |
| 1426 | |
| 1427 | static inline int kbd_init_info(void) |
| 1428 | { |
| 1429 | struct kbd_state state; |
| 1430 | int ret; |
| 1431 | int i; |
| 1432 | |
| 1433 | ret = kbd_get_info(&kbd_info); |
| 1434 | if (ret) |
| 1435 | return ret; |
| 1436 | |
| 1437 | kbd_get_state(&state); |
| 1438 | |
| 1439 | /* NOTE: timeout value is stored in 6 bits so max value is 63 */ |
| 1440 | if (kbd_info.seconds > 63) |
| 1441 | kbd_info.seconds = 63; |
| 1442 | if (kbd_info.minutes > 63) |
| 1443 | kbd_info.minutes = 63; |
| 1444 | if (kbd_info.hours > 63) |
| 1445 | kbd_info.hours = 63; |
| 1446 | if (kbd_info.days > 63) |
| 1447 | kbd_info.days = 63; |
| 1448 | |
| 1449 | /* NOTE: On tested machines ON mode did not work and caused |
| 1450 | * problems (turned backlight off) so do not use it |
| 1451 | */ |
| 1452 | kbd_info.modes &= ~BIT(KBD_MODE_BIT_ON); |
| 1453 | |
| 1454 | kbd_previous_level = kbd_get_level(&state); |
| 1455 | kbd_previous_mode_bit = state.mode_bit; |
| 1456 | |
| 1457 | if (kbd_previous_level == 0 && kbd_get_max_level() != 0) |
| 1458 | kbd_previous_level = 1; |
| 1459 | |
| 1460 | if (kbd_previous_mode_bit == KBD_MODE_BIT_OFF) { |
| 1461 | kbd_previous_mode_bit = |
| 1462 | ffs(kbd_info.modes & ~BIT(KBD_MODE_BIT_OFF)); |
| 1463 | if (kbd_previous_mode_bit != 0) |
| 1464 | kbd_previous_mode_bit--; |
| 1465 | } |
| 1466 | |
| 1467 | if (kbd_info.modes & (BIT(KBD_MODE_BIT_ALS) | |
| 1468 | BIT(KBD_MODE_BIT_TRIGGER_ALS))) |
| 1469 | kbd_als_supported = true; |
| 1470 | |
| 1471 | if (kbd_info.modes & ( |
| 1472 | BIT(KBD_MODE_BIT_TRIGGER_ALS) | BIT(KBD_MODE_BIT_TRIGGER) | |
| 1473 | BIT(KBD_MODE_BIT_TRIGGER_25) | BIT(KBD_MODE_BIT_TRIGGER_50) | |
| 1474 | BIT(KBD_MODE_BIT_TRIGGER_75) | BIT(KBD_MODE_BIT_TRIGGER_100) |
| 1475 | )) |
| 1476 | kbd_triggers_supported = true; |
| 1477 | |
| 1478 | /* kbd_mode_levels[0] is reserved, see below */ |
| 1479 | for (i = 0; i < 16; ++i) |
| 1480 | if (kbd_is_level_mode_bit(i) && (BIT(i) & kbd_info.modes)) |
| 1481 | kbd_mode_levels[1 + kbd_mode_levels_count++] = i; |
| 1482 | |
| 1483 | /* |
| 1484 | * Find the first supported mode and assign to kbd_mode_levels[0]. |
| 1485 | * This should be 0 (off), but we cannot depend on the BIOS to |
| 1486 | * support 0. |
| 1487 | */ |
| 1488 | if (kbd_mode_levels_count > 0) { |
| 1489 | for (i = 0; i < 16; ++i) { |
| 1490 | if (BIT(i) & kbd_info.modes) { |
| 1491 | kbd_mode_levels[0] = i; |
| 1492 | break; |
| 1493 | } |
| 1494 | } |
| 1495 | kbd_mode_levels_count++; |
| 1496 | } |
| 1497 | |
| 1498 | return 0; |
| 1499 | |
| 1500 | } |
| 1501 | |
| 1502 | static inline void kbd_init_tokens(void) |
| 1503 | { |
| 1504 | int i; |
| 1505 | |
| 1506 | for (i = 0; i < ARRAY_SIZE(kbd_tokens); ++i) |
| 1507 | if (find_token_id(kbd_tokens[i]) != -1) |
| 1508 | kbd_token_bits |= BIT(i); |
| 1509 | } |
| 1510 | |
| 1511 | static void kbd_init(void) |
| 1512 | { |
| 1513 | int ret; |
| 1514 | |
| 1515 | ret = kbd_init_info(); |
| 1516 | kbd_init_tokens(); |
| 1517 | |
| 1518 | if (kbd_token_bits != 0 || ret == 0) |
| 1519 | kbd_led_present = true; |
| 1520 | } |
| 1521 | |
| 1522 | static ssize_t kbd_led_timeout_store(struct device *dev, |
| 1523 | struct device_attribute *attr, |
| 1524 | const char *buf, size_t count) |
| 1525 | { |
| 1526 | struct kbd_state new_state; |
| 1527 | struct kbd_state state; |
| 1528 | bool convert; |
| 1529 | int value; |
| 1530 | int ret; |
| 1531 | char ch; |
| 1532 | u8 unit; |
| 1533 | int i; |
| 1534 | |
| 1535 | ret = sscanf(buf, "%d %c", &value, &ch); |
| 1536 | if (ret < 1) |
| 1537 | return -EINVAL; |
| 1538 | else if (ret == 1) |
| 1539 | ch = 's'; |
| 1540 | |
| 1541 | if (value < 0) |
| 1542 | return -EINVAL; |
| 1543 | |
| 1544 | convert = false; |
| 1545 | |
| 1546 | switch (ch) { |
| 1547 | case 's': |
| 1548 | if (value > kbd_info.seconds) |
| 1549 | convert = true; |
| 1550 | unit = KBD_TIMEOUT_SECONDS; |
| 1551 | break; |
| 1552 | case 'm': |
| 1553 | if (value > kbd_info.minutes) |
| 1554 | convert = true; |
| 1555 | unit = KBD_TIMEOUT_MINUTES; |
| 1556 | break; |
| 1557 | case 'h': |
| 1558 | if (value > kbd_info.hours) |
| 1559 | convert = true; |
| 1560 | unit = KBD_TIMEOUT_HOURS; |
| 1561 | break; |
| 1562 | case 'd': |
| 1563 | if (value > kbd_info.days) |
| 1564 | convert = true; |
| 1565 | unit = KBD_TIMEOUT_DAYS; |
| 1566 | break; |
| 1567 | default: |
| 1568 | return -EINVAL; |
| 1569 | } |
| 1570 | |
| 1571 | if (quirks && quirks->needs_kbd_timeouts) |
| 1572 | convert = true; |
| 1573 | |
| 1574 | if (convert) { |
| 1575 | /* Convert value from current units to seconds */ |
| 1576 | switch (unit) { |
| 1577 | case KBD_TIMEOUT_DAYS: |
| 1578 | value *= 24; |
| 1579 | case KBD_TIMEOUT_HOURS: |
| 1580 | value *= 60; |
| 1581 | case KBD_TIMEOUT_MINUTES: |
| 1582 | value *= 60; |
| 1583 | unit = KBD_TIMEOUT_SECONDS; |
| 1584 | } |
| 1585 | |
| 1586 | if (quirks && quirks->needs_kbd_timeouts) { |
| 1587 | for (i = 0; quirks->kbd_timeouts[i] != -1; i++) { |
| 1588 | if (value <= quirks->kbd_timeouts[i]) { |
| 1589 | value = quirks->kbd_timeouts[i]; |
| 1590 | break; |
| 1591 | } |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | if (value <= kbd_info.seconds && kbd_info.seconds) { |
| 1596 | unit = KBD_TIMEOUT_SECONDS; |
| 1597 | } else if (value / 60 <= kbd_info.minutes && kbd_info.minutes) { |
| 1598 | value /= 60; |
| 1599 | unit = KBD_TIMEOUT_MINUTES; |
| 1600 | } else if (value / (60 * 60) <= kbd_info.hours && kbd_info.hours) { |
| 1601 | value /= (60 * 60); |
| 1602 | unit = KBD_TIMEOUT_HOURS; |
| 1603 | } else if (value / (60 * 60 * 24) <= kbd_info.days && kbd_info.days) { |
| 1604 | value /= (60 * 60 * 24); |
| 1605 | unit = KBD_TIMEOUT_DAYS; |
| 1606 | } else { |
| 1607 | return -EINVAL; |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | ret = kbd_get_state(&state); |
| 1612 | if (ret) |
| 1613 | return ret; |
| 1614 | |
| 1615 | new_state = state; |
| 1616 | new_state.timeout_value = value; |
| 1617 | new_state.timeout_unit = unit; |
| 1618 | |
| 1619 | ret = kbd_set_state_safe(&new_state, &state); |
| 1620 | if (ret) |
| 1621 | return ret; |
| 1622 | |
| 1623 | return count; |
| 1624 | } |
| 1625 | |
| 1626 | static ssize_t kbd_led_timeout_show(struct device *dev, |
| 1627 | struct device_attribute *attr, char *buf) |
| 1628 | { |
| 1629 | struct kbd_state state; |
| 1630 | int ret; |
| 1631 | int len; |
| 1632 | |
| 1633 | ret = kbd_get_state(&state); |
| 1634 | if (ret) |
| 1635 | return ret; |
| 1636 | |
| 1637 | len = sprintf(buf, "%d", state.timeout_value); |
| 1638 | |
| 1639 | switch (state.timeout_unit) { |
| 1640 | case KBD_TIMEOUT_SECONDS: |
| 1641 | return len + sprintf(buf+len, "s\n"); |
| 1642 | case KBD_TIMEOUT_MINUTES: |
| 1643 | return len + sprintf(buf+len, "m\n"); |
| 1644 | case KBD_TIMEOUT_HOURS: |
| 1645 | return len + sprintf(buf+len, "h\n"); |
| 1646 | case KBD_TIMEOUT_DAYS: |
| 1647 | return len + sprintf(buf+len, "d\n"); |
| 1648 | default: |
| 1649 | return -EINVAL; |
| 1650 | } |
| 1651 | |
| 1652 | return len; |
| 1653 | } |
| 1654 | |
| 1655 | static DEVICE_ATTR(stop_timeout, S_IRUGO | S_IWUSR, |
| 1656 | kbd_led_timeout_show, kbd_led_timeout_store); |
| 1657 | |
| 1658 | static const char * const kbd_led_triggers[] = { |
| 1659 | "keyboard", |
| 1660 | "touchpad", |
| 1661 | /*"trackstick"*/ NULL, /* NOTE: trackstick is just alias for touchpad */ |
| 1662 | "mouse", |
| 1663 | }; |
| 1664 | |
| 1665 | static ssize_t kbd_led_triggers_store(struct device *dev, |
| 1666 | struct device_attribute *attr, |
| 1667 | const char *buf, size_t count) |
| 1668 | { |
| 1669 | struct kbd_state new_state; |
| 1670 | struct kbd_state state; |
| 1671 | bool triggers_enabled = false; |
| 1672 | int trigger_bit = -1; |
| 1673 | char trigger[21]; |
| 1674 | int i, ret; |
| 1675 | |
| 1676 | ret = sscanf(buf, "%20s", trigger); |
| 1677 | if (ret != 1) |
| 1678 | return -EINVAL; |
| 1679 | |
| 1680 | if (trigger[0] != '+' && trigger[0] != '-') |
| 1681 | return -EINVAL; |
| 1682 | |
| 1683 | ret = kbd_get_state(&state); |
| 1684 | if (ret) |
| 1685 | return ret; |
| 1686 | |
| 1687 | if (kbd_triggers_supported) |
| 1688 | triggers_enabled = kbd_is_trigger_mode_bit(state.mode_bit); |
| 1689 | |
| 1690 | if (kbd_triggers_supported) { |
| 1691 | for (i = 0; i < ARRAY_SIZE(kbd_led_triggers); ++i) { |
| 1692 | if (!(kbd_info.triggers & BIT(i))) |
| 1693 | continue; |
| 1694 | if (!kbd_led_triggers[i]) |
| 1695 | continue; |
| 1696 | if (strcmp(trigger+1, kbd_led_triggers[i]) != 0) |
| 1697 | continue; |
| 1698 | if (trigger[0] == '+' && |
| 1699 | triggers_enabled && (state.triggers & BIT(i))) |
| 1700 | return count; |
| 1701 | if (trigger[0] == '-' && |
| 1702 | (!triggers_enabled || !(state.triggers & BIT(i)))) |
| 1703 | return count; |
| 1704 | trigger_bit = i; |
| 1705 | break; |
| 1706 | } |
| 1707 | } |
| 1708 | |
| 1709 | if (trigger_bit != -1) { |
| 1710 | new_state = state; |
| 1711 | if (trigger[0] == '+') |
| 1712 | new_state.triggers |= BIT(trigger_bit); |
| 1713 | else { |
| 1714 | new_state.triggers &= ~BIT(trigger_bit); |
| 1715 | /* NOTE: trackstick bit (2) must be disabled when |
| 1716 | * disabling touchpad bit (1), otherwise touchpad |
| 1717 | * bit (1) will not be disabled */ |
| 1718 | if (trigger_bit == 1) |
| 1719 | new_state.triggers &= ~BIT(2); |
| 1720 | } |
| 1721 | if ((kbd_info.triggers & new_state.triggers) != |
| 1722 | new_state.triggers) |
| 1723 | return -EINVAL; |
| 1724 | if (new_state.triggers && !triggers_enabled) { |
| 1725 | new_state.mode_bit = KBD_MODE_BIT_TRIGGER; |
| 1726 | kbd_set_level(&new_state, kbd_previous_level); |
| 1727 | } else if (new_state.triggers == 0) { |
| 1728 | kbd_set_level(&new_state, 0); |
| 1729 | } |
| 1730 | if (!(kbd_info.modes & BIT(new_state.mode_bit))) |
| 1731 | return -EINVAL; |
| 1732 | ret = kbd_set_state_safe(&new_state, &state); |
| 1733 | if (ret) |
| 1734 | return ret; |
| 1735 | if (new_state.mode_bit != KBD_MODE_BIT_OFF) |
| 1736 | kbd_previous_mode_bit = new_state.mode_bit; |
| 1737 | return count; |
| 1738 | } |
| 1739 | |
| 1740 | return -EINVAL; |
| 1741 | } |
| 1742 | |
| 1743 | static ssize_t kbd_led_triggers_show(struct device *dev, |
| 1744 | struct device_attribute *attr, char *buf) |
| 1745 | { |
| 1746 | struct kbd_state state; |
| 1747 | bool triggers_enabled; |
| 1748 | int level, i, ret; |
| 1749 | int len = 0; |
| 1750 | |
| 1751 | ret = kbd_get_state(&state); |
| 1752 | if (ret) |
| 1753 | return ret; |
| 1754 | |
| 1755 | len = 0; |
| 1756 | |
| 1757 | if (kbd_triggers_supported) { |
| 1758 | triggers_enabled = kbd_is_trigger_mode_bit(state.mode_bit); |
| 1759 | level = kbd_get_level(&state); |
| 1760 | for (i = 0; i < ARRAY_SIZE(kbd_led_triggers); ++i) { |
| 1761 | if (!(kbd_info.triggers & BIT(i))) |
| 1762 | continue; |
| 1763 | if (!kbd_led_triggers[i]) |
| 1764 | continue; |
| 1765 | if ((triggers_enabled || level <= 0) && |
| 1766 | (state.triggers & BIT(i))) |
| 1767 | buf[len++] = '+'; |
| 1768 | else |
| 1769 | buf[len++] = '-'; |
| 1770 | len += sprintf(buf+len, "%s ", kbd_led_triggers[i]); |
| 1771 | } |
| 1772 | } |
| 1773 | |
| 1774 | if (len) |
| 1775 | buf[len - 1] = '\n'; |
| 1776 | |
| 1777 | return len; |
| 1778 | } |
| 1779 | |
| 1780 | static DEVICE_ATTR(start_triggers, S_IRUGO | S_IWUSR, |
| 1781 | kbd_led_triggers_show, kbd_led_triggers_store); |
| 1782 | |
| 1783 | static ssize_t kbd_led_als_enabled_store(struct device *dev, |
| 1784 | struct device_attribute *attr, |
| 1785 | const char *buf, size_t count) |
| 1786 | { |
| 1787 | struct kbd_state new_state; |
| 1788 | struct kbd_state state; |
| 1789 | bool triggers_enabled = false; |
| 1790 | int enable; |
| 1791 | int ret; |
| 1792 | |
| 1793 | ret = kstrtoint(buf, 0, &enable); |
| 1794 | if (ret) |
| 1795 | return ret; |
| 1796 | |
| 1797 | ret = kbd_get_state(&state); |
| 1798 | if (ret) |
| 1799 | return ret; |
| 1800 | |
| 1801 | if (enable == kbd_is_als_mode_bit(state.mode_bit)) |
| 1802 | return count; |
| 1803 | |
| 1804 | new_state = state; |
| 1805 | |
| 1806 | if (kbd_triggers_supported) |
| 1807 | triggers_enabled = kbd_is_trigger_mode_bit(state.mode_bit); |
| 1808 | |
| 1809 | if (enable) { |
| 1810 | if (triggers_enabled) |
| 1811 | new_state.mode_bit = KBD_MODE_BIT_TRIGGER_ALS; |
| 1812 | else |
| 1813 | new_state.mode_bit = KBD_MODE_BIT_ALS; |
| 1814 | } else { |
| 1815 | if (triggers_enabled) { |
| 1816 | new_state.mode_bit = KBD_MODE_BIT_TRIGGER; |
| 1817 | kbd_set_level(&new_state, kbd_previous_level); |
| 1818 | } else { |
| 1819 | new_state.mode_bit = KBD_MODE_BIT_ON; |
| 1820 | } |
| 1821 | } |
| 1822 | if (!(kbd_info.modes & BIT(new_state.mode_bit))) |
| 1823 | return -EINVAL; |
| 1824 | |
| 1825 | ret = kbd_set_state_safe(&new_state, &state); |
| 1826 | if (ret) |
| 1827 | return ret; |
| 1828 | kbd_previous_mode_bit = new_state.mode_bit; |
| 1829 | |
| 1830 | return count; |
| 1831 | } |
| 1832 | |
| 1833 | static ssize_t kbd_led_als_enabled_show(struct device *dev, |
| 1834 | struct device_attribute *attr, |
| 1835 | char *buf) |
| 1836 | { |
| 1837 | struct kbd_state state; |
| 1838 | bool enabled = false; |
| 1839 | int ret; |
| 1840 | |
| 1841 | ret = kbd_get_state(&state); |
| 1842 | if (ret) |
| 1843 | return ret; |
| 1844 | enabled = kbd_is_als_mode_bit(state.mode_bit); |
| 1845 | |
| 1846 | return sprintf(buf, "%d\n", enabled ? 1 : 0); |
| 1847 | } |
| 1848 | |
| 1849 | static DEVICE_ATTR(als_enabled, S_IRUGO | S_IWUSR, |
| 1850 | kbd_led_als_enabled_show, kbd_led_als_enabled_store); |
| 1851 | |
| 1852 | static ssize_t kbd_led_als_setting_store(struct device *dev, |
| 1853 | struct device_attribute *attr, |
| 1854 | const char *buf, size_t count) |
| 1855 | { |
| 1856 | struct kbd_state state; |
| 1857 | struct kbd_state new_state; |
| 1858 | u8 setting; |
| 1859 | int ret; |
| 1860 | |
| 1861 | ret = kstrtou8(buf, 10, &setting); |
| 1862 | if (ret) |
| 1863 | return ret; |
| 1864 | |
| 1865 | ret = kbd_get_state(&state); |
| 1866 | if (ret) |
| 1867 | return ret; |
| 1868 | |
| 1869 | new_state = state; |
| 1870 | new_state.als_setting = setting; |
| 1871 | |
| 1872 | ret = kbd_set_state_safe(&new_state, &state); |
| 1873 | if (ret) |
| 1874 | return ret; |
| 1875 | |
| 1876 | return count; |
| 1877 | } |
| 1878 | |
| 1879 | static ssize_t kbd_led_als_setting_show(struct device *dev, |
| 1880 | struct device_attribute *attr, |
| 1881 | char *buf) |
| 1882 | { |
| 1883 | struct kbd_state state; |
| 1884 | int ret; |
| 1885 | |
| 1886 | ret = kbd_get_state(&state); |
| 1887 | if (ret) |
| 1888 | return ret; |
| 1889 | |
| 1890 | return sprintf(buf, "%d\n", state.als_setting); |
| 1891 | } |
| 1892 | |
| 1893 | static DEVICE_ATTR(als_setting, S_IRUGO | S_IWUSR, |
| 1894 | kbd_led_als_setting_show, kbd_led_als_setting_store); |
| 1895 | |
| 1896 | static struct attribute *kbd_led_attrs[] = { |
| 1897 | &dev_attr_stop_timeout.attr, |
| 1898 | &dev_attr_start_triggers.attr, |
| 1899 | NULL, |
| 1900 | }; |
| 1901 | |
| 1902 | static const struct attribute_group kbd_led_group = { |
| 1903 | .attrs = kbd_led_attrs, |
| 1904 | }; |
| 1905 | |
| 1906 | static struct attribute *kbd_led_als_attrs[] = { |
| 1907 | &dev_attr_als_enabled.attr, |
| 1908 | &dev_attr_als_setting.attr, |
| 1909 | NULL, |
| 1910 | }; |
| 1911 | |
| 1912 | static const struct attribute_group kbd_led_als_group = { |
| 1913 | .attrs = kbd_led_als_attrs, |
| 1914 | }; |
| 1915 | |
| 1916 | static const struct attribute_group *kbd_led_groups[] = { |
| 1917 | &kbd_led_group, |
| 1918 | &kbd_led_als_group, |
| 1919 | NULL, |
| 1920 | }; |
| 1921 | |
| 1922 | static enum led_brightness kbd_led_level_get(struct led_classdev *led_cdev) |
| 1923 | { |
| 1924 | int ret; |
| 1925 | u16 num; |
| 1926 | struct kbd_state state; |
| 1927 | |
| 1928 | if (kbd_get_max_level()) { |
| 1929 | ret = kbd_get_state(&state); |
| 1930 | if (ret) |
| 1931 | return 0; |
| 1932 | ret = kbd_get_level(&state); |
| 1933 | if (ret < 0) |
| 1934 | return 0; |
| 1935 | return ret; |
| 1936 | } |
| 1937 | |
| 1938 | if (kbd_get_valid_token_counts()) { |
| 1939 | ret = kbd_get_first_active_token_bit(); |
| 1940 | if (ret < 0) |
| 1941 | return 0; |
| 1942 | for (num = kbd_token_bits; num != 0 && ret > 0; --ret) |
| 1943 | num &= num - 1; /* clear the first bit set */ |
| 1944 | if (num == 0) |
| 1945 | return 0; |
| 1946 | return ffs(num) - 1; |
| 1947 | } |
| 1948 | |
| 1949 | pr_warn("Keyboard brightness level control not supported\n"); |
| 1950 | return 0; |
| 1951 | } |
| 1952 | |
| 1953 | static void kbd_led_level_set(struct led_classdev *led_cdev, |
| 1954 | enum led_brightness value) |
| 1955 | { |
| 1956 | struct kbd_state state; |
| 1957 | struct kbd_state new_state; |
| 1958 | u16 num; |
| 1959 | |
| 1960 | if (kbd_get_max_level()) { |
| 1961 | if (kbd_get_state(&state)) |
| 1962 | return; |
| 1963 | new_state = state; |
| 1964 | if (kbd_set_level(&new_state, value)) |
| 1965 | return; |
| 1966 | kbd_set_state_safe(&new_state, &state); |
| 1967 | return; |
| 1968 | } |
| 1969 | |
| 1970 | if (kbd_get_valid_token_counts()) { |
| 1971 | for (num = kbd_token_bits; num != 0 && value > 0; --value) |
| 1972 | num &= num - 1; /* clear the first bit set */ |
| 1973 | if (num == 0) |
| 1974 | return; |
| 1975 | kbd_set_token_bit(ffs(num) - 1); |
| 1976 | return; |
| 1977 | } |
| 1978 | |
| 1979 | pr_warn("Keyboard brightness level control not supported\n"); |
| 1980 | } |
| 1981 | |
| 1982 | static struct led_classdev kbd_led = { |
| 1983 | .name = "dell::kbd_backlight", |
| 1984 | .brightness_set = kbd_led_level_set, |
| 1985 | .brightness_get = kbd_led_level_get, |
| 1986 | .groups = kbd_led_groups, |
| 1987 | }; |
| 1988 | |
| 1989 | static int __init kbd_led_init(struct device *dev) |
| 1990 | { |
| 1991 | kbd_init(); |
| 1992 | if (!kbd_led_present) |
| 1993 | return -ENODEV; |
| 1994 | if (!kbd_als_supported) |
| 1995 | kbd_led_groups[1] = NULL; |
| 1996 | kbd_led.max_brightness = kbd_get_max_level(); |
| 1997 | if (!kbd_led.max_brightness) { |
| 1998 | kbd_led.max_brightness = kbd_get_valid_token_counts(); |
| 1999 | if (kbd_led.max_brightness) |
| 2000 | kbd_led.max_brightness--; |
| 2001 | } |
| 2002 | return led_classdev_register(dev, &kbd_led); |
| 2003 | } |
| 2004 | |
| 2005 | static void brightness_set_exit(struct led_classdev *led_cdev, |
| 2006 | enum led_brightness value) |
| 2007 | { |
| 2008 | /* Don't change backlight level on exit */ |
| 2009 | }; |
| 2010 | |
| 2011 | static void kbd_led_exit(void) |
| 2012 | { |
| 2013 | if (!kbd_led_present) |
| 2014 | return; |
| 2015 | kbd_led.brightness_set = brightness_set_exit; |
| 2016 | led_classdev_unregister(&kbd_led); |
| 2017 | } |
| 2018 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2019 | static int __init dell_init(void) |
| 2020 | { |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2021 | int max_intensity = 0; |
| 2022 | int ret; |
| 2023 | |
| 2024 | if (!dmi_check_system(dell_device_table)) |
| 2025 | return -ENODEV; |
| 2026 | |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 2027 | quirks = NULL; |
| 2028 | /* find if this machine support other functions */ |
| 2029 | dmi_check_system(dell_quirks); |
| 2030 | |
Jean Delvare | e7a19c56 | 2009-03-30 21:46:44 +0200 | [diff] [blame] | 2031 | dmi_walk(find_tokens, NULL); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2032 | |
| 2033 | if (!da_tokens) { |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 2034 | pr_info("Unable to find dmi tokens\n"); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2035 | return -ENODEV; |
| 2036 | } |
| 2037 | |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 2038 | ret = platform_driver_register(&platform_driver); |
| 2039 | if (ret) |
| 2040 | goto fail_platform_driver; |
| 2041 | platform_device = platform_device_alloc("dell-laptop", -1); |
| 2042 | if (!platform_device) { |
| 2043 | ret = -ENOMEM; |
| 2044 | goto fail_platform_device1; |
| 2045 | } |
| 2046 | ret = platform_device_add(platform_device); |
| 2047 | if (ret) |
| 2048 | goto fail_platform_device2; |
| 2049 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 2050 | /* |
| 2051 | * Allocate buffer below 4GB for SMI data--only 32-bit physical addr |
| 2052 | * is passed to SMI handler. |
| 2053 | */ |
| 2054 | bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32); |
Wei Yongjun | 9f20820 | 2013-05-09 10:03:02 +0800 | [diff] [blame] | 2055 | if (!bufferpage) { |
| 2056 | ret = -ENOMEM; |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 2057 | goto fail_buffer; |
Wei Yongjun | 9f20820 | 2013-05-09 10:03:02 +0800 | [diff] [blame] | 2058 | } |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 2059 | buffer = page_address(bufferpage); |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 2060 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 2061 | ret = dell_setup_rfkill(); |
| 2062 | |
| 2063 | if (ret) { |
| 2064 | pr_warn("Unable to setup rfkill\n"); |
| 2065 | goto fail_rfkill; |
| 2066 | } |
| 2067 | |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 2068 | if (quirks && quirks->touchpad_led) |
| 2069 | touchpad_led_init(&platform_device->dev); |
| 2070 | |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 2071 | kbd_led_init(&platform_device->dev); |
| 2072 | |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 2073 | dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL); |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 2074 | if (dell_laptop_dir != NULL) |
| 2075 | debugfs_create_file("rfkill", 0444, dell_laptop_dir, NULL, |
| 2076 | &dell_debugfs_fops); |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 2077 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2078 | #ifdef CONFIG_ACPI |
| 2079 | /* In the event of an ACPI backlight being available, don't |
| 2080 | * register the platform controller. |
| 2081 | */ |
| 2082 | if (acpi_video_backlight_support()) |
| 2083 | return 0; |
| 2084 | #endif |
| 2085 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 2086 | get_buffer(); |
| 2087 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); |
| 2088 | if (buffer->input[0] != -1) { |
| 2089 | dell_send_request(buffer, 0, 2); |
| 2090 | max_intensity = buffer->output[3]; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2091 | } |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 2092 | release_buffer(); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2093 | |
| 2094 | if (max_intensity) { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 2095 | struct backlight_properties props; |
| 2096 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 2097 | props.type = BACKLIGHT_PLATFORM; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 2098 | props.max_brightness = max_intensity; |
| 2099 | dell_backlight_device = backlight_device_register("dell_backlight", |
| 2100 | &platform_device->dev, |
| 2101 | NULL, |
| 2102 | &dell_ops, |
| 2103 | &props); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2104 | |
| 2105 | if (IS_ERR(dell_backlight_device)) { |
| 2106 | ret = PTR_ERR(dell_backlight_device); |
| 2107 | dell_backlight_device = NULL; |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 2108 | goto fail_backlight; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2109 | } |
| 2110 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2111 | dell_backlight_device->props.brightness = |
| 2112 | dell_get_intensity(dell_backlight_device); |
| 2113 | backlight_update_status(dell_backlight_device); |
| 2114 | } |
| 2115 | |
| 2116 | return 0; |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 2117 | |
| 2118 | fail_backlight: |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 2119 | dell_cleanup_rfkill(); |
| 2120 | fail_rfkill: |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 2121 | free_page((unsigned long)bufferpage); |
| 2122 | fail_buffer: |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 2123 | platform_device_del(platform_device); |
| 2124 | fail_platform_device2: |
| 2125 | platform_device_put(platform_device); |
| 2126 | fail_platform_device1: |
| 2127 | platform_driver_unregister(&platform_driver); |
| 2128 | fail_platform_driver: |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2129 | kfree(da_tokens); |
| 2130 | return ret; |
| 2131 | } |
| 2132 | |
| 2133 | static void __exit dell_exit(void) |
| 2134 | { |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 2135 | debugfs_remove_recursive(dell_laptop_dir); |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 2136 | if (quirks && quirks->touchpad_led) |
| 2137 | touchpad_led_exit(); |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 2138 | kbd_led_exit(); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2139 | backlight_device_unregister(dell_backlight_device); |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 2140 | dell_cleanup_rfkill(); |
Matthew Garrett | facd61d | 2010-02-09 14:03:04 -0500 | [diff] [blame] | 2141 | if (platform_device) { |
Matthew Garrett | 92e00e4 | 2010-03-01 09:46:43 -0500 | [diff] [blame] | 2142 | platform_device_unregister(platform_device); |
Matthew Garrett | facd61d | 2010-02-09 14:03:04 -0500 | [diff] [blame] | 2143 | platform_driver_unregister(&platform_driver); |
| 2144 | } |
Matthew Garrett | e551260 | 2010-02-09 14:05:01 -0500 | [diff] [blame] | 2145 | kfree(da_tokens); |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 2146 | free_page((unsigned long)buffer); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2147 | } |
| 2148 | |
Pali Rohár | f835857 | 2015-06-06 10:23:30 +0200 | [diff] [blame] | 2149 | /* dell-rbtn.c driver export functions which will not work correctly (and could |
| 2150 | * cause kernel crash) if they are called before dell-rbtn.c init code. This is |
| 2151 | * not problem when dell-rbtn.c is compiled as external module. When both files |
| 2152 | * (dell-rbtn.c and dell-laptop.c) are compiled statically into kernel, then we |
| 2153 | * need to ensure that dell_init() will be called after initializing dell-rbtn. |
| 2154 | * This can be achieved by late_initcall() instead module_init(). |
| 2155 | */ |
| 2156 | late_initcall(dell_init); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2157 | module_exit(dell_exit); |
| 2158 | |
| 2159 | MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); |
Gabriele Mazzotta | 6cff8d6 | 2015-02-19 11:58:29 +0100 | [diff] [blame] | 2160 | MODULE_AUTHOR("Gabriele Mazzotta <gabriele.mzt@gmail.com>"); |
| 2161 | MODULE_AUTHOR("Pali Rohár <pali.rohar@gmail.com>"); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 2162 | MODULE_DESCRIPTION("Dell laptop driver"); |
| 2163 | MODULE_LICENSE("GPL"); |