blob: b39419cc29836ed29f2268a0371a90c6f0d15c39 [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
36#include <linux/autoconf.h>
37#include <linux/kernel.h>
38#include <linux/module.h>
39#include <linux/init.h>
40#include <linux/types.h>
41#include <linux/err.h>
42#include <linux/proc_fs.h>
Corentin Chary6b7091e2007-01-26 14:04:45 +010043#include <linux/backlight.h>
44#include <linux/fb.h>
Corentin Charybe18cda2007-01-26 14:04:35 +010045#include <linux/leds.h>
Corentin Chary85091b72007-01-26 14:04:30 +010046#include <linux/platform_device.h>
47#include <acpi/acpi_drivers.h>
48#include <acpi/acpi_bus.h>
49#include <asm/uaccess.h>
50
Corentin Chary8ec555c2007-03-11 10:28:03 +010051#define ASUS_LAPTOP_VERSION "0.41"
Corentin Chary85091b72007-01-26 14:04:30 +010052
53#define ASUS_HOTK_NAME "Asus Laptop Support"
54#define ASUS_HOTK_CLASS "hotkey"
55#define ASUS_HOTK_DEVICE_NAME "Hotkey"
56#define ASUS_HOTK_HID "ATK0100"
57#define ASUS_HOTK_FILE "asus-laptop"
58#define ASUS_HOTK_PREFIX "\\_SB.ATKD."
59
Corentin Charybe18cda2007-01-26 14:04:35 +010060/*
Corentin Chary6b7091e2007-01-26 14:04:45 +010061 * Some events we use, same for all Asus
62 */
63#define ATKD_BR_UP 0x10
64#define ATKD_BR_DOWN 0x20
65#define ATKD_LCD_ON 0x33
66#define ATKD_LCD_OFF 0x34
67
68/*
Corentin Chary4564de12007-01-26 14:04:40 +010069 * Known bits returned by \_SB.ATKD.HWRS
Corentin Charybe18cda2007-01-26 14:04:35 +010070 */
Corentin Chary4564de12007-01-26 14:04:40 +010071#define WL_HWRS 0x80
72#define BT_HWRS 0x100
73
74/*
75 * Flags for hotk status
76 * WL_ON and BT_ON are also used for wireless_status()
77 */
78#define WL_ON 0x01 //internal Wifi
79#define BT_ON 0x02 //internal Bluetooth
Corentin Charybe18cda2007-01-26 14:04:35 +010080#define MLED_ON 0x04 //mail LED
81#define TLED_ON 0x08 //touchpad LED
Len Brown8def05f2007-01-30 01:46:43 -050082#define RLED_ON 0x10 //Record LED
83#define PLED_ON 0x20 //Phone LED
Corentin Charyfdd8d082007-03-11 10:26:48 +010084#define GLED_ON 0x40 //Gaming LED
85#define LCD_ON 0x80 //LCD backlight
Corentin Charye539c2f2007-05-06 14:47:06 +020086#define GPS_ON 0x100 //GPS
Corentin Charybe18cda2007-01-26 14:04:35 +010087
Corentin Chary85091b72007-01-26 14:04:30 +010088#define ASUS_LOG ASUS_HOTK_FILE ": "
89#define ASUS_ERR KERN_ERR ASUS_LOG
90#define ASUS_WARNING KERN_WARNING ASUS_LOG
91#define ASUS_NOTICE KERN_NOTICE ASUS_LOG
92#define ASUS_INFO KERN_INFO ASUS_LOG
93#define ASUS_DEBUG KERN_DEBUG ASUS_LOG
94
95MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
96MODULE_DESCRIPTION(ASUS_HOTK_NAME);
97MODULE_LICENSE("GPL");
98
Corentin Chary185e5af2007-03-11 10:27:33 +010099/* WAPF defines the behavior of the Fn+Fx wlan key
100 * The significance of values is yet to be found, but
101 * most of the time:
102 * 0x0 will do nothing
103 * 0x1 will allow to control the device with Fn+Fx key.
104 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
105 * 0x5 like 0x1 or 0x4
106 * So, if something doesn't work as you want, just try other values =)
107 */
108static uint wapf = 1;
109module_param(wapf, uint, 0644);
110MODULE_PARM_DESC(wapf, "WAPF value");
111
Corentin Chary85091b72007-01-26 14:04:30 +0100112#define ASUS_HANDLE(object, paths...) \
113 static acpi_handle object##_handle = NULL; \
114 static char *object##_paths[] = { paths }
115
Corentin Charybe18cda2007-01-26 14:04:35 +0100116/* LED */
117ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
118ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
Len Brown8def05f2007-01-30 01:46:43 -0500119ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */
120ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */
Corentin Charyfdd8d082007-03-11 10:26:48 +0100121ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED"); /* G1, G2 (probably) */
Corentin Charybe18cda2007-01-26 14:04:35 +0100122
Corentin Chary722ad972007-01-26 14:04:55 +0100123/* LEDD */
124ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
125
Corentin Chary4564de12007-01-26 14:04:40 +0100126/* Bluetooth and WLAN
127 * WLED and BLED are not handled like other XLED, because in some dsdt
128 * they also control the WLAN/Bluetooth device.
129 */
130ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED");
131ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED");
Len Brown8def05f2007-01-30 01:46:43 -0500132ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */
Corentin Chary4564de12007-01-26 14:04:40 +0100133
Corentin Chary6b7091e2007-01-26 14:04:45 +0100134/* Brightness */
135ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV");
136ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV");
137
138/* Backlight */
Len Brown8def05f2007-01-30 01:46:43 -0500139ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
140 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
141 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
142 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
143 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
144 "\\_SB.PCI0.PX40.Q10", /* S1x */
145 "\\Q10"); /* A2x, L2D, L3D, M2E */
Corentin Chary6b7091e2007-01-26 14:04:45 +0100146
Corentin Chary78127b42007-01-26 14:04:49 +0100147/* Display */
148ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
Len Brown8def05f2007-01-30 01:46:43 -0500149ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD", /* A6B, A6K A6R A7D F3JM L4R M6R A3G
150 M6A M6V VX-1 V6J V6V W3Z */
151 "\\_SB.PCI0.P0P2.VGA.GETD", /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V
Corentin Chary78127b42007-01-26 14:04:49 +0100152 S5A M5A z33A W1Jc W2V */
Len Brown8def05f2007-01-30 01:46:43 -0500153 "\\_SB.PCI0.P0P3.VGA.GETD", /* A6V A6Q */
154 "\\_SB.PCI0.P0PA.VGA.GETD", /* A6T, A6M */
155 "\\_SB.PCI0.PCI1.VGAC.NMAP", /* L3C */
156 "\\_SB.PCI0.VGA.GETD", /* Z96F */
157 "\\ACTD", /* A2D */
158 "\\ADVG", /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
159 "\\DNXT", /* P30 */
160 "\\INFB", /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
161 "\\SSTE"); /* A3F A6F A3N A3L M6N W3N W6A */
Corentin Chary78127b42007-01-26 14:04:49 +0100162
Len Brown8def05f2007-01-30 01:46:43 -0500163ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */
164ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100165
Corentin Charye539c2f2007-05-06 14:47:06 +0200166/* GPS */
167/* R2H use different handle for GPS on/off */
168ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON"); /* R2H */
169ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */
170ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST");
171
Corentin Chary85091b72007-01-26 14:04:30 +0100172/*
173 * This is the main structure, we can use it to store anything interesting
174 * about the hotk device
175 */
176struct asus_hotk {
Len Brown8def05f2007-01-30 01:46:43 -0500177 char *name; //laptop name
Corentin Chary85091b72007-01-26 14:04:30 +0100178 struct acpi_device *device; //the device we are in
179 acpi_handle handle; //the handle of the hotk device
180 char status; //status of the hotk, for LEDs, ...
Corentin Chary722ad972007-01-26 14:04:55 +0100181 u32 ledd_status; //status of the LED display
Len Brown8def05f2007-01-30 01:46:43 -0500182 u8 light_level; //light sensor level
183 u8 light_switch; //light sensor switch value
Corentin Chary85091b72007-01-26 14:04:30 +0100184 u16 event_count[128]; //count for each event TODO make this better
185};
186
187/*
188 * This header is made available to allow proper configuration given model,
189 * revision number , ... this info cannot go in struct asus_hotk because it is
190 * available before the hotk
191 */
192static struct acpi_table_header *asus_info;
193
194/* The actual device the driver binds to */
195static struct asus_hotk *hotk;
196
197/*
198 * The hotkey driver declaration
199 */
200static int asus_hotk_add(struct acpi_device *device);
201static int asus_hotk_remove(struct acpi_device *device, int type);
202static struct acpi_driver asus_hotk_driver = {
203 .name = ASUS_HOTK_NAME,
204 .class = ASUS_HOTK_CLASS,
205 .ids = ASUS_HOTK_HID,
206 .ops = {
207 .add = asus_hotk_add,
208 .remove = asus_hotk_remove,
209 },
210};
211
Corentin Chary6b7091e2007-01-26 14:04:45 +0100212/* The backlight device /sys/class/backlight */
213static struct backlight_device *asus_backlight_device;
214
215/*
216 * The backlight class declaration
217 */
218static int read_brightness(struct backlight_device *bd);
219static int update_bl_status(struct backlight_device *bd);
Richard Purdie599a52d2007-02-10 23:07:48 +0000220static struct backlight_ops asusbl_ops = {
Len Brown8def05f2007-01-30 01:46:43 -0500221 .get_brightness = read_brightness,
222 .update_status = update_bl_status,
Corentin Chary6b7091e2007-01-26 14:04:45 +0100223};
224
Corentin Charybe18cda2007-01-26 14:04:35 +0100225/* These functions actually update the LED's, and are called from a
226 * workqueue. By doing this as separate work rather than when the LED
227 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
228 * potentially bad time, such as a timer interrupt. */
229static struct workqueue_struct *led_workqueue;
230
231#define ASUS_LED(object, ledname) \
232 static void object##_led_set(struct led_classdev *led_cdev, \
233 enum led_brightness value); \
234 static void object##_led_update(struct work_struct *ignored); \
235 static int object##_led_wk; \
Adrian Bunkf110ef52007-02-20 01:07:25 +0100236 static DECLARE_WORK(object##_led_work, object##_led_update); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100237 static struct led_classdev object##_led = { \
238 .name = "asus:" ledname, \
239 .brightness_set = object##_led_set, \
240 }
241
242ASUS_LED(mled, "mail");
243ASUS_LED(tled, "touchpad");
244ASUS_LED(rled, "record");
245ASUS_LED(pled, "phone");
Corentin Charyfdd8d082007-03-11 10:26:48 +0100246ASUS_LED(gled, "gaming");
Corentin Charybe18cda2007-01-26 14:04:35 +0100247
Corentin Chary85091b72007-01-26 14:04:30 +0100248/*
249 * This function evaluates an ACPI method, given an int as parameter, the
250 * method is searched within the scope of the handle, can be NULL. The output
251 * of the method is written is output, which can also be NULL
252 *
253 * returns 1 if write is successful, 0 else.
254 */
255static int write_acpi_int(acpi_handle handle, const char *method, int val,
256 struct acpi_buffer *output)
257{
258 struct acpi_object_list params; //list of input parameters (an int here)
259 union acpi_object in_obj; //the only param we use
260 acpi_status status;
261
262 params.count = 1;
263 params.pointer = &in_obj;
264 in_obj.type = ACPI_TYPE_INTEGER;
265 in_obj.integer.value = val;
266
267 status = acpi_evaluate_object(handle, (char *)method, &params, output);
268 return (status == AE_OK);
269}
270
Len Brown8def05f2007-01-30 01:46:43 -0500271static int read_wireless_status(int mask)
272{
Corentin Chary9a816852007-03-11 10:25:38 +0100273 ulong status;
274 acpi_status rv = AE_OK;
Corentin Chary4564de12007-01-26 14:04:40 +0100275
276 if (!wireless_status_handle)
277 return (hotk->status & mask) ? 1 : 0;
278
Corentin Chary9a816852007-03-11 10:25:38 +0100279 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
280 if (ACPI_FAILURE(rv))
Corentin Chary4564de12007-01-26 14:04:40 +0100281 printk(ASUS_WARNING "Error reading Wireless status\n");
Corentin Chary9a816852007-03-11 10:25:38 +0100282 else
283 return (status & mask) ? 1 : 0;
Corentin Chary4564de12007-01-26 14:04:40 +0100284
285 return (hotk->status & mask) ? 1 : 0;
286}
287
Corentin Charye539c2f2007-05-06 14:47:06 +0200288static int read_gps_status(void) {
289 ulong status;
290 acpi_status rv = AE_OK;
291
292 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
293 if (ACPI_FAILURE(rv))
294 printk(ASUS_WARNING "Error reading GPS status\n");
295 else
296 return status ? 1 : 0;
297
298 return (hotk->status & GPS_ON) ? 1 : 0;
299}
300
Corentin Charybe18cda2007-01-26 14:04:35 +0100301/* Generic LED functions */
302static int read_status(int mask)
303{
Corentin Chary4564de12007-01-26 14:04:40 +0100304 /* There is a special method for both wireless devices */
305 if (mask == BT_ON || mask == WL_ON)
306 return read_wireless_status(mask);
Corentin Charye539c2f2007-05-06 14:47:06 +0200307 else if(mask == GPS_ON)
308 return read_gps_status();
Corentin Chary4564de12007-01-26 14:04:40 +0100309
Corentin Charybe18cda2007-01-26 14:04:35 +0100310 return (hotk->status & mask) ? 1 : 0;
311}
312
Corentin Chary935ffee2007-03-11 10:26:12 +0100313static void write_status(acpi_handle handle, int out, int mask)
Corentin Charybe18cda2007-01-26 14:04:35 +0100314{
315 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
316
Corentin Chary935ffee2007-03-11 10:26:12 +0100317 switch (mask) {
318 case MLED_ON:
Corentin Charybe18cda2007-01-26 14:04:35 +0100319 out = !out & 0x1;
Corentin Chary935ffee2007-03-11 10:26:12 +0100320 break;
Corentin Charyfdd8d082007-03-11 10:26:48 +0100321 case GLED_ON:
322 out = (out & 0x1) + 1;
323 break;
Corentin Charye539c2f2007-05-06 14:47:06 +0200324 case GPS_ON:
325 handle = (out) ? gps_on_handle : gps_off_handle;
326 out = 0x02;
327 break;
Corentin Chary935ffee2007-03-11 10:26:12 +0100328 default:
329 out &= 0x1;
330 break;
331 }
Corentin Charybe18cda2007-01-26 14:04:35 +0100332
333 if (handle && !write_acpi_int(handle, NULL, out, NULL))
Corentin Chary935ffee2007-03-11 10:26:12 +0100334 printk(ASUS_WARNING " write failed %x\n", mask);
Corentin Charybe18cda2007-01-26 14:04:35 +0100335}
336
337/* /sys/class/led handlers */
Corentin Chary935ffee2007-03-11 10:26:12 +0100338#define ASUS_LED_HANDLER(object, mask) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100339 static void object##_led_set(struct led_classdev *led_cdev, \
340 enum led_brightness value) \
341 { \
342 object##_led_wk = value; \
343 queue_work(led_workqueue, &object##_led_work); \
344 } \
345 static void object##_led_update(struct work_struct *ignored) \
346 { \
347 int value = object##_led_wk; \
Corentin Chary935ffee2007-03-11 10:26:12 +0100348 write_status(object##_set_handle, value, (mask)); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100349 }
350
Corentin Chary935ffee2007-03-11 10:26:12 +0100351ASUS_LED_HANDLER(mled, MLED_ON);
352ASUS_LED_HANDLER(pled, PLED_ON);
353ASUS_LED_HANDLER(rled, RLED_ON);
354ASUS_LED_HANDLER(tled, TLED_ON);
Corentin Charyfdd8d082007-03-11 10:26:48 +0100355ASUS_LED_HANDLER(gled, GLED_ON);
Corentin Charybe18cda2007-01-26 14:04:35 +0100356
Corentin Chary6b7091e2007-01-26 14:04:45 +0100357static int get_lcd_state(void)
358{
359 return read_status(LCD_ON);
360}
361
362static int set_lcd_state(int value)
363{
364 int lcd = 0;
365 acpi_status status = 0;
366
367 lcd = value ? 1 : 0;
368
369 if (lcd == get_lcd_state())
370 return 0;
371
Len Brown8def05f2007-01-30 01:46:43 -0500372 if (lcd_switch_handle) {
Corentin Chary6b7091e2007-01-26 14:04:45 +0100373 status = acpi_evaluate_object(lcd_switch_handle,
374 NULL, NULL, NULL);
375
376 if (ACPI_FAILURE(status))
377 printk(ASUS_WARNING "Error switching LCD\n");
378 }
379
Corentin Chary935ffee2007-03-11 10:26:12 +0100380 write_status(NULL, lcd, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100381 return 0;
382}
383
384static void lcd_blank(int blank)
385{
386 struct backlight_device *bd = asus_backlight_device;
387
Len Brown8def05f2007-01-30 01:46:43 -0500388 if (bd) {
Richard Purdie599a52d2007-02-10 23:07:48 +0000389 bd->props.power = blank;
Richard Purdie28ee0862007-02-08 22:25:09 +0000390 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100391 }
392}
393
394static int read_brightness(struct backlight_device *bd)
395{
Corentin Chary9a816852007-03-11 10:25:38 +0100396 ulong value;
397 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100398
Corentin Chary9a816852007-03-11 10:25:38 +0100399 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
400 if (ACPI_FAILURE(rv))
Corentin Chary6b7091e2007-01-26 14:04:45 +0100401 printk(ASUS_WARNING "Error reading brightness\n");
402
403 return value;
404}
405
406static int set_brightness(struct backlight_device *bd, int value)
407{
408 int ret = 0;
409
410 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
411 /* 0 <= value <= 15 */
412
413 if (!write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
414 printk(ASUS_WARNING "Error changing brightness\n");
415 ret = -EIO;
416 }
417
418 return ret;
419}
420
421static int update_bl_status(struct backlight_device *bd)
422{
423 int rv;
Richard Purdie599a52d2007-02-10 23:07:48 +0000424 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100425
426 rv = set_brightness(bd, value);
Len Brown8def05f2007-01-30 01:46:43 -0500427 if (rv)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100428 return rv;
429
Richard Purdie599a52d2007-02-10 23:07:48 +0000430 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100431 return set_lcd_state(value);
432}
433
Corentin Chary85091b72007-01-26 14:04:30 +0100434/*
435 * Platform device handlers
436 */
437
438/*
439 * We write our info in page, we begin at offset off and cannot write more
440 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
441 * number of bytes written in page
442 */
443static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500444 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100445{
446 int len = 0;
Corentin Chary9a816852007-03-11 10:25:38 +0100447 ulong temp;
Corentin Chary85091b72007-01-26 14:04:30 +0100448 char buf[16]; //enough for all info
Corentin Chary9a816852007-03-11 10:25:38 +0100449 acpi_status rv = AE_OK;
450
Corentin Chary85091b72007-01-26 14:04:30 +0100451 /*
452 * We use the easy way, we don't care of off and count, so we don't set eof
453 * to 1
454 */
455
456 len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
457 len += sprintf(page + len, "Model reference : %s\n", hotk->name);
458 /*
459 * The SFUN method probably allows the original driver to get the list
460 * of features supported by a given model. For now, 0x0100 or 0x0800
461 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
462 * The significance of others is yet to be found.
463 */
Corentin Chary9a816852007-03-11 10:25:38 +0100464 rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
465 if (!ACPI_FAILURE(rv))
466 len += sprintf(page + len, "SFUN value : 0x%04x\n",
467 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100468 /*
469 * Another value for userspace: the ASYM method returns 0x02 for
470 * battery low and 0x04 for battery critical, its readings tend to be
471 * more accurate than those provided by _BST.
472 * Note: since not all the laptops provide this method, errors are
473 * silently ignored.
474 */
Corentin Chary9a816852007-03-11 10:25:38 +0100475 rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
476 if (!ACPI_FAILURE(rv))
477 len += sprintf(page + len, "ASYM value : 0x%04x\n",
478 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100479 if (asus_info) {
480 snprintf(buf, 16, "%d", asus_info->length);
481 len += sprintf(page + len, "DSDT length : %s\n", buf);
482 snprintf(buf, 16, "%d", asus_info->checksum);
483 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
484 snprintf(buf, 16, "%d", asus_info->revision);
485 len += sprintf(page + len, "DSDT revision : %s\n", buf);
486 snprintf(buf, 7, "%s", asus_info->oem_id);
487 len += sprintf(page + len, "OEM id : %s\n", buf);
488 snprintf(buf, 9, "%s", asus_info->oem_table_id);
489 len += sprintf(page + len, "OEM table id : %s\n", buf);
490 snprintf(buf, 16, "%x", asus_info->oem_revision);
491 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
492 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
493 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
494 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
495 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
496 }
497
498 return len;
499}
500
501static int parse_arg(const char *buf, unsigned long count, int *val)
502{
503 if (!count)
504 return 0;
505 if (count > 31)
506 return -EINVAL;
507 if (sscanf(buf, "%i", val) != 1)
508 return -EINVAL;
509 return count;
510}
511
Corentin Chary4564de12007-01-26 14:04:40 +0100512static ssize_t store_status(const char *buf, size_t count,
Corentin Chary935ffee2007-03-11 10:26:12 +0100513 acpi_handle handle, int mask)
Corentin Chary4564de12007-01-26 14:04:40 +0100514{
515 int rv, value;
516 int out = 0;
517
518 rv = parse_arg(buf, count, &value);
519 if (rv > 0)
520 out = value ? 1 : 0;
521
Corentin Chary935ffee2007-03-11 10:26:12 +0100522 write_status(handle, out, mask);
Corentin Chary4564de12007-01-26 14:04:40 +0100523
524 return rv;
525}
526
527/*
Corentin Chary722ad972007-01-26 14:04:55 +0100528 * LEDD display
529 */
530static ssize_t show_ledd(struct device *dev,
531 struct device_attribute *attr, char *buf)
532{
533 return sprintf(buf, "0x%08x\n", hotk->ledd_status);
534}
535
536static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
537 const char *buf, size_t count)
538{
539 int rv, value;
540
541 rv = parse_arg(buf, count, &value);
542 if (rv > 0) {
543 if (!write_acpi_int(ledd_set_handle, NULL, value, NULL))
544 printk(ASUS_WARNING "LED display write failed\n");
545 else
546 hotk->ledd_status = (u32) value;
547 }
548 return rv;
549}
550
551/*
Corentin Chary4564de12007-01-26 14:04:40 +0100552 * WLAN
553 */
554static ssize_t show_wlan(struct device *dev,
555 struct device_attribute *attr, char *buf)
556{
557 return sprintf(buf, "%d\n", read_status(WL_ON));
558}
559
560static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
561 const char *buf, size_t count)
562{
Corentin Chary935ffee2007-03-11 10:26:12 +0100563 return store_status(buf, count, wl_switch_handle, WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100564}
565
566/*
567 * Bluetooth
568 */
569static ssize_t show_bluetooth(struct device *dev,
570 struct device_attribute *attr, char *buf)
571{
572 return sprintf(buf, "%d\n", read_status(BT_ON));
573}
574
Len Brown8def05f2007-01-30 01:46:43 -0500575static ssize_t store_bluetooth(struct device *dev,
576 struct device_attribute *attr, const char *buf,
577 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100578{
Corentin Chary935ffee2007-03-11 10:26:12 +0100579 return store_status(buf, count, bt_switch_handle, BT_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100580}
581
Corentin Chary78127b42007-01-26 14:04:49 +0100582/*
583 * Display
584 */
585static void set_display(int value)
586{
587 /* no sanity check needed for now */
588 if (!write_acpi_int(display_set_handle, NULL, value, NULL))
589 printk(ASUS_WARNING "Error setting display\n");
590 return;
591}
592
593static int read_display(void)
594{
Corentin Chary9a816852007-03-11 10:25:38 +0100595 ulong value = 0;
596 acpi_status rv = AE_OK;
Corentin Chary78127b42007-01-26 14:04:49 +0100597
598 /* In most of the case, we know how to set the display, but sometime
599 we can't read it */
Len Brown8def05f2007-01-30 01:46:43 -0500600 if (display_get_handle) {
Corentin Chary9a816852007-03-11 10:25:38 +0100601 rv = acpi_evaluate_integer(display_get_handle, NULL,
602 NULL, &value);
603 if (ACPI_FAILURE(rv))
Corentin Chary78127b42007-01-26 14:04:49 +0100604 printk(ASUS_WARNING "Error reading display status\n");
605 }
606
607 value &= 0x0F; /* needed for some models, shouldn't hurt others */
608
609 return value;
610}
Len Brown8def05f2007-01-30 01:46:43 -0500611
Corentin Chary78127b42007-01-26 14:04:49 +0100612/*
613 * Now, *this* one could be more user-friendly, but so far, no-one has
614 * complained. The significance of bits is the same as in store_disp()
615 */
616static ssize_t show_disp(struct device *dev,
617 struct device_attribute *attr, char *buf)
618{
619 return sprintf(buf, "%d\n", read_display());
620}
621
622/*
623 * Experimental support for display switching. As of now: 1 should activate
624 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
625 * Any combination (bitwise) of these will suffice. I never actually tested 4
626 * displays hooked up simultaneously, so be warned. See the acpi4asus README
627 * for more info.
628 */
629static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
630 const char *buf, size_t count)
631{
632 int rv, value;
633
634 rv = parse_arg(buf, count, &value);
635 if (rv > 0)
636 set_display(value);
637 return rv;
638}
639
Corentin Chary8b857352007-01-26 14:04:58 +0100640/*
641 * Light Sens
642 */
643static void set_light_sens_switch(int value)
644{
645 if (!write_acpi_int(ls_switch_handle, NULL, value, NULL))
646 printk(ASUS_WARNING "Error setting light sensor switch\n");
647 hotk->light_switch = value;
648}
649
650static ssize_t show_lssw(struct device *dev,
651 struct device_attribute *attr, char *buf)
652{
653 return sprintf(buf, "%d\n", hotk->light_switch);
654}
655
656static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
657 const char *buf, size_t count)
658{
659 int rv, value;
660
661 rv = parse_arg(buf, count, &value);
662 if (rv > 0)
663 set_light_sens_switch(value ? 1 : 0);
664
665 return rv;
666}
667
668static void set_light_sens_level(int value)
669{
670 if (!write_acpi_int(ls_level_handle, NULL, value, NULL))
671 printk(ASUS_WARNING "Error setting light sensor level\n");
672 hotk->light_level = value;
673}
674
675static ssize_t show_lslvl(struct device *dev,
676 struct device_attribute *attr, char *buf)
677{
678 return sprintf(buf, "%d\n", hotk->light_level);
679}
680
681static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
682 const char *buf, size_t count)
683{
684 int rv, value;
685
686 rv = parse_arg(buf, count, &value);
687 if (rv > 0) {
688 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
689 /* 0 <= value <= 15 */
690 set_light_sens_level(value);
691 }
692
693 return rv;
694}
695
Corentin Charye539c2f2007-05-06 14:47:06 +0200696/*
697 * GPS
698 */
699static ssize_t show_gps(struct device *dev,
700 struct device_attribute *attr, char *buf)
701{
702 return sprintf(buf, "%d\n", read_status(GPS_ON));
703}
704
705static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
706 const char *buf, size_t count)
707{
708 return store_status(buf, count, NULL, GPS_ON);
709}
710
Corentin Chary85091b72007-01-26 14:04:30 +0100711static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
712{
713 /* TODO Find a better way to handle events count. */
714 if (!hotk)
715 return;
716
Corentin Chary6b7091e2007-01-26 14:04:45 +0100717 /*
718 * We need to tell the backlight device when the backlight power is
719 * switched
720 */
721 if (event == ATKD_LCD_ON) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100722 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100723 lcd_blank(FB_BLANK_UNBLANK);
Len Brown8def05f2007-01-30 01:46:43 -0500724 } else if (event == ATKD_LCD_OFF) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100725 write_status(NULL, 0, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100726 lcd_blank(FB_BLANK_POWERDOWN);
727 }
728
Corentin Chary85091b72007-01-26 14:04:30 +0100729 acpi_bus_generate_event(hotk->device, event,
730 hotk->event_count[event % 128]++);
731
732 return;
733}
734
735#define ASUS_CREATE_DEVICE_ATTR(_name) \
736 struct device_attribute dev_attr_##_name = { \
737 .attr = { \
738 .name = __stringify(_name), \
739 .mode = 0, \
740 .owner = THIS_MODULE }, \
741 .show = NULL, \
742 .store = NULL, \
743 }
744
745#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
746 do { \
747 dev_attr_##_name.attr.mode = _mode; \
748 dev_attr_##_name.show = _show; \
749 dev_attr_##_name.store = _store; \
750 } while(0)
751
752static ASUS_CREATE_DEVICE_ATTR(infos);
Corentin Chary4564de12007-01-26 14:04:40 +0100753static ASUS_CREATE_DEVICE_ATTR(wlan);
754static ASUS_CREATE_DEVICE_ATTR(bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100755static ASUS_CREATE_DEVICE_ATTR(display);
Corentin Chary722ad972007-01-26 14:04:55 +0100756static ASUS_CREATE_DEVICE_ATTR(ledd);
Corentin Chary8b857352007-01-26 14:04:58 +0100757static ASUS_CREATE_DEVICE_ATTR(ls_switch);
758static ASUS_CREATE_DEVICE_ATTR(ls_level);
Corentin Charye539c2f2007-05-06 14:47:06 +0200759static ASUS_CREATE_DEVICE_ATTR(gps);
Corentin Chary85091b72007-01-26 14:04:30 +0100760
761static struct attribute *asuspf_attributes[] = {
Len Brown8def05f2007-01-30 01:46:43 -0500762 &dev_attr_infos.attr,
763 &dev_attr_wlan.attr,
764 &dev_attr_bluetooth.attr,
765 &dev_attr_display.attr,
766 &dev_attr_ledd.attr,
767 &dev_attr_ls_switch.attr,
768 &dev_attr_ls_level.attr,
Corentin Charye539c2f2007-05-06 14:47:06 +0200769 &dev_attr_gps.attr,
Len Brown8def05f2007-01-30 01:46:43 -0500770 NULL
Corentin Chary85091b72007-01-26 14:04:30 +0100771};
772
773static struct attribute_group asuspf_attribute_group = {
Len Brown8def05f2007-01-30 01:46:43 -0500774 .attrs = asuspf_attributes
Corentin Chary85091b72007-01-26 14:04:30 +0100775};
776
777static struct platform_driver asuspf_driver = {
Len Brown8def05f2007-01-30 01:46:43 -0500778 .driver = {
779 .name = ASUS_HOTK_FILE,
780 .owner = THIS_MODULE,
781 }
Corentin Chary85091b72007-01-26 14:04:30 +0100782};
783
784static struct platform_device *asuspf_device;
785
Corentin Chary85091b72007-01-26 14:04:30 +0100786static void asus_hotk_add_fs(void)
787{
788 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
Corentin Chary4564de12007-01-26 14:04:40 +0100789
790 if (wl_switch_handle)
791 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
792
793 if (bt_switch_handle)
794 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
795 show_bluetooth, store_bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100796
797 if (display_set_handle && display_get_handle)
798 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
Len Brown8def05f2007-01-30 01:46:43 -0500799 else if (display_set_handle)
Corentin Chary78127b42007-01-26 14:04:49 +0100800 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
801
Corentin Chary722ad972007-01-26 14:04:55 +0100802 if (ledd_set_handle)
803 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
804
Corentin Chary8b857352007-01-26 14:04:58 +0100805 if (ls_switch_handle && ls_level_handle) {
806 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
807 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
808 }
Corentin Charye539c2f2007-05-06 14:47:06 +0200809
810 if(gps_status_handle && gps_on_handle && gps_off_handle)
811 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
Corentin Chary85091b72007-01-26 14:04:30 +0100812}
813
Len Brown8def05f2007-01-30 01:46:43 -0500814static int asus_handle_init(char *name, acpi_handle * handle,
Corentin Chary85091b72007-01-26 14:04:30 +0100815 char **paths, int num_paths)
816{
817 int i;
818 acpi_status status;
819
820 for (i = 0; i < num_paths; i++) {
821 status = acpi_get_handle(NULL, paths[i], handle);
822 if (ACPI_SUCCESS(status))
823 return 0;
824 }
825
826 *handle = NULL;
827 return -ENODEV;
828}
829
830#define ASUS_HANDLE_INIT(object) \
831 asus_handle_init(#object, &object##_handle, object##_paths, \
832 ARRAY_SIZE(object##_paths))
833
Corentin Chary85091b72007-01-26 14:04:30 +0100834/*
835 * This function is used to initialize the hotk with right values. In this
836 * method, we can make all the detection we want, and modify the hotk struct
837 */
838static int asus_hotk_get_info(void)
839{
840 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +0100841 union acpi_object *model = NULL;
Corentin Chary9a816852007-03-11 10:25:38 +0100842 ulong bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +0100843 char *string = NULL;
844 acpi_status status;
845
846 /*
847 * Get DSDT headers early enough to allow for differentiating between
848 * models, but late enough to allow acpi_bus_register_driver() to fail
849 * before doing anything ACPI-specific. Should we encounter a machine,
850 * which needs special handling (i.e. its hotkey device has a different
851 * HID), this bit will be moved. A global variable asus_info contains
852 * the DSDT header.
853 */
Len Brown894d79b2007-02-03 02:13:53 -0500854 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
Corentin Chary85091b72007-01-26 14:04:30 +0100855 if (ACPI_FAILURE(status))
856 printk(ASUS_WARNING "Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +0100857
858 /* We have to write 0 on init this far for all ASUS models */
859 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
860 printk(ASUS_ERR "Hotkey initialization failed\n");
861 return -ENODEV;
862 }
863
864 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +0100865 status =
866 acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
867 if (ACPI_FAILURE(status))
Corentin Chary85091b72007-01-26 14:04:30 +0100868 printk(ASUS_WARNING "Error calling BSTS\n");
869 else if (bsts_result)
870 printk(ASUS_NOTICE "BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100871 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +0100872
Corentin Chary185e5af2007-03-11 10:27:33 +0100873 /* This too ... */
874 write_acpi_int(hotk->handle, "CWAP", wapf, NULL);
875
Corentin Chary85091b72007-01-26 14:04:30 +0100876 /*
877 * Try to match the object returned by INIT to the specific model.
878 * Handle every possible object (or the lack of thereof) the DSDT
879 * writers might throw at us. When in trouble, we pass NULL to
880 * asus_model_match() and try something completely different.
881 */
882 if (buffer.pointer) {
883 model = buffer.pointer;
884 switch (model->type) {
885 case ACPI_TYPE_STRING:
886 string = model->string.pointer;
887 break;
888 case ACPI_TYPE_BUFFER:
889 string = model->buffer.pointer;
890 break;
891 default:
892 string = "";
893 break;
894 }
895 }
896 hotk->name = kstrdup(string, GFP_KERNEL);
897 if (!hotk->name)
898 return -ENOMEM;
899
Len Brown8def05f2007-01-30 01:46:43 -0500900 if (*string)
Corentin Chary85091b72007-01-26 14:04:30 +0100901 printk(ASUS_NOTICE " %s model detected\n", string);
902
Corentin Charybe18cda2007-01-26 14:04:35 +0100903 ASUS_HANDLE_INIT(mled_set);
904 ASUS_HANDLE_INIT(tled_set);
905 ASUS_HANDLE_INIT(rled_set);
906 ASUS_HANDLE_INIT(pled_set);
Corentin Charyfdd8d082007-03-11 10:26:48 +0100907 ASUS_HANDLE_INIT(gled_set);
Corentin Charybe18cda2007-01-26 14:04:35 +0100908
Corentin Chary722ad972007-01-26 14:04:55 +0100909 ASUS_HANDLE_INIT(ledd_set);
910
Corentin Chary4564de12007-01-26 14:04:40 +0100911 /*
912 * The HWRS method return informations about the hardware.
913 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
914 * The significance of others is yet to be found.
915 * If we don't find the method, we assume the device are present.
916 */
Corentin Chary9a816852007-03-11 10:25:38 +0100917 status =
918 acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result);
919 if (ACPI_FAILURE(status))
Corentin Chary4564de12007-01-26 14:04:40 +0100920 hwrs_result = WL_HWRS | BT_HWRS;
921
Len Brown8def05f2007-01-30 01:46:43 -0500922 if (hwrs_result & WL_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +0100923 ASUS_HANDLE_INIT(wl_switch);
Len Brown8def05f2007-01-30 01:46:43 -0500924 if (hwrs_result & BT_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +0100925 ASUS_HANDLE_INIT(bt_switch);
926
927 ASUS_HANDLE_INIT(wireless_status);
928
Corentin Chary6b7091e2007-01-26 14:04:45 +0100929 ASUS_HANDLE_INIT(brightness_set);
930 ASUS_HANDLE_INIT(brightness_get);
931
932 ASUS_HANDLE_INIT(lcd_switch);
933
Corentin Chary78127b42007-01-26 14:04:49 +0100934 ASUS_HANDLE_INIT(display_set);
935 ASUS_HANDLE_INIT(display_get);
936
Corentin Chary8b857352007-01-26 14:04:58 +0100937 /* There is a lot of models with "ALSL", but a few get
938 a real light sens, so we need to check it. */
Corentin Chary832d9952007-05-06 14:47:29 +0200939 if (!ASUS_HANDLE_INIT(ls_switch))
Corentin Chary8b857352007-01-26 14:04:58 +0100940 ASUS_HANDLE_INIT(ls_level);
941
Corentin Charye539c2f2007-05-06 14:47:06 +0200942 ASUS_HANDLE_INIT(gps_on);
943 ASUS_HANDLE_INIT(gps_off);
944 ASUS_HANDLE_INIT(gps_status);
945
Corentin Chary85091b72007-01-26 14:04:30 +0100946 kfree(model);
947
948 return AE_OK;
949}
950
951static int asus_hotk_check(void)
952{
953 int result = 0;
954
955 result = acpi_bus_get_status(hotk->device);
956 if (result)
957 return result;
958
959 if (hotk->device->status.present) {
960 result = asus_hotk_get_info();
961 } else {
962 printk(ASUS_ERR "Hotkey device not present, aborting\n");
963 return -EINVAL;
964 }
965
966 return result;
967}
968
969static int asus_hotk_found;
970
971static int asus_hotk_add(struct acpi_device *device)
972{
973 acpi_status status = AE_OK;
974 int result;
975
976 if (!device)
977 return -EINVAL;
978
979 printk(ASUS_NOTICE "Asus Laptop Support version %s\n",
980 ASUS_LAPTOP_VERSION);
981
982 hotk = kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
983 if (!hotk)
984 return -ENOMEM;
985 memset(hotk, 0, sizeof(struct asus_hotk));
986
987 hotk->handle = device->handle;
988 strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
989 strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
990 acpi_driver_data(device) = hotk;
991 hotk->device = device;
992
993 result = asus_hotk_check();
994 if (result)
995 goto end;
996
997 asus_hotk_add_fs();
998
999 /*
1000 * We install the handler, it will receive the hotk in parameter, so, we
1001 * could add other data to the hotk struct
1002 */
Corentin Charya9dbcb32007-05-06 14:46:41 +02001003 status = acpi_install_notify_handler(hotk->handle, ACPI_ALL_NOTIFY,
Corentin Chary85091b72007-01-26 14:04:30 +01001004 asus_hotk_notify, hotk);
1005 if (ACPI_FAILURE(status))
1006 printk(ASUS_ERR "Error installing notify handler\n");
1007
1008 asus_hotk_found = 1;
1009
Corentin Chary6b7091e2007-01-26 14:04:45 +01001010 /* WLED and BLED are on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001011 write_status(bt_switch_handle, 1, BT_ON);
1012 write_status(wl_switch_handle, 1, WL_ON);
1013
1014 /* If the h/w switch is off, we need to check the real status */
1015 write_status(NULL, read_status(BT_ON), BT_ON);
1016 write_status(NULL, read_status(WL_ON), WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +01001017
Corentin Chary6b7091e2007-01-26 14:04:45 +01001018 /* LCD Backlight is on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +01001019 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001020
Corentin Chary722ad972007-01-26 14:04:55 +01001021 /* LED display is off by default */
1022 hotk->ledd_status = 0xFFF;
1023
Len Brown8def05f2007-01-30 01:46:43 -05001024 /* Set initial values of light sensor and level */
1025 hotk->light_switch = 1; /* Default to light sensor disabled */
1026 hotk->light_level = 0; /* level 5 for sensor sensitivity */
Corentin Chary8b857352007-01-26 14:04:58 +01001027
Len Brown8def05f2007-01-30 01:46:43 -05001028 if (ls_switch_handle)
1029 set_light_sens_switch(hotk->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +01001030
Len Brown8def05f2007-01-30 01:46:43 -05001031 if (ls_level_handle)
1032 set_light_sens_level(hotk->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +01001033
Corentin Charye539c2f2007-05-06 14:47:06 +02001034 /* GPS is on by default */
1035 write_status(NULL, 1, GPS_ON);
1036
Corentin Chary85091b72007-01-26 14:04:30 +01001037 end:
1038 if (result) {
1039 kfree(hotk->name);
1040 kfree(hotk);
1041 }
1042
1043 return result;
1044}
1045
1046static int asus_hotk_remove(struct acpi_device *device, int type)
1047{
1048 acpi_status status = 0;
1049
1050 if (!device || !acpi_driver_data(device))
1051 return -EINVAL;
1052
Corentin Charya9dbcb32007-05-06 14:46:41 +02001053 status = acpi_remove_notify_handler(hotk->handle, ACPI_ALL_NOTIFY,
Corentin Chary85091b72007-01-26 14:04:30 +01001054 asus_hotk_notify);
1055 if (ACPI_FAILURE(status))
1056 printk(ASUS_ERR "Error removing notify handler\n");
1057
1058 kfree(hotk->name);
1059 kfree(hotk);
1060
1061 return 0;
1062}
1063
Corentin Chary6b7091e2007-01-26 14:04:45 +01001064static void asus_backlight_exit(void)
1065{
Len Brown8def05f2007-01-30 01:46:43 -05001066 if (asus_backlight_device)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001067 backlight_device_unregister(asus_backlight_device);
1068}
1069
Corentin Charybe18cda2007-01-26 14:04:35 +01001070#define ASUS_LED_UNREGISTER(object) \
1071 if(object##_led.class_dev \
1072 && !IS_ERR(object##_led.class_dev)) \
1073 led_classdev_unregister(&object##_led)
1074
1075static void asus_led_exit(void)
1076{
1077 ASUS_LED_UNREGISTER(mled);
1078 ASUS_LED_UNREGISTER(tled);
1079 ASUS_LED_UNREGISTER(pled);
1080 ASUS_LED_UNREGISTER(rled);
Corentin Charyfdd8d082007-03-11 10:26:48 +01001081 ASUS_LED_UNREGISTER(gled);
Corentin Charybe18cda2007-01-26 14:04:35 +01001082
1083 destroy_workqueue(led_workqueue);
1084}
1085
Corentin Chary85091b72007-01-26 14:04:30 +01001086static void __exit asus_laptop_exit(void)
1087{
Corentin Chary6b7091e2007-01-26 14:04:45 +01001088 asus_backlight_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001089 asus_led_exit();
1090
Corentin Chary85091b72007-01-26 14:04:30 +01001091 acpi_bus_unregister_driver(&asus_hotk_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001092 sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
1093 platform_device_unregister(asuspf_device);
1094 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001095}
1096
Len Brown8def05f2007-01-30 01:46:43 -05001097static int asus_backlight_init(struct device *dev)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001098{
1099 struct backlight_device *bd;
1100
Len Brown8def05f2007-01-30 01:46:43 -05001101 if (brightness_set_handle && lcd_switch_handle) {
1102 bd = backlight_device_register(ASUS_HOTK_FILE, dev,
Richard Purdie599a52d2007-02-10 23:07:48 +00001103 NULL, &asusbl_ops);
Len Brown8def05f2007-01-30 01:46:43 -05001104 if (IS_ERR(bd)) {
Corentin Chary6b7091e2007-01-26 14:04:45 +01001105 printk(ASUS_ERR
1106 "Could not register asus backlight device\n");
1107 asus_backlight_device = NULL;
1108 return PTR_ERR(bd);
1109 }
1110
1111 asus_backlight_device = bd;
1112
Richard Purdie599a52d2007-02-10 23:07:48 +00001113 bd->props.max_brightness = 15;
1114 bd->props.brightness = read_brightness(NULL);
1115 bd->props.power = FB_BLANK_UNBLANK;
Richard Purdie28ee0862007-02-08 22:25:09 +00001116 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001117 }
1118 return 0;
1119}
1120
Corentin Charybe18cda2007-01-26 14:04:35 +01001121static int asus_led_register(acpi_handle handle,
Len Brown8def05f2007-01-30 01:46:43 -05001122 struct led_classdev *ldev, struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001123{
Len Brown8def05f2007-01-30 01:46:43 -05001124 if (!handle)
Corentin Charybe18cda2007-01-26 14:04:35 +01001125 return 0;
1126
1127 return led_classdev_register(dev, ldev);
1128}
Len Brown8def05f2007-01-30 01:46:43 -05001129
Corentin Charybe18cda2007-01-26 14:04:35 +01001130#define ASUS_LED_REGISTER(object, device) \
1131 asus_led_register(object##_set_handle, &object##_led, device)
1132
Len Brown8def05f2007-01-30 01:46:43 -05001133static int asus_led_init(struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001134{
1135 int rv;
1136
1137 rv = ASUS_LED_REGISTER(mled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001138 if (rv)
Corentin Charybe18cda2007-01-26 14:04:35 +01001139 return rv;
1140
1141 rv = ASUS_LED_REGISTER(tled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001142 if (rv)
Corentin Charybe18cda2007-01-26 14:04:35 +01001143 return rv;
1144
1145 rv = ASUS_LED_REGISTER(rled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001146 if (rv)
Corentin Charybe18cda2007-01-26 14:04:35 +01001147 return rv;
1148
1149 rv = ASUS_LED_REGISTER(pled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001150 if (rv)
Corentin Charybe18cda2007-01-26 14:04:35 +01001151 return rv;
1152
Corentin Charyfdd8d082007-03-11 10:26:48 +01001153 rv = ASUS_LED_REGISTER(gled, dev);
1154 if (rv)
1155 return rv;
1156
Corentin Charybe18cda2007-01-26 14:04:35 +01001157 led_workqueue = create_singlethread_workqueue("led_workqueue");
Len Brown8def05f2007-01-30 01:46:43 -05001158 if (!led_workqueue)
Corentin Charybe18cda2007-01-26 14:04:35 +01001159 return -ENOMEM;
1160
1161 return 0;
1162}
1163
Corentin Chary85091b72007-01-26 14:04:30 +01001164static int __init asus_laptop_init(void)
1165{
Corentin Charybe18cda2007-01-26 14:04:35 +01001166 struct device *dev;
Corentin Chary85091b72007-01-26 14:04:30 +01001167 int result;
1168
1169 if (acpi_disabled)
1170 return -ENODEV;
1171
Corentin Chary85091b72007-01-26 14:04:30 +01001172 result = acpi_bus_register_driver(&asus_hotk_driver);
1173 if (result < 0)
1174 return result;
1175
1176 /*
1177 * This is a bit of a kludge. We only want this module loaded
1178 * for ASUS systems, but there's currently no way to probe the
1179 * ACPI namespace for ASUS HIDs. So we just return failure if
1180 * we didn't find one, which will cause the module to be
1181 * unloaded.
1182 */
1183 if (!asus_hotk_found) {
1184 acpi_bus_unregister_driver(&asus_hotk_driver);
1185 return -ENODEV;
1186 }
1187
Corentin Charybe18cda2007-01-26 14:04:35 +01001188 dev = acpi_get_physical_device(hotk->device->handle);
1189
Corentin Chary6b7091e2007-01-26 14:04:45 +01001190 result = asus_backlight_init(dev);
Len Brown8def05f2007-01-30 01:46:43 -05001191 if (result)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001192 goto fail_backlight;
1193
Corentin Charybe18cda2007-01-26 14:04:35 +01001194 result = asus_led_init(dev);
Len Brown8def05f2007-01-30 01:46:43 -05001195 if (result)
Corentin Charybe18cda2007-01-26 14:04:35 +01001196 goto fail_led;
1197
Len Brown8def05f2007-01-30 01:46:43 -05001198 /* Register platform stuff */
Corentin Chary85091b72007-01-26 14:04:30 +01001199 result = platform_driver_register(&asuspf_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001200 if (result)
1201 goto fail_platform_driver;
Corentin Chary85091b72007-01-26 14:04:30 +01001202
Len Brown8def05f2007-01-30 01:46:43 -05001203 asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
1204 if (!asuspf_device) {
1205 result = -ENOMEM;
1206 goto fail_platform_device1;
1207 }
Corentin Chary85091b72007-01-26 14:04:30 +01001208
Len Brown8def05f2007-01-30 01:46:43 -05001209 result = platform_device_add(asuspf_device);
1210 if (result)
1211 goto fail_platform_device2;
Corentin Chary85091b72007-01-26 14:04:30 +01001212
Len Brown8def05f2007-01-30 01:46:43 -05001213 result = sysfs_create_group(&asuspf_device->dev.kobj,
Corentin Chary85091b72007-01-26 14:04:30 +01001214 &asuspf_attribute_group);
Len Brown8def05f2007-01-30 01:46:43 -05001215 if (result)
1216 goto fail_sysfs;
Corentin Chary85091b72007-01-26 14:04:30 +01001217
Len Brown8def05f2007-01-30 01:46:43 -05001218 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001219
Len Brown8def05f2007-01-30 01:46:43 -05001220 fail_sysfs:
1221 platform_device_del(asuspf_device);
Corentin Chary85091b72007-01-26 14:04:30 +01001222
Len Brown8def05f2007-01-30 01:46:43 -05001223 fail_platform_device2:
Corentin Chary85091b72007-01-26 14:04:30 +01001224 platform_device_put(asuspf_device);
1225
Len Brown8def05f2007-01-30 01:46:43 -05001226 fail_platform_device1:
1227 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001228
Len Brown8def05f2007-01-30 01:46:43 -05001229 fail_platform_driver:
Corentin Charybe18cda2007-01-26 14:04:35 +01001230 asus_led_exit();
1231
Len Brown8def05f2007-01-30 01:46:43 -05001232 fail_led:
Corentin Chary6b7091e2007-01-26 14:04:45 +01001233 asus_backlight_exit();
1234
Len Brown8def05f2007-01-30 01:46:43 -05001235 fail_backlight:
Corentin Chary85091b72007-01-26 14:04:30 +01001236
1237 return result;
1238}
1239
1240module_init(asus_laptop_init);
1241module_exit(asus_laptop_exit);