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