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