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