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