ir-core.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. 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. #define IR_TYPE_UNKNOWN 0
  26. #define IR_TYPE_RC5 (1 << 0) /* Philips RC5 protocol */
  27. #define IR_TYPE_PD (1 << 1) /* Pulse distance encoded IR */
  28. #define IR_TYPE_NEC (1 << 2)
  29. #define IR_TYPE_OTHER (((u64)1) << 63l)
  30. enum raw_event_type {
  31. IR_SPACE = (1 << 0),
  32. IR_PULSE = (1 << 1),
  33. IR_START_EVENT = (1 << 2),
  34. IR_STOP_EVENT = (1 << 3),
  35. };
  36. struct ir_scancode {
  37. u16 scancode;
  38. u32 keycode;
  39. };
  40. struct ir_scancode_table {
  41. struct ir_scancode *scan;
  42. int size;
  43. u64 ir_type;
  44. char *name;
  45. spinlock_t lock;
  46. };
  47. struct ir_dev_props {
  48. unsigned long allowed_protos;
  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. struct timer_list timer_keyup; /* timer for key release */
  62. };
  63. struct ir_input_dev {
  64. struct device dev; /* device */
  65. char *driver_name; /* Name of the driver module */
  66. struct ir_scancode_table rc_tab; /* scan/key table */
  67. unsigned long devno; /* device number */
  68. const struct ir_dev_props *props; /* Device properties */
  69. struct ir_raw_event_ctrl *raw; /* for raw pulse/space events */
  70. /* key info - needed by IR keycode handlers */
  71. u32 keycode; /* linux key code */
  72. int keypressed; /* current state */
  73. };
  74. struct ir_raw_handler {
  75. struct list_head list;
  76. int (*decode)(struct input_dev *input_dev,
  77. struct ir_raw_event *evs,
  78. int len);
  79. int (*raw_register)(struct input_dev *input_dev);
  80. int (*raw_unregister)(struct input_dev *input_dev);
  81. };
  82. #define to_ir_input_dev(_attr) container_of(_attr, struct ir_input_dev, attr)
  83. /* Routines from ir-keytable.c */
  84. u32 ir_g_keycode_from_table(struct input_dev *input_dev,
  85. u32 scancode);
  86. void ir_keyup(struct input_dev *dev);
  87. void ir_keydown(struct input_dev *dev, int scancode);
  88. int ir_input_register(struct input_dev *dev,
  89. const struct ir_scancode_table *ir_codes,
  90. const struct ir_dev_props *props,
  91. const char *driver_name);
  92. void ir_input_unregister(struct input_dev *input_dev);
  93. /* Routines from ir-sysfs.c */
  94. int ir_register_class(struct input_dev *input_dev);
  95. void ir_unregister_class(struct input_dev *input_dev);
  96. /* Routines from ir-raw-event.c */
  97. int ir_raw_event_register(struct input_dev *input_dev);
  98. void ir_raw_event_unregister(struct input_dev *input_dev);
  99. int ir_raw_event_store(struct input_dev *input_dev, enum raw_event_type type);
  100. int ir_raw_event_handle(struct input_dev *input_dev);
  101. int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler);
  102. void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler);
  103. void ir_raw_init(void);
  104. /* from ir-nec-decoder.c */
  105. #ifdef CONFIG_IR_NEC_DECODER_MODULE
  106. #define load_nec_decode() request_module("ir-nec-decoder")
  107. #else
  108. #define load_nec_decode() 0
  109. #endif
  110. #endif /* _IR_CORE */