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