Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Acer WMI Laptop Extras |
| 3 | * |
Carlos Corbacho | 4f0175d | 2009-04-04 09:33:39 +0100 | [diff] [blame] | 4 | * Copyright (C) 2007-2009 Carlos Corbacho <carlos@strangeworlds.co.uk> |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 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 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/dmi.h> |
Carlos Corbacho | f2b585b | 2008-06-21 09:09:27 +0100 | [diff] [blame] | 30 | #include <linux/fb.h> |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 31 | #include <linux/backlight.h> |
| 32 | #include <linux/leds.h> |
| 33 | #include <linux/platform_device.h> |
| 34 | #include <linux/acpi.h> |
| 35 | #include <linux/i8042.h> |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 36 | #include <linux/rfkill.h> |
| 37 | #include <linux/workqueue.h> |
Carlos Corbacho | 8114352 | 2008-06-21 09:09:53 +0100 | [diff] [blame] | 38 | #include <linux/debugfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 39 | #include <linux/slab.h> |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 40 | |
| 41 | #include <acpi/acpi_drivers.h> |
| 42 | |
| 43 | MODULE_AUTHOR("Carlos Corbacho"); |
| 44 | MODULE_DESCRIPTION("Acer Laptop WMI Extras Driver"); |
| 45 | MODULE_LICENSE("GPL"); |
| 46 | |
| 47 | #define ACER_LOGPREFIX "acer-wmi: " |
| 48 | #define ACER_ERR KERN_ERR ACER_LOGPREFIX |
| 49 | #define ACER_NOTICE KERN_NOTICE ACER_LOGPREFIX |
| 50 | #define ACER_INFO KERN_INFO ACER_LOGPREFIX |
| 51 | |
| 52 | /* |
| 53 | * The following defines quirks to get some specific functions to work |
| 54 | * which are known to not be supported over ACPI-WMI (such as the mail LED |
| 55 | * on WMID based Acer's) |
| 56 | */ |
| 57 | struct acer_quirks { |
| 58 | const char *vendor; |
| 59 | const char *model; |
| 60 | u16 quirks; |
| 61 | }; |
| 62 | |
| 63 | /* |
| 64 | * Magic Number |
| 65 | * Meaning is unknown - this number is required for writing to ACPI for AMW0 |
| 66 | * (it's also used in acerhk when directly accessing the BIOS) |
| 67 | */ |
| 68 | #define ACER_AMW0_WRITE 0x9610 |
| 69 | |
| 70 | /* |
| 71 | * Bit masks for the AMW0 interface |
| 72 | */ |
| 73 | #define ACER_AMW0_WIRELESS_MASK 0x35 |
| 74 | #define ACER_AMW0_BLUETOOTH_MASK 0x34 |
| 75 | #define ACER_AMW0_MAILLED_MASK 0x31 |
| 76 | |
| 77 | /* |
| 78 | * Method IDs for WMID interface |
| 79 | */ |
| 80 | #define ACER_WMID_GET_WIRELESS_METHODID 1 |
| 81 | #define ACER_WMID_GET_BLUETOOTH_METHODID 2 |
| 82 | #define ACER_WMID_GET_BRIGHTNESS_METHODID 3 |
| 83 | #define ACER_WMID_SET_WIRELESS_METHODID 4 |
| 84 | #define ACER_WMID_SET_BLUETOOTH_METHODID 5 |
| 85 | #define ACER_WMID_SET_BRIGHTNESS_METHODID 6 |
| 86 | #define ACER_WMID_GET_THREEG_METHODID 10 |
| 87 | #define ACER_WMID_SET_THREEG_METHODID 11 |
| 88 | |
| 89 | /* |
| 90 | * Acer ACPI method GUIDs |
| 91 | */ |
| 92 | #define AMW0_GUID1 "67C3371D-95A3-4C37-BB61-DD47B491DAAB" |
Carlos Corbacho | 5753dd5 | 2008-06-21 09:09:48 +0100 | [diff] [blame] | 93 | #define AMW0_GUID2 "431F16ED-0C2B-444C-B267-27DEB140CF9C" |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 94 | #define WMID_GUID1 "6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3" |
| 95 | #define WMID_GUID2 "95764E09-FB56-4e83-B31A-37761F60994A" |
| 96 | |
| 97 | MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB"); |
| 98 | MODULE_ALIAS("wmi:6AF4F258-B401-42fd-BE91-3D4AC2D7C0D3"); |
| 99 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 100 | /* |
| 101 | * Interface capability flags |
| 102 | */ |
| 103 | #define ACER_CAP_MAILLED (1<<0) |
| 104 | #define ACER_CAP_WIRELESS (1<<1) |
| 105 | #define ACER_CAP_BLUETOOTH (1<<2) |
| 106 | #define ACER_CAP_BRIGHTNESS (1<<3) |
| 107 | #define ACER_CAP_THREEG (1<<4) |
| 108 | #define ACER_CAP_ANY (0xFFFFFFFF) |
| 109 | |
| 110 | /* |
| 111 | * Interface type flags |
| 112 | */ |
| 113 | enum interface_flags { |
| 114 | ACER_AMW0, |
| 115 | ACER_AMW0_V2, |
| 116 | ACER_WMID, |
| 117 | }; |
| 118 | |
| 119 | #define ACER_DEFAULT_WIRELESS 0 |
| 120 | #define ACER_DEFAULT_BLUETOOTH 0 |
| 121 | #define ACER_DEFAULT_MAILLED 0 |
| 122 | #define ACER_DEFAULT_THREEG 0 |
| 123 | |
| 124 | static int max_brightness = 0xF; |
| 125 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 126 | static int mailled = -1; |
| 127 | static int brightness = -1; |
| 128 | static int threeg = -1; |
| 129 | static int force_series; |
| 130 | |
| 131 | module_param(mailled, int, 0444); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 132 | module_param(brightness, int, 0444); |
| 133 | module_param(threeg, int, 0444); |
| 134 | module_param(force_series, int, 0444); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 135 | MODULE_PARM_DESC(mailled, "Set initial state of Mail LED"); |
| 136 | MODULE_PARM_DESC(brightness, "Set initial LCD backlight brightness"); |
| 137 | MODULE_PARM_DESC(threeg, "Set initial state of 3G hardware"); |
| 138 | MODULE_PARM_DESC(force_series, "Force a different laptop series"); |
| 139 | |
| 140 | struct acer_data { |
| 141 | int mailled; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 142 | int threeg; |
| 143 | int brightness; |
| 144 | }; |
| 145 | |
Carlos Corbacho | 8114352 | 2008-06-21 09:09:53 +0100 | [diff] [blame] | 146 | struct acer_debug { |
| 147 | struct dentry *root; |
| 148 | struct dentry *devices; |
| 149 | u32 wmid_devices; |
| 150 | }; |
| 151 | |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 152 | static struct rfkill *wireless_rfkill; |
| 153 | static struct rfkill *bluetooth_rfkill; |
| 154 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 155 | /* Each low-level interface must define at least some of the following */ |
| 156 | struct wmi_interface { |
| 157 | /* The WMI device type */ |
| 158 | u32 type; |
| 159 | |
| 160 | /* The capabilities this interface provides */ |
| 161 | u32 capability; |
| 162 | |
| 163 | /* Private data for the current interface */ |
| 164 | struct acer_data data; |
Carlos Corbacho | 8114352 | 2008-06-21 09:09:53 +0100 | [diff] [blame] | 165 | |
| 166 | /* debugfs entries associated with this interface */ |
| 167 | struct acer_debug debug; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | /* The static interface pointer, points to the currently detected interface */ |
| 171 | static struct wmi_interface *interface; |
| 172 | |
| 173 | /* |
| 174 | * Embedded Controller quirks |
| 175 | * Some laptops require us to directly access the EC to either enable or query |
| 176 | * features that are not available through WMI. |
| 177 | */ |
| 178 | |
| 179 | struct quirk_entry { |
| 180 | u8 wireless; |
| 181 | u8 mailled; |
Carlos Corbacho | 9991d9f | 2008-06-21 09:09:22 +0100 | [diff] [blame] | 182 | s8 brightness; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 183 | u8 bluetooth; |
| 184 | }; |
| 185 | |
| 186 | static struct quirk_entry *quirks; |
| 187 | |
| 188 | static void set_quirks(void) |
| 189 | { |
Arjan van de Ven | 83097ac | 2008-08-23 21:45:21 -0700 | [diff] [blame] | 190 | if (!interface) |
| 191 | return; |
| 192 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 193 | if (quirks->mailled) |
| 194 | interface->capability |= ACER_CAP_MAILLED; |
| 195 | |
| 196 | if (quirks->brightness) |
| 197 | interface->capability |= ACER_CAP_BRIGHTNESS; |
| 198 | } |
| 199 | |
| 200 | static int dmi_matched(const struct dmi_system_id *dmi) |
| 201 | { |
| 202 | quirks = dmi->driver_data; |
Axel Lin | d53bf0f | 2010-06-30 13:32:16 +0800 | [diff] [blame] | 203 | return 1; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static struct quirk_entry quirk_unknown = { |
| 207 | }; |
| 208 | |
Carlos Corbacho | 9991d9f | 2008-06-21 09:09:22 +0100 | [diff] [blame] | 209 | static struct quirk_entry quirk_acer_aspire_1520 = { |
| 210 | .brightness = -1, |
| 211 | }; |
| 212 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 213 | static struct quirk_entry quirk_acer_travelmate_2490 = { |
| 214 | .mailled = 1, |
| 215 | }; |
| 216 | |
| 217 | /* This AMW0 laptop has no bluetooth */ |
| 218 | static struct quirk_entry quirk_medion_md_98300 = { |
| 219 | .wireless = 1, |
| 220 | }; |
| 221 | |
Carlos Corbacho | 6f061ab | 2008-06-21 09:09:38 +0100 | [diff] [blame] | 222 | static struct quirk_entry quirk_fujitsu_amilo_li_1718 = { |
| 223 | .wireless = 2, |
| 224 | }; |
| 225 | |
Carlos Corbacho | a74dd5f | 2009-04-04 09:33:29 +0100 | [diff] [blame] | 226 | /* The Aspire One has a dummy ACPI-WMI interface - disable it */ |
| 227 | static struct dmi_system_id __devinitdata acer_blacklist[] = { |
| 228 | { |
| 229 | .ident = "Acer Aspire One (SSD)", |
| 230 | .matches = { |
| 231 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 232 | DMI_MATCH(DMI_PRODUCT_NAME, "AOA110"), |
| 233 | }, |
| 234 | }, |
| 235 | { |
| 236 | .ident = "Acer Aspire One (HDD)", |
| 237 | .matches = { |
| 238 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 239 | DMI_MATCH(DMI_PRODUCT_NAME, "AOA150"), |
| 240 | }, |
| 241 | }, |
| 242 | {} |
| 243 | }; |
| 244 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 245 | static struct dmi_system_id acer_quirks[] = { |
| 246 | { |
| 247 | .callback = dmi_matched, |
Carlos Corbacho | 9991d9f | 2008-06-21 09:09:22 +0100 | [diff] [blame] | 248 | .ident = "Acer Aspire 1360", |
| 249 | .matches = { |
| 250 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 251 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1360"), |
| 252 | }, |
| 253 | .driver_data = &quirk_acer_aspire_1520, |
| 254 | }, |
| 255 | { |
| 256 | .callback = dmi_matched, |
| 257 | .ident = "Acer Aspire 1520", |
| 258 | .matches = { |
| 259 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 260 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1520"), |
| 261 | }, |
| 262 | .driver_data = &quirk_acer_aspire_1520, |
| 263 | }, |
| 264 | { |
| 265 | .callback = dmi_matched, |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 266 | .ident = "Acer Aspire 3100", |
| 267 | .matches = { |
| 268 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 269 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3100"), |
| 270 | }, |
| 271 | .driver_data = &quirk_acer_travelmate_2490, |
| 272 | }, |
| 273 | { |
| 274 | .callback = dmi_matched, |
Carlos Corbacho | ed9cfe9 | 2008-03-12 20:13:00 +0000 | [diff] [blame] | 275 | .ident = "Acer Aspire 3610", |
| 276 | .matches = { |
| 277 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 278 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 3610"), |
| 279 | }, |
| 280 | .driver_data = &quirk_acer_travelmate_2490, |
| 281 | }, |
| 282 | { |
| 283 | .callback = dmi_matched, |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 284 | .ident = "Acer Aspire 5100", |
| 285 | .matches = { |
| 286 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 287 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5100"), |
| 288 | }, |
| 289 | .driver_data = &quirk_acer_travelmate_2490, |
| 290 | }, |
| 291 | { |
| 292 | .callback = dmi_matched, |
Carlos Corbacho | ed9cfe9 | 2008-03-12 20:13:00 +0000 | [diff] [blame] | 293 | .ident = "Acer Aspire 5610", |
| 294 | .matches = { |
| 295 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 296 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5610"), |
| 297 | }, |
| 298 | .driver_data = &quirk_acer_travelmate_2490, |
| 299 | }, |
| 300 | { |
| 301 | .callback = dmi_matched, |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 302 | .ident = "Acer Aspire 5630", |
| 303 | .matches = { |
| 304 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 305 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5630"), |
| 306 | }, |
| 307 | .driver_data = &quirk_acer_travelmate_2490, |
| 308 | }, |
| 309 | { |
| 310 | .callback = dmi_matched, |
| 311 | .ident = "Acer Aspire 5650", |
| 312 | .matches = { |
| 313 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 314 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5650"), |
| 315 | }, |
| 316 | .driver_data = &quirk_acer_travelmate_2490, |
| 317 | }, |
| 318 | { |
| 319 | .callback = dmi_matched, |
| 320 | .ident = "Acer Aspire 5680", |
| 321 | .matches = { |
| 322 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 323 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 5680"), |
| 324 | }, |
| 325 | .driver_data = &quirk_acer_travelmate_2490, |
| 326 | }, |
| 327 | { |
| 328 | .callback = dmi_matched, |
| 329 | .ident = "Acer Aspire 9110", |
| 330 | .matches = { |
| 331 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 332 | DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 9110"), |
| 333 | }, |
| 334 | .driver_data = &quirk_acer_travelmate_2490, |
| 335 | }, |
| 336 | { |
| 337 | .callback = dmi_matched, |
| 338 | .ident = "Acer TravelMate 2490", |
| 339 | .matches = { |
| 340 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 341 | DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 2490"), |
| 342 | }, |
| 343 | .driver_data = &quirk_acer_travelmate_2490, |
| 344 | }, |
| 345 | { |
| 346 | .callback = dmi_matched, |
Carlos Corbacho | 262ee35 | 2008-02-16 00:02:56 +0000 | [diff] [blame] | 347 | .ident = "Acer TravelMate 4200", |
| 348 | .matches = { |
| 349 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 350 | DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4200"), |
| 351 | }, |
| 352 | .driver_data = &quirk_acer_travelmate_2490, |
| 353 | }, |
| 354 | { |
| 355 | .callback = dmi_matched, |
Carlos Corbacho | 6f061ab | 2008-06-21 09:09:38 +0100 | [diff] [blame] | 356 | .ident = "Fujitsu Siemens Amilo Li 1718", |
| 357 | .matches = { |
| 358 | DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), |
| 359 | DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Li 1718"), |
| 360 | }, |
| 361 | .driver_data = &quirk_fujitsu_amilo_li_1718, |
| 362 | }, |
| 363 | { |
| 364 | .callback = dmi_matched, |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 365 | .ident = "Medion MD 98300", |
| 366 | .matches = { |
| 367 | DMI_MATCH(DMI_SYS_VENDOR, "MEDION"), |
| 368 | DMI_MATCH(DMI_PRODUCT_NAME, "WAM2030"), |
| 369 | }, |
| 370 | .driver_data = &quirk_medion_md_98300, |
| 371 | }, |
| 372 | {} |
| 373 | }; |
| 374 | |
| 375 | /* Find which quirks are needed for a particular vendor/ model pair */ |
| 376 | static void find_quirks(void) |
| 377 | { |
| 378 | if (!force_series) { |
| 379 | dmi_check_system(acer_quirks); |
| 380 | } else if (force_series == 2490) { |
| 381 | quirks = &quirk_acer_travelmate_2490; |
| 382 | } |
| 383 | |
| 384 | if (quirks == NULL) |
| 385 | quirks = &quirk_unknown; |
| 386 | |
| 387 | set_quirks(); |
| 388 | } |
| 389 | |
| 390 | /* |
| 391 | * General interface convenience methods |
| 392 | */ |
| 393 | |
| 394 | static bool has_cap(u32 cap) |
| 395 | { |
| 396 | if ((interface->capability & cap) != 0) |
| 397 | return 1; |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | /* |
| 403 | * AMW0 (V1) interface |
| 404 | */ |
| 405 | struct wmab_args { |
| 406 | u32 eax; |
| 407 | u32 ebx; |
| 408 | u32 ecx; |
| 409 | u32 edx; |
| 410 | }; |
| 411 | |
| 412 | struct wmab_ret { |
| 413 | u32 eax; |
| 414 | u32 ebx; |
| 415 | u32 ecx; |
| 416 | u32 edx; |
| 417 | u32 eex; |
| 418 | }; |
| 419 | |
| 420 | static acpi_status wmab_execute(struct wmab_args *regbuf, |
| 421 | struct acpi_buffer *result) |
| 422 | { |
| 423 | struct acpi_buffer input; |
| 424 | acpi_status status; |
| 425 | input.length = sizeof(struct wmab_args); |
| 426 | input.pointer = (u8 *)regbuf; |
| 427 | |
| 428 | status = wmi_evaluate_method(AMW0_GUID1, 1, 1, &input, result); |
| 429 | |
| 430 | return status; |
| 431 | } |
| 432 | |
| 433 | static acpi_status AMW0_get_u32(u32 *value, u32 cap, |
| 434 | struct wmi_interface *iface) |
| 435 | { |
| 436 | int err; |
| 437 | u8 result; |
| 438 | |
| 439 | switch (cap) { |
| 440 | case ACER_CAP_MAILLED: |
| 441 | switch (quirks->mailled) { |
| 442 | default: |
| 443 | err = ec_read(0xA, &result); |
| 444 | if (err) |
| 445 | return AE_ERROR; |
| 446 | *value = (result >> 7) & 0x1; |
| 447 | return AE_OK; |
| 448 | } |
| 449 | break; |
| 450 | case ACER_CAP_WIRELESS: |
| 451 | switch (quirks->wireless) { |
| 452 | case 1: |
| 453 | err = ec_read(0x7B, &result); |
| 454 | if (err) |
| 455 | return AE_ERROR; |
| 456 | *value = result & 0x1; |
| 457 | return AE_OK; |
Carlos Corbacho | 6f061ab | 2008-06-21 09:09:38 +0100 | [diff] [blame] | 458 | case 2: |
| 459 | err = ec_read(0x71, &result); |
| 460 | if (err) |
| 461 | return AE_ERROR; |
| 462 | *value = result & 0x1; |
| 463 | return AE_OK; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 464 | default: |
| 465 | err = ec_read(0xA, &result); |
| 466 | if (err) |
| 467 | return AE_ERROR; |
| 468 | *value = (result >> 2) & 0x1; |
| 469 | return AE_OK; |
| 470 | } |
| 471 | break; |
| 472 | case ACER_CAP_BLUETOOTH: |
| 473 | switch (quirks->bluetooth) { |
| 474 | default: |
| 475 | err = ec_read(0xA, &result); |
| 476 | if (err) |
| 477 | return AE_ERROR; |
| 478 | *value = (result >> 4) & 0x1; |
| 479 | return AE_OK; |
| 480 | } |
| 481 | break; |
| 482 | case ACER_CAP_BRIGHTNESS: |
| 483 | switch (quirks->brightness) { |
| 484 | default: |
| 485 | err = ec_read(0x83, &result); |
| 486 | if (err) |
| 487 | return AE_ERROR; |
| 488 | *value = result; |
| 489 | return AE_OK; |
| 490 | } |
| 491 | break; |
| 492 | default: |
Lin Ming | 0823797 | 2008-08-08 11:57:11 +0800 | [diff] [blame] | 493 | return AE_ERROR; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 494 | } |
| 495 | return AE_OK; |
| 496 | } |
| 497 | |
| 498 | static acpi_status AMW0_set_u32(u32 value, u32 cap, struct wmi_interface *iface) |
| 499 | { |
| 500 | struct wmab_args args; |
| 501 | |
| 502 | args.eax = ACER_AMW0_WRITE; |
| 503 | args.ebx = value ? (1<<8) : 0; |
| 504 | args.ecx = args.edx = 0; |
| 505 | |
| 506 | switch (cap) { |
| 507 | case ACER_CAP_MAILLED: |
| 508 | if (value > 1) |
| 509 | return AE_BAD_PARAMETER; |
| 510 | args.ebx |= ACER_AMW0_MAILLED_MASK; |
| 511 | break; |
| 512 | case ACER_CAP_WIRELESS: |
| 513 | if (value > 1) |
| 514 | return AE_BAD_PARAMETER; |
| 515 | args.ebx |= ACER_AMW0_WIRELESS_MASK; |
| 516 | break; |
| 517 | case ACER_CAP_BLUETOOTH: |
| 518 | if (value > 1) |
| 519 | return AE_BAD_PARAMETER; |
| 520 | args.ebx |= ACER_AMW0_BLUETOOTH_MASK; |
| 521 | break; |
| 522 | case ACER_CAP_BRIGHTNESS: |
| 523 | if (value > max_brightness) |
| 524 | return AE_BAD_PARAMETER; |
| 525 | switch (quirks->brightness) { |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 526 | default: |
Carlos Corbacho | 4609d02 | 2008-02-08 23:51:49 +0000 | [diff] [blame] | 527 | return ec_write(0x83, value); |
| 528 | break; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 529 | } |
| 530 | default: |
Lin Ming | 0823797 | 2008-08-08 11:57:11 +0800 | [diff] [blame] | 531 | return AE_ERROR; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /* Actually do the set */ |
| 535 | return wmab_execute(&args, NULL); |
| 536 | } |
| 537 | |
| 538 | static acpi_status AMW0_find_mailled(void) |
| 539 | { |
| 540 | struct wmab_args args; |
| 541 | struct wmab_ret ret; |
| 542 | acpi_status status = AE_OK; |
| 543 | struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 544 | union acpi_object *obj; |
| 545 | |
| 546 | args.eax = 0x86; |
| 547 | args.ebx = args.ecx = args.edx = 0; |
| 548 | |
| 549 | status = wmab_execute(&args, &out); |
| 550 | if (ACPI_FAILURE(status)) |
| 551 | return status; |
| 552 | |
| 553 | obj = (union acpi_object *) out.pointer; |
| 554 | if (obj && obj->type == ACPI_TYPE_BUFFER && |
| 555 | obj->buffer.length == sizeof(struct wmab_ret)) { |
| 556 | ret = *((struct wmab_ret *) obj->buffer.pointer); |
| 557 | } else { |
Axel Lin | 7677fbd | 2010-07-20 15:19:53 -0700 | [diff] [blame^] | 558 | kfree(out.pointer); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 559 | return AE_ERROR; |
| 560 | } |
| 561 | |
| 562 | if (ret.eex & 0x1) |
| 563 | interface->capability |= ACER_CAP_MAILLED; |
| 564 | |
| 565 | kfree(out.pointer); |
| 566 | |
| 567 | return AE_OK; |
| 568 | } |
| 569 | |
| 570 | static acpi_status AMW0_set_capabilities(void) |
| 571 | { |
| 572 | struct wmab_args args; |
| 573 | struct wmab_ret ret; |
Axel Lin | 7677fbd | 2010-07-20 15:19:53 -0700 | [diff] [blame^] | 574 | acpi_status status; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 575 | struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 576 | union acpi_object *obj; |
| 577 | |
Carlos Corbacho | 5753dd5 | 2008-06-21 09:09:48 +0100 | [diff] [blame] | 578 | /* |
| 579 | * On laptops with this strange GUID (non Acer), normal probing doesn't |
| 580 | * work. |
| 581 | */ |
| 582 | if (wmi_has_guid(AMW0_GUID2)) { |
| 583 | interface->capability |= ACER_CAP_WIRELESS; |
| 584 | return AE_OK; |
| 585 | } |
| 586 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 587 | args.eax = ACER_AMW0_WRITE; |
| 588 | args.ecx = args.edx = 0; |
| 589 | |
| 590 | args.ebx = 0xa2 << 8; |
| 591 | args.ebx |= ACER_AMW0_WIRELESS_MASK; |
| 592 | |
| 593 | status = wmab_execute(&args, &out); |
| 594 | if (ACPI_FAILURE(status)) |
| 595 | return status; |
| 596 | |
Axel Lin | 7677fbd | 2010-07-20 15:19:53 -0700 | [diff] [blame^] | 597 | obj = out.pointer; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 598 | if (obj && obj->type == ACPI_TYPE_BUFFER && |
| 599 | obj->buffer.length == sizeof(struct wmab_ret)) { |
| 600 | ret = *((struct wmab_ret *) obj->buffer.pointer); |
| 601 | } else { |
Axel Lin | 7677fbd | 2010-07-20 15:19:53 -0700 | [diff] [blame^] | 602 | status = AE_ERROR; |
| 603 | goto out; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | if (ret.eax & 0x1) |
| 607 | interface->capability |= ACER_CAP_WIRELESS; |
| 608 | |
| 609 | args.ebx = 2 << 8; |
| 610 | args.ebx |= ACER_AMW0_BLUETOOTH_MASK; |
| 611 | |
Axel Lin | 7677fbd | 2010-07-20 15:19:53 -0700 | [diff] [blame^] | 612 | /* |
| 613 | * It's ok to use existing buffer for next wmab_execute call. |
| 614 | * But we need to kfree(out.pointer) if next wmab_execute fail. |
| 615 | */ |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 616 | status = wmab_execute(&args, &out); |
| 617 | if (ACPI_FAILURE(status)) |
Axel Lin | 7677fbd | 2010-07-20 15:19:53 -0700 | [diff] [blame^] | 618 | goto out; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 619 | |
| 620 | obj = (union acpi_object *) out.pointer; |
| 621 | if (obj && obj->type == ACPI_TYPE_BUFFER |
| 622 | && obj->buffer.length == sizeof(struct wmab_ret)) { |
| 623 | ret = *((struct wmab_ret *) obj->buffer.pointer); |
| 624 | } else { |
Axel Lin | 7677fbd | 2010-07-20 15:19:53 -0700 | [diff] [blame^] | 625 | status = AE_ERROR; |
| 626 | goto out; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | if (ret.eax & 0x1) |
| 630 | interface->capability |= ACER_CAP_BLUETOOTH; |
| 631 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 632 | /* |
| 633 | * This appears to be safe to enable, since all Wistron based laptops |
| 634 | * appear to use the same EC register for brightness, even if they |
| 635 | * differ for wireless, etc |
| 636 | */ |
Carlos Corbacho | 9991d9f | 2008-06-21 09:09:22 +0100 | [diff] [blame] | 637 | if (quirks->brightness >= 0) |
| 638 | interface->capability |= ACER_CAP_BRIGHTNESS; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 639 | |
Axel Lin | 7677fbd | 2010-07-20 15:19:53 -0700 | [diff] [blame^] | 640 | status = AE_OK; |
| 641 | out: |
| 642 | kfree(out.pointer); |
| 643 | return status; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | static struct wmi_interface AMW0_interface = { |
| 647 | .type = ACER_AMW0, |
| 648 | }; |
| 649 | |
| 650 | static struct wmi_interface AMW0_V2_interface = { |
| 651 | .type = ACER_AMW0_V2, |
| 652 | }; |
| 653 | |
| 654 | /* |
| 655 | * New interface (The WMID interface) |
| 656 | */ |
| 657 | static acpi_status |
| 658 | WMI_execute_u32(u32 method_id, u32 in, u32 *out) |
| 659 | { |
| 660 | struct acpi_buffer input = { (acpi_size) sizeof(u32), (void *)(&in) }; |
| 661 | struct acpi_buffer result = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 662 | union acpi_object *obj; |
| 663 | u32 tmp; |
| 664 | acpi_status status; |
| 665 | |
| 666 | status = wmi_evaluate_method(WMID_GUID1, 1, method_id, &input, &result); |
| 667 | |
| 668 | if (ACPI_FAILURE(status)) |
| 669 | return status; |
| 670 | |
| 671 | obj = (union acpi_object *) result.pointer; |
| 672 | if (obj && obj->type == ACPI_TYPE_BUFFER && |
| 673 | obj->buffer.length == sizeof(u32)) { |
| 674 | tmp = *((u32 *) obj->buffer.pointer); |
| 675 | } else { |
| 676 | tmp = 0; |
| 677 | } |
| 678 | |
| 679 | if (out) |
| 680 | *out = tmp; |
| 681 | |
| 682 | kfree(result.pointer); |
| 683 | |
| 684 | return status; |
| 685 | } |
| 686 | |
| 687 | static acpi_status WMID_get_u32(u32 *value, u32 cap, |
| 688 | struct wmi_interface *iface) |
| 689 | { |
| 690 | acpi_status status; |
| 691 | u8 tmp; |
| 692 | u32 result, method_id = 0; |
| 693 | |
| 694 | switch (cap) { |
| 695 | case ACER_CAP_WIRELESS: |
| 696 | method_id = ACER_WMID_GET_WIRELESS_METHODID; |
| 697 | break; |
| 698 | case ACER_CAP_BLUETOOTH: |
| 699 | method_id = ACER_WMID_GET_BLUETOOTH_METHODID; |
| 700 | break; |
| 701 | case ACER_CAP_BRIGHTNESS: |
| 702 | method_id = ACER_WMID_GET_BRIGHTNESS_METHODID; |
| 703 | break; |
| 704 | case ACER_CAP_THREEG: |
| 705 | method_id = ACER_WMID_GET_THREEG_METHODID; |
| 706 | break; |
| 707 | case ACER_CAP_MAILLED: |
| 708 | if (quirks->mailled == 1) { |
| 709 | ec_read(0x9f, &tmp); |
| 710 | *value = tmp & 0x1; |
| 711 | return 0; |
| 712 | } |
| 713 | default: |
Lin Ming | 0823797 | 2008-08-08 11:57:11 +0800 | [diff] [blame] | 714 | return AE_ERROR; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 715 | } |
| 716 | status = WMI_execute_u32(method_id, 0, &result); |
| 717 | |
| 718 | if (ACPI_SUCCESS(status)) |
| 719 | *value = (u8)result; |
| 720 | |
| 721 | return status; |
| 722 | } |
| 723 | |
| 724 | static acpi_status WMID_set_u32(u32 value, u32 cap, struct wmi_interface *iface) |
| 725 | { |
| 726 | u32 method_id = 0; |
| 727 | char param; |
| 728 | |
| 729 | switch (cap) { |
| 730 | case ACER_CAP_BRIGHTNESS: |
| 731 | if (value > max_brightness) |
| 732 | return AE_BAD_PARAMETER; |
| 733 | method_id = ACER_WMID_SET_BRIGHTNESS_METHODID; |
| 734 | break; |
| 735 | case ACER_CAP_WIRELESS: |
| 736 | if (value > 1) |
| 737 | return AE_BAD_PARAMETER; |
| 738 | method_id = ACER_WMID_SET_WIRELESS_METHODID; |
| 739 | break; |
| 740 | case ACER_CAP_BLUETOOTH: |
| 741 | if (value > 1) |
| 742 | return AE_BAD_PARAMETER; |
| 743 | method_id = ACER_WMID_SET_BLUETOOTH_METHODID; |
| 744 | break; |
| 745 | case ACER_CAP_THREEG: |
| 746 | if (value > 1) |
| 747 | return AE_BAD_PARAMETER; |
| 748 | method_id = ACER_WMID_SET_THREEG_METHODID; |
| 749 | break; |
| 750 | case ACER_CAP_MAILLED: |
| 751 | if (value > 1) |
| 752 | return AE_BAD_PARAMETER; |
| 753 | if (quirks->mailled == 1) { |
| 754 | param = value ? 0x92 : 0x93; |
Dmitry Torokhov | 181d683 | 2009-09-16 01:06:43 -0700 | [diff] [blame] | 755 | i8042_lock_chip(); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 756 | i8042_command(¶m, 0x1059); |
Dmitry Torokhov | 181d683 | 2009-09-16 01:06:43 -0700 | [diff] [blame] | 757 | i8042_unlock_chip(); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 758 | return 0; |
| 759 | } |
| 760 | break; |
| 761 | default: |
Lin Ming | 0823797 | 2008-08-08 11:57:11 +0800 | [diff] [blame] | 762 | return AE_ERROR; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 763 | } |
| 764 | return WMI_execute_u32(method_id, (u32)value, NULL); |
| 765 | } |
| 766 | |
| 767 | static acpi_status WMID_set_capabilities(void) |
| 768 | { |
| 769 | struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 770 | union acpi_object *obj; |
| 771 | acpi_status status; |
| 772 | u32 devices; |
| 773 | |
| 774 | status = wmi_query_block(WMID_GUID2, 1, &out); |
| 775 | if (ACPI_FAILURE(status)) |
| 776 | return status; |
| 777 | |
| 778 | obj = (union acpi_object *) out.pointer; |
| 779 | if (obj && obj->type == ACPI_TYPE_BUFFER && |
| 780 | obj->buffer.length == sizeof(u32)) { |
| 781 | devices = *((u32 *) obj->buffer.pointer); |
| 782 | } else { |
Axel Lin | 6690486 | 2010-07-20 15:19:52 -0700 | [diff] [blame] | 783 | kfree(out.pointer); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 784 | return AE_ERROR; |
| 785 | } |
| 786 | |
| 787 | /* Not sure on the meaning of the relevant bits yet to detect these */ |
| 788 | interface->capability |= ACER_CAP_WIRELESS; |
| 789 | interface->capability |= ACER_CAP_THREEG; |
| 790 | |
| 791 | /* WMID always provides brightness methods */ |
| 792 | interface->capability |= ACER_CAP_BRIGHTNESS; |
| 793 | |
| 794 | if (devices & 0x10) |
| 795 | interface->capability |= ACER_CAP_BLUETOOTH; |
| 796 | |
| 797 | if (!(devices & 0x20)) |
| 798 | max_brightness = 0x9; |
| 799 | |
Axel Lin | 6690486 | 2010-07-20 15:19:52 -0700 | [diff] [blame] | 800 | kfree(out.pointer); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 801 | return status; |
| 802 | } |
| 803 | |
| 804 | static struct wmi_interface wmid_interface = { |
| 805 | .type = ACER_WMID, |
| 806 | }; |
| 807 | |
| 808 | /* |
| 809 | * Generic Device (interface-independent) |
| 810 | */ |
| 811 | |
| 812 | static acpi_status get_u32(u32 *value, u32 cap) |
| 813 | { |
Lin Ming | 0823797 | 2008-08-08 11:57:11 +0800 | [diff] [blame] | 814 | acpi_status status = AE_ERROR; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 815 | |
| 816 | switch (interface->type) { |
| 817 | case ACER_AMW0: |
| 818 | status = AMW0_get_u32(value, cap, interface); |
| 819 | break; |
| 820 | case ACER_AMW0_V2: |
| 821 | if (cap == ACER_CAP_MAILLED) { |
| 822 | status = AMW0_get_u32(value, cap, interface); |
| 823 | break; |
| 824 | } |
| 825 | case ACER_WMID: |
| 826 | status = WMID_get_u32(value, cap, interface); |
| 827 | break; |
| 828 | } |
| 829 | |
| 830 | return status; |
| 831 | } |
| 832 | |
| 833 | static acpi_status set_u32(u32 value, u32 cap) |
| 834 | { |
Carlos Corbacho | 5c742b4 | 2008-08-06 19:13:56 +0100 | [diff] [blame] | 835 | acpi_status status; |
| 836 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 837 | if (interface->capability & cap) { |
| 838 | switch (interface->type) { |
| 839 | case ACER_AMW0: |
| 840 | return AMW0_set_u32(value, cap, interface); |
| 841 | case ACER_AMW0_V2: |
Carlos Corbacho | 5c742b4 | 2008-08-06 19:13:56 +0100 | [diff] [blame] | 842 | if (cap == ACER_CAP_MAILLED) |
| 843 | return AMW0_set_u32(value, cap, interface); |
| 844 | |
| 845 | /* |
| 846 | * On some models, some WMID methods don't toggle |
| 847 | * properly. For those cases, we want to run the AMW0 |
| 848 | * method afterwards to be certain we've really toggled |
| 849 | * the device state. |
| 850 | */ |
| 851 | if (cap == ACER_CAP_WIRELESS || |
| 852 | cap == ACER_CAP_BLUETOOTH) { |
| 853 | status = WMID_set_u32(value, cap, interface); |
| 854 | if (ACPI_FAILURE(status)) |
| 855 | return status; |
| 856 | |
| 857 | return AMW0_set_u32(value, cap, interface); |
| 858 | } |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 859 | case ACER_WMID: |
| 860 | return WMID_set_u32(value, cap, interface); |
| 861 | default: |
| 862 | return AE_BAD_PARAMETER; |
| 863 | } |
| 864 | } |
| 865 | return AE_BAD_PARAMETER; |
| 866 | } |
| 867 | |
| 868 | static void __init acer_commandline_init(void) |
| 869 | { |
| 870 | /* |
| 871 | * These will all fail silently if the value given is invalid, or the |
| 872 | * capability isn't available on the given interface |
| 873 | */ |
| 874 | set_u32(mailled, ACER_CAP_MAILLED); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 875 | set_u32(threeg, ACER_CAP_THREEG); |
| 876 | set_u32(brightness, ACER_CAP_BRIGHTNESS); |
| 877 | } |
| 878 | |
| 879 | /* |
| 880 | * LED device (Mail LED only, no other LEDs known yet) |
| 881 | */ |
| 882 | static void mail_led_set(struct led_classdev *led_cdev, |
| 883 | enum led_brightness value) |
| 884 | { |
| 885 | set_u32(value, ACER_CAP_MAILLED); |
| 886 | } |
| 887 | |
| 888 | static struct led_classdev mail_led = { |
Carlos Corbacho | 343c004 | 2008-02-24 13:34:18 +0000 | [diff] [blame] | 889 | .name = "acer-wmi::mail", |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 890 | .brightness_set = mail_led_set, |
| 891 | }; |
| 892 | |
Sam Ravnborg | 7560e38 | 2008-02-17 13:22:54 +0100 | [diff] [blame] | 893 | static int __devinit acer_led_init(struct device *dev) |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 894 | { |
| 895 | return led_classdev_register(dev, &mail_led); |
| 896 | } |
| 897 | |
| 898 | static void acer_led_exit(void) |
| 899 | { |
| 900 | led_classdev_unregister(&mail_led); |
| 901 | } |
| 902 | |
| 903 | /* |
| 904 | * Backlight device |
| 905 | */ |
| 906 | static struct backlight_device *acer_backlight_device; |
| 907 | |
| 908 | static int read_brightness(struct backlight_device *bd) |
| 909 | { |
| 910 | u32 value; |
| 911 | get_u32(&value, ACER_CAP_BRIGHTNESS); |
| 912 | return value; |
| 913 | } |
| 914 | |
| 915 | static int update_bl_status(struct backlight_device *bd) |
| 916 | { |
Carlos Corbacho | f2b585b | 2008-06-21 09:09:27 +0100 | [diff] [blame] | 917 | int intensity = bd->props.brightness; |
| 918 | |
| 919 | if (bd->props.power != FB_BLANK_UNBLANK) |
| 920 | intensity = 0; |
| 921 | if (bd->props.fb_blank != FB_BLANK_UNBLANK) |
| 922 | intensity = 0; |
| 923 | |
| 924 | set_u32(intensity, ACER_CAP_BRIGHTNESS); |
| 925 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | static struct backlight_ops acer_bl_ops = { |
| 930 | .get_brightness = read_brightness, |
| 931 | .update_status = update_bl_status, |
| 932 | }; |
| 933 | |
Sam Ravnborg | 7560e38 | 2008-02-17 13:22:54 +0100 | [diff] [blame] | 934 | static int __devinit acer_backlight_init(struct device *dev) |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 935 | { |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 936 | struct backlight_properties props; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 937 | struct backlight_device *bd; |
| 938 | |
Matthew Garrett | a19a6ee | 2010-02-17 16:39:44 -0500 | [diff] [blame] | 939 | memset(&props, 0, sizeof(struct backlight_properties)); |
| 940 | props.max_brightness = max_brightness; |
| 941 | bd = backlight_device_register("acer-wmi", dev, NULL, &acer_bl_ops, |
| 942 | &props); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 943 | if (IS_ERR(bd)) { |
| 944 | printk(ACER_ERR "Could not register Acer backlight device\n"); |
| 945 | acer_backlight_device = NULL; |
| 946 | return PTR_ERR(bd); |
| 947 | } |
| 948 | |
| 949 | acer_backlight_device = bd; |
| 950 | |
Carlos Corbacho | f2b585b | 2008-06-21 09:09:27 +0100 | [diff] [blame] | 951 | bd->props.power = FB_BLANK_UNBLANK; |
Carlos Corbacho | 6f6ef82 | 2009-12-26 19:24:31 +0000 | [diff] [blame] | 952 | bd->props.brightness = read_brightness(bd); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 953 | backlight_update_status(bd); |
| 954 | return 0; |
| 955 | } |
| 956 | |
Sam Ravnborg | 7560e38 | 2008-02-17 13:22:54 +0100 | [diff] [blame] | 957 | static void acer_backlight_exit(void) |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 958 | { |
| 959 | backlight_device_unregister(acer_backlight_device); |
| 960 | } |
| 961 | |
| 962 | /* |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 963 | * Rfkill devices |
| 964 | */ |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 965 | static void acer_rfkill_update(struct work_struct *ignored); |
| 966 | static DECLARE_DELAYED_WORK(acer_rfkill_work, acer_rfkill_update); |
| 967 | static void acer_rfkill_update(struct work_struct *ignored) |
| 968 | { |
| 969 | u32 state; |
| 970 | acpi_status status; |
| 971 | |
| 972 | status = get_u32(&state, ACER_CAP_WIRELESS); |
| 973 | if (ACPI_SUCCESS(status)) |
Troy Moure | a878417 | 2009-06-17 11:51:56 +0100 | [diff] [blame] | 974 | rfkill_set_sw_state(wireless_rfkill, !state); |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 975 | |
| 976 | if (has_cap(ACER_CAP_BLUETOOTH)) { |
| 977 | status = get_u32(&state, ACER_CAP_BLUETOOTH); |
| 978 | if (ACPI_SUCCESS(status)) |
Troy Moure | a878417 | 2009-06-17 11:51:56 +0100 | [diff] [blame] | 979 | rfkill_set_sw_state(bluetooth_rfkill, !state); |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 980 | } |
| 981 | |
Carlos Corbacho | ae3a1b4 | 2008-10-10 17:33:35 +0100 | [diff] [blame] | 982 | schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ)); |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 983 | } |
| 984 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 985 | static int acer_rfkill_set(void *data, bool blocked) |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 986 | { |
| 987 | acpi_status status; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 988 | u32 cap = (unsigned long)data; |
Alan Jenkins | ed5c8ef | 2009-07-19 09:48:28 +0100 | [diff] [blame] | 989 | status = set_u32(!blocked, cap); |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 990 | if (ACPI_FAILURE(status)) |
| 991 | return -ENODEV; |
| 992 | return 0; |
| 993 | } |
| 994 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 995 | static const struct rfkill_ops acer_rfkill_ops = { |
| 996 | .set_block = acer_rfkill_set, |
| 997 | }; |
| 998 | |
| 999 | static struct rfkill *acer_rfkill_register(struct device *dev, |
| 1000 | enum rfkill_type type, |
| 1001 | char *name, u32 cap) |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1002 | { |
| 1003 | int err; |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1004 | struct rfkill *rfkill_dev; |
| 1005 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1006 | rfkill_dev = rfkill_alloc(name, dev, type, |
| 1007 | &acer_rfkill_ops, |
| 1008 | (void *)(unsigned long)cap); |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1009 | if (!rfkill_dev) |
| 1010 | return ERR_PTR(-ENOMEM); |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1011 | |
| 1012 | err = rfkill_register(rfkill_dev); |
| 1013 | if (err) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1014 | rfkill_destroy(rfkill_dev); |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1015 | return ERR_PTR(err); |
| 1016 | } |
| 1017 | return rfkill_dev; |
| 1018 | } |
| 1019 | |
| 1020 | static int acer_rfkill_init(struct device *dev) |
| 1021 | { |
| 1022 | wireless_rfkill = acer_rfkill_register(dev, RFKILL_TYPE_WLAN, |
| 1023 | "acer-wireless", ACER_CAP_WIRELESS); |
| 1024 | if (IS_ERR(wireless_rfkill)) |
| 1025 | return PTR_ERR(wireless_rfkill); |
| 1026 | |
| 1027 | if (has_cap(ACER_CAP_BLUETOOTH)) { |
| 1028 | bluetooth_rfkill = acer_rfkill_register(dev, |
| 1029 | RFKILL_TYPE_BLUETOOTH, "acer-bluetooth", |
| 1030 | ACER_CAP_BLUETOOTH); |
| 1031 | if (IS_ERR(bluetooth_rfkill)) { |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1032 | rfkill_unregister(wireless_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1033 | rfkill_destroy(wireless_rfkill); |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1034 | return PTR_ERR(bluetooth_rfkill); |
| 1035 | } |
| 1036 | } |
| 1037 | |
Carlos Corbacho | ae3a1b4 | 2008-10-10 17:33:35 +0100 | [diff] [blame] | 1038 | schedule_delayed_work(&acer_rfkill_work, round_jiffies_relative(HZ)); |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1039 | |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
| 1043 | static void acer_rfkill_exit(void) |
| 1044 | { |
| 1045 | cancel_delayed_work_sync(&acer_rfkill_work); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1046 | |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1047 | rfkill_unregister(wireless_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1048 | rfkill_destroy(wireless_rfkill); |
| 1049 | |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1050 | if (has_cap(ACER_CAP_BLUETOOTH)) { |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1051 | rfkill_unregister(bluetooth_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 1052 | rfkill_destroy(bluetooth_rfkill); |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1053 | } |
| 1054 | return; |
| 1055 | } |
| 1056 | |
| 1057 | /* |
Carlos Corbacho | 7d9a06d | 2008-10-08 21:40:26 +0100 | [diff] [blame] | 1058 | * sysfs interface |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1059 | */ |
Carlos Corbacho | 7d9a06d | 2008-10-08 21:40:26 +0100 | [diff] [blame] | 1060 | static ssize_t show_bool_threeg(struct device *dev, |
| 1061 | struct device_attribute *attr, char *buf) |
| 1062 | { |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1063 | u32 result; \ |
Carlos Corbacho | 7d9a06d | 2008-10-08 21:40:26 +0100 | [diff] [blame] | 1064 | acpi_status status = get_u32(&result, ACER_CAP_THREEG); |
| 1065 | if (ACPI_SUCCESS(status)) |
| 1066 | return sprintf(buf, "%u\n", result); |
| 1067 | return sprintf(buf, "Read error\n"); |
| 1068 | } |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1069 | |
Carlos Corbacho | 7d9a06d | 2008-10-08 21:40:26 +0100 | [diff] [blame] | 1070 | static ssize_t set_bool_threeg(struct device *dev, |
| 1071 | struct device_attribute *attr, const char *buf, size_t count) |
| 1072 | { |
| 1073 | u32 tmp = simple_strtoul(buf, NULL, 10); |
| 1074 | acpi_status status = set_u32(tmp, ACER_CAP_THREEG); |
| 1075 | if (ACPI_FAILURE(status)) |
| 1076 | return -EINVAL; |
| 1077 | return count; |
| 1078 | } |
| 1079 | static DEVICE_ATTR(threeg, S_IWUGO | S_IRUGO | S_IWUSR, show_bool_threeg, |
| 1080 | set_bool_threeg); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1081 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1082 | static ssize_t show_interface(struct device *dev, struct device_attribute *attr, |
| 1083 | char *buf) |
| 1084 | { |
| 1085 | switch (interface->type) { |
| 1086 | case ACER_AMW0: |
| 1087 | return sprintf(buf, "AMW0\n"); |
| 1088 | case ACER_AMW0_V2: |
| 1089 | return sprintf(buf, "AMW0 v2\n"); |
| 1090 | case ACER_WMID: |
| 1091 | return sprintf(buf, "WMID\n"); |
| 1092 | default: |
| 1093 | return sprintf(buf, "Error!\n"); |
| 1094 | } |
| 1095 | } |
| 1096 | |
Axel Lin | 370525d | 2010-06-30 10:20:23 +0800 | [diff] [blame] | 1097 | static DEVICE_ATTR(interface, S_IRUGO, show_interface, NULL); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1098 | |
| 1099 | /* |
Carlos Corbacho | 8114352 | 2008-06-21 09:09:53 +0100 | [diff] [blame] | 1100 | * debugfs functions |
| 1101 | */ |
| 1102 | static u32 get_wmid_devices(void) |
| 1103 | { |
| 1104 | struct acpi_buffer out = {ACPI_ALLOCATE_BUFFER, NULL}; |
| 1105 | union acpi_object *obj; |
| 1106 | acpi_status status; |
Axel Lin | 6690486 | 2010-07-20 15:19:52 -0700 | [diff] [blame] | 1107 | u32 devices = 0; |
Carlos Corbacho | 8114352 | 2008-06-21 09:09:53 +0100 | [diff] [blame] | 1108 | |
| 1109 | status = wmi_query_block(WMID_GUID2, 1, &out); |
| 1110 | if (ACPI_FAILURE(status)) |
| 1111 | return 0; |
| 1112 | |
| 1113 | obj = (union acpi_object *) out.pointer; |
| 1114 | if (obj && obj->type == ACPI_TYPE_BUFFER && |
| 1115 | obj->buffer.length == sizeof(u32)) { |
Axel Lin | 6690486 | 2010-07-20 15:19:52 -0700 | [diff] [blame] | 1116 | devices = *((u32 *) obj->buffer.pointer); |
Carlos Corbacho | 8114352 | 2008-06-21 09:09:53 +0100 | [diff] [blame] | 1117 | } |
Axel Lin | 6690486 | 2010-07-20 15:19:52 -0700 | [diff] [blame] | 1118 | |
| 1119 | kfree(out.pointer); |
| 1120 | return devices; |
Carlos Corbacho | 8114352 | 2008-06-21 09:09:53 +0100 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | /* |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1124 | * Platform device |
| 1125 | */ |
| 1126 | static int __devinit acer_platform_probe(struct platform_device *device) |
| 1127 | { |
| 1128 | int err; |
| 1129 | |
| 1130 | if (has_cap(ACER_CAP_MAILLED)) { |
| 1131 | err = acer_led_init(&device->dev); |
| 1132 | if (err) |
| 1133 | goto error_mailled; |
| 1134 | } |
| 1135 | |
| 1136 | if (has_cap(ACER_CAP_BRIGHTNESS)) { |
| 1137 | err = acer_backlight_init(&device->dev); |
| 1138 | if (err) |
| 1139 | goto error_brightness; |
| 1140 | } |
| 1141 | |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1142 | err = acer_rfkill_init(&device->dev); |
Andy Whitcroft | 350e329 | 2009-04-04 09:33:34 +0100 | [diff] [blame] | 1143 | if (err) |
| 1144 | goto error_rfkill; |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1145 | |
| 1146 | return err; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1147 | |
Andy Whitcroft | 350e329 | 2009-04-04 09:33:34 +0100 | [diff] [blame] | 1148 | error_rfkill: |
| 1149 | if (has_cap(ACER_CAP_BRIGHTNESS)) |
| 1150 | acer_backlight_exit(); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1151 | error_brightness: |
Andy Whitcroft | 350e329 | 2009-04-04 09:33:34 +0100 | [diff] [blame] | 1152 | if (has_cap(ACER_CAP_MAILLED)) |
| 1153 | acer_led_exit(); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1154 | error_mailled: |
| 1155 | return err; |
| 1156 | } |
| 1157 | |
| 1158 | static int acer_platform_remove(struct platform_device *device) |
| 1159 | { |
| 1160 | if (has_cap(ACER_CAP_MAILLED)) |
| 1161 | acer_led_exit(); |
| 1162 | if (has_cap(ACER_CAP_BRIGHTNESS)) |
| 1163 | acer_backlight_exit(); |
Carlos Corbacho | 0606e1a | 2008-10-08 21:40:21 +0100 | [diff] [blame] | 1164 | |
| 1165 | acer_rfkill_exit(); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | static int acer_platform_suspend(struct platform_device *dev, |
| 1170 | pm_message_t state) |
| 1171 | { |
| 1172 | u32 value; |
| 1173 | struct acer_data *data = &interface->data; |
| 1174 | |
| 1175 | if (!data) |
| 1176 | return -ENOMEM; |
| 1177 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1178 | if (has_cap(ACER_CAP_MAILLED)) { |
| 1179 | get_u32(&value, ACER_CAP_MAILLED); |
| 1180 | data->mailled = value; |
| 1181 | } |
| 1182 | |
| 1183 | if (has_cap(ACER_CAP_BRIGHTNESS)) { |
| 1184 | get_u32(&value, ACER_CAP_BRIGHTNESS); |
| 1185 | data->brightness = value; |
| 1186 | } |
| 1187 | |
| 1188 | return 0; |
| 1189 | } |
| 1190 | |
| 1191 | static int acer_platform_resume(struct platform_device *device) |
| 1192 | { |
| 1193 | struct acer_data *data = &interface->data; |
| 1194 | |
| 1195 | if (!data) |
| 1196 | return -ENOMEM; |
| 1197 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1198 | if (has_cap(ACER_CAP_MAILLED)) |
| 1199 | set_u32(data->mailled, ACER_CAP_MAILLED); |
| 1200 | |
| 1201 | if (has_cap(ACER_CAP_BRIGHTNESS)) |
| 1202 | set_u32(data->brightness, ACER_CAP_BRIGHTNESS); |
| 1203 | |
| 1204 | return 0; |
| 1205 | } |
| 1206 | |
| 1207 | static struct platform_driver acer_platform_driver = { |
| 1208 | .driver = { |
| 1209 | .name = "acer-wmi", |
| 1210 | .owner = THIS_MODULE, |
| 1211 | }, |
| 1212 | .probe = acer_platform_probe, |
| 1213 | .remove = acer_platform_remove, |
| 1214 | .suspend = acer_platform_suspend, |
| 1215 | .resume = acer_platform_resume, |
| 1216 | }; |
| 1217 | |
| 1218 | static struct platform_device *acer_platform_device; |
| 1219 | |
| 1220 | static int remove_sysfs(struct platform_device *device) |
| 1221 | { |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1222 | if (has_cap(ACER_CAP_THREEG)) |
| 1223 | device_remove_file(&device->dev, &dev_attr_threeg); |
| 1224 | |
| 1225 | device_remove_file(&device->dev, &dev_attr_interface); |
| 1226 | |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | static int create_sysfs(void) |
| 1231 | { |
| 1232 | int retval = -ENOMEM; |
| 1233 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1234 | if (has_cap(ACER_CAP_THREEG)) { |
| 1235 | retval = device_create_file(&acer_platform_device->dev, |
| 1236 | &dev_attr_threeg); |
| 1237 | if (retval) |
| 1238 | goto error_sysfs; |
| 1239 | } |
| 1240 | |
| 1241 | retval = device_create_file(&acer_platform_device->dev, |
| 1242 | &dev_attr_interface); |
| 1243 | if (retval) |
| 1244 | goto error_sysfs; |
| 1245 | |
| 1246 | return 0; |
| 1247 | |
| 1248 | error_sysfs: |
| 1249 | remove_sysfs(acer_platform_device); |
| 1250 | return retval; |
| 1251 | } |
| 1252 | |
Carlos Corbacho | 8114352 | 2008-06-21 09:09:53 +0100 | [diff] [blame] | 1253 | static void remove_debugfs(void) |
| 1254 | { |
| 1255 | debugfs_remove(interface->debug.devices); |
| 1256 | debugfs_remove(interface->debug.root); |
| 1257 | } |
| 1258 | |
| 1259 | static int create_debugfs(void) |
| 1260 | { |
| 1261 | interface->debug.root = debugfs_create_dir("acer-wmi", NULL); |
| 1262 | if (!interface->debug.root) { |
| 1263 | printk(ACER_ERR "Failed to create debugfs directory"); |
| 1264 | return -ENOMEM; |
| 1265 | } |
| 1266 | |
| 1267 | interface->debug.devices = debugfs_create_u32("devices", S_IRUGO, |
| 1268 | interface->debug.root, |
| 1269 | &interface->debug.wmid_devices); |
| 1270 | if (!interface->debug.devices) |
| 1271 | goto error_debugfs; |
| 1272 | |
| 1273 | return 0; |
| 1274 | |
| 1275 | error_debugfs: |
Russ Dill | 39dbbb4 | 2008-09-02 14:35:40 -0700 | [diff] [blame] | 1276 | remove_debugfs(); |
Carlos Corbacho | 8114352 | 2008-06-21 09:09:53 +0100 | [diff] [blame] | 1277 | return -ENOMEM; |
| 1278 | } |
| 1279 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1280 | static int __init acer_wmi_init(void) |
| 1281 | { |
| 1282 | int err; |
| 1283 | |
Carlos Corbacho | 860f0c6 | 2008-06-21 09:09:58 +0100 | [diff] [blame] | 1284 | printk(ACER_INFO "Acer Laptop ACPI-WMI Extras\n"); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1285 | |
Carlos Corbacho | a74dd5f | 2009-04-04 09:33:29 +0100 | [diff] [blame] | 1286 | if (dmi_check_system(acer_blacklist)) { |
| 1287 | printk(ACER_INFO "Blacklisted hardware detected - " |
| 1288 | "not loading\n"); |
| 1289 | return -ENODEV; |
| 1290 | } |
| 1291 | |
Carlos Corbacho | 9991d9f | 2008-06-21 09:09:22 +0100 | [diff] [blame] | 1292 | find_quirks(); |
| 1293 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1294 | /* |
| 1295 | * Detect which ACPI-WMI interface we're using. |
| 1296 | */ |
| 1297 | if (wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1)) |
| 1298 | interface = &AMW0_V2_interface; |
| 1299 | |
| 1300 | if (!wmi_has_guid(AMW0_GUID1) && wmi_has_guid(WMID_GUID1)) |
| 1301 | interface = &wmid_interface; |
| 1302 | |
| 1303 | if (wmi_has_guid(WMID_GUID2) && interface) { |
| 1304 | if (ACPI_FAILURE(WMID_set_capabilities())) { |
Carlos Corbacho | 8d039bc | 2008-03-12 20:12:50 +0000 | [diff] [blame] | 1305 | printk(ACER_ERR "Unable to detect available WMID " |
| 1306 | "devices\n"); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1307 | return -ENODEV; |
| 1308 | } |
| 1309 | } else if (!wmi_has_guid(WMID_GUID2) && interface) { |
Carlos Corbacho | 8d039bc | 2008-03-12 20:12:50 +0000 | [diff] [blame] | 1310 | printk(ACER_ERR "No WMID device detection method found\n"); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1311 | return -ENODEV; |
| 1312 | } |
| 1313 | |
| 1314 | if (wmi_has_guid(AMW0_GUID1) && !wmi_has_guid(WMID_GUID1)) { |
| 1315 | interface = &AMW0_interface; |
| 1316 | |
| 1317 | if (ACPI_FAILURE(AMW0_set_capabilities())) { |
Carlos Corbacho | 8d039bc | 2008-03-12 20:12:50 +0000 | [diff] [blame] | 1318 | printk(ACER_ERR "Unable to detect available AMW0 " |
| 1319 | "devices\n"); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1320 | return -ENODEV; |
| 1321 | } |
| 1322 | } |
| 1323 | |
Carlos Corbacho | 9b963c4 | 2008-02-24 13:34:29 +0000 | [diff] [blame] | 1324 | if (wmi_has_guid(AMW0_GUID1)) |
| 1325 | AMW0_find_mailled(); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1326 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1327 | if (!interface) { |
Carlos Corbacho | 8d039bc | 2008-03-12 20:12:50 +0000 | [diff] [blame] | 1328 | printk(ACER_ERR "No or unsupported WMI interface, unable to " |
| 1329 | "load\n"); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1330 | return -ENODEV; |
| 1331 | } |
| 1332 | |
Arjan van de Ven | 83097ac | 2008-08-23 21:45:21 -0700 | [diff] [blame] | 1333 | set_quirks(); |
| 1334 | |
Michael Spang | 1ba869e | 2009-03-12 14:31:34 -0700 | [diff] [blame] | 1335 | if (acpi_video_backlight_support() && has_cap(ACER_CAP_BRIGHTNESS)) { |
Thomas Renninger | febf2d9 | 2008-08-01 17:37:56 +0200 | [diff] [blame] | 1336 | interface->capability &= ~ACER_CAP_BRIGHTNESS; |
| 1337 | printk(ACER_INFO "Brightness must be controlled by " |
| 1338 | "generic video driver\n"); |
| 1339 | } |
| 1340 | |
Axel Lin | 1c79632 | 2010-06-22 16:17:38 +0800 | [diff] [blame] | 1341 | err = platform_driver_register(&acer_platform_driver); |
| 1342 | if (err) { |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1343 | printk(ACER_ERR "Unable to register platform driver.\n"); |
| 1344 | goto error_platform_register; |
| 1345 | } |
Axel Lin | 1c79632 | 2010-06-22 16:17:38 +0800 | [diff] [blame] | 1346 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1347 | acer_platform_device = platform_device_alloc("acer-wmi", -1); |
Axel Lin | 1c79632 | 2010-06-22 16:17:38 +0800 | [diff] [blame] | 1348 | if (!acer_platform_device) { |
| 1349 | err = -ENOMEM; |
| 1350 | goto error_device_alloc; |
| 1351 | } |
| 1352 | |
| 1353 | err = platform_device_add(acer_platform_device); |
| 1354 | if (err) |
| 1355 | goto error_device_add; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1356 | |
| 1357 | err = create_sysfs(); |
| 1358 | if (err) |
Axel Lin | 1c79632 | 2010-06-22 16:17:38 +0800 | [diff] [blame] | 1359 | goto error_create_sys; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1360 | |
Carlos Corbacho | 8114352 | 2008-06-21 09:09:53 +0100 | [diff] [blame] | 1361 | if (wmi_has_guid(WMID_GUID2)) { |
| 1362 | interface->debug.wmid_devices = get_wmid_devices(); |
| 1363 | err = create_debugfs(); |
| 1364 | if (err) |
Axel Lin | 1c79632 | 2010-06-22 16:17:38 +0800 | [diff] [blame] | 1365 | goto error_create_debugfs; |
Carlos Corbacho | 8114352 | 2008-06-21 09:09:53 +0100 | [diff] [blame] | 1366 | } |
| 1367 | |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1368 | /* Override any initial settings with values from the commandline */ |
| 1369 | acer_commandline_init(); |
| 1370 | |
| 1371 | return 0; |
| 1372 | |
Axel Lin | 1c79632 | 2010-06-22 16:17:38 +0800 | [diff] [blame] | 1373 | error_create_debugfs: |
| 1374 | remove_sysfs(acer_platform_device); |
| 1375 | error_create_sys: |
| 1376 | platform_device_del(acer_platform_device); |
| 1377 | error_device_add: |
| 1378 | platform_device_put(acer_platform_device); |
| 1379 | error_device_alloc: |
| 1380 | platform_driver_unregister(&acer_platform_driver); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1381 | error_platform_register: |
Axel Lin | 1c79632 | 2010-06-22 16:17:38 +0800 | [diff] [blame] | 1382 | return err; |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | static void __exit acer_wmi_exit(void) |
| 1386 | { |
| 1387 | remove_sysfs(acer_platform_device); |
Russ Dill | 39dbbb4 | 2008-09-02 14:35:40 -0700 | [diff] [blame] | 1388 | remove_debugfs(); |
Axel Lin | 97ba0af | 2010-06-03 15:18:03 +0800 | [diff] [blame] | 1389 | platform_device_unregister(acer_platform_device); |
Carlos Corbacho | 745a5d2 | 2008-02-05 02:17:10 +0000 | [diff] [blame] | 1390 | platform_driver_unregister(&acer_platform_driver); |
| 1391 | |
| 1392 | printk(ACER_INFO "Acer Laptop WMI Extras unloaded\n"); |
| 1393 | return; |
| 1394 | } |
| 1395 | |
| 1396 | module_init(acer_wmi_init); |
| 1397 | module_exit(acer_wmi_exit); |