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