blob: 38b69cb69773b00e3ad6f7c90e790684826f1fe7 [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.
29 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 */
31
32#include <linux/kernel.h>
33#include <linux/module.h>
34#include <linux/init.h>
35#include <linux/types.h>
36#include <linux/proc_fs.h>
37#include <acpi/acpi_drivers.h>
38#include <acpi/acpi_bus.h>
39#include <asm/uaccess.h>
40
Karol Kozimora170a532006-06-30 19:03:00 -040041#define ASUS_ACPI_VERSION "0.30"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#define PROC_ASUS "asus" //the directory
44#define PROC_MLED "mled"
45#define PROC_WLED "wled"
46#define PROC_TLED "tled"
47#define PROC_INFO "info"
48#define PROC_LCD "lcd"
49#define PROC_BRN "brn"
50#define PROC_DISP "disp"
51
52#define ACPI_HOTK_NAME "Asus Laptop ACPI Extras Driver"
53#define ACPI_HOTK_CLASS "hotkey"
54#define ACPI_HOTK_DEVICE_NAME "Hotkey"
55#define ACPI_HOTK_HID "ATK0100"
56
57/*
58 * Some events we use, same for all Asus
59 */
Len Brown4be44fc2005-08-05 00:44:28 -040060#define BR_UP 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -070061#define BR_DOWN 0x20
62
63/*
64 * Flags for hotk status
65 */
66#define MLED_ON 0x01 //is MLED ON ?
67#define WLED_ON 0x02
68#define TLED_ON 0x04
69
70MODULE_AUTHOR("Julien Lerouge, Karol Kozimor");
71MODULE_DESCRIPTION(ACPI_HOTK_NAME);
72MODULE_LICENSE("GPL");
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074static uid_t asus_uid;
75static gid_t asus_gid;
76module_param(asus_uid, uint, 0);
Karol Kozimoraea19aa2006-01-03 23:05:00 -050077MODULE_PARM_DESC(asus_uid, "UID for entries in /proc/acpi/asus.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070078module_param(asus_gid, uint, 0);
Karol Kozimoraea19aa2006-01-03 23:05:00 -050079MODULE_PARM_DESC(asus_gid, "GID for entries in /proc/acpi/asus.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Linus Torvalds1da177e2005-04-16 15:20:36 -070081/* For each model, all features implemented,
82 * those marked with R are relative to HOTK, A for absolute */
83struct model_data {
Len Brown4be44fc2005-08-05 00:44:28 -040084 char *name; //name of the laptop________________A
85 char *mt_mled; //method to handle mled_____________R
86 char *mled_status; //node to handle mled reading_______A
87 char *mt_wled; //method to handle wled_____________R
88 char *wled_status; //node to handle wled reading_______A
89 char *mt_tled; //method to handle tled_____________R
90 char *tled_status; //node to handle tled reading_______A
91 char *mt_lcd_switch; //method to turn LCD ON/OFF_________A
92 char *lcd_status; //node to read LCD panel state______A
93 char *brightness_up; //method to set brightness up_______A
94 char *brightness_down; //guess what ?______________________A
95 char *brightness_set; //method to set absolute brightness_R
96 char *brightness_get; //method to get absolute brightness_R
97 char *brightness_status; //node to get brightness____________A
98 char *display_set; //method to set video output________R
99 char *display_get; //method to get video output________R
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100};
101
102/*
103 * This is the main structure, we can use it to store anything interesting
104 * about the hotk device
105 */
106struct asus_hotk {
Len Brown4be44fc2005-08-05 00:44:28 -0400107 struct acpi_device *device; //the device we are in
108 acpi_handle handle; //the handle of the hotk device
109 char status; //status of the hotk, for LEDs, ...
110 struct model_data *methods; //methods available on the laptop
111 u8 brightness; //brightness level
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 enum {
Len Brown4be44fc2005-08-05 00:44:28 -0400113 A1x = 0, //A1340D, A1300F
114 A2x, //A2500H
115 D1x, //D1
116 L2D, //L2000D
117 L3C, //L3800C
118 L3D, //L3400D
119 L3H, //L3H, but also L2000E
120 L4R, //L4500R
121 L5x, //L5800C
122 L8L, //L8400L
123 M1A, //M1300A
124 M2E, //M2400E, L4400L
125 M6N, //M6800N
126 M6R, //M6700R
127 P30, //Samsung P30
128 S1x, //S1300A, but also L1400B and M2400A (L84F)
129 S2x, //S200 (J1 reported), Victor MP-XP7210
130 xxN, //M2400N, M3700N, M5200N, S1300N, S5200N, W1OOON
131 //(Centrino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 END_MODEL
Len Brown4be44fc2005-08-05 00:44:28 -0400133 } model; //Models currently supported
134 u16 event_count[128]; //count for each event TODO make this better
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135};
136
137/* Here we go */
138#define A1x_PREFIX "\\_SB.PCI0.ISA.EC0."
139#define L3C_PREFIX "\\_SB.PCI0.PX40.ECD0."
140#define M1A_PREFIX "\\_SB.PCI0.PX40.EC0."
141#define P30_PREFIX "\\_SB.PCI0.LPCB.EC0."
142#define S1x_PREFIX "\\_SB.PCI0.PX40."
143#define S2x_PREFIX A1x_PREFIX
144#define xxN_PREFIX "\\_SB.PCI0.SBRG.EC0."
145
146static struct model_data model_conf[END_MODEL] = {
Len Brown4be44fc2005-08-05 00:44:28 -0400147 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 * TODO I have seen a SWBX and AIBX method on some models, like L1400B,
149 * it seems to be a kind of switch, but what for ?
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 */
151
152 {
Len Brown4be44fc2005-08-05 00:44:28 -0400153 .name = "A1x",
154 .mt_mled = "MLED",
155 .mled_status = "\\MAIL",
156 .mt_lcd_switch = A1x_PREFIX "_Q10",
157 .lcd_status = "\\BKLI",
158 .brightness_up = A1x_PREFIX "_Q0E",
159 .brightness_down = A1x_PREFIX "_Q0F"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161 {
Len Brown4be44fc2005-08-05 00:44:28 -0400162 .name = "A2x",
163 .mt_mled = "MLED",
164 .mt_wled = "WLED",
165 .wled_status = "\\SG66",
166 .mt_lcd_switch = "\\Q10",
167 .lcd_status = "\\BAOF",
168 .brightness_set = "SPLV",
169 .brightness_get = "GPLV",
170 .display_set = "SDSP",
171 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 {
Len Brown4be44fc2005-08-05 00:44:28 -0400174 .name = "D1x",
175 .mt_mled = "MLED",
176 .mt_lcd_switch = "\\Q0D",
177 .lcd_status = "\\GP11",
178 .brightness_up = "\\Q0C",
179 .brightness_down = "\\Q0B",
180 .brightness_status = "\\BLVL",
181 .display_set = "SDSP",
182 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 {
Len Brown4be44fc2005-08-05 00:44:28 -0400185 .name = "L2D",
186 .mt_mled = "MLED",
187 .mled_status = "\\SGP6",
188 .mt_wled = "WLED",
189 .wled_status = "\\RCP3",
190 .mt_lcd_switch = "\\Q10",
191 .lcd_status = "\\SGP0",
192 .brightness_up = "\\Q0E",
193 .brightness_down = "\\Q0F",
194 .display_set = "SDSP",
195 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 {
Len Brown4be44fc2005-08-05 00:44:28 -0400198 .name = "L3C",
199 .mt_mled = "MLED",
200 .mt_wled = "WLED",
201 .mt_lcd_switch = L3C_PREFIX "_Q10",
202 .lcd_status = "\\GL32",
203 .brightness_set = "SPLV",
204 .brightness_get = "GPLV",
205 .display_set = "SDSP",
206 .display_get = "\\_SB.PCI0.PCI1.VGAC.NMAP"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 {
Len Brown4be44fc2005-08-05 00:44:28 -0400209 .name = "L3D",
210 .mt_mled = "MLED",
211 .mled_status = "\\MALD",
212 .mt_wled = "WLED",
213 .mt_lcd_switch = "\\Q10",
214 .lcd_status = "\\BKLG",
215 .brightness_set = "SPLV",
216 .brightness_get = "GPLV",
217 .display_set = "SDSP",
218 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 {
Len Brown4be44fc2005-08-05 00:44:28 -0400221 .name = "L3H",
222 .mt_mled = "MLED",
223 .mt_wled = "WLED",
224 .mt_lcd_switch = "EHK",
225 .lcd_status = "\\_SB.PCI0.PM.PBC",
226 .brightness_set = "SPLV",
227 .brightness_get = "GPLV",
228 .display_set = "SDSP",
229 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 {
Len Brown4be44fc2005-08-05 00:44:28 -0400232 .name = "L4R",
233 .mt_mled = "MLED",
234 .mt_wled = "WLED",
235 .wled_status = "\\_SB.PCI0.SBRG.SG13",
236 .mt_lcd_switch = xxN_PREFIX "_Q10",
237 .lcd_status = "\\_SB.PCI0.SBSM.SEO4",
238 .brightness_set = "SPLV",
239 .brightness_get = "GPLV",
240 .display_set = "SDSP",
241 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243 {
Len Brown4be44fc2005-08-05 00:44:28 -0400244 .name = "L5x",
245 .mt_mled = "MLED",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246/* WLED present, but not controlled by ACPI */
Len Brown4be44fc2005-08-05 00:44:28 -0400247 .mt_tled = "TLED",
248 .mt_lcd_switch = "\\Q0D",
249 .lcd_status = "\\BAOF",
250 .brightness_set = "SPLV",
251 .brightness_get = "GPLV",
252 .display_set = "SDSP",
253 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 {
Len Brown4be44fc2005-08-05 00:44:28 -0400256 .name = "L8L"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257/* No features, but at least support the hotkeys */
Len Brown4be44fc2005-08-05 00:44:28 -0400258 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260 {
Len Brown4be44fc2005-08-05 00:44:28 -0400261 .name = "M1A",
262 .mt_mled = "MLED",
263 .mt_lcd_switch = M1A_PREFIX "Q10",
264 .lcd_status = "\\PNOF",
265 .brightness_up = M1A_PREFIX "Q0E",
266 .brightness_down = M1A_PREFIX "Q0F",
267 .brightness_status = "\\BRIT",
268 .display_set = "SDSP",
269 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271 {
Len Brown4be44fc2005-08-05 00:44:28 -0400272 .name = "M2E",
273 .mt_mled = "MLED",
274 .mt_wled = "WLED",
275 .mt_lcd_switch = "\\Q10",
276 .lcd_status = "\\GP06",
277 .brightness_set = "SPLV",
278 .brightness_get = "GPLV",
279 .display_set = "SDSP",
280 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282 {
Len Brown4be44fc2005-08-05 00:44:28 -0400283 .name = "M6N",
284 .mt_mled = "MLED",
285 .mt_wled = "WLED",
286 .wled_status = "\\_SB.PCI0.SBRG.SG13",
287 .mt_lcd_switch = xxN_PREFIX "_Q10",
288 .lcd_status = "\\_SB.BKLT",
289 .brightness_set = "SPLV",
290 .brightness_get = "GPLV",
291 .display_set = "SDSP",
Karol Kozimorbb84db92006-01-03 23:03:00 -0500292 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 {
Len Brown4be44fc2005-08-05 00:44:28 -0400294 .name = "M6R",
295 .mt_mled = "MLED",
296 .mt_wled = "WLED",
297 .mt_lcd_switch = xxN_PREFIX "_Q10",
298 .lcd_status = "\\_SB.PCI0.SBSM.SEO4",
299 .brightness_set = "SPLV",
300 .brightness_get = "GPLV",
301 .display_set = "SDSP",
302 .display_get = "\\SSTE"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 {
Len Brown4be44fc2005-08-05 00:44:28 -0400305 .name = "P30",
306 .mt_wled = "WLED",
307 .mt_lcd_switch = P30_PREFIX "_Q0E",
308 .lcd_status = "\\BKLT",
309 .brightness_up = P30_PREFIX "_Q68",
310 .brightness_down = P30_PREFIX "_Q69",
311 .brightness_get = "GPLV",
312 .display_set = "SDSP",
313 .display_get = "\\DNXT"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315 {
Len Brown4be44fc2005-08-05 00:44:28 -0400316 .name = "S1x",
317 .mt_mled = "MLED",
318 .mled_status = "\\EMLE",
319 .mt_wled = "WLED",
320 .mt_lcd_switch = S1x_PREFIX "Q10",
321 .lcd_status = "\\PNOF",
322 .brightness_set = "SPLV",
323 .brightness_get = "GPLV"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
325 {
Len Brown4be44fc2005-08-05 00:44:28 -0400326 .name = "S2x",
327 .mt_mled = "MLED",
328 .mled_status = "\\MAIL",
329 .mt_lcd_switch = S2x_PREFIX "_Q10",
330 .lcd_status = "\\BKLI",
331 .brightness_up = S2x_PREFIX "_Q0B",
332 .brightness_down = S2x_PREFIX "_Q0A"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 {
Len Brown4be44fc2005-08-05 00:44:28 -0400335 .name = "xxN",
336 .mt_mled = "MLED",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337/* WLED present, but not controlled by ACPI */
Len Brown4be44fc2005-08-05 00:44:28 -0400338 .mt_lcd_switch = xxN_PREFIX "_Q10",
339 .lcd_status = "\\BKLT",
340 .brightness_set = "SPLV",
341 .brightness_get = "GPLV",
342 .display_set = "SDSP",
343 .display_get = "\\ADVG"}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344};
345
346/* procdir we use */
347static struct proc_dir_entry *asus_proc_dir;
348
349/*
350 * This header is made available to allow proper configuration given model,
351 * revision number , ... this info cannot go in struct asus_hotk because it is
352 * available before the hotk
353 */
354static struct acpi_table_header *asus_info;
355
356/* The actual device the driver binds to */
357static struct asus_hotk *hotk;
358
359/*
360 * The hotkey driver declaration
361 */
362static int asus_hotk_add(struct acpi_device *device);
363static int asus_hotk_remove(struct acpi_device *device, int type);
364static struct acpi_driver asus_hotk_driver = {
Len Brown4be44fc2005-08-05 00:44:28 -0400365 .name = ACPI_HOTK_NAME,
366 .class = ACPI_HOTK_CLASS,
367 .ids = ACPI_HOTK_HID,
368 .ops = {
369 .add = asus_hotk_add,
370 .remove = asus_hotk_remove,
371 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372};
373
374/*
375 * This function evaluates an ACPI method, given an int as parameter, the
376 * method is searched within the scope of the handle, can be NULL. The output
377 * of the method is written is output, which can also be NULL
378 *
379 * returns 1 if write is successful, 0 else.
380 */
381static int write_acpi_int(acpi_handle handle, const char *method, int val,
382 struct acpi_buffer *output)
383{
384 struct acpi_object_list params; //list of input parameters (an int here)
385 union acpi_object in_obj; //the only param we use
386 acpi_status status;
387
388 params.count = 1;
389 params.pointer = &in_obj;
390 in_obj.type = ACPI_TYPE_INTEGER;
391 in_obj.integer.value = val;
392
Len Brown4be44fc2005-08-05 00:44:28 -0400393 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 return (status == AE_OK);
395}
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397static int read_acpi_int(acpi_handle handle, const char *method, int *val)
398{
399 struct acpi_buffer output;
400 union acpi_object out_obj;
401 acpi_status status;
402
403 output.length = sizeof(out_obj);
404 output.pointer = &out_obj;
405
Len Brown4be44fc2005-08-05 00:44:28 -0400406 status = acpi_evaluate_object(handle, (char *)method, NULL, &output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 *val = out_obj.integer.value;
408 return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER);
409}
410
411/*
412 * We write our info in page, we begin at offset off and cannot write more
413 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
414 * number of bytes written in page
415 */
416static int
417proc_read_info(char *page, char **start, off_t off, int count, int *eof,
Len Brown4be44fc2005-08-05 00:44:28 -0400418 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
420 int len = 0;
421 int temp;
422 char buf[16]; //enough for all info
423 /*
424 * We use the easy way, we don't care of off and count, so we don't set eof
425 * to 1
426 */
427
428 len += sprintf(page, ACPI_HOTK_NAME " " ASUS_ACPI_VERSION "\n");
Len Brown4be44fc2005-08-05 00:44:28 -0400429 len += sprintf(page + len, "Model reference : %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 hotk->methods->name);
431 /*
432 * The SFUN method probably allows the original driver to get the list
433 * of features supported by a given model. For now, 0x0100 or 0x0800
434 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
435 * The significance of others is yet to be found.
436 */
437 if (read_acpi_int(hotk->handle, "SFUN", &temp))
Len Brown4be44fc2005-08-05 00:44:28 -0400438 len +=
439 sprintf(page + len, "SFUN value : 0x%04x\n", temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 /*
441 * Another value for userspace: the ASYM method returns 0x02 for
442 * battery low and 0x04 for battery critical, its readings tend to be
443 * more accurate than those provided by _BST.
444 * Note: since not all the laptops provide this method, errors are
445 * silently ignored.
446 */
447 if (read_acpi_int(hotk->handle, "ASYM", &temp))
Len Brown4be44fc2005-08-05 00:44:28 -0400448 len +=
449 sprintf(page + len, "ASYM value : 0x%04x\n", temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 if (asus_info) {
451 snprintf(buf, 16, "%d", asus_info->length);
452 len += sprintf(page + len, "DSDT length : %s\n", buf);
453 snprintf(buf, 16, "%d", asus_info->checksum);
454 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
455 snprintf(buf, 16, "%d", asus_info->revision);
456 len += sprintf(page + len, "DSDT revision : %s\n", buf);
457 snprintf(buf, 7, "%s", asus_info->oem_id);
458 len += sprintf(page + len, "OEM id : %s\n", buf);
459 snprintf(buf, 9, "%s", asus_info->oem_table_id);
460 len += sprintf(page + len, "OEM table id : %s\n", buf);
461 snprintf(buf, 16, "%x", asus_info->oem_revision);
462 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
463 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
464 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
465 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
466 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
467 }
468
469 return len;
470}
471
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472/*
473 * /proc handlers
474 * We write our info in page, we begin at offset off and cannot write more
475 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
476 * number of bytes written in page
477 */
478
479/* Generic LED functions */
Len Brown4be44fc2005-08-05 00:44:28 -0400480static int read_led(const char *ledname, int ledmask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481{
482 if (ledname) {
483 int led_status;
484
485 if (read_acpi_int(NULL, ledname, &led_status))
486 return led_status;
487 else
488 printk(KERN_WARNING "Asus ACPI: Error reading LED "
489 "status\n");
490 }
491 return (hotk->status & ledmask) ? 1 : 0;
492}
493
Len Brown4be44fc2005-08-05 00:44:28 -0400494static int parse_arg(const char __user * buf, unsigned long count, int *val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495{
496 char s[32];
497 if (!count)
498 return 0;
499 if (count > 31)
500 return -EINVAL;
501 if (copy_from_user(s, buf, count))
502 return -EFAULT;
503 s[count] = 0;
504 if (sscanf(s, "%i", val) != 1)
505 return -EINVAL;
506 return count;
507}
508
509/* FIXME: kill extraneous args so it can be called independently */
510static int
Len Brown4be44fc2005-08-05 00:44:28 -0400511write_led(const char __user * buffer, unsigned long count,
512 char *ledname, int ledmask, int invert)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513{
514 int value;
515 int led_out = 0;
516
517 count = parse_arg(buffer, count, &value);
518 if (count > 0)
519 led_out = value ? 1 : 0;
520
521 hotk->status =
522 (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask);
523
Len Brown4be44fc2005-08-05 00:44:28 -0400524 if (invert) /* invert target value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 led_out = !led_out & 0x1;
526
527 if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
Len Brown4be44fc2005-08-05 00:44:28 -0400528 printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n",
529 ledname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 return count;
532}
533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534/*
535 * Proc handlers for MLED
536 */
537static int
538proc_read_mled(char *page, char **start, off_t off, int count, int *eof,
539 void *data)
540{
Len Brown4be44fc2005-08-05 00:44:28 -0400541 return sprintf(page, "%d\n",
542 read_led(hotk->methods->mled_status, MLED_ON));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543}
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545static int
Len Brown4be44fc2005-08-05 00:44:28 -0400546proc_write_mled(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 unsigned long count, void *data)
548{
549 return write_led(buffer, count, hotk->methods->mt_mled, MLED_ON, 1);
550}
551
552/*
553 * Proc handlers for WLED
554 */
555static int
556proc_read_wled(char *page, char **start, off_t off, int count, int *eof,
557 void *data)
558{
Len Brown4be44fc2005-08-05 00:44:28 -0400559 return sprintf(page, "%d\n",
560 read_led(hotk->methods->wled_status, WLED_ON));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561}
562
563static int
Len Brown4be44fc2005-08-05 00:44:28 -0400564proc_write_wled(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 unsigned long count, void *data)
566{
567 return write_led(buffer, count, hotk->methods->mt_wled, WLED_ON, 0);
568}
569
570/*
571 * Proc handlers for TLED
572 */
573static int
574proc_read_tled(char *page, char **start, off_t off, int count, int *eof,
575 void *data)
576{
Len Brown4be44fc2005-08-05 00:44:28 -0400577 return sprintf(page, "%d\n",
578 read_led(hotk->methods->tled_status, TLED_ON));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579}
580
581static int
Len Brown4be44fc2005-08-05 00:44:28 -0400582proc_write_tled(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 unsigned long count, void *data)
584{
585 return write_led(buffer, count, hotk->methods->mt_tled, TLED_ON, 0);
586}
587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588static int get_lcd_state(void)
589{
590 int lcd = 0;
591
592 if (hotk->model != L3H) {
Len Brown4be44fc2005-08-05 00:44:28 -0400593 /* We don't have to check anything if we are here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 if (!read_acpi_int(NULL, hotk->methods->lcd_status, &lcd))
Len Brown4be44fc2005-08-05 00:44:28 -0400595 printk(KERN_WARNING
596 "Asus ACPI: Error reading LCD status\n");
597
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 if (hotk->model == L2D)
599 lcd = ~lcd;
Len Brown4be44fc2005-08-05 00:44:28 -0400600 } else { /* L3H and the like have to be handled differently */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 acpi_status status = 0;
602 struct acpi_object_list input;
603 union acpi_object mt_params[2];
604 struct acpi_buffer output;
605 union acpi_object out_obj;
Len Brown4be44fc2005-08-05 00:44:28 -0400606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 input.count = 2;
608 input.pointer = mt_params;
609 /* Note: the following values are partly guessed up, but
610 otherwise they seem to work */
611 mt_params[0].type = ACPI_TYPE_INTEGER;
612 mt_params[0].integer.value = 0x02;
613 mt_params[1].type = ACPI_TYPE_INTEGER;
614 mt_params[1].integer.value = 0x02;
615
616 output.length = sizeof(out_obj);
617 output.pointer = &out_obj;
Len Brown4be44fc2005-08-05 00:44:28 -0400618
619 status =
620 acpi_evaluate_object(NULL, hotk->methods->lcd_status,
621 &input, &output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 if (status != AE_OK)
623 return -1;
624 if (out_obj.type == ACPI_TYPE_INTEGER)
625 /* That's what the AML code does */
626 lcd = out_obj.integer.value >> 8;
627 }
Len Brown4be44fc2005-08-05 00:44:28 -0400628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return (lcd & 1);
630}
631
632static int set_lcd_state(int value)
633{
634 int lcd = 0;
635 acpi_status status = 0;
636
637 lcd = value ? 1 : 0;
638 if (lcd != get_lcd_state()) {
639 /* switch */
640 if (hotk->model != L3H) {
641 status =
Len Brown4be44fc2005-08-05 00:44:28 -0400642 acpi_evaluate_object(NULL,
643 hotk->methods->mt_lcd_switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 NULL, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400645 } else { /* L3H and the like have to be handled differently */
646 if (!write_acpi_int
647 (hotk->handle, hotk->methods->mt_lcd_switch, 0x07,
648 NULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 status = AE_ERROR;
650 /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress,
651 the exact behaviour is simulated here */
652 }
653 if (ACPI_FAILURE(status))
654 printk(KERN_WARNING "Asus ACPI: Error switching LCD\n");
655 }
656 return 0;
657
658}
659
660static int
661proc_read_lcd(char *page, char **start, off_t off, int count, int *eof,
662 void *data)
663{
664 return sprintf(page, "%d\n", get_lcd_state());
665}
666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667static int
Len Brown4be44fc2005-08-05 00:44:28 -0400668proc_write_lcd(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 unsigned long count, void *data)
670{
671 int value;
Len Brown4be44fc2005-08-05 00:44:28 -0400672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 count = parse_arg(buffer, count, &value);
674 if (count > 0)
675 set_lcd_state(value);
676 return count;
677}
678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679static int read_brightness(void)
680{
681 int value;
Len Brown4be44fc2005-08-05 00:44:28 -0400682
683 if (hotk->methods->brightness_get) { /* SPLV/GPLV laptop */
684 if (!read_acpi_int(hotk->handle, hotk->methods->brightness_get,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 &value))
Len Brown4be44fc2005-08-05 00:44:28 -0400686 printk(KERN_WARNING
687 "Asus ACPI: Error reading brightness\n");
688 } else if (hotk->methods->brightness_status) { /* For D1 for example */
689 if (!read_acpi_int(NULL, hotk->methods->brightness_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 &value))
Len Brown4be44fc2005-08-05 00:44:28 -0400691 printk(KERN_WARNING
692 "Asus ACPI: Error reading brightness\n");
693 } else /* No GPLV method */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 value = hotk->brightness;
695 return value;
696}
697
698/*
699 * Change the brightness level
700 */
701static void set_brightness(int value)
702{
703 acpi_status status = 0;
704
705 /* SPLV laptop */
Len Brown4be44fc2005-08-05 00:44:28 -0400706 if (hotk->methods->brightness_set) {
707 if (!write_acpi_int(hotk->handle, hotk->methods->brightness_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 value, NULL))
Len Brown4be44fc2005-08-05 00:44:28 -0400709 printk(KERN_WARNING
710 "Asus ACPI: Error changing brightness\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 return;
712 }
713
714 /* No SPLV method if we are here, act as appropriate */
715 value -= read_brightness();
716 while (value != 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400717 status = acpi_evaluate_object(NULL, (value > 0) ?
718 hotk->methods->brightness_up :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 hotk->methods->brightness_down,
720 NULL, NULL);
721 (value > 0) ? value-- : value++;
722 if (ACPI_FAILURE(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400723 printk(KERN_WARNING
724 "Asus ACPI: Error changing brightness\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
726 return;
727}
728
729static int
730proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
731 void *data)
732{
733 return sprintf(page, "%d\n", read_brightness());
734}
735
736static int
Len Brown4be44fc2005-08-05 00:44:28 -0400737proc_write_brn(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 unsigned long count, void *data)
739{
740 int value;
741
742 count = parse_arg(buffer, count, &value);
743 if (count > 0) {
744 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400745 /* 0 <= value <= 15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 set_brightness(value);
747 } else if (count < 0) {
748 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
749 }
750
751 return count;
752}
753
754static void set_display(int value)
755{
756 /* no sanity check needed for now */
Len Brown4be44fc2005-08-05 00:44:28 -0400757 if (!write_acpi_int(hotk->handle, hotk->methods->display_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 value, NULL))
759 printk(KERN_WARNING "Asus ACPI: Error setting display\n");
760 return;
761}
762
763/*
764 * Now, *this* one could be more user-friendly, but so far, no-one has
765 * complained. The significance of bits is the same as in proc_write_disp()
766 */
767static int
768proc_read_disp(char *page, char **start, off_t off, int count, int *eof,
Len Brown4be44fc2005-08-05 00:44:28 -0400769 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770{
771 int value = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400772
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 if (!read_acpi_int(hotk->handle, hotk->methods->display_get, &value))
Len Brown4be44fc2005-08-05 00:44:28 -0400774 printk(KERN_WARNING
775 "Asus ACPI: Error reading display status\n");
776 value &= 0x07; /* needed for some models, shouldn't hurt others */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 return sprintf(page, "%d\n", value);
778}
779
780/*
781 * Experimental support for display switching. As of now: 1 should activate
782 * the LCD output, 2 should do for CRT, and 4 for TV-Out. Any combination
783 * (bitwise) of these will suffice. I never actually tested 3 displays hooked up
784 * simultaneously, so be warned. See the acpi4asus README for more info.
785 */
786static int
Len Brown4be44fc2005-08-05 00:44:28 -0400787proc_write_disp(struct file *file, const char __user * buffer,
788 unsigned long count, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
790 int value;
791
792 count = parse_arg(buffer, count, &value);
793 if (count > 0)
794 set_display(value);
795 else if (count < 0)
796 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
797
798 return count;
799}
800
Len Brown4be44fc2005-08-05 00:44:28 -0400801typedef int (proc_readfunc) (char *page, char **start, off_t off, int count,
802 int *eof, void *data);
803typedef int (proc_writefunc) (struct file * file, const char __user * buffer,
804 unsigned long count, void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806static int
Bjorn Helgaas200739c2006-03-28 17:04:00 -0500807asus_proc_add(char *name, proc_writefunc * writefunc,
Len Brown4be44fc2005-08-05 00:44:28 -0400808 proc_readfunc * readfunc, mode_t mode,
809 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
Len Brown4be44fc2005-08-05 00:44:28 -0400811 struct proc_dir_entry *proc =
812 create_proc_entry(name, mode, acpi_device_dir(device));
813 if (!proc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 printk(KERN_WARNING " Unable to create %s fs entry\n", name);
815 return -1;
816 }
817 proc->write_proc = writefunc;
818 proc->read_proc = readfunc;
819 proc->data = acpi_driver_data(device);
820 proc->owner = THIS_MODULE;
821 proc->uid = asus_uid;
822 proc->gid = asus_gid;
823 return 0;
824}
825
Bjorn Helgaas200739c2006-03-28 17:04:00 -0500826static int asus_hotk_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
828 struct proc_dir_entry *proc;
829 mode_t mode;
Len Brown4be44fc2005-08-05 00:44:28 -0400830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 /*
832 * If parameter uid or gid is not changed, keep the default setting for
833 * our proc entries (-rw-rw-rw-) else, it means we care about security,
834 * and then set to -rw-rw----
835 */
836
Len Brown4be44fc2005-08-05 00:44:28 -0400837 if ((asus_uid == 0) && (asus_gid == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 mode = S_IFREG | S_IRUGO | S_IWUGO;
839 } else {
840 mode = S_IFREG | S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP;
Karol Kozimoraea19aa2006-01-03 23:05:00 -0500841 printk(KERN_WARNING " asus_uid and asus_gid parameters are "
842 "deprecated, use chown and chmod instead!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 }
844
845 acpi_device_dir(device) = asus_proc_dir;
846 if (!acpi_device_dir(device))
847 return -ENODEV;
848
849 proc = create_proc_entry(PROC_INFO, mode, acpi_device_dir(device));
850 if (proc) {
851 proc->read_proc = proc_read_info;
852 proc->data = acpi_driver_data(device);
853 proc->owner = THIS_MODULE;
854 proc->uid = asus_uid;
855 proc->gid = asus_gid;
856 } else {
857 printk(KERN_WARNING " Unable to create " PROC_INFO
858 " fs entry\n");
859 }
860
861 if (hotk->methods->mt_wled) {
Len Brown4be44fc2005-08-05 00:44:28 -0400862 asus_proc_add(PROC_WLED, &proc_write_wled, &proc_read_wled,
863 mode, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 }
865
866 if (hotk->methods->mt_mled) {
Len Brown4be44fc2005-08-05 00:44:28 -0400867 asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled,
868 mode, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 }
870
871 if (hotk->methods->mt_tled) {
Len Brown4be44fc2005-08-05 00:44:28 -0400872 asus_proc_add(PROC_TLED, &proc_write_tled, &proc_read_tled,
873 mode, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 }
875
876 /*
877 * We need both read node and write method as LCD switch is also accessible
878 * from keyboard
879 */
880 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400881 asus_proc_add(PROC_LCD, &proc_write_lcd, &proc_read_lcd, mode,
882 device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 }
Len Brown4be44fc2005-08-05 00:44:28 -0400884
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 if ((hotk->methods->brightness_up && hotk->methods->brightness_down) ||
886 (hotk->methods->brightness_get && hotk->methods->brightness_set)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400887 asus_proc_add(PROC_BRN, &proc_write_brn, &proc_read_brn, mode,
888 device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 }
890
891 if (hotk->methods->display_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400892 asus_proc_add(PROC_DISP, &proc_write_disp, &proc_read_disp,
893 mode, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 }
895
896 return 0;
897}
898
Len Brown4be44fc2005-08-05 00:44:28 -0400899static int asus_hotk_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
Len Brown4be44fc2005-08-05 00:44:28 -0400901 if (acpi_device_dir(device)) {
902 remove_proc_entry(PROC_INFO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 if (hotk->methods->mt_wled)
Len Brown4be44fc2005-08-05 00:44:28 -0400904 remove_proc_entry(PROC_WLED, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 if (hotk->methods->mt_mled)
Len Brown4be44fc2005-08-05 00:44:28 -0400906 remove_proc_entry(PROC_MLED, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 if (hotk->methods->mt_tled)
Len Brown4be44fc2005-08-05 00:44:28 -0400908 remove_proc_entry(PROC_TLED, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status)
910 remove_proc_entry(PROC_LCD, acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -0400911 if ((hotk->methods->brightness_up
912 && hotk->methods->brightness_down)
913 || (hotk->methods->brightness_get
914 && hotk->methods->brightness_set))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 remove_proc_entry(PROC_BRN, acpi_device_dir(device));
916 if (hotk->methods->display_set)
917 remove_proc_entry(PROC_DISP, acpi_device_dir(device));
918 }
919 return 0;
920}
921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
923{
Len Brown4be44fc2005-08-05 00:44:28 -0400924 /* TODO Find a better way to handle events count. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 if (!hotk)
926 return;
927
928 if ((event & ~((u32) BR_UP)) < 16) {
929 hotk->brightness = (event & ~((u32) BR_UP));
Len Brown4be44fc2005-08-05 00:44:28 -0400930 } else if ((event & ~((u32) BR_DOWN)) < 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 hotk->brightness = (event & ~((u32) BR_DOWN));
932 }
933
934 acpi_bus_generate_event(hotk->device, event,
935 hotk->event_count[event % 128]++);
936
937 return;
938}
939
940/*
941 * This function is used to initialize the hotk with right values. In this
942 * method, we can make all the detection we want, and modify the hotk struct
943 */
Bjorn Helgaas200739c2006-03-28 17:04:00 -0500944static int asus_hotk_get_info(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945{
946 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
947 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
948 union acpi_object *model = NULL;
949 int bsts_result;
950 acpi_status status;
951
952 /*
953 * Get DSDT headers early enough to allow for differentiating between
954 * models, but late enough to allow acpi_bus_register_driver() to fail
955 * before doing anything ACPI-specific. Should we encounter a machine,
956 * which needs special handling (i.e. its hotkey device has a different
957 * HID), this bit will be moved. A global variable asus_info contains
958 * the DSDT header.
959 */
Bob Mooreb229cf92006-04-21 17:15:00 -0400960 status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 if (ACPI_FAILURE(status))
962 printk(KERN_WARNING " Couldn't get the DSDT table header\n");
963 else
Len Brown4be44fc2005-08-05 00:44:28 -0400964 asus_info = (struct acpi_table_header *)dsdt.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
966 /* We have to write 0 on init this far for all ASUS models */
967 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
968 printk(KERN_ERR " Hotkey initialization failed\n");
969 return -ENODEV;
970 }
971
972 /* This needs to be called for some laptops to init properly */
973 if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result))
974 printk(KERN_WARNING " Error calling BSTS\n");
975 else if (bsts_result)
Len Brown4be44fc2005-08-05 00:44:28 -0400976 printk(KERN_NOTICE " BSTS called, 0x%02x returned\n",
977 bsts_result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Karol Kozimorb697b532005-12-22 12:42:00 -0500979 /* This is unlikely with implicit return */
980 if (buffer.pointer == NULL)
981 return -EINVAL;
982
Karol Kozimora170a532006-06-30 19:03:00 -0400983 model = (union acpi_object *)buffer.pointer;
Karol Kozimorb697b532005-12-22 12:42:00 -0500984 /*
985 * Samsung P30 has a device with a valid _HID whose INIT does not
986 * return anything. It used to be possible to catch this exception,
987 * but the implicit return code will now happily confuse the
988 * driver. We assume that every ACPI_TYPE_STRING is a valid model
989 * identifier but it's still possible to get completely bogus data.
990 */
991 if (model->type == ACPI_TYPE_STRING) {
Karol Kozimora170a532006-06-30 19:03:00 -0400992 printk(KERN_NOTICE " %s model detected, ",
993 model->string.pointer);
Karol Kozimorb697b532005-12-22 12:42:00 -0500994 } else {
Len Brown4be44fc2005-08-05 00:44:28 -0400995 if (asus_info && /* Samsung P30 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) {
997 hotk->model = P30;
Len Brown4be44fc2005-08-05 00:44:28 -0400998 printk(KERN_NOTICE
999 " Samsung P30 detected, supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 } else {
1001 hotk->model = M2E;
1002 printk(KERN_WARNING " no string returned by INIT\n");
1003 printk(KERN_WARNING " trying default values, supply "
1004 "the developers with your DSDT\n");
1005 }
1006 hotk->methods = &model_conf[hotk->model];
Karol Kozimora170a532006-06-30 19:03:00 -04001007
Len Brown02438d82006-06-30 03:19:10 -04001008 kfree(model);
Len Brown4be44fc2005-08-05 00:44:28 -04001009
Karol Kozimorb697b532005-12-22 12:42:00 -05001010 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
1012
1013 hotk->model = END_MODEL;
1014 if (strncmp(model->string.pointer, "L3D", 3) == 0)
1015 hotk->model = L3D;
1016 else if (strncmp(model->string.pointer, "L3H", 3) == 0 ||
1017 strncmp(model->string.pointer, "L2E", 3) == 0)
1018 hotk->model = L3H;
1019 else if (strncmp(model->string.pointer, "L3", 2) == 0 ||
1020 strncmp(model->string.pointer, "L2B", 3) == 0)
1021 hotk->model = L3C;
1022 else if (strncmp(model->string.pointer, "L8L", 3) == 0)
1023 hotk->model = L8L;
1024 else if (strncmp(model->string.pointer, "L4R", 3) == 0)
1025 hotk->model = L4R;
1026 else if (strncmp(model->string.pointer, "M6N", 3) == 0)
1027 hotk->model = M6N;
1028 else if (strncmp(model->string.pointer, "M6R", 3) == 0)
1029 hotk->model = M6R;
1030 else if (strncmp(model->string.pointer, "M2N", 3) == 0 ||
1031 strncmp(model->string.pointer, "M3N", 3) == 0 ||
1032 strncmp(model->string.pointer, "M5N", 3) == 0 ||
1033 strncmp(model->string.pointer, "M6N", 3) == 0 ||
1034 strncmp(model->string.pointer, "S1N", 3) == 0 ||
1035 strncmp(model->string.pointer, "S5N", 3) == 0 ||
Len Brown4be44fc2005-08-05 00:44:28 -04001036 strncmp(model->string.pointer, "W1N", 3) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 hotk->model = xxN;
1038 else if (strncmp(model->string.pointer, "M1", 2) == 0)
1039 hotk->model = M1A;
1040 else if (strncmp(model->string.pointer, "M2", 2) == 0 ||
1041 strncmp(model->string.pointer, "L4E", 3) == 0)
1042 hotk->model = M2E;
1043 else if (strncmp(model->string.pointer, "L2", 2) == 0)
1044 hotk->model = L2D;
1045 else if (strncmp(model->string.pointer, "L8", 2) == 0)
1046 hotk->model = S1x;
1047 else if (strncmp(model->string.pointer, "D1", 2) == 0)
1048 hotk->model = D1x;
1049 else if (strncmp(model->string.pointer, "A1", 2) == 0)
1050 hotk->model = A1x;
1051 else if (strncmp(model->string.pointer, "A2", 2) == 0)
1052 hotk->model = A2x;
1053 else if (strncmp(model->string.pointer, "J1", 2) == 0)
1054 hotk->model = S2x;
1055 else if (strncmp(model->string.pointer, "L5", 2) == 0)
1056 hotk->model = L5x;
1057
1058 if (hotk->model == END_MODEL) {
1059 printk("unsupported, trying default values, supply the "
1060 "developers with your DSDT\n");
1061 hotk->model = M2E;
1062 } else {
1063 printk("supported\n");
1064 }
1065
1066 hotk->methods = &model_conf[hotk->model];
1067
1068 /* Sort of per-model blacklist */
1069 if (strncmp(model->string.pointer, "L2B", 3) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -04001070 hotk->methods->lcd_status = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 /* L2B is similar enough to L3C to use its settings, with this only
1072 exception */
1073 else if (strncmp(model->string.pointer, "S5N", 3) == 0 ||
1074 strncmp(model->string.pointer, "M5N", 3) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -04001075 hotk->methods->mt_mled = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 /* S5N and M5N have no MLED */
1077 else if (strncmp(model->string.pointer, "M2N", 3) == 0 ||
1078 strncmp(model->string.pointer, "W1N", 3) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -04001079 hotk->methods->mt_wled = "WLED";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 /* M2N and W1N have a usable WLED */
1081 else if (asus_info) {
1082 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0)
1083 hotk->methods->mled_status = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001084 /* S1300A reports L84F, but L1400B too, account for that */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 }
1086
Len Brown02438d82006-06-30 03:19:10 -04001087 kfree(model);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089 return AE_OK;
1090}
1091
Bjorn Helgaas200739c2006-03-28 17:04:00 -05001092static int asus_hotk_check(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093{
1094 int result = 0;
1095
1096 result = acpi_bus_get_status(hotk->device);
1097 if (result)
1098 return result;
1099
1100 if (hotk->device->status.present) {
1101 result = asus_hotk_get_info();
1102 } else {
1103 printk(KERN_ERR " Hotkey device not present, aborting\n");
1104 return -EINVAL;
1105 }
1106
1107 return result;
1108}
1109
Bjorn Helgaas578b3332006-03-28 17:04:00 -05001110static int asus_hotk_found;
1111
Bjorn Helgaas200739c2006-03-28 17:04:00 -05001112static int asus_hotk_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113{
1114 acpi_status status = AE_OK;
1115 int result;
1116
1117 if (!device)
1118 return -EINVAL;
1119
1120 printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n",
1121 ASUS_ACPI_VERSION);
1122
1123 hotk =
Len Brown4be44fc2005-08-05 00:44:28 -04001124 (struct asus_hotk *)kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 if (!hotk)
1126 return -ENOMEM;
1127 memset(hotk, 0, sizeof(struct asus_hotk));
1128
1129 hotk->handle = device->handle;
1130 strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME);
1131 strcpy(acpi_device_class(device), ACPI_HOTK_CLASS);
1132 acpi_driver_data(device) = hotk;
1133 hotk->device = device;
1134
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 result = asus_hotk_check();
1136 if (result)
1137 goto end;
1138
1139 result = asus_hotk_add_fs(device);
1140 if (result)
1141 goto end;
1142
1143 /*
1144 * We install the handler, it will receive the hotk in parameter, so, we
1145 * could add other data to the hotk struct
1146 */
1147 status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
1148 asus_hotk_notify, hotk);
1149 if (ACPI_FAILURE(status))
1150 printk(KERN_ERR " Error installing notify handler\n");
1151
1152 /* For laptops without GPLV: init the hotk->brightness value */
Len Brown4be44fc2005-08-05 00:44:28 -04001153 if ((!hotk->methods->brightness_get)
1154 && (!hotk->methods->brightness_status)
Karol Kozimora170a532006-06-30 19:03:00 -04001155 && (hotk->methods->brightness_up && hotk->methods->brightness_down)) {
Len Brown4be44fc2005-08-05 00:44:28 -04001156 status =
1157 acpi_evaluate_object(NULL, hotk->methods->brightness_down,
1158 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 if (ACPI_FAILURE(status))
1160 printk(KERN_WARNING " Error changing brightness\n");
1161 else {
Len Brown4be44fc2005-08-05 00:44:28 -04001162 status =
1163 acpi_evaluate_object(NULL,
1164 hotk->methods->brightness_up,
1165 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 if (ACPI_FAILURE(status))
Len Brown4be44fc2005-08-05 00:44:28 -04001167 printk(KERN_WARNING " Strange, error changing"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 " brightness\n");
1169 }
1170 }
1171
Bjorn Helgaas578b3332006-03-28 17:04:00 -05001172 asus_hotk_found = 1;
1173
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 end:
1175 if (result) {
1176 kfree(hotk);
1177 }
1178
1179 return result;
1180}
1181
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182static int asus_hotk_remove(struct acpi_device *device, int type)
1183{
1184 acpi_status status = 0;
1185
1186 if (!device || !acpi_driver_data(device))
1187 return -EINVAL;
1188
1189 status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
1190 asus_hotk_notify);
1191 if (ACPI_FAILURE(status))
1192 printk(KERN_ERR "Asus ACPI: Error removing notify handler\n");
1193
1194 asus_hotk_remove_fs(device);
1195
1196 kfree(hotk);
1197
1198 return 0;
1199}
1200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201static int __init asus_acpi_init(void)
1202{
1203 int result;
1204
1205 if (acpi_disabled)
1206 return -ENODEV;
1207
Len Brown4be44fc2005-08-05 00:44:28 -04001208 if (!acpi_specific_hotkey_enabled) {
Luming Yufb9802f2005-03-18 18:03:45 -05001209 printk(KERN_ERR "Using generic hotkey driver\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001210 return -ENODEV;
Luming Yufb9802f2005-03-18 18:03:45 -05001211 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir);
1213 if (!asus_proc_dir) {
1214 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n");
1215 return -ENODEV;
1216 }
1217 asus_proc_dir->owner = THIS_MODULE;
1218
1219 result = acpi_bus_register_driver(&asus_hotk_driver);
Bjorn Helgaas578b3332006-03-28 17:04:00 -05001220 if (result < 0) {
1221 remove_proc_entry(PROC_ASUS, acpi_root_dir);
Andrew Morton5e7d8812006-06-24 19:36:00 -04001222 return result;
Bjorn Helgaas578b3332006-03-28 17:04:00 -05001223 }
1224
1225 /*
1226 * This is a bit of a kludge. We only want this module loaded
1227 * for ASUS systems, but there's currently no way to probe the
1228 * ACPI namespace for ASUS HIDs. So we just return failure if
1229 * we didn't find one, which will cause the module to be
1230 * unloaded.
1231 */
1232 if (!asus_hotk_found) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 acpi_bus_unregister_driver(&asus_hotk_driver);
1234 remove_proc_entry(PROC_ASUS, acpi_root_dir);
Andrew Mortonebd5f2c2006-05-13 22:56:00 -04001235 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 }
1237
1238 return 0;
1239}
1240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241static void __exit asus_acpi_exit(void)
1242{
1243 acpi_bus_unregister_driver(&asus_hotk_driver);
1244 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1245
Len Brown02438d82006-06-30 03:19:10 -04001246 kfree(asus_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
1248 return;
1249}
1250
1251module_init(asus_acpi_init);
1252module_exit(asus_acpi_exit);