ir-core.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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/input.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/kfifo.h>
  20. #include <linux/time.h>
  21. #include <linux/timer.h>
  22. #include <media/rc-map.h>
  23. extern int ir_core_debug;
  24. #define IR_dprintk(level, fmt, arg...) if (ir_core_debug >= level) \
  25. printk(KERN_DEBUG "%s: " fmt , __func__, ## arg)
  26. #define IR_TYPE_UNKNOWN 0
  27. #define IR_TYPE_RC5 (1 << 0) /* Philips RC5 protocol */
  28. #define IR_TYPE_PD (1 << 1) /* Pulse distance encoded IR */
  29. #define IR_TYPE_NEC (1 << 2)
  30. #define IR_TYPE_OTHER (((u64)1) << 63l)
  31. enum raw_event_type {
  32. IR_SPACE = (1 << 0),
  33. IR_PULSE = (1 << 1),
  34. IR_START_EVENT = (1 << 2),
  35. IR_STOP_EVENT = (1 << 3),
  36. };
  37. struct ir_scancode {
  38. u16 scancode;
  39. u32 keycode;
  40. };
  41. struct ir_scancode_table {
  42. struct ir_scancode *scan;
  43. int size;
  44. u64 ir_type;
  45. char *name;
  46. spinlock_t lock;
  47. };
  48. struct rc_keymap {
  49. struct list_head list;
  50. struct ir_scancode_table map;
  51. };
  52. struct ir_dev_props {
  53. unsigned long allowed_protos;
  54. void *priv;
  55. int (*change_protocol)(void *priv, u64 ir_type);
  56. int (*open)(void *priv);
  57. void (*close)(void *priv);
  58. };
  59. struct ir_raw_event {
  60. struct timespec delta; /* Time spent before event */
  61. enum raw_event_type type; /* event type */
  62. };
  63. struct ir_raw_event_ctrl {
  64. struct kfifo kfifo; /* fifo for the pulse/space events */
  65. struct timespec last_event; /* when last event occurred */
  66. struct timer_list timer_keyup; /* timer for key release */
  67. };
  68. struct ir_input_dev {
  69. struct device dev; /* device */
  70. char *driver_name; /* Name of the driver module */
  71. struct ir_scancode_table rc_tab; /* scan/key table */
  72. unsigned long devno; /* device number */
  73. const struct ir_dev_props *props; /* Device properties */
  74. struct ir_raw_event_ctrl *raw; /* for raw pulse/space events */
  75. /* key info - needed by IR keycode handlers */
  76. u32 keycode; /* linux key code */
  77. int keypressed; /* current state */
  78. };
  79. struct ir_raw_handler {
  80. struct list_head list;
  81. int (*decode)(struct input_dev *input_dev,
  82. struct ir_raw_event *evs,
  83. int len);
  84. int (*raw_register)(struct input_dev *input_dev);
  85. int (*raw_unregister)(struct input_dev *input_dev);
  86. };
  87. #define to_ir_input_dev(_attr) container_of(_attr, struct ir_input_dev, attr)
  88. #define IR_KEYTABLE(a) \
  89. ir_codes_ ## a ## _table
  90. #define DECLARE_IR_KEYTABLE(a) \
  91. extern struct ir_scancode_table IR_KEYTABLE(a)
  92. #define DEFINE_IR_KEYTABLE(tabname, type) \
  93. struct ir_scancode_table IR_KEYTABLE(tabname) = { \
  94. .scan = tabname, \
  95. .size = ARRAY_SIZE(tabname), \
  96. .ir_type = type, \
  97. .name = #tabname, \
  98. }; \
  99. EXPORT_SYMBOL_GPL(IR_KEYTABLE(tabname))
  100. #define DEFINE_LEGACY_IR_KEYTABLE(tabname) \
  101. DEFINE_IR_KEYTABLE(tabname, IR_TYPE_UNKNOWN)
  102. /* Routines from rc-map.c */
  103. int ir_register_map(struct rc_keymap *map);
  104. void ir_unregister_map(struct rc_keymap *map);
  105. struct ir_scancode_table *get_rc_map(const char *name);
  106. void rc_map_init(void);
  107. /* Routines from ir-keytable.c */
  108. u32 ir_g_keycode_from_table(struct input_dev *input_dev,
  109. u32 scancode);
  110. void ir_keyup(struct input_dev *dev);
  111. void ir_keydown(struct input_dev *dev, int scancode);
  112. int __ir_input_register(struct input_dev *dev,
  113. const struct ir_scancode_table *ir_codes,
  114. const struct ir_dev_props *props,
  115. const char *driver_name);
  116. static inline int ir_input_register(struct input_dev *dev,
  117. const char *map_name,
  118. const struct ir_dev_props *props,
  119. const char *driver_name) {
  120. struct ir_scancode_table *ir_codes;
  121. struct ir_input_dev *ir_dev;
  122. int rc;
  123. if (!map_name)
  124. return -EINVAL;
  125. ir_codes = get_rc_map(map_name);
  126. if (!ir_codes)
  127. return -EINVAL;
  128. rc = __ir_input_register(dev, ir_codes, props, driver_name);
  129. if (rc < 0)
  130. return -EINVAL;
  131. ir_dev = input_get_drvdata(dev);
  132. if (!rc && ir_dev->props && ir_dev->props->change_protocol)
  133. rc = ir_dev->props->change_protocol(ir_dev->props->priv,
  134. ir_codes->ir_type);
  135. return rc;
  136. }
  137. void ir_input_unregister(struct input_dev *input_dev);
  138. /* Routines from ir-sysfs.c */
  139. int ir_register_class(struct input_dev *input_dev);
  140. void ir_unregister_class(struct input_dev *input_dev);
  141. /* Routines from ir-raw-event.c */
  142. int ir_raw_event_register(struct input_dev *input_dev);
  143. void ir_raw_event_unregister(struct input_dev *input_dev);
  144. int ir_raw_event_store(struct input_dev *input_dev, enum raw_event_type type);
  145. int ir_raw_event_handle(struct input_dev *input_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. /* from ir-nec-decoder.c */
  150. #ifdef CONFIG_IR_NEC_DECODER_MODULE
  151. #define load_nec_decode() request_module("ir-nec-decoder")
  152. #else
  153. #define load_nec_decode() 0
  154. #endif
  155. #endif /* _IR_CORE */