rc-map.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #include <media/ir-core.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/delay.h>
  17. /* Used to handle IR raw handler extensions */
  18. static LIST_HEAD(rc_map_list);
  19. static DEFINE_SPINLOCK(rc_map_lock);
  20. static struct rc_keymap *seek_rc_map(const char *name)
  21. {
  22. struct rc_keymap *map = NULL;
  23. spin_lock(&rc_map_lock);
  24. list_for_each_entry(map, &rc_map_list, list) {
  25. if (!strcmp(name, map->map.name)) {
  26. spin_unlock(&rc_map_lock);
  27. return map;
  28. }
  29. }
  30. spin_unlock(&rc_map_lock);
  31. return NULL;
  32. }
  33. struct ir_scancode_table *get_rc_map(const char *name)
  34. {
  35. struct rc_keymap *map;
  36. map = seek_rc_map(name);
  37. #ifdef MODULE
  38. if (!map) {
  39. int rc = request_module(name);
  40. if (rc < 0) {
  41. printk(KERN_ERR "Couldn't load IR keymap %s\n", name);
  42. return NULL;
  43. }
  44. msleep(20); /* Give some time for IR to register */
  45. map = seek_rc_map(name);
  46. }
  47. #endif
  48. if (!map) {
  49. printk(KERN_ERR "IR keymap %s not found\n", name);
  50. return NULL;
  51. }
  52. printk(KERN_INFO "Registered IR keymap %s\n", map->map.name);
  53. return &map->map;
  54. }
  55. EXPORT_SYMBOL_GPL(get_rc_map);
  56. int ir_register_map(struct rc_keymap *map)
  57. {
  58. spin_lock(&rc_map_lock);
  59. list_add_tail(&map->list, &rc_map_list);
  60. spin_unlock(&rc_map_lock);
  61. return 0;
  62. }
  63. EXPORT_SYMBOL_GPL(ir_register_map);
  64. void ir_unregister_map(struct rc_keymap *map)
  65. {
  66. spin_lock(&rc_map_lock);
  67. list_del(&map->list);
  68. spin_unlock(&rc_map_lock);
  69. }
  70. EXPORT_SYMBOL_GPL(ir_unregister_map);