| 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 |  | 
|  | 14 | #include <linux/module.h> | 
|  | 15 | #include <linux/kernel.h> | 
|  | 16 | #include <linux/init.h> | 
|  | 17 | #include <linux/platform_device.h> | 
|  | 18 | #include <linux/backlight.h> | 
|  | 19 | #include <linux/err.h> | 
|  | 20 | #include <linux/dmi.h> | 
|  | 21 | #include <linux/io.h> | 
|  | 22 | #include <linux/rfkill.h> | 
|  | 23 | #include <linux/power_supply.h> | 
|  | 24 | #include <linux/acpi.h> | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 25 | #include <linux/mm.h> | 
| Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 26 | #include <linux/i8042.h> | 
| Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> | 
| Len Brown | cad7312 | 2009-01-09 17:23:38 -0500 | [diff] [blame] | 28 | #include "../../firmware/dcdbas.h" | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 29 |  | 
|  | 30 | #define BRIGHTNESS_TOKEN 0x7d | 
|  | 31 |  | 
|  | 32 | /* This structure will be modified by the firmware when we enter | 
|  | 33 | * system management mode, hence the volatiles */ | 
|  | 34 |  | 
|  | 35 | struct calling_interface_buffer { | 
|  | 36 | u16 class; | 
|  | 37 | u16 select; | 
|  | 38 | volatile u32 input[4]; | 
|  | 39 | volatile u32 output[4]; | 
|  | 40 | } __packed; | 
|  | 41 |  | 
|  | 42 | struct calling_interface_token { | 
|  | 43 | u16 tokenID; | 
|  | 44 | u16 location; | 
|  | 45 | union { | 
|  | 46 | u16 value; | 
|  | 47 | u16 stringlength; | 
|  | 48 | }; | 
|  | 49 | }; | 
|  | 50 |  | 
|  | 51 | struct calling_interface_structure { | 
|  | 52 | struct dmi_header header; | 
|  | 53 | u16 cmdIOAddress; | 
|  | 54 | u8 cmdIOCode; | 
|  | 55 | u32 supportedCmds; | 
|  | 56 | struct calling_interface_token tokens[]; | 
|  | 57 | } __packed; | 
|  | 58 |  | 
|  | 59 | static int da_command_address; | 
|  | 60 | static int da_command_code; | 
|  | 61 | static int da_num_tokens; | 
|  | 62 | static struct calling_interface_token *da_tokens; | 
|  | 63 |  | 
| Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 64 | static struct platform_driver platform_driver = { | 
|  | 65 | .driver = { | 
|  | 66 | .name = "dell-laptop", | 
|  | 67 | .owner = THIS_MODULE, | 
|  | 68 | } | 
|  | 69 | }; | 
|  | 70 |  | 
|  | 71 | static struct platform_device *platform_device; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 72 | static struct backlight_device *dell_backlight_device; | 
|  | 73 | static struct rfkill *wifi_rfkill; | 
|  | 74 | static struct rfkill *bluetooth_rfkill; | 
|  | 75 | static struct rfkill *wwan_rfkill; | 
|  | 76 |  | 
|  | 77 | static const struct dmi_system_id __initdata dell_device_table[] = { | 
|  | 78 | { | 
|  | 79 | .ident = "Dell laptop", | 
|  | 80 | .matches = { | 
|  | 81 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | 
|  | 82 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), | 
|  | 83 | }, | 
|  | 84 | }, | 
| Erik Andren | cb6a793 | 2010-02-14 11:53:23 -0500 | [diff] [blame] | 85 | { | 
|  | 86 | .ident = "Dell Computer Corporation", | 
|  | 87 | .matches = { | 
|  | 88 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"), | 
|  | 89 | DMI_MATCH(DMI_CHASSIS_TYPE, "8"), | 
|  | 90 | }, | 
|  | 91 | }, | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 92 | { } | 
|  | 93 | }; | 
|  | 94 |  | 
| Mario Limonciello | e5fefd0 | 2010-02-09 17:41:03 -0500 | [diff] [blame] | 95 | static struct dmi_system_id __devinitdata dell_blacklist[] = { | 
|  | 96 | /* Supported by compal-laptop */ | 
|  | 97 | { | 
|  | 98 | .ident = "Dell Mini 9", | 
|  | 99 | .matches = { | 
|  | 100 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | 
|  | 101 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 910"), | 
|  | 102 | }, | 
|  | 103 | }, | 
|  | 104 | { | 
|  | 105 | .ident = "Dell Mini 10", | 
|  | 106 | .matches = { | 
|  | 107 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | 
|  | 108 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1010"), | 
|  | 109 | }, | 
|  | 110 | }, | 
|  | 111 | { | 
|  | 112 | .ident = "Dell Mini 10v", | 
|  | 113 | .matches = { | 
|  | 114 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | 
|  | 115 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1011"), | 
|  | 116 | }, | 
|  | 117 | }, | 
|  | 118 | { | 
|  | 119 | .ident = "Dell Inspiron 11z", | 
|  | 120 | .matches = { | 
|  | 121 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | 
|  | 122 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1110"), | 
|  | 123 | }, | 
|  | 124 | }, | 
|  | 125 | { | 
|  | 126 | .ident = "Dell Mini 12", | 
|  | 127 | .matches = { | 
|  | 128 | DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), | 
|  | 129 | DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 1210"), | 
|  | 130 | }, | 
|  | 131 | }, | 
|  | 132 | {} | 
|  | 133 | }; | 
|  | 134 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 135 | static struct calling_interface_buffer *buffer; | 
| Ingo Molnar | 94d8f78 | 2010-03-01 09:43:52 -0500 | [diff] [blame] | 136 | static struct page *bufferpage; | 
|  | 137 | static DEFINE_MUTEX(buffer_mutex); | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 138 |  | 
| Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame] | 139 | static int hwswitch_state; | 
|  | 140 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 141 | static void get_buffer(void) | 
|  | 142 | { | 
|  | 143 | mutex_lock(&buffer_mutex); | 
|  | 144 | memset(buffer, 0, sizeof(struct calling_interface_buffer)); | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | static void release_buffer(void) | 
|  | 148 | { | 
|  | 149 | mutex_unlock(&buffer_mutex); | 
|  | 150 | } | 
|  | 151 |  | 
| Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 152 | static void __init parse_da_table(const struct dmi_header *dm) | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 153 | { | 
|  | 154 | /* Final token is a terminator, so we don't want to copy it */ | 
|  | 155 | int tokens = (dm->length-11)/sizeof(struct calling_interface_token)-1; | 
|  | 156 | struct calling_interface_structure *table = | 
|  | 157 | container_of(dm, struct calling_interface_structure, header); | 
|  | 158 |  | 
|  | 159 | /* 4 bytes of table header, plus 7 bytes of Dell header, plus at least | 
|  | 160 | 6 bytes of entry */ | 
|  | 161 |  | 
|  | 162 | if (dm->length < 17) | 
|  | 163 | return; | 
|  | 164 |  | 
|  | 165 | da_command_address = table->cmdIOAddress; | 
|  | 166 | da_command_code = table->cmdIOCode; | 
|  | 167 |  | 
|  | 168 | da_tokens = krealloc(da_tokens, (da_num_tokens + tokens) * | 
|  | 169 | sizeof(struct calling_interface_token), | 
|  | 170 | GFP_KERNEL); | 
|  | 171 |  | 
|  | 172 | if (!da_tokens) | 
|  | 173 | return; | 
|  | 174 |  | 
|  | 175 | memcpy(da_tokens+da_num_tokens, table->tokens, | 
|  | 176 | sizeof(struct calling_interface_token) * tokens); | 
|  | 177 |  | 
|  | 178 | da_num_tokens += tokens; | 
|  | 179 | } | 
|  | 180 |  | 
| Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 181 | static void __init find_tokens(const struct dmi_header *dm, void *dummy) | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 182 | { | 
|  | 183 | switch (dm->type) { | 
|  | 184 | case 0xd4: /* Indexed IO */ | 
|  | 185 | break; | 
|  | 186 | case 0xd5: /* Protected Area Type 1 */ | 
|  | 187 | break; | 
|  | 188 | case 0xd6: /* Protected Area Type 2 */ | 
|  | 189 | break; | 
|  | 190 | case 0xda: /* Calling interface */ | 
|  | 191 | parse_da_table(dm); | 
|  | 192 | break; | 
|  | 193 | } | 
|  | 194 | } | 
|  | 195 |  | 
|  | 196 | static int find_token_location(int tokenid) | 
|  | 197 | { | 
|  | 198 | int i; | 
|  | 199 | for (i = 0; i < da_num_tokens; i++) { | 
|  | 200 | if (da_tokens[i].tokenID == tokenid) | 
|  | 201 | return da_tokens[i].location; | 
|  | 202 | } | 
|  | 203 |  | 
|  | 204 | return -1; | 
|  | 205 | } | 
|  | 206 |  | 
|  | 207 | static struct calling_interface_buffer * | 
|  | 208 | dell_send_request(struct calling_interface_buffer *buffer, int class, | 
|  | 209 | int select) | 
|  | 210 | { | 
|  | 211 | struct smi_cmd command; | 
|  | 212 |  | 
|  | 213 | command.magic = SMI_CMD_MAGIC; | 
|  | 214 | command.command_address = da_command_address; | 
|  | 215 | command.command_code = da_command_code; | 
|  | 216 | command.ebx = virt_to_phys(buffer); | 
|  | 217 | command.ecx = 0x42534931; | 
|  | 218 |  | 
|  | 219 | buffer->class = class; | 
|  | 220 | buffer->select = select; | 
|  | 221 |  | 
|  | 222 | dcdbas_smi_request(&command); | 
|  | 223 |  | 
|  | 224 | return buffer; | 
|  | 225 | } | 
|  | 226 |  | 
|  | 227 | /* Derived from information in DellWirelessCtl.cpp: | 
|  | 228 | Class 17, select 11 is radio control. It returns an array of 32-bit values. | 
|  | 229 |  | 
| Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame] | 230 | Input byte 0 = 0: Wireless information | 
|  | 231 |  | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 232 | result[0]: return code | 
|  | 233 | result[1]: | 
|  | 234 | Bit 0:      Hardware switch supported | 
|  | 235 | Bit 1:      Wifi locator supported | 
|  | 236 | Bit 2:      Wifi is supported | 
|  | 237 | Bit 3:      Bluetooth is supported | 
|  | 238 | Bit 4:      WWAN is supported | 
|  | 239 | Bit 5:      Wireless keyboard supported | 
|  | 240 | Bits 6-7:   Reserved | 
|  | 241 | Bit 8:      Wifi is installed | 
|  | 242 | Bit 9:      Bluetooth is installed | 
|  | 243 | Bit 10:     WWAN is installed | 
|  | 244 | Bits 11-15: Reserved | 
|  | 245 | Bit 16:     Hardware switch is on | 
|  | 246 | Bit 17:     Wifi is blocked | 
|  | 247 | Bit 18:     Bluetooth is blocked | 
|  | 248 | Bit 19:     WWAN is blocked | 
|  | 249 | Bits 20-31: Reserved | 
|  | 250 | result[2]: NVRAM size in bytes | 
|  | 251 | result[3]: NVRAM format version number | 
| Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame] | 252 |  | 
|  | 253 | Input byte 0 = 2: Wireless switch configuration | 
|  | 254 | result[0]: return code | 
|  | 255 | result[1]: | 
|  | 256 | Bit 0:      Wifi controlled by switch | 
|  | 257 | Bit 1:      Bluetooth controlled by switch | 
|  | 258 | Bit 2:      WWAN controlled by switch | 
|  | 259 | Bits 3-6:   Reserved | 
|  | 260 | Bit 7:      Wireless switch config locked | 
|  | 261 | Bit 8:      Wifi locator enabled | 
|  | 262 | Bits 9-14:  Reserved | 
|  | 263 | Bit 15:     Wifi locator setting locked | 
|  | 264 | Bits 16-31: Reserved | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 265 | */ | 
|  | 266 |  | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 267 | static int dell_rfkill_set(void *data, bool blocked) | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 268 | { | 
| Johannes Berg | 624f0de | 2009-06-15 16:26:47 +0200 | [diff] [blame] | 269 | int disable = blocked ? 1 : 0; | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 270 | unsigned long radio = (unsigned long)data; | 
| Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame] | 271 | int hwswitch_bit = (unsigned long)data - 1; | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 272 | int ret = 0; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 273 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 274 | get_buffer(); | 
|  | 275 | dell_send_request(buffer, 17, 11); | 
| Mario Limonciello | ec1722a | 2010-02-09 14:11:05 -0500 | [diff] [blame] | 276 |  | 
| Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame] | 277 | /* If the hardware switch controls this radio, and the hardware | 
|  | 278 | switch is disabled, don't allow changing the software state */ | 
|  | 279 | if ((hwswitch_state & BIT(hwswitch_bit)) && | 
|  | 280 | !(buffer->output[1] & BIT(16))) { | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 281 | ret = -EINVAL; | 
|  | 282 | goto out; | 
|  | 283 | } | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 284 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 285 | buffer->input[0] = (1 | (radio<<8) | (disable << 16)); | 
|  | 286 | dell_send_request(buffer, 17, 11); | 
|  | 287 |  | 
|  | 288 | out: | 
|  | 289 | release_buffer(); | 
|  | 290 | return ret; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 291 | } | 
|  | 292 |  | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 293 | static void dell_rfkill_query(struct rfkill *rfkill, void *data) | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 294 | { | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 295 | int status; | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 296 | int bit = (unsigned long)data + 16; | 
| Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame] | 297 | int hwswitch_bit = (unsigned long)data - 1; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 298 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 299 | get_buffer(); | 
|  | 300 | dell_send_request(buffer, 17, 11); | 
|  | 301 | status = buffer->output[1]; | 
|  | 302 | release_buffer(); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 303 |  | 
| Matthew Garrett | e1fbf34 | 2009-07-31 03:25:38 +0100 | [diff] [blame] | 304 | rfkill_set_sw_state(rfkill, !!(status & BIT(bit))); | 
| Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame] | 305 |  | 
|  | 306 | if (hwswitch_state & (BIT(hwswitch_bit))) | 
|  | 307 | rfkill_set_hw_state(rfkill, !(status & BIT(16))); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 308 | } | 
|  | 309 |  | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 310 | static const struct rfkill_ops dell_rfkill_ops = { | 
|  | 311 | .set_block = dell_rfkill_set, | 
|  | 312 | .query = dell_rfkill_query, | 
|  | 313 | }; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 314 |  | 
| Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 315 | static void dell_update_rfkill(struct work_struct *ignored) | 
|  | 316 | { | 
|  | 317 | if (wifi_rfkill) | 
|  | 318 | dell_rfkill_query(wifi_rfkill, (void *)1); | 
|  | 319 | if (bluetooth_rfkill) | 
|  | 320 | dell_rfkill_query(bluetooth_rfkill, (void *)2); | 
|  | 321 | if (wwan_rfkill) | 
|  | 322 | dell_rfkill_query(wwan_rfkill, (void *)3); | 
|  | 323 | } | 
|  | 324 | static DECLARE_DELAYED_WORK(dell_rfkill_work, dell_update_rfkill); | 
|  | 325 |  | 
|  | 326 |  | 
| Alan Jenkins | 4788df4 | 2009-08-19 15:06:50 +0100 | [diff] [blame] | 327 | static int __init dell_setup_rfkill(void) | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 328 | { | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 329 | int status; | 
|  | 330 | int ret; | 
|  | 331 |  | 
| Mario Limonciello | e5fefd0 | 2010-02-09 17:41:03 -0500 | [diff] [blame] | 332 | if (dmi_check_system(dell_blacklist)) { | 
|  | 333 | printk(KERN_INFO "dell-laptop: Blacklisted hardware detected - " | 
|  | 334 | "not enabling rfkill\n"); | 
|  | 335 | return 0; | 
|  | 336 | } | 
|  | 337 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 338 | get_buffer(); | 
|  | 339 | dell_send_request(buffer, 17, 11); | 
|  | 340 | status = buffer->output[1]; | 
| Matthew Garrett | c6760ac | 2010-02-10 14:44:03 -0500 | [diff] [blame] | 341 | buffer->input[0] = 0x2; | 
|  | 342 | dell_send_request(buffer, 17, 11); | 
|  | 343 | hwswitch_state = buffer->output[1]; | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 344 | release_buffer(); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 345 |  | 
|  | 346 | if ((status & (1<<2|1<<8)) == (1<<2|1<<8)) { | 
| Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 347 | wifi_rfkill = rfkill_alloc("dell-wifi", &platform_device->dev, | 
|  | 348 | RFKILL_TYPE_WLAN, | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 349 | &dell_rfkill_ops, (void *) 1); | 
|  | 350 | if (!wifi_rfkill) { | 
|  | 351 | ret = -ENOMEM; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 352 | goto err_wifi; | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 353 | } | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 354 | ret = rfkill_register(wifi_rfkill); | 
|  | 355 | if (ret) | 
|  | 356 | goto err_wifi; | 
|  | 357 | } | 
|  | 358 |  | 
|  | 359 | if ((status & (1<<3|1<<9)) == (1<<3|1<<9)) { | 
| Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 360 | bluetooth_rfkill = rfkill_alloc("dell-bluetooth", | 
|  | 361 | &platform_device->dev, | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 362 | RFKILL_TYPE_BLUETOOTH, | 
|  | 363 | &dell_rfkill_ops, (void *) 2); | 
|  | 364 | if (!bluetooth_rfkill) { | 
|  | 365 | ret = -ENOMEM; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 366 | goto err_bluetooth; | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 367 | } | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 368 | ret = rfkill_register(bluetooth_rfkill); | 
|  | 369 | if (ret) | 
|  | 370 | goto err_bluetooth; | 
|  | 371 | } | 
|  | 372 |  | 
|  | 373 | if ((status & (1<<4|1<<10)) == (1<<4|1<<10)) { | 
| Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 374 | wwan_rfkill = rfkill_alloc("dell-wwan", | 
|  | 375 | &platform_device->dev, | 
|  | 376 | RFKILL_TYPE_WWAN, | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 377 | &dell_rfkill_ops, (void *) 3); | 
|  | 378 | if (!wwan_rfkill) { | 
|  | 379 | ret = -ENOMEM; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 380 | goto err_wwan; | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 381 | } | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 382 | ret = rfkill_register(wwan_rfkill); | 
|  | 383 | if (ret) | 
|  | 384 | goto err_wwan; | 
|  | 385 | } | 
|  | 386 |  | 
|  | 387 | return 0; | 
|  | 388 | err_wwan: | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 389 | rfkill_destroy(wwan_rfkill); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 390 | if (bluetooth_rfkill) | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 391 | rfkill_unregister(bluetooth_rfkill); | 
|  | 392 | err_bluetooth: | 
|  | 393 | rfkill_destroy(bluetooth_rfkill); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 394 | if (wifi_rfkill) | 
| Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 395 | rfkill_unregister(wifi_rfkill); | 
|  | 396 | err_wifi: | 
|  | 397 | rfkill_destroy(wifi_rfkill); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 398 |  | 
|  | 399 | return ret; | 
|  | 400 | } | 
|  | 401 |  | 
| Alan Jenkins | 4311bb2 | 2009-08-19 15:06:48 +0100 | [diff] [blame] | 402 | static void dell_cleanup_rfkill(void) | 
|  | 403 | { | 
|  | 404 | if (wifi_rfkill) { | 
|  | 405 | rfkill_unregister(wifi_rfkill); | 
|  | 406 | rfkill_destroy(wifi_rfkill); | 
|  | 407 | } | 
|  | 408 | if (bluetooth_rfkill) { | 
|  | 409 | rfkill_unregister(bluetooth_rfkill); | 
|  | 410 | rfkill_destroy(bluetooth_rfkill); | 
|  | 411 | } | 
|  | 412 | if (wwan_rfkill) { | 
|  | 413 | rfkill_unregister(wwan_rfkill); | 
|  | 414 | rfkill_destroy(wwan_rfkill); | 
|  | 415 | } | 
|  | 416 | } | 
|  | 417 |  | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 418 | static int dell_send_intensity(struct backlight_device *bd) | 
|  | 419 | { | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 420 | int ret = 0; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 421 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 422 | get_buffer(); | 
|  | 423 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); | 
|  | 424 | buffer->input[1] = bd->props.brightness; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 425 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 426 | if (buffer->input[0] == -1) { | 
|  | 427 | ret = -ENODEV; | 
|  | 428 | goto out; | 
|  | 429 | } | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 430 |  | 
|  | 431 | if (power_supply_is_system_supplied() > 0) | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 432 | dell_send_request(buffer, 1, 2); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 433 | else | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 434 | dell_send_request(buffer, 1, 1); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 435 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 436 | out: | 
|  | 437 | release_buffer(); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 438 | return 0; | 
|  | 439 | } | 
|  | 440 |  | 
|  | 441 | static int dell_get_intensity(struct backlight_device *bd) | 
|  | 442 | { | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 443 | int ret = 0; | 
| 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 | get_buffer(); | 
|  | 446 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 447 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 448 | if (buffer->input[0] == -1) { | 
|  | 449 | ret = -ENODEV; | 
|  | 450 | goto out; | 
|  | 451 | } | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 452 |  | 
|  | 453 | if (power_supply_is_system_supplied() > 0) | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 454 | dell_send_request(buffer, 0, 2); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 455 | else | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 456 | dell_send_request(buffer, 0, 1); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 457 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 458 | out: | 
|  | 459 | release_buffer(); | 
|  | 460 | if (ret) | 
|  | 461 | return ret; | 
|  | 462 | return buffer->output[1]; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 463 | } | 
|  | 464 |  | 
|  | 465 | static struct backlight_ops dell_ops = { | 
|  | 466 | .get_brightness = dell_get_intensity, | 
|  | 467 | .update_status  = dell_send_intensity, | 
|  | 468 | }; | 
|  | 469 |  | 
| Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 470 | bool dell_laptop_i8042_filter(unsigned char data, unsigned char str, | 
|  | 471 | struct serio *port) | 
|  | 472 | { | 
|  | 473 | static bool extended; | 
|  | 474 |  | 
|  | 475 | if (str & 0x20) | 
|  | 476 | return false; | 
|  | 477 |  | 
|  | 478 | if (unlikely(data == 0xe0)) { | 
|  | 479 | extended = true; | 
|  | 480 | return false; | 
|  | 481 | } else if (unlikely(extended)) { | 
|  | 482 | switch (data) { | 
|  | 483 | case 0x8: | 
|  | 484 | schedule_delayed_work(&dell_rfkill_work, | 
|  | 485 | round_jiffies_relative(HZ)); | 
|  | 486 | break; | 
|  | 487 | } | 
|  | 488 | extended = false; | 
|  | 489 | } | 
|  | 490 |  | 
|  | 491 | return false; | 
|  | 492 | } | 
|  | 493 |  | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 494 | static int __init dell_init(void) | 
|  | 495 | { | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 496 | int max_intensity = 0; | 
|  | 497 | int ret; | 
|  | 498 |  | 
|  | 499 | if (!dmi_check_system(dell_device_table)) | 
|  | 500 | return -ENODEV; | 
|  | 501 |  | 
| Jean Delvare | e7a19c5 | 2009-03-30 21:46:44 +0200 | [diff] [blame] | 502 | dmi_walk(find_tokens, NULL); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 503 |  | 
|  | 504 | if (!da_tokens)  { | 
|  | 505 | printk(KERN_INFO "dell-laptop: Unable to find dmi tokens\n"); | 
|  | 506 | return -ENODEV; | 
|  | 507 | } | 
|  | 508 |  | 
| Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 509 | ret = platform_driver_register(&platform_driver); | 
|  | 510 | if (ret) | 
|  | 511 | goto fail_platform_driver; | 
|  | 512 | platform_device = platform_device_alloc("dell-laptop", -1); | 
|  | 513 | if (!platform_device) { | 
|  | 514 | ret = -ENOMEM; | 
|  | 515 | goto fail_platform_device1; | 
|  | 516 | } | 
|  | 517 | ret = platform_device_add(platform_device); | 
|  | 518 | if (ret) | 
|  | 519 | goto fail_platform_device2; | 
|  | 520 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 521 | /* | 
|  | 522 | * Allocate buffer below 4GB for SMI data--only 32-bit physical addr | 
|  | 523 | * is passed to SMI handler. | 
|  | 524 | */ | 
|  | 525 | bufferpage = alloc_page(GFP_KERNEL | GFP_DMA32); | 
|  | 526 |  | 
|  | 527 | if (!bufferpage) | 
|  | 528 | goto fail_buffer; | 
|  | 529 | buffer = page_address(bufferpage); | 
|  | 530 | mutex_init(&buffer_mutex); | 
|  | 531 |  | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 532 | ret = dell_setup_rfkill(); | 
|  | 533 |  | 
|  | 534 | if (ret) { | 
|  | 535 | printk(KERN_WARNING "dell-laptop: Unable to setup rfkill\n"); | 
| Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 536 | goto fail_rfkill; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 537 | } | 
|  | 538 |  | 
| Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 539 | ret = i8042_install_filter(dell_laptop_i8042_filter); | 
|  | 540 | if (ret) { | 
|  | 541 | printk(KERN_WARNING | 
|  | 542 | "dell-laptop: Unable to install key filter\n"); | 
|  | 543 | goto fail_filter; | 
|  | 544 | } | 
|  | 545 |  | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 546 | #ifdef CONFIG_ACPI | 
|  | 547 | /* In the event of an ACPI backlight being available, don't | 
|  | 548 | * register the platform controller. | 
|  | 549 | */ | 
|  | 550 | if (acpi_video_backlight_support()) | 
|  | 551 | return 0; | 
|  | 552 | #endif | 
|  | 553 |  | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 554 | get_buffer(); | 
|  | 555 | buffer->input[0] = find_token_location(BRIGHTNESS_TOKEN); | 
|  | 556 | if (buffer->input[0] != -1) { | 
|  | 557 | dell_send_request(buffer, 0, 2); | 
|  | 558 | max_intensity = buffer->output[3]; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 559 | } | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 560 | release_buffer(); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 561 |  | 
|  | 562 | if (max_intensity) { | 
| Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 563 | struct backlight_properties props; | 
|  | 564 | memset(&props, 0, sizeof(struct backlight_properties)); | 
|  | 565 | props.max_brightness = max_intensity; | 
|  | 566 | dell_backlight_device = backlight_device_register("dell_backlight", | 
|  | 567 | &platform_device->dev, | 
|  | 568 | NULL, | 
|  | 569 | &dell_ops, | 
|  | 570 | &props); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 571 |  | 
|  | 572 | if (IS_ERR(dell_backlight_device)) { | 
|  | 573 | ret = PTR_ERR(dell_backlight_device); | 
|  | 574 | dell_backlight_device = NULL; | 
| Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 575 | goto fail_backlight; | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 576 | } | 
|  | 577 |  | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 578 | dell_backlight_device->props.brightness = | 
|  | 579 | dell_get_intensity(dell_backlight_device); | 
|  | 580 | backlight_update_status(dell_backlight_device); | 
|  | 581 | } | 
|  | 582 |  | 
|  | 583 | return 0; | 
| Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 584 |  | 
|  | 585 | fail_backlight: | 
| Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 586 | i8042_remove_filter(dell_laptop_i8042_filter); | 
| Matthew Garrett | 92e00e4 | 2010-03-01 09:46:43 -0500 | [diff] [blame] | 587 | cancel_delayed_work_sync(&dell_rfkill_work); | 
| Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 588 | fail_filter: | 
| Alan Jenkins | 4311bb2 | 2009-08-19 15:06:48 +0100 | [diff] [blame] | 589 | dell_cleanup_rfkill(); | 
| Alan Jenkins | 71e9dc7 | 2009-08-19 15:06:47 +0100 | [diff] [blame] | 590 | fail_rfkill: | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 591 | free_page((unsigned long)bufferpage); | 
|  | 592 | fail_buffer: | 
| Alan Jenkins | ada3248 | 2009-08-19 15:06:49 +0100 | [diff] [blame] | 593 | platform_device_del(platform_device); | 
|  | 594 | fail_platform_device2: | 
|  | 595 | platform_device_put(platform_device); | 
|  | 596 | fail_platform_device1: | 
|  | 597 | platform_driver_unregister(&platform_driver); | 
|  | 598 | fail_platform_driver: | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 599 | kfree(da_tokens); | 
|  | 600 | return ret; | 
|  | 601 | } | 
|  | 602 |  | 
|  | 603 | static void __exit dell_exit(void) | 
|  | 604 | { | 
| Matthew Garrett | 814cb8a | 2009-12-09 18:23:36 +0000 | [diff] [blame] | 605 | i8042_remove_filter(dell_laptop_i8042_filter); | 
| Matthew Garrett | 92e00e4 | 2010-03-01 09:46:43 -0500 | [diff] [blame] | 606 | cancel_delayed_work_sync(&dell_rfkill_work); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 607 | backlight_device_unregister(dell_backlight_device); | 
| Alan Jenkins | 4311bb2 | 2009-08-19 15:06:48 +0100 | [diff] [blame] | 608 | dell_cleanup_rfkill(); | 
| Matthew Garrett | facd61d | 2010-02-09 14:03:04 -0500 | [diff] [blame] | 609 | if (platform_device) { | 
| Matthew Garrett | 92e00e4 | 2010-03-01 09:46:43 -0500 | [diff] [blame] | 610 | platform_device_unregister(platform_device); | 
| Matthew Garrett | facd61d | 2010-02-09 14:03:04 -0500 | [diff] [blame] | 611 | platform_driver_unregister(&platform_driver); | 
|  | 612 | } | 
| Matthew Garrett | e551260 | 2010-02-09 14:05:01 -0500 | [diff] [blame] | 613 | kfree(da_tokens); | 
| Stuart Hayes | 116ee77 | 2010-02-10 14:12:13 -0500 | [diff] [blame] | 614 | free_page((unsigned long)buffer); | 
| Matthew Garrett | ad8f07c | 2009-01-07 18:08:56 -0800 | [diff] [blame] | 615 | } | 
|  | 616 |  | 
|  | 617 | module_init(dell_init); | 
|  | 618 | module_exit(dell_exit); | 
|  | 619 |  | 
|  | 620 | MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); | 
|  | 621 | MODULE_DESCRIPTION("Dell laptop driver"); | 
|  | 622 | MODULE_LICENSE("GPL"); | 
|  | 623 | MODULE_ALIAS("dmi:*svnDellInc.:*:ct8:*"); | 
| Erik Andren | cb6a793 | 2010-02-14 11:53:23 -0500 | [diff] [blame] | 624 | MODULE_ALIAS("dmi:*svnDellComputerCorporation.:*:ct8:*"); |