blob: 1a3f4b123a37a995e3d99fc2f127597d081d1641 [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);
Mauro Carvalho Chehab6eb94352010-04-07 16:19:36 -030020static DEFINE_SPINLOCK(rc_map_lock);
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030021
22static 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) {
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030028 if (!strcmp(name, map->map.name)) {
29 spin_unlock(&rc_map_lock);
30 return map;
31 }
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030032 }
33 spin_unlock(&rc_map_lock);
34
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030035 return NULL;
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030036}
37
38struct ir_scancode_table *get_rc_map(const char *name)
39{
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030040
41 struct rc_keymap *map;
42
43 map = seek_rc_map(name);
44#ifdef MODULE
45 if (!map) {
Mauro Carvalho Chehab5fa29892010-04-08 19:04:06 -030046 int rc = request_module(name);
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030047 if (rc < 0) {
48 printk(KERN_ERR "Couldn't load IR keymap %s\n", name);
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030049 return NULL;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030050 }
51 msleep(20); /* Give some time for IR to register */
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030052
53 map = seek_rc_map(name);
54 }
55#endif
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030056 if (!map) {
57 printk(KERN_ERR "IR keymap %s not found\n", name);
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030058 return NULL;
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030059 }
60
61 printk(KERN_INFO "Registered IR keymap %s\n", map->map.name);
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030062
63 return &map->map;
64}
65EXPORT_SYMBOL_GPL(get_rc_map);
66
67int ir_register_map(struct rc_keymap *map)
68{
69 spin_lock(&rc_map_lock);
70 list_add_tail(&map->list, &rc_map_list);
71 spin_unlock(&rc_map_lock);
72 return 0;
73}
Mauro Carvalho Chehab6686fa62010-04-02 03:05:46 -030074EXPORT_SYMBOL_GPL(ir_register_map);
Mauro Carvalho Chehab9ce50c12010-04-02 02:33:35 -030075
76void ir_unregister_map(struct rc_keymap *map)
77{
78 spin_lock(&rc_map_lock);
79 list_del(&map->list);
80 spin_unlock(&rc_map_lock);
81}
Mauro Carvalho Chehab6686fa62010-04-02 03:05:46 -030082EXPORT_SYMBOL_GPL(ir_unregister_map);
Mauro Carvalho Chehab02858ee2010-04-02 20:01:00 -030083
84void rc_map_init(void)
85{
86 spin_lock_init(&rc_map_lock);
87
88}