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