blob: 7ace5b9a3d28659a2c2616ac9ab22b2ed6494668 [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
6 * Copyright (C) 2006 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 helpfull
33 *
34 */
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
51#define ASUS_LAPTOP_VERSION "0.40"
52
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
84#define LCD_ON 0x40 //LCD backlight
Corentin Charybe18cda2007-01-26 14:04:35 +010085
Corentin Chary85091b72007-01-26 14:04:30 +010086#define ASUS_LOG ASUS_HOTK_FILE ": "
87#define ASUS_ERR KERN_ERR ASUS_LOG
88#define ASUS_WARNING KERN_WARNING ASUS_LOG
89#define ASUS_NOTICE KERN_NOTICE ASUS_LOG
90#define ASUS_INFO KERN_INFO ASUS_LOG
91#define ASUS_DEBUG KERN_DEBUG ASUS_LOG
92
93MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary");
94MODULE_DESCRIPTION(ASUS_HOTK_NAME);
95MODULE_LICENSE("GPL");
96
97#define ASUS_HANDLE(object, paths...) \
98 static acpi_handle object##_handle = NULL; \
99 static char *object##_paths[] = { paths }
100
Corentin Charybe18cda2007-01-26 14:04:35 +0100101/* LED */
102ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED");
103ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED");
Len Brown8def05f2007-01-30 01:46:43 -0500104ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */
105ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */
Corentin Charybe18cda2007-01-26 14:04:35 +0100106
Corentin Chary722ad972007-01-26 14:04:55 +0100107/* LEDD */
108ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM");
109
Corentin Chary4564de12007-01-26 14:04:40 +0100110/* Bluetooth and WLAN
111 * WLED and BLED are not handled like other XLED, because in some dsdt
112 * they also control the WLAN/Bluetooth device.
113 */
114ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED");
115ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED");
Len Brown8def05f2007-01-30 01:46:43 -0500116ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */
Corentin Chary4564de12007-01-26 14:04:40 +0100117
Corentin Chary6b7091e2007-01-26 14:04:45 +0100118/* Brightness */
119ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV");
120ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV");
121
122/* Backlight */
Len Brown8def05f2007-01-30 01:46:43 -0500123ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */
124 "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */
125 "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */
126 "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */
127 "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */
128 "\\_SB.PCI0.PX40.Q10", /* S1x */
129 "\\Q10"); /* A2x, L2D, L3D, M2E */
Corentin Chary6b7091e2007-01-26 14:04:45 +0100130
Corentin Chary78127b42007-01-26 14:04:49 +0100131/* Display */
132ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
Len Brown8def05f2007-01-30 01:46:43 -0500133ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD", /* A6B, A6K A6R A7D F3JM L4R M6R A3G
134 M6A M6V VX-1 V6J V6V W3Z */
135 "\\_SB.PCI0.P0P2.VGA.GETD", /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V
Corentin Chary78127b42007-01-26 14:04:49 +0100136 S5A M5A z33A W1Jc W2V */
Len Brown8def05f2007-01-30 01:46:43 -0500137 "\\_SB.PCI0.P0P3.VGA.GETD", /* A6V A6Q */
138 "\\_SB.PCI0.P0PA.VGA.GETD", /* A6T, A6M */
139 "\\_SB.PCI0.PCI1.VGAC.NMAP", /* L3C */
140 "\\_SB.PCI0.VGA.GETD", /* Z96F */
141 "\\ACTD", /* A2D */
142 "\\ADVG", /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */
143 "\\DNXT", /* P30 */
144 "\\INFB", /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */
145 "\\SSTE"); /* A3F A6F A3N A3L M6N W3N W6A */
Corentin Chary78127b42007-01-26 14:04:49 +0100146
Len Brown8def05f2007-01-30 01:46:43 -0500147ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */
148ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */
Corentin Chary8b857352007-01-26 14:04:58 +0100149
Corentin Chary85091b72007-01-26 14:04:30 +0100150/*
151 * This is the main structure, we can use it to store anything interesting
152 * about the hotk device
153 */
154struct asus_hotk {
Len Brown8def05f2007-01-30 01:46:43 -0500155 char *name; //laptop name
Corentin Chary85091b72007-01-26 14:04:30 +0100156 struct acpi_device *device; //the device we are in
157 acpi_handle handle; //the handle of the hotk device
158 char status; //status of the hotk, for LEDs, ...
Corentin Chary722ad972007-01-26 14:04:55 +0100159 u32 ledd_status; //status of the LED display
Len Brown8def05f2007-01-30 01:46:43 -0500160 u8 light_level; //light sensor level
161 u8 light_switch; //light sensor switch value
Corentin Chary85091b72007-01-26 14:04:30 +0100162 u16 event_count[128]; //count for each event TODO make this better
163};
164
165/*
166 * This header is made available to allow proper configuration given model,
167 * revision number , ... this info cannot go in struct asus_hotk because it is
168 * available before the hotk
169 */
170static struct acpi_table_header *asus_info;
171
172/* The actual device the driver binds to */
173static struct asus_hotk *hotk;
174
175/*
176 * The hotkey driver declaration
177 */
178static int asus_hotk_add(struct acpi_device *device);
179static int asus_hotk_remove(struct acpi_device *device, int type);
180static struct acpi_driver asus_hotk_driver = {
181 .name = ASUS_HOTK_NAME,
182 .class = ASUS_HOTK_CLASS,
183 .ids = ASUS_HOTK_HID,
184 .ops = {
185 .add = asus_hotk_add,
186 .remove = asus_hotk_remove,
187 },
188};
189
Corentin Chary6b7091e2007-01-26 14:04:45 +0100190/* The backlight device /sys/class/backlight */
191static struct backlight_device *asus_backlight_device;
192
193/*
194 * The backlight class declaration
195 */
196static int read_brightness(struct backlight_device *bd);
197static int update_bl_status(struct backlight_device *bd);
198static struct backlight_properties asusbl_data = {
Len Brown8def05f2007-01-30 01:46:43 -0500199 .get_brightness = read_brightness,
200 .update_status = update_bl_status,
201 .max_brightness = 15,
Corentin Chary6b7091e2007-01-26 14:04:45 +0100202};
203
Corentin Charybe18cda2007-01-26 14:04:35 +0100204/* These functions actually update the LED's, and are called from a
205 * workqueue. By doing this as separate work rather than when the LED
206 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
207 * potentially bad time, such as a timer interrupt. */
208static struct workqueue_struct *led_workqueue;
209
210#define ASUS_LED(object, ledname) \
211 static void object##_led_set(struct led_classdev *led_cdev, \
212 enum led_brightness value); \
213 static void object##_led_update(struct work_struct *ignored); \
214 static int object##_led_wk; \
215 DECLARE_WORK(object##_led_work, object##_led_update); \
216 static struct led_classdev object##_led = { \
217 .name = "asus:" ledname, \
218 .brightness_set = object##_led_set, \
219 }
220
221ASUS_LED(mled, "mail");
222ASUS_LED(tled, "touchpad");
223ASUS_LED(rled, "record");
224ASUS_LED(pled, "phone");
225
Corentin Chary85091b72007-01-26 14:04:30 +0100226/*
227 * This function evaluates an ACPI method, given an int as parameter, the
228 * method is searched within the scope of the handle, can be NULL. The output
229 * of the method is written is output, which can also be NULL
230 *
231 * returns 1 if write is successful, 0 else.
232 */
233static int write_acpi_int(acpi_handle handle, const char *method, int val,
234 struct acpi_buffer *output)
235{
236 struct acpi_object_list params; //list of input parameters (an int here)
237 union acpi_object in_obj; //the only param we use
238 acpi_status status;
239
240 params.count = 1;
241 params.pointer = &in_obj;
242 in_obj.type = ACPI_TYPE_INTEGER;
243 in_obj.integer.value = val;
244
245 status = acpi_evaluate_object(handle, (char *)method, &params, output);
246 return (status == AE_OK);
247}
248
249static int read_acpi_int(acpi_handle handle, const char *method, int *val,
250 struct acpi_object_list *params)
251{
252 struct acpi_buffer output;
253 union acpi_object out_obj;
254 acpi_status status;
255
256 output.length = sizeof(out_obj);
257 output.pointer = &out_obj;
258
259 status = acpi_evaluate_object(handle, (char *)method, params, &output);
260 *val = out_obj.integer.value;
261 return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER);
262}
263
Len Brown8def05f2007-01-30 01:46:43 -0500264static int read_wireless_status(int mask)
265{
Corentin Chary4564de12007-01-26 14:04:40 +0100266 int status;
267
268 if (!wireless_status_handle)
269 return (hotk->status & mask) ? 1 : 0;
270
271 if (read_acpi_int(wireless_status_handle, NULL, &status, NULL)) {
272 return (status & mask) ? 1 : 0;
273 } else
274 printk(ASUS_WARNING "Error reading Wireless status\n");
275
276 return (hotk->status & mask) ? 1 : 0;
277}
278
Corentin Charybe18cda2007-01-26 14:04:35 +0100279/* Generic LED functions */
280static int read_status(int mask)
281{
Corentin Chary4564de12007-01-26 14:04:40 +0100282 /* There is a special method for both wireless devices */
283 if (mask == BT_ON || mask == WL_ON)
284 return read_wireless_status(mask);
285
Corentin Charybe18cda2007-01-26 14:04:35 +0100286 return (hotk->status & mask) ? 1 : 0;
287}
288
Len Brown8def05f2007-01-30 01:46:43 -0500289static void write_status(acpi_handle handle, int out, int mask, int invert)
Corentin Charybe18cda2007-01-26 14:04:35 +0100290{
291 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
292
293 if (invert) /* invert target value */
294 out = !out & 0x1;
295
296 if (handle && !write_acpi_int(handle, NULL, out, NULL))
297 printk(ASUS_WARNING " write failed\n");
298}
299
300/* /sys/class/led handlers */
301#define ASUS_LED_HANDLER(object, mask, invert) \
302 static void object##_led_set(struct led_classdev *led_cdev, \
303 enum led_brightness value) \
304 { \
305 object##_led_wk = value; \
306 queue_work(led_workqueue, &object##_led_work); \
307 } \
308 static void object##_led_update(struct work_struct *ignored) \
309 { \
310 int value = object##_led_wk; \
311 write_status(object##_set_handle, value, (mask), (invert)); \
312 }
313
314ASUS_LED_HANDLER(mled, MLED_ON, 1);
315ASUS_LED_HANDLER(pled, PLED_ON, 0);
316ASUS_LED_HANDLER(rled, RLED_ON, 0);
317ASUS_LED_HANDLER(tled, TLED_ON, 0);
318
Corentin Chary6b7091e2007-01-26 14:04:45 +0100319static int get_lcd_state(void)
320{
321 return read_status(LCD_ON);
322}
323
324static int set_lcd_state(int value)
325{
326 int lcd = 0;
327 acpi_status status = 0;
328
329 lcd = value ? 1 : 0;
330
331 if (lcd == get_lcd_state())
332 return 0;
333
Len Brown8def05f2007-01-30 01:46:43 -0500334 if (lcd_switch_handle) {
Corentin Chary6b7091e2007-01-26 14:04:45 +0100335 status = acpi_evaluate_object(lcd_switch_handle,
336 NULL, NULL, NULL);
337
338 if (ACPI_FAILURE(status))
339 printk(ASUS_WARNING "Error switching LCD\n");
340 }
341
342 write_status(NULL, lcd, LCD_ON, 0);
343 return 0;
344}
345
346static void lcd_blank(int blank)
347{
348 struct backlight_device *bd = asus_backlight_device;
349
Len Brown8def05f2007-01-30 01:46:43 -0500350 if (bd) {
Richard Purdie28ee0862007-02-08 22:25:09 +0000351 bd->props->power = blank;
352 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100353 }
354}
355
356static int read_brightness(struct backlight_device *bd)
357{
358 int value;
359
360 if (!read_acpi_int(brightness_get_handle, NULL, &value, NULL))
361 printk(ASUS_WARNING "Error reading brightness\n");
362
363 return value;
364}
365
366static int set_brightness(struct backlight_device *bd, int value)
367{
368 int ret = 0;
369
370 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
371 /* 0 <= value <= 15 */
372
373 if (!write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
374 printk(ASUS_WARNING "Error changing brightness\n");
375 ret = -EIO;
376 }
377
378 return ret;
379}
380
381static int update_bl_status(struct backlight_device *bd)
382{
383 int rv;
384 int value = bd->props->brightness;
385
386 rv = set_brightness(bd, value);
Len Brown8def05f2007-01-30 01:46:43 -0500387 if (rv)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100388 return rv;
389
390 value = (bd->props->power == FB_BLANK_UNBLANK) ? 1 : 0;
391 return set_lcd_state(value);
392}
393
Corentin Chary85091b72007-01-26 14:04:30 +0100394/*
395 * Platform device handlers
396 */
397
398/*
399 * We write our info in page, we begin at offset off and cannot write more
400 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
401 * number of bytes written in page
402 */
403static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500404 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100405{
406 int len = 0;
407 int temp;
408 char buf[16]; //enough for all info
409 /*
410 * We use the easy way, we don't care of off and count, so we don't set eof
411 * to 1
412 */
413
414 len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
415 len += sprintf(page + len, "Model reference : %s\n", hotk->name);
416 /*
417 * The SFUN method probably allows the original driver to get the list
418 * of features supported by a given model. For now, 0x0100 or 0x0800
419 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
420 * The significance of others is yet to be found.
421 */
422 if (read_acpi_int(hotk->handle, "SFUN", &temp, NULL))
423 len +=
424 sprintf(page + len, "SFUN value : 0x%04x\n", temp);
425 /*
426 * Another value for userspace: the ASYM method returns 0x02 for
427 * battery low and 0x04 for battery critical, its readings tend to be
428 * more accurate than those provided by _BST.
429 * Note: since not all the laptops provide this method, errors are
430 * silently ignored.
431 */
432 if (read_acpi_int(hotk->handle, "ASYM", &temp, NULL))
433 len +=
434 sprintf(page + len, "ASYM value : 0x%04x\n", temp);
435 if (asus_info) {
436 snprintf(buf, 16, "%d", asus_info->length);
437 len += sprintf(page + len, "DSDT length : %s\n", buf);
438 snprintf(buf, 16, "%d", asus_info->checksum);
439 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
440 snprintf(buf, 16, "%d", asus_info->revision);
441 len += sprintf(page + len, "DSDT revision : %s\n", buf);
442 snprintf(buf, 7, "%s", asus_info->oem_id);
443 len += sprintf(page + len, "OEM id : %s\n", buf);
444 snprintf(buf, 9, "%s", asus_info->oem_table_id);
445 len += sprintf(page + len, "OEM table id : %s\n", buf);
446 snprintf(buf, 16, "%x", asus_info->oem_revision);
447 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
448 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
449 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
450 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
451 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
452 }
453
454 return len;
455}
456
457static int parse_arg(const char *buf, unsigned long count, int *val)
458{
459 if (!count)
460 return 0;
461 if (count > 31)
462 return -EINVAL;
463 if (sscanf(buf, "%i", val) != 1)
464 return -EINVAL;
465 return count;
466}
467
Corentin Chary4564de12007-01-26 14:04:40 +0100468static ssize_t store_status(const char *buf, size_t count,
469 acpi_handle handle, int mask, int invert)
470{
471 int rv, value;
472 int out = 0;
473
474 rv = parse_arg(buf, count, &value);
475 if (rv > 0)
476 out = value ? 1 : 0;
477
478 write_status(handle, out, mask, invert);
479
480 return rv;
481}
482
483/*
Corentin Chary722ad972007-01-26 14:04:55 +0100484 * LEDD display
485 */
486static ssize_t show_ledd(struct device *dev,
487 struct device_attribute *attr, char *buf)
488{
489 return sprintf(buf, "0x%08x\n", hotk->ledd_status);
490}
491
492static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
493 const char *buf, size_t count)
494{
495 int rv, value;
496
497 rv = parse_arg(buf, count, &value);
498 if (rv > 0) {
499 if (!write_acpi_int(ledd_set_handle, NULL, value, NULL))
500 printk(ASUS_WARNING "LED display write failed\n");
501 else
502 hotk->ledd_status = (u32) value;
503 }
504 return rv;
505}
506
507/*
Corentin Chary4564de12007-01-26 14:04:40 +0100508 * WLAN
509 */
510static ssize_t show_wlan(struct device *dev,
511 struct device_attribute *attr, char *buf)
512{
513 return sprintf(buf, "%d\n", read_status(WL_ON));
514}
515
516static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
517 const char *buf, size_t count)
518{
519 return store_status(buf, count, wl_switch_handle, WL_ON, 0);
520}
521
522/*
523 * Bluetooth
524 */
525static ssize_t show_bluetooth(struct device *dev,
526 struct device_attribute *attr, char *buf)
527{
528 return sprintf(buf, "%d\n", read_status(BT_ON));
529}
530
Len Brown8def05f2007-01-30 01:46:43 -0500531static ssize_t store_bluetooth(struct device *dev,
532 struct device_attribute *attr, const char *buf,
533 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100534{
535 return store_status(buf, count, bt_switch_handle, BT_ON, 0);
536}
537
Corentin Chary78127b42007-01-26 14:04:49 +0100538/*
539 * Display
540 */
541static void set_display(int value)
542{
543 /* no sanity check needed for now */
544 if (!write_acpi_int(display_set_handle, NULL, value, NULL))
545 printk(ASUS_WARNING "Error setting display\n");
546 return;
547}
548
549static int read_display(void)
550{
551 int value = 0;
552
553 /* In most of the case, we know how to set the display, but sometime
554 we can't read it */
Len Brown8def05f2007-01-30 01:46:43 -0500555 if (display_get_handle) {
Corentin Chary78127b42007-01-26 14:04:49 +0100556 if (!read_acpi_int(display_get_handle, NULL, &value, NULL))
557 printk(ASUS_WARNING "Error reading display status\n");
558 }
559
560 value &= 0x0F; /* needed for some models, shouldn't hurt others */
561
562 return value;
563}
Len Brown8def05f2007-01-30 01:46:43 -0500564
Corentin Chary78127b42007-01-26 14:04:49 +0100565/*
566 * Now, *this* one could be more user-friendly, but so far, no-one has
567 * complained. The significance of bits is the same as in store_disp()
568 */
569static ssize_t show_disp(struct device *dev,
570 struct device_attribute *attr, char *buf)
571{
572 return sprintf(buf, "%d\n", read_display());
573}
574
575/*
576 * Experimental support for display switching. As of now: 1 should activate
577 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
578 * Any combination (bitwise) of these will suffice. I never actually tested 4
579 * displays hooked up simultaneously, so be warned. See the acpi4asus README
580 * for more info.
581 */
582static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
583 const char *buf, size_t count)
584{
585 int rv, value;
586
587 rv = parse_arg(buf, count, &value);
588 if (rv > 0)
589 set_display(value);
590 return rv;
591}
592
Corentin Chary8b857352007-01-26 14:04:58 +0100593/*
594 * Light Sens
595 */
596static void set_light_sens_switch(int value)
597{
598 if (!write_acpi_int(ls_switch_handle, NULL, value, NULL))
599 printk(ASUS_WARNING "Error setting light sensor switch\n");
600 hotk->light_switch = value;
601}
602
603static ssize_t show_lssw(struct device *dev,
604 struct device_attribute *attr, char *buf)
605{
606 return sprintf(buf, "%d\n", hotk->light_switch);
607}
608
609static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
610 const char *buf, size_t count)
611{
612 int rv, value;
613
614 rv = parse_arg(buf, count, &value);
615 if (rv > 0)
616 set_light_sens_switch(value ? 1 : 0);
617
618 return rv;
619}
620
621static void set_light_sens_level(int value)
622{
623 if (!write_acpi_int(ls_level_handle, NULL, value, NULL))
624 printk(ASUS_WARNING "Error setting light sensor level\n");
625 hotk->light_level = value;
626}
627
628static ssize_t show_lslvl(struct device *dev,
629 struct device_attribute *attr, char *buf)
630{
631 return sprintf(buf, "%d\n", hotk->light_level);
632}
633
634static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
635 const char *buf, size_t count)
636{
637 int rv, value;
638
639 rv = parse_arg(buf, count, &value);
640 if (rv > 0) {
641 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
642 /* 0 <= value <= 15 */
643 set_light_sens_level(value);
644 }
645
646 return rv;
647}
648
Corentin Chary85091b72007-01-26 14:04:30 +0100649static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
650{
651 /* TODO Find a better way to handle events count. */
652 if (!hotk)
653 return;
654
Corentin Chary6b7091e2007-01-26 14:04:45 +0100655 /*
656 * We need to tell the backlight device when the backlight power is
657 * switched
658 */
659 if (event == ATKD_LCD_ON) {
660 write_status(NULL, 1, LCD_ON, 0);
661 lcd_blank(FB_BLANK_UNBLANK);
Len Brown8def05f2007-01-30 01:46:43 -0500662 } else if (event == ATKD_LCD_OFF) {
Corentin Chary6b7091e2007-01-26 14:04:45 +0100663 write_status(NULL, 0, LCD_ON, 0);
664 lcd_blank(FB_BLANK_POWERDOWN);
665 }
666
Corentin Chary85091b72007-01-26 14:04:30 +0100667 acpi_bus_generate_event(hotk->device, event,
668 hotk->event_count[event % 128]++);
669
670 return;
671}
672
673#define ASUS_CREATE_DEVICE_ATTR(_name) \
674 struct device_attribute dev_attr_##_name = { \
675 .attr = { \
676 .name = __stringify(_name), \
677 .mode = 0, \
678 .owner = THIS_MODULE }, \
679 .show = NULL, \
680 .store = NULL, \
681 }
682
683#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
684 do { \
685 dev_attr_##_name.attr.mode = _mode; \
686 dev_attr_##_name.show = _show; \
687 dev_attr_##_name.store = _store; \
688 } while(0)
689
690static ASUS_CREATE_DEVICE_ATTR(infos);
Corentin Chary4564de12007-01-26 14:04:40 +0100691static ASUS_CREATE_DEVICE_ATTR(wlan);
692static ASUS_CREATE_DEVICE_ATTR(bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100693static ASUS_CREATE_DEVICE_ATTR(display);
Corentin Chary722ad972007-01-26 14:04:55 +0100694static ASUS_CREATE_DEVICE_ATTR(ledd);
Corentin Chary8b857352007-01-26 14:04:58 +0100695static ASUS_CREATE_DEVICE_ATTR(ls_switch);
696static ASUS_CREATE_DEVICE_ATTR(ls_level);
Corentin Chary85091b72007-01-26 14:04:30 +0100697
698static struct attribute *asuspf_attributes[] = {
Len Brown8def05f2007-01-30 01:46:43 -0500699 &dev_attr_infos.attr,
700 &dev_attr_wlan.attr,
701 &dev_attr_bluetooth.attr,
702 &dev_attr_display.attr,
703 &dev_attr_ledd.attr,
704 &dev_attr_ls_switch.attr,
705 &dev_attr_ls_level.attr,
706 NULL
Corentin Chary85091b72007-01-26 14:04:30 +0100707};
708
709static struct attribute_group asuspf_attribute_group = {
Len Brown8def05f2007-01-30 01:46:43 -0500710 .attrs = asuspf_attributes
Corentin Chary85091b72007-01-26 14:04:30 +0100711};
712
713static struct platform_driver asuspf_driver = {
Len Brown8def05f2007-01-30 01:46:43 -0500714 .driver = {
715 .name = ASUS_HOTK_FILE,
716 .owner = THIS_MODULE,
717 }
Corentin Chary85091b72007-01-26 14:04:30 +0100718};
719
720static struct platform_device *asuspf_device;
721
Corentin Chary85091b72007-01-26 14:04:30 +0100722static void asus_hotk_add_fs(void)
723{
724 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
Corentin Chary4564de12007-01-26 14:04:40 +0100725
726 if (wl_switch_handle)
727 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
728
729 if (bt_switch_handle)
730 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
731 show_bluetooth, store_bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100732
733 if (display_set_handle && display_get_handle)
734 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
Len Brown8def05f2007-01-30 01:46:43 -0500735 else if (display_set_handle)
Corentin Chary78127b42007-01-26 14:04:49 +0100736 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
737
Corentin Chary722ad972007-01-26 14:04:55 +0100738 if (ledd_set_handle)
739 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
740
Corentin Chary8b857352007-01-26 14:04:58 +0100741 if (ls_switch_handle && ls_level_handle) {
742 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
743 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
744 }
Corentin Chary85091b72007-01-26 14:04:30 +0100745}
746
Len Brown8def05f2007-01-30 01:46:43 -0500747static int asus_handle_init(char *name, acpi_handle * handle,
Corentin Chary85091b72007-01-26 14:04:30 +0100748 char **paths, int num_paths)
749{
750 int i;
751 acpi_status status;
752
753 for (i = 0; i < num_paths; i++) {
754 status = acpi_get_handle(NULL, paths[i], handle);
755 if (ACPI_SUCCESS(status))
756 return 0;
757 }
758
759 *handle = NULL;
760 return -ENODEV;
761}
762
763#define ASUS_HANDLE_INIT(object) \
764 asus_handle_init(#object, &object##_handle, object##_paths, \
765 ARRAY_SIZE(object##_paths))
766
Corentin Chary85091b72007-01-26 14:04:30 +0100767/*
768 * This function is used to initialize the hotk with right values. In this
769 * method, we can make all the detection we want, and modify the hotk struct
770 */
771static int asus_hotk_get_info(void)
772{
773 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +0100774 union acpi_object *model = NULL;
Corentin Chary4564de12007-01-26 14:04:40 +0100775 int bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +0100776 char *string = NULL;
777 acpi_status status;
778
779 /*
780 * Get DSDT headers early enough to allow for differentiating between
781 * models, but late enough to allow acpi_bus_register_driver() to fail
782 * before doing anything ACPI-specific. Should we encounter a machine,
783 * which needs special handling (i.e. its hotkey device has a different
784 * HID), this bit will be moved. A global variable asus_info contains
785 * the DSDT header.
786 */
Len Brown894d79b2007-02-03 02:13:53 -0500787 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
Corentin Chary85091b72007-01-26 14:04:30 +0100788 if (ACPI_FAILURE(status))
789 printk(ASUS_WARNING "Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +0100790
791 /* We have to write 0 on init this far for all ASUS models */
792 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
793 printk(ASUS_ERR "Hotkey initialization failed\n");
794 return -ENODEV;
795 }
796
797 /* This needs to be called for some laptops to init properly */
798 if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result, NULL))
799 printk(ASUS_WARNING "Error calling BSTS\n");
800 else if (bsts_result)
801 printk(ASUS_NOTICE "BSTS called, 0x%02x returned\n",
802 bsts_result);
803
804 /*
805 * Try to match the object returned by INIT to the specific model.
806 * Handle every possible object (or the lack of thereof) the DSDT
807 * writers might throw at us. When in trouble, we pass NULL to
808 * asus_model_match() and try something completely different.
809 */
810 if (buffer.pointer) {
811 model = buffer.pointer;
812 switch (model->type) {
813 case ACPI_TYPE_STRING:
814 string = model->string.pointer;
815 break;
816 case ACPI_TYPE_BUFFER:
817 string = model->buffer.pointer;
818 break;
819 default:
820 string = "";
821 break;
822 }
823 }
824 hotk->name = kstrdup(string, GFP_KERNEL);
825 if (!hotk->name)
826 return -ENOMEM;
827
Len Brown8def05f2007-01-30 01:46:43 -0500828 if (*string)
Corentin Chary85091b72007-01-26 14:04:30 +0100829 printk(ASUS_NOTICE " %s model detected\n", string);
830
Corentin Charybe18cda2007-01-26 14:04:35 +0100831 ASUS_HANDLE_INIT(mled_set);
832 ASUS_HANDLE_INIT(tled_set);
833 ASUS_HANDLE_INIT(rled_set);
834 ASUS_HANDLE_INIT(pled_set);
835
Corentin Chary722ad972007-01-26 14:04:55 +0100836 ASUS_HANDLE_INIT(ledd_set);
837
Corentin Chary4564de12007-01-26 14:04:40 +0100838 /*
839 * The HWRS method return informations about the hardware.
840 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
841 * The significance of others is yet to be found.
842 * If we don't find the method, we assume the device are present.
843 */
844 if (!read_acpi_int(hotk->handle, "HRWS", &hwrs_result, NULL))
845 hwrs_result = WL_HWRS | BT_HWRS;
846
Len Brown8def05f2007-01-30 01:46:43 -0500847 if (hwrs_result & WL_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +0100848 ASUS_HANDLE_INIT(wl_switch);
Len Brown8def05f2007-01-30 01:46:43 -0500849 if (hwrs_result & BT_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +0100850 ASUS_HANDLE_INIT(bt_switch);
851
852 ASUS_HANDLE_INIT(wireless_status);
853
Corentin Chary6b7091e2007-01-26 14:04:45 +0100854 ASUS_HANDLE_INIT(brightness_set);
855 ASUS_HANDLE_INIT(brightness_get);
856
857 ASUS_HANDLE_INIT(lcd_switch);
858
Corentin Chary78127b42007-01-26 14:04:49 +0100859 ASUS_HANDLE_INIT(display_set);
860 ASUS_HANDLE_INIT(display_get);
861
Corentin Chary8b857352007-01-26 14:04:58 +0100862 /* There is a lot of models with "ALSL", but a few get
863 a real light sens, so we need to check it. */
Len Brown8def05f2007-01-30 01:46:43 -0500864 if (ASUS_HANDLE_INIT(ls_switch))
Corentin Chary8b857352007-01-26 14:04:58 +0100865 ASUS_HANDLE_INIT(ls_level);
866
Corentin Chary85091b72007-01-26 14:04:30 +0100867 kfree(model);
868
869 return AE_OK;
870}
871
872static int asus_hotk_check(void)
873{
874 int result = 0;
875
876 result = acpi_bus_get_status(hotk->device);
877 if (result)
878 return result;
879
880 if (hotk->device->status.present) {
881 result = asus_hotk_get_info();
882 } else {
883 printk(ASUS_ERR "Hotkey device not present, aborting\n");
884 return -EINVAL;
885 }
886
887 return result;
888}
889
890static int asus_hotk_found;
891
892static int asus_hotk_add(struct acpi_device *device)
893{
894 acpi_status status = AE_OK;
895 int result;
896
897 if (!device)
898 return -EINVAL;
899
900 printk(ASUS_NOTICE "Asus Laptop Support version %s\n",
901 ASUS_LAPTOP_VERSION);
902
903 hotk = kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
904 if (!hotk)
905 return -ENOMEM;
906 memset(hotk, 0, sizeof(struct asus_hotk));
907
908 hotk->handle = device->handle;
909 strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
910 strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
911 acpi_driver_data(device) = hotk;
912 hotk->device = device;
913
914 result = asus_hotk_check();
915 if (result)
916 goto end;
917
918 asus_hotk_add_fs();
919
920 /*
921 * We install the handler, it will receive the hotk in parameter, so, we
922 * could add other data to the hotk struct
923 */
924 status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
925 asus_hotk_notify, hotk);
926 if (ACPI_FAILURE(status))
927 printk(ASUS_ERR "Error installing notify handler\n");
928
929 asus_hotk_found = 1;
930
Corentin Chary6b7091e2007-01-26 14:04:45 +0100931 /* WLED and BLED are on by default */
Corentin Chary4564de12007-01-26 14:04:40 +0100932 write_status(bt_switch_handle, 1, BT_ON, 0);
933 write_status(wl_switch_handle, 1, WL_ON, 0);
934
Corentin Chary6b7091e2007-01-26 14:04:45 +0100935 /* LCD Backlight is on by default */
936 write_status(NULL, 1, LCD_ON, 0);
937
Corentin Chary722ad972007-01-26 14:04:55 +0100938 /* LED display is off by default */
939 hotk->ledd_status = 0xFFF;
940
Len Brown8def05f2007-01-30 01:46:43 -0500941 /* Set initial values of light sensor and level */
942 hotk->light_switch = 1; /* Default to light sensor disabled */
943 hotk->light_level = 0; /* level 5 for sensor sensitivity */
Corentin Chary8b857352007-01-26 14:04:58 +0100944
Len Brown8def05f2007-01-30 01:46:43 -0500945 if (ls_switch_handle)
946 set_light_sens_switch(hotk->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +0100947
Len Brown8def05f2007-01-30 01:46:43 -0500948 if (ls_level_handle)
949 set_light_sens_level(hotk->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +0100950
Corentin Chary85091b72007-01-26 14:04:30 +0100951 end:
952 if (result) {
953 kfree(hotk->name);
954 kfree(hotk);
955 }
956
957 return result;
958}
959
960static int asus_hotk_remove(struct acpi_device *device, int type)
961{
962 acpi_status status = 0;
963
964 if (!device || !acpi_driver_data(device))
965 return -EINVAL;
966
967 status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
968 asus_hotk_notify);
969 if (ACPI_FAILURE(status))
970 printk(ASUS_ERR "Error removing notify handler\n");
971
972 kfree(hotk->name);
973 kfree(hotk);
974
975 return 0;
976}
977
Corentin Chary6b7091e2007-01-26 14:04:45 +0100978static void asus_backlight_exit(void)
979{
Len Brown8def05f2007-01-30 01:46:43 -0500980 if (asus_backlight_device)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100981 backlight_device_unregister(asus_backlight_device);
982}
983
Corentin Charybe18cda2007-01-26 14:04:35 +0100984#define ASUS_LED_UNREGISTER(object) \
985 if(object##_led.class_dev \
986 && !IS_ERR(object##_led.class_dev)) \
987 led_classdev_unregister(&object##_led)
988
989static void asus_led_exit(void)
990{
991 ASUS_LED_UNREGISTER(mled);
992 ASUS_LED_UNREGISTER(tled);
993 ASUS_LED_UNREGISTER(pled);
994 ASUS_LED_UNREGISTER(rled);
995
996 destroy_workqueue(led_workqueue);
997}
998
Corentin Chary85091b72007-01-26 14:04:30 +0100999static void __exit asus_laptop_exit(void)
1000{
Corentin Chary6b7091e2007-01-26 14:04:45 +01001001 asus_backlight_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001002 asus_led_exit();
1003
Corentin Chary85091b72007-01-26 14:04:30 +01001004 acpi_bus_unregister_driver(&asus_hotk_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001005 sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
1006 platform_device_unregister(asuspf_device);
1007 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001008}
1009
Len Brown8def05f2007-01-30 01:46:43 -05001010static int asus_backlight_init(struct device *dev)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001011{
1012 struct backlight_device *bd;
1013
Len Brown8def05f2007-01-30 01:46:43 -05001014 if (brightness_set_handle && lcd_switch_handle) {
1015 bd = backlight_device_register(ASUS_HOTK_FILE, dev,
1016 NULL, &asusbl_data);
1017 if (IS_ERR(bd)) {
Corentin Chary6b7091e2007-01-26 14:04:45 +01001018 printk(ASUS_ERR
1019 "Could not register asus backlight device\n");
1020 asus_backlight_device = NULL;
1021 return PTR_ERR(bd);
1022 }
1023
1024 asus_backlight_device = bd;
1025
Richard Purdie28ee0862007-02-08 22:25:09 +00001026 bd->props->brightness = read_brightness(NULL);
1027 bd->props->power = FB_BLANK_UNBLANK;
1028 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001029 }
1030 return 0;
1031}
1032
Corentin Charybe18cda2007-01-26 14:04:35 +01001033static int asus_led_register(acpi_handle handle,
Len Brown8def05f2007-01-30 01:46:43 -05001034 struct led_classdev *ldev, struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001035{
Len Brown8def05f2007-01-30 01:46:43 -05001036 if (!handle)
Corentin Charybe18cda2007-01-26 14:04:35 +01001037 return 0;
1038
1039 return led_classdev_register(dev, ldev);
1040}
Len Brown8def05f2007-01-30 01:46:43 -05001041
Corentin Charybe18cda2007-01-26 14:04:35 +01001042#define ASUS_LED_REGISTER(object, device) \
1043 asus_led_register(object##_set_handle, &object##_led, device)
1044
Len Brown8def05f2007-01-30 01:46:43 -05001045static int asus_led_init(struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001046{
1047 int rv;
1048
1049 rv = ASUS_LED_REGISTER(mled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001050 if (rv)
Corentin Charybe18cda2007-01-26 14:04:35 +01001051 return rv;
1052
1053 rv = ASUS_LED_REGISTER(tled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001054 if (rv)
Corentin Charybe18cda2007-01-26 14:04:35 +01001055 return rv;
1056
1057 rv = ASUS_LED_REGISTER(rled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001058 if (rv)
Corentin Charybe18cda2007-01-26 14:04:35 +01001059 return rv;
1060
1061 rv = ASUS_LED_REGISTER(pled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001062 if (rv)
Corentin Charybe18cda2007-01-26 14:04:35 +01001063 return rv;
1064
1065 led_workqueue = create_singlethread_workqueue("led_workqueue");
Len Brown8def05f2007-01-30 01:46:43 -05001066 if (!led_workqueue)
Corentin Charybe18cda2007-01-26 14:04:35 +01001067 return -ENOMEM;
1068
1069 return 0;
1070}
1071
Corentin Chary85091b72007-01-26 14:04:30 +01001072static int __init asus_laptop_init(void)
1073{
Corentin Charybe18cda2007-01-26 14:04:35 +01001074 struct device *dev;
Corentin Chary85091b72007-01-26 14:04:30 +01001075 int result;
1076
1077 if (acpi_disabled)
1078 return -ENODEV;
1079
Corentin Chary85091b72007-01-26 14:04:30 +01001080 result = acpi_bus_register_driver(&asus_hotk_driver);
1081 if (result < 0)
1082 return result;
1083
1084 /*
1085 * This is a bit of a kludge. We only want this module loaded
1086 * for ASUS systems, but there's currently no way to probe the
1087 * ACPI namespace for ASUS HIDs. So we just return failure if
1088 * we didn't find one, which will cause the module to be
1089 * unloaded.
1090 */
1091 if (!asus_hotk_found) {
1092 acpi_bus_unregister_driver(&asus_hotk_driver);
1093 return -ENODEV;
1094 }
1095
Corentin Charybe18cda2007-01-26 14:04:35 +01001096 dev = acpi_get_physical_device(hotk->device->handle);
1097
Corentin Chary6b7091e2007-01-26 14:04:45 +01001098 result = asus_backlight_init(dev);
Len Brown8def05f2007-01-30 01:46:43 -05001099 if (result)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001100 goto fail_backlight;
1101
Corentin Charybe18cda2007-01-26 14:04:35 +01001102 result = asus_led_init(dev);
Len Brown8def05f2007-01-30 01:46:43 -05001103 if (result)
Corentin Charybe18cda2007-01-26 14:04:35 +01001104 goto fail_led;
1105
Len Brown8def05f2007-01-30 01:46:43 -05001106 /* Register platform stuff */
Corentin Chary85091b72007-01-26 14:04:30 +01001107 result = platform_driver_register(&asuspf_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001108 if (result)
1109 goto fail_platform_driver;
Corentin Chary85091b72007-01-26 14:04:30 +01001110
Len Brown8def05f2007-01-30 01:46:43 -05001111 asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
1112 if (!asuspf_device) {
1113 result = -ENOMEM;
1114 goto fail_platform_device1;
1115 }
Corentin Chary85091b72007-01-26 14:04:30 +01001116
Len Brown8def05f2007-01-30 01:46:43 -05001117 result = platform_device_add(asuspf_device);
1118 if (result)
1119 goto fail_platform_device2;
Corentin Chary85091b72007-01-26 14:04:30 +01001120
Len Brown8def05f2007-01-30 01:46:43 -05001121 result = sysfs_create_group(&asuspf_device->dev.kobj,
Corentin Chary85091b72007-01-26 14:04:30 +01001122 &asuspf_attribute_group);
Len Brown8def05f2007-01-30 01:46:43 -05001123 if (result)
1124 goto fail_sysfs;
Corentin Chary85091b72007-01-26 14:04:30 +01001125
Len Brown8def05f2007-01-30 01:46:43 -05001126 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001127
Len Brown8def05f2007-01-30 01:46:43 -05001128 fail_sysfs:
1129 platform_device_del(asuspf_device);
Corentin Chary85091b72007-01-26 14:04:30 +01001130
Len Brown8def05f2007-01-30 01:46:43 -05001131 fail_platform_device2:
Corentin Chary85091b72007-01-26 14:04:30 +01001132 platform_device_put(asuspf_device);
1133
Len Brown8def05f2007-01-30 01:46:43 -05001134 fail_platform_device1:
1135 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001136
Len Brown8def05f2007-01-30 01:46:43 -05001137 fail_platform_driver:
Corentin Charybe18cda2007-01-26 14:04:35 +01001138 asus_led_exit();
1139
Len Brown8def05f2007-01-30 01:46:43 -05001140 fail_led:
Corentin Chary6b7091e2007-01-26 14:04:45 +01001141 asus_backlight_exit();
1142
Len Brown8def05f2007-01-30 01:46:43 -05001143 fail_backlight:
Corentin Chary85091b72007-01-26 14:04:30 +01001144
1145 return result;
1146}
1147
1148module_init(asus_laptop_init);
1149module_exit(asus_laptop_exit);