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