asus-laptop.c revision 5ad77dcfb49a85715bcb9174a133cba140eda1bc
1/*
2 *  asus-laptop.c - Asus Laptop Support
3 *
4 *
5 *  Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
6 *  Copyright (C) 2006-2007 Corentin Chary
7 *
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 helpful
33 *  Sam Lin        - GPS support
34 */
35
36#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
37
38#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>
44#include <linux/backlight.h>
45#include <linux/fb.h>
46#include <linux/leds.h>
47#include <linux/platform_device.h>
48#include <linux/uaccess.h>
49#include <linux/input.h>
50#include <linux/input/sparse-keymap.h>
51#include <linux/rfkill.h>
52#include <linux/slab.h>
53#include <linux/dmi.h>
54#include <acpi/acpi_drivers.h>
55#include <acpi/acpi_bus.h>
56
57#define ASUS_LAPTOP_VERSION	"0.42"
58
59#define ASUS_LAPTOP_NAME	"Asus Laptop Support"
60#define ASUS_LAPTOP_CLASS	"hotkey"
61#define ASUS_LAPTOP_DEVICE_NAME	"Hotkey"
62#define ASUS_LAPTOP_FILE	KBUILD_MODNAME
63#define ASUS_LAPTOP_PREFIX	"\\_SB.ATKD."
64
65MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
66MODULE_DESCRIPTION(ASUS_LAPTOP_NAME);
67MODULE_LICENSE("GPL");
68
69/*
70 * WAPF defines the behavior of the Fn+Fx wlan key
71 * The significance of values is yet to be found, but
72 * most of the time:
73 * 0x0 will do nothing
74 * 0x1 will allow to control the device with Fn+Fx key.
75 * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key
76 * 0x5 like 0x1 or 0x4
77 * So, if something doesn't work as you want, just try other values =)
78 */
79static uint wapf = 1;
80module_param(wapf, uint, 0444);
81MODULE_PARM_DESC(wapf, "WAPF value");
82
83static int wlan_status = 1;
84static int bluetooth_status = 1;
85static int wimax_status = -1;
86static int wwan_status = -1;
87
88module_param(wlan_status, int, 0444);
89MODULE_PARM_DESC(wlan_status, "Set the wireless status on boot "
90		 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
91		 "default is 1");
92
93module_param(bluetooth_status, int, 0444);
94MODULE_PARM_DESC(bluetooth_status, "Set the wireless status on boot "
95		 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
96		 "default is 1");
97
98module_param(wimax_status, int, 0444);
99MODULE_PARM_DESC(wimax_status, "Set the wireless status on boot "
100		 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
101		 "default is 1");
102
103module_param(wwan_status, int, 0444);
104MODULE_PARM_DESC(wwan_status, "Set the wireless status on boot "
105		 "(0 = disabled, 1 = enabled, -1 = don't do anything). "
106		 "default is 1");
107
108/*
109 * Some events we use, same for all Asus
110 */
111#define ATKD_BR_UP	0x10	/* (event & ~ATKD_BR_UP) = brightness level */
112#define ATKD_BR_DOWN	0x20	/* (event & ~ATKD_BR_DOWN) = britghness level */
113#define ATKD_BR_MIN	ATKD_BR_UP
114#define ATKD_BR_MAX	(ATKD_BR_DOWN | 0xF)	/* 0x2f */
115#define ATKD_LCD_ON	0x33
116#define ATKD_LCD_OFF	0x34
117
118/*
119 * Known bits returned by \_SB.ATKD.HWRS
120 */
121#define WL_HWRS		0x80
122#define BT_HWRS		0x100
123
124/*
125 * Flags for hotk status
126 * WL_ON and BT_ON are also used for wireless_status()
127 */
128#define WL_RSTS		0x01	/* internal Wifi */
129#define BT_RSTS		0x02	/* internal Bluetooth */
130#define WM_RSTS		0x08    /* internal wimax */
131#define WW_RSTS		0x20    /* internal wwan */
132
133/* LED */
134#define METHOD_MLED		"MLED"
135#define METHOD_TLED		"TLED"
136#define METHOD_RLED		"RLED"	/* W1JC */
137#define METHOD_PLED		"PLED"	/* A7J */
138#define METHOD_GLED		"GLED"	/* G1, G2 (probably) */
139
140/* LEDD */
141#define METHOD_LEDD		"SLCM"
142
143/*
144 * Bluetooth and WLAN
145 * WLED and BLED are not handled like other XLED, because in some dsdt
146 * they also control the WLAN/Bluetooth device.
147 */
148#define METHOD_WLAN		"WLED"
149#define METHOD_BLUETOOTH	"BLED"
150
151/* WWAN and WIMAX */
152#define METHOD_WWAN		"GSMC"
153#define METHOD_WIMAX		"WMXC"
154
155#define METHOD_WL_STATUS	"RSTS"
156
157/* Brightness */
158#define METHOD_BRIGHTNESS_SET	"SPLV"
159#define METHOD_BRIGHTNESS_GET	"GPLV"
160
161/* Display */
162#define METHOD_SWITCH_DISPLAY	"SDSP"
163
164#define METHOD_ALS_CONTROL	"ALSC" /* Z71A Z71V */
165#define METHOD_ALS_LEVEL	"ALSL" /* Z71A Z71V */
166
167/* GPS */
168/* R2H use different handle for GPS on/off */
169#define METHOD_GPS_ON		"SDON"
170#define METHOD_GPS_OFF		"SDOF"
171#define METHOD_GPS_STATUS	"GPST"
172
173/* Keyboard light */
174#define METHOD_KBD_LIGHT_SET	"SLKB"
175#define METHOD_KBD_LIGHT_GET	"GLKB"
176
177/*
178 * Define a specific led structure to keep the main structure clean
179 */
180struct asus_led {
181	int wk;
182	struct work_struct work;
183	struct led_classdev led;
184	struct asus_laptop *asus;
185	const char *method;
186};
187
188/*
189 * This is the main structure, we can use it to store anything interesting
190 * about the hotk device
191 */
192struct asus_laptop {
193	char *name;		/* laptop name */
194
195	struct acpi_table_header *dsdt_info;
196	struct platform_device *platform_device;
197	struct acpi_device *device;		/* the device we are in */
198	struct backlight_device *backlight_device;
199
200	struct input_dev *inputdev;
201	struct key_entry *keymap;
202
203	struct asus_led mled;
204	struct asus_led tled;
205	struct asus_led rled;
206	struct asus_led pled;
207	struct asus_led gled;
208	struct asus_led kled;
209	struct workqueue_struct *led_workqueue;
210
211	int wireless_status;
212	bool have_rsts;
213
214	struct rfkill *gps_rfkill;
215
216	acpi_handle handle;	/* the handle of the hotk device */
217	u32 ledd_status;	/* status of the LED display */
218	u8 light_level;		/* light sensor level */
219	u8 light_switch;	/* light sensor switch value */
220	u16 event_count[128];	/* count for each event TODO make this better */
221};
222
223static const struct key_entry asus_keymap[] = {
224	/* Lenovo SL Specific keycodes */
225	{KE_KEY, 0x02, { KEY_SCREENLOCK } },
226	{KE_KEY, 0x05, { KEY_WLAN } },
227	{KE_KEY, 0x08, { KEY_F13 } },
228	{KE_KEY, 0x17, { KEY_ZOOM } },
229	{KE_KEY, 0x1f, { KEY_BATTERY } },
230	/* End of Lenovo SL Specific keycodes */
231	{KE_KEY, 0x30, { KEY_VOLUMEUP } },
232	{KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
233	{KE_KEY, 0x32, { KEY_MUTE } },
234	{KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } },
235	{KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } },
236	{KE_KEY, 0x40, { KEY_PREVIOUSSONG } },
237	{KE_KEY, 0x41, { KEY_NEXTSONG } },
238	{KE_KEY, 0x43, { KEY_STOPCD } },
239	{KE_KEY, 0x45, { KEY_PLAYPAUSE } },
240	{KE_KEY, 0x4c, { KEY_MEDIA } },
241	{KE_KEY, 0x50, { KEY_EMAIL } },
242	{KE_KEY, 0x51, { KEY_WWW } },
243	{KE_KEY, 0x55, { KEY_CALC } },
244	{KE_KEY, 0x5C, { KEY_SCREENLOCK } },  /* Screenlock */
245	{KE_KEY, 0x5D, { KEY_WLAN } },
246	{KE_KEY, 0x5E, { KEY_WLAN } },
247	{KE_KEY, 0x5F, { KEY_WLAN } },
248	{KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } },
249	{KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } },
250	{KE_KEY, 0x62, { KEY_SWITCHVIDEOMODE } },
251	{KE_KEY, 0x63, { KEY_SWITCHVIDEOMODE } },
252	{KE_KEY, 0x6B, { KEY_F13 } }, /* Lock Touchpad */
253	{KE_KEY, 0x7E, { KEY_BLUETOOTH } },
254	{KE_KEY, 0x7D, { KEY_BLUETOOTH } },
255	{KE_KEY, 0x82, { KEY_CAMERA } },
256	{KE_KEY, 0x88, { KEY_WLAN  } },
257	{KE_KEY, 0x8A, { KEY_PROG1 } },
258	{KE_KEY, 0x95, { KEY_MEDIA } },
259	{KE_KEY, 0x99, { KEY_PHONE } },
260	{KE_KEY, 0xc4, { KEY_KBDILLUMUP } },
261	{KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } },
262	{KE_KEY, 0xb5, { KEY_CALC } },
263	{KE_END, 0},
264};
265
266
267/*
268 * This function evaluates an ACPI method, given an int as parameter, the
269 * method is searched within the scope of the handle, can be NULL. The output
270 * of the method is written is output, which can also be NULL
271 *
272 * returns 0 if write is successful, -1 else.
273 */
274static int write_acpi_int_ret(acpi_handle handle, const char *method, int val,
275			      struct acpi_buffer *output)
276{
277	struct acpi_object_list params;	/* list of input parameters (an int) */
278	union acpi_object in_obj;	/* the only param we use */
279	acpi_status status;
280
281	if (!handle)
282		return -1;
283
284	params.count = 1;
285	params.pointer = &in_obj;
286	in_obj.type = ACPI_TYPE_INTEGER;
287	in_obj.integer.value = val;
288
289	status = acpi_evaluate_object(handle, (char *)method, &params, output);
290	if (status == AE_OK)
291		return 0;
292	else
293		return -1;
294}
295
296static int write_acpi_int(acpi_handle handle, const char *method, int val)
297{
298	return write_acpi_int_ret(handle, method, val, NULL);
299}
300
301static int acpi_check_handle(acpi_handle handle, const char *method,
302			     acpi_handle *ret)
303{
304	acpi_status status;
305
306	if (method == NULL)
307		return -ENODEV;
308
309	if (ret)
310		status = acpi_get_handle(handle, (char *)method,
311					 ret);
312	else {
313		acpi_handle dummy;
314
315		status = acpi_get_handle(handle, (char *)method,
316					 &dummy);
317	}
318
319	if (status != AE_OK) {
320		if (ret)
321			pr_warn("Error finding %s\n", method);
322		return -ENODEV;
323	}
324	return 0;
325}
326
327/* Generic LED function */
328static int asus_led_set(struct asus_laptop *asus, const char *method,
329			 int value)
330{
331	if (!strcmp(method, METHOD_MLED))
332		value = !value;
333	else if (!strcmp(method, METHOD_GLED))
334		value = !value + 1;
335	else
336		value = !!value;
337
338	return write_acpi_int(asus->handle, method, value);
339}
340
341/*
342 * LEDs
343 */
344/* /sys/class/led handlers */
345static void asus_led_cdev_set(struct led_classdev *led_cdev,
346			 enum led_brightness value)
347{
348	struct asus_led *led = container_of(led_cdev, struct asus_led, led);
349	struct asus_laptop *asus = led->asus;
350
351	led->wk = !!value;
352	queue_work(asus->led_workqueue, &led->work);
353}
354
355static void asus_led_cdev_update(struct work_struct *work)
356{
357	struct asus_led *led = container_of(work, struct asus_led, work);
358	struct asus_laptop *asus = led->asus;
359
360	asus_led_set(asus, led->method, led->wk);
361}
362
363static enum led_brightness asus_led_cdev_get(struct led_classdev *led_cdev)
364{
365	return led_cdev->brightness;
366}
367
368/*
369 * Keyboard backlight (also a LED)
370 */
371static int asus_kled_lvl(struct asus_laptop *asus)
372{
373	unsigned long long kblv;
374	struct acpi_object_list params;
375	union acpi_object in_obj;
376	acpi_status rv;
377
378	params.count = 1;
379	params.pointer = &in_obj;
380	in_obj.type = ACPI_TYPE_INTEGER;
381	in_obj.integer.value = 2;
382
383	rv = acpi_evaluate_integer(asus->handle, METHOD_KBD_LIGHT_GET,
384				   &params, &kblv);
385	if (ACPI_FAILURE(rv)) {
386		pr_warn("Error reading kled level\n");
387		return -ENODEV;
388	}
389	return kblv;
390}
391
392static int asus_kled_set(struct asus_laptop *asus, int kblv)
393{
394	if (kblv > 0)
395		kblv = (1 << 7) | (kblv & 0x7F);
396	else
397		kblv = 0;
398
399	if (write_acpi_int(asus->handle, METHOD_KBD_LIGHT_SET, kblv)) {
400		pr_warn("Keyboard LED display write failed\n");
401		return -EINVAL;
402	}
403	return 0;
404}
405
406static void asus_kled_cdev_set(struct led_classdev *led_cdev,
407			      enum led_brightness value)
408{
409	struct asus_led *led = container_of(led_cdev, struct asus_led, led);
410	struct asus_laptop *asus = led->asus;
411
412	led->wk = value;
413	queue_work(asus->led_workqueue, &led->work);
414}
415
416static void asus_kled_cdev_update(struct work_struct *work)
417{
418	struct asus_led *led = container_of(work, struct asus_led, work);
419	struct asus_laptop *asus = led->asus;
420
421	asus_kled_set(asus, led->wk);
422}
423
424static enum led_brightness asus_kled_cdev_get(struct led_classdev *led_cdev)
425{
426	struct asus_led *led = container_of(led_cdev, struct asus_led, led);
427	struct asus_laptop *asus = led->asus;
428
429	return asus_kled_lvl(asus);
430}
431
432static void asus_led_exit(struct asus_laptop *asus)
433{
434	if (asus->mled.led.dev)
435		led_classdev_unregister(&asus->mled.led);
436	if (asus->tled.led.dev)
437		led_classdev_unregister(&asus->tled.led);
438	if (asus->pled.led.dev)
439		led_classdev_unregister(&asus->pled.led);
440	if (asus->rled.led.dev)
441		led_classdev_unregister(&asus->rled.led);
442	if (asus->gled.led.dev)
443		led_classdev_unregister(&asus->gled.led);
444	if (asus->kled.led.dev)
445		led_classdev_unregister(&asus->kled.led);
446	if (asus->led_workqueue) {
447		destroy_workqueue(asus->led_workqueue);
448		asus->led_workqueue = NULL;
449	}
450}
451
452/*  Ugly macro, need to fix that later */
453static int asus_led_register(struct asus_laptop *asus,
454			     struct asus_led *led,
455			     const char *name, const char *method)
456{
457	struct led_classdev *led_cdev = &led->led;
458
459	if (!method || acpi_check_handle(asus->handle, method, NULL))
460		return 0; /* Led not present */
461
462	led->asus = asus;
463	led->method = method;
464
465	INIT_WORK(&led->work, asus_led_cdev_update);
466	led_cdev->name = name;
467	led_cdev->brightness_set = asus_led_cdev_set;
468	led_cdev->brightness_get = asus_led_cdev_get;
469	led_cdev->max_brightness = 1;
470	return led_classdev_register(&asus->platform_device->dev, led_cdev);
471}
472
473static int asus_led_init(struct asus_laptop *asus)
474{
475	int r;
476
477	/*
478	 * Functions that actually update the LED's are called from a
479	 * workqueue. By doing this as separate work rather than when the LED
480	 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
481	 * potentially bad time, such as a timer interrupt.
482	 */
483	asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
484	if (!asus->led_workqueue)
485		return -ENOMEM;
486
487	r = asus_led_register(asus, &asus->mled, "asus::mail", METHOD_MLED);
488	if (r)
489		goto error;
490	r = asus_led_register(asus, &asus->tled, "asus::touchpad", METHOD_TLED);
491	if (r)
492		goto error;
493	r = asus_led_register(asus, &asus->rled, "asus::record", METHOD_RLED);
494	if (r)
495		goto error;
496	r = asus_led_register(asus, &asus->pled, "asus::phone", METHOD_PLED);
497	if (r)
498		goto error;
499	r = asus_led_register(asus, &asus->gled, "asus::gaming", METHOD_GLED);
500	if (r)
501		goto error;
502	if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL) &&
503	    !acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_GET, NULL)) {
504		struct asus_led *led = &asus->kled;
505		struct led_classdev *cdev = &led->led;
506
507		led->asus = asus;
508
509		INIT_WORK(&led->work, asus_kled_cdev_update);
510		cdev->name = "asus::kbd_backlight";
511		cdev->brightness_set = asus_kled_cdev_set;
512		cdev->brightness_get = asus_kled_cdev_get;
513		cdev->max_brightness = 3;
514		r = led_classdev_register(&asus->platform_device->dev, cdev);
515	}
516error:
517	if (r)
518		asus_led_exit(asus);
519	return r;
520}
521
522/*
523 * Backlight device
524 */
525static int asus_read_brightness(struct backlight_device *bd)
526{
527	struct asus_laptop *asus = bl_get_data(bd);
528	unsigned long long value;
529	acpi_status rv = AE_OK;
530
531	rv = acpi_evaluate_integer(asus->handle, METHOD_BRIGHTNESS_GET,
532				   NULL, &value);
533	if (ACPI_FAILURE(rv))
534		pr_warn("Error reading brightness\n");
535
536	return value;
537}
538
539static int asus_set_brightness(struct backlight_device *bd, int value)
540{
541	struct asus_laptop *asus = bl_get_data(bd);
542
543	if (write_acpi_int(asus->handle, METHOD_BRIGHTNESS_SET, value)) {
544		pr_warn("Error changing brightness\n");
545		return -EIO;
546	}
547	return 0;
548}
549
550static int update_bl_status(struct backlight_device *bd)
551{
552	int value = bd->props.brightness;
553
554	return asus_set_brightness(bd, value);
555}
556
557static const struct backlight_ops asusbl_ops = {
558	.get_brightness = asus_read_brightness,
559	.update_status = update_bl_status,
560};
561
562static int asus_backlight_notify(struct asus_laptop *asus)
563{
564	struct backlight_device *bd = asus->backlight_device;
565	int old = bd->props.brightness;
566
567	backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
568
569	return old;
570}
571
572static int asus_backlight_init(struct asus_laptop *asus)
573{
574	struct backlight_device *bd;
575	struct backlight_properties props;
576
577	if (acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_GET, NULL) ||
578	    acpi_check_handle(asus->handle, METHOD_BRIGHTNESS_SET, NULL))
579		return 0;
580
581	memset(&props, 0, sizeof(struct backlight_properties));
582	props.max_brightness = 15;
583	props.type = BACKLIGHT_PLATFORM;
584
585	bd = backlight_device_register(ASUS_LAPTOP_FILE,
586				       &asus->platform_device->dev, asus,
587				       &asusbl_ops, &props);
588	if (IS_ERR(bd)) {
589		pr_err("Could not register asus backlight device\n");
590		asus->backlight_device = NULL;
591		return PTR_ERR(bd);
592	}
593
594	asus->backlight_device = bd;
595	bd->props.brightness = asus_read_brightness(bd);
596	bd->props.power = FB_BLANK_UNBLANK;
597	backlight_update_status(bd);
598	return 0;
599}
600
601static void asus_backlight_exit(struct asus_laptop *asus)
602{
603	if (asus->backlight_device)
604		backlight_device_unregister(asus->backlight_device);
605	asus->backlight_device = NULL;
606}
607
608/*
609 * Platform device handlers
610 */
611
612/*
613 * We write our info in page, we begin at offset off and cannot write more
614 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
615 * number of bytes written in page
616 */
617static ssize_t show_infos(struct device *dev,
618			  struct device_attribute *attr, char *page)
619{
620	struct asus_laptop *asus = dev_get_drvdata(dev);
621	int len = 0;
622	unsigned long long temp;
623	char buf[16];		/* enough for all info */
624	acpi_status rv = AE_OK;
625
626	/*
627	 * We use the easy way, we don't care of off and count,
628	 * so we don't set eof to 1
629	 */
630
631	len += sprintf(page, ASUS_LAPTOP_NAME " " ASUS_LAPTOP_VERSION "\n");
632	len += sprintf(page + len, "Model reference    : %s\n", asus->name);
633	/*
634	 * The SFUN method probably allows the original driver to get the list
635	 * of features supported by a given model. For now, 0x0100 or 0x0800
636	 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
637	 * The significance of others is yet to be found.
638	 */
639	rv = acpi_evaluate_integer(asus->handle, "SFUN", NULL, &temp);
640	if (!ACPI_FAILURE(rv))
641		len += sprintf(page + len, "SFUN value         : %#x\n",
642			       (uint) temp);
643	/*
644	 * The HWRS method return informations about the hardware.
645	 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
646	 * The significance of others is yet to be found.
647	 * If we don't find the method, we assume the device are present.
648	 */
649	rv = acpi_evaluate_integer(asus->handle, "HRWS", NULL, &temp);
650	if (!ACPI_FAILURE(rv))
651		len += sprintf(page + len, "HRWS value         : %#x\n",
652			       (uint) temp);
653	/*
654	 * Another value for userspace: the ASYM method returns 0x02 for
655	 * battery low and 0x04 for battery critical, its readings tend to be
656	 * more accurate than those provided by _BST.
657	 * Note: since not all the laptops provide this method, errors are
658	 * silently ignored.
659	 */
660	rv = acpi_evaluate_integer(asus->handle, "ASYM", NULL, &temp);
661	if (!ACPI_FAILURE(rv))
662		len += sprintf(page + len, "ASYM value         : %#x\n",
663			       (uint) temp);
664	if (asus->dsdt_info) {
665		snprintf(buf, 16, "%d", asus->dsdt_info->length);
666		len += sprintf(page + len, "DSDT length        : %s\n", buf);
667		snprintf(buf, 16, "%d", asus->dsdt_info->checksum);
668		len += sprintf(page + len, "DSDT checksum      : %s\n", buf);
669		snprintf(buf, 16, "%d", asus->dsdt_info->revision);
670		len += sprintf(page + len, "DSDT revision      : %s\n", buf);
671		snprintf(buf, 7, "%s", asus->dsdt_info->oem_id);
672		len += sprintf(page + len, "OEM id             : %s\n", buf);
673		snprintf(buf, 9, "%s", asus->dsdt_info->oem_table_id);
674		len += sprintf(page + len, "OEM table id       : %s\n", buf);
675		snprintf(buf, 16, "%x", asus->dsdt_info->oem_revision);
676		len += sprintf(page + len, "OEM revision       : 0x%s\n", buf);
677		snprintf(buf, 5, "%s", asus->dsdt_info->asl_compiler_id);
678		len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
679		snprintf(buf, 16, "%x", asus->dsdt_info->asl_compiler_revision);
680		len += sprintf(page + len, "ASL comp revision  : 0x%s\n", buf);
681	}
682
683	return len;
684}
685
686static int parse_arg(const char *buf, unsigned long count, int *val)
687{
688	if (!count)
689		return 0;
690	if (count > 31)
691		return -EINVAL;
692	if (sscanf(buf, "%i", val) != 1)
693		return -EINVAL;
694	return count;
695}
696
697static ssize_t sysfs_acpi_set(struct asus_laptop *asus,
698			      const char *buf, size_t count,
699			      const char *method)
700{
701	int rv, value;
702	int out = 0;
703
704	rv = parse_arg(buf, count, &value);
705	if (rv > 0)
706		out = value ? 1 : 0;
707
708	if (write_acpi_int(asus->handle, method, value))
709		return -ENODEV;
710	return rv;
711}
712
713/*
714 * LEDD display
715 */
716static ssize_t show_ledd(struct device *dev,
717			 struct device_attribute *attr, char *buf)
718{
719	struct asus_laptop *asus = dev_get_drvdata(dev);
720
721	return sprintf(buf, "0x%08x\n", asus->ledd_status);
722}
723
724static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
725			  const char *buf, size_t count)
726{
727	struct asus_laptop *asus = dev_get_drvdata(dev);
728	int rv, value;
729
730	rv = parse_arg(buf, count, &value);
731	if (rv > 0) {
732		if (write_acpi_int(asus->handle, METHOD_LEDD, value)) {
733			pr_warn("LED display write failed\n");
734			return -ENODEV;
735		}
736		asus->ledd_status = (u32) value;
737	}
738	return rv;
739}
740
741/*
742 * Wireless
743 */
744static int asus_wireless_status(struct asus_laptop *asus, int mask)
745{
746	unsigned long long status;
747	acpi_status rv = AE_OK;
748
749	if (!asus->have_rsts)
750		return (asus->wireless_status & mask) ? 1 : 0;
751
752	rv = acpi_evaluate_integer(asus->handle, METHOD_WL_STATUS,
753				   NULL, &status);
754	if (ACPI_FAILURE(rv)) {
755		pr_warn("Error reading Wireless status\n");
756		return -EINVAL;
757	}
758	return !!(status & mask);
759}
760
761/*
762 * WLAN
763 */
764static int asus_wlan_set(struct asus_laptop *asus, int status)
765{
766	if (write_acpi_int(asus->handle, METHOD_WLAN, !!status)) {
767		pr_warn("Error setting wlan status to %d\n", status);
768		return -EIO;
769	}
770	return 0;
771}
772
773static ssize_t show_wlan(struct device *dev,
774			 struct device_attribute *attr, char *buf)
775{
776	struct asus_laptop *asus = dev_get_drvdata(dev);
777
778	return sprintf(buf, "%d\n", asus_wireless_status(asus, WL_RSTS));
779}
780
781static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
782			  const char *buf, size_t count)
783{
784	struct asus_laptop *asus = dev_get_drvdata(dev);
785
786	return sysfs_acpi_set(asus, buf, count, METHOD_WLAN);
787}
788
789/*
790 * Bluetooth
791 */
792static int asus_bluetooth_set(struct asus_laptop *asus, int status)
793{
794	if (write_acpi_int(asus->handle, METHOD_BLUETOOTH, !!status)) {
795		pr_warn("Error setting bluetooth status to %d\n", status);
796		return -EIO;
797	}
798	return 0;
799}
800
801static ssize_t show_bluetooth(struct device *dev,
802			      struct device_attribute *attr, char *buf)
803{
804	struct asus_laptop *asus = dev_get_drvdata(dev);
805
806	return sprintf(buf, "%d\n", asus_wireless_status(asus, BT_RSTS));
807}
808
809static ssize_t store_bluetooth(struct device *dev,
810			       struct device_attribute *attr, const char *buf,
811			       size_t count)
812{
813	struct asus_laptop *asus = dev_get_drvdata(dev);
814
815	return sysfs_acpi_set(asus, buf, count, METHOD_BLUETOOTH);
816}
817
818/*
819 * Wimax
820 */
821static int asus_wimax_set(struct asus_laptop *asus, int status)
822{
823	if (write_acpi_int(asus->handle, METHOD_WIMAX, !!status)) {
824		pr_warn("Error setting wimax status to %d\n", status);
825		return -EIO;
826	}
827	return 0;
828}
829
830static ssize_t show_wimax(struct device *dev,
831			      struct device_attribute *attr, char *buf)
832{
833	struct asus_laptop *asus = dev_get_drvdata(dev);
834
835	return sprintf(buf, "%d\n", asus_wireless_status(asus, WM_RSTS));
836}
837
838static ssize_t store_wimax(struct device *dev,
839			       struct device_attribute *attr, const char *buf,
840			       size_t count)
841{
842	struct asus_laptop *asus = dev_get_drvdata(dev);
843
844	return sysfs_acpi_set(asus, buf, count, METHOD_WIMAX);
845}
846
847/*
848 * Wwan
849 */
850static int asus_wwan_set(struct asus_laptop *asus, int status)
851{
852	if (write_acpi_int(asus->handle, METHOD_WWAN, !!status)) {
853		pr_warn("Error setting wwan status to %d\n", status);
854		return -EIO;
855	}
856	return 0;
857}
858
859static ssize_t show_wwan(struct device *dev,
860			      struct device_attribute *attr, char *buf)
861{
862	struct asus_laptop *asus = dev_get_drvdata(dev);
863
864	return sprintf(buf, "%d\n", asus_wireless_status(asus, WW_RSTS));
865}
866
867static ssize_t store_wwan(struct device *dev,
868			       struct device_attribute *attr, const char *buf,
869			       size_t count)
870{
871	struct asus_laptop *asus = dev_get_drvdata(dev);
872
873	return sysfs_acpi_set(asus, buf, count, METHOD_WWAN);
874}
875
876/*
877 * Display
878 */
879static void asus_set_display(struct asus_laptop *asus, int value)
880{
881	/* no sanity check needed for now */
882	if (write_acpi_int(asus->handle, METHOD_SWITCH_DISPLAY, value))
883		pr_warn("Error setting display\n");
884	return;
885}
886
887/*
888 * Experimental support for display switching. As of now: 1 should activate
889 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
890 * Any combination (bitwise) of these will suffice. I never actually tested 4
891 * displays hooked up simultaneously, so be warned. See the acpi4asus README
892 * for more info.
893 */
894static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
895			  const char *buf, size_t count)
896{
897	struct asus_laptop *asus = dev_get_drvdata(dev);
898	int rv, value;
899
900	rv = parse_arg(buf, count, &value);
901	if (rv > 0)
902		asus_set_display(asus, value);
903	return rv;
904}
905
906/*
907 * Light Sens
908 */
909static void asus_als_switch(struct asus_laptop *asus, int value)
910{
911	if (write_acpi_int(asus->handle, METHOD_ALS_CONTROL, value))
912		pr_warn("Error setting light sensor switch\n");
913	asus->light_switch = value;
914}
915
916static ssize_t show_lssw(struct device *dev,
917			 struct device_attribute *attr, char *buf)
918{
919	struct asus_laptop *asus = dev_get_drvdata(dev);
920
921	return sprintf(buf, "%d\n", asus->light_switch);
922}
923
924static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
925			  const char *buf, size_t count)
926{
927	struct asus_laptop *asus = dev_get_drvdata(dev);
928	int rv, value;
929
930	rv = parse_arg(buf, count, &value);
931	if (rv > 0)
932		asus_als_switch(asus, value ? 1 : 0);
933
934	return rv;
935}
936
937static void asus_als_level(struct asus_laptop *asus, int value)
938{
939	if (write_acpi_int(asus->handle, METHOD_ALS_LEVEL, value))
940		pr_warn("Error setting light sensor level\n");
941	asus->light_level = value;
942}
943
944static ssize_t show_lslvl(struct device *dev,
945			  struct device_attribute *attr, char *buf)
946{
947	struct asus_laptop *asus = dev_get_drvdata(dev);
948
949	return sprintf(buf, "%d\n", asus->light_level);
950}
951
952static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
953			   const char *buf, size_t count)
954{
955	struct asus_laptop *asus = dev_get_drvdata(dev);
956	int rv, value;
957
958	rv = parse_arg(buf, count, &value);
959	if (rv > 0) {
960		value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
961		/* 0 <= value <= 15 */
962		asus_als_level(asus, value);
963	}
964
965	return rv;
966}
967
968/*
969 * GPS
970 */
971static int asus_gps_status(struct asus_laptop *asus)
972{
973	unsigned long long status;
974	acpi_status rv = AE_OK;
975
976	rv = acpi_evaluate_integer(asus->handle, METHOD_GPS_STATUS,
977				   NULL, &status);
978	if (ACPI_FAILURE(rv)) {
979		pr_warn("Error reading GPS status\n");
980		return -ENODEV;
981	}
982	return !!status;
983}
984
985static int asus_gps_switch(struct asus_laptop *asus, int status)
986{
987	const char *meth = status ? METHOD_GPS_ON : METHOD_GPS_OFF;
988
989	if (write_acpi_int(asus->handle, meth, 0x02))
990		return -ENODEV;
991	return 0;
992}
993
994static ssize_t show_gps(struct device *dev,
995			struct device_attribute *attr, char *buf)
996{
997	struct asus_laptop *asus = dev_get_drvdata(dev);
998
999	return sprintf(buf, "%d\n", asus_gps_status(asus));
1000}
1001
1002static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
1003			 const char *buf, size_t count)
1004{
1005	struct asus_laptop *asus = dev_get_drvdata(dev);
1006	int rv, value;
1007	int ret;
1008
1009	rv = parse_arg(buf, count, &value);
1010	if (rv <= 0)
1011		return -EINVAL;
1012	ret = asus_gps_switch(asus, !!value);
1013	if (ret)
1014		return ret;
1015	rfkill_set_sw_state(asus->gps_rfkill, !value);
1016	return rv;
1017}
1018
1019/*
1020 * rfkill
1021 */
1022static int asus_gps_rfkill_set(void *data, bool blocked)
1023{
1024	struct asus_laptop *asus = data;
1025
1026	return asus_gps_switch(asus, !blocked);
1027}
1028
1029static const struct rfkill_ops asus_gps_rfkill_ops = {
1030	.set_block = asus_gps_rfkill_set,
1031};
1032
1033static void asus_rfkill_exit(struct asus_laptop *asus)
1034{
1035	if (asus->gps_rfkill) {
1036		rfkill_unregister(asus->gps_rfkill);
1037		rfkill_destroy(asus->gps_rfkill);
1038		asus->gps_rfkill = NULL;
1039	}
1040}
1041
1042static int asus_rfkill_init(struct asus_laptop *asus)
1043{
1044	int result;
1045
1046	if (acpi_check_handle(asus->handle, METHOD_GPS_ON, NULL) ||
1047	    acpi_check_handle(asus->handle, METHOD_GPS_OFF, NULL) ||
1048	    acpi_check_handle(asus->handle, METHOD_GPS_STATUS, NULL))
1049		return 0;
1050
1051	asus->gps_rfkill = rfkill_alloc("asus-gps", &asus->platform_device->dev,
1052					RFKILL_TYPE_GPS,
1053					&asus_gps_rfkill_ops, asus);
1054	if (!asus->gps_rfkill)
1055		return -EINVAL;
1056
1057	result = rfkill_register(asus->gps_rfkill);
1058	if (result) {
1059		rfkill_destroy(asus->gps_rfkill);
1060		asus->gps_rfkill = NULL;
1061	}
1062
1063	return result;
1064}
1065
1066/*
1067 * Input device (i.e. hotkeys)
1068 */
1069static void asus_input_notify(struct asus_laptop *asus, int event)
1070{
1071	if (asus->inputdev)
1072		sparse_keymap_report_event(asus->inputdev, event, 1, true);
1073}
1074
1075static int asus_input_init(struct asus_laptop *asus)
1076{
1077	struct input_dev *input;
1078	int error;
1079
1080	input = input_allocate_device();
1081	if (!input) {
1082		pr_info("Unable to allocate input device\n");
1083		return -ENOMEM;
1084	}
1085	input->name = "Asus Laptop extra buttons";
1086	input->phys = ASUS_LAPTOP_FILE "/input0";
1087	input->id.bustype = BUS_HOST;
1088	input->dev.parent = &asus->platform_device->dev;
1089
1090	error = sparse_keymap_setup(input, asus_keymap, NULL);
1091	if (error) {
1092		pr_err("Unable to setup input device keymap\n");
1093		goto err_free_dev;
1094	}
1095	error = input_register_device(input);
1096	if (error) {
1097		pr_info("Unable to register input device\n");
1098		goto err_free_keymap;
1099	}
1100
1101	asus->inputdev = input;
1102	return 0;
1103
1104err_free_keymap:
1105	sparse_keymap_free(input);
1106err_free_dev:
1107	input_free_device(input);
1108	return error;
1109}
1110
1111static void asus_input_exit(struct asus_laptop *asus)
1112{
1113	if (asus->inputdev) {
1114		sparse_keymap_free(asus->inputdev);
1115		input_unregister_device(asus->inputdev);
1116	}
1117	asus->inputdev = NULL;
1118}
1119
1120/*
1121 * ACPI driver
1122 */
1123static void asus_acpi_notify(struct acpi_device *device, u32 event)
1124{
1125	struct asus_laptop *asus = acpi_driver_data(device);
1126	u16 count;
1127
1128	/* TODO Find a better way to handle events count. */
1129	count = asus->event_count[event % 128]++;
1130	acpi_bus_generate_proc_event(asus->device, event, count);
1131	acpi_bus_generate_netlink_event(asus->device->pnp.device_class,
1132					dev_name(&asus->device->dev), event,
1133					count);
1134
1135	/* Brightness events are special */
1136	if (event >= ATKD_BR_MIN && event <= ATKD_BR_MAX) {
1137
1138		/* Ignore them completely if the acpi video driver is used */
1139		if (asus->backlight_device != NULL) {
1140			/* Update the backlight device. */
1141			asus_backlight_notify(asus);
1142		}
1143		return ;
1144	}
1145	asus_input_notify(asus, event);
1146}
1147
1148static DEVICE_ATTR(infos, S_IRUGO, show_infos, NULL);
1149static DEVICE_ATTR(wlan, S_IRUGO | S_IWUSR, show_wlan, store_wlan);
1150static DEVICE_ATTR(bluetooth, S_IRUGO | S_IWUSR,
1151		   show_bluetooth, store_bluetooth);
1152static DEVICE_ATTR(wimax, S_IRUGO | S_IWUSR, show_wimax, store_wimax);
1153static DEVICE_ATTR(wwan, S_IRUGO | S_IWUSR, show_wwan, store_wwan);
1154static DEVICE_ATTR(display, S_IWUSR, NULL, store_disp);
1155static DEVICE_ATTR(ledd, S_IRUGO | S_IWUSR, show_ledd, store_ledd);
1156static DEVICE_ATTR(ls_level, S_IRUGO | S_IWUSR, show_lslvl, store_lslvl);
1157static DEVICE_ATTR(ls_switch, S_IRUGO | S_IWUSR, show_lssw, store_lssw);
1158static DEVICE_ATTR(gps, S_IRUGO | S_IWUSR, show_gps, store_gps);
1159
1160static struct attribute *asus_attributes[] = {
1161	&dev_attr_infos.attr,
1162	&dev_attr_wlan.attr,
1163	&dev_attr_bluetooth.attr,
1164	&dev_attr_wimax.attr,
1165	&dev_attr_wwan.attr,
1166	&dev_attr_display.attr,
1167	&dev_attr_ledd.attr,
1168	&dev_attr_ls_level.attr,
1169	&dev_attr_ls_switch.attr,
1170	&dev_attr_gps.attr,
1171	NULL
1172};
1173
1174static mode_t asus_sysfs_is_visible(struct kobject *kobj,
1175				    struct attribute *attr,
1176				    int idx)
1177{
1178	struct device *dev = container_of(kobj, struct device, kobj);
1179	struct platform_device *pdev = to_platform_device(dev);
1180	struct asus_laptop *asus = platform_get_drvdata(pdev);
1181	acpi_handle handle = asus->handle;
1182	bool supported;
1183
1184	if (attr == &dev_attr_wlan.attr) {
1185		supported = !acpi_check_handle(handle, METHOD_WLAN, NULL);
1186
1187	} else if (attr == &dev_attr_bluetooth.attr) {
1188		supported = !acpi_check_handle(handle, METHOD_BLUETOOTH, NULL);
1189
1190	} else if (attr == &dev_attr_display.attr) {
1191		supported = !acpi_check_handle(handle, METHOD_SWITCH_DISPLAY, NULL);
1192
1193	} else if (attr == &dev_attr_wimax.attr) {
1194		supported =
1195			!acpi_check_handle(asus->handle, METHOD_WIMAX, NULL);
1196
1197	} else if (attr == &dev_attr_wwan.attr) {
1198		supported = !acpi_check_handle(asus->handle, METHOD_WWAN, NULL);
1199
1200	} else if (attr == &dev_attr_ledd.attr) {
1201		supported = !acpi_check_handle(handle, METHOD_LEDD, NULL);
1202
1203	} else if (attr == &dev_attr_ls_switch.attr ||
1204		   attr == &dev_attr_ls_level.attr) {
1205		supported = !acpi_check_handle(handle, METHOD_ALS_CONTROL, NULL) &&
1206			    !acpi_check_handle(handle, METHOD_ALS_LEVEL, NULL);
1207
1208	} else if (attr == &dev_attr_gps.attr) {
1209		supported = !acpi_check_handle(handle, METHOD_GPS_ON, NULL) &&
1210			    !acpi_check_handle(handle, METHOD_GPS_OFF, NULL) &&
1211			    !acpi_check_handle(handle, METHOD_GPS_STATUS, NULL);
1212	} else {
1213		supported = true;
1214	}
1215
1216	return supported ? attr->mode : 0;
1217}
1218
1219
1220static const struct attribute_group asus_attr_group = {
1221	.is_visible	= asus_sysfs_is_visible,
1222	.attrs		= asus_attributes,
1223};
1224
1225static int asus_platform_init(struct asus_laptop *asus)
1226{
1227	int result;
1228
1229	asus->platform_device = platform_device_alloc(ASUS_LAPTOP_FILE, -1);
1230	if (!asus->platform_device)
1231		return -ENOMEM;
1232	platform_set_drvdata(asus->platform_device, asus);
1233
1234	result = platform_device_add(asus->platform_device);
1235	if (result)
1236		goto fail_platform_device;
1237
1238	result = sysfs_create_group(&asus->platform_device->dev.kobj,
1239				    &asus_attr_group);
1240	if (result)
1241		goto fail_sysfs;
1242
1243	return 0;
1244
1245fail_sysfs:
1246	platform_device_del(asus->platform_device);
1247fail_platform_device:
1248	platform_device_put(asus->platform_device);
1249	return result;
1250}
1251
1252static void asus_platform_exit(struct asus_laptop *asus)
1253{
1254	sysfs_remove_group(&asus->platform_device->dev.kobj, &asus_attr_group);
1255	platform_device_unregister(asus->platform_device);
1256}
1257
1258static struct platform_driver platform_driver = {
1259	.driver = {
1260		.name = ASUS_LAPTOP_FILE,
1261		.owner = THIS_MODULE,
1262	}
1263};
1264
1265/*
1266 * This function is used to initialize the context with right values. In this
1267 * method, we can make all the detection we want, and modify the asus_laptop
1268 * struct
1269 */
1270static int asus_laptop_get_info(struct asus_laptop *asus)
1271{
1272	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1273	union acpi_object *model = NULL;
1274	unsigned long long bsts_result, hwrs_result;
1275	char *string = NULL;
1276	acpi_status status;
1277
1278	/*
1279	 * Get DSDT headers early enough to allow for differentiating between
1280	 * models, but late enough to allow acpi_bus_register_driver() to fail
1281	 * before doing anything ACPI-specific. Should we encounter a machine,
1282	 * which needs special handling (i.e. its hotkey device has a different
1283	 * HID), this bit will be moved.
1284	 */
1285	status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus->dsdt_info);
1286	if (ACPI_FAILURE(status))
1287		pr_warn("Couldn't get the DSDT table header\n");
1288
1289	/* We have to write 0 on init this far for all ASUS models */
1290	if (write_acpi_int_ret(asus->handle, "INIT", 0, &buffer)) {
1291		pr_err("Hotkey initialization failed\n");
1292		return -ENODEV;
1293	}
1294
1295	/* This needs to be called for some laptops to init properly */
1296	status =
1297	    acpi_evaluate_integer(asus->handle, "BSTS", NULL, &bsts_result);
1298	if (ACPI_FAILURE(status))
1299		pr_warn("Error calling BSTS\n");
1300	else if (bsts_result)
1301		pr_notice("BSTS called, 0x%02x returned\n",
1302		       (uint) bsts_result);
1303
1304	/* This too ... */
1305	if (write_acpi_int(asus->handle, "CWAP", wapf))
1306		pr_err("Error calling CWAP(%d)\n", wapf);
1307	/*
1308	 * Try to match the object returned by INIT to the specific model.
1309	 * Handle every possible object (or the lack of thereof) the DSDT
1310	 * writers might throw at us. When in trouble, we pass NULL to
1311	 * asus_model_match() and try something completely different.
1312	 */
1313	if (buffer.pointer) {
1314		model = buffer.pointer;
1315		switch (model->type) {
1316		case ACPI_TYPE_STRING:
1317			string = model->string.pointer;
1318			break;
1319		case ACPI_TYPE_BUFFER:
1320			string = model->buffer.pointer;
1321			break;
1322		default:
1323			string = "";
1324			break;
1325		}
1326	}
1327	asus->name = kstrdup(string, GFP_KERNEL);
1328	if (!asus->name) {
1329		kfree(buffer.pointer);
1330		return -ENOMEM;
1331	}
1332
1333	if (*string)
1334		pr_notice("  %s model detected\n", string);
1335
1336	/*
1337	 * The HWRS method return informations about the hardware.
1338	 * 0x80 bit is for WLAN, 0x100 for Bluetooth,
1339	 * 0x40 for WWAN, 0x10 for WIMAX.
1340	 * The significance of others is yet to be found.
1341	 */
1342	status =
1343	    acpi_evaluate_integer(asus->handle, "HRWS", NULL, &hwrs_result);
1344	if (!ACPI_FAILURE(status))
1345		pr_notice("  HRWS returned %x", (int)hwrs_result);
1346
1347	if (!acpi_check_handle(asus->handle, METHOD_WL_STATUS, NULL))
1348		asus->have_rsts = true;
1349
1350	kfree(model);
1351
1352	return AE_OK;
1353}
1354
1355static int __devinit asus_acpi_init(struct asus_laptop *asus)
1356{
1357	int result = 0;
1358
1359	result = acpi_bus_get_status(asus->device);
1360	if (result)
1361		return result;
1362	if (!asus->device->status.present) {
1363		pr_err("Hotkey device not present, aborting\n");
1364		return -ENODEV;
1365	}
1366
1367	result = asus_laptop_get_info(asus);
1368	if (result)
1369		return result;
1370
1371	/* WLED and BLED are on by default */
1372	if (bluetooth_status >= 0)
1373		asus_bluetooth_set(asus, !!bluetooth_status);
1374
1375	if (wlan_status >= 0)
1376		asus_wlan_set(asus, !!wlan_status);
1377
1378	if (wimax_status >= 0)
1379		asus_wimax_set(asus, !!wimax_status);
1380
1381	if (wwan_status >= 0)
1382		asus_wwan_set(asus, !!wwan_status);
1383
1384	/* Keyboard Backlight is on by default */
1385	if (!acpi_check_handle(asus->handle, METHOD_KBD_LIGHT_SET, NULL))
1386		asus_kled_set(asus, 1);
1387
1388	/* LED display is off by default */
1389	asus->ledd_status = 0xFFF;
1390
1391	/* Set initial values of light sensor and level */
1392	asus->light_switch = 0;	/* Default to light sensor disabled */
1393	asus->light_level = 5;	/* level 5 for sensor sensitivity */
1394
1395	if (!acpi_check_handle(asus->handle, METHOD_ALS_CONTROL, NULL) &&
1396	    !acpi_check_handle(asus->handle, METHOD_ALS_LEVEL, NULL)) {
1397		asus_als_switch(asus, asus->light_switch);
1398		asus_als_level(asus, asus->light_level);
1399	}
1400
1401	return result;
1402}
1403
1404static void __devinit asus_dmi_check(void)
1405{
1406	const char *model;
1407
1408	model = dmi_get_system_info(DMI_PRODUCT_NAME);
1409	if (!model)
1410		return;
1411
1412	/* On L1400B WLED control the sound card, don't mess with it ... */
1413	if (strncmp(model, "L1400B", 6) == 0) {
1414		wlan_status = -1;
1415	}
1416}
1417
1418static bool asus_device_present;
1419
1420static int __devinit asus_acpi_add(struct acpi_device *device)
1421{
1422	struct asus_laptop *asus;
1423	int result;
1424
1425	pr_notice("Asus Laptop Support version %s\n",
1426		  ASUS_LAPTOP_VERSION);
1427	asus = kzalloc(sizeof(struct asus_laptop), GFP_KERNEL);
1428	if (!asus)
1429		return -ENOMEM;
1430	asus->handle = device->handle;
1431	strcpy(acpi_device_name(device), ASUS_LAPTOP_DEVICE_NAME);
1432	strcpy(acpi_device_class(device), ASUS_LAPTOP_CLASS);
1433	device->driver_data = asus;
1434	asus->device = device;
1435
1436	asus_dmi_check();
1437
1438	result = asus_acpi_init(asus);
1439	if (result)
1440		goto fail_platform;
1441
1442	/*
1443	 * Register the platform device first.  It is used as a parent for the
1444	 * sub-devices below.
1445	 */
1446	result = asus_platform_init(asus);
1447	if (result)
1448		goto fail_platform;
1449
1450	if (!acpi_video_backlight_support()) {
1451		result = asus_backlight_init(asus);
1452		if (result)
1453			goto fail_backlight;
1454	} else
1455		pr_info("Backlight controlled by ACPI video driver\n");
1456
1457	result = asus_input_init(asus);
1458	if (result)
1459		goto fail_input;
1460
1461	result = asus_led_init(asus);
1462	if (result)
1463		goto fail_led;
1464
1465	result = asus_rfkill_init(asus);
1466	if (result)
1467		goto fail_rfkill;
1468
1469	asus_device_present = true;
1470	return 0;
1471
1472fail_rfkill:
1473	asus_led_exit(asus);
1474fail_led:
1475	asus_input_exit(asus);
1476fail_input:
1477	asus_backlight_exit(asus);
1478fail_backlight:
1479	asus_platform_exit(asus);
1480fail_platform:
1481	kfree(asus->name);
1482	kfree(asus);
1483
1484	return result;
1485}
1486
1487static int asus_acpi_remove(struct acpi_device *device, int type)
1488{
1489	struct asus_laptop *asus = acpi_driver_data(device);
1490
1491	asus_backlight_exit(asus);
1492	asus_rfkill_exit(asus);
1493	asus_led_exit(asus);
1494	asus_input_exit(asus);
1495	asus_platform_exit(asus);
1496
1497	kfree(asus->name);
1498	kfree(asus);
1499	return 0;
1500}
1501
1502static const struct acpi_device_id asus_device_ids[] = {
1503	{"ATK0100", 0},
1504	{"ATK0101", 0},
1505	{"", 0},
1506};
1507MODULE_DEVICE_TABLE(acpi, asus_device_ids);
1508
1509static struct acpi_driver asus_acpi_driver = {
1510	.name = ASUS_LAPTOP_NAME,
1511	.class = ASUS_LAPTOP_CLASS,
1512	.owner = THIS_MODULE,
1513	.ids = asus_device_ids,
1514	.flags = ACPI_DRIVER_ALL_NOTIFY_EVENTS,
1515	.ops = {
1516		.add = asus_acpi_add,
1517		.remove = asus_acpi_remove,
1518		.notify = asus_acpi_notify,
1519		},
1520};
1521
1522static int __init asus_laptop_init(void)
1523{
1524	int result;
1525
1526	result = platform_driver_register(&platform_driver);
1527	if (result < 0)
1528		return result;
1529
1530	result = acpi_bus_register_driver(&asus_acpi_driver);
1531	if (result < 0)
1532		goto fail_acpi_driver;
1533	if (!asus_device_present) {
1534		result = -ENODEV;
1535		goto fail_no_device;
1536	}
1537	return 0;
1538
1539fail_no_device:
1540	acpi_bus_unregister_driver(&asus_acpi_driver);
1541fail_acpi_driver:
1542	platform_driver_unregister(&platform_driver);
1543	return result;
1544}
1545
1546static void __exit asus_laptop_exit(void)
1547{
1548	acpi_bus_unregister_driver(&asus_acpi_driver);
1549	platform_driver_unregister(&platform_driver);
1550}
1551
1552module_init(asus_laptop_init);
1553module_exit(asus_laptop_exit);
1554