Commit | Line | Data |
---|---|---|
85091b71 CC |
1 | /* |
2 | * asus-laptop.c - Asus Laptop Support | |
3 | * | |
4 | * | |
5 | * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor | |
8ec555c2 | 6 | * Copyright (C) 2006-2007 Corentin Chary |
85091b71 CC |
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 | |
e539c2f6 | 33 | * Sam Lin - GPS support |
85091b71 CC |
34 | */ |
35 | ||
85091b71 CC |
36 | #include <linux/kernel.h> |
37 | #include <linux/module.h> | |
38 | #include <linux/init.h> | |
39 | #include <linux/types.h> | |
40 | #include <linux/err.h> | |
41 | #include <linux/proc_fs.h> | |
6b7091e7 CC |
42 | #include <linux/backlight.h> |
43 | #include <linux/fb.h> | |
be18cdab | 44 | #include <linux/leds.h> |
85091b71 CC |
45 | #include <linux/platform_device.h> |
46 | #include <acpi/acpi_drivers.h> | |
47 | #include <acpi/acpi_bus.h> | |
48 | #include <asm/uaccess.h> | |
49 | ||
f3985327 | 50 | #define ASUS_LAPTOP_VERSION "0.42" |
85091b71 CC |
51 | |
52 | #define ASUS_HOTK_NAME "Asus Laptop Support" | |
53 | #define ASUS_HOTK_CLASS "hotkey" | |
54 | #define ASUS_HOTK_DEVICE_NAME "Hotkey" | |
85091b71 CC |
55 | #define ASUS_HOTK_FILE "asus-laptop" |
56 | #define ASUS_HOTK_PREFIX "\\_SB.ATKD." | |
57 | ||
6b7091e7 CC |
58 | /* |
59 | * Some events we use, same for all Asus | |
60 | */ | |
61 | #define ATKD_BR_UP 0x10 | |
62 | #define ATKD_BR_DOWN 0x20 | |
63 | #define ATKD_LCD_ON 0x33 | |
64 | #define ATKD_LCD_OFF 0x34 | |
65 | ||
4564de17 CC |
66 | /* |
67 | * Known bits returned by \_SB.ATKD.HWRS | |
68 | */ | |
69 | #define WL_HWRS 0x80 | |
70 | #define BT_HWRS 0x100 | |
71 | ||
be18cdab CC |
72 | /* |
73 | * Flags for hotk status | |
4564de17 | 74 | * WL_ON and BT_ON are also used for wireless_status() |
be18cdab | 75 | */ |
4564de17 CC |
76 | #define WL_ON 0x01 //internal Wifi |
77 | #define BT_ON 0x02 //internal Bluetooth | |
be18cdab CC |
78 | #define MLED_ON 0x04 //mail LED |
79 | #define TLED_ON 0x08 //touchpad LED | |
8def05fa LB |
80 | #define RLED_ON 0x10 //Record LED |
81 | #define PLED_ON 0x20 //Phone LED | |
fdd8d080 CC |
82 | #define GLED_ON 0x40 //Gaming LED |
83 | #define LCD_ON 0x80 //LCD backlight | |
f3985327 | 84 | #define GPS_ON 0x100 //GPS |
be18cdab | 85 | |
85091b71 CC |
86 | #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 | ||
93 | MODULE_AUTHOR("Julien Lerouge, Karol Kozimor, Corentin Chary"); | |
94 | MODULE_DESCRIPTION(ASUS_HOTK_NAME); | |
95 | MODULE_LICENSE("GPL"); | |
96 | ||
185e5af9 CC |
97 | /* WAPF defines the behavior of the Fn+Fx wlan key |
98 | * The significance of values is yet to be found, but | |
99 | * most of the time: | |
100 | * 0x0 will do nothing | |
101 | * 0x1 will allow to control the device with Fn+Fx key. | |
102 | * 0x4 will send an ACPI event (0x88) while pressing the Fn+Fx key | |
103 | * 0x5 like 0x1 or 0x4 | |
104 | * So, if something doesn't work as you want, just try other values =) | |
105 | */ | |
106 | static uint wapf = 1; | |
107 | module_param(wapf, uint, 0644); | |
108 | MODULE_PARM_DESC(wapf, "WAPF value"); | |
109 | ||
85091b71 CC |
110 | #define ASUS_HANDLE(object, paths...) \ |
111 | static acpi_handle object##_handle = NULL; \ | |
112 | static char *object##_paths[] = { paths } | |
113 | ||
be18cdab CC |
114 | /* LED */ |
115 | ASUS_HANDLE(mled_set, ASUS_HOTK_PREFIX "MLED"); | |
116 | ASUS_HANDLE(tled_set, ASUS_HOTK_PREFIX "TLED"); | |
8def05fa LB |
117 | ASUS_HANDLE(rled_set, ASUS_HOTK_PREFIX "RLED"); /* W1JC */ |
118 | ASUS_HANDLE(pled_set, ASUS_HOTK_PREFIX "PLED"); /* A7J */ | |
fdd8d080 | 119 | ASUS_HANDLE(gled_set, ASUS_HOTK_PREFIX "GLED"); /* G1, G2 (probably) */ |
be18cdab | 120 | |
722ad971 CC |
121 | /* LEDD */ |
122 | ASUS_HANDLE(ledd_set, ASUS_HOTK_PREFIX "SLCM"); | |
123 | ||
4564de17 CC |
124 | /* Bluetooth and WLAN |
125 | * WLED and BLED are not handled like other XLED, because in some dsdt | |
126 | * they also control the WLAN/Bluetooth device. | |
127 | */ | |
128 | ASUS_HANDLE(wl_switch, ASUS_HOTK_PREFIX "WLED"); | |
129 | ASUS_HANDLE(bt_switch, ASUS_HOTK_PREFIX "BLED"); | |
8def05fa | 130 | ASUS_HANDLE(wireless_status, ASUS_HOTK_PREFIX "RSTS"); /* All new models */ |
4564de17 | 131 | |
6b7091e7 CC |
132 | /* Brightness */ |
133 | ASUS_HANDLE(brightness_set, ASUS_HOTK_PREFIX "SPLV"); | |
134 | ASUS_HANDLE(brightness_get, ASUS_HOTK_PREFIX "GPLV"); | |
135 | ||
136 | /* Backlight */ | |
8def05fa LB |
137 | ASUS_HANDLE(lcd_switch, "\\_SB.PCI0.SBRG.EC0._Q10", /* All new models */ |
138 | "\\_SB.PCI0.ISA.EC0._Q10", /* A1x */ | |
139 | "\\_SB.PCI0.PX40.ECD0._Q10", /* L3C */ | |
140 | "\\_SB.PCI0.PX40.EC0.Q10", /* M1A */ | |
141 | "\\_SB.PCI0.LPCB.EC0._Q10", /* P30 */ | |
4d0b856e | 142 | "\\_SB.PCI0.LPCB.EC0._Q0E", /* P30/P35 */ |
8def05fa LB |
143 | "\\_SB.PCI0.PX40.Q10", /* S1x */ |
144 | "\\Q10"); /* A2x, L2D, L3D, M2E */ | |
6b7091e7 | 145 | |
78127b4a CC |
146 | /* Display */ |
147 | ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP"); | |
8def05fa LB |
148 | ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD", /* A6B, A6K A6R A7D F3JM L4R M6R A3G |
149 | M6A M6V VX-1 V6J V6V W3Z */ | |
150 | "\\_SB.PCI0.P0P2.VGA.GETD", /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V | |
f3985327 | 151 | S5A M5A z33A W1Jc W2V G1 */ |
8def05fa LB |
152 | "\\_SB.PCI0.P0P3.VGA.GETD", /* A6V A6Q */ |
153 | "\\_SB.PCI0.P0PA.VGA.GETD", /* A6T, A6M */ | |
154 | "\\_SB.PCI0.PCI1.VGAC.NMAP", /* L3C */ | |
155 | "\\_SB.PCI0.VGA.GETD", /* Z96F */ | |
156 | "\\ACTD", /* A2D */ | |
157 | "\\ADVG", /* A4G Z71A W1N W5A W5F M2N M3N M5N M6N S1N S5N */ | |
158 | "\\DNXT", /* P30 */ | |
159 | "\\INFB", /* A2H D1 L2D L3D L3H L2E L5D L5C M1A M2E L4L W3V */ | |
160 | "\\SSTE"); /* A3F A6F A3N A3L M6N W3N W6A */ | |
161 | ||
162 | ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */ | |
163 | ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */ | |
8b857353 | 164 | |
e539c2f6 CC |
165 | /* GPS */ |
166 | /* R2H use different handle for GPS on/off */ | |
f3985327 CC |
167 | ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON"); /* R2H */ |
168 | ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */ | |
e539c2f6 CC |
169 | ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST"); |
170 | ||
85091b71 CC |
171 | /* |
172 | * This is the main structure, we can use it to store anything interesting | |
173 | * about the hotk device | |
174 | */ | |
175 | struct asus_hotk { | |
8def05fa | 176 | char *name; //laptop name |
85091b71 CC |
177 | struct acpi_device *device; //the device we are in |
178 | acpi_handle handle; //the handle of the hotk device | |
179 | char status; //status of the hotk, for LEDs, ... | |
722ad971 | 180 | u32 ledd_status; //status of the LED display |
8def05fa LB |
181 | u8 light_level; //light sensor level |
182 | u8 light_switch; //light sensor switch value | |
85091b71 CC |
183 | u16 event_count[128]; //count for each event TODO make this better |
184 | }; | |
185 | ||
186 | /* | |
187 | * This header is made available to allow proper configuration given model, | |
188 | * revision number , ... this info cannot go in struct asus_hotk because it is | |
189 | * available before the hotk | |
190 | */ | |
191 | static struct acpi_table_header *asus_info; | |
192 | ||
193 | /* The actual device the driver binds to */ | |
194 | static struct asus_hotk *hotk; | |
195 | ||
196 | /* | |
197 | * The hotkey driver declaration | |
198 | */ | |
1ba90e3a TR |
199 | static const struct acpi_device_id asus_device_ids[] = { |
200 | {"ATK0100", 0}, | |
201 | {"", 0}, | |
202 | }; | |
203 | MODULE_DEVICE_TABLE(acpi, asus_device_ids); | |
204 | ||
85091b71 CC |
205 | static int asus_hotk_add(struct acpi_device *device); |
206 | static int asus_hotk_remove(struct acpi_device *device, int type); | |
207 | static struct acpi_driver asus_hotk_driver = { | |
208 | .name = ASUS_HOTK_NAME, | |
209 | .class = ASUS_HOTK_CLASS, | |
1ba90e3a | 210 | .ids = asus_device_ids, |
85091b71 CC |
211 | .ops = { |
212 | .add = asus_hotk_add, | |
213 | .remove = asus_hotk_remove, | |
214 | }, | |
215 | }; | |
216 | ||
6b7091e7 CC |
217 | /* The backlight device /sys/class/backlight */ |
218 | static struct backlight_device *asus_backlight_device; | |
219 | ||
220 | /* | |
221 | * The backlight class declaration | |
222 | */ | |
223 | static int read_brightness(struct backlight_device *bd); | |
224 | static int update_bl_status(struct backlight_device *bd); | |
599a52d1 | 225 | static struct backlight_ops asusbl_ops = { |
8def05fa LB |
226 | .get_brightness = read_brightness, |
227 | .update_status = update_bl_status, | |
6b7091e7 CC |
228 | }; |
229 | ||
be18cdab CC |
230 | /* These functions actually update the LED's, and are called from a |
231 | * workqueue. By doing this as separate work rather than when the LED | |
232 | * subsystem asks, we avoid messing with the Asus ACPI stuff during a | |
233 | * potentially bad time, such as a timer interrupt. */ | |
234 | static struct workqueue_struct *led_workqueue; | |
235 | ||
236 | #define ASUS_LED(object, ledname) \ | |
237 | static void object##_led_set(struct led_classdev *led_cdev, \ | |
238 | enum led_brightness value); \ | |
239 | static void object##_led_update(struct work_struct *ignored); \ | |
240 | static int object##_led_wk; \ | |
f110ef58 | 241 | static DECLARE_WORK(object##_led_work, object##_led_update); \ |
be18cdab | 242 | static struct led_classdev object##_led = { \ |
6c152bee | 243 | .name = "asus::" ledname, \ |
be18cdab CC |
244 | .brightness_set = object##_led_set, \ |
245 | } | |
246 | ||
247 | ASUS_LED(mled, "mail"); | |
248 | ASUS_LED(tled, "touchpad"); | |
249 | ASUS_LED(rled, "record"); | |
250 | ASUS_LED(pled, "phone"); | |
fdd8d080 | 251 | ASUS_LED(gled, "gaming"); |
be18cdab | 252 | |
85091b71 CC |
253 | /* |
254 | * This function evaluates an ACPI method, given an int as parameter, the | |
255 | * method is searched within the scope of the handle, can be NULL. The output | |
256 | * of the method is written is output, which can also be NULL | |
257 | * | |
f8d1c94b | 258 | * returns 0 if write is successful, -1 else. |
85091b71 CC |
259 | */ |
260 | static int write_acpi_int(acpi_handle handle, const char *method, int val, | |
261 | struct acpi_buffer *output) | |
262 | { | |
263 | struct acpi_object_list params; //list of input parameters (an int here) | |
264 | union acpi_object in_obj; //the only param we use | |
265 | acpi_status status; | |
266 | ||
f8d1c94b CC |
267 | if (!handle) |
268 | return 0; | |
269 | ||
85091b71 CC |
270 | params.count = 1; |
271 | params.pointer = &in_obj; | |
272 | in_obj.type = ACPI_TYPE_INTEGER; | |
273 | in_obj.integer.value = val; | |
274 | ||
275 | status = acpi_evaluate_object(handle, (char *)method, ¶ms, output); | |
f8d1c94b CC |
276 | if (status == AE_OK) |
277 | return 0; | |
278 | else | |
279 | return -1; | |
85091b71 CC |
280 | } |
281 | ||
8def05fa LB |
282 | static int read_wireless_status(int mask) |
283 | { | |
27663c58 | 284 | unsigned long long status; |
9a816850 | 285 | acpi_status rv = AE_OK; |
4564de17 CC |
286 | |
287 | if (!wireless_status_handle) | |
288 | return (hotk->status & mask) ? 1 : 0; | |
289 | ||
9a816850 CC |
290 | rv = acpi_evaluate_integer(wireless_status_handle, NULL, NULL, &status); |
291 | if (ACPI_FAILURE(rv)) | |
4564de17 | 292 | printk(ASUS_WARNING "Error reading Wireless status\n"); |
9a816850 CC |
293 | else |
294 | return (status & mask) ? 1 : 0; | |
4564de17 CC |
295 | |
296 | return (hotk->status & mask) ? 1 : 0; | |
297 | } | |
298 | ||
f3985327 CC |
299 | static int read_gps_status(void) |
300 | { | |
27663c58 | 301 | unsigned long long status; |
e539c2f6 CC |
302 | acpi_status rv = AE_OK; |
303 | ||
304 | rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status); | |
305 | if (ACPI_FAILURE(rv)) | |
f3985327 | 306 | printk(ASUS_WARNING "Error reading GPS status\n"); |
e539c2f6 | 307 | else |
f3985327 | 308 | return status ? 1 : 0; |
e539c2f6 | 309 | |
f3985327 | 310 | return (hotk->status & GPS_ON) ? 1 : 0; |
e539c2f6 CC |
311 | } |
312 | ||
be18cdab CC |
313 | /* Generic LED functions */ |
314 | static int read_status(int mask) | |
315 | { | |
4564de17 CC |
316 | /* There is a special method for both wireless devices */ |
317 | if (mask == BT_ON || mask == WL_ON) | |
318 | return read_wireless_status(mask); | |
f3985327 CC |
319 | else if (mask == GPS_ON) |
320 | return read_gps_status(); | |
4564de17 | 321 | |
be18cdab CC |
322 | return (hotk->status & mask) ? 1 : 0; |
323 | } | |
324 | ||
935ffeec | 325 | static void write_status(acpi_handle handle, int out, int mask) |
be18cdab CC |
326 | { |
327 | hotk->status = (out) ? (hotk->status | mask) : (hotk->status & ~mask); | |
328 | ||
935ffeec CC |
329 | switch (mask) { |
330 | case MLED_ON: | |
e1af14e4 | 331 | out = !(out & 0x1); |
935ffeec | 332 | break; |
fdd8d080 CC |
333 | case GLED_ON: |
334 | out = (out & 0x1) + 1; | |
335 | break; | |
e539c2f6 CC |
336 | case GPS_ON: |
337 | handle = (out) ? gps_on_handle : gps_off_handle; | |
338 | out = 0x02; | |
339 | break; | |
935ffeec CC |
340 | default: |
341 | out &= 0x1; | |
342 | break; | |
343 | } | |
be18cdab | 344 | |
f8d1c94b | 345 | if (write_acpi_int(handle, NULL, out, NULL)) |
935ffeec | 346 | printk(ASUS_WARNING " write failed %x\n", mask); |
be18cdab CC |
347 | } |
348 | ||
349 | /* /sys/class/led handlers */ | |
935ffeec | 350 | #define ASUS_LED_HANDLER(object, mask) \ |
be18cdab CC |
351 | static void object##_led_set(struct led_classdev *led_cdev, \ |
352 | enum led_brightness value) \ | |
353 | { \ | |
e3deda9c | 354 | object##_led_wk = (value > 0) ? 1 : 0; \ |
be18cdab CC |
355 | queue_work(led_workqueue, &object##_led_work); \ |
356 | } \ | |
357 | static void object##_led_update(struct work_struct *ignored) \ | |
358 | { \ | |
359 | int value = object##_led_wk; \ | |
935ffeec | 360 | write_status(object##_set_handle, value, (mask)); \ |
be18cdab CC |
361 | } |
362 | ||
935ffeec CC |
363 | ASUS_LED_HANDLER(mled, MLED_ON); |
364 | ASUS_LED_HANDLER(pled, PLED_ON); | |
365 | ASUS_LED_HANDLER(rled, RLED_ON); | |
366 | ASUS_LED_HANDLER(tled, TLED_ON); | |
fdd8d080 | 367 | ASUS_LED_HANDLER(gled, GLED_ON); |
be18cdab | 368 | |
6b7091e7 CC |
369 | static int get_lcd_state(void) |
370 | { | |
371 | return read_status(LCD_ON); | |
372 | } | |
373 | ||
374 | static int set_lcd_state(int value) | |
375 | { | |
376 | int lcd = 0; | |
377 | acpi_status status = 0; | |
378 | ||
379 | lcd = value ? 1 : 0; | |
380 | ||
381 | if (lcd == get_lcd_state()) | |
382 | return 0; | |
383 | ||
8def05fa | 384 | if (lcd_switch_handle) { |
6b7091e7 CC |
385 | status = acpi_evaluate_object(lcd_switch_handle, |
386 | NULL, NULL, NULL); | |
387 | ||
388 | if (ACPI_FAILURE(status)) | |
389 | printk(ASUS_WARNING "Error switching LCD\n"); | |
390 | } | |
391 | ||
935ffeec | 392 | write_status(NULL, lcd, LCD_ON); |
6b7091e7 CC |
393 | return 0; |
394 | } | |
395 | ||
396 | static void lcd_blank(int blank) | |
397 | { | |
398 | struct backlight_device *bd = asus_backlight_device; | |
399 | ||
8def05fa | 400 | if (bd) { |
599a52d1 | 401 | bd->props.power = blank; |
28ee086d | 402 | backlight_update_status(bd); |
6b7091e7 CC |
403 | } |
404 | } | |
405 | ||
406 | static int read_brightness(struct backlight_device *bd) | |
407 | { | |
27663c58 | 408 | unsigned long long value; |
9a816850 | 409 | acpi_status rv = AE_OK; |
6b7091e7 | 410 | |
9a816850 CC |
411 | rv = acpi_evaluate_integer(brightness_get_handle, NULL, NULL, &value); |
412 | if (ACPI_FAILURE(rv)) | |
6b7091e7 CC |
413 | printk(ASUS_WARNING "Error reading brightness\n"); |
414 | ||
415 | return value; | |
416 | } | |
417 | ||
418 | static int set_brightness(struct backlight_device *bd, int value) | |
419 | { | |
420 | int ret = 0; | |
421 | ||
422 | value = (0 < value) ? ((15 < value) ? 15 : value) : 0; | |
423 | /* 0 <= value <= 15 */ | |
424 | ||
f8d1c94b | 425 | if (write_acpi_int(brightness_set_handle, NULL, value, NULL)) { |
6b7091e7 CC |
426 | printk(ASUS_WARNING "Error changing brightness\n"); |
427 | ret = -EIO; | |
428 | } | |
429 | ||
430 | return ret; | |
431 | } | |
432 | ||
433 | static int update_bl_status(struct backlight_device *bd) | |
434 | { | |
435 | int rv; | |
599a52d1 | 436 | int value = bd->props.brightness; |
6b7091e7 CC |
437 | |
438 | rv = set_brightness(bd, value); | |
8def05fa | 439 | if (rv) |
6b7091e7 CC |
440 | return rv; |
441 | ||
599a52d1 | 442 | value = (bd->props.power == FB_BLANK_UNBLANK) ? 1 : 0; |
6b7091e7 CC |
443 | return set_lcd_state(value); |
444 | } | |
445 | ||
85091b71 CC |
446 | /* |
447 | * Platform device handlers | |
448 | */ | |
449 | ||
450 | /* | |
451 | * We write our info in page, we begin at offset off and cannot write more | |
452 | * than count bytes. We set eof to 1 if we handle those 2 values. We return the | |
453 | * number of bytes written in page | |
454 | */ | |
455 | static ssize_t show_infos(struct device *dev, | |
8def05fa | 456 | struct device_attribute *attr, char *page) |
85091b71 CC |
457 | { |
458 | int len = 0; | |
27663c58 | 459 | unsigned long long temp; |
85091b71 | 460 | char buf[16]; //enough for all info |
9a816850 CC |
461 | acpi_status rv = AE_OK; |
462 | ||
85091b71 CC |
463 | /* |
464 | * We use the easy way, we don't care of off and count, so we don't set eof | |
465 | * to 1 | |
466 | */ | |
467 | ||
468 | len += sprintf(page, ASUS_HOTK_NAME " " ASUS_LAPTOP_VERSION "\n"); | |
469 | len += sprintf(page + len, "Model reference : %s\n", hotk->name); | |
470 | /* | |
471 | * The SFUN method probably allows the original driver to get the list | |
472 | * of features supported by a given model. For now, 0x0100 or 0x0800 | |
473 | * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card. | |
474 | * The significance of others is yet to be found. | |
475 | */ | |
9a816850 CC |
476 | rv = acpi_evaluate_integer(hotk->handle, "SFUN", NULL, &temp); |
477 | if (!ACPI_FAILURE(rv)) | |
478 | len += sprintf(page + len, "SFUN value : 0x%04x\n", | |
479 | (uint) temp); | |
85091b71 CC |
480 | /* |
481 | * Another value for userspace: the ASYM method returns 0x02 for | |
482 | * battery low and 0x04 for battery critical, its readings tend to be | |
483 | * more accurate than those provided by _BST. | |
484 | * Note: since not all the laptops provide this method, errors are | |
485 | * silently ignored. | |
486 | */ | |
9a816850 CC |
487 | rv = acpi_evaluate_integer(hotk->handle, "ASYM", NULL, &temp); |
488 | if (!ACPI_FAILURE(rv)) | |
489 | len += sprintf(page + len, "ASYM value : 0x%04x\n", | |
490 | (uint) temp); | |
85091b71 CC |
491 | if (asus_info) { |
492 | snprintf(buf, 16, "%d", asus_info->length); | |
493 | len += sprintf(page + len, "DSDT length : %s\n", buf); | |
494 | snprintf(buf, 16, "%d", asus_info->checksum); | |
495 | len += sprintf(page + len, "DSDT checksum : %s\n", buf); | |
496 | snprintf(buf, 16, "%d", asus_info->revision); | |
497 | len += sprintf(page + len, "DSDT revision : %s\n", buf); | |
498 | snprintf(buf, 7, "%s", asus_info->oem_id); | |
499 | len += sprintf(page + len, "OEM id : %s\n", buf); | |
500 | snprintf(buf, 9, "%s", asus_info->oem_table_id); | |
501 | len += sprintf(page + len, "OEM table id : %s\n", buf); | |
502 | snprintf(buf, 16, "%x", asus_info->oem_revision); | |
503 | len += sprintf(page + len, "OEM revision : 0x%s\n", buf); | |
504 | snprintf(buf, 5, "%s", asus_info->asl_compiler_id); | |
505 | len += sprintf(page + len, "ASL comp vendor id : %s\n", buf); | |
506 | snprintf(buf, 16, "%x", asus_info->asl_compiler_revision); | |
507 | len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf); | |
508 | } | |
509 | ||
510 | return len; | |
511 | } | |
512 | ||
513 | static int parse_arg(const char *buf, unsigned long count, int *val) | |
514 | { | |
515 | if (!count) | |
516 | return 0; | |
517 | if (count > 31) | |
518 | return -EINVAL; | |
519 | if (sscanf(buf, "%i", val) != 1) | |
520 | return -EINVAL; | |
521 | return count; | |
522 | } | |
523 | ||
4564de17 | 524 | static ssize_t store_status(const char *buf, size_t count, |
935ffeec | 525 | acpi_handle handle, int mask) |
4564de17 CC |
526 | { |
527 | int rv, value; | |
528 | int out = 0; | |
529 | ||
530 | rv = parse_arg(buf, count, &value); | |
531 | if (rv > 0) | |
532 | out = value ? 1 : 0; | |
533 | ||
935ffeec | 534 | write_status(handle, out, mask); |
4564de17 CC |
535 | |
536 | return rv; | |
537 | } | |
538 | ||
722ad971 CC |
539 | /* |
540 | * LEDD display | |
541 | */ | |
542 | static ssize_t show_ledd(struct device *dev, | |
543 | struct device_attribute *attr, char *buf) | |
544 | { | |
545 | return sprintf(buf, "0x%08x\n", hotk->ledd_status); | |
546 | } | |
547 | ||
548 | static ssize_t store_ledd(struct device *dev, struct device_attribute *attr, | |
549 | const char *buf, size_t count) | |
550 | { | |
551 | int rv, value; | |
552 | ||
553 | rv = parse_arg(buf, count, &value); | |
554 | if (rv > 0) { | |
f8d1c94b | 555 | if (write_acpi_int(ledd_set_handle, NULL, value, NULL)) |
722ad971 CC |
556 | printk(ASUS_WARNING "LED display write failed\n"); |
557 | else | |
558 | hotk->ledd_status = (u32) value; | |
559 | } | |
560 | return rv; | |
561 | } | |
562 | ||
4564de17 CC |
563 | /* |
564 | * WLAN | |
565 | */ | |
566 | static ssize_t show_wlan(struct device *dev, | |
567 | struct device_attribute *attr, char *buf) | |
568 | { | |
569 | return sprintf(buf, "%d\n", read_status(WL_ON)); | |
570 | } | |
571 | ||
572 | static ssize_t store_wlan(struct device *dev, struct device_attribute *attr, | |
573 | const char *buf, size_t count) | |
574 | { | |
935ffeec | 575 | return store_status(buf, count, wl_switch_handle, WL_ON); |
4564de17 CC |
576 | } |
577 | ||
578 | /* | |
579 | * Bluetooth | |
580 | */ | |
581 | static ssize_t show_bluetooth(struct device *dev, | |
582 | struct device_attribute *attr, char *buf) | |
583 | { | |
584 | return sprintf(buf, "%d\n", read_status(BT_ON)); | |
585 | } | |
586 | ||
8def05fa LB |
587 | static ssize_t store_bluetooth(struct device *dev, |
588 | struct device_attribute *attr, const char *buf, | |
589 | size_t count) | |
4564de17 | 590 | { |
935ffeec | 591 | return store_status(buf, count, bt_switch_handle, BT_ON); |
4564de17 CC |
592 | } |
593 | ||
78127b4a CC |
594 | /* |
595 | * Display | |
596 | */ | |
597 | static void set_display(int value) | |
598 | { | |
599 | /* no sanity check needed for now */ | |
f8d1c94b | 600 | if (write_acpi_int(display_set_handle, NULL, value, NULL)) |
78127b4a CC |
601 | printk(ASUS_WARNING "Error setting display\n"); |
602 | return; | |
603 | } | |
604 | ||
605 | static int read_display(void) | |
606 | { | |
27663c58 | 607 | unsigned long long value = 0; |
9a816850 | 608 | acpi_status rv = AE_OK; |
78127b4a CC |
609 | |
610 | /* In most of the case, we know how to set the display, but sometime | |
611 | we can't read it */ | |
8def05fa | 612 | if (display_get_handle) { |
9a816850 CC |
613 | rv = acpi_evaluate_integer(display_get_handle, NULL, |
614 | NULL, &value); | |
615 | if (ACPI_FAILURE(rv)) | |
78127b4a CC |
616 | printk(ASUS_WARNING "Error reading display status\n"); |
617 | } | |
618 | ||
619 | value &= 0x0F; /* needed for some models, shouldn't hurt others */ | |
620 | ||
621 | return value; | |
622 | } | |
8def05fa | 623 | |
78127b4a CC |
624 | /* |
625 | * Now, *this* one could be more user-friendly, but so far, no-one has | |
626 | * complained. The significance of bits is the same as in store_disp() | |
627 | */ | |
628 | static ssize_t show_disp(struct device *dev, | |
629 | struct device_attribute *attr, char *buf) | |
630 | { | |
631 | return sprintf(buf, "%d\n", read_display()); | |
632 | } | |
633 | ||
634 | /* | |
635 | * Experimental support for display switching. As of now: 1 should activate | |
636 | * the LCD output, 2 should do for CRT, 4 for TV-Out and 8 for DVI. | |
637 | * Any combination (bitwise) of these will suffice. I never actually tested 4 | |
638 | * displays hooked up simultaneously, so be warned. See the acpi4asus README | |
639 | * for more info. | |
640 | */ | |
641 | static ssize_t store_disp(struct device *dev, struct device_attribute *attr, | |
642 | const char *buf, size_t count) | |
643 | { | |
644 | int rv, value; | |
645 | ||
646 | rv = parse_arg(buf, count, &value); | |
647 | if (rv > 0) | |
648 | set_display(value); | |
649 | return rv; | |
650 | } | |
651 | ||
8b857353 CC |
652 | /* |
653 | * Light Sens | |
654 | */ | |
655 | static void set_light_sens_switch(int value) | |
656 | { | |
f8d1c94b | 657 | if (write_acpi_int(ls_switch_handle, NULL, value, NULL)) |
8b857353 CC |
658 | printk(ASUS_WARNING "Error setting light sensor switch\n"); |
659 | hotk->light_switch = value; | |
660 | } | |
661 | ||
662 | static ssize_t show_lssw(struct device *dev, | |
663 | struct device_attribute *attr, char *buf) | |
664 | { | |
665 | return sprintf(buf, "%d\n", hotk->light_switch); | |
666 | } | |
667 | ||
668 | static ssize_t store_lssw(struct device *dev, struct device_attribute *attr, | |
669 | const char *buf, size_t count) | |
670 | { | |
671 | int rv, value; | |
672 | ||
673 | rv = parse_arg(buf, count, &value); | |
674 | if (rv > 0) | |
675 | set_light_sens_switch(value ? 1 : 0); | |
676 | ||
677 | return rv; | |
678 | } | |
679 | ||
680 | static void set_light_sens_level(int value) | |
681 | { | |
f8d1c94b | 682 | if (write_acpi_int(ls_level_handle, NULL, value, NULL)) |
8b857353 CC |
683 | printk(ASUS_WARNING "Error setting light sensor level\n"); |
684 | hotk->light_level = value; | |
685 | } | |
686 | ||
687 | static ssize_t show_lslvl(struct device *dev, | |
688 | struct device_attribute *attr, char *buf) | |
689 | { | |
690 | return sprintf(buf, "%d\n", hotk->light_level); | |
691 | } | |
692 | ||
693 | static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr, | |
694 | const char *buf, size_t count) | |
695 | { | |
696 | int rv, value; | |
697 | ||
698 | rv = parse_arg(buf, count, &value); | |
699 | if (rv > 0) { | |
700 | value = (0 < value) ? ((15 < value) ? 15 : value) : 0; | |
701 | /* 0 <= value <= 15 */ | |
702 | set_light_sens_level(value); | |
703 | } | |
704 | ||
705 | return rv; | |
706 | } | |
707 | ||
e539c2f6 CC |
708 | /* |
709 | * GPS | |
710 | */ | |
711 | static ssize_t show_gps(struct device *dev, | |
712 | struct device_attribute *attr, char *buf) | |
713 | { | |
714 | return sprintf(buf, "%d\n", read_status(GPS_ON)); | |
715 | } | |
716 | ||
717 | static ssize_t store_gps(struct device *dev, struct device_attribute *attr, | |
718 | const char *buf, size_t count) | |
719 | { | |
f3985327 | 720 | return store_status(buf, count, NULL, GPS_ON); |
e539c2f6 CC |
721 | } |
722 | ||
85091b71 CC |
723 | static void asus_hotk_notify(acpi_handle handle, u32 event, void *data) |
724 | { | |
725 | /* TODO Find a better way to handle events count. */ | |
726 | if (!hotk) | |
727 | return; | |
728 | ||
6b7091e7 CC |
729 | /* |
730 | * We need to tell the backlight device when the backlight power is | |
731 | * switched | |
732 | */ | |
733 | if (event == ATKD_LCD_ON) { | |
935ffeec | 734 | write_status(NULL, 1, LCD_ON); |
6b7091e7 | 735 | lcd_blank(FB_BLANK_UNBLANK); |
8def05fa | 736 | } else if (event == ATKD_LCD_OFF) { |
935ffeec | 737 | write_status(NULL, 0, LCD_ON); |
6b7091e7 CC |
738 | lcd_blank(FB_BLANK_POWERDOWN); |
739 | } | |
740 | ||
2a7dc0d8 CC |
741 | acpi_bus_generate_netlink_event(hotk->device->pnp.device_class, |
742 | dev_name(&hotk->device->dev), event, | |
743 | hotk->event_count[event % 128]++); | |
85091b71 CC |
744 | |
745 | return; | |
746 | } | |
747 | ||
748 | #define ASUS_CREATE_DEVICE_ATTR(_name) \ | |
749 | struct device_attribute dev_attr_##_name = { \ | |
750 | .attr = { \ | |
751 | .name = __stringify(_name), \ | |
7b595756 | 752 | .mode = 0 }, \ |
85091b71 CC |
753 | .show = NULL, \ |
754 | .store = NULL, \ | |
755 | } | |
756 | ||
757 | #define ASUS_SET_DEVICE_ATTR(_name, _mode, _show, _store) \ | |
758 | do { \ | |
759 | dev_attr_##_name.attr.mode = _mode; \ | |
760 | dev_attr_##_name.show = _show; \ | |
761 | dev_attr_##_name.store = _store; \ | |
762 | } while(0) | |
763 | ||
764 | static ASUS_CREATE_DEVICE_ATTR(infos); | |
4564de17 CC |
765 | static ASUS_CREATE_DEVICE_ATTR(wlan); |
766 | static ASUS_CREATE_DEVICE_ATTR(bluetooth); | |
78127b4a | 767 | static ASUS_CREATE_DEVICE_ATTR(display); |
722ad971 | 768 | static ASUS_CREATE_DEVICE_ATTR(ledd); |
8b857353 CC |
769 | static ASUS_CREATE_DEVICE_ATTR(ls_switch); |
770 | static ASUS_CREATE_DEVICE_ATTR(ls_level); | |
e539c2f6 | 771 | static ASUS_CREATE_DEVICE_ATTR(gps); |
85091b71 CC |
772 | |
773 | static struct attribute *asuspf_attributes[] = { | |
8def05fa LB |
774 | &dev_attr_infos.attr, |
775 | &dev_attr_wlan.attr, | |
776 | &dev_attr_bluetooth.attr, | |
777 | &dev_attr_display.attr, | |
778 | &dev_attr_ledd.attr, | |
779 | &dev_attr_ls_switch.attr, | |
780 | &dev_attr_ls_level.attr, | |
e539c2f6 | 781 | &dev_attr_gps.attr, |
8def05fa | 782 | NULL |
85091b71 CC |
783 | }; |
784 | ||
785 | static struct attribute_group asuspf_attribute_group = { | |
8def05fa | 786 | .attrs = asuspf_attributes |
85091b71 CC |
787 | }; |
788 | ||
789 | static struct platform_driver asuspf_driver = { | |
8def05fa LB |
790 | .driver = { |
791 | .name = ASUS_HOTK_FILE, | |
792 | .owner = THIS_MODULE, | |
793 | } | |
85091b71 CC |
794 | }; |
795 | ||
796 | static struct platform_device *asuspf_device; | |
797 | ||
85091b71 CC |
798 | static void asus_hotk_add_fs(void) |
799 | { | |
800 | ASUS_SET_DEVICE_ATTR(infos, 0444, show_infos, NULL); | |
4564de17 CC |
801 | |
802 | if (wl_switch_handle) | |
803 | ASUS_SET_DEVICE_ATTR(wlan, 0644, show_wlan, store_wlan); | |
804 | ||
805 | if (bt_switch_handle) | |
806 | ASUS_SET_DEVICE_ATTR(bluetooth, 0644, | |
807 | show_bluetooth, store_bluetooth); | |
78127b4a CC |
808 | |
809 | if (display_set_handle && display_get_handle) | |
810 | ASUS_SET_DEVICE_ATTR(display, 0644, show_disp, store_disp); | |
8def05fa | 811 | else if (display_set_handle) |
78127b4a CC |
812 | ASUS_SET_DEVICE_ATTR(display, 0200, NULL, store_disp); |
813 | ||
722ad971 CC |
814 | if (ledd_set_handle) |
815 | ASUS_SET_DEVICE_ATTR(ledd, 0644, show_ledd, store_ledd); | |
816 | ||
8b857353 CC |
817 | if (ls_switch_handle && ls_level_handle) { |
818 | ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl); | |
819 | ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw); | |
820 | } | |
e539c2f6 | 821 | |
f3985327 | 822 | if (gps_status_handle && gps_on_handle && gps_off_handle) |
e539c2f6 | 823 | ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps); |
85091b71 CC |
824 | } |
825 | ||
8def05fa | 826 | static int asus_handle_init(char *name, acpi_handle * handle, |
85091b71 CC |
827 | char **paths, int num_paths) |
828 | { | |
829 | int i; | |
830 | acpi_status status; | |
831 | ||
832 | for (i = 0; i < num_paths; i++) { | |
833 | status = acpi_get_handle(NULL, paths[i], handle); | |
834 | if (ACPI_SUCCESS(status)) | |
835 | return 0; | |
836 | } | |
837 | ||
838 | *handle = NULL; | |
839 | return -ENODEV; | |
840 | } | |
841 | ||
842 | #define ASUS_HANDLE_INIT(object) \ | |
843 | asus_handle_init(#object, &object##_handle, object##_paths, \ | |
844 | ARRAY_SIZE(object##_paths)) | |
845 | ||
85091b71 CC |
846 | /* |
847 | * This function is used to initialize the hotk with right values. In this | |
848 | * method, we can make all the detection we want, and modify the hotk struct | |
849 | */ | |
850 | static int asus_hotk_get_info(void) | |
851 | { | |
852 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; | |
85091b71 | 853 | union acpi_object *model = NULL; |
27663c58 | 854 | unsigned long long bsts_result, hwrs_result; |
85091b71 CC |
855 | char *string = NULL; |
856 | acpi_status status; | |
857 | ||
858 | /* | |
859 | * Get DSDT headers early enough to allow for differentiating between | |
860 | * models, but late enough to allow acpi_bus_register_driver() to fail | |
861 | * before doing anything ACPI-specific. Should we encounter a machine, | |
862 | * which needs special handling (i.e. its hotkey device has a different | |
863 | * HID), this bit will be moved. A global variable asus_info contains | |
864 | * the DSDT header. | |
865 | */ | |
894d79be | 866 | status = acpi_get_table(ACPI_SIG_DSDT, 1, &asus_info); |
85091b71 CC |
867 | if (ACPI_FAILURE(status)) |
868 | printk(ASUS_WARNING "Couldn't get the DSDT table header\n"); | |
85091b71 CC |
869 | |
870 | /* We have to write 0 on init this far for all ASUS models */ | |
f8d1c94b | 871 | if (write_acpi_int(hotk->handle, "INIT", 0, &buffer)) { |
85091b71 CC |
872 | printk(ASUS_ERR "Hotkey initialization failed\n"); |
873 | return -ENODEV; | |
874 | } | |
875 | ||
876 | /* This needs to be called for some laptops to init properly */ | |
9a816850 CC |
877 | status = |
878 | acpi_evaluate_integer(hotk->handle, "BSTS", NULL, &bsts_result); | |
879 | if (ACPI_FAILURE(status)) | |
85091b71 CC |
880 | printk(ASUS_WARNING "Error calling BSTS\n"); |
881 | else if (bsts_result) | |
882 | printk(ASUS_NOTICE "BSTS called, 0x%02x returned\n", | |
9a816850 | 883 | (uint) bsts_result); |
85091b71 | 884 | |
185e5af9 CC |
885 | /* This too ... */ |
886 | write_acpi_int(hotk->handle, "CWAP", wapf, NULL); | |
887 | ||
85091b71 CC |
888 | /* |
889 | * Try to match the object returned by INIT to the specific model. | |
890 | * Handle every possible object (or the lack of thereof) the DSDT | |
891 | * writers might throw at us. When in trouble, we pass NULL to | |
892 | * asus_model_match() and try something completely different. | |
893 | */ | |
894 | if (buffer.pointer) { | |
895 | model = buffer.pointer; | |
896 | switch (model->type) { | |
897 | case ACPI_TYPE_STRING: | |
898 | string = model->string.pointer; | |
899 | break; | |
900 | case ACPI_TYPE_BUFFER: | |
901 | string = model->buffer.pointer; | |
902 | break; | |
903 | default: | |
904 | string = ""; | |
905 | break; | |
906 | } | |
907 | } | |
908 | hotk->name = kstrdup(string, GFP_KERNEL); | |
909 | if (!hotk->name) | |
910 | return -ENOMEM; | |
911 | ||
8def05fa | 912 | if (*string) |
85091b71 CC |
913 | printk(ASUS_NOTICE " %s model detected\n", string); |
914 | ||
be18cdab CC |
915 | ASUS_HANDLE_INIT(mled_set); |
916 | ASUS_HANDLE_INIT(tled_set); | |
917 | ASUS_HANDLE_INIT(rled_set); | |
918 | ASUS_HANDLE_INIT(pled_set); | |
fdd8d080 | 919 | ASUS_HANDLE_INIT(gled_set); |
be18cdab | 920 | |
722ad971 CC |
921 | ASUS_HANDLE_INIT(ledd_set); |
922 | ||
4564de17 CC |
923 | /* |
924 | * The HWRS method return informations about the hardware. | |
925 | * 0x80 bit is for WLAN, 0x100 for Bluetooth. | |
926 | * The significance of others is yet to be found. | |
927 | * If we don't find the method, we assume the device are present. | |
928 | */ | |
9a816850 CC |
929 | status = |
930 | acpi_evaluate_integer(hotk->handle, "HRWS", NULL, &hwrs_result); | |
931 | if (ACPI_FAILURE(status)) | |
4564de17 CC |
932 | hwrs_result = WL_HWRS | BT_HWRS; |
933 | ||
8def05fa | 934 | if (hwrs_result & WL_HWRS) |
4564de17 | 935 | ASUS_HANDLE_INIT(wl_switch); |
8def05fa | 936 | if (hwrs_result & BT_HWRS) |
4564de17 CC |
937 | ASUS_HANDLE_INIT(bt_switch); |
938 | ||
939 | ASUS_HANDLE_INIT(wireless_status); | |
940 | ||
6b7091e7 CC |
941 | ASUS_HANDLE_INIT(brightness_set); |
942 | ASUS_HANDLE_INIT(brightness_get); | |
943 | ||
944 | ASUS_HANDLE_INIT(lcd_switch); | |
945 | ||
78127b4a CC |
946 | ASUS_HANDLE_INIT(display_set); |
947 | ASUS_HANDLE_INIT(display_get); | |
948 | ||
8b857353 CC |
949 | /* There is a lot of models with "ALSL", but a few get |
950 | a real light sens, so we need to check it. */ | |
832d9950 | 951 | if (!ASUS_HANDLE_INIT(ls_switch)) |
8b857353 CC |
952 | ASUS_HANDLE_INIT(ls_level); |
953 | ||
e539c2f6 CC |
954 | ASUS_HANDLE_INIT(gps_on); |
955 | ASUS_HANDLE_INIT(gps_off); | |
956 | ASUS_HANDLE_INIT(gps_status); | |
957 | ||
85091b71 CC |
958 | kfree(model); |
959 | ||
960 | return AE_OK; | |
961 | } | |
962 | ||
963 | static int asus_hotk_check(void) | |
964 | { | |
965 | int result = 0; | |
966 | ||
967 | result = acpi_bus_get_status(hotk->device); | |
968 | if (result) | |
969 | return result; | |
970 | ||
971 | if (hotk->device->status.present) { | |
972 | result = asus_hotk_get_info(); | |
973 | } else { | |
974 | printk(ASUS_ERR "Hotkey device not present, aborting\n"); | |
975 | return -EINVAL; | |
976 | } | |
977 | ||
978 | return result; | |
979 | } | |
980 | ||
981 | static int asus_hotk_found; | |
982 | ||
983 | static int asus_hotk_add(struct acpi_device *device) | |
984 | { | |
985 | acpi_status status = AE_OK; | |
986 | int result; | |
987 | ||
988 | if (!device) | |
989 | return -EINVAL; | |
990 | ||
991 | printk(ASUS_NOTICE "Asus Laptop Support version %s\n", | |
992 | ASUS_LAPTOP_VERSION); | |
993 | ||
dd00cc48 | 994 | hotk = kzalloc(sizeof(struct asus_hotk), GFP_KERNEL); |
85091b71 CC |
995 | if (!hotk) |
996 | return -ENOMEM; | |
85091b71 CC |
997 | |
998 | hotk->handle = device->handle; | |
999 | strcpy(acpi_device_name(device), ASUS_HOTK_DEVICE_NAME); | |
1000 | strcpy(acpi_device_class(device), ASUS_HOTK_CLASS); | |
db89b4f0 | 1001 | device->driver_data = hotk; |
85091b71 CC |
1002 | hotk->device = device; |
1003 | ||
1004 | result = asus_hotk_check(); | |
1005 | if (result) | |
1006 | goto end; | |
1007 | ||
1008 | asus_hotk_add_fs(); | |
1009 | ||
1010 | /* | |
1011 | * We install the handler, it will receive the hotk in parameter, so, we | |
1012 | * could add other data to the hotk struct | |
1013 | */ | |
a9dbcb37 | 1014 | status = acpi_install_notify_handler(hotk->handle, ACPI_ALL_NOTIFY, |
85091b71 CC |
1015 | asus_hotk_notify, hotk); |
1016 | if (ACPI_FAILURE(status)) | |
1017 | printk(ASUS_ERR "Error installing notify handler\n"); | |
1018 | ||
1019 | asus_hotk_found = 1; | |
1020 | ||
6b7091e7 | 1021 | /* WLED and BLED are on by default */ |
935ffeec CC |
1022 | write_status(bt_switch_handle, 1, BT_ON); |
1023 | write_status(wl_switch_handle, 1, WL_ON); | |
1024 | ||
1025 | /* If the h/w switch is off, we need to check the real status */ | |
1026 | write_status(NULL, read_status(BT_ON), BT_ON); | |
1027 | write_status(NULL, read_status(WL_ON), WL_ON); | |
4564de17 | 1028 | |
6b7091e7 | 1029 | /* LCD Backlight is on by default */ |
935ffeec | 1030 | write_status(NULL, 1, LCD_ON); |
6b7091e7 | 1031 | |
722ad971 CC |
1032 | /* LED display is off by default */ |
1033 | hotk->ledd_status = 0xFFF; | |
1034 | ||
8def05fa LB |
1035 | /* Set initial values of light sensor and level */ |
1036 | hotk->light_switch = 1; /* Default to light sensor disabled */ | |
1037 | hotk->light_level = 0; /* level 5 for sensor sensitivity */ | |
8b857353 | 1038 | |
8def05fa LB |
1039 | if (ls_switch_handle) |
1040 | set_light_sens_switch(hotk->light_switch); | |
8b857353 | 1041 | |
8def05fa LB |
1042 | if (ls_level_handle) |
1043 | set_light_sens_level(hotk->light_level); | |
8b857353 | 1044 | |
e539c2f6 CC |
1045 | /* GPS is on by default */ |
1046 | write_status(NULL, 1, GPS_ON); | |
1047 | ||
85091b71 CC |
1048 | end: |
1049 | if (result) { | |
1050 | kfree(hotk->name); | |
1051 | kfree(hotk); | |
1052 | } | |
1053 | ||
1054 | return result; | |
1055 | } | |
1056 | ||
1057 | static int asus_hotk_remove(struct acpi_device *device, int type) | |
1058 | { | |
1059 | acpi_status status = 0; | |
1060 | ||
1061 | if (!device || !acpi_driver_data(device)) | |
1062 | return -EINVAL; | |
1063 | ||
a9dbcb37 | 1064 | status = acpi_remove_notify_handler(hotk->handle, ACPI_ALL_NOTIFY, |
85091b71 CC |
1065 | asus_hotk_notify); |
1066 | if (ACPI_FAILURE(status)) | |
1067 | printk(ASUS_ERR "Error removing notify handler\n"); | |
1068 | ||
1069 | kfree(hotk->name); | |
1070 | kfree(hotk); | |
1071 | ||
1072 | return 0; | |
1073 | } | |
1074 | ||
6b7091e7 CC |
1075 | static void asus_backlight_exit(void) |
1076 | { | |
8def05fa | 1077 | if (asus_backlight_device) |
6b7091e7 CC |
1078 | backlight_device_unregister(asus_backlight_device); |
1079 | } | |
1080 | ||
be18cdab | 1081 | #define ASUS_LED_UNREGISTER(object) \ |
e1996a69 GC |
1082 | if (object##_led.dev) \ |
1083 | led_classdev_unregister(&object##_led) | |
be18cdab CC |
1084 | |
1085 | static void asus_led_exit(void) | |
1086 | { | |
3b0d7117 | 1087 | destroy_workqueue(led_workqueue); |
be18cdab CC |
1088 | ASUS_LED_UNREGISTER(mled); |
1089 | ASUS_LED_UNREGISTER(tled); | |
1090 | ASUS_LED_UNREGISTER(pled); | |
1091 | ASUS_LED_UNREGISTER(rled); | |
fdd8d080 | 1092 | ASUS_LED_UNREGISTER(gled); |
be18cdab CC |
1093 | } |
1094 | ||
85091b71 CC |
1095 | static void __exit asus_laptop_exit(void) |
1096 | { | |
6b7091e7 | 1097 | asus_backlight_exit(); |
be18cdab CC |
1098 | asus_led_exit(); |
1099 | ||
85091b71 | 1100 | acpi_bus_unregister_driver(&asus_hotk_driver); |
8def05fa LB |
1101 | sysfs_remove_group(&asuspf_device->dev.kobj, &asuspf_attribute_group); |
1102 | platform_device_unregister(asuspf_device); | |
1103 | platform_driver_unregister(&asuspf_driver); | |
85091b71 CC |
1104 | } |
1105 | ||
8def05fa | 1106 | static int asus_backlight_init(struct device *dev) |
6b7091e7 CC |
1107 | { |
1108 | struct backlight_device *bd; | |
1109 | ||
8def05fa LB |
1110 | if (brightness_set_handle && lcd_switch_handle) { |
1111 | bd = backlight_device_register(ASUS_HOTK_FILE, dev, | |
599a52d1 | 1112 | NULL, &asusbl_ops); |
8def05fa | 1113 | if (IS_ERR(bd)) { |
6b7091e7 CC |
1114 | printk(ASUS_ERR |
1115 | "Could not register asus backlight device\n"); | |
1116 | asus_backlight_device = NULL; | |
1117 | return PTR_ERR(bd); | |
1118 | } | |
1119 | ||
1120 | asus_backlight_device = bd; | |
1121 | ||
599a52d1 RP |
1122 | bd->props.max_brightness = 15; |
1123 | bd->props.brightness = read_brightness(NULL); | |
1124 | bd->props.power = FB_BLANK_UNBLANK; | |
28ee086d | 1125 | backlight_update_status(bd); |
6b7091e7 CC |
1126 | } |
1127 | return 0; | |
1128 | } | |
1129 | ||
be18cdab | 1130 | static int asus_led_register(acpi_handle handle, |
8def05fa | 1131 | struct led_classdev *ldev, struct device *dev) |
be18cdab | 1132 | { |
8def05fa | 1133 | if (!handle) |
be18cdab CC |
1134 | return 0; |
1135 | ||
1136 | return led_classdev_register(dev, ldev); | |
1137 | } | |
8def05fa | 1138 | |
be18cdab CC |
1139 | #define ASUS_LED_REGISTER(object, device) \ |
1140 | asus_led_register(object##_set_handle, &object##_led, device) | |
1141 | ||
8def05fa | 1142 | static int asus_led_init(struct device *dev) |
be18cdab CC |
1143 | { |
1144 | int rv; | |
1145 | ||
1146 | rv = ASUS_LED_REGISTER(mled, dev); | |
8def05fa | 1147 | if (rv) |
3b0d7117 | 1148 | goto out; |
be18cdab CC |
1149 | |
1150 | rv = ASUS_LED_REGISTER(tled, dev); | |
8def05fa | 1151 | if (rv) |
3b0d7117 | 1152 | goto out1; |
be18cdab CC |
1153 | |
1154 | rv = ASUS_LED_REGISTER(rled, dev); | |
8def05fa | 1155 | if (rv) |
3b0d7117 | 1156 | goto out2; |
be18cdab CC |
1157 | |
1158 | rv = ASUS_LED_REGISTER(pled, dev); | |
8def05fa | 1159 | if (rv) |
3b0d7117 | 1160 | goto out3; |
be18cdab | 1161 | |
fdd8d080 CC |
1162 | rv = ASUS_LED_REGISTER(gled, dev); |
1163 | if (rv) | |
3b0d7117 | 1164 | goto out4; |
fdd8d080 | 1165 | |
be18cdab | 1166 | led_workqueue = create_singlethread_workqueue("led_workqueue"); |
8def05fa | 1167 | if (!led_workqueue) |
3b0d7117 | 1168 | goto out5; |
be18cdab CC |
1169 | |
1170 | return 0; | |
3b0d7117 AV |
1171 | out5: |
1172 | rv = -ENOMEM; | |
1173 | ASUS_LED_UNREGISTER(gled); | |
1174 | out4: | |
1175 | ASUS_LED_UNREGISTER(pled); | |
1176 | out3: | |
1177 | ASUS_LED_UNREGISTER(rled); | |
1178 | out2: | |
1179 | ASUS_LED_UNREGISTER(tled); | |
1180 | out1: | |
1181 | ASUS_LED_UNREGISTER(mled); | |
1182 | out: | |
1183 | return rv; | |
be18cdab CC |
1184 | } |
1185 | ||
85091b71 CC |
1186 | static int __init asus_laptop_init(void) |
1187 | { | |
be18cdab | 1188 | struct device *dev; |
85091b71 CC |
1189 | int result; |
1190 | ||
1191 | if (acpi_disabled) | |
1192 | return -ENODEV; | |
1193 | ||
85091b71 CC |
1194 | result = acpi_bus_register_driver(&asus_hotk_driver); |
1195 | if (result < 0) | |
1196 | return result; | |
1197 | ||
1198 | /* | |
1199 | * This is a bit of a kludge. We only want this module loaded | |
1200 | * for ASUS systems, but there's currently no way to probe the | |
1201 | * ACPI namespace for ASUS HIDs. So we just return failure if | |
1202 | * we didn't find one, which will cause the module to be | |
1203 | * unloaded. | |
1204 | */ | |
1205 | if (!asus_hotk_found) { | |
1206 | acpi_bus_unregister_driver(&asus_hotk_driver); | |
1207 | return -ENODEV; | |
1208 | } | |
1209 | ||
be18cdab CC |
1210 | dev = acpi_get_physical_device(hotk->device->handle); |
1211 | ||
6766fec3 TR |
1212 | if (!acpi_video_backlight_support()) { |
1213 | result = asus_backlight_init(dev); | |
1214 | if (result) | |
1215 | goto fail_backlight; | |
1216 | } else | |
1217 | printk(ASUS_INFO "Brightness ignored, must be controlled by " | |
1218 | "ACPI video driver\n"); | |
6b7091e7 | 1219 | |
be18cdab | 1220 | result = asus_led_init(dev); |
8def05fa | 1221 | if (result) |
be18cdab CC |
1222 | goto fail_led; |
1223 | ||
8def05fa | 1224 | /* Register platform stuff */ |
85091b71 | 1225 | result = platform_driver_register(&asuspf_driver); |
8def05fa LB |
1226 | if (result) |
1227 | goto fail_platform_driver; | |
85091b71 | 1228 | |
8def05fa LB |
1229 | asuspf_device = platform_device_alloc(ASUS_HOTK_FILE, -1); |
1230 | if (!asuspf_device) { | |
1231 | result = -ENOMEM; | |
1232 | goto fail_platform_device1; | |
1233 | } | |
85091b71 | 1234 | |
8def05fa LB |
1235 | result = platform_device_add(asuspf_device); |
1236 | if (result) | |
1237 | goto fail_platform_device2; | |
85091b71 | 1238 | |
8def05fa | 1239 | result = sysfs_create_group(&asuspf_device->dev.kobj, |
85091b71 | 1240 | &asuspf_attribute_group); |
8def05fa LB |
1241 | if (result) |
1242 | goto fail_sysfs; | |
85091b71 | 1243 | |
8def05fa | 1244 | return 0; |
85091b71 | 1245 | |
8def05fa LB |
1246 | fail_sysfs: |
1247 | platform_device_del(asuspf_device); | |
85091b71 | 1248 | |
8def05fa | 1249 | fail_platform_device2: |
85091b71 CC |
1250 | platform_device_put(asuspf_device); |
1251 | ||
8def05fa LB |
1252 | fail_platform_device1: |
1253 | platform_driver_unregister(&asuspf_driver); | |
85091b71 | 1254 | |
8def05fa | 1255 | fail_platform_driver: |
be18cdab CC |
1256 | asus_led_exit(); |
1257 | ||
8def05fa | 1258 | fail_led: |
6b7091e7 CC |
1259 | asus_backlight_exit(); |
1260 | ||
8def05fa | 1261 | fail_backlight: |
85091b71 CC |
1262 | |
1263 | return result; | |
1264 | } | |
1265 | ||
1266 | module_init(asus_laptop_init); | |
1267 | module_exit(asus_laptop_exit); |