Mauro Carvalho Chehab | 9ce50c1 | 2010-04-02 02:33:35 -0300 | [diff] [blame] | 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> |
Peter Huewe | a7b3903 | 2010-05-05 12:20:21 -0300 | [diff] [blame] | 17 | #include <linux/delay.h> |
Mauro Carvalho Chehab | 9ce50c1 | 2010-04-02 02:33:35 -0300 | [diff] [blame] | 18 | |
| 19 | /* Used to handle IR raw handler extensions */ |
| 20 | static LIST_HEAD(rc_map_list); |
Mauro Carvalho Chehab | 6eb9435 | 2010-04-07 16:19:36 -0300 | [diff] [blame] | 21 | static DEFINE_SPINLOCK(rc_map_lock); |
Mauro Carvalho Chehab | 9ce50c1 | 2010-04-02 02:33:35 -0300 | [diff] [blame] | 22 | |
| 23 | static 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 Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 29 | if (!strcmp(name, map->map.name)) { |
| 30 | spin_unlock(&rc_map_lock); |
| 31 | return map; |
| 32 | } |
Mauro Carvalho Chehab | 9ce50c1 | 2010-04-02 02:33:35 -0300 | [diff] [blame] | 33 | } |
| 34 | spin_unlock(&rc_map_lock); |
| 35 | |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 36 | return NULL; |
Mauro Carvalho Chehab | 9ce50c1 | 2010-04-02 02:33:35 -0300 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | struct ir_scancode_table *get_rc_map(const char *name) |
| 40 | { |
Mauro Carvalho Chehab | 9ce50c1 | 2010-04-02 02:33:35 -0300 | [diff] [blame] | 41 | |
| 42 | struct rc_keymap *map; |
| 43 | |
| 44 | map = seek_rc_map(name); |
| 45 | #ifdef MODULE |
| 46 | if (!map) { |
Mauro Carvalho Chehab | 5fa2989 | 2010-04-08 19:04:06 -0300 | [diff] [blame] | 47 | int rc = request_module(name); |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 48 | if (rc < 0) { |
| 49 | printk(KERN_ERR "Couldn't load IR keymap %s\n", name); |
Mauro Carvalho Chehab | 9ce50c1 | 2010-04-02 02:33:35 -0300 | [diff] [blame] | 50 | return NULL; |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 51 | } |
| 52 | msleep(20); /* Give some time for IR to register */ |
Mauro Carvalho Chehab | 9ce50c1 | 2010-04-02 02:33:35 -0300 | [diff] [blame] | 53 | |
| 54 | map = seek_rc_map(name); |
| 55 | } |
| 56 | #endif |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 57 | if (!map) { |
| 58 | printk(KERN_ERR "IR keymap %s not found\n", name); |
Mauro Carvalho Chehab | 9ce50c1 | 2010-04-02 02:33:35 -0300 | [diff] [blame] | 59 | return NULL; |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | printk(KERN_INFO "Registered IR keymap %s\n", map->map.name); |
Mauro Carvalho Chehab | 9ce50c1 | 2010-04-02 02:33:35 -0300 | [diff] [blame] | 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 | } |
Mauro Carvalho Chehab | 6686fa6 | 2010-04-02 03:05:46 -0300 | [diff] [blame] | 75 | EXPORT_SYMBOL_GPL(ir_register_map); |
Mauro Carvalho Chehab | 9ce50c1 | 2010-04-02 02:33:35 -0300 | [diff] [blame] | 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 | } |
Mauro Carvalho Chehab | 6686fa6 | 2010-04-02 03:05:46 -0300 | [diff] [blame] | 83 | EXPORT_SYMBOL_GPL(ir_unregister_map); |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 84 | |
Maxim Levitsky | b378f43 | 2010-07-31 11:59:21 -0300 | [diff] [blame] | 85 | |
| 86 | static struct ir_scancode empty[] = { |
| 87 | { 0x2a, KEY_COFFEE }, |
| 88 | }; |
| 89 | |
| 90 | static struct rc_keymap empty_map = { |
| 91 | .map = { |
| 92 | .scan = empty, |
| 93 | .size = ARRAY_SIZE(empty), |
| 94 | .ir_type = IR_TYPE_UNKNOWN, /* Legacy IR type */ |
| 95 | .name = RC_MAP_EMPTY, |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | int ir_rcmap_init(void) |
| 100 | { |
| 101 | return ir_register_map(&empty_map); |
| 102 | } |
| 103 | |
| 104 | void ir_rcmap_cleanup(void) |
| 105 | { |
| 106 | ir_unregister_map(&empty_map); |
| 107 | } |