saa7134-input.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  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. struct ir_scancode_table *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. u64 ir_type = IR_TYPE_OTHER;
  486. int err;
  487. if (dev->has_remote != SAA7134_REMOTE_GPIO)
  488. return -ENODEV;
  489. if (disable_ir)
  490. return -ENODEV;
  491. /* detect & configure */
  492. switch (dev->board) {
  493. case SAA7134_BOARD_FLYVIDEO2000:
  494. case SAA7134_BOARD_FLYVIDEO3000:
  495. case SAA7134_BOARD_FLYTVPLATINUM_FM:
  496. case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
  497. case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
  498. ir_codes = &ir_codes_flyvideo_table;
  499. mask_keycode = 0xEC00000;
  500. mask_keydown = 0x0040000;
  501. break;
  502. case SAA7134_BOARD_CINERGY400:
  503. case SAA7134_BOARD_CINERGY600:
  504. case SAA7134_BOARD_CINERGY600_MK3:
  505. ir_codes = &ir_codes_cinergy_table;
  506. mask_keycode = 0x00003f;
  507. mask_keyup = 0x040000;
  508. break;
  509. case SAA7134_BOARD_ECS_TVP3XP:
  510. case SAA7134_BOARD_ECS_TVP3XP_4CB5:
  511. ir_codes = &ir_codes_eztv_table;
  512. mask_keycode = 0x00017c;
  513. mask_keyup = 0x000002;
  514. polling = 50; // ms
  515. break;
  516. case SAA7134_BOARD_KWORLD_XPERT:
  517. case SAA7134_BOARD_AVACSSMARTTV:
  518. ir_codes = &ir_codes_pixelview_table;
  519. mask_keycode = 0x00001F;
  520. mask_keyup = 0x000020;
  521. polling = 50; // ms
  522. break;
  523. case SAA7134_BOARD_MD2819:
  524. case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
  525. case SAA7134_BOARD_AVERMEDIA_305:
  526. case SAA7134_BOARD_AVERMEDIA_307:
  527. case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
  528. case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
  529. case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
  530. case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
  531. case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
  532. case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
  533. case SAA7134_BOARD_AVERMEDIA_M102:
  534. case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
  535. ir_codes = &ir_codes_avermedia_table;
  536. mask_keycode = 0x0007C8;
  537. mask_keydown = 0x000010;
  538. polling = 50; // ms
  539. /* Set GPIO pin2 to high to enable the IR controller */
  540. saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
  541. saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
  542. break;
  543. case SAA7134_BOARD_AVERMEDIA_M135A:
  544. ir_codes = &ir_codes_avermedia_m135a_rm_jx_table;
  545. mask_keydown = 0x0040000;
  546. mask_keycode = 0xffff;
  547. raw_decode = 1;
  548. break;
  549. case SAA7134_BOARD_AVERMEDIA_777:
  550. case SAA7134_BOARD_AVERMEDIA_A16AR:
  551. ir_codes = &ir_codes_avermedia_table;
  552. mask_keycode = 0x02F200;
  553. mask_keydown = 0x000400;
  554. polling = 50; // ms
  555. /* Without this we won't receive key up events */
  556. saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
  557. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
  558. break;
  559. case SAA7134_BOARD_AVERMEDIA_A16D:
  560. ir_codes = &ir_codes_avermedia_a16d_table;
  561. mask_keycode = 0x02F200;
  562. mask_keydown = 0x000400;
  563. polling = 50; /* ms */
  564. /* Without this we won't receive key up events */
  565. saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
  566. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
  567. break;
  568. case SAA7134_BOARD_KWORLD_TERMINATOR:
  569. ir_codes = &ir_codes_pixelview_table;
  570. mask_keycode = 0x00001f;
  571. mask_keyup = 0x000060;
  572. polling = 50; // ms
  573. break;
  574. case SAA7134_BOARD_MANLI_MTV001:
  575. case SAA7134_BOARD_MANLI_MTV002:
  576. ir_codes = &ir_codes_manli_table;
  577. mask_keycode = 0x001f00;
  578. mask_keyup = 0x004000;
  579. polling = 50; /* ms */
  580. break;
  581. case SAA7134_BOARD_BEHOLD_409FM:
  582. case SAA7134_BOARD_BEHOLD_401:
  583. case SAA7134_BOARD_BEHOLD_403:
  584. case SAA7134_BOARD_BEHOLD_403FM:
  585. case SAA7134_BOARD_BEHOLD_405:
  586. case SAA7134_BOARD_BEHOLD_405FM:
  587. case SAA7134_BOARD_BEHOLD_407:
  588. case SAA7134_BOARD_BEHOLD_407FM:
  589. case SAA7134_BOARD_BEHOLD_409:
  590. case SAA7134_BOARD_BEHOLD_505FM:
  591. case SAA7134_BOARD_BEHOLD_505RDS_MK5:
  592. case SAA7134_BOARD_BEHOLD_505RDS_MK3:
  593. case SAA7134_BOARD_BEHOLD_507_9FM:
  594. case SAA7134_BOARD_BEHOLD_507RDS_MK3:
  595. case SAA7134_BOARD_BEHOLD_507RDS_MK5:
  596. ir_codes = &ir_codes_manli_table;
  597. mask_keycode = 0x003f00;
  598. mask_keyup = 0x004000;
  599. polling = 50; /* ms */
  600. break;
  601. case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
  602. ir_codes = &ir_codes_behold_columbus_table;
  603. mask_keycode = 0x003f00;
  604. mask_keyup = 0x004000;
  605. polling = 50; // ms
  606. break;
  607. case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
  608. ir_codes = &ir_codes_pctv_sedna_table;
  609. mask_keycode = 0x001f00;
  610. mask_keyup = 0x004000;
  611. polling = 50; // ms
  612. break;
  613. case SAA7134_BOARD_GOTVIEW_7135:
  614. ir_codes = &ir_codes_gotview7135_table;
  615. mask_keycode = 0x0003CC;
  616. mask_keydown = 0x000010;
  617. polling = 5; /* ms */
  618. saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
  619. break;
  620. case SAA7134_BOARD_VIDEOMATE_TV_PVR:
  621. case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
  622. case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
  623. ir_codes = &ir_codes_videomate_tv_pvr_table;
  624. mask_keycode = 0x00003F;
  625. mask_keyup = 0x400000;
  626. polling = 50; // ms
  627. break;
  628. case SAA7134_BOARD_PROTEUS_2309:
  629. ir_codes = &ir_codes_proteus_2309_table;
  630. mask_keycode = 0x00007F;
  631. mask_keyup = 0x000080;
  632. polling = 50; // ms
  633. break;
  634. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  635. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  636. ir_codes = &ir_codes_videomate_tv_pvr_table;
  637. mask_keycode = 0x003F00;
  638. mask_keyup = 0x040000;
  639. break;
  640. case SAA7134_BOARD_FLYDVBS_LR300:
  641. case SAA7134_BOARD_FLYDVBT_LR301:
  642. case SAA7134_BOARD_FLYDVBTDUO:
  643. ir_codes = &ir_codes_flydvb_table;
  644. mask_keycode = 0x0001F00;
  645. mask_keydown = 0x0040000;
  646. break;
  647. case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
  648. case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
  649. case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
  650. ir_codes = &ir_codes_asus_pc39_table;
  651. mask_keydown = 0x0040000;
  652. rc5_gpio = 1;
  653. break;
  654. case SAA7134_BOARD_ENCORE_ENLTV:
  655. case SAA7134_BOARD_ENCORE_ENLTV_FM:
  656. ir_codes = &ir_codes_encore_enltv_table;
  657. mask_keycode = 0x00007f;
  658. mask_keyup = 0x040000;
  659. polling = 50; // ms
  660. break;
  661. case SAA7134_BOARD_ENCORE_ENLTV_FM53:
  662. ir_codes = &ir_codes_encore_enltv_fm53_table;
  663. mask_keydown = 0x0040000;
  664. mask_keycode = 0x00007f;
  665. nec_gpio = 1;
  666. break;
  667. case SAA7134_BOARD_10MOONSTVMASTER3:
  668. ir_codes = &ir_codes_encore_enltv_table;
  669. mask_keycode = 0x5f80000;
  670. mask_keyup = 0x8000000;
  671. polling = 50; //ms
  672. break;
  673. case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
  674. ir_codes = &ir_codes_genius_tvgo_a11mce_table;
  675. mask_keycode = 0xff;
  676. mask_keydown = 0xf00000;
  677. polling = 50; /* ms */
  678. break;
  679. case SAA7134_BOARD_REAL_ANGEL_220:
  680. ir_codes = &ir_codes_real_audio_220_32_keys_table;
  681. mask_keycode = 0x3f00;
  682. mask_keyup = 0x4000;
  683. polling = 50; /* ms */
  684. break;
  685. case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
  686. ir_codes = &ir_codes_kworld_plus_tv_analog_table;
  687. mask_keycode = 0x7f;
  688. polling = 40; /* ms */
  689. break;
  690. case SAA7134_BOARD_VIDEOMATE_S350:
  691. ir_codes = &ir_codes_videomate_s350_table;
  692. mask_keycode = 0x003f00;
  693. mask_keydown = 0x040000;
  694. break;
  695. case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
  696. ir_codes = &ir_codes_winfast_table;
  697. mask_keycode = 0x5f00;
  698. mask_keyup = 0x020000;
  699. polling = 50; /* ms */
  700. break;
  701. break;
  702. }
  703. if (NULL == ir_codes) {
  704. printk("%s: Oops: IR config error [card=%d]\n",
  705. dev->name, dev->board);
  706. return -ENODEV;
  707. }
  708. ir = kzalloc(sizeof(*ir), GFP_KERNEL);
  709. input_dev = input_allocate_device();
  710. if (!ir || !input_dev) {
  711. err = -ENOMEM;
  712. goto err_out_free;
  713. }
  714. ir->dev = input_dev;
  715. dev->remote = ir;
  716. ir->running = 0;
  717. /* init hardware-specific stuff */
  718. ir->mask_keycode = mask_keycode;
  719. ir->mask_keydown = mask_keydown;
  720. ir->mask_keyup = mask_keyup;
  721. ir->polling = polling;
  722. ir->rc5_gpio = rc5_gpio;
  723. ir->nec_gpio = nec_gpio;
  724. ir->raw_decode = raw_decode;
  725. /* init input device */
  726. snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
  727. saa7134_boards[dev->board].name);
  728. snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
  729. pci_name(dev->pci));
  730. ir->props.priv = dev;
  731. ir->props.open = saa7134_ir_open;
  732. ir->props.close = saa7134_ir_close;
  733. if (ir_codes->ir_type != IR_TYPE_OTHER && !raw_decode) {
  734. ir->props.allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC;
  735. ir->props.change_protocol = saa7134_ir_change_protocol;
  736. /* Set IR protocol */
  737. saa7134_ir_change_protocol(ir->props.priv, ir_codes->ir_type);
  738. }
  739. err = ir_input_init(input_dev, &ir->ir, ir_type);
  740. if (err < 0)
  741. goto err_out_free;
  742. input_dev->name = ir->name;
  743. input_dev->phys = ir->phys;
  744. input_dev->id.bustype = BUS_PCI;
  745. input_dev->id.version = 1;
  746. if (dev->pci->subsystem_vendor) {
  747. input_dev->id.vendor = dev->pci->subsystem_vendor;
  748. input_dev->id.product = dev->pci->subsystem_device;
  749. } else {
  750. input_dev->id.vendor = dev->pci->vendor;
  751. input_dev->id.product = dev->pci->device;
  752. }
  753. input_dev->dev.parent = &dev->pci->dev;
  754. err = ir_input_register(ir->dev, ir_codes, &ir->props, MODULE_NAME);
  755. if (err)
  756. goto err_out_free;
  757. if (ir_codes->ir_type != IR_TYPE_OTHER) {
  758. err = ir_raw_event_register(ir->dev);
  759. if (err)
  760. goto err_out_free;
  761. }
  762. /* the remote isn't as bouncy as a keyboard */
  763. ir->dev->rep[REP_DELAY] = repeat_delay;
  764. ir->dev->rep[REP_PERIOD] = repeat_period;
  765. return 0;
  766. err_out_free:
  767. dev->remote = NULL;
  768. kfree(ir);
  769. return err;
  770. }
  771. void saa7134_input_fini(struct saa7134_dev *dev)
  772. {
  773. if (NULL == dev->remote)
  774. return;
  775. saa7134_ir_stop(dev);
  776. ir_raw_event_unregister(dev->remote->dev);
  777. ir_input_unregister(dev->remote->dev);
  778. kfree(dev->remote);
  779. dev->remote = NULL;
  780. }
  781. void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
  782. {
  783. struct i2c_board_info info;
  784. struct i2c_msg msg_msi = {
  785. .addr = 0x50,
  786. .flags = I2C_M_RD,
  787. .len = 0,
  788. .buf = NULL,
  789. };
  790. int rc;
  791. if (disable_ir) {
  792. dprintk("IR has been disabled, not probing for i2c remote\n");
  793. return;
  794. }
  795. memset(&info, 0, sizeof(struct i2c_board_info));
  796. memset(&dev->init_data, 0, sizeof(dev->init_data));
  797. strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
  798. switch (dev->board) {
  799. case SAA7134_BOARD_PINNACLE_PCTV_110i:
  800. case SAA7134_BOARD_PINNACLE_PCTV_310i:
  801. dev->init_data.name = "Pinnacle PCTV";
  802. if (pinnacle_remote == 0) {
  803. dev->init_data.get_key = get_key_pinnacle_color;
  804. dev->init_data.ir_codes = &ir_codes_pinnacle_color_table;
  805. info.addr = 0x47;
  806. } else {
  807. dev->init_data.get_key = get_key_pinnacle_grey;
  808. dev->init_data.ir_codes = &ir_codes_pinnacle_grey_table;
  809. info.addr = 0x47;
  810. }
  811. break;
  812. case SAA7134_BOARD_UPMOST_PURPLE_TV:
  813. dev->init_data.name = "Purple TV";
  814. dev->init_data.get_key = get_key_purpletv;
  815. dev->init_data.ir_codes = &ir_codes_purpletv_table;
  816. info.addr = 0x7a;
  817. break;
  818. case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
  819. dev->init_data.name = "MSI TV@nywhere Plus";
  820. dev->init_data.get_key = get_key_msi_tvanywhere_plus;
  821. dev->init_data.ir_codes = &ir_codes_msi_tvanywhere_plus_table;
  822. info.addr = 0x30;
  823. /* MSI TV@nywhere Plus controller doesn't seem to
  824. respond to probes unless we read something from
  825. an existing device. Weird...
  826. REVISIT: might no longer be needed */
  827. rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
  828. dprintk(KERN_DEBUG "probe 0x%02x @ %s: %s\n",
  829. msg_msi.addr, dev->i2c_adap.name,
  830. (1 == rc) ? "yes" : "no");
  831. break;
  832. case SAA7134_BOARD_HAUPPAUGE_HVR1110:
  833. dev->init_data.name = "HVR 1110";
  834. dev->init_data.get_key = get_key_hvr1110;
  835. dev->init_data.ir_codes = &ir_codes_hauppauge_new_table;
  836. info.addr = 0x71;
  837. break;
  838. case SAA7134_BOARD_BEHOLD_607FM_MK3:
  839. case SAA7134_BOARD_BEHOLD_607FM_MK5:
  840. case SAA7134_BOARD_BEHOLD_609FM_MK3:
  841. case SAA7134_BOARD_BEHOLD_609FM_MK5:
  842. case SAA7134_BOARD_BEHOLD_607RDS_MK3:
  843. case SAA7134_BOARD_BEHOLD_607RDS_MK5:
  844. case SAA7134_BOARD_BEHOLD_609RDS_MK3:
  845. case SAA7134_BOARD_BEHOLD_609RDS_MK5:
  846. case SAA7134_BOARD_BEHOLD_M6:
  847. case SAA7134_BOARD_BEHOLD_M63:
  848. case SAA7134_BOARD_BEHOLD_M6_EXTRA:
  849. case SAA7134_BOARD_BEHOLD_H6:
  850. case SAA7134_BOARD_BEHOLD_X7:
  851. dev->init_data.name = "BeholdTV";
  852. dev->init_data.get_key = get_key_beholdm6xx;
  853. dev->init_data.ir_codes = &ir_codes_behold_table;
  854. dev->init_data.type = IR_TYPE_NEC;
  855. info.addr = 0x2d;
  856. break;
  857. case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
  858. case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
  859. info.addr = 0x40;
  860. break;
  861. case SAA7134_BOARD_FLYDVB_TRIO:
  862. dev->init_data.name = "FlyDVB Trio";
  863. dev->init_data.get_key = get_key_flydvb_trio;
  864. dev->init_data.ir_codes = &ir_codes_flydvb_table;
  865. info.addr = 0x0b;
  866. break;
  867. default:
  868. dprintk("No I2C IR support for board %x\n", dev->board);
  869. return;
  870. }
  871. if (dev->init_data.name)
  872. info.platform_data = &dev->init_data;
  873. i2c_new_device(&dev->i2c_adap, &info);
  874. }
  875. static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
  876. {
  877. struct card_ir *ir = dev->remote;
  878. unsigned long timeout;
  879. int pulse;
  880. /* Generate initial event */
  881. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  882. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  883. pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
  884. ir_raw_event_store(dev->remote->dev, pulse ? IR_PULSE : IR_SPACE);
  885. /*
  886. * Wait 15 ms from the start of the first IR event before processing
  887. * the event. This time is enough for NEC protocol. May need adjustments
  888. * to work with other protocols.
  889. */
  890. if (!ir->active) {
  891. timeout = jiffies + jiffies_to_msecs(15);
  892. mod_timer(&ir->timer_end, timeout);
  893. ir->active = 1;
  894. }
  895. return 1;
  896. }
  897. static int saa7134_rc5_irq(struct saa7134_dev *dev)
  898. {
  899. struct card_ir *ir = dev->remote;
  900. struct timeval tv;
  901. u32 gap;
  902. unsigned long current_jiffies, timeout;
  903. /* get time of bit */
  904. current_jiffies = jiffies;
  905. do_gettimeofday(&tv);
  906. /* avoid overflow with gap >1s */
  907. if (tv.tv_sec - ir->base_time.tv_sec > 1) {
  908. gap = 200000;
  909. } else {
  910. gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
  911. tv.tv_usec - ir->base_time.tv_usec;
  912. }
  913. /* active code => add bit */
  914. if (ir->active) {
  915. /* only if in the code (otherwise spurious IRQ or timer
  916. late) */
  917. if (ir->last_bit < 28) {
  918. ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
  919. ir_rc5_remote_gap;
  920. ir->code |= 1 << ir->last_bit;
  921. }
  922. /* starting new code */
  923. } else {
  924. ir->active = 1;
  925. ir->code = 0;
  926. ir->base_time = tv;
  927. ir->last_bit = 0;
  928. timeout = current_jiffies + (500 + 30 * HZ) / 1000;
  929. mod_timer(&ir->timer_end, timeout);
  930. }
  931. return 1;
  932. }
  933. /* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
  934. The first pulse (start) has 9 + 4.5 ms
  935. */
  936. static void saa7134_nec_timer(unsigned long data)
  937. {
  938. struct saa7134_dev *dev = (struct saa7134_dev *) data;
  939. struct card_ir *ir = dev->remote;
  940. dprintk("Cancel key repeat\n");
  941. ir_input_nokey(ir->dev, &ir->ir);
  942. }
  943. static void nec_task(unsigned long data)
  944. {
  945. struct saa7134_dev *dev = (struct saa7134_dev *) data;
  946. struct card_ir *ir;
  947. struct timeval tv;
  948. int count, pulse, oldpulse, gap;
  949. u32 ircode = 0, not_code = 0;
  950. int ngap = 0;
  951. if (!data) {
  952. printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
  953. /* GPIO will be kept disabled */
  954. return;
  955. }
  956. ir = dev->remote;
  957. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  958. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  959. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  960. oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
  961. pulse = oldpulse;
  962. do_gettimeofday(&tv);
  963. ir->base_time = tv;
  964. /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
  965. Unfortunately, using IRQ to decode pulse didn't work, since it uses
  966. a pulse train of 38KHz. This means one pulse on each 52 us
  967. */
  968. do {
  969. /* Wait until the end of pulse/space or 5 ms */
  970. for (count = 0; count < 500; count++) {
  971. udelay(10);
  972. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  973. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  974. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  975. pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
  976. & ir->mask_keydown;
  977. if (pulse != oldpulse)
  978. break;
  979. }
  980. do_gettimeofday(&tv);
  981. gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
  982. tv.tv_usec - ir->base_time.tv_usec;
  983. if (!pulse) {
  984. /* Bit 0 has 560 us, while bit 1 has 1120 us.
  985. Do something only if bit == 1
  986. */
  987. if (ngap && (gap > 560 + 280)) {
  988. unsigned int shift = ngap - 1;
  989. /* Address first, then command */
  990. if (shift < 8) {
  991. shift += 8;
  992. ircode |= 1 << shift;
  993. } else if (shift < 16) {
  994. not_code |= 1 << shift;
  995. } else if (shift < 24) {
  996. shift -= 16;
  997. ircode |= 1 << shift;
  998. } else {
  999. shift -= 24;
  1000. not_code |= 1 << shift;
  1001. }
  1002. }
  1003. ngap++;
  1004. }
  1005. ir->base_time = tv;
  1006. /* TIMEOUT - Long pulse */
  1007. if (gap >= 5000)
  1008. break;
  1009. oldpulse = pulse;
  1010. } while (ngap < 32);
  1011. if (ngap == 32) {
  1012. /* FIXME: should check if not_code == ~ircode */
  1013. ir->code = ir_extract_bits(ircode, ir->mask_keycode);
  1014. dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
  1015. ir->code, ircode, not_code);
  1016. ir_input_keydown(ir->dev, &ir->ir, ir->code);
  1017. } else
  1018. dprintk("Repeat last key\n");
  1019. /* Keep repeating the last key */
  1020. mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150));
  1021. saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
  1022. }
  1023. static int saa7134_nec_irq(struct saa7134_dev *dev)
  1024. {
  1025. struct card_ir *ir = dev->remote;
  1026. saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
  1027. tasklet_schedule(&ir->tlet);
  1028. return 1;
  1029. }