em28xx-input.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. static IR_KEYTAB_TYPE ir_codes_em_pinnacle_usb[IR_KEYTAB_SIZE] = {
  68. [ 0x3a ] = KEY_KP0,
  69. [ 0x31 ] = KEY_KP1,
  70. [ 0x32 ] = KEY_KP2,
  71. [ 0x33 ] = KEY_KP3,
  72. [ 0x34 ] = KEY_KP4,
  73. [ 0x35 ] = KEY_KP5,
  74. [ 0x36 ] = KEY_KP6,
  75. [ 0x37 ] = KEY_KP7,
  76. [ 0x38 ] = KEY_KP8,
  77. [ 0x39 ] = KEY_KP9,
  78. [ 0x2f ] = KEY_POWER,
  79. [ 0x2e ] = KEY_P,
  80. [ 0x1f ] = KEY_L,
  81. [ 0x2b ] = KEY_I,
  82. [ 0x2d ] = KEY_ZOOM,
  83. [ 0x1e ] = KEY_ZOOM,
  84. [ 0x1b ] = KEY_VOLUMEUP,
  85. [ 0x0f ] = KEY_VOLUMEDOWN,
  86. [ 0x17 ] = KEY_CHANNELUP,
  87. [ 0x1c ] = KEY_CHANNELDOWN,
  88. [ 0x25 ] = KEY_INFO,
  89. [ 0x3c ] = KEY_MUTE,
  90. [ 0x3d ] = KEY_LEFT,
  91. [ 0x3b ] = KEY_RIGHT,
  92. [ 0x3f ] = KEY_UP,
  93. [ 0x3e ] = KEY_DOWN,
  94. [ 0x1a ] = KEY_PAUSE,
  95. [ 0x1d ] = KEY_MENU,
  96. [ 0x19 ] = KEY_PLAY,
  97. [ 0x16 ] = KEY_REWIND,
  98. [ 0x13 ] = KEY_FORWARD,
  99. [ 0x15 ] = KEY_PAUSE,
  100. [ 0x0e ] = KEY_REWIND,
  101. [ 0x0d ] = KEY_PLAY,
  102. [ 0x0b ] = KEY_STOP,
  103. [ 0x07 ] = KEY_FORWARD,
  104. [ 0x27 ] = KEY_RECORD,
  105. [ 0x26 ] = KEY_TUNER,
  106. [ 0x29 ] = KEY_TEXT,
  107. [ 0x2a ] = KEY_MEDIA,
  108. [ 0x18 ] = KEY_EPG,
  109. [ 0x27 ] = KEY_RECORD,
  110. };
  111. /* ----------------------------------------------------------------------- */
  112. static int get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  113. {
  114. unsigned char b;
  115. /* poll IR chip */
  116. if (1 != i2c_master_recv(&ir->c,&b,1)) {
  117. dprintk("read error\n");
  118. return -EIO;
  119. }
  120. /* it seems that 0xFE indicates that a button is still hold
  121. down, while 0xff indicates that no button is hold
  122. down. 0xfe sequences are sometimes interrupted by 0xFF */
  123. dprintk("key %02x\n", b);
  124. if (b == 0xff)
  125. return 0;
  126. if (b == 0xfe)
  127. /* keep old data */
  128. return 1;
  129. *ir_key = b;
  130. *ir_raw = b;
  131. return 1;
  132. }
  133. static int get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  134. {
  135. unsigned char buf[2];
  136. unsigned char code;
  137. /* poll IR chip */
  138. if (2 != i2c_master_recv(&ir->c,buf,2))
  139. return -EIO;
  140. /* Does eliminate repeated parity code */
  141. if (buf[1]==0xff)
  142. return 0;
  143. ir->old=buf[1];
  144. /* Rearranges bits to the right order */
  145. code= ((buf[0]&0x01)<<5) | /* 0010 0000 */
  146. ((buf[0]&0x02)<<3) | /* 0001 0000 */
  147. ((buf[0]&0x04)<<1) | /* 0000 1000 */
  148. ((buf[0]&0x08)>>1) | /* 0000 0100 */
  149. ((buf[0]&0x10)>>3) | /* 0000 0010 */
  150. ((buf[0]&0x20)>>5); /* 0000 0001 */
  151. dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n",code,buf[0]);
  152. /* return key */
  153. *ir_key = code;
  154. *ir_raw = code;
  155. return 1;
  156. }
  157. static int get_key_pinnacle_usb(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  158. {
  159. unsigned char buf[3];
  160. /* poll IR chip */
  161. if (3 != i2c_master_recv(&ir->c,buf,3)) {
  162. dprintk("read error\n");
  163. return -EIO;
  164. }
  165. dprintk("key %02x\n", buf[2]&0x3f);
  166. if (buf[0]!=0x00){
  167. return 0;
  168. }
  169. *ir_key = buf[2]&0x3f;
  170. *ir_raw = buf[2]&0x3f;
  171. return 1;
  172. }
  173. /* ----------------------------------------------------------------------- */
  174. void em28xx_set_ir(struct em28xx * dev,struct IR_i2c *ir)
  175. {
  176. if (disable_ir) {
  177. ir->get_key=NULL;
  178. return ;
  179. }
  180. /* detect & configure */
  181. switch (dev->model) {
  182. case (EM2800_BOARD_UNKNOWN):
  183. break;
  184. case (EM2820_BOARD_UNKNOWN):
  185. break;
  186. case (EM2800_BOARD_TERRATEC_CINERGY_200):
  187. case (EM2820_BOARD_TERRATEC_CINERGY_250):
  188. ir->ir_codes = ir_codes_em_terratec;
  189. ir->get_key = get_key_terratec;
  190. snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM28XX Terratec)");
  191. break;
  192. case (EM2820_BOARD_PINNACLE_USB_2):
  193. ir->ir_codes = ir_codes_em_pinnacle_usb;
  194. ir->get_key = get_key_pinnacle_usb;
  195. snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM28XX Pinnacle PCTV)");
  196. break;
  197. case (EM2820_BOARD_HAUPPAUGE_WINTV_USB_2):
  198. ir->ir_codes = ir_codes_hauppauge_new;
  199. ir->get_key = get_key_em_haup;
  200. snprintf(ir->c.name, sizeof(ir->c.name), "i2c IR (EM2840 Hauppauge)");
  201. break;
  202. case (EM2820_BOARD_MSI_VOX_USB_2):
  203. break;
  204. case (EM2800_BOARD_LEADTEK_WINFAST_USBII):
  205. break;
  206. case (EM2800_BOARD_KWORLD_USB2800):
  207. break;
  208. }
  209. }
  210. /* ----------------------------------------------------------------------
  211. * Local variables:
  212. * c-basic-offset: 8
  213. * End:
  214. */