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> |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 24 | #include <linux/power_supply.h> |
| 25 | #include <linux/acpi.h> |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 26 | #include <linux/mm.h> |
Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 27 | #include <linux/i8042.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 29 | #include <linux/debugfs.h> |
| 30 | #include <linux/seq_file.h> |
Len Brown | cad7312 | 2009-01-09 17:23:38 -0500 | [diff] [blame] | 31 | #include "../../firmware/dcdbas.h" |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 32 | |
| 33 | #define BRIGHTNESS_TOKEN 0x7d |
| 34 | |
| 35 | /* This structure will be modified by the firmware when we enter |
| 36 | * system management mode, hence the volatiles */ |
| 37 | |
| 38 | struct calling_interface_buffer { |
| 39 | u16 class; |
| 40 | u16 select; |
| 41 | volatile u32 input[4]; |
| 42 | volatile u32 output[4]; |
| 43 | } __packed; |
| 44 | |
| 45 | struct calling_interface_token { |
| 46 | u16 tokenID; |
| 47 | u16 location; |
| 48 | union { |
| 49 | u16 value; |
| 50 | u16 stringlength; |
| 51 | }; |
| 52 | }; |
| 53 | |
| 54 | struct calling_interface_structure { |
| 55 | struct dmi_header header; |
| 56 | u16 cmdIOAddress; |
| 57 | u8 cmdIOCode; |
| 58 | u32 supportedCmds; |
| 59 | struct calling_interface_token tokens[]; |
| 60 | } __packed; |
| 61 | |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 62 | struct quirk_entry { |
| 63 | u8 touchpad_led; |
| 64 | }; |
| 65 | |
| 66 | static struct quirk_entry *quirks; |
| 67 | |
| 68 | static struct quirk_entry quirk_dell_vostro_v130 = { |
| 69 | .touchpad_led = 1, |
| 70 | }; |
| 71 | |
| 72 | static int dmi_matched(const struct dmi_system_id *dmi) |
| 73 | { |
| 74 | quirks = dmi->driver_data; |
| 75 | return 1; |
| 76 | } |
| 77 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 78 | static int da_command_address; |
| 79 | static int da_command_code; |
| 80 | static int da_num_tokens; |
| 81 | static struct calling_interface_token *da_tokens; |
| 82 | |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 83 | static struct platform_driver platform_driver = { |
| 84 | .driver = { |
| 85 | .name = "dell-laptop", |
| 86 | .owner = THIS_MODULE, |
| 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; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 92 | |
Uwe Kleine-König | 145047d | 2012-03-30 22:05:04 +0200 | [diff] [blame] | 93 | static const struct dmi_system_id dell_device_table[] __initconst = { |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 94 | { |
| 95 | .ident = "Dell laptop", |
| 96 | .matches = { |
| 97 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 98 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), |
| 99 | }, |
| 100 | }, |
Erik Andren | cb6a793 | 2010-02-14 11:53:23 -0500 | [diff] [blame] | 101 | { |
Rezwanul Kabir | 410d44c | 2010-06-23 12:02:43 -0500 | [diff] [blame] | 102 | .matches = { |
| 103 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 104 | DMI_MATCH(DMI_CHASSIS_TYPE, "9"), /*Laptop*/ |
| 105 | }, |
| 106 | }, |
| 107 | { |
Erik Andren | cb6a793 | 2010-02-14 11:53:23 -0500 | [diff] [blame] | 108 | .ident = "Dell Computer Corporation", |
| 109 | .matches = { |
| 110 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), |
| 111 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), |
| 112 | }, |
| 113 | }, |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 114 | { } |
| 115 | }; |
Dmitry Torokhov | 35ae64f | 2011-11-14 00:25:00 -0800 | [diff] [blame] | 116 | MODULE_DEVICE_TABLE(dmi, dell_device_table); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 117 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 118 | static struct dmi_system_id dell_quirks[] = { |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 119 | { |
| 120 | .callback = dmi_matched, |
| 121 | .ident = "Dell Vostro V130", |
| 122 | .matches = { |
| 123 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 124 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V130"), |
| 125 | }, |
| 126 | .driver_data = &quirk_dell_vostro_v130, |
| 127 | }, |
| 128 | { |
| 129 | .callback = dmi_matched, |
| 130 | .ident = "Dell Vostro V131", |
| 131 | .matches = { |
| 132 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 133 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro V131"), |
| 134 | }, |
| 135 | .driver_data = &quirk_dell_vostro_v130, |
| 136 | }, |
AceLan Kao | 2a74885 | 2011-11-17 15:30:42 +0800 | [diff] [blame] | 137 | { |
| 138 | .callback = dmi_matched, |
Ang Way Chuang | 57b31b2 | 2012-04-12 13:11:27 +0800 | [diff] [blame] | 139 | .ident = "Dell Vostro 3350", |
| 140 | .matches = { |
| 141 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 142 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3350"), |
| 143 | }, |
| 144 | .driver_data = &quirk_dell_vostro_v130, |
| 145 | }, |
| 146 | { |
| 147 | .callback = dmi_matched, |
AceLan Kao | 2a74885 | 2011-11-17 15:30:42 +0800 | [diff] [blame] | 148 | .ident = "Dell Vostro 3555", |
| 149 | .matches = { |
| 150 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 151 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3555"), |
| 152 | }, |
| 153 | .driver_data = &quirk_dell_vostro_v130, |
| 154 | }, |
| 155 | { |
| 156 | .callback = dmi_matched, |
| 157 | .ident = "Dell Inspiron N311z", |
| 158 | .matches = { |
| 159 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 160 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron N311z"), |
| 161 | }, |
| 162 | .driver_data = &quirk_dell_vostro_v130, |
| 163 | }, |
| 164 | { |
| 165 | .callback = dmi_matched, |
| 166 | .ident = "Dell Inspiron M5110", |
| 167 | .matches = { |
| 168 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 169 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron M5110"), |
| 170 | }, |
| 171 | .driver_data = &quirk_dell_vostro_v130, |
| 172 | }, |
AceLan Kao | 7f83922 | 2012-04-20 11:47:26 +0800 | [diff] [blame] | 173 | { |
| 174 | .callback = dmi_matched, |
| 175 | .ident = "Dell Vostro 3360", |
| 176 | .matches = { |
| 177 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 178 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3360"), |
| 179 | }, |
| 180 | .driver_data = &quirk_dell_vostro_v130, |
| 181 | }, |
| 182 | { |
| 183 | .callback = dmi_matched, |
| 184 | .ident = "Dell Vostro 3460", |
| 185 | .matches = { |
| 186 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 187 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3460"), |
| 188 | }, |
| 189 | .driver_data = &quirk_dell_vostro_v130, |
| 190 | }, |
| 191 | { |
| 192 | .callback = dmi_matched, |
| 193 | .ident = "Dell Vostro 3560", |
| 194 | .matches = { |
| 195 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 196 | DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3560"), |
| 197 | }, |
| 198 | .driver_data = &quirk_dell_vostro_v130, |
| 199 | }, |
AceLan Kao | d0e0a477 | 2012-05-22 12:38:51 +0800 | [diff] [blame] | 200 | { |
| 201 | .callback = dmi_matched, |
| 202 | .ident = "Dell Vostro 3450", |
| 203 | .matches = { |
| 204 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
| 205 | DMI_MATCH(DMI_PRODUCT_NAME, "Dell System Vostro 3450"), |
| 206 | }, |
| 207 | .driver_data = &quirk_dell_vostro_v130, |
| 208 | }, |
AceLan Kao | 5f1e88f | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 209 | { |
| 210 | .callback = dmi_matched, |
| 211 | .ident = "Dell Inspiron 5420", |
| 212 | .matches = { |
| 213 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 214 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5420"), |
AceLan Kao | 5f1e88f | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 215 | }, |
| 216 | .driver_data = &quirk_dell_vostro_v130, |
| 217 | }, |
| 218 | { |
| 219 | .callback = dmi_matched, |
| 220 | .ident = "Dell Inspiron 5520", |
| 221 | .matches = { |
| 222 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 223 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5520"), |
AceLan Kao | 5f1e88f | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 224 | }, |
| 225 | .driver_data = &quirk_dell_vostro_v130, |
| 226 | }, |
| 227 | { |
| 228 | .callback = dmi_matched, |
| 229 | .ident = "Dell Inspiron 5720", |
| 230 | .matches = { |
| 231 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 232 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 5720"), |
AceLan Kao | 5f1e88f | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 233 | }, |
| 234 | .driver_data = &quirk_dell_vostro_v130, |
| 235 | }, |
| 236 | { |
| 237 | .callback = dmi_matched, |
| 238 | .ident = "Dell Inspiron 7420", |
| 239 | .matches = { |
| 240 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 241 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7420"), |
AceLan Kao | 5f1e88f | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 242 | }, |
| 243 | .driver_data = &quirk_dell_vostro_v130, |
| 244 | }, |
| 245 | { |
| 246 | .callback = dmi_matched, |
| 247 | .ident = "Dell Inspiron 7520", |
| 248 | .matches = { |
| 249 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 250 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7520"), |
AceLan Kao | 5f1e88f | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 251 | }, |
| 252 | .driver_data = &quirk_dell_vostro_v130, |
| 253 | }, |
| 254 | { |
| 255 | .callback = dmi_matched, |
| 256 | .ident = "Dell Inspiron 7720", |
| 257 | .matches = { |
| 258 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), |
AceLan Kao | a2174ba | 2012-08-06 09:48:58 +0800 | [diff] [blame] | 259 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 7720"), |
AceLan Kao | 5f1e88f | 2012-07-13 16:39:57 +0800 | [diff] [blame] | 260 | }, |
| 261 | .driver_data = &quirk_dell_vostro_v130, |
| 262 | }, |
Martin Nyhus | d62d421 | 2012-03-15 18:25:48 +0100 | [diff] [blame] | 263 | { } |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 264 | }; |
| 265 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 266 | static struct calling_interface_buffer *buffer; |
Ingo Molnar | 94d8f78 | 2010-03-01 09:43:52 -0500 | [diff] [blame] | 267 | static struct page *bufferpage; |
| 268 | static DEFINE_MUTEX(buffer_mutex); |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 269 | |
Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame] | 270 | static int hwswitch_state; |
| 271 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 272 | static void get_buffer(void) |
| 273 | { |
| 274 | mutex_lock(&buffer_mutex); |
| 275 | memset(buffer, 0, sizeof(struct calling_interface_buffer)); |
| 276 | } |
| 277 | |
| 278 | static void release_buffer(void) |
| 279 | { |
| 280 | mutex_unlock(&buffer_mutex); |
| 281 | } |
| 282 | |
Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 283 | static void __init parse_da_table(const struct dmi_header *dm) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 284 | { |
| 285 | /* Final token is a terminator, so we don't want to copy it */ |
| 286 | int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1; |
David Woodhouse | fe9ab00 | 2013-03-14 13:21:00 +0000 | [diff] [blame] | 287 | struct calling_interface_token *new_da_tokens; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 288 | struct calling_interface_structure *table = |
| 289 | container_of(dm, struct calling_interface_structure, header); |
| 290 | |
| 291 | /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least |
| 292 | 6 bytes of entry */ |
| 293 | |
| 294 | if (dm->length < 17) |
| 295 | return; |
| 296 | |
| 297 | da_command_address = table->cmdIOAddress; |
| 298 | da_command_code = table->cmdIOCode; |
| 299 | |
David Woodhouse | fe9ab00 | 2013-03-14 13:21:00 +0000 | [diff] [blame] | 300 | new_da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) * |
| 301 | sizeof(struct calling_interface_token), |
| 302 | GFP_KERNEL); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 303 | |
David Woodhouse | fe9ab00 | 2013-03-14 13:21:00 +0000 | [diff] [blame] | 304 | if (!new_da_tokens) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 305 | return; |
David Woodhouse | fe9ab00 | 2013-03-14 13:21:00 +0000 | [diff] [blame] | 306 | da_tokens = new_da_tokens; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 307 | |
| 308 | memcpy(da_tokens+da_num_tokens, table->tokens, |
| 309 | sizeof(struct calling_interface_token) * tokens); |
| 310 | |
| 311 | da_num_tokens += tokens; |
| 312 | } |
| 313 | |
Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 314 | static void __init find_tokens(const struct dmi_header *dm, void *dummy) |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 315 | { |
| 316 | switch (dm->type) { |
| 317 | case 0xd4: /* Indexed IO */ |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 318 | case 0xd5: /* Protected Area Type 1 */ |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 319 | case 0xd6: /* Protected Area Type 2 */ |
| 320 | break; |
| 321 | case 0xda: /* Calling interface */ |
| 322 | parse_da_table(dm); |
| 323 | break; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | static int find_token_location(int tokenid) |
| 328 | { |
| 329 | int i; |
| 330 | for (i = 0; i < da_num_tokens; i++) { |
| 331 | if (da_tokens[i].tokenID == tokenid) |
| 332 | return da_tokens[i].location; |
| 333 | } |
| 334 | |
| 335 | return -1; |
| 336 | } |
| 337 | |
| 338 | static struct calling_interface_buffer * |
| 339 | dell_send_request(struct calling_interface_buffer *buffer, int class, |
| 340 | int select) |
| 341 | { |
| 342 | struct smi_cmd command; |
| 343 | |
| 344 | command.magic = SMI_CMD_MAGIC; |
| 345 | command.command_address = da_command_address; |
| 346 | command.command_code = da_command_code; |
| 347 | command.ebx = virt_to_phys(buffer); |
| 348 | command.ecx = 0x42534931; |
| 349 | |
| 350 | buffer->class = class; |
| 351 | buffer->select = select; |
| 352 | |
| 353 | dcdbas_smi_request(&command); |
| 354 | |
| 355 | return buffer; |
| 356 | } |
| 357 | |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 358 | static struct dentry *dell_laptop_dir; |
| 359 | |
| 360 | static int dell_debugfs_show(struct seq_file *s, void *data) |
| 361 | { |
| 362 | int status; |
| 363 | |
| 364 | get_buffer(); |
| 365 | dell_send_request(buffer, 17, 11); |
| 366 | status = buffer->output[1]; |
| 367 | release_buffer(); |
| 368 | |
| 369 | seq_printf(s, "status:\t0x%X\n", status); |
| 370 | seq_printf(s, "Bit 0 : Hardware switch supported: %lu\n", |
| 371 | status & BIT(0)); |
| 372 | seq_printf(s, "Bit 1 : Wifi locator supported: %lu\n", |
| 373 | (status & BIT(1)) >> 1); |
| 374 | seq_printf(s, "Bit 2 : Wifi is supported: %lu\n", |
| 375 | (status & BIT(2)) >> 2); |
| 376 | seq_printf(s, "Bit 3 : Bluetooth is supported: %lu\n", |
| 377 | (status & BIT(3)) >> 3); |
| 378 | seq_printf(s, "Bit 4 : WWAN is supported: %lu\n", |
| 379 | (status & BIT(4)) >> 4); |
| 380 | seq_printf(s, "Bit 5 : Wireless keyboard supported: %lu\n", |
| 381 | (status & BIT(5)) >> 5); |
| 382 | seq_printf(s, "Bit 8 : Wifi is installed: %lu\n", |
| 383 | (status & BIT(8)) >> 8); |
| 384 | seq_printf(s, "Bit 9 : Bluetooth is installed: %lu\n", |
| 385 | (status & BIT(9)) >> 9); |
| 386 | seq_printf(s, "Bit 10: WWAN is installed: %lu\n", |
| 387 | (status & BIT(10)) >> 10); |
| 388 | seq_printf(s, "Bit 16: Hardware switch is on: %lu\n", |
| 389 | (status & BIT(16)) >> 16); |
| 390 | seq_printf(s, "Bit 17: Wifi is blocked: %lu\n", |
| 391 | (status & BIT(17)) >> 17); |
| 392 | seq_printf(s, "Bit 18: Bluetooth is blocked: %lu\n", |
| 393 | (status & BIT(18)) >> 18); |
| 394 | seq_printf(s, "Bit 19: WWAN is blocked: %lu\n", |
| 395 | (status & BIT(19)) >> 19); |
| 396 | |
| 397 | seq_printf(s, "\nhwswitch_state:\t0x%X\n", hwswitch_state); |
| 398 | seq_printf(s, "Bit 0 : Wifi controlled by switch: %lu\n", |
| 399 | hwswitch_state & BIT(0)); |
| 400 | seq_printf(s, "Bit 1 : Bluetooth controlled by switch: %lu\n", |
| 401 | (hwswitch_state & BIT(1)) >> 1); |
| 402 | seq_printf(s, "Bit 2 : WWAN controlled by switch: %lu\n", |
| 403 | (hwswitch_state & BIT(2)) >> 2); |
| 404 | seq_printf(s, "Bit 7 : Wireless switch config locked: %lu\n", |
| 405 | (hwswitch_state & BIT(7)) >> 7); |
| 406 | seq_printf(s, "Bit 8 : Wifi locator enabled: %lu\n", |
| 407 | (hwswitch_state & BIT(8)) >> 8); |
| 408 | seq_printf(s, "Bit 15: Wifi locator setting locked: %lu\n", |
| 409 | (hwswitch_state & BIT(15)) >> 15); |
| 410 | |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | static int dell_debugfs_open(struct inode *inode, struct file *file) |
| 415 | { |
| 416 | return single_open(file, dell_debugfs_show, inode->i_private); |
| 417 | } |
| 418 | |
| 419 | static const struct file_operations dell_debugfs_fops = { |
| 420 | .owner = THIS_MODULE, |
| 421 | .open = dell_debugfs_open, |
| 422 | .read = seq_read, |
| 423 | .llseek = seq_lseek, |
| 424 | .release = single_release, |
| 425 | }; |
| 426 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 427 | static int dell_send_intensity(struct backlight_device *bd) |
| 428 | { |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 429 | int ret = 0; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 430 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 431 | get_buffer(); |
| 432 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); |
| 433 | buffer->input[1] = bd->props.brightness; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 434 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 435 | if (buffer->input[0] == -1) { |
| 436 | ret = -ENODEV; |
| 437 | goto out; |
| 438 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 439 | |
| 440 | if (power_supply_is_system_supplied() > 0) |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 441 | dell_send_request(buffer, 1, 2); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 442 | else |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 443 | dell_send_request(buffer, 1, 1); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 444 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 445 | out: |
| 446 | release_buffer(); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | static int dell_get_intensity(struct backlight_device *bd) |
| 451 | { |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 452 | int ret = 0; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 453 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 454 | get_buffer(); |
| 455 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 456 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 457 | if (buffer->input[0] == -1) { |
| 458 | ret = -ENODEV; |
| 459 | goto out; |
| 460 | } |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 461 | |
| 462 | if (power_supply_is_system_supplied() > 0) |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 463 | dell_send_request(buffer, 0, 2); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 464 | else |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 465 | dell_send_request(buffer, 0, 1); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 466 | |
Jose Alonso | b486742 | 2011-07-10 15:46:51 -0300 | [diff] [blame] | 467 | ret = buffer->output[1]; |
| 468 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 469 | out: |
| 470 | release_buffer(); |
Jose Alonso | b486742 | 2011-07-10 15:46:51 -0300 | [diff] [blame] | 471 | return ret; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 472 | } |
| 473 | |
Lionel Debroux | acc2472 | 2010-11-16 14:14:02 +0100 | [diff] [blame] | 474 | static const struct backlight_ops dell_ops = { |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 475 | .get_brightness = dell_get_intensity, |
| 476 | .update_status = dell_send_intensity, |
| 477 | }; |
| 478 | |
Randy Dunlap | 869f8df | 2011-11-16 18:20:51 -0800 | [diff] [blame] | 479 | static void touchpad_led_on(void) |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 480 | { |
| 481 | int command = 0x97; |
| 482 | char data = 1; |
| 483 | i8042_command(&data, command | 1 << 12); |
| 484 | } |
| 485 | |
Randy Dunlap | 869f8df | 2011-11-16 18:20:51 -0800 | [diff] [blame] | 486 | static void touchpad_led_off(void) |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 487 | { |
| 488 | int command = 0x97; |
| 489 | char data = 2; |
| 490 | i8042_command(&data, command | 1 << 12); |
| 491 | } |
| 492 | |
| 493 | static void touchpad_led_set(struct led_classdev *led_cdev, |
| 494 | enum led_brightness value) |
| 495 | { |
| 496 | if (value > 0) |
| 497 | touchpad_led_on(); |
| 498 | else |
| 499 | touchpad_led_off(); |
| 500 | } |
| 501 | |
| 502 | static struct led_classdev touchpad_led = { |
| 503 | .name = "dell-laptop::touchpad", |
| 504 | .brightness_set = touchpad_led_set, |
AceLan Kao | 2d5de9e | 2012-01-17 16:18:06 +0800 | [diff] [blame] | 505 | .flags = LED_CORE_SUSPENDRESUME, |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 506 | }; |
| 507 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 508 | static int touchpad_led_init(struct device *dev) |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 509 | { |
| 510 | return led_classdev_register(dev, &touchpad_led); |
| 511 | } |
| 512 | |
| 513 | static void touchpad_led_exit(void) |
| 514 | { |
| 515 | led_classdev_unregister(&touchpad_led); |
| 516 | } |
| 517 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 518 | static int __init dell_init(void) |
| 519 | { |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 520 | int max_intensity = 0; |
| 521 | int ret; |
| 522 | |
| 523 | if (!dmi_check_system(dell_device_table)) |
| 524 | return -ENODEV; |
| 525 | |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 526 | quirks = NULL; |
| 527 | /* find if this machine support other functions */ |
| 528 | dmi_check_system(dell_quirks); |
| 529 | |
Jean Delvare | e7a19c56 | 2009-03-30 21:46:44 +0200 | [diff] [blame] | 530 | dmi_walk(find_tokens, NULL); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 531 | |
| 532 | if (!da_tokens) { |
Joe Perches | eb88952 | 2011-03-29 15:21:37 -0700 | [diff] [blame] | 533 | pr_info("Unable to find dmi tokens\n"); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 534 | return -ENODEV; |
| 535 | } |
| 536 | |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 537 | ret = platform_driver_register(&platform_driver); |
| 538 | if (ret) |
| 539 | goto fail_platform_driver; |
| 540 | platform_device = platform_device_alloc("dell-laptop", -1); |
| 541 | if (!platform_device) { |
| 542 | ret = -ENOMEM; |
| 543 | goto fail_platform_device1; |
| 544 | } |
| 545 | ret = platform_device_add(platform_device); |
| 546 | if (ret) |
| 547 | goto fail_platform_device2; |
| 548 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 549 | /* |
| 550 | * Allocate buffer below 4GB for SMI data--only 32-bit physical addr |
| 551 | * is passed to SMI handler. |
| 552 | */ |
| 553 | bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32); |
Wei Yongjun | 9f20820 | 2013-05-09 10:03:02 +0800 | [diff] [blame] | 554 | if (!bufferpage) { |
| 555 | ret = -ENOMEM; |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 556 | goto fail_buffer; |
Wei Yongjun | 9f20820 | 2013-05-09 10:03:02 +0800 | [diff] [blame] | 557 | } |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 558 | buffer = page_address(bufferpage); |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 559 | |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 560 | if (quirks && quirks->touchpad_led) |
| 561 | touchpad_led_init(&platform_device->dev); |
| 562 | |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 563 | dell_laptop_dir = debugfs_create_dir("dell_laptop", NULL); |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 564 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 565 | #ifdef CONFIG_ACPI |
| 566 | /* In the event of an ACPI backlight being available, don't |
| 567 | * register the platform controller. |
| 568 | */ |
| 569 | if (acpi_video_backlight_support()) |
| 570 | return 0; |
| 571 | #endif |
| 572 | |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 573 | get_buffer(); |
| 574 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); |
| 575 | if (buffer->input[0] != -1) { |
| 576 | dell_send_request(buffer, 0, 2); |
| 577 | max_intensity = buffer->output[3]; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 578 | } |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 579 | release_buffer(); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 580 | |
| 581 | if (max_intensity) { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 582 | struct backlight_properties props; |
| 583 | memset(&props, 0, sizeof(struct backlight_properties)); |
Matthew Garrett | bb7ca74 | 2011-03-22 16:30:21 -0700 | [diff] [blame] | 584 | props.type = BACKLIGHT_PLATFORM; |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 585 | props.max_brightness = max_intensity; |
| 586 | dell_backlight_device = backlight_device_register("dell_backlight", |
| 587 | &platform_device->dev, |
| 588 | NULL, |
| 589 | &dell_ops, |
| 590 | &props); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 591 | |
| 592 | if (IS_ERR(dell_backlight_device)) { |
| 593 | ret = PTR_ERR(dell_backlight_device); |
| 594 | dell_backlight_device = NULL; |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 595 | goto fail_backlight; |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 596 | } |
| 597 | |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 598 | dell_backlight_device->props.brightness = |
| 599 | dell_get_intensity(dell_backlight_device); |
| 600 | backlight_update_status(dell_backlight_device); |
| 601 | } |
| 602 | |
| 603 | return 0; |
Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 604 | |
| 605 | fail_backlight: |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 606 | free_page((unsigned long)bufferpage); |
| 607 | fail_buffer: |
Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 608 | platform_device_del(platform_device); |
| 609 | fail_platform_device2: |
| 610 | platform_device_put(platform_device); |
| 611 | fail_platform_device1: |
| 612 | platform_driver_unregister(&platform_driver); |
| 613 | fail_platform_driver: |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 614 | kfree(da_tokens); |
| 615 | return ret; |
| 616 | } |
| 617 | |
| 618 | static void __exit dell_exit(void) |
| 619 | { |
Keng-Yu Lin | 037accf | 2010-09-28 11:43:31 +0800 | [diff] [blame] | 620 | debugfs_remove_recursive(dell_laptop_dir); |
AceLan Kao | 2d8b90b | 2011-10-04 16:25:44 +0800 | [diff] [blame] | 621 | if (quirks && quirks->touchpad_led) |
| 622 | touchpad_led_exit(); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 623 | backlight_device_unregister(dell_backlight_device); |
Matthew Garrett | facd61d | 2010-02-09 14:03:04 -0500 | [diff] [blame] | 624 | if (platform_device) { |
Matthew Garrett | 92e00e4 | 2010-03-01 09:46:43 -0500 | [diff] [blame] | 625 | platform_device_unregister(platform_device); |
Matthew Garrett | facd61d | 2010-02-09 14:03:04 -0500 | [diff] [blame] | 626 | platform_driver_unregister(&platform_driver); |
| 627 | } |
Matthew Garrett | e551260 | 2010-02-09 14:05:01 -0500 | [diff] [blame] | 628 | kfree(da_tokens); |
Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 629 | free_page((unsigned long)buffer); |
Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | module_init(dell_init); |
| 633 | module_exit(dell_exit); |
| 634 | |
| 635 | MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); |
| 636 | MODULE_DESCRIPTION("Dell laptop driver"); |
| 637 | MODULE_LICENSE("GPL"); |