2 * hotkey.c - ACPI Hotkey Driver ($Revision: 0.2 $)
4 * Copyright (C) 2004 Luming Yu <luming.yu@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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.
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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>
36 #define HOTKEY_ACPI_VERSION "0.1"
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"
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
50 #define ACPI_HOTKEY_EVENT 0x1
51 #define ACPI_HOTKEY_POLLING 0x2
52 #define ACPI_UNDEFINED_EVENT 0xf
54 #define RESULT_STR_LEN 80
56 #define ACTION_METHOD 0
59 #define IS_EVENT(e) ((e) <= 10000 && (e) >0)
60 #define IS_POLL(e) ((e) > 10000)
61 #define IS_OTHERS(e) ((e)<=0 || (e)>=20000)
62 #define _COMPONENT ACPI_HOTKEY_COMPONENT
63 ACPI_MODULE_NAME("acpi_hotkey")
65 MODULE_AUTHOR("luming.yu@intel.com");
66 MODULE_DESCRIPTION(ACPI_HOTK_NAME);
67 MODULE_LICENSE("GPL");
69 /* standardized internal hotkey number/event */
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,
85 HK_EVENT_VOLUME_INCLREASE,
86 HK_EVENT_VOLUME_DECREASE,
88 /* running state control */
89 HK_EVENT_ENTERRING_S3,
90 HK_EVENT_ENTERRING_S4,
91 HK_EVENT_ENTERRING_S5,
95 static struct proc_dir_entry *hotkey_proc_dir;
96 static struct proc_dir_entry *hotkey_config;
97 static struct proc_dir_entry *hotkey_poll_config;
98 static struct proc_dir_entry *hotkey_action;
99 static struct proc_dir_entry *hotkey_info;
101 /* linkage for all type of hotkey */
102 struct 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 */
108 /* event based hotkey */
109 struct acpi_event_hotkey {
110 struct acpi_hotkey_link hotkey_link;
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 */
119 * 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.
127 /* polling based hotkey */
128 struct acpi_polling_hotkey {
129 struct acpi_hotkey_link hotkey_link;
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 */
135 union acpi_object *poll_result; /* polling_result */
136 struct proc_dir_entry *proc;
139 /* hotkey object union */
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;
147 /* hotkey object list */
148 struct acpi_hotkey_list {
149 struct list_head *entries;
153 static int auto_hotkey_add(struct acpi_device *device);
154 static int auto_hotkey_remove(struct acpi_device *device, int type);
156 static struct acpi_driver hotkey_driver = {
157 .name = ACPI_HOTK_NAME,
158 .class = ACPI_HOTK_CLASS,
159 .ids = ACPI_HOTK_HID,
161 .add = auto_hotkey_add,
162 .remove = auto_hotkey_remove,
166 static void free_hotkey_device(union acpi_hotkey *key);
167 static void free_hotkey_buffer(union acpi_hotkey *key);
168 static void free_poll_hotkey_buffer(union acpi_hotkey *key);
169 static int hotkey_open_config(struct inode *inode, struct file *file);
170 static int hotkey_poll_open_config(struct inode *inode, struct file *file);
171 static ssize_t hotkey_write_config(struct file *file,
172 const char __user * buffer,
173 size_t count, loff_t * data);
174 static int hotkey_info_open_fs(struct inode *inode, struct file *file);
175 static int hotkey_action_open_fs(struct inode *inode, struct file *file);
176 static ssize_t hotkey_execute_aml_method(struct file *file,
177 const char __user * buffer,
178 size_t count, loff_t * data);
179 static int hotkey_config_seq_show(struct seq_file *seq, void *offset);
180 static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset);
181 static int hotkey_polling_open_fs(struct inode *inode, struct file *file);
182 static union acpi_hotkey *get_hotkey_by_event(struct
184 *hotkey_list, int event);
186 /* event based config */
187 static const struct file_operations hotkey_config_fops = {
188 .open = hotkey_open_config,
190 .write = hotkey_write_config,
192 .release = single_release,
195 /* polling based config */
196 static const struct file_operations hotkey_poll_config_fops = {
197 .open = hotkey_poll_open_config,
199 .write = hotkey_write_config,
201 .release = single_release,
204 /* hotkey driver info */
205 static const struct file_operations hotkey_info_fops = {
206 .open = hotkey_info_open_fs,
209 .release = single_release,
213 static const struct file_operations hotkey_action_fops = {
214 .open = hotkey_action_open_fs,
216 .write = hotkey_execute_aml_method,
218 .release = single_release,
221 /* polling results */
222 static const struct file_operations hotkey_polling_fops = {
223 .open = hotkey_polling_open_fs,
226 .release = single_release,
229 struct acpi_hotkey_list global_hotkey_list; /* link all ev or pl hotkey */
230 struct list_head hotkey_entries; /* head of the list of hotkey_list */
232 static int hotkey_info_seq_show(struct seq_file *seq, void *offset)
235 seq_printf(seq, "Hotkey generic driver ver: %s\n", HOTKEY_ACPI_VERSION);
240 static int hotkey_info_open_fs(struct inode *inode, struct file *file)
242 return single_open(file, hotkey_info_seq_show, PDE(inode)->data);
245 static char *format_result(union acpi_object *object)
249 buf = (char *)kmalloc(RESULT_STR_LEN, GFP_KERNEL);
251 memset(buf, 0, RESULT_STR_LEN);
255 /* Now, just support integer type */
256 if (object->type == ACPI_TYPE_INTEGER)
257 sprintf(buf, "%d\n", (u32) object->integer.value);
262 static int hotkey_polling_seq_show(struct seq_file *seq, void *offset)
264 struct acpi_polling_hotkey *poll_hotkey =
265 (struct acpi_polling_hotkey *)seq->private;
269 if (poll_hotkey->poll_result) {
270 buf = format_result(poll_hotkey->poll_result);
272 seq_printf(seq, "%s", buf);
278 static int hotkey_polling_open_fs(struct inode *inode, struct file *file)
280 return single_open(file, hotkey_polling_seq_show, PDE(inode)->data);
283 static int hotkey_action_open_fs(struct inode *inode, struct file *file)
285 return single_open(file, hotkey_info_seq_show, PDE(inode)->data);
288 /* Mapping external hotkey number to standardized hotkey event num */
289 static int hotkey_get_internal_event(int event, struct acpi_hotkey_list *list)
291 struct list_head *entries;
295 list_for_each(entries, list->entries) {
296 union acpi_hotkey *key =
297 container_of(entries, union acpi_hotkey, entries);
298 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT
299 && key->event_hotkey.external_hotkey_num == event) {
300 val = key->link.hotkey_standard_num;
309 acpi_hotkey_notify_handler(acpi_handle handle, u32 event, void *data)
311 struct acpi_device *device = NULL;
315 if (acpi_bus_get_device(handle, &device))
318 internal_event = hotkey_get_internal_event(event, &global_hotkey_list);
319 acpi_bus_generate_event(device, internal_event, 0);
324 /* Need to invent automatically hotkey add method */
325 static int auto_hotkey_add(struct acpi_device *device)
331 /* Need to invent automatically hotkey remove method */
332 static int auto_hotkey_remove(struct acpi_device *device, int type)
338 /* Create a proc file for each polling method */
339 static int create_polling_proc(union acpi_hotkey *device)
341 struct proc_dir_entry *proc;
345 mode = S_IFREG | S_IRUGO | S_IWUGO;
347 sprintf(proc_name, "%d", device->link.hotkey_standard_num);
349 strcat(proc_name, device->poll_hotkey.poll_method);
351 proc = create_proc_entry(proc_name, mode, hotkey_proc_dir);
356 proc->proc_fops = &hotkey_polling_fops;
357 proc->owner = THIS_MODULE;
361 device->poll_hotkey.proc = proc;
366 static int hotkey_add(union acpi_hotkey *device)
369 struct acpi_device *dev = NULL;
372 if (device->link.hotkey_type == ACPI_HOTKEY_EVENT) {
373 acpi_bus_get_device(device->event_hotkey.bus_handle, &dev);
374 status = acpi_install_notify_handler(dev->handle,
376 acpi_hotkey_notify_handler,
378 } else /* Add polling hotkey */
379 create_polling_proc(device);
381 global_hotkey_list.count++;
383 list_add_tail(&device->link.entries, global_hotkey_list.entries);
388 static int hotkey_remove(union acpi_hotkey *device)
390 struct list_head *entries, *next;
393 list_for_each_safe(entries, next, global_hotkey_list.entries) {
394 union acpi_hotkey *key =
395 container_of(entries, union acpi_hotkey, entries);
396 if (key->link.hotkey_standard_num ==
397 device->link.hotkey_standard_num) {
398 list_del(&key->link.entries);
399 free_hotkey_device(key);
400 global_hotkey_list.count--;
408 static int hotkey_update(union acpi_hotkey *key)
410 struct list_head *entries;
413 list_for_each(entries, global_hotkey_list.entries) {
414 union acpi_hotkey *tmp =
415 container_of(entries, union acpi_hotkey, entries);
416 if (tmp->link.hotkey_standard_num ==
417 key->link.hotkey_standard_num) {
418 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
419 free_hotkey_buffer(tmp);
420 tmp->event_hotkey.bus_handle =
421 key->event_hotkey.bus_handle;
422 tmp->event_hotkey.external_hotkey_num =
423 key->event_hotkey.external_hotkey_num;
424 tmp->event_hotkey.action_handle =
425 key->event_hotkey.action_handle;
426 tmp->event_hotkey.action_method =
427 key->event_hotkey.action_method;
433 sprintf(proc_name, "%d", tmp->link.hotkey_standard_num);
434 strcat(proc_name, tmp->poll_hotkey.poll_method);
435 remove_proc_entry(proc_name,hotkey_proc_dir);
437 free_poll_hotkey_buffer(tmp);
438 tmp->poll_hotkey.poll_handle =
439 key->poll_hotkey.poll_handle;
440 tmp->poll_hotkey.poll_method =
441 key->poll_hotkey.poll_method;
442 tmp->poll_hotkey.action_handle =
443 key->poll_hotkey.action_handle;
444 tmp->poll_hotkey.action_method =
445 key->poll_hotkey.action_method;
446 tmp->poll_hotkey.poll_result =
447 key->poll_hotkey.poll_result;
449 create_polling_proc(tmp);
461 static void free_hotkey_device(union acpi_hotkey *key)
463 struct acpi_device *dev;
466 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
467 acpi_bus_get_device(key->event_hotkey.bus_handle, &dev);
469 acpi_remove_notify_handler(dev->handle,
471 acpi_hotkey_notify_handler);
472 free_hotkey_buffer(key);
476 sprintf(proc_name, "%d", key->link.hotkey_standard_num);
478 strcat(proc_name, key->poll_hotkey.poll_method);
480 remove_proc_entry(proc_name, hotkey_proc_dir);
481 free_poll_hotkey_buffer(key);
487 static void free_hotkey_buffer(union acpi_hotkey *key)
489 kfree(key->event_hotkey.action_method);
492 static void free_poll_hotkey_buffer(union acpi_hotkey *key)
494 kfree(key->poll_hotkey.action_method);
495 kfree(key->poll_hotkey.poll_method);
496 kfree(key->poll_hotkey.poll_result);
499 init_hotkey_device(union acpi_hotkey *key, char *bus_str, char *action_str,
500 char *method, int std_num, int external_num)
502 acpi_handle tmp_handle;
503 acpi_status status = AE_OK;
506 if (std_num < 0 || IS_POLL(std_num) || !key)
509 if (!bus_str || !action_str || !method)
512 key->link.hotkey_type = ACPI_HOTKEY_EVENT;
513 key->link.hotkey_standard_num = std_num;
514 key->event_hotkey.flag = 0;
515 key->event_hotkey.action_method = method;
518 acpi_get_handle(NULL, bus_str, &(key->event_hotkey.bus_handle));
519 if (ACPI_FAILURE(status))
521 key->event_hotkey.external_hotkey_num = external_num;
523 acpi_get_handle(NULL, action_str,
524 &(key->event_hotkey.action_handle));
525 if (ACPI_FAILURE(status))
527 status = acpi_get_handle(key->event_hotkey.action_handle,
528 method, &tmp_handle);
529 if (ACPI_FAILURE(status))
537 init_poll_hotkey_device(union acpi_hotkey *key,
540 char *action_str, char *action_method, int std_num)
542 acpi_status status = AE_OK;
543 acpi_handle tmp_handle;
546 if (std_num < 0 || IS_EVENT(std_num) || !key)
549 if (!poll_str || !poll_method || !action_str || !action_method)
552 key->link.hotkey_type = ACPI_HOTKEY_POLLING;
553 key->link.hotkey_standard_num = std_num;
554 key->poll_hotkey.flag = 0;
555 key->poll_hotkey.poll_method = poll_method;
556 key->poll_hotkey.action_method = action_method;
559 acpi_get_handle(NULL, poll_str, &(key->poll_hotkey.poll_handle));
560 if (ACPI_FAILURE(status))
562 status = acpi_get_handle(key->poll_hotkey.poll_handle,
563 poll_method, &tmp_handle);
564 if (ACPI_FAILURE(status))
567 acpi_get_handle(NULL, action_str,
568 &(key->poll_hotkey.action_handle));
569 if (ACPI_FAILURE(status))
571 status = acpi_get_handle(key->poll_hotkey.action_handle,
572 action_method, &tmp_handle);
573 if (ACPI_FAILURE(status))
575 key->poll_hotkey.poll_result =
576 (union acpi_object *)kmalloc(sizeof(union acpi_object), GFP_KERNEL);
577 if (!key->poll_hotkey.poll_result)
584 static int hotkey_open_config(struct inode *inode, struct file *file)
587 (file, hotkey_config_seq_show, PDE(inode)->data));
590 static int hotkey_poll_open_config(struct inode *inode, struct file *file)
593 (file, hotkey_poll_config_seq_show, PDE(inode)->data));
596 static int hotkey_config_seq_show(struct seq_file *seq, void *offset)
598 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
599 struct list_head *entries;
600 char bus_name[ACPI_PATHNAME_MAX] = { 0 };
601 char action_name[ACPI_PATHNAME_MAX] = { 0 };
602 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
603 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
606 list_for_each(entries, hotkey_list->entries) {
607 union acpi_hotkey *key =
608 container_of(entries, union acpi_hotkey, entries);
609 if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) {
610 acpi_get_name(key->event_hotkey.bus_handle,
611 ACPI_NAME_TYPE_MAX, &bus);
612 acpi_get_name(key->event_hotkey.action_handle,
613 ACPI_NAME_TYPE_MAX, &act);
614 seq_printf(seq, "%s:%s:%s:%d:%d\n", bus_name,
616 key->event_hotkey.action_method,
617 key->link.hotkey_standard_num,
618 key->event_hotkey.external_hotkey_num);
625 static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset)
627 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
628 struct list_head *entries;
629 char bus_name[ACPI_PATHNAME_MAX] = { 0 };
630 char action_name[ACPI_PATHNAME_MAX] = { 0 };
631 struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name };
632 struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name };
635 list_for_each(entries, hotkey_list->entries) {
636 union acpi_hotkey *key =
637 container_of(entries, union acpi_hotkey, entries);
638 if (key->link.hotkey_type == ACPI_HOTKEY_POLLING) {
639 acpi_get_name(key->poll_hotkey.poll_handle,
640 ACPI_NAME_TYPE_MAX, &bus);
641 acpi_get_name(key->poll_hotkey.action_handle,
642 ACPI_NAME_TYPE_MAX, &act);
643 seq_printf(seq, "%s:%s:%s:%s:%d\n", bus_name,
644 key->poll_hotkey.poll_method,
646 key->poll_hotkey.action_method,
647 key->link.hotkey_standard_num);
655 get_parms(char *config_record,
659 char **action_handle,
660 char **method, int *internal_event_num, int *external_event_num)
662 char *tmp, *tmp1, count;
664 sscanf(config_record, "%d", cmd);
667 if (sscanf(config_record, "%d:%d", cmd, internal_event_num) !=
673 tmp = strchr(config_record, ':');
677 tmp1 = strchr(tmp, ':');
682 *bus_handle = (char *)kmalloc(count + 1, GFP_KERNEL);
685 strncpy(*bus_handle, tmp, count);
686 *(*bus_handle + count) = 0;
690 tmp1 = strchr(tmp, ':');
694 *bus_method = (char *)kmalloc(count + 1, GFP_KERNEL);
697 strncpy(*bus_method, tmp, count);
698 *(*bus_method + count) = 0;
702 tmp1 = strchr(tmp, ':');
706 *action_handle = (char *)kmalloc(count + 1, GFP_KERNEL);
709 strncpy(*action_handle, tmp, count);
710 *(*action_handle + count) = 0;
714 tmp1 = strchr(tmp, ':');
718 *method = (char *)kmalloc(count + 1, GFP_KERNEL);
721 strncpy(*method, tmp, count);
722 *(*method + count) = 0;
724 if (sscanf(tmp1 + 1, "%d:%d", internal_event_num, external_event_num) <=
733 /* count is length for one input record */
734 static ssize_t hotkey_write_config(struct file *file,
735 const char __user * buffer,
736 size_t count, loff_t * data)
738 char *config_record = NULL;
739 char *bus_handle = NULL;
740 char *bus_method = NULL;
741 char *action_handle = NULL;
743 int cmd, internal_event_num, external_event_num;
745 union acpi_hotkey *key = NULL;
748 config_record = (char *)kmalloc(count + 1, GFP_KERNEL);
752 if (copy_from_user(config_record, buffer, count)) {
753 kfree(config_record);
754 printk(KERN_ERR PREFIX "Invalid data\n");
757 config_record[count] = 0;
759 ret = get_parms(config_record,
764 &method, &internal_event_num, &external_event_num);
766 kfree(config_record);
767 if (IS_OTHERS(internal_event_num))
773 kfree(action_handle);
775 printk(KERN_ERR PREFIX "Invalid data format ret=%d\n", ret);
779 key = kmalloc(sizeof(union acpi_hotkey), GFP_KERNEL);
782 memset(key, 0, sizeof(union acpi_hotkey));
784 union acpi_hotkey *tmp = NULL;
785 tmp = get_hotkey_by_event(&global_hotkey_list,
788 printk(KERN_ERR PREFIX "Invalid key\n");
790 memcpy(key, tmp, sizeof(union acpi_hotkey));
793 if (IS_EVENT(internal_event_num)) {
795 ret = init_hotkey_device(key, bus_handle, action_handle, method,
799 ret = init_poll_hotkey_device(key, bus_handle, bus_method,
800 action_handle, method,
804 kfree(action_handle);
805 if (IS_EVENT(internal_event_num))
806 free_hotkey_buffer(key);
808 free_poll_hotkey_buffer(key);
810 printk(KERN_ERR PREFIX "Invalid hotkey\n");
816 kfree(action_handle);
820 if (get_hotkey_by_event
821 (&global_hotkey_list, key->link.hotkey_standard_num))
830 if (hotkey_update(key))
839 if (IS_EVENT(internal_event_num))
840 free_hotkey_buffer(key);
842 free_poll_hotkey_buffer(key);
844 printk(KERN_ERR PREFIX "invalid key\n");
849 * This function evaluates an ACPI method, given an int as parameter, the
850 * method is searched within the scope of the handle, can be NULL. The output
851 * of the method is written is output, which can also be NULL
853 * returns 1 if write is successful, 0 else.
855 static int write_acpi_int(acpi_handle handle, const char *method, int val,
856 struct acpi_buffer *output)
858 struct acpi_object_list params; /* list of input parameters (an int here) */
859 union acpi_object in_obj; /* the only param we use */
863 params.pointer = &in_obj;
864 in_obj.type = ACPI_TYPE_INTEGER;
865 in_obj.integer.value = val;
867 status = acpi_evaluate_object(handle, (char *)method, ¶ms, output);
869 return (status == AE_OK);
872 static int read_acpi_int(acpi_handle handle, const char *method,
873 union acpi_object *val)
875 struct acpi_buffer output;
876 union acpi_object out_obj;
879 output.length = sizeof(out_obj);
880 output.pointer = &out_obj;
882 status = acpi_evaluate_object(handle, (char *)method, NULL, &output);
884 val->integer.value = out_obj.integer.value;
885 val->type = out_obj.type;
887 printk(KERN_ERR PREFIX "null val pointer\n");
888 return ((status == AE_OK)
889 && (out_obj.type == ACPI_TYPE_INTEGER));
892 static union acpi_hotkey *get_hotkey_by_event(struct
894 *hotkey_list, int event)
896 struct list_head *entries;
898 list_for_each(entries, hotkey_list->entries) {
899 union acpi_hotkey *key =
900 container_of(entries, union acpi_hotkey, entries);
901 if (key->link.hotkey_standard_num == event) {
909 * user call AML method interface:
911 * echo "event_num: arg type : value"
912 * example: echo "1:1:30" > /proc/acpi/action
913 * Just support 1 integer arg passing to AML method
916 static ssize_t hotkey_execute_aml_method(struct file *file,
917 const char __user * buffer,
918 size_t count, loff_t * data)
920 struct acpi_hotkey_list *hotkey_list = &global_hotkey_list;
922 int event, method_type, type, value;
923 union acpi_hotkey *key;
926 arg = (char *)kmalloc(count + 1, GFP_KERNEL);
931 if (copy_from_user(arg, buffer, count)) {
933 printk(KERN_ERR PREFIX "Invalid argument 2\n");
937 if (sscanf(arg, "%d:%d:%d:%d", &event, &method_type, &type, &value) !=
940 printk(KERN_ERR PREFIX "Invalid argument 3\n");
944 if (type == ACPI_TYPE_INTEGER) {
945 key = get_hotkey_by_event(hotkey_list, event);
949 write_acpi_int(key->event_hotkey.action_handle,
950 key->event_hotkey.action_method, value,
952 else if (IS_POLL(event)) {
953 if (method_type == POLL_METHOD)
954 read_acpi_int(key->poll_hotkey.poll_handle,
955 key->poll_hotkey.poll_method,
956 key->poll_hotkey.poll_result);
957 else if (method_type == ACTION_METHOD)
958 write_acpi_int(key->poll_hotkey.action_handle,
959 key->poll_hotkey.action_method,
966 printk(KERN_WARNING "Not supported\n");
975 static int __init hotkey_init(void)
978 mode_t mode = S_IFREG | S_IRUGO | S_IWUGO;
984 if (acpi_specific_hotkey_enabled) {
985 printk("Using specific hotkey driver\n");
989 hotkey_proc_dir = proc_mkdir(HOTKEY_PROC, acpi_root_dir);
990 if (!hotkey_proc_dir) {
993 hotkey_proc_dir->owner = THIS_MODULE;
996 create_proc_entry(HOTKEY_EV_CONFIG, mode, hotkey_proc_dir);
997 if (!hotkey_config) {
1000 hotkey_config->proc_fops = &hotkey_config_fops;
1001 hotkey_config->data = &global_hotkey_list;
1002 hotkey_config->owner = THIS_MODULE;
1003 hotkey_config->uid = 0;
1004 hotkey_config->gid = 0;
1007 hotkey_poll_config =
1008 create_proc_entry(HOTKEY_PL_CONFIG, mode, hotkey_proc_dir);
1009 if (!hotkey_poll_config) {
1012 hotkey_poll_config->proc_fops = &hotkey_poll_config_fops;
1013 hotkey_poll_config->data = &global_hotkey_list;
1014 hotkey_poll_config->owner = THIS_MODULE;
1015 hotkey_poll_config->uid = 0;
1016 hotkey_poll_config->gid = 0;
1019 hotkey_action = create_proc_entry(HOTKEY_ACTION, mode, hotkey_proc_dir);
1020 if (!hotkey_action) {
1023 hotkey_action->proc_fops = &hotkey_action_fops;
1024 hotkey_action->owner = THIS_MODULE;
1025 hotkey_action->uid = 0;
1026 hotkey_action->gid = 0;
1029 hotkey_info = create_proc_entry(HOTKEY_INFO, mode, hotkey_proc_dir);
1033 hotkey_info->proc_fops = &hotkey_info_fops;
1034 hotkey_info->owner = THIS_MODULE;
1035 hotkey_info->uid = 0;
1036 hotkey_info->gid = 0;
1039 result = acpi_bus_register_driver(&hotkey_driver);
1042 global_hotkey_list.count = 0;
1043 global_hotkey_list.entries = &hotkey_entries;
1045 INIT_LIST_HEAD(&hotkey_entries);
1050 remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir);
1052 remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir);
1054 remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir);
1056 remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir);
1058 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
1062 static void __exit hotkey_exit(void)
1064 struct list_head *entries, *next;
1067 list_for_each_safe(entries, next, global_hotkey_list.entries) {
1068 union acpi_hotkey *key =
1069 container_of(entries, union acpi_hotkey, entries);
1071 acpi_os_wait_events_complete(NULL);
1072 list_del(&key->link.entries);
1073 global_hotkey_list.count--;
1074 free_hotkey_device(key);
1076 acpi_bus_unregister_driver(&hotkey_driver);
1077 remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir);
1078 remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir);
1079 remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir);
1080 remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir);
1081 remove_proc_entry(HOTKEY_PROC, acpi_root_dir);
1085 module_init(hotkey_init);
1086 module_exit(hotkey_exit);