Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Acer WMI Laptop Extras |
| 3 | * |
| 4 | * Copyright (C) 2007-2008 Carlos Corbacho <carlos@strangeworlds.co.uk> |
| 5 | * |
| 6 | * Based on acer_acpi: |
| 7 | * Copyright (C) 2005-2007 E.M. Smith |
| 8 | * Copyright (C) 2007-2008 Carlos Corbacho <cathectic@gmail.com> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #define ACER_WMI_VERSION "0.1" |
| 26 | |
| 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/types.h> |
| 31 | #include <linux/dmi.h> |
| 32 | #include <linux/backlight.h> |
| 33 | #include <linux/leds.h> |
| 34 | #include <linux/platform_device.h> |
| 35 | #include <linux/acpi.h> |
| 36 | #include <linux/i8042.h> |
| 37 | |
| 38 | #include <acpi/acpi_drivers.h> |
| 39 | |
| 40 | MODULE_AUTHOR("Carlos Corbacho"); |
| 41 | MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver"); |
| 42 | MODULE_LICENSE("GPL"); |
| 43 | |
| 44 | #define ACER_LOGPREFIX "acer-wmi: " |
| 45 | #define ACER_ERR KERN_ERR ACER_LOGPREFIX |
| 46 | #define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX |
| 47 | #define ACER_INFO KERN_INFO ACER_LOGPREFIX |
| 48 | |
| 49 | /* |
| 50 | * The following defines quirks to get some specific functions to work |
| 51 | * which are known to not be supported over ACPI-WMI (such as the mail LED |
| 52 | * on WMID based Acer's) |
| 53 | */ |
| 54 | struct acer_quirks { |
| 55 | const char *vendor; |
| 56 | const char *model; |
| 57 | u16 quirks; |
| 58 | }; |
| 59 | |
| 60 | /* |
| 61 | * Magic Number |
| 62 | * Meaning is unknown - this number is required for writing to ACPI for AMW0 |
| 63 | * (it's also used in acerhk when directly accessing the BIOS) |
| 64 | */ |
| 65 | #define ACER_AMW0_WRITE 0x9610 |
| 66 | |
| 67 | /* |
| 68 | * Bit masks for the AMW0 interface |
| 69 | */ |
| 70 | #define ACER_AMW0_WIRELESS_MASK 0x35 |
| 71 | #define ACER_AMW0_BLUETOOTH_MASK 0x34 |
| 72 | #define ACER_AMW0_MAILLED_MASK 0x31 |
| 73 | |
| 74 | /* |
| 75 | * Method IDs for WMID interface |
| 76 | */ |
| 77 | #define ACER_WMID_GET_WIRELESS_METHODID 1 |
| 78 | #define ACER_WMID_GET_BLUETOOTH_METHODID 2 |
| 79 | #define ACER_WMID_GET_BRIGHTNESS_METHODID 3 |
| 80 | #define ACER_WMID_SET_WIRELESS_METHODID 4 |
| 81 | #define ACER_WMID_SET_BLUETOOTH_METHODID 5 |
| 82 | #define ACER_WMID_SET_BRIGHTNESS_METHODID 6 |
| 83 | #define ACER_WMID_GET_THREEG_METHODID 10 |
| 84 | #define ACER_WMID_SET_THREEG_METHODID 11 |
| 85 | |
| 86 | /* |
| 87 | * Acer ACPI method GUIDs |
| 88 | */ |
| 89 | #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB" |
| 90 | #define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3" |
| 91 | #define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A" |
| 92 | |
| 93 | MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB"); |
| 94 | MODULE_ALIAS("wmi:6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"); |
| 95 | |
| 96 | /* Temporary workaround until the WMI sysfs interface goes in */ |
| 97 | MODULE_ALIAS("dmi:*:*Acer*:*:"); |
| 98 | |
| 99 | /* |
| 100 | * Interface capability flags |
| 101 | */ |
| 102 | #define ACER_CAP_MAILLED (1<<0) |
| 103 | #define ACER_CAP_WIRELESS (1<<1) |
| 104 | #define ACER_CAP_BLUETOOTH (1<<2) |
| 105 | #define ACER_CAP_BRIGHTNESS (1<<3) |
| 106 | #define ACER_CAP_THREEG (1<<4) |
| 107 | #define ACER_CAP_ANY (0xFFFFFFFF) |
| 108 | |
| 109 | /* |
| 110 | * Interface type flags |
| 111 | */ |
| 112 | enum interface_flags { |
| 113 | ACER_AMW0, |
| 114 | ACER_AMW0_V2, |
| 115 | ACER_WMID, |
| 116 | }; |
| 117 | |
| 118 | #define ACER_DEFAULT_WIRELESS 0 |
| 119 | #define ACER_DEFAULT_BLUETOOTH 0 |
| 120 | #define ACER_DEFAULT_MAILLED 0 |
| 121 | #define ACER_DEFAULT_THREEG 0 |
| 122 | |
| 123 | static int max_brightness = 0xF; |
| 124 | |
| 125 | static int wireless = -1; |
| 126 | static int bluetooth = -1; |
| 127 | static int mailled = -1; |
| 128 | static int brightness = -1; |
| 129 | static int threeg = -1; |
| 130 | static int force_series; |
| 131 | |
| 132 | module_param(mailled, int, 0444); |
| 133 | module_param(wireless, int, 0444); |
| 134 | module_param(bluetooth, int, 0444); |
| 135 | module_param(brightness, int, 0444); |
| 136 | module_param(threeg, int, 0444); |
| 137 | module_param(force_series, int, 0444); |
| 138 | MODULE_PARM_DESC(wireless, "Set initial state of Wireless hardware"); |
| 139 | MODULE_PARM_DESC(bluetooth, "Set initial state of Bluetooth hardware"); |
| 140 | MODULE_PARM_DESC(mailled, "Set initial state of Mail LED"); |
| 141 | MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness"); |
| 142 | MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware"); |
| 143 | MODULE_PARM_DESC(force_series, "Force a different laptop series"); |
| 144 | |
| 145 | struct acer_data { |
| 146 | int mailled; |
| 147 | int wireless; |
| 148 | int bluetooth; |
| 149 | int threeg; |
| 150 | int brightness; |
| 151 | }; |
| 152 | |
| 153 | /* Each low-level interface must define at least some of the following */ |
| 154 | struct wmi_interface { |
| 155 | /* The WMI device type */ |
| 156 | u32 type; |
| 157 | |
| 158 | /* The capabilities this interface provides */ |
| 159 | u32 capability; |
| 160 | |
| 161 | /* Private data for the current interface */ |
| 162 | struct acer_data data; |
| 163 | }; |
| 164 | |
| 165 | /* The static interface pointer, points to the currently detected interface */ |
| 166 | static struct wmi_interface *interface; |
| 167 | |
| 168 | /* |
| 169 | * Embedded Controller quirks |
| 170 | * Some laptops require us to directly access the EC to either enable or query |
| 171 | * features that are not available through WMI. |
| 172 | */ |
| 173 | |
| 174 | struct quirk_entry { |
| 175 | u8 wireless; |
| 176 | u8 mailled; |
Carlos Corbacho | 9991d9f | 2008-06-21 09:09:22 +0100 | [diff] [blame^] | 177 | s8 brightness; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 178 | u8 bluetooth; |
| 179 | }; |
| 180 | |
| 181 | static struct quirk_entry *quirks; |
| 182 | |
| 183 | static void set_quirks(void) |
| 184 | { |
| 185 | if (quirks->mailled) |
| 186 | interface->capability |= ACER_CAP_MAILLED; |
| 187 | |
| 188 | if (quirks->brightness) |
| 189 | interface->capability |= ACER_CAP_BRIGHTNESS; |
| 190 | } |
| 191 | |
| 192 | static int dmi_matched(const struct dmi_system_id *dmi) |
| 193 | { |
| 194 | quirks = dmi->driver_data; |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | static struct quirk_entry quirk_unknown = { |
| 199 | }; |
| 200 | |
Carlos Corbacho | 9991d9f | 2008-06-21 09:09:22 +0100 | [diff] [blame^] | 201 | static struct quirk_entry quirk_acer_aspire_1520 = { |
| 202 | .brightness = -1, |
| 203 | }; |
| 204 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 205 | static struct quirk_entry quirk_acer_travelmate_2490 = { |
| 206 | .mailled = 1, |
| 207 | }; |
| 208 | |
| 209 | /* This AMW0 laptop has no bluetooth */ |
| 210 | static struct quirk_entry quirk_medion_md_98300 = { |
| 211 | .wireless = 1, |
| 212 | }; |
| 213 | |
| 214 | static struct dmi_system_id acer_quirks[] = { |
| 215 | { |
| 216 | .callback = dmi_matched, |
Carlos Corbacho | 9991d9f | 2008-06-21 09:09:22 +0100 | [diff] [blame^] | 217 | .ident = "Acer Aspire 1360", |
| 218 | .matches = { |
| 219 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 220 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"), |
| 221 | }, |
| 222 | .driver_data = &quirk_acer_aspire_1520, |
| 223 | }, |
| 224 | { |
| 225 | .callback = dmi_matched, |
| 226 | .ident = "Acer Aspire 1520", |
| 227 | .matches = { |
| 228 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 229 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"), |
| 230 | }, |
| 231 | .driver_data = &quirk_acer_aspire_1520, |
| 232 | }, |
| 233 | { |
| 234 | .callback = dmi_matched, |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 235 | .ident = "Acer Aspire 3100", |
| 236 | .matches = { |
| 237 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 238 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"), |
| 239 | }, |
| 240 | .driver_data = &quirk_acer_travelmate_2490, |
| 241 | }, |
| 242 | { |
| 243 | .callback = dmi_matched, |
Carlos Corbacho | ed9cfe9 | 2008-03-12 20:13:00 +0000 | [diff] [blame] | 244 | .ident = "Acer Aspire 3610", |
| 245 | .matches = { |
| 246 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 247 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"), |
| 248 | }, |
| 249 | .driver_data = &quirk_acer_travelmate_2490, |
| 250 | }, |
| 251 | { |
| 252 | .callback = dmi_matched, |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 253 | .ident = "Acer Aspire 5100", |
| 254 | .matches = { |
| 255 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 256 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"), |
| 257 | }, |
| 258 | .driver_data = &quirk_acer_travelmate_2490, |
| 259 | }, |
| 260 | { |
| 261 | .callback = dmi_matched, |
Carlos Corbacho | ed9cfe9 | 2008-03-12 20:13:00 +0000 | [diff] [blame] | 262 | .ident = "Acer Aspire 5610", |
| 263 | .matches = { |
| 264 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 265 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"), |
| 266 | }, |
| 267 | .driver_data = &quirk_acer_travelmate_2490, |
| 268 | }, |
| 269 | { |
| 270 | .callback = dmi_matched, |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 271 | .ident = "Acer Aspire 5630", |
| 272 | .matches = { |
| 273 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 274 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"), |
| 275 | }, |
| 276 | .driver_data = &quirk_acer_travelmate_2490, |
| 277 | }, |
| 278 | { |
| 279 | .callback = dmi_matched, |
| 280 | .ident = "Acer Aspire 5650", |
| 281 | .matches = { |
| 282 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 283 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"), |
| 284 | }, |
| 285 | .driver_data = &quirk_acer_travelmate_2490, |
| 286 | }, |
| 287 | { |
| 288 | .callback = dmi_matched, |
| 289 | .ident = "Acer Aspire 5680", |
| 290 | .matches = { |
| 291 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 292 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"), |
| 293 | }, |
| 294 | .driver_data = &quirk_acer_travelmate_2490, |
| 295 | }, |
| 296 | { |
| 297 | .callback = dmi_matched, |
| 298 | .ident = "Acer Aspire 9110", |
| 299 | .matches = { |
| 300 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 301 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"), |
| 302 | }, |
| 303 | .driver_data = &quirk_acer_travelmate_2490, |
| 304 | }, |
| 305 | { |
| 306 | .callback = dmi_matched, |
| 307 | .ident = "Acer TravelMate 2490", |
| 308 | .matches = { |
| 309 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 310 | DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"), |
| 311 | }, |
| 312 | .driver_data = &quirk_acer_travelmate_2490, |
| 313 | }, |
| 314 | { |
| 315 | .callback = dmi_matched, |
Carlos Corbacho | 262ee35 | 2008-02-16 00:02:56 +0000 | [diff] [blame] | 316 | .ident = "Acer TravelMate 4200", |
| 317 | .matches = { |
| 318 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 319 | DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"), |
| 320 | }, |
| 321 | .driver_data = &quirk_acer_travelmate_2490, |
| 322 | }, |
| 323 | { |
| 324 | .callback = dmi_matched, |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 325 | .ident = "Medion MD 98300", |
| 326 | .matches = { |
| 327 | DMI_MATCH(DMI_SYS_VENDOR, "MEDION"), |
| 328 | DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"), |
| 329 | }, |
| 330 | .driver_data = &quirk_medion_md_98300, |
| 331 | }, |
| 332 | {} |
| 333 | }; |
| 334 | |
| 335 | /* Find which quirks are needed for a particular vendor/ model pair */ |
| 336 | static void find_quirks(void) |
| 337 | { |
| 338 | if (!force_series) { |
| 339 | dmi_check_system(acer_quirks); |
| 340 | } else if (force_series == 2490) { |
| 341 | quirks = &quirk_acer_travelmate_2490; |
| 342 | } |
| 343 | |
| 344 | if (quirks == NULL) |
| 345 | quirks = &quirk_unknown; |
| 346 | |
| 347 | set_quirks(); |
| 348 | } |
| 349 | |
| 350 | /* |
| 351 | * General interface convenience methods |
| 352 | */ |
| 353 | |
| 354 | static bool has_cap(u32 cap) |
| 355 | { |
| 356 | if ((interface->capability & cap) != 0) |
| 357 | return 1; |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * AMW0 (V1) interface |
| 364 | */ |
| 365 | struct wmab_args { |
| 366 | u32 eax; |
| 367 | u32 ebx; |
| 368 | u32 ecx; |
| 369 | u32 edx; |
| 370 | }; |
| 371 | |
| 372 | struct wmab_ret { |
| 373 | u32 eax; |
| 374 | u32 ebx; |
| 375 | u32 ecx; |
| 376 | u32 edx; |
| 377 | u32 eex; |
| 378 | }; |
| 379 | |
| 380 | static acpi_status wmab_execute(struct wmab_args *regbuf, |
| 381 | struct acpi_buffer *result) |
| 382 | { |
| 383 | struct acpi_buffer input; |
| 384 | acpi_status status; |
| 385 | input.length = sizeof(struct wmab_args); |
| 386 | input.pointer = (u8 *)regbuf; |
| 387 | |
| 388 | status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result); |
| 389 | |
| 390 | return status; |
| 391 | } |
| 392 | |
| 393 | static acpi_status AMW0_get_u32(u32 *value, u32 cap, |
| 394 | struct wmi_interface *iface) |
| 395 | { |
| 396 | int err; |
| 397 | u8 result; |
| 398 | |
| 399 | switch (cap) { |
| 400 | case ACER_CAP_MAILLED: |
| 401 | switch (quirks->mailled) { |
| 402 | default: |
| 403 | err = ec_read(0xA, &result); |
| 404 | if (err) |
| 405 | return AE_ERROR; |
| 406 | *value = (result >> 7) & 0x1; |
| 407 | return AE_OK; |
| 408 | } |
| 409 | break; |
| 410 | case ACER_CAP_WIRELESS: |
| 411 | switch (quirks->wireless) { |
| 412 | case 1: |
| 413 | err = ec_read(0x7B, &result); |
| 414 | if (err) |
| 415 | return AE_ERROR; |
| 416 | *value = result & 0x1; |
| 417 | return AE_OK; |
| 418 | default: |
| 419 | err = ec_read(0xA, &result); |
| 420 | if (err) |
| 421 | return AE_ERROR; |
| 422 | *value = (result >> 2) & 0x1; |
| 423 | return AE_OK; |
| 424 | } |
| 425 | break; |
| 426 | case ACER_CAP_BLUETOOTH: |
| 427 | switch (quirks->bluetooth) { |
| 428 | default: |
| 429 | err = ec_read(0xA, &result); |
| 430 | if (err) |
| 431 | return AE_ERROR; |
| 432 | *value = (result >> 4) & 0x1; |
| 433 | return AE_OK; |
| 434 | } |
| 435 | break; |
| 436 | case ACER_CAP_BRIGHTNESS: |
| 437 | switch (quirks->brightness) { |
| 438 | default: |
| 439 | err = ec_read(0x83, &result); |
| 440 | if (err) |
| 441 | return AE_ERROR; |
| 442 | *value = result; |
| 443 | return AE_OK; |
| 444 | } |
| 445 | break; |
| 446 | default: |
| 447 | return AE_BAD_ADDRESS; |
| 448 | } |
| 449 | return AE_OK; |
| 450 | } |
| 451 | |
| 452 | static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface) |
| 453 | { |
| 454 | struct wmab_args args; |
| 455 | |
| 456 | args.eax = ACER_AMW0_WRITE; |
| 457 | args.ebx = value ? (1<<8) : 0; |
| 458 | args.ecx = args.edx = 0; |
| 459 | |
| 460 | switch (cap) { |
| 461 | case ACER_CAP_MAILLED: |
| 462 | if (value > 1) |
| 463 | return AE_BAD_PARAMETER; |
| 464 | args.ebx |= ACER_AMW0_MAILLED_MASK; |
| 465 | break; |
| 466 | case ACER_CAP_WIRELESS: |
| 467 | if (value > 1) |
| 468 | return AE_BAD_PARAMETER; |
| 469 | args.ebx |= ACER_AMW0_WIRELESS_MASK; |
| 470 | break; |
| 471 | case ACER_CAP_BLUETOOTH: |
| 472 | if (value > 1) |
| 473 | return AE_BAD_PARAMETER; |
| 474 | args.ebx |= ACER_AMW0_BLUETOOTH_MASK; |
| 475 | break; |
| 476 | case ACER_CAP_BRIGHTNESS: |
| 477 | if (value > max_brightness) |
| 478 | return AE_BAD_PARAMETER; |
| 479 | switch (quirks->brightness) { |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 480 | default: |
Carlos Corbacho | 4609d02 | 2008-02-08 23:51:49 +0000 | [diff] [blame] | 481 | return ec_write(0x83, value); |
| 482 | break; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 483 | } |
| 484 | default: |
| 485 | return AE_BAD_ADDRESS; |
| 486 | } |
| 487 | |
| 488 | /* Actually do the set */ |
| 489 | return wmab_execute(&args, NULL); |
| 490 | } |
| 491 | |
| 492 | static acpi_status AMW0_find_mailled(void) |
| 493 | { |
| 494 | struct wmab_args args; |
| 495 | struct wmab_ret ret; |
| 496 | acpi_status status = AE_OK; |
| 497 | struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 498 | union acpi_object *obj; |
| 499 | |
| 500 | args.eax = 0x86; |
| 501 | args.ebx = args.ecx = args.edx = 0; |
| 502 | |
| 503 | status = wmab_execute(&args, &out); |
| 504 | if (ACPI_FAILURE(status)) |
| 505 | return status; |
| 506 | |
| 507 | obj = (union acpi_object *) out.pointer; |
| 508 | if (obj && obj->type == ACPI_TYPE_BUFFER && |
| 509 | obj->buffer.length == sizeof(struct wmab_ret)) { |
| 510 | ret = *((struct wmab_ret *) obj->buffer.pointer); |
| 511 | } else { |
| 512 | return AE_ERROR; |
| 513 | } |
| 514 | |
| 515 | if (ret.eex & 0x1) |
| 516 | interface->capability |= ACER_CAP_MAILLED; |
| 517 | |
| 518 | kfree(out.pointer); |
| 519 | |
| 520 | return AE_OK; |
| 521 | } |
| 522 | |
| 523 | static acpi_status AMW0_set_capabilities(void) |
| 524 | { |
| 525 | struct wmab_args args; |
| 526 | struct wmab_ret ret; |
| 527 | acpi_status status = AE_OK; |
| 528 | struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 529 | union acpi_object *obj; |
| 530 | |
| 531 | args.eax = ACER_AMW0_WRITE; |
| 532 | args.ecx = args.edx = 0; |
| 533 | |
| 534 | args.ebx = 0xa2 << 8; |
| 535 | args.ebx |= ACER_AMW0_WIRELESS_MASK; |
| 536 | |
| 537 | status = wmab_execute(&args, &out); |
| 538 | if (ACPI_FAILURE(status)) |
| 539 | return status; |
| 540 | |
| 541 | obj = (union acpi_object *) out.pointer; |
| 542 | if (obj && obj->type == ACPI_TYPE_BUFFER && |
| 543 | obj->buffer.length == sizeof(struct wmab_ret)) { |
| 544 | ret = *((struct wmab_ret *) obj->buffer.pointer); |
| 545 | } else { |
| 546 | return AE_ERROR; |
| 547 | } |
| 548 | |
| 549 | if (ret.eax & 0x1) |
| 550 | interface->capability |= ACER_CAP_WIRELESS; |
| 551 | |
| 552 | args.ebx = 2 << 8; |
| 553 | args.ebx |= ACER_AMW0_BLUETOOTH_MASK; |
| 554 | |
| 555 | status = wmab_execute(&args, &out); |
| 556 | if (ACPI_FAILURE(status)) |
| 557 | return status; |
| 558 | |
| 559 | obj = (union acpi_object *) out.pointer; |
| 560 | if (obj && obj->type == ACPI_TYPE_BUFFER |
| 561 | && obj->buffer.length == sizeof(struct wmab_ret)) { |
| 562 | ret = *((struct wmab_ret *) obj->buffer.pointer); |
| 563 | } else { |
| 564 | return AE_ERROR; |
| 565 | } |
| 566 | |
| 567 | if (ret.eax & 0x1) |
| 568 | interface->capability |= ACER_CAP_BLUETOOTH; |
| 569 | |
| 570 | kfree(out.pointer); |
| 571 | |
| 572 | /* |
| 573 | * This appears to be safe to enable, since all Wistron based laptops |
| 574 | * appear to use the same EC register for brightness, even if they |
| 575 | * differ for wireless, etc |
| 576 | */ |
Carlos Corbacho | 9991d9f | 2008-06-21 09:09:22 +0100 | [diff] [blame^] | 577 | if (quirks->brightness >= 0) |
| 578 | interface->capability |= ACER_CAP_BRIGHTNESS; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 579 | |
| 580 | return AE_OK; |
| 581 | } |
| 582 | |
| 583 | static struct wmi_interface AMW0_interface = { |
| 584 | .type = ACER_AMW0, |
| 585 | }; |
| 586 | |
| 587 | static struct wmi_interface AMW0_V2_interface = { |
| 588 | .type = ACER_AMW0_V2, |
| 589 | }; |
| 590 | |
| 591 | /* |
| 592 | * New interface (The WMID interface) |
| 593 | */ |
| 594 | static acpi_status |
| 595 | WMI_execute_u32(u32 method_id, u32 in, u32 *out) |
| 596 | { |
| 597 | struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) }; |
| 598 | struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 599 | union acpi_object *obj; |
| 600 | u32 tmp; |
| 601 | acpi_status status; |
| 602 | |
| 603 | status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result); |
| 604 | |
| 605 | if (ACPI_FAILURE(status)) |
| 606 | return status; |
| 607 | |
| 608 | obj = (union acpi_object *) result.pointer; |
| 609 | if (obj && obj->type == ACPI_TYPE_BUFFER && |
| 610 | obj->buffer.length == sizeof(u32)) { |
| 611 | tmp = *((u32 *) obj->buffer.pointer); |
| 612 | } else { |
| 613 | tmp = 0; |
| 614 | } |
| 615 | |
| 616 | if (out) |
| 617 | *out = tmp; |
| 618 | |
| 619 | kfree(result.pointer); |
| 620 | |
| 621 | return status; |
| 622 | } |
| 623 | |
| 624 | static acpi_status WMID_get_u32(u32 *value, u32 cap, |
| 625 | struct wmi_interface *iface) |
| 626 | { |
| 627 | acpi_status status; |
| 628 | u8 tmp; |
| 629 | u32 result, method_id = 0; |
| 630 | |
| 631 | switch (cap) { |
| 632 | case ACER_CAP_WIRELESS: |
| 633 | method_id = ACER_WMID_GET_WIRELESS_METHODID; |
| 634 | break; |
| 635 | case ACER_CAP_BLUETOOTH: |
| 636 | method_id = ACER_WMID_GET_BLUETOOTH_METHODID; |
| 637 | break; |
| 638 | case ACER_CAP_BRIGHTNESS: |
| 639 | method_id = ACER_WMID_GET_BRIGHTNESS_METHODID; |
| 640 | break; |
| 641 | case ACER_CAP_THREEG: |
| 642 | method_id = ACER_WMID_GET_THREEG_METHODID; |
| 643 | break; |
| 644 | case ACER_CAP_MAILLED: |
| 645 | if (quirks->mailled == 1) { |
| 646 | ec_read(0x9f, &tmp); |
| 647 | *value = tmp & 0x1; |
| 648 | return 0; |
| 649 | } |
| 650 | default: |
| 651 | return AE_BAD_ADDRESS; |
| 652 | } |
| 653 | status = WMI_execute_u32(method_id, 0, &result); |
| 654 | |
| 655 | if (ACPI_SUCCESS(status)) |
| 656 | *value = (u8)result; |
| 657 | |
| 658 | return status; |
| 659 | } |
| 660 | |
| 661 | static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface) |
| 662 | { |
| 663 | u32 method_id = 0; |
| 664 | char param; |
| 665 | |
| 666 | switch (cap) { |
| 667 | case ACER_CAP_BRIGHTNESS: |
| 668 | if (value > max_brightness) |
| 669 | return AE_BAD_PARAMETER; |
| 670 | method_id = ACER_WMID_SET_BRIGHTNESS_METHODID; |
| 671 | break; |
| 672 | case ACER_CAP_WIRELESS: |
| 673 | if (value > 1) |
| 674 | return AE_BAD_PARAMETER; |
| 675 | method_id = ACER_WMID_SET_WIRELESS_METHODID; |
| 676 | break; |
| 677 | case ACER_CAP_BLUETOOTH: |
| 678 | if (value > 1) |
| 679 | return AE_BAD_PARAMETER; |
| 680 | method_id = ACER_WMID_SET_BLUETOOTH_METHODID; |
| 681 | break; |
| 682 | case ACER_CAP_THREEG: |
| 683 | if (value > 1) |
| 684 | return AE_BAD_PARAMETER; |
| 685 | method_id = ACER_WMID_SET_THREEG_METHODID; |
| 686 | break; |
| 687 | case ACER_CAP_MAILLED: |
| 688 | if (value > 1) |
| 689 | return AE_BAD_PARAMETER; |
| 690 | if (quirks->mailled == 1) { |
| 691 | param = value ? 0x92 : 0x93; |
| 692 | i8042_command(¶m, 0x1059); |
| 693 | return 0; |
| 694 | } |
| 695 | break; |
| 696 | default: |
| 697 | return AE_BAD_ADDRESS; |
| 698 | } |
| 699 | return WMI_execute_u32(method_id, (u32)value, NULL); |
| 700 | } |
| 701 | |
| 702 | static acpi_status WMID_set_capabilities(void) |
| 703 | { |
| 704 | struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 705 | union acpi_object *obj; |
| 706 | acpi_status status; |
| 707 | u32 devices; |
| 708 | |
| 709 | status = wmi_query_block(WMID_GUID2, 1, &out); |
| 710 | if (ACPI_FAILURE(status)) |
| 711 | return status; |
| 712 | |
| 713 | obj = (union acpi_object *) out.pointer; |
| 714 | if (obj && obj->type == ACPI_TYPE_BUFFER && |
| 715 | obj->buffer.length == sizeof(u32)) { |
| 716 | devices = *((u32 *) obj->buffer.pointer); |
| 717 | } else { |
| 718 | return AE_ERROR; |
| 719 | } |
| 720 | |
| 721 | /* Not sure on the meaning of the relevant bits yet to detect these */ |
| 722 | interface->capability |= ACER_CAP_WIRELESS; |
| 723 | interface->capability |= ACER_CAP_THREEG; |
| 724 | |
| 725 | /* WMID always provides brightness methods */ |
| 726 | interface->capability |= ACER_CAP_BRIGHTNESS; |
| 727 | |
| 728 | if (devices & 0x10) |
| 729 | interface->capability |= ACER_CAP_BLUETOOTH; |
| 730 | |
| 731 | if (!(devices & 0x20)) |
| 732 | max_brightness = 0x9; |
| 733 | |
| 734 | return status; |
| 735 | } |
| 736 | |
| 737 | static struct wmi_interface wmid_interface = { |
| 738 | .type = ACER_WMID, |
| 739 | }; |
| 740 | |
| 741 | /* |
| 742 | * Generic Device (interface-independent) |
| 743 | */ |
| 744 | |
| 745 | static acpi_status get_u32(u32 *value, u32 cap) |
| 746 | { |
| 747 | acpi_status status = AE_BAD_ADDRESS; |
| 748 | |
| 749 | switch (interface->type) { |
| 750 | case ACER_AMW0: |
| 751 | status = AMW0_get_u32(value, cap, interface); |
| 752 | break; |
| 753 | case ACER_AMW0_V2: |
| 754 | if (cap == ACER_CAP_MAILLED) { |
| 755 | status = AMW0_get_u32(value, cap, interface); |
| 756 | break; |
| 757 | } |
| 758 | case ACER_WMID: |
| 759 | status = WMID_get_u32(value, cap, interface); |
| 760 | break; |
| 761 | } |
| 762 | |
| 763 | return status; |
| 764 | } |
| 765 | |
| 766 | static acpi_status set_u32(u32 value, u32 cap) |
| 767 | { |
| 768 | if (interface->capability & cap) { |
| 769 | switch (interface->type) { |
| 770 | case ACER_AMW0: |
| 771 | return AMW0_set_u32(value, cap, interface); |
| 772 | case ACER_AMW0_V2: |
| 773 | case ACER_WMID: |
| 774 | return WMID_set_u32(value, cap, interface); |
| 775 | default: |
| 776 | return AE_BAD_PARAMETER; |
| 777 | } |
| 778 | } |
| 779 | return AE_BAD_PARAMETER; |
| 780 | } |
| 781 | |
| 782 | static void __init acer_commandline_init(void) |
| 783 | { |
| 784 | /* |
| 785 | * These will all fail silently if the value given is invalid, or the |
| 786 | * capability isn't available on the given interface |
| 787 | */ |
| 788 | set_u32(mailled, ACER_CAP_MAILLED); |
| 789 | set_u32(wireless, ACER_CAP_WIRELESS); |
| 790 | set_u32(bluetooth, ACER_CAP_BLUETOOTH); |
| 791 | set_u32(threeg, ACER_CAP_THREEG); |
| 792 | set_u32(brightness, ACER_CAP_BRIGHTNESS); |
| 793 | } |
| 794 | |
| 795 | /* |
| 796 | * LED device (Mail LED only, no other LEDs known yet) |
| 797 | */ |
| 798 | static void mail_led_set(struct led_classdev *led_cdev, |
| 799 | enum led_brightness value) |
| 800 | { |
| 801 | set_u32(value, ACER_CAP_MAILLED); |
| 802 | } |
| 803 | |
| 804 | static struct led_classdev mail_led = { |
Carlos Corbacho | 343c004 | 2008-02-24 13:34:18 +0000 | [diff] [blame] | 805 | .name = "acer-wmi::mail", |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 806 | .brightness_set = mail_led_set, |
| 807 | }; |
| 808 | |
Sam Ravnborg | 7560e38 | 2008-02-17 13:22:54 +0100 | [diff] [blame] | 809 | static int __devinit acer_led_init(struct device *dev) |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 810 | { |
| 811 | return led_classdev_register(dev, &mail_led); |
| 812 | } |
| 813 | |
| 814 | static void acer_led_exit(void) |
| 815 | { |
| 816 | led_classdev_unregister(&mail_led); |
| 817 | } |
| 818 | |
| 819 | /* |
| 820 | * Backlight device |
| 821 | */ |
| 822 | static struct backlight_device *acer_backlight_device; |
| 823 | |
| 824 | static int read_brightness(struct backlight_device *bd) |
| 825 | { |
| 826 | u32 value; |
| 827 | get_u32(&value, ACER_CAP_BRIGHTNESS); |
| 828 | return value; |
| 829 | } |
| 830 | |
| 831 | static int update_bl_status(struct backlight_device *bd) |
| 832 | { |
| 833 | set_u32(bd->props.brightness, ACER_CAP_BRIGHTNESS); |
| 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | static struct backlight_ops acer_bl_ops = { |
| 838 | .get_brightness = read_brightness, |
| 839 | .update_status = update_bl_status, |
| 840 | }; |
| 841 | |
Sam Ravnborg | 7560e38 | 2008-02-17 13:22:54 +0100 | [diff] [blame] | 842 | static int __devinit acer_backlight_init(struct device *dev) |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 843 | { |
| 844 | struct backlight_device *bd; |
| 845 | |
| 846 | bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops); |
| 847 | if (IS_ERR(bd)) { |
| 848 | printk(ACER_ERR "Could not register Acer backlight device\n"); |
| 849 | acer_backlight_device = NULL; |
| 850 | return PTR_ERR(bd); |
| 851 | } |
| 852 | |
| 853 | acer_backlight_device = bd; |
| 854 | |
| 855 | bd->props.max_brightness = max_brightness; |
| 856 | bd->props.brightness = read_brightness(NULL); |
| 857 | backlight_update_status(bd); |
| 858 | return 0; |
| 859 | } |
| 860 | |
Sam Ravnborg | 7560e38 | 2008-02-17 13:22:54 +0100 | [diff] [blame] | 861 | static void acer_backlight_exit(void) |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 862 | { |
| 863 | backlight_device_unregister(acer_backlight_device); |
| 864 | } |
| 865 | |
| 866 | /* |
| 867 | * Read/ write bool sysfs macro |
| 868 | */ |
| 869 | #define show_set_bool(value, cap) \ |
| 870 | static ssize_t \ |
| 871 | show_bool_##value(struct device *dev, struct device_attribute *attr, \ |
| 872 | char *buf) \ |
| 873 | { \ |
| 874 | u32 result; \ |
| 875 | acpi_status status = get_u32(&result, cap); \ |
| 876 | if (ACPI_SUCCESS(status)) \ |
| 877 | return sprintf(buf, "%u\n", result); \ |
| 878 | return sprintf(buf, "Read error\n"); \ |
| 879 | } \ |
| 880 | \ |
| 881 | static ssize_t \ |
| 882 | set_bool_##value(struct device *dev, struct device_attribute *attr, \ |
| 883 | const char *buf, size_t count) \ |
| 884 | { \ |
| 885 | u32 tmp = simple_strtoul(buf, NULL, 10); \ |
| 886 | acpi_status status = set_u32(tmp, cap); \ |
| 887 | if (ACPI_FAILURE(status)) \ |
| 888 | return -EINVAL; \ |
| 889 | return count; \ |
| 890 | } \ |
| 891 | static DEVICE_ATTR(value, S_IWUGO | S_IRUGO | S_IWUSR, \ |
| 892 | show_bool_##value, set_bool_##value); |
| 893 | |
| 894 | show_set_bool(wireless, ACER_CAP_WIRELESS); |
| 895 | show_set_bool(bluetooth, ACER_CAP_BLUETOOTH); |
| 896 | show_set_bool(threeg, ACER_CAP_THREEG); |
| 897 | |
| 898 | /* |
| 899 | * Read interface sysfs macro |
| 900 | */ |
| 901 | static ssize_t show_interface(struct device *dev, struct device_attribute *attr, |
| 902 | char *buf) |
| 903 | { |
| 904 | switch (interface->type) { |
| 905 | case ACER_AMW0: |
| 906 | return sprintf(buf, "AMW0\n"); |
| 907 | case ACER_AMW0_V2: |
| 908 | return sprintf(buf, "AMW0 v2\n"); |
| 909 | case ACER_WMID: |
| 910 | return sprintf(buf, "WMID\n"); |
| 911 | default: |
| 912 | return sprintf(buf, "Error!\n"); |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | static DEVICE_ATTR(interface, S_IWUGO | S_IRUGO | S_IWUSR, |
| 917 | show_interface, NULL); |
| 918 | |
| 919 | /* |
| 920 | * Platform device |
| 921 | */ |
| 922 | static int __devinit acer_platform_probe(struct platform_device *device) |
| 923 | { |
| 924 | int err; |
| 925 | |
| 926 | if (has_cap(ACER_CAP_MAILLED)) { |
| 927 | err = acer_led_init(&device->dev); |
| 928 | if (err) |
| 929 | goto error_mailled; |
| 930 | } |
| 931 | |
| 932 | if (has_cap(ACER_CAP_BRIGHTNESS)) { |
| 933 | err = acer_backlight_init(&device->dev); |
| 934 | if (err) |
| 935 | goto error_brightness; |
| 936 | } |
| 937 | |
| 938 | return 0; |
| 939 | |
| 940 | error_brightness: |
| 941 | acer_led_exit(); |
| 942 | error_mailled: |
| 943 | return err; |
| 944 | } |
| 945 | |
| 946 | static int acer_platform_remove(struct platform_device *device) |
| 947 | { |
| 948 | if (has_cap(ACER_CAP_MAILLED)) |
| 949 | acer_led_exit(); |
| 950 | if (has_cap(ACER_CAP_BRIGHTNESS)) |
| 951 | acer_backlight_exit(); |
| 952 | return 0; |
| 953 | } |
| 954 | |
| 955 | static int acer_platform_suspend(struct platform_device *dev, |
| 956 | pm_message_t state) |
| 957 | { |
| 958 | u32 value; |
| 959 | struct acer_data *data = &interface->data; |
| 960 | |
| 961 | if (!data) |
| 962 | return -ENOMEM; |
| 963 | |
| 964 | if (has_cap(ACER_CAP_WIRELESS)) { |
| 965 | get_u32(&value, ACER_CAP_WIRELESS); |
| 966 | data->wireless = value; |
| 967 | } |
| 968 | |
| 969 | if (has_cap(ACER_CAP_BLUETOOTH)) { |
| 970 | get_u32(&value, ACER_CAP_BLUETOOTH); |
| 971 | data->bluetooth = value; |
| 972 | } |
| 973 | |
| 974 | if (has_cap(ACER_CAP_MAILLED)) { |
| 975 | get_u32(&value, ACER_CAP_MAILLED); |
| 976 | data->mailled = value; |
| 977 | } |
| 978 | |
| 979 | if (has_cap(ACER_CAP_BRIGHTNESS)) { |
| 980 | get_u32(&value, ACER_CAP_BRIGHTNESS); |
| 981 | data->brightness = value; |
| 982 | } |
| 983 | |
| 984 | return 0; |
| 985 | } |
| 986 | |
| 987 | static int acer_platform_resume(struct platform_device *device) |
| 988 | { |
| 989 | struct acer_data *data = &interface->data; |
| 990 | |
| 991 | if (!data) |
| 992 | return -ENOMEM; |
| 993 | |
| 994 | if (has_cap(ACER_CAP_WIRELESS)) |
| 995 | set_u32(data->wireless, ACER_CAP_WIRELESS); |
| 996 | |
| 997 | if (has_cap(ACER_CAP_BLUETOOTH)) |
| 998 | set_u32(data->bluetooth, ACER_CAP_BLUETOOTH); |
| 999 | |
| 1000 | if (has_cap(ACER_CAP_THREEG)) |
| 1001 | set_u32(data->threeg, ACER_CAP_THREEG); |
| 1002 | |
| 1003 | if (has_cap(ACER_CAP_MAILLED)) |
| 1004 | set_u32(data->mailled, ACER_CAP_MAILLED); |
| 1005 | |
| 1006 | if (has_cap(ACER_CAP_BRIGHTNESS)) |
| 1007 | set_u32(data->brightness, ACER_CAP_BRIGHTNESS); |
| 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | static struct platform_driver acer_platform_driver = { |
| 1013 | .driver = { |
| 1014 | .name = "acer-wmi", |
| 1015 | .owner = THIS_MODULE, |
| 1016 | }, |
| 1017 | .probe = acer_platform_probe, |
| 1018 | .remove = acer_platform_remove, |
| 1019 | .suspend = acer_platform_suspend, |
| 1020 | .resume = acer_platform_resume, |
| 1021 | }; |
| 1022 | |
| 1023 | static struct platform_device *acer_platform_device; |
| 1024 | |
| 1025 | static int remove_sysfs(struct platform_device *device) |
| 1026 | { |
| 1027 | if (has_cap(ACER_CAP_WIRELESS)) |
| 1028 | device_remove_file(&device->dev, &dev_attr_wireless); |
| 1029 | |
| 1030 | if (has_cap(ACER_CAP_BLUETOOTH)) |
| 1031 | device_remove_file(&device->dev, &dev_attr_bluetooth); |
| 1032 | |
| 1033 | if (has_cap(ACER_CAP_THREEG)) |
| 1034 | device_remove_file(&device->dev, &dev_attr_threeg); |
| 1035 | |
| 1036 | device_remove_file(&device->dev, &dev_attr_interface); |
| 1037 | |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
| 1041 | static int create_sysfs(void) |
| 1042 | { |
| 1043 | int retval = -ENOMEM; |
| 1044 | |
| 1045 | if (has_cap(ACER_CAP_WIRELESS)) { |
| 1046 | retval = device_create_file(&acer_platform_device->dev, |
| 1047 | &dev_attr_wireless); |
| 1048 | if (retval) |
| 1049 | goto error_sysfs; |
| 1050 | } |
| 1051 | |
| 1052 | if (has_cap(ACER_CAP_BLUETOOTH)) { |
| 1053 | retval = device_create_file(&acer_platform_device->dev, |
| 1054 | &dev_attr_bluetooth); |
| 1055 | if (retval) |
| 1056 | goto error_sysfs; |
| 1057 | } |
| 1058 | |
| 1059 | if (has_cap(ACER_CAP_THREEG)) { |
| 1060 | retval = device_create_file(&acer_platform_device->dev, |
| 1061 | &dev_attr_threeg); |
| 1062 | if (retval) |
| 1063 | goto error_sysfs; |
| 1064 | } |
| 1065 | |
| 1066 | retval = device_create_file(&acer_platform_device->dev, |
| 1067 | &dev_attr_interface); |
| 1068 | if (retval) |
| 1069 | goto error_sysfs; |
| 1070 | |
| 1071 | return 0; |
| 1072 | |
| 1073 | error_sysfs: |
| 1074 | remove_sysfs(acer_platform_device); |
| 1075 | return retval; |
| 1076 | } |
| 1077 | |
| 1078 | static int __init acer_wmi_init(void) |
| 1079 | { |
| 1080 | int err; |
| 1081 | |
| 1082 | printk(ACER_INFO "Acer Laptop ACPI-WMI Extras version %s\n", |
| 1083 | ACER_WMI_VERSION); |
| 1084 | |
Carlos Corbacho | 9991d9f | 2008-06-21 09:09:22 +0100 | [diff] [blame^] | 1085 | find_quirks(); |
| 1086 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1087 | /* |
| 1088 | * Detect which ACPI-WMI interface we're using. |
| 1089 | */ |
| 1090 | if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1)) |
| 1091 | interface = &AMW0_V2_interface; |
| 1092 | |
| 1093 | if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1)) |
| 1094 | interface = &wmid_interface; |
| 1095 | |
| 1096 | if (wmi_has_guid(WMID_GUID2) && interface) { |
| 1097 | if (ACPI_FAILURE(WMID_set_capabilities())) { |
Carlos Corbacho | 8d039bc | 2008-03-12 20:12:50 +0000 | [diff] [blame] | 1098 | printk(ACER_ERR "Unable to detect available WMID " |
| 1099 | "devices\n"); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1100 | return -ENODEV; |
| 1101 | } |
| 1102 | } else if (!wmi_has_guid(WMID_GUID2) && interface) { |
Carlos Corbacho | 8d039bc | 2008-03-12 20:12:50 +0000 | [diff] [blame] | 1103 | printk(ACER_ERR "No WMID device detection method found\n"); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1104 | return -ENODEV; |
| 1105 | } |
| 1106 | |
| 1107 | if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) { |
| 1108 | interface = &AMW0_interface; |
| 1109 | |
| 1110 | if (ACPI_FAILURE(AMW0_set_capabilities())) { |
Carlos Corbacho | 8d039bc | 2008-03-12 20:12:50 +0000 | [diff] [blame] | 1111 | printk(ACER_ERR "Unable to detect available AMW0 " |
| 1112 | "devices\n"); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1113 | return -ENODEV; |
| 1114 | } |
| 1115 | } |
| 1116 | |
Carlos Corbacho | 9b963c4 | 2008-02-24 13:34:29 +0000 | [diff] [blame] | 1117 | if (wmi_has_guid(AMW0_GUID1)) |
| 1118 | AMW0_find_mailled(); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1119 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1120 | if (!interface) { |
Carlos Corbacho | 8d039bc | 2008-03-12 20:12:50 +0000 | [diff] [blame] | 1121 | printk(ACER_ERR "No or unsupported WMI interface, unable to " |
| 1122 | "load\n"); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1123 | return -ENODEV; |
| 1124 | } |
| 1125 | |
| 1126 | if (platform_driver_register(&acer_platform_driver)) { |
| 1127 | printk(ACER_ERR "Unable to register platform driver.\n"); |
| 1128 | goto error_platform_register; |
| 1129 | } |
| 1130 | acer_platform_device = platform_device_alloc("acer-wmi", -1); |
| 1131 | platform_device_add(acer_platform_device); |
| 1132 | |
| 1133 | err = create_sysfs(); |
| 1134 | if (err) |
| 1135 | return err; |
| 1136 | |
| 1137 | /* Override any initial settings with values from the commandline */ |
| 1138 | acer_commandline_init(); |
| 1139 | |
| 1140 | return 0; |
| 1141 | |
| 1142 | error_platform_register: |
| 1143 | return -ENODEV; |
| 1144 | } |
| 1145 | |
| 1146 | static void __exit acer_wmi_exit(void) |
| 1147 | { |
| 1148 | remove_sysfs(acer_platform_device); |
| 1149 | platform_device_del(acer_platform_device); |
| 1150 | platform_driver_unregister(&acer_platform_driver); |
| 1151 | |
| 1152 | printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n"); |
| 1153 | return; |
| 1154 | } |
| 1155 | |
| 1156 | module_init(acer_wmi_init); |
| 1157 | module_exit(acer_wmi_exit); |