rc-map.c 1.9 KB

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