rc-core-priv.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Remote Controller core raw events header
  3. *
  4. * Copyright (C) 2010 by Mauro Carvalho Chehab
  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 _RC_CORE_PRIV
  16. #define _RC_CORE_PRIV
  17. /* Define the max number of pulse/space transitions to buffer */
  18. #define MAX_IR_EVENT_SIZE 512
  19. #include <linux/slab.h>
  20. #include <linux/spinlock.h>
  21. #include <media/rc-core.h>
  22. struct ir_raw_handler {
  23. struct list_head list;
  24. u64 protocols; /* which are handled by this handler */
  25. int (*decode)(struct rc_dev *dev, struct ir_raw_event event);
  26. /* These two should only be used by the lirc decoder */
  27. int (*raw_register)(struct rc_dev *dev);
  28. int (*raw_unregister)(struct rc_dev *dev);
  29. };
  30. struct ir_raw_event_ctrl {
  31. struct list_head list; /* to keep track of raw clients */
  32. struct task_struct *thread;
  33. spinlock_t lock;
  34. /* fifo for the pulse/space durations */
  35. DECLARE_KFIFO(kfifo, struct ir_raw_event, MAX_IR_EVENT_SIZE);
  36. ktime_t last_event; /* when last event occurred */
  37. enum raw_event_type last_type; /* last event type */
  38. struct rc_dev *dev; /* pointer to the parent rc_dev */
  39. /* raw decoder state follows */
  40. struct ir_raw_event prev_ev;
  41. struct ir_raw_event this_ev;
  42. struct nec_dec {
  43. int state;
  44. unsigned count;
  45. u32 bits;
  46. bool is_nec_x;
  47. bool necx_repeat;
  48. } nec;
  49. struct rc5_dec {
  50. int state;
  51. u32 bits;
  52. unsigned count;
  53. bool is_rc5x;
  54. } rc5;
  55. struct rc6_dec {
  56. int state;
  57. u8 header;
  58. u32 body;
  59. bool toggle;
  60. unsigned count;
  61. unsigned wanted_bits;
  62. } rc6;
  63. struct sony_dec {
  64. int state;
  65. u32 bits;
  66. unsigned count;
  67. } sony;
  68. struct jvc_dec {
  69. int state;
  70. u16 bits;
  71. u16 old_bits;
  72. unsigned count;
  73. bool first;
  74. bool toggle;
  75. } jvc;
  76. struct sanyo_dec {
  77. int state;
  78. unsigned count;
  79. u64 bits;
  80. } sanyo;
  81. struct sharp_dec {
  82. int state;
  83. unsigned count;
  84. u32 bits;
  85. unsigned int pulse_len;
  86. } sharp;
  87. struct mce_kbd_dec {
  88. struct input_dev *idev;
  89. struct timer_list rx_timeout;
  90. char name[64];
  91. char phys[64];
  92. int state;
  93. u8 header;
  94. u32 body;
  95. unsigned count;
  96. unsigned wanted_bits;
  97. } mce_kbd;
  98. struct lirc_codec {
  99. struct rc_dev *dev;
  100. struct lirc_driver *drv;
  101. int carrier_low;
  102. ktime_t gap_start;
  103. u64 gap_duration;
  104. bool gap;
  105. bool send_timeout_reports;
  106. } lirc;
  107. struct xmp_dec {
  108. int state;
  109. unsigned count;
  110. u32 durations[16];
  111. } xmp;
  112. };
  113. /* macros for IR decoders */
  114. static inline bool geq_margin(unsigned d1, unsigned d2, unsigned margin)
  115. {
  116. return d1 > (d2 - margin);
  117. }
  118. static inline bool eq_margin(unsigned d1, unsigned d2, unsigned margin)
  119. {
  120. return ((d1 > (d2 - margin)) && (d1 < (d2 + margin)));
  121. }
  122. static inline bool is_transition(struct ir_raw_event *x, struct ir_raw_event *y)
  123. {
  124. return x->pulse != y->pulse;
  125. }
  126. static inline void decrease_duration(struct ir_raw_event *ev, unsigned duration)
  127. {
  128. if (duration > ev->duration)
  129. ev->duration = 0;
  130. else
  131. ev->duration -= duration;
  132. }
  133. /* Returns true if event is normal pulse/space event */
  134. static inline bool is_timing_event(struct ir_raw_event ev)
  135. {
  136. return !ev.carrier_report && !ev.reset;
  137. }
  138. #define TO_US(duration) DIV_ROUND_CLOSEST((duration), 1000)
  139. #define TO_STR(is_pulse) ((is_pulse) ? "pulse" : "space")
  140. /*
  141. * Routines from rc-raw.c to be used internally and by decoders
  142. */
  143. u64 ir_raw_get_allowed_protocols(void);
  144. int ir_raw_event_register(struct rc_dev *dev);
  145. void ir_raw_event_unregister(struct rc_dev *dev);
  146. int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
  147. void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
  148. void ir_raw_init(void);
  149. /*
  150. * Decoder initialization code
  151. *
  152. * Those load logic are called during ir-core init, and automatically
  153. * loads the compiled decoders for their usage with IR raw events
  154. */
  155. #endif /* _RC_CORE_PRIV */