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