blob: 1d799b3fc4e897940d5e9036ff7a691172c49b80 [file] [log] [blame]
Corentin Chary85091b72007-01-26 14:04:30 +01001/*
2 * asus-laptop.c - Asus Laptop Support
3 *
4 *
5 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
Corentin Chary8ec555c2007-03-11 10:28:03 +01006 * Copyright (C) 2006-2007 Corentin Chary
Corentin Chary85091b72007-01-26 14:04:30 +01007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 *
23 * The development page for this driver is located at
24 * http://sourceforge.net/projects/acpi4asus/
25 *
26 * Credits:
27 * Pontus Fuchs - Helper functions, cleanup
28 * Johann Wiesner - Small compile fixes
29 * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
30 * Eric Burghard - LED display support for W1N
31 * Josh Green - Light Sens support
32 * Thomas Tuttle - His first patch for led support was very helpfull
Corentin Charye539c2f2007-05-06 14:47:06 +020033 * Sam Lin - GPS support
Corentin Chary85091b72007-01-26 14:04:30 +010034 */
35
Corentin Chary2fcc23d2009-06-19 14:52:03 +020036#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37
Corentin Chary85091b72007-01-26 14:04:30 +010038#include <linux/kernel.h>
39#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/types.h>
42#include <linux/err.h>
43#include <linux/proc_fs.h>
Corentin Chary6b7091e2007-01-26 14:04:45 +010044#include <linux/backlight.h>
45#include <linux/fb.h>
Corentin Charybe18cda2007-01-26 14:04:35 +010046#include <linux/leds.h>
Corentin Chary85091b72007-01-26 14:04:30 +010047#include <linux/platform_device.h>
48#include <acpi/acpi_drivers.h>
49#include <acpi/acpi_bus.h>
50#include <asm/uaccess.h>
Corentin Chary034ce902009-01-20 16:17:43 +010051#include <linux/input.h>
Corentin Chary85091b72007-01-26 14:04:30 +010052
Corentin Charyf3985322007-05-06 14:48:22 +020053#define ASUS_LAPTOP_VERSION "0.42"
Corentin Chary85091b72007-01-26 14:04:30 +010054
55#define ASUS_HOTK_NAME "Asus Laptop Support"
56#define ASUS_HOTK_CLASS "hotkey"
57#define ASUS_HOTK_DEVICE_NAME "Hotkey"
Corentin Chary2fcc23d2009-06-19 14:52:03 +020058#define ASUS_HOTK_FILE KBUILD_MODNAME
Corentin Chary85091b72007-01-26 14:04:30 +010059#define ASUS_HOTK_PREFIX "\\_SB.ATKD."
60
Corentin Chary2fcc23d2009-06-19 14:52:03 +020061
Corentin Charybe18cda2007-01-26 14:04:35 +010062/*
Corentin Chary6b7091e2007-01-26 14:04:45 +010063 * Some events we use, same for all Asus
64 */
65#define ATKD_BR_UP 0x10
66#define ATKD_BR_DOWN 0x20
67#define ATKD_LCD_ON 0x33
68#define ATKD_LCD_OFF 0x34
69
70/*
Corentin Chary4564de12007-01-26 14:04:40 +010071 * Known bits returned by \_SB.ATKD.HWRS
Corentin Charybe18cda2007-01-26 14:04:35 +010072 */
Corentin Chary4564de12007-01-26 14:04:40 +010073#define WL_HWRS 0x80
74#define BT_HWRS 0x100
75
76/*
77 * Flags for hotk status
78 * WL_ON and BT_ON are also used for wireless_status()
79 */
Corentin Charybe966662009-08-29 10:28:29 +020080#define WL_ON 0x01 /* internal Wifi */
81#define BT_ON 0x02 /* internal Bluetooth */
82#define MLED_ON 0x04 /* mail LED */
83#define TLED_ON 0x08 /* touchpad LED */
84#define RLED_ON 0x10 /* Record LED */
85#define PLED_ON 0x20 /* Phone LED */
86#define GLED_ON 0x40 /* Gaming LED */
87#define LCD_ON 0x80 /* LCD backlight */
88#define GPS_ON 0x100 /* GPS */
89#define KEY_ON 0x200 /* Keyboard backlight */
Corentin Charybe18cda2007-01-26 14:04:35 +010090
Corentin Chary85091b72007-01-26 14:04:30 +010091#define ASUS_LOG ASUS_HOTK_FILE ": "
92#define ASUS_ERR KERN_ERR ASUS_LOG
93#define ASUS_WARNING KERN_WARNING ASUS_LOG
94#define ASUS_NOTICE KERN_NOTICE ASUS_LOG
95#define ASUS_INFO KERN_INFO ASUS_LOG
96#define ASUS_DEBUG KERN_DEBUG ASUS_LOG
97
98MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
99MODULE_DESCRIPTION(ASUS_HOTK_NAME);
100MODULE_LICENSE("GPL");
101
Corentin Charybe966662009-08-29 10:28:29 +0200102/*
103 * WAPF defines the behavior of the Fn+Fx wlan key
Corentin Chary185e5af2007-03-11 10:27:33 +0100104 * The significance of values is yet to be found, but
105 * most of the time:
106 * 0x0 will do nothing
107 * 0x1 will allow to control the device with Fn+Fx key.
108 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
109 * 0x5 like 0x1 or 0x4
110 * So, if something doesn't work as you want, just try other values =)
111 */
112static uint wapf = 1;
113module_param(wapf, uint, 0644);
114MODULE_PARM_DESC(wapf, "WAPF value");
115
Corentin Chary0e875f42010-01-10 20:49:26 +0100116static uint wireless_status = 1;
117static uint bluetooth_status = 1;
118
119module_param(wireless_status, uint, 0644);
120MODULE_PARM_DESC(wireless_status, "Set the wireless status on boot "
121 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
122 "default is 1");
123
124module_param(bluetooth_status, uint, 0644);
125MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
126 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
127 "default is 1");
128
Corentin Chary85091b72007-01-26 14:04:30 +0100129#define ASUS_HANDLE(object, paths...) \
130 static acpi_handle object##_handle = NULL; \
131 static char *object##_paths[] = { paths }
132
Corentin Charybe18cda2007-01-26 14:04:35 +0100133/* LED */
134ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
135ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
Len Brown8def05f2007-01-30 01:46:43 -0500136ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */
137ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */
Corentin Charyfdd8d082007-03-11 10:26:48 +0100138ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED"); /* G1, G2 (probably) */
Corentin Charybe18cda2007-01-26 14:04:35 +0100139
Corentin Chary722ad972007-01-26 14:04:55 +0100140/* LEDD */
141ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
142
Corentin Charybe966662009-08-29 10:28:29 +0200143/*
144 * Bluetooth and WLAN
Corentin Chary4564de12007-01-26 14:04:40 +0100145 * WLED and BLED are not handled like other XLED, because in some dsdt
146 * they also control the WLAN/Bluetooth device.
147 */
148ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED");
149ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED");
Len Brown8def05f2007-01-30 01:46:43 -0500150ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */
Corentin Chary4564de12007-01-26 14:04:40 +0100151
Corentin Chary6b7091e2007-01-26 14:04:45 +0100152/* Brightness */
153ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV");
154ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV");
155
156/* Backlight */
Len Brown8def05f2007-01-30 01:46:43 -0500157ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
158 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
159 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
160 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
161 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
Torsten Krah4d0b856e2008-10-17 09:47:57 +0200162 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */
Len Brown8def05f2007-01-30 01:46:43 -0500163 "\\_SB.PCI0.PX40.Q10", /* S1x */
164 "\\Q10"); /* A2x, L2D, L3D, M2E */
Corentin Chary6b7091e2007-01-26 14:04:45 +0100165
Corentin Chary78127b42007-01-26 14:04:49 +0100166/* Display */
167ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
Corentin Charybe966662009-08-29 10:28:29 +0200168ASUS_HANDLE(display_get,
169 /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */
170 "\\_SB.PCI0.P0P1.VGA.GETD",
171 /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */
172 "\\_SB.PCI0.P0P2.VGA.GETD",
173 /* A6V A6Q */
174 "\\_SB.PCI0.P0P3.VGA.GETD",
175 /* A6T, A6M */
176 "\\_SB.PCI0.P0PA.VGA.GETD",
177 /* L3C */
178 "\\_SB.PCI0.PCI1.VGAC.NMAP",
179 /* Z96F */
180 "\\_SB.PCI0.VGA.GETD",
181 /* A2D */
182 "\\ACTD",
183 /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
184 "\\ADVG",
185 /* P30 */
186 "\\DNXT",
187 /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
188 "\\INFB",
189 /* A3F A6F A3N A3L M6N W3N W6A */
190 "\\SSTE");
Corentin Chary78127b42007-01-26 14:04:49 +0100191
Corentin Charybe966662009-08-29 10:28:29 +0200192ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */
193ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100194
Corentin Charye539c2f2007-05-06 14:47:06 +0200195/* GPS */
196/* R2H use different handle for GPS on/off */
Corentin Charyf3985322007-05-06 14:48:22 +0200197ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON"); /* R2H */
198ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */
Corentin Charye539c2f2007-05-06 14:47:06 +0200199ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST");
200
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000201/* Keyboard light */
202ASUS_HANDLE(kled_set, ASUS_HOTK_PREFIX "SLKB");
203ASUS_HANDLE(kled_get, ASUS_HOTK_PREFIX "GLKB");
204
Corentin Chary85091b72007-01-26 14:04:30 +0100205/*
206 * This is the main structure, we can use it to store anything interesting
207 * about the hotk device
208 */
209struct asus_hotk {
Corentin Charybe966662009-08-29 10:28:29 +0200210 char *name; /* laptop name */
211 struct acpi_device *device; /* the device we are in */
212 acpi_handle handle; /* the handle of the hotk device */
213 char status; /* status of the hotk, for LEDs, ... */
214 u32 ledd_status; /* status of the LED display */
215 u8 light_level; /* light sensor level */
216 u8 light_switch; /* light sensor switch value */
217 u16 event_count[128]; /* count for each event TODO make this better */
Corentin Chary034ce902009-01-20 16:17:43 +0100218 struct input_dev *inputdev;
219 u16 *keycode_map;
Corentin Chary85091b72007-01-26 14:04:30 +0100220};
221
222/*
223 * This header is made available to allow proper configuration given model,
224 * revision number , ... this info cannot go in struct asus_hotk because it is
225 * available before the hotk
226 */
227static struct acpi_table_header *asus_info;
228
229/* The actual device the driver binds to */
230static struct asus_hotk *hotk;
231
232/*
233 * The hotkey driver declaration
234 */
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200235static const struct acpi_device_id asus_device_ids[] = {
236 {"ATK0100", 0},
Ike Panhc14f8af32009-12-03 07:45:11 +0000237 {"ATK0101", 0},
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200238 {"", 0},
239};
240MODULE_DEVICE_TABLE(acpi, asus_device_ids);
241
Corentin Chary85091b72007-01-26 14:04:30 +0100242static int asus_hotk_add(struct acpi_device *device);
243static int asus_hotk_remove(struct acpi_device *device, int type);
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600244static void asus_hotk_notify(struct acpi_device *device, u32 event);
245
Corentin Chary85091b72007-01-26 14:04:30 +0100246static struct acpi_driver asus_hotk_driver = {
247 .name = ASUS_HOTK_NAME,
248 .class = ASUS_HOTK_CLASS,
Alan Jenkinsedf62452009-12-03 07:44:51 +0000249 .owner = THIS_MODULE,
Thomas Renninger1ba90e32007-07-23 14:44:41 +0200250 .ids = asus_device_ids,
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600251 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
Corentin Chary85091b72007-01-26 14:04:30 +0100252 .ops = {
253 .add = asus_hotk_add,
254 .remove = asus_hotk_remove,
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600255 .notify = asus_hotk_notify,
Corentin Chary85091b72007-01-26 14:04:30 +0100256 },
257};
258
Corentin Chary6b7091e2007-01-26 14:04:45 +0100259/* The backlight device /sys/class/backlight */
260static struct backlight_device *asus_backlight_device;
261
262/*
263 * The backlight class declaration
264 */
265static int read_brightness(struct backlight_device *bd);
266static int update_bl_status(struct backlight_device *bd);
Richard Purdie599a52d2007-02-10 23:07:48 +0000267static struct backlight_ops asusbl_ops = {
Len Brown8def05f2007-01-30 01:46:43 -0500268 .get_brightness = read_brightness,
269 .update_status = update_bl_status,
Corentin Chary6b7091e2007-01-26 14:04:45 +0100270};
271
Corentin Charybe966662009-08-29 10:28:29 +0200272/*
273 * These functions actually update the LED's, and are called from a
Corentin Charybe18cda2007-01-26 14:04:35 +0100274 * workqueue. By doing this as separate work rather than when the LED
275 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
Corentin Charybe966662009-08-29 10:28:29 +0200276 * potentially bad time, such as a timer interrupt.
277 */
Corentin Charybe18cda2007-01-26 14:04:35 +0100278static struct workqueue_struct *led_workqueue;
279
Corentin Chary977c3282009-08-28 12:56:49 +0000280#define ASUS_LED(object, ledname, max) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100281 static void object##_led_set(struct led_classdev *led_cdev, \
282 enum led_brightness value); \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000283 static enum led_brightness object##_led_get( \
284 struct led_classdev *led_cdev); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100285 static void object##_led_update(struct work_struct *ignored); \
286 static int object##_led_wk; \
Adrian Bunkf110ef52007-02-20 01:07:25 +0100287 static DECLARE_WORK(object##_led_work, object##_led_update); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100288 static struct led_classdev object##_led = { \
Richard Purdie6c152be2007-10-31 15:00:07 +0100289 .name = "asus::" ledname, \
Corentin Charybe18cda2007-01-26 14:04:35 +0100290 .brightness_set = object##_led_set, \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000291 .brightness_get = object##_led_get, \
Corentin Chary977c3282009-08-28 12:56:49 +0000292 .max_brightness = max \
Corentin Charybe18cda2007-01-26 14:04:35 +0100293 }
294
Corentin Chary977c3282009-08-28 12:56:49 +0000295ASUS_LED(mled, "mail", 1);
296ASUS_LED(tled, "touchpad", 1);
297ASUS_LED(rled, "record", 1);
298ASUS_LED(pled, "phone", 1);
299ASUS_LED(gled, "gaming", 1);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000300ASUS_LED(kled, "kbd_backlight", 3);
Corentin Charybe18cda2007-01-26 14:04:35 +0100301
Corentin Chary034ce902009-01-20 16:17:43 +0100302struct key_entry {
303 char type;
304 u8 code;
305 u16 keycode;
306};
307
308enum { KE_KEY, KE_END };
309
310static struct key_entry asus_keymap[] = {
Ike Panhc14f8af32009-12-03 07:45:11 +0000311 {KE_KEY, 0x02, KEY_SCREENLOCK},
312 {KE_KEY, 0x05, KEY_WLAN},
313 {KE_KEY, 0x08, KEY_F13},
314 {KE_KEY, 0x17, KEY_ZOOM},
315 {KE_KEY, 0x1f, KEY_BATTERY},
Corentin Chary034ce902009-01-20 16:17:43 +0100316 {KE_KEY, 0x30, KEY_VOLUMEUP},
317 {KE_KEY, 0x31, KEY_VOLUMEDOWN},
318 {KE_KEY, 0x32, KEY_MUTE},
319 {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE},
320 {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE},
321 {KE_KEY, 0x40, KEY_PREVIOUSSONG},
322 {KE_KEY, 0x41, KEY_NEXTSONG},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200323 {KE_KEY, 0x43, KEY_STOPCD},
Corentin Chary034ce902009-01-20 16:17:43 +0100324 {KE_KEY, 0x45, KEY_PLAYPAUSE},
Corentin Chary4644d0e2009-08-28 12:56:52 +0000325 {KE_KEY, 0x4c, KEY_MEDIA},
Corentin Chary034ce902009-01-20 16:17:43 +0100326 {KE_KEY, 0x50, KEY_EMAIL},
327 {KE_KEY, 0x51, KEY_WWW},
Corentin Chary0aa20f72009-08-28 12:56:53 +0000328 {KE_KEY, 0x55, KEY_CALC},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200329 {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */
Corentin Chary034ce902009-01-20 16:17:43 +0100330 {KE_KEY, 0x5D, KEY_WLAN},
Corentin Charyf6413752009-08-28 12:56:48 +0000331 {KE_KEY, 0x5E, KEY_WLAN},
332 {KE_KEY, 0x5F, KEY_WLAN},
333 {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE},
Corentin Chary034ce902009-01-20 16:17:43 +0100334 {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE},
Ike Panhc14f8af32009-12-03 07:45:11 +0000335 {KE_KEY, 0x62, KEY_SWITCHVIDEOMODE},
336 {KE_KEY, 0x63, KEY_SWITCHVIDEOMODE},
Corentin Chary16851f92009-12-03 07:45:10 +0000337 {KE_KEY, 0x6B, KEY_F13}, /* Lock Touchpad */
Corentin Chary034ce902009-01-20 16:17:43 +0100338 {KE_KEY, 0x82, KEY_CAMERA},
Corentin Chary1f0233e2009-12-03 07:45:12 +0000339 {KE_KEY, 0x88, KEY_WLAN },
Corentin Chary309f5fb2009-04-27 09:23:42 +0200340 {KE_KEY, 0x8A, KEY_PROG1},
Corentin Chary034ce902009-01-20 16:17:43 +0100341 {KE_KEY, 0x95, KEY_MEDIA},
342 {KE_KEY, 0x99, KEY_PHONE},
Corentin Charydc795262009-08-28 12:56:51 +0000343 {KE_KEY, 0xc4, KEY_KBDILLUMUP},
344 {KE_KEY, 0xc5, KEY_KBDILLUMDOWN},
Corentin Chary034ce902009-01-20 16:17:43 +0100345 {KE_END, 0},
346};
347
Corentin Chary85091b72007-01-26 14:04:30 +0100348/*
349 * This function evaluates an ACPI method, given an int as parameter, the
350 * method is searched within the scope of the handle, can be NULL. The output
351 * of the method is written is output, which can also be NULL
352 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100353 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100354 */
355static int write_acpi_int(acpi_handle handle, const char *method, int val,
356 struct acpi_buffer *output)
357{
Corentin Charybe966662009-08-29 10:28:29 +0200358 struct acpi_object_list params; /* list of input parameters (an int) */
359 union acpi_object in_obj; /* the only param we use */
Corentin Chary85091b72007-01-26 14:04:30 +0100360 acpi_status status;
361
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100362 if (!handle)
363 return 0;
364
Corentin Chary85091b72007-01-26 14:04:30 +0100365 params.count = 1;
366 params.pointer = &in_obj;
367 in_obj.type = ACPI_TYPE_INTEGER;
368 in_obj.integer.value = val;
369
370 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100371 if (status == AE_OK)
372 return 0;
373 else
374 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100375}
376
Len Brown8def05f2007-01-30 01:46:43 -0500377static int read_wireless_status(int mask)
378{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400379 unsigned long long status;
Corentin Chary9a816852007-03-11 10:25:38 +0100380 acpi_status rv = AE_OK;
Corentin Chary4564de12007-01-26 14:04:40 +0100381
382 if (!wireless_status_handle)
383 return (hotk->status & mask) ? 1 : 0;
384
Corentin Chary9a816852007-03-11 10:25:38 +0100385 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
386 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200387 pr_warning("Error reading Wireless status\n");
Corentin Chary9a816852007-03-11 10:25:38 +0100388 else
389 return (status & mask) ? 1 : 0;
Corentin Chary4564de12007-01-26 14:04:40 +0100390
391 return (hotk->status & mask) ? 1 : 0;
392}
393
Corentin Charyf3985322007-05-06 14:48:22 +0200394static int read_gps_status(void)
395{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400396 unsigned long long status;
Corentin Charye539c2f2007-05-06 14:47:06 +0200397 acpi_status rv = AE_OK;
398
399 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
400 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200401 pr_warning("Error reading GPS status\n");
Corentin Charye539c2f2007-05-06 14:47:06 +0200402 else
Corentin Charyf3985322007-05-06 14:48:22 +0200403 return status ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200404
Corentin Charyf3985322007-05-06 14:48:22 +0200405 return (hotk->status & GPS_ON) ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200406}
407
Corentin Charybe18cda2007-01-26 14:04:35 +0100408/* Generic LED functions */
409static int read_status(int mask)
410{
Corentin Chary4564de12007-01-26 14:04:40 +0100411 /* There is a special method for both wireless devices */
412 if (mask == BT_ON || mask == WL_ON)
413 return read_wireless_status(mask);
Corentin Charyf3985322007-05-06 14:48:22 +0200414 else if (mask == GPS_ON)
415 return read_gps_status();
Corentin Chary4564de12007-01-26 14:04:40 +0100416
Corentin Charybe18cda2007-01-26 14:04:35 +0100417 return (hotk->status & mask) ? 1 : 0;
418}
419
Corentin Chary935ffee2007-03-11 10:26:12 +0100420static void write_status(acpi_handle handle, int out, int mask)
Corentin Charybe18cda2007-01-26 14:04:35 +0100421{
422 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
423
Corentin Chary935ffee2007-03-11 10:26:12 +0100424 switch (mask) {
425 case MLED_ON:
Roel Kluine1af14e2008-02-02 21:07:38 +0100426 out = !(out & 0x1);
Corentin Chary935ffee2007-03-11 10:26:12 +0100427 break;
Corentin Charyfdd8d082007-03-11 10:26:48 +0100428 case GLED_ON:
429 out = (out & 0x1) + 1;
430 break;
Corentin Charye539c2f2007-05-06 14:47:06 +0200431 case GPS_ON:
432 handle = (out) ? gps_on_handle : gps_off_handle;
433 out = 0x02;
434 break;
Corentin Chary935ffee2007-03-11 10:26:12 +0100435 default:
436 out &= 0x1;
437 break;
438 }
Corentin Charybe18cda2007-01-26 14:04:35 +0100439
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100440 if (write_acpi_int(handle, NULL, out, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200441 pr_warning(" write failed %x\n", mask);
Corentin Charybe18cda2007-01-26 14:04:35 +0100442}
443
444/* /sys/class/led handlers */
Corentin Chary935ffee2007-03-11 10:26:12 +0100445#define ASUS_LED_HANDLER(object, mask) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100446 static void object##_led_set(struct led_classdev *led_cdev, \
447 enum led_brightness value) \
448 { \
Corentin Charye3deda92008-09-24 10:35:55 +0200449 object##_led_wk = (value > 0) ? 1 : 0; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100450 queue_work(led_workqueue, &object##_led_work); \
451 } \
452 static void object##_led_update(struct work_struct *ignored) \
453 { \
454 int value = object##_led_wk; \
Corentin Chary935ffee2007-03-11 10:26:12 +0100455 write_status(object##_set_handle, value, (mask)); \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000456 } \
457 static enum led_brightness object##_led_get( \
458 struct led_classdev *led_cdev) \
459 { \
460 return led_cdev->brightness; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100461 }
462
Corentin Chary935ffee2007-03-11 10:26:12 +0100463ASUS_LED_HANDLER(mled, MLED_ON);
464ASUS_LED_HANDLER(pled, PLED_ON);
465ASUS_LED_HANDLER(rled, RLED_ON);
466ASUS_LED_HANDLER(tled, TLED_ON);
Corentin Charyfdd8d082007-03-11 10:26:48 +0100467ASUS_LED_HANDLER(gled, GLED_ON);
Corentin Charybe18cda2007-01-26 14:04:35 +0100468
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000469/*
470 * Keyboard backlight
471 */
472static int get_kled_lvl(void)
473{
474 unsigned long long kblv;
475 struct acpi_object_list params;
476 union acpi_object in_obj;
477 acpi_status rv;
478
479 params.count = 1;
480 params.pointer = &in_obj;
481 in_obj.type = ACPI_TYPE_INTEGER;
482 in_obj.integer.value = 2;
483
484 rv = acpi_evaluate_integer(kled_get_handle, NULL, &params, &kblv);
485 if (ACPI_FAILURE(rv)) {
486 pr_warning("Error reading kled level\n");
487 return 0;
488 }
489 return kblv;
490}
491
492static int set_kled_lvl(int kblv)
493{
494 if (kblv > 0)
495 kblv = (1 << 7) | (kblv & 0x7F);
496 else
497 kblv = 0;
498
499 if (write_acpi_int(kled_set_handle, NULL, kblv, NULL)) {
500 pr_warning("Keyboard LED display write failed\n");
501 return -EINVAL;
502 }
503 return 0;
504}
505
506static void kled_led_set(struct led_classdev *led_cdev,
507 enum led_brightness value)
508{
509 kled_led_wk = value;
510 queue_work(led_workqueue, &kled_led_work);
511}
512
513static void kled_led_update(struct work_struct *ignored)
514{
515 set_kled_lvl(kled_led_wk);
516}
517
518static enum led_brightness kled_led_get(struct led_classdev *led_cdev)
519{
520 return get_kled_lvl();
521}
522
Corentin Chary6b7091e2007-01-26 14:04:45 +0100523static int get_lcd_state(void)
524{
525 return read_status(LCD_ON);
526}
527
528static int set_lcd_state(int value)
529{
530 int lcd = 0;
531 acpi_status status = 0;
532
533 lcd = value ? 1 : 0;
534
535 if (lcd == get_lcd_state())
536 return 0;
537
Len Brown8def05f2007-01-30 01:46:43 -0500538 if (lcd_switch_handle) {
Corentin Chary6b7091e2007-01-26 14:04:45 +0100539 status = acpi_evaluate_object(lcd_switch_handle,
540 NULL, NULL, NULL);
541
542 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200543 pr_warning("Error switching LCD\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100544 }
545
Corentin Chary935ffee2007-03-11 10:26:12 +0100546 write_status(NULL, lcd, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100547 return 0;
548}
549
550static void lcd_blank(int blank)
551{
552 struct backlight_device *bd = asus_backlight_device;
553
Len Brown8def05f2007-01-30 01:46:43 -0500554 if (bd) {
Richard Purdie599a52d2007-02-10 23:07:48 +0000555 bd->props.power = blank;
Richard Purdie28ee0862007-02-08 22:25:09 +0000556 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100557 }
558}
559
560static int read_brightness(struct backlight_device *bd)
561{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400562 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100563 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100564
Corentin Chary9a816852007-03-11 10:25:38 +0100565 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
566 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200567 pr_warning("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100568
569 return value;
570}
571
572static int set_brightness(struct backlight_device *bd, int value)
573{
574 int ret = 0;
575
576 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
577 /* 0 <= value <= 15 */
578
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100579 if (write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200580 pr_warning("Error changing brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100581 ret = -EIO;
582 }
583
584 return ret;
585}
586
587static int update_bl_status(struct backlight_device *bd)
588{
589 int rv;
Richard Purdie599a52d2007-02-10 23:07:48 +0000590 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100591
592 rv = set_brightness(bd, value);
Len Brown8def05f2007-01-30 01:46:43 -0500593 if (rv)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100594 return rv;
595
Richard Purdie599a52d2007-02-10 23:07:48 +0000596 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100597 return set_lcd_state(value);
598}
599
Corentin Chary85091b72007-01-26 14:04:30 +0100600/*
601 * Platform device handlers
602 */
603
604/*
605 * We write our info in page, we begin at offset off and cannot write more
606 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
607 * number of bytes written in page
608 */
609static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500610 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100611{
612 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400613 unsigned long long temp;
Corentin Charybe966662009-08-29 10:28:29 +0200614 char buf[16]; /* enough for all info */
Corentin Chary9a816852007-03-11 10:25:38 +0100615 acpi_status rv = AE_OK;
616
Corentin Chary85091b72007-01-26 14:04:30 +0100617 /*
618 * We use the easy way, we don't care of off and count, so we don't set eof
619 * to 1
620 */
621
622 len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
623 len += sprintf(page + len, "Model reference : %s\n", hotk->name);
624 /*
625 * The SFUN method probably allows the original driver to get the list
626 * of features supported by a given model. For now, 0x0100 or 0x0800
627 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
628 * The significance of others is yet to be found.
629 */
Corentin Chary9a816852007-03-11 10:25:38 +0100630 rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
631 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000632 len += sprintf(page + len, "SFUN value : %#x\n",
633 (uint) temp);
634 /*
635 * The HWRS method return informations about the hardware.
636 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
637 * The significance of others is yet to be found.
638 * If we don't find the method, we assume the device are present.
639 */
640 rv = acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &temp);
641 if (!ACPI_FAILURE(rv))
642 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100643 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100644 /*
645 * Another value for userspace: the ASYM method returns 0x02 for
646 * battery low and 0x04 for battery critical, its readings tend to be
647 * more accurate than those provided by _BST.
648 * Note: since not all the laptops provide this method, errors are
649 * silently ignored.
650 */
Corentin Chary9a816852007-03-11 10:25:38 +0100651 rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
652 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000653 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100654 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100655 if (asus_info) {
656 snprintf(buf, 16, "%d", asus_info->length);
657 len += sprintf(page + len, "DSDT length : %s\n", buf);
658 snprintf(buf, 16, "%d", asus_info->checksum);
659 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
660 snprintf(buf, 16, "%d", asus_info->revision);
661 len += sprintf(page + len, "DSDT revision : %s\n", buf);
662 snprintf(buf, 7, "%s", asus_info->oem_id);
663 len += sprintf(page + len, "OEM id : %s\n", buf);
664 snprintf(buf, 9, "%s", asus_info->oem_table_id);
665 len += sprintf(page + len, "OEM table id : %s\n", buf);
666 snprintf(buf, 16, "%x", asus_info->oem_revision);
667 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
668 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
669 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
670 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
671 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
672 }
673
674 return len;
675}
676
677static int parse_arg(const char *buf, unsigned long count, int *val)
678{
679 if (!count)
680 return 0;
681 if (count > 31)
682 return -EINVAL;
683 if (sscanf(buf, "%i", val) != 1)
684 return -EINVAL;
685 return count;
686}
687
Corentin Chary4564de12007-01-26 14:04:40 +0100688static ssize_t store_status(const char *buf, size_t count,
Corentin Chary935ffee2007-03-11 10:26:12 +0100689 acpi_handle handle, int mask)
Corentin Chary4564de12007-01-26 14:04:40 +0100690{
691 int rv, value;
692 int out = 0;
693
694 rv = parse_arg(buf, count, &value);
695 if (rv > 0)
696 out = value ? 1 : 0;
697
Corentin Chary935ffee2007-03-11 10:26:12 +0100698 write_status(handle, out, mask);
Corentin Chary4564de12007-01-26 14:04:40 +0100699
700 return rv;
701}
702
703/*
Corentin Chary722ad972007-01-26 14:04:55 +0100704 * LEDD display
705 */
706static ssize_t show_ledd(struct device *dev,
707 struct device_attribute *attr, char *buf)
708{
709 return sprintf(buf, "0x%08x\n", hotk->ledd_status);
710}
711
712static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
713 const char *buf, size_t count)
714{
715 int rv, value;
716
717 rv = parse_arg(buf, count, &value);
718 if (rv > 0) {
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100719 if (write_acpi_int(ledd_set_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200720 pr_warning("LED display write failed\n");
Corentin Chary722ad972007-01-26 14:04:55 +0100721 else
722 hotk->ledd_status = (u32) value;
723 }
724 return rv;
725}
726
727/*
Corentin Chary4564de12007-01-26 14:04:40 +0100728 * WLAN
729 */
730static ssize_t show_wlan(struct device *dev,
731 struct device_attribute *attr, char *buf)
732{
733 return sprintf(buf, "%d\n", read_status(WL_ON));
734}
735
736static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
737 const char *buf, size_t count)
738{
Corentin Chary935ffee2007-03-11 10:26:12 +0100739 return store_status(buf, count, wl_switch_handle, WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100740}
741
742/*
743 * Bluetooth
744 */
745static ssize_t show_bluetooth(struct device *dev,
746 struct device_attribute *attr, char *buf)
747{
748 return sprintf(buf, "%d\n", read_status(BT_ON));
749}
750
Len Brown8def05f2007-01-30 01:46:43 -0500751static ssize_t store_bluetooth(struct device *dev,
752 struct device_attribute *attr, const char *buf,
753 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100754{
Corentin Chary935ffee2007-03-11 10:26:12 +0100755 return store_status(buf, count, bt_switch_handle, BT_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100756}
757
Corentin Chary78127b42007-01-26 14:04:49 +0100758/*
759 * Display
760 */
761static void set_display(int value)
762{
763 /* no sanity check needed for now */
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100764 if (write_acpi_int(display_set_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200765 pr_warning("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100766 return;
767}
768
769static int read_display(void)
770{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400771 unsigned long long value = 0;
Corentin Chary9a816852007-03-11 10:25:38 +0100772 acpi_status rv = AE_OK;
Corentin Chary78127b42007-01-26 14:04:49 +0100773
Corentin Charybe966662009-08-29 10:28:29 +0200774 /*
775 * In most of the case, we know how to set the display, but sometime
776 * we can't read it
777 */
Len Brown8def05f2007-01-30 01:46:43 -0500778 if (display_get_handle) {
Corentin Chary9a816852007-03-11 10:25:38 +0100779 rv = acpi_evaluate_integer(display_get_handle, NULL,
780 NULL, &value);
781 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200782 pr_warning("Error reading display status\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100783 }
784
785 value &= 0x0F; /* needed for some models, shouldn't hurt others */
786
787 return value;
788}
Len Brown8def05f2007-01-30 01:46:43 -0500789
Corentin Chary78127b42007-01-26 14:04:49 +0100790/*
791 * Now, *this* one could be more user-friendly, but so far, no-one has
792 * complained. The significance of bits is the same as in store_disp()
793 */
794static ssize_t show_disp(struct device *dev,
795 struct device_attribute *attr, char *buf)
796{
797 return sprintf(buf, "%d\n", read_display());
798}
799
800/*
801 * Experimental support for display switching. As of now: 1 should activate
802 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
803 * Any combination (bitwise) of these will suffice. I never actually tested 4
804 * displays hooked up simultaneously, so be warned. See the acpi4asus README
805 * for more info.
806 */
807static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
808 const char *buf, size_t count)
809{
810 int rv, value;
811
812 rv = parse_arg(buf, count, &value);
813 if (rv > 0)
814 set_display(value);
815 return rv;
816}
817
Corentin Chary8b857352007-01-26 14:04:58 +0100818/*
819 * Light Sens
820 */
821static void set_light_sens_switch(int value)
822{
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100823 if (write_acpi_int(ls_switch_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200824 pr_warning("Error setting light sensor switch\n");
Corentin Chary8b857352007-01-26 14:04:58 +0100825 hotk->light_switch = value;
826}
827
828static ssize_t show_lssw(struct device *dev,
829 struct device_attribute *attr, char *buf)
830{
831 return sprintf(buf, "%d\n", hotk->light_switch);
832}
833
834static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
835 const char *buf, size_t count)
836{
837 int rv, value;
838
839 rv = parse_arg(buf, count, &value);
840 if (rv > 0)
841 set_light_sens_switch(value ? 1 : 0);
842
843 return rv;
844}
845
846static void set_light_sens_level(int value)
847{
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100848 if (write_acpi_int(ls_level_handle, NULL, value, NULL))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200849 pr_warning("Error setting light sensor level\n");
Corentin Chary8b857352007-01-26 14:04:58 +0100850 hotk->light_level = value;
851}
852
853static ssize_t show_lslvl(struct device *dev,
854 struct device_attribute *attr, char *buf)
855{
856 return sprintf(buf, "%d\n", hotk->light_level);
857}
858
859static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
860 const char *buf, size_t count)
861{
862 int rv, value;
863
864 rv = parse_arg(buf, count, &value);
865 if (rv > 0) {
866 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
867 /* 0 <= value <= 15 */
868 set_light_sens_level(value);
869 }
870
871 return rv;
872}
873
Corentin Charye539c2f2007-05-06 14:47:06 +0200874/*
875 * GPS
876 */
877static ssize_t show_gps(struct device *dev,
878 struct device_attribute *attr, char *buf)
879{
880 return sprintf(buf, "%d\n", read_status(GPS_ON));
881}
882
883static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
884 const char *buf, size_t count)
885{
Corentin Charyf3985322007-05-06 14:48:22 +0200886 return store_status(buf, count, NULL, GPS_ON);
Corentin Charye539c2f2007-05-06 14:47:06 +0200887}
888
Corentin Chary034ce902009-01-20 16:17:43 +0100889/*
890 * Hotkey functions
891 */
892static struct key_entry *asus_get_entry_by_scancode(int code)
893{
894 struct key_entry *key;
895
896 for (key = asus_keymap; key->type != KE_END; key++)
897 if (code == key->code)
898 return key;
899
900 return NULL;
901}
902
903static struct key_entry *asus_get_entry_by_keycode(int code)
904{
905 struct key_entry *key;
906
907 for (key = asus_keymap; key->type != KE_END; key++)
908 if (code == key->keycode && key->type == KE_KEY)
909 return key;
910
911 return NULL;
912}
913
914static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode)
915{
916 struct key_entry *key = asus_get_entry_by_scancode(scancode);
917
918 if (key && key->type == KE_KEY) {
919 *keycode = key->keycode;
920 return 0;
921 }
922
923 return -EINVAL;
924}
925
926static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode)
927{
928 struct key_entry *key;
929 int old_keycode;
930
931 if (keycode < 0 || keycode > KEY_MAX)
932 return -EINVAL;
933
934 key = asus_get_entry_by_scancode(scancode);
935 if (key && key->type == KE_KEY) {
936 old_keycode = key->keycode;
937 key->keycode = keycode;
938 set_bit(keycode, dev->keybit);
939 if (!asus_get_entry_by_keycode(old_keycode))
940 clear_bit(old_keycode, dev->keybit);
941 return 0;
942 }
943
944 return -EINVAL;
945}
946
Bjorn Helgaas586ed162009-04-30 09:35:53 -0600947static void asus_hotk_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +0100948{
Corentin Chary034ce902009-01-20 16:17:43 +0100949 static struct key_entry *key;
Corentin Chary6050c8d2009-02-15 19:30:19 +0100950 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +0100951
Corentin Chary85091b72007-01-26 14:04:30 +0100952 /* TODO Find a better way to handle events count. */
953 if (!hotk)
954 return;
955
Corentin Chary6b7091e2007-01-26 14:04:45 +0100956 /*
957 * We need to tell the backlight device when the backlight power is
958 * switched
959 */
960 if (event == ATKD_LCD_ON) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100961 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100962 lcd_blank(FB_BLANK_UNBLANK);
Len Brown8def05f2007-01-30 01:46:43 -0500963 } else if (event == ATKD_LCD_OFF) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100964 write_status(NULL, 0, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100965 lcd_blank(FB_BLANK_POWERDOWN);
966 }
967
Corentin Chary6050c8d2009-02-15 19:30:19 +0100968 count = hotk->event_count[event % 128]++;
969 acpi_bus_generate_proc_event(hotk->device, event, count);
Corentin Chary2a7dc0d2009-01-20 16:17:42 +0100970 acpi_bus_generate_netlink_event(hotk->device->pnp.device_class,
971 dev_name(&hotk->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +0100972 count);
Corentin Chary85091b72007-01-26 14:04:30 +0100973
Corentin Chary034ce902009-01-20 16:17:43 +0100974 if (hotk->inputdev) {
975 key = asus_get_entry_by_scancode(event);
976 if (!key)
977 return ;
978
979 switch (key->type) {
980 case KE_KEY:
981 input_report_key(hotk->inputdev, key->keycode, 1);
982 input_sync(hotk->inputdev);
983 input_report_key(hotk->inputdev, key->keycode, 0);
984 input_sync(hotk->inputdev);
985 break;
986 }
987 }
Corentin Chary85091b72007-01-26 14:04:30 +0100988}
989
990#define ASUS_CREATE_DEVICE_ATTR(_name) \
991 struct device_attribute dev_attr_##_name = { \
992 .attr = { \
993 .name = __stringify(_name), \
Tejun Heo7b595752007-06-14 03:45:17 +0900994 .mode = 0 }, \
Corentin Chary85091b72007-01-26 14:04:30 +0100995 .show = NULL, \
996 .store = NULL, \
997 }
998
999#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
1000 do { \
1001 dev_attr_##_name.attr.mode = _mode; \
1002 dev_attr_##_name.show = _show; \
1003 dev_attr_##_name.store = _store; \
1004 } while(0)
1005
1006static ASUS_CREATE_DEVICE_ATTR(infos);
Corentin Chary4564de12007-01-26 14:04:40 +01001007static ASUS_CREATE_DEVICE_ATTR(wlan);
1008static ASUS_CREATE_DEVICE_ATTR(bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +01001009static ASUS_CREATE_DEVICE_ATTR(display);
Corentin Chary722ad972007-01-26 14:04:55 +01001010static ASUS_CREATE_DEVICE_ATTR(ledd);
Corentin Chary8b857352007-01-26 14:04:58 +01001011static ASUS_CREATE_DEVICE_ATTR(ls_switch);
1012static ASUS_CREATE_DEVICE_ATTR(ls_level);
Corentin Charye539c2f2007-05-06 14:47:06 +02001013static ASUS_CREATE_DEVICE_ATTR(gps);
Corentin Chary85091b72007-01-26 14:04:30 +01001014
1015static struct attribute *asuspf_attributes[] = {
Len Brown8def05f2007-01-30 01:46:43 -05001016 &dev_attr_infos.attr,
1017 &dev_attr_wlan.attr,
1018 &dev_attr_bluetooth.attr,
1019 &dev_attr_display.attr,
1020 &dev_attr_ledd.attr,
1021 &dev_attr_ls_switch.attr,
1022 &dev_attr_ls_level.attr,
Corentin Charye539c2f2007-05-06 14:47:06 +02001023 &dev_attr_gps.attr,
Len Brown8def05f2007-01-30 01:46:43 -05001024 NULL
Corentin Chary85091b72007-01-26 14:04:30 +01001025};
1026
1027static struct attribute_group asuspf_attribute_group = {
Len Brown8def05f2007-01-30 01:46:43 -05001028 .attrs = asuspf_attributes
Corentin Chary85091b72007-01-26 14:04:30 +01001029};
1030
1031static struct platform_driver asuspf_driver = {
Len Brown8def05f2007-01-30 01:46:43 -05001032 .driver = {
1033 .name = ASUS_HOTK_FILE,
1034 .owner = THIS_MODULE,
1035 }
Corentin Chary85091b72007-01-26 14:04:30 +01001036};
1037
1038static struct platform_device *asuspf_device;
1039
Corentin Chary85091b72007-01-26 14:04:30 +01001040static void asus_hotk_add_fs(void)
1041{
1042 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
Corentin Chary4564de12007-01-26 14:04:40 +01001043
1044 if (wl_switch_handle)
1045 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
1046
1047 if (bt_switch_handle)
1048 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
1049 show_bluetooth, store_bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +01001050
1051 if (display_set_handle && display_get_handle)
1052 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
Len Brown8def05f2007-01-30 01:46:43 -05001053 else if (display_set_handle)
Corentin Chary78127b42007-01-26 14:04:49 +01001054 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
1055
Corentin Chary722ad972007-01-26 14:04:55 +01001056 if (ledd_set_handle)
1057 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
1058
Corentin Chary8b857352007-01-26 14:04:58 +01001059 if (ls_switch_handle && ls_level_handle) {
1060 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
1061 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
1062 }
Corentin Charye539c2f2007-05-06 14:47:06 +02001063
Corentin Charyf3985322007-05-06 14:48:22 +02001064 if (gps_status_handle && gps_on_handle && gps_off_handle)
Corentin Charye539c2f2007-05-06 14:47:06 +02001065 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
Corentin Chary85091b72007-01-26 14:04:30 +01001066}
1067
Len Brown8def05f2007-01-30 01:46:43 -05001068static int asus_handle_init(char *name, acpi_handle * handle,
Corentin Chary85091b72007-01-26 14:04:30 +01001069 char **paths, int num_paths)
1070{
1071 int i;
1072 acpi_status status;
1073
1074 for (i = 0; i < num_paths; i++) {
1075 status = acpi_get_handle(NULL, paths[i], handle);
1076 if (ACPI_SUCCESS(status))
1077 return 0;
1078 }
1079
1080 *handle = NULL;
1081 return -ENODEV;
1082}
1083
1084#define ASUS_HANDLE_INIT(object) \
1085 asus_handle_init(#object, &object##_handle, object##_paths, \
1086 ARRAY_SIZE(object##_paths))
1087
Corentin Chary85091b72007-01-26 14:04:30 +01001088/*
1089 * This function is used to initialize the hotk with right values. In this
1090 * method, we can make all the detection we want, and modify the hotk struct
1091 */
1092static int asus_hotk_get_info(void)
1093{
1094 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001095 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001096 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001097 char *string = NULL;
1098 acpi_status status;
1099
1100 /*
1101 * Get DSDT headers early enough to allow for differentiating between
1102 * models, but late enough to allow acpi_bus_register_driver() to fail
1103 * before doing anything ACPI-specific. Should we encounter a machine,
1104 * which needs special handling (i.e. its hotkey device has a different
1105 * HID), this bit will be moved. A global variable asus_info contains
1106 * the DSDT header.
1107 */
Len Brown894d79b2007-02-03 02:13:53 -05001108 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001109 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001110 pr_warning("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001111
1112 /* We have to write 0 on init this far for all ASUS models */
Corentin CHARYf8d1c942008-01-16 16:56:42 +01001113 if (write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001114 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001115 return -ENODEV;
1116 }
1117
1118 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001119 status =
1120 acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
1121 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001122 pr_warning("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001123 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001124 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001125 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001126
Corentin Chary185e5af2007-03-11 10:27:33 +01001127 /* This too ... */
1128 write_acpi_int(hotk->handle, "CWAP", wapf, NULL);
1129
Corentin Chary85091b72007-01-26 14:04:30 +01001130 /*
1131 * Try to match the object returned by INIT to the specific model.
1132 * Handle every possible object (or the lack of thereof) the DSDT
1133 * writers might throw at us. When in trouble, we pass NULL to
1134 * asus_model_match() and try something completely different.
1135 */
1136 if (buffer.pointer) {
1137 model = buffer.pointer;
1138 switch (model->type) {
1139 case ACPI_TYPE_STRING:
1140 string = model->string.pointer;
1141 break;
1142 case ACPI_TYPE_BUFFER:
1143 string = model->buffer.pointer;
1144 break;
1145 default:
1146 string = "";
1147 break;
1148 }
1149 }
1150 hotk->name = kstrdup(string, GFP_KERNEL);
1151 if (!hotk->name)
1152 return -ENOMEM;
1153
Len Brown8def05f2007-01-30 01:46:43 -05001154 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001155 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001156
Corentin Charybe18cda2007-01-26 14:04:35 +01001157 ASUS_HANDLE_INIT(mled_set);
1158 ASUS_HANDLE_INIT(tled_set);
1159 ASUS_HANDLE_INIT(rled_set);
1160 ASUS_HANDLE_INIT(pled_set);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001161 ASUS_HANDLE_INIT(gled_set);
Corentin Charybe18cda2007-01-26 14:04:35 +01001162
Corentin Chary722ad972007-01-26 14:04:55 +01001163 ASUS_HANDLE_INIT(ledd_set);
1164
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001165 ASUS_HANDLE_INIT(kled_set);
1166 ASUS_HANDLE_INIT(kled_get);
1167
Corentin Chary4564de12007-01-26 14:04:40 +01001168 /*
1169 * The HWRS method return informations about the hardware.
1170 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
1171 * The significance of others is yet to be found.
1172 * If we don't find the method, we assume the device are present.
1173 */
Corentin Chary9a816852007-03-11 10:25:38 +01001174 status =
1175 acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result);
1176 if (ACPI_FAILURE(status))
Corentin Chary4564de12007-01-26 14:04:40 +01001177 hwrs_result = WL_HWRS | BT_HWRS;
1178
Len Brown8def05f2007-01-30 01:46:43 -05001179 if (hwrs_result & WL_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001180 ASUS_HANDLE_INIT(wl_switch);
Len Brown8def05f2007-01-30 01:46:43 -05001181 if (hwrs_result & BT_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001182 ASUS_HANDLE_INIT(bt_switch);
1183
1184 ASUS_HANDLE_INIT(wireless_status);
1185
Corentin Chary6b7091e2007-01-26 14:04:45 +01001186 ASUS_HANDLE_INIT(brightness_set);
1187 ASUS_HANDLE_INIT(brightness_get);
1188
1189 ASUS_HANDLE_INIT(lcd_switch);
1190
Corentin Chary78127b42007-01-26 14:04:49 +01001191 ASUS_HANDLE_INIT(display_set);
1192 ASUS_HANDLE_INIT(display_get);
1193
Corentin Charybe966662009-08-29 10:28:29 +02001194 /*
1195 * There is a lot of models with "ALSL", but a few get
1196 * a real light sens, so we need to check it.
1197 */
Corentin Chary832d9952007-05-06 14:47:29 +02001198 if (!ASUS_HANDLE_INIT(ls_switch))
Corentin Chary8b857352007-01-26 14:04:58 +01001199 ASUS_HANDLE_INIT(ls_level);
1200
Corentin Charye539c2f2007-05-06 14:47:06 +02001201 ASUS_HANDLE_INIT(gps_on);
1202 ASUS_HANDLE_INIT(gps_off);
1203 ASUS_HANDLE_INIT(gps_status);
1204
Corentin Chary85091b72007-01-26 14:04:30 +01001205 kfree(model);
1206
1207 return AE_OK;
1208}
1209
Corentin Chary034ce902009-01-20 16:17:43 +01001210static int asus_input_init(void)
1211{
1212 const struct key_entry *key;
1213 int result;
1214
1215 hotk->inputdev = input_allocate_device();
1216 if (!hotk->inputdev) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001217 pr_info("Unable to allocate input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001218 return 0;
1219 }
1220 hotk->inputdev->name = "Asus Laptop extra buttons";
1221 hotk->inputdev->phys = ASUS_HOTK_FILE "/input0";
1222 hotk->inputdev->id.bustype = BUS_HOST;
1223 hotk->inputdev->getkeycode = asus_getkeycode;
1224 hotk->inputdev->setkeycode = asus_setkeycode;
1225
1226 for (key = asus_keymap; key->type != KE_END; key++) {
1227 switch (key->type) {
1228 case KE_KEY:
1229 set_bit(EV_KEY, hotk->inputdev->evbit);
1230 set_bit(key->keycode, hotk->inputdev->keybit);
1231 break;
1232 }
1233 }
1234 result = input_register_device(hotk->inputdev);
1235 if (result) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001236 pr_info("Unable to register input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001237 input_free_device(hotk->inputdev);
1238 }
1239 return result;
1240}
1241
Corentin Chary85091b72007-01-26 14:04:30 +01001242static int asus_hotk_check(void)
1243{
1244 int result = 0;
1245
1246 result = acpi_bus_get_status(hotk->device);
1247 if (result)
1248 return result;
1249
1250 if (hotk->device->status.present) {
1251 result = asus_hotk_get_info();
1252 } else {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001253 pr_err("Hotkey device not present, aborting\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001254 return -EINVAL;
1255 }
1256
1257 return result;
1258}
1259
1260static int asus_hotk_found;
1261
1262static int asus_hotk_add(struct acpi_device *device)
1263{
Corentin Chary85091b72007-01-26 14:04:30 +01001264 int result;
1265
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001266 pr_notice("Asus Laptop Support version %s\n",
Corentin Chary85091b72007-01-26 14:04:30 +01001267 ASUS_LAPTOP_VERSION);
1268
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07001269 hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL);
Corentin Chary85091b72007-01-26 14:04:30 +01001270 if (!hotk)
1271 return -ENOMEM;
Corentin Chary85091b72007-01-26 14:04:30 +01001272
1273 hotk->handle = device->handle;
1274 strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
1275 strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
Pavel Machekdb89b4f2008-09-22 14:37:34 -07001276 device->driver_data = hotk;
Corentin Chary85091b72007-01-26 14:04:30 +01001277 hotk->device = device;
1278
1279 result = asus_hotk_check();
1280 if (result)
1281 goto end;
1282
1283 asus_hotk_add_fs();
1284
Corentin Chary85091b72007-01-26 14:04:30 +01001285 asus_hotk_found = 1;
1286
Corentin Chary6b7091e2007-01-26 14:04:45 +01001287 /* WLED and BLED are on by default */
Corentin Chary0e875f42010-01-10 20:49:26 +01001288 if (bluetooth_status != -1)
1289 write_status(bt_switch_handle, !!bluetooth_status, BT_ON);
1290 if (wireless_status != -1)
1291 write_status(wl_switch_handle, !!wireless_status, WL_ON);
Corentin Chary935ffee2007-03-11 10:26:12 +01001292
1293 /* If the h/w switch is off, we need to check the real status */
1294 write_status(NULL, read_status(BT_ON), BT_ON);
1295 write_status(NULL, read_status(WL_ON), WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +01001296
Corentin Chary6b7091e2007-01-26 14:04:45 +01001297 /* LCD Backlight is on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001298 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001299
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001300 /* Keyboard Backlight is on by default */
1301 if (kled_set_handle)
1302 set_kled_lvl(1);
1303
Corentin Chary722ad972007-01-26 14:04:55 +01001304 /* LED display is off by default */
1305 hotk->ledd_status = 0xFFF;
1306
Len Brown8def05f2007-01-30 01:46:43 -05001307 /* Set initial values of light sensor and level */
Corentin Charyd951d4c2009-12-07 22:05:50 +01001308 hotk->light_switch = 0; /* Default to light sensor disabled */
1309 hotk->light_level = 5; /* level 5 for sensor sensitivity */
Corentin Chary8b857352007-01-26 14:04:58 +01001310
Len Brown8def05f2007-01-30 01:46:43 -05001311 if (ls_switch_handle)
1312 set_light_sens_switch(hotk->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001313
Len Brown8def05f2007-01-30 01:46:43 -05001314 if (ls_level_handle)
1315 set_light_sens_level(hotk->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001316
Corentin Charye539c2f2007-05-06 14:47:06 +02001317 /* GPS is on by default */
1318 write_status(NULL, 1, GPS_ON);
1319
Corentin Charyed6f4422009-01-20 16:17:45 +01001320end:
Corentin Chary85091b72007-01-26 14:04:30 +01001321 if (result) {
1322 kfree(hotk->name);
1323 kfree(hotk);
1324 }
1325
1326 return result;
1327}
1328
1329static int asus_hotk_remove(struct acpi_device *device, int type)
1330{
Corentin Chary85091b72007-01-26 14:04:30 +01001331 kfree(hotk->name);
1332 kfree(hotk);
1333
1334 return 0;
1335}
1336
Corentin Chary6b7091e2007-01-26 14:04:45 +01001337static void asus_backlight_exit(void)
1338{
Len Brown8def05f2007-01-30 01:46:43 -05001339 if (asus_backlight_device)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001340 backlight_device_unregister(asus_backlight_device);
1341}
1342
Corentin Charybe18cda2007-01-26 14:04:35 +01001343#define ASUS_LED_UNREGISTER(object) \
Guillaume Chazaraine1996a62007-08-16 18:18:53 +02001344 if (object##_led.dev) \
1345 led_classdev_unregister(&object##_led)
Corentin Charybe18cda2007-01-26 14:04:35 +01001346
1347static void asus_led_exit(void)
1348{
Al Viro3b0d7112007-07-23 11:21:34 +01001349 destroy_workqueue(led_workqueue);
Corentin Charybe18cda2007-01-26 14:04:35 +01001350 ASUS_LED_UNREGISTER(mled);
1351 ASUS_LED_UNREGISTER(tled);
1352 ASUS_LED_UNREGISTER(pled);
1353 ASUS_LED_UNREGISTER(rled);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001354 ASUS_LED_UNREGISTER(gled);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001355 ASUS_LED_UNREGISTER(kled);
Corentin Charybe18cda2007-01-26 14:04:35 +01001356}
1357
Corentin Chary034ce902009-01-20 16:17:43 +01001358static void asus_input_exit(void)
1359{
1360 if (hotk->inputdev)
1361 input_unregister_device(hotk->inputdev);
1362}
1363
Corentin Chary85091b72007-01-26 14:04:30 +01001364static void __exit asus_laptop_exit(void)
1365{
Corentin Chary6b7091e2007-01-26 14:04:45 +01001366 asus_backlight_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001367 asus_led_exit();
Corentin Chary034ce902009-01-20 16:17:43 +01001368 asus_input_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001369
Corentin Chary85091b72007-01-26 14:04:30 +01001370 acpi_bus_unregister_driver(&asus_hotk_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001371 sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
1372 platform_device_unregister(asuspf_device);
1373 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001374}
1375
Len Brown8def05f2007-01-30 01:46:43 -05001376static int asus_backlight_init(struct device *dev)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001377{
1378 struct backlight_device *bd;
1379
Len Brown8def05f2007-01-30 01:46:43 -05001380 if (brightness_set_handle && lcd_switch_handle) {
1381 bd = backlight_device_register(ASUS_HOTK_FILE, dev,
Richard Purdie599a52d2007-02-10 23:07:48 +00001382 NULL, &asusbl_ops);
Len Brown8def05f2007-01-30 01:46:43 -05001383 if (IS_ERR(bd)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001384 pr_err("Could not register asus backlight device\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +01001385 asus_backlight_device = NULL;
1386 return PTR_ERR(bd);
1387 }
1388
1389 asus_backlight_device = bd;
1390
Richard Purdie599a52d2007-02-10 23:07:48 +00001391 bd->props.max_brightness = 15;
1392 bd->props.brightness = read_brightness(NULL);
1393 bd->props.power = FB_BLANK_UNBLANK;
Richard Purdie28ee0862007-02-08 22:25:09 +00001394 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001395 }
1396 return 0;
1397}
1398
Corentin Charybe18cda2007-01-26 14:04:35 +01001399static int asus_led_register(acpi_handle handle,
Len Brown8def05f2007-01-30 01:46:43 -05001400 struct led_classdev *ldev, struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001401{
Len Brown8def05f2007-01-30 01:46:43 -05001402 if (!handle)
Corentin Charybe18cda2007-01-26 14:04:35 +01001403 return 0;
1404
1405 return led_classdev_register(dev, ldev);
1406}
Len Brown8def05f2007-01-30 01:46:43 -05001407
Corentin Charybe18cda2007-01-26 14:04:35 +01001408#define ASUS_LED_REGISTER(object, device) \
1409 asus_led_register(object##_set_handle, &object##_led, device)
1410
Len Brown8def05f2007-01-30 01:46:43 -05001411static int asus_led_init(struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001412{
1413 int rv;
1414
1415 rv = ASUS_LED_REGISTER(mled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001416 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001417 goto out;
Corentin Charybe18cda2007-01-26 14:04:35 +01001418
1419 rv = ASUS_LED_REGISTER(tled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001420 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001421 goto out1;
Corentin Charybe18cda2007-01-26 14:04:35 +01001422
1423 rv = ASUS_LED_REGISTER(rled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001424 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001425 goto out2;
Corentin Charybe18cda2007-01-26 14:04:35 +01001426
1427 rv = ASUS_LED_REGISTER(pled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001428 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001429 goto out3;
Corentin Charybe18cda2007-01-26 14:04:35 +01001430
Corentin Charyfdd8d082007-03-11 10:26:48 +01001431 rv = ASUS_LED_REGISTER(gled, dev);
1432 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001433 goto out4;
Corentin Charyfdd8d082007-03-11 10:26:48 +01001434
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001435 if (kled_set_handle && kled_get_handle)
1436 rv = ASUS_LED_REGISTER(kled, dev);
1437 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001438 goto out5;
Corentin Charybe18cda2007-01-26 14:04:35 +01001439
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001440 led_workqueue = create_singlethread_workqueue("led_workqueue");
1441 if (!led_workqueue)
1442 goto out6;
1443
Corentin Charybe18cda2007-01-26 14:04:35 +01001444 return 0;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001445out6:
Al Viro3b0d7112007-07-23 11:21:34 +01001446 rv = -ENOMEM;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001447 ASUS_LED_UNREGISTER(kled);
1448out5:
Al Viro3b0d7112007-07-23 11:21:34 +01001449 ASUS_LED_UNREGISTER(gled);
1450out4:
1451 ASUS_LED_UNREGISTER(pled);
1452out3:
1453 ASUS_LED_UNREGISTER(rled);
1454out2:
1455 ASUS_LED_UNREGISTER(tled);
1456out1:
1457 ASUS_LED_UNREGISTER(mled);
1458out:
1459 return rv;
Corentin Charybe18cda2007-01-26 14:04:35 +01001460}
1461
Corentin Chary85091b72007-01-26 14:04:30 +01001462static int __init asus_laptop_init(void)
1463{
1464 int result;
1465
Corentin Chary85091b72007-01-26 14:04:30 +01001466 result = acpi_bus_register_driver(&asus_hotk_driver);
1467 if (result < 0)
1468 return result;
1469
1470 /*
1471 * This is a bit of a kludge. We only want this module loaded
1472 * for ASUS systems, but there's currently no way to probe the
1473 * ACPI namespace for ASUS HIDs. So we just return failure if
1474 * we didn't find one, which will cause the module to be
1475 * unloaded.
1476 */
1477 if (!asus_hotk_found) {
1478 acpi_bus_unregister_driver(&asus_hotk_driver);
1479 return -ENODEV;
1480 }
1481
Corentin Chary034ce902009-01-20 16:17:43 +01001482 result = asus_input_init();
1483 if (result)
1484 goto fail_input;
1485
Len Brown8def05f2007-01-30 01:46:43 -05001486 /* Register platform stuff */
Corentin Chary85091b72007-01-26 14:04:30 +01001487 result = platform_driver_register(&asuspf_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001488 if (result)
1489 goto fail_platform_driver;
Corentin Chary85091b72007-01-26 14:04:30 +01001490
Len Brown8def05f2007-01-30 01:46:43 -05001491 asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
1492 if (!asuspf_device) {
1493 result = -ENOMEM;
1494 goto fail_platform_device1;
1495 }
Corentin Chary85091b72007-01-26 14:04:30 +01001496
Len Brown8def05f2007-01-30 01:46:43 -05001497 result = platform_device_add(asuspf_device);
1498 if (result)
1499 goto fail_platform_device2;
Corentin Chary85091b72007-01-26 14:04:30 +01001500
Len Brown8def05f2007-01-30 01:46:43 -05001501 result = sysfs_create_group(&asuspf_device->dev.kobj,
Corentin Chary85091b72007-01-26 14:04:30 +01001502 &asuspf_attribute_group);
Len Brown8def05f2007-01-30 01:46:43 -05001503 if (result)
1504 goto fail_sysfs;
Corentin Chary85091b72007-01-26 14:04:30 +01001505
Corentin Chary116bf2e2009-06-16 19:28:46 +00001506 result = asus_led_init(&asuspf_device->dev);
1507 if (result)
1508 goto fail_led;
1509
1510 if (!acpi_video_backlight_support()) {
1511 result = asus_backlight_init(&asuspf_device->dev);
1512 if (result)
1513 goto fail_backlight;
1514 } else
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001515 pr_info("Brightness ignored, must be controlled by "
Corentin Chary116bf2e2009-06-16 19:28:46 +00001516 "ACPI video driver\n");
1517
Len Brown8def05f2007-01-30 01:46:43 -05001518 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001519
Corentin Chary116bf2e2009-06-16 19:28:46 +00001520fail_backlight:
1521 asus_led_exit();
1522
1523fail_led:
1524 sysfs_remove_group(&asuspf_device->dev.kobj,
1525 &asuspf_attribute_group);
1526
Corentin Charyed6f4422009-01-20 16:17:45 +01001527fail_sysfs:
Len Brown8def05f2007-01-30 01:46:43 -05001528 platform_device_del(asuspf_device);
Corentin Chary85091b72007-01-26 14:04:30 +01001529
Corentin Charyed6f4422009-01-20 16:17:45 +01001530fail_platform_device2:
Corentin Chary85091b72007-01-26 14:04:30 +01001531 platform_device_put(asuspf_device);
1532
Corentin Charyed6f4422009-01-20 16:17:45 +01001533fail_platform_device1:
Len Brown8def05f2007-01-30 01:46:43 -05001534 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001535
Corentin Charyed6f4422009-01-20 16:17:45 +01001536fail_platform_driver:
Corentin Chary034ce902009-01-20 16:17:43 +01001537 asus_input_exit();
1538
Corentin Charyed6f4422009-01-20 16:17:45 +01001539fail_input:
Corentin Chary85091b72007-01-26 14:04:30 +01001540
1541 return result;
1542}
1543
1544module_init(asus_laptop_init);
1545module_exit(asus_laptop_exit);