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