blob: 055cfd5c8766c3f217ee943e282557e7c3e7effb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * asus_acpi.c - Asus Laptop ACPI Extras
3 *
4 *
5 * Copyright (C) 2002, 2003, 2004 Julien Lerouge, Karol Kozimor
6 *
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 *
30 * TODO:
31 * add Fn key status
32 * Add mode selection on module loading (parameter) -> still necessary?
33 * Complete display switching -- may require dirty hacks or calling _DOS?
34 */
35
36#include <linux/kernel.h>
37#include <linux/module.h>
38#include <linux/init.h>
39#include <linux/types.h>
40#include <linux/proc_fs.h>
41#include <acpi/acpi_drivers.h>
42#include <acpi/acpi_bus.h>
43#include <asm/uaccess.h>
44
45#define ASUS_ACPI_VERSION "0.29"
46
47#define PROC_ASUS "asus" //the directory
48#define PROC_MLED "mled"
49#define PROC_WLED "wled"
50#define PROC_TLED "tled"
51#define PROC_INFO "info"
52#define PROC_LCD "lcd"
53#define PROC_BRN "brn"
54#define PROC_DISP "disp"
55
56#define ACPI_HOTK_NAME "Asus Laptop ACPI Extras Driver"
57#define ACPI_HOTK_CLASS "hotkey"
58#define ACPI_HOTK_DEVICE_NAME "Hotkey"
59#define ACPI_HOTK_HID "ATK0100"
60
61/*
62 * Some events we use, same for all Asus
63 */
Len Brown4be44fc2005-08-05 00:44:28 -040064#define BR_UP 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define BR_DOWN 0x20
66
67/*
68 * Flags for hotk status
69 */
70#define MLED_ON 0x01 //is MLED ON ?
71#define WLED_ON 0x02
72#define TLED_ON 0x04
73
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
95 char *mt_lcd_switch; //method to turn LCD ON/OFF_________A
96 char *lcd_status; //node to read LCD panel state______A
97 char *brightness_up; //method to set brightness up_______A
98 char *brightness_down; //guess what ?______________________A
99 char *brightness_set; //method to set absolute brightness_R
100 char *brightness_get; //method to get absolute brightness_R
101 char *brightness_status; //node to get brightness____________A
102 char *display_set; //method to set video output________R
103 char *display_get; //method to get video output________R
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104};
105
106/*
107 * This is the main structure, we can use it to store anything interesting
108 * about the hotk device
109 */
110struct asus_hotk {
Len Brown4be44fc2005-08-05 00:44:28 -0400111 struct acpi_device *device; //the device we are in
112 acpi_handle handle; //the handle of the hotk device
113 char status; //status of the hotk, for LEDs, ...
114 struct model_data *methods; //methods available on the laptop
115 u8 brightness; //brightness level
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 enum {
Len Brown4be44fc2005-08-05 00:44:28 -0400117 A1x = 0, //A1340D, A1300F
118 A2x, //A2500H
119 D1x, //D1
120 L2D, //L2000D
121 L3C, //L3800C
122 L3D, //L3400D
123 L3H, //L3H, but also L2000E
124 L4R, //L4500R
125 L5x, //L5800C
126 L8L, //L8400L
127 M1A, //M1300A
128 M2E, //M2400E, L4400L
129 M6N, //M6800N
130 M6R, //M6700R
131 P30, //Samsung P30
132 S1x, //S1300A, but also L1400B and M2400A (L84F)
133 S2x, //S200 (J1 reported), Victor MP-XP7210
134 xxN, //M2400N, M3700N, M5200N, S1300N, S5200N, W1OOON
135 //(Centrino)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 END_MODEL
Len Brown4be44fc2005-08-05 00:44:28 -0400137 } model; //Models currently supported
138 u16 event_count[128]; //count for each event TODO make this better
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139};
140
141/* Here we go */
142#define A1x_PREFIX "\\_SB.PCI0.ISA.EC0."
143#define L3C_PREFIX "\\_SB.PCI0.PX40.ECD0."
144#define M1A_PREFIX "\\_SB.PCI0.PX40.EC0."
145#define P30_PREFIX "\\_SB.PCI0.LPCB.EC0."
146#define S1x_PREFIX "\\_SB.PCI0.PX40."
147#define S2x_PREFIX A1x_PREFIX
148#define xxN_PREFIX "\\_SB.PCI0.SBRG.EC0."
149
150static struct model_data model_conf[END_MODEL] = {
Len Brown4be44fc2005-08-05 00:44:28 -0400151 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 * Those pathnames are relative to the HOTK / ATKD device :
153 * - mt_mled
154 * - mt_wled
155 * - brightness_set
156 * - brightness_get
157 * - display_set
158 * - display_get
159 *
160 * TODO I have seen a SWBX and AIBX method on some models, like L1400B,
161 * it seems to be a kind of switch, but what for ?
162 *
163 */
164
165 {
Len Brown4be44fc2005-08-05 00:44:28 -0400166 .name = "A1x",
167 .mt_mled = "MLED",
168 .mled_status = "\\MAIL",
169 .mt_lcd_switch = A1x_PREFIX "_Q10",
170 .lcd_status = "\\BKLI",
171 .brightness_up = A1x_PREFIX "_Q0E",
172 .brightness_down = A1x_PREFIX "_Q0F"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 {
Len Brown4be44fc2005-08-05 00:44:28 -0400175 .name = "A2x",
176 .mt_mled = "MLED",
177 .mt_wled = "WLED",
178 .wled_status = "\\SG66",
179 .mt_lcd_switch = "\\Q10",
180 .lcd_status = "\\BAOF",
181 .brightness_set = "SPLV",
182 .brightness_get = "GPLV",
183 .display_set = "SDSP",
184 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 {
Len Brown4be44fc2005-08-05 00:44:28 -0400187 .name = "D1x",
188 .mt_mled = "MLED",
189 .mt_lcd_switch = "\\Q0D",
190 .lcd_status = "\\GP11",
191 .brightness_up = "\\Q0C",
192 .brightness_down = "\\Q0B",
193 .brightness_status = "\\BLVL",
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 = "L2D",
199 .mt_mled = "MLED",
200 .mled_status = "\\SGP6",
201 .mt_wled = "WLED",
202 .wled_status = "\\RCP3",
203 .mt_lcd_switch = "\\Q10",
204 .lcd_status = "\\SGP0",
205 .brightness_up = "\\Q0E",
206 .brightness_down = "\\Q0F",
207 .display_set = "SDSP",
208 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 {
Len Brown4be44fc2005-08-05 00:44:28 -0400211 .name = "L3C",
212 .mt_mled = "MLED",
213 .mt_wled = "WLED",
214 .mt_lcd_switch = L3C_PREFIX "_Q10",
215 .lcd_status = "\\GL32",
216 .brightness_set = "SPLV",
217 .brightness_get = "GPLV",
218 .display_set = "SDSP",
219 .display_get = "\\_SB.PCI0.PCI1.VGAC.NMAP"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 {
Len Brown4be44fc2005-08-05 00:44:28 -0400222 .name = "L3D",
223 .mt_mled = "MLED",
224 .mled_status = "\\MALD",
225 .mt_wled = "WLED",
226 .mt_lcd_switch = "\\Q10",
227 .lcd_status = "\\BKLG",
228 .brightness_set = "SPLV",
229 .brightness_get = "GPLV",
230 .display_set = "SDSP",
231 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 {
Len Brown4be44fc2005-08-05 00:44:28 -0400234 .name = "L3H",
235 .mt_mled = "MLED",
236 .mt_wled = "WLED",
237 .mt_lcd_switch = "EHK",
238 .lcd_status = "\\_SB.PCI0.PM.PBC",
239 .brightness_set = "SPLV",
240 .brightness_get = "GPLV",
241 .display_set = "SDSP",
242 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244 {
Len Brown4be44fc2005-08-05 00:44:28 -0400245 .name = "L4R",
246 .mt_mled = "MLED",
247 .mt_wled = "WLED",
248 .wled_status = "\\_SB.PCI0.SBRG.SG13",
249 .mt_lcd_switch = xxN_PREFIX "_Q10",
250 .lcd_status = "\\_SB.PCI0.SBSM.SEO4",
251 .brightness_set = "SPLV",
252 .brightness_get = "GPLV",
253 .display_set = "SDSP",
254 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256 {
Len Brown4be44fc2005-08-05 00:44:28 -0400257 .name = "L5x",
258 .mt_mled = "MLED",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259/* WLED present, but not controlled by ACPI */
Len Brown4be44fc2005-08-05 00:44:28 -0400260 .mt_tled = "TLED",
261 .mt_lcd_switch = "\\Q0D",
262 .lcd_status = "\\BAOF",
263 .brightness_set = "SPLV",
264 .brightness_get = "GPLV",
265 .display_set = "SDSP",
266 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 {
Len Brown4be44fc2005-08-05 00:44:28 -0400269 .name = "L8L"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270/* No features, but at least support the hotkeys */
Len Brown4be44fc2005-08-05 00:44:28 -0400271 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273 {
Len Brown4be44fc2005-08-05 00:44:28 -0400274 .name = "M1A",
275 .mt_mled = "MLED",
276 .mt_lcd_switch = M1A_PREFIX "Q10",
277 .lcd_status = "\\PNOF",
278 .brightness_up = M1A_PREFIX "Q0E",
279 .brightness_down = M1A_PREFIX "Q0F",
280 .brightness_status = "\\BRIT",
281 .display_set = "SDSP",
282 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 {
Len Brown4be44fc2005-08-05 00:44:28 -0400285 .name = "M2E",
286 .mt_mled = "MLED",
287 .mt_wled = "WLED",
288 .mt_lcd_switch = "\\Q10",
289 .lcd_status = "\\GP06",
290 .brightness_set = "SPLV",
291 .brightness_get = "GPLV",
292 .display_set = "SDSP",
293 .display_get = "\\INFB"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295 {
Len Brown4be44fc2005-08-05 00:44:28 -0400296 .name = "M6N",
297 .mt_mled = "MLED",
298 .mt_wled = "WLED",
299 .wled_status = "\\_SB.PCI0.SBRG.SG13",
300 .mt_lcd_switch = xxN_PREFIX "_Q10",
301 .lcd_status = "\\_SB.BKLT",
302 .brightness_set = "SPLV",
303 .brightness_get = "GPLV",
304 .display_set = "SDSP",
Karol Kozimorbb84db92006-01-03 23:03:00 -0500305 .display_get = "\\_SB.PCI0.P0P1.VGA.GETD"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 {
Len Brown4be44fc2005-08-05 00:44:28 -0400307 .name = "M6R",
308 .mt_mled = "MLED",
309 .mt_wled = "WLED",
310 .mt_lcd_switch = xxN_PREFIX "_Q10",
311 .lcd_status = "\\_SB.PCI0.SBSM.SEO4",
312 .brightness_set = "SPLV",
313 .brightness_get = "GPLV",
314 .display_set = "SDSP",
315 .display_get = "\\SSTE"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 {
Len Brown4be44fc2005-08-05 00:44:28 -0400318 .name = "P30",
319 .mt_wled = "WLED",
320 .mt_lcd_switch = P30_PREFIX "_Q0E",
321 .lcd_status = "\\BKLT",
322 .brightness_up = P30_PREFIX "_Q68",
323 .brightness_down = P30_PREFIX "_Q69",
324 .brightness_get = "GPLV",
325 .display_set = "SDSP",
326 .display_get = "\\DNXT"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 {
Len Brown4be44fc2005-08-05 00:44:28 -0400329 .name = "S1x",
330 .mt_mled = "MLED",
331 .mled_status = "\\EMLE",
332 .mt_wled = "WLED",
333 .mt_lcd_switch = S1x_PREFIX "Q10",
334 .lcd_status = "\\PNOF",
335 .brightness_set = "SPLV",
336 .brightness_get = "GPLV"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338 {
Len Brown4be44fc2005-08-05 00:44:28 -0400339 .name = "S2x",
340 .mt_mled = "MLED",
341 .mled_status = "\\MAIL",
342 .mt_lcd_switch = S2x_PREFIX "_Q10",
343 .lcd_status = "\\BKLI",
344 .brightness_up = S2x_PREFIX "_Q0B",
345 .brightness_down = S2x_PREFIX "_Q0A"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 {
Len Brown4be44fc2005-08-05 00:44:28 -0400348 .name = "xxN",
349 .mt_mled = "MLED",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350/* WLED present, but not controlled by ACPI */
Len Brown4be44fc2005-08-05 00:44:28 -0400351 .mt_lcd_switch = xxN_PREFIX "_Q10",
352 .lcd_status = "\\BKLT",
353 .brightness_set = "SPLV",
354 .brightness_get = "GPLV",
355 .display_set = "SDSP",
356 .display_get = "\\ADVG"}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357};
358
359/* procdir we use */
360static struct proc_dir_entry *asus_proc_dir;
361
362/*
363 * This header is made available to allow proper configuration given model,
364 * revision number , ... this info cannot go in struct asus_hotk because it is
365 * available before the hotk
366 */
367static struct acpi_table_header *asus_info;
368
369/* The actual device the driver binds to */
370static struct asus_hotk *hotk;
371
372/*
373 * The hotkey driver declaration
374 */
375static int asus_hotk_add(struct acpi_device *device);
376static int asus_hotk_remove(struct acpi_device *device, int type);
377static struct acpi_driver asus_hotk_driver = {
Len Brown4be44fc2005-08-05 00:44:28 -0400378 .name = ACPI_HOTK_NAME,
379 .class = ACPI_HOTK_CLASS,
380 .ids = ACPI_HOTK_HID,
381 .ops = {
382 .add = asus_hotk_add,
383 .remove = asus_hotk_remove,
384 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385};
386
387/*
388 * This function evaluates an ACPI method, given an int as parameter, the
389 * method is searched within the scope of the handle, can be NULL. The output
390 * of the method is written is output, which can also be NULL
391 *
392 * returns 1 if write is successful, 0 else.
393 */
394static int write_acpi_int(acpi_handle handle, const char *method, int val,
395 struct acpi_buffer *output)
396{
397 struct acpi_object_list params; //list of input parameters (an int here)
398 union acpi_object in_obj; //the only param we use
399 acpi_status status;
400
401 params.count = 1;
402 params.pointer = &in_obj;
403 in_obj.type = ACPI_TYPE_INTEGER;
404 in_obj.integer.value = val;
405
Len Brown4be44fc2005-08-05 00:44:28 -0400406 status = acpi_evaluate_object(handle, (char *)method, &params, output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return (status == AE_OK);
408}
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410static int read_acpi_int(acpi_handle handle, const char *method, int *val)
411{
412 struct acpi_buffer output;
413 union acpi_object out_obj;
414 acpi_status status;
415
416 output.length = sizeof(out_obj);
417 output.pointer = &out_obj;
418
Len Brown4be44fc2005-08-05 00:44:28 -0400419 status = acpi_evaluate_object(handle, (char *)method, NULL, &output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 *val = out_obj.integer.value;
421 return (status == AE_OK) && (out_obj.type == ACPI_TYPE_INTEGER);
422}
423
424/*
425 * We write our info in page, we begin at offset off and cannot write more
426 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
427 * number of bytes written in page
428 */
429static int
430proc_read_info(char *page, char **start, off_t off, int count, int *eof,
Len Brown4be44fc2005-08-05 00:44:28 -0400431 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
433 int len = 0;
434 int temp;
435 char buf[16]; //enough for all info
436 /*
437 * We use the easy way, we don't care of off and count, so we don't set eof
438 * to 1
439 */
440
441 len += sprintf(page, ACPI_HOTK_NAME " " ASUS_ACPI_VERSION "\n");
Len Brown4be44fc2005-08-05 00:44:28 -0400442 len += sprintf(page + len, "Model reference : %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 hotk->methods->name);
444 /*
445 * The SFUN method probably allows the original driver to get the list
446 * of features supported by a given model. For now, 0x0100 or 0x0800
447 * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
448 * The significance of others is yet to be found.
449 */
450 if (read_acpi_int(hotk->handle, "SFUN", &temp))
Len Brown4be44fc2005-08-05 00:44:28 -0400451 len +=
452 sprintf(page + len, "SFUN value : 0x%04x\n", temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 /*
454 * Another value for userspace: the ASYM method returns 0x02 for
455 * battery low and 0x04 for battery critical, its readings tend to be
456 * more accurate than those provided by _BST.
457 * Note: since not all the laptops provide this method, errors are
458 * silently ignored.
459 */
460 if (read_acpi_int(hotk->handle, "ASYM", &temp))
Len Brown4be44fc2005-08-05 00:44:28 -0400461 len +=
462 sprintf(page + len, "ASYM value : 0x%04x\n", temp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 if (asus_info) {
464 snprintf(buf, 16, "%d", asus_info->length);
465 len += sprintf(page + len, "DSDT length : %s\n", buf);
466 snprintf(buf, 16, "%d", asus_info->checksum);
467 len += sprintf(page + len, "DSDT checksum : %s\n", buf);
468 snprintf(buf, 16, "%d", asus_info->revision);
469 len += sprintf(page + len, "DSDT revision : %s\n", buf);
470 snprintf(buf, 7, "%s", asus_info->oem_id);
471 len += sprintf(page + len, "OEM id : %s\n", buf);
472 snprintf(buf, 9, "%s", asus_info->oem_table_id);
473 len += sprintf(page + len, "OEM table id : %s\n", buf);
474 snprintf(buf, 16, "%x", asus_info->oem_revision);
475 len += sprintf(page + len, "OEM revision : 0x%s\n", buf);
476 snprintf(buf, 5, "%s", asus_info->asl_compiler_id);
477 len += sprintf(page + len, "ASL comp vendor id : %s\n", buf);
478 snprintf(buf, 16, "%x", asus_info->asl_compiler_revision);
479 len += sprintf(page + len, "ASL comp revision : 0x%s\n", buf);
480 }
481
482 return len;
483}
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485/*
486 * /proc handlers
487 * We write our info in page, we begin at offset off and cannot write more
488 * than count bytes. We set eof to 1 if we handle those 2 values. We return the
489 * number of bytes written in page
490 */
491
492/* Generic LED functions */
Len Brown4be44fc2005-08-05 00:44:28 -0400493static int read_led(const char *ledname, int ledmask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494{
495 if (ledname) {
496 int led_status;
497
498 if (read_acpi_int(NULL, ledname, &led_status))
499 return led_status;
500 else
501 printk(KERN_WARNING "Asus ACPI: Error reading LED "
502 "status\n");
503 }
504 return (hotk->status & ledmask) ? 1 : 0;
505}
506
Len Brown4be44fc2005-08-05 00:44:28 -0400507static int parse_arg(const char __user * buf, unsigned long count, int *val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508{
509 char s[32];
510 if (!count)
511 return 0;
512 if (count > 31)
513 return -EINVAL;
514 if (copy_from_user(s, buf, count))
515 return -EFAULT;
516 s[count] = 0;
517 if (sscanf(s, "%i", val) != 1)
518 return -EINVAL;
519 return count;
520}
521
522/* FIXME: kill extraneous args so it can be called independently */
523static int
Len Brown4be44fc2005-08-05 00:44:28 -0400524write_led(const char __user * buffer, unsigned long count,
525 char *ledname, int ledmask, int invert)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526{
527 int value;
528 int led_out = 0;
529
530 count = parse_arg(buffer, count, &value);
531 if (count > 0)
532 led_out = value ? 1 : 0;
533
534 hotk->status =
535 (led_out) ? (hotk->status | ledmask) : (hotk->status & ~ledmask);
536
Len Brown4be44fc2005-08-05 00:44:28 -0400537 if (invert) /* invert target value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 led_out = !led_out & 0x1;
539
540 if (!write_acpi_int(hotk->handle, ledname, led_out, NULL))
Len Brown4be44fc2005-08-05 00:44:28 -0400541 printk(KERN_WARNING "Asus ACPI: LED (%s) write failed\n",
542 ledname);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 return count;
545}
546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547/*
548 * Proc handlers for MLED
549 */
550static int
551proc_read_mled(char *page, char **start, off_t off, int count, int *eof,
552 void *data)
553{
Len Brown4be44fc2005-08-05 00:44:28 -0400554 return sprintf(page, "%d\n",
555 read_led(hotk->methods->mled_status, MLED_ON));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556}
557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558static int
Len Brown4be44fc2005-08-05 00:44:28 -0400559proc_write_mled(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 unsigned long count, void *data)
561{
562 return write_led(buffer, count, hotk->methods->mt_mled, MLED_ON, 1);
563}
564
565/*
566 * Proc handlers for WLED
567 */
568static int
569proc_read_wled(char *page, char **start, off_t off, int count, int *eof,
570 void *data)
571{
Len Brown4be44fc2005-08-05 00:44:28 -0400572 return sprintf(page, "%d\n",
573 read_led(hotk->methods->wled_status, WLED_ON));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574}
575
576static int
Len Brown4be44fc2005-08-05 00:44:28 -0400577proc_write_wled(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 unsigned long count, void *data)
579{
580 return write_led(buffer, count, hotk->methods->mt_wled, WLED_ON, 0);
581}
582
583/*
584 * Proc handlers for TLED
585 */
586static int
587proc_read_tled(char *page, char **start, off_t off, int count, int *eof,
588 void *data)
589{
Len Brown4be44fc2005-08-05 00:44:28 -0400590 return sprintf(page, "%d\n",
591 read_led(hotk->methods->tled_status, TLED_ON));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592}
593
594static int
Len Brown4be44fc2005-08-05 00:44:28 -0400595proc_write_tled(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 unsigned long count, void *data)
597{
598 return write_led(buffer, count, hotk->methods->mt_tled, TLED_ON, 0);
599}
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601static int get_lcd_state(void)
602{
603 int lcd = 0;
604
605 if (hotk->model != L3H) {
Len Brown4be44fc2005-08-05 00:44:28 -0400606 /* We don't have to check anything if we are here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 if (!read_acpi_int(NULL, hotk->methods->lcd_status, &lcd))
Len Brown4be44fc2005-08-05 00:44:28 -0400608 printk(KERN_WARNING
609 "Asus ACPI: Error reading LCD status\n");
610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 if (hotk->model == L2D)
612 lcd = ~lcd;
Len Brown4be44fc2005-08-05 00:44:28 -0400613 } else { /* L3H and the like have to be handled differently */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 acpi_status status = 0;
615 struct acpi_object_list input;
616 union acpi_object mt_params[2];
617 struct acpi_buffer output;
618 union acpi_object out_obj;
Len Brown4be44fc2005-08-05 00:44:28 -0400619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 input.count = 2;
621 input.pointer = mt_params;
622 /* Note: the following values are partly guessed up, but
623 otherwise they seem to work */
624 mt_params[0].type = ACPI_TYPE_INTEGER;
625 mt_params[0].integer.value = 0x02;
626 mt_params[1].type = ACPI_TYPE_INTEGER;
627 mt_params[1].integer.value = 0x02;
628
629 output.length = sizeof(out_obj);
630 output.pointer = &out_obj;
Len Brown4be44fc2005-08-05 00:44:28 -0400631
632 status =
633 acpi_evaluate_object(NULL, hotk->methods->lcd_status,
634 &input, &output);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 if (status != AE_OK)
636 return -1;
637 if (out_obj.type == ACPI_TYPE_INTEGER)
638 /* That's what the AML code does */
639 lcd = out_obj.integer.value >> 8;
640 }
Len Brown4be44fc2005-08-05 00:44:28 -0400641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 return (lcd & 1);
643}
644
645static int set_lcd_state(int value)
646{
647 int lcd = 0;
648 acpi_status status = 0;
649
650 lcd = value ? 1 : 0;
651 if (lcd != get_lcd_state()) {
652 /* switch */
653 if (hotk->model != L3H) {
654 status =
Len Brown4be44fc2005-08-05 00:44:28 -0400655 acpi_evaluate_object(NULL,
656 hotk->methods->mt_lcd_switch,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 NULL, NULL);
Len Brown4be44fc2005-08-05 00:44:28 -0400658 } else { /* L3H and the like have to be handled differently */
659 if (!write_acpi_int
660 (hotk->handle, hotk->methods->mt_lcd_switch, 0x07,
661 NULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 status = AE_ERROR;
663 /* L3H's AML executes EHK (0x07) upon Fn+F7 keypress,
664 the exact behaviour is simulated here */
665 }
666 if (ACPI_FAILURE(status))
667 printk(KERN_WARNING "Asus ACPI: Error switching LCD\n");
668 }
669 return 0;
670
671}
672
673static int
674proc_read_lcd(char *page, char **start, off_t off, int count, int *eof,
675 void *data)
676{
677 return sprintf(page, "%d\n", get_lcd_state());
678}
679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680static int
Len Brown4be44fc2005-08-05 00:44:28 -0400681proc_write_lcd(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 unsigned long count, void *data)
683{
684 int value;
Len Brown4be44fc2005-08-05 00:44:28 -0400685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 count = parse_arg(buffer, count, &value);
687 if (count > 0)
688 set_lcd_state(value);
689 return count;
690}
691
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692static int read_brightness(void)
693{
694 int value;
Len Brown4be44fc2005-08-05 00:44:28 -0400695
696 if (hotk->methods->brightness_get) { /* SPLV/GPLV laptop */
697 if (!read_acpi_int(hotk->handle, hotk->methods->brightness_get,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 &value))
Len Brown4be44fc2005-08-05 00:44:28 -0400699 printk(KERN_WARNING
700 "Asus ACPI: Error reading brightness\n");
701 } else if (hotk->methods->brightness_status) { /* For D1 for example */
702 if (!read_acpi_int(NULL, hotk->methods->brightness_status,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 &value))
Len Brown4be44fc2005-08-05 00:44:28 -0400704 printk(KERN_WARNING
705 "Asus ACPI: Error reading brightness\n");
706 } else /* No GPLV method */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 value = hotk->brightness;
708 return value;
709}
710
711/*
712 * Change the brightness level
713 */
714static void set_brightness(int value)
715{
716 acpi_status status = 0;
717
718 /* SPLV laptop */
Len Brown4be44fc2005-08-05 00:44:28 -0400719 if (hotk->methods->brightness_set) {
720 if (!write_acpi_int(hotk->handle, hotk->methods->brightness_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 value, NULL))
Len Brown4be44fc2005-08-05 00:44:28 -0400722 printk(KERN_WARNING
723 "Asus ACPI: Error changing brightness\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 return;
725 }
726
727 /* No SPLV method if we are here, act as appropriate */
728 value -= read_brightness();
729 while (value != 0) {
Len Brown4be44fc2005-08-05 00:44:28 -0400730 status = acpi_evaluate_object(NULL, (value > 0) ?
731 hotk->methods->brightness_up :
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 hotk->methods->brightness_down,
733 NULL, NULL);
734 (value > 0) ? value-- : value++;
735 if (ACPI_FAILURE(status))
Len Brown4be44fc2005-08-05 00:44:28 -0400736 printk(KERN_WARNING
737 "Asus ACPI: Error changing brightness\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 }
739 return;
740}
741
742static int
743proc_read_brn(char *page, char **start, off_t off, int count, int *eof,
744 void *data)
745{
746 return sprintf(page, "%d\n", read_brightness());
747}
748
749static int
Len Brown4be44fc2005-08-05 00:44:28 -0400750proc_write_brn(struct file *file, const char __user * buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 unsigned long count, void *data)
752{
753 int value;
754
755 count = parse_arg(buffer, count, &value);
756 if (count > 0) {
757 value = (0 < value) ? ((15 < value) ? 15 : value) : 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400758 /* 0 <= value <= 15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 set_brightness(value);
760 } else if (count < 0) {
761 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
762 }
763
764 return count;
765}
766
767static void set_display(int value)
768{
769 /* no sanity check needed for now */
Len Brown4be44fc2005-08-05 00:44:28 -0400770 if (!write_acpi_int(hotk->handle, hotk->methods->display_set,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 value, NULL))
772 printk(KERN_WARNING "Asus ACPI: Error setting display\n");
773 return;
774}
775
776/*
777 * Now, *this* one could be more user-friendly, but so far, no-one has
778 * complained. The significance of bits is the same as in proc_write_disp()
779 */
780static int
781proc_read_disp(char *page, char **start, off_t off, int count, int *eof,
Len Brown4be44fc2005-08-05 00:44:28 -0400782 void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783{
784 int value = 0;
Len Brown4be44fc2005-08-05 00:44:28 -0400785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 if (!read_acpi_int(hotk->handle, hotk->methods->display_get, &value))
Len Brown4be44fc2005-08-05 00:44:28 -0400787 printk(KERN_WARNING
788 "Asus ACPI: Error reading display status\n");
789 value &= 0x07; /* needed for some models, shouldn't hurt others */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 return sprintf(page, "%d\n", value);
791}
792
793/*
794 * Experimental support for display switching. As of now: 1 should activate
795 * the LCD output, 2 should do for CRT, and 4 for TV-Out. Any combination
796 * (bitwise) of these will suffice. I never actually tested 3 displays hooked up
797 * simultaneously, so be warned. See the acpi4asus README for more info.
798 */
799static int
Len Brown4be44fc2005-08-05 00:44:28 -0400800proc_write_disp(struct file *file, const char __user * buffer,
801 unsigned long count, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802{
803 int value;
804
805 count = parse_arg(buffer, count, &value);
806 if (count > 0)
807 set_display(value);
808 else if (count < 0)
809 printk(KERN_WARNING "Asus ACPI: Error reading user input\n");
810
811 return count;
812}
813
Len Brown4be44fc2005-08-05 00:44:28 -0400814typedef int (proc_readfunc) (char *page, char **start, off_t off, int count,
815 int *eof, void *data);
816typedef int (proc_writefunc) (struct file * file, const char __user * buffer,
817 unsigned long count, void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819static int
Bjorn Helgaas200739c2006-03-28 17:04:00 -0500820asus_proc_add(char *name, proc_writefunc * writefunc,
Len Brown4be44fc2005-08-05 00:44:28 -0400821 proc_readfunc * readfunc, mode_t mode,
822 struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
Len Brown4be44fc2005-08-05 00:44:28 -0400824 struct proc_dir_entry *proc =
825 create_proc_entry(name, mode, acpi_device_dir(device));
826 if (!proc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 printk(KERN_WARNING " Unable to create %s fs entry\n", name);
828 return -1;
829 }
830 proc->write_proc = writefunc;
831 proc->read_proc = readfunc;
832 proc->data = acpi_driver_data(device);
833 proc->owner = THIS_MODULE;
834 proc->uid = asus_uid;
835 proc->gid = asus_gid;
836 return 0;
837}
838
Bjorn Helgaas200739c2006-03-28 17:04:00 -0500839static int asus_hotk_add_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840{
841 struct proc_dir_entry *proc;
842 mode_t mode;
Len Brown4be44fc2005-08-05 00:44:28 -0400843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 /*
845 * If parameter uid or gid is not changed, keep the default setting for
846 * our proc entries (-rw-rw-rw-) else, it means we care about security,
847 * and then set to -rw-rw----
848 */
849
Len Brown4be44fc2005-08-05 00:44:28 -0400850 if ((asus_uid == 0) && (asus_gid == 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 mode = S_IFREG | S_IRUGO | S_IWUGO;
852 } else {
853 mode = S_IFREG | S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP;
Karol Kozimoraea19aa2006-01-03 23:05:00 -0500854 printk(KERN_WARNING " asus_uid and asus_gid parameters are "
855 "deprecated, use chown and chmod instead!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 }
857
858 acpi_device_dir(device) = asus_proc_dir;
859 if (!acpi_device_dir(device))
860 return -ENODEV;
861
862 proc = create_proc_entry(PROC_INFO, mode, acpi_device_dir(device));
863 if (proc) {
864 proc->read_proc = proc_read_info;
865 proc->data = acpi_driver_data(device);
866 proc->owner = THIS_MODULE;
867 proc->uid = asus_uid;
868 proc->gid = asus_gid;
869 } else {
870 printk(KERN_WARNING " Unable to create " PROC_INFO
871 " fs entry\n");
872 }
873
874 if (hotk->methods->mt_wled) {
Len Brown4be44fc2005-08-05 00:44:28 -0400875 asus_proc_add(PROC_WLED, &proc_write_wled, &proc_read_wled,
876 mode, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 }
878
879 if (hotk->methods->mt_mled) {
Len Brown4be44fc2005-08-05 00:44:28 -0400880 asus_proc_add(PROC_MLED, &proc_write_mled, &proc_read_mled,
881 mode, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 }
883
884 if (hotk->methods->mt_tled) {
Len Brown4be44fc2005-08-05 00:44:28 -0400885 asus_proc_add(PROC_TLED, &proc_write_tled, &proc_read_tled,
886 mode, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 }
888
889 /*
890 * We need both read node and write method as LCD switch is also accessible
891 * from keyboard
892 */
893 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400894 asus_proc_add(PROC_LCD, &proc_write_lcd, &proc_read_lcd, mode,
895 device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
Len Brown4be44fc2005-08-05 00:44:28 -0400897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 if ((hotk->methods->brightness_up && hotk->methods->brightness_down) ||
899 (hotk->methods->brightness_get && hotk->methods->brightness_set)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400900 asus_proc_add(PROC_BRN, &proc_write_brn, &proc_read_brn, mode,
901 device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 }
903
904 if (hotk->methods->display_set) {
Len Brown4be44fc2005-08-05 00:44:28 -0400905 asus_proc_add(PROC_DISP, &proc_write_disp, &proc_read_disp,
906 mode, device);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 }
908
909 return 0;
910}
911
Len Brown4be44fc2005-08-05 00:44:28 -0400912static int asus_hotk_remove_fs(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913{
Len Brown4be44fc2005-08-05 00:44:28 -0400914 if (acpi_device_dir(device)) {
915 remove_proc_entry(PROC_INFO, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 if (hotk->methods->mt_wled)
Len Brown4be44fc2005-08-05 00:44:28 -0400917 remove_proc_entry(PROC_WLED, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 if (hotk->methods->mt_mled)
Len Brown4be44fc2005-08-05 00:44:28 -0400919 remove_proc_entry(PROC_MLED, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 if (hotk->methods->mt_tled)
Len Brown4be44fc2005-08-05 00:44:28 -0400921 remove_proc_entry(PROC_TLED, acpi_device_dir(device));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 if (hotk->methods->mt_lcd_switch && hotk->methods->lcd_status)
923 remove_proc_entry(PROC_LCD, acpi_device_dir(device));
Len Brown4be44fc2005-08-05 00:44:28 -0400924 if ((hotk->methods->brightness_up
925 && hotk->methods->brightness_down)
926 || (hotk->methods->brightness_get
927 && hotk->methods->brightness_set))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 remove_proc_entry(PROC_BRN, acpi_device_dir(device));
929 if (hotk->methods->display_set)
930 remove_proc_entry(PROC_DISP, acpi_device_dir(device));
931 }
932 return 0;
933}
934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
936{
Len Brown4be44fc2005-08-05 00:44:28 -0400937 /* TODO Find a better way to handle events count. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 if (!hotk)
939 return;
940
941 if ((event & ~((u32) BR_UP)) < 16) {
942 hotk->brightness = (event & ~((u32) BR_UP));
Len Brown4be44fc2005-08-05 00:44:28 -0400943 } else if ((event & ~((u32) BR_DOWN)) < 16) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 hotk->brightness = (event & ~((u32) BR_DOWN));
945 }
946
947 acpi_bus_generate_event(hotk->device, event,
948 hotk->event_count[event % 128]++);
949
950 return;
951}
952
953/*
954 * This function is used to initialize the hotk with right values. In this
955 * method, we can make all the detection we want, and modify the hotk struct
956 */
Bjorn Helgaas200739c2006-03-28 17:04:00 -0500957static int asus_hotk_get_info(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958{
959 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
960 struct acpi_buffer dsdt = { ACPI_ALLOCATE_BUFFER, NULL };
961 union acpi_object *model = NULL;
962 int bsts_result;
963 acpi_status status;
964
965 /*
966 * Get DSDT headers early enough to allow for differentiating between
967 * models, but late enough to allow acpi_bus_register_driver() to fail
968 * before doing anything ACPI-specific. Should we encounter a machine,
969 * which needs special handling (i.e. its hotkey device has a different
970 * HID), this bit will be moved. A global variable asus_info contains
971 * the DSDT header.
972 */
Bob Mooreb229cf92006-04-21 17:15:00 -0400973 status = acpi_get_table(ACPI_TABLE_ID_DSDT, 1, &dsdt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 if (ACPI_FAILURE(status))
975 printk(KERN_WARNING " Couldn't get the DSDT table header\n");
976 else
Len Brown4be44fc2005-08-05 00:44:28 -0400977 asus_info = (struct acpi_table_header *)dsdt.pointer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 /* We have to write 0 on init this far for all ASUS models */
980 if (!write_acpi_int(hotk->handle, "INIT", 0, &buffer)) {
981 printk(KERN_ERR " Hotkey initialization failed\n");
982 return -ENODEV;
983 }
984
985 /* This needs to be called for some laptops to init properly */
986 if (!read_acpi_int(hotk->handle, "BSTS", &bsts_result))
987 printk(KERN_WARNING " Error calling BSTS\n");
988 else if (bsts_result)
Len Brown4be44fc2005-08-05 00:44:28 -0400989 printk(KERN_NOTICE " BSTS called, 0x%02x returned\n",
990 bsts_result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991
Karol Kozimorb697b532005-12-22 12:42:00 -0500992 /* This is unlikely with implicit return */
993 if (buffer.pointer == NULL)
994 return -EINVAL;
995
996 model = (union acpi_object *) buffer.pointer;
997 /*
998 * Samsung P30 has a device with a valid _HID whose INIT does not
999 * return anything. It used to be possible to catch this exception,
1000 * but the implicit return code will now happily confuse the
1001 * driver. We assume that every ACPI_TYPE_STRING is a valid model
1002 * identifier but it's still possible to get completely bogus data.
1003 */
1004 if (model->type == ACPI_TYPE_STRING) {
1005 printk(KERN_NOTICE " %s model detected, ", model->string.pointer);
1006 } else {
Len Brown4be44fc2005-08-05 00:44:28 -04001007 if (asus_info && /* Samsung P30 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 strncmp(asus_info->oem_table_id, "ODEM", 4) == 0) {
1009 hotk->model = P30;
Len Brown4be44fc2005-08-05 00:44:28 -04001010 printk(KERN_NOTICE
1011 " Samsung P30 detected, supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 } else {
1013 hotk->model = M2E;
1014 printk(KERN_WARNING " no string returned by INIT\n");
1015 printk(KERN_WARNING " trying default values, supply "
1016 "the developers with your DSDT\n");
1017 }
1018 hotk->methods = &model_conf[hotk->model];
Karol Kozimorb697b532005-12-22 12:42:00 -05001019
1020 acpi_os_free(model);
Len Brown4be44fc2005-08-05 00:44:28 -04001021
Karol Kozimorb697b532005-12-22 12:42:00 -05001022 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
1024
1025 hotk->model = END_MODEL;
1026 if (strncmp(model->string.pointer, "L3D", 3) == 0)
1027 hotk->model = L3D;
1028 else if (strncmp(model->string.pointer, "L3H", 3) == 0 ||
1029 strncmp(model->string.pointer, "L2E", 3) == 0)
1030 hotk->model = L3H;
1031 else if (strncmp(model->string.pointer, "L3", 2) == 0 ||
1032 strncmp(model->string.pointer, "L2B", 3) == 0)
1033 hotk->model = L3C;
1034 else if (strncmp(model->string.pointer, "L8L", 3) == 0)
1035 hotk->model = L8L;
1036 else if (strncmp(model->string.pointer, "L4R", 3) == 0)
1037 hotk->model = L4R;
1038 else if (strncmp(model->string.pointer, "M6N", 3) == 0)
1039 hotk->model = M6N;
1040 else if (strncmp(model->string.pointer, "M6R", 3) == 0)
1041 hotk->model = M6R;
1042 else if (strncmp(model->string.pointer, "M2N", 3) == 0 ||
1043 strncmp(model->string.pointer, "M3N", 3) == 0 ||
1044 strncmp(model->string.pointer, "M5N", 3) == 0 ||
1045 strncmp(model->string.pointer, "M6N", 3) == 0 ||
1046 strncmp(model->string.pointer, "S1N", 3) == 0 ||
1047 strncmp(model->string.pointer, "S5N", 3) == 0 ||
Len Brown4be44fc2005-08-05 00:44:28 -04001048 strncmp(model->string.pointer, "W1N", 3) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 hotk->model = xxN;
1050 else if (strncmp(model->string.pointer, "M1", 2) == 0)
1051 hotk->model = M1A;
1052 else if (strncmp(model->string.pointer, "M2", 2) == 0 ||
1053 strncmp(model->string.pointer, "L4E", 3) == 0)
1054 hotk->model = M2E;
1055 else if (strncmp(model->string.pointer, "L2", 2) == 0)
1056 hotk->model = L2D;
1057 else if (strncmp(model->string.pointer, "L8", 2) == 0)
1058 hotk->model = S1x;
1059 else if (strncmp(model->string.pointer, "D1", 2) == 0)
1060 hotk->model = D1x;
1061 else if (strncmp(model->string.pointer, "A1", 2) == 0)
1062 hotk->model = A1x;
1063 else if (strncmp(model->string.pointer, "A2", 2) == 0)
1064 hotk->model = A2x;
1065 else if (strncmp(model->string.pointer, "J1", 2) == 0)
1066 hotk->model = S2x;
1067 else if (strncmp(model->string.pointer, "L5", 2) == 0)
1068 hotk->model = L5x;
1069
1070 if (hotk->model == END_MODEL) {
1071 printk("unsupported, trying default values, supply the "
1072 "developers with your DSDT\n");
1073 hotk->model = M2E;
1074 } else {
1075 printk("supported\n");
1076 }
1077
1078 hotk->methods = &model_conf[hotk->model];
1079
1080 /* Sort of per-model blacklist */
1081 if (strncmp(model->string.pointer, "L2B", 3) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -04001082 hotk->methods->lcd_status = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 /* L2B is similar enough to L3C to use its settings, with this only
1084 exception */
1085 else if (strncmp(model->string.pointer, "S5N", 3) == 0 ||
1086 strncmp(model->string.pointer, "M5N", 3) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -04001087 hotk->methods->mt_mled = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 /* S5N and M5N have no MLED */
1089 else if (strncmp(model->string.pointer, "M2N", 3) == 0 ||
1090 strncmp(model->string.pointer, "W1N", 3) == 0)
Len Brown4be44fc2005-08-05 00:44:28 -04001091 hotk->methods->mt_wled = "WLED";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 /* M2N and W1N have a usable WLED */
1093 else if (asus_info) {
1094 if (strncmp(asus_info->oem_table_id, "L1", 2) == 0)
1095 hotk->methods->mled_status = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -04001096 /* S1300A reports L84F, but L1400B too, account for that */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 }
1098
1099 acpi_os_free(model);
1100
1101 return AE_OK;
1102}
1103
Bjorn Helgaas200739c2006-03-28 17:04:00 -05001104static int asus_hotk_check(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105{
1106 int result = 0;
1107
1108 result = acpi_bus_get_status(hotk->device);
1109 if (result)
1110 return result;
1111
1112 if (hotk->device->status.present) {
1113 result = asus_hotk_get_info();
1114 } else {
1115 printk(KERN_ERR " Hotkey device not present, aborting\n");
1116 return -EINVAL;
1117 }
1118
1119 return result;
1120}
1121
Bjorn Helgaas578b3332006-03-28 17:04:00 -05001122static int asus_hotk_found;
1123
Bjorn Helgaas200739c2006-03-28 17:04:00 -05001124static int asus_hotk_add(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125{
1126 acpi_status status = AE_OK;
1127 int result;
1128
1129 if (!device)
1130 return -EINVAL;
1131
1132 printk(KERN_NOTICE "Asus Laptop ACPI Extras version %s\n",
1133 ASUS_ACPI_VERSION);
1134
1135 hotk =
Len Brown4be44fc2005-08-05 00:44:28 -04001136 (struct asus_hotk *)kmalloc(sizeof(struct asus_hotk), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 if (!hotk)
1138 return -ENOMEM;
1139 memset(hotk, 0, sizeof(struct asus_hotk));
1140
1141 hotk->handle = device->handle;
1142 strcpy(acpi_device_name(device), ACPI_HOTK_DEVICE_NAME);
1143 strcpy(acpi_device_class(device), ACPI_HOTK_CLASS);
1144 acpi_driver_data(device) = hotk;
1145 hotk->device = device;
1146
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 result = asus_hotk_check();
1148 if (result)
1149 goto end;
1150
1151 result = asus_hotk_add_fs(device);
1152 if (result)
1153 goto end;
1154
1155 /*
1156 * We install the handler, it will receive the hotk in parameter, so, we
1157 * could add other data to the hotk struct
1158 */
1159 status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
1160 asus_hotk_notify, hotk);
1161 if (ACPI_FAILURE(status))
1162 printk(KERN_ERR " Error installing notify handler\n");
1163
1164 /* For laptops without GPLV: init the hotk->brightness value */
Len Brown4be44fc2005-08-05 00:44:28 -04001165 if ((!hotk->methods->brightness_get)
1166 && (!hotk->methods->brightness_status)
1167 && (hotk->methods->brightness_up
1168 && hotk->methods->brightness_down)) {
1169 status =
1170 acpi_evaluate_object(NULL, hotk->methods->brightness_down,
1171 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 if (ACPI_FAILURE(status))
1173 printk(KERN_WARNING " Error changing brightness\n");
1174 else {
Len Brown4be44fc2005-08-05 00:44:28 -04001175 status =
1176 acpi_evaluate_object(NULL,
1177 hotk->methods->brightness_up,
1178 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 if (ACPI_FAILURE(status))
Len Brown4be44fc2005-08-05 00:44:28 -04001180 printk(KERN_WARNING " Strange, error changing"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 " brightness\n");
1182 }
1183 }
1184
Bjorn Helgaas578b3332006-03-28 17:04:00 -05001185 asus_hotk_found = 1;
1186
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 end:
1188 if (result) {
1189 kfree(hotk);
1190 }
1191
1192 return result;
1193}
1194
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195static int asus_hotk_remove(struct acpi_device *device, int type)
1196{
1197 acpi_status status = 0;
1198
1199 if (!device || !acpi_driver_data(device))
1200 return -EINVAL;
1201
1202 status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY,
1203 asus_hotk_notify);
1204 if (ACPI_FAILURE(status))
1205 printk(KERN_ERR "Asus ACPI: Error removing notify handler\n");
1206
1207 asus_hotk_remove_fs(device);
1208
1209 kfree(hotk);
1210
1211 return 0;
1212}
1213
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214static int __init asus_acpi_init(void)
1215{
1216 int result;
1217
1218 if (acpi_disabled)
1219 return -ENODEV;
1220
Len Brown4be44fc2005-08-05 00:44:28 -04001221 if (!acpi_specific_hotkey_enabled) {
Luming Yufb9802f2005-03-18 18:03:45 -05001222 printk(KERN_ERR "Using generic hotkey driver\n");
Len Brown4be44fc2005-08-05 00:44:28 -04001223 return -ENODEV;
Luming Yufb9802f2005-03-18 18:03:45 -05001224 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 asus_proc_dir = proc_mkdir(PROC_ASUS, acpi_root_dir);
1226 if (!asus_proc_dir) {
1227 printk(KERN_ERR "Asus ACPI: Unable to create /proc entry\n");
1228 return -ENODEV;
1229 }
1230 asus_proc_dir->owner = THIS_MODULE;
1231
1232 result = acpi_bus_register_driver(&asus_hotk_driver);
Bjorn Helgaas578b3332006-03-28 17:04:00 -05001233 if (result < 0) {
1234 remove_proc_entry(PROC_ASUS, acpi_root_dir);
Andrew Morton5e7d8812006-06-24 19:36:00 -04001235 return result;
Bjorn Helgaas578b3332006-03-28 17:04:00 -05001236 }
1237
1238 /*
1239 * This is a bit of a kludge. We only want this module loaded
1240 * for ASUS systems, but there's currently no way to probe the
1241 * ACPI namespace for ASUS HIDs. So we just return failure if
1242 * we didn't find one, which will cause the module to be
1243 * unloaded.
1244 */
1245 if (!asus_hotk_found) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 acpi_bus_unregister_driver(&asus_hotk_driver);
1247 remove_proc_entry(PROC_ASUS, acpi_root_dir);
Andrew Mortonebd5f2c2006-05-13 22:56:00 -04001248 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 }
1250
1251 return 0;
1252}
1253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254static void __exit asus_acpi_exit(void)
1255{
1256 acpi_bus_unregister_driver(&asus_hotk_driver);
1257 remove_proc_entry(PROC_ASUS, acpi_root_dir);
1258
1259 acpi_os_free(asus_info);
1260
1261 return;
1262}
1263
1264module_init(asus_acpi_init);
1265module_exit(asus_acpi_exit);