saa7134-input.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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. void saa7134_input_irq(struct saa7134_dev *dev)
  164. {
  165. struct card_ir *ir = dev->remote;
  166. if (!ir->polling && !ir->rc5_gpio) {
  167. build_key(dev);
  168. } else if (ir->rc5_gpio) {
  169. saa7134_rc5_irq(dev);
  170. }
  171. }
  172. static void saa7134_input_timer(unsigned long data)
  173. {
  174. struct saa7134_dev *dev = (struct saa7134_dev *)data;
  175. struct card_ir *ir = dev->remote;
  176. build_key(dev);
  177. mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
  178. }
  179. void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
  180. {
  181. if (ir->polling) {
  182. setup_timer(&ir->timer, saa7134_input_timer,
  183. (unsigned long)dev);
  184. ir->timer.expires = jiffies + HZ;
  185. add_timer(&ir->timer);
  186. } else if (ir->rc5_gpio) {
  187. /* set timer_end for code completion */
  188. init_timer(&ir->timer_end);
  189. ir->timer_end.function = ir_rc5_timer_end;
  190. ir->timer_end.data = (unsigned long)ir;
  191. init_timer(&ir->timer_keyup);
  192. ir->timer_keyup.function = ir_rc5_timer_keyup;
  193. ir->timer_keyup.data = (unsigned long)ir;
  194. ir->shift_by = 2;
  195. ir->start = 0x2;
  196. ir->addr = 0x17;
  197. ir->rc5_key_timeout = ir_rc5_key_timeout;
  198. ir->rc5_remote_gap = ir_rc5_remote_gap;
  199. }
  200. }
  201. void saa7134_ir_stop(struct saa7134_dev *dev)
  202. {
  203. if (dev->remote->polling)
  204. del_timer_sync(&dev->remote->timer);
  205. }
  206. int saa7134_input_init1(struct saa7134_dev *dev)
  207. {
  208. struct card_ir *ir;
  209. struct input_dev *input_dev;
  210. IR_KEYTAB_TYPE *ir_codes = NULL;
  211. u32 mask_keycode = 0;
  212. u32 mask_keydown = 0;
  213. u32 mask_keyup = 0;
  214. int polling = 0;
  215. int rc5_gpio = 0;
  216. int ir_type = IR_TYPE_OTHER;
  217. int err;
  218. if (dev->has_remote != SAA7134_REMOTE_GPIO)
  219. return -ENODEV;
  220. if (disable_ir)
  221. return -ENODEV;
  222. /* detect & configure */
  223. switch (dev->board) {
  224. case SAA7134_BOARD_FLYVIDEO2000:
  225. case SAA7134_BOARD_FLYVIDEO3000:
  226. case SAA7134_BOARD_FLYTVPLATINUM_FM:
  227. case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
  228. ir_codes = ir_codes_flyvideo;
  229. mask_keycode = 0xEC00000;
  230. mask_keydown = 0x0040000;
  231. break;
  232. case SAA7134_BOARD_CINERGY400:
  233. case SAA7134_BOARD_CINERGY600:
  234. case SAA7134_BOARD_CINERGY600_MK3:
  235. ir_codes = ir_codes_cinergy;
  236. mask_keycode = 0x00003f;
  237. mask_keyup = 0x040000;
  238. break;
  239. case SAA7134_BOARD_ECS_TVP3XP:
  240. case SAA7134_BOARD_ECS_TVP3XP_4CB5:
  241. ir_codes = ir_codes_eztv;
  242. mask_keycode = 0x00017c;
  243. mask_keyup = 0x000002;
  244. polling = 50; // ms
  245. break;
  246. case SAA7134_BOARD_KWORLD_XPERT:
  247. case SAA7134_BOARD_AVACSSMARTTV:
  248. ir_codes = ir_codes_pixelview;
  249. mask_keycode = 0x00001F;
  250. mask_keyup = 0x000020;
  251. polling = 50; // ms
  252. break;
  253. case SAA7134_BOARD_MD2819:
  254. case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
  255. case SAA7134_BOARD_AVERMEDIA_305:
  256. case SAA7134_BOARD_AVERMEDIA_307:
  257. case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
  258. case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
  259. case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
  260. case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
  261. case SAA7134_BOARD_AVERMEDIA_M102:
  262. ir_codes = ir_codes_avermedia;
  263. mask_keycode = 0x0007C8;
  264. mask_keydown = 0x000010;
  265. polling = 50; // ms
  266. /* Set GPIO pin2 to high to enable the IR controller */
  267. saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
  268. saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
  269. break;
  270. case SAA7134_BOARD_AVERMEDIA_777:
  271. case SAA7134_BOARD_AVERMEDIA_A16AR:
  272. ir_codes = ir_codes_avermedia;
  273. mask_keycode = 0x02F200;
  274. mask_keydown = 0x000400;
  275. polling = 50; // ms
  276. /* Without this we won't receive key up events */
  277. saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
  278. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
  279. break;
  280. case SAA7134_BOARD_AVERMEDIA_A16D:
  281. ir_codes = ir_codes_avermedia_a16d;
  282. mask_keycode = 0x02F200;
  283. mask_keydown = 0x000400;
  284. polling = 50; /* ms */
  285. /* Without this we won't receive key up events */
  286. saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
  287. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
  288. break;
  289. case SAA7134_BOARD_KWORLD_TERMINATOR:
  290. ir_codes = ir_codes_pixelview;
  291. mask_keycode = 0x00001f;
  292. mask_keyup = 0x000060;
  293. polling = 50; // ms
  294. break;
  295. case SAA7134_BOARD_MANLI_MTV001:
  296. case SAA7134_BOARD_MANLI_MTV002:
  297. ir_codes = ir_codes_manli;
  298. mask_keycode = 0x001f00;
  299. mask_keyup = 0x004000;
  300. polling = 50; /* ms */
  301. break;
  302. case SAA7134_BOARD_BEHOLD_409FM:
  303. case SAA7134_BOARD_BEHOLD_401:
  304. case SAA7134_BOARD_BEHOLD_403:
  305. case SAA7134_BOARD_BEHOLD_403FM:
  306. case SAA7134_BOARD_BEHOLD_405:
  307. case SAA7134_BOARD_BEHOLD_405FM:
  308. case SAA7134_BOARD_BEHOLD_407:
  309. case SAA7134_BOARD_BEHOLD_407FM:
  310. case SAA7134_BOARD_BEHOLD_409:
  311. case SAA7134_BOARD_BEHOLD_505FM:
  312. case SAA7134_BOARD_BEHOLD_507_9FM:
  313. ir_codes = ir_codes_manli;
  314. mask_keycode = 0x003f00;
  315. mask_keyup = 0x004000;
  316. polling = 50; /* ms */
  317. break;
  318. case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
  319. ir_codes = ir_codes_behold_columbus;
  320. mask_keycode = 0x003f00;
  321. mask_keyup = 0x004000;
  322. polling = 50; // ms
  323. break;
  324. case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
  325. ir_codes = ir_codes_pctv_sedna;
  326. mask_keycode = 0x001f00;
  327. mask_keyup = 0x004000;
  328. polling = 50; // ms
  329. break;
  330. case SAA7134_BOARD_GOTVIEW_7135:
  331. ir_codes = ir_codes_gotview7135;
  332. mask_keycode = 0x0003CC;
  333. mask_keydown = 0x000010;
  334. polling = 5; /* ms */
  335. saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
  336. break;
  337. case SAA7134_BOARD_VIDEOMATE_TV_PVR:
  338. case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
  339. case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
  340. ir_codes = ir_codes_videomate_tv_pvr;
  341. mask_keycode = 0x00003F;
  342. mask_keyup = 0x400000;
  343. polling = 50; // ms
  344. break;
  345. case SAA7134_BOARD_PROTEUS_2309:
  346. ir_codes = ir_codes_proteus_2309;
  347. mask_keycode = 0x00007F;
  348. mask_keyup = 0x000080;
  349. polling = 50; // ms
  350. break;
  351. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  352. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  353. ir_codes = ir_codes_videomate_tv_pvr;
  354. mask_keycode = 0x003F00;
  355. mask_keyup = 0x040000;
  356. break;
  357. case SAA7134_BOARD_FLYDVBS_LR300:
  358. case SAA7134_BOARD_FLYDVBT_LR301:
  359. case SAA7134_BOARD_FLYDVBTDUO:
  360. ir_codes = ir_codes_flydvb;
  361. mask_keycode = 0x0001F00;
  362. mask_keydown = 0x0040000;
  363. break;
  364. case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
  365. case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
  366. ir_codes = ir_codes_asus_pc39;
  367. mask_keydown = 0x0040000;
  368. rc5_gpio = 1;
  369. break;
  370. case SAA7134_BOARD_ENCORE_ENLTV:
  371. case SAA7134_BOARD_ENCORE_ENLTV_FM:
  372. ir_codes = ir_codes_encore_enltv;
  373. mask_keycode = 0x00007f;
  374. mask_keyup = 0x040000;
  375. polling = 50; // ms
  376. break;
  377. case SAA7134_BOARD_10MOONSTVMASTER3:
  378. ir_codes = ir_codes_encore_enltv;
  379. mask_keycode = 0x5f80000;
  380. mask_keyup = 0x8000000;
  381. polling = 50; //ms
  382. break;
  383. case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
  384. ir_codes = ir_codes_genius_tvgo_a11mce;
  385. mask_keycode = 0xff;
  386. mask_keydown = 0xf00000;
  387. polling = 50; /* ms */
  388. break;
  389. }
  390. if (NULL == ir_codes) {
  391. printk("%s: Oops: IR config error [card=%d]\n",
  392. dev->name, dev->board);
  393. return -ENODEV;
  394. }
  395. ir = kzalloc(sizeof(*ir), GFP_KERNEL);
  396. input_dev = input_allocate_device();
  397. if (!ir || !input_dev) {
  398. err = -ENOMEM;
  399. goto err_out_free;
  400. }
  401. ir->dev = input_dev;
  402. /* init hardware-specific stuff */
  403. ir->mask_keycode = mask_keycode;
  404. ir->mask_keydown = mask_keydown;
  405. ir->mask_keyup = mask_keyup;
  406. ir->polling = polling;
  407. ir->rc5_gpio = rc5_gpio;
  408. /* init input device */
  409. snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
  410. saa7134_boards[dev->board].name);
  411. snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
  412. pci_name(dev->pci));
  413. ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
  414. input_dev->name = ir->name;
  415. input_dev->phys = ir->phys;
  416. input_dev->id.bustype = BUS_PCI;
  417. input_dev->id.version = 1;
  418. if (dev->pci->subsystem_vendor) {
  419. input_dev->id.vendor = dev->pci->subsystem_vendor;
  420. input_dev->id.product = dev->pci->subsystem_device;
  421. } else {
  422. input_dev->id.vendor = dev->pci->vendor;
  423. input_dev->id.product = dev->pci->device;
  424. }
  425. input_dev->dev.parent = &dev->pci->dev;
  426. dev->remote = ir;
  427. saa7134_ir_start(dev, ir);
  428. err = input_register_device(ir->dev);
  429. if (err)
  430. goto err_out_stop;
  431. /* the remote isn't as bouncy as a keyboard */
  432. ir->dev->rep[REP_DELAY] = repeat_delay;
  433. ir->dev->rep[REP_PERIOD] = repeat_period;
  434. return 0;
  435. err_out_stop:
  436. saa7134_ir_stop(dev);
  437. dev->remote = NULL;
  438. err_out_free:
  439. input_free_device(input_dev);
  440. kfree(ir);
  441. return err;
  442. }
  443. void saa7134_input_fini(struct saa7134_dev *dev)
  444. {
  445. if (NULL == dev->remote)
  446. return;
  447. saa7134_ir_stop(dev);
  448. input_unregister_device(dev->remote->dev);
  449. kfree(dev->remote);
  450. dev->remote = NULL;
  451. }
  452. void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
  453. {
  454. if (disable_ir) {
  455. dprintk("Found supported i2c remote, but IR has been disabled\n");
  456. ir->get_key=NULL;
  457. return;
  458. }
  459. switch (dev->board) {
  460. case SAA7134_BOARD_PINNACLE_PCTV_110i:
  461. case SAA7134_BOARD_PINNACLE_PCTV_310i:
  462. snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV");
  463. if (pinnacle_remote == 0) {
  464. ir->get_key = get_key_pinnacle_color;
  465. ir->ir_codes = ir_codes_pinnacle_color;
  466. } else {
  467. ir->get_key = get_key_pinnacle_grey;
  468. ir->ir_codes = ir_codes_pinnacle_grey;
  469. }
  470. break;
  471. case SAA7134_BOARD_UPMOST_PURPLE_TV:
  472. snprintf(ir->c.name, sizeof(ir->c.name), "Purple TV");
  473. ir->get_key = get_key_purpletv;
  474. ir->ir_codes = ir_codes_purpletv;
  475. break;
  476. case SAA7134_BOARD_HAUPPAUGE_HVR1110:
  477. snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110");
  478. ir->get_key = get_key_hvr1110;
  479. ir->ir_codes = ir_codes_hauppauge_new;
  480. break;
  481. case SAA7134_BOARD_BEHOLD_607_9FM:
  482. case SAA7134_BOARD_BEHOLD_M6:
  483. case SAA7134_BOARD_BEHOLD_H6:
  484. snprintf(ir->c.name, sizeof(ir->c.name), "BeholdTV");
  485. ir->get_key = get_key_beholdm6xx;
  486. ir->ir_codes = ir_codes_behold;
  487. break;
  488. default:
  489. dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board);
  490. break;
  491. }
  492. }
  493. static int saa7134_rc5_irq(struct saa7134_dev *dev)
  494. {
  495. struct card_ir *ir = dev->remote;
  496. struct timeval tv;
  497. u32 gap;
  498. unsigned long current_jiffies, timeout;
  499. /* get time of bit */
  500. current_jiffies = jiffies;
  501. do_gettimeofday(&tv);
  502. /* avoid overflow with gap >1s */
  503. if (tv.tv_sec - ir->base_time.tv_sec > 1) {
  504. gap = 200000;
  505. } else {
  506. gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
  507. tv.tv_usec - ir->base_time.tv_usec;
  508. }
  509. /* active code => add bit */
  510. if (ir->active) {
  511. /* only if in the code (otherwise spurious IRQ or timer
  512. late) */
  513. if (ir->last_bit < 28) {
  514. ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
  515. ir_rc5_remote_gap;
  516. ir->code |= 1 << ir->last_bit;
  517. }
  518. /* starting new code */
  519. } else {
  520. ir->active = 1;
  521. ir->code = 0;
  522. ir->base_time = tv;
  523. ir->last_bit = 0;
  524. timeout = current_jiffies + (500 + 30 * HZ) / 1000;
  525. mod_timer(&ir->timer_end, timeout);
  526. }
  527. return 1;
  528. }
  529. /* ----------------------------------------------------------------------
  530. * Local variables:
  531. * c-basic-offset: 8
  532. * End:
  533. */