cx88-input.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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 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. struct cx88_IR {
  271. struct cx88_core *core;
  272. struct input_dev *input;
  273. struct ir_input_state ir;
  274. char name[32];
  275. char phys[32];
  276. /* sample from gpio pin 16 */
  277. int sampling;
  278. u32 samples[16];
  279. int scount;
  280. unsigned long release;
  281. /* poll external decoder */
  282. int polling;
  283. struct work_struct work;
  284. struct timer_list timer;
  285. u32 gpio_addr;
  286. u32 last_gpio;
  287. u32 mask_keycode;
  288. u32 mask_keydown;
  289. u32 mask_keyup;
  290. };
  291. static int ir_debug = 0;
  292. module_param(ir_debug, int, 0644); /* debug level [IR] */
  293. MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
  294. #define ir_dprintk(fmt, arg...) if (ir_debug) \
  295. printk(KERN_DEBUG "%s IR: " fmt , ir->core->name , ##arg)
  296. /* ---------------------------------------------------------------------- */
  297. static void cx88_ir_handle_key(struct cx88_IR *ir)
  298. {
  299. struct cx88_core *core = ir->core;
  300. u32 gpio, data;
  301. /* read gpio value */
  302. gpio = cx_read(ir->gpio_addr);
  303. if (ir->polling) {
  304. if (ir->last_gpio == gpio)
  305. return;
  306. ir->last_gpio = gpio;
  307. }
  308. /* extract data */
  309. data = ir_extract_bits(gpio, ir->mask_keycode);
  310. ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n",
  311. gpio, data,
  312. ir->polling ? "poll" : "irq",
  313. (gpio & ir->mask_keydown) ? " down" : "",
  314. (gpio & ir->mask_keyup) ? " up" : "");
  315. if (ir->mask_keydown) {
  316. /* bit set on keydown */
  317. if (gpio & ir->mask_keydown) {
  318. ir_input_keydown(ir->input, &ir->ir, data, data);
  319. } else {
  320. ir_input_nokey(ir->input, &ir->ir);
  321. }
  322. } else if (ir->mask_keyup) {
  323. /* bit cleared on keydown */
  324. if (0 == (gpio & ir->mask_keyup)) {
  325. ir_input_keydown(ir->input, &ir->ir, data, data);
  326. } else {
  327. ir_input_nokey(ir->input, &ir->ir);
  328. }
  329. } else {
  330. /* can't distinguish keydown/up :-/ */
  331. ir_input_keydown(ir->input, &ir->ir, data, data);
  332. ir_input_nokey(ir->input, &ir->ir);
  333. }
  334. }
  335. static void ir_timer(unsigned long data)
  336. {
  337. struct cx88_IR *ir = (struct cx88_IR *)data;
  338. schedule_work(&ir->work);
  339. }
  340. static void cx88_ir_work(void *data)
  341. {
  342. struct cx88_IR *ir = data;
  343. unsigned long timeout;
  344. cx88_ir_handle_key(ir);
  345. timeout = jiffies + (ir->polling * HZ / 1000);
  346. mod_timer(&ir->timer, timeout);
  347. }
  348. /* ---------------------------------------------------------------------- */
  349. int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
  350. {
  351. struct cx88_IR *ir;
  352. struct input_dev *input_dev;
  353. IR_KEYTAB_TYPE *ir_codes = NULL;
  354. int ir_type = IR_TYPE_OTHER;
  355. ir = kzalloc(sizeof(*ir), GFP_KERNEL);
  356. input_dev = input_allocate_device();
  357. if (!ir || !input_dev) {
  358. kfree(ir);
  359. input_free_device(input_dev);
  360. return -ENOMEM;
  361. }
  362. ir->input = input_dev;
  363. /* detect & configure */
  364. switch (core->board) {
  365. case CX88_BOARD_DNTV_LIVE_DVB_T:
  366. case CX88_BOARD_KWORLD_DVB_T:
  367. ir_codes = ir_codes_dntv_live_dvb_t;
  368. ir->gpio_addr = MO_GP1_IO;
  369. ir->mask_keycode = 0x1f;
  370. ir->mask_keyup = 0x60;
  371. ir->polling = 50; /* ms */
  372. break;
  373. case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
  374. ir_codes = ir_codes_cinergy_1400;
  375. ir_type = IR_TYPE_PD;
  376. ir->sampling = 1;
  377. break;
  378. case CX88_BOARD_HAUPPAUGE:
  379. case CX88_BOARD_HAUPPAUGE_DVB_T1:
  380. case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
  381. case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
  382. case CX88_BOARD_HAUPPAUGE_HVR1100:
  383. ir_codes = ir_codes_hauppauge_new;
  384. ir_type = IR_TYPE_RC5;
  385. ir->sampling = 1;
  386. break;
  387. case CX88_BOARD_WINFAST2000XP_EXPERT:
  388. ir_codes = ir_codes_winfast;
  389. ir->gpio_addr = MO_GP0_IO;
  390. ir->mask_keycode = 0x8f8;
  391. ir->mask_keyup = 0x100;
  392. ir->polling = 1; /* ms */
  393. break;
  394. case CX88_BOARD_IODATA_GVBCTV7E:
  395. ir_codes = ir_codes_iodata_bctv7e;
  396. ir->gpio_addr = MO_GP0_IO;
  397. ir->mask_keycode = 0xfd;
  398. ir->mask_keydown = 0x02;
  399. ir->polling = 5; /* ms */
  400. break;
  401. case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
  402. ir_codes = ir_codes_pixelview;
  403. ir->gpio_addr = MO_GP1_IO;
  404. ir->mask_keycode = 0x1f;
  405. ir->mask_keyup = 0x80;
  406. ir->polling = 1; /* ms */
  407. break;
  408. case CX88_BOARD_ADSTECH_DVB_T_PCI:
  409. ir_codes = ir_codes_adstech_dvb_t_pci;
  410. ir->gpio_addr = MO_GP1_IO;
  411. ir->mask_keycode = 0xbf;
  412. ir->mask_keyup = 0x40;
  413. ir->polling = 50; /* ms */
  414. break;
  415. case CX88_BOARD_MSI_TVANYWHERE_MASTER:
  416. ir_codes = ir_codes_msi_tvanywhere;
  417. ir->gpio_addr = MO_GP1_IO;
  418. ir->mask_keycode = 0x1f;
  419. ir->mask_keyup = 0x40;
  420. ir->polling = 1; /* ms */
  421. break;
  422. case CX88_BOARD_AVERTV_303:
  423. ir_codes = ir_codes_avertv_303;
  424. ir->gpio_addr = MO_GP2_IO;
  425. ir->mask_keycode = 0xfb;
  426. ir->mask_keydown = 0x02;
  427. ir->polling = 50; /* ms */
  428. break;
  429. }
  430. if (NULL == ir_codes) {
  431. kfree(ir);
  432. input_free_device(input_dev);
  433. return -ENODEV;
  434. }
  435. /* init input device */
  436. snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)",
  437. cx88_boards[core->board].name);
  438. snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
  439. ir_input_init(input_dev, &ir->ir, ir_type, ir_codes);
  440. input_dev->name = ir->name;
  441. input_dev->phys = ir->phys;
  442. input_dev->id.bustype = BUS_PCI;
  443. input_dev->id.version = 1;
  444. if (pci->subsystem_vendor) {
  445. input_dev->id.vendor = pci->subsystem_vendor;
  446. input_dev->id.product = pci->subsystem_device;
  447. } else {
  448. input_dev->id.vendor = pci->vendor;
  449. input_dev->id.product = pci->device;
  450. }
  451. input_dev->cdev.dev = &pci->dev;
  452. /* record handles to ourself */
  453. ir->core = core;
  454. core->ir = ir;
  455. if (ir->polling) {
  456. INIT_WORK(&ir->work, cx88_ir_work, ir);
  457. init_timer(&ir->timer);
  458. ir->timer.function = ir_timer;
  459. ir->timer.data = (unsigned long)ir;
  460. schedule_work(&ir->work);
  461. }
  462. if (ir->sampling) {
  463. core->pci_irqmask |= (1 << 18); /* IR_SMP_INT */
  464. cx_write(MO_DDS_IO, 0xa80a80); /* 4 kHz sample rate */
  465. cx_write(MO_DDSCFG_IO, 0x5); /* enable */
  466. }
  467. /* all done */
  468. input_register_device(ir->input);
  469. return 0;
  470. }
  471. int cx88_ir_fini(struct cx88_core *core)
  472. {
  473. struct cx88_IR *ir = core->ir;
  474. /* skip detach on non attached boards */
  475. if (NULL == ir)
  476. return 0;
  477. if (ir->polling) {
  478. del_timer(&ir->timer);
  479. flush_scheduled_work();
  480. }
  481. input_unregister_device(ir->input);
  482. kfree(ir);
  483. /* done */
  484. core->ir = NULL;
  485. return 0;
  486. }
  487. /* ---------------------------------------------------------------------- */
  488. void cx88_ir_irq(struct cx88_core *core)
  489. {
  490. struct cx88_IR *ir = core->ir;
  491. u32 samples, ircode;
  492. int i;
  493. if (NULL == ir)
  494. return;
  495. if (!ir->sampling)
  496. return;
  497. samples = cx_read(MO_SAMPLE_IO);
  498. if (0 != samples && 0xffffffff != samples) {
  499. /* record sample data */
  500. if (ir->scount < ARRAY_SIZE(ir->samples))
  501. ir->samples[ir->scount++] = samples;
  502. return;
  503. }
  504. if (!ir->scount) {
  505. /* nothing to sample */
  506. if (ir->ir.keypressed && time_after(jiffies, ir->release))
  507. ir_input_nokey(ir->input, &ir->ir);
  508. return;
  509. }
  510. /* have a complete sample */
  511. if (ir->scount < ARRAY_SIZE(ir->samples))
  512. ir->samples[ir->scount++] = samples;
  513. for (i = 0; i < ir->scount; i++)
  514. ir->samples[i] = ~ir->samples[i];
  515. if (ir_debug)
  516. ir_dump_samples(ir->samples, ir->scount);
  517. /* decode it */
  518. switch (core->board) {
  519. case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
  520. ircode = ir_decode_pulsedistance(ir->samples, ir->scount, 1, 4);
  521. if (ircode == 0xffffffff) { /* decoding error */
  522. ir_dprintk("pulse distance decoding error\n");
  523. break;
  524. }
  525. ir_dprintk("pulse distance decoded: %x\n", ircode);
  526. if (ircode == 0) { /* key still pressed */
  527. ir_dprintk("pulse distance decoded repeat code\n");
  528. ir->release = jiffies + msecs_to_jiffies(120);
  529. break;
  530. }
  531. if ((ircode & 0xffff) != 0xeb04) { /* wrong address */
  532. ir_dprintk("pulse distance decoded wrong address\n");
  533. break;
  534. }
  535. if (((~ircode >> 24) & 0xff) != ((ircode >> 16) & 0xff)) { /* wrong checksum */
  536. ir_dprintk("pulse distance decoded wrong check sum\n");
  537. break;
  538. }
  539. ir_dprintk("Key Code: %x\n", (ircode >> 16) & 0x7f);
  540. ir_input_keydown(ir->input, &ir->ir, (ircode >> 16) & 0x7f, (ircode >> 16) & 0xff);
  541. ir->release = jiffies + msecs_to_jiffies(120);
  542. break;
  543. case CX88_BOARD_HAUPPAUGE:
  544. case CX88_BOARD_HAUPPAUGE_DVB_T1:
  545. case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
  546. case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
  547. ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
  548. ir_dprintk("biphase decoded: %x\n", ircode);
  549. if ((ircode & 0xfffff000) != 0x3000)
  550. break;
  551. ir_input_keydown(ir->input, &ir->ir, ircode & 0x3f, ircode);
  552. ir->release = jiffies + msecs_to_jiffies(120);
  553. break;
  554. }
  555. ir->scount = 0;
  556. return;
  557. }
  558. /* ---------------------------------------------------------------------- */
  559. MODULE_AUTHOR("Gerd Knorr, Pavel Machek, Chris Pascoe");
  560. MODULE_DESCRIPTION("input driver for cx88 GPIO-based IR remote controls");
  561. MODULE_LICENSE("GPL");
  562. /*
  563. * Local variables:
  564. * c-basic-offset: 8
  565. * End:
  566. */