cx88-input.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. /*
  2. *
  3. * Device driver for GPIO attached remote control interfaces
  4. * on Conexant 2388x based TV/DVB cards.
  5. *
  6. * Copyright (c) 2003 Pavel Machek
  7. * Copyright (c) 2004 Gerd Knorr
  8. * Copyright (c) 2004, 2005 Chris Pascoe
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #include <linux/init.h>
  25. #include <linux/delay.h>
  26. #include <linux/input.h>
  27. #include <linux/pci.h>
  28. #include <linux/module.h>
  29. #include <linux/moduleparam.h>
  30. #include "cx88.h"
  31. #include <media/ir-common.h>
  32. /* ---------------------------------------------------------------------- */
  33. /* DigitalNow DNTV Live DVB-T Remote */
  34. static IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE] = {
  35. [0x00] = KEY_ESC, /* 'go up a level?' */
  36. /* Keys 0 to 9 */
  37. [0x0a] = KEY_KP0,
  38. [0x01] = KEY_KP1,
  39. [0x02] = KEY_KP2,
  40. [0x03] = KEY_KP3,
  41. [0x04] = KEY_KP4,
  42. [0x05] = KEY_KP5,
  43. [0x06] = KEY_KP6,
  44. [0x07] = KEY_KP7,
  45. [0x08] = KEY_KP8,
  46. [0x09] = KEY_KP9,
  47. [0x0b] = KEY_TUNER, /* tv/fm */
  48. [0x0c] = KEY_SEARCH, /* scan */
  49. [0x0d] = KEY_STOP,
  50. [0x0e] = KEY_PAUSE,
  51. [0x0f] = KEY_LIST, /* source */
  52. [0x10] = KEY_MUTE,
  53. [0x11] = KEY_REWIND, /* backward << */
  54. [0x12] = KEY_POWER,
  55. [0x13] = KEY_S, /* snap */
  56. [0x14] = KEY_AUDIO, /* stereo */
  57. [0x15] = KEY_CLEAR, /* reset */
  58. [0x16] = KEY_PLAY,
  59. [0x17] = KEY_ENTER,
  60. [0x18] = KEY_ZOOM, /* full screen */
  61. [0x19] = KEY_FASTFORWARD, /* forward >> */
  62. [0x1a] = KEY_CHANNELUP,
  63. [0x1b] = KEY_VOLUMEUP,
  64. [0x1c] = KEY_INFO, /* preview */
  65. [0x1d] = KEY_RECORD, /* record */
  66. [0x1e] = KEY_CHANNELDOWN,
  67. [0x1f] = KEY_VOLUMEDOWN,
  68. };
  69. /* ---------------------------------------------------------------------- */
  70. /* IO-DATA BCTV7E Remote */
  71. static IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE] = {
  72. [0x40] = KEY_TV,
  73. [0x20] = KEY_RADIO, /* FM */
  74. [0x60] = KEY_EPG,
  75. [0x00] = KEY_POWER,
  76. /* Keys 0 to 9 */
  77. [0x44] = KEY_KP0, /* 10 */
  78. [0x50] = KEY_KP1,
  79. [0x30] = KEY_KP2,
  80. [0x70] = KEY_KP3,
  81. [0x48] = KEY_KP4,
  82. [0x28] = KEY_KP5,
  83. [0x68] = KEY_KP6,
  84. [0x58] = KEY_KP7,
  85. [0x38] = KEY_KP8,
  86. [0x78] = KEY_KP9,
  87. [0x10] = KEY_L, /* Live */
  88. [0x08] = KEY_T, /* Time Shift */
  89. [0x18] = KEY_PLAYPAUSE, /* Play */
  90. [0x24] = KEY_ENTER, /* 11 */
  91. [0x64] = KEY_ESC, /* 12 */
  92. [0x04] = KEY_M, /* Multi */
  93. [0x54] = KEY_VIDEO,
  94. [0x34] = KEY_CHANNELUP,
  95. [0x74] = KEY_VOLUMEUP,
  96. [0x14] = KEY_MUTE,
  97. [0x4c] = KEY_S, /* SVIDEO */
  98. [0x2c] = KEY_CHANNELDOWN,
  99. [0x6c] = KEY_VOLUMEDOWN,
  100. [0x0c] = KEY_ZOOM,
  101. [0x5c] = KEY_PAUSE,
  102. [0x3c] = KEY_C, /* || (red) */
  103. [0x7c] = KEY_RECORD, /* recording */
  104. [0x1c] = KEY_STOP,
  105. [0x41] = KEY_REWIND, /* backward << */
  106. [0x21] = KEY_PLAY,
  107. [0x61] = KEY_FASTFORWARD, /* forward >> */
  108. [0x01] = KEY_NEXT, /* skip >| */
  109. };
  110. /* ---------------------------------------------------------------------- */
  111. /* ADS Tech Instant TV DVB-T PCI Remote */
  112. static IR_KEYTAB_TYPE ir_codes_adstech_dvb_t_pci[IR_KEYTAB_SIZE] = {
  113. /* Keys 0 to 9 */
  114. [0x4d] = KEY_0,
  115. [0x57] = KEY_1,
  116. [0x4f] = KEY_2,
  117. [0x53] = KEY_3,
  118. [0x56] = KEY_4,
  119. [0x4e] = KEY_5,
  120. [0x5e] = KEY_6,
  121. [0x54] = KEY_7,
  122. [0x4c] = KEY_8,
  123. [0x5c] = KEY_9,
  124. [0x5b] = KEY_POWER,
  125. [0x5f] = KEY_MUTE,
  126. [0x55] = KEY_GOTO,
  127. [0x5d] = KEY_SEARCH,
  128. [0x17] = KEY_EPG, /* Guide */
  129. [0x1f] = KEY_MENU,
  130. [0x0f] = KEY_UP,
  131. [0x46] = KEY_DOWN,
  132. [0x16] = KEY_LEFT,
  133. [0x1e] = KEY_RIGHT,
  134. [0x0e] = KEY_SELECT, /* Enter */
  135. [0x5a] = KEY_INFO,
  136. [0x52] = KEY_EXIT,
  137. [0x59] = KEY_PREVIOUS,
  138. [0x51] = KEY_NEXT,
  139. [0x58] = KEY_REWIND,
  140. [0x50] = KEY_FORWARD,
  141. [0x44] = KEY_PLAYPAUSE,
  142. [0x07] = KEY_STOP,
  143. [0x1b] = KEY_RECORD,
  144. [0x13] = KEY_TUNER, /* Live */
  145. [0x0a] = KEY_A,
  146. [0x12] = KEY_B,
  147. [0x03] = KEY_PROG1, /* 1 */
  148. [0x01] = KEY_PROG2, /* 2 */
  149. [0x00] = KEY_PROG3, /* 3 */
  150. [0x06] = KEY_DVD,
  151. [0x48] = KEY_AUX, /* Photo */
  152. [0x40] = KEY_VIDEO,
  153. [0x19] = KEY_AUDIO, /* Music */
  154. [0x0b] = KEY_CHANNELUP,
  155. [0x08] = KEY_CHANNELDOWN,
  156. [0x15] = KEY_VOLUMEUP,
  157. [0x1c] = KEY_VOLUMEDOWN,
  158. };
  159. /* ---------------------------------------------------------------------- */
  160. /* MSI TV@nywhere remote */
  161. static IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE] = {
  162. /* Keys 0 to 9 */
  163. [0x00] = KEY_0,
  164. [0x01] = KEY_1,
  165. [0x02] = KEY_2,
  166. [0x03] = KEY_3,
  167. [0x04] = KEY_4,
  168. [0x05] = KEY_5,
  169. [0x06] = KEY_6,
  170. [0x07] = KEY_7,
  171. [0x08] = KEY_8,
  172. [0x09] = KEY_9,
  173. [0x0c] = KEY_MUTE,
  174. [0x0f] = KEY_SCREEN, /* Full Screen */
  175. [0x10] = KEY_F, /* Funtion */
  176. [0x11] = KEY_T, /* Time shift */
  177. [0x12] = KEY_POWER,
  178. [0x13] = KEY_MEDIA, /* MTS */
  179. [0x14] = KEY_SLOW,
  180. [0x16] = KEY_REWIND, /* backward << */
  181. [0x17] = KEY_ENTER, /* Return */
  182. [0x18] = KEY_FASTFORWARD, /* forward >> */
  183. [0x1a] = KEY_CHANNELUP,
  184. [0x1b] = KEY_VOLUMEUP,
  185. [0x1e] = KEY_CHANNELDOWN,
  186. [0x1f] = KEY_VOLUMEDOWN,
  187. };
  188. /* ---------------------------------------------------------------------- */
  189. /* Cinergy 1400 DVB-T */
  190. static IR_KEYTAB_TYPE ir_codes_cinergy_1400[IR_KEYTAB_SIZE] = {
  191. [0x01] = KEY_POWER,
  192. [0x02] = KEY_1,
  193. [0x03] = KEY_2,
  194. [0x04] = KEY_3,
  195. [0x05] = KEY_4,
  196. [0x06] = KEY_5,
  197. [0x07] = KEY_6,
  198. [0x08] = KEY_7,
  199. [0x09] = KEY_8,
  200. [0x0a] = KEY_9,
  201. [0x0c] = KEY_0,
  202. [0x0b] = KEY_VIDEO,
  203. [0x0d] = KEY_REFRESH,
  204. [0x0e] = KEY_SELECT,
  205. [0x0f] = KEY_EPG,
  206. [0x10] = KEY_UP,
  207. [0x11] = KEY_LEFT,
  208. [0x12] = KEY_OK,
  209. [0x13] = KEY_RIGHT,
  210. [0x14] = KEY_DOWN,
  211. [0x15] = KEY_TEXT,
  212. [0x16] = KEY_INFO,
  213. [0x17] = KEY_RED,
  214. [0x18] = KEY_GREEN,
  215. [0x19] = KEY_YELLOW,
  216. [0x1a] = KEY_BLUE,
  217. [0x1b] = KEY_CHANNELUP,
  218. [0x1c] = KEY_VOLUMEUP,
  219. [0x1d] = KEY_MUTE,
  220. [0x1e] = KEY_VOLUMEDOWN,
  221. [0x1f] = KEY_CHANNELDOWN,
  222. [0x40] = KEY_PAUSE,
  223. [0x4c] = KEY_PLAY,
  224. [0x58] = KEY_RECORD,
  225. [0x54] = KEY_PREVIOUS,
  226. [0x48] = KEY_STOP,
  227. [0x5c] = KEY_NEXT,
  228. };
  229. /* ---------------------------------------------------------------------- */
  230. /* AVERTV STUDIO 303 Remote */
  231. static IR_KEYTAB_TYPE ir_codes_avertv_303[IR_KEYTAB_SIZE] = {
  232. [ 0x2a ] = KEY_KP1,
  233. [ 0x32 ] = KEY_KP2,
  234. [ 0x3a ] = KEY_KP3,
  235. [ 0x4a ] = KEY_KP4,
  236. [ 0x52 ] = KEY_KP5,
  237. [ 0x5a ] = KEY_KP6,
  238. [ 0x6a ] = KEY_KP7,
  239. [ 0x72 ] = KEY_KP8,
  240. [ 0x7a ] = KEY_KP9,
  241. [ 0x0e ] = KEY_KP0,
  242. [ 0x02 ] = KEY_POWER,
  243. [ 0x22 ] = KEY_VIDEO,
  244. [ 0x42 ] = KEY_AUDIO,
  245. [ 0x62 ] = KEY_ZOOM,
  246. [ 0x0a ] = KEY_TV,
  247. [ 0x12 ] = KEY_CD,
  248. [ 0x1a ] = KEY_TEXT,
  249. [ 0x16 ] = KEY_SUBTITLE,
  250. [ 0x1e ] = KEY_REWIND,
  251. [ 0x06 ] = KEY_PRINT,
  252. [ 0x2e ] = KEY_SEARCH,
  253. [ 0x36 ] = KEY_SLEEP,
  254. [ 0x3e ] = KEY_SHUFFLE,
  255. [ 0x26 ] = KEY_MUTE,
  256. [ 0x4e ] = KEY_RECORD,
  257. [ 0x56 ] = KEY_PAUSE,
  258. [ 0x5e ] = KEY_STOP,
  259. [ 0x46 ] = KEY_PLAY,
  260. [ 0x6e ] = KEY_RED,
  261. [ 0x0b ] = KEY_GREEN,
  262. [ 0x66 ] = KEY_YELLOW,
  263. [ 0x03 ] = KEY_BLUE,
  264. [ 0x76 ] = KEY_LEFT,
  265. [ 0x7e ] = KEY_RIGHT,
  266. [ 0x13 ] = KEY_DOWN,
  267. [ 0x1b ] = KEY_UP,
  268. };
  269. /* ---------------------------------------------------------------------- */
  270. /* DigitalNow DNTV Live! DVB-T Pro Remote */
  271. static IR_KEYTAB_TYPE ir_codes_dntv_live_dvbt_pro[IR_KEYTAB_SIZE] = {
  272. [ 0x16 ] = KEY_POWER,
  273. [ 0x5b ] = KEY_HOME,
  274. [ 0x55 ] = KEY_TV, /* live tv */
  275. [ 0x58 ] = KEY_TUNER, /* digital Radio */
  276. [ 0x5a ] = KEY_RADIO, /* FM radio */
  277. [ 0x59 ] = KEY_DVD, /* dvd menu */
  278. [ 0x03 ] = KEY_1,
  279. [ 0x01 ] = KEY_2,
  280. [ 0x06 ] = KEY_3,
  281. [ 0x09 ] = KEY_4,
  282. [ 0x1d ] = KEY_5,
  283. [ 0x1f ] = KEY_6,
  284. [ 0x0d ] = KEY_7,
  285. [ 0x19 ] = KEY_8,
  286. [ 0x1b ] = KEY_9,
  287. [ 0x0c ] = KEY_CANCEL,
  288. [ 0x15 ] = KEY_0,
  289. [ 0x4a ] = KEY_CLEAR,
  290. [ 0x13 ] = KEY_BACK,
  291. [ 0x00 ] = KEY_TAB,
  292. [ 0x4b ] = KEY_UP,
  293. [ 0x4e ] = KEY_LEFT,
  294. [ 0x4f ] = KEY_OK,
  295. [ 0x52 ] = KEY_RIGHT,
  296. [ 0x51 ] = KEY_DOWN,
  297. [ 0x1e ] = KEY_VOLUMEUP,
  298. [ 0x0a ] = KEY_VOLUMEDOWN,
  299. [ 0x02 ] = KEY_CHANNELDOWN,
  300. [ 0x05 ] = KEY_CHANNELUP,
  301. [ 0x11 ] = KEY_RECORD,
  302. [ 0x14 ] = KEY_PLAY,
  303. [ 0x4c ] = KEY_PAUSE,
  304. [ 0x1a ] = KEY_STOP,
  305. [ 0x40 ] = KEY_REWIND,
  306. [ 0x12 ] = KEY_FASTFORWARD,
  307. [ 0x41 ] = KEY_PREVIOUSSONG, /* replay |< */
  308. [ 0x42 ] = KEY_NEXTSONG, /* skip >| */
  309. [ 0x54 ] = KEY_CAMERA, /* capture */
  310. [ 0x50 ] = KEY_LANGUAGE, /* sap */
  311. [ 0x47 ] = KEY_TV2, /* pip */
  312. [ 0x4d ] = KEY_SCREEN,
  313. [ 0x43 ] = KEY_SUBTITLE,
  314. [ 0x10 ] = KEY_MUTE,
  315. [ 0x49 ] = KEY_AUDIO, /* l/r */
  316. [ 0x07 ] = KEY_SLEEP,
  317. [ 0x08 ] = KEY_VIDEO, /* a/v */
  318. [ 0x0e ] = KEY_PREVIOUS, /* recall */
  319. [ 0x45 ] = KEY_ZOOM, /* zoom + */
  320. [ 0x46 ] = KEY_ANGLE, /* zoom - */
  321. [ 0x56 ] = KEY_RED,
  322. [ 0x57 ] = KEY_GREEN,
  323. [ 0x5c ] = KEY_YELLOW,
  324. [ 0x5d ] = KEY_BLUE,
  325. };
  326. /* ---------------------------------------------------------------------- */
  327. struct cx88_IR {
  328. struct cx88_core *core;
  329. struct input_dev *input;
  330. struct ir_input_state ir;
  331. char name[32];
  332. char phys[32];
  333. /* sample from gpio pin 16 */
  334. u32 sampling;
  335. u32 samples[16];
  336. int scount;
  337. unsigned long release;
  338. /* poll external decoder */
  339. int polling;
  340. struct work_struct work;
  341. struct timer_list timer;
  342. u32 gpio_addr;
  343. u32 last_gpio;
  344. u32 mask_keycode;
  345. u32 mask_keydown;
  346. u32 mask_keyup;
  347. };
  348. static int ir_debug = 0;
  349. module_param(ir_debug, int, 0644); /* debug level [IR] */
  350. MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
  351. #define ir_dprintk(fmt, arg...) if (ir_debug) \
  352. printk(KERN_DEBUG "%s IR: " fmt , ir->core->name , ##arg)
  353. /* ---------------------------------------------------------------------- */
  354. static void cx88_ir_handle_key(struct cx88_IR *ir)
  355. {
  356. struct cx88_core *core = ir->core;
  357. u32 gpio, data;
  358. /* read gpio value */
  359. gpio = cx_read(ir->gpio_addr);
  360. if (ir->polling) {
  361. if (ir->last_gpio == gpio)
  362. return;
  363. ir->last_gpio = gpio;
  364. }
  365. /* extract data */
  366. data = ir_extract_bits(gpio, ir->mask_keycode);
  367. ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n",
  368. gpio, data,
  369. ir->polling ? "poll" : "irq",
  370. (gpio & ir->mask_keydown) ? " down" : "",
  371. (gpio & ir->mask_keyup) ? " up" : "");
  372. if (ir->mask_keydown) {
  373. /* bit set on keydown */
  374. if (gpio & ir->mask_keydown) {
  375. ir_input_keydown(ir->input, &ir->ir, data, data);
  376. } else {
  377. ir_input_nokey(ir->input, &ir->ir);
  378. }
  379. } else if (ir->mask_keyup) {
  380. /* bit cleared on keydown */
  381. if (0 == (gpio & ir->mask_keyup)) {
  382. ir_input_keydown(ir->input, &ir->ir, data, data);
  383. } else {
  384. ir_input_nokey(ir->input, &ir->ir);
  385. }
  386. } else {
  387. /* can't distinguish keydown/up :-/ */
  388. ir_input_keydown(ir->input, &ir->ir, data, data);
  389. ir_input_nokey(ir->input, &ir->ir);
  390. }
  391. }
  392. static void ir_timer(unsigned long data)
  393. {
  394. struct cx88_IR *ir = (struct cx88_IR *)data;
  395. schedule_work(&ir->work);
  396. }
  397. static void cx88_ir_work(void *data)
  398. {
  399. struct cx88_IR *ir = data;
  400. unsigned long timeout;
  401. cx88_ir_handle_key(ir);
  402. timeout = jiffies + (ir->polling * HZ / 1000);
  403. mod_timer(&ir->timer, timeout);
  404. }
  405. /* ---------------------------------------------------------------------- */
  406. int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
  407. {
  408. struct cx88_IR *ir;
  409. struct input_dev *input_dev;
  410. IR_KEYTAB_TYPE *ir_codes = NULL;
  411. int ir_type = IR_TYPE_OTHER;
  412. ir = kzalloc(sizeof(*ir), GFP_KERNEL);
  413. input_dev = input_allocate_device();
  414. if (!ir || !input_dev) {
  415. kfree(ir);
  416. input_free_device(input_dev);
  417. return -ENOMEM;
  418. }
  419. ir->input = input_dev;
  420. /* detect & configure */
  421. switch (core->board) {
  422. case CX88_BOARD_DNTV_LIVE_DVB_T:
  423. case CX88_BOARD_KWORLD_DVB_T:
  424. ir_codes = ir_codes_dntv_live_dvb_t;
  425. ir->gpio_addr = MO_GP1_IO;
  426. ir->mask_keycode = 0x1f;
  427. ir->mask_keyup = 0x60;
  428. ir->polling = 50; /* ms */
  429. break;
  430. case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
  431. ir_codes = ir_codes_cinergy_1400;
  432. ir_type = IR_TYPE_PD;
  433. ir->sampling = 0xeb04; /* address */
  434. break;
  435. case CX88_BOARD_HAUPPAUGE:
  436. case CX88_BOARD_HAUPPAUGE_DVB_T1:
  437. case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
  438. case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
  439. case CX88_BOARD_HAUPPAUGE_HVR1100:
  440. ir_codes = ir_codes_hauppauge_new;
  441. ir_type = IR_TYPE_RC5;
  442. ir->sampling = 1;
  443. break;
  444. case CX88_BOARD_WINFAST2000XP_EXPERT:
  445. ir_codes = ir_codes_winfast;
  446. ir->gpio_addr = MO_GP0_IO;
  447. ir->mask_keycode = 0x8f8;
  448. ir->mask_keyup = 0x100;
  449. ir->polling = 1; /* ms */
  450. break;
  451. case CX88_BOARD_IODATA_GVBCTV7E:
  452. ir_codes = ir_codes_iodata_bctv7e;
  453. ir->gpio_addr = MO_GP0_IO;
  454. ir->mask_keycode = 0xfd;
  455. ir->mask_keydown = 0x02;
  456. ir->polling = 5; /* ms */
  457. break;
  458. case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
  459. ir_codes = ir_codes_pixelview;
  460. ir->gpio_addr = MO_GP1_IO;
  461. ir->mask_keycode = 0x1f;
  462. ir->mask_keyup = 0x80;
  463. ir->polling = 1; /* ms */
  464. break;
  465. case CX88_BOARD_ADSTECH_DVB_T_PCI:
  466. ir_codes = ir_codes_adstech_dvb_t_pci;
  467. ir->gpio_addr = MO_GP1_IO;
  468. ir->mask_keycode = 0xbf;
  469. ir->mask_keyup = 0x40;
  470. ir->polling = 50; /* ms */
  471. break;
  472. case CX88_BOARD_MSI_TVANYWHERE_MASTER:
  473. ir_codes = ir_codes_msi_tvanywhere;
  474. ir->gpio_addr = MO_GP1_IO;
  475. ir->mask_keycode = 0x1f;
  476. ir->mask_keyup = 0x40;
  477. ir->polling = 1; /* ms */
  478. break;
  479. case CX88_BOARD_AVERTV_303:
  480. ir_codes = ir_codes_avertv_303;
  481. ir->gpio_addr = MO_GP2_IO;
  482. ir->mask_keycode = 0xfb;
  483. ir->mask_keydown = 0x02;
  484. ir->polling = 50; /* ms */
  485. break;
  486. case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
  487. ir_codes = ir_codes_dntv_live_dvbt_pro;
  488. ir_type = IR_TYPE_PD;
  489. ir->sampling = 0xff00; /* address */
  490. break;
  491. }
  492. if (NULL == ir_codes) {
  493. kfree(ir);
  494. input_free_device(input_dev);
  495. return -ENODEV;
  496. }
  497. /* init input device */
  498. snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)",
  499. cx88_boards[core->board].name);
  500. snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
  501. ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
  502. input_dev->name = ir->name;
  503. input_dev->phys = ir->phys;
  504. input_dev->id.bustype = BUS_PCI;
  505. input_dev->id.version = 1;
  506. if (pci->subsystem_vendor) {
  507. input_dev->id.vendor = pci->subsystem_vendor;
  508. input_dev->id.product = pci->subsystem_device;
  509. } else {
  510. input_dev->id.vendor = pci->vendor;
  511. input_dev->id.product = pci->device;
  512. }
  513. input_dev->cdev.dev = &pci->dev;
  514. /* record handles to ourself */
  515. ir->core = core;
  516. core->ir = ir;
  517. if (ir->polling) {
  518. INIT_WORK(&ir->work, cx88_ir_work, ir);
  519. init_timer(&ir->timer);
  520. ir->timer.function = ir_timer;
  521. ir->timer.data = (unsigned long)ir;
  522. schedule_work(&ir->work);
  523. }
  524. if (ir->sampling) {
  525. core->pci_irqmask |= (1 << 18); /* IR_SMP_INT */
  526. cx_write(MO_DDS_IO, 0xa80a80); /* 4 kHz sample rate */
  527. cx_write(MO_DDSCFG_IO, 0x5); /* enable */
  528. }
  529. /* all done */
  530. input_register_device(ir->input);
  531. return 0;
  532. }
  533. int cx88_ir_fini(struct cx88_core *core)
  534. {
  535. struct cx88_IR *ir = core->ir;
  536. /* skip detach on non attached boards */
  537. if (NULL == ir)
  538. return 0;
  539. if (ir->sampling) {
  540. cx_write(MO_DDSCFG_IO, 0x0);
  541. core->pci_irqmask &= ~(1 << 18);
  542. }
  543. if (ir->polling) {
  544. del_timer(&ir->timer);
  545. flush_scheduled_work();
  546. }
  547. input_unregister_device(ir->input);
  548. kfree(ir);
  549. /* done */
  550. core->ir = NULL;
  551. return 0;
  552. }
  553. /* ---------------------------------------------------------------------- */
  554. void cx88_ir_irq(struct cx88_core *core)
  555. {
  556. struct cx88_IR *ir = core->ir;
  557. u32 samples, ircode;
  558. int i;
  559. if (NULL == ir)
  560. return;
  561. if (!ir->sampling)
  562. return;
  563. samples = cx_read(MO_SAMPLE_IO);
  564. if (0 != samples && 0xffffffff != samples) {
  565. /* record sample data */
  566. if (ir->scount < ARRAY_SIZE(ir->samples))
  567. ir->samples[ir->scount++] = samples;
  568. return;
  569. }
  570. if (!ir->scount) {
  571. /* nothing to sample */
  572. if (ir->ir.keypressed && time_after(jiffies, ir->release))
  573. ir_input_nokey(ir->input, &ir->ir);
  574. return;
  575. }
  576. /* have a complete sample */
  577. if (ir->scount < ARRAY_SIZE(ir->samples))
  578. ir->samples[ir->scount++] = samples;
  579. for (i = 0; i < ir->scount; i++)
  580. ir->samples[i] = ~ir->samples[i];
  581. if (ir_debug)
  582. ir_dump_samples(ir->samples, ir->scount);
  583. /* decode it */
  584. switch (core->board) {
  585. case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
  586. case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
  587. ircode = ir_decode_pulsedistance(ir->samples, ir->scount, 1, 4);
  588. if (ircode == 0xffffffff) { /* decoding error */
  589. ir_dprintk("pulse distance decoding error\n");
  590. break;
  591. }
  592. ir_dprintk("pulse distance decoded: %x\n", ircode);
  593. if (ircode == 0) { /* key still pressed */
  594. ir_dprintk("pulse distance decoded repeat code\n");
  595. ir->release = jiffies + msecs_to_jiffies(120);
  596. break;
  597. }
  598. if ((ircode & 0xffff) != (ir->sampling & 0xffff)) { /* wrong address */
  599. ir_dprintk("pulse distance decoded wrong address\n");
  600. break;
  601. }
  602. if (((~ircode >> 24) & 0xff) != ((ircode >> 16) & 0xff)) { /* wrong checksum */
  603. ir_dprintk("pulse distance decoded wrong check sum\n");
  604. break;
  605. }
  606. ir_dprintk("Key Code: %x\n", (ircode >> 16) & 0x7f);
  607. ir_input_keydown(ir->input, &ir->ir, (ircode >> 16) & 0x7f, (ircode >> 16) & 0xff);
  608. ir->release = jiffies + msecs_to_jiffies(120);
  609. break;
  610. case CX88_BOARD_HAUPPAUGE:
  611. case CX88_BOARD_HAUPPAUGE_DVB_T1:
  612. case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
  613. case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
  614. ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
  615. ir_dprintk("biphase decoded: %x\n", ircode);
  616. if ((ircode & 0xfffff000) != 0x3000)
  617. break;
  618. ir_input_keydown(ir->input, &ir->ir, ircode & 0x3f, ircode);
  619. ir->release = jiffies + msecs_to_jiffies(120);
  620. break;
  621. }
  622. ir->scount = 0;
  623. return;
  624. }
  625. /* ---------------------------------------------------------------------- */
  626. MODULE_AUTHOR("Gerd Knorr, Pavel Machek, Chris Pascoe");
  627. MODULE_DESCRIPTION("input driver for cx88 GPIO-based IR remote controls");
  628. MODULE_LICENSE("GPL");
  629. /*
  630. * Local variables:
  631. * c-basic-offset: 8
  632. * End:
  633. */