saa7134-input.c 30 KB

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