blob: 099f92a2c6f2335c0e332ceed82dbb835a455555 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * asus_acpi.c - Asus Laptop ACPI Extras
3 *
4 *
Karol Kozimora170a532006-06-30 19:03:00 -04005 * Copyright (C) 2002-2005 Julien Lerouge, 2003-2006 Karol Kozimor
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 *
22 * The development page for this driver is located at
23 * http://sourceforge.net/projects/acpi4asus/
24 *
25 * Credits:
26 * Pontus Fuchs - Helper functions, cleanup
27 * Johann Wiesner - Small compile fixes
28 * John Belmonte - ACPI code for Toshiba laptop was a good starting point.
Karol Kozimor42cb8912006-06-30 19:04:00 -040029 * Éric Burghard - LED display support for W1N
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 */
32
33#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/types.h>
37#include <linux/proc_fs.h>
38#include <acpi/acpi_drivers.h>
39#include <acpi/acpi_bus.h>
40#include <asm/uaccess.h>
41
Karol Kozimora170a532006-06-30 19:03:00 -040042#define ASUS_ACPI_VERSION "0.30"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#define PROC_ASUS "asus" //the directory
45#define PROC_MLED "mled"
46#define PROC_WLED "wled"
47#define PROC_TLED "tled"
Karol Kozimore067aaa2006-06-30 19:07:00 -040048#define PROC_BT "bluetooth"
Karol Kozimor42cb8912006-06-30 19:04:00 -040049#define PROC_LEDD "ledd"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define PROC_INFO "info"
51#define PROC_LCD "lcd"
52#define PROC_BRN "brn"
53#define PROC_DISP "disp"
54
55#define ACPI_HOTK_NAME "Asus Laptop ACPI Extras Driver"
56#define ACPI_HOTK_CLASS "hotkey"
57#define ACPI_HOTK_DEVICE_NAME "Hotkey"
58#define ACPI_HOTK_HID "ATK0100"
59
60/*
61 * Some events we use, same for all Asus
62 */
Len Brown4be44fc2005-08-05 00:44:28 -040063#define BR_UP 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -070064#define BR_DOWN 0x20
65
66/*
67 * Flags for hotk status
68 */
Karol Kozimore067aaa2006-06-30 19:07:00 -040069#define MLED_ON 0x01 //mail LED
70#define WLED_ON 0x02 //wireless LED
71#define TLED_ON 0x04 //touchpad LED
72#define BT_ON 0x08 //internal Bluetooth
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74MODULE_AUTHOR("Julien Lerouge, Karol Kozimor");
75MODULE_DESCRIPTION(ACPI_HOTK_NAME);
76MODULE_LICENSE("GPL");
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078static uid_t asus_uid;
79static gid_t asus_gid;
80module_param(asus_uid, uint, 0);
Karol Kozimoraea19aa2006-01-03 23:05:00 -050081MODULE_PARM_DESC(asus_uid, "UID for entries in /proc/acpi/asus.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070082module_param(asus_gid, uint, 0);
Karol Kozimoraea19aa2006-01-03 23:05:00 -050083MODULE_PARM_DESC(asus_gid, "GID for entries in /proc/acpi/asus.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/* For each model, all features implemented,
86 * those marked with R are relative to HOTK, A for absolute */
87struct model_data {
Len Brown4be44fc2005-08-05 00:44:28 -040088 char *name; //name of the laptop________________A
89 char *mt_mled; //method to handle mled_____________R
90 char *mled_status; //node to handle mled reading_______A
91 char *mt_wled; //method to handle wled_____________R
92 char *wled_status; //node to handle wled reading_______A
93 char *mt_tled; //method to handle tled_____________R
94 char *tled_status; //node to handle tled reading_______A
Karol Kozimor42cb8912006-06-30 19:04:00 -040095 char *mt_ledd; //method to handle LED display______R
Karol Kozimore067aaa2006-06-30 19:07:00 -040096 char *mt_bt_switch; //method to switch Bluetooth on/off_R
97 char *bt_status; //no model currently supports this__?
98 char *mt_lcd_switch; //method to turn LCD on/off_________A
Len Brown4be44fc2005-08-05 00:44:28 -040099 char *lcd_status; //node to read LCD panel state______A
100 char *brightness_up; //method to set brightness up_______A
101 char *brightness_down; //guess what ?______________________A
102 char *brightness_set; //method to set absolute brightness_R
103 char *brightness_get; //method to get absolute brightness_R
104 char *brightness_status; //node to get brightness____________A
105 char *display_set; //method to set video output________R
106 char *display_get; //method to get video output________R
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
109/*
110 * This is the main structure, we can use it to store anything interesting
111 * about the hotk device
112 */
113struct asus_hotk {
Len Brown4be44fc2005-08-05 00:44:28 -0400114 struct acpi_device *device; //the device we are in
115 acpi_handle handle; //the handle of the hotk device
116 char status; //status of the hotk, for LEDs, ...
Karol Kozimor42cb8912006-06-30 19:04:00 -0400117 u32 ledd_status; //status of the LED display
Len Brown4be44fc2005-08-05 00:44:28 -0400118 struct model_data *methods; //methods available on the laptop
119 u8 brightness; //brightness level
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 enum {
Len Brown4be44fc2005-08-05 00:44:28 -0400121 A1x = 0, //A1340D, A1300F
122 A2x, //A2500H
Karol Kozimorf78c5892006-06-30 19:06:00 -0400123 A4G, //A4700G
Len Brown4be44fc2005-08-05 00:44:28 -0400124 D1x, //D1
125 L2D, //L2000D
126 L3C, //L3800C
127 L3D, //L3400D
Karol Kozimorebccb842006-06-30 19:08:00 -0400128 L3H, //L3H, L2000E, L5D
Len Brown4be44fc2005-08-05 00:44:28 -0400129 L4R, //L4500R
130 L5x, //L5800C
131 L8L, //L8400L
132 M1A, //M1300A
133 M2E, //M2400E, L4400L
Karol Kozimorc067a782006-06-30 19:05:00 -0400134 M6N, //M6800N, W3400N
Karol Kozimored2cb072006-06-30 19:03:00 -0400135 M6R, //M6700R, A3000G
Len Brown4be44fc2005-08-05 00:44:28 -0400136 P30, //Samsung P30
137 S1x, //S1300A, but also L1400B and M2400A (L84F)
138 S2x, //S200 (J1 reported), Victor MP-XP7210
Karol Kozimor42cb8912006-06-30 19:04:00 -0400139 W1N, //W1000N
Karol Kozimore067aaa2006-06-30 19:07:00 -0400140 W5A, //W5A
Karol Kozimor42cb8912006-06-30 19:04:00 -0400141 xxN, //M2400N, M3700N, M5200N, M6800N, S1300N, S5200N
Len Brown4be44fc2005-08-05 00:44:28 -0400142 //(Centrino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 END_MODEL
Len Brown4be44fc2005-08-05 00:44:28 -0400144 } model; //Models currently supported
145 u16 event_count[128]; //count for each event TODO make this better
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146};
147
148/* Here we go */
149#define A1x_PREFIX "\\_SB.PCI0.ISA.EC0."
150#define L3C_PREFIX "\\_SB.PCI0.PX40.ECD0."
151#define M1A_PREFIX "\\_SB.PCI0.PX40.EC0."
152#define P30_PREFIX "\\_SB.PCI0.LPCB.EC0."
153#define S1x_PREFIX "\\_SB.PCI0.PX40."
154#define S2x_PREFIX A1x_PREFIX
155#define xxN_PREFIX "\\_SB.PCI0.SBRG.EC0."
156
157static struct model_data model_conf[END_MODEL] = {
Len Brown4be44fc2005-08-05 00:44:28 -0400158 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 * TODO I have seen a SWBX and AIBX method on some models, like L1400B,
160 * it seems to be a kind of switch, but what for ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 */
162
163 {
Len Brown4be44fc2005-08-05 00:44:28 -0400164 .name = "A1x",
165 .mt_mled = "MLED",
166 .mled_status = "\\MAIL",
167 .mt_lcd_switch = A1x_PREFIX "_Q10",
168 .lcd_status = "\\BKLI",
169 .brightness_up = A1x_PREFIX "_Q0E",
170 .brightness_down = A1x_PREFIX "_Q0F"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172 {
Len Brown4be44fc2005-08-05 00:44:28 -0400173 .name = "A2x",
174 .mt_mled = "MLED",
175 .mt_wled = "WLED",
176 .wled_status = "\\SG66",
177 .mt_lcd_switch = "\\Q10",
178 .lcd_status = "\\BAOF",
179 .brightness_set = "SPLV",
180 .brightness_get = "GPLV",
181 .display_set = "SDSP",
182 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 {
Karol Kozimorf78c5892006-06-30 19:06:00 -0400185 .name = "A4G",
186 .mt_mled = "MLED",
187/* WLED present, but not controlled by ACPI */
188 .mt_lcd_switch = xxN_PREFIX "_Q10",
189 .brightness_set = "SPLV",
190 .brightness_get = "GPLV",
191 .display_set = "SDSP",
192 .display_get = "\\ADVG"},
193
194 {
Len Brown4be44fc2005-08-05 00:44:28 -0400195 .name = "D1x",
196 .mt_mled = "MLED",
197 .mt_lcd_switch = "\\Q0D",
198 .lcd_status = "\\GP11",
199 .brightness_up = "\\Q0C",
200 .brightness_down = "\\Q0B",
201 .brightness_status = "\\BLVL",
202 .display_set = "SDSP",
203 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205 {
Len Brown4be44fc2005-08-05 00:44:28 -0400206 .name = "L2D",
207 .mt_mled = "MLED",
208 .mled_status = "\\SGP6",
209 .mt_wled = "WLED",
210 .wled_status = "\\RCP3",
211 .mt_lcd_switch = "\\Q10",
212 .lcd_status = "\\SGP0",
213 .brightness_up = "\\Q0E",
214 .brightness_down = "\\Q0F",
215 .display_set = "SDSP",
216 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218 {
Len Brown4be44fc2005-08-05 00:44:28 -0400219 .name = "L3C",
220 .mt_mled = "MLED",
221 .mt_wled = "WLED",
222 .mt_lcd_switch = L3C_PREFIX "_Q10",
223 .lcd_status = "\\GL32",
224 .brightness_set = "SPLV",
225 .brightness_get = "GPLV",
226 .display_set = "SDSP",
227 .display_get = "\\_SB.PCI0.PCI1.VGAC.NMAP"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 {
Len Brown4be44fc2005-08-05 00:44:28 -0400230 .name = "L3D",
231 .mt_mled = "MLED",
232 .mled_status = "\\MALD",
233 .mt_wled = "WLED",
234 .mt_lcd_switch = "\\Q10",
235 .lcd_status = "\\BKLG",
236 .brightness_set = "SPLV",
237 .brightness_get = "GPLV",
238 .display_set = "SDSP",
239 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241 {
Len Brown4be44fc2005-08-05 00:44:28 -0400242 .name = "L3H",
243 .mt_mled = "MLED",
244 .mt_wled = "WLED",
245 .mt_lcd_switch = "EHK",
246 .lcd_status = "\\_SB.PCI0.PM.PBC",
247 .brightness_set = "SPLV",
248 .brightness_get = "GPLV",
249 .display_set = "SDSP",
250 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252 {
Len Brown4be44fc2005-08-05 00:44:28 -0400253 .name = "L4R",
254 .mt_mled = "MLED",
255 .mt_wled = "WLED",
256 .wled_status = "\\_SB.PCI0.SBRG.SG13",
257 .mt_lcd_switch = xxN_PREFIX "_Q10",
258 .lcd_status = "\\_SB.PCI0.SBSM.SEO4",
259 .brightness_set = "SPLV",
260 .brightness_get = "GPLV",
261 .display_set = "SDSP",
262 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 {
Len Brown4be44fc2005-08-05 00:44:28 -0400265 .name = "L5x",
266 .mt_mled = "MLED",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267/* WLED present, but not controlled by ACPI */
Len Brown4be44fc2005-08-05 00:44:28 -0400268 .mt_tled = "TLED",
269 .mt_lcd_switch = "\\Q0D",
270 .lcd_status = "\\BAOF",
271 .brightness_set = "SPLV",
272 .brightness_get = "GPLV",
273 .display_set = "SDSP",
274 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276 {
Len Brown4be44fc2005-08-05 00:44:28 -0400277 .name = "L8L"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278/* No features, but at least support the hotkeys */
Len Brown4be44fc2005-08-05 00:44:28 -0400279 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 {
Len Brown4be44fc2005-08-05 00:44:28 -0400282 .name = "M1A",
283 .mt_mled = "MLED",
284 .mt_lcd_switch = M1A_PREFIX "Q10",
285 .lcd_status = "\\PNOF",
286 .brightness_up = M1A_PREFIX "Q0E",
287 .brightness_down = M1A_PREFIX "Q0F",
288 .brightness_status = "\\BRIT",
289 .display_set = "SDSP",
290 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291
292 {
Len Brown4be44fc2005-08-05 00:44:28 -0400293 .name = "M2E",
294 .mt_mled = "MLED",
295 .mt_wled = "WLED",
296 .mt_lcd_switch = "\\Q10",
297 .lcd_status = "\\GP06",
298 .brightness_set = "SPLV",
299 .brightness_get = "GPLV",
300 .display_set = "SDSP",
301 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
303 {
Len Brown4be44fc2005-08-05 00:44:28 -0400304 .name = "M6N",
305 .mt_mled = "MLED",
306 .mt_wled = "WLED",
307 .wled_status = "\\_SB.PCI0.SBRG.SG13",
308 .mt_lcd_switch = xxN_PREFIX "_Q10",
309 .lcd_status = "\\_SB.BKLT",
310 .brightness_set = "SPLV",
311 .brightness_get = "GPLV",
312 .display_set = "SDSP",
Karol Kozimorbb84db92006-01-03 23:03:00 -0500313 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 {
Len Brown4be44fc2005-08-05 00:44:28 -0400315 .name = "M6R",
316 .mt_mled = "MLED",
317 .mt_wled = "WLED",
318 .mt_lcd_switch = xxN_PREFIX "_Q10",
319 .lcd_status = "\\_SB.PCI0.SBSM.SEO4",
320 .brightness_set = "SPLV",
321 .brightness_get = "GPLV",
322 .display_set = "SDSP",
323 .display_get = "\\SSTE"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 {
Len Brown4be44fc2005-08-05 00:44:28 -0400326 .name = "P30",
327 .mt_wled = "WLED",
328 .mt_lcd_switch = P30_PREFIX "_Q0E",
329 .lcd_status = "\\BKLT",
330 .brightness_up = P30_PREFIX "_Q68",
331 .brightness_down = P30_PREFIX "_Q69",
332 .brightness_get = "GPLV",
333 .display_set = "SDSP",
334 .display_get = "\\DNXT"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336 {
Len Brown4be44fc2005-08-05 00:44:28 -0400337 .name = "S1x",
338 .mt_mled = "MLED",
339 .mled_status = "\\EMLE",
340 .mt_wled = "WLED",
341 .mt_lcd_switch = S1x_PREFIX "Q10",
342 .lcd_status = "\\PNOF",
343 .brightness_set = "SPLV",
344 .brightness_get = "GPLV"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 {
Len Brown4be44fc2005-08-05 00:44:28 -0400347 .name = "S2x",
348 .mt_mled = "MLED",
349 .mled_status = "\\MAIL",
350 .mt_lcd_switch = S2x_PREFIX "_Q10",
351 .lcd_status = "\\BKLI",
352 .brightness_up = S2x_PREFIX "_Q0B",
353 .brightness_down = S2x_PREFIX "_Q0A"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 {
Karol Kozimor42cb8912006-06-30 19:04:00 -0400356 .name = "W1N",
357 .mt_mled = "MLED",
358 .mt_wled = "WLED",
359 .mt_ledd = "SLCM",
360 .mt_lcd_switch = xxN_PREFIX "_Q10",
361 .lcd_status = "\\BKLT",
362 .brightness_set = "SPLV",
363 .brightness_get = "GPLV",
364 .display_set = "SDSP",
365 .display_get = "\\ADVG"},
366
367 {
Karol Kozimore067aaa2006-06-30 19:07:00 -0400368 .name = "W5A",
369 .mt_bt_switch = "BLED",
370 .mt_wled = "WLED",
371 .mt_lcd_switch = xxN_PREFIX "_Q10",
372 .brightness_set = "SPLV",
373 .brightness_get = "GPLV",
374 .display_set = "SDSP",
375 .display_get = "\\ADVG"},
376
377 {
Len Brown4be44fc2005-08-05 00:44:28 -0400378 .name = "xxN",
379 .mt_mled = "MLED",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380/* WLED present, but not controlled by ACPI */
Len Brown4be44fc2005-08-05 00:44:28 -0400381 .mt_lcd_switch = xxN_PREFIX "_Q10",
382 .lcd_status = "\\BKLT",
383 .brightness_set = "SPLV",
384 .brightness_get = "GPLV",
385 .display_set = "SDSP",
386 .display_get = "\\ADVG"}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387};
388
389/* procdir we use */
390static struct proc_dir_entry *asus_proc_dir;
391
392/*
393 * This header is made available to allow proper configuration given model,
394 * revision number , ... this info cannot go in struct asus_hotk because it is
395 * available before the hotk
396 */
397static struct acpi_table_header *asus_info;
398
399/* The actual device the driver binds to */
400static struct asus_hotk *hotk;
401
402/*
403 * The hotkey driver declaration
404 */
405static int asus_hotk_add(struct acpi_device *device);
406static int asus_hotk_remove(struct acpi_device *device, int type);
407static struct acpi_driver asus_hotk_driver = {
Len Brown4be44fc2005-08-05 00:44:28 -0400408 .name = ACPI_HOTK_NAME,
409 .class = ACPI_HOTK_CLASS,
410 .ids = ACPI_HOTK_HID,
411 .ops = {
412 .add = asus_hotk_add,
413 .remove = asus_hotk_remove,
414 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415};
416
417/*
418 * This function evaluates an ACPI method, given an int as parameter, the
419 * method is searched within the scope of the handle, can be NULL. The output
420 * of the method is written is output, which can also be NULL
421 *
422 * returns 1 if write is successful, 0 else.
423 */
424static int write_acpi_int(acpi_handle handle, const char *method, int val,
425 struct acpi_buffer *output)
426{
427 struct acpi_object_list params; //list of input parameters (an int here)
428 union acpi_object in_obj; //the only param we use
429 acpi_status status;
430
431 params.count = 1;
432 params.pointer = &in_obj;
433 in_obj.type = ACPI_TYPE_INTEGER;
434 in_obj.integer.value = val;
435
Len Brown4be44fc2005-08-05 00:44:28 -0400436 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 return (status == AE_OK);
438}
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440static int read_acpi_int(acpi_handle handle, const char *method, int *val)
441{
442 struct acpi_buffer output;
443 union acpi_object out_obj;
444 acpi_status status;
445
446 output.length = sizeof(out_obj);
447 output.pointer = &out_obj;
448
Len Brown4be44fc2005-08-05 00:44:28 -0400449 status = acpi_evaluate_object(handle, (char *)method, NULL, &output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 *val = out_obj.integer.value;
451 return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER);
452}
453
454/*
455 * We write our info in page, we begin at offset off and cannot write more
456 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
457 * number of bytes written in page
458 */
459static int
460proc_read_info(char *page, char **start, off_t off, int count, int *eof,
Len Brown4be44fc2005-08-05 00:44:28 -0400461 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462{
463 int len = 0;
464 int temp;
465 char buf[16]; //enough for all info
466 /*
467 * We use the easy way, we don't care of off and count, so we don't set eof
468 * to 1
469 */
470
471 len += sprintf(page, ACPI_HOTK_NAME " " ASUS_ACPI_VERSION "\n");
Len Brown4be44fc2005-08-05 00:44:28 -0400472 len += sprintf(page + len, "Model reference : %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 hotk->methods->name);
474 /*
475 * The SFUN method probably allows the original driver to get the list
476 * of features supported by a given model. For now, 0x0100 or 0x0800
477 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
478 * The significance of others is yet to be found.
479 */
480 if (read_acpi_int(hotk->handle, "SFUN", &temp))
Len Brown4be44fc2005-08-05 00:44:28 -0400481 len +=
482 sprintf(page + len, "SFUN value : 0x%04x\n", temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 /*
484 * Another value for userspace: the ASYM method returns 0x02 for
485 * battery low and 0x04 for battery critical, its readings tend to be
486 * more accurate than those provided by _BST.
487 * Note: since not all the laptops provide this method, errors are
488 * silently ignored.
489 */
490 if (read_acpi_int(hotk->handle, "ASYM", &temp))
Len Brown4be44fc2005-08-05 00:44:28 -0400491 len +=
492 sprintf(page + len, "ASYM value : 0x%04x\n", temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 if (asus_info) {
494 snprintf(buf, 16, "%d", asus_info->length);
495 len += sprintf(page + len, "DSDT length : %s\n", buf);
496 snprintf(buf, 16, "%d", asus_info->checksum);
497 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
498 snprintf(buf, 16, "%d", asus_info->revision);
499 len += sprintf(page + len, "DSDT revision : %s\n", buf);
500 snprintf(buf, 7, "%s", asus_info->oem_id);
501 len += sprintf(page + len, "OEM id : %s\n", buf);
502 snprintf(buf, 9, "%s", asus_info->oem_table_id);
503 len += sprintf(page + len, "OEM table id : %s\n", buf);
504 snprintf(buf, 16, "%x", asus_info->oem_revision);
505 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
506 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
507 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
508 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
509 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
510 }
511
512 return len;
513}
514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515/*
516 * /proc handlers
517 * We write our info in page, we begin at offset off and cannot write more
518 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
519 * number of bytes written in page
520 */
521
522/* Generic LED functions */
Len Brown4be44fc2005-08-05 00:44:28 -0400523static int read_led(const char *ledname, int ledmask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
525 if (ledname) {
526 int led_status;
527
528 if (read_acpi_int(NULL, ledname, &led_status))
529 return led_status;
530 else
531 printk(KERN_WARNING "Asus ACPI: Error reading LED "
532 "status\n");
533 }
534 return (hotk->status & ledmask) ? 1 : 0;
535}
536
Len Brown4be44fc2005-08-05 00:44:28 -0400537static int parse_arg(const char __user * buf, unsigned long count, int *val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
539 char s[32];
540 if (!count)
541 return 0;
542 if (count > 31)
543 return -EINVAL;
544 if (copy_from_user(s, buf, count))
545 return -EFAULT;
546 s[count] = 0;
547 if (sscanf(s, "%i", val) != 1)
548 return -EINVAL;
549 return count;
550}
551
552/* FIXME: kill extraneous args so it can be called independently */
553static int
Len Brown4be44fc2005-08-05 00:44:28 -0400554write_led(const char __user * buffer, unsigned long count,
555 char *ledname, int ledmask, int invert)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556{
557 int value;
558 int led_out = 0;
559
560 count = parse_arg(buffer, count, &value);
561 if (count > 0)
562 led_out = value ? 1 : 0;
563
564 hotk->status =
565 (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask);
566
Len Brown4be44fc2005-08-05 00:44:28 -0400567 if (invert) /* invert target value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 led_out = !led_out & 0x1;
569
570 if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
Len Brown4be44fc2005-08-05 00:44:28 -0400571 printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n",
572 ledname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574 return count;
575}
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577/*
578 * Proc handlers for MLED
579 */
580static int
581proc_read_mled(char *page, char **start, off_t off, int count, int *eof,
582 void *data)
583{
Len Brown4be44fc2005-08-05 00:44:28 -0400584 return sprintf(page, "%d\n",
585 read_led(hotk->methods->mled_status, MLED_ON));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586}
587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588static int
Len Brown4be44fc2005-08-05 00:44:28 -0400589proc_write_mled(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 unsigned long count, void *data)
591{
592 return write_led(buffer, count, hotk->methods->mt_mled, MLED_ON, 1);
593}
594
595/*
Karol Kozimor42cb8912006-06-30 19:04:00 -0400596 * Proc handlers for LED display
597 */
598static int
599proc_read_ledd(char *page, char **start, off_t off, int count, int *eof,
600 void *data)
601{
602 return sprintf(page, "0x%08x\n", hotk->ledd_status);
603}
604
605static int
606proc_write_ledd(struct file *file, const char __user * buffer,
607 unsigned long count, void *data)
608{
609 int value;
610
611 count = parse_arg(buffer, count, &value);
612 if (count > 0) {
613 if (!write_acpi_int
614 (hotk->handle, hotk->methods->mt_ledd, value, NULL))
615 printk(KERN_WARNING
616 "Asus ACPI: LED display write failed\n");
617 else
618 hotk->ledd_status = (u32) value;
619 } else if (count < 0)
620 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
621
622 return count;
623}
624
625/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 * Proc handlers for WLED
627 */
628static int
629proc_read_wled(char *page, char **start, off_t off, int count, int *eof,
630 void *data)
631{
Len Brown4be44fc2005-08-05 00:44:28 -0400632 return sprintf(page, "%d\n",
633 read_led(hotk->methods->wled_status, WLED_ON));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634}
635
636static int
Len Brown4be44fc2005-08-05 00:44:28 -0400637proc_write_wled(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 unsigned long count, void *data)
639{
640 return write_led(buffer, count, hotk->methods->mt_wled, WLED_ON, 0);
641}
642
643/*
Karol Kozimore067aaa2006-06-30 19:07:00 -0400644 * Proc handlers for Bluetooth
645 */
646static int
647proc_read_bluetooth(char *page, char **start, off_t off, int count, int *eof,
648 void *data)
649{
650 return sprintf(page, "%d\n", read_led(hotk->methods->bt_status, BT_ON));
651}
652
653static int
654proc_write_bluetooth(struct file *file, const char __user * buffer,
655 unsigned long count, void *data)
656{
657 /* Note: mt_bt_switch controls both internal Bluetooth adapter's
658 presence and its LED */
659 return write_led(buffer, count, hotk->methods->mt_bt_switch, BT_ON, 0);
660}
661
662/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 * Proc handlers for TLED
664 */
665static int
666proc_read_tled(char *page, char **start, off_t off, int count, int *eof,
667 void *data)
668{
Len Brown4be44fc2005-08-05 00:44:28 -0400669 return sprintf(page, "%d\n",
670 read_led(hotk->methods->tled_status, TLED_ON));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671}
672
673static int
Len Brown4be44fc2005-08-05 00:44:28 -0400674proc_write_tled(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 unsigned long count, void *data)
676{
677 return write_led(buffer, count, hotk->methods->mt_tled, TLED_ON, 0);
678}
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680static int get_lcd_state(void)
681{
682 int lcd = 0;
683
684 if (hotk->model != L3H) {
Len Brown4be44fc2005-08-05 00:44:28 -0400685 /* We don't have to check anything if we are here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 if (!read_acpi_int(NULL, hotk->methods->lcd_status, &lcd))
Len Brown4be44fc2005-08-05 00:44:28 -0400687 printk(KERN_WARNING
688 "Asus ACPI: Error reading LCD status\n");
689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 if (hotk->model == L2D)
691 lcd = ~lcd;
Len Brown4be44fc2005-08-05 00:44:28 -0400692 } else { /* L3H and the like have to be handled differently */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 acpi_status status = 0;
694 struct acpi_object_list input;
695 union acpi_object mt_params[2];
696 struct acpi_buffer output;
697 union acpi_object out_obj;
Len Brown4be44fc2005-08-05 00:44:28 -0400698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 input.count = 2;
700 input.pointer = mt_params;
701 /* Note: the following values are partly guessed up, but
702 otherwise they seem to work */
703 mt_params[0].type = ACPI_TYPE_INTEGER;
704 mt_params[0].integer.value = 0x02;
705 mt_params[1].type = ACPI_TYPE_INTEGER;
706 mt_params[1].integer.value = 0x02;
707
708 output.length = sizeof(out_obj);
709 output.pointer = &out_obj;
Len Brown4be44fc2005-08-05 00:44:28 -0400710
711 status =
712 acpi_evaluate_object(NULL, hotk->methods->lcd_status,
713 &input, &output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 if (status != AE_OK)
715 return -1;
716 if (out_obj.type == ACPI_TYPE_INTEGER)
717 /* That's what the AML code does */
718 lcd = out_obj.integer.value >> 8;
719 }
Len Brown4be44fc2005-08-05 00:44:28 -0400720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 return (lcd & 1);
722}
723
724static int set_lcd_state(int value)
725{
726 int lcd = 0;
727 acpi_status status = 0;
728
729 lcd = value ? 1 : 0;
730 if (lcd != get_lcd_state()) {
731 /* switch */
732 if (hotk->model != L3H) {
733 status =
Len Brown4be44fc2005-08-05 00:44:28 -0400734 acpi_evaluate_object(NULL,
735 hotk->methods->mt_lcd_switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 NULL, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400737 } else { /* L3H and the like have to be handled differently */
738 if (!write_acpi_int
739 (hotk->handle, hotk->methods->mt_lcd_switch, 0x07,
740 NULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 status = AE_ERROR;
742 /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress,
743 the exact behaviour is simulated here */
744 }
745 if (ACPI_FAILURE(status))
746 printk(KERN_WARNING "Asus ACPI: Error switching LCD\n");
747 }
748 return 0;
749
750}
751
752static int
753proc_read_lcd(char *page, char **start, off_t off, int count, int *eof,
754 void *data)
755{
756 return sprintf(page, "%d\n", get_lcd_state());
757}
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759static int
Len Brown4be44fc2005-08-05 00:44:28 -0400760proc_write_lcd(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 unsigned long count, void *data)
762{
763 int value;
Len Brown4be44fc2005-08-05 00:44:28 -0400764
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 count = parse_arg(buffer, count, &value);
766 if (count > 0)
767 set_lcd_state(value);
768 return count;
769}
770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771static int read_brightness(void)
772{
773 int value;
Len Brown4be44fc2005-08-05 00:44:28 -0400774
775 if (hotk->methods->brightness_get) { /* SPLV/GPLV laptop */
776 if (!read_acpi_int(hotk->handle, hotk->methods->brightness_get,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 &value))
Len Brown4be44fc2005-08-05 00:44:28 -0400778 printk(KERN_WARNING
779 "Asus ACPI: Error reading brightness\n");
780 } else if (hotk->methods->brightness_status) { /* For D1 for example */
781 if (!read_acpi_int(NULL, hotk->methods->brightness_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 &value))
Len Brown4be44fc2005-08-05 00:44:28 -0400783 printk(KERN_WARNING
784 "Asus ACPI: Error reading brightness\n");
785 } else /* No GPLV method */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 value = hotk->brightness;
787 return value;
788}
789
790/*
791 * Change the brightness level
792 */
793static void set_brightness(int value)
794{
795 acpi_status status = 0;
796
797 /* SPLV laptop */
Len Brown4be44fc2005-08-05 00:44:28 -0400798 if (hotk->methods->brightness_set) {
799 if (!write_acpi_int(hotk->handle, hotk->methods->brightness_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 value, NULL))
Len Brown4be44fc2005-08-05 00:44:28 -0400801 printk(KERN_WARNING
802 "Asus ACPI: Error changing brightness\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 return;
804 }
805
806 /* No SPLV method if we are here, act as appropriate */
807 value -= read_brightness();
808 while (value != 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400809 status = acpi_evaluate_object(NULL, (value > 0) ?
810 hotk->methods->brightness_up :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 hotk->methods->brightness_down,
812 NULL, NULL);
813 (value > 0) ? value-- : value++;
814 if (ACPI_FAILURE(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400815 printk(KERN_WARNING
816 "Asus ACPI: Error changing brightness\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 }
818 return;
819}
820
821static int
822proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
823 void *data)
824{
825 return sprintf(page, "%d\n", read_brightness());
826}
827
828static int
Len Brown4be44fc2005-08-05 00:44:28 -0400829proc_write_brn(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 unsigned long count, void *data)
831{
832 int value;
833
834 count = parse_arg(buffer, count, &value);
835 if (count > 0) {
836 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400837 /* 0 <= value <= 15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 set_brightness(value);
839 } else if (count < 0) {
840 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
841 }
842
843 return count;
844}
845
846static void set_display(int value)
847{
848 /* no sanity check needed for now */
Len Brown4be44fc2005-08-05 00:44:28 -0400849 if (!write_acpi_int(hotk->handle, hotk->methods->display_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 value, NULL))
851 printk(KERN_WARNING "Asus ACPI: Error setting display\n");
852 return;
853}
854
855/*
856 * Now, *this* one could be more user-friendly, but so far, no-one has
857 * complained. The significance of bits is the same as in proc_write_disp()
858 */
859static int
860proc_read_disp(char *page, char **start, off_t off, int count, int *eof,
Len Brown4be44fc2005-08-05 00:44:28 -0400861 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862{
863 int value = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 if (!read_acpi_int(hotk->handle, hotk->methods->display_get, &value))
Len Brown4be44fc2005-08-05 00:44:28 -0400866 printk(KERN_WARNING
867 "Asus ACPI: Error reading display status\n");
868 value &= 0x07; /* needed for some models, shouldn't hurt others */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 return sprintf(page, "%d\n", value);
870}
871
872/*
873 * Experimental support for display switching. As of now: 1 should activate
874 * the LCD output, 2 should do for CRT, and 4 for TV-Out. Any combination
875 * (bitwise) of these will suffice. I never actually tested 3 displays hooked up
876 * simultaneously, so be warned. See the acpi4asus README for more info.
877 */
878static int
Len Brown4be44fc2005-08-05 00:44:28 -0400879proc_write_disp(struct file *file, const char __user * buffer,
880 unsigned long count, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881{
882 int value;
883
884 count = parse_arg(buffer, count, &value);
885 if (count > 0)
886 set_display(value);
887 else if (count < 0)
888 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
889
890 return count;
891}
892
Len Brown4be44fc2005-08-05 00:44:28 -0400893typedef int (proc_readfunc) (char *page, char **start, off_t off, int count,
894 int *eof, void *data);
895typedef int (proc_writefunc) (struct file * file, const char __user * buffer,
896 unsigned long count, void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
898static int
Bjorn Helgaas200739c2006-03-28 17:04:00 -0500899asus_proc_add(char *name, proc_writefunc * writefunc,
Len Brown4be44fc2005-08-05 00:44:28 -0400900 proc_readfunc * readfunc, mode_t mode,
901 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902{
Len Brown4be44fc2005-08-05 00:44:28 -0400903 struct proc_dir_entry *proc =
904 create_proc_entry(name, mode, acpi_device_dir(device));
905 if (!proc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 printk(KERN_WARNING " Unable to create %s fs entry\n", name);
907 return -1;
908 }
909 proc->write_proc = writefunc;
910 proc->read_proc = readfunc;
911 proc->data = acpi_driver_data(device);
912 proc->owner = THIS_MODULE;
913 proc->uid = asus_uid;
914 proc->gid = asus_gid;
915 return 0;
916}
917
Bjorn Helgaas200739c2006-03-28 17:04:00 -0500918static int asus_hotk_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919{
920 struct proc_dir_entry *proc;
921 mode_t mode;
Len Brown4be44fc2005-08-05 00:44:28 -0400922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 /*
924 * If parameter uid or gid is not changed, keep the default setting for
925 * our proc entries (-rw-rw-rw-) else, it means we care about security,
926 * and then set to -rw-rw----
927 */
928
Len Brown4be44fc2005-08-05 00:44:28 -0400929 if ((asus_uid == 0) && (asus_gid == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 mode = S_IFREG | S_IRUGO | S_IWUGO;
931 } else {
932 mode = S_IFREG | S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP;
Karol Kozimoraea19aa2006-01-03 23:05:00 -0500933 printk(KERN_WARNING " asus_uid and asus_gid parameters are "
934 "deprecated, use chown and chmod instead!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 }
936
937 acpi_device_dir(device) = asus_proc_dir;
938 if (!acpi_device_dir(device))
939 return -ENODEV;
940
941 proc = create_proc_entry(PROC_INFO, mode, acpi_device_dir(device));
942 if (proc) {
943 proc->read_proc = proc_read_info;
944 proc->data = acpi_driver_data(device);
945 proc->owner = THIS_MODULE;
946 proc->uid = asus_uid;
947 proc->gid = asus_gid;
948 } else {
949 printk(KERN_WARNING " Unable to create " PROC_INFO
950 " fs entry\n");
951 }
952
953 if (hotk->methods->mt_wled) {
Len Brown4be44fc2005-08-05 00:44:28 -0400954 asus_proc_add(PROC_WLED, &proc_write_wled, &proc_read_wled,
955 mode, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 }
957
Karol Kozimor42cb8912006-06-30 19:04:00 -0400958 if (hotk->methods->mt_ledd) {
959 asus_proc_add(PROC_LEDD, &proc_write_ledd, &proc_read_ledd,
960 mode, device);
961 }
962
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 if (hotk->methods->mt_mled) {
Len Brown4be44fc2005-08-05 00:44:28 -0400964 asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled,
965 mode, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 }
967
968 if (hotk->methods->mt_tled) {
Len Brown4be44fc2005-08-05 00:44:28 -0400969 asus_proc_add(PROC_TLED, &proc_write_tled, &proc_read_tled,
970 mode, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 }
972
Karol Kozimore067aaa2006-06-30 19:07:00 -0400973 if (hotk->methods->mt_bt_switch) {
974 asus_proc_add(PROC_BT, &proc_write_bluetooth,
975 &proc_read_bluetooth, mode, device);
976 }
977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 /*
979 * We need both read node and write method as LCD switch is also accessible
980 * from keyboard
981 */
982 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400983 asus_proc_add(PROC_LCD, &proc_write_lcd, &proc_read_lcd, mode,
984 device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 }
Len Brown4be44fc2005-08-05 00:44:28 -0400986
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 if ((hotk->methods->brightness_up && hotk->methods->brightness_down) ||
988 (hotk->methods->brightness_get && hotk->methods->brightness_set)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400989 asus_proc_add(PROC_BRN, &proc_write_brn, &proc_read_brn, mode,
990 device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 }
992
993 if (hotk->methods->display_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400994 asus_proc_add(PROC_DISP, &proc_write_disp, &proc_read_disp,
995 mode, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 }
997
998 return 0;
999}
1000
Len Brown4be44fc2005-08-05 00:44:28 -04001001static int asus_hotk_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002{
Len Brown4be44fc2005-08-05 00:44:28 -04001003 if (acpi_device_dir(device)) {
1004 remove_proc_entry(PROC_INFO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (hotk->methods->mt_wled)
Len Brown4be44fc2005-08-05 00:44:28 -04001006 remove_proc_entry(PROC_WLED, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 if (hotk->methods->mt_mled)
Len Brown4be44fc2005-08-05 00:44:28 -04001008 remove_proc_entry(PROC_MLED, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 if (hotk->methods->mt_tled)
Len Brown4be44fc2005-08-05 00:44:28 -04001010 remove_proc_entry(PROC_TLED, acpi_device_dir(device));
Karol Kozimor42cb8912006-06-30 19:04:00 -04001011 if (hotk->methods->mt_ledd)
1012 remove_proc_entry(PROC_LEDD, acpi_device_dir(device));
Karol Kozimore067aaa2006-06-30 19:07:00 -04001013 if (hotk->methods->mt_bt_switch)
1014 remove_proc_entry(PROC_BT, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status)
1016 remove_proc_entry(PROC_LCD, acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -04001017 if ((hotk->methods->brightness_up
1018 && hotk->methods->brightness_down)
1019 || (hotk->methods->brightness_get
1020 && hotk->methods->brightness_set))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 remove_proc_entry(PROC_BRN, acpi_device_dir(device));
1022 if (hotk->methods->display_set)
1023 remove_proc_entry(PROC_DISP, acpi_device_dir(device));
1024 }
1025 return 0;
1026}
1027
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
1029{
Len Brown4be44fc2005-08-05 00:44:28 -04001030 /* TODO Find a better way to handle events count. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 if (!hotk)
1032 return;
1033
1034 if ((event & ~((u32) BR_UP)) < 16) {
1035 hotk->brightness = (event & ~((u32) BR_UP));
Len Brown4be44fc2005-08-05 00:44:28 -04001036 } else if ((event & ~((u32) BR_DOWN)) < 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 hotk->brightness = (event & ~((u32) BR_DOWN));
1038 }
1039
1040 acpi_bus_generate_event(hotk->device, event,
1041 hotk->event_count[event % 128]++);
1042
1043 return;
1044}
1045
1046/*
1047 * This function is used to initialize the hotk with right values. In this
1048 * method, we can make all the detection we want, and modify the hotk struct
1049 */
Bjorn Helgaas200739c2006-03-28 17:04:00 -05001050static int asus_hotk_get_info(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
1052 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
1053 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
1054 union acpi_object *model = NULL;
1055 int bsts_result;
1056 acpi_status status;
1057
1058 /*
1059 * Get DSDT headers early enough to allow for differentiating between
1060 * models, but late enough to allow acpi_bus_register_driver() to fail
1061 * before doing anything ACPI-specific. Should we encounter a machine,
1062 * which needs special handling (i.e. its hotkey device has a different
1063 * HID), this bit will be moved. A global variable asus_info contains
1064 * the DSDT header.
1065 */
Bob Mooreb229cf92006-04-21 17:15:00 -04001066 status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 if (ACPI_FAILURE(status))
1068 printk(KERN_WARNING " Couldn't get the DSDT table header\n");
1069 else
Len Brown4be44fc2005-08-05 00:44:28 -04001070 asus_info = (struct acpi_table_header *)dsdt.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072 /* We have to write 0 on init this far for all ASUS models */
1073 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
1074 printk(KERN_ERR " Hotkey initialization failed\n");
1075 return -ENODEV;
1076 }
1077
1078 /* This needs to be called for some laptops to init properly */
1079 if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result))
1080 printk(KERN_WARNING " Error calling BSTS\n");
1081 else if (bsts_result)
Len Brown4be44fc2005-08-05 00:44:28 -04001082 printk(KERN_NOTICE " BSTS called, 0x%02x returned\n",
1083 bsts_result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Karol Kozimorb697b532005-12-22 12:42:00 -05001085 /* This is unlikely with implicit return */
1086 if (buffer.pointer == NULL)
1087 return -EINVAL;
1088
Karol Kozimora170a532006-06-30 19:03:00 -04001089 model = (union acpi_object *)buffer.pointer;
Karol Kozimorb697b532005-12-22 12:42:00 -05001090 /*
1091 * Samsung P30 has a device with a valid _HID whose INIT does not
1092 * return anything. It used to be possible to catch this exception,
1093 * but the implicit return code will now happily confuse the
1094 * driver. We assume that every ACPI_TYPE_STRING is a valid model
1095 * identifier but it's still possible to get completely bogus data.
1096 */
1097 if (model->type == ACPI_TYPE_STRING) {
Karol Kozimora170a532006-06-30 19:03:00 -04001098 printk(KERN_NOTICE " %s model detected, ",
1099 model->string.pointer);
Karol Kozimorb697b532005-12-22 12:42:00 -05001100 } else {
Len Brown4be44fc2005-08-05 00:44:28 -04001101 if (asus_info && /* Samsung P30 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) {
1103 hotk->model = P30;
Len Brown4be44fc2005-08-05 00:44:28 -04001104 printk(KERN_NOTICE
1105 " Samsung P30 detected, supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 } else {
1107 hotk->model = M2E;
1108 printk(KERN_WARNING " no string returned by INIT\n");
1109 printk(KERN_WARNING " trying default values, supply "
1110 "the developers with your DSDT\n");
1111 }
1112 hotk->methods = &model_conf[hotk->model];
Karol Kozimora170a532006-06-30 19:03:00 -04001113
Len Brown02438d82006-06-30 03:19:10 -04001114 kfree(model);
Len Brown4be44fc2005-08-05 00:44:28 -04001115
Karol Kozimorb697b532005-12-22 12:42:00 -05001116 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 }
1118
1119 hotk->model = END_MODEL;
1120 if (strncmp(model->string.pointer, "L3D", 3) == 0)
1121 hotk->model = L3D;
Karol Kozimorebccb842006-06-30 19:08:00 -04001122 else if (strncmp(model->string.pointer, "L2E", 3) == 0 ||
1123 strncmp(model->string.pointer, "L3H", 3) == 0 ||
1124 strncmp(model->string.pointer, "L5D", 3) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 hotk->model = L3H;
1126 else if (strncmp(model->string.pointer, "L3", 2) == 0 ||
1127 strncmp(model->string.pointer, "L2B", 3) == 0)
1128 hotk->model = L3C;
1129 else if (strncmp(model->string.pointer, "L8L", 3) == 0)
1130 hotk->model = L8L;
1131 else if (strncmp(model->string.pointer, "L4R", 3) == 0)
1132 hotk->model = L4R;
Karol Kozimorc067a782006-06-30 19:05:00 -04001133 else if (strncmp(model->string.pointer, "M6N", 3) == 0 ||
1134 strncmp(model->string.pointer, "W3N", 3) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 hotk->model = M6N;
Karol Kozimored2cb072006-06-30 19:03:00 -04001136 else if (strncmp(model->string.pointer, "M6R", 3) == 0 ||
1137 strncmp(model->string.pointer, "A3G", 3) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 hotk->model = M6R;
1139 else if (strncmp(model->string.pointer, "M2N", 3) == 0 ||
1140 strncmp(model->string.pointer, "M3N", 3) == 0 ||
1141 strncmp(model->string.pointer, "M5N", 3) == 0 ||
1142 strncmp(model->string.pointer, "M6N", 3) == 0 ||
1143 strncmp(model->string.pointer, "S1N", 3) == 0 ||
Karol Kozimor42cb8912006-06-30 19:04:00 -04001144 strncmp(model->string.pointer, "S5N", 3) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 hotk->model = xxN;
1146 else if (strncmp(model->string.pointer, "M1", 2) == 0)
1147 hotk->model = M1A;
1148 else if (strncmp(model->string.pointer, "M2", 2) == 0 ||
1149 strncmp(model->string.pointer, "L4E", 3) == 0)
1150 hotk->model = M2E;
1151 else if (strncmp(model->string.pointer, "L2", 2) == 0)
1152 hotk->model = L2D;
1153 else if (strncmp(model->string.pointer, "L8", 2) == 0)
1154 hotk->model = S1x;
1155 else if (strncmp(model->string.pointer, "D1", 2) == 0)
1156 hotk->model = D1x;
1157 else if (strncmp(model->string.pointer, "A1", 2) == 0)
1158 hotk->model = A1x;
1159 else if (strncmp(model->string.pointer, "A2", 2) == 0)
1160 hotk->model = A2x;
1161 else if (strncmp(model->string.pointer, "J1", 2) == 0)
1162 hotk->model = S2x;
1163 else if (strncmp(model->string.pointer, "L5", 2) == 0)
1164 hotk->model = L5x;
Karol Kozimorf78c5892006-06-30 19:06:00 -04001165 else if (strncmp(model->string.pointer, "A4G", 3) == 0)
1166 hotk->model = A4G;
Karol Kozimor42cb8912006-06-30 19:04:00 -04001167 else if (strncmp(model->string.pointer, "W1N", 3) == 0)
1168 hotk->model = W1N;
Karol Kozimore067aaa2006-06-30 19:07:00 -04001169 else if (strncmp(model->string.pointer, "W5A", 3) == 0)
1170 hotk->model = W5A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
1172 if (hotk->model == END_MODEL) {
1173 printk("unsupported, trying default values, supply the "
1174 "developers with your DSDT\n");
1175 hotk->model = M2E;
1176 } else {
1177 printk("supported\n");
1178 }
1179
1180 hotk->methods = &model_conf[hotk->model];
1181
1182 /* Sort of per-model blacklist */
1183 if (strncmp(model->string.pointer, "L2B", 3) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -04001184 hotk->methods->lcd_status = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 /* L2B is similar enough to L3C to use its settings, with this only
1186 exception */
Karol Kozimored2cb072006-06-30 19:03:00 -04001187 else if (strncmp(model->string.pointer, "A3G", 3) == 0)
1188 hotk->methods->lcd_status = "\\BLFG";
1189 /* A3G is like M6R */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 else if (strncmp(model->string.pointer, "S5N", 3) == 0 ||
Karol Kozimorc067a782006-06-30 19:05:00 -04001191 strncmp(model->string.pointer, "M5N", 3) == 0 ||
1192 strncmp(model->string.pointer, "W3N", 3) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -04001193 hotk->methods->mt_mled = NULL;
Karol Kozimorc067a782006-06-30 19:05:00 -04001194 /* S5N, M5N and W3N have no MLED */
Karol Kozimorebccb842006-06-30 19:08:00 -04001195 else if (strncmp(model->string.pointer, "L5D", 3) == 0)
1196 hotk->methods->mt_wled = NULL;
1197 /* L5D's WLED is not controlled by ACPI */
Karol Kozimor42cb8912006-06-30 19:04:00 -04001198 else if (strncmp(model->string.pointer, "M2N", 3) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -04001199 hotk->methods->mt_wled = "WLED";
Karol Kozimor42cb8912006-06-30 19:04:00 -04001200 /* M2N has a usable WLED */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 else if (asus_info) {
1202 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0)
1203 hotk->methods->mled_status = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001204 /* S1300A reports L84F, but L1400B too, account for that */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 }
1206
Len Brown02438d82006-06-30 03:19:10 -04001207 kfree(model);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
1209 return AE_OK;
1210}
1211
Bjorn Helgaas200739c2006-03-28 17:04:00 -05001212static int asus_hotk_check(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
1214 int result = 0;
1215
1216 result = acpi_bus_get_status(hotk->device);
1217 if (result)
1218 return result;
1219
1220 if (hotk->device->status.present) {
1221 result = asus_hotk_get_info();
1222 } else {
1223 printk(KERN_ERR " Hotkey device not present, aborting\n");
1224 return -EINVAL;
1225 }
1226
1227 return result;
1228}
1229
Bjorn Helgaas578b3332006-03-28 17:04:00 -05001230static int asus_hotk_found;
1231
Bjorn Helgaas200739c2006-03-28 17:04:00 -05001232static int asus_hotk_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233{
1234 acpi_status status = AE_OK;
1235 int result;
1236
1237 if (!device)
1238 return -EINVAL;
1239
1240 printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n",
1241 ASUS_ACPI_VERSION);
1242
1243 hotk =
Len Brown4be44fc2005-08-05 00:44:28 -04001244 (struct asus_hotk *)kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 if (!hotk)
1246 return -ENOMEM;
1247 memset(hotk, 0, sizeof(struct asus_hotk));
1248
1249 hotk->handle = device->handle;
1250 strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME);
1251 strcpy(acpi_device_class(device), ACPI_HOTK_CLASS);
1252 acpi_driver_data(device) = hotk;
1253 hotk->device = device;
1254
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 result = asus_hotk_check();
1256 if (result)
1257 goto end;
1258
1259 result = asus_hotk_add_fs(device);
1260 if (result)
1261 goto end;
1262
1263 /*
1264 * We install the handler, it will receive the hotk in parameter, so, we
1265 * could add other data to the hotk struct
1266 */
1267 status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
1268 asus_hotk_notify, hotk);
1269 if (ACPI_FAILURE(status))
1270 printk(KERN_ERR " Error installing notify handler\n");
1271
1272 /* For laptops without GPLV: init the hotk->brightness value */
Len Brown4be44fc2005-08-05 00:44:28 -04001273 if ((!hotk->methods->brightness_get)
1274 && (!hotk->methods->brightness_status)
Karol Kozimora170a532006-06-30 19:03:00 -04001275 && (hotk->methods->brightness_up && hotk->methods->brightness_down)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001276 status =
1277 acpi_evaluate_object(NULL, hotk->methods->brightness_down,
1278 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 if (ACPI_FAILURE(status))
1280 printk(KERN_WARNING " Error changing brightness\n");
1281 else {
Len Brown4be44fc2005-08-05 00:44:28 -04001282 status =
1283 acpi_evaluate_object(NULL,
1284 hotk->methods->brightness_up,
1285 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 if (ACPI_FAILURE(status))
Len Brown4be44fc2005-08-05 00:44:28 -04001287 printk(KERN_WARNING " Strange, error changing"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 " brightness\n");
1289 }
1290 }
1291
Bjorn Helgaas578b3332006-03-28 17:04:00 -05001292 asus_hotk_found = 1;
1293
Karol Kozimor42cb8912006-06-30 19:04:00 -04001294 /* LED display is off by default */
1295 hotk->ledd_status = 0xFFF;
1296
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 end:
1298 if (result) {
1299 kfree(hotk);
1300 }
1301
1302 return result;
1303}
1304
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305static int asus_hotk_remove(struct acpi_device *device, int type)
1306{
1307 acpi_status status = 0;
1308
1309 if (!device || !acpi_driver_data(device))
1310 return -EINVAL;
1311
1312 status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
1313 asus_hotk_notify);
1314 if (ACPI_FAILURE(status))
1315 printk(KERN_ERR "Asus ACPI: Error removing notify handler\n");
1316
1317 asus_hotk_remove_fs(device);
1318
1319 kfree(hotk);
1320
1321 return 0;
1322}
1323
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324static int __init asus_acpi_init(void)
1325{
1326 int result;
1327
1328 if (acpi_disabled)
1329 return -ENODEV;
1330
Len Brown4be44fc2005-08-05 00:44:28 -04001331 if (!acpi_specific_hotkey_enabled) {
Luming Yufb9802f2005-03-18 18:03:45 -05001332 printk(KERN_ERR "Using generic hotkey driver\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001333 return -ENODEV;
Luming Yufb9802f2005-03-18 18:03:45 -05001334 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir);
1336 if (!asus_proc_dir) {
1337 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n");
1338 return -ENODEV;
1339 }
1340 asus_proc_dir->owner = THIS_MODULE;
1341
1342 result = acpi_bus_register_driver(&asus_hotk_driver);
Bjorn Helgaas578b3332006-03-28 17:04:00 -05001343 if (result < 0) {
1344 remove_proc_entry(PROC_ASUS, acpi_root_dir);
Andrew Morton5e7d8812006-06-24 19:36:00 -04001345 return result;
Bjorn Helgaas578b3332006-03-28 17:04:00 -05001346 }
1347
1348 /*
1349 * This is a bit of a kludge. We only want this module loaded
1350 * for ASUS systems, but there's currently no way to probe the
1351 * ACPI namespace for ASUS HIDs. So we just return failure if
1352 * we didn't find one, which will cause the module to be
1353 * unloaded.
1354 */
1355 if (!asus_hotk_found) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 acpi_bus_unregister_driver(&asus_hotk_driver);
1357 remove_proc_entry(PROC_ASUS, acpi_root_dir);
Andrew Mortonebd5f2c2006-05-13 22:56:00 -04001358 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 }
1360
1361 return 0;
1362}
1363
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364static void __exit asus_acpi_exit(void)
1365{
1366 acpi_bus_unregister_driver(&asus_hotk_driver);
1367 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1368
Len Brown02438d82006-06-30 03:19:10 -04001369 kfree(asus_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
1371 return;
1372}
1373
1374module_init(asus_acpi_init);
1375module_exit(asus_acpi_exit);