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