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