Version:  2.0.40 2.2.26 2.4.37 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2 4.3 4.4 4.5 4.6

Linux/drivers/platform/x86/acer-wmi.c

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

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us