rc-map.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /* Used to handle IR raw handler extensions */
  17. static LIST_HEAD(rc_map_list);
  18. static spinlock_t rc_map_lock;
  19. static struct rc_keymap *seek_rc_map(const char *name)
  20. {
  21. struct rc_keymap *map = NULL;
  22. spin_lock(&rc_map_lock);
  23. list_for_each_entry(map, &rc_map_list, list) {
  24. if (!strcmp(name, map->map.name))
  25. break;
  26. }
  27. spin_unlock(&rc_map_lock);
  28. return map;
  29. }
  30. struct ir_scancode_table *get_rc_map(const char *name)
  31. {
  32. int rc = 0;
  33. struct rc_keymap *map;
  34. map = seek_rc_map(name);
  35. #ifdef MODULE
  36. if (!map) {
  37. rc = request_module("name");
  38. if (rc < 0)
  39. return NULL;
  40. map = seek_rc_map(name);
  41. }
  42. #endif
  43. if (!map)
  44. return NULL;
  45. return &map->map;
  46. }
  47. EXPORT_SYMBOL_GPL(get_rc_map);
  48. int ir_register_map(struct rc_keymap *map)
  49. {
  50. spin_lock(&rc_map_lock);
  51. list_add_tail(&map->list, &rc_map_list);
  52. spin_unlock(&rc_map_lock);
  53. return 0;
  54. }
  55. EXPORT_SYMBOL_GPL(ir_raw_handler_register);
  56. void ir_unregister_map(struct rc_keymap *map)
  57. {
  58. spin_lock(&rc_map_lock);
  59. list_del(&map->list);
  60. spin_unlock(&rc_map_lock);
  61. }
  62. EXPORT_SYMBOL_GPL(ir_raw_handler_unregister);