cx88-input.c 17 KB

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