em28xx-input.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. *
  3. * handle saa7134 IR remotes via linux kernel input layer.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  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. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. #include <linux/module.h>
  21. #include <linux/moduleparam.h>
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/sched.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/input.h>
  27. #include <linux/usb.h>
  28. #include "em2820.h"
  29. static unsigned int disable_ir = 0;
  30. module_param(disable_ir, int, 0444);
  31. MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
  32. static unsigned int ir_debug = 0;
  33. module_param(ir_debug, int, 0644);
  34. MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
  35. #define dprintk(fmt, arg...) if (ir_debug) \
  36. printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
  37. /* ---------------------------------------------------------------------- */
  38. static IR_KEYTAB_TYPE ir_codes_em_terratec[IR_KEYTAB_SIZE] = {
  39. [ 0x01 ] = KEY_CHANNEL,
  40. [ 0x02 ] = KEY_SELECT,
  41. [ 0x03 ] = KEY_MUTE,
  42. [ 0x04 ] = KEY_POWER,
  43. [ 0x05 ] = KEY_KP1,
  44. [ 0x06 ] = KEY_KP2,
  45. [ 0x07 ] = KEY_KP3,
  46. [ 0x08 ] = KEY_CHANNELUP,
  47. [ 0x09 ] = KEY_KP4,
  48. [ 0x0a ] = KEY_KP5,
  49. [ 0x0b ] = KEY_KP6,
  50. [ 0x0c ] = KEY_CHANNELDOWN,
  51. [ 0x0d ] = KEY_KP7,
  52. [ 0x0e ] = KEY_KP8,
  53. [ 0x0f ] = KEY_KP9,
  54. [ 0x10 ] = KEY_VOLUMEUP,
  55. [ 0x11 ] = KEY_KP0,
  56. [ 0x12 ] = KEY_MENU,
  57. [ 0x13 ] = KEY_PRINT,
  58. [ 0x14 ] = KEY_VOLUMEDOWN,
  59. [ 0x16 ] = KEY_PAUSE,
  60. [ 0x18 ] = KEY_RECORD,
  61. [ 0x19 ] = KEY_REWIND,
  62. [ 0x1a ] = KEY_PLAY,
  63. [ 0x1b ] = KEY_FORWARD,
  64. [ 0x1c ] = KEY_BACKSPACE,
  65. [ 0x1e ] = KEY_STOP,
  66. [ 0x40 ] = KEY_ZOOM,
  67. };
  68. /* ----------------------------------------------------------------------- */
  69. static int get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  70. {
  71. unsigned char b;
  72. /* poll IR chip */
  73. if (1 != i2c_master_recv(&ir->c,&b,1)) {
  74. dprintk("read error\n");
  75. return -EIO;
  76. }
  77. /* it seems that 0xFE indicates that a button is still hold
  78. down, while 0xff indicates that no button is hold
  79. down. 0xfe sequences are sometimes interrupted by 0xFF */
  80. dprintk("key %02x\n", b);
  81. if (b == 0xff)
  82. return 0;
  83. if (b == 0xfe)
  84. /* keep old data */
  85. return 1;
  86. *ir_key = b;
  87. *ir_raw = b;
  88. return 1;
  89. }
  90. static int get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  91. {
  92. unsigned char buf[2];
  93. unsigned char code;
  94. /* poll IR chip */
  95. if (2 != i2c_master_recv(&ir->c,buf,2))
  96. return -EIO;
  97. /* Does eliminate repeated parity code */
  98. if (buf[1]==0xff)
  99. return 0;
  100. /* avoid fast reapeating */
  101. if (buf[1]==ir->old)
  102. return 0;
  103. ir->old=buf[1];
  104. /* Rearranges bits to the right order */
  105. code= ((buf[0]&0x01)<<5) | /* 0010 0000 */
  106. ((buf[0]&0x02)<<3) | /* 0001 0000 */
  107. ((buf[0]&0x04)<<1) | /* 0000 1000 */
  108. ((buf[0]&0x08)>>1) | /* 0000 0100 */
  109. ((buf[0]&0x10)>>3) | /* 0000 0010 */
  110. ((buf[0]&0x20)>>5); /* 0000 0001 */
  111. dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n",code,buf[0]);
  112. /* return key */
  113. *ir_key = code;
  114. *ir_raw = code;
  115. return 1;
  116. }
  117. /* ----------------------------------------------------------------------- */
  118. void em2820_set_ir(struct em2820 * dev,struct IR_i2c *ir)
  119. {
  120. if (disable_ir) {
  121. ir->get_key=NULL;
  122. return ;
  123. }
  124. /* detect & configure */
  125. switch (dev->model) {
  126. case (EM2800_BOARD_UNKNOWN):
  127. break;
  128. case (EM2820_BOARD_UNKNOWN):
  129. break;
  130. case (EM2800_BOARD_TERRATEC_CINERGY_200):
  131. case (EM2820_BOARD_TERRATEC_CINERGY_250):
  132. ir->ir_codes = ir_codes_em_terratec;
  133. ir->get_key = get_key_terratec;
  134. snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM2820 Terratec)");
  135. break;
  136. case (EM2820_BOARD_PINNACLE_USB_2):
  137. break;
  138. case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
  139. ir->ir_codes = ir_codes_hauppauge_new;
  140. ir->get_key = get_key_em_haup;
  141. snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM2840 Hauppauge)");
  142. break;
  143. case (EM2820_BOARD_MSI_VOX_USB_2):
  144. break;
  145. case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
  146. break;
  147. case (EM2800_BOARD_KWORLD_USB2800):
  148. break;
  149. }
  150. }
  151. /* ----------------------------------------------------------------------
  152. * Local variables:
  153. * c-basic-offset: 8
  154. * End:
  155. */