ir-core.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 rc_driver_type {
  26. RC_DRIVER_SCANCODE = 0, /* Driver or hardware generates a scancode */
  27. RC_DRIVER_IR_RAW, /* Needs a Infra-Red pulse/space decoder */
  28. };
  29. enum raw_event_type {
  30. IR_SPACE = (1 << 0),
  31. IR_PULSE = (1 << 1),
  32. IR_START_EVENT = (1 << 2),
  33. IR_STOP_EVENT = (1 << 3),
  34. };
  35. /**
  36. * struct ir_dev_props - Allow caller drivers to set special properties
  37. * @driver_type: specifies if the driver or hardware have already a decoder,
  38. * or if it needs to use the IR raw event decoders to produce a scancode
  39. * @allowed_protos: bitmask with the supported IR_TYPE_* protocols
  40. * @scanmask: some hardware decoders are not capable of providing the full
  41. * scancode to the application. As this is a hardware limit, we can't do
  42. * anything with it. Yet, as the same keycode table can be used with other
  43. * devices, a mask is provided to allow its usage. Drivers should generally
  44. * leave this field in blank
  45. * @priv: driver-specific data, to be used on the callbacks
  46. * @change_protocol: allow changing the protocol used on hardware decoders
  47. * @open: callback to allow drivers to enable polling/irq when IR input device
  48. * is opened.
  49. * @close: callback to allow drivers to disable polling/irq when IR input device
  50. * is opened.
  51. */
  52. struct ir_dev_props {
  53. enum rc_driver_type driver_type;
  54. unsigned long allowed_protos;
  55. u32 scanmask;
  56. void *priv;
  57. int (*change_protocol)(void *priv, u64 ir_type);
  58. int (*open)(void *priv);
  59. void (*close)(void *priv);
  60. };
  61. struct ir_raw_event {
  62. struct timespec delta; /* Time spent before event */
  63. enum raw_event_type type; /* event type */
  64. };
  65. struct ir_raw_event_ctrl {
  66. struct kfifo kfifo; /* fifo for the pulse/space events */
  67. struct timespec last_event; /* when last event occurred */
  68. };
  69. struct ir_input_dev {
  70. struct device dev; /* device */
  71. char *driver_name; /* Name of the driver module */
  72. struct ir_scancode_table rc_tab; /* scan/key table */
  73. unsigned long devno; /* device number */
  74. const struct ir_dev_props *props; /* Device properties */
  75. struct ir_raw_event_ctrl *raw; /* for raw pulse/space events */
  76. struct input_dev *input_dev; /* the input device associated with this device */
  77. /* key info - needed by IR keycode handlers */
  78. spinlock_t keylock; /* protects the below members */
  79. bool keypressed; /* current state */
  80. unsigned long keyup_jiffies; /* when should the current keypress be released? */
  81. struct timer_list timer_keyup; /* timer for releasing a keypress */
  82. u32 last_keycode; /* keycode of last command */
  83. u32 last_scancode; /* scancode of last command */
  84. u8 last_toggle; /* toggle of last command */
  85. };
  86. struct ir_raw_handler {
  87. struct list_head list;
  88. int (*decode)(struct input_dev *input_dev,
  89. struct ir_raw_event *ev);
  90. int (*raw_register)(struct input_dev *input_dev);
  91. int (*raw_unregister)(struct input_dev *input_dev);
  92. };
  93. #define to_ir_input_dev(_attr) container_of(_attr, struct ir_input_dev, attr)
  94. /* Routines from ir-keytable.c */
  95. u32 ir_g_keycode_from_table(struct input_dev *input_dev,
  96. u32 scancode);
  97. void ir_repeat(struct input_dev *dev);
  98. void ir_keydown(struct input_dev *dev, int scancode, u8 toggle);
  99. int __ir_input_register(struct input_dev *dev,
  100. const struct ir_scancode_table *ir_codes,
  101. const struct ir_dev_props *props,
  102. const char *driver_name);
  103. static inline int ir_input_register(struct input_dev *dev,
  104. const char *map_name,
  105. const struct ir_dev_props *props,
  106. const char *driver_name) {
  107. struct ir_scancode_table *ir_codes;
  108. struct ir_input_dev *ir_dev;
  109. int rc;
  110. if (!map_name)
  111. return -EINVAL;
  112. ir_codes = get_rc_map(map_name);
  113. if (!ir_codes)
  114. return -EINVAL;
  115. rc = __ir_input_register(dev, ir_codes, props, driver_name);
  116. if (rc < 0)
  117. return -EINVAL;
  118. ir_dev = input_get_drvdata(dev);
  119. if (!rc && ir_dev->props && ir_dev->props->change_protocol)
  120. rc = ir_dev->props->change_protocol(ir_dev->props->priv,
  121. ir_codes->ir_type);
  122. return rc;
  123. }
  124. void ir_input_unregister(struct input_dev *input_dev);
  125. /* Routines from ir-sysfs.c */
  126. int ir_register_class(struct input_dev *input_dev);
  127. void ir_unregister_class(struct input_dev *input_dev);
  128. /* Routines from ir-raw-event.c */
  129. int ir_raw_event_register(struct input_dev *input_dev);
  130. void ir_raw_event_unregister(struct input_dev *input_dev);
  131. int ir_raw_event_store(struct input_dev *input_dev, enum raw_event_type type);
  132. int ir_raw_event_handle(struct input_dev *input_dev);
  133. int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
  134. void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
  135. void ir_raw_init(void);
  136. /* from ir-nec-decoder.c */
  137. #ifdef CONFIG_IR_NEC_DECODER_MODULE
  138. #define load_nec_decode() request_module("ir-nec-decoder")
  139. #else
  140. #define load_nec_decode() 0
  141. #endif
  142. /* from ir-rc5-decoder.c */
  143. #ifdef CONFIG_IR_RC5_DECODER_MODULE
  144. #define load_rc5_decode() request_module("ir-rc5-decoder")
  145. #else
  146. #define load_rc5_decode() 0
  147. #endif
  148. #endif /* _IR_CORE */