saa7134-input.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. /*
  2. *
  3. * handle saa7134 IR remotes via linux kernel input layer.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/delay.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/input.h>
  25. #include <linux/slab.h>
  26. #include "saa7134-reg.h"
  27. #include "saa7134.h"
  28. #define MODULE_NAME "saa7134"
  29. static unsigned int disable_ir;
  30. module_param(disable_ir, int, 0444);
  31. MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
  32. static unsigned int ir_debug;
  33. module_param(ir_debug, int, 0644);
  34. MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
  35. static int pinnacle_remote;
  36. module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
  37. MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
  38. static int ir_rc5_remote_gap = 885;
  39. module_param(ir_rc5_remote_gap, int, 0644);
  40. static int ir_rc5_key_timeout = 115;
  41. module_param(ir_rc5_key_timeout, int, 0644);
  42. static int repeat_delay = 500;
  43. module_param(repeat_delay, int, 0644);
  44. MODULE_PARM_DESC(repeat_delay, "delay before key repeat started");
  45. static int repeat_period = 33;
  46. module_param(repeat_period, int, 0644);
  47. MODULE_PARM_DESC(repeat_period, "repeat period between "
  48. "keypresses when key is down");
  49. static unsigned int disable_other_ir;
  50. module_param(disable_other_ir, int, 0644);
  51. MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
  52. "alternative remotes from other manufacturers");
  53. #define dprintk(fmt, arg...) if (ir_debug) \
  54. printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg)
  55. #define i2cdprintk(fmt, arg...) if (ir_debug) \
  56. printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg)
  57. /* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */
  58. static int saa7134_rc5_irq(struct saa7134_dev *dev);
  59. static int saa7134_nec_irq(struct saa7134_dev *dev);
  60. static int saa7134_raw_decode_irq(struct saa7134_dev *dev);
  61. static void nec_task(unsigned long data);
  62. static void saa7134_nec_timer(unsigned long data);
  63. /* -------------------- GPIO generic keycode builder -------------------- */
  64. static int build_key(struct saa7134_dev *dev)
  65. {
  66. struct card_ir *ir = dev->remote;
  67. u32 gpio, data;
  68. /* here comes the additional handshake steps for some cards */
  69. switch (dev->board) {
  70. case SAA7134_BOARD_GOTVIEW_7135:
  71. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80);
  72. saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80);
  73. break;
  74. }
  75. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  76. saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
  77. saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN);
  78. gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
  79. if (ir->polling) {
  80. if (ir->last_gpio == gpio)
  81. return 0;
  82. ir->last_gpio = gpio;
  83. }
  84. data = ir_extract_bits(gpio, ir->mask_keycode);
  85. dprintk("build_key gpio=0x%x mask=0x%x data=%d\n",
  86. gpio, ir->mask_keycode, data);
  87. switch (dev->board) {
  88. case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
  89. if (data == ir->mask_keycode)
  90. ir_input_nokey(ir->dev, &ir->ir);
  91. else
  92. ir_input_keydown(ir->dev, &ir->ir, data);
  93. return 0;
  94. }
  95. if (ir->polling) {
  96. if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
  97. (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
  98. ir_input_keydown(ir->dev, &ir->ir, data);
  99. } else {
  100. ir_input_nokey(ir->dev, &ir->ir);
  101. }
  102. }
  103. else { /* IRQ driven mode - handle key press and release in one go */
  104. if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
  105. (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
  106. ir_input_keydown(ir->dev, &ir->ir, data);
  107. ir_input_nokey(ir->dev, &ir->ir);
  108. }
  109. }
  110. return 0;
  111. }
  112. /* --------------------- Chip specific I2C key builders ----------------- */
  113. static int get_key_flydvb_trio(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  114. {
  115. int gpio;
  116. int attempt = 0;
  117. unsigned char b;
  118. /* We need this to access GPI Used by the saa_readl macro. */
  119. struct saa7134_dev *dev = ir->c->adapter->algo_data;
  120. if (dev == NULL) {
  121. dprintk("get_key_flydvb_trio: "
  122. "gir->c->adapter->algo_data is NULL!\n");
  123. return -EIO;
  124. }
  125. /* rising SAA7134_GPIGPRESCAN reads the status */
  126. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  127. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  128. gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
  129. if (0x40000 & ~gpio)
  130. return 0; /* No button press */
  131. /* No button press - only before first key pressed */
  132. if (b == 0xFF)
  133. return 0;
  134. /* poll IR chip */
  135. /* weak up the IR chip */
  136. b = 0;
  137. while (1 != i2c_master_send(ir->c, &b, 1)) {
  138. if ((attempt++) < 10) {
  139. /*
  140. * wait a bit for next attempt -
  141. * I don't know how make it better
  142. */
  143. msleep(10);
  144. continue;
  145. }
  146. i2cdprintk("send wake up byte to pic16C505 (IR chip)"
  147. "failed %dx\n", attempt);
  148. return -EIO;
  149. }
  150. if (1 != i2c_master_recv(ir->c, &b, 1)) {
  151. i2cdprintk("read error\n");
  152. return -EIO;
  153. }
  154. *ir_key = b;
  155. *ir_raw = b;
  156. return 1;
  157. }
  158. static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
  159. u32 *ir_raw)
  160. {
  161. unsigned char b;
  162. int gpio;
  163. /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
  164. struct saa7134_dev *dev = ir->c->adapter->algo_data;
  165. if (dev == NULL) {
  166. dprintk("get_key_msi_tvanywhere_plus: "
  167. "gir->c->adapter->algo_data is NULL!\n");
  168. return -EIO;
  169. }
  170. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  171. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  172. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  173. gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
  174. /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
  175. I2C receive if gpio&0x40 is not low. */
  176. if (gpio & 0x40)
  177. return 0; /* No button press */
  178. /* GPIO says there is a button press. Get it. */
  179. if (1 != i2c_master_recv(ir->c, &b, 1)) {
  180. i2cdprintk("read error\n");
  181. return -EIO;
  182. }
  183. /* No button press */
  184. if (b == 0xff)
  185. return 0;
  186. /* Button pressed */
  187. dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
  188. *ir_key = b;
  189. *ir_raw = b;
  190. return 1;
  191. }
  192. static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  193. {
  194. unsigned char b;
  195. /* poll IR chip */
  196. if (1 != i2c_master_recv(ir->c, &b, 1)) {
  197. i2cdprintk("read error\n");
  198. return -EIO;
  199. }
  200. /* no button press */
  201. if (b==0)
  202. return 0;
  203. /* repeating */
  204. if (b & 0x80)
  205. return 1;
  206. *ir_key = b;
  207. *ir_raw = b;
  208. return 1;
  209. }
  210. static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  211. {
  212. unsigned char buf[5], cod4, code3, code4;
  213. /* poll IR chip */
  214. if (5 != i2c_master_recv(ir->c, buf, 5))
  215. return -EIO;
  216. cod4 = buf[4];
  217. code4 = (cod4 >> 2);
  218. code3 = buf[3];
  219. if (code3 == 0)
  220. /* no key pressed */
  221. return 0;
  222. /* return key */
  223. *ir_key = code4;
  224. *ir_raw = code4;
  225. return 1;
  226. }
  227. static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  228. {
  229. unsigned char data[12];
  230. u32 gpio;
  231. struct saa7134_dev *dev = ir->c->adapter->algo_data;
  232. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  233. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  234. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  235. gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
  236. if (0x400000 & ~gpio)
  237. return 0; /* No button press */
  238. ir->c->addr = 0x5a >> 1;
  239. if (12 != i2c_master_recv(ir->c, data, 12)) {
  240. i2cdprintk("read error\n");
  241. return -EIO;
  242. }
  243. /* IR of this card normally decode signals NEC-standard from
  244. * - Sven IHOO MT 5.1R remote. xxyye718
  245. * - Sven DVD HD-10xx remote. xxyyf708
  246. * - BBK ...
  247. * - mayby others
  248. * So, skip not our, if disable full codes mode.
  249. */
  250. if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir)
  251. return 0;
  252. /* Wrong data decode fix */
  253. if (data[9] != (unsigned char)(~data[8]))
  254. return 0;
  255. *ir_key = data[9];
  256. *ir_raw = data[9];
  257. return 1;
  258. }
  259. /* Common (grey or coloured) pinnacle PCTV remote handling
  260. *
  261. */
  262. static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
  263. int parity_offset, int marker, int code_modulo)
  264. {
  265. unsigned char b[4];
  266. unsigned int start = 0,parity = 0,code = 0;
  267. /* poll IR chip */
  268. if (4 != i2c_master_recv(ir->c, b, 4)) {
  269. i2cdprintk("read error\n");
  270. return -EIO;
  271. }
  272. for (start = 0; start < ARRAY_SIZE(b); start++) {
  273. if (b[start] == marker) {
  274. code=b[(start+parity_offset + 1) % 4];
  275. parity=b[(start+parity_offset) % 4];
  276. }
  277. }
  278. /* Empty Request */
  279. if (parity == 0)
  280. return 0;
  281. /* Repeating... */
  282. if (ir->old == parity)
  283. return 0;
  284. ir->old = parity;
  285. /* drop special codes when a key is held down a long time for the grey controller
  286. In this case, the second bit of the code is asserted */
  287. if (marker == 0xfe && (code & 0x40))
  288. return 0;
  289. code %= code_modulo;
  290. *ir_raw = code;
  291. *ir_key = code;
  292. i2cdprintk("Pinnacle PCTV key %02x\n", code);
  293. return 1;
  294. }
  295. /* The grey pinnacle PCTV remote
  296. *
  297. * There are one issue with this remote:
  298. * - I2c packet does not change when the same key is pressed quickly. The workaround
  299. * is to hold down each key for about half a second, so that another code is generated
  300. * in the i2c packet, and the function can distinguish key presses.
  301. *
  302. * Sylvain Pasche <sylvain.pasche@gmail.com>
  303. */
  304. static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  305. {
  306. return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff);
  307. }
  308. /* The new pinnacle PCTV remote (with the colored buttons)
  309. *
  310. * Ricardo Cerqueira <v4l@cerqueira.org>
  311. */
  312. static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  313. {
  314. /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE
  315. *
  316. * this is the only value that results in 42 unique
  317. * codes < 128
  318. */
  319. return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88);
  320. }
  321. void saa7134_input_irq(struct saa7134_dev *dev)
  322. {
  323. struct card_ir *ir;
  324. if (!dev || !dev->remote)
  325. return;
  326. ir = dev->remote;
  327. if (!ir->running)
  328. return;
  329. if (ir->nec_gpio) {
  330. saa7134_nec_irq(dev);
  331. } else if (!ir->polling && !ir->rc5_gpio && !ir->raw_decode) {
  332. build_key(dev);
  333. } else if (ir->rc5_gpio) {
  334. saa7134_rc5_irq(dev);
  335. } else if (ir->raw_decode) {
  336. saa7134_raw_decode_irq(dev);
  337. }
  338. }
  339. static void saa7134_input_timer(unsigned long data)
  340. {
  341. struct saa7134_dev *dev = (struct saa7134_dev *)data;
  342. struct card_ir *ir = dev->remote;
  343. build_key(dev);
  344. mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
  345. }
  346. void ir_raw_decode_timer_end(unsigned long data)
  347. {
  348. struct saa7134_dev *dev = (struct saa7134_dev *)data;
  349. struct card_ir *ir = dev->remote;
  350. ir_raw_event_handle(dev->remote->dev);
  351. ir->active = 0;
  352. }
  353. static int __saa7134_ir_start(void *priv)
  354. {
  355. struct saa7134_dev *dev = priv;
  356. struct card_ir *ir;
  357. if (!dev)
  358. return -EINVAL;
  359. ir = dev->remote;
  360. if (!ir)
  361. return -EINVAL;
  362. if (ir->running)
  363. return 0;
  364. ir->running = 1;
  365. if (ir->polling) {
  366. setup_timer(&ir->timer, saa7134_input_timer,
  367. (unsigned long)dev);
  368. ir->timer.expires = jiffies + HZ;
  369. add_timer(&ir->timer);
  370. } else if (ir->rc5_gpio) {
  371. /* set timer_end for code completion */
  372. init_timer(&ir->timer_end);
  373. ir->timer_end.function = ir_rc5_timer_end;
  374. ir->timer_end.data = (unsigned long)ir;
  375. init_timer(&ir->timer_keyup);
  376. ir->timer_keyup.function = ir_rc5_timer_keyup;
  377. ir->timer_keyup.data = (unsigned long)ir;
  378. ir->shift_by = 2;
  379. ir->start = 0x2;
  380. ir->addr = 0x17;
  381. ir->rc5_key_timeout = ir_rc5_key_timeout;
  382. ir->rc5_remote_gap = ir_rc5_remote_gap;
  383. } else if (ir->nec_gpio) {
  384. setup_timer(&ir->timer_keyup, saa7134_nec_timer,
  385. (unsigned long)dev);
  386. tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
  387. } else if (ir->raw_decode) {
  388. /* set timer_end for code completion */
  389. init_timer(&ir->timer_end);
  390. ir->timer_end.function = ir_raw_decode_timer_end;
  391. ir->timer_end.data = (unsigned long)dev;
  392. ir->active = 0;
  393. }
  394. return 0;
  395. }
  396. static void __saa7134_ir_stop(void *priv)
  397. {
  398. struct saa7134_dev *dev = priv;
  399. struct card_ir *ir;
  400. if (!dev)
  401. return;
  402. ir = dev->remote;
  403. if (!ir)
  404. return;
  405. if (!ir->running)
  406. return;
  407. if (dev->remote->polling)
  408. del_timer_sync(&dev->remote->timer);
  409. else if (ir->rc5_gpio)
  410. del_timer_sync(&ir->timer_end);
  411. else if (ir->nec_gpio)
  412. tasklet_kill(&ir->tlet);
  413. else if (ir->raw_decode) {
  414. del_timer_sync(&ir->timer_end);
  415. ir->active = 0;
  416. }
  417. ir->running = 0;
  418. return;
  419. }
  420. int saa7134_ir_start(struct saa7134_dev *dev)
  421. {
  422. if (dev->remote->users)
  423. return __saa7134_ir_start(dev);
  424. return 0;
  425. }
  426. void saa7134_ir_stop(struct saa7134_dev *dev)
  427. {
  428. if (dev->remote->users)
  429. __saa7134_ir_stop(dev);
  430. }
  431. static int saa7134_ir_open(void *priv)
  432. {
  433. struct saa7134_dev *dev = priv;
  434. dev->remote->users++;
  435. return __saa7134_ir_start(dev);
  436. }
  437. static void saa7134_ir_close(void *priv)
  438. {
  439. struct saa7134_dev *dev = priv;
  440. dev->remote->users--;
  441. if (!dev->remote->users)
  442. __saa7134_ir_stop(dev);
  443. }
  444. int saa7134_ir_change_protocol(void *priv, u64 ir_type)
  445. {
  446. struct saa7134_dev *dev = priv;
  447. struct card_ir *ir = dev->remote;
  448. u32 nec_gpio, rc5_gpio;
  449. if (ir_type == IR_TYPE_RC5) {
  450. dprintk("Changing protocol to RC5\n");
  451. nec_gpio = 0;
  452. rc5_gpio = 1;
  453. } else if (ir_type == IR_TYPE_NEC) {
  454. dprintk("Changing protocol to NEC\n");
  455. nec_gpio = 1;
  456. rc5_gpio = 0;
  457. } else {
  458. dprintk("IR protocol type %ud is not supported\n",
  459. (unsigned)ir_type);
  460. return -EINVAL;
  461. }
  462. if (ir->running) {
  463. saa7134_ir_stop(dev);
  464. ir->nec_gpio = nec_gpio;
  465. ir->rc5_gpio = rc5_gpio;
  466. saa7134_ir_start(dev);
  467. } else {
  468. ir->nec_gpio = nec_gpio;
  469. ir->rc5_gpio = rc5_gpio;
  470. }
  471. return 0;
  472. }
  473. int saa7134_input_init1(struct saa7134_dev *dev)
  474. {
  475. struct card_ir *ir;
  476. struct input_dev *input_dev;
  477. char *ir_codes = NULL;
  478. u32 mask_keycode = 0;
  479. u32 mask_keydown = 0;
  480. u32 mask_keyup = 0;
  481. int polling = 0;
  482. int rc5_gpio = 0;
  483. int nec_gpio = 0;
  484. int raw_decode = 0;
  485. int allow_protocol_change = 0;
  486. u64 ir_type = IR_TYPE_OTHER;
  487. int err;
  488. if (dev->has_remote != SAA7134_REMOTE_GPIO)
  489. return -ENODEV;
  490. if (disable_ir)
  491. return -ENODEV;
  492. /* detect & configure */
  493. switch (dev->board) {
  494. case SAA7134_BOARD_FLYVIDEO2000:
  495. case SAA7134_BOARD_FLYVIDEO3000:
  496. case SAA7134_BOARD_FLYTVPLATINUM_FM:
  497. case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
  498. case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
  499. ir_codes = RC_MAP_FLYVIDEO;
  500. mask_keycode = 0xEC00000;
  501. mask_keydown = 0x0040000;
  502. break;
  503. case SAA7134_BOARD_CINERGY400:
  504. case SAA7134_BOARD_CINERGY600:
  505. case SAA7134_BOARD_CINERGY600_MK3:
  506. ir_codes = RC_MAP_CINERGY;
  507. mask_keycode = 0x00003f;
  508. mask_keyup = 0x040000;
  509. break;
  510. case SAA7134_BOARD_ECS_TVP3XP:
  511. case SAA7134_BOARD_ECS_TVP3XP_4CB5:
  512. ir_codes = RC_MAP_EZTV;
  513. mask_keycode = 0x00017c;
  514. mask_keyup = 0x000002;
  515. polling = 50; // ms
  516. break;
  517. case SAA7134_BOARD_KWORLD_XPERT:
  518. case SAA7134_BOARD_AVACSSMARTTV:
  519. ir_codes = RC_MAP_PIXELVIEW;
  520. mask_keycode = 0x00001F;
  521. mask_keyup = 0x000020;
  522. polling = 50; // ms
  523. break;
  524. case SAA7134_BOARD_MD2819:
  525. case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
  526. case SAA7134_BOARD_AVERMEDIA_305:
  527. case SAA7134_BOARD_AVERMEDIA_307:
  528. case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
  529. case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
  530. case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
  531. case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
  532. case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
  533. case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
  534. case SAA7134_BOARD_AVERMEDIA_M102:
  535. case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
  536. ir_codes = RC_MAP_AVERMEDIA;
  537. mask_keycode = 0x0007C8;
  538. mask_keydown = 0x000010;
  539. polling = 50; // ms
  540. /* Set GPIO pin2 to high to enable the IR controller */
  541. saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
  542. saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
  543. break;
  544. case SAA7134_BOARD_AVERMEDIA_M135A:
  545. ir_codes = RC_MAP_AVERMEDIA_M135A;
  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. info.addr = 0x30;
  825. /* MSI TV@nywhere Plus controller doesn't seem to
  826. respond to probes unless we read something from
  827. an existing device. Weird...
  828. REVISIT: might no longer be needed */
  829. rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
  830. dprintk(KERN_DEBUG "probe 0x%02x @ %s: %s\n",
  831. msg_msi.addr, dev->i2c_adap.name,
  832. (1 == rc) ? "yes" : "no");
  833. break;
  834. case SAA7134_BOARD_HAUPPAUGE_HVR1110:
  835. dev->init_data.name = "HVR 1110";
  836. dev->init_data.get_key = get_key_hvr1110;
  837. dev->init_data.ir_codes = RC_MAP_HAUPPAUGE_NEW;
  838. info.addr = 0x71;
  839. break;
  840. case SAA7134_BOARD_BEHOLD_607FM_MK3:
  841. case SAA7134_BOARD_BEHOLD_607FM_MK5:
  842. case SAA7134_BOARD_BEHOLD_609FM_MK3:
  843. case SAA7134_BOARD_BEHOLD_609FM_MK5:
  844. case SAA7134_BOARD_BEHOLD_607RDS_MK3:
  845. case SAA7134_BOARD_BEHOLD_607RDS_MK5:
  846. case SAA7134_BOARD_BEHOLD_609RDS_MK3:
  847. case SAA7134_BOARD_BEHOLD_609RDS_MK5:
  848. case SAA7134_BOARD_BEHOLD_M6:
  849. case SAA7134_BOARD_BEHOLD_M63:
  850. case SAA7134_BOARD_BEHOLD_M6_EXTRA:
  851. case SAA7134_BOARD_BEHOLD_H6:
  852. case SAA7134_BOARD_BEHOLD_X7:
  853. case SAA7134_BOARD_BEHOLD_H7:
  854. case SAA7134_BOARD_BEHOLD_A7:
  855. dev->init_data.name = "BeholdTV";
  856. dev->init_data.get_key = get_key_beholdm6xx;
  857. dev->init_data.ir_codes = RC_MAP_BEHOLD;
  858. dev->init_data.type = IR_TYPE_NEC;
  859. info.addr = 0x2d;
  860. break;
  861. case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
  862. case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
  863. info.addr = 0x40;
  864. break;
  865. case SAA7134_BOARD_FLYDVB_TRIO:
  866. dev->init_data.name = "FlyDVB Trio";
  867. dev->init_data.get_key = get_key_flydvb_trio;
  868. dev->init_data.ir_codes = RC_MAP_FLYDVB;
  869. info.addr = 0x0b;
  870. break;
  871. default:
  872. dprintk("No I2C IR support for board %x\n", dev->board);
  873. return;
  874. }
  875. if (dev->init_data.name)
  876. info.platform_data = &dev->init_data;
  877. i2c_new_device(&dev->i2c_adap, &info);
  878. }
  879. static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
  880. {
  881. struct card_ir *ir = dev->remote;
  882. unsigned long timeout;
  883. int space;
  884. /* Generate initial event */
  885. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  886. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  887. space = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
  888. ir_raw_event_store_edge(dev->remote->dev, space ? IR_SPACE : IR_PULSE);
  889. /*
  890. * Wait 15 ms from the start of the first IR event before processing
  891. * the event. This time is enough for NEC protocol. May need adjustments
  892. * to work with other protocols.
  893. */
  894. if (!ir->active) {
  895. timeout = jiffies + jiffies_to_msecs(15);
  896. mod_timer(&ir->timer_end, timeout);
  897. ir->active = 1;
  898. }
  899. return 1;
  900. }
  901. static int saa7134_rc5_irq(struct saa7134_dev *dev)
  902. {
  903. struct card_ir *ir = dev->remote;
  904. struct timeval tv;
  905. u32 gap;
  906. unsigned long current_jiffies, timeout;
  907. /* get time of bit */
  908. current_jiffies = jiffies;
  909. do_gettimeofday(&tv);
  910. /* avoid overflow with gap >1s */
  911. if (tv.tv_sec - ir->base_time.tv_sec > 1) {
  912. gap = 200000;
  913. } else {
  914. gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
  915. tv.tv_usec - ir->base_time.tv_usec;
  916. }
  917. /* active code => add bit */
  918. if (ir->active) {
  919. /* only if in the code (otherwise spurious IRQ or timer
  920. late) */
  921. if (ir->last_bit < 28) {
  922. ir->last_bit = (gap - ir_rc5_remote_gap / 2) /
  923. ir_rc5_remote_gap;
  924. ir->code |= 1 << ir->last_bit;
  925. }
  926. /* starting new code */
  927. } else {
  928. ir->active = 1;
  929. ir->code = 0;
  930. ir->base_time = tv;
  931. ir->last_bit = 0;
  932. timeout = current_jiffies + (500 + 30 * HZ) / 1000;
  933. mod_timer(&ir->timer_end, timeout);
  934. }
  935. return 1;
  936. }
  937. /* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
  938. The first pulse (start) has 9 + 4.5 ms
  939. */
  940. static void saa7134_nec_timer(unsigned long data)
  941. {
  942. struct saa7134_dev *dev = (struct saa7134_dev *) data;
  943. struct card_ir *ir = dev->remote;
  944. dprintk("Cancel key repeat\n");
  945. ir_input_nokey(ir->dev, &ir->ir);
  946. }
  947. static void nec_task(unsigned long data)
  948. {
  949. struct saa7134_dev *dev = (struct saa7134_dev *) data;
  950. struct card_ir *ir;
  951. struct timeval tv;
  952. int count, pulse, oldpulse, gap;
  953. u32 ircode = 0, not_code = 0;
  954. int ngap = 0;
  955. if (!data) {
  956. printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
  957. /* GPIO will be kept disabled */
  958. return;
  959. }
  960. ir = dev->remote;
  961. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  962. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  963. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  964. oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
  965. pulse = oldpulse;
  966. do_gettimeofday(&tv);
  967. ir->base_time = tv;
  968. /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
  969. Unfortunately, using IRQ to decode pulse didn't work, since it uses
  970. a pulse train of 38KHz. This means one pulse on each 52 us
  971. */
  972. do {
  973. /* Wait until the end of pulse/space or 5 ms */
  974. for (count = 0; count < 500; count++) {
  975. udelay(10);
  976. /* rising SAA7134_GPIO_GPRESCAN reads the status */
  977. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  978. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  979. pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
  980. & ir->mask_keydown;
  981. if (pulse != oldpulse)
  982. break;
  983. }
  984. do_gettimeofday(&tv);
  985. gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
  986. tv.tv_usec - ir->base_time.tv_usec;
  987. if (!pulse) {
  988. /* Bit 0 has 560 us, while bit 1 has 1120 us.
  989. Do something only if bit == 1
  990. */
  991. if (ngap && (gap > 560 + 280)) {
  992. unsigned int shift = ngap - 1;
  993. /* Address first, then command */
  994. if (shift < 8) {
  995. shift += 8;
  996. ircode |= 1 << shift;
  997. } else if (shift < 16) {
  998. not_code |= 1 << shift;
  999. } else if (shift < 24) {
  1000. shift -= 16;
  1001. ircode |= 1 << shift;
  1002. } else {
  1003. shift -= 24;
  1004. not_code |= 1 << shift;
  1005. }
  1006. }
  1007. ngap++;
  1008. }
  1009. ir->base_time = tv;
  1010. /* TIMEOUT - Long pulse */
  1011. if (gap >= 5000)
  1012. break;
  1013. oldpulse = pulse;
  1014. } while (ngap < 32);
  1015. if (ngap == 32) {
  1016. /* FIXME: should check if not_code == ~ircode */
  1017. ir->code = ir_extract_bits(ircode, ir->mask_keycode);
  1018. dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
  1019. ir->code, ircode, not_code);
  1020. ir_input_keydown(ir->dev, &ir->ir, ir->code);
  1021. } else
  1022. dprintk("Repeat last key\n");
  1023. /* Keep repeating the last key */
  1024. mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150));
  1025. saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
  1026. }
  1027. static int saa7134_nec_irq(struct saa7134_dev *dev)
  1028. {
  1029. struct card_ir *ir = dev->remote;
  1030. saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P);
  1031. tasklet_schedule(&ir->tlet);
  1032. return 1;
  1033. }