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