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