saa7134-input.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  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/init.h>
  22. #include <linux/delay.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/input.h>
  25. #include "saa7134-reg.h"
  26. #include "saa7134.h"
  27. static unsigned int disable_ir;
  28. module_param(disable_ir, int, 0444);
  29. MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
  30. static unsigned int ir_debug;
  31. module_param(ir_debug, int, 0644);
  32. MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
  33. static int pinnacle_remote;
  34. module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
  35. MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
  36. static int ir_rc5_remote_gap = 885;
  37. module_param(ir_rc5_remote_gap, int, 0644);
  38. static int ir_rc5_key_timeout = 115;
  39. module_param(ir_rc5_key_timeout, int, 0644);
  40. static int repeat_delay = 500;
  41. module_param(repeat_delay, int, 0644);
  42. MODULE_PARM_DESC(repeat_delay, "delay before key repeat started");
  43. static int repeat_period = 33;
  44. module_param(repeat_period, int, 0644);
  45. MODULE_PARM_DESC(repeat_period, "repeat period between "
  46. "keypresses when key is down");
  47. static unsigned int disable_other_ir;
  48. module_param(disable_other_ir, int, 0644);
  49. MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
  50. "alternative remotes from other manufacturers");
  51. #define dprintk(fmt, arg...) if (ir_debug) \
  52. printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
  53. #define i2cdprintk(fmt, arg...) if (ir_debug) \
  54. printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
  55. /** rc5 functions */
  56. static int saa7134_rc5_irq(struct saa7134_dev *dev);
  57. /* -------------------- GPIO generic keycode builder -------------------- */
  58. static int build_key(struct saa7134_dev *dev)
  59. {
  60. struct card_ir *ir = dev->remote;
  61. u32 gpio, data;
  62. /* here comes the additional handshake steps for some cards */
  63. switch (dev->board) {
  64. case SAA7134_BOARD_GOTVIEW_7135:
  65. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80);
  66. saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80);
  67. break;
  68. }
  69. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  70. saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
  71. saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
  72. gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
  73. if (ir->polling) {
  74. if (ir->last_gpio == gpio)
  75. return 0;
  76. ir->last_gpio = gpio;
  77. }
  78. data = ir_extract_bits(gpio, ir->mask_keycode);
  79. dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
  80. gpio, ir->mask_keycode, data);
  81. if (ir->polling) {
  82. if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
  83. (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
  84. ir_input_keydown(ir->dev, &ir->ir, data, data);
  85. } else {
  86. ir_input_nokey(ir->dev, &ir->ir);
  87. }
  88. }
  89. else { /* IRQ driven mode - handle key press and release in one go */
  90. if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
  91. (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
  92. ir_input_keydown(ir->dev, &ir->ir, data, data);
  93. ir_input_nokey(ir->dev, &ir->ir);
  94. }
  95. }
  96. return 0;
  97. }
  98. /* --------------------- Chip specific I2C key builders ----------------- */
  99. static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  100. {
  101. unsigned char b;
  102. /* poll IR chip */
  103. if (1 != i2c_master_recv(&ir->c,&b,1)) {
  104. i2cdprintk("read error\n");
  105. return -EIO;
  106. }
  107. /* no button press */
  108. if (b==0)
  109. return 0;
  110. /* repeating */
  111. if (b & 0x80)
  112. return 1;
  113. *ir_key = b;
  114. *ir_raw = b;
  115. return 1;
  116. }
  117. static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  118. {
  119. unsigned char buf[5], cod4, code3, code4;
  120. /* poll IR chip */
  121. if (5 != i2c_master_recv(&ir->c,buf,5))
  122. return -EIO;
  123. cod4 = buf[4];
  124. code4 = (cod4 >> 2);
  125. code3 = buf[3];
  126. if (code3 == 0)
  127. /* no key pressed */
  128. return 0;
  129. /* return key */
  130. *ir_key = code4;
  131. *ir_raw = code4;
  132. return 1;
  133. }
  134. static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  135. {
  136. unsigned char data[12];
  137. u32 gpio;
  138. struct saa7134_dev *dev = ir->c.adapter->algo_data;
  139. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  140. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  141. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  142. gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
  143. if (0x400000 & ~gpio)
  144. return 0; /* No button press */
  145. ir->c.addr = 0x5a >> 1;
  146. if (12 != i2c_master_recv(&ir->c, data, 12)) {
  147. i2cdprintk("read error\n");
  148. return -EIO;
  149. }
  150. /* IR of this card normally decode signals NEC-standard from
  151. * - Sven IHOO MT 5.1R remote. xxyye718
  152. * - Sven DVD HD-10xx remote. xxyyf708
  153. * - BBK ...
  154. * - mayby others
  155. * So, skip not our, if disable full codes mode.
  156. */
  157. if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir)
  158. return 0;
  159. *ir_key = data[9];
  160. *ir_raw = data[9];
  161. return 1;
  162. }
  163. /* Common (grey or coloured) pinnacle PCTV remote handling
  164. *
  165. */
  166. static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
  167. int parity_offset, int marker, int code_modulo)
  168. {
  169. unsigned char b[4];
  170. unsigned int start = 0,parity = 0,code = 0;
  171. /* poll IR chip */
  172. if (4 != i2c_master_recv(&ir->c, b, 4)) {
  173. i2cdprintk("read error\n");
  174. return -EIO;
  175. }
  176. for (start = 0; start < ARRAY_SIZE(b); start++) {
  177. if (b[start] == marker) {
  178. code=b[(start+parity_offset + 1) % 4];
  179. parity=b[(start+parity_offset) % 4];
  180. }
  181. }
  182. /* Empty Request */
  183. if (parity == 0)
  184. return 0;
  185. /* Repeating... */
  186. if (ir->old == parity)
  187. return 0;
  188. ir->old = parity;
  189. /* drop special codes when a key is held down a long time for the grey controller
  190. In this case, the second bit of the code is asserted */
  191. if (marker == 0xfe && (code & 0x40))
  192. return 0;
  193. code %= code_modulo;
  194. *ir_raw = code;
  195. *ir_key = code;
  196. i2cdprintk("Pinnacle PCTV key %02x\n", code);
  197. return 1;
  198. }
  199. /* The grey pinnacle PCTV remote
  200. *
  201. * There are one issue with this remote:
  202. * - I2c packet does not change when the same key is pressed quickly. The workaround
  203. * is to hold down each key for about half a second, so that another code is generated
  204. * in the i2c packet, and the function can distinguish key presses.
  205. *
  206. * Sylvain Pasche <sylvain.pasche@gmail.com>
  207. */
  208. static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  209. {
  210. return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff);
  211. }
  212. /* The new pinnacle PCTV remote (with the colored buttons)
  213. *
  214. * Ricardo Cerqueira <v4l@cerqueira.org>
  215. */
  216. static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  217. {
  218. /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
  219. *
  220. * this is the only value that results in 42 unique
  221. * codes < 128
  222. */
  223. return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
  224. }
  225. void saa7134_input_irq(struct saa7134_dev *dev)
  226. {
  227. struct card_ir *ir = dev->remote;
  228. if (!ir->polling && !ir->rc5_gpio) {
  229. build_key(dev);
  230. } else if (ir->rc5_gpio) {
  231. saa7134_rc5_irq(dev);
  232. }
  233. }
  234. static void saa7134_input_timer(unsigned long data)
  235. {
  236. struct saa7134_dev *dev = (struct saa7134_dev *)data;
  237. struct card_ir *ir = dev->remote;
  238. build_key(dev);
  239. mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
  240. }
  241. void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
  242. {
  243. if (ir->polling) {
  244. setup_timer(&ir->timer, saa7134_input_timer,
  245. (unsigned long)dev);
  246. ir->timer.expires = jiffies + HZ;
  247. add_timer(&ir->timer);
  248. } else if (ir->rc5_gpio) {
  249. /* set timer_end for code completion */
  250. init_timer(&ir->timer_end);
  251. ir->timer_end.function = ir_rc5_timer_end;
  252. ir->timer_end.data = (unsigned long)ir;
  253. init_timer(&ir->timer_keyup);
  254. ir->timer_keyup.function = ir_rc5_timer_keyup;
  255. ir->timer_keyup.data = (unsigned long)ir;
  256. ir->shift_by = 2;
  257. ir->start = 0x2;
  258. ir->addr = 0x17;
  259. ir->rc5_key_timeout = ir_rc5_key_timeout;
  260. ir->rc5_remote_gap = ir_rc5_remote_gap;
  261. }
  262. }
  263. void saa7134_ir_stop(struct saa7134_dev *dev)
  264. {
  265. if (dev->remote->polling)
  266. del_timer_sync(&dev->remote->timer);
  267. }
  268. int saa7134_input_init1(struct saa7134_dev *dev)
  269. {
  270. struct card_ir *ir;
  271. struct input_dev *input_dev;
  272. IR_KEYTAB_TYPE *ir_codes = NULL;
  273. u32 mask_keycode = 0;
  274. u32 mask_keydown = 0;
  275. u32 mask_keyup = 0;
  276. int polling = 0;
  277. int rc5_gpio = 0;
  278. int ir_type = IR_TYPE_OTHER;
  279. int err;
  280. if (dev->has_remote != SAA7134_REMOTE_GPIO)
  281. return -ENODEV;
  282. if (disable_ir)
  283. return -ENODEV;
  284. /* detect & configure */
  285. switch (dev->board) {
  286. case SAA7134_BOARD_FLYVIDEO2000:
  287. case SAA7134_BOARD_FLYVIDEO3000:
  288. case SAA7134_BOARD_FLYTVPLATINUM_FM:
  289. case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
  290. ir_codes = ir_codes_flyvideo;
  291. mask_keycode = 0xEC00000;
  292. mask_keydown = 0x0040000;
  293. break;
  294. case SAA7134_BOARD_CINERGY400:
  295. case SAA7134_BOARD_CINERGY600:
  296. case SAA7134_BOARD_CINERGY600_MK3:
  297. ir_codes = ir_codes_cinergy;
  298. mask_keycode = 0x00003f;
  299. mask_keyup = 0x040000;
  300. break;
  301. case SAA7134_BOARD_ECS_TVP3XP:
  302. case SAA7134_BOARD_ECS_TVP3XP_4CB5:
  303. ir_codes = ir_codes_eztv;
  304. mask_keycode = 0x00017c;
  305. mask_keyup = 0x000002;
  306. polling = 50; // ms
  307. break;
  308. case SAA7134_BOARD_KWORLD_XPERT:
  309. case SAA7134_BOARD_AVACSSMARTTV:
  310. ir_codes = ir_codes_pixelview;
  311. mask_keycode = 0x00001F;
  312. mask_keyup = 0x000020;
  313. polling = 50; // ms
  314. break;
  315. case SAA7134_BOARD_MD2819:
  316. case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
  317. case SAA7134_BOARD_AVERMEDIA_305:
  318. case SAA7134_BOARD_AVERMEDIA_307:
  319. case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
  320. case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
  321. case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
  322. case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
  323. case SAA7134_BOARD_AVERMEDIA_M102:
  324. ir_codes = ir_codes_avermedia;
  325. mask_keycode = 0x0007C8;
  326. mask_keydown = 0x000010;
  327. polling = 50; // ms
  328. /* Set GPIO pin2 to high to enable the IR controller */
  329. saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
  330. saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
  331. break;
  332. case SAA7134_BOARD_AVERMEDIA_777:
  333. case SAA7134_BOARD_AVERMEDIA_A16AR:
  334. ir_codes = ir_codes_avermedia;
  335. mask_keycode = 0x02F200;
  336. mask_keydown = 0x000400;
  337. polling = 50; // ms
  338. /* Without this we won't receive key up events */
  339. saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
  340. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
  341. break;
  342. case SAA7134_BOARD_AVERMEDIA_A16D:
  343. ir_codes = ir_codes_avermedia_a16d;
  344. mask_keycode = 0x02F200;
  345. mask_keydown = 0x000400;
  346. polling = 50; /* ms */
  347. /* Without this we won't receive key up events */
  348. saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
  349. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
  350. break;
  351. case SAA7134_BOARD_KWORLD_TERMINATOR:
  352. ir_codes = ir_codes_pixelview;
  353. mask_keycode = 0x00001f;
  354. mask_keyup = 0x000060;
  355. polling = 50; // ms
  356. break;
  357. case SAA7134_BOARD_MANLI_MTV001:
  358. case SAA7134_BOARD_MANLI_MTV002:
  359. ir_codes = ir_codes_manli;
  360. mask_keycode = 0x001f00;
  361. mask_keyup = 0x004000;
  362. polling = 50; /* ms */
  363. break;
  364. case SAA7134_BOARD_BEHOLD_409FM:
  365. case SAA7134_BOARD_BEHOLD_401:
  366. case SAA7134_BOARD_BEHOLD_403:
  367. case SAA7134_BOARD_BEHOLD_403FM:
  368. case SAA7134_BOARD_BEHOLD_405:
  369. case SAA7134_BOARD_BEHOLD_405FM:
  370. case SAA7134_BOARD_BEHOLD_407:
  371. case SAA7134_BOARD_BEHOLD_407FM:
  372. case SAA7134_BOARD_BEHOLD_409:
  373. case SAA7134_BOARD_BEHOLD_505FM:
  374. case SAA7134_BOARD_BEHOLD_507_9FM:
  375. ir_codes = ir_codes_manli;
  376. mask_keycode = 0x003f00;
  377. mask_keyup = 0x004000;
  378. polling = 50; /* ms */
  379. break;
  380. case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
  381. ir_codes = ir_codes_behold_columbus;
  382. mask_keycode = 0x003f00;
  383. mask_keyup = 0x004000;
  384. polling = 50; // ms
  385. break;
  386. case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
  387. ir_codes = ir_codes_pctv_sedna;
  388. mask_keycode = 0x001f00;
  389. mask_keyup = 0x004000;
  390. polling = 50; // ms
  391. break;
  392. case SAA7134_BOARD_GOTVIEW_7135:
  393. ir_codes = ir_codes_gotview7135;
  394. mask_keycode = 0x0003CC;
  395. mask_keydown = 0x000010;
  396. polling = 5; /* ms */
  397. saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
  398. break;
  399. case SAA7134_BOARD_VIDEOMATE_TV_PVR:
  400. case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
  401. case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
  402. ir_codes = ir_codes_videomate_tv_pvr;
  403. mask_keycode = 0x00003F;
  404. mask_keyup = 0x400000;
  405. polling = 50; // ms
  406. break;
  407. case SAA7134_BOARD_PROTEUS_2309:
  408. ir_codes = ir_codes_proteus_2309;
  409. mask_keycode = 0x00007F;
  410. mask_keyup = 0x000080;
  411. polling = 50; // ms
  412. break;
  413. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  414. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  415. ir_codes = ir_codes_videomate_tv_pvr;
  416. mask_keycode = 0x003F00;
  417. mask_keyup = 0x040000;
  418. break;
  419. case SAA7134_BOARD_FLYDVBS_LR300:
  420. case SAA7134_BOARD_FLYDVBT_LR301:
  421. case SAA7134_BOARD_FLYDVBTDUO:
  422. ir_codes = ir_codes_flydvb;
  423. mask_keycode = 0x0001F00;
  424. mask_keydown = 0x0040000;
  425. break;
  426. case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
  427. case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
  428. case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
  429. ir_codes = ir_codes_asus_pc39;
  430. mask_keydown = 0x0040000;
  431. rc5_gpio = 1;
  432. break;
  433. case SAA7134_BOARD_ENCORE_ENLTV:
  434. case SAA7134_BOARD_ENCORE_ENLTV_FM:
  435. ir_codes = ir_codes_encore_enltv;
  436. mask_keycode = 0x00007f;
  437. mask_keyup = 0x040000;
  438. polling = 50; // ms
  439. break;
  440. case SAA7134_BOARD_10MOONSTVMASTER3:
  441. ir_codes = ir_codes_encore_enltv;
  442. mask_keycode = 0x5f80000;
  443. mask_keyup = 0x8000000;
  444. polling = 50; //ms
  445. break;
  446. case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
  447. ir_codes = ir_codes_genius_tvgo_a11mce;
  448. mask_keycode = 0xff;
  449. mask_keydown = 0xf00000;
  450. polling = 50; /* ms */
  451. break;
  452. }
  453. if (NULL == ir_codes) {
  454. printk("%s: Oops: IR config error [card=%d]\n",
  455. dev->name, dev->board);
  456. return -ENODEV;
  457. }
  458. ir = kzalloc(sizeof(*ir), GFP_KERNEL);
  459. input_dev = input_allocate_device();
  460. if (!ir || !input_dev) {
  461. err = -ENOMEM;
  462. goto err_out_free;
  463. }
  464. ir->dev = input_dev;
  465. /* init hardware-specific stuff */
  466. ir->mask_keycode = mask_keycode;
  467. ir->mask_keydown = mask_keydown;
  468. ir->mask_keyup = mask_keyup;
  469. ir->polling = polling;
  470. ir->rc5_gpio = rc5_gpio;
  471. /* init input device */
  472. snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
  473. saa7134_boards[dev->board].name);
  474. snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
  475. pci_name(dev->pci));
  476. ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
  477. input_dev->name = ir->name;
  478. input_dev->phys = ir->phys;
  479. input_dev->id.bustype = BUS_PCI;
  480. input_dev->id.version = 1;
  481. if (dev->pci->subsystem_vendor) {
  482. input_dev->id.vendor = dev->pci->subsystem_vendor;
  483. input_dev->id.product = dev->pci->subsystem_device;
  484. } else {
  485. input_dev->id.vendor = dev->pci->vendor;
  486. input_dev->id.product = dev->pci->device;
  487. }
  488. input_dev->dev.parent = &dev->pci->dev;
  489. dev->remote = ir;
  490. saa7134_ir_start(dev, ir);
  491. err = input_register_device(ir->dev);
  492. if (err)
  493. goto err_out_stop;
  494. /* the remote isn't as bouncy as a keyboard */
  495. ir->dev->rep[REP_DELAY] = repeat_delay;
  496. ir->dev->rep[REP_PERIOD] = repeat_period;
  497. return 0;
  498. err_out_stop:
  499. saa7134_ir_stop(dev);
  500. dev->remote = NULL;
  501. err_out_free:
  502. input_free_device(input_dev);
  503. kfree(ir);
  504. return err;
  505. }
  506. void saa7134_input_fini(struct saa7134_dev *dev)
  507. {
  508. if (NULL == dev->remote)
  509. return;
  510. saa7134_ir_stop(dev);
  511. input_unregister_device(dev->remote->dev);
  512. kfree(dev->remote);
  513. dev->remote = NULL;
  514. }
  515. void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
  516. {
  517. if (disable_ir) {
  518. dprintk("Found supported i2c remote, but IR has been disabled\n");
  519. ir->get_key=NULL;
  520. return;
  521. }
  522. switch (dev->board) {
  523. case SAA7134_BOARD_PINNACLE_PCTV_110i:
  524. case SAA7134_BOARD_PINNACLE_PCTV_310i:
  525. snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV");
  526. if (pinnacle_remote == 0) {
  527. ir->get_key = get_key_pinnacle_color;
  528. ir->ir_codes = ir_codes_pinnacle_color;
  529. } else {
  530. ir->get_key = get_key_pinnacle_grey;
  531. ir->ir_codes = ir_codes_pinnacle_grey;
  532. }
  533. break;
  534. case SAA7134_BOARD_UPMOST_PURPLE_TV:
  535. snprintf(ir->c.name, sizeof(ir->c.name), "Purple TV");
  536. ir->get_key = get_key_purpletv;
  537. ir->ir_codes = ir_codes_purpletv;
  538. break;
  539. case SAA7134_BOARD_HAUPPAUGE_HVR1110:
  540. snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110");
  541. ir->get_key = get_key_hvr1110;
  542. ir->ir_codes = ir_codes_hauppauge_new;
  543. break;
  544. case SAA7134_BOARD_BEHOLD_607_9FM:
  545. case SAA7134_BOARD_BEHOLD_M6:
  546. case SAA7134_BOARD_BEHOLD_M63:
  547. case SAA7134_BOARD_BEHOLD_M6_EXTRA:
  548. case SAA7134_BOARD_BEHOLD_H6:
  549. snprintf(ir->c.name, sizeof(ir->c.name), "BeholdTV");
  550. ir->get_key = get_key_beholdm6xx;
  551. ir->ir_codes = ir_codes_behold;
  552. break;
  553. default:
  554. dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board);
  555. break;
  556. }
  557. }
  558. static int saa7134_rc5_irq(struct saa7134_dev *dev)
  559. {
  560. struct card_ir *ir = dev->remote;
  561. struct timeval tv;
  562. u32 gap;
  563. unsigned long current_jiffies, timeout;
  564. /* get time of bit */
  565. current_jiffies = jiffies;
  566. do_gettimeofday(&tv);
  567. /* avoid overflow with gap >1s */
  568. if (tv.tv_sec - ir->base_time.tv_sec > 1) {
  569. gap = 200000;
  570. } else {
  571. gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
  572. tv.tv_usec - ir->base_time.tv_usec;
  573. }
  574. /* active code => add bit */
  575. if (ir->active) {
  576. /* only if in the code (otherwise spurious IRQ or timer
  577. late) */
  578. if (ir->last_bit < 28) {
  579. ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
  580. ir_rc5_remote_gap;
  581. ir->code |= 1 << ir->last_bit;
  582. }
  583. /* starting new code */
  584. } else {
  585. ir->active = 1;
  586. ir->code = 0;
  587. ir->base_time = tv;
  588. ir->last_bit = 0;
  589. timeout = current_jiffies + (500 + 30 * HZ) / 1000;
  590. mod_timer(&ir->timer_end, timeout);
  591. }
  592. return 1;
  593. }
  594. /* ----------------------------------------------------------------------
  595. * Local variables:
  596. * c-basic-offset: 8
  597. * End:
  598. */