em28xx-input.c 4.7 KB

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