saa7134-input.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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 "saa7134-reg.h"
  28. #include "saa7134.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. static int pinnacle_remote = 0;
  36. module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
  37. MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
  38. #define dprintk(fmt, arg...) if (ir_debug) \
  39. printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
  40. #define i2cdprintk(fmt, arg...) if (ir_debug) \
  41. printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
  42. /* -------------------- GPIO generic keycode builder -------------------- */
  43. static int build_key(struct saa7134_dev *dev)
  44. {
  45. struct saa7134_ir *ir = dev->remote;
  46. u32 gpio, data;
  47. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  48. saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
  49. saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
  50. gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
  51. if (ir->polling) {
  52. if (ir->last_gpio == gpio)
  53. return 0;
  54. ir->last_gpio = gpio;
  55. }
  56. data = ir_extract_bits(gpio, ir->mask_keycode);
  57. dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
  58. gpio, ir->mask_keycode, data);
  59. if (ir->polling) {
  60. if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
  61. (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
  62. ir_input_keydown(ir->dev, &ir->ir, data, data);
  63. } else {
  64. ir_input_nokey(ir->dev, &ir->ir);
  65. }
  66. }
  67. else { /* IRQ driven mode - handle key press and release in one go */
  68. if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
  69. (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
  70. ir_input_keydown(ir->dev, &ir->ir, data, data);
  71. ir_input_nokey(ir->dev, &ir->ir);
  72. }
  73. }
  74. return 0;
  75. }
  76. /* --------------------- Chip specific I2C key builders ----------------- */
  77. static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  78. {
  79. unsigned char b;
  80. /* poll IR chip */
  81. if (1 != i2c_master_recv(&ir->c,&b,1)) {
  82. i2cdprintk("read error\n");
  83. return -EIO;
  84. }
  85. /* no button press */
  86. if (b==0)
  87. return 0;
  88. /* repeating */
  89. if (b & 0x80)
  90. return 1;
  91. *ir_key = b;
  92. *ir_raw = b;
  93. return 1;
  94. }
  95. void saa7134_input_irq(struct saa7134_dev *dev)
  96. {
  97. struct saa7134_ir *ir = dev->remote;
  98. if (!ir->polling)
  99. build_key(dev);
  100. }
  101. static void saa7134_input_timer(unsigned long data)
  102. {
  103. struct saa7134_dev *dev = (struct saa7134_dev*)data;
  104. struct saa7134_ir *ir = dev->remote;
  105. unsigned long timeout;
  106. build_key(dev);
  107. timeout = jiffies + (ir->polling * HZ / 1000);
  108. mod_timer(&ir->timer, timeout);
  109. }
  110. int saa7134_input_init1(struct saa7134_dev *dev)
  111. {
  112. struct saa7134_ir *ir;
  113. struct input_dev *input_dev;
  114. IR_KEYTAB_TYPE *ir_codes = NULL;
  115. u32 mask_keycode = 0;
  116. u32 mask_keydown = 0;
  117. u32 mask_keyup = 0;
  118. int polling = 0;
  119. int ir_type = IR_TYPE_OTHER;
  120. if (dev->has_remote != SAA7134_REMOTE_GPIO)
  121. return -ENODEV;
  122. if (disable_ir)
  123. return -ENODEV;
  124. /* detect & configure */
  125. switch (dev->board) {
  126. case SAA7134_BOARD_FLYVIDEO2000:
  127. case SAA7134_BOARD_FLYVIDEO3000:
  128. case SAA7134_BOARD_FLYTVPLATINUM_FM:
  129. case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
  130. ir_codes = ir_codes_flyvideo;
  131. mask_keycode = 0xEC00000;
  132. mask_keydown = 0x0040000;
  133. break;
  134. case SAA7134_BOARD_CINERGY400:
  135. case SAA7134_BOARD_CINERGY600:
  136. case SAA7134_BOARD_CINERGY600_MK3:
  137. ir_codes = ir_codes_cinergy;
  138. mask_keycode = 0x00003f;
  139. mask_keyup = 0x040000;
  140. break;
  141. case SAA7134_BOARD_ECS_TVP3XP:
  142. case SAA7134_BOARD_ECS_TVP3XP_4CB5:
  143. ir_codes = ir_codes_eztv;
  144. mask_keycode = 0x00017c;
  145. mask_keyup = 0x000002;
  146. polling = 50; // ms
  147. break;
  148. case SAA7134_BOARD_KWORLD_XPERT:
  149. case SAA7134_BOARD_AVACSSMARTTV:
  150. ir_codes = ir_codes_pixelview;
  151. mask_keycode = 0x00001F;
  152. mask_keyup = 0x000020;
  153. polling = 50; // ms
  154. break;
  155. case SAA7134_BOARD_MD2819:
  156. case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
  157. case SAA7134_BOARD_AVERMEDIA_305:
  158. case SAA7134_BOARD_AVERMEDIA_307:
  159. case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
  160. case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
  161. case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
  162. case SAA7134_BOARD_AVERMEDIA_A16AR:
  163. ir_codes = ir_codes_avermedia;
  164. mask_keycode = 0x0007C8;
  165. mask_keydown = 0x000010;
  166. polling = 50; // ms
  167. /* Set GPIO pin2 to high to enable the IR controller */
  168. saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
  169. saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
  170. break;
  171. case SAA7134_BOARD_KWORLD_TERMINATOR:
  172. ir_codes = ir_codes_pixelview;
  173. mask_keycode = 0x00001f;
  174. mask_keyup = 0x000060;
  175. polling = 50; // ms
  176. break;
  177. case SAA7134_BOARD_MANLI_MTV001:
  178. case SAA7134_BOARD_MANLI_MTV002:
  179. case SAA7134_BOARD_BEHOLD_409FM:
  180. ir_codes = ir_codes_manli;
  181. mask_keycode = 0x001f00;
  182. mask_keyup = 0x004000;
  183. polling = 50; // ms
  184. break;
  185. case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
  186. ir_codes = ir_codes_pctv_sedna;
  187. mask_keycode = 0x001f00;
  188. mask_keyup = 0x004000;
  189. polling = 50; // ms
  190. break;
  191. case SAA7134_BOARD_GOTVIEW_7135:
  192. ir_codes = ir_codes_gotview7135;
  193. mask_keycode = 0x0003EC;
  194. mask_keyup = 0x008000;
  195. mask_keydown = 0x000010;
  196. polling = 50; // ms
  197. break;
  198. case SAA7134_BOARD_VIDEOMATE_TV_PVR:
  199. case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
  200. case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
  201. ir_codes = ir_codes_videomate_tv_pvr;
  202. mask_keycode = 0x00003F;
  203. mask_keyup = 0x400000;
  204. polling = 50; // ms
  205. break;
  206. case SAA7134_BOARD_PROTEUS_2309:
  207. ir_codes = ir_codes_proteus_2309;
  208. mask_keycode = 0x00007F;
  209. mask_keyup = 0x000080;
  210. polling = 50; // ms
  211. break;
  212. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  213. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  214. ir_codes = ir_codes_videomate_tv_pvr;
  215. mask_keycode = 0x003F00;
  216. mask_keyup = 0x040000;
  217. break;
  218. case SAA7134_BOARD_FLYDVBT_LR301:
  219. case SAA7134_BOARD_FLYDVBTDUO:
  220. ir_codes = ir_codes_flydvb;
  221. mask_keycode = 0x0001F00;
  222. mask_keydown = 0x0040000;
  223. break;
  224. }
  225. if (NULL == ir_codes) {
  226. printk("%s: Oops: IR config error [card=%d]\n",
  227. dev->name, dev->board);
  228. return -ENODEV;
  229. }
  230. ir = kzalloc(sizeof(*ir), GFP_KERNEL);
  231. input_dev = input_allocate_device();
  232. if (!ir || !input_dev) {
  233. kfree(ir);
  234. input_free_device(input_dev);
  235. return -ENOMEM;
  236. }
  237. ir->dev = input_dev;
  238. /* init hardware-specific stuff */
  239. ir->mask_keycode = mask_keycode;
  240. ir->mask_keydown = mask_keydown;
  241. ir->mask_keyup = mask_keyup;
  242. ir->polling = polling;
  243. /* init input device */
  244. snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
  245. saa7134_boards[dev->board].name);
  246. snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
  247. pci_name(dev->pci));
  248. ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
  249. input_dev->name = ir->name;
  250. input_dev->phys = ir->phys;
  251. input_dev->id.bustype = BUS_PCI;
  252. input_dev->id.version = 1;
  253. if (dev->pci->subsystem_vendor) {
  254. input_dev->id.vendor = dev->pci->subsystem_vendor;
  255. input_dev->id.product = dev->pci->subsystem_device;
  256. } else {
  257. input_dev->id.vendor = dev->pci->vendor;
  258. input_dev->id.product = dev->pci->device;
  259. }
  260. input_dev->cdev.dev = &dev->pci->dev;
  261. /* all done */
  262. dev->remote = ir;
  263. if (ir->polling) {
  264. init_timer(&ir->timer);
  265. ir->timer.function = saa7134_input_timer;
  266. ir->timer.data = (unsigned long)dev;
  267. ir->timer.expires = jiffies + HZ;
  268. add_timer(&ir->timer);
  269. }
  270. input_register_device(ir->dev);
  271. return 0;
  272. }
  273. void saa7134_input_fini(struct saa7134_dev *dev)
  274. {
  275. if (NULL == dev->remote)
  276. return;
  277. if (dev->remote->polling)
  278. del_timer_sync(&dev->remote->timer);
  279. input_unregister_device(dev->remote->dev);
  280. kfree(dev->remote);
  281. dev->remote = NULL;
  282. }
  283. void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
  284. {
  285. if (disable_ir) {
  286. dprintk("Found supported i2c remote, but IR has been disabled\n");
  287. ir->get_key=NULL;
  288. return;
  289. }
  290. switch (dev->board) {
  291. case SAA7134_BOARD_PINNACLE_PCTV_110i:
  292. snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV");
  293. if (pinnacle_remote == 0) {
  294. ir->get_key = get_key_pinnacle_color;
  295. ir->ir_codes = ir_codes_pinnacle_color;
  296. } else {
  297. ir->get_key = get_key_pinnacle_grey;
  298. ir->ir_codes = ir_codes_pinnacle_grey;
  299. }
  300. break;
  301. case SAA7134_BOARD_UPMOST_PURPLE_TV:
  302. snprintf(ir->c.name, sizeof(ir->c.name), "Purple TV");
  303. ir->get_key = get_key_purpletv;
  304. ir->ir_codes = ir_codes_purpletv;
  305. break;
  306. default:
  307. dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board);
  308. break;
  309. }
  310. }
  311. /* ----------------------------------------------------------------------
  312. * Local variables:
  313. * c-basic-offset: 8
  314. * End:
  315. */