saa7134-input.c 24 KB

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