em28xx-input.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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 i2cdprintk(fmt, arg...) \
  34. if (ir_debug) { \
  35. printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
  36. }
  37. #define dprintk(fmt, arg...) \
  38. if (ir_debug) { \
  39. printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
  40. }
  41. /**********************************************************
  42. Polling structure used by em28xx IR's
  43. **********************************************************/
  44. struct em28xx_ir_poll_result {
  45. unsigned int toggle_bit:1;
  46. unsigned int read_count:7;
  47. u8 rc_address;
  48. u8 rc_data[4]; /* 1 byte on em2860/2880, 4 on em2874 */
  49. };
  50. struct em28xx_IR {
  51. struct em28xx *dev;
  52. struct rc_dev *rc;
  53. char name[32];
  54. char phys[32];
  55. /* poll external decoder */
  56. int polling;
  57. struct delayed_work work;
  58. unsigned int full_code:1;
  59. unsigned int last_readcount;
  60. int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *);
  61. };
  62. /**********************************************************
  63. I2C IR based get keycodes - should be used with ir-kbd-i2c
  64. **********************************************************/
  65. static int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  66. {
  67. unsigned char b;
  68. /* poll IR chip */
  69. if (1 != i2c_master_recv(ir->c, &b, 1)) {
  70. i2cdprintk("read error\n");
  71. return -EIO;
  72. }
  73. /* it seems that 0xFE indicates that a button is still hold
  74. down, while 0xff indicates that no button is hold
  75. down. 0xfe sequences are sometimes interrupted by 0xFF */
  76. i2cdprintk("key %02x\n", b);
  77. if (b == 0xff)
  78. return 0;
  79. if (b == 0xfe)
  80. /* keep old data */
  81. return 1;
  82. *ir_key = b;
  83. *ir_raw = b;
  84. return 1;
  85. }
  86. static int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
  87. {
  88. unsigned char buf[2];
  89. u16 code;
  90. int size;
  91. /* poll IR chip */
  92. size = i2c_master_recv(ir->c, buf, sizeof(buf));
  93. if (size != 2)
  94. return -EIO;
  95. /* Does eliminate repeated parity code */
  96. if (buf[1] == 0xff)
  97. return 0;
  98. ir->old = buf[1];
  99. /*
  100. * Rearranges bits to the right order.
  101. * The bit order were determined experimentally by using
  102. * The original Hauppauge Grey IR and another RC5 that uses addr=0x08
  103. * The RC5 code has 14 bits, but we've experimentally determined
  104. * the meaning for only 11 bits.
  105. * So, the code translation is not complete. Yet, it is enough to
  106. * work with the provided RC5 IR.
  107. */
  108. code =
  109. ((buf[0] & 0x01) ? 0x0020 : 0) | /* 0010 0000 */
  110. ((buf[0] & 0x02) ? 0x0010 : 0) | /* 0001 0000 */
  111. ((buf[0] & 0x04) ? 0x0008 : 0) | /* 0000 1000 */
  112. ((buf[0] & 0x08) ? 0x0004 : 0) | /* 0000 0100 */
  113. ((buf[0] & 0x10) ? 0x0002 : 0) | /* 0000 0010 */
  114. ((buf[0] & 0x20) ? 0x0001 : 0) | /* 0000 0001 */
  115. ((buf[1] & 0x08) ? 0x1000 : 0) | /* 0001 0000 */
  116. ((buf[1] & 0x10) ? 0x0800 : 0) | /* 0000 1000 */
  117. ((buf[1] & 0x20) ? 0x0400 : 0) | /* 0000 0100 */
  118. ((buf[1] & 0x40) ? 0x0200 : 0) | /* 0000 0010 */
  119. ((buf[1] & 0x80) ? 0x0100 : 0); /* 0000 0001 */
  120. i2cdprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x%02x)\n",
  121. code, buf[1], buf[0]);
  122. /* return key */
  123. *ir_key = code;
  124. *ir_raw = code;
  125. return 1;
  126. }
  127. static int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
  128. u32 *ir_raw)
  129. {
  130. unsigned char buf[3];
  131. /* poll IR chip */
  132. if (3 != i2c_master_recv(ir->c, buf, 3)) {
  133. i2cdprintk("read error\n");
  134. return -EIO;
  135. }
  136. i2cdprintk("key %02x\n", buf[2]&0x3f);
  137. if (buf[0] != 0x00)
  138. return 0;
  139. *ir_key = buf[2]&0x3f;
  140. *ir_raw = buf[2]&0x3f;
  141. return 1;
  142. }
  143. static int em28xx_get_key_winfast_usbii_deluxe(struct IR_i2c *ir, u32 *ir_key,
  144. u32 *ir_raw)
  145. {
  146. unsigned char subaddr, keydetect, key;
  147. struct i2c_msg msg[] = { { .addr = ir->c->addr, .flags = 0, .buf = &subaddr, .len = 1},
  148. { .addr = ir->c->addr, .flags = I2C_M_RD, .buf = &keydetect, .len = 1} };
  149. subaddr = 0x10;
  150. if (2 != i2c_transfer(ir->c->adapter, msg, 2)) {
  151. i2cdprintk("read error\n");
  152. return -EIO;
  153. }
  154. if (keydetect == 0x00)
  155. return 0;
  156. subaddr = 0x00;
  157. msg[1].buf = &key;
  158. if (2 != i2c_transfer(ir->c->adapter, msg, 2)) {
  159. i2cdprintk("read error\n");
  160. return -EIO;
  161. }
  162. if (key == 0x00)
  163. return 0;
  164. *ir_key = key;
  165. *ir_raw = key;
  166. return 1;
  167. }
  168. /**********************************************************
  169. Poll based get keycode functions
  170. **********************************************************/
  171. /* This is for the em2860/em2880 */
  172. static int default_polling_getkey(struct em28xx_IR *ir,
  173. struct em28xx_ir_poll_result *poll_result)
  174. {
  175. struct em28xx *dev = ir->dev;
  176. int rc;
  177. u8 msg[3] = { 0, 0, 0 };
  178. /* Read key toggle, brand, and key code
  179. on registers 0x45, 0x46 and 0x47
  180. */
  181. rc = dev->em28xx_read_reg_req_len(dev, 0, EM28XX_R45_IR,
  182. msg, sizeof(msg));
  183. if (rc < 0)
  184. return rc;
  185. /* Infrared toggle (Reg 0x45[7]) */
  186. poll_result->toggle_bit = (msg[0] >> 7);
  187. /* Infrared read count (Reg 0x45[6:0] */
  188. poll_result->read_count = (msg[0] & 0x7f);
  189. /* Remote Control Address (Reg 0x46) */
  190. poll_result->rc_address = msg[1];
  191. /* Remote Control Data (Reg 0x47) */
  192. poll_result->rc_data[0] = msg[2];
  193. return 0;
  194. }
  195. static int em2874_polling_getkey(struct em28xx_IR *ir,
  196. struct em28xx_ir_poll_result *poll_result)
  197. {
  198. struct em28xx *dev = ir->dev;
  199. int rc;
  200. u8 msg[5] = { 0, 0, 0, 0, 0 };
  201. /* Read key toggle, brand, and key code
  202. on registers 0x51-55
  203. */
  204. rc = dev->em28xx_read_reg_req_len(dev, 0, EM2874_R51_IR,
  205. msg, sizeof(msg));
  206. if (rc < 0)
  207. return rc;
  208. /* Infrared toggle (Reg 0x51[7]) */
  209. poll_result->toggle_bit = (msg[0] >> 7);
  210. /* Infrared read count (Reg 0x51[6:0] */
  211. poll_result->read_count = (msg[0] & 0x7f);
  212. /* Remote Control Address (Reg 0x52) */
  213. poll_result->rc_address = msg[1];
  214. /* Remote Control Data (Reg 0x53-55) */
  215. poll_result->rc_data[0] = msg[2];
  216. poll_result->rc_data[1] = msg[3];
  217. poll_result->rc_data[2] = msg[4];
  218. return 0;
  219. }
  220. /**********************************************************
  221. Polling code for em28xx
  222. **********************************************************/
  223. static void em28xx_ir_handle_key(struct em28xx_IR *ir)
  224. {
  225. int result;
  226. struct em28xx_ir_poll_result poll_result;
  227. /* read the registers containing the IR status */
  228. result = ir->get_key(ir, &poll_result);
  229. if (unlikely(result < 0)) {
  230. dprintk("ir->get_key() failed %d\n", result);
  231. return;
  232. }
  233. if (unlikely(poll_result.read_count != ir->last_readcount)) {
  234. dprintk("%s: toggle: %d, count: %d, key 0x%02x%02x\n", __func__,
  235. poll_result.toggle_bit, poll_result.read_count,
  236. poll_result.rc_address, poll_result.rc_data[0]);
  237. if (ir->full_code)
  238. rc_keydown(ir->rc,
  239. poll_result.rc_address << 8 |
  240. poll_result.rc_data[0],
  241. poll_result.toggle_bit);
  242. else
  243. rc_keydown(ir->rc,
  244. poll_result.rc_data[0],
  245. poll_result.toggle_bit);
  246. if (ir->dev->chip_id == CHIP_ID_EM2874 ||
  247. ir->dev->chip_id == CHIP_ID_EM2884)
  248. /* The em2874 clears the readcount field every time the
  249. register is read. The em2860/2880 datasheet says that it
  250. is supposed to clear the readcount, but it doesn't. So with
  251. the em2874, we are looking for a non-zero read count as
  252. opposed to a readcount that is incrementing */
  253. ir->last_readcount = 0;
  254. else
  255. ir->last_readcount = poll_result.read_count;
  256. }
  257. }
  258. static void em28xx_ir_work(struct work_struct *work)
  259. {
  260. struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work);
  261. em28xx_ir_handle_key(ir);
  262. schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
  263. }
  264. static int em28xx_ir_start(struct rc_dev *rc)
  265. {
  266. struct em28xx_IR *ir = rc->priv;
  267. INIT_DELAYED_WORK(&ir->work, em28xx_ir_work);
  268. schedule_delayed_work(&ir->work, 0);
  269. return 0;
  270. }
  271. static void em28xx_ir_stop(struct rc_dev *rc)
  272. {
  273. struct em28xx_IR *ir = rc->priv;
  274. cancel_delayed_work_sync(&ir->work);
  275. }
  276. static int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type)
  277. {
  278. int rc = 0;
  279. struct em28xx_IR *ir = rc_dev->priv;
  280. struct em28xx *dev = ir->dev;
  281. u8 ir_config = EM2874_IR_RC5;
  282. /* Adjust xclk based o IR table for RC5/NEC tables */
  283. if (*rc_type & RC_BIT_RC5) {
  284. dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
  285. ir->full_code = 1;
  286. *rc_type = RC_BIT_RC5;
  287. } else if (*rc_type & RC_BIT_NEC) {
  288. dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
  289. ir_config = EM2874_IR_NEC;
  290. ir->full_code = 1;
  291. *rc_type = RC_BIT_NEC;
  292. } else if (*rc_type != RC_BIT_UNKNOWN)
  293. rc = -EINVAL;
  294. em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
  295. EM28XX_XCLK_IR_RC5_MODE);
  296. /* Setup the proper handler based on the chip */
  297. switch (dev->chip_id) {
  298. case CHIP_ID_EM2860:
  299. case CHIP_ID_EM2883:
  300. ir->get_key = default_polling_getkey;
  301. break;
  302. case CHIP_ID_EM2884:
  303. case CHIP_ID_EM2874:
  304. case CHIP_ID_EM28174:
  305. ir->get_key = em2874_polling_getkey;
  306. em28xx_write_regs(dev, EM2874_R50_IR_CONFIG, &ir_config, 1);
  307. break;
  308. default:
  309. printk("Unrecognized em28xx chip id 0x%02x: IR not supported\n",
  310. dev->chip_id);
  311. rc = -EINVAL;
  312. }
  313. return rc;
  314. }
  315. static void em28xx_register_i2c_ir(struct em28xx *dev)
  316. {
  317. /* Leadtek winfast tv USBII deluxe can find a non working IR-device */
  318. /* at address 0x18, so if that address is needed for another board in */
  319. /* the future, please put it after 0x1f. */
  320. struct i2c_board_info info;
  321. const unsigned short addr_list[] = {
  322. 0x1f, 0x30, 0x47, I2C_CLIENT_END
  323. };
  324. memset(&info, 0, sizeof(struct i2c_board_info));
  325. memset(&dev->init_data, 0, sizeof(dev->init_data));
  326. strlcpy(info.type, "ir_video", I2C_NAME_SIZE);
  327. /* detect & configure */
  328. switch (dev->model) {
  329. case EM2800_BOARD_TERRATEC_CINERGY_200:
  330. case EM2820_BOARD_TERRATEC_CINERGY_250:
  331. dev->init_data.ir_codes = RC_MAP_EM_TERRATEC;
  332. dev->init_data.get_key = em28xx_get_key_terratec;
  333. dev->init_data.name = "i2c IR (EM28XX Terratec)";
  334. break;
  335. case EM2820_BOARD_PINNACLE_USB_2:
  336. dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY;
  337. dev->init_data.get_key = em28xx_get_key_pinnacle_usb_grey;
  338. dev->init_data.name = "i2c IR (EM28XX Pinnacle PCTV)";
  339. break;
  340. case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
  341. dev->init_data.ir_codes = RC_MAP_HAUPPAUGE;
  342. dev->init_data.get_key = em28xx_get_key_em_haup;
  343. dev->init_data.name = "i2c IR (EM2840 Hauppauge)";
  344. break;
  345. case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
  346. dev->init_data.ir_codes = RC_MAP_WINFAST_USBII_DELUXE;
  347. dev->init_data.get_key = em28xx_get_key_winfast_usbii_deluxe;
  348. dev->init_data.name = "i2c IR (EM2820 Winfast TV USBII Deluxe)";
  349. break;
  350. }
  351. if (dev->init_data.name)
  352. info.platform_data = &dev->init_data;
  353. i2c_new_probed_device(&dev->i2c_adap, &info, addr_list, NULL);
  354. }
  355. /**********************************************************
  356. Handle Webcam snapshot button
  357. **********************************************************/
  358. static void em28xx_query_sbutton(struct work_struct *work)
  359. {
  360. /* Poll the register and see if the button is depressed */
  361. struct em28xx *dev =
  362. container_of(work, struct em28xx, sbutton_query_work.work);
  363. int ret;
  364. ret = em28xx_read_reg(dev, EM28XX_R0C_USBSUSP);
  365. if (ret & EM28XX_R0C_USBSUSP_SNAPSHOT) {
  366. u8 cleared;
  367. /* Button is depressed, clear the register */
  368. cleared = ((u8) ret) & ~EM28XX_R0C_USBSUSP_SNAPSHOT;
  369. em28xx_write_regs(dev, EM28XX_R0C_USBSUSP, &cleared, 1);
  370. /* Not emulate the keypress */
  371. input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY,
  372. 1);
  373. /* Now unpress the key */
  374. input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY,
  375. 0);
  376. }
  377. /* Schedule next poll */
  378. schedule_delayed_work(&dev->sbutton_query_work,
  379. msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL));
  380. }
  381. static void em28xx_register_snapshot_button(struct em28xx *dev)
  382. {
  383. struct input_dev *input_dev;
  384. int err;
  385. em28xx_info("Registering snapshot button...\n");
  386. input_dev = input_allocate_device();
  387. if (!input_dev) {
  388. em28xx_errdev("input_allocate_device failed\n");
  389. return;
  390. }
  391. usb_make_path(dev->udev, dev->snapshot_button_path,
  392. sizeof(dev->snapshot_button_path));
  393. strlcat(dev->snapshot_button_path, "/sbutton",
  394. sizeof(dev->snapshot_button_path));
  395. INIT_DELAYED_WORK(&dev->sbutton_query_work, em28xx_query_sbutton);
  396. input_dev->name = "em28xx snapshot button";
  397. input_dev->phys = dev->snapshot_button_path;
  398. input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
  399. set_bit(EM28XX_SNAPSHOT_KEY, input_dev->keybit);
  400. input_dev->keycodesize = 0;
  401. input_dev->keycodemax = 0;
  402. input_dev->id.bustype = BUS_USB;
  403. input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
  404. input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
  405. input_dev->id.version = 1;
  406. input_dev->dev.parent = &dev->udev->dev;
  407. err = input_register_device(input_dev);
  408. if (err) {
  409. em28xx_errdev("input_register_device failed\n");
  410. input_free_device(input_dev);
  411. return;
  412. }
  413. dev->sbutton_input_dev = input_dev;
  414. schedule_delayed_work(&dev->sbutton_query_work,
  415. msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL));
  416. return;
  417. }
  418. static void em28xx_deregister_snapshot_button(struct em28xx *dev)
  419. {
  420. if (dev->sbutton_input_dev != NULL) {
  421. em28xx_info("Deregistering snapshot button\n");
  422. cancel_delayed_work_sync(&dev->sbutton_query_work);
  423. input_unregister_device(dev->sbutton_input_dev);
  424. dev->sbutton_input_dev = NULL;
  425. }
  426. return;
  427. }
  428. static int em28xx_ir_init(struct em28xx *dev)
  429. {
  430. struct em28xx_IR *ir;
  431. struct rc_dev *rc;
  432. int err = -ENOMEM;
  433. u64 rc_type;
  434. if (dev->board.ir_codes == NULL) {
  435. /* No remote control support */
  436. em28xx_warn("Remote control support is not available for "
  437. "this card.\n");
  438. return 0;
  439. }
  440. ir = kzalloc(sizeof(*ir), GFP_KERNEL);
  441. rc = rc_allocate_device();
  442. if (!ir || !rc)
  443. goto err_out_free;
  444. /* record handles to ourself */
  445. ir->dev = dev;
  446. dev->ir = ir;
  447. ir->rc = rc;
  448. /*
  449. * em2874 supports more protocols. For now, let's just announce
  450. * the two protocols that were already tested
  451. */
  452. rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC;
  453. rc->priv = ir;
  454. rc->change_protocol = em28xx_ir_change_protocol;
  455. rc->open = em28xx_ir_start;
  456. rc->close = em28xx_ir_stop;
  457. /* By default, keep protocol field untouched */
  458. rc_type = RC_BIT_UNKNOWN;
  459. err = em28xx_ir_change_protocol(rc, &rc_type);
  460. if (err)
  461. goto err_out_free;
  462. /* This is how often we ask the chip for IR information */
  463. ir->polling = 100; /* ms */
  464. /* init input device */
  465. snprintf(ir->name, sizeof(ir->name), "em28xx IR (%s)",
  466. dev->name);
  467. usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
  468. strlcat(ir->phys, "/input0", sizeof(ir->phys));
  469. rc->input_name = ir->name;
  470. rc->input_phys = ir->phys;
  471. rc->input_id.bustype = BUS_USB;
  472. rc->input_id.version = 1;
  473. rc->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
  474. rc->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
  475. rc->dev.parent = &dev->udev->dev;
  476. rc->map_name = dev->board.ir_codes;
  477. rc->driver_name = MODULE_NAME;
  478. /* all done */
  479. err = rc_register_device(rc);
  480. if (err)
  481. goto err_out_stop;
  482. em28xx_register_i2c_ir(dev);
  483. #if defined(CONFIG_MODULES) && defined(MODULE)
  484. if (dev->board.has_ir_i2c)
  485. request_module("ir-kbd-i2c");
  486. #endif
  487. if (dev->board.has_snapshot_button)
  488. em28xx_register_snapshot_button(dev);
  489. return 0;
  490. err_out_stop:
  491. dev->ir = NULL;
  492. err_out_free:
  493. rc_free_device(rc);
  494. kfree(ir);
  495. return err;
  496. }
  497. static int em28xx_ir_fini(struct em28xx *dev)
  498. {
  499. struct em28xx_IR *ir = dev->ir;
  500. em28xx_deregister_snapshot_button(dev);
  501. /* skip detach on non attached boards */
  502. if (!ir)
  503. return 0;
  504. if (ir->rc)
  505. rc_unregister_device(ir->rc);
  506. /* done */
  507. kfree(ir);
  508. dev->ir = NULL;
  509. return 0;
  510. }
  511. static struct em28xx_ops rc_ops = {
  512. .id = EM28XX_RC,
  513. .name = "Em28xx Input Extension",
  514. .init = em28xx_ir_init,
  515. .fini = em28xx_ir_fini,
  516. };
  517. static int __init em28xx_rc_register(void)
  518. {
  519. return em28xx_register_extension(&rc_ops);
  520. }
  521. static void __exit em28xx_rc_unregister(void)
  522. {
  523. em28xx_unregister_extension(&rc_ops);
  524. }
  525. MODULE_LICENSE("GPL");
  526. MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
  527. MODULE_DESCRIPTION("Em28xx Input driver");
  528. module_init(em28xx_rc_register);
  529. module_exit(em28xx_rc_unregister);