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