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