]>
Commit | Line | Data |
---|---|---|
9ce50c1a MCC |
1 | /* ir-raw-event.c - handle IR Pulse/Space event |
2 | * | |
3 | * Copyright (C) 2010 by Mauro Carvalho Chehab <mchehab@redhat.com> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation version 2 of the License. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, | |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
13 | */ | |
14 | ||
15 | #include <media/ir-core.h> | |
16 | #include <linux/spinlock.h> | |
17 | ||
18 | /* Used to handle IR raw handler extensions */ | |
19 | static LIST_HEAD(rc_map_list); | |
6eb9435b | 20 | static DEFINE_SPINLOCK(rc_map_lock); |
9ce50c1a MCC |
21 | |
22 | static struct rc_keymap *seek_rc_map(const char *name) | |
23 | { | |
24 | struct rc_keymap *map = NULL; | |
25 | ||
26 | spin_lock(&rc_map_lock); | |
27 | list_for_each_entry(map, &rc_map_list, list) { | |
02858eed MCC |
28 | if (!strcmp(name, map->map.name)) { |
29 | spin_unlock(&rc_map_lock); | |
30 | return map; | |
31 | } | |
9ce50c1a MCC |
32 | } |
33 | spin_unlock(&rc_map_lock); | |
34 | ||
02858eed | 35 | return NULL; |
9ce50c1a MCC |
36 | } |
37 | ||
38 | struct ir_scancode_table *get_rc_map(const char *name) | |
39 | { | |
40 | int rc = 0; | |
41 | ||
42 | struct rc_keymap *map; | |
43 | ||
44 | map = seek_rc_map(name); | |
45 | #ifdef MODULE | |
46 | if (!map) { | |
02858eed MCC |
47 | rc = request_module(name); |
48 | if (rc < 0) { | |
49 | printk(KERN_ERR "Couldn't load IR keymap %s\n", name); | |
9ce50c1a | 50 | return NULL; |
02858eed MCC |
51 | } |
52 | msleep(20); /* Give some time for IR to register */ | |
9ce50c1a MCC |
53 | |
54 | map = seek_rc_map(name); | |
55 | } | |
56 | #endif | |
02858eed MCC |
57 | if (!map) { |
58 | printk(KERN_ERR "IR keymap %s not found\n", name); | |
9ce50c1a | 59 | return NULL; |
02858eed MCC |
60 | } |
61 | ||
62 | printk(KERN_INFO "Registered IR keymap %s\n", map->map.name); | |
9ce50c1a MCC |
63 | |
64 | return &map->map; | |
65 | } | |
66 | EXPORT_SYMBOL_GPL(get_rc_map); | |
67 | ||
68 | int ir_register_map(struct rc_keymap *map) | |
69 | { | |
70 | spin_lock(&rc_map_lock); | |
71 | list_add_tail(&map->list, &rc_map_list); | |
72 | spin_unlock(&rc_map_lock); | |
73 | return 0; | |
74 | } | |
6686fa69 | 75 | EXPORT_SYMBOL_GPL(ir_register_map); |
9ce50c1a MCC |
76 | |
77 | void ir_unregister_map(struct rc_keymap *map) | |
78 | { | |
79 | spin_lock(&rc_map_lock); | |
80 | list_del(&map->list); | |
81 | spin_unlock(&rc_map_lock); | |
82 | } | |
6686fa69 | 83 | EXPORT_SYMBOL_GPL(ir_unregister_map); |
02858eed MCC |
84 | |
85 | void rc_map_init(void) | |
86 | { | |
87 | spin_lock_init(&rc_map_lock); | |
88 | ||
89 | } |