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