saa7134-input.c 27 KB

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