em28xx-input.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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@infradead.org>
  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/interrupt.h>
  24. #include <linux/input.h>
  25. #include <linux/usb.h>
  26. #include "em28xx.h"
  27. static unsigned int disable_ir = 0;
  28. module_param(disable_ir, int, 0444);
  29. MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
  30. static unsigned int ir_debug = 0;
  31. module_param(ir_debug, int, 0644);
  32. MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
  33. #define dprintk(fmt, arg...) if (ir_debug) \
  34. printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
  35. /* ----------------------------------------------------------------------- */
  36. static int get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  37. {
  38. unsigned char b;
  39. /* poll IR chip */
  40. if (1 != i2c_master_recv(&ir->c,&b,1)) {
  41. dprintk("read error\n");
  42. return -EIO;
  43. }
  44. /* it seems that 0xFE indicates that a button is still hold
  45. down, while 0xff indicates that no button is hold
  46. down. 0xfe sequences are sometimes interrupted by 0xFF */
  47. dprintk("key %02x\n", b);
  48. if (b == 0xff)
  49. return 0;
  50. if (b == 0xfe)
  51. /* keep old data */
  52. return 1;
  53. *ir_key = b;
  54. *ir_raw = b;
  55. return 1;
  56. }
  57. static int get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  58. {
  59. unsigned char buf[2];
  60. unsigned char code;
  61. /* poll IR chip */
  62. if (2 != i2c_master_recv(&ir->c,buf,2))
  63. return -EIO;
  64. /* Does eliminate repeated parity code */
  65. if (buf[1]==0xff)
  66. return 0;
  67. ir->old=buf[1];
  68. /* Rearranges bits to the right order */
  69. code= ((buf[0]&0x01)<<5) | /* 0010 0000 */
  70. ((buf[0]&0x02)<<3) | /* 0001 0000 */
  71. ((buf[0]&0x04)<<1) | /* 0000 1000 */
  72. ((buf[0]&0x08)>>1) | /* 0000 0100 */
  73. ((buf[0]&0x10)>>3) | /* 0000 0010 */
  74. ((buf[0]&0x20)>>5); /* 0000 0001 */
  75. dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n",code,buf[0]);
  76. /* return key */
  77. *ir_key = code;
  78. *ir_raw = code;
  79. return 1;
  80. }
  81. static int get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  82. {
  83. unsigned char buf[3];
  84. /* poll IR chip */
  85. if (3 != i2c_master_recv(&ir->c,buf,3)) {
  86. dprintk("read error\n");
  87. return -EIO;
  88. }
  89. dprintk("key %02x\n", buf[2]&0x3f);
  90. if (buf[0]!=0x00){
  91. return 0;
  92. }
  93. *ir_key = buf[2]&0x3f;
  94. *ir_raw = buf[2]&0x3f;
  95. return 1;
  96. }
  97. /* ----------------------------------------------------------------------- */
  98. void em28xx_set_ir(struct em28xx * dev,struct IR_i2c *ir)
  99. {
  100. if (disable_ir) {
  101. ir->get_key=NULL;
  102. return ;
  103. }
  104. /* detect & configure */
  105. switch (dev->model) {
  106. case (EM2800_BOARD_UNKNOWN):
  107. break;
  108. case (EM2820_BOARD_UNKNOWN):
  109. break;
  110. case (EM2800_BOARD_TERRATEC_CINERGY_200):
  111. case (EM2820_BOARD_TERRATEC_CINERGY_250):
  112. ir->ir_codes = ir_codes_em_terratec;
  113. ir->get_key = get_key_terratec;
  114. snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM28XX Terratec)");
  115. break;
  116. case (EM2820_BOARD_PINNACLE_USB_2):
  117. ir->ir_codes = ir_codes_pinnacle_grey;
  118. ir->get_key = get_key_pinnacle_usb_grey;
  119. snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM28XX Pinnacle PCTV)");
  120. break;
  121. case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
  122. ir->ir_codes = ir_codes_hauppauge_new;
  123. ir->get_key = get_key_em_haup;
  124. snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM2840 Hauppauge)");
  125. break;
  126. case (EM2820_BOARD_MSI_VOX_USB_2):
  127. break;
  128. case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
  129. break;
  130. case (EM2800_BOARD_KWORLD_USB2800):
  131. break;
  132. }
  133. }
  134. /* ----------------------------------------------------------------------
  135. * Local variables:
  136. * c-basic-offset: 8
  137. * End:
  138. */