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