blob: 1f76a40badecea06e7de62811df078fdb1cb23c9 [file] [log] [blame]
Luming Yu79cda7d2005-08-03 18:07:59 -04001/*
2 * hotkey.c - ACPI Hotkey Driver ($Revision: 0.2 $)
Luming Yufb9802f2005-03-18 18:03:45 -05003 *
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/types.h>
28#include <linux/proc_fs.h>
29#include <linux/sched.h>
30#include <linux/kmod.h>
31#include <linux/seq_file.h>
32#include <acpi/acpi_drivers.h>
33#include <acpi/acpi_bus.h>
34#include <asm/uaccess.h>
35
36#define HOTKEY_ACPI_VERSION "0.1"
37
38#define HOTKEY_PROC "hotkey"
39#define HOTKEY_EV_CONFIG "event_config"
40#define HOTKEY_PL_CONFIG "poll_config"
41#define HOTKEY_ACTION "action"
42#define HOTKEY_INFO "info"
43
44#define ACPI_HOTK_NAME "Generic Hotkey Driver"
45#define ACPI_HOTK_CLASS "Hotkey"
46#define ACPI_HOTK_DEVICE_NAME "Hotkey"
47#define ACPI_HOTK_HID "Unknown?"
48#define ACPI_HOTKEY_COMPONENT 0x20000000
49
50#define ACPI_HOTKEY_EVENT 0x1
51#define ACPI_HOTKEY_POLLING 0x2
52#define ACPI_UNDEFINED_EVENT 0xf
53
Luming Yu79cda7d2005-08-03 18:07:59 -040054#define RESULT_STR_LEN 80
Luming Yufb9802f2005-03-18 18:03:45 -050055
Luming Yu79cda7d2005-08-03 18:07:59 -040056#define ACTION_METHOD 0
57#define POLL_METHOD 1
Luming Yufb9802f2005-03-18 18:03:45 -050058
Luming Yu79cda7d2005-08-03 18:07:59 -040059#define IS_EVENT(e) ((e) <= 10000 && (e) >0)
60#define IS_POLL(e) ((e) > 10000)
61#define IS_OTHERS(e) ((e)<=0 || (e)>=20000)
Luming Yufb9802f2005-03-18 18:03:45 -050062#define _COMPONENT ACPI_HOTKEY_COMPONENT
63ACPI_MODULE_NAME("acpi_hotkey")
64
Luming Yu79cda7d2005-08-03 18:07:59 -040065MODULE_AUTHOR("luming.yu@intel.com");
Luming Yufb9802f2005-03-18 18:03:45 -050066MODULE_DESCRIPTION(ACPI_HOTK_NAME);
67MODULE_LICENSE("GPL");
68
69/* standardized internal hotkey number/event */
70enum {
71 /* Video Extension event */
72 HK_EVENT_CYCLE_OUTPUT_DEVICE = 0x80,
73 HK_EVENT_OUTPUT_DEVICE_STATUS_CHANGE,
74 HK_EVENT_CYCLE_DISPLAY_OUTPUT,
75 HK_EVENT_NEXT_DISPLAY_OUTPUT,
76 HK_EVENT_PREVIOUS_DISPLAY_OUTPUT,
77 HK_EVENT_CYCLE_BRIGHTNESS,
78 HK_EVENT_INCREASE_BRIGHTNESS,
79 HK_EVENT_DECREASE_BRIGHTNESS,
80 HK_EVENT_ZERO_BRIGHTNESS,
81 HK_EVENT_DISPLAY_DEVICE_OFF,
82
83 /* Snd Card event */
84 HK_EVENT_VOLUME_MUTE,
85 HK_EVENT_VOLUME_INCLREASE,
86 HK_EVENT_VOLUME_DECREASE,
87
88 /* running state control */
89 HK_EVENT_ENTERRING_S3,
90 HK_EVENT_ENTERRING_S4,
91 HK_EVENT_ENTERRING_S5,
92};
93
94/* procdir we use */
95static struct proc_dir_entry *hotkey_proc_dir;
96static struct proc_dir_entry *hotkey_config;
97static struct proc_dir_entry *hotkey_poll_config;
98static struct proc_dir_entry *hotkey_action;
99static struct proc_dir_entry *hotkey_info;
100
101/* linkage for all type of hotkey */
102struct acpi_hotkey_link {
103 struct list_head entries;
104 int hotkey_type; /* event or polling based hotkey */
105 int hotkey_standard_num; /* standardized hotkey(event) number */
106};
107
108/* event based hotkey */
109struct acpi_event_hotkey {
110 struct acpi_hotkey_link hotkey_link;
111 int flag;
112 acpi_handle bus_handle; /* bus to install notify handler */
113 int external_hotkey_num; /* external hotkey/event number */
114 acpi_handle action_handle; /* acpi handle attached aml action method */
115 char *action_method; /* action method */
116};
117
Luming Yu79cda7d2005-08-03 18:07:59 -0400118/*
Luming Yufb9802f2005-03-18 18:03:45 -0500119 * There are two ways to poll status
120 * 1. directy call read_xxx method, without any arguments passed in
121 * 2. call write_xxx method, with arguments passed in, you need
122 * the result is saved in acpi_polling_hotkey.poll_result.
123 * anthoer read command through polling interface.
124 *
125 */
126
127/* polling based hotkey */
128struct acpi_polling_hotkey {
129 struct acpi_hotkey_link hotkey_link;
130 int flag;
131 acpi_handle poll_handle; /* acpi handle attached polling method */
132 char *poll_method; /* poll method */
133 acpi_handle action_handle; /* acpi handle attached action method */
134 char *action_method; /* action method */
Luming Yu79cda7d2005-08-03 18:07:59 -0400135 union acpi_object *poll_result; /* polling_result */
Luming Yufb9802f2005-03-18 18:03:45 -0500136 struct proc_dir_entry *proc;
137};
138
139/* hotkey object union */
140union acpi_hotkey {
141 struct list_head entries;
142 struct acpi_hotkey_link link;
143 struct acpi_event_hotkey event_hotkey;
144 struct acpi_polling_hotkey poll_hotkey;
145};
146
147/* hotkey object list */
148struct acpi_hotkey_list {
149 struct list_head *entries;
150 int count;
151};
152
153static int auto_hotkey_add(struct acpi_device *device);
154static int auto_hotkey_remove(struct acpi_device *device, int type);
155
156static struct acpi_driver hotkey_driver = {
157 .name = ACPI_HOTK_NAME,
158 .class = ACPI_HOTK_CLASS,
159 .ids = ACPI_HOTK_HID,
160 .ops = {
161 .add = auto_hotkey_add,
162 .remove = auto_hotkey_remove,
163 },
164};
165
Luming Yu79cda7d2005-08-03 18:07:59 -0400166static void free_hotkey_device(union acpi_hotkey *key);
167static void free_hotkey_buffer(union acpi_hotkey *key);
168static void free_poll_hotkey_buffer(union acpi_hotkey *key);
Luming Yufb9802f2005-03-18 18:03:45 -0500169static int hotkey_open_config(struct inode *inode, struct file *file);
Luming Yu79cda7d2005-08-03 18:07:59 -0400170static int hotkey_poll_open_config(struct inode *inode, struct file *file);
Luming Yufb9802f2005-03-18 18:03:45 -0500171static ssize_t hotkey_write_config(struct file *file,
172 const char __user * buffer,
173 size_t count, loff_t * data);
Luming Yufb9802f2005-03-18 18:03:45 -0500174static int hotkey_info_open_fs(struct inode *inode, struct file *file);
175static int hotkey_action_open_fs(struct inode *inode, struct file *file);
176static ssize_t hotkey_execute_aml_method(struct file *file,
177 const char __user * buffer,
178 size_t count, loff_t * data);
179static int hotkey_config_seq_show(struct seq_file *seq, void *offset);
Luming Yu79cda7d2005-08-03 18:07:59 -0400180static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset);
Luming Yufb9802f2005-03-18 18:03:45 -0500181static int hotkey_polling_open_fs(struct inode *inode, struct file *file);
Luming Yu79cda7d2005-08-03 18:07:59 -0400182static union acpi_hotkey *get_hotkey_by_event(struct
183 acpi_hotkey_list
184 *hotkey_list, int event);
Luming Yufb9802f2005-03-18 18:03:45 -0500185
186/* event based config */
187static struct file_operations hotkey_config_fops = {
188 .open = hotkey_open_config,
189 .read = seq_read,
190 .write = hotkey_write_config,
191 .llseek = seq_lseek,
192 .release = single_release,
193};
194
195/* polling based config */
196static struct file_operations hotkey_poll_config_fops = {
Luming Yu79cda7d2005-08-03 18:07:59 -0400197 .open = hotkey_poll_open_config,
Luming Yufb9802f2005-03-18 18:03:45 -0500198 .read = seq_read,
Luming Yu79cda7d2005-08-03 18:07:59 -0400199 .write = hotkey_write_config,
Luming Yufb9802f2005-03-18 18:03:45 -0500200 .llseek = seq_lseek,
201 .release = single_release,
202};
203
204/* hotkey driver info */
205static struct file_operations hotkey_info_fops = {
206 .open = hotkey_info_open_fs,
207 .read = seq_read,
208 .llseek = seq_lseek,
209 .release = single_release,
210};
211
212/* action */
213static struct file_operations hotkey_action_fops = {
214 .open = hotkey_action_open_fs,
215 .read = seq_read,
216 .write = hotkey_execute_aml_method,
217 .llseek = seq_lseek,
218 .release = single_release,
219};
220
221/* polling results */
222static struct file_operations hotkey_polling_fops = {
223 .open = hotkey_polling_open_fs,
224 .read = seq_read,
225 .llseek = seq_lseek,
226 .release = single_release,
227};
228
229struct acpi_hotkey_list global_hotkey_list; /* link all ev or pl hotkey */
230struct list_head hotkey_entries; /* head of the list of hotkey_list */
231
232static int hotkey_info_seq_show(struct seq_file *seq, void *offset)
233{
234 ACPI_FUNCTION_TRACE("hotkey_info_seq_show");
235
Luming Yu79cda7d2005-08-03 18:07:59 -0400236 seq_printf(seq, "Hotkey generic driver ver: %s\n", HOTKEY_ACPI_VERSION);
Luming Yufb9802f2005-03-18 18:03:45 -0500237
238 return_VALUE(0);
239}
240
241static int hotkey_info_open_fs(struct inode *inode, struct file *file)
242{
243 return single_open(file, hotkey_info_seq_show, PDE(inode)->data);
244}
245
246static char *format_result(union acpi_object *object)
247{
Luming Yu79cda7d2005-08-03 18:07:59 -0400248 char *buf = NULL;
249
250 buf = (char *)kmalloc(RESULT_STR_LEN, GFP_KERNEL);
251 if (buf)
252 memset(buf, 0, RESULT_STR_LEN);
253 else
254 goto do_fail;
Luming Yufb9802f2005-03-18 18:03:45 -0500255
256 /* Now, just support integer type */
257 if (object->type == ACPI_TYPE_INTEGER)
Luming Yu79cda7d2005-08-03 18:07:59 -0400258 sprintf(buf, "%d\n", (u32) object->integer.value);
259do_fail:
260 return (buf);
Luming Yufb9802f2005-03-18 18:03:45 -0500261}
262
263static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
264{
265 struct acpi_polling_hotkey *poll_hotkey =
266 (struct acpi_polling_hotkey *)seq->private;
Luming Yu79cda7d2005-08-03 18:07:59 -0400267 char *buf;
Luming Yufb9802f2005-03-18 18:03:45 -0500268
269 ACPI_FUNCTION_TRACE("hotkey_polling_seq_show");
270
Luming Yu79cda7d2005-08-03 18:07:59 -0400271 if (poll_hotkey->poll_result){
272 buf = format_result(poll_hotkey->poll_result);
273 if(buf)
274 seq_printf(seq, "%s", buf);
275 kfree(buf);
276 }
Luming Yufb9802f2005-03-18 18:03:45 -0500277 return_VALUE(0);
278}
279
280static int hotkey_polling_open_fs(struct inode *inode, struct file *file)
281{
282 return single_open(file, hotkey_polling_seq_show, PDE(inode)->data);
283}
284
285static int hotkey_action_open_fs(struct inode *inode, struct file *file)
286{
287 return single_open(file, hotkey_info_seq_show, PDE(inode)->data);
288}
289
290/* Mapping external hotkey number to standardized hotkey event num */
291static int hotkey_get_internal_event(int event, struct acpi_hotkey_list *list)
292{
Luming Yu79cda7d2005-08-03 18:07:59 -0400293 struct list_head *entries;
294 int val = -1;
Luming Yufb9802f2005-03-18 18:03:45 -0500295
296 ACPI_FUNCTION_TRACE("hotkey_get_internal_event");
297
Luming Yu79cda7d2005-08-03 18:07:59 -0400298 list_for_each(entries, list->entries) {
Luming Yufb9802f2005-03-18 18:03:45 -0500299 union acpi_hotkey *key =
300 container_of(entries, union acpi_hotkey, entries);
301 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT
Luming Yu79cda7d2005-08-03 18:07:59 -0400302 && key->event_hotkey.external_hotkey_num == event){
Luming Yufb9802f2005-03-18 18:03:45 -0500303 val = key->link.hotkey_standard_num;
Luming Yu79cda7d2005-08-03 18:07:59 -0400304 break;
305 }
Luming Yufb9802f2005-03-18 18:03:45 -0500306 }
307
308 return_VALUE(val);
309}
310
311static void
312acpi_hotkey_notify_handler(acpi_handle handle, u32 event, void *data)
313{
314 struct acpi_device *device = NULL;
315 u32 internal_event;
316
317 ACPI_FUNCTION_TRACE("acpi_hotkey_notify_handler");
318
319 if (acpi_bus_get_device(handle, &device))
320 return_VOID;
321
322 internal_event = hotkey_get_internal_event(event, &global_hotkey_list);
Luming Yu79cda7d2005-08-03 18:07:59 -0400323 acpi_bus_generate_event(device, internal_event, 0);
Luming Yufb9802f2005-03-18 18:03:45 -0500324
325 return_VOID;
326}
327
328/* Need to invent automatically hotkey add method */
329static int auto_hotkey_add(struct acpi_device *device)
330{
331 /* Implement me */
332 return 0;
333}
334
335/* Need to invent automatically hotkey remove method */
336static int auto_hotkey_remove(struct acpi_device *device, int type)
337{
338 /* Implement me */
339 return 0;
340}
341
342/* Create a proc file for each polling method */
343static int create_polling_proc(union acpi_hotkey *device)
344{
345 struct proc_dir_entry *proc;
Luming Yu79cda7d2005-08-03 18:07:59 -0400346 char proc_name[80];
Andrew Morton8de7a632005-03-30 22:53:30 -0500347 mode_t mode;
Luming Yufb9802f2005-03-18 18:03:45 -0500348
349 ACPI_FUNCTION_TRACE("create_polling_proc");
Andrew Morton8de7a632005-03-30 22:53:30 -0500350 mode = S_IFREG | S_IRUGO | S_IWUGO;
Luming Yufb9802f2005-03-18 18:03:45 -0500351
Luming Yu79cda7d2005-08-03 18:07:59 -0400352 sprintf(proc_name, "%d", device->link.hotkey_standard_num);
353 /*
354 strcat(proc_name, device->poll_hotkey.poll_method);
355 */
356 proc = create_proc_entry(proc_name, mode, hotkey_proc_dir);
Luming Yufb9802f2005-03-18 18:03:45 -0500357
358 if (!proc) {
359 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
360 "Hotkey: Unable to create %s entry\n",
361 device->poll_hotkey.poll_method));
362 return_VALUE(-ENODEV);
363 } else {
364 proc->proc_fops = &hotkey_polling_fops;
365 proc->owner = THIS_MODULE;
366 proc->data = device;
367 proc->uid = 0;
368 proc->gid = 0;
369 device->poll_hotkey.proc = proc;
370 }
371 return_VALUE(0);
372}
373
Luming Yufb9802f2005-03-18 18:03:45 -0500374static int hotkey_add(union acpi_hotkey *device)
375{
376 int status = 0;
377 struct acpi_device *dev = NULL;
378
379 ACPI_FUNCTION_TRACE("hotkey_add");
380
381 if (device->link.hotkey_type == ACPI_HOTKEY_EVENT) {
Luming Yu79cda7d2005-08-03 18:07:59 -0400382 acpi_bus_get_device(device->event_hotkey.bus_handle, &dev);
Luming Yufb9802f2005-03-18 18:03:45 -0500383 status = acpi_install_notify_handler(dev->handle,
Luming Yu79cda7d2005-08-03 18:07:59 -0400384 ACPI_DEVICE_NOTIFY,
Luming Yufb9802f2005-03-18 18:03:45 -0500385 acpi_hotkey_notify_handler,
Luming Yu79cda7d2005-08-03 18:07:59 -0400386 dev);
Luming Yufb9802f2005-03-18 18:03:45 -0500387 } else /* Add polling hotkey */
388 create_polling_proc(device);
389
390 global_hotkey_list.count++;
391
392 list_add_tail(&device->link.entries, global_hotkey_list.entries);
393
394 return_VALUE(status);
395}
396
397static int hotkey_remove(union acpi_hotkey *device)
398{
399 struct list_head *entries, *next;
400
401 ACPI_FUNCTION_TRACE("hotkey_remove");
402
403 list_for_each_safe(entries, next, global_hotkey_list.entries) {
404 union acpi_hotkey *key =
405 container_of(entries, union acpi_hotkey, entries);
406 if (key->link.hotkey_standard_num ==
407 device->link.hotkey_standard_num) {
408 list_del(&key->link.entries);
Luming Yu79cda7d2005-08-03 18:07:59 -0400409 free_hotkey_device(key);
Luming Yufb9802f2005-03-18 18:03:45 -0500410 global_hotkey_list.count--;
411 break;
412 }
413 }
Luming Yu79cda7d2005-08-03 18:07:59 -0400414 kfree(device);
Luming Yufb9802f2005-03-18 18:03:45 -0500415 return_VALUE(0);
416}
417
Luming Yu79cda7d2005-08-03 18:07:59 -0400418static int hotkey_update(union acpi_hotkey *key)
Luming Yufb9802f2005-03-18 18:03:45 -0500419{
Luming Yu79cda7d2005-08-03 18:07:59 -0400420 struct list_head *entries;
Luming Yufb9802f2005-03-18 18:03:45 -0500421
422 ACPI_FUNCTION_TRACE("hotkey_update");
423
Luming Yu79cda7d2005-08-03 18:07:59 -0400424 list_for_each(entries, global_hotkey_list.entries) {
425 union acpi_hotkey *tmp=
Luming Yufb9802f2005-03-18 18:03:45 -0500426 container_of(entries, union acpi_hotkey, entries);
Luming Yu79cda7d2005-08-03 18:07:59 -0400427 if (tmp->link.hotkey_standard_num ==
Luming Yufb9802f2005-03-18 18:03:45 -0500428 key->link.hotkey_standard_num) {
Luming Yu79cda7d2005-08-03 18:07:59 -0400429 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
430 free_hotkey_buffer(tmp);
431 tmp->event_hotkey.bus_handle =
432 key->event_hotkey.bus_handle;
433 tmp->event_hotkey.external_hotkey_num =
434 key->event_hotkey.external_hotkey_num;
435 tmp->event_hotkey.action_handle =
436 key->event_hotkey.action_handle;
437 tmp->event_hotkey.action_method =
438 key->event_hotkey.action_method;
439 kfree(key);
440 } else {
441 /*
442 char proc_name[80];
443
444 sprintf(proc_name, "%d", tmp->link.hotkey_standard_num);
445 strcat(proc_name, tmp->poll_hotkey.poll_method);
446 remove_proc_entry(proc_name,hotkey_proc_dir);
447 */
448 free_poll_hotkey_buffer(tmp);
449 tmp->poll_hotkey.poll_handle =
450 key->poll_hotkey.poll_handle;
451 tmp->poll_hotkey.poll_method =
452 key->poll_hotkey.poll_method;
453 tmp->poll_hotkey.action_handle =
454 key->poll_hotkey.action_handle;
455 tmp->poll_hotkey.action_method =
456 key->poll_hotkey.action_method;
457 tmp->poll_hotkey.poll_result =
458 key->poll_hotkey.poll_result;
459 /*
460 create_polling_proc(tmp);
461 */
462 kfree(key);
463 }
464 return_VALUE(0);
Luming Yufb9802f2005-03-18 18:03:45 -0500465 break;
466 }
467 }
468
Luming Yu79cda7d2005-08-03 18:07:59 -0400469 return_VALUE(-ENODEV);
Luming Yufb9802f2005-03-18 18:03:45 -0500470}
471
472static void free_hotkey_device(union acpi_hotkey *key)
473{
474 struct acpi_device *dev;
Luming Yufb9802f2005-03-18 18:03:45 -0500475
476 ACPI_FUNCTION_TRACE("free_hotkey_device");
477
478 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
Luming Yu79cda7d2005-08-03 18:07:59 -0400479 acpi_bus_get_device(key->event_hotkey.bus_handle, &dev);
Luming Yufb9802f2005-03-18 18:03:45 -0500480 if (dev->handle)
481 acpi_remove_notify_handler(dev->handle,
Luming Yu79cda7d2005-08-03 18:07:59 -0400482 ACPI_DEVICE_NOTIFY,
Luming Yufb9802f2005-03-18 18:03:45 -0500483 acpi_hotkey_notify_handler);
Luming Yu79cda7d2005-08-03 18:07:59 -0400484 free_hotkey_buffer(key);
485 } else {
486 char proc_name[80];
487
488 sprintf(proc_name, "%d", key->link.hotkey_standard_num);
489 /*
490 strcat(proc_name, key->poll_hotkey.poll_method);
491 */
492 remove_proc_entry(proc_name,hotkey_proc_dir);
493 free_poll_hotkey_buffer(key);
494 }
Luming Yufb9802f2005-03-18 18:03:45 -0500495 kfree(key);
496 return_VOID;
497}
498
Luming Yu79cda7d2005-08-03 18:07:59 -0400499static void
500free_hotkey_buffer(union acpi_hotkey *key)
501{
502 kfree(key->event_hotkey.action_method);
503}
504
505static void
506free_poll_hotkey_buffer(union acpi_hotkey *key)
507{
508 kfree(key->poll_hotkey.action_method);
509 kfree(key->poll_hotkey.poll_method);
510 kfree(key->poll_hotkey.poll_result);
511}
Luming Yufb9802f2005-03-18 18:03:45 -0500512static int
513init_hotkey_device(union acpi_hotkey *key, char *bus_str, char *action_str,
514 char *method, int std_num, int external_num)
515{
Luming Yu79cda7d2005-08-03 18:07:59 -0400516 acpi_handle tmp_handle;
517 acpi_status status = AE_OK;
518
Luming Yufb9802f2005-03-18 18:03:45 -0500519 ACPI_FUNCTION_TRACE("init_hotkey_device");
520
Luming Yu79cda7d2005-08-03 18:07:59 -0400521 if(std_num < 0 || IS_POLL(std_num) || !key )
522 goto do_fail;
523
524 if(!bus_str || !action_str || !method)
525 goto do_fail;
526
Luming Yufb9802f2005-03-18 18:03:45 -0500527 key->link.hotkey_type = ACPI_HOTKEY_EVENT;
528 key->link.hotkey_standard_num = std_num;
529 key->event_hotkey.flag = 0;
Luming Yu79cda7d2005-08-03 18:07:59 -0400530 key->event_hotkey.action_method = method;
Luming Yufb9802f2005-03-18 18:03:45 -0500531
Luming Yu79cda7d2005-08-03 18:07:59 -0400532 status = acpi_get_handle(NULL,bus_str, &(key->event_hotkey.bus_handle));
533 if(ACPI_FAILURE(status))
534 goto do_fail;
535 key->event_hotkey.external_hotkey_num = external_num;
536 status = acpi_get_handle(NULL,action_str, &(key->event_hotkey.action_handle));
537 if(ACPI_FAILURE(status))
538 goto do_fail;
539 status = acpi_get_handle(key->event_hotkey.action_handle,
540 method, &tmp_handle);
541 if (ACPI_FAILURE(status))
542 goto do_fail;
543 return_VALUE(AE_OK);
544do_fail:
545 return_VALUE(-ENODEV);
Luming Yufb9802f2005-03-18 18:03:45 -0500546}
547
548static int
549init_poll_hotkey_device(union acpi_hotkey *key,
550 char *poll_str,
551 char *poll_method,
552 char *action_str, char *action_method, int std_num)
553{
Luming Yu79cda7d2005-08-03 18:07:59 -0400554 acpi_status status = AE_OK;
555 acpi_handle tmp_handle;
556
Luming Yufb9802f2005-03-18 18:03:45 -0500557 ACPI_FUNCTION_TRACE("init_poll_hotkey_device");
558
Luming Yu79cda7d2005-08-03 18:07:59 -0400559 if(std_num < 0 || IS_EVENT(std_num) || !key)
560 goto do_fail;
561
562 if(!poll_str || !poll_method || !action_str || !action_method)
563 goto do_fail;
564
Luming Yufb9802f2005-03-18 18:03:45 -0500565 key->link.hotkey_type = ACPI_HOTKEY_POLLING;
566 key->link.hotkey_standard_num = std_num;
567 key->poll_hotkey.flag = 0;
Luming Yufb9802f2005-03-18 18:03:45 -0500568 key->poll_hotkey.poll_method = poll_method;
Luming Yu79cda7d2005-08-03 18:07:59 -0400569 key->poll_hotkey.action_method = action_method;
570
571 status = acpi_get_handle(NULL,poll_str, &(key->poll_hotkey.poll_handle));
572 if(ACPI_FAILURE(status))
573 goto do_fail;
574 status = acpi_get_handle(key->poll_hotkey.poll_handle,
575 poll_method, &tmp_handle);
576 if (ACPI_FAILURE(status))
577 goto do_fail;
578 status = acpi_get_handle(NULL,action_str, &(key->poll_hotkey.action_handle));
579 if (ACPI_FAILURE(status))
580 goto do_fail;
581 status = acpi_get_handle(key->poll_hotkey.action_handle,
582 action_method, &tmp_handle);
583 if (ACPI_FAILURE(status))
584 goto do_fail;
Luming Yufb9802f2005-03-18 18:03:45 -0500585 key->poll_hotkey.poll_result =
586 (union acpi_object *)kmalloc(sizeof(union acpi_object), GFP_KERNEL);
Luming Yu79cda7d2005-08-03 18:07:59 -0400587 if(!key->poll_hotkey.poll_result)
588 goto do_fail;
589 return_VALUE(AE_OK);
590do_fail:
591 return_VALUE(-ENODEV);
Luming Yufb9802f2005-03-18 18:03:45 -0500592}
593
Luming Yufb9802f2005-03-18 18:03:45 -0500594
595static int hotkey_open_config(struct inode *inode, struct file *file)
596{
597 ACPI_FUNCTION_TRACE("hotkey_open_config");
598 return_VALUE(single_open
599 (file, hotkey_config_seq_show, PDE(inode)->data));
600}
601
Luming Yu79cda7d2005-08-03 18:07:59 -0400602static int hotkey_poll_open_config(struct inode *inode, struct file *file)
603{
604 ACPI_FUNCTION_TRACE("hotkey_poll_open_config");
605 return_VALUE(single_open
606 (file, hotkey_poll_config_seq_show, PDE(inode)->data));
607}
608
Luming Yufb9802f2005-03-18 18:03:45 -0500609static int hotkey_config_seq_show(struct seq_file *seq, void *offset)
610{
611 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
Luming Yu79cda7d2005-08-03 18:07:59 -0400612 struct list_head *entries;
Luming Yufb9802f2005-03-18 18:03:45 -0500613 char bus_name[ACPI_PATHNAME_MAX] = { 0 };
614 char action_name[ACPI_PATHNAME_MAX] = { 0 };
615 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
616 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
617
618 ACPI_FUNCTION_TRACE(("hotkey_config_seq_show"));
619
Luming Yu79cda7d2005-08-03 18:07:59 -0400620 list_for_each(entries, hotkey_list->entries) {
Luming Yufb9802f2005-03-18 18:03:45 -0500621 union acpi_hotkey *key =
622 container_of(entries, union acpi_hotkey, entries);
623 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
624 acpi_get_name(key->event_hotkey.bus_handle,
625 ACPI_NAME_TYPE_MAX, &bus);
626 acpi_get_name(key->event_hotkey.action_handle,
627 ACPI_NAME_TYPE_MAX, &act);
Luming Yu79cda7d2005-08-03 18:07:59 -0400628 seq_printf(seq, "%s:%s:%s:%d:%d\n", bus_name,
Luming Yufb9802f2005-03-18 18:03:45 -0500629 action_name,
630 key->event_hotkey.action_method,
631 key->link.hotkey_standard_num,
632 key->event_hotkey.external_hotkey_num);
Luming Yu79cda7d2005-08-03 18:07:59 -0400633 }
634 }
635 seq_puts(seq, "\n");
636 return_VALUE(0);
637}
638
639static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset)
640{
641 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
642 struct list_head *entries;
643 char bus_name[ACPI_PATHNAME_MAX] = { 0 };
644 char action_name[ACPI_PATHNAME_MAX] = { 0 };
645 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
646 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
647
648 ACPI_FUNCTION_TRACE(("hotkey_config_seq_show"));
649
650 list_for_each(entries, hotkey_list->entries) {
651 union acpi_hotkey *key =
652 container_of(entries, union acpi_hotkey, entries);
653 if (key->link.hotkey_type == ACPI_HOTKEY_POLLING) {
Luming Yufb9802f2005-03-18 18:03:45 -0500654 acpi_get_name(key->poll_hotkey.poll_handle,
655 ACPI_NAME_TYPE_MAX, &bus);
656 acpi_get_name(key->poll_hotkey.action_handle,
657 ACPI_NAME_TYPE_MAX, &act);
Luming Yu79cda7d2005-08-03 18:07:59 -0400658 seq_printf(seq, "%s:%s:%s:%s:%d\n", bus_name,
Luming Yufb9802f2005-03-18 18:03:45 -0500659 key->poll_hotkey.poll_method,
660 action_name,
661 key->poll_hotkey.action_method,
662 key->link.hotkey_standard_num);
663 }
664 }
665 seq_puts(seq, "\n");
Luming Yufb9802f2005-03-18 18:03:45 -0500666 return_VALUE(0);
667}
668
669static int
670get_parms(char *config_record,
671 int *cmd,
Luming Yu79cda7d2005-08-03 18:07:59 -0400672 char **bus_handle,
673 char **bus_method,
674 char **action_handle,
675 char **method, int *internal_event_num, int *external_event_num)
Luming Yufb9802f2005-03-18 18:03:45 -0500676{
Luming Yu79cda7d2005-08-03 18:07:59 -0400677 char *tmp, *tmp1, count;
Luming Yufb9802f2005-03-18 18:03:45 -0500678 ACPI_FUNCTION_TRACE(("get_parms"));
679
680 sscanf(config_record, "%d", cmd);
681
Luming Yu79cda7d2005-08-03 18:07:59 -0400682 if(*cmd == 1){
683 if(sscanf(config_record, "%d:%d", cmd, internal_event_num)!=2)
684 goto do_fail;
685 else
686 return (6);
687 }
Luming Yufb9802f2005-03-18 18:03:45 -0500688 tmp = strchr(config_record, ':');
Luming Yu79cda7d2005-08-03 18:07:59 -0400689 if (!tmp)
690 goto do_fail;
Luming Yufb9802f2005-03-18 18:03:45 -0500691 tmp++;
692 tmp1 = strchr(tmp, ':');
Luming Yu79cda7d2005-08-03 18:07:59 -0400693 if (!tmp1)
694 goto do_fail;
695
696 count = tmp1 - tmp;
697 *bus_handle = (char *) kmalloc(count+1, GFP_KERNEL);
698 if(!*bus_handle)
699 goto do_fail;
700 strncpy(*bus_handle, tmp, count);
701 *(*bus_handle + count) = 0;
Luming Yufb9802f2005-03-18 18:03:45 -0500702
703 tmp = tmp1;
704 tmp++;
705 tmp1 = strchr(tmp, ':');
Luming Yu79cda7d2005-08-03 18:07:59 -0400706 if (!tmp1)
707 goto do_fail;
708 count = tmp1 - tmp;
709 *bus_method = (char *) kmalloc(count+1, GFP_KERNEL);
710 if(!*bus_method)
711 goto do_fail;
712 strncpy(*bus_method, tmp, count);
713 *(*bus_method + count) = 0;
Luming Yufb9802f2005-03-18 18:03:45 -0500714
715 tmp = tmp1;
716 tmp++;
717 tmp1 = strchr(tmp, ':');
Luming Yu79cda7d2005-08-03 18:07:59 -0400718 if (!tmp1)
719 goto do_fail;
720 count = tmp1 - tmp;
721 *action_handle = (char *) kmalloc(count+1, GFP_KERNEL);
722 strncpy(*action_handle, tmp, count);
723 *(*action_handle + count) = 0;
Luming Yufb9802f2005-03-18 18:03:45 -0500724
725 tmp = tmp1;
726 tmp++;
727 tmp1 = strchr(tmp, ':');
Luming Yu79cda7d2005-08-03 18:07:59 -0400728 if (!tmp1)
729 goto do_fail;
730 count = tmp1 - tmp;
731 *method = (char *) kmalloc(count+1, GFP_KERNEL);
732 if(!*method)
733 goto do_fail;
734 strncpy(*method, tmp, count);
735 *(*method + count) = 0;
Luming Yufb9802f2005-03-18 18:03:45 -0500736
Luming Yu79cda7d2005-08-03 18:07:59 -0400737 if(sscanf(tmp1 + 1, "%d:%d", internal_event_num, external_event_num)<=0)
738 goto do_fail;
739
Luming Yufb9802f2005-03-18 18:03:45 -0500740 return_VALUE(6);
Luming Yu79cda7d2005-08-03 18:07:59 -0400741do_fail:
742 return_VALUE(-1);
Luming Yufb9802f2005-03-18 18:03:45 -0500743}
744
745/* count is length for one input record */
746static ssize_t hotkey_write_config(struct file *file,
747 const char __user * buffer,
748 size_t count, loff_t * data)
749{
Luming Yu79cda7d2005-08-03 18:07:59 -0400750 char *config_record = NULL;
751 char *bus_handle = NULL;
752 char *bus_method = NULL;
753 char *action_handle = NULL;
754 char *method = NULL;
Luming Yufb9802f2005-03-18 18:03:45 -0500755 int cmd, internal_event_num, external_event_num;
756 int ret = 0;
757 union acpi_hotkey *key = NULL;
758
759 ACPI_FUNCTION_TRACE(("hotkey_write_config"));
760
Luming Yu79cda7d2005-08-03 18:07:59 -0400761 config_record = (char *) kmalloc(count+1, GFP_KERNEL);
762 if(!config_record)
763 return_VALUE(-ENOMEM);
Luming Yufb9802f2005-03-18 18:03:45 -0500764
765 if (copy_from_user(config_record, buffer, count)) {
Luming Yu79cda7d2005-08-03 18:07:59 -0400766 kfree(config_record);
Luming Yufb9802f2005-03-18 18:03:45 -0500767 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid data \n"));
768 return_VALUE(-EINVAL);
769 }
Luming Yu79cda7d2005-08-03 18:07:59 -0400770 config_record[count] = 0;
Luming Yufb9802f2005-03-18 18:03:45 -0500771
772 ret = get_parms(config_record,
773 &cmd,
Luming Yu79cda7d2005-08-03 18:07:59 -0400774 &bus_handle,
775 &bus_method,
776 &action_handle,
777 &method, &internal_event_num, &external_event_num);
778
779 kfree(config_record);
780 if(IS_OTHERS(internal_event_num))
781 goto do_fail;
Luming Yufb9802f2005-03-18 18:03:45 -0500782 if (ret != 6) {
Luming Yu79cda7d2005-08-03 18:07:59 -0400783do_fail:
784 kfree(bus_handle);
785 kfree(bus_method);
786 kfree(action_handle);
787 kfree(method);
Luming Yufb9802f2005-03-18 18:03:45 -0500788 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
789 "Invalid data format ret=%d\n", ret));
790 return_VALUE(-EINVAL);
791 }
792
793 key = kmalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
Luming Yu79cda7d2005-08-03 18:07:59 -0400794 if(!key)
795 goto do_fail;
796 memset(key, 0, sizeof(union acpi_hotkey));
797 if(cmd == 1) {
798 union acpi_hotkey *tmp = NULL;
799 tmp = get_hotkey_by_event(&global_hotkey_list,
800 internal_event_num);
801 if(!tmp)
802 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid key"));
803 else
804 memcpy(key, tmp, sizeof(union acpi_hotkey));
805 goto cont_cmd;
806 }
807 if (IS_EVENT(internal_event_num)) {
808 kfree(bus_method);
809 ret = init_hotkey_device(key, bus_handle, action_handle, method,
Luming Yufb9802f2005-03-18 18:03:45 -0500810 internal_event_num, external_event_num);
Luming Yu79cda7d2005-08-03 18:07:59 -0400811 } else
812 ret = init_poll_hotkey_device(key, bus_handle, bus_method,
813 action_handle, method,
Luming Yufb9802f2005-03-18 18:03:45 -0500814 internal_event_num);
Luming Yu79cda7d2005-08-03 18:07:59 -0400815 if (ret) {
816 kfree(bus_handle);
817 kfree(action_handle);
818 if(IS_EVENT(internal_event_num))
819 free_hotkey_buffer(key);
820 else
821 free_poll_hotkey_buffer(key);
Luming Yufb9802f2005-03-18 18:03:45 -0500822 kfree(key);
823 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid hotkey \n"));
824 return_VALUE(-EINVAL);
825 }
Luming Yu79cda7d2005-08-03 18:07:59 -0400826
827cont_cmd:
828 kfree(bus_handle);
829 kfree(action_handle);
830
Luming Yufb9802f2005-03-18 18:03:45 -0500831 switch (cmd) {
832 case 0:
Luming Yu79cda7d2005-08-03 18:07:59 -0400833 if(get_hotkey_by_event(&global_hotkey_list,key->link.hotkey_standard_num))
834 goto fail_out;
835 else
836 hotkey_add(key);
Luming Yufb9802f2005-03-18 18:03:45 -0500837 break;
838 case 1:
839 hotkey_remove(key);
840 break;
841 case 2:
Luming Yu79cda7d2005-08-03 18:07:59 -0400842 if(hotkey_update(key))
843 goto fail_out;
Luming Yufb9802f2005-03-18 18:03:45 -0500844 break;
845 default:
Luming Yu79cda7d2005-08-03 18:07:59 -0400846 goto fail_out;
Luming Yufb9802f2005-03-18 18:03:45 -0500847 break;
848 }
849 return_VALUE(count);
Luming Yu79cda7d2005-08-03 18:07:59 -0400850fail_out:
851 if(IS_EVENT(internal_event_num))
852 free_hotkey_buffer(key);
853 else
854 free_poll_hotkey_buffer(key);
855 kfree(key);
856 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "invalid key\n"));
857 return_VALUE(-EINVAL);
Luming Yufb9802f2005-03-18 18:03:45 -0500858}
859
Luming Yu79cda7d2005-08-03 18:07:59 -0400860/*
Luming Yufb9802f2005-03-18 18:03:45 -0500861 * This function evaluates an ACPI method, given an int as parameter, the
862 * method is searched within the scope of the handle, can be NULL. The output
863 * of the method is written is output, which can also be NULL
864 *
865 * returns 1 if write is successful, 0 else.
866 */
867static int write_acpi_int(acpi_handle handle, const char *method, int val,
868 struct acpi_buffer *output)
869{
870 struct acpi_object_list params; /* list of input parameters (an int here) */
871 union acpi_object in_obj; /* the only param we use */
872 acpi_status status;
873
874 ACPI_FUNCTION_TRACE("write_acpi_int");
875 params.count = 1;
876 params.pointer = &in_obj;
877 in_obj.type = ACPI_TYPE_INTEGER;
878 in_obj.integer.value = val;
879
880 status = acpi_evaluate_object(handle, (char *)method, &params, output);
881
882 return_VALUE(status == AE_OK);
883}
884
Luming Yu79cda7d2005-08-03 18:07:59 -0400885static int read_acpi_int(acpi_handle handle, const char *method, union acpi_object *val)
Luming Yufb9802f2005-03-18 18:03:45 -0500886{
887 struct acpi_buffer output;
888 union acpi_object out_obj;
889 acpi_status status;
890
891 ACPI_FUNCTION_TRACE("read_acpi_int");
892 output.length = sizeof(out_obj);
893 output.pointer = &out_obj;
894
895 status = acpi_evaluate_object(handle, (char *)method, NULL, &output);
Luming Yu79cda7d2005-08-03 18:07:59 -0400896 if(val){
897 val->integer.value = out_obj.integer.value;
898 val->type = out_obj.type;
899 } else
900 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "null val pointer"));
Luming Yufb9802f2005-03-18 18:03:45 -0500901 return_VALUE((status == AE_OK)
902 && (out_obj.type == ACPI_TYPE_INTEGER));
903}
904
Luming Yu79cda7d2005-08-03 18:07:59 -0400905static union acpi_hotkey *get_hotkey_by_event(struct
906 acpi_hotkey_list
907 *hotkey_list, int event)
Luming Yufb9802f2005-03-18 18:03:45 -0500908{
Luming Yu79cda7d2005-08-03 18:07:59 -0400909 struct list_head *entries;
Luming Yufb9802f2005-03-18 18:03:45 -0500910
Luming Yu79cda7d2005-08-03 18:07:59 -0400911 list_for_each(entries, hotkey_list->entries) {
Luming Yufb9802f2005-03-18 18:03:45 -0500912 union acpi_hotkey *key =
913 container_of(entries, union acpi_hotkey, entries);
Luming Yu79cda7d2005-08-03 18:07:59 -0400914 if (key->link.hotkey_standard_num == event) {
915 return(key);
Luming Yufb9802f2005-03-18 18:03:45 -0500916 }
917 }
Luming Yu79cda7d2005-08-03 18:07:59 -0400918 return(NULL);
Luming Yufb9802f2005-03-18 18:03:45 -0500919}
920
Luming Yu79cda7d2005-08-03 18:07:59 -0400921/*
Luming Yufb9802f2005-03-18 18:03:45 -0500922 * user call AML method interface:
923 * Call convention:
924 * echo "event_num: arg type : value"
925 * example: echo "1:1:30" > /proc/acpi/action
926 * Just support 1 integer arg passing to AML method
927 */
928
929static ssize_t hotkey_execute_aml_method(struct file *file,
930 const char __user * buffer,
931 size_t count, loff_t * data)
932{
933 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
Luming Yu79cda7d2005-08-03 18:07:59 -0400934 char *arg;
935 int event,method_type,type, value;
936 union acpi_hotkey *key;
Luming Yufb9802f2005-03-18 18:03:45 -0500937
938 ACPI_FUNCTION_TRACE("hotkey_execte_aml_method");
939
Luming Yu79cda7d2005-08-03 18:07:59 -0400940 arg = (char *) kmalloc(count+1, GFP_KERNEL);
941 if(!arg)
942 return_VALUE(-ENOMEM);
943 arg[count]=0;
Luming Yufb9802f2005-03-18 18:03:45 -0500944
945 if (copy_from_user(arg, buffer, count)) {
Luming Yu79cda7d2005-08-03 18:07:59 -0400946 kfree(arg);
Luming Yufb9802f2005-03-18 18:03:45 -0500947 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 2"));
948 return_VALUE(-EINVAL);
949 }
950
Luming Yu79cda7d2005-08-03 18:07:59 -0400951 if (sscanf(arg, "%d:%d:%d:%d", &event, &method_type, &type, &value) != 4) {
952 kfree(arg);
Luming Yufb9802f2005-03-18 18:03:45 -0500953 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Invalid argument 3"));
954 return_VALUE(-EINVAL);
955 }
Luming Yu79cda7d2005-08-03 18:07:59 -0400956 kfree(arg);
Luming Yufb9802f2005-03-18 18:03:45 -0500957 if (type == ACPI_TYPE_INTEGER) {
Luming Yu79cda7d2005-08-03 18:07:59 -0400958 key = get_hotkey_by_event(hotkey_list, event);
959 if(!key)
960 goto do_fail;
Luming Yufb9802f2005-03-18 18:03:45 -0500961 if (IS_EVENT(event))
Luming Yu79cda7d2005-08-03 18:07:59 -0400962 write_acpi_int(key->event_hotkey.action_handle,
963 key->event_hotkey.action_method, value, NULL);
Luming Yufb9802f2005-03-18 18:03:45 -0500964 else if (IS_POLL(event)) {
Luming Yu79cda7d2005-08-03 18:07:59 -0400965 if ( method_type == POLL_METHOD )
966 read_acpi_int(key->poll_hotkey.poll_handle,
967 key->poll_hotkey.poll_method,
968 key->poll_hotkey.poll_result);
969 else if ( method_type == ACTION_METHOD )
970 write_acpi_int(key->poll_hotkey.action_handle,
971 key->poll_hotkey.action_method, value, NULL);
972 else
973 goto do_fail;
974
Luming Yufb9802f2005-03-18 18:03:45 -0500975 }
976 } else {
977 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Not supported"));
978 return_VALUE(-EINVAL);
979 }
Luming Yufb9802f2005-03-18 18:03:45 -0500980 return_VALUE(count);
Luming Yu79cda7d2005-08-03 18:07:59 -0400981do_fail:
982 return_VALUE(-EINVAL);
983
Luming Yufb9802f2005-03-18 18:03:45 -0500984}
985
986static int __init hotkey_init(void)
987{
988 int result;
989 mode_t mode = S_IFREG | S_IRUGO | S_IWUGO;
990
991 ACPI_FUNCTION_TRACE("hotkey_init");
992
993 if (acpi_disabled)
994 return -ENODEV;
995
996 if (acpi_specific_hotkey_enabled) {
997 printk("Using specific hotkey driver\n");
998 return -ENODEV;
999 }
1000
1001 hotkey_proc_dir = proc_mkdir(HOTKEY_PROC, acpi_root_dir);
1002 if (!hotkey_proc_dir) {
1003 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1004 "Hotkey: Unable to create %s entry\n",
1005 HOTKEY_PROC));
1006 return (-ENODEV);
1007 }
1008 hotkey_proc_dir->owner = THIS_MODULE;
1009
1010 hotkey_config =
1011 create_proc_entry(HOTKEY_EV_CONFIG, mode, hotkey_proc_dir);
1012 if (!hotkey_config) {
1013 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1014 "Hotkey: Unable to create %s entry\n",
1015 HOTKEY_EV_CONFIG));
Luming Yu79cda7d2005-08-03 18:07:59 -04001016 goto do_fail1;
Luming Yufb9802f2005-03-18 18:03:45 -05001017 } else {
1018 hotkey_config->proc_fops = &hotkey_config_fops;
1019 hotkey_config->data = &global_hotkey_list;
1020 hotkey_config->owner = THIS_MODULE;
1021 hotkey_config->uid = 0;
1022 hotkey_config->gid = 0;
1023 }
1024
1025 hotkey_poll_config =
1026 create_proc_entry(HOTKEY_PL_CONFIG, mode, hotkey_proc_dir);
1027 if (!hotkey_poll_config) {
1028 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1029 "Hotkey: Unable to create %s entry\n",
1030 HOTKEY_EV_CONFIG));
Luming Yu79cda7d2005-08-03 18:07:59 -04001031
1032 goto do_fail2;
Luming Yufb9802f2005-03-18 18:03:45 -05001033 } else {
1034 hotkey_poll_config->proc_fops = &hotkey_poll_config_fops;
1035 hotkey_poll_config->data = &global_hotkey_list;
1036 hotkey_poll_config->owner = THIS_MODULE;
1037 hotkey_poll_config->uid = 0;
1038 hotkey_poll_config->gid = 0;
1039 }
1040
1041 hotkey_action = create_proc_entry(HOTKEY_ACTION, mode, hotkey_proc_dir);
1042 if (!hotkey_action) {
1043 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1044 "Hotkey: Unable to create %s entry\n",
1045 HOTKEY_ACTION));
Luming Yu79cda7d2005-08-03 18:07:59 -04001046 goto do_fail3;
Luming Yufb9802f2005-03-18 18:03:45 -05001047 } else {
1048 hotkey_action->proc_fops = &hotkey_action_fops;
1049 hotkey_action->owner = THIS_MODULE;
1050 hotkey_action->uid = 0;
1051 hotkey_action->gid = 0;
1052 }
1053
1054 hotkey_info = create_proc_entry(HOTKEY_INFO, mode, hotkey_proc_dir);
1055 if (!hotkey_info) {
1056 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
1057 "Hotkey: Unable to create %s entry\n",
1058 HOTKEY_INFO));
Luming Yu79cda7d2005-08-03 18:07:59 -04001059 goto do_fail4;
Luming Yufb9802f2005-03-18 18:03:45 -05001060 } else {
1061 hotkey_info->proc_fops = &hotkey_info_fops;
1062 hotkey_info->owner = THIS_MODULE;
1063 hotkey_info->uid = 0;
1064 hotkey_info->gid = 0;
1065 }
1066
1067 result = acpi_bus_register_driver(&hotkey_driver);
Luming Yu79cda7d2005-08-03 18:07:59 -04001068 if (result < 0)
1069 goto do_fail5;
Luming Yufb9802f2005-03-18 18:03:45 -05001070 global_hotkey_list.count = 0;
1071 global_hotkey_list.entries = &hotkey_entries;
1072
1073 INIT_LIST_HEAD(&hotkey_entries);
1074
1075 return (0);
Luming Yu79cda7d2005-08-03 18:07:59 -04001076
1077do_fail5:
1078 remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir);
1079do_fail4:
1080 remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir);
1081do_fail3:
1082 remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir);
1083do_fail2:
1084 remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir);
1085do_fail1:
1086 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
1087 return (-ENODEV);
Luming Yufb9802f2005-03-18 18:03:45 -05001088}
1089
1090static void __exit hotkey_exit(void)
1091{
1092 struct list_head *entries, *next;
1093
Luming Yu79cda7d2005-08-03 18:07:59 -04001094 ACPI_FUNCTION_TRACE("hotkey_exit");
Luming Yufb9802f2005-03-18 18:03:45 -05001095
1096 list_for_each_safe(entries, next, global_hotkey_list.entries) {
1097 union acpi_hotkey *key =
1098 container_of(entries, union acpi_hotkey, entries);
1099
1100 acpi_os_wait_events_complete(NULL);
1101 list_del(&key->link.entries);
1102 global_hotkey_list.count--;
1103 free_hotkey_device(key);
1104 }
1105 acpi_bus_unregister_driver(&hotkey_driver);
1106 remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir);
1107 remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir);
1108 remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir);
1109 remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir);
1110 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
1111 return;
1112}
1113
1114module_init(hotkey_init);
1115module_exit(hotkey_exit);