saa7134-input.c 30 KB

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