bttv-input.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. /*
  2. *
  3. * Copyright (c) 2003 Gerd Knorr
  4. * Copyright (c) 2003 Pavel Machek
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/module.h>
  21. #include <linux/moduleparam.h>
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/input.h>
  26. #include "bttv.h"
  27. #include "bttvp.h"
  28. /* ---------------------------------------------------------------------- */
  29. static IR_KEYTAB_TYPE ir_codes_avermedia[IR_KEYTAB_SIZE] = {
  30. [ 34 ] = KEY_KP0,
  31. [ 40 ] = KEY_KP1,
  32. [ 24 ] = KEY_KP2,
  33. [ 56 ] = KEY_KP3,
  34. [ 36 ] = KEY_KP4,
  35. [ 20 ] = KEY_KP5,
  36. [ 52 ] = KEY_KP6,
  37. [ 44 ] = KEY_KP7,
  38. [ 28 ] = KEY_KP8,
  39. [ 60 ] = KEY_KP9,
  40. [ 48 ] = KEY_EJECTCD, // Unmarked on my controller
  41. [ 0 ] = KEY_POWER,
  42. [ 18 ] = BTN_LEFT, // DISPLAY/L
  43. [ 50 ] = BTN_RIGHT, // LOOP/R
  44. [ 10 ] = KEY_MUTE,
  45. [ 38 ] = KEY_RECORD,
  46. [ 22 ] = KEY_PAUSE,
  47. [ 54 ] = KEY_STOP,
  48. [ 30 ] = KEY_VOLUMEDOWN,
  49. [ 62 ] = KEY_VOLUMEUP,
  50. [ 32 ] = KEY_TUNER, // TV/FM
  51. [ 16 ] = KEY_CD,
  52. [ 8 ] = KEY_VIDEO,
  53. [ 4 ] = KEY_AUDIO,
  54. [ 12 ] = KEY_ZOOM, // full screen
  55. [ 2 ] = KEY_INFO, // preview
  56. [ 42 ] = KEY_SEARCH, // autoscan
  57. [ 26 ] = KEY_STOP, // freeze
  58. [ 58 ] = KEY_RECORD, // capture
  59. [ 6 ] = KEY_PLAY, // unmarked
  60. [ 46 ] = KEY_RED, // unmarked
  61. [ 14 ] = KEY_GREEN, // unmarked
  62. [ 33 ] = KEY_YELLOW, // unmarked
  63. [ 17 ] = KEY_CHANNELDOWN,
  64. [ 49 ] = KEY_CHANNELUP,
  65. [ 1 ] = KEY_BLUE, // unmarked
  66. };
  67. /* Matt Jesson <dvb@jesson.eclipse.co.uk */
  68. static IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE] = {
  69. [ 0x28 ] = KEY_KP0, //'0' / 'enter'
  70. [ 0x22 ] = KEY_KP1, //'1'
  71. [ 0x12 ] = KEY_KP2, //'2' / 'up arrow'
  72. [ 0x32 ] = KEY_KP3, //'3'
  73. [ 0x24 ] = KEY_KP4, //'4' / 'left arrow'
  74. [ 0x14 ] = KEY_KP5, //'5'
  75. [ 0x34 ] = KEY_KP6, //'6' / 'right arrow'
  76. [ 0x26 ] = KEY_KP7, //'7'
  77. [ 0x16 ] = KEY_KP8, //'8' / 'down arrow'
  78. [ 0x36 ] = KEY_KP9, //'9'
  79. [ 0x20 ] = KEY_LIST, // 'source'
  80. [ 0x10 ] = KEY_TEXT, // 'teletext'
  81. [ 0x00 ] = KEY_POWER, // 'power'
  82. [ 0x04 ] = KEY_AUDIO, // 'audio'
  83. [ 0x06 ] = KEY_ZOOM, // 'full screen'
  84. [ 0x18 ] = KEY_VIDEO, // 'display'
  85. [ 0x38 ] = KEY_SEARCH, // 'loop'
  86. [ 0x08 ] = KEY_INFO, // 'preview'
  87. [ 0x2a ] = KEY_REWIND, // 'backward <<'
  88. [ 0x1a ] = KEY_FASTFORWARD, // 'forward >>'
  89. [ 0x3a ] = KEY_RECORD, // 'capture'
  90. [ 0x0a ] = KEY_MUTE, // 'mute'
  91. [ 0x2c ] = KEY_RECORD, // 'record'
  92. [ 0x1c ] = KEY_PAUSE, // 'pause'
  93. [ 0x3c ] = KEY_STOP, // 'stop'
  94. [ 0x0c ] = KEY_PLAY, // 'play'
  95. [ 0x2e ] = KEY_RED, // 'red'
  96. [ 0x01 ] = KEY_BLUE, // 'blue' / 'cancel'
  97. [ 0x0e ] = KEY_YELLOW, // 'yellow' / 'ok'
  98. [ 0x21 ] = KEY_GREEN, // 'green'
  99. [ 0x11 ] = KEY_CHANNELDOWN, // 'channel -'
  100. [ 0x31 ] = KEY_CHANNELUP, // 'channel +'
  101. [ 0x1e ] = KEY_VOLUMEDOWN, // 'volume -'
  102. [ 0x3e ] = KEY_VOLUMEUP, // 'volume +'
  103. };
  104. /* Attila Kondoros <attila.kondoros@chello.hu> */
  105. static IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = {
  106. [ 1 ] = KEY_KP1,
  107. [ 2 ] = KEY_KP2,
  108. [ 3 ] = KEY_KP3,
  109. [ 4 ] = KEY_KP4,
  110. [ 5 ] = KEY_KP5,
  111. [ 6 ] = KEY_KP6,
  112. [ 7 ] = KEY_KP7,
  113. [ 8 ] = KEY_KP8,
  114. [ 9 ] = KEY_KP9,
  115. [ 0 ] = KEY_KP0,
  116. [ 23 ] = KEY_LAST, // +100
  117. [ 10 ] = KEY_LIST, // recall
  118. [ 28 ] = KEY_TUNER, // TV/FM
  119. [ 21 ] = KEY_SEARCH, // scan
  120. [ 18 ] = KEY_POWER, // power
  121. [ 31 ] = KEY_VOLUMEDOWN, // vol up
  122. [ 27 ] = KEY_VOLUMEUP, // vol down
  123. [ 30 ] = KEY_CHANNELDOWN, // chn up
  124. [ 26 ] = KEY_CHANNELUP, // chn down
  125. [ 17 ] = KEY_VIDEO, // video
  126. [ 15 ] = KEY_ZOOM, // full screen
  127. [ 19 ] = KEY_MUTE, // mute/unmute
  128. [ 16 ] = KEY_TEXT, // min
  129. [ 13 ] = KEY_STOP, // freeze
  130. [ 14 ] = KEY_RECORD, // record
  131. [ 29 ] = KEY_PLAYPAUSE, // stop
  132. [ 25 ] = KEY_PLAY, // play
  133. [ 22 ] = KEY_GOTO, // osd
  134. [ 20 ] = KEY_REFRESH, // default
  135. [ 12 ] = KEY_KPPLUS, // fine tune >>>>
  136. [ 24 ] = KEY_KPMINUS // fine tune <<<<
  137. };
  138. /* ---------------------------------------------------------------------- */
  139. static IR_KEYTAB_TYPE ir_codes_conceptronic[IR_KEYTAB_SIZE] = {
  140. [ 30 ] = KEY_POWER, // power
  141. [ 7 ] = KEY_MEDIA, // source
  142. [ 28 ] = KEY_SEARCH, // scan
  143. /* FIXME: duplicate keycodes?
  144. *
  145. * These four keys seem to share the same GPIO as CH+, CH-, <<< and >>>
  146. * The GPIO values are
  147. * 6397fb for both "Scan <" and "CH -",
  148. * 639ffb for "Scan >" and "CH+",
  149. * 6384fb for "Tune <" and "<<<",
  150. * 638cfb for "Tune >" and ">>>", regardless of the mask.
  151. *
  152. * [ 23 ] = KEY_BACK, // fm scan <<
  153. * [ 31 ] = KEY_FORWARD, // fm scan >>
  154. *
  155. * [ 4 ] = KEY_LEFT, // fm tuning <
  156. * [ 12 ] = KEY_RIGHT, // fm tuning >
  157. *
  158. * For now, these four keys are disabled. Pressing them will generate
  159. * the CH+/CH-/<<</>>> events
  160. */
  161. [ 3 ] = KEY_TUNER, // TV/FM
  162. [ 0 ] = KEY_RECORD,
  163. [ 8 ] = KEY_STOP,
  164. [ 17 ] = KEY_PLAY,
  165. [ 26 ] = KEY_PLAYPAUSE, // freeze
  166. [ 25 ] = KEY_ZOOM, // zoom
  167. [ 15 ] = KEY_TEXT, // min
  168. [ 1 ] = KEY_KP1,
  169. [ 11 ] = KEY_KP2,
  170. [ 27 ] = KEY_KP3,
  171. [ 5 ] = KEY_KP4,
  172. [ 9 ] = KEY_KP5,
  173. [ 21 ] = KEY_KP6,
  174. [ 6 ] = KEY_KP7,
  175. [ 10 ] = KEY_KP8,
  176. [ 18 ] = KEY_KP9,
  177. [ 2 ] = KEY_KP0,
  178. [ 16 ] = KEY_LAST, // +100
  179. [ 19 ] = KEY_LIST, // recall
  180. [ 31 ] = KEY_CHANNELUP, // chn down
  181. [ 23 ] = KEY_CHANNELDOWN, // chn up
  182. [ 22 ] = KEY_VOLUMEUP, // vol down
  183. [ 20 ] = KEY_VOLUMEDOWN, // vol up
  184. [ 4 ] = KEY_KPMINUS, // <<<
  185. [ 14 ] = KEY_SETUP, // function
  186. [ 12 ] = KEY_KPPLUS, // >>>
  187. [ 13 ] = KEY_GOTO, // mts
  188. [ 29 ] = KEY_REFRESH, // reset
  189. [ 24 ] = KEY_MUTE // mute/unmute
  190. };
  191. static IR_KEYTAB_TYPE ir_codes_nebula[IR_KEYTAB_SIZE] = {
  192. [0x00] = KEY_KP0,
  193. [0x01] = KEY_KP1,
  194. [0x02] = KEY_KP2,
  195. [0x03] = KEY_KP3,
  196. [0x04] = KEY_KP4,
  197. [0x05] = KEY_KP5,
  198. [0x06] = KEY_KP6,
  199. [0x07] = KEY_KP7,
  200. [0x08] = KEY_KP8,
  201. [0x09] = KEY_KP9,
  202. [0x0a] = KEY_TV,
  203. [0x0b] = KEY_AUX,
  204. [0x0c] = KEY_DVD,
  205. [0x0d] = KEY_POWER,
  206. [0x0e] = KEY_MHP, /* labelled 'Picture' */
  207. [0x0f] = KEY_AUDIO,
  208. [0x10] = KEY_INFO,
  209. [0x11] = KEY_F13, /* 16:9 */
  210. [0x12] = KEY_F14, /* 14:9 */
  211. [0x13] = KEY_EPG,
  212. [0x14] = KEY_EXIT,
  213. [0x15] = KEY_MENU,
  214. [0x16] = KEY_UP,
  215. [0x17] = KEY_DOWN,
  216. [0x18] = KEY_LEFT,
  217. [0x19] = KEY_RIGHT,
  218. [0x1a] = KEY_ENTER,
  219. [0x1b] = KEY_CHANNELUP,
  220. [0x1c] = KEY_CHANNELDOWN,
  221. [0x1d] = KEY_VOLUMEUP,
  222. [0x1e] = KEY_VOLUMEDOWN,
  223. [0x1f] = KEY_RED,
  224. [0x20] = KEY_GREEN,
  225. [0x21] = KEY_YELLOW,
  226. [0x22] = KEY_BLUE,
  227. [0x23] = KEY_SUBTITLE,
  228. [0x24] = KEY_F15, /* AD */
  229. [0x25] = KEY_TEXT,
  230. [0x26] = KEY_MUTE,
  231. [0x27] = KEY_REWIND,
  232. [0x28] = KEY_STOP,
  233. [0x29] = KEY_PLAY,
  234. [0x2a] = KEY_FASTFORWARD,
  235. [0x2b] = KEY_F16, /* chapter */
  236. [0x2c] = KEY_PAUSE,
  237. [0x2d] = KEY_PLAY,
  238. [0x2e] = KEY_RECORD,
  239. [0x2f] = KEY_F17, /* picture in picture */
  240. [0x30] = KEY_KPPLUS, /* zoom in */
  241. [0x31] = KEY_KPMINUS, /* zoom out */
  242. [0x32] = KEY_F18, /* capture */
  243. [0x33] = KEY_F19, /* web */
  244. [0x34] = KEY_EMAIL,
  245. [0x35] = KEY_PHONE,
  246. [0x36] = KEY_PC
  247. };
  248. static int debug;
  249. module_param(debug, int, 0644); /* debug level (0,1,2) */
  250. static int repeat_delay = 500;
  251. module_param(repeat_delay, int, 0644);
  252. static int repeat_period = 33;
  253. module_param(repeat_period, int, 0644);
  254. #define DEVNAME "bttv-input"
  255. /* ---------------------------------------------------------------------- */
  256. static void ir_handle_key(struct bttv *btv)
  257. {
  258. struct bttv_ir *ir = btv->remote;
  259. u32 gpio,data;
  260. /* read gpio value */
  261. gpio = bttv_gpio_read(&btv->c);
  262. if (ir->polling) {
  263. if (ir->last_gpio == gpio)
  264. return;
  265. ir->last_gpio = gpio;
  266. }
  267. /* extract data */
  268. data = ir_extract_bits(gpio, ir->mask_keycode);
  269. dprintk(KERN_INFO DEVNAME ": irq gpio=0x%x code=%d | %s%s%s\n",
  270. gpio, data,
  271. ir->polling ? "poll" : "irq",
  272. (gpio & ir->mask_keydown) ? " down" : "",
  273. (gpio & ir->mask_keyup) ? " up" : "");
  274. if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) ||
  275. (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) {
  276. ir_input_keydown(ir->dev,&ir->ir,data,data);
  277. } else {
  278. ir_input_nokey(ir->dev,&ir->ir);
  279. }
  280. }
  281. void bttv_input_irq(struct bttv *btv)
  282. {
  283. struct bttv_ir *ir = btv->remote;
  284. if (!ir->polling)
  285. ir_handle_key(btv);
  286. }
  287. static void bttv_input_timer(unsigned long data)
  288. {
  289. struct bttv *btv = (struct bttv*)data;
  290. struct bttv_ir *ir = btv->remote;
  291. unsigned long timeout;
  292. ir_handle_key(btv);
  293. timeout = jiffies + (ir->polling * HZ / 1000);
  294. mod_timer(&ir->timer, timeout);
  295. }
  296. /* ---------------------------------------------------------------*/
  297. static int rc5_remote_gap = 885;
  298. module_param(rc5_remote_gap, int, 0644);
  299. static int rc5_key_timeout = 200;
  300. module_param(rc5_key_timeout, int, 0644);
  301. #define RC5_START(x) (((x)>>12)&3)
  302. #define RC5_TOGGLE(x) (((x)>>11)&1)
  303. #define RC5_ADDR(x) (((x)>>6)&31)
  304. #define RC5_INSTR(x) ((x)&63)
  305. /* decode raw bit pattern to RC5 code */
  306. static u32 rc5_decode(unsigned int code)
  307. {
  308. unsigned int org_code = code;
  309. unsigned int pair;
  310. unsigned int rc5 = 0;
  311. int i;
  312. code = (code << 1) | 1;
  313. for (i = 0; i < 14; ++i) {
  314. pair = code & 0x3;
  315. code >>= 2;
  316. rc5 <<= 1;
  317. switch (pair) {
  318. case 0:
  319. case 2:
  320. break;
  321. case 1:
  322. rc5 |= 1;
  323. break;
  324. case 3:
  325. dprintk(KERN_WARNING "bad code: %x\n", org_code);
  326. return 0;
  327. }
  328. }
  329. dprintk(KERN_WARNING "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, "
  330. "instr=%x\n", rc5, org_code, RC5_START(rc5),
  331. RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5));
  332. return rc5;
  333. }
  334. static int bttv_rc5_irq(struct bttv *btv)
  335. {
  336. struct bttv_ir *ir = btv->remote;
  337. struct timeval tv;
  338. u32 gpio;
  339. u32 gap;
  340. unsigned long current_jiffies, timeout;
  341. /* read gpio port */
  342. gpio = bttv_gpio_read(&btv->c);
  343. /* remote IRQ? */
  344. if (!(gpio & 0x20))
  345. return 0;
  346. /* get time of bit */
  347. current_jiffies = jiffies;
  348. do_gettimeofday(&tv);
  349. /* avoid overflow with gap >1s */
  350. if (tv.tv_sec - ir->base_time.tv_sec > 1) {
  351. gap = 200000;
  352. } else {
  353. gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
  354. tv.tv_usec - ir->base_time.tv_usec;
  355. }
  356. /* active code => add bit */
  357. if (ir->active) {
  358. /* only if in the code (otherwise spurious IRQ or timer
  359. late) */
  360. if (ir->last_bit < 28) {
  361. ir->last_bit = (gap - rc5_remote_gap / 2) /
  362. rc5_remote_gap;
  363. ir->code |= 1 << ir->last_bit;
  364. }
  365. /* starting new code */
  366. } else {
  367. ir->active = 1;
  368. ir->code = 0;
  369. ir->base_time = tv;
  370. ir->last_bit = 0;
  371. timeout = current_jiffies + (500 + 30 * HZ) / 1000;
  372. mod_timer(&ir->timer_end, timeout);
  373. }
  374. /* toggle GPIO pin 4 to reset the irq */
  375. bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
  376. bttv_gpio_write(&btv->c, gpio | (1 << 4));
  377. return 1;
  378. }
  379. static void bttv_rc5_timer_end(unsigned long data)
  380. {
  381. struct bttv_ir *ir = (struct bttv_ir *)data;
  382. struct timeval tv;
  383. unsigned long current_jiffies, timeout;
  384. u32 gap;
  385. /* get time */
  386. current_jiffies = jiffies;
  387. do_gettimeofday(&tv);
  388. /* avoid overflow with gap >1s */
  389. if (tv.tv_sec - ir->base_time.tv_sec > 1) {
  390. gap = 200000;
  391. } else {
  392. gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
  393. tv.tv_usec - ir->base_time.tv_usec;
  394. }
  395. /* Allow some timmer jitter (RC5 is ~24ms anyway so this is ok) */
  396. if (gap < 28000) {
  397. dprintk(KERN_WARNING "spurious timer_end\n");
  398. return;
  399. }
  400. ir->active = 0;
  401. if (ir->last_bit < 20) {
  402. /* ignore spurious codes (caused by light/other remotes) */
  403. dprintk(KERN_WARNING "short code: %x\n", ir->code);
  404. } else {
  405. u32 rc5 = rc5_decode(ir->code);
  406. /* two start bits? */
  407. if (RC5_START(rc5) != 3) {
  408. dprintk(KERN_WARNING "rc5 start bits invalid: %u\n", RC5_START(rc5));
  409. /* right address? */
  410. } else if (RC5_ADDR(rc5) == 0x0) {
  411. u32 toggle = RC5_TOGGLE(rc5);
  412. u32 instr = RC5_INSTR(rc5);
  413. /* Good code, decide if repeat/repress */
  414. if (toggle != RC5_TOGGLE(ir->last_rc5) ||
  415. instr != RC5_INSTR(ir->last_rc5)) {
  416. dprintk(KERN_WARNING "instruction %x, toggle %x\n", instr,
  417. toggle);
  418. ir_input_nokey(ir->dev, &ir->ir);
  419. ir_input_keydown(ir->dev, &ir->ir, instr,
  420. instr);
  421. }
  422. /* Set/reset key-up timer */
  423. timeout = current_jiffies + (500 + rc5_key_timeout
  424. * HZ) / 1000;
  425. mod_timer(&ir->timer_keyup, timeout);
  426. /* Save code for repeat test */
  427. ir->last_rc5 = rc5;
  428. }
  429. }
  430. }
  431. static void bttv_rc5_timer_keyup(unsigned long data)
  432. {
  433. struct bttv_ir *ir = (struct bttv_ir *)data;
  434. dprintk(KERN_DEBUG "key released\n");
  435. ir_input_nokey(ir->dev, &ir->ir);
  436. }
  437. /* ---------------------------------------------------------------------- */
  438. int bttv_input_init(struct bttv *btv)
  439. {
  440. struct bttv_ir *ir;
  441. IR_KEYTAB_TYPE *ir_codes = NULL;
  442. struct input_dev *input_dev;
  443. int ir_type = IR_TYPE_OTHER;
  444. if (!btv->has_remote)
  445. return -ENODEV;
  446. ir = kzalloc(sizeof(*ir),GFP_KERNEL);
  447. input_dev = input_allocate_device();
  448. if (!ir || !input_dev) {
  449. kfree(ir);
  450. input_free_device(input_dev);
  451. return -ENOMEM;
  452. }
  453. memset(ir,0,sizeof(*ir));
  454. /* detect & configure */
  455. switch (btv->c.type) {
  456. case BTTV_BOARD_AVERMEDIA:
  457. case BTTV_BOARD_AVPHONE98:
  458. case BTTV_BOARD_AVERMEDIA98:
  459. ir_codes = ir_codes_avermedia;
  460. ir->mask_keycode = 0xf88000;
  461. ir->mask_keydown = 0x010000;
  462. ir->polling = 50; // ms
  463. break;
  464. case BTTV_BOARD_AVDVBT_761:
  465. case BTTV_BOARD_AVDVBT_771:
  466. ir_codes = ir_codes_avermedia_dvbt;
  467. ir->mask_keycode = 0x0f00c0;
  468. ir->mask_keydown = 0x000020;
  469. ir->polling = 50; // ms
  470. break;
  471. case BTTV_BOARD_PXELVWPLTVPAK:
  472. ir_codes = ir_codes_pixelview;
  473. ir->mask_keycode = 0x003e00;
  474. ir->mask_keyup = 0x010000;
  475. ir->polling = 50; // ms
  476. break;
  477. case BTTV_BOARD_PV_BT878P_9B:
  478. case BTTV_BOARD_PV_BT878P_PLUS:
  479. ir_codes = ir_codes_pixelview;
  480. ir->mask_keycode = 0x001f00;
  481. ir->mask_keyup = 0x008000;
  482. ir->polling = 50; // ms
  483. break;
  484. case BTTV_BOARD_WINFAST2000:
  485. ir_codes = ir_codes_winfast;
  486. ir->mask_keycode = 0x1f8;
  487. break;
  488. case BTTV_BOARD_MAGICTVIEW061:
  489. case BTTV_BOARD_MAGICTVIEW063:
  490. ir_codes = ir_codes_winfast;
  491. ir->mask_keycode = 0x0008e000;
  492. ir->mask_keydown = 0x00200000;
  493. break;
  494. case BTTV_BOARD_APAC_VIEWCOMP:
  495. ir_codes = ir_codes_apac_viewcomp;
  496. ir->mask_keycode = 0x001f00;
  497. ir->mask_keyup = 0x008000;
  498. ir->polling = 50; // ms
  499. break;
  500. case BTTV_BOARD_CONCEPTRONIC_CTVFMI2:
  501. ir_codes = ir_codes_conceptronic;
  502. ir->mask_keycode = 0x001F00;
  503. ir->mask_keyup = 0x006000;
  504. ir->polling = 50; // ms
  505. break;
  506. case BTTV_BOARD_NEBULA_DIGITV:
  507. ir_codes = ir_codes_nebula;
  508. btv->custom_irq = bttv_rc5_irq;
  509. ir->rc5_gpio = 1;
  510. break;
  511. case BTTV_BOARD_MACHTV_MAGICTV:
  512. ir_codes = ir_codes_apac_viewcomp;
  513. ir->mask_keycode = 0x001F00;
  514. ir->mask_keyup = 0x004000;
  515. ir->polling = 50; /* ms */
  516. break;
  517. }
  518. if (NULL == ir_codes) {
  519. dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n",btv->c.type);
  520. kfree(ir);
  521. input_free_device(input_dev);
  522. return -ENODEV;
  523. }
  524. if (ir->rc5_gpio) {
  525. u32 gpio;
  526. /* enable remote irq */
  527. bttv_gpio_inout(&btv->c, (1 << 4), 1 << 4);
  528. gpio = bttv_gpio_read(&btv->c);
  529. bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
  530. bttv_gpio_write(&btv->c, gpio | (1 << 4));
  531. } else {
  532. /* init hardware-specific stuff */
  533. bttv_gpio_inout(&btv->c, ir->mask_keycode | ir->mask_keydown, 0);
  534. }
  535. /* init input device */
  536. ir->dev = input_dev;
  537. snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)",
  538. btv->c.type);
  539. snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0",
  540. pci_name(btv->c.pci));
  541. ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
  542. input_dev->name = ir->name;
  543. input_dev->phys = ir->phys;
  544. input_dev->id.bustype = BUS_PCI;
  545. input_dev->id.version = 1;
  546. if (btv->c.pci->subsystem_vendor) {
  547. input_dev->id.vendor = btv->c.pci->subsystem_vendor;
  548. input_dev->id.product = btv->c.pci->subsystem_device;
  549. } else {
  550. input_dev->id.vendor = btv->c.pci->vendor;
  551. input_dev->id.product = btv->c.pci->device;
  552. }
  553. input_dev->cdev.dev = &btv->c.pci->dev;
  554. btv->remote = ir;
  555. if (ir->polling) {
  556. init_timer(&ir->timer);
  557. ir->timer.function = bttv_input_timer;
  558. ir->timer.data = (unsigned long)btv;
  559. ir->timer.expires = jiffies + HZ;
  560. add_timer(&ir->timer);
  561. } else if (ir->rc5_gpio) {
  562. /* set timer_end for code completion */
  563. init_timer(&ir->timer_end);
  564. ir->timer_end.function = bttv_rc5_timer_end;
  565. ir->timer_end.data = (unsigned long)ir;
  566. init_timer(&ir->timer_keyup);
  567. ir->timer_keyup.function = bttv_rc5_timer_keyup;
  568. ir->timer_keyup.data = (unsigned long)ir;
  569. }
  570. /* all done */
  571. input_register_device(btv->remote->dev);
  572. printk(DEVNAME ": %s detected at %s\n",ir->name,ir->phys);
  573. /* the remote isn't as bouncy as a keyboard */
  574. ir->dev->rep[REP_DELAY] = repeat_delay;
  575. ir->dev->rep[REP_PERIOD] = repeat_period;
  576. return 0;
  577. }
  578. void bttv_input_fini(struct bttv *btv)
  579. {
  580. if (btv->remote == NULL)
  581. return;
  582. if (btv->remote->polling) {
  583. del_timer_sync(&btv->remote->timer);
  584. flush_scheduled_work();
  585. }
  586. if (btv->remote->rc5_gpio) {
  587. u32 gpio;
  588. del_timer_sync(&btv->remote->timer_end);
  589. flush_scheduled_work();
  590. gpio = bttv_gpio_read(&btv->c);
  591. bttv_gpio_write(&btv->c, gpio & ~(1 << 4));
  592. }
  593. input_unregister_device(btv->remote->dev);
  594. kfree(btv->remote);
  595. btv->remote = NULL;
  596. }
  597. /*
  598. * Local variables:
  599. * c-basic-offset: 8
  600. * End:
  601. */