saa7134-input.c 28 KB

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