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