em28xx-input.c 4.4 KB

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