blob: 2f6201ce18988e72f495b5ed0e28ce2a0556b3cd [file] [log] [blame]
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -03001/* 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 */
19static LIST_HEAD(rc_map_list);
20static spinlock_t rc_map_lock;
21
22
23static struct rc_keymap *seek_rc_map(const char *name)
24{
25 struct rc_keymap *map = NULL;
26
27 spin_lock(&rc_map_lock);
28 list_for_each_entry(map, &rc_map_list, list) {
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030029 if (!strcmp(name, map->map.name)) {
30 spin_unlock(&rc_map_lock);
31 return map;
32 }
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030033 }
34 spin_unlock(&rc_map_lock);
35
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030036 return NULL;
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030037}
38
39struct ir_scancode_table *get_rc_map(const char *name)
40{
41 int rc = 0;
42
43 struct rc_keymap *map;
44
45 map = seek_rc_map(name);
46#ifdef MODULE
47 if (!map) {
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030048 rc = request_module(name);
49 if (rc < 0) {
50 printk(KERN_ERR "Couldn't load IR keymap %s\n", name);
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030051 return NULL;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030052 }
53 msleep(20); /* Give some time for IR to register */
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030054
55 map = seek_rc_map(name);
56 }
57#endif
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030058 if (!map) {
59 printk(KERN_ERR "IR keymap %s not found\n", name);
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030060 return NULL;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030061 }
62
63 printk(KERN_INFO "Registered IR keymap %s\n", map->map.name);
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030064
65 return &map->map;
66}
67EXPORT_SYMBOL_GPL(get_rc_map);
68
69int ir_register_map(struct rc_keymap *map)
70{
71 spin_lock(&rc_map_lock);
72 list_add_tail(&map->list, &rc_map_list);
73 spin_unlock(&rc_map_lock);
74 return 0;
75}
Mauro Carvalho Chehab6686fa62010-04-02 03:05:46 -030076EXPORT_SYMBOL_GPL(ir_register_map);
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030077
78void ir_unregister_map(struct rc_keymap *map)
79{
80 spin_lock(&rc_map_lock);
81 list_del(&map->list);
82 spin_unlock(&rc_map_lock);
83}
Mauro Carvalho Chehab6686fa62010-04-02 03:05:46 -030084EXPORT_SYMBOL_GPL(ir_unregister_map);
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030085
86void rc_map_init(void)
87{
88 spin_lock_init(&rc_map_lock);
89
90}