blob: 3ba579899ac708e43670b02989a21e423e2205d1 [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);
Richard Purdie599a52d2007-02-10 23:07:48 +0000198static struct backlight_ops asusbl_ops = {
Len Brown8def05f2007-01-30 01:46:43 -0500199 .get_brightness = read_brightness,
200 .update_status = update_bl_status,
Corentin Chary6b7091e2007-01-26 14:04:45 +0100201};
202
Corentin Charybe18cda2007-01-26 14:04:35 +0100203/* These functions actually update the LED's, and are called from a
204 * workqueue. By doing this as separate work rather than when the LED
205 * subsystem asks, we avoid messing with the Asus ACPI stuff during a
206 * potentially bad time, such as a timer interrupt. */
207static struct workqueue_struct *led_workqueue;
208
209#define ASUS_LED(object, ledname) \
210 static void object##_led_set(struct led_classdev *led_cdev, \
211 enum led_brightness value); \
212 static void object##_led_update(struct work_struct *ignored); \
213 static int object##_led_wk; \
Adrian Bunkf110ef52007-02-20 01:07:25 +0100214 static DECLARE_WORK(object##_led_work, object##_led_update); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100215 static struct led_classdev object##_led = { \
216 .name = "asus:" ledname, \
217 .brightness_set = object##_led_set, \
218 }
219
220ASUS_LED(mled, "mail");
221ASUS_LED(tled, "touchpad");
222ASUS_LED(rled, "record");
223ASUS_LED(pled, "phone");
224
Corentin Chary85091b72007-01-26 14:04:30 +0100225/*
226 * This function evaluates an ACPI method, given an int as parameter, the
227 * method is searched within the scope of the handle, can be NULL. The output
228 * of the method is written is output, which can also be NULL
229 *
230 * returns 1 if write is successful, 0 else.
231 */
232static int write_acpi_int(acpi_handle handle, const char *method, int val,
233 struct acpi_buffer *output)
234{
235 struct acpi_object_list params; //list of input parameters (an int here)
236 union acpi_object in_obj; //the only param we use
237 acpi_status status;
238
239 params.count = 1;
240 params.pointer = &in_obj;
241 in_obj.type = ACPI_TYPE_INTEGER;
242 in_obj.integer.value = val;
243
244 status = acpi_evaluate_object(handle, (char *)method, &params, output);
245 return (status == AE_OK);
246}
247
Len Brown8def05f2007-01-30 01:46:43 -0500248static int read_wireless_status(int mask)
249{
Corentin Chary9a816852007-03-11 10:25:38 +0100250 ulong status;
251 acpi_status rv = AE_OK;
Corentin Chary4564de12007-01-26 14:04:40 +0100252
253 if (!wireless_status_handle)
254 return (hotk->status & mask) ? 1 : 0;
255
Corentin Chary9a816852007-03-11 10:25:38 +0100256 rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status);
257 if (ACPI_FAILURE(rv))
Corentin Chary4564de12007-01-26 14:04:40 +0100258 printk(ASUS_WARNING "Error reading Wireless status\n");
Corentin Chary9a816852007-03-11 10:25:38 +0100259 else
260 return (status & mask) ? 1 : 0;
Corentin Chary4564de12007-01-26 14:04:40 +0100261
262 return (hotk->status & mask) ? 1 : 0;
263}
264
Corentin Charybe18cda2007-01-26 14:04:35 +0100265/* Generic LED functions */
266static int read_status(int mask)
267{
Corentin Chary4564de12007-01-26 14:04:40 +0100268 /* There is a special method for both wireless devices */
269 if (mask == BT_ON || mask == WL_ON)
270 return read_wireless_status(mask);
271
Corentin Charybe18cda2007-01-26 14:04:35 +0100272 return (hotk->status & mask) ? 1 : 0;
273}
274
Corentin Chary935ffee2007-03-11 10:26:12 +0100275static void write_status(acpi_handle handle, int out, int mask)
Corentin Charybe18cda2007-01-26 14:04:35 +0100276{
277 hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask);
278
Corentin Chary935ffee2007-03-11 10:26:12 +0100279 switch (mask) {
280 case MLED_ON:
Corentin Charybe18cda2007-01-26 14:04:35 +0100281 out = !out & 0x1;
Corentin Chary935ffee2007-03-11 10:26:12 +0100282 break;
283 default:
284 out &= 0x1;
285 break;
286 }
Corentin Charybe18cda2007-01-26 14:04:35 +0100287
288 if (handle && !write_acpi_int(handle, NULL, out, NULL))
Corentin Chary935ffee2007-03-11 10:26:12 +0100289 printk(ASUS_WARNING " write failed %x\n", mask);
Corentin Charybe18cda2007-01-26 14:04:35 +0100290}
291
292/* /sys/class/led handlers */
Corentin Chary935ffee2007-03-11 10:26:12 +0100293#define ASUS_LED_HANDLER(object, mask) \
Corentin Charybe18cda2007-01-26 14:04:35 +0100294 static void object##_led_set(struct led_classdev *led_cdev, \
295 enum led_brightness value) \
296 { \
297 object##_led_wk = value; \
298 queue_work(led_workqueue, &object##_led_work); \
299 } \
300 static void object##_led_update(struct work_struct *ignored) \
301 { \
302 int value = object##_led_wk; \
Corentin Chary935ffee2007-03-11 10:26:12 +0100303 write_status(object##_set_handle, value, (mask)); \
Corentin Charybe18cda2007-01-26 14:04:35 +0100304 }
305
Corentin Chary935ffee2007-03-11 10:26:12 +0100306ASUS_LED_HANDLER(mled, MLED_ON);
307ASUS_LED_HANDLER(pled, PLED_ON);
308ASUS_LED_HANDLER(rled, RLED_ON);
309ASUS_LED_HANDLER(tled, TLED_ON);
Corentin Charybe18cda2007-01-26 14:04:35 +0100310
Corentin Chary6b7091e2007-01-26 14:04:45 +0100311static int get_lcd_state(void)
312{
313 return read_status(LCD_ON);
314}
315
316static int set_lcd_state(int value)
317{
318 int lcd = 0;
319 acpi_status status = 0;
320
321 lcd = value ? 1 : 0;
322
323 if (lcd == get_lcd_state())
324 return 0;
325
Len Brown8def05f2007-01-30 01:46:43 -0500326 if (lcd_switch_handle) {
Corentin Chary6b7091e2007-01-26 14:04:45 +0100327 status = acpi_evaluate_object(lcd_switch_handle,
328 NULL, NULL, NULL);
329
330 if (ACPI_FAILURE(status))
331 printk(ASUS_WARNING "Error switching LCD\n");
332 }
333
Corentin Chary935ffee2007-03-11 10:26:12 +0100334 write_status(NULL, lcd, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100335 return 0;
336}
337
338static void lcd_blank(int blank)
339{
340 struct backlight_device *bd = asus_backlight_device;
341
Len Brown8def05f2007-01-30 01:46:43 -0500342 if (bd) {
Richard Purdie599a52d2007-02-10 23:07:48 +0000343 bd->props.power = blank;
Richard Purdie28ee0862007-02-08 22:25:09 +0000344 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100345 }
346}
347
348static int read_brightness(struct backlight_device *bd)
349{
Corentin Chary9a816852007-03-11 10:25:38 +0100350 ulong value;
351 acpi_status rv = AE_OK;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100352
Corentin Chary9a816852007-03-11 10:25:38 +0100353 rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value);
354 if (ACPI_FAILURE(rv))
Corentin Chary6b7091e2007-01-26 14:04:45 +0100355 printk(ASUS_WARNING "Error reading brightness\n");
356
357 return value;
358}
359
360static int set_brightness(struct backlight_device *bd, int value)
361{
362 int ret = 0;
363
364 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
365 /* 0 <= value <= 15 */
366
367 if (!write_acpi_int(brightness_set_handle, NULL, value, NULL)) {
368 printk(ASUS_WARNING "Error changing brightness\n");
369 ret = -EIO;
370 }
371
372 return ret;
373}
374
375static int update_bl_status(struct backlight_device *bd)
376{
377 int rv;
Richard Purdie599a52d2007-02-10 23:07:48 +0000378 int value = bd->props.brightness;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100379
380 rv = set_brightness(bd, value);
Len Brown8def05f2007-01-30 01:46:43 -0500381 if (rv)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100382 return rv;
383
Richard Purdie599a52d2007-02-10 23:07:48 +0000384 value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0;
Corentin Chary6b7091e2007-01-26 14:04:45 +0100385 return set_lcd_state(value);
386}
387
Corentin Chary85091b72007-01-26 14:04:30 +0100388/*
389 * Platform device handlers
390 */
391
392/*
393 * We write our info in page, we begin at offset off and cannot write more
394 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
395 * number of bytes written in page
396 */
397static ssize_t show_infos(struct device *dev,
Len Brown8def05f2007-01-30 01:46:43 -0500398 struct device_attribute *attr, char *page)
Corentin Chary85091b72007-01-26 14:04:30 +0100399{
400 int len = 0;
Corentin Chary9a816852007-03-11 10:25:38 +0100401 ulong temp;
Corentin Chary85091b72007-01-26 14:04:30 +0100402 char buf[16]; //enough for all info
Corentin Chary9a816852007-03-11 10:25:38 +0100403 acpi_status rv = AE_OK;
404
Corentin Chary85091b72007-01-26 14:04:30 +0100405 /*
406 * We use the easy way, we don't care of off and count, so we don't set eof
407 * to 1
408 */
409
410 len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n");
411 len += sprintf(page + len, "Model reference : %s\n", hotk->name);
412 /*
413 * The SFUN method probably allows the original driver to get the list
414 * of features supported by a given model. For now, 0x0100 or 0x0800
415 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
416 * The significance of others is yet to be found.
417 */
Corentin Chary9a816852007-03-11 10:25:38 +0100418 rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp);
419 if (!ACPI_FAILURE(rv))
420 len += sprintf(page + len, "SFUN value : 0x%04x\n",
421 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100422 /*
423 * Another value for userspace: the ASYM method returns 0x02 for
424 * battery low and 0x04 for battery critical, its readings tend to be
425 * more accurate than those provided by _BST.
426 * Note: since not all the laptops provide this method, errors are
427 * silently ignored.
428 */
Corentin Chary9a816852007-03-11 10:25:38 +0100429 rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp);
430 if (!ACPI_FAILURE(rv))
431 len += sprintf(page + len, "ASYM value : 0x%04x\n",
432 (uint) temp);
Corentin Chary85091b72007-01-26 14:04:30 +0100433 if (asus_info) {
434 snprintf(buf, 16, "%d", asus_info->length);
435 len += sprintf(page + len, "DSDT length : %s\n", buf);
436 snprintf(buf, 16, "%d", asus_info->checksum);
437 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
438 snprintf(buf, 16, "%d", asus_info->revision);
439 len += sprintf(page + len, "DSDT revision : %s\n", buf);
440 snprintf(buf, 7, "%s", asus_info->oem_id);
441 len += sprintf(page + len, "OEM id : %s\n", buf);
442 snprintf(buf, 9, "%s", asus_info->oem_table_id);
443 len += sprintf(page + len, "OEM table id : %s\n", buf);
444 snprintf(buf, 16, "%x", asus_info->oem_revision);
445 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
446 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
447 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
448 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
449 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
450 }
451
452 return len;
453}
454
455static int parse_arg(const char *buf, unsigned long count, int *val)
456{
457 if (!count)
458 return 0;
459 if (count > 31)
460 return -EINVAL;
461 if (sscanf(buf, "%i", val) != 1)
462 return -EINVAL;
463 return count;
464}
465
Corentin Chary4564de12007-01-26 14:04:40 +0100466static ssize_t store_status(const char *buf, size_t count,
Corentin Chary935ffee2007-03-11 10:26:12 +0100467 acpi_handle handle, int mask)
Corentin Chary4564de12007-01-26 14:04:40 +0100468{
469 int rv, value;
470 int out = 0;
471
472 rv = parse_arg(buf, count, &value);
473 if (rv > 0)
474 out = value ? 1 : 0;
475
Corentin Chary935ffee2007-03-11 10:26:12 +0100476 write_status(handle, out, mask);
Corentin Chary4564de12007-01-26 14:04:40 +0100477
478 return rv;
479}
480
481/*
Corentin Chary722ad972007-01-26 14:04:55 +0100482 * LEDD display
483 */
484static ssize_t show_ledd(struct device *dev,
485 struct device_attribute *attr, char *buf)
486{
487 return sprintf(buf, "0x%08x\n", hotk->ledd_status);
488}
489
490static ssize_t store_ledd(struct device *dev, struct device_attribute *attr,
491 const char *buf, size_t count)
492{
493 int rv, value;
494
495 rv = parse_arg(buf, count, &value);
496 if (rv > 0) {
497 if (!write_acpi_int(ledd_set_handle, NULL, value, NULL))
498 printk(ASUS_WARNING "LED display write failed\n");
499 else
500 hotk->ledd_status = (u32) value;
501 }
502 return rv;
503}
504
505/*
Corentin Chary4564de12007-01-26 14:04:40 +0100506 * WLAN
507 */
508static ssize_t show_wlan(struct device *dev,
509 struct device_attribute *attr, char *buf)
510{
511 return sprintf(buf, "%d\n", read_status(WL_ON));
512}
513
514static ssize_t store_wlan(struct device *dev, struct device_attribute *attr,
515 const char *buf, size_t count)
516{
Corentin Chary935ffee2007-03-11 10:26:12 +0100517 return store_status(buf, count, wl_switch_handle, WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100518}
519
520/*
521 * Bluetooth
522 */
523static ssize_t show_bluetooth(struct device *dev,
524 struct device_attribute *attr, char *buf)
525{
526 return sprintf(buf, "%d\n", read_status(BT_ON));
527}
528
Len Brown8def05f2007-01-30 01:46:43 -0500529static ssize_t store_bluetooth(struct device *dev,
530 struct device_attribute *attr, const char *buf,
531 size_t count)
Corentin Chary4564de12007-01-26 14:04:40 +0100532{
Corentin Chary935ffee2007-03-11 10:26:12 +0100533 return store_status(buf, count, bt_switch_handle, BT_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100534}
535
Corentin Chary78127b42007-01-26 14:04:49 +0100536/*
537 * Display
538 */
539static void set_display(int value)
540{
541 /* no sanity check needed for now */
542 if (!write_acpi_int(display_set_handle, NULL, value, NULL))
543 printk(ASUS_WARNING "Error setting display\n");
544 return;
545}
546
547static int read_display(void)
548{
Corentin Chary9a816852007-03-11 10:25:38 +0100549 ulong value = 0;
550 acpi_status rv = AE_OK;
Corentin Chary78127b42007-01-26 14:04:49 +0100551
552 /* In most of the case, we know how to set the display, but sometime
553 we can't read it */
Len Brown8def05f2007-01-30 01:46:43 -0500554 if (display_get_handle) {
Corentin Chary9a816852007-03-11 10:25:38 +0100555 rv = acpi_evaluate_integer(display_get_handle, NULL,
556 NULL, &value);
557 if (ACPI_FAILURE(rv))
Corentin Chary78127b42007-01-26 14:04:49 +0100558 printk(ASUS_WARNING "Error reading display status\n");
559 }
560
561 value &= 0x0F; /* needed for some models, shouldn't hurt others */
562
563 return value;
564}
Len Brown8def05f2007-01-30 01:46:43 -0500565
Corentin Chary78127b42007-01-26 14:04:49 +0100566/*
567 * Now, *this* one could be more user-friendly, but so far, no-one has
568 * complained. The significance of bits is the same as in store_disp()
569 */
570static ssize_t show_disp(struct device *dev,
571 struct device_attribute *attr, char *buf)
572{
573 return sprintf(buf, "%d\n", read_display());
574}
575
576/*
577 * Experimental support for display switching. As of now: 1 should activate
578 * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI.
579 * Any combination (bitwise) of these will suffice. I never actually tested 4
580 * displays hooked up simultaneously, so be warned. See the acpi4asus README
581 * for more info.
582 */
583static ssize_t store_disp(struct device *dev, struct device_attribute *attr,
584 const char *buf, size_t count)
585{
586 int rv, value;
587
588 rv = parse_arg(buf, count, &value);
589 if (rv > 0)
590 set_display(value);
591 return rv;
592}
593
Corentin Chary8b857352007-01-26 14:04:58 +0100594/*
595 * Light Sens
596 */
597static void set_light_sens_switch(int value)
598{
599 if (!write_acpi_int(ls_switch_handle, NULL, value, NULL))
600 printk(ASUS_WARNING "Error setting light sensor switch\n");
601 hotk->light_switch = value;
602}
603
604static ssize_t show_lssw(struct device *dev,
605 struct device_attribute *attr, char *buf)
606{
607 return sprintf(buf, "%d\n", hotk->light_switch);
608}
609
610static ssize_t store_lssw(struct device *dev, struct device_attribute *attr,
611 const char *buf, size_t count)
612{
613 int rv, value;
614
615 rv = parse_arg(buf, count, &value);
616 if (rv > 0)
617 set_light_sens_switch(value ? 1 : 0);
618
619 return rv;
620}
621
622static void set_light_sens_level(int value)
623{
624 if (!write_acpi_int(ls_level_handle, NULL, value, NULL))
625 printk(ASUS_WARNING "Error setting light sensor level\n");
626 hotk->light_level = value;
627}
628
629static ssize_t show_lslvl(struct device *dev,
630 struct device_attribute *attr, char *buf)
631{
632 return sprintf(buf, "%d\n", hotk->light_level);
633}
634
635static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
636 const char *buf, size_t count)
637{
638 int rv, value;
639
640 rv = parse_arg(buf, count, &value);
641 if (rv > 0) {
642 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
643 /* 0 <= value <= 15 */
644 set_light_sens_level(value);
645 }
646
647 return rv;
648}
649
Corentin Chary85091b72007-01-26 14:04:30 +0100650static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
651{
652 /* TODO Find a better way to handle events count. */
653 if (!hotk)
654 return;
655
Corentin Chary6b7091e2007-01-26 14:04:45 +0100656 /*
657 * We need to tell the backlight device when the backlight power is
658 * switched
659 */
660 if (event == ATKD_LCD_ON) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100661 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100662 lcd_blank(FB_BLANK_UNBLANK);
Len Brown8def05f2007-01-30 01:46:43 -0500663 } else if (event == ATKD_LCD_OFF) {
Corentin Chary935ffee2007-03-11 10:26:12 +0100664 write_status(NULL, 0, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100665 lcd_blank(FB_BLANK_POWERDOWN);
666 }
667
Corentin Chary85091b72007-01-26 14:04:30 +0100668 acpi_bus_generate_event(hotk->device, event,
669 hotk->event_count[event % 128]++);
670
671 return;
672}
673
674#define ASUS_CREATE_DEVICE_ATTR(_name) \
675 struct device_attribute dev_attr_##_name = { \
676 .attr = { \
677 .name = __stringify(_name), \
678 .mode = 0, \
679 .owner = THIS_MODULE }, \
680 .show = NULL, \
681 .store = NULL, \
682 }
683
684#define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \
685 do { \
686 dev_attr_##_name.attr.mode = _mode; \
687 dev_attr_##_name.show = _show; \
688 dev_attr_##_name.store = _store; \
689 } while(0)
690
691static ASUS_CREATE_DEVICE_ATTR(infos);
Corentin Chary4564de12007-01-26 14:04:40 +0100692static ASUS_CREATE_DEVICE_ATTR(wlan);
693static ASUS_CREATE_DEVICE_ATTR(bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100694static ASUS_CREATE_DEVICE_ATTR(display);
Corentin Chary722ad972007-01-26 14:04:55 +0100695static ASUS_CREATE_DEVICE_ATTR(ledd);
Corentin Chary8b857352007-01-26 14:04:58 +0100696static ASUS_CREATE_DEVICE_ATTR(ls_switch);
697static ASUS_CREATE_DEVICE_ATTR(ls_level);
Corentin Chary85091b72007-01-26 14:04:30 +0100698
699static struct attribute *asuspf_attributes[] = {
Len Brown8def05f2007-01-30 01:46:43 -0500700 &dev_attr_infos.attr,
701 &dev_attr_wlan.attr,
702 &dev_attr_bluetooth.attr,
703 &dev_attr_display.attr,
704 &dev_attr_ledd.attr,
705 &dev_attr_ls_switch.attr,
706 &dev_attr_ls_level.attr,
707 NULL
Corentin Chary85091b72007-01-26 14:04:30 +0100708};
709
710static struct attribute_group asuspf_attribute_group = {
Len Brown8def05f2007-01-30 01:46:43 -0500711 .attrs = asuspf_attributes
Corentin Chary85091b72007-01-26 14:04:30 +0100712};
713
714static struct platform_driver asuspf_driver = {
Len Brown8def05f2007-01-30 01:46:43 -0500715 .driver = {
716 .name = ASUS_HOTK_FILE,
717 .owner = THIS_MODULE,
718 }
Corentin Chary85091b72007-01-26 14:04:30 +0100719};
720
721static struct platform_device *asuspf_device;
722
Corentin Chary85091b72007-01-26 14:04:30 +0100723static void asus_hotk_add_fs(void)
724{
725 ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL);
Corentin Chary4564de12007-01-26 14:04:40 +0100726
727 if (wl_switch_handle)
728 ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan);
729
730 if (bt_switch_handle)
731 ASUS_SET_DEVICE_ATTR(bluetooth, 0644,
732 show_bluetooth, store_bluetooth);
Corentin Chary78127b42007-01-26 14:04:49 +0100733
734 if (display_set_handle && display_get_handle)
735 ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp);
Len Brown8def05f2007-01-30 01:46:43 -0500736 else if (display_set_handle)
Corentin Chary78127b42007-01-26 14:04:49 +0100737 ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp);
738
Corentin Chary722ad972007-01-26 14:04:55 +0100739 if (ledd_set_handle)
740 ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd);
741
Corentin Chary8b857352007-01-26 14:04:58 +0100742 if (ls_switch_handle && ls_level_handle) {
743 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
744 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
745 }
Corentin Chary85091b72007-01-26 14:04:30 +0100746}
747
Len Brown8def05f2007-01-30 01:46:43 -0500748static int asus_handle_init(char *name, acpi_handle * handle,
Corentin Chary85091b72007-01-26 14:04:30 +0100749 char **paths, int num_paths)
750{
751 int i;
752 acpi_status status;
753
754 for (i = 0; i < num_paths; i++) {
755 status = acpi_get_handle(NULL, paths[i], handle);
756 if (ACPI_SUCCESS(status))
757 return 0;
758 }
759
760 *handle = NULL;
761 return -ENODEV;
762}
763
764#define ASUS_HANDLE_INIT(object) \
765 asus_handle_init(#object, &object##_handle, object##_paths, \
766 ARRAY_SIZE(object##_paths))
767
Corentin Chary85091b72007-01-26 14:04:30 +0100768/*
769 * This function is used to initialize the hotk with right values. In this
770 * method, we can make all the detection we want, and modify the hotk struct
771 */
772static int asus_hotk_get_info(void)
773{
774 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Corentin Chary85091b72007-01-26 14:04:30 +0100775 union acpi_object *model = NULL;
Corentin Chary9a816852007-03-11 10:25:38 +0100776 ulong bsts_result, hwrs_result;
Corentin Chary85091b72007-01-26 14:04:30 +0100777 char *string = NULL;
778 acpi_status status;
779
780 /*
781 * Get DSDT headers early enough to allow for differentiating between
782 * models, but late enough to allow acpi_bus_register_driver() to fail
783 * before doing anything ACPI-specific. Should we encounter a machine,
784 * which needs special handling (i.e. its hotkey device has a different
785 * HID), this bit will be moved. A global variable asus_info contains
786 * the DSDT header.
787 */
Len Brown894d79b2007-02-03 02:13:53 -0500788 status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info);
Corentin Chary85091b72007-01-26 14:04:30 +0100789 if (ACPI_FAILURE(status))
790 printk(ASUS_WARNING "Couldn't get the DSDT table header\n");
Corentin Chary85091b72007-01-26 14:04:30 +0100791
792 /* We have to write 0 on init this far for all ASUS models */
793 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
794 printk(ASUS_ERR "Hotkey initialization failed\n");
795 return -ENODEV;
796 }
797
798 /* This needs to be called for some laptops to init properly */
Corentin Chary9a816852007-03-11 10:25:38 +0100799 status =
800 acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result);
801 if (ACPI_FAILURE(status))
Corentin Chary85091b72007-01-26 14:04:30 +0100802 printk(ASUS_WARNING "Error calling BSTS\n");
803 else if (bsts_result)
804 printk(ASUS_NOTICE "BSTS called, 0x%02x returned\n",
Corentin Chary9a816852007-03-11 10:25:38 +0100805 (uint) bsts_result);
Corentin Chary85091b72007-01-26 14:04:30 +0100806
807 /*
808 * Try to match the object returned by INIT to the specific model.
809 * Handle every possible object (or the lack of thereof) the DSDT
810 * writers might throw at us. When in trouble, we pass NULL to
811 * asus_model_match() and try something completely different.
812 */
813 if (buffer.pointer) {
814 model = buffer.pointer;
815 switch (model->type) {
816 case ACPI_TYPE_STRING:
817 string = model->string.pointer;
818 break;
819 case ACPI_TYPE_BUFFER:
820 string = model->buffer.pointer;
821 break;
822 default:
823 string = "";
824 break;
825 }
826 }
827 hotk->name = kstrdup(string, GFP_KERNEL);
828 if (!hotk->name)
829 return -ENOMEM;
830
Len Brown8def05f2007-01-30 01:46:43 -0500831 if (*string)
Corentin Chary85091b72007-01-26 14:04:30 +0100832 printk(ASUS_NOTICE " %s model detected\n", string);
833
Corentin Charybe18cda2007-01-26 14:04:35 +0100834 ASUS_HANDLE_INIT(mled_set);
835 ASUS_HANDLE_INIT(tled_set);
836 ASUS_HANDLE_INIT(rled_set);
837 ASUS_HANDLE_INIT(pled_set);
838
Corentin Chary722ad972007-01-26 14:04:55 +0100839 ASUS_HANDLE_INIT(ledd_set);
840
Corentin Chary4564de12007-01-26 14:04:40 +0100841 /*
842 * The HWRS method return informations about the hardware.
843 * 0x80 bit is for WLAN, 0x100 for Bluetooth.
844 * The significance of others is yet to be found.
845 * If we don't find the method, we assume the device are present.
846 */
Corentin Chary9a816852007-03-11 10:25:38 +0100847 status =
848 acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result);
849 if (ACPI_FAILURE(status))
Corentin Chary4564de12007-01-26 14:04:40 +0100850 hwrs_result = WL_HWRS | BT_HWRS;
851
Len Brown8def05f2007-01-30 01:46:43 -0500852 if (hwrs_result & WL_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +0100853 ASUS_HANDLE_INIT(wl_switch);
Len Brown8def05f2007-01-30 01:46:43 -0500854 if (hwrs_result & BT_HWRS)
Corentin Chary4564de12007-01-26 14:04:40 +0100855 ASUS_HANDLE_INIT(bt_switch);
856
857 ASUS_HANDLE_INIT(wireless_status);
858
Corentin Chary6b7091e2007-01-26 14:04:45 +0100859 ASUS_HANDLE_INIT(brightness_set);
860 ASUS_HANDLE_INIT(brightness_get);
861
862 ASUS_HANDLE_INIT(lcd_switch);
863
Corentin Chary78127b42007-01-26 14:04:49 +0100864 ASUS_HANDLE_INIT(display_set);
865 ASUS_HANDLE_INIT(display_get);
866
Corentin Chary8b857352007-01-26 14:04:58 +0100867 /* There is a lot of models with "ALSL", but a few get
868 a real light sens, so we need to check it. */
Len Brown8def05f2007-01-30 01:46:43 -0500869 if (ASUS_HANDLE_INIT(ls_switch))
Corentin Chary8b857352007-01-26 14:04:58 +0100870 ASUS_HANDLE_INIT(ls_level);
871
Corentin Chary85091b72007-01-26 14:04:30 +0100872 kfree(model);
873
874 return AE_OK;
875}
876
877static int asus_hotk_check(void)
878{
879 int result = 0;
880
881 result = acpi_bus_get_status(hotk->device);
882 if (result)
883 return result;
884
885 if (hotk->device->status.present) {
886 result = asus_hotk_get_info();
887 } else {
888 printk(ASUS_ERR "Hotkey device not present, aborting\n");
889 return -EINVAL;
890 }
891
892 return result;
893}
894
895static int asus_hotk_found;
896
897static int asus_hotk_add(struct acpi_device *device)
898{
899 acpi_status status = AE_OK;
900 int result;
901
902 if (!device)
903 return -EINVAL;
904
905 printk(ASUS_NOTICE "Asus Laptop Support version %s\n",
906 ASUS_LAPTOP_VERSION);
907
908 hotk = kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
909 if (!hotk)
910 return -ENOMEM;
911 memset(hotk, 0, sizeof(struct asus_hotk));
912
913 hotk->handle = device->handle;
914 strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME);
915 strcpy(acpi_device_class(device), ASUS_HOTK_CLASS);
916 acpi_driver_data(device) = hotk;
917 hotk->device = device;
918
919 result = asus_hotk_check();
920 if (result)
921 goto end;
922
923 asus_hotk_add_fs();
924
925 /*
926 * We install the handler, it will receive the hotk in parameter, so, we
927 * could add other data to the hotk struct
928 */
929 status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
930 asus_hotk_notify, hotk);
931 if (ACPI_FAILURE(status))
932 printk(ASUS_ERR "Error installing notify handler\n");
933
934 asus_hotk_found = 1;
935
Corentin Chary6b7091e2007-01-26 14:04:45 +0100936 /* WLED and BLED are on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +0100937 write_status(bt_switch_handle, 1, BT_ON);
938 write_status(wl_switch_handle, 1, WL_ON);
939
940 /* If the h/w switch is off, we need to check the real status */
941 write_status(NULL, read_status(BT_ON), BT_ON);
942 write_status(NULL, read_status(WL_ON), WL_ON);
Corentin Chary4564de12007-01-26 14:04:40 +0100943
Corentin Chary6b7091e2007-01-26 14:04:45 +0100944 /* LCD Backlight is on by default */
Corentin Chary935ffee2007-03-11 10:26:12 +0100945 write_status(NULL, 1, LCD_ON);
Corentin Chary6b7091e2007-01-26 14:04:45 +0100946
Corentin Chary722ad972007-01-26 14:04:55 +0100947 /* LED display is off by default */
948 hotk->ledd_status = 0xFFF;
949
Len Brown8def05f2007-01-30 01:46:43 -0500950 /* Set initial values of light sensor and level */
951 hotk->light_switch = 1; /* Default to light sensor disabled */
952 hotk->light_level = 0; /* level 5 for sensor sensitivity */
Corentin Chary8b857352007-01-26 14:04:58 +0100953
Len Brown8def05f2007-01-30 01:46:43 -0500954 if (ls_switch_handle)
955 set_light_sens_switch(hotk->light_switch);
Corentin Chary8b857352007-01-26 14:04:58 +0100956
Len Brown8def05f2007-01-30 01:46:43 -0500957 if (ls_level_handle)
958 set_light_sens_level(hotk->light_level);
Corentin Chary8b857352007-01-26 14:04:58 +0100959
Corentin Chary85091b72007-01-26 14:04:30 +0100960 end:
961 if (result) {
962 kfree(hotk->name);
963 kfree(hotk);
964 }
965
966 return result;
967}
968
969static int asus_hotk_remove(struct acpi_device *device, int type)
970{
971 acpi_status status = 0;
972
973 if (!device || !acpi_driver_data(device))
974 return -EINVAL;
975
976 status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
977 asus_hotk_notify);
978 if (ACPI_FAILURE(status))
979 printk(ASUS_ERR "Error removing notify handler\n");
980
981 kfree(hotk->name);
982 kfree(hotk);
983
984 return 0;
985}
986
Corentin Chary6b7091e2007-01-26 14:04:45 +0100987static void asus_backlight_exit(void)
988{
Len Brown8def05f2007-01-30 01:46:43 -0500989 if (asus_backlight_device)
Corentin Chary6b7091e2007-01-26 14:04:45 +0100990 backlight_device_unregister(asus_backlight_device);
991}
992
Corentin Charybe18cda2007-01-26 14:04:35 +0100993#define ASUS_LED_UNREGISTER(object) \
994 if(object##_led.class_dev \
995 && !IS_ERR(object##_led.class_dev)) \
996 led_classdev_unregister(&object##_led)
997
998static void asus_led_exit(void)
999{
1000 ASUS_LED_UNREGISTER(mled);
1001 ASUS_LED_UNREGISTER(tled);
1002 ASUS_LED_UNREGISTER(pled);
1003 ASUS_LED_UNREGISTER(rled);
1004
1005 destroy_workqueue(led_workqueue);
1006}
1007
Corentin Chary85091b72007-01-26 14:04:30 +01001008static void __exit asus_laptop_exit(void)
1009{
Corentin Chary6b7091e2007-01-26 14:04:45 +01001010 asus_backlight_exit();
Corentin Charybe18cda2007-01-26 14:04:35 +01001011 asus_led_exit();
1012
Corentin Chary85091b72007-01-26 14:04:30 +01001013 acpi_bus_unregister_driver(&asus_hotk_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001014 sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group);
1015 platform_device_unregister(asuspf_device);
1016 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001017}
1018
Len Brown8def05f2007-01-30 01:46:43 -05001019static int asus_backlight_init(struct device *dev)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001020{
1021 struct backlight_device *bd;
1022
Len Brown8def05f2007-01-30 01:46:43 -05001023 if (brightness_set_handle && lcd_switch_handle) {
1024 bd = backlight_device_register(ASUS_HOTK_FILE, dev,
Richard Purdie599a52d2007-02-10 23:07:48 +00001025 NULL, &asusbl_ops);
Len Brown8def05f2007-01-30 01:46:43 -05001026 if (IS_ERR(bd)) {
Corentin Chary6b7091e2007-01-26 14:04:45 +01001027 printk(ASUS_ERR
1028 "Could not register asus backlight device\n");
1029 asus_backlight_device = NULL;
1030 return PTR_ERR(bd);
1031 }
1032
1033 asus_backlight_device = bd;
1034
Richard Purdie599a52d2007-02-10 23:07:48 +00001035 bd->props.max_brightness = 15;
1036 bd->props.brightness = read_brightness(NULL);
1037 bd->props.power = FB_BLANK_UNBLANK;
Richard Purdie28ee0862007-02-08 22:25:09 +00001038 backlight_update_status(bd);
Corentin Chary6b7091e2007-01-26 14:04:45 +01001039 }
1040 return 0;
1041}
1042
Corentin Charybe18cda2007-01-26 14:04:35 +01001043static int asus_led_register(acpi_handle handle,
Len Brown8def05f2007-01-30 01:46:43 -05001044 struct led_classdev *ldev, struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001045{
Len Brown8def05f2007-01-30 01:46:43 -05001046 if (!handle)
Corentin Charybe18cda2007-01-26 14:04:35 +01001047 return 0;
1048
1049 return led_classdev_register(dev, ldev);
1050}
Len Brown8def05f2007-01-30 01:46:43 -05001051
Corentin Charybe18cda2007-01-26 14:04:35 +01001052#define ASUS_LED_REGISTER(object, device) \
1053 asus_led_register(object##_set_handle, &object##_led, device)
1054
Len Brown8def05f2007-01-30 01:46:43 -05001055static int asus_led_init(struct device *dev)
Corentin Charybe18cda2007-01-26 14:04:35 +01001056{
1057 int rv;
1058
1059 rv = ASUS_LED_REGISTER(mled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001060 if (rv)
Corentin Charybe18cda2007-01-26 14:04:35 +01001061 return rv;
1062
1063 rv = ASUS_LED_REGISTER(tled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001064 if (rv)
Corentin Charybe18cda2007-01-26 14:04:35 +01001065 return rv;
1066
1067 rv = ASUS_LED_REGISTER(rled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001068 if (rv)
Corentin Charybe18cda2007-01-26 14:04:35 +01001069 return rv;
1070
1071 rv = ASUS_LED_REGISTER(pled, dev);
Len Brown8def05f2007-01-30 01:46:43 -05001072 if (rv)
Corentin Charybe18cda2007-01-26 14:04:35 +01001073 return rv;
1074
1075 led_workqueue = create_singlethread_workqueue("led_workqueue");
Len Brown8def05f2007-01-30 01:46:43 -05001076 if (!led_workqueue)
Corentin Charybe18cda2007-01-26 14:04:35 +01001077 return -ENOMEM;
1078
1079 return 0;
1080}
1081
Corentin Chary85091b72007-01-26 14:04:30 +01001082static int __init asus_laptop_init(void)
1083{
Corentin Charybe18cda2007-01-26 14:04:35 +01001084 struct device *dev;
Corentin Chary85091b72007-01-26 14:04:30 +01001085 int result;
1086
1087 if (acpi_disabled)
1088 return -ENODEV;
1089
Corentin Chary85091b72007-01-26 14:04:30 +01001090 result = acpi_bus_register_driver(&asus_hotk_driver);
1091 if (result < 0)
1092 return result;
1093
1094 /*
1095 * This is a bit of a kludge. We only want this module loaded
1096 * for ASUS systems, but there's currently no way to probe the
1097 * ACPI namespace for ASUS HIDs. So we just return failure if
1098 * we didn't find one, which will cause the module to be
1099 * unloaded.
1100 */
1101 if (!asus_hotk_found) {
1102 acpi_bus_unregister_driver(&asus_hotk_driver);
1103 return -ENODEV;
1104 }
1105
Corentin Charybe18cda2007-01-26 14:04:35 +01001106 dev = acpi_get_physical_device(hotk->device->handle);
1107
Corentin Chary6b7091e2007-01-26 14:04:45 +01001108 result = asus_backlight_init(dev);
Len Brown8def05f2007-01-30 01:46:43 -05001109 if (result)
Corentin Chary6b7091e2007-01-26 14:04:45 +01001110 goto fail_backlight;
1111
Corentin Charybe18cda2007-01-26 14:04:35 +01001112 result = asus_led_init(dev);
Len Brown8def05f2007-01-30 01:46:43 -05001113 if (result)
Corentin Charybe18cda2007-01-26 14:04:35 +01001114 goto fail_led;
1115
Len Brown8def05f2007-01-30 01:46:43 -05001116 /* Register platform stuff */
Corentin Chary85091b72007-01-26 14:04:30 +01001117 result = platform_driver_register(&asuspf_driver);
Len Brown8def05f2007-01-30 01:46:43 -05001118 if (result)
1119 goto fail_platform_driver;
Corentin Chary85091b72007-01-26 14:04:30 +01001120
Len Brown8def05f2007-01-30 01:46:43 -05001121 asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1);
1122 if (!asuspf_device) {
1123 result = -ENOMEM;
1124 goto fail_platform_device1;
1125 }
Corentin Chary85091b72007-01-26 14:04:30 +01001126
Len Brown8def05f2007-01-30 01:46:43 -05001127 result = platform_device_add(asuspf_device);
1128 if (result)
1129 goto fail_platform_device2;
Corentin Chary85091b72007-01-26 14:04:30 +01001130
Len Brown8def05f2007-01-30 01:46:43 -05001131 result = sysfs_create_group(&asuspf_device->dev.kobj,
Corentin Chary85091b72007-01-26 14:04:30 +01001132 &asuspf_attribute_group);
Len Brown8def05f2007-01-30 01:46:43 -05001133 if (result)
1134 goto fail_sysfs;
Corentin Chary85091b72007-01-26 14:04:30 +01001135
Len Brown8def05f2007-01-30 01:46:43 -05001136 return 0;
Corentin Chary85091b72007-01-26 14:04:30 +01001137
Len Brown8def05f2007-01-30 01:46:43 -05001138 fail_sysfs:
1139 platform_device_del(asuspf_device);
Corentin Chary85091b72007-01-26 14:04:30 +01001140
Len Brown8def05f2007-01-30 01:46:43 -05001141 fail_platform_device2:
Corentin Chary85091b72007-01-26 14:04:30 +01001142 platform_device_put(asuspf_device);
1143
Len Brown8def05f2007-01-30 01:46:43 -05001144 fail_platform_device1:
1145 platform_driver_unregister(&asuspf_driver);
Corentin Chary85091b72007-01-26 14:04:30 +01001146
Len Brown8def05f2007-01-30 01:46:43 -05001147 fail_platform_driver:
Corentin Charybe18cda2007-01-26 14:04:35 +01001148 asus_led_exit();
1149
Len Brown8def05f2007-01-30 01:46:43 -05001150 fail_led:
Corentin Chary6b7091e2007-01-26 14:04:45 +01001151 asus_backlight_exit();
1152
Len Brown8def05f2007-01-30 01:46:43 -05001153 fail_backlight:
Corentin Chary85091b72007-01-26 14:04:30 +01001154
1155 return result;
1156}
1157
1158module_init(asus_laptop_init);
1159module_exit(asus_laptop_exit);