ir-core.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Remote Controller core header
  3. *
  4. * Copyright (C) 2009-2010 by Mauro Carvalho Chehab <mchehab@redhat.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation version 2 of the License.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #ifndef _IR_CORE
  16. #define _IR_CORE
  17. #include <linux/spinlock.h>
  18. #include <linux/kfifo.h>
  19. #include <linux/time.h>
  20. #include <linux/timer.h>
  21. #include <media/rc-map.h>
  22. extern int ir_core_debug;
  23. #define IR_dprintk(level, fmt, arg...) if (ir_core_debug >= level) \
  24. printk(KERN_DEBUG "%s: " fmt , __func__, ## arg)
  25. enum raw_event_type {
  26. IR_SPACE = (1 << 0),
  27. IR_PULSE = (1 << 1),
  28. IR_START_EVENT = (1 << 2),
  29. IR_STOP_EVENT = (1 << 3),
  30. };
  31. /**
  32. * struct ir_dev_props - Allow caller drivers to set special properties
  33. * @allowed_protos: bitmask with the supported IR_TYPE_* protocols
  34. * @scanmask: some hardware decoders are not capable of providing the full
  35. * scancode to the application. As this is a hardware limit, we can't do
  36. * anything with it. Yet, as the same keycode table can be used with other
  37. * devices, a mask is provided to allow its usage. Drivers should generally
  38. * leave this field in blank
  39. * @priv: driver-specific data, to be used on the callbacks
  40. * @change_protocol: allow changing the protocol used on hardware decoders
  41. * @open: callback to allow drivers to enable polling/irq when IR input device
  42. * is opened.
  43. * @close: callback to allow drivers to disable polling/irq when IR input device
  44. * is opened.
  45. */
  46. struct ir_dev_props {
  47. unsigned long allowed_protos;
  48. u32 scanmask;
  49. void *priv;
  50. int (*change_protocol)(void *priv, u64 ir_type);
  51. int (*open)(void *priv);
  52. void (*close)(void *priv);
  53. };
  54. struct ir_raw_event {
  55. struct timespec delta; /* Time spent before event */
  56. enum raw_event_type type; /* event type */
  57. };
  58. struct ir_raw_event_ctrl {
  59. struct kfifo kfifo; /* fifo for the pulse/space events */
  60. struct timespec last_event; /* when last event occurred */
  61. };
  62. struct ir_input_dev {
  63. struct device dev; /* device */
  64. char *driver_name; /* Name of the driver module */
  65. struct ir_scancode_table rc_tab; /* scan/key table */
  66. unsigned long devno; /* device number */
  67. const struct ir_dev_props *props; /* Device properties */
  68. struct ir_raw_event_ctrl *raw; /* for raw pulse/space events */
  69. struct input_dev *input_dev; /* the input device associated with this device */
  70. /* key info - needed by IR keycode handlers */
  71. spinlock_t keylock; /* protects the below members */
  72. bool keypressed; /* current state */
  73. unsigned long keyup_jiffies; /* when should the current keypress be released? */
  74. struct timer_list timer_keyup; /* timer for releasing a keypress */
  75. u32 last_keycode; /* keycode of last command */
  76. u32 last_scancode; /* scancode of last command */
  77. u8 last_toggle; /* toggle of last command */
  78. };
  79. struct ir_raw_handler {
  80. struct list_head list;
  81. int (*decode)(struct input_dev *input_dev,
  82. struct ir_raw_event *ev);
  83. int (*raw_register)(struct input_dev *input_dev);
  84. int (*raw_unregister)(struct input_dev *input_dev);
  85. };
  86. #define to_ir_input_dev(_attr) container_of(_attr, struct ir_input_dev, attr)
  87. /* Routines from ir-keytable.c */
  88. u32 ir_g_keycode_from_table(struct input_dev *input_dev,
  89. u32 scancode);
  90. void ir_repeat(struct input_dev *dev);
  91. void ir_keydown(struct input_dev *dev, int scancode, u8 toggle);
  92. int __ir_input_register(struct input_dev *dev,
  93. const struct ir_scancode_table *ir_codes,
  94. const struct ir_dev_props *props,
  95. const char *driver_name);
  96. static inline int ir_input_register(struct input_dev *dev,
  97. const char *map_name,
  98. const struct ir_dev_props *props,
  99. const char *driver_name) {
  100. struct ir_scancode_table *ir_codes;
  101. struct ir_input_dev *ir_dev;
  102. int rc;
  103. if (!map_name)
  104. return -EINVAL;
  105. ir_codes = get_rc_map(map_name);
  106. if (!ir_codes)
  107. return -EINVAL;
  108. rc = __ir_input_register(dev, ir_codes, props, driver_name);
  109. if (rc < 0)
  110. return -EINVAL;
  111. ir_dev = input_get_drvdata(dev);
  112. if (!rc && ir_dev->props && ir_dev->props->change_protocol)
  113. rc = ir_dev->props->change_protocol(ir_dev->props->priv,
  114. ir_codes->ir_type);
  115. return rc;
  116. }
  117. void ir_input_unregister(struct input_dev *input_dev);
  118. /* Routines from ir-sysfs.c */
  119. int ir_register_class(struct input_dev *input_dev);
  120. void ir_unregister_class(struct input_dev *input_dev);
  121. /* Routines from ir-raw-event.c */
  122. int ir_raw_event_register(struct input_dev *input_dev);
  123. void ir_raw_event_unregister(struct input_dev *input_dev);
  124. int ir_raw_event_store(struct input_dev *input_dev, enum raw_event_type type);
  125. int ir_raw_event_handle(struct input_dev *input_dev);
  126. int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
  127. void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
  128. void ir_raw_init(void);
  129. /* from ir-nec-decoder.c */
  130. #ifdef CONFIG_IR_NEC_DECODER_MODULE
  131. #define load_nec_decode() request_module("ir-nec-decoder")
  132. #else
  133. #define load_nec_decode() 0
  134. #endif
  135. /* from ir-rc5-decoder.c */
  136. #ifdef CONFIG_IR_RC5_DECODER_MODULE
  137. #define load_rc5_decode() request_module("ir-rc5-decoder")
  138. #else
  139. #define load_rc5_decode() 0
  140. #endif
  141. #endif /* _IR_CORE */