saa7134-input.c 27 KB

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