]>
Commit | Line | Data |
---|---|---|
79cda7d0 LY |
1 | /* |
2 | * hotkey.c - ACPI Hotkey Driver ($Revision: 0.2 $) | |
fb9802fa LY |
3 | * |
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 | ||
79cda7d0 | 54 | #define RESULT_STR_LEN 80 |
fb9802fa | 55 | |
79cda7d0 LY |
56 | #define ACTION_METHOD 0 |
57 | #define POLL_METHOD 1 | |
fb9802fa | 58 | |
79cda7d0 LY |
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) | |
fb9802fa LY |
62 | #define _COMPONENT ACPI_HOTKEY_COMPONENT |
63 | ACPI_MODULE_NAME("acpi_hotkey") | |
64 | ||
4be44fcd | 65 | MODULE_AUTHOR("luming.yu@intel.com"); |
fb9802fa LY |
66 | MODULE_DESCRIPTION(ACPI_HOTK_NAME); |
67 | MODULE_LICENSE("GPL"); | |
68 | ||
69 | /* standardized internal hotkey number/event */ | |
70 | enum { | |
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 | ||
5672bde6 H |
94 | enum conf_entry_enum { |
95 | bus_handle = 0, | |
96 | bus_method = 1, | |
97 | action_handle = 2, | |
98 | method = 3, | |
99 | LAST_CONF_ENTRY | |
100 | }; | |
101 | ||
fb9802fa LY |
102 | /* procdir we use */ |
103 | static struct proc_dir_entry *hotkey_proc_dir; | |
104 | static struct proc_dir_entry *hotkey_config; | |
105 | static struct proc_dir_entry *hotkey_poll_config; | |
106 | static struct proc_dir_entry *hotkey_action; | |
107 | static struct proc_dir_entry *hotkey_info; | |
108 | ||
109 | /* linkage for all type of hotkey */ | |
110 | struct acpi_hotkey_link { | |
111 | struct list_head entries; | |
112 | int hotkey_type; /* event or polling based hotkey */ | |
113 | int hotkey_standard_num; /* standardized hotkey(event) number */ | |
114 | }; | |
115 | ||
116 | /* event based hotkey */ | |
117 | struct acpi_event_hotkey { | |
118 | struct acpi_hotkey_link hotkey_link; | |
119 | int flag; | |
120 | acpi_handle bus_handle; /* bus to install notify handler */ | |
121 | int external_hotkey_num; /* external hotkey/event number */ | |
122 | acpi_handle action_handle; /* acpi handle attached aml action method */ | |
123 | char *action_method; /* action method */ | |
124 | }; | |
125 | ||
79cda7d0 | 126 | /* |
fb9802fa LY |
127 | * There are two ways to poll status |
128 | * 1. directy call read_xxx method, without any arguments passed in | |
129 | * 2. call write_xxx method, with arguments passed in, you need | |
130 | * the result is saved in acpi_polling_hotkey.poll_result. | |
131 | * anthoer read command through polling interface. | |
132 | * | |
133 | */ | |
134 | ||
135 | /* polling based hotkey */ | |
136 | struct acpi_polling_hotkey { | |
137 | struct acpi_hotkey_link hotkey_link; | |
138 | int flag; | |
139 | acpi_handle poll_handle; /* acpi handle attached polling method */ | |
140 | char *poll_method; /* poll method */ | |
141 | acpi_handle action_handle; /* acpi handle attached action method */ | |
142 | char *action_method; /* action method */ | |
79cda7d0 | 143 | union acpi_object *poll_result; /* polling_result */ |
fb9802fa LY |
144 | struct proc_dir_entry *proc; |
145 | }; | |
146 | ||
147 | /* hotkey object union */ | |
148 | union acpi_hotkey { | |
149 | struct list_head entries; | |
150 | struct acpi_hotkey_link link; | |
151 | struct acpi_event_hotkey event_hotkey; | |
152 | struct acpi_polling_hotkey poll_hotkey; | |
153 | }; | |
154 | ||
155 | /* hotkey object list */ | |
156 | struct acpi_hotkey_list { | |
157 | struct list_head *entries; | |
158 | int count; | |
159 | }; | |
160 | ||
161 | static int auto_hotkey_add(struct acpi_device *device); | |
162 | static int auto_hotkey_remove(struct acpi_device *device, int type); | |
163 | ||
164 | static struct acpi_driver hotkey_driver = { | |
165 | .name = ACPI_HOTK_NAME, | |
166 | .class = ACPI_HOTK_CLASS, | |
167 | .ids = ACPI_HOTK_HID, | |
168 | .ops = { | |
169 | .add = auto_hotkey_add, | |
170 | .remove = auto_hotkey_remove, | |
171 | }, | |
172 | }; | |
173 | ||
79cda7d0 LY |
174 | static void free_hotkey_device(union acpi_hotkey *key); |
175 | static void free_hotkey_buffer(union acpi_hotkey *key); | |
176 | static void free_poll_hotkey_buffer(union acpi_hotkey *key); | |
fb9802fa | 177 | static int hotkey_open_config(struct inode *inode, struct file *file); |
79cda7d0 | 178 | static int hotkey_poll_open_config(struct inode *inode, struct file *file); |
fb9802fa LY |
179 | static ssize_t hotkey_write_config(struct file *file, |
180 | const char __user * buffer, | |
181 | size_t count, loff_t * data); | |
fb9802fa LY |
182 | static int hotkey_info_open_fs(struct inode *inode, struct file *file); |
183 | static int hotkey_action_open_fs(struct inode *inode, struct file *file); | |
184 | static ssize_t hotkey_execute_aml_method(struct file *file, | |
185 | const char __user * buffer, | |
186 | size_t count, loff_t * data); | |
187 | static int hotkey_config_seq_show(struct seq_file *seq, void *offset); | |
79cda7d0 | 188 | static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset); |
fb9802fa | 189 | static int hotkey_polling_open_fs(struct inode *inode, struct file *file); |
79cda7d0 | 190 | static union acpi_hotkey *get_hotkey_by_event(struct |
4be44fcd LB |
191 | acpi_hotkey_list |
192 | *hotkey_list, int event); | |
fb9802fa LY |
193 | |
194 | /* event based config */ | |
d7508032 | 195 | static const struct file_operations hotkey_config_fops = { |
fb9802fa LY |
196 | .open = hotkey_open_config, |
197 | .read = seq_read, | |
198 | .write = hotkey_write_config, | |
199 | .llseek = seq_lseek, | |
200 | .release = single_release, | |
201 | }; | |
202 | ||
203 | /* polling based config */ | |
d7508032 | 204 | static const struct file_operations hotkey_poll_config_fops = { |
79cda7d0 | 205 | .open = hotkey_poll_open_config, |
fb9802fa | 206 | .read = seq_read, |
79cda7d0 | 207 | .write = hotkey_write_config, |
fb9802fa LY |
208 | .llseek = seq_lseek, |
209 | .release = single_release, | |
210 | }; | |
211 | ||
212 | /* hotkey driver info */ | |
d7508032 | 213 | static const struct file_operations hotkey_info_fops = { |
fb9802fa LY |
214 | .open = hotkey_info_open_fs, |
215 | .read = seq_read, | |
216 | .llseek = seq_lseek, | |
217 | .release = single_release, | |
218 | }; | |
219 | ||
220 | /* action */ | |
d7508032 | 221 | static const struct file_operations hotkey_action_fops = { |
fb9802fa LY |
222 | .open = hotkey_action_open_fs, |
223 | .read = seq_read, | |
224 | .write = hotkey_execute_aml_method, | |
225 | .llseek = seq_lseek, | |
226 | .release = single_release, | |
227 | }; | |
228 | ||
229 | /* polling results */ | |
d7508032 | 230 | static const struct file_operations hotkey_polling_fops = { |
fb9802fa LY |
231 | .open = hotkey_polling_open_fs, |
232 | .read = seq_read, | |
233 | .llseek = seq_lseek, | |
234 | .release = single_release, | |
235 | }; | |
236 | ||
237 | struct acpi_hotkey_list global_hotkey_list; /* link all ev or pl hotkey */ | |
238 | struct list_head hotkey_entries; /* head of the list of hotkey_list */ | |
239 | ||
240 | static int hotkey_info_seq_show(struct seq_file *seq, void *offset) | |
241 | { | |
fb9802fa | 242 | |
79cda7d0 | 243 | seq_printf(seq, "Hotkey generic driver ver: %s\n", HOTKEY_ACPI_VERSION); |
fb9802fa | 244 | |
d550d98d | 245 | return 0; |
fb9802fa LY |
246 | } |
247 | ||
248 | static int hotkey_info_open_fs(struct inode *inode, struct file *file) | |
249 | { | |
250 | return single_open(file, hotkey_info_seq_show, PDE(inode)->data); | |
251 | } | |
252 | ||
253 | static char *format_result(union acpi_object *object) | |
254 | { | |
5672bde6 | 255 | char *buf; |
fb9802fa | 256 | |
5672bde6 H |
257 | buf = kzalloc(RESULT_STR_LEN, GFP_KERNEL); |
258 | if (!buf) | |
259 | return NULL; | |
fb9802fa LY |
260 | /* Now, just support integer type */ |
261 | if (object->type == ACPI_TYPE_INTEGER) | |
79cda7d0 | 262 | sprintf(buf, "%d\n", (u32) object->integer.value); |
5672bde6 | 263 | return buf; |
fb9802fa LY |
264 | } |
265 | ||
266 | static int hotkey_polling_seq_show(struct seq_file *seq, void *offset) | |
267 | { | |
50dd0969 | 268 | struct acpi_polling_hotkey *poll_hotkey = seq->private; |
79cda7d0 | 269 | char *buf; |
fb9802fa | 270 | |
fb9802fa | 271 | |
4be44fcd | 272 | if (poll_hotkey->poll_result) { |
79cda7d0 | 273 | buf = format_result(poll_hotkey->poll_result); |
4be44fcd | 274 | if (buf) |
79cda7d0 LY |
275 | seq_printf(seq, "%s", buf); |
276 | kfree(buf); | |
277 | } | |
d550d98d | 278 | return 0; |
fb9802fa LY |
279 | } |
280 | ||
281 | static int hotkey_polling_open_fs(struct inode *inode, struct file *file) | |
282 | { | |
283 | return single_open(file, hotkey_polling_seq_show, PDE(inode)->data); | |
284 | } | |
285 | ||
286 | static int hotkey_action_open_fs(struct inode *inode, struct file *file) | |
287 | { | |
288 | return single_open(file, hotkey_info_seq_show, PDE(inode)->data); | |
289 | } | |
290 | ||
291 | /* Mapping external hotkey number to standardized hotkey event num */ | |
292 | static int hotkey_get_internal_event(int event, struct acpi_hotkey_list *list) | |
293 | { | |
79cda7d0 LY |
294 | struct list_head *entries; |
295 | int val = -1; | |
fb9802fa | 296 | |
fb9802fa | 297 | |
79cda7d0 | 298 | list_for_each(entries, list->entries) { |
fb9802fa LY |
299 | union acpi_hotkey *key = |
300 | container_of(entries, union acpi_hotkey, entries); | |
301 | if (key->link.hotkey_type == ACPI_HOTKEY_EVENT | |
4be44fcd | 302 | && key->event_hotkey.external_hotkey_num == event) { |
fb9802fa | 303 | val = key->link.hotkey_standard_num; |
79cda7d0 LY |
304 | break; |
305 | } | |
fb9802fa LY |
306 | } |
307 | ||
d550d98d | 308 | return val; |
fb9802fa LY |
309 | } |
310 | ||
311 | static void | |
312 | acpi_hotkey_notify_handler(acpi_handle handle, u32 event, void *data) | |
313 | { | |
314 | struct acpi_device *device = NULL; | |
315 | u32 internal_event; | |
316 | ||
fb9802fa LY |
317 | |
318 | if (acpi_bus_get_device(handle, &device)) | |
d550d98d | 319 | return; |
fb9802fa LY |
320 | |
321 | internal_event = hotkey_get_internal_event(event, &global_hotkey_list); | |
79cda7d0 | 322 | acpi_bus_generate_event(device, internal_event, 0); |
fb9802fa | 323 | |
d550d98d | 324 | return; |
fb9802fa LY |
325 | } |
326 | ||
327 | /* Need to invent automatically hotkey add method */ | |
328 | static int auto_hotkey_add(struct acpi_device *device) | |
329 | { | |
330 | /* Implement me */ | |
331 | return 0; | |
332 | } | |
333 | ||
334 | /* Need to invent automatically hotkey remove method */ | |
335 | static int auto_hotkey_remove(struct acpi_device *device, int type) | |
336 | { | |
337 | /* Implement me */ | |
338 | return 0; | |
339 | } | |
340 | ||
341 | /* Create a proc file for each polling method */ | |
342 | static int create_polling_proc(union acpi_hotkey *device) | |
343 | { | |
344 | struct proc_dir_entry *proc; | |
4be44fcd | 345 | char proc_name[80]; |
8de7a63b | 346 | mode_t mode; |
fb9802fa | 347 | |
8de7a63b | 348 | mode = S_IFREG | S_IRUGO | S_IWUGO; |
fb9802fa | 349 | |
79cda7d0 LY |
350 | sprintf(proc_name, "%d", device->link.hotkey_standard_num); |
351 | /* | |
4be44fcd LB |
352 | strcat(proc_name, device->poll_hotkey.poll_method); |
353 | */ | |
79cda7d0 | 354 | proc = create_proc_entry(proc_name, mode, hotkey_proc_dir); |
fb9802fa LY |
355 | |
356 | if (!proc) { | |
d550d98d | 357 | return -ENODEV; |
fb9802fa LY |
358 | } else { |
359 | proc->proc_fops = &hotkey_polling_fops; | |
360 | proc->owner = THIS_MODULE; | |
361 | proc->data = device; | |
362 | proc->uid = 0; | |
363 | proc->gid = 0; | |
364 | device->poll_hotkey.proc = proc; | |
365 | } | |
d550d98d | 366 | return 0; |
fb9802fa LY |
367 | } |
368 | ||
fb9802fa LY |
369 | static int hotkey_add(union acpi_hotkey *device) |
370 | { | |
371 | int status = 0; | |
372 | struct acpi_device *dev = NULL; | |
373 | ||
fb9802fa LY |
374 | |
375 | if (device->link.hotkey_type == ACPI_HOTKEY_EVENT) { | |
79cda7d0 | 376 | acpi_bus_get_device(device->event_hotkey.bus_handle, &dev); |
fb9802fa | 377 | status = acpi_install_notify_handler(dev->handle, |
79cda7d0 | 378 | ACPI_DEVICE_NOTIFY, |
fb9802fa | 379 | acpi_hotkey_notify_handler, |
79cda7d0 | 380 | dev); |
fb9802fa LY |
381 | } else /* Add polling hotkey */ |
382 | create_polling_proc(device); | |
383 | ||
384 | global_hotkey_list.count++; | |
385 | ||
386 | list_add_tail(&device->link.entries, global_hotkey_list.entries); | |
387 | ||
d550d98d | 388 | return status; |
fb9802fa LY |
389 | } |
390 | ||
391 | static int hotkey_remove(union acpi_hotkey *device) | |
392 | { | |
393 | struct list_head *entries, *next; | |
394 | ||
fb9802fa LY |
395 | |
396 | list_for_each_safe(entries, next, global_hotkey_list.entries) { | |
397 | union acpi_hotkey *key = | |
398 | container_of(entries, union acpi_hotkey, entries); | |
399 | if (key->link.hotkey_standard_num == | |
400 | device->link.hotkey_standard_num) { | |
401 | list_del(&key->link.entries); | |
79cda7d0 | 402 | free_hotkey_device(key); |
fb9802fa LY |
403 | global_hotkey_list.count--; |
404 | break; | |
405 | } | |
406 | } | |
79cda7d0 | 407 | kfree(device); |
d550d98d | 408 | return 0; |
fb9802fa LY |
409 | } |
410 | ||
4be44fcd | 411 | static int hotkey_update(union acpi_hotkey *key) |
fb9802fa | 412 | { |
79cda7d0 | 413 | struct list_head *entries; |
fb9802fa | 414 | |
fb9802fa | 415 | |
79cda7d0 | 416 | list_for_each(entries, global_hotkey_list.entries) { |
4be44fcd | 417 | union acpi_hotkey *tmp = |
fb9802fa | 418 | container_of(entries, union acpi_hotkey, entries); |
79cda7d0 | 419 | if (tmp->link.hotkey_standard_num == |
fb9802fa | 420 | key->link.hotkey_standard_num) { |
79cda7d0 LY |
421 | if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) { |
422 | free_hotkey_buffer(tmp); | |
423 | tmp->event_hotkey.bus_handle = | |
4be44fcd | 424 | key->event_hotkey.bus_handle; |
79cda7d0 | 425 | tmp->event_hotkey.external_hotkey_num = |
4be44fcd | 426 | key->event_hotkey.external_hotkey_num; |
79cda7d0 | 427 | tmp->event_hotkey.action_handle = |
4be44fcd | 428 | key->event_hotkey.action_handle; |
79cda7d0 | 429 | tmp->event_hotkey.action_method = |
4be44fcd | 430 | key->event_hotkey.action_method; |
79cda7d0 LY |
431 | kfree(key); |
432 | } else { | |
433 | /* | |
4be44fcd | 434 | char proc_name[80]; |
79cda7d0 | 435 | |
4be44fcd LB |
436 | sprintf(proc_name, "%d", tmp->link.hotkey_standard_num); |
437 | strcat(proc_name, tmp->poll_hotkey.poll_method); | |
438 | remove_proc_entry(proc_name,hotkey_proc_dir); | |
439 | */ | |
79cda7d0 LY |
440 | free_poll_hotkey_buffer(tmp); |
441 | tmp->poll_hotkey.poll_handle = | |
4be44fcd | 442 | key->poll_hotkey.poll_handle; |
79cda7d0 | 443 | tmp->poll_hotkey.poll_method = |
4be44fcd | 444 | key->poll_hotkey.poll_method; |
79cda7d0 | 445 | tmp->poll_hotkey.action_handle = |
4be44fcd | 446 | key->poll_hotkey.action_handle; |
79cda7d0 | 447 | tmp->poll_hotkey.action_method = |
4be44fcd | 448 | key->poll_hotkey.action_method; |
79cda7d0 | 449 | tmp->poll_hotkey.poll_result = |
4be44fcd | 450 | key->poll_hotkey.poll_result; |
79cda7d0 | 451 | /* |
4be44fcd LB |
452 | create_polling_proc(tmp); |
453 | */ | |
79cda7d0 LY |
454 | kfree(key); |
455 | } | |
d550d98d | 456 | return 0; |
fb9802fa LY |
457 | break; |
458 | } | |
459 | } | |
460 | ||
d550d98d | 461 | return -ENODEV; |
fb9802fa LY |
462 | } |
463 | ||
464 | static void free_hotkey_device(union acpi_hotkey *key) | |
465 | { | |
466 | struct acpi_device *dev; | |
fb9802fa | 467 | |
fb9802fa LY |
468 | |
469 | if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) { | |
79cda7d0 | 470 | acpi_bus_get_device(key->event_hotkey.bus_handle, &dev); |
fb9802fa LY |
471 | if (dev->handle) |
472 | acpi_remove_notify_handler(dev->handle, | |
79cda7d0 | 473 | ACPI_DEVICE_NOTIFY, |
fb9802fa | 474 | acpi_hotkey_notify_handler); |
79cda7d0 LY |
475 | free_hotkey_buffer(key); |
476 | } else { | |
4be44fcd | 477 | char proc_name[80]; |
79cda7d0 LY |
478 | |
479 | sprintf(proc_name, "%d", key->link.hotkey_standard_num); | |
480 | /* | |
4be44fcd LB |
481 | strcat(proc_name, key->poll_hotkey.poll_method); |
482 | */ | |
483 | remove_proc_entry(proc_name, hotkey_proc_dir); | |
79cda7d0 LY |
484 | free_poll_hotkey_buffer(key); |
485 | } | |
fb9802fa | 486 | kfree(key); |
d550d98d | 487 | return; |
fb9802fa LY |
488 | } |
489 | ||
4be44fcd | 490 | static void free_hotkey_buffer(union acpi_hotkey *key) |
79cda7d0 | 491 | { |
5672bde6 | 492 | /* key would never be null, action method could be */ |
79cda7d0 LY |
493 | kfree(key->event_hotkey.action_method); |
494 | } | |
495 | ||
4be44fcd | 496 | static void free_poll_hotkey_buffer(union acpi_hotkey *key) |
79cda7d0 | 497 | { |
5672bde6 | 498 | /* key would never be null, others could be*/ |
79cda7d0 LY |
499 | kfree(key->poll_hotkey.action_method); |
500 | kfree(key->poll_hotkey.poll_method); | |
501 | kfree(key->poll_hotkey.poll_result); | |
502 | } | |
fb9802fa | 503 | static int |
5672bde6 H |
504 | init_hotkey_device(union acpi_hotkey *key, char **config_entry, |
505 | int std_num, int external_num) | |
fb9802fa | 506 | { |
4be44fcd | 507 | acpi_handle tmp_handle; |
79cda7d0 LY |
508 | acpi_status status = AE_OK; |
509 | ||
4be44fcd | 510 | if (std_num < 0 || IS_POLL(std_num) || !key) |
79cda7d0 LY |
511 | goto do_fail; |
512 | ||
5672bde6 H |
513 | if (!config_entry[bus_handle] || !config_entry[action_handle] |
514 | || !config_entry[method]) | |
79cda7d0 LY |
515 | goto do_fail; |
516 | ||
fb9802fa LY |
517 | key->link.hotkey_type = ACPI_HOTKEY_EVENT; |
518 | key->link.hotkey_standard_num = std_num; | |
519 | key->event_hotkey.flag = 0; | |
5672bde6 | 520 | key->event_hotkey.action_method = config_entry[method]; |
fb9802fa | 521 | |
5672bde6 H |
522 | status = acpi_get_handle(NULL, config_entry[bus_handle], |
523 | &(key->event_hotkey.bus_handle)); | |
4be44fcd | 524 | if (ACPI_FAILURE(status)) |
5672bde6 | 525 | goto do_fail_zero; |
79cda7d0 | 526 | key->event_hotkey.external_hotkey_num = external_num; |
5672bde6 | 527 | status = acpi_get_handle(NULL, config_entry[action_handle], |
4be44fcd LB |
528 | &(key->event_hotkey.action_handle)); |
529 | if (ACPI_FAILURE(status)) | |
5672bde6 | 530 | goto do_fail_zero; |
79cda7d0 | 531 | status = acpi_get_handle(key->event_hotkey.action_handle, |
5672bde6 | 532 | config_entry[method], &tmp_handle); |
79cda7d0 | 533 | if (ACPI_FAILURE(status)) |
5672bde6 | 534 | goto do_fail_zero; |
d550d98d | 535 | return AE_OK; |
5672bde6 H |
536 | do_fail_zero: |
537 | key->event_hotkey.action_method = NULL; | |
538 | do_fail: | |
d550d98d | 539 | return -ENODEV; |
fb9802fa LY |
540 | } |
541 | ||
542 | static int | |
5672bde6 H |
543 | init_poll_hotkey_device(union acpi_hotkey *key, char **config_entry, |
544 | int std_num) | |
fb9802fa | 545 | { |
79cda7d0 | 546 | acpi_status status = AE_OK; |
4be44fcd | 547 | acpi_handle tmp_handle; |
79cda7d0 | 548 | |
4be44fcd | 549 | if (std_num < 0 || IS_EVENT(std_num) || !key) |
79cda7d0 | 550 | goto do_fail; |
5672bde6 H |
551 | if (!config_entry[bus_handle] ||!config_entry[bus_method] || |
552 | !config_entry[action_handle] || !config_entry[method]) | |
79cda7d0 LY |
553 | goto do_fail; |
554 | ||
fb9802fa LY |
555 | key->link.hotkey_type = ACPI_HOTKEY_POLLING; |
556 | key->link.hotkey_standard_num = std_num; | |
557 | key->poll_hotkey.flag = 0; | |
5672bde6 H |
558 | key->poll_hotkey.poll_method = config_entry[bus_method]; |
559 | key->poll_hotkey.action_method = config_entry[method]; | |
79cda7d0 | 560 | |
5672bde6 H |
561 | status = acpi_get_handle(NULL, config_entry[bus_handle], |
562 | &(key->poll_hotkey.poll_handle)); | |
4be44fcd | 563 | if (ACPI_FAILURE(status)) |
5672bde6 | 564 | goto do_fail_zero; |
79cda7d0 | 565 | status = acpi_get_handle(key->poll_hotkey.poll_handle, |
5672bde6 | 566 | config_entry[bus_method], &tmp_handle); |
4be44fcd | 567 | if (ACPI_FAILURE(status)) |
5672bde6 | 568 | goto do_fail_zero; |
4be44fcd | 569 | status = |
5672bde6 | 570 | acpi_get_handle(NULL, config_entry[action_handle], |
4be44fcd | 571 | &(key->poll_hotkey.action_handle)); |
79cda7d0 | 572 | if (ACPI_FAILURE(status)) |
5672bde6 | 573 | goto do_fail_zero; |
79cda7d0 | 574 | status = acpi_get_handle(key->poll_hotkey.action_handle, |
5672bde6 | 575 | config_entry[method], &tmp_handle); |
79cda7d0 | 576 | if (ACPI_FAILURE(status)) |
5672bde6 | 577 | goto do_fail_zero; |
fb9802fa | 578 | key->poll_hotkey.poll_result = |
50dd0969 | 579 | kmalloc(sizeof(union acpi_object), GFP_KERNEL); |
4be44fcd | 580 | if (!key->poll_hotkey.poll_result) |
5672bde6 | 581 | goto do_fail_zero; |
d550d98d | 582 | return AE_OK; |
5672bde6 H |
583 | |
584 | do_fail_zero: | |
585 | key->poll_hotkey.poll_method = NULL; | |
586 | key->poll_hotkey.action_method = NULL; | |
587 | do_fail: | |
d550d98d | 588 | return -ENODEV; |
fb9802fa LY |
589 | } |
590 | ||
fb9802fa LY |
591 | static int hotkey_open_config(struct inode *inode, struct file *file) |
592 | { | |
d550d98d | 593 | return (single_open |
fb9802fa LY |
594 | (file, hotkey_config_seq_show, PDE(inode)->data)); |
595 | } | |
596 | ||
79cda7d0 LY |
597 | static int hotkey_poll_open_config(struct inode *inode, struct file *file) |
598 | { | |
d550d98d | 599 | return (single_open |
79cda7d0 LY |
600 | (file, hotkey_poll_config_seq_show, PDE(inode)->data)); |
601 | } | |
602 | ||
fb9802fa LY |
603 | static int hotkey_config_seq_show(struct seq_file *seq, void *offset) |
604 | { | |
605 | struct acpi_hotkey_list *hotkey_list = &global_hotkey_list; | |
79cda7d0 | 606 | struct list_head *entries; |
fb9802fa LY |
607 | char bus_name[ACPI_PATHNAME_MAX] = { 0 }; |
608 | char action_name[ACPI_PATHNAME_MAX] = { 0 }; | |
609 | struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name }; | |
610 | struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name }; | |
611 | ||
fb9802fa | 612 | |
79cda7d0 | 613 | list_for_each(entries, hotkey_list->entries) { |
fb9802fa LY |
614 | union acpi_hotkey *key = |
615 | container_of(entries, union acpi_hotkey, entries); | |
616 | if (key->link.hotkey_type == ACPI_HOTKEY_EVENT) { | |
617 | acpi_get_name(key->event_hotkey.bus_handle, | |
618 | ACPI_NAME_TYPE_MAX, &bus); | |
619 | acpi_get_name(key->event_hotkey.action_handle, | |
620 | ACPI_NAME_TYPE_MAX, &act); | |
79cda7d0 | 621 | seq_printf(seq, "%s:%s:%s:%d:%d\n", bus_name, |
fb9802fa LY |
622 | action_name, |
623 | key->event_hotkey.action_method, | |
624 | key->link.hotkey_standard_num, | |
625 | key->event_hotkey.external_hotkey_num); | |
79cda7d0 LY |
626 | } |
627 | } | |
628 | seq_puts(seq, "\n"); | |
d550d98d | 629 | return 0; |
79cda7d0 LY |
630 | } |
631 | ||
632 | static int hotkey_poll_config_seq_show(struct seq_file *seq, void *offset) | |
633 | { | |
634 | struct acpi_hotkey_list *hotkey_list = &global_hotkey_list; | |
635 | struct list_head *entries; | |
636 | char bus_name[ACPI_PATHNAME_MAX] = { 0 }; | |
637 | char action_name[ACPI_PATHNAME_MAX] = { 0 }; | |
638 | struct acpi_buffer bus = { ACPI_PATHNAME_MAX, bus_name }; | |
639 | struct acpi_buffer act = { ACPI_PATHNAME_MAX, action_name }; | |
640 | ||
79cda7d0 LY |
641 | |
642 | list_for_each(entries, hotkey_list->entries) { | |
643 | union acpi_hotkey *key = | |
644 | container_of(entries, union acpi_hotkey, entries); | |
645 | if (key->link.hotkey_type == ACPI_HOTKEY_POLLING) { | |
fb9802fa LY |
646 | acpi_get_name(key->poll_hotkey.poll_handle, |
647 | ACPI_NAME_TYPE_MAX, &bus); | |
648 | acpi_get_name(key->poll_hotkey.action_handle, | |
649 | ACPI_NAME_TYPE_MAX, &act); | |
79cda7d0 | 650 | seq_printf(seq, "%s:%s:%s:%s:%d\n", bus_name, |
fb9802fa LY |
651 | key->poll_hotkey.poll_method, |
652 | action_name, | |
653 | key->poll_hotkey.action_method, | |
654 | key->link.hotkey_standard_num); | |
655 | } | |
656 | } | |
657 | seq_puts(seq, "\n"); | |
d550d98d | 658 | return 0; |
fb9802fa LY |
659 | } |
660 | ||
661 | static int | |
5672bde6 H |
662 | get_parms(char *config_record, int *cmd, char **config_entry, |
663 | int *internal_event_num, int *external_event_num) | |
fb9802fa | 664 | { |
5672bde6 H |
665 | /* the format of *config_record = |
666 | * "1:\d+:*" : "cmd:internal_event_num" | |
667 | * "\d+:\w+:\w+:\w+:\w+:\d+:\d+" : | |
668 | * "cmd:bus_handle:bus_method:action_handle:method:internal_event_num:external_event_num" | |
669 | */ | |
79cda7d0 | 670 | char *tmp, *tmp1, count; |
5672bde6 | 671 | int i; |
fb9802fa LY |
672 | |
673 | sscanf(config_record, "%d", cmd); | |
4be44fcd LB |
674 | if (*cmd == 1) { |
675 | if (sscanf(config_record, "%d:%d", cmd, internal_event_num) != | |
676 | 2) | |
79cda7d0 LY |
677 | goto do_fail; |
678 | else | |
679 | return (6); | |
680 | } | |
fb9802fa | 681 | tmp = strchr(config_record, ':'); |
79cda7d0 LY |
682 | if (!tmp) |
683 | goto do_fail; | |
fb9802fa | 684 | tmp++; |
5672bde6 H |
685 | for (i = 0; i < LAST_CONF_ENTRY; i++) { |
686 | tmp1 = strchr(tmp, ':'); | |
687 | if (!tmp1) { | |
688 | goto do_fail; | |
689 | } | |
690 | count = tmp1 - tmp; | |
691 | config_entry[i] = kzalloc(count + 1, GFP_KERNEL); | |
692 | if (!config_entry[i]) | |
693 | goto handle_failure; | |
694 | strncpy(config_entry[i], tmp, count); | |
695 | tmp = tmp1 + 1; | |
696 | } | |
697 | if (sscanf(tmp, "%d:%d", internal_event_num, external_event_num) <= 0) | |
698 | goto handle_failure; | |
699 | if (!IS_OTHERS(*internal_event_num)) { | |
700 | return 6; | |
701 | } | |
702 | handle_failure: | |
703 | while (i-- > 0) | |
704 | kfree(config_entry[i]); | |
705 | do_fail: | |
d550d98d | 706 | return -1; |
fb9802fa LY |
707 | } |
708 | ||
709 | /* count is length for one input record */ | |
710 | static ssize_t hotkey_write_config(struct file *file, | |
711 | const char __user * buffer, | |
712 | size_t count, loff_t * data) | |
713 | { | |
79cda7d0 | 714 | char *config_record = NULL; |
5672bde6 | 715 | char *config_entry[LAST_CONF_ENTRY]; |
fb9802fa LY |
716 | int cmd, internal_event_num, external_event_num; |
717 | int ret = 0; | |
5672bde6 | 718 | union acpi_hotkey *key = kzalloc(sizeof(union acpi_hotkey), GFP_KERNEL); |
fb9802fa | 719 | |
5672bde6 H |
720 | if (!key) |
721 | return -ENOMEM; | |
fb9802fa | 722 | |
5672bde6 H |
723 | config_record = kzalloc(count + 1, GFP_KERNEL); |
724 | if (!config_record) { | |
725 | kfree(key); | |
d550d98d | 726 | return -ENOMEM; |
5672bde6 | 727 | } |
fb9802fa LY |
728 | |
729 | if (copy_from_user(config_record, buffer, count)) { | |
79cda7d0 | 730 | kfree(config_record); |
5672bde6 | 731 | kfree(key); |
6468463a | 732 | printk(KERN_ERR PREFIX "Invalid data\n"); |
d550d98d | 733 | return -EINVAL; |
fb9802fa | 734 | } |
5672bde6 H |
735 | ret = get_parms(config_record, &cmd, config_entry, |
736 | &internal_event_num, &external_event_num); | |
79cda7d0 | 737 | kfree(config_record); |
fb9802fa | 738 | if (ret != 6) { |
6468463a | 739 | printk(KERN_ERR PREFIX "Invalid data format ret=%d\n", ret); |
d550d98d | 740 | return -EINVAL; |
fb9802fa LY |
741 | } |
742 | ||
4be44fcd | 743 | if (cmd == 1) { |
79cda7d0 LY |
744 | union acpi_hotkey *tmp = NULL; |
745 | tmp = get_hotkey_by_event(&global_hotkey_list, | |
4be44fcd LB |
746 | internal_event_num); |
747 | if (!tmp) | |
6468463a | 748 | printk(KERN_ERR PREFIX "Invalid key\n"); |
79cda7d0 LY |
749 | else |
750 | memcpy(key, tmp, sizeof(union acpi_hotkey)); | |
751 | goto cont_cmd; | |
752 | } | |
753 | if (IS_EVENT(internal_event_num)) { | |
5672bde6 H |
754 | if (init_hotkey_device(key, config_entry, |
755 | internal_event_num, external_event_num)) | |
756 | goto init_hotkey_fail; | |
757 | } else { | |
758 | if (init_poll_hotkey_device(key, config_entry, | |
759 | internal_event_num)) | |
760 | goto init_poll_hotkey_fail; | |
fb9802fa | 761 | } |
5672bde6 | 762 | cont_cmd: |
fb9802fa LY |
763 | switch (cmd) { |
764 | case 0: | |
5672bde6 H |
765 | if (get_hotkey_by_event(&global_hotkey_list, |
766 | key->link.hotkey_standard_num)) | |
79cda7d0 LY |
767 | goto fail_out; |
768 | else | |
769 | hotkey_add(key); | |
fb9802fa LY |
770 | break; |
771 | case 1: | |
772 | hotkey_remove(key); | |
773 | break; | |
774 | case 2: | |
5672bde6 | 775 | /* key is kfree()ed if matched*/ |
4be44fcd | 776 | if (hotkey_update(key)) |
79cda7d0 | 777 | goto fail_out; |
fb9802fa LY |
778 | break; |
779 | default: | |
79cda7d0 | 780 | goto fail_out; |
fb9802fa LY |
781 | break; |
782 | } | |
d550d98d | 783 | return count; |
5672bde6 H |
784 | |
785 | init_poll_hotkey_fail: /* failed init_poll_hotkey_device */ | |
786 | kfree(config_entry[bus_method]); | |
787 | config_entry[bus_method] = NULL; | |
788 | init_hotkey_fail: /* failed init_hotkey_device */ | |
789 | kfree(config_entry[method]); | |
790 | fail_out: | |
791 | kfree(config_entry[bus_handle]); | |
792 | kfree(config_entry[action_handle]); | |
793 | /* No double free since elements =NULL for error cases */ | |
794 | if (IS_EVENT(internal_event_num)) { | |
795 | if (config_entry[bus_method]) | |
796 | kfree(config_entry[bus_method]); | |
797 | free_hotkey_buffer(key); /* frees [method] */ | |
798 | } else | |
799 | free_poll_hotkey_buffer(key); /* frees [bus_method]+[method] */ | |
79cda7d0 | 800 | kfree(key); |
6468463a | 801 | printk(KERN_ERR PREFIX "invalid key\n"); |
d550d98d | 802 | return -EINVAL; |
fb9802fa LY |
803 | } |
804 | ||
79cda7d0 | 805 | /* |
fb9802fa LY |
806 | * This function evaluates an ACPI method, given an int as parameter, the |
807 | * method is searched within the scope of the handle, can be NULL. The output | |
808 | * of the method is written is output, which can also be NULL | |
809 | * | |
810 | * returns 1 if write is successful, 0 else. | |
811 | */ | |
812 | static int write_acpi_int(acpi_handle handle, const char *method, int val, | |
813 | struct acpi_buffer *output) | |
814 | { | |
815 | struct acpi_object_list params; /* list of input parameters (an int here) */ | |
816 | union acpi_object in_obj; /* the only param we use */ | |
817 | acpi_status status; | |
818 | ||
fb9802fa LY |
819 | params.count = 1; |
820 | params.pointer = &in_obj; | |
821 | in_obj.type = ACPI_TYPE_INTEGER; | |
822 | in_obj.integer.value = val; | |
823 | ||
824 | status = acpi_evaluate_object(handle, (char *)method, ¶ms, output); | |
825 | ||
d550d98d | 826 | return (status == AE_OK); |
fb9802fa LY |
827 | } |
828 | ||
4be44fcd LB |
829 | static int read_acpi_int(acpi_handle handle, const char *method, |
830 | union acpi_object *val) | |
fb9802fa LY |
831 | { |
832 | struct acpi_buffer output; | |
833 | union acpi_object out_obj; | |
834 | acpi_status status; | |
835 | ||
fb9802fa LY |
836 | output.length = sizeof(out_obj); |
837 | output.pointer = &out_obj; | |
838 | ||
839 | status = acpi_evaluate_object(handle, (char *)method, NULL, &output); | |
4be44fcd | 840 | if (val) { |
79cda7d0 LY |
841 | val->integer.value = out_obj.integer.value; |
842 | val->type = out_obj.type; | |
843 | } else | |
6468463a | 844 | printk(KERN_ERR PREFIX "null val pointer\n"); |
d550d98d | 845 | return ((status == AE_OK) |
fb9802fa LY |
846 | && (out_obj.type == ACPI_TYPE_INTEGER)); |
847 | } | |
848 | ||
79cda7d0 | 849 | static union acpi_hotkey *get_hotkey_by_event(struct |
4be44fcd LB |
850 | acpi_hotkey_list |
851 | *hotkey_list, int event) | |
fb9802fa | 852 | { |
79cda7d0 | 853 | struct list_head *entries; |
fb9802fa | 854 | |
79cda7d0 | 855 | list_for_each(entries, hotkey_list->entries) { |
fb9802fa LY |
856 | union acpi_hotkey *key = |
857 | container_of(entries, union acpi_hotkey, entries); | |
79cda7d0 | 858 | if (key->link.hotkey_standard_num == event) { |
4be44fcd | 859 | return (key); |
fb9802fa LY |
860 | } |
861 | } | |
4be44fcd | 862 | return (NULL); |
fb9802fa LY |
863 | } |
864 | ||
79cda7d0 | 865 | /* |
fb9802fa LY |
866 | * user call AML method interface: |
867 | * Call convention: | |
868 | * echo "event_num: arg type : value" | |
869 | * example: echo "1:1:30" > /proc/acpi/action | |
870 | * Just support 1 integer arg passing to AML method | |
871 | */ | |
872 | ||
873 | static ssize_t hotkey_execute_aml_method(struct file *file, | |
874 | const char __user * buffer, | |
875 | size_t count, loff_t * data) | |
876 | { | |
877 | struct acpi_hotkey_list *hotkey_list = &global_hotkey_list; | |
79cda7d0 | 878 | char *arg; |
4be44fcd | 879 | int event, method_type, type, value; |
79cda7d0 | 880 | union acpi_hotkey *key; |
fb9802fa | 881 | |
fb9802fa | 882 | |
5672bde6 | 883 | arg = kzalloc(count + 1, GFP_KERNEL); |
4be44fcd | 884 | if (!arg) |
d550d98d | 885 | return -ENOMEM; |
fb9802fa LY |
886 | |
887 | if (copy_from_user(arg, buffer, count)) { | |
79cda7d0 | 888 | kfree(arg); |
6468463a | 889 | printk(KERN_ERR PREFIX "Invalid argument 2\n"); |
d550d98d | 890 | return -EINVAL; |
fb9802fa LY |
891 | } |
892 | ||
4be44fcd LB |
893 | if (sscanf(arg, "%d:%d:%d:%d", &event, &method_type, &type, &value) != |
894 | 4) { | |
79cda7d0 | 895 | kfree(arg); |
6468463a | 896 | printk(KERN_ERR PREFIX "Invalid argument 3\n"); |
d550d98d | 897 | return -EINVAL; |
fb9802fa | 898 | } |
79cda7d0 | 899 | kfree(arg); |
fb9802fa | 900 | if (type == ACPI_TYPE_INTEGER) { |
79cda7d0 | 901 | key = get_hotkey_by_event(hotkey_list, event); |
4be44fcd | 902 | if (!key) |
79cda7d0 | 903 | goto do_fail; |
fb9802fa | 904 | if (IS_EVENT(event)) |
79cda7d0 | 905 | write_acpi_int(key->event_hotkey.action_handle, |
4be44fcd LB |
906 | key->event_hotkey.action_method, value, |
907 | NULL); | |
fb9802fa | 908 | else if (IS_POLL(event)) { |
4be44fcd | 909 | if (method_type == POLL_METHOD) |
79cda7d0 | 910 | read_acpi_int(key->poll_hotkey.poll_handle, |
4be44fcd LB |
911 | key->poll_hotkey.poll_method, |
912 | key->poll_hotkey.poll_result); | |
913 | else if (method_type == ACTION_METHOD) | |
79cda7d0 | 914 | write_acpi_int(key->poll_hotkey.action_handle, |
4be44fcd LB |
915 | key->poll_hotkey.action_method, |
916 | value, NULL); | |
79cda7d0 LY |
917 | else |
918 | goto do_fail; | |
919 | ||
fb9802fa LY |
920 | } |
921 | } else { | |
cece9296 | 922 | printk(KERN_WARNING "Not supported\n"); |
d550d98d | 923 | return -EINVAL; |
fb9802fa | 924 | } |
d550d98d | 925 | return count; |
4be44fcd | 926 | do_fail: |
d550d98d | 927 | return -EINVAL; |
79cda7d0 | 928 | |
fb9802fa LY |
929 | } |
930 | ||
931 | static int __init hotkey_init(void) | |
932 | { | |
933 | int result; | |
934 | mode_t mode = S_IFREG | S_IRUGO | S_IWUGO; | |
935 | ||
fb9802fa LY |
936 | |
937 | if (acpi_disabled) | |
938 | return -ENODEV; | |
939 | ||
940 | if (acpi_specific_hotkey_enabled) { | |
941 | printk("Using specific hotkey driver\n"); | |
942 | return -ENODEV; | |
943 | } | |
944 | ||
945 | hotkey_proc_dir = proc_mkdir(HOTKEY_PROC, acpi_root_dir); | |
946 | if (!hotkey_proc_dir) { | |
fb9802fa LY |
947 | return (-ENODEV); |
948 | } | |
949 | hotkey_proc_dir->owner = THIS_MODULE; | |
950 | ||
951 | hotkey_config = | |
952 | create_proc_entry(HOTKEY_EV_CONFIG, mode, hotkey_proc_dir); | |
953 | if (!hotkey_config) { | |
79cda7d0 | 954 | goto do_fail1; |
fb9802fa LY |
955 | } else { |
956 | hotkey_config->proc_fops = &hotkey_config_fops; | |
957 | hotkey_config->data = &global_hotkey_list; | |
958 | hotkey_config->owner = THIS_MODULE; | |
959 | hotkey_config->uid = 0; | |
960 | hotkey_config->gid = 0; | |
961 | } | |
962 | ||
963 | hotkey_poll_config = | |
964 | create_proc_entry(HOTKEY_PL_CONFIG, mode, hotkey_proc_dir); | |
965 | if (!hotkey_poll_config) { | |
79cda7d0 | 966 | goto do_fail2; |
fb9802fa LY |
967 | } else { |
968 | hotkey_poll_config->proc_fops = &hotkey_poll_config_fops; | |
969 | hotkey_poll_config->data = &global_hotkey_list; | |
970 | hotkey_poll_config->owner = THIS_MODULE; | |
971 | hotkey_poll_config->uid = 0; | |
972 | hotkey_poll_config->gid = 0; | |
973 | } | |
974 | ||
975 | hotkey_action = create_proc_entry(HOTKEY_ACTION, mode, hotkey_proc_dir); | |
976 | if (!hotkey_action) { | |
79cda7d0 | 977 | goto do_fail3; |
fb9802fa LY |
978 | } else { |
979 | hotkey_action->proc_fops = &hotkey_action_fops; | |
980 | hotkey_action->owner = THIS_MODULE; | |
981 | hotkey_action->uid = 0; | |
982 | hotkey_action->gid = 0; | |
983 | } | |
984 | ||
985 | hotkey_info = create_proc_entry(HOTKEY_INFO, mode, hotkey_proc_dir); | |
986 | if (!hotkey_info) { | |
79cda7d0 | 987 | goto do_fail4; |
fb9802fa LY |
988 | } else { |
989 | hotkey_info->proc_fops = &hotkey_info_fops; | |
990 | hotkey_info->owner = THIS_MODULE; | |
991 | hotkey_info->uid = 0; | |
992 | hotkey_info->gid = 0; | |
993 | } | |
994 | ||
995 | result = acpi_bus_register_driver(&hotkey_driver); | |
79cda7d0 LY |
996 | if (result < 0) |
997 | goto do_fail5; | |
fb9802fa LY |
998 | global_hotkey_list.count = 0; |
999 | global_hotkey_list.entries = &hotkey_entries; | |
1000 | ||
1001 | INIT_LIST_HEAD(&hotkey_entries); | |
1002 | ||
1003 | return (0); | |
79cda7d0 | 1004 | |
4be44fcd | 1005 | do_fail5: |
79cda7d0 | 1006 | remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir); |
4be44fcd | 1007 | do_fail4: |
79cda7d0 | 1008 | remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir); |
4be44fcd | 1009 | do_fail3: |
79cda7d0 | 1010 | remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir); |
4be44fcd | 1011 | do_fail2: |
79cda7d0 | 1012 | remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir); |
4be44fcd | 1013 | do_fail1: |
79cda7d0 LY |
1014 | remove_proc_entry(HOTKEY_PROC, acpi_root_dir); |
1015 | return (-ENODEV); | |
fb9802fa LY |
1016 | } |
1017 | ||
1018 | static void __exit hotkey_exit(void) | |
1019 | { | |
1020 | struct list_head *entries, *next; | |
1021 | ||
fb9802fa LY |
1022 | |
1023 | list_for_each_safe(entries, next, global_hotkey_list.entries) { | |
1024 | union acpi_hotkey *key = | |
1025 | container_of(entries, union acpi_hotkey, entries); | |
1026 | ||
1027 | acpi_os_wait_events_complete(NULL); | |
1028 | list_del(&key->link.entries); | |
1029 | global_hotkey_list.count--; | |
1030 | free_hotkey_device(key); | |
1031 | } | |
1032 | acpi_bus_unregister_driver(&hotkey_driver); | |
1033 | remove_proc_entry(HOTKEY_EV_CONFIG, hotkey_proc_dir); | |
1034 | remove_proc_entry(HOTKEY_PL_CONFIG, hotkey_proc_dir); | |
1035 | remove_proc_entry(HOTKEY_ACTION, hotkey_proc_dir); | |
1036 | remove_proc_entry(HOTKEY_INFO, hotkey_proc_dir); | |
1037 | remove_proc_entry(HOTKEY_PROC, acpi_root_dir); | |
1038 | return; | |
1039 | } | |
1040 | ||
1041 | module_init(hotkey_init); | |
1042 | module_exit(hotkey_exit); |