saa7134-input.c 26 KB

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