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> |
| 5 | * |
| 6 | * Based on documentation in the libsmbios package, Copyright (C) 2005 Dell |
| 7 | * Inc. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 15 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 16 | #include <linux/module.h> |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/backlight.h> |
| 21 | #include <linux/err.h> |
| 22 | #include <linux/dmi.h> |
| 23 | #include <linux/io.h> |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 24 | #include <linux/rfkill.h> |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 25 | #include <linux/power_supply.h> |
| 26 | #include <linux/acpi.h> |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 27 | #include <linux/mm.h> |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 28 | #include <linux/i8042.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 30 | #include <linux/debugfs.h> |
| 31 | #include <linux/seq_file.h> |
Len Brown | cad7312 | 2009-01-09 17:23:38 -0500 | [diff] [blame] | 32 | #include "../../firmware/dcdbas.h" |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 33 | |
| 34 | #define BRIGHTNESS_TOKEN 0x7d |
| 35 | |
| 36 | /* This structure will be modified by the firmware when we enter |
| 37 | * system management mode, hence the volatiles */ |
| 38 | |
| 39 | struct calling_interface_buffer { |
| 40 | u16 class; |
| 41 | u16 select; |
| 42 | volatile u32 input[4]; |
| 43 | volatile u32 output[4]; |
| 44 | } __packed; |
| 45 | |
| 46 | struct calling_interface_token { |
| 47 | u16 tokenID; |
| 48 | u16 location; |
| 49 | union { |
| 50 | u16 value; |
| 51 | u16 stringlength; |
| 52 | }; |
| 53 | }; |
| 54 | |
| 55 | struct calling_interface_structure { |
| 56 | struct dmi_header header; |
| 57 | u16 cmdIOAddress; |
| 58 | u8 cmdIOCode; |
| 59 | u32 supportedCmds; |
| 60 | struct calling_interface_token tokens[]; |
| 61 | } __packed; |
| 62 | |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 63 | struct quirk_entry { |
| 64 | u8 touchpad_led; |
| 65 | }; |
| 66 | |
| 67 | static struct quirk_entry *quirks; |
| 68 | |
| 69 | static struct quirk_entry quirk_dell_vostro_v130 = { |
| 70 | .touchpad_led = 1, |
| 71 | }; |
| 72 | |
| 73 | static int dmi_matched(const struct dmi_system_id *dmi) |
| 74 | { |
| 75 | quirks = dmi->driver_data; |
| 76 | return 1; |
| 77 | } |
| 78 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 79 | static int da_command_address; |
| 80 | static int da_command_code; |
| 81 | static int da_num_tokens; |
| 82 | static struct calling_interface_token *da_tokens; |
| 83 | |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 84 | static struct platform_driver platform_driver = { |
| 85 | .driver = { |
| 86 | .name = "dell-laptop", |
| 87 | .owner = THIS_MODULE, |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | static struct platform_device *platform_device; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 92 | static struct backlight_device *dell_backlight_device; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 93 | static struct rfkill *wifi_rfkill; |
| 94 | static struct rfkill *bluetooth_rfkill; |
| 95 | static struct rfkill *wwan_rfkill; |
Hans de Goede | 8e0e668d | 2013-11-17 14:00:26 +0100 | [diff] [blame^] | 96 | static bool force_rfkill; |
| 97 | |
| 98 | module_param(force_rfkill, bool, 0444); |
| 99 | MODULE_PARM_DESC(force_rfkill, "enable rfkill on non whitelisted models"); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 100 | |
Uwe Kleine-König | 145047d | 2012-03-30 22:05:04 +0200 | [diff] [blame] | 101 | static const struct dmi_system_id dell_device_table[] __initconst = { |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 102 | { |
| 103 | .ident = "Dell laptop", |
| 104 | .matches = { |
| 105 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 106 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), |
| 107 | }, |
| 108 | }, |
Erik Andren | cb6a793 | 2010-02-14 11:53:23 -0500 | [diff] [blame] | 109 | { |
Rezwanul Kabir | 410d44c | 2010-06-23 12:02:43 -0500 | [diff] [blame] | 110 | .matches = { |
| 111 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 112 | DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /*Laptop*/ |
| 113 | }, |
| 114 | }, |
| 115 | { |
Erik Andren | cb6a793 | 2010-02-14 11:53:23 -0500 | [diff] [blame] | 116 | .ident = "Dell Computer Corporation", |
| 117 | .matches = { |
| 118 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), |
| 119 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), |
| 120 | }, |
| 121 | }, |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 122 | { } |
| 123 | }; |
Dmitry Torokhov | 35ae64f | 2011-11-14 00:25:00 -0800 | [diff] [blame] | 124 | MODULE_DEVICE_TABLE(dmi, dell_device_table); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 125 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 126 | static struct dmi_system_id dell_quirks[] = { |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 127 | { |
| 128 | .callback = dmi_matched, |
| 129 | .ident = "Dell Vostro V130", |
| 130 | .matches = { |
| 131 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 132 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V130"), |
| 133 | }, |
| 134 | .driver_data = &quirk_dell_vostro_v130, |
| 135 | }, |
| 136 | { |
| 137 | .callback = dmi_matched, |
| 138 | .ident = "Dell Vostro V131", |
| 139 | .matches = { |
| 140 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 141 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"), |
| 142 | }, |
| 143 | .driver_data = &quirk_dell_vostro_v130, |
| 144 | }, |
AceLan Kao | 2a74885 | 2011-11-17 15:30:42 +0800 | [diff] [blame] | 145 | { |
| 146 | .callback = dmi_matched, |
Ang Way Chuang | 57b31b2 | 2012-04-12 13:11:27 +0800 | [diff] [blame] | 147 | .ident = "Dell Vostro 3350", |
| 148 | .matches = { |
| 149 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 150 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3350"), |
| 151 | }, |
| 152 | .driver_data = &quirk_dell_vostro_v130, |
| 153 | }, |
| 154 | { |
| 155 | .callback = dmi_matched, |
AceLan Kao | 2a74885 | 2011-11-17 15:30:42 +0800 | [diff] [blame] | 156 | .ident = "Dell Vostro 3555", |
| 157 | .matches = { |
| 158 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 159 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3555"), |
| 160 | }, |
| 161 | .driver_data = &quirk_dell_vostro_v130, |
| 162 | }, |
| 163 | { |
| 164 | .callback = dmi_matched, |
| 165 | .ident = "Dell Inspiron N311z", |
| 166 | .matches = { |
| 167 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 168 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N311z"), |
| 169 | }, |
| 170 | .driver_data = &quirk_dell_vostro_v130, |
| 171 | }, |
| 172 | { |
| 173 | .callback = dmi_matched, |
| 174 | .ident = "Dell Inspiron M5110", |
| 175 | .matches = { |
| 176 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 177 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"), |
| 178 | }, |
| 179 | .driver_data = &quirk_dell_vostro_v130, |
| 180 | }, |
AceLan Kao | 7f83922 | 2012-04-20 11:47:26 +0800 | [diff] [blame] | 181 | { |
| 182 | .callback = dmi_matched, |
| 183 | .ident = "Dell Vostro 3360", |
| 184 | .matches = { |
| 185 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 186 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"), |
| 187 | }, |
| 188 | .driver_data = &quirk_dell_vostro_v130, |
| 189 | }, |
| 190 | { |
| 191 | .callback = dmi_matched, |
| 192 | .ident = "Dell Vostro 3460", |
| 193 | .matches = { |
| 194 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 195 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3460"), |
| 196 | }, |
| 197 | .driver_data = &quirk_dell_vostro_v130, |
| 198 | }, |
| 199 | { |
| 200 | .callback = dmi_matched, |
| 201 | .ident = "Dell Vostro 3560", |
| 202 | .matches = { |
| 203 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 204 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3560"), |
| 205 | }, |
| 206 | .driver_data = &quirk_dell_vostro_v130, |
| 207 | }, |
AceLan Kao | d0e0a477 | 2012-05-22 12:38:51 +0800 | [diff] [blame] | 208 | { |
| 209 | .callback = dmi_matched, |
| 210 | .ident = "Dell Vostro 3450", |
| 211 | .matches = { |
| 212 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 213 | DMI_MATCH(DMI_PRODUCT_NAME, "Dell System Vostro 3450"), |
| 214 | }, |
| 215 | .driver_data = &quirk_dell_vostro_v130, |
| 216 | }, |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 217 | { |
| 218 | .callback = dmi_matched, |
| 219 | .ident = "Dell Inspiron 5420", |
| 220 | .matches = { |
| 221 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 222 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5420"), |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 223 | }, |
| 224 | .driver_data = &quirk_dell_vostro_v130, |
| 225 | }, |
| 226 | { |
| 227 | .callback = dmi_matched, |
| 228 | .ident = "Dell Inspiron 5520", |
| 229 | .matches = { |
| 230 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 231 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5520"), |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 232 | }, |
| 233 | .driver_data = &quirk_dell_vostro_v130, |
| 234 | }, |
| 235 | { |
| 236 | .callback = dmi_matched, |
| 237 | .ident = "Dell Inspiron 5720", |
| 238 | .matches = { |
| 239 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 240 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5720"), |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 241 | }, |
| 242 | .driver_data = &quirk_dell_vostro_v130, |
| 243 | }, |
| 244 | { |
| 245 | .callback = dmi_matched, |
| 246 | .ident = "Dell Inspiron 7420", |
| 247 | .matches = { |
| 248 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 249 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7420"), |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 250 | }, |
| 251 | .driver_data = &quirk_dell_vostro_v130, |
| 252 | }, |
| 253 | { |
| 254 | .callback = dmi_matched, |
| 255 | .ident = "Dell Inspiron 7520", |
| 256 | .matches = { |
| 257 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 258 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7520"), |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 259 | }, |
| 260 | .driver_data = &quirk_dell_vostro_v130, |
| 261 | }, |
| 262 | { |
| 263 | .callback = dmi_matched, |
| 264 | .ident = "Dell Inspiron 7720", |
| 265 | .matches = { |
| 266 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 267 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"), |
AceLan Kao | 5f1e88f4 | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 268 | }, |
| 269 | .driver_data = &quirk_dell_vostro_v130, |
| 270 | }, |
Martin Nyhus | d62d421 | 2012-03-15 18:25:48 +0100 | [diff] [blame] | 271 | { } |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 272 | }; |
| 273 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 274 | static struct calling_interface_buffer *buffer; |
Ingo Molnar | 94d8f78 | 2010-03-01 09:43:52 -0500 | [diff] [blame] | 275 | static struct page *bufferpage; |
| 276 | static DEFINE_MUTEX(buffer_mutex); |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 277 | |
Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame] | 278 | static int hwswitch_state; |
| 279 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 280 | static void get_buffer(void) |
| 281 | { |
| 282 | mutex_lock(&buffer_mutex); |
| 283 | memset(buffer, 0, sizeof(struct calling_interface_buffer)); |
| 284 | } |
| 285 | |
| 286 | static void release_buffer(void) |
| 287 | { |
| 288 | mutex_unlock(&buffer_mutex); |
| 289 | } |
| 290 | |
Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 291 | static void __init parse_da_table(const struct dmi_header *dm) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 292 | { |
| 293 | /* Final token is a terminator, so we don't want to copy it */ |
| 294 | int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1; |
David Woodhouse | fe9ab00 | 2013-03-14 13:21:00 +0000 | [diff] [blame] | 295 | struct calling_interface_token *new_da_tokens; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 296 | struct calling_interface_structure *table = |
| 297 | container_of(dm, struct calling_interface_structure, header); |
| 298 | |
| 299 | /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least |
| 300 | 6 bytes of entry */ |
| 301 | |
| 302 | if (dm->length < 17) |
| 303 | return; |
| 304 | |
| 305 | da_command_address = table->cmdIOAddress; |
| 306 | da_command_code = table->cmdIOCode; |
| 307 | |
David Woodhouse | fe9ab00 | 2013-03-14 13:21:00 +0000 | [diff] [blame] | 308 | new_da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) * |
| 309 | sizeof(struct calling_interface_token), |
| 310 | GFP_KERNEL); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 311 | |
David Woodhouse | fe9ab00 | 2013-03-14 13:21:00 +0000 | [diff] [blame] | 312 | if (!new_da_tokens) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 313 | return; |
David Woodhouse | fe9ab00 | 2013-03-14 13:21:00 +0000 | [diff] [blame] | 314 | da_tokens = new_da_tokens; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 315 | |
| 316 | memcpy(da_tokens+da_num_tokens, table->tokens, |
| 317 | sizeof(struct calling_interface_token) * tokens); |
| 318 | |
| 319 | da_num_tokens += tokens; |
| 320 | } |
| 321 | |
Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 322 | static void __init find_tokens(const struct dmi_header *dm, void *dummy) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 323 | { |
| 324 | switch (dm->type) { |
| 325 | case 0xd4: /* Indexed IO */ |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 326 | case 0xd5: /* Protected Area Type 1 */ |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 327 | case 0xd6: /* Protected Area Type 2 */ |
| 328 | break; |
| 329 | case 0xda: /* Calling interface */ |
| 330 | parse_da_table(dm); |
| 331 | break; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | static int find_token_location(int tokenid) |
| 336 | { |
| 337 | int i; |
| 338 | for (i = 0; i < da_num_tokens; i++) { |
| 339 | if (da_tokens[i].tokenID == tokenid) |
| 340 | return da_tokens[i].location; |
| 341 | } |
| 342 | |
| 343 | return -1; |
| 344 | } |
| 345 | |
| 346 | static struct calling_interface_buffer * |
| 347 | dell_send_request(struct calling_interface_buffer *buffer, int class, |
| 348 | int select) |
| 349 | { |
| 350 | struct smi_cmd command; |
| 351 | |
| 352 | command.magic = SMI_CMD_MAGIC; |
| 353 | command.command_address = da_command_address; |
| 354 | command.command_code = da_command_code; |
| 355 | command.ebx = virt_to_phys(buffer); |
| 356 | command.ecx = 0x42534931; |
| 357 | |
| 358 | buffer->class = class; |
| 359 | buffer->select = select; |
| 360 | |
| 361 | dcdbas_smi_request(&command); |
| 362 | |
| 363 | return buffer; |
| 364 | } |
| 365 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 366 | /* Derived from information in DellWirelessCtl.cpp: |
| 367 | Class 17, select 11 is radio control. It returns an array of 32-bit values. |
| 368 | |
| 369 | Input byte 0 = 0: Wireless information |
| 370 | |
| 371 | result[0]: return code |
| 372 | result[1]: |
| 373 | Bit 0: Hardware switch supported |
| 374 | Bit 1: Wifi locator supported |
| 375 | Bit 2: Wifi is supported |
| 376 | Bit 3: Bluetooth is supported |
| 377 | Bit 4: WWAN is supported |
| 378 | Bit 5: Wireless keyboard supported |
| 379 | Bits 6-7: Reserved |
| 380 | Bit 8: Wifi is installed |
| 381 | Bit 9: Bluetooth is installed |
| 382 | Bit 10: WWAN is installed |
| 383 | Bits 11-15: Reserved |
| 384 | Bit 16: Hardware switch is on |
| 385 | Bit 17: Wifi is blocked |
| 386 | Bit 18: Bluetooth is blocked |
| 387 | Bit 19: WWAN is blocked |
| 388 | Bits 20-31: Reserved |
| 389 | result[2]: NVRAM size in bytes |
| 390 | result[3]: NVRAM format version number |
| 391 | |
| 392 | Input byte 0 = 2: Wireless switch configuration |
| 393 | result[0]: return code |
| 394 | result[1]: |
| 395 | Bit 0: Wifi controlled by switch |
| 396 | Bit 1: Bluetooth controlled by switch |
| 397 | Bit 2: WWAN controlled by switch |
| 398 | Bits 3-6: Reserved |
| 399 | Bit 7: Wireless switch config locked |
| 400 | Bit 8: Wifi locator enabled |
| 401 | Bits 9-14: Reserved |
| 402 | Bit 15: Wifi locator setting locked |
| 403 | Bits 16-31: Reserved |
| 404 | */ |
| 405 | |
| 406 | static int dell_rfkill_set(void *data, bool blocked) |
| 407 | { |
| 408 | int disable = blocked ? 1 : 0; |
| 409 | unsigned long radio = (unsigned long)data; |
| 410 | int hwswitch_bit = (unsigned long)data - 1; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 411 | |
| 412 | get_buffer(); |
| 413 | dell_send_request(buffer, 17, 11); |
| 414 | |
| 415 | /* If the hardware switch controls this radio, and the hardware |
Hans de Goede | ed11289 | 2013-11-17 14:00:24 +0100 | [diff] [blame] | 416 | switch is disabled, always disable the radio */ |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 417 | if ((hwswitch_state & BIT(hwswitch_bit)) && |
Hans de Goede | 4d39d88 | 2013-11-17 14:00:22 +0100 | [diff] [blame] | 418 | !(buffer->output[1] & BIT(16))) |
Hans de Goede | ed11289 | 2013-11-17 14:00:24 +0100 | [diff] [blame] | 419 | disable = 1; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 420 | |
| 421 | buffer->input[0] = (1 | (radio<<8) | (disable << 16)); |
| 422 | dell_send_request(buffer, 17, 11); |
| 423 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 424 | release_buffer(); |
Hans de Goede | 4d39d88 | 2013-11-17 14:00:22 +0100 | [diff] [blame] | 425 | return 0; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 426 | } |
| 427 | |
Hans de Goede | 04c9a3a | 2013-11-17 14:00:23 +0100 | [diff] [blame] | 428 | /* Must be called with the buffer held */ |
Hans de Goede | 33f9359 | 2013-11-17 14:00:20 +0100 | [diff] [blame] | 429 | static void dell_rfkill_update_sw_state(struct rfkill *rfkill, int radio, |
| 430 | int status) |
Hans de Goede | d038880 | 2013-11-17 14:00:19 +0100 | [diff] [blame] | 431 | { |
Hans de Goede | 04c9a3a | 2013-11-17 14:00:23 +0100 | [diff] [blame] | 432 | if (status & BIT(0)) { |
| 433 | /* Has hw-switch, sync sw_state to BIOS */ |
| 434 | int block = rfkill_blocked(rfkill); |
| 435 | buffer->input[0] = (1 | (radio << 8) | (block << 16)); |
| 436 | dell_send_request(buffer, 17, 11); |
| 437 | } else { |
Hans de Goede | 3f56588 | 2013-11-17 14:00:21 +0100 | [diff] [blame] | 438 | /* No hw-switch, sync BIOS state to sw_state */ |
| 439 | rfkill_set_sw_state(rfkill, !!(status & BIT(radio + 16))); |
| 440 | } |
Hans de Goede | 33f9359 | 2013-11-17 14:00:20 +0100 | [diff] [blame] | 441 | } |
Hans de Goede | d038880 | 2013-11-17 14:00:19 +0100 | [diff] [blame] | 442 | |
Hans de Goede | 33f9359 | 2013-11-17 14:00:20 +0100 | [diff] [blame] | 443 | static void dell_rfkill_update_hw_state(struct rfkill *rfkill, int radio, |
| 444 | int status) |
| 445 | { |
Hans de Goede | d038880 | 2013-11-17 14:00:19 +0100 | [diff] [blame] | 446 | if (hwswitch_state & (BIT(radio - 1))) |
| 447 | rfkill_set_hw_state(rfkill, !(status & BIT(16))); |
| 448 | } |
| 449 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 450 | static void dell_rfkill_query(struct rfkill *rfkill, void *data) |
| 451 | { |
| 452 | int status; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 453 | |
| 454 | get_buffer(); |
| 455 | dell_send_request(buffer, 17, 11); |
| 456 | status = buffer->output[1]; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 457 | |
Hans de Goede | 33f9359 | 2013-11-17 14:00:20 +0100 | [diff] [blame] | 458 | dell_rfkill_update_hw_state(rfkill, (unsigned long)data, status); |
Hans de Goede | 04c9a3a | 2013-11-17 14:00:23 +0100 | [diff] [blame] | 459 | |
| 460 | release_buffer(); |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | static const struct rfkill_ops dell_rfkill_ops = { |
| 464 | .set_block = dell_rfkill_set, |
| 465 | .query = dell_rfkill_query, |
| 466 | }; |
| 467 | |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 468 | static struct dentry *dell_laptop_dir; |
| 469 | |
| 470 | static int dell_debugfs_show(struct seq_file *s, void *data) |
| 471 | { |
| 472 | int status; |
| 473 | |
| 474 | get_buffer(); |
| 475 | dell_send_request(buffer, 17, 11); |
| 476 | status = buffer->output[1]; |
| 477 | release_buffer(); |
| 478 | |
| 479 | seq_printf(s, "status:\t0x%X\n", status); |
| 480 | seq_printf(s, "Bit 0 : Hardware switch supported: %lu\n", |
| 481 | status & BIT(0)); |
| 482 | seq_printf(s, "Bit 1 : Wifi locator supported: %lu\n", |
| 483 | (status & BIT(1)) >> 1); |
| 484 | seq_printf(s, "Bit 2 : Wifi is supported: %lu\n", |
| 485 | (status & BIT(2)) >> 2); |
| 486 | seq_printf(s, "Bit 3 : Bluetooth is supported: %lu\n", |
| 487 | (status & BIT(3)) >> 3); |
| 488 | seq_printf(s, "Bit 4 : WWAN is supported: %lu\n", |
| 489 | (status & BIT(4)) >> 4); |
| 490 | seq_printf(s, "Bit 5 : Wireless keyboard supported: %lu\n", |
| 491 | (status & BIT(5)) >> 5); |
| 492 | seq_printf(s, "Bit 8 : Wifi is installed: %lu\n", |
| 493 | (status & BIT(8)) >> 8); |
| 494 | seq_printf(s, "Bit 9 : Bluetooth is installed: %lu\n", |
| 495 | (status & BIT(9)) >> 9); |
| 496 | seq_printf(s, "Bit 10: WWAN is installed: %lu\n", |
| 497 | (status & BIT(10)) >> 10); |
| 498 | seq_printf(s, "Bit 16: Hardware switch is on: %lu\n", |
| 499 | (status & BIT(16)) >> 16); |
| 500 | seq_printf(s, "Bit 17: Wifi is blocked: %lu\n", |
| 501 | (status & BIT(17)) >> 17); |
| 502 | seq_printf(s, "Bit 18: Bluetooth is blocked: %lu\n", |
| 503 | (status & BIT(18)) >> 18); |
| 504 | seq_printf(s, "Bit 19: WWAN is blocked: %lu\n", |
| 505 | (status & BIT(19)) >> 19); |
| 506 | |
| 507 | seq_printf(s, "\nhwswitch_state:\t0x%X\n", hwswitch_state); |
| 508 | seq_printf(s, "Bit 0 : Wifi controlled by switch: %lu\n", |
| 509 | hwswitch_state & BIT(0)); |
| 510 | seq_printf(s, "Bit 1 : Bluetooth controlled by switch: %lu\n", |
| 511 | (hwswitch_state & BIT(1)) >> 1); |
| 512 | seq_printf(s, "Bit 2 : WWAN controlled by switch: %lu\n", |
| 513 | (hwswitch_state & BIT(2)) >> 2); |
| 514 | seq_printf(s, "Bit 7 : Wireless switch config locked: %lu\n", |
| 515 | (hwswitch_state & BIT(7)) >> 7); |
| 516 | seq_printf(s, "Bit 8 : Wifi locator enabled: %lu\n", |
| 517 | (hwswitch_state & BIT(8)) >> 8); |
| 518 | seq_printf(s, "Bit 15: Wifi locator setting locked: %lu\n", |
| 519 | (hwswitch_state & BIT(15)) >> 15); |
| 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | static int dell_debugfs_open(struct inode *inode, struct file *file) |
| 525 | { |
| 526 | return single_open(file, dell_debugfs_show, inode->i_private); |
| 527 | } |
| 528 | |
| 529 | static const struct file_operations dell_debugfs_fops = { |
| 530 | .owner = THIS_MODULE, |
| 531 | .open = dell_debugfs_open, |
| 532 | .read = seq_read, |
| 533 | .llseek = seq_lseek, |
| 534 | .release = single_release, |
| 535 | }; |
| 536 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 537 | static void dell_update_rfkill(struct work_struct *ignored) |
| 538 | { |
Hans de Goede | d038880 | 2013-11-17 14:00:19 +0100 | [diff] [blame] | 539 | int status; |
| 540 | |
| 541 | get_buffer(); |
| 542 | dell_send_request(buffer, 17, 11); |
| 543 | status = buffer->output[1]; |
Hans de Goede | d038880 | 2013-11-17 14:00:19 +0100 | [diff] [blame] | 544 | |
Hans de Goede | 33f9359 | 2013-11-17 14:00:20 +0100 | [diff] [blame] | 545 | if (wifi_rfkill) { |
| 546 | dell_rfkill_update_hw_state(wifi_rfkill, 1, status); |
| 547 | dell_rfkill_update_sw_state(wifi_rfkill, 1, status); |
| 548 | } |
| 549 | if (bluetooth_rfkill) { |
| 550 | dell_rfkill_update_hw_state(bluetooth_rfkill, 2, status); |
| 551 | dell_rfkill_update_sw_state(bluetooth_rfkill, 2, status); |
| 552 | } |
| 553 | if (wwan_rfkill) { |
| 554 | dell_rfkill_update_hw_state(wwan_rfkill, 3, status); |
| 555 | dell_rfkill_update_sw_state(wwan_rfkill, 3, status); |
| 556 | } |
Hans de Goede | 04c9a3a | 2013-11-17 14:00:23 +0100 | [diff] [blame] | 557 | |
| 558 | release_buffer(); |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 559 | } |
| 560 | static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill); |
| 561 | |
| 562 | |
| 563 | static int __init dell_setup_rfkill(void) |
| 564 | { |
| 565 | int status; |
| 566 | int ret; |
Hans de Goede | 2a92551 | 2013-11-17 14:00:17 +0100 | [diff] [blame] | 567 | const char *product; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 568 | |
Hans de Goede | 2a92551 | 2013-11-17 14:00:17 +0100 | [diff] [blame] | 569 | /* |
| 570 | * rfkill causes trouble on various non Latitudes, according to Dell |
| 571 | * actually testing the rfkill functionality is only done on Latitudes. |
| 572 | */ |
| 573 | product = dmi_get_system_info(DMI_PRODUCT_NAME); |
Hans de Goede | 8e0e668d | 2013-11-17 14:00:26 +0100 | [diff] [blame^] | 574 | if (!force_rfkill && (!product || strncmp(product, "Latitude", 8))) |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 575 | return 0; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 576 | |
| 577 | get_buffer(); |
| 578 | dell_send_request(buffer, 17, 11); |
| 579 | status = buffer->output[1]; |
| 580 | buffer->input[0] = 0x2; |
| 581 | dell_send_request(buffer, 17, 11); |
| 582 | hwswitch_state = buffer->output[1]; |
Hans de Goede | ddde708 | 2013-11-17 14:00:18 +0100 | [diff] [blame] | 583 | /* If there is no hwswitch, then clear all hw-controlled bits */ |
| 584 | if (!(status & BIT(0))) |
| 585 | hwswitch_state &= ~7; |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 586 | release_buffer(); |
| 587 | |
| 588 | if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) { |
| 589 | wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev, |
| 590 | RFKILL_TYPE_WLAN, |
| 591 | &dell_rfkill_ops, (void *) 1); |
| 592 | if (!wifi_rfkill) { |
| 593 | ret = -ENOMEM; |
| 594 | goto err_wifi; |
| 595 | } |
| 596 | ret = rfkill_register(wifi_rfkill); |
| 597 | if (ret) |
| 598 | goto err_wifi; |
| 599 | } |
| 600 | |
| 601 | if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) { |
| 602 | bluetooth_rfkill = rfkill_alloc("dell-bluetooth", |
| 603 | &platform_device->dev, |
| 604 | RFKILL_TYPE_BLUETOOTH, |
| 605 | &dell_rfkill_ops, (void *) 2); |
| 606 | if (!bluetooth_rfkill) { |
| 607 | ret = -ENOMEM; |
| 608 | goto err_bluetooth; |
| 609 | } |
| 610 | ret = rfkill_register(bluetooth_rfkill); |
| 611 | if (ret) |
| 612 | goto err_bluetooth; |
| 613 | } |
| 614 | |
| 615 | if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) { |
| 616 | wwan_rfkill = rfkill_alloc("dell-wwan", |
| 617 | &platform_device->dev, |
| 618 | RFKILL_TYPE_WWAN, |
| 619 | &dell_rfkill_ops, (void *) 3); |
| 620 | if (!wwan_rfkill) { |
| 621 | ret = -ENOMEM; |
| 622 | goto err_wwan; |
| 623 | } |
| 624 | ret = rfkill_register(wwan_rfkill); |
| 625 | if (ret) |
| 626 | goto err_wwan; |
| 627 | } |
| 628 | |
| 629 | return 0; |
| 630 | err_wwan: |
| 631 | rfkill_destroy(wwan_rfkill); |
| 632 | if (bluetooth_rfkill) |
| 633 | rfkill_unregister(bluetooth_rfkill); |
| 634 | err_bluetooth: |
| 635 | rfkill_destroy(bluetooth_rfkill); |
| 636 | if (wifi_rfkill) |
| 637 | rfkill_unregister(wifi_rfkill); |
| 638 | err_wifi: |
| 639 | rfkill_destroy(wifi_rfkill); |
| 640 | |
| 641 | return ret; |
| 642 | } |
| 643 | |
| 644 | static void dell_cleanup_rfkill(void) |
| 645 | { |
| 646 | if (wifi_rfkill) { |
| 647 | rfkill_unregister(wifi_rfkill); |
| 648 | rfkill_destroy(wifi_rfkill); |
| 649 | } |
| 650 | if (bluetooth_rfkill) { |
| 651 | rfkill_unregister(bluetooth_rfkill); |
| 652 | rfkill_destroy(bluetooth_rfkill); |
| 653 | } |
| 654 | if (wwan_rfkill) { |
| 655 | rfkill_unregister(wwan_rfkill); |
| 656 | rfkill_destroy(wwan_rfkill); |
| 657 | } |
| 658 | } |
| 659 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 660 | static int dell_send_intensity(struct backlight_device *bd) |
| 661 | { |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 662 | int ret = 0; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 663 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 664 | get_buffer(); |
| 665 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); |
| 666 | buffer->input[1] = bd->props.brightness; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 667 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 668 | if (buffer->input[0] == -1) { |
| 669 | ret = -ENODEV; |
| 670 | goto out; |
| 671 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 672 | |
| 673 | if (power_supply_is_system_supplied() > 0) |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 674 | dell_send_request(buffer, 1, 2); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 675 | else |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 676 | dell_send_request(buffer, 1, 1); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 677 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 678 | out: |
| 679 | release_buffer(); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | static int dell_get_intensity(struct backlight_device *bd) |
| 684 | { |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 685 | int ret = 0; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 686 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 687 | get_buffer(); |
| 688 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 689 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 690 | if (buffer->input[0] == -1) { |
| 691 | ret = -ENODEV; |
| 692 | goto out; |
| 693 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 694 | |
| 695 | if (power_supply_is_system_supplied() > 0) |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 696 | dell_send_request(buffer, 0, 2); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 697 | else |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 698 | dell_send_request(buffer, 0, 1); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 699 | |
Jose Alonso | b486742 | 2011-07-10 15:46:51 -0300 | [diff] [blame] | 700 | ret = buffer->output[1]; |
| 701 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 702 | out: |
| 703 | release_buffer(); |
Jose Alonso | b486742 | 2011-07-10 15:46:51 -0300 | [diff] [blame] | 704 | return ret; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 705 | } |
| 706 | |
Lionel Debroux | acc2472 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 707 | static const struct backlight_ops dell_ops = { |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 708 | .get_brightness = dell_get_intensity, |
| 709 | .update_status = dell_send_intensity, |
| 710 | }; |
| 711 | |
Randy Dunlap | 869f8df | 2011-11-16 18:20:51 -0800 | [diff] [blame] | 712 | static void touchpad_led_on(void) |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 713 | { |
| 714 | int command = 0x97; |
| 715 | char data = 1; |
| 716 | i8042_command(&data, command | 1 << 12); |
| 717 | } |
| 718 | |
Randy Dunlap | 869f8df | 2011-11-16 18:20:51 -0800 | [diff] [blame] | 719 | static void touchpad_led_off(void) |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 720 | { |
| 721 | int command = 0x97; |
| 722 | char data = 2; |
| 723 | i8042_command(&data, command | 1 << 12); |
| 724 | } |
| 725 | |
| 726 | static void touchpad_led_set(struct led_classdev *led_cdev, |
| 727 | enum led_brightness value) |
| 728 | { |
| 729 | if (value > 0) |
| 730 | touchpad_led_on(); |
| 731 | else |
| 732 | touchpad_led_off(); |
| 733 | } |
| 734 | |
| 735 | static struct led_classdev touchpad_led = { |
| 736 | .name = "dell-laptop::touchpad", |
| 737 | .brightness_set = touchpad_led_set, |
AceLan Kao | 2d5de9e | 2012-01-17 16:18:06 +0800 | [diff] [blame] | 738 | .flags = LED_CORE_SUSPENDRESUME, |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 739 | }; |
| 740 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 741 | static int touchpad_led_init(struct device *dev) |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 742 | { |
| 743 | return led_classdev_register(dev, &touchpad_led); |
| 744 | } |
| 745 | |
| 746 | static void touchpad_led_exit(void) |
| 747 | { |
| 748 | led_classdev_unregister(&touchpad_led); |
| 749 | } |
| 750 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 751 | static bool dell_laptop_i8042_filter(unsigned char data, unsigned char str, |
| 752 | struct serio *port) |
| 753 | { |
| 754 | static bool extended; |
| 755 | |
| 756 | if (str & 0x20) |
| 757 | return false; |
| 758 | |
| 759 | if (unlikely(data == 0xe0)) { |
| 760 | extended = true; |
| 761 | return false; |
| 762 | } else if (unlikely(extended)) { |
| 763 | switch (data) { |
| 764 | case 0x8: |
| 765 | schedule_delayed_work(&dell_rfkill_work, |
Hans de Goede | 26c22d6 | 2013-11-17 14:00:25 +0100 | [diff] [blame] | 766 | round_jiffies_relative(HZ / 4)); |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 767 | break; |
| 768 | } |
| 769 | extended = false; |
| 770 | } |
| 771 | |
| 772 | return false; |
| 773 | } |
| 774 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 775 | static int __init dell_init(void) |
| 776 | { |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 777 | int max_intensity = 0; |
| 778 | int ret; |
| 779 | |
| 780 | if (!dmi_check_system(dell_device_table)) |
| 781 | return -ENODEV; |
| 782 | |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 783 | quirks = NULL; |
| 784 | /* find if this machine support other functions */ |
| 785 | dmi_check_system(dell_quirks); |
| 786 | |
Jean Delvare | e7a19c56 | 2009-03-30 21:46:44 +0200 | [diff] [blame] | 787 | dmi_walk(find_tokens, NULL); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 788 | |
| 789 | if (!da_tokens) { |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 790 | pr_info("Unable to find dmi tokens\n"); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 791 | return -ENODEV; |
| 792 | } |
| 793 | |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 794 | ret = platform_driver_register(&platform_driver); |
| 795 | if (ret) |
| 796 | goto fail_platform_driver; |
| 797 | platform_device = platform_device_alloc("dell-laptop", -1); |
| 798 | if (!platform_device) { |
| 799 | ret = -ENOMEM; |
| 800 | goto fail_platform_device1; |
| 801 | } |
| 802 | ret = platform_device_add(platform_device); |
| 803 | if (ret) |
| 804 | goto fail_platform_device2; |
| 805 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 806 | /* |
| 807 | * Allocate buffer below 4GB for SMI data--only 32-bit physical addr |
| 808 | * is passed to SMI handler. |
| 809 | */ |
| 810 | bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32); |
Wei Yongjun | 9f20820 | 2013-05-09 10:03:02 +0800 | [diff] [blame] | 811 | if (!bufferpage) { |
| 812 | ret = -ENOMEM; |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 813 | goto fail_buffer; |
Wei Yongjun | 9f20820 | 2013-05-09 10:03:02 +0800 | [diff] [blame] | 814 | } |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 815 | buffer = page_address(bufferpage); |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 816 | |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 817 | ret = dell_setup_rfkill(); |
| 818 | |
| 819 | if (ret) { |
| 820 | pr_warn("Unable to setup rfkill\n"); |
| 821 | goto fail_rfkill; |
| 822 | } |
| 823 | |
| 824 | ret = i8042_install_filter(dell_laptop_i8042_filter); |
| 825 | if (ret) { |
| 826 | pr_warn("Unable to install key filter\n"); |
| 827 | goto fail_filter; |
| 828 | } |
| 829 | |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 830 | if (quirks && quirks->touchpad_led) |
| 831 | touchpad_led_init(&platform_device->dev); |
| 832 | |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 833 | dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL); |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 834 | if (dell_laptop_dir != NULL) |
| 835 | debugfs_create_file("rfkill", 0444, dell_laptop_dir, NULL, |
| 836 | &dell_debugfs_fops); |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 837 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 838 | #ifdef CONFIG_ACPI |
| 839 | /* In the event of an ACPI backlight being available, don't |
| 840 | * register the platform controller. |
| 841 | */ |
| 842 | if (acpi_video_backlight_support()) |
| 843 | return 0; |
| 844 | #endif |
| 845 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 846 | get_buffer(); |
| 847 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); |
| 848 | if (buffer->input[0] != -1) { |
| 849 | dell_send_request(buffer, 0, 2); |
| 850 | max_intensity = buffer->output[3]; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 851 | } |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 852 | release_buffer(); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 853 | |
| 854 | if (max_intensity) { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 855 | struct backlight_properties props; |
| 856 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 857 | props.type = BACKLIGHT_PLATFORM; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 858 | props.max_brightness = max_intensity; |
| 859 | dell_backlight_device = backlight_device_register("dell_backlight", |
| 860 | &platform_device->dev, |
| 861 | NULL, |
| 862 | &dell_ops, |
| 863 | &props); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 864 | |
| 865 | if (IS_ERR(dell_backlight_device)) { |
| 866 | ret = PTR_ERR(dell_backlight_device); |
| 867 | dell_backlight_device = NULL; |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 868 | goto fail_backlight; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 869 | } |
| 870 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 871 | dell_backlight_device->props.brightness = |
| 872 | dell_get_intensity(dell_backlight_device); |
| 873 | backlight_update_status(dell_backlight_device); |
| 874 | } |
| 875 | |
| 876 | return 0; |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 877 | |
| 878 | fail_backlight: |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 879 | i8042_remove_filter(dell_laptop_i8042_filter); |
| 880 | cancel_delayed_work_sync(&dell_rfkill_work); |
| 881 | fail_filter: |
| 882 | dell_cleanup_rfkill(); |
| 883 | fail_rfkill: |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 884 | free_page((unsigned long)bufferpage); |
| 885 | fail_buffer: |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 886 | platform_device_del(platform_device); |
| 887 | fail_platform_device2: |
| 888 | platform_device_put(platform_device); |
| 889 | fail_platform_device1: |
| 890 | platform_driver_unregister(&platform_driver); |
| 891 | fail_platform_driver: |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 892 | kfree(da_tokens); |
| 893 | return ret; |
| 894 | } |
| 895 | |
| 896 | static void __exit dell_exit(void) |
| 897 | { |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 898 | debugfs_remove_recursive(dell_laptop_dir); |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 899 | if (quirks && quirks->touchpad_led) |
| 900 | touchpad_led_exit(); |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 901 | i8042_remove_filter(dell_laptop_i8042_filter); |
| 902 | cancel_delayed_work_sync(&dell_rfkill_work); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 903 | backlight_device_unregister(dell_backlight_device); |
Hans de Goede | 4cc8a57 | 2013-11-17 14:00:16 +0100 | [diff] [blame] | 904 | dell_cleanup_rfkill(); |
Matthew Garrett | facd61d | 2010-02-09 14:03:04 -0500 | [diff] [blame] | 905 | if (platform_device) { |
Matthew Garrett | 92e00e4 | 2010-03-01 09:46:43 -0500 | [diff] [blame] | 906 | platform_device_unregister(platform_device); |
Matthew Garrett | facd61d | 2010-02-09 14:03:04 -0500 | [diff] [blame] | 907 | platform_driver_unregister(&platform_driver); |
| 908 | } |
Matthew Garrett | e551260 | 2010-02-09 14:05:01 -0500 | [diff] [blame] | 909 | kfree(da_tokens); |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 910 | free_page((unsigned long)buffer); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | module_init(dell_init); |
| 914 | module_exit(dell_exit); |
| 915 | |
| 916 | MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); |
| 917 | MODULE_DESCRIPTION("Dell laptop driver"); |
| 918 | MODULE_LICENSE("GPL"); |