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