saa7134-input.c 27 KB

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