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