saa7134-input.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  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. ir_raw_event_handle(dev->remote->dev);
  354. }
  355. static int __saa7134_ir_start(void *priv)
  356. {
  357. struct saa7134_dev *dev = priv;
  358. struct saa7134_card_ir *ir;
  359. if (!dev || !dev->remote)
  360. return -EINVAL;
  361. ir = dev->remote;
  362. if (ir->running)
  363. return 0;
  364. /* Moved here from saa7134_input_init1() because the latter
  365. * is not called on device resume */
  366. switch (dev->board) {
  367. case SAA7134_BOARD_MD2819:
  368. case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
  369. case SAA7134_BOARD_AVERMEDIA_305:
  370. case SAA7134_BOARD_AVERMEDIA_307:
  371. case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
  372. case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
  373. case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
  374. case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
  375. case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
  376. case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
  377. case SAA7134_BOARD_AVERMEDIA_M102:
  378. case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
  379. /* Without this we won't receive key up events */
  380. saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
  381. saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
  382. break;
  383. case SAA7134_BOARD_AVERMEDIA_777:
  384. case SAA7134_BOARD_AVERMEDIA_A16AR:
  385. /* Without this we won't receive key up events */
  386. saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
  387. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
  388. break;
  389. case SAA7134_BOARD_AVERMEDIA_A16D:
  390. /* Without this we won't receive key up events */
  391. saa_setb(SAA7134_GPIO_GPMODE1, 0x1);
  392. saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1);
  393. break;
  394. case SAA7134_BOARD_GOTVIEW_7135:
  395. saa_setb(SAA7134_GPIO_GPMODE1, 0x80);
  396. break;
  397. }
  398. ir->running = true;
  399. if (ir->polling) {
  400. setup_timer(&ir->timer, saa7134_input_timer,
  401. (unsigned long)dev);
  402. ir->timer.expires = jiffies + HZ;
  403. add_timer(&ir->timer);
  404. } else if (ir->raw_decode) {
  405. /* set timer_end for code completion */
  406. setup_timer(&ir->timer, ir_raw_decode_timer_end,
  407. (unsigned long)dev);
  408. }
  409. return 0;
  410. }
  411. static void __saa7134_ir_stop(void *priv)
  412. {
  413. struct saa7134_dev *dev = priv;
  414. struct saa7134_card_ir *ir;
  415. if (!dev || !dev->remote)
  416. return;
  417. ir = dev->remote;
  418. if (!ir->running)
  419. return;
  420. if (ir->polling || ir->raw_decode)
  421. del_timer_sync(&ir->timer);
  422. ir->running = false;
  423. return;
  424. }
  425. int saa7134_ir_start(struct saa7134_dev *dev)
  426. {
  427. if (dev->remote->users)
  428. return __saa7134_ir_start(dev);
  429. return 0;
  430. }
  431. void saa7134_ir_stop(struct saa7134_dev *dev)
  432. {
  433. if (dev->remote->users)
  434. __saa7134_ir_stop(dev);
  435. }
  436. static int saa7134_ir_open(struct rc_dev *rc)
  437. {
  438. struct saa7134_dev *dev = rc->priv;
  439. dev->remote->users++;
  440. return __saa7134_ir_start(dev);
  441. }
  442. static void saa7134_ir_close(struct rc_dev *rc)
  443. {
  444. struct saa7134_dev *dev = rc->priv;
  445. dev->remote->users--;
  446. if (!dev->remote->users)
  447. __saa7134_ir_stop(dev);
  448. }
  449. int saa7134_input_init1(struct saa7134_dev *dev)
  450. {
  451. struct saa7134_card_ir *ir;
  452. struct rc_dev *rc;
  453. char *ir_codes = NULL;
  454. u32 mask_keycode = 0;
  455. u32 mask_keydown = 0;
  456. u32 mask_keyup = 0;
  457. unsigned polling = 0;
  458. bool raw_decode = false;
  459. int err;
  460. if (dev->has_remote != SAA7134_REMOTE_GPIO)
  461. return -ENODEV;
  462. if (disable_ir)
  463. return -ENODEV;
  464. /* detect & configure */
  465. switch (dev->board) {
  466. case SAA7134_BOARD_FLYVIDEO2000:
  467. case SAA7134_BOARD_FLYVIDEO3000:
  468. case SAA7134_BOARD_FLYTVPLATINUM_FM:
  469. case SAA7134_BOARD_FLYTVPLATINUM_MINI2:
  470. case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM:
  471. ir_codes = RC_MAP_FLYVIDEO;
  472. mask_keycode = 0xEC00000;
  473. mask_keydown = 0x0040000;
  474. break;
  475. case SAA7134_BOARD_CINERGY400:
  476. case SAA7134_BOARD_CINERGY600:
  477. case SAA7134_BOARD_CINERGY600_MK3:
  478. ir_codes = RC_MAP_CINERGY;
  479. mask_keycode = 0x00003f;
  480. mask_keyup = 0x040000;
  481. break;
  482. case SAA7134_BOARD_ECS_TVP3XP:
  483. case SAA7134_BOARD_ECS_TVP3XP_4CB5:
  484. ir_codes = RC_MAP_EZTV;
  485. mask_keycode = 0x00017c;
  486. mask_keyup = 0x000002;
  487. polling = 50; // ms
  488. break;
  489. case SAA7134_BOARD_KWORLD_XPERT:
  490. case SAA7134_BOARD_AVACSSMARTTV:
  491. ir_codes = RC_MAP_PIXELVIEW;
  492. mask_keycode = 0x00001F;
  493. mask_keyup = 0x000020;
  494. polling = 50; // ms
  495. break;
  496. case SAA7134_BOARD_MD2819:
  497. case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
  498. case SAA7134_BOARD_AVERMEDIA_305:
  499. case SAA7134_BOARD_AVERMEDIA_307:
  500. case SAA7134_BOARD_AVERMEDIA_STUDIO_305:
  501. case SAA7134_BOARD_AVERMEDIA_STUDIO_505:
  502. case SAA7134_BOARD_AVERMEDIA_STUDIO_307:
  503. case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
  504. case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA:
  505. case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
  506. case SAA7134_BOARD_AVERMEDIA_M102:
  507. case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS:
  508. ir_codes = RC_MAP_AVERMEDIA;
  509. mask_keycode = 0x0007C8;
  510. mask_keydown = 0x000010;
  511. polling = 50; // ms
  512. /* GPIO stuff moved to __saa7134_ir_start() */
  513. break;
  514. case SAA7134_BOARD_AVERMEDIA_M135A:
  515. ir_codes = RC_MAP_AVERMEDIA_M135A;
  516. mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
  517. mask_keyup = 0x0040000;
  518. mask_keycode = 0xffff;
  519. raw_decode = true;
  520. break;
  521. case SAA7134_BOARD_AVERMEDIA_M733A:
  522. ir_codes = RC_MAP_AVERMEDIA_M733A_RM_K6;
  523. mask_keydown = 0x0040000;
  524. mask_keyup = 0x0040000;
  525. mask_keycode = 0xffff;
  526. raw_decode = true;
  527. break;
  528. case SAA7134_BOARD_AVERMEDIA_777:
  529. case SAA7134_BOARD_AVERMEDIA_A16AR:
  530. ir_codes = RC_MAP_AVERMEDIA;
  531. mask_keycode = 0x02F200;
  532. mask_keydown = 0x000400;
  533. polling = 50; // ms
  534. /* GPIO stuff moved to __saa7134_ir_start() */
  535. break;
  536. case SAA7134_BOARD_AVERMEDIA_A16D:
  537. ir_codes = RC_MAP_AVERMEDIA_A16D;
  538. mask_keycode = 0x02F200;
  539. mask_keydown = 0x000400;
  540. polling = 50; /* ms */
  541. /* GPIO stuff moved to __saa7134_ir_start() */
  542. break;
  543. case SAA7134_BOARD_KWORLD_TERMINATOR:
  544. ir_codes = RC_MAP_PIXELVIEW;
  545. mask_keycode = 0x00001f;
  546. mask_keyup = 0x000060;
  547. polling = 50; // ms
  548. break;
  549. case SAA7134_BOARD_MANLI_MTV001:
  550. case SAA7134_BOARD_MANLI_MTV002:
  551. ir_codes = RC_MAP_MANLI;
  552. mask_keycode = 0x001f00;
  553. mask_keyup = 0x004000;
  554. polling = 50; /* ms */
  555. break;
  556. case SAA7134_BOARD_BEHOLD_409FM:
  557. case SAA7134_BOARD_BEHOLD_401:
  558. case SAA7134_BOARD_BEHOLD_403:
  559. case SAA7134_BOARD_BEHOLD_403FM:
  560. case SAA7134_BOARD_BEHOLD_405:
  561. case SAA7134_BOARD_BEHOLD_405FM:
  562. case SAA7134_BOARD_BEHOLD_407:
  563. case SAA7134_BOARD_BEHOLD_407FM:
  564. case SAA7134_BOARD_BEHOLD_409:
  565. case SAA7134_BOARD_BEHOLD_505FM:
  566. case SAA7134_BOARD_BEHOLD_505RDS_MK5:
  567. case SAA7134_BOARD_BEHOLD_505RDS_MK3:
  568. case SAA7134_BOARD_BEHOLD_507_9FM:
  569. case SAA7134_BOARD_BEHOLD_507RDS_MK3:
  570. case SAA7134_BOARD_BEHOLD_507RDS_MK5:
  571. ir_codes = RC_MAP_MANLI;
  572. mask_keycode = 0x003f00;
  573. mask_keyup = 0x004000;
  574. polling = 50; /* ms */
  575. break;
  576. case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
  577. ir_codes = RC_MAP_BEHOLD_COLUMBUS;
  578. mask_keycode = 0x003f00;
  579. mask_keyup = 0x004000;
  580. polling = 50; // ms
  581. break;
  582. case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS:
  583. ir_codes = RC_MAP_PCTV_SEDNA;
  584. mask_keycode = 0x001f00;
  585. mask_keyup = 0x004000;
  586. polling = 50; // ms
  587. break;
  588. case SAA7134_BOARD_GOTVIEW_7135:
  589. ir_codes = RC_MAP_GOTVIEW7135;
  590. mask_keycode = 0x0003CC;
  591. mask_keydown = 0x000010;
  592. polling = 5; /* ms */
  593. /* GPIO stuff moved to __saa7134_ir_start() */
  594. break;
  595. case SAA7134_BOARD_VIDEOMATE_TV_PVR:
  596. case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
  597. case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII:
  598. ir_codes = RC_MAP_VIDEOMATE_TV_PVR;
  599. mask_keycode = 0x00003F;
  600. mask_keyup = 0x400000;
  601. polling = 50; // ms
  602. break;
  603. case SAA7134_BOARD_PROTEUS_2309:
  604. ir_codes = RC_MAP_PROTEUS_2309;
  605. mask_keycode = 0x00007F;
  606. mask_keyup = 0x000080;
  607. polling = 50; // ms
  608. break;
  609. case SAA7134_BOARD_VIDEOMATE_DVBT_300:
  610. case SAA7134_BOARD_VIDEOMATE_DVBT_200:
  611. ir_codes = RC_MAP_VIDEOMATE_TV_PVR;
  612. mask_keycode = 0x003F00;
  613. mask_keyup = 0x040000;
  614. break;
  615. case SAA7134_BOARD_FLYDVBS_LR300:
  616. case SAA7134_BOARD_FLYDVBT_LR301:
  617. case SAA7134_BOARD_FLYDVBTDUO:
  618. ir_codes = RC_MAP_FLYDVB;
  619. mask_keycode = 0x0001F00;
  620. mask_keydown = 0x0040000;
  621. break;
  622. case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
  623. case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
  624. case SAA7134_BOARD_ASUSTeK_P7131_ANALOG:
  625. ir_codes = RC_MAP_ASUS_PC39;
  626. mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
  627. mask_keyup = 0x0040000;
  628. mask_keycode = 0xffff;
  629. raw_decode = true;
  630. break;
  631. case SAA7134_BOARD_ASUSTeK_PS3_100:
  632. ir_codes = RC_MAP_ASUS_PS3_100;
  633. mask_keydown = 0x0040000;
  634. mask_keyup = 0x0040000;
  635. mask_keycode = 0xffff;
  636. raw_decode = true;
  637. break;
  638. case SAA7134_BOARD_ENCORE_ENLTV:
  639. case SAA7134_BOARD_ENCORE_ENLTV_FM:
  640. ir_codes = RC_MAP_ENCORE_ENLTV;
  641. mask_keycode = 0x00007f;
  642. mask_keyup = 0x040000;
  643. polling = 50; // ms
  644. break;
  645. case SAA7134_BOARD_ENCORE_ENLTV_FM53:
  646. case SAA7134_BOARD_ENCORE_ENLTV_FM3:
  647. ir_codes = RC_MAP_ENCORE_ENLTV_FM53;
  648. mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
  649. mask_keyup = 0x0040000;
  650. mask_keycode = 0xffff;
  651. raw_decode = true;
  652. break;
  653. case SAA7134_BOARD_10MOONSTVMASTER3:
  654. ir_codes = RC_MAP_ENCORE_ENLTV;
  655. mask_keycode = 0x5f80000;
  656. mask_keyup = 0x8000000;
  657. polling = 50; //ms
  658. break;
  659. case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
  660. ir_codes = RC_MAP_GENIUS_TVGO_A11MCE;
  661. mask_keycode = 0xff;
  662. mask_keydown = 0xf00000;
  663. polling = 50; /* ms */
  664. break;
  665. case SAA7134_BOARD_REAL_ANGEL_220:
  666. ir_codes = RC_MAP_REAL_AUDIO_220_32_KEYS;
  667. mask_keycode = 0x3f00;
  668. mask_keyup = 0x4000;
  669. polling = 50; /* ms */
  670. break;
  671. case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG:
  672. ir_codes = RC_MAP_KWORLD_PLUS_TV_ANALOG;
  673. mask_keycode = 0x7f;
  674. polling = 40; /* ms */
  675. break;
  676. case SAA7134_BOARD_VIDEOMATE_S350:
  677. ir_codes = RC_MAP_VIDEOMATE_S350;
  678. mask_keycode = 0x003f00;
  679. mask_keydown = 0x040000;
  680. break;
  681. case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S:
  682. ir_codes = RC_MAP_WINFAST;
  683. mask_keycode = 0x5f00;
  684. mask_keyup = 0x020000;
  685. polling = 50; /* ms */
  686. break;
  687. case SAA7134_BOARD_VIDEOMATE_M1F:
  688. ir_codes = RC_MAP_VIDEOMATE_K100;
  689. mask_keycode = 0x0ff00;
  690. mask_keyup = 0x040000;
  691. break;
  692. case SAA7134_BOARD_HAUPPAUGE_HVR1150:
  693. case SAA7134_BOARD_HAUPPAUGE_HVR1120:
  694. ir_codes = RC_MAP_HAUPPAUGE;
  695. mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */
  696. mask_keyup = 0x0040000;
  697. mask_keycode = 0xffff;
  698. raw_decode = true;
  699. break;
  700. }
  701. if (NULL == ir_codes) {
  702. printk("%s: Oops: IR config error [card=%d]\n",
  703. dev->name, dev->board);
  704. return -ENODEV;
  705. }
  706. ir = kzalloc(sizeof(*ir), GFP_KERNEL);
  707. rc = rc_allocate_device();
  708. if (!ir || !rc) {
  709. err = -ENOMEM;
  710. goto err_out_free;
  711. }
  712. ir->dev = rc;
  713. dev->remote = ir;
  714. /* init hardware-specific stuff */
  715. ir->mask_keycode = mask_keycode;
  716. ir->mask_keydown = mask_keydown;
  717. ir->mask_keyup = mask_keyup;
  718. ir->polling = polling;
  719. ir->raw_decode = raw_decode;
  720. /* init input device */
  721. snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
  722. saa7134_boards[dev->board].name);
  723. snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
  724. pci_name(dev->pci));
  725. rc->priv = dev;
  726. rc->open = saa7134_ir_open;
  727. rc->close = saa7134_ir_close;
  728. if (raw_decode)
  729. rc->driver_type = RC_DRIVER_IR_RAW;
  730. rc->input_name = ir->name;
  731. rc->input_phys = ir->phys;
  732. rc->input_id.bustype = BUS_PCI;
  733. rc->input_id.version = 1;
  734. if (dev->pci->subsystem_vendor) {
  735. rc->input_id.vendor = dev->pci->subsystem_vendor;
  736. rc->input_id.product = dev->pci->subsystem_device;
  737. } else {
  738. rc->input_id.vendor = dev->pci->vendor;
  739. rc->input_id.product = dev->pci->device;
  740. }
  741. rc->dev.parent = &dev->pci->dev;
  742. rc->map_name = ir_codes;
  743. rc->driver_name = MODULE_NAME;
  744. err = rc_register_device(rc);
  745. if (err)
  746. goto err_out_free;
  747. return 0;
  748. err_out_free:
  749. rc_free_device(rc);
  750. dev->remote = NULL;
  751. kfree(ir);
  752. return err;
  753. }
  754. void saa7134_input_fini(struct saa7134_dev *dev)
  755. {
  756. if (NULL == dev->remote)
  757. return;
  758. saa7134_ir_stop(dev);
  759. rc_unregister_device(dev->remote->dev);
  760. kfree(dev->remote);
  761. dev->remote = NULL;
  762. }
  763. void saa7134_probe_i2c_ir(struct saa7134_dev *dev)
  764. {
  765. struct i2c_board_info info;
  766. struct i2c_msg msg_msi = {
  767. .addr = 0x50,
  768. .flags = I2C_M_RD,
  769. .len = 0,
  770. .buf = NULL,
  771. };
  772. int rc;
  773. if (disable_ir) {
  774. dprintk("IR has been disabled, not probing for i2c remote\n");
  775. return;
  776. }
  777. memset(&info, 0, sizeof(struct i2c_board_info));
  778. memset(&dev->init_data, 0, sizeof(dev->init_data));
  779. strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
  780. switch (dev->board) {
  781. case SAA7134_BOARD_PINNACLE_PCTV_110i:
  782. case SAA7134_BOARD_PINNACLE_PCTV_310i:
  783. dev->init_data.name = "Pinnacle PCTV";
  784. if (pinnacle_remote == 0) {
  785. dev->init_data.get_key = get_key_pinnacle_color;
  786. dev->init_data.ir_codes = RC_MAP_PINNACLE_COLOR;
  787. info.addr = 0x47;
  788. } else {
  789. dev->init_data.get_key = get_key_pinnacle_grey;
  790. dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY;
  791. info.addr = 0x47;
  792. }
  793. break;
  794. case SAA7134_BOARD_UPMOST_PURPLE_TV:
  795. dev->init_data.name = "Purple TV";
  796. dev->init_data.get_key = get_key_purpletv;
  797. dev->init_data.ir_codes = RC_MAP_PURPLETV;
  798. info.addr = 0x7a;
  799. break;
  800. case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
  801. dev->init_data.name = "MSI TV@nywhere Plus";
  802. dev->init_data.get_key = get_key_msi_tvanywhere_plus;
  803. dev->init_data.ir_codes = RC_MAP_MSI_TVANYWHERE_PLUS;
  804. /*
  805. * MSI TV@nyware Plus requires more frequent polling
  806. * otherwise it will miss some keypresses
  807. */
  808. dev->init_data.polling_interval = 50;
  809. info.addr = 0x30;
  810. /* MSI TV@nywhere Plus controller doesn't seem to
  811. respond to probes unless we read something from
  812. an existing device. Weird...
  813. REVISIT: might no longer be needed */
  814. rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
  815. dprintk("probe 0x%02x @ %s: %s\n",
  816. msg_msi.addr, dev->i2c_adap.name,
  817. (1 == rc) ? "yes" : "no");
  818. break;
  819. case SAA7134_BOARD_KWORLD_PC150U:
  820. /* copied and modified from MSI TV@nywhere Plus */
  821. dev->init_data.name = "Kworld PC150-U";
  822. dev->init_data.get_key = get_key_kworld_pc150u;
  823. dev->init_data.ir_codes = RC_MAP_KWORLD_PC150U;
  824. info.addr = 0x30;
  825. /* MSI TV@nywhere Plus controller doesn't seem to
  826. respond to probes unless we read something from
  827. an existing device. Weird...
  828. REVISIT: might no longer be needed */
  829. rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1);
  830. dprintk("probe 0x%02x @ %s: %s\n",
  831. msg_msi.addr, dev->i2c_adap.name,
  832. (1 == rc) ? "yes" : "no");
  833. break;
  834. case SAA7134_BOARD_HAUPPAUGE_HVR1110:
  835. dev->init_data.name = "HVR 1110";
  836. dev->init_data.get_key = get_key_hvr1110;
  837. dev->init_data.ir_codes = RC_MAP_HAUPPAUGE;
  838. info.addr = 0x71;
  839. break;
  840. case SAA7134_BOARD_BEHOLD_607FM_MK3:
  841. case SAA7134_BOARD_BEHOLD_607FM_MK5:
  842. case SAA7134_BOARD_BEHOLD_609FM_MK3:
  843. case SAA7134_BOARD_BEHOLD_609FM_MK5:
  844. case SAA7134_BOARD_BEHOLD_607RDS_MK3:
  845. case SAA7134_BOARD_BEHOLD_607RDS_MK5:
  846. case SAA7134_BOARD_BEHOLD_609RDS_MK3:
  847. case SAA7134_BOARD_BEHOLD_609RDS_MK5:
  848. case SAA7134_BOARD_BEHOLD_M6:
  849. case SAA7134_BOARD_BEHOLD_M63:
  850. case SAA7134_BOARD_BEHOLD_M6_EXTRA:
  851. case SAA7134_BOARD_BEHOLD_H6:
  852. case SAA7134_BOARD_BEHOLD_X7:
  853. case SAA7134_BOARD_BEHOLD_H7:
  854. case SAA7134_BOARD_BEHOLD_A7:
  855. dev->init_data.name = "BeholdTV";
  856. dev->init_data.get_key = get_key_beholdm6xx;
  857. dev->init_data.ir_codes = RC_MAP_BEHOLD;
  858. dev->init_data.type = RC_BIT_NEC;
  859. info.addr = 0x2d;
  860. break;
  861. case SAA7134_BOARD_AVERMEDIA_CARDBUS_501:
  862. case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
  863. info.addr = 0x40;
  864. break;
  865. case SAA7134_BOARD_FLYDVB_TRIO:
  866. dev->init_data.name = "FlyDVB Trio";
  867. dev->init_data.get_key = get_key_flydvb_trio;
  868. dev->init_data.ir_codes = RC_MAP_FLYDVB;
  869. info.addr = 0x0b;
  870. break;
  871. default:
  872. dprintk("No I2C IR support for board %x\n", dev->board);
  873. return;
  874. }
  875. if (dev->init_data.name)
  876. info.platform_data = &dev->init_data;
  877. i2c_new_device(&dev->i2c_adap, &info);
  878. }
  879. static int saa7134_raw_decode_irq(struct saa7134_dev *dev)
  880. {
  881. struct saa7134_card_ir *ir = dev->remote;
  882. unsigned long timeout;
  883. int space;
  884. /* Generate initial event */
  885. saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  886. saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
  887. space = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
  888. ir_raw_event_store_edge(dev->remote->dev, space ? IR_SPACE : IR_PULSE);
  889. /*
  890. * Wait 15 ms from the start of the first IR event before processing
  891. * the event. This time is enough for NEC protocol. May need adjustments
  892. * to work with other protocols.
  893. */
  894. smp_mb();
  895. if (!timer_pending(&ir->timer)) {
  896. timeout = jiffies + msecs_to_jiffies(15);
  897. mod_timer(&ir->timer, timeout);
  898. }
  899. return 1;
  900. }