blob: 4ff30ca4df124cb405d6aceecaf059743bab2a92 [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 Chary91687cc2009-11-28 10:32:34 +010053#define ASUS_LAPTOP_VERSION "0.42"
Corentin Chary85091b72007-01-26 14:04:30 +010054
Corentin Chary50a90c42009-11-30 21:55:12 +010055#define ASUS_LAPTOP_NAME "Asus Laptop Support"
56#define ASUS_LAPTOP_CLASS "hotkey"
57#define ASUS_LAPTOP_DEVICE_NAME "Hotkey"
58#define ASUS_LAPTOP_FILE KBUILD_MODNAME
59#define ASUS_LAPTOP_PREFIX "\\_SB.ATKD."
Corentin Chary85091b72007-01-26 14:04:30 +010060
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 */
Corentin Chary91687cc2009-11-28 10:32:34 +010065#define ATKD_BR_UP 0x10
66#define ATKD_BR_DOWN 0x20
67#define ATKD_LCD_ON 0x33
68#define ATKD_LCD_OFF 0x34
Corentin Chary6b7091e2007-01-26 14:04:45 +010069
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 Chary91687cc2009-11-28 10:32:34 +010073#define WL_HWRS 0x80
74#define BT_HWRS 0x100
Corentin Chary4564de12007-01-26 14:04:40 +010075
76/*
77 * Flags for hotk status
78 * WL_ON and BT_ON are also used for wireless_status()
79 */
Corentin Chary91687cc2009-11-28 10:32:34 +010080#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 Chary85091b72007-01-26 14:04:30 +010090
91MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
Corentin Chary50a90c42009-11-30 21:55:12 +010092MODULE_DESCRIPTION(ASUS_LAPTOP_NAME);
Corentin Chary85091b72007-01-26 14:04:30 +010093MODULE_LICENSE("GPL");
94
Corentin Charybe966662009-08-29 10:28:29 +020095/*
96 * WAPF defines the behavior of the Fn+Fx wlan key
Corentin Chary185e5af2007-03-11 10:27:33 +010097 * The significance of values is yet to be found, but
98 * most of the time:
99 * 0x0 will do nothing
100 * 0x1 will allow to control the device with Fn+Fx key.
101 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
102 * 0x5 like 0x1 or 0x4
103 * So, if something doesn't work as you want, just try other values =)
104 */
105static uint wapf = 1;
106module_param(wapf, uint, 0644);
107MODULE_PARM_DESC(wapf, "WAPF value");
108
Corentin Chary0e875f42010-01-10 20:49:26 +0100109static uint wireless_status = 1;
110static uint bluetooth_status = 1;
111
112module_param(wireless_status, uint, 0644);
113MODULE_PARM_DESC(wireless_status, "Set the wireless status on boot "
114 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
115 "default is 1");
116
117module_param(bluetooth_status, uint, 0644);
118MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
119 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
120 "default is 1");
121
Corentin Chary85091b72007-01-26 14:04:30 +0100122#define ASUS_HANDLE(object, paths...) \
123 static acpi_handle object##_handle = NULL; \
124 static char *object##_paths[] = { paths }
125
Corentin Charybe18cda2007-01-26 14:04:35 +0100126/* LED */
Corentin Chary50a90c42009-11-30 21:55:12 +0100127ASUS_HANDLE(mled_set, ASUS_LAPTOP_PREFIX "MLED");
128ASUS_HANDLE(tled_set, ASUS_LAPTOP_PREFIX "TLED");
129ASUS_HANDLE(rled_set, ASUS_LAPTOP_PREFIX "RLED"); /* W1JC */
130ASUS_HANDLE(pled_set, ASUS_LAPTOP_PREFIX "PLED"); /* A7J */
131ASUS_HANDLE(gled_set, ASUS_LAPTOP_PREFIX "GLED"); /* G1, G2 (probably) */
Corentin Charybe18cda2007-01-26 14:04:35 +0100132
Corentin Chary722ad972007-01-26 14:04:55 +0100133/* LEDD */
Corentin Chary50a90c42009-11-30 21:55:12 +0100134ASUS_HANDLE(ledd_set, ASUS_LAPTOP_PREFIX "SLCM");
Corentin Chary722ad972007-01-26 14:04:55 +0100135
Corentin Charybe966662009-08-29 10:28:29 +0200136/*
137 * Bluetooth and WLAN
Corentin Chary4564de12007-01-26 14:04:40 +0100138 * WLED and BLED are not handled like other XLED, because in some dsdt
139 * they also control the WLAN/Bluetooth device.
140 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100141ASUS_HANDLE(wl_switch, ASUS_LAPTOP_PREFIX "WLED");
142ASUS_HANDLE(bt_switch, ASUS_LAPTOP_PREFIX "BLED");
143ASUS_HANDLE(wireless_status, ASUS_LAPTOP_PREFIX "RSTS"); /* All new models */
Corentin Chary4564de12007-01-26 14:04:40 +0100144
Corentin Chary6b7091e2007-01-26 14:04:45 +0100145/* Brightness */
Corentin Chary50a90c42009-11-30 21:55:12 +0100146ASUS_HANDLE(brightness_set, ASUS_LAPTOP_PREFIX "SPLV");
147ASUS_HANDLE(brightness_get, ASUS_LAPTOP_PREFIX "GPLV");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100148
149/* Backlight */
Len Brown8def05f2007-01-30 01:46:43 -0500150ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
151 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
152 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
153 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
154 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
Torsten Krah4d0b856e2008-10-17 09:47:57 +0200155 "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */
Len Brown8def05f2007-01-30 01:46:43 -0500156 "\\_SB.PCI0.PX40.Q10", /* S1x */
157 "\\Q10"); /* A2x, L2D, L3D, M2E */
Corentin Chary6b7091e2007-01-26 14:04:45 +0100158
Corentin Chary78127b42007-01-26 14:04:49 +0100159/* Display */
Corentin Chary50a90c42009-11-30 21:55:12 +0100160ASUS_HANDLE(display_set, ASUS_LAPTOP_PREFIX "SDSP");
Corentin Charybe966662009-08-29 10:28:29 +0200161ASUS_HANDLE(display_get,
162 /* A6B, A6K A6R A7D F3JM L4R M6R A3G M6A M6V VX-1 V6J V6V W3Z */
163 "\\_SB.PCI0.P0P1.VGA.GETD",
164 /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V S5A M5A z33A W1Jc W2V G1 */
165 "\\_SB.PCI0.P0P2.VGA.GETD",
166 /* A6V A6Q */
167 "\\_SB.PCI0.P0P3.VGA.GETD",
168 /* A6T, A6M */
169 "\\_SB.PCI0.P0PA.VGA.GETD",
170 /* L3C */
171 "\\_SB.PCI0.PCI1.VGAC.NMAP",
172 /* Z96F */
173 "\\_SB.PCI0.VGA.GETD",
174 /* A2D */
175 "\\ACTD",
176 /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
177 "\\ADVG",
178 /* P30 */
179 "\\DNXT",
180 /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
181 "\\INFB",
182 /* A3F A6F A3N A3L M6N W3N W6A */
183 "\\SSTE");
Corentin Chary78127b42007-01-26 14:04:49 +0100184
Corentin Chary50a90c42009-11-30 21:55:12 +0100185ASUS_HANDLE(ls_switch, ASUS_LAPTOP_PREFIX "ALSC"); /* Z71A Z71V */
186ASUS_HANDLE(ls_level, ASUS_LAPTOP_PREFIX "ALSL"); /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100187
Corentin Charye539c2f2007-05-06 14:47:06 +0200188/* GPS */
189/* R2H use different handle for GPS on/off */
Corentin Chary50a90c42009-11-30 21:55:12 +0100190ASUS_HANDLE(gps_on, ASUS_LAPTOP_PREFIX "SDON"); /* R2H */
191ASUS_HANDLE(gps_off, ASUS_LAPTOP_PREFIX "SDOF"); /* R2H */
192ASUS_HANDLE(gps_status, ASUS_LAPTOP_PREFIX "GPST");
Corentin Charye539c2f2007-05-06 14:47:06 +0200193
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000194/* Keyboard light */
Corentin Chary50a90c42009-11-30 21:55:12 +0100195ASUS_HANDLE(kled_set, ASUS_LAPTOP_PREFIX "SLKB");
196ASUS_HANDLE(kled_get, ASUS_LAPTOP_PREFIX "GLKB");
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000197
Corentin Chary85091b72007-01-26 14:04:30 +0100198/*
199 * This is the main structure, we can use it to store anything interesting
200 * about the hotk device
201 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100202struct asus_laptop {
Corentin Charybe966662009-08-29 10:28:29 +0200203 char *name; /* laptop name */
Corentin Chary600ad522009-11-30 21:42:42 +0100204
Corentin Chary7c247642009-11-30 22:13:54 +0100205 struct acpi_table_header *dsdt_info;
Corentin Chary600ad522009-11-30 21:42:42 +0100206 struct platform_device *platform_device;
Corentin Chary7c247642009-11-30 22:13:54 +0100207 struct acpi_device *device; /* the device we are in */
208 struct backlight_device *backlight_device;
209 struct input_dev *inputdev;
210
Corentin Charybe966662009-08-29 10:28:29 +0200211 acpi_handle handle; /* the handle of the hotk device */
212 char status; /* status of the hotk, for LEDs, ... */
213 u32 ledd_status; /* status of the LED display */
214 u8 light_level; /* light sensor level */
215 u8 light_switch; /* light sensor switch value */
216 u16 event_count[128]; /* count for each event TODO make this better */
Corentin Chary034ce902009-01-20 16:17:43 +0100217 u16 *keycode_map;
Corentin Chary85091b72007-01-26 14:04:30 +0100218};
219
Corentin Chary50a90c42009-11-30 21:55:12 +0100220static struct asus_laptop *asus;
Corentin Chary85091b72007-01-26 14:04:30 +0100221
Corentin Chary7c247642009-11-30 22:13:54 +0100222static struct workqueue_struct *led_workqueue;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100223
224/*
225 * The backlight class declaration
226 */
227static int read_brightness(struct backlight_device *bd);
228static int update_bl_status(struct backlight_device *bd);
Richard Purdie599a52d2007-02-10 23:07:48 +0000229static struct backlight_ops asusbl_ops = {
Len Brown8def05f2007-01-30 01:46:43 -0500230 .get_brightness = read_brightness,
231 .update_status = update_bl_status,
Corentin Chary6b7091e2007-01-26 14:04:45 +0100232};
233
Corentin Chary977c3282009-08-28 12:56:49 +0000234#define ASUS_LED(object, ledname, max) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100235 static void object##_led_set(struct led_classdev *led_cdev, \
236 enum led_brightness value); \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000237 static enum led_brightness object##_led_get( \
238 struct led_classdev *led_cdev); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100239 static void object##_led_update(struct work_struct *ignored); \
240 static int object##_led_wk; \
Adrian Bunkf110ef52007-02-20 01:07:25 +0100241 static DECLARE_WORK(object##_led_work, object##_led_update); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100242 static struct led_classdev object##_led = { \
Richard Purdie6c152be2007-10-31 15:00:07 +0100243 .name = "asus::" ledname, \
Corentin Charybe18cda2007-01-26 14:04:35 +0100244 .brightness_set = object##_led_set, \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000245 .brightness_get = object##_led_get, \
Corentin Chary977c3282009-08-28 12:56:49 +0000246 .max_brightness = max \
Corentin Charybe18cda2007-01-26 14:04:35 +0100247 }
248
Corentin Chary977c3282009-08-28 12:56:49 +0000249ASUS_LED(mled, "mail", 1);
250ASUS_LED(tled, "touchpad", 1);
251ASUS_LED(rled, "record", 1);
252ASUS_LED(pled, "phone", 1);
253ASUS_LED(gled, "gaming", 1);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000254ASUS_LED(kled, "kbd_backlight", 3);
Corentin Charybe18cda2007-01-26 14:04:35 +0100255
Corentin Chary034ce902009-01-20 16:17:43 +0100256struct key_entry {
257 char type;
258 u8 code;
259 u16 keycode;
260};
261
262enum { KE_KEY, KE_END };
263
264static struct key_entry asus_keymap[] = {
Ike Panhc14f8af32009-12-03 07:45:11 +0000265 {KE_KEY, 0x02, KEY_SCREENLOCK},
266 {KE_KEY, 0x05, KEY_WLAN},
267 {KE_KEY, 0x08, KEY_F13},
268 {KE_KEY, 0x17, KEY_ZOOM},
269 {KE_KEY, 0x1f, KEY_BATTERY},
Corentin Chary034ce902009-01-20 16:17:43 +0100270 {KE_KEY, 0x30, KEY_VOLUMEUP},
271 {KE_KEY, 0x31, KEY_VOLUMEDOWN},
272 {KE_KEY, 0x32, KEY_MUTE},
273 {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE},
274 {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE},
275 {KE_KEY, 0x40, KEY_PREVIOUSSONG},
276 {KE_KEY, 0x41, KEY_NEXTSONG},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200277 {KE_KEY, 0x43, KEY_STOPCD},
Corentin Chary034ce902009-01-20 16:17:43 +0100278 {KE_KEY, 0x45, KEY_PLAYPAUSE},
Corentin Chary4644d0e2009-08-28 12:56:52 +0000279 {KE_KEY, 0x4c, KEY_MEDIA},
Corentin Chary034ce902009-01-20 16:17:43 +0100280 {KE_KEY, 0x50, KEY_EMAIL},
281 {KE_KEY, 0x51, KEY_WWW},
Corentin Chary0aa20f72009-08-28 12:56:53 +0000282 {KE_KEY, 0x55, KEY_CALC},
Corentin Chary309f5fb2009-04-27 09:23:42 +0200283 {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */
Corentin Chary034ce902009-01-20 16:17:43 +0100284 {KE_KEY, 0x5D, KEY_WLAN},
Corentin Charyf6413752009-08-28 12:56:48 +0000285 {KE_KEY, 0x5E, KEY_WLAN},
286 {KE_KEY, 0x5F, KEY_WLAN},
287 {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE},
Corentin Chary034ce902009-01-20 16:17:43 +0100288 {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE},
Ike Panhc14f8af32009-12-03 07:45:11 +0000289 {KE_KEY, 0x62, KEY_SWITCHVIDEOMODE},
290 {KE_KEY, 0x63, KEY_SWITCHVIDEOMODE},
Corentin Chary16851f92009-12-03 07:45:10 +0000291 {KE_KEY, 0x6B, KEY_F13}, /* Lock Touchpad */
Corentin Chary034ce902009-01-20 16:17:43 +0100292 {KE_KEY, 0x82, KEY_CAMERA},
Corentin Chary1f0233e2009-12-03 07:45:12 +0000293 {KE_KEY, 0x88, KEY_WLAN },
Corentin Chary309f5fb2009-04-27 09:23:42 +0200294 {KE_KEY, 0x8A, KEY_PROG1},
Corentin Chary034ce902009-01-20 16:17:43 +0100295 {KE_KEY, 0x95, KEY_MEDIA},
296 {KE_KEY, 0x99, KEY_PHONE},
Corentin Charydc795262009-08-28 12:56:51 +0000297 {KE_KEY, 0xc4, KEY_KBDILLUMUP},
298 {KE_KEY, 0xc5, KEY_KBDILLUMDOWN},
Corentin Chary034ce902009-01-20 16:17:43 +0100299 {KE_END, 0},
300};
301
Corentin Chary85091b72007-01-26 14:04:30 +0100302/*
303 * This function evaluates an ACPI method, given an int as parameter, the
304 * method is searched within the scope of the handle, can be NULL. The output
305 * of the method is written is output, which can also be NULL
306 *
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100307 * returns 0 if write is successful, -1 else.
Corentin Chary85091b72007-01-26 14:04:30 +0100308 */
Corentin Charyd8c67322009-11-28 10:27:51 +0100309static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
310 struct acpi_buffer *output)
Corentin Chary85091b72007-01-26 14:04:30 +0100311{
Corentin Charybe966662009-08-29 10:28:29 +0200312 struct acpi_object_list params; /* list of input parameters (an int) */
313 union acpi_object in_obj; /* the only param we use */
Corentin Chary85091b72007-01-26 14:04:30 +0100314 acpi_status status;
315
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100316 if (!handle)
317 return 0;
318
Corentin Chary85091b72007-01-26 14:04:30 +0100319 params.count = 1;
320 params.pointer = &in_obj;
321 in_obj.type = ACPI_TYPE_INTEGER;
322 in_obj.integer.value = val;
323
324 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Corentin CHARYf8d1c942008-01-16 16:56:42 +0100325 if (status == AE_OK)
326 return 0;
327 else
328 return -1;
Corentin Chary85091b72007-01-26 14:04:30 +0100329}
330
Corentin Charyd8c67322009-11-28 10:27:51 +0100331static int write_acpi_int(acpi_handle handle, const char *method, int val)
332{
333 return write_acpi_int_ret(handle, method, val, NULL);
334}
335
Len Brown8def05f2007-01-30 01:46:43 -0500336static int read_wireless_status(int mask)
337{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400338 unsigned long long status;
Corentin Chary9a816852007-03-11 10:25:38 +0100339 acpi_status rv = AE_OK;
Corentin Chary4564de12007-01-26 14:04:40 +0100340
341 if (!wireless_status_handle)
Corentin Chary50a90c42009-11-30 21:55:12 +0100342 return (asus->status & mask) ? 1 : 0;
Corentin Chary4564de12007-01-26 14:04:40 +0100343
Corentin Chary9a816852007-03-11 10:25:38 +0100344 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
345 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200346 pr_warning("Error reading Wireless status\n");
Corentin Chary9a816852007-03-11 10:25:38 +0100347 else
348 return (status & mask) ? 1 : 0;
Corentin Chary4564de12007-01-26 14:04:40 +0100349
Corentin Chary50a90c42009-11-30 21:55:12 +0100350 return (asus->status & mask) ? 1 : 0;
Corentin Chary4564de12007-01-26 14:04:40 +0100351}
352
Corentin Charyf3985322007-05-06 14:48:22 +0200353static int read_gps_status(void)
354{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400355 unsigned long long status;
Corentin Charye539c2f2007-05-06 14:47:06 +0200356 acpi_status rv = AE_OK;
357
358 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
359 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200360 pr_warning("Error reading GPS status\n");
Corentin Charye539c2f2007-05-06 14:47:06 +0200361 else
Corentin Charyf3985322007-05-06 14:48:22 +0200362 return status ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200363
Corentin Chary50a90c42009-11-30 21:55:12 +0100364 return (asus->status & GPS_ON) ? 1 : 0;
Corentin Charye539c2f2007-05-06 14:47:06 +0200365}
366
Corentin Charybe18cda2007-01-26 14:04:35 +0100367/* Generic LED functions */
368static int read_status(int mask)
369{
Corentin Chary4564de12007-01-26 14:04:40 +0100370 /* There is a special method for both wireless devices */
371 if (mask == BT_ON || mask == WL_ON)
372 return read_wireless_status(mask);
Corentin Charyf3985322007-05-06 14:48:22 +0200373 else if (mask == GPS_ON)
374 return read_gps_status();
Corentin Chary4564de12007-01-26 14:04:40 +0100375
Corentin Chary50a90c42009-11-30 21:55:12 +0100376 return (asus->status & mask) ? 1 : 0;
Corentin Charybe18cda2007-01-26 14:04:35 +0100377}
378
Corentin Chary935ffee2007-03-11 10:26:12 +0100379static void write_status(acpi_handle handle, int out, int mask)
Corentin Charybe18cda2007-01-26 14:04:35 +0100380{
Corentin Chary50a90c42009-11-30 21:55:12 +0100381 asus->status = (out) ? (asus->status | mask) : (asus->status & ~mask);
Corentin Charybe18cda2007-01-26 14:04:35 +0100382
Corentin Chary935ffee2007-03-11 10:26:12 +0100383 switch (mask) {
384 case MLED_ON:
Roel Kluine1af14e2008-02-02 21:07:38 +0100385 out = !(out & 0x1);
Corentin Chary935ffee2007-03-11 10:26:12 +0100386 break;
Corentin Charyfdd8d082007-03-11 10:26:48 +0100387 case GLED_ON:
388 out = (out & 0x1) + 1;
389 break;
Corentin Charye539c2f2007-05-06 14:47:06 +0200390 case GPS_ON:
391 handle = (out) ? gps_on_handle : gps_off_handle;
392 out = 0x02;
393 break;
Corentin Chary935ffee2007-03-11 10:26:12 +0100394 default:
395 out &= 0x1;
396 break;
397 }
Corentin Charybe18cda2007-01-26 14:04:35 +0100398
Corentin Charyd8c67322009-11-28 10:27:51 +0100399 if (write_acpi_int(handle, NULL, out))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200400 pr_warning(" write failed %x\n", mask);
Corentin Charybe18cda2007-01-26 14:04:35 +0100401}
402
403/* /sys/class/led handlers */
Corentin Chary935ffee2007-03-11 10:26:12 +0100404#define ASUS_LED_HANDLER(object, mask) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100405 static void object##_led_set(struct led_classdev *led_cdev, \
406 enum led_brightness value) \
407 { \
Corentin Charye3deda92008-09-24 10:35:55 +0200408 object##_led_wk = (value > 0) ? 1 : 0; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100409 queue_work(led_workqueue, &object##_led_work); \
410 } \
411 static void object##_led_update(struct work_struct *ignored) \
412 { \
413 int value = object##_led_wk; \
Corentin Chary935ffee2007-03-11 10:26:12 +0100414 write_status(object##_set_handle, value, (mask)); \
Corentin Charyabfa57e2009-08-28 12:56:47 +0000415 } \
416 static enum led_brightness object##_led_get( \
417 struct led_classdev *led_cdev) \
418 { \
419 return led_cdev->brightness; \
Corentin Charybe18cda2007-01-26 14:04:35 +0100420 }
421
Corentin Chary935ffee2007-03-11 10:26:12 +0100422ASUS_LED_HANDLER(mled, MLED_ON);
423ASUS_LED_HANDLER(pled, PLED_ON);
424ASUS_LED_HANDLER(rled, RLED_ON);
425ASUS_LED_HANDLER(tled, TLED_ON);
Corentin Charyfdd8d082007-03-11 10:26:48 +0100426ASUS_LED_HANDLER(gled, GLED_ON);
Corentin Charybe18cda2007-01-26 14:04:35 +0100427
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000428/*
429 * Keyboard backlight
430 */
431static int get_kled_lvl(void)
432{
433 unsigned long long kblv;
434 struct acpi_object_list params;
435 union acpi_object in_obj;
436 acpi_status rv;
437
438 params.count = 1;
439 params.pointer = &in_obj;
440 in_obj.type = ACPI_TYPE_INTEGER;
441 in_obj.integer.value = 2;
442
443 rv = acpi_evaluate_integer(kled_get_handle, NULL, &params, &kblv);
444 if (ACPI_FAILURE(rv)) {
445 pr_warning("Error reading kled level\n");
446 return 0;
447 }
448 return kblv;
449}
450
451static int set_kled_lvl(int kblv)
452{
453 if (kblv > 0)
454 kblv = (1 << 7) | (kblv & 0x7F);
455 else
456 kblv = 0;
457
Corentin Charyd8c67322009-11-28 10:27:51 +0100458 if (write_acpi_int(kled_set_handle, NULL, kblv)) {
Corentin Charyb7d3fbc2009-08-28 12:56:50 +0000459 pr_warning("Keyboard LED display write failed\n");
460 return -EINVAL;
461 }
462 return 0;
463}
464
465static void kled_led_set(struct led_classdev *led_cdev,
466 enum led_brightness value)
467{
468 kled_led_wk = value;
469 queue_work(led_workqueue, &kled_led_work);
470}
471
472static void kled_led_update(struct work_struct *ignored)
473{
474 set_kled_lvl(kled_led_wk);
475}
476
477static enum led_brightness kled_led_get(struct led_classdev *led_cdev)
478{
479 return get_kled_lvl();
480}
481
Corentin Chary6b7091e2007-01-26 14:04:45 +0100482static int get_lcd_state(void)
483{
484 return read_status(LCD_ON);
485}
486
487static int set_lcd_state(int value)
488{
489 int lcd = 0;
490 acpi_status status = 0;
491
492 lcd = value ? 1 : 0;
493
494 if (lcd == get_lcd_state())
495 return 0;
496
Len Brown8def05f2007-01-30 01:46:43 -0500497 if (lcd_switch_handle) {
Corentin Chary6b7091e2007-01-26 14:04:45 +0100498 status = acpi_evaluate_object(lcd_switch_handle,
499 NULL, NULL, NULL);
500
501 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200502 pr_warning("Error switching LCD\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100503 }
504
Corentin Chary935ffee2007-03-11 10:26:12 +0100505 write_status(NULL, lcd, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100506 return 0;
507}
508
509static void lcd_blank(int blank)
510{
Corentin Chary7c247642009-11-30 22:13:54 +0100511 struct backlight_device *bd = asus->backlight_device;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100512
Len Brown8def05f2007-01-30 01:46:43 -0500513 if (bd) {
Richard Purdie599a52d2007-02-10 23:07:48 +0000514 bd->props.power = blank;
Richard Purdie28ee0862007-02-08 22:25:09 +0000515 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100516 }
517}
518
519static int read_brightness(struct backlight_device *bd)
520{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400521 unsigned long long value;
Corentin Chary9a816852007-03-11 10:25:38 +0100522 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100523
Corentin Chary9a816852007-03-11 10:25:38 +0100524 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
525 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200526 pr_warning("Error reading brightness\n");
Corentin Chary6b7091e2007-01-26 14:04:45 +0100527
528 return value;
529}
530
531static int set_brightness(struct backlight_device *bd, int value)
532{
Corentin Charyd8c67322009-11-28 10:27:51 +0100533 if (write_acpi_int(brightness_set_handle, NULL, value)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200534 pr_warning("Error changing brightness\n");
Corentin Charye5b50f62009-11-28 10:19:55 +0100535 return -EIO;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100536 }
Corentin Charye5b50f62009-11-28 10:19:55 +0100537 return 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100538}
539
540static int update_bl_status(struct backlight_device *bd)
541{
542 int rv;
Richard Purdie599a52d2007-02-10 23:07:48 +0000543 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100544
545 rv = set_brightness(bd, value);
Len Brown8def05f2007-01-30 01:46:43 -0500546 if (rv)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100547 return rv;
548
Richard Purdie599a52d2007-02-10 23:07:48 +0000549 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100550 return set_lcd_state(value);
551}
552
Corentin Chary85091b72007-01-26 14:04:30 +0100553/*
554 * Platform device handlers
555 */
556
557/*
558 * We write our info in page, we begin at offset off and cannot write more
559 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
560 * number of bytes written in page
561 */
562static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500563 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100564{
565 int len = 0;
Matthew Wilcox27663c52008-10-10 02:22:59 -0400566 unsigned long long temp;
Corentin Charybe966662009-08-29 10:28:29 +0200567 char buf[16]; /* enough for all info */
Corentin Chary9a816852007-03-11 10:25:38 +0100568 acpi_status rv = AE_OK;
569
Corentin Chary85091b72007-01-26 14:04:30 +0100570 /*
571 * We use the easy way, we don't care of off and count, so we don't set eof
572 * to 1
573 */
574
Corentin Chary50a90c42009-11-30 21:55:12 +0100575 len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
576 len += sprintf(page + len, "Model reference : %s\n", asus->name);
Corentin Chary85091b72007-01-26 14:04:30 +0100577 /*
578 * The SFUN method probably allows the original driver to get the list
579 * of features supported by a given model. For now, 0x0100 or 0x0800
580 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
581 * The significance of others is yet to be found.
582 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100583 rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100584 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000585 len += sprintf(page + len, "SFUN value : %#x\n",
586 (uint) temp);
587 /*
588 * The HWRS method return informations about the hardware.
589 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
590 * The significance of others is yet to be found.
591 * If we don't find the method, we assume the device are present.
592 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100593 rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
Corentin Chary1d4a3802009-08-28 12:56:46 +0000594 if (!ACPI_FAILURE(rv))
595 len += sprintf(page + len, "HRWS value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100596 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100597 /*
598 * Another value for userspace: the ASYM method returns 0x02 for
599 * battery low and 0x04 for battery critical, its readings tend to be
600 * more accurate than those provided by _BST.
601 * Note: since not all the laptops provide this method, errors are
602 * silently ignored.
603 */
Corentin Chary50a90c42009-11-30 21:55:12 +0100604 rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
Corentin Chary9a816852007-03-11 10:25:38 +0100605 if (!ACPI_FAILURE(rv))
Corentin Chary1d4a3802009-08-28 12:56:46 +0000606 len += sprintf(page + len, "ASYM value : %#x\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100607 (uint) temp);
Corentin Chary7c247642009-11-30 22:13:54 +0100608 if (asus->dsdt_info) {
609 snprintf(buf, 16, "%d", asus->dsdt_info->length);
Corentin Chary85091b72007-01-26 14:04:30 +0100610 len += sprintf(page + len, "DSDT length : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100611 snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
Corentin Chary85091b72007-01-26 14:04:30 +0100612 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100613 snprintf(buf, 16, "%d", asus->dsdt_info->revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100614 len += sprintf(page + len, "DSDT revision : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100615 snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100616 len += sprintf(page + len, "OEM id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100617 snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100618 len += sprintf(page + len, "OEM table id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100619 snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100620 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100621 snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
Corentin Chary85091b72007-01-26 14:04:30 +0100622 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
Corentin Chary7c247642009-11-30 22:13:54 +0100623 snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
Corentin Chary85091b72007-01-26 14:04:30 +0100624 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
625 }
626
627 return len;
628}
629
630static int parse_arg(const char *buf, unsigned long count, int *val)
631{
632 if (!count)
633 return 0;
634 if (count > 31)
635 return -EINVAL;
636 if (sscanf(buf, "%i", val) != 1)
637 return -EINVAL;
638 return count;
639}
640
Corentin Chary4564de12007-01-26 14:04:40 +0100641static ssize_t store_status(const char *buf, size_t count,
Corentin Chary935ffee2007-03-11 10:26:12 +0100642 acpi_handle handle, int mask)
Corentin Chary4564de12007-01-26 14:04:40 +0100643{
644 int rv, value;
645 int out = 0;
646
647 rv = parse_arg(buf, count, &value);
648 if (rv > 0)
649 out = value ? 1 : 0;
650
Corentin Chary935ffee2007-03-11 10:26:12 +0100651 write_status(handle, out, mask);
Corentin Chary4564de12007-01-26 14:04:40 +0100652
653 return rv;
654}
655
656/*
Corentin Chary722ad972007-01-26 14:04:55 +0100657 * LEDD display
658 */
659static ssize_t show_ledd(struct device *dev,
660 struct device_attribute *attr, char *buf)
661{
Corentin Chary50a90c42009-11-30 21:55:12 +0100662 return sprintf(buf, "0x%08x\n", asus->ledd_status);
Corentin Chary722ad972007-01-26 14:04:55 +0100663}
664
665static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
666 const char *buf, size_t count)
667{
668 int rv, value;
669
670 rv = parse_arg(buf, count, &value);
671 if (rv > 0) {
Corentin Charyd8c67322009-11-28 10:27:51 +0100672 if (write_acpi_int(ledd_set_handle, NULL, value))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200673 pr_warning("LED display write failed\n");
Corentin Chary722ad972007-01-26 14:04:55 +0100674 else
Corentin Chary50a90c42009-11-30 21:55:12 +0100675 asus->ledd_status = (u32) value;
Corentin Chary722ad972007-01-26 14:04:55 +0100676 }
677 return rv;
678}
679
680/*
Corentin Chary4564de12007-01-26 14:04:40 +0100681 * WLAN
682 */
683static ssize_t show_wlan(struct device *dev,
684 struct device_attribute *attr, char *buf)
685{
686 return sprintf(buf, "%d\n", read_status(WL_ON));
687}
688
689static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
690 const char *buf, size_t count)
691{
Corentin Chary935ffee2007-03-11 10:26:12 +0100692 return store_status(buf, count, wl_switch_handle, WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100693}
694
695/*
696 * Bluetooth
697 */
698static ssize_t show_bluetooth(struct device *dev,
699 struct device_attribute *attr, char *buf)
700{
701 return sprintf(buf, "%d\n", read_status(BT_ON));
702}
703
Len Brown8def05f2007-01-30 01:46:43 -0500704static ssize_t store_bluetooth(struct device *dev,
705 struct device_attribute *attr, const char *buf,
706 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100707{
Corentin Chary935ffee2007-03-11 10:26:12 +0100708 return store_status(buf, count, bt_switch_handle, BT_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100709}
710
Corentin Chary78127b42007-01-26 14:04:49 +0100711/*
712 * Display
713 */
714static void set_display(int value)
715{
716 /* no sanity check needed for now */
Corentin Charyd8c67322009-11-28 10:27:51 +0100717 if (write_acpi_int(display_set_handle, NULL, value))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200718 pr_warning("Error setting display\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100719 return;
720}
721
722static int read_display(void)
723{
Matthew Wilcox27663c52008-10-10 02:22:59 -0400724 unsigned long long value = 0;
Corentin Chary9a816852007-03-11 10:25:38 +0100725 acpi_status rv = AE_OK;
Corentin Chary78127b42007-01-26 14:04:49 +0100726
Corentin Charybe966662009-08-29 10:28:29 +0200727 /*
728 * In most of the case, we know how to set the display, but sometime
729 * we can't read it
730 */
Len Brown8def05f2007-01-30 01:46:43 -0500731 if (display_get_handle) {
Corentin Chary9a816852007-03-11 10:25:38 +0100732 rv = acpi_evaluate_integer(display_get_handle, NULL,
733 NULL, &value);
734 if (ACPI_FAILURE(rv))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200735 pr_warning("Error reading display status\n");
Corentin Chary78127b42007-01-26 14:04:49 +0100736 }
737
738 value &= 0x0F; /* needed for some models, shouldn't hurt others */
739
740 return value;
741}
Len Brown8def05f2007-01-30 01:46:43 -0500742
Corentin Chary78127b42007-01-26 14:04:49 +0100743/*
744 * Now, *this* one could be more user-friendly, but so far, no-one has
745 * complained. The significance of bits is the same as in store_disp()
746 */
747static ssize_t show_disp(struct device *dev,
748 struct device_attribute *attr, char *buf)
749{
750 return sprintf(buf, "%d\n", read_display());
751}
752
753/*
754 * Experimental support for display switching. As of now: 1 should activate
755 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
756 * Any combination (bitwise) of these will suffice. I never actually tested 4
757 * displays hooked up simultaneously, so be warned. See the acpi4asus README
758 * for more info.
759 */
760static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
761 const char *buf, size_t count)
762{
763 int rv, value;
764
765 rv = parse_arg(buf, count, &value);
766 if (rv > 0)
767 set_display(value);
768 return rv;
769}
770
Corentin Chary8b857352007-01-26 14:04:58 +0100771/*
772 * Light Sens
773 */
774static void set_light_sens_switch(int value)
775{
Corentin Charyd8c67322009-11-28 10:27:51 +0100776 if (write_acpi_int(ls_switch_handle, NULL, value))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200777 pr_warning("Error setting light sensor switch\n");
Corentin Chary50a90c42009-11-30 21:55:12 +0100778 asus->light_switch = value;
Corentin Chary8b857352007-01-26 14:04:58 +0100779}
780
781static ssize_t show_lssw(struct device *dev,
782 struct device_attribute *attr, char *buf)
783{
Corentin Chary50a90c42009-11-30 21:55:12 +0100784 return sprintf(buf, "%d\n", asus->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +0100785}
786
787static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
788 const char *buf, size_t count)
789{
790 int rv, value;
791
792 rv = parse_arg(buf, count, &value);
793 if (rv > 0)
794 set_light_sens_switch(value ? 1 : 0);
795
796 return rv;
797}
798
799static void set_light_sens_level(int value)
800{
Corentin Charyd8c67322009-11-28 10:27:51 +0100801 if (write_acpi_int(ls_level_handle, NULL, value))
Corentin Chary2fcc23d2009-06-19 14:52:03 +0200802 pr_warning("Error setting light sensor level\n");
Corentin Chary50a90c42009-11-30 21:55:12 +0100803 asus->light_level = value;
Corentin Chary8b857352007-01-26 14:04:58 +0100804}
805
806static ssize_t show_lslvl(struct device *dev,
807 struct device_attribute *attr, char *buf)
808{
Corentin Chary50a90c42009-11-30 21:55:12 +0100809 return sprintf(buf, "%d\n", asus->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +0100810}
811
812static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
813 const char *buf, size_t count)
814{
815 int rv, value;
816
817 rv = parse_arg(buf, count, &value);
818 if (rv > 0) {
819 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
820 /* 0 <= value <= 15 */
821 set_light_sens_level(value);
822 }
823
824 return rv;
825}
826
Corentin Charye539c2f2007-05-06 14:47:06 +0200827/*
828 * GPS
829 */
830static ssize_t show_gps(struct device *dev,
831 struct device_attribute *attr, char *buf)
832{
833 return sprintf(buf, "%d\n", read_status(GPS_ON));
834}
835
836static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
837 const char *buf, size_t count)
838{
Corentin Charyf3985322007-05-06 14:48:22 +0200839 return store_status(buf, count, NULL, GPS_ON);
Corentin Charye539c2f2007-05-06 14:47:06 +0200840}
841
Corentin Chary034ce902009-01-20 16:17:43 +0100842/*
843 * Hotkey functions
844 */
845static struct key_entry *asus_get_entry_by_scancode(int code)
846{
847 struct key_entry *key;
848
849 for (key = asus_keymap; key->type != KE_END; key++)
850 if (code == key->code)
851 return key;
852
853 return NULL;
854}
855
856static struct key_entry *asus_get_entry_by_keycode(int code)
857{
858 struct key_entry *key;
859
860 for (key = asus_keymap; key->type != KE_END; key++)
861 if (code == key->keycode && key->type == KE_KEY)
862 return key;
863
864 return NULL;
865}
866
867static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode)
868{
869 struct key_entry *key = asus_get_entry_by_scancode(scancode);
870
871 if (key && key->type == KE_KEY) {
872 *keycode = key->keycode;
873 return 0;
874 }
875
876 return -EINVAL;
877}
878
879static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode)
880{
881 struct key_entry *key;
882 int old_keycode;
883
884 if (keycode < 0 || keycode > KEY_MAX)
885 return -EINVAL;
886
887 key = asus_get_entry_by_scancode(scancode);
888 if (key && key->type == KE_KEY) {
889 old_keycode = key->keycode;
890 key->keycode = keycode;
891 set_bit(keycode, dev->keybit);
892 if (!asus_get_entry_by_keycode(old_keycode))
893 clear_bit(old_keycode, dev->keybit);
894 return 0;
895 }
896
897 return -EINVAL;
898}
899
Corentin Chary600ad522009-11-30 21:42:42 +0100900static void asus_acpi_notify(struct acpi_device *device, u32 event)
Corentin Chary85091b72007-01-26 14:04:30 +0100901{
Corentin Chary034ce902009-01-20 16:17:43 +0100902 static struct key_entry *key;
Corentin Chary6050c8d2009-02-15 19:30:19 +0100903 u16 count;
Corentin Chary034ce902009-01-20 16:17:43 +0100904
Corentin Chary6b7091e2007-01-26 14:04:45 +0100905 /*
906 * We need to tell the backlight device when the backlight power is
907 * switched
908 */
909 if (event == ATKD_LCD_ON) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100910 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100911 lcd_blank(FB_BLANK_UNBLANK);
Len Brown8def05f2007-01-30 01:46:43 -0500912 } else if (event == ATKD_LCD_OFF) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100913 write_status(NULL, 0, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100914 lcd_blank(FB_BLANK_POWERDOWN);
915 }
916
Corentin Chary619d8b12009-11-28 10:35:37 +0100917 /* TODO Find a better way to handle events count. */
Corentin Chary50a90c42009-11-30 21:55:12 +0100918 count = asus->event_count[event % 128]++;
919 acpi_bus_generate_proc_event(asus->device, event, count);
920 acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
921 dev_name(&asus->device->dev), event,
Corentin Chary6050c8d2009-02-15 19:30:19 +0100922 count);
Corentin Chary85091b72007-01-26 14:04:30 +0100923
Corentin Chary50a90c42009-11-30 21:55:12 +0100924 if (asus->inputdev) {
Corentin Chary034ce902009-01-20 16:17:43 +0100925 key = asus_get_entry_by_scancode(event);
926 if (!key)
927 return ;
928
929 switch (key->type) {
930 case KE_KEY:
Corentin Chary50a90c42009-11-30 21:55:12 +0100931 input_report_key(asus->inputdev, key->keycode, 1);
932 input_sync(asus->inputdev);
933 input_report_key(asus->inputdev, key->keycode, 0);
934 input_sync(asus->inputdev);
Corentin Chary034ce902009-01-20 16:17:43 +0100935 break;
936 }
937 }
Corentin Chary85091b72007-01-26 14:04:30 +0100938}
939
940#define ASUS_CREATE_DEVICE_ATTR(_name) \
941 struct device_attribute dev_attr_##_name = { \
942 .attr = { \
943 .name = __stringify(_name), \
Tejun Heo7b595752007-06-14 03:45:17 +0900944 .mode = 0 }, \
Corentin Chary85091b72007-01-26 14:04:30 +0100945 .show = NULL, \
946 .store = NULL, \
947 }
948
949#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
950 do { \
951 dev_attr_##_name.attr.mode = _mode; \
952 dev_attr_##_name.show = _show; \
953 dev_attr_##_name.store = _store; \
954 } while(0)
955
956static ASUS_CREATE_DEVICE_ATTR(infos);
Corentin Chary4564de12007-01-26 14:04:40 +0100957static ASUS_CREATE_DEVICE_ATTR(wlan);
958static ASUS_CREATE_DEVICE_ATTR(bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100959static ASUS_CREATE_DEVICE_ATTR(display);
Corentin Chary722ad972007-01-26 14:04:55 +0100960static ASUS_CREATE_DEVICE_ATTR(ledd);
Corentin Chary8b857352007-01-26 14:04:58 +0100961static ASUS_CREATE_DEVICE_ATTR(ls_switch);
962static ASUS_CREATE_DEVICE_ATTR(ls_level);
Corentin Charye539c2f2007-05-06 14:47:06 +0200963static ASUS_CREATE_DEVICE_ATTR(gps);
Corentin Chary85091b72007-01-26 14:04:30 +0100964
965static struct attribute *asuspf_attributes[] = {
Len Brown8def05f2007-01-30 01:46:43 -0500966 &dev_attr_infos.attr,
967 &dev_attr_wlan.attr,
968 &dev_attr_bluetooth.attr,
969 &dev_attr_display.attr,
970 &dev_attr_ledd.attr,
971 &dev_attr_ls_switch.attr,
972 &dev_attr_ls_level.attr,
Corentin Charye539c2f2007-05-06 14:47:06 +0200973 &dev_attr_gps.attr,
Len Brown8def05f2007-01-30 01:46:43 -0500974 NULL
Corentin Chary85091b72007-01-26 14:04:30 +0100975};
976
Corentin Chary600ad522009-11-30 21:42:42 +0100977static struct attribute_group platform_attribute_group = {
Len Brown8def05f2007-01-30 01:46:43 -0500978 .attrs = asuspf_attributes
Corentin Chary85091b72007-01-26 14:04:30 +0100979};
980
Corentin Chary600ad522009-11-30 21:42:42 +0100981static int asus_platform_init(void)
982{
983 int result;
984
Corentin Chary50a90c42009-11-30 21:55:12 +0100985 asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
986 if (!asus->platform_device)
Corentin Chary600ad522009-11-30 21:42:42 +0100987 return -ENOMEM;
988
Corentin Chary50a90c42009-11-30 21:55:12 +0100989 result = platform_device_add(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +0100990 if (result)
991 goto fail_platform_device;
992
Corentin Chary50a90c42009-11-30 21:55:12 +0100993 result = sysfs_create_group(&asus->platform_device->dev.kobj,
Corentin Chary600ad522009-11-30 21:42:42 +0100994 &platform_attribute_group);
995 if (result)
996 goto fail_sysfs;
997 return 0;
998
999fail_sysfs:
Corentin Chary50a90c42009-11-30 21:55:12 +01001000 platform_device_del(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001001fail_platform_device:
Corentin Chary50a90c42009-11-30 21:55:12 +01001002 platform_device_put(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001003 return result;
1004}
1005
1006static void asus_platform_exit(void)
1007{
Corentin Chary50a90c42009-11-30 21:55:12 +01001008 sysfs_remove_group(&asus->platform_device->dev.kobj,
Corentin Chary600ad522009-11-30 21:42:42 +01001009 &platform_attribute_group);
Corentin Chary50a90c42009-11-30 21:55:12 +01001010 platform_device_unregister(asus->platform_device);
Corentin Chary600ad522009-11-30 21:42:42 +01001011}
1012
1013static struct platform_driver platform_driver = {
Len Brown8def05f2007-01-30 01:46:43 -05001014 .driver = {
Corentin Chary50a90c42009-11-30 21:55:12 +01001015 .name = ASUS_LAPTOP_FILE,
Len Brown8def05f2007-01-30 01:46:43 -05001016 .owner = THIS_MODULE,
1017 }
Corentin Chary85091b72007-01-26 14:04:30 +01001018};
1019
Corentin Chary50a90c42009-11-30 21:55:12 +01001020static void asus_laptop_add_fs(void)
Corentin Chary85091b72007-01-26 14:04:30 +01001021{
1022 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
Corentin Chary4564de12007-01-26 14:04:40 +01001023
1024 if (wl_switch_handle)
1025 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
1026
1027 if (bt_switch_handle)
1028 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
1029 show_bluetooth, store_bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +01001030
1031 if (display_set_handle && display_get_handle)
1032 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
Len Brown8def05f2007-01-30 01:46:43 -05001033 else if (display_set_handle)
Corentin Chary78127b42007-01-26 14:04:49 +01001034 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
1035
Corentin Chary722ad972007-01-26 14:04:55 +01001036 if (ledd_set_handle)
1037 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
1038
Corentin Chary8b857352007-01-26 14:04:58 +01001039 if (ls_switch_handle && ls_level_handle) {
1040 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
1041 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
1042 }
Corentin Charye539c2f2007-05-06 14:47:06 +02001043
Corentin Charyf3985322007-05-06 14:48:22 +02001044 if (gps_status_handle && gps_on_handle && gps_off_handle)
Corentin Charye539c2f2007-05-06 14:47:06 +02001045 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
Corentin Chary85091b72007-01-26 14:04:30 +01001046}
1047
Len Brown8def05f2007-01-30 01:46:43 -05001048static int asus_handle_init(char *name, acpi_handle * handle,
Corentin Chary85091b72007-01-26 14:04:30 +01001049 char **paths, int num_paths)
1050{
1051 int i;
1052 acpi_status status;
1053
1054 for (i = 0; i < num_paths; i++) {
1055 status = acpi_get_handle(NULL, paths[i], handle);
1056 if (ACPI_SUCCESS(status))
1057 return 0;
1058 }
1059
1060 *handle = NULL;
1061 return -ENODEV;
1062}
1063
1064#define ASUS_HANDLE_INIT(object) \
1065 asus_handle_init(#object, &object##_handle, object##_paths, \
1066 ARRAY_SIZE(object##_paths))
1067
Corentin Chary85091b72007-01-26 14:04:30 +01001068/*
Corentin Chary50a90c42009-11-30 21:55:12 +01001069 * This function is used to initialize the context with right values. In this
1070 * method, we can make all the detection we want, and modify the asus_laptop
1071 * struct
Corentin Chary85091b72007-01-26 14:04:30 +01001072 */
Corentin Chary7c247642009-11-30 22:13:54 +01001073static int asus_laptop_get_info(struct asus_laptop *asus)
Corentin Chary85091b72007-01-26 14:04:30 +01001074{
1075 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +01001076 union acpi_object *model = NULL;
Matthew Wilcox27663c52008-10-10 02:22:59 -04001077 unsigned long long bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +01001078 char *string = NULL;
1079 acpi_status status;
1080
1081 /*
1082 * Get DSDT headers early enough to allow for differentiating between
1083 * models, but late enough to allow acpi_bus_register_driver() to fail
1084 * before doing anything ACPI-specific. Should we encounter a machine,
1085 * which needs special handling (i.e. its hotkey device has a different
Corentin Chary7c247642009-11-30 22:13:54 +01001086 * HID), this bit will be moved.
Corentin Chary85091b72007-01-26 14:04:30 +01001087 */
Corentin Chary7c247642009-11-30 22:13:54 +01001088 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
Corentin Chary85091b72007-01-26 14:04:30 +01001089 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001090 pr_warning("Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001091
1092 /* We have to write 0 on init this far for all ASUS models */
Corentin Chary50a90c42009-11-30 21:55:12 +01001093 if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001094 pr_err("Hotkey initialization failed\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001095 return -ENODEV;
1096 }
1097
1098 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +01001099 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001100 acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
Corentin Chary9a816852007-03-11 10:25:38 +01001101 if (ACPI_FAILURE(status))
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001102 pr_warning("Error calling BSTS\n");
Corentin Chary85091b72007-01-26 14:04:30 +01001103 else if (bsts_result)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001104 pr_notice("BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +01001105 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +01001106
Corentin Chary185e5af2007-03-11 10:27:33 +01001107 /* This too ... */
Corentin Chary50a90c42009-11-30 21:55:12 +01001108 write_acpi_int(asus->handle, "CWAP", wapf);
Corentin Chary185e5af2007-03-11 10:27:33 +01001109
Corentin Chary85091b72007-01-26 14:04:30 +01001110 /*
1111 * Try to match the object returned by INIT to the specific model.
1112 * Handle every possible object (or the lack of thereof) the DSDT
1113 * writers might throw at us. When in trouble, we pass NULL to
1114 * asus_model_match() and try something completely different.
1115 */
1116 if (buffer.pointer) {
1117 model = buffer.pointer;
1118 switch (model->type) {
1119 case ACPI_TYPE_STRING:
1120 string = model->string.pointer;
1121 break;
1122 case ACPI_TYPE_BUFFER:
1123 string = model->buffer.pointer;
1124 break;
1125 default:
1126 string = "";
1127 break;
1128 }
1129 }
Corentin Chary50a90c42009-11-30 21:55:12 +01001130 asus->name = kstrdup(string, GFP_KERNEL);
1131 if (!asus->name)
Corentin Chary85091b72007-01-26 14:04:30 +01001132 return -ENOMEM;
1133
Len Brown8def05f2007-01-30 01:46:43 -05001134 if (*string)
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001135 pr_notice(" %s model detected\n", string);
Corentin Chary85091b72007-01-26 14:04:30 +01001136
Corentin Charybe18cda2007-01-26 14:04:35 +01001137 ASUS_HANDLE_INIT(mled_set);
1138 ASUS_HANDLE_INIT(tled_set);
1139 ASUS_HANDLE_INIT(rled_set);
1140 ASUS_HANDLE_INIT(pled_set);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001141 ASUS_HANDLE_INIT(gled_set);
Corentin Charybe18cda2007-01-26 14:04:35 +01001142
Corentin Chary722ad972007-01-26 14:04:55 +01001143 ASUS_HANDLE_INIT(ledd_set);
1144
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001145 ASUS_HANDLE_INIT(kled_set);
1146 ASUS_HANDLE_INIT(kled_get);
1147
Corentin Chary4564de12007-01-26 14:04:40 +01001148 /*
1149 * The HWRS method return informations about the hardware.
1150 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
1151 * The significance of others is yet to be found.
1152 * If we don't find the method, we assume the device are present.
1153 */
Corentin Chary9a816852007-03-11 10:25:38 +01001154 status =
Corentin Chary50a90c42009-11-30 21:55:12 +01001155 acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
Corentin Chary9a816852007-03-11 10:25:38 +01001156 if (ACPI_FAILURE(status))
Corentin Chary4564de12007-01-26 14:04:40 +01001157 hwrs_result = WL_HWRS | BT_HWRS;
1158
Len Brown8def05f2007-01-30 01:46:43 -05001159 if (hwrs_result & WL_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001160 ASUS_HANDLE_INIT(wl_switch);
Len Brown8def05f2007-01-30 01:46:43 -05001161 if (hwrs_result & BT_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +01001162 ASUS_HANDLE_INIT(bt_switch);
1163
1164 ASUS_HANDLE_INIT(wireless_status);
1165
Corentin Chary6b7091e2007-01-26 14:04:45 +01001166 ASUS_HANDLE_INIT(brightness_set);
1167 ASUS_HANDLE_INIT(brightness_get);
1168
1169 ASUS_HANDLE_INIT(lcd_switch);
1170
Corentin Chary78127b42007-01-26 14:04:49 +01001171 ASUS_HANDLE_INIT(display_set);
1172 ASUS_HANDLE_INIT(display_get);
1173
Corentin Charybe966662009-08-29 10:28:29 +02001174 /*
1175 * There is a lot of models with "ALSL", but a few get
1176 * a real light sens, so we need to check it.
1177 */
Corentin Chary832d9952007-05-06 14:47:29 +02001178 if (!ASUS_HANDLE_INIT(ls_switch))
Corentin Chary8b857352007-01-26 14:04:58 +01001179 ASUS_HANDLE_INIT(ls_level);
1180
Corentin Charye539c2f2007-05-06 14:47:06 +02001181 ASUS_HANDLE_INIT(gps_on);
1182 ASUS_HANDLE_INIT(gps_off);
1183 ASUS_HANDLE_INIT(gps_status);
1184
Corentin Chary85091b72007-01-26 14:04:30 +01001185 kfree(model);
1186
1187 return AE_OK;
1188}
1189
Corentin Chary600ad522009-11-30 21:42:42 +01001190static int asus_input_init(struct device *dev)
Corentin Chary034ce902009-01-20 16:17:43 +01001191{
1192 const struct key_entry *key;
1193 int result;
1194
Corentin Chary50a90c42009-11-30 21:55:12 +01001195 asus->inputdev = input_allocate_device();
1196 if (!asus->inputdev) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001197 pr_info("Unable to allocate input device\n");
Corentin Chary034ce902009-01-20 16:17:43 +01001198 return 0;
1199 }
Corentin Chary50a90c42009-11-30 21:55:12 +01001200 asus->inputdev->name = "Asus Laptop extra buttons";
1201 asus->inputdev->dev.parent = dev;
1202 asus->inputdev->phys = ASUS_LAPTOP_FILE "/input0";
1203 asus->inputdev->id.bustype = BUS_HOST;
1204 asus->inputdev->getkeycode = asus_getkeycode;
1205 asus->inputdev->setkeycode = asus_setkeycode;
Corentin Chary034ce902009-01-20 16:17:43 +01001206
1207 for (key = asus_keymap; key->type != KE_END; key++) {
1208 switch (key->type) {
1209 case KE_KEY:
Corentin Chary50a90c42009-11-30 21:55:12 +01001210 set_bit(EV_KEY, asus->inputdev->evbit);
1211 set_bit(key->keycode, asus->inputdev->keybit);
Corentin Chary034ce902009-01-20 16:17:43 +01001212 break;
1213 }
1214 }
Corentin Chary50a90c42009-11-30 21:55:12 +01001215 result = input_register_device(asus->inputdev);
Corentin Chary034ce902009-01-20 16:17:43 +01001216 if (result) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001217 pr_info("Unable to register input device\n");
Corentin Chary50a90c42009-11-30 21:55:12 +01001218 input_free_device(asus->inputdev);
Corentin Chary034ce902009-01-20 16:17:43 +01001219 }
1220 return result;
1221}
1222
Corentin Chary6b7091e2007-01-26 14:04:45 +01001223static void asus_backlight_exit(void)
1224{
Corentin Chary7c247642009-11-30 22:13:54 +01001225 if (asus->backlight_device)
1226 backlight_device_unregister(asus->backlight_device);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001227}
1228
Corentin Charybe18cda2007-01-26 14:04:35 +01001229#define ASUS_LED_UNREGISTER(object) \
Guillaume Chazaraine1996a692007-08-16 18:18:53 +02001230 if (object##_led.dev) \
1231 led_classdev_unregister(&object##_led)
Corentin Charybe18cda2007-01-26 14:04:35 +01001232
1233static void asus_led_exit(void)
1234{
Al Viro3b0d7112007-07-23 11:21:34 +01001235 destroy_workqueue(led_workqueue);
Corentin Charybe18cda2007-01-26 14:04:35 +01001236 ASUS_LED_UNREGISTER(mled);
1237 ASUS_LED_UNREGISTER(tled);
1238 ASUS_LED_UNREGISTER(pled);
1239 ASUS_LED_UNREGISTER(rled);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001240 ASUS_LED_UNREGISTER(gled);
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001241 ASUS_LED_UNREGISTER(kled);
Corentin Charybe18cda2007-01-26 14:04:35 +01001242}
1243
Corentin Chary034ce902009-01-20 16:17:43 +01001244static void asus_input_exit(void)
1245{
Corentin Chary50a90c42009-11-30 21:55:12 +01001246 if (asus->inputdev)
1247 input_unregister_device(asus->inputdev);
Corentin Chary034ce902009-01-20 16:17:43 +01001248}
1249
Len Brown8def05f2007-01-30 01:46:43 -05001250static int asus_backlight_init(struct device *dev)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001251{
1252 struct backlight_device *bd;
1253
Len Brown8def05f2007-01-30 01:46:43 -05001254 if (brightness_set_handle && lcd_switch_handle) {
Corentin Chary50a90c42009-11-30 21:55:12 +01001255 bd = backlight_device_register(ASUS_LAPTOP_FILE, dev,
Richard Purdie599a52d2007-02-10 23:07:48 +00001256 NULL, &asusbl_ops);
Len Brown8def05f2007-01-30 01:46:43 -05001257 if (IS_ERR(bd)) {
Corentin Chary2fcc23d2009-06-19 14:52:03 +02001258 pr_err("Could not register asus backlight device\n");
Corentin Chary7c247642009-11-30 22:13:54 +01001259 asus->backlight_device = NULL;
Corentin Chary6b7091e2007-01-26 14:04:45 +01001260 return PTR_ERR(bd);
1261 }
1262
Corentin Chary7c247642009-11-30 22:13:54 +01001263 asus->backlight_device = bd;
Corentin Chary6b7091e2007-01-26 14:04:45 +01001264
Richard Purdie599a52d2007-02-10 23:07:48 +00001265 bd->props.max_brightness = 15;
1266 bd->props.brightness = read_brightness(NULL);
1267 bd->props.power = FB_BLANK_UNBLANK;
Richard Purdie28ee0862007-02-08 22:25:09 +00001268 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001269 }
1270 return 0;
1271}
1272
Corentin Charybe18cda2007-01-26 14:04:35 +01001273static int asus_led_register(acpi_handle handle,
Len Brown8def05f2007-01-30 01:46:43 -05001274 struct led_classdev *ldev, struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001275{
Len Brown8def05f2007-01-30 01:46:43 -05001276 if (!handle)
Corentin Charybe18cda2007-01-26 14:04:35 +01001277 return 0;
1278
1279 return led_classdev_register(dev, ldev);
1280}
Len Brown8def05f2007-01-30 01:46:43 -05001281
Corentin Charybe18cda2007-01-26 14:04:35 +01001282#define ASUS_LED_REGISTER(object, device) \
1283 asus_led_register(object##_set_handle, &object##_led, device)
1284
Len Brown8def05f2007-01-30 01:46:43 -05001285static int asus_led_init(struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001286{
1287 int rv;
1288
1289 rv = ASUS_LED_REGISTER(mled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001290 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001291 goto out;
Corentin Charybe18cda2007-01-26 14:04:35 +01001292
1293 rv = ASUS_LED_REGISTER(tled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001294 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001295 goto out1;
Corentin Charybe18cda2007-01-26 14:04:35 +01001296
1297 rv = ASUS_LED_REGISTER(rled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001298 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001299 goto out2;
Corentin Charybe18cda2007-01-26 14:04:35 +01001300
1301 rv = ASUS_LED_REGISTER(pled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001302 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001303 goto out3;
Corentin Charybe18cda2007-01-26 14:04:35 +01001304
Corentin Charyfdd8d082007-03-11 10:26:48 +01001305 rv = ASUS_LED_REGISTER(gled, dev);
1306 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001307 goto out4;
Corentin Charyfdd8d082007-03-11 10:26:48 +01001308
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001309 if (kled_set_handle && kled_get_handle)
1310 rv = ASUS_LED_REGISTER(kled, dev);
1311 if (rv)
Al Viro3b0d7112007-07-23 11:21:34 +01001312 goto out5;
Corentin Charybe18cda2007-01-26 14:04:35 +01001313
Corentin Chary7c247642009-11-30 22:13:54 +01001314 /*
1315 * Functions that actually update the LED's are called from a
1316 * workqueue. By doing this as separate work rather than when the LED
1317 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
1318 * potentially bad time, such as a timer interrupt.
1319 */
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001320 led_workqueue = create_singlethread_workqueue("led_workqueue");
1321 if (!led_workqueue)
1322 goto out6;
1323
Corentin Charybe18cda2007-01-26 14:04:35 +01001324 return 0;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001325out6:
Al Viro3b0d7112007-07-23 11:21:34 +01001326 rv = -ENOMEM;
Corentin Charyb7d3fbc2009-08-28 12:56:50 +00001327 ASUS_LED_UNREGISTER(kled);
1328out5:
Al Viro3b0d7112007-07-23 11:21:34 +01001329 ASUS_LED_UNREGISTER(gled);
1330out4:
1331 ASUS_LED_UNREGISTER(pled);
1332out3:
1333 ASUS_LED_UNREGISTER(rled);
1334out2:
1335 ASUS_LED_UNREGISTER(tled);
1336out1:
1337 ASUS_LED_UNREGISTER(mled);
1338out:
1339 return rv;
Corentin Charybe18cda2007-01-26 14:04:35 +01001340}
1341
Corentin Chary600ad522009-11-30 21:42:42 +01001342
1343static bool asus_device_present;
1344
1345static int __devinit asus_acpi_init(struct acpi_device *device)
1346{
1347 int result = 0;
1348
Corentin Chary50a90c42009-11-30 21:55:12 +01001349 result = acpi_bus_get_status(asus->device);
Corentin Chary600ad522009-11-30 21:42:42 +01001350 if (result)
1351 return result;
Corentin Chary50a90c42009-11-30 21:55:12 +01001352 if (!asus->device->status.present) {
Corentin Chary600ad522009-11-30 21:42:42 +01001353 pr_err("Hotkey device not present, aborting\n");
1354 return -ENODEV;
1355 }
1356
Corentin Chary7c247642009-11-30 22:13:54 +01001357 result = asus_laptop_get_info(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001358 if (result)
1359 return result;
1360
Corentin Chary50a90c42009-11-30 21:55:12 +01001361 asus_laptop_add_fs();
Corentin Chary600ad522009-11-30 21:42:42 +01001362
1363 /* WLED and BLED are on by default */
1364 write_status(bt_switch_handle, 1, BT_ON);
1365 write_status(wl_switch_handle, 1, WL_ON);
1366
1367 /* If the h/w switch is off, we need to check the real status */
1368 write_status(NULL, read_status(BT_ON), BT_ON);
1369 write_status(NULL, read_status(WL_ON), WL_ON);
1370
1371 /* LCD Backlight is on by default */
1372 write_status(NULL, 1, LCD_ON);
1373
1374 /* Keyboard Backlight is on by default */
1375 if (kled_set_handle)
1376 set_kled_lvl(1);
1377
1378 /* LED display is off by default */
Corentin Chary50a90c42009-11-30 21:55:12 +01001379 asus->ledd_status = 0xFFF;
Corentin Chary600ad522009-11-30 21:42:42 +01001380
1381 /* Set initial values of light sensor and level */
1382 hotk->light_switch = 0; /* Default to light sensor disabled */
1383 hotk->light_level = 5; /* level 5 for sensor sensitivity */
1384
1385 if (ls_switch_handle)
Corentin Chary50a90c42009-11-30 21:55:12 +01001386 set_light_sens_switch(asus->light_switch);
Corentin Chary600ad522009-11-30 21:42:42 +01001387
1388 if (ls_level_handle)
Corentin Chary50a90c42009-11-30 21:55:12 +01001389 set_light_sens_level(asus->light_level);
Corentin Chary600ad522009-11-30 21:42:42 +01001390
1391 /* GPS is on by default */
1392 write_status(NULL, 1, GPS_ON);
1393 return result;
1394}
1395
1396static int __devinit asus_acpi_add(struct acpi_device *device)
1397{
1398 int result;
1399
1400 pr_notice("Asus Laptop Support version %s\n",
1401 ASUS_LAPTOP_VERSION);
Corentin Chary50a90c42009-11-30 21:55:12 +01001402 asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1403 if (!asus)
Corentin Chary600ad522009-11-30 21:42:42 +01001404 return -ENOMEM;
Corentin Chary50a90c42009-11-30 21:55:12 +01001405 asus->handle = device->handle;
1406 strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1407 strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1408 device->driver_data = asus;
1409 asus->device = device;
Corentin Chary600ad522009-11-30 21:42:42 +01001410
1411 result = asus_acpi_init(device);
1412 if (result)
1413 goto fail_platform;
1414
1415 /*
1416 * Register the platform device first. It is used as a parent for the
1417 * sub-devices below.
1418 */
1419 result = asus_platform_init();
1420 if (result)
1421 goto fail_platform;
1422
1423 if (!acpi_video_backlight_support()) {
Corentin Chary50a90c42009-11-30 21:55:12 +01001424 result = asus_backlight_init(&asus->platform_device->dev);
Corentin Chary600ad522009-11-30 21:42:42 +01001425 if (result)
1426 goto fail_backlight;
1427 } else
1428 pr_info("Backlight controlled by ACPI video driver\n");
1429
Corentin Chary50a90c42009-11-30 21:55:12 +01001430 result = asus_input_init(&asus->platform_device->dev);
Corentin Chary600ad522009-11-30 21:42:42 +01001431 if (result)
1432 goto fail_input;
1433
Corentin Chary50a90c42009-11-30 21:55:12 +01001434 result = asus_led_init(&asus->platform_device->dev);
Corentin Chary600ad522009-11-30 21:42:42 +01001435 if (result)
1436 goto fail_led;
1437
1438 asus_device_present = true;
1439 return 0;
1440
1441fail_led:
1442 asus_input_exit();
1443fail_input:
1444 asus_backlight_exit();
1445fail_backlight:
1446 asus_platform_exit();
1447fail_platform:
Corentin Chary50a90c42009-11-30 21:55:12 +01001448 kfree(asus->name);
1449 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001450
1451 return result;
1452}
1453
1454static int asus_acpi_remove(struct acpi_device *device, int type)
1455{
1456 asus_backlight_exit();
1457 asus_led_exit();
1458 asus_input_exit();
1459 asus_platform_exit();
1460
Corentin Chary50a90c42009-11-30 21:55:12 +01001461 kfree(asus->name);
1462 kfree(asus);
Corentin Chary600ad522009-11-30 21:42:42 +01001463 return 0;
1464}
1465
1466static const struct acpi_device_id asus_device_ids[] = {
1467 {"ATK0100", 0},
1468 {"ATK0101", 0},
1469 {"", 0},
1470};
1471MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1472
1473static struct acpi_driver asus_acpi_driver = {
Corentin Chary50a90c42009-11-30 21:55:12 +01001474 .name = ASUS_LAPTOP_NAME,
1475 .class = ASUS_LAPTOP_CLASS,
Corentin Chary600ad522009-11-30 21:42:42 +01001476 .owner = THIS_MODULE,
1477 .ids = asus_device_ids,
1478 .flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1479 .ops = {
1480 .add = asus_acpi_add,
1481 .remove = asus_acpi_remove,
1482 .notify = asus_acpi_notify,
1483 },
1484};
1485
Corentin Chary85091b72007-01-26 14:04:30 +01001486static int __init asus_laptop_init(void)
1487{
1488 int result;
1489
Corentin Chary600ad522009-11-30 21:42:42 +01001490 result = platform_driver_register(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001491 if (result < 0)
1492 return result;
1493
Corentin Chary600ad522009-11-30 21:42:42 +01001494 result = acpi_bus_register_driver(&asus_acpi_driver);
1495 if (result < 0)
1496 goto fail_acpi_driver;
1497 if (!asus_device_present) {
1498 result = -ENODEV;
1499 goto fail_no_device;
Corentin Chary85091b72007-01-26 14:04:30 +01001500 }
Len Brown8def05f2007-01-30 01:46:43 -05001501 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001502
Corentin Chary600ad522009-11-30 21:42:42 +01001503fail_no_device:
1504 acpi_bus_unregister_driver(&asus_acpi_driver);
1505fail_acpi_driver:
1506 platform_driver_unregister(&platform_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001507 return result;
1508}
1509
Corentin Chary600ad522009-11-30 21:42:42 +01001510static void __exit asus_laptop_exit(void)
1511{
1512 acpi_bus_unregister_driver(&asus_acpi_driver);
1513 platform_driver_unregister(&platform_driver);
1514}
1515
Corentin Chary85091b72007-01-26 14:04:30 +01001516module_init(asus_laptop_init);
1517module_exit(asus_laptop_exit);