cx88-input.c 17 KB

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