saa7134-input.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  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 <linux/slab.h>
  26. #include "saa7134-reg.h"
  27. #include "saa7134.h"
  28. #define MODULE_NAME "saa7134"
  29. static unsigned int disable_ir;
  30. module_param(disable_ir, int, 0444);
  31. MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
  32. static unsigned int ir_debug;
  33. module_param(ir_debug, int, 0644);
  34. MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
  35. static int pinnacle_remote;
  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. static int ir_rc5_remote_gap = 885;
  39. module_param(ir_rc5_remote_gap, int, 0644);
  40. static int ir_rc5_key_timeout = 115;
  41. module_param(ir_rc5_key_timeout, int, 0644);
  42. static int repeat_delay = 500;
  43. module_param(repeat_delay, int, 0644);
  44. MODULE_PARM_DESC(repeat_delay, "delay before key repeat started");
  45. static int repeat_period = 33;
  46. module_param(repeat_period, int, 0644);
  47. MODULE_PARM_DESC(repeat_period, "repeat period between "
  48. "keypresses when key is down");
  49. static unsigned int disable_other_ir;
  50. module_param(disable_other_ir, int, 0644);
  51. MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
  52. "alternative remotes from other manufacturers");
  53. #define dprintk(fmt, arg...) if (ir_debug) \
  54. printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
  55. #define i2cdprintk(fmt, arg...) if (ir_debug) \
  56. printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg)
  57. /* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */
  58. static int saa7134_rc5_irq(struct saa7134_dev *dev);
  59. static int saa7134_nec_irq(struct saa7134_dev *dev);
  60. static int saa7134_raw_decode_irq(struct saa7134_dev *dev);
  61. static void nec_task(unsigned long data);
  62. static void saa7134_nec_timer(unsigned long data);
  63. /* -------------------- GPIO generic keycode builder -------------------- */
  64. static int build_key(struct saa7134_dev *dev)
  65. {
  66. struct card_ir *ir = dev->remote;
  67. u32 gpio, data;
  68. /* here comes the additional handshake steps for some cards */
  69. switch (dev->board) {
  70. case SAA7134_BOARD_GOTVIEW_7135:
  71. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80);
  72. saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80);
  73. break;
  74. }
  75. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  76. saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
  77. saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
  78. gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
  79. if (ir->polling) {
  80. if (ir->last_gpio == gpio)
  81. return 0;
  82. ir->last_gpio = gpio;
  83. }
  84. data = ir_extract_bits(gpio, ir->mask_keycode);
  85. dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
  86. gpio, ir->mask_keycode, data);
  87. switch (dev->board) {
  88. case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
  89. if (data == ir->mask_keycode)
  90. ir_input_nokey(ir->dev, &ir->ir);
  91. else
  92. ir_input_keydown(ir->dev, &ir->ir, data);
  93. return 0;
  94. }
  95. if (ir->polling) {
  96. if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
  97. (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
  98. ir_input_keydown(ir->dev, &ir->ir, data);
  99. } else {
  100. ir_input_nokey(ir->dev, &ir->ir);
  101. }
  102. }
  103. else { /* IRQ driven mode - handle key press and release in one go */
  104. if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
  105. (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
  106. ir_input_keydown(ir->dev, &ir->ir, data);
  107. ir_input_nokey(ir->dev, &ir->ir);
  108. }
  109. }
  110. return 0;
  111. }
  112. /* --------------------- Chip specific I2C key builders ----------------- */
  113. static int get_key_flydvb_trio(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  114. {
  115. int gpio;
  116. int attempt = 0;
  117. unsigned char b;
  118. /* We need this to access GPI Used by the saa_readl macro. */
  119. struct saa7134_dev *dev = ir->c->adapter->algo_data;
  120. if (dev == NULL) {
  121. dprintk("get_key_flydvb_trio: "
  122. "gir->c->adapter->algo_data is NULL!\n");
  123. return -EIO;
  124. }
  125. /* rising SAA7134_GPIGPRESCAN reads the status */
  126. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  127. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  128. gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
  129. if (0x40000 & ~gpio)
  130. return 0; /* No button press */
  131. /* No button press - only before first key pressed */
  132. if (b == 0xFF)
  133. return 0;
  134. /* poll IR chip */
  135. /* weak up the IR chip */
  136. b = 0;
  137. while (1 != i2c_master_send(ir->c, &b, 1)) {
  138. if ((attempt++) < 10) {
  139. /*
  140. * wait a bit for next attempt -
  141. * I don't know how make it better
  142. */
  143. msleep(10);
  144. continue;
  145. }
  146. i2cdprintk("send wake up byte to pic16C505 (IR chip)"
  147. "failed %dx\n", attempt);
  148. return -EIO;
  149. }
  150. if (1 != i2c_master_recv(ir->c, &b, 1)) {
  151. i2cdprintk("read error\n");
  152. return -EIO;
  153. }
  154. *ir_key = b;
  155. *ir_raw = b;
  156. return 1;
  157. }
  158. static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
  159. u32 *ir_raw)
  160. {
  161. unsigned char b;
  162. int gpio;
  163. /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
  164. struct saa7134_dev *dev = ir->c->adapter->algo_data;
  165. if (dev == NULL) {
  166. dprintk("get_key_msi_tvanywhere_plus: "
  167. "gir->c->adapter->algo_data is NULL!\n");
  168. return -EIO;
  169. }
  170. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  171. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  172. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  173. gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
  174. /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
  175. I2C receive if gpio&0x40 is not low. */
  176. if (gpio & 0x40)
  177. return 0; /* No button press */
  178. /* GPIO says there is a button press. Get it. */
  179. if (1 != i2c_master_recv(ir->c, &b, 1)) {
  180. i2cdprintk("read error\n");
  181. return -EIO;
  182. }
  183. /* No button press */
  184. if (b == 0xff)
  185. return 0;
  186. /* Button pressed */
  187. dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
  188. *ir_key = b;
  189. *ir_raw = b;
  190. return 1;
  191. }
  192. static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  193. {
  194. unsigned char b;
  195. /* poll IR chip */
  196. if (1 != i2c_master_recv(ir->c, &b, 1)) {
  197. i2cdprintk("read error\n");
  198. return -EIO;
  199. }
  200. /* no button press */
  201. if (b==0)
  202. return 0;
  203. /* repeating */
  204. if (b & 0x80)
  205. return 1;
  206. *ir_key = b;
  207. *ir_raw = b;
  208. return 1;
  209. }
  210. static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  211. {
  212. unsigned char buf[5], cod4, code3, code4;
  213. /* poll IR chip */
  214. if (5 != i2c_master_recv(ir->c, buf, 5))
  215. return -EIO;
  216. cod4 = buf[4];
  217. code4 = (cod4 >> 2);
  218. code3 = buf[3];
  219. if (code3 == 0)
  220. /* no key pressed */
  221. return 0;
  222. /* return key */
  223. *ir_key = code4;
  224. *ir_raw = code4;
  225. return 1;
  226. }
  227. static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  228. {
  229. unsigned char data[12];
  230. u32 gpio;
  231. struct saa7134_dev *dev = ir->c->adapter->algo_data;
  232. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  233. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  234. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  235. gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
  236. if (0x400000 & ~gpio)
  237. return 0; /* No button press */
  238. ir->c->addr = 0x5a >> 1;
  239. if (12 != i2c_master_recv(ir->c, data, 12)) {
  240. i2cdprintk("read error\n");
  241. return -EIO;
  242. }
  243. /* IR of this card normally decode signals NEC-standard from
  244. * - Sven IHOO MT 5.1R remote. xxyye718
  245. * - Sven DVD HD-10xx remote. xxyyf708
  246. * - BBK ...
  247. * - mayby others
  248. * So, skip not our, if disable full codes mode.
  249. */
  250. if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir)
  251. return 0;
  252. /* Wrong data decode fix */
  253. if (data[9] != (unsigned char)(~data[8]))
  254. return 0;
  255. *ir_key = data[9];
  256. *ir_raw = data[9];
  257. return 1;
  258. }
  259. /* Common (grey or coloured) pinnacle PCTV remote handling
  260. *
  261. */
  262. static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
  263. int parity_offset, int marker, int code_modulo)
  264. {
  265. unsigned char b[4];
  266. unsigned int start = 0,parity = 0,code = 0;
  267. /* poll IR chip */
  268. if (4 != i2c_master_recv(ir->c, b, 4)) {
  269. i2cdprintk("read error\n");
  270. return -EIO;
  271. }
  272. for (start = 0; start < ARRAY_SIZE(b); start++) {
  273. if (b[start] == marker) {
  274. code=b[(start+parity_offset + 1) % 4];
  275. parity=b[(start+parity_offset) % 4];
  276. }
  277. }
  278. /* Empty Request */
  279. if (parity == 0)
  280. return 0;
  281. /* Repeating... */
  282. if (ir->old == parity)
  283. return 0;
  284. ir->old = parity;
  285. /* drop special codes when a key is held down a long time for the grey controller
  286. In this case, the second bit of the code is asserted */
  287. if (marker == 0xfe && (code & 0x40))
  288. return 0;
  289. code %= code_modulo;
  290. *ir_raw = code;
  291. *ir_key = code;
  292. i2cdprintk("Pinnacle PCTV key %02x\n", code);
  293. return 1;
  294. }
  295. /* The grey pinnacle PCTV remote
  296. *
  297. * There are one issue with this remote:
  298. * - I2c packet does not change when the same key is pressed quickly. The workaround
  299. * is to hold down each key for about half a second, so that another code is generated
  300. * in the i2c packet, and the function can distinguish key presses.
  301. *
  302. * Sylvain Pasche <sylvain.pasche@gmail.com>
  303. */
  304. static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  305. {
  306. return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff);
  307. }
  308. /* The new pinnacle PCTV remote (with the colored buttons)
  309. *
  310. * Ricardo Cerqueira <v4l@cerqueira.org>
  311. */
  312. static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  313. {
  314. /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
  315. *
  316. * this is the only value that results in 42 unique
  317. * codes < 128
  318. */
  319. return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
  320. }
  321. void saa7134_input_irq(struct saa7134_dev *dev)
  322. {
  323. struct card_ir *ir;
  324. if (!dev || !dev->remote)
  325. return;
  326. ir = dev->remote;
  327. if (!ir->running)
  328. return;
  329. if (ir->nec_gpio) {
  330. saa7134_nec_irq(dev);
  331. } else if (!ir->polling && !ir->rc5_gpio && !ir->raw_decode) {
  332. build_key(dev);
  333. } else if (ir->rc5_gpio) {
  334. saa7134_rc5_irq(dev);
  335. } else if (ir->raw_decode) {
  336. saa7134_raw_decode_irq(dev);
  337. }
  338. }
  339. static void saa7134_input_timer(unsigned long data)
  340. {
  341. struct saa7134_dev *dev = (struct saa7134_dev *)data;
  342. struct card_ir *ir = dev->remote;
  343. build_key(dev);
  344. mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
  345. }
  346. void ir_raw_decode_timer_end(unsigned long data)
  347. {
  348. struct saa7134_dev *dev = (struct saa7134_dev *)data;
  349. struct card_ir *ir = dev->remote;
  350. ir_raw_event_handle(dev->remote->dev);
  351. ir->active = 0;
  352. }
  353. static int __saa7134_ir_start(void *priv)
  354. {
  355. struct saa7134_dev *dev = priv;
  356. struct card_ir *ir;
  357. if (!dev)
  358. return -EINVAL;
  359. ir = dev->remote;
  360. if (!ir)
  361. return -EINVAL;
  362. if (ir->running)
  363. return 0;
  364. ir->running = 1;
  365. if (ir->polling) {
  366. setup_timer(&ir->timer, saa7134_input_timer,
  367. (unsigned long)dev);
  368. ir->timer.expires = jiffies + HZ;
  369. add_timer(&ir->timer);
  370. } else if (ir->rc5_gpio) {
  371. /* set timer_end for code completion */
  372. init_timer(&ir->timer_end);
  373. ir->timer_end.function = ir_rc5_timer_end;
  374. ir->timer_end.data = (unsigned long)ir;
  375. init_timer(&ir->timer_keyup);
  376. ir->timer_keyup.function = ir_rc5_timer_keyup;
  377. ir->timer_keyup.data = (unsigned long)ir;
  378. ir->shift_by = 2;
  379. ir->start = 0x2;
  380. ir->addr = 0x17;
  381. ir->rc5_key_timeout = ir_rc5_key_timeout;
  382. ir->rc5_remote_gap = ir_rc5_remote_gap;
  383. } else if (ir->nec_gpio) {
  384. setup_timer(&ir->timer_keyup, saa7134_nec_timer,
  385. (unsigned long)dev);
  386. tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
  387. } else if (ir->raw_decode) {
  388. /* set timer_end for code completion */
  389. init_timer(&ir->timer_end);
  390. ir->timer_end.function = ir_raw_decode_timer_end;
  391. ir->timer_end.data = (unsigned long)dev;
  392. ir->active = 0;
  393. }
  394. return 0;
  395. }
  396. static void __saa7134_ir_stop(void *priv)
  397. {
  398. struct saa7134_dev *dev = priv;
  399. struct card_ir *ir;
  400. if (!dev)
  401. return;
  402. ir = dev->remote;
  403. if (!ir)
  404. return;
  405. if (!ir->running)
  406. return;
  407. if (dev->remote->polling)
  408. del_timer_sync(&dev->remote->timer);
  409. else if (ir->rc5_gpio)
  410. del_timer_sync(&ir->timer_end);
  411. else if (ir->nec_gpio)
  412. tasklet_kill(&ir->tlet);
  413. else if (ir->raw_decode) {
  414. del_timer_sync(&ir->timer_end);
  415. ir->active = 0;
  416. }
  417. ir->running = 0;
  418. return;
  419. }
  420. int saa7134_ir_start(struct saa7134_dev *dev)
  421. {
  422. if (dev->remote->users)
  423. return __saa7134_ir_start(dev);
  424. return 0;
  425. }
  426. void saa7134_ir_stop(struct saa7134_dev *dev)
  427. {
  428. if (dev->remote->users)
  429. __saa7134_ir_stop(dev);
  430. }
  431. static int saa7134_ir_open(void *priv)
  432. {
  433. struct saa7134_dev *dev = priv;
  434. dev->remote->users++;
  435. return __saa7134_ir_start(dev);
  436. }
  437. static void saa7134_ir_close(void *priv)
  438. {
  439. struct saa7134_dev *dev = priv;
  440. dev->remote->users--;
  441. if (!dev->remote->users)
  442. __saa7134_ir_stop(dev);
  443. }
  444. int saa7134_ir_change_protocol(void *priv, u64 ir_type)
  445. {
  446. struct saa7134_dev *dev = priv;
  447. struct card_ir *ir = dev->remote;
  448. u32 nec_gpio, rc5_gpio;
  449. if (ir_type == IR_TYPE_RC5) {
  450. dprintk("Changing protocol to RC5\n");
  451. nec_gpio = 0;
  452. rc5_gpio = 1;
  453. } else if (ir_type == IR_TYPE_NEC) {
  454. dprintk("Changing protocol to NEC\n");
  455. nec_gpio = 1;
  456. rc5_gpio = 0;
  457. } else {
  458. dprintk("IR protocol type %ud is not supported\n",
  459. (unsigned)ir_type);
  460. return -EINVAL;
  461. }
  462. if (ir->running) {
  463. saa7134_ir_stop(dev);
  464. ir->nec_gpio = nec_gpio;
  465. ir->rc5_gpio = rc5_gpio;
  466. saa7134_ir_start(dev);
  467. } else {
  468. ir->nec_gpio = nec_gpio;
  469. ir->rc5_gpio = rc5_gpio;
  470. }
  471. return 0;
  472. }
  473. int saa7134_input_init1(struct saa7134_dev *dev)
  474. {
  475. struct card_ir *ir;
  476. struct input_dev *input_dev;
  477. char *ir_codes = NULL;
  478. u32 mask_keycode = 0;
  479. u32 mask_keydown = 0;
  480. u32 mask_keyup = 0;
  481. int polling = 0;
  482. int rc5_gpio = 0;
  483. int nec_gpio = 0;
  484. int raw_decode = 0;
  485. int allow_protocol_change = 0;
  486. u64 ir_type = IR_TYPE_OTHER;
  487. int err;
  488. if (dev->has_remote != SAA7134_REMOTE_GPIO)
  489. return -ENODEV;
  490. if (disable_ir)
  491. return -ENODEV;
  492. /* detect & configure */
  493. switch (dev->board) {
  494. case SAA7134_BOARD_FLYVIDEO2000:
  495. case SAA7134_BOARD_FLYVIDEO3000:
  496. case SAA7134_BOARD_FLYTVPLATINUM_FM:
  497. case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
  498. case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
  499. ir_codes = RC_MAP_FLYVIDEO;
  500. mask_keycode = 0xEC00000;
  501. mask_keydown = 0x0040000;
  502. break;
  503. case SAA7134_BOARD_CINERGY400:
  504. case SAA7134_BOARD_CINERGY600:
  505. case SAA7134_BOARD_CINERGY600_MK3:
  506. ir_codes = RC_MAP_CINERGY;
  507. mask_keycode = 0x00003f;
  508. mask_keyup = 0x040000;
  509. break;
  510. case SAA7134_BOARD_ECS_TVP3XP:
  511. case SAA7134_BOARD_ECS_TVP3XP_4CB5:
  512. ir_codes = RC_MAP_EZTV;
  513. mask_keycode = 0x00017c;
  514. mask_keyup = 0x000002;
  515. polling = 50; // ms
  516. break;
  517. case SAA7134_BOARD_KWORLD_XPERT:
  518. case SAA7134_BOARD_AVACSSMARTTV:
  519. ir_codes = RC_MAP_PIXELVIEW;
  520. mask_keycode = 0x00001F;
  521. mask_keyup = 0x000020;
  522. polling = 50; // ms
  523. break;
  524. case SAA7134_BOARD_MD2819:
  525. case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
  526. case SAA7134_BOARD_AVERMEDIA_305:
  527. case SAA7134_BOARD_AVERMEDIA_307:
  528. case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
  529. case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
  530. case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
  531. case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
  532. case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
  533. case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
  534. case SAA7134_BOARD_AVERMEDIA_M102:
  535. case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
  536. ir_codes = RC_MAP_AVERMEDIA;
  537. mask_keycode = 0x0007C8;
  538. mask_keydown = 0x000010;
  539. polling = 50; // ms
  540. /* Set GPIO pin2 to high to enable the IR controller */
  541. saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
  542. saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
  543. break;
  544. case SAA7134_BOARD_AVERMEDIA_M135A:
  545. ir_codes = RC_MAP_AVERMEDIA_M135A_RM_JX;
  546. mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
  547. mask_keyup = 0x0040000;
  548. mask_keycode = 0xffff;
  549. raw_decode = 1;
  550. break;
  551. case SAA7134_BOARD_AVERMEDIA_777:
  552. case SAA7134_BOARD_AVERMEDIA_A16AR:
  553. ir_codes = RC_MAP_AVERMEDIA;
  554. mask_keycode = 0x02F200;
  555. mask_keydown = 0x000400;
  556. polling = 50; // ms
  557. /* Without this we won't receive key up events */
  558. saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
  559. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
  560. break;
  561. case SAA7134_BOARD_AVERMEDIA_A16D:
  562. ir_codes = RC_MAP_AVERMEDIA_A16D;
  563. mask_keycode = 0x02F200;
  564. mask_keydown = 0x000400;
  565. polling = 50; /* ms */
  566. /* Without this we won't receive key up events */
  567. saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
  568. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
  569. break;
  570. case SAA7134_BOARD_KWORLD_TERMINATOR:
  571. ir_codes = RC_MAP_PIXELVIEW;
  572. mask_keycode = 0x00001f;
  573. mask_keyup = 0x000060;
  574. polling = 50; // ms
  575. break;
  576. case SAA7134_BOARD_MANLI_MTV001:
  577. case SAA7134_BOARD_MANLI_MTV002:
  578. ir_codes = RC_MAP_MANLI;
  579. mask_keycode = 0x001f00;
  580. mask_keyup = 0x004000;
  581. polling = 50; /* ms */
  582. break;
  583. case SAA7134_BOARD_BEHOLD_409FM:
  584. case SAA7134_BOARD_BEHOLD_401:
  585. case SAA7134_BOARD_BEHOLD_403:
  586. case SAA7134_BOARD_BEHOLD_403FM:
  587. case SAA7134_BOARD_BEHOLD_405:
  588. case SAA7134_BOARD_BEHOLD_405FM:
  589. case SAA7134_BOARD_BEHOLD_407:
  590. case SAA7134_BOARD_BEHOLD_407FM:
  591. case SAA7134_BOARD_BEHOLD_409:
  592. case SAA7134_BOARD_BEHOLD_505FM:
  593. case SAA7134_BOARD_BEHOLD_505RDS_MK5:
  594. case SAA7134_BOARD_BEHOLD_505RDS_MK3:
  595. case SAA7134_BOARD_BEHOLD_507_9FM:
  596. case SAA7134_BOARD_BEHOLD_507RDS_MK3:
  597. case SAA7134_BOARD_BEHOLD_507RDS_MK5:
  598. ir_codes = RC_MAP_MANLI;
  599. mask_keycode = 0x003f00;
  600. mask_keyup = 0x004000;
  601. polling = 50; /* ms */
  602. break;
  603. case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
  604. ir_codes = RC_MAP_BEHOLD_COLUMBUS;
  605. mask_keycode = 0x003f00;
  606. mask_keyup = 0x004000;
  607. polling = 50; // ms
  608. break;
  609. case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
  610. ir_codes = RC_MAP_PCTV_SEDNA;
  611. mask_keycode = 0x001f00;
  612. mask_keyup = 0x004000;
  613. polling = 50; // ms
  614. break;
  615. case SAA7134_BOARD_GOTVIEW_7135:
  616. ir_codes = RC_MAP_GOTVIEW7135;
  617. mask_keycode = 0x0003CC;
  618. mask_keydown = 0x000010;
  619. polling = 5; /* ms */
  620. saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
  621. break;
  622. case SAA7134_BOARD_VIDEOMATE_TV_PVR:
  623. case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
  624. case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
  625. ir_codes = RC_MAP_VIDEOMATE_TV_PVR;
  626. mask_keycode = 0x00003F;
  627. mask_keyup = 0x400000;
  628. polling = 50; // ms
  629. break;
  630. case SAA7134_BOARD_PROTEUS_2309:
  631. ir_codes = RC_MAP_PROTEUS_2309;
  632. mask_keycode = 0x00007F;
  633. mask_keyup = 0x000080;
  634. polling = 50; // ms
  635. break;
  636. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  637. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  638. ir_codes = RC_MAP_VIDEOMATE_TV_PVR;
  639. mask_keycode = 0x003F00;
  640. mask_keyup = 0x040000;
  641. break;
  642. case SAA7134_BOARD_FLYDVBS_LR300:
  643. case SAA7134_BOARD_FLYDVBT_LR301:
  644. case SAA7134_BOARD_FLYDVBTDUO:
  645. ir_codes = RC_MAP_FLYDVB;
  646. mask_keycode = 0x0001F00;
  647. mask_keydown = 0x0040000;
  648. break;
  649. case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
  650. case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
  651. case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
  652. ir_codes = RC_MAP_ASUS_PC39;
  653. mask_keydown = 0x0040000;
  654. rc5_gpio = 1;
  655. break;
  656. case SAA7134_BOARD_ENCORE_ENLTV:
  657. case SAA7134_BOARD_ENCORE_ENLTV_FM:
  658. ir_codes = RC_MAP_ENCORE_ENLTV;
  659. mask_keycode = 0x00007f;
  660. mask_keyup = 0x040000;
  661. polling = 50; // ms
  662. break;
  663. case SAA7134_BOARD_ENCORE_ENLTV_FM53:
  664. ir_codes = RC_MAP_ENCORE_ENLTV_FM53;
  665. mask_keydown = 0x0040000;
  666. mask_keycode = 0x00007f;
  667. nec_gpio = 1;
  668. break;
  669. case SAA7134_BOARD_10MOONSTVMASTER3:
  670. ir_codes = RC_MAP_ENCORE_ENLTV;
  671. mask_keycode = 0x5f80000;
  672. mask_keyup = 0x8000000;
  673. polling = 50; //ms
  674. break;
  675. case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
  676. ir_codes = RC_MAP_GENIUS_TVGO_A11MCE;
  677. mask_keycode = 0xff;
  678. mask_keydown = 0xf00000;
  679. polling = 50; /* ms */
  680. break;
  681. case SAA7134_BOARD_REAL_ANGEL_220:
  682. ir_codes = RC_MAP_REAL_AUDIO_220_32_KEYS;
  683. mask_keycode = 0x3f00;
  684. mask_keyup = 0x4000;
  685. polling = 50; /* ms */
  686. break;
  687. case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
  688. ir_codes = RC_MAP_KWORLD_PLUS_TV_ANALOG;
  689. mask_keycode = 0x7f;
  690. polling = 40; /* ms */
  691. break;
  692. case SAA7134_BOARD_VIDEOMATE_S350:
  693. ir_codes = RC_MAP_VIDEOMATE_S350;
  694. mask_keycode = 0x003f00;
  695. mask_keydown = 0x040000;
  696. break;
  697. case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
  698. ir_codes = RC_MAP_WINFAST;
  699. mask_keycode = 0x5f00;
  700. mask_keyup = 0x020000;
  701. polling = 50; /* ms */
  702. break;
  703. break;
  704. }
  705. if (NULL == ir_codes) {
  706. printk("%s: Oops: IR config error [card=%d]\n",
  707. dev->name, dev->board);
  708. return -ENODEV;
  709. }
  710. ir = kzalloc(sizeof(*ir), GFP_KERNEL);
  711. input_dev = input_allocate_device();
  712. if (!ir || !input_dev) {
  713. err = -ENOMEM;
  714. goto err_out_free;
  715. }
  716. ir->dev = input_dev;
  717. dev->remote = ir;
  718. ir->running = 0;
  719. /* init hardware-specific stuff */
  720. ir->mask_keycode = mask_keycode;
  721. ir->mask_keydown = mask_keydown;
  722. ir->mask_keyup = mask_keyup;
  723. ir->polling = polling;
  724. ir->rc5_gpio = rc5_gpio;
  725. ir->nec_gpio = nec_gpio;
  726. ir->raw_decode = raw_decode;
  727. /* init input device */
  728. snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
  729. saa7134_boards[dev->board].name);
  730. snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
  731. pci_name(dev->pci));
  732. ir->props.priv = dev;
  733. ir->props.open = saa7134_ir_open;
  734. ir->props.close = saa7134_ir_close;
  735. if (raw_decode)
  736. ir->props.driver_type = RC_DRIVER_IR_RAW;
  737. if (!raw_decode && allow_protocol_change) {
  738. ir->props.allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC;
  739. ir->props.change_protocol = saa7134_ir_change_protocol;
  740. }
  741. err = ir_input_init(input_dev, &ir->ir, ir_type);
  742. if (err < 0)
  743. goto err_out_free;
  744. input_dev->name = ir->name;
  745. input_dev->phys = ir->phys;
  746. input_dev->id.bustype = BUS_PCI;
  747. input_dev->id.version = 1;
  748. if (dev->pci->subsystem_vendor) {
  749. input_dev->id.vendor = dev->pci->subsystem_vendor;
  750. input_dev->id.product = dev->pci->subsystem_device;
  751. } else {
  752. input_dev->id.vendor = dev->pci->vendor;
  753. input_dev->id.product = dev->pci->device;
  754. }
  755. input_dev->dev.parent = &dev->pci->dev;
  756. err = ir_input_register(ir->dev, ir_codes, &ir->props, MODULE_NAME);
  757. if (err)
  758. goto err_out_free;
  759. /* the remote isn't as bouncy as a keyboard */
  760. ir->dev->rep[REP_DELAY] = repeat_delay;
  761. ir->dev->rep[REP_PERIOD] = repeat_period;
  762. return 0;
  763. err_out_free:
  764. dev->remote = NULL;
  765. kfree(ir);
  766. return err;
  767. }
  768. void saa7134_input_fini(struct saa7134_dev *dev)
  769. {
  770. if (NULL == dev->remote)
  771. return;
  772. saa7134_ir_stop(dev);
  773. ir_input_unregister(dev->remote->dev);
  774. kfree(dev->remote);
  775. dev->remote = NULL;
  776. }
  777. void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
  778. {
  779. struct i2c_board_info info;
  780. struct i2c_msg msg_msi = {
  781. .addr = 0x50,
  782. .flags = I2C_M_RD,
  783. .len = 0,
  784. .buf = NULL,
  785. };
  786. int rc;
  787. if (disable_ir) {
  788. dprintk("IR has been disabled, not probing for i2c remote\n");
  789. return;
  790. }
  791. memset(&info, 0, sizeof(struct i2c_board_info));
  792. memset(&dev->init_data, 0, sizeof(dev->init_data));
  793. strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
  794. switch (dev->board) {
  795. case SAA7134_BOARD_PINNACLE_PCTV_110i:
  796. case SAA7134_BOARD_PINNACLE_PCTV_310i:
  797. dev->init_data.name = "Pinnacle PCTV";
  798. if (pinnacle_remote == 0) {
  799. dev->init_data.get_key = get_key_pinnacle_color;
  800. dev->init_data.ir_codes = RC_MAP_PINNACLE_COLOR;
  801. info.addr = 0x47;
  802. } else {
  803. dev->init_data.get_key = get_key_pinnacle_grey;
  804. dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY;
  805. info.addr = 0x47;
  806. }
  807. break;
  808. case SAA7134_BOARD_UPMOST_PURPLE_TV:
  809. dev->init_data.name = "Purple TV";
  810. dev->init_data.get_key = get_key_purpletv;
  811. dev->init_data.ir_codes = RC_MAP_PURPLETV;
  812. info.addr = 0x7a;
  813. break;
  814. case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
  815. dev->init_data.name = "MSI TV@nywhere Plus";
  816. dev->init_data.get_key = get_key_msi_tvanywhere_plus;
  817. dev->init_data.ir_codes = RC_MAP_MSI_TVANYWHERE_PLUS;
  818. info.addr = 0x30;
  819. /* MSI TV@nywhere Plus controller doesn't seem to
  820. respond to probes unless we read something from
  821. an existing device. Weird...
  822. REVISIT: might no longer be needed */
  823. rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
  824. dprintk(KERN_DEBUG "probe 0x%02x @ %s: %s\n",
  825. msg_msi.addr, dev->i2c_adap.name,
  826. (1 == rc) ? "yes" : "no");
  827. break;
  828. case SAA7134_BOARD_HAUPPAUGE_HVR1110:
  829. dev->init_data.name = "HVR 1110";
  830. dev->init_data.get_key = get_key_hvr1110;
  831. dev->init_data.ir_codes = RC_MAP_HAUPPAUGE_NEW;
  832. info.addr = 0x71;
  833. break;
  834. case SAA7134_BOARD_BEHOLD_607FM_MK3:
  835. case SAA7134_BOARD_BEHOLD_607FM_MK5:
  836. case SAA7134_BOARD_BEHOLD_609FM_MK3:
  837. case SAA7134_BOARD_BEHOLD_609FM_MK5:
  838. case SAA7134_BOARD_BEHOLD_607RDS_MK3:
  839. case SAA7134_BOARD_BEHOLD_607RDS_MK5:
  840. case SAA7134_BOARD_BEHOLD_609RDS_MK3:
  841. case SAA7134_BOARD_BEHOLD_609RDS_MK5:
  842. case SAA7134_BOARD_BEHOLD_M6:
  843. case SAA7134_BOARD_BEHOLD_M63:
  844. case SAA7134_BOARD_BEHOLD_M6_EXTRA:
  845. case SAA7134_BOARD_BEHOLD_H6:
  846. case SAA7134_BOARD_BEHOLD_X7:
  847. dev->init_data.name = "BeholdTV";
  848. dev->init_data.get_key = get_key_beholdm6xx;
  849. dev->init_data.ir_codes = RC_MAP_BEHOLD;
  850. dev->init_data.type = IR_TYPE_NEC;
  851. info.addr = 0x2d;
  852. break;
  853. case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
  854. case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
  855. info.addr = 0x40;
  856. break;
  857. case SAA7134_BOARD_FLYDVB_TRIO:
  858. dev->init_data.name = "FlyDVB Trio";
  859. dev->init_data.get_key = get_key_flydvb_trio;
  860. dev->init_data.ir_codes = RC_MAP_FLYDVB;
  861. info.addr = 0x0b;
  862. break;
  863. default:
  864. dprintk("No I2C IR support for board %x\n", dev->board);
  865. return;
  866. }
  867. if (dev->init_data.name)
  868. info.platform_data = &dev->init_data;
  869. i2c_new_device(&dev->i2c_adap, &info);
  870. }
  871. static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
  872. {
  873. struct card_ir *ir = dev->remote;
  874. unsigned long timeout;
  875. int space;
  876. /* Generate initial event */
  877. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  878. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  879. space = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
  880. ir_raw_event_store_edge(dev->remote->dev, space ? IR_SPACE : IR_PULSE);
  881. /*
  882. * Wait 15 ms from the start of the first IR event before processing
  883. * the event. This time is enough for NEC protocol. May need adjustments
  884. * to work with other protocols.
  885. */
  886. if (!ir->active) {
  887. timeout = jiffies + jiffies_to_msecs(15);
  888. mod_timer(&ir->timer_end, timeout);
  889. ir->active = 1;
  890. }
  891. return 1;
  892. }
  893. static int saa7134_rc5_irq(struct saa7134_dev *dev)
  894. {
  895. struct card_ir *ir = dev->remote;
  896. struct timeval tv;
  897. u32 gap;
  898. unsigned long current_jiffies, timeout;
  899. /* get time of bit */
  900. current_jiffies = jiffies;
  901. do_gettimeofday(&tv);
  902. /* avoid overflow with gap >1s */
  903. if (tv.tv_sec - ir->base_time.tv_sec > 1) {
  904. gap = 200000;
  905. } else {
  906. gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
  907. tv.tv_usec - ir->base_time.tv_usec;
  908. }
  909. /* active code => add bit */
  910. if (ir->active) {
  911. /* only if in the code (otherwise spurious IRQ or timer
  912. late) */
  913. if (ir->last_bit < 28) {
  914. ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
  915. ir_rc5_remote_gap;
  916. ir->code |= 1 << ir->last_bit;
  917. }
  918. /* starting new code */
  919. } else {
  920. ir->active = 1;
  921. ir->code = 0;
  922. ir->base_time = tv;
  923. ir->last_bit = 0;
  924. timeout = current_jiffies + (500 + 30 * HZ) / 1000;
  925. mod_timer(&ir->timer_end, timeout);
  926. }
  927. return 1;
  928. }
  929. /* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
  930. The first pulse (start) has 9 + 4.5 ms
  931. */
  932. static void saa7134_nec_timer(unsigned long data)
  933. {
  934. struct saa7134_dev *dev = (struct saa7134_dev *) data;
  935. struct card_ir *ir = dev->remote;
  936. dprintk("Cancel key repeat\n");
  937. ir_input_nokey(ir->dev, &ir->ir);
  938. }
  939. static void nec_task(unsigned long data)
  940. {
  941. struct saa7134_dev *dev = (struct saa7134_dev *) data;
  942. struct card_ir *ir;
  943. struct timeval tv;
  944. int count, pulse, oldpulse, gap;
  945. u32 ircode = 0, not_code = 0;
  946. int ngap = 0;
  947. if (!data) {
  948. printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
  949. /* GPIO will be kept disabled */
  950. return;
  951. }
  952. ir = dev->remote;
  953. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  954. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  955. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  956. oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
  957. pulse = oldpulse;
  958. do_gettimeofday(&tv);
  959. ir->base_time = tv;
  960. /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
  961. Unfortunately, using IRQ to decode pulse didn't work, since it uses
  962. a pulse train of 38KHz. This means one pulse on each 52 us
  963. */
  964. do {
  965. /* Wait until the end of pulse/space or 5 ms */
  966. for (count = 0; count < 500; count++) {
  967. udelay(10);
  968. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  969. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  970. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  971. pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
  972. & ir->mask_keydown;
  973. if (pulse != oldpulse)
  974. break;
  975. }
  976. do_gettimeofday(&tv);
  977. gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
  978. tv.tv_usec - ir->base_time.tv_usec;
  979. if (!pulse) {
  980. /* Bit 0 has 560 us, while bit 1 has 1120 us.
  981. Do something only if bit == 1
  982. */
  983. if (ngap && (gap > 560 + 280)) {
  984. unsigned int shift = ngap - 1;
  985. /* Address first, then command */
  986. if (shift < 8) {
  987. shift += 8;
  988. ircode |= 1 << shift;
  989. } else if (shift < 16) {
  990. not_code |= 1 << shift;
  991. } else if (shift < 24) {
  992. shift -= 16;
  993. ircode |= 1 << shift;
  994. } else {
  995. shift -= 24;
  996. not_code |= 1 << shift;
  997. }
  998. }
  999. ngap++;
  1000. }
  1001. ir->base_time = tv;
  1002. /* TIMEOUT - Long pulse */
  1003. if (gap >= 5000)
  1004. break;
  1005. oldpulse = pulse;
  1006. } while (ngap < 32);
  1007. if (ngap == 32) {
  1008. /* FIXME: should check if not_code == ~ircode */
  1009. ir->code = ir_extract_bits(ircode, ir->mask_keycode);
  1010. dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
  1011. ir->code, ircode, not_code);
  1012. ir_input_keydown(ir->dev, &ir->ir, ir->code);
  1013. } else
  1014. dprintk("Repeat last key\n");
  1015. /* Keep repeating the last key */
  1016. mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150));
  1017. saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
  1018. }
  1019. static int saa7134_nec_irq(struct saa7134_dev *dev)
  1020. {
  1021. struct card_ir *ir = dev->remote;
  1022. saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
  1023. tasklet_schedule(&ir->tlet);
  1024. return 1;
  1025. }