em28xx-input.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. /*
  2. handle em28xx IR remotes via linux kernel input layer.
  3. Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
  4. Markus Rechberger <mrechberger@gmail.com>
  5. Mauro Carvalho Chehab <mchehab@infradead.org>
  6. Sascha Sommer <saschasommer@freenet.de>
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/delay.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/usb.h>
  24. #include <linux/slab.h>
  25. #include "em28xx.h"
  26. #define EM28XX_SNAPSHOT_KEY KEY_CAMERA
  27. #define EM28XX_SBUTTON_QUERY_INTERVAL 500
  28. #define EM28XX_R0C_USBSUSP_SNAPSHOT 0x20
  29. static unsigned int ir_debug;
  30. module_param(ir_debug, int, 0644);
  31. MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
  32. #define MODULE_NAME "em28xx"
  33. #define dprintk(fmt, arg...) \
  34. if (ir_debug) { \
  35. printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
  36. }
  37. /**********************************************************
  38. Polling structure used by em28xx IR's
  39. **********************************************************/
  40. struct em28xx_ir_poll_result {
  41. unsigned int toggle_bit:1;
  42. unsigned int read_count:7;
  43. u32 scancode;
  44. };
  45. struct em28xx_IR {
  46. struct em28xx *dev;
  47. struct rc_dev *rc;
  48. char name[32];
  49. char phys[32];
  50. /* poll decoder */
  51. int polling;
  52. struct delayed_work work;
  53. unsigned int full_code:1;
  54. unsigned int last_readcount;
  55. u64 rc_type;
  56. /* i2c slave address of external device (if used) */
  57. u16 i2c_dev_addr;
  58. int (*get_key_i2c)(struct i2c_client *, u32 *);
  59. int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *);
  60. };
  61. /**********************************************************
  62. I2C IR based get keycodes - should be used with ir-kbd-i2c
  63. **********************************************************/
  64. static int em28xx_get_key_terratec(struct i2c_client *i2c_dev, u32 *ir_key)
  65. {
  66. unsigned char b;
  67. /* poll IR chip */
  68. if (1 != i2c_master_recv(i2c_dev, &b, 1))
  69. return -EIO;
  70. /* it seems that 0xFE indicates that a button is still hold
  71. down, while 0xff indicates that no button is hold down. */
  72. if (b == 0xff)
  73. return 0;
  74. if (b == 0xfe)
  75. /* keep old data */
  76. return 1;
  77. *ir_key = b;
  78. return 1;
  79. }
  80. static int em28xx_get_key_em_haup(struct i2c_client *i2c_dev, u32 *ir_key)
  81. {
  82. unsigned char buf[2];
  83. u16 code;
  84. int size;
  85. /* poll IR chip */
  86. size = i2c_master_recv(i2c_dev, buf, sizeof(buf));
  87. if (size != 2)
  88. return -EIO;
  89. /* Does eliminate repeated parity code */
  90. if (buf[1] == 0xff)
  91. return 0;
  92. /*
  93. * Rearranges bits to the right order.
  94. * The bit order were determined experimentally by using
  95. * The original Hauppauge Grey IR and another RC5 that uses addr=0x08
  96. * The RC5 code has 14 bits, but we've experimentally determined
  97. * the meaning for only 11 bits.
  98. * So, the code translation is not complete. Yet, it is enough to
  99. * work with the provided RC5 IR.
  100. */
  101. code =
  102. ((buf[0] & 0x01) ? 0x0020 : 0) | /* 0010 0000 */
  103. ((buf[0] & 0x02) ? 0x0010 : 0) | /* 0001 0000 */
  104. ((buf[0] & 0x04) ? 0x0008 : 0) | /* 0000 1000 */
  105. ((buf[0] & 0x08) ? 0x0004 : 0) | /* 0000 0100 */
  106. ((buf[0] & 0x10) ? 0x0002 : 0) | /* 0000 0010 */
  107. ((buf[0] & 0x20) ? 0x0001 : 0) | /* 0000 0001 */
  108. ((buf[1] & 0x08) ? 0x1000 : 0) | /* 0001 0000 */
  109. ((buf[1] & 0x10) ? 0x0800 : 0) | /* 0000 1000 */
  110. ((buf[1] & 0x20) ? 0x0400 : 0) | /* 0000 0100 */
  111. ((buf[1] & 0x40) ? 0x0200 : 0) | /* 0000 0010 */
  112. ((buf[1] & 0x80) ? 0x0100 : 0); /* 0000 0001 */
  113. /* return key */
  114. *ir_key = code;
  115. return 1;
  116. }
  117. static int em28xx_get_key_pinnacle_usb_grey(struct i2c_client *i2c_dev,
  118. u32 *ir_key)
  119. {
  120. unsigned char buf[3];
  121. /* poll IR chip */
  122. if (3 != i2c_master_recv(i2c_dev, buf, 3))
  123. return -EIO;
  124. if (buf[0] != 0x00)
  125. return 0;
  126. *ir_key = buf[2]&0x3f;
  127. return 1;
  128. }
  129. static int em28xx_get_key_winfast_usbii_deluxe(struct i2c_client *i2c_dev,
  130. u32 *ir_key)
  131. {
  132. unsigned char subaddr, keydetect, key;
  133. struct i2c_msg msg[] = { { .addr = i2c_dev->addr, .flags = 0, .buf = &subaddr, .len = 1},
  134. { .addr = i2c_dev->addr, .flags = I2C_M_RD, .buf = &keydetect, .len = 1} };
  135. subaddr = 0x10;
  136. if (2 != i2c_transfer(i2c_dev->adapter, msg, 2))
  137. return -EIO;
  138. if (keydetect == 0x00)
  139. return 0;
  140. subaddr = 0x00;
  141. msg[1].buf = &key;
  142. if (2 != i2c_transfer(i2c_dev->adapter, msg, 2))
  143. return -EIO;
  144. if (key == 0x00)
  145. return 0;
  146. *ir_key = key;
  147. return 1;
  148. }
  149. /**********************************************************
  150. Poll based get keycode functions
  151. **********************************************************/
  152. /* This is for the em2860/em2880 */
  153. static int default_polling_getkey(struct em28xx_IR *ir,
  154. struct em28xx_ir_poll_result *poll_result)
  155. {
  156. struct em28xx *dev = ir->dev;
  157. int rc;
  158. u8 msg[3] = { 0, 0, 0 };
  159. /* Read key toggle, brand, and key code
  160. on registers 0x45, 0x46 and 0x47
  161. */
  162. rc = dev->em28xx_read_reg_req_len(dev, 0, EM28XX_R45_IR,
  163. msg, sizeof(msg));
  164. if (rc < 0)
  165. return rc;
  166. /* Infrared toggle (Reg 0x45[7]) */
  167. poll_result->toggle_bit = (msg[0] >> 7);
  168. /* Infrared read count (Reg 0x45[6:0] */
  169. poll_result->read_count = (msg[0] & 0x7f);
  170. /* Remote Control Address/Data (Regs 0x46/0x47) */
  171. poll_result->scancode = msg[1] << 8 | msg[2];
  172. return 0;
  173. }
  174. static int em2874_polling_getkey(struct em28xx_IR *ir,
  175. struct em28xx_ir_poll_result *poll_result)
  176. {
  177. struct em28xx *dev = ir->dev;
  178. int rc;
  179. u8 msg[5] = { 0, 0, 0, 0, 0 };
  180. /* Read key toggle, brand, and key code
  181. on registers 0x51-55
  182. */
  183. rc = dev->em28xx_read_reg_req_len(dev, 0, EM2874_R51_IR,
  184. msg, sizeof(msg));
  185. if (rc < 0)
  186. return rc;
  187. /* Infrared toggle (Reg 0x51[7]) */
  188. poll_result->toggle_bit = (msg[0] >> 7);
  189. /* Infrared read count (Reg 0x51[6:0] */
  190. poll_result->read_count = (msg[0] & 0x7f);
  191. /*
  192. * Remote Control Address (Reg 0x52)
  193. * Remote Control Data (Reg 0x53-0x55)
  194. */
  195. switch (ir->rc_type) {
  196. case RC_BIT_RC5:
  197. poll_result->scancode = msg[1] << 8 | msg[2];
  198. break;
  199. case RC_BIT_NEC:
  200. if ((msg[3] ^ msg[4]) != 0xff) /* 32 bits NEC */
  201. poll_result->scancode = (msg[1] << 24) |
  202. (msg[2] << 16) |
  203. (msg[3] << 8) |
  204. msg[4];
  205. else if ((msg[1] ^ msg[2]) != 0xff) /* 24 bits NEC */
  206. poll_result->scancode = (msg[1] << 16) |
  207. (msg[2] << 8) |
  208. msg[3];
  209. else /* Normal NEC */
  210. poll_result->scancode = msg[1] << 8 | msg[3];
  211. break;
  212. case RC_BIT_RC6_0:
  213. poll_result->scancode = msg[1] << 8 | msg[2];
  214. break;
  215. default:
  216. poll_result->scancode = (msg[1] << 24) | (msg[2] << 16) |
  217. (msg[3] << 8) | msg[4];
  218. break;
  219. }
  220. return 0;
  221. }
  222. /**********************************************************
  223. Polling code for em28xx
  224. **********************************************************/
  225. static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir)
  226. {
  227. static u32 ir_key;
  228. int rc;
  229. struct i2c_client client;
  230. client.adapter = &ir->dev->i2c_adap;
  231. client.addr = ir->i2c_dev_addr;
  232. rc = ir->get_key_i2c(&client, &ir_key);
  233. if (rc < 0) {
  234. dprintk("ir->get_key_i2c() failed: %d\n", rc);
  235. return rc;
  236. }
  237. if (rc) {
  238. dprintk("%s: keycode = 0x%04x\n", __func__, ir_key);
  239. rc_keydown(ir->rc, ir_key, 0);
  240. }
  241. return 0;
  242. }
  243. static void em28xx_ir_handle_key(struct em28xx_IR *ir)
  244. {
  245. int result;
  246. struct em28xx_ir_poll_result poll_result;
  247. /* read the registers containing the IR status */
  248. result = ir->get_key(ir, &poll_result);
  249. if (unlikely(result < 0)) {
  250. dprintk("ir->get_key() failed: %d\n", result);
  251. return;
  252. }
  253. if (unlikely(poll_result.read_count != ir->last_readcount)) {
  254. dprintk("%s: toggle: %d, count: %d, key 0x%04x\n", __func__,
  255. poll_result.toggle_bit, poll_result.read_count,
  256. poll_result.scancode);
  257. if (ir->full_code)
  258. rc_keydown(ir->rc,
  259. poll_result.scancode,
  260. poll_result.toggle_bit);
  261. else
  262. rc_keydown(ir->rc,
  263. poll_result.scancode & 0xff,
  264. poll_result.toggle_bit);
  265. if (ir->dev->chip_id == CHIP_ID_EM2874 ||
  266. ir->dev->chip_id == CHIP_ID_EM2884)
  267. /* The em2874 clears the readcount field every time the
  268. register is read. The em2860/2880 datasheet says that it
  269. is supposed to clear the readcount, but it doesn't. So with
  270. the em2874, we are looking for a non-zero read count as
  271. opposed to a readcount that is incrementing */
  272. ir->last_readcount = 0;
  273. else
  274. ir->last_readcount = poll_result.read_count;
  275. }
  276. }
  277. static void em28xx_ir_work(struct work_struct *work)
  278. {
  279. struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work);
  280. if (ir->i2c_dev_addr) /* external i2c device */
  281. em28xx_i2c_ir_handle_key(ir);
  282. else /* internal device */
  283. em28xx_ir_handle_key(ir);
  284. schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
  285. }
  286. static int em28xx_ir_start(struct rc_dev *rc)
  287. {
  288. struct em28xx_IR *ir = rc->priv;
  289. INIT_DELAYED_WORK(&ir->work, em28xx_ir_work);
  290. schedule_delayed_work(&ir->work, 0);
  291. return 0;
  292. }
  293. static void em28xx_ir_stop(struct rc_dev *rc)
  294. {
  295. struct em28xx_IR *ir = rc->priv;
  296. cancel_delayed_work_sync(&ir->work);
  297. }
  298. static int em2860_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type)
  299. {
  300. struct em28xx_IR *ir = rc_dev->priv;
  301. struct em28xx *dev = ir->dev;
  302. /* Adjust xclk based on IR table for RC5/NEC tables */
  303. if (*rc_type & RC_BIT_RC5) {
  304. dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
  305. ir->full_code = 1;
  306. *rc_type = RC_BIT_RC5;
  307. } else if (*rc_type & RC_BIT_NEC) {
  308. dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
  309. ir->full_code = 1;
  310. *rc_type = RC_BIT_NEC;
  311. } else if (*rc_type & RC_BIT_UNKNOWN) {
  312. *rc_type = RC_BIT_UNKNOWN;
  313. } else {
  314. *rc_type = ir->rc_type;
  315. return -EINVAL;
  316. }
  317. em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
  318. EM28XX_XCLK_IR_RC5_MODE);
  319. ir->rc_type = *rc_type;
  320. return 0;
  321. }
  322. static int em2874_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type)
  323. {
  324. struct em28xx_IR *ir = rc_dev->priv;
  325. struct em28xx *dev = ir->dev;
  326. u8 ir_config = EM2874_IR_RC5;
  327. /* Adjust xclk and set type based on IR table for RC5/NEC/RC6 tables */
  328. if (*rc_type & RC_BIT_RC5) {
  329. dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
  330. ir->full_code = 1;
  331. *rc_type = RC_BIT_RC5;
  332. } else if (*rc_type & RC_BIT_NEC) {
  333. dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
  334. ir_config = EM2874_IR_NEC | EM2874_IR_NEC_NO_PARITY;
  335. ir->full_code = 1;
  336. *rc_type = RC_BIT_NEC;
  337. } else if (*rc_type & RC_BIT_RC6_0) {
  338. dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
  339. ir_config = EM2874_IR_RC6_MODE_0;
  340. ir->full_code = 1;
  341. *rc_type = RC_BIT_RC6_0;
  342. } else if (*rc_type & RC_BIT_UNKNOWN) {
  343. *rc_type = RC_BIT_UNKNOWN;
  344. } else {
  345. *rc_type = ir->rc_type;
  346. return -EINVAL;
  347. }
  348. em28xx_write_regs(dev, EM2874_R50_IR_CONFIG, &ir_config, 1);
  349. em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
  350. EM28XX_XCLK_IR_RC5_MODE);
  351. ir->rc_type = *rc_type;
  352. return 0;
  353. }
  354. static int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type)
  355. {
  356. struct em28xx_IR *ir = rc_dev->priv;
  357. struct em28xx *dev = ir->dev;
  358. /* Setup the proper handler based on the chip */
  359. switch (dev->chip_id) {
  360. case CHIP_ID_EM2860:
  361. case CHIP_ID_EM2883:
  362. return em2860_ir_change_protocol(rc_dev, rc_type);
  363. case CHIP_ID_EM2884:
  364. case CHIP_ID_EM2874:
  365. case CHIP_ID_EM28174:
  366. return em2874_ir_change_protocol(rc_dev, rc_type);
  367. default:
  368. printk("Unrecognized em28xx chip id 0x%02x: IR not supported\n",
  369. dev->chip_id);
  370. return -EINVAL;
  371. }
  372. }
  373. static int em28xx_probe_i2c_ir(struct em28xx *dev)
  374. {
  375. int i = 0;
  376. /* Leadtek winfast tv USBII deluxe can find a non working IR-device */
  377. /* at address 0x18, so if that address is needed for another board in */
  378. /* the future, please put it after 0x1f. */
  379. const unsigned short addr_list[] = {
  380. 0x1f, 0x30, 0x47, I2C_CLIENT_END
  381. };
  382. while (addr_list[i] != I2C_CLIENT_END) {
  383. if (i2c_probe_func_quick_read(&dev->i2c_adap, addr_list[i]) == 1)
  384. return addr_list[i];
  385. i++;
  386. }
  387. return -ENODEV;
  388. }
  389. /**********************************************************
  390. Handle Webcam snapshot button
  391. **********************************************************/
  392. static void em28xx_query_sbutton(struct work_struct *work)
  393. {
  394. /* Poll the register and see if the button is depressed */
  395. struct em28xx *dev =
  396. container_of(work, struct em28xx, sbutton_query_work.work);
  397. int ret;
  398. ret = em28xx_read_reg(dev, EM28XX_R0C_USBSUSP);
  399. if (ret & EM28XX_R0C_USBSUSP_SNAPSHOT) {
  400. u8 cleared;
  401. /* Button is depressed, clear the register */
  402. cleared = ((u8) ret) & ~EM28XX_R0C_USBSUSP_SNAPSHOT;
  403. em28xx_write_regs(dev, EM28XX_R0C_USBSUSP, &cleared, 1);
  404. /* Not emulate the keypress */
  405. input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY,
  406. 1);
  407. /* Now unpress the key */
  408. input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY,
  409. 0);
  410. }
  411. /* Schedule next poll */
  412. schedule_delayed_work(&dev->sbutton_query_work,
  413. msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL));
  414. }
  415. static void em28xx_register_snapshot_button(struct em28xx *dev)
  416. {
  417. struct input_dev *input_dev;
  418. int err;
  419. em28xx_info("Registering snapshot button...\n");
  420. input_dev = input_allocate_device();
  421. if (!input_dev) {
  422. em28xx_errdev("input_allocate_device failed\n");
  423. return;
  424. }
  425. usb_make_path(dev->udev, dev->snapshot_button_path,
  426. sizeof(dev->snapshot_button_path));
  427. strlcat(dev->snapshot_button_path, "/sbutton",
  428. sizeof(dev->snapshot_button_path));
  429. INIT_DELAYED_WORK(&dev->sbutton_query_work, em28xx_query_sbutton);
  430. input_dev->name = "em28xx snapshot button";
  431. input_dev->phys = dev->snapshot_button_path;
  432. input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
  433. set_bit(EM28XX_SNAPSHOT_KEY, input_dev->keybit);
  434. input_dev->keycodesize = 0;
  435. input_dev->keycodemax = 0;
  436. input_dev->id.bustype = BUS_USB;
  437. input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
  438. input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
  439. input_dev->id.version = 1;
  440. input_dev->dev.parent = &dev->udev->dev;
  441. err = input_register_device(input_dev);
  442. if (err) {
  443. em28xx_errdev("input_register_device failed\n");
  444. input_free_device(input_dev);
  445. return;
  446. }
  447. dev->sbutton_input_dev = input_dev;
  448. schedule_delayed_work(&dev->sbutton_query_work,
  449. msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL));
  450. return;
  451. }
  452. static void em28xx_deregister_snapshot_button(struct em28xx *dev)
  453. {
  454. if (dev->sbutton_input_dev != NULL) {
  455. em28xx_info("Deregistering snapshot button\n");
  456. cancel_delayed_work_sync(&dev->sbutton_query_work);
  457. input_unregister_device(dev->sbutton_input_dev);
  458. dev->sbutton_input_dev = NULL;
  459. }
  460. return;
  461. }
  462. static int em28xx_ir_init(struct em28xx *dev)
  463. {
  464. struct em28xx_IR *ir;
  465. struct rc_dev *rc;
  466. int err = -ENOMEM;
  467. u64 rc_type;
  468. u16 i2c_rc_dev_addr = 0;
  469. if (dev->board.has_snapshot_button)
  470. em28xx_register_snapshot_button(dev);
  471. if (dev->board.has_ir_i2c) {
  472. i2c_rc_dev_addr = em28xx_probe_i2c_ir(dev);
  473. if (!i2c_rc_dev_addr) {
  474. dev->board.has_ir_i2c = 0;
  475. em28xx_warn("No i2c IR remote control device found.\n");
  476. return -ENODEV;
  477. }
  478. }
  479. if (dev->board.ir_codes == NULL && !dev->board.has_ir_i2c) {
  480. /* No remote control support */
  481. em28xx_warn("Remote control support is not available for "
  482. "this card.\n");
  483. return 0;
  484. }
  485. ir = kzalloc(sizeof(*ir), GFP_KERNEL);
  486. rc = rc_allocate_device();
  487. if (!ir || !rc)
  488. goto error;
  489. /* record handles to ourself */
  490. ir->dev = dev;
  491. dev->ir = ir;
  492. ir->rc = rc;
  493. rc->priv = ir;
  494. rc->open = em28xx_ir_start;
  495. rc->close = em28xx_ir_stop;
  496. if (dev->board.has_ir_i2c) { /* external i2c device */
  497. switch (dev->model) {
  498. case EM2800_BOARD_TERRATEC_CINERGY_200:
  499. case EM2820_BOARD_TERRATEC_CINERGY_250:
  500. rc->map_name = RC_MAP_EM_TERRATEC;
  501. ir->get_key_i2c = em28xx_get_key_terratec;
  502. break;
  503. case EM2820_BOARD_PINNACLE_USB_2:
  504. rc->map_name = RC_MAP_PINNACLE_GREY;
  505. ir->get_key_i2c = em28xx_get_key_pinnacle_usb_grey;
  506. break;
  507. case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
  508. rc->map_name = RC_MAP_HAUPPAUGE;
  509. ir->get_key_i2c = em28xx_get_key_em_haup;
  510. rc->allowed_protos = RC_BIT_RC5;
  511. break;
  512. case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
  513. rc->map_name = RC_MAP_WINFAST_USBII_DELUXE;
  514. ir->get_key_i2c = em28xx_get_key_winfast_usbii_deluxe;
  515. break;
  516. default:
  517. err = -ENODEV;
  518. goto error;
  519. }
  520. ir->i2c_dev_addr = i2c_rc_dev_addr;
  521. } else { /* internal device */
  522. switch (dev->chip_id) {
  523. case CHIP_ID_EM2860:
  524. case CHIP_ID_EM2883:
  525. rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC;
  526. ir->get_key = default_polling_getkey;
  527. break;
  528. case CHIP_ID_EM2884:
  529. case CHIP_ID_EM2874:
  530. case CHIP_ID_EM28174:
  531. ir->get_key = em2874_polling_getkey;
  532. rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC |
  533. RC_BIT_RC6_0;
  534. break;
  535. default:
  536. err = -ENODEV;
  537. goto error;
  538. }
  539. rc->change_protocol = em28xx_ir_change_protocol;
  540. rc->map_name = dev->board.ir_codes;
  541. /* By default, keep protocol field untouched */
  542. rc_type = RC_BIT_UNKNOWN;
  543. err = em28xx_ir_change_protocol(rc, &rc_type);
  544. if (err)
  545. goto error;
  546. }
  547. /* This is how often we ask the chip for IR information */
  548. ir->polling = 100; /* ms */
  549. /* init input device */
  550. snprintf(ir->name, sizeof(ir->name), "em28xx IR (%s)", dev->name);
  551. usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
  552. strlcat(ir->phys, "/input0", sizeof(ir->phys));
  553. rc->input_name = ir->name;
  554. rc->input_phys = ir->phys;
  555. rc->input_id.bustype = BUS_USB;
  556. rc->input_id.version = 1;
  557. rc->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
  558. rc->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
  559. rc->dev.parent = &dev->udev->dev;
  560. rc->driver_name = MODULE_NAME;
  561. /* all done */
  562. err = rc_register_device(rc);
  563. if (err)
  564. goto error;
  565. return 0;
  566. error:
  567. dev->ir = NULL;
  568. rc_free_device(rc);
  569. kfree(ir);
  570. return err;
  571. }
  572. static int em28xx_ir_fini(struct em28xx *dev)
  573. {
  574. struct em28xx_IR *ir = dev->ir;
  575. em28xx_deregister_snapshot_button(dev);
  576. /* skip detach on non attached boards */
  577. if (!ir)
  578. return 0;
  579. if (ir->rc)
  580. rc_unregister_device(ir->rc);
  581. /* done */
  582. kfree(ir);
  583. dev->ir = NULL;
  584. return 0;
  585. }
  586. static struct em28xx_ops rc_ops = {
  587. .id = EM28XX_RC,
  588. .name = "Em28xx Input Extension",
  589. .init = em28xx_ir_init,
  590. .fini = em28xx_ir_fini,
  591. };
  592. static int __init em28xx_rc_register(void)
  593. {
  594. return em28xx_register_extension(&rc_ops);
  595. }
  596. static void __exit em28xx_rc_unregister(void)
  597. {
  598. em28xx_unregister_extension(&rc_ops);
  599. }
  600. MODULE_LICENSE("GPL");
  601. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  602. MODULE_DESCRIPTION("Em28xx Input driver");
  603. module_init(em28xx_rc_register);
  604. module_exit(em28xx_rc_unregister);