cx88-input.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  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. #include "cx88.h"
  21. #include <linux/init.h>
  22. #include <linux/hrtimer.h>
  23. #include <linux/pci.h>
  24. #include <linux/slab.h>
  25. #include <linux/module.h>
  26. #include <media/rc-core.h>
  27. #define MODULE_NAME "cx88xx"
  28. /* ---------------------------------------------------------------------- */
  29. struct cx88_IR {
  30. struct cx88_core *core;
  31. struct rc_dev *dev;
  32. int users;
  33. char name[32];
  34. char phys[32];
  35. /* sample from gpio pin 16 */
  36. u32 sampling;
  37. /* poll external decoder */
  38. int polling;
  39. struct hrtimer timer;
  40. u32 gpio_addr;
  41. u32 last_gpio;
  42. u32 mask_keycode;
  43. u32 mask_keydown;
  44. u32 mask_keyup;
  45. };
  46. static unsigned int ir_samplerate = 4;
  47. module_param(ir_samplerate, uint, 0444);
  48. MODULE_PARM_DESC(ir_samplerate, "IR samplerate in kHz, 1 - 20, default 4");
  49. static int ir_debug;
  50. module_param(ir_debug, int, 0644); /* debug level [IR] */
  51. MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
  52. #define ir_dprintk(fmt, arg...) do { \
  53. if (ir_debug) \
  54. printk(KERN_DEBUG "%s IR: " fmt, ir->core->name, ##arg);\
  55. } while (0)
  56. #define dprintk(fmt, arg...) do { \
  57. if (ir_debug) \
  58. printk(KERN_DEBUG "cx88 IR: " fmt, ##arg); \
  59. } while (0)
  60. /* ---------------------------------------------------------------------- */
  61. static void cx88_ir_handle_key(struct cx88_IR *ir)
  62. {
  63. struct cx88_core *core = ir->core;
  64. u32 gpio, data, auxgpio;
  65. /* read gpio value */
  66. gpio = cx_read(ir->gpio_addr);
  67. switch (core->boardnr) {
  68. case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
  69. /*
  70. * This board apparently uses a combination of 2 GPIO
  71. * to represent the keys. Additionally, the second GPIO
  72. * can be used for parity.
  73. *
  74. * Example:
  75. *
  76. * for key "5"
  77. * gpio = 0x758, auxgpio = 0xe5 or 0xf5
  78. * for key "Power"
  79. * gpio = 0x758, auxgpio = 0xed or 0xfd
  80. */
  81. auxgpio = cx_read(MO_GP1_IO);
  82. /* Take out the parity part */
  83. gpio = (gpio & 0x7fd) + (auxgpio & 0xef);
  84. break;
  85. case CX88_BOARD_WINFAST_DTV1000:
  86. case CX88_BOARD_WINFAST_DTV1800H:
  87. case CX88_BOARD_WINFAST_DTV1800H_XC4000:
  88. case CX88_BOARD_WINFAST_DTV2000H_PLUS:
  89. case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL:
  90. case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F36:
  91. case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F43:
  92. gpio = (gpio & 0x6ff) | ((cx_read(MO_GP1_IO) << 8) & 0x900);
  93. auxgpio = gpio;
  94. break;
  95. default:
  96. auxgpio = gpio;
  97. }
  98. if (ir->polling) {
  99. if (ir->last_gpio == auxgpio)
  100. return;
  101. ir->last_gpio = auxgpio;
  102. }
  103. /* extract data */
  104. data = ir_extract_bits(gpio, ir->mask_keycode);
  105. ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n",
  106. gpio, data,
  107. ir->polling ? "poll" : "irq",
  108. (gpio & ir->mask_keydown) ? " down" : "",
  109. (gpio & ir->mask_keyup) ? " up" : "");
  110. if (ir->core->boardnr == CX88_BOARD_NORWOOD_MICRO) {
  111. u32 gpio_key = cx_read(MO_GP0_IO);
  112. data = (data << 4) | ((gpio_key & 0xf0) >> 4);
  113. rc_keydown(ir->dev, RC_PROTO_UNKNOWN, data, 0);
  114. } else if (ir->core->boardnr == CX88_BOARD_PROLINK_PLAYTVPVR ||
  115. ir->core->boardnr == CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO) {
  116. /* bit cleared on keydown, NEC scancode, 0xAAAACC, A = 0x866b */
  117. u16 addr;
  118. u8 cmd;
  119. u32 scancode;
  120. addr = (data >> 8) & 0xffff;
  121. cmd = (data >> 0) & 0x00ff;
  122. scancode = RC_SCANCODE_NECX(addr, cmd);
  123. if (0 == (gpio & ir->mask_keyup))
  124. rc_keydown_notimeout(ir->dev, RC_PROTO_NECX, scancode,
  125. 0);
  126. else
  127. rc_keyup(ir->dev);
  128. } else if (ir->mask_keydown) {
  129. /* bit set on keydown */
  130. if (gpio & ir->mask_keydown)
  131. rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data,
  132. 0);
  133. else
  134. rc_keyup(ir->dev);
  135. } else if (ir->mask_keyup) {
  136. /* bit cleared on keydown */
  137. if (0 == (gpio & ir->mask_keyup))
  138. rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data,
  139. 0);
  140. else
  141. rc_keyup(ir->dev);
  142. } else {
  143. /* can't distinguish keydown/up :-/ */
  144. rc_keydown_notimeout(ir->dev, RC_PROTO_UNKNOWN, data, 0);
  145. rc_keyup(ir->dev);
  146. }
  147. }
  148. static enum hrtimer_restart cx88_ir_work(struct hrtimer *timer)
  149. {
  150. unsigned long missed;
  151. struct cx88_IR *ir = container_of(timer, struct cx88_IR, timer);
  152. cx88_ir_handle_key(ir);
  153. missed = hrtimer_forward_now(&ir->timer,
  154. ktime_set(0, ir->polling * 1000000));
  155. if (missed > 1)
  156. ir_dprintk("Missed ticks %ld\n", missed - 1);
  157. return HRTIMER_RESTART;
  158. }
  159. static int __cx88_ir_start(void *priv)
  160. {
  161. struct cx88_core *core = priv;
  162. struct cx88_IR *ir;
  163. if (!core || !core->ir)
  164. return -EINVAL;
  165. ir = core->ir;
  166. if (ir->polling) {
  167. hrtimer_init(&ir->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  168. ir->timer.function = cx88_ir_work;
  169. hrtimer_start(&ir->timer,
  170. ktime_set(0, ir->polling * 1000000),
  171. HRTIMER_MODE_REL);
  172. }
  173. if (ir->sampling) {
  174. core->pci_irqmask |= PCI_INT_IR_SMPINT;
  175. cx_write(MO_DDS_IO, 0x33F286 * ir_samplerate); /* samplerate */
  176. cx_write(MO_DDSCFG_IO, 0x5); /* enable */
  177. }
  178. return 0;
  179. }
  180. static void __cx88_ir_stop(void *priv)
  181. {
  182. struct cx88_core *core = priv;
  183. struct cx88_IR *ir;
  184. if (!core || !core->ir)
  185. return;
  186. ir = core->ir;
  187. if (ir->sampling) {
  188. cx_write(MO_DDSCFG_IO, 0x0);
  189. core->pci_irqmask &= ~PCI_INT_IR_SMPINT;
  190. }
  191. if (ir->polling)
  192. hrtimer_cancel(&ir->timer);
  193. }
  194. int cx88_ir_start(struct cx88_core *core)
  195. {
  196. if (core->ir->users)
  197. return __cx88_ir_start(core);
  198. return 0;
  199. }
  200. EXPORT_SYMBOL(cx88_ir_start);
  201. void cx88_ir_stop(struct cx88_core *core)
  202. {
  203. if (core->ir->users)
  204. __cx88_ir_stop(core);
  205. }
  206. EXPORT_SYMBOL(cx88_ir_stop);
  207. static int cx88_ir_open(struct rc_dev *rc)
  208. {
  209. struct cx88_core *core = rc->priv;
  210. core->ir->users++;
  211. return __cx88_ir_start(core);
  212. }
  213. static void cx88_ir_close(struct rc_dev *rc)
  214. {
  215. struct cx88_core *core = rc->priv;
  216. core->ir->users--;
  217. if (!core->ir->users)
  218. __cx88_ir_stop(core);
  219. }
  220. /* ---------------------------------------------------------------------- */
  221. int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
  222. {
  223. struct cx88_IR *ir;
  224. struct rc_dev *dev;
  225. char *ir_codes = NULL;
  226. u64 rc_proto = RC_PROTO_BIT_OTHER;
  227. int err = -ENOMEM;
  228. u32 hardware_mask = 0; /* For devices with a hardware mask, when
  229. * used with a full-code IR table
  230. */
  231. ir = kzalloc(sizeof(*ir), GFP_KERNEL);
  232. dev = rc_allocate_device(RC_DRIVER_IR_RAW);
  233. if (!ir || !dev)
  234. goto err_out_free;
  235. ir->dev = dev;
  236. /* detect & configure */
  237. switch (core->boardnr) {
  238. case CX88_BOARD_DNTV_LIVE_DVB_T:
  239. case CX88_BOARD_KWORLD_DVB_T:
  240. case CX88_BOARD_KWORLD_DVB_T_CX22702:
  241. ir_codes = RC_MAP_DNTV_LIVE_DVB_T;
  242. ir->gpio_addr = MO_GP1_IO;
  243. ir->mask_keycode = 0x1f;
  244. ir->mask_keyup = 0x60;
  245. ir->polling = 50; /* ms */
  246. break;
  247. case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1:
  248. ir_codes = RC_MAP_CINERGY_1400;
  249. ir->sampling = 0xeb04; /* address */
  250. break;
  251. case CX88_BOARD_HAUPPAUGE:
  252. case CX88_BOARD_HAUPPAUGE_DVB_T1:
  253. case CX88_BOARD_HAUPPAUGE_NOVASE2_S1:
  254. case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
  255. case CX88_BOARD_HAUPPAUGE_HVR1100:
  256. case CX88_BOARD_HAUPPAUGE_HVR3000:
  257. case CX88_BOARD_HAUPPAUGE_HVR4000:
  258. case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
  259. case CX88_BOARD_PCHDTV_HD3000:
  260. case CX88_BOARD_PCHDTV_HD5500:
  261. case CX88_BOARD_HAUPPAUGE_IRONLY:
  262. ir_codes = RC_MAP_HAUPPAUGE;
  263. ir->sampling = 1;
  264. break;
  265. case CX88_BOARD_WINFAST_DTV2000H:
  266. case CX88_BOARD_WINFAST_DTV2000H_J:
  267. case CX88_BOARD_WINFAST_DTV1800H:
  268. case CX88_BOARD_WINFAST_DTV1800H_XC4000:
  269. case CX88_BOARD_WINFAST_DTV2000H_PLUS:
  270. ir_codes = RC_MAP_WINFAST;
  271. ir->gpio_addr = MO_GP0_IO;
  272. ir->mask_keycode = 0x8f8;
  273. ir->mask_keyup = 0x100;
  274. ir->polling = 50; /* ms */
  275. break;
  276. case CX88_BOARD_WINFAST2000XP_EXPERT:
  277. case CX88_BOARD_WINFAST_DTV1000:
  278. case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL:
  279. case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F36:
  280. case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL_6F43:
  281. ir_codes = RC_MAP_WINFAST;
  282. ir->gpio_addr = MO_GP0_IO;
  283. ir->mask_keycode = 0x8f8;
  284. ir->mask_keyup = 0x100;
  285. ir->polling = 1; /* ms */
  286. break;
  287. case CX88_BOARD_IODATA_GVBCTV7E:
  288. ir_codes = RC_MAP_IODATA_BCTV7E;
  289. ir->gpio_addr = MO_GP0_IO;
  290. ir->mask_keycode = 0xfd;
  291. ir->mask_keydown = 0x02;
  292. ir->polling = 5; /* ms */
  293. break;
  294. case CX88_BOARD_PROLINK_PLAYTVPVR:
  295. case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO:
  296. /*
  297. * It seems that this hardware is paired with NEC extended
  298. * address 0x866b. So, unfortunately, its usage with other
  299. * IR's with different address won't work. Still, there are
  300. * other IR's from the same manufacturer that works, like the
  301. * 002-T mini RC, provided with newer PV hardware
  302. */
  303. ir_codes = RC_MAP_PIXELVIEW_MK12;
  304. rc_proto = RC_PROTO_BIT_NECX;
  305. ir->gpio_addr = MO_GP1_IO;
  306. ir->mask_keyup = 0x80;
  307. ir->polling = 10; /* ms */
  308. hardware_mask = 0x3f; /* Hardware returns only 6 bits from command part */
  309. break;
  310. case CX88_BOARD_PROLINK_PV_8000GT:
  311. case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
  312. ir_codes = RC_MAP_PIXELVIEW_NEW;
  313. ir->gpio_addr = MO_GP1_IO;
  314. ir->mask_keycode = 0x3f;
  315. ir->mask_keyup = 0x80;
  316. ir->polling = 1; /* ms */
  317. break;
  318. case CX88_BOARD_KWORLD_LTV883:
  319. ir_codes = RC_MAP_PIXELVIEW;
  320. ir->gpio_addr = MO_GP1_IO;
  321. ir->mask_keycode = 0x1f;
  322. ir->mask_keyup = 0x60;
  323. ir->polling = 1; /* ms */
  324. break;
  325. case CX88_BOARD_ADSTECH_DVB_T_PCI:
  326. ir_codes = RC_MAP_ADSTECH_DVB_T_PCI;
  327. ir->gpio_addr = MO_GP1_IO;
  328. ir->mask_keycode = 0xbf;
  329. ir->mask_keyup = 0x40;
  330. ir->polling = 50; /* ms */
  331. break;
  332. case CX88_BOARD_MSI_TVANYWHERE_MASTER:
  333. ir_codes = RC_MAP_MSI_TVANYWHERE;
  334. ir->gpio_addr = MO_GP1_IO;
  335. ir->mask_keycode = 0x1f;
  336. ir->mask_keyup = 0x40;
  337. ir->polling = 1; /* ms */
  338. break;
  339. case CX88_BOARD_AVERTV_303:
  340. case CX88_BOARD_AVERTV_STUDIO_303:
  341. ir_codes = RC_MAP_AVERTV_303;
  342. ir->gpio_addr = MO_GP2_IO;
  343. ir->mask_keycode = 0xfb;
  344. ir->mask_keydown = 0x02;
  345. ir->polling = 50; /* ms */
  346. break;
  347. case CX88_BOARD_OMICOM_SS4_PCI:
  348. case CX88_BOARD_SATTRADE_ST4200:
  349. case CX88_BOARD_TBS_8920:
  350. case CX88_BOARD_TBS_8910:
  351. case CX88_BOARD_PROF_7300:
  352. case CX88_BOARD_PROF_7301:
  353. case CX88_BOARD_PROF_6200:
  354. ir_codes = RC_MAP_TBS_NEC;
  355. ir->sampling = 0xff00; /* address */
  356. break;
  357. case CX88_BOARD_TEVII_S464:
  358. case CX88_BOARD_TEVII_S460:
  359. case CX88_BOARD_TEVII_S420:
  360. ir_codes = RC_MAP_TEVII_NEC;
  361. ir->sampling = 0xff00; /* address */
  362. break;
  363. case CX88_BOARD_DNTV_LIVE_DVB_T_PRO:
  364. ir_codes = RC_MAP_DNTV_LIVE_DVBT_PRO;
  365. ir->sampling = 0xff00; /* address */
  366. break;
  367. case CX88_BOARD_NORWOOD_MICRO:
  368. ir_codes = RC_MAP_NORWOOD;
  369. ir->gpio_addr = MO_GP1_IO;
  370. ir->mask_keycode = 0x0e;
  371. ir->mask_keyup = 0x80;
  372. ir->polling = 50; /* ms */
  373. break;
  374. case CX88_BOARD_NPGTECH_REALTV_TOP10FM:
  375. ir_codes = RC_MAP_NPGTECH;
  376. ir->gpio_addr = MO_GP0_IO;
  377. ir->mask_keycode = 0xfa;
  378. ir->polling = 50; /* ms */
  379. break;
  380. case CX88_BOARD_PINNACLE_PCTV_HD_800i:
  381. ir_codes = RC_MAP_PINNACLE_PCTV_HD;
  382. ir->sampling = 1;
  383. break;
  384. case CX88_BOARD_POWERCOLOR_REAL_ANGEL:
  385. ir_codes = RC_MAP_POWERCOLOR_REAL_ANGEL;
  386. ir->gpio_addr = MO_GP2_IO;
  387. ir->mask_keycode = 0x7e;
  388. ir->polling = 100; /* ms */
  389. break;
  390. case CX88_BOARD_TWINHAN_VP1027_DVBS:
  391. ir_codes = RC_MAP_TWINHAN_VP1027_DVBS;
  392. ir->sampling = 0xff00; /* address */
  393. break;
  394. }
  395. if (!ir_codes) {
  396. err = -ENODEV;
  397. goto err_out_free;
  398. }
  399. /*
  400. * The usage of mask_keycode were very convenient, due to several
  401. * reasons. Among others, the scancode tables were using the scancode
  402. * as the index elements. So, the less bits it was used, the smaller
  403. * the table were stored. After the input changes, the better is to use
  404. * the full scancodes, since it allows replacing the IR remote by
  405. * another one. Unfortunately, there are still some hardware, like
  406. * Pixelview Ultra Pro, where only part of the scancode is sent via
  407. * GPIO. So, there's no way to get the full scancode. Due to that,
  408. * hardware_mask were introduced here: it represents those hardware
  409. * that has such limits.
  410. */
  411. if (hardware_mask && !ir->mask_keycode)
  412. ir->mask_keycode = hardware_mask;
  413. /* init input device */
  414. snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", core->board.name);
  415. snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci));
  416. dev->device_name = ir->name;
  417. dev->input_phys = ir->phys;
  418. dev->input_id.bustype = BUS_PCI;
  419. dev->input_id.version = 1;
  420. if (pci->subsystem_vendor) {
  421. dev->input_id.vendor = pci->subsystem_vendor;
  422. dev->input_id.product = pci->subsystem_device;
  423. } else {
  424. dev->input_id.vendor = pci->vendor;
  425. dev->input_id.product = pci->device;
  426. }
  427. dev->dev.parent = &pci->dev;
  428. dev->map_name = ir_codes;
  429. dev->driver_name = MODULE_NAME;
  430. dev->priv = core;
  431. dev->open = cx88_ir_open;
  432. dev->close = cx88_ir_close;
  433. dev->scancode_mask = hardware_mask;
  434. if (ir->sampling) {
  435. dev->timeout = 10 * 1000 * 1000; /* 10 ms */
  436. } else {
  437. dev->driver_type = RC_DRIVER_SCANCODE;
  438. dev->allowed_protocols = rc_proto;
  439. }
  440. ir->core = core;
  441. core->ir = ir;
  442. /* all done */
  443. err = rc_register_device(dev);
  444. if (err)
  445. goto err_out_free;
  446. return 0;
  447. err_out_free:
  448. rc_free_device(dev);
  449. core->ir = NULL;
  450. kfree(ir);
  451. return err;
  452. }
  453. int cx88_ir_fini(struct cx88_core *core)
  454. {
  455. struct cx88_IR *ir = core->ir;
  456. /* skip detach on non attached boards */
  457. if (!ir)
  458. return 0;
  459. cx88_ir_stop(core);
  460. rc_unregister_device(ir->dev);
  461. kfree(ir);
  462. /* done */
  463. core->ir = NULL;
  464. return 0;
  465. }
  466. /* ---------------------------------------------------------------------- */
  467. void cx88_ir_irq(struct cx88_core *core)
  468. {
  469. struct cx88_IR *ir = core->ir;
  470. u32 samples;
  471. unsigned int todo, bits;
  472. struct ir_raw_event ev;
  473. if (!ir || !ir->sampling)
  474. return;
  475. /*
  476. * Samples are stored in a 32 bit register, oldest sample in
  477. * the msb. A set bit represents space and an unset bit
  478. * represents a pulse.
  479. */
  480. samples = cx_read(MO_SAMPLE_IO);
  481. if (samples == 0xff && ir->dev->idle)
  482. return;
  483. init_ir_raw_event(&ev);
  484. for (todo = 32; todo > 0; todo -= bits) {
  485. ev.pulse = samples & 0x80000000 ? false : true;
  486. bits = min(todo, 32U - fls(ev.pulse ? samples : ~samples));
  487. ev.duration = (bits * (NSEC_PER_SEC / 1000)) / ir_samplerate;
  488. ir_raw_event_store_with_filter(ir->dev, &ev);
  489. samples <<= bits;
  490. }
  491. ir_raw_event_handle(ir->dev);
  492. }
  493. static int get_key_pvr2000(struct IR_i2c *ir, enum rc_proto *protocol,
  494. u32 *scancode, u8 *toggle)
  495. {
  496. int flags, code;
  497. /* poll IR chip */
  498. flags = i2c_smbus_read_byte_data(ir->c, 0x10);
  499. if (flags < 0) {
  500. dprintk("read error\n");
  501. return 0;
  502. }
  503. /* key pressed ? */
  504. if (0 == (flags & 0x80))
  505. return 0;
  506. /* read actual key code */
  507. code = i2c_smbus_read_byte_data(ir->c, 0x00);
  508. if (code < 0) {
  509. dprintk("read error\n");
  510. return 0;
  511. }
  512. dprintk("IR Key/Flags: (0x%02x/0x%02x)\n",
  513. code & 0xff, flags & 0xff);
  514. *protocol = RC_PROTO_UNKNOWN;
  515. *scancode = code & 0xff;
  516. *toggle = 0;
  517. return 1;
  518. }
  519. void cx88_i2c_init_ir(struct cx88_core *core)
  520. {
  521. struct i2c_board_info info;
  522. static const unsigned short default_addr_list[] = {
  523. 0x18, 0x6b, 0x71,
  524. I2C_CLIENT_END
  525. };
  526. static const unsigned short pvr2000_addr_list[] = {
  527. 0x18, 0x1a,
  528. I2C_CLIENT_END
  529. };
  530. const unsigned short *addr_list = default_addr_list;
  531. const unsigned short *addrp;
  532. /* Instantiate the IR receiver device, if present */
  533. if (core->i2c_rc != 0)
  534. return;
  535. memset(&info, 0, sizeof(struct i2c_board_info));
  536. strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
  537. switch (core->boardnr) {
  538. case CX88_BOARD_LEADTEK_PVR2000:
  539. addr_list = pvr2000_addr_list;
  540. core->init_data.name = "cx88 Leadtek PVR 2000 remote";
  541. core->init_data.type = RC_PROTO_BIT_UNKNOWN;
  542. core->init_data.get_key = get_key_pvr2000;
  543. core->init_data.ir_codes = RC_MAP_EMPTY;
  544. break;
  545. }
  546. /*
  547. * We can't call i2c_new_probed_device() because it uses
  548. * quick writes for probing and at least some RC receiver
  549. * devices only reply to reads.
  550. * Also, Hauppauge XVR needs to be specified, as address 0x71
  551. * conflicts with another remote type used with saa7134
  552. */
  553. for (addrp = addr_list; *addrp != I2C_CLIENT_END; addrp++) {
  554. info.platform_data = NULL;
  555. memset(&core->init_data, 0, sizeof(core->init_data));
  556. if (*addrp == 0x71) {
  557. /* Hauppauge Z8F0811 */
  558. strlcpy(info.type, "ir_z8f0811_haup", I2C_NAME_SIZE);
  559. core->init_data.name = core->board.name;
  560. core->init_data.ir_codes = RC_MAP_HAUPPAUGE;
  561. core->init_data.type = RC_PROTO_BIT_RC5 |
  562. RC_PROTO_BIT_RC6_MCE | RC_PROTO_BIT_RC6_6A_32;
  563. core->init_data.internal_get_key_func = IR_KBD_GET_KEY_HAUP_XVR;
  564. info.platform_data = &core->init_data;
  565. }
  566. if (i2c_smbus_xfer(&core->i2c_adap, *addrp, 0,
  567. I2C_SMBUS_READ, 0,
  568. I2C_SMBUS_QUICK, NULL) >= 0) {
  569. info.addr = *addrp;
  570. i2c_new_device(&core->i2c_adap, &info);
  571. break;
  572. }
  573. }
  574. }
  575. /* ---------------------------------------------------------------------- */
  576. MODULE_AUTHOR("Gerd Knorr, Pavel Machek, Chris Pascoe");
  577. MODULE_DESCRIPTION("input driver for cx88 GPIO-based IR remote controls");
  578. MODULE_LICENSE("GPL");