1 // SPDX-License-Identifier: GPL-2.0+
3 // handle em28xx IR remotes via linux kernel input layer.
5 // Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
6 // Markus Rechberger <mrechberger@gmail.com>
7 // Mauro Carvalho Chehab <mchehab@kernel.org>
8 // Sascha Sommer <saschasommer@freenet.de>
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.
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.
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/delay.h>
25 #include <linux/interrupt.h>
26 #include <linux/usb.h>
27 #include <linux/slab.h>
28 #include <linux/bitrev.h>
30 #define EM28XX_SNAPSHOT_KEY KEY_CAMERA
31 #define EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL 500 /* [ms] */
32 #define EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL 100 /* [ms] */
34 static unsigned int ir_debug;
35 module_param(ir_debug, int, 0644);
36 MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
38 #define MODULE_NAME "em28xx"
40 #define dprintk(fmt, arg...) do { \
42 dev_printk(KERN_DEBUG, &ir->dev->intf->dev, \
43 "input: %s: " fmt, __func__, ## arg); \
47 * Polling structure used by em28xx IR's
50 struct em28xx_ir_poll_result {
51 unsigned int toggle_bit:1;
52 unsigned int read_count:7;
54 enum rc_proto protocol;
66 struct delayed_work work;
67 unsigned int full_code:1;
68 unsigned int last_readcount;
71 struct i2c_client *i2c_client;
73 int (*get_key_i2c)(struct i2c_client *ir, enum rc_proto *protocol,
75 int (*get_key)(struct em28xx_IR *ir, struct em28xx_ir_poll_result *r);
79 * I2C IR based get keycodes - should be used with ir-kbd-i2c
82 static int em28xx_get_key_terratec(struct i2c_client *i2c_dev,
83 enum rc_proto *protocol, u32 *scancode)
89 rc = i2c_master_recv(i2c_dev, &b, 1);
97 * it seems that 0xFE indicates that a button is still hold
98 * down, while 0xff indicates that no button is hold down.
108 *protocol = RC_PROTO_UNKNOWN;
113 static int em28xx_get_key_em_haup(struct i2c_client *i2c_dev,
114 enum rc_proto *protocol, u32 *scancode)
116 unsigned char buf[2];
120 size = i2c_master_recv(i2c_dev, buf, sizeof(buf));
125 /* Does eliminate repeated parity code */
130 * Rearranges bits to the right order.
131 * The bit order were determined experimentally by using
132 * The original Hauppauge Grey IR and another RC5 that uses addr=0x08
133 * The RC5 code has 14 bits, but we've experimentally determined
134 * the meaning for only 11 bits.
135 * So, the code translation is not complete. Yet, it is enough to
136 * work with the provided RC5 IR.
138 *protocol = RC_PROTO_RC5;
139 *scancode = (bitrev8(buf[1]) & 0x1f) << 8 | bitrev8(buf[0]) >> 2;
143 static int em28xx_get_key_pinnacle_usb_grey(struct i2c_client *i2c_dev,
144 enum rc_proto *protocol,
147 unsigned char buf[3];
151 if (i2c_master_recv(i2c_dev, buf, 3) != 3)
157 *protocol = RC_PROTO_UNKNOWN;
158 *scancode = buf[2] & 0x3f;
162 static int em28xx_get_key_winfast_usbii_deluxe(struct i2c_client *i2c_dev,
163 enum rc_proto *protocol,
166 unsigned char subaddr, keydetect, key;
168 struct i2c_msg msg[] = {
170 .addr = i2c_dev->addr,
172 .buf = &subaddr, .len = 1
174 .addr = i2c_dev->addr,
182 if (i2c_transfer(i2c_dev->adapter, msg, 2) != 2)
184 if (keydetect == 0x00)
189 if (i2c_transfer(i2c_dev->adapter, msg, 2) != 2)
194 *protocol = RC_PROTO_UNKNOWN;
200 * Poll based get keycode functions
203 /* This is for the em2860/em2880 */
204 static int default_polling_getkey(struct em28xx_IR *ir,
205 struct em28xx_ir_poll_result *poll_result)
207 struct em28xx *dev = ir->dev;
209 u8 msg[3] = { 0, 0, 0 };
212 * Read key toggle, brand, and key code
213 * on registers 0x45, 0x46 and 0x47
215 rc = dev->em28xx_read_reg_req_len(dev, 0, EM28XX_R45_IR,
220 /* Infrared toggle (Reg 0x45[7]) */
221 poll_result->toggle_bit = (msg[0] >> 7);
223 /* Infrared read count (Reg 0x45[6:0] */
224 poll_result->read_count = (msg[0] & 0x7f);
226 /* Remote Control Address/Data (Regs 0x46/0x47) */
227 switch (ir->rc_proto) {
228 case RC_PROTO_BIT_RC5:
229 poll_result->protocol = RC_PROTO_RC5;
230 poll_result->scancode = RC_SCANCODE_RC5(msg[1], msg[2]);
233 case RC_PROTO_BIT_NEC:
234 poll_result->protocol = RC_PROTO_NEC;
235 poll_result->scancode = RC_SCANCODE_NEC(msg[1], msg[2]);
239 poll_result->protocol = RC_PROTO_UNKNOWN;
240 poll_result->scancode = msg[1] << 8 | msg[2];
247 static int em2874_polling_getkey(struct em28xx_IR *ir,
248 struct em28xx_ir_poll_result *poll_result)
250 struct em28xx *dev = ir->dev;
252 u8 msg[5] = { 0, 0, 0, 0, 0 };
255 * Read key toggle, brand, and key code
256 * on registers 0x51-55
258 rc = dev->em28xx_read_reg_req_len(dev, 0, EM2874_R51_IR,
263 /* Infrared toggle (Reg 0x51[7]) */
264 poll_result->toggle_bit = (msg[0] >> 7);
266 /* Infrared read count (Reg 0x51[6:0] */
267 poll_result->read_count = (msg[0] & 0x7f);
270 * Remote Control Address (Reg 0x52)
271 * Remote Control Data (Reg 0x53-0x55)
273 switch (ir->rc_proto) {
274 case RC_PROTO_BIT_RC5:
275 poll_result->protocol = RC_PROTO_RC5;
276 poll_result->scancode = RC_SCANCODE_RC5(msg[1], msg[2]);
279 case RC_PROTO_BIT_NEC:
280 poll_result->scancode = msg[1] << 8 | msg[2];
281 if ((msg[3] ^ msg[4]) != 0xff) { /* 32 bits NEC */
282 poll_result->protocol = RC_PROTO_NEC32;
283 poll_result->scancode = RC_SCANCODE_NEC32((msg[1] << 24) |
287 } else if ((msg[1] ^ msg[2]) != 0xff) { /* 24 bits NEC */
288 poll_result->protocol = RC_PROTO_NECX;
289 poll_result->scancode = RC_SCANCODE_NECX(msg[1] << 8 |
291 } else { /* Normal NEC */
292 poll_result->protocol = RC_PROTO_NEC;
293 poll_result->scancode = RC_SCANCODE_NEC(msg[1], msg[3]);
297 case RC_PROTO_BIT_RC6_0:
298 poll_result->protocol = RC_PROTO_RC6_0;
299 poll_result->scancode = RC_SCANCODE_RC6_0(msg[1], msg[2]);
303 poll_result->protocol = RC_PROTO_UNKNOWN;
304 poll_result->scancode = (msg[1] << 24) | (msg[2] << 16) |
305 (msg[3] << 8) | msg[4];
313 * Polling code for em28xx
316 static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir)
319 enum rc_proto protocol;
322 rc = ir->get_key_i2c(ir->i2c_client, &protocol, &scancode);
324 dprintk("ir->get_key_i2c() failed: %d\n", rc);
329 dprintk("%s: proto = 0x%04x, scancode = 0x%04x\n",
330 __func__, protocol, scancode);
331 rc_keydown(ir->rc, protocol, scancode, 0);
336 static void em28xx_ir_handle_key(struct em28xx_IR *ir)
339 struct em28xx_ir_poll_result poll_result;
341 /* read the registers containing the IR status */
342 result = ir->get_key(ir, &poll_result);
343 if (unlikely(result < 0)) {
344 dprintk("ir->get_key() failed: %d\n", result);
348 if (unlikely(poll_result.read_count != ir->last_readcount)) {
349 dprintk("%s: toggle: %d, count: %d, key 0x%04x\n", __func__,
350 poll_result.toggle_bit, poll_result.read_count,
351 poll_result.scancode);
354 poll_result.protocol,
355 poll_result.scancode,
356 poll_result.toggle_bit);
360 poll_result.scancode & 0xff,
361 poll_result.toggle_bit);
363 if (ir->dev->chip_id == CHIP_ID_EM2874 ||
364 ir->dev->chip_id == CHIP_ID_EM2884)
366 * The em2874 clears the readcount field every time the
367 * register is read. The em2860/2880 datasheet says
368 * that it is supposed to clear the readcount, but it
369 * doesn't. So with the em2874, we are looking for a
370 * non-zero read count as opposed to a readcount
371 * that is incrementing
373 ir->last_readcount = 0;
375 ir->last_readcount = poll_result.read_count;
379 static void em28xx_ir_work(struct work_struct *work)
381 struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work);
383 if (ir->i2c_client) /* external i2c device */
384 em28xx_i2c_ir_handle_key(ir);
385 else /* internal device */
386 em28xx_ir_handle_key(ir);
387 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
390 static int em28xx_ir_start(struct rc_dev *rc)
392 struct em28xx_IR *ir = rc->priv;
394 INIT_DELAYED_WORK(&ir->work, em28xx_ir_work);
395 schedule_delayed_work(&ir->work, 0);
400 static void em28xx_ir_stop(struct rc_dev *rc)
402 struct em28xx_IR *ir = rc->priv;
404 cancel_delayed_work_sync(&ir->work);
407 static int em2860_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_proto)
409 struct em28xx_IR *ir = rc_dev->priv;
410 struct em28xx *dev = ir->dev;
412 /* Adjust xclk based on IR table for RC5/NEC tables */
413 if (*rc_proto & RC_PROTO_BIT_RC5) {
414 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
416 *rc_proto = RC_PROTO_BIT_RC5;
417 } else if (*rc_proto & RC_PROTO_BIT_NEC) {
418 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
420 *rc_proto = RC_PROTO_BIT_NEC;
421 } else if (*rc_proto & RC_PROTO_BIT_UNKNOWN) {
422 *rc_proto = RC_PROTO_BIT_UNKNOWN;
424 *rc_proto = ir->rc_proto;
427 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
428 EM28XX_XCLK_IR_RC5_MODE);
430 ir->rc_proto = *rc_proto;
435 static int em2874_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_proto)
437 struct em28xx_IR *ir = rc_dev->priv;
438 struct em28xx *dev = ir->dev;
439 u8 ir_config = EM2874_IR_RC5;
441 /* Adjust xclk and set type based on IR table for RC5/NEC/RC6 tables */
442 if (*rc_proto & RC_PROTO_BIT_RC5) {
443 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
445 *rc_proto = RC_PROTO_BIT_RC5;
446 } else if (*rc_proto & RC_PROTO_BIT_NEC) {
447 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
448 ir_config = EM2874_IR_NEC | EM2874_IR_NEC_NO_PARITY;
450 *rc_proto = RC_PROTO_BIT_NEC;
451 } else if (*rc_proto & RC_PROTO_BIT_RC6_0) {
452 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
453 ir_config = EM2874_IR_RC6_MODE_0;
455 *rc_proto = RC_PROTO_BIT_RC6_0;
456 } else if (*rc_proto & RC_PROTO_BIT_UNKNOWN) {
457 *rc_proto = RC_PROTO_BIT_UNKNOWN;
459 *rc_proto = ir->rc_proto;
462 em28xx_write_regs(dev, EM2874_R50_IR_CONFIG, &ir_config, 1);
463 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
464 EM28XX_XCLK_IR_RC5_MODE);
466 ir->rc_proto = *rc_proto;
471 static int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_proto)
473 struct em28xx_IR *ir = rc_dev->priv;
474 struct em28xx *dev = ir->dev;
476 /* Setup the proper handler based on the chip */
477 switch (dev->chip_id) {
480 return em2860_ir_change_protocol(rc_dev, rc_proto);
483 case CHIP_ID_EM28174:
484 case CHIP_ID_EM28178:
485 return em2874_ir_change_protocol(rc_dev, rc_proto);
487 dev_err(&ir->dev->intf->dev,
488 "Unrecognized em28xx chip id 0x%02x: IR not supported\n",
494 static int em28xx_probe_i2c_ir(struct em28xx *dev)
498 * Leadtek winfast tv USBII deluxe can find a non working IR-device
499 * at address 0x18, so if that address is needed for another board in
500 * the future, please put it after 0x1f.
502 const unsigned short addr_list[] = {
503 0x1f, 0x30, 0x47, I2C_CLIENT_END
506 while (addr_list[i] != I2C_CLIENT_END) {
507 if (i2c_probe_func_quick_read(&dev->i2c_adap[dev->def_i2c_bus],
520 static void em28xx_query_buttons(struct work_struct *work)
523 container_of(work, struct em28xx, buttons_query_work.work);
526 bool is_pressed, was_pressed;
527 const struct em28xx_led *led;
529 /* Poll and evaluate all addresses */
530 for (i = 0; i < dev->num_button_polling_addresses; i++) {
531 /* Read value from register */
532 regval = em28xx_read_reg(dev, dev->button_polling_addresses[i]);
535 /* Check states of the buttons and act */
537 while (dev->board.buttons[j].role >= 0 &&
538 dev->board.buttons[j].role < EM28XX_NUM_BUTTON_ROLES) {
539 const struct em28xx_button *button;
541 button = &dev->board.buttons[j];
543 /* Check if button uses the current address */
544 if (button->reg_r != dev->button_polling_addresses[i]) {
548 /* Determine if button is and was pressed last time */
549 is_pressed = regval & button->mask;
550 was_pressed = dev->button_polling_last_values[i]
552 if (button->inverted) {
553 is_pressed = !is_pressed;
554 was_pressed = !was_pressed;
556 /* Clear button state (if needed) */
557 if (is_pressed && button->reg_clearing)
558 em28xx_write_reg(dev, button->reg_clearing,
559 (~regval & button->mask)
560 | (regval & ~button->mask));
561 /* Handle button state */
562 if (!is_pressed || was_pressed) {
566 switch (button->role) {
567 case EM28XX_BUTTON_SNAPSHOT:
568 /* Emulate the keypress */
569 input_report_key(dev->sbutton_input_dev,
570 EM28XX_SNAPSHOT_KEY, 1);
571 /* Unpress the key */
572 input_report_key(dev->sbutton_input_dev,
573 EM28XX_SNAPSHOT_KEY, 0);
575 case EM28XX_BUTTON_ILLUMINATION:
576 led = em28xx_find_led(dev,
577 EM28XX_LED_ILLUMINATION);
578 /* Switch illumination LED on/off */
580 em28xx_toggle_reg_bits(dev,
585 WARN_ONCE(1, "BUG: unhandled button role.");
590 /* Save current value for comparison during the next polling */
591 dev->button_polling_last_values[i] = regval;
593 /* Schedule next poll */
594 schedule_delayed_work(&dev->buttons_query_work,
595 msecs_to_jiffies(dev->button_polling_interval));
598 static int em28xx_register_snapshot_button(struct em28xx *dev)
600 struct usb_device *udev = interface_to_usbdev(dev->intf);
601 struct input_dev *input_dev;
604 dev_info(&dev->intf->dev, "Registering snapshot button...\n");
605 input_dev = input_allocate_device();
609 usb_make_path(udev, dev->snapshot_button_path,
610 sizeof(dev->snapshot_button_path));
611 strlcat(dev->snapshot_button_path, "/sbutton",
612 sizeof(dev->snapshot_button_path));
614 input_dev->name = "em28xx snapshot button";
615 input_dev->phys = dev->snapshot_button_path;
616 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
617 set_bit(EM28XX_SNAPSHOT_KEY, input_dev->keybit);
618 input_dev->keycodesize = 0;
619 input_dev->keycodemax = 0;
620 input_dev->id.bustype = BUS_USB;
621 input_dev->id.vendor = le16_to_cpu(udev->descriptor.idVendor);
622 input_dev->id.product = le16_to_cpu(udev->descriptor.idProduct);
623 input_dev->id.version = 1;
624 input_dev->dev.parent = &dev->intf->dev;
626 err = input_register_device(input_dev);
628 dev_err(&dev->intf->dev, "input_register_device failed\n");
629 input_free_device(input_dev);
633 dev->sbutton_input_dev = input_dev;
637 static void em28xx_init_buttons(struct em28xx *dev)
640 bool addr_new = false;
642 dev->button_polling_interval = EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL;
643 while (dev->board.buttons[i].role >= 0 &&
644 dev->board.buttons[i].role < EM28XX_NUM_BUTTON_ROLES) {
645 const struct em28xx_button *button = &dev->board.buttons[i];
647 /* Check if polling address is already on the list */
649 for (j = 0; j < dev->num_button_polling_addresses; j++) {
650 if (button->reg_r == dev->button_polling_addresses[j]) {
655 /* Check if max. number of polling addresses is exceeded */
656 if (addr_new && dev->num_button_polling_addresses
657 >= EM28XX_NUM_BUTTON_ADDRESSES_MAX) {
658 WARN_ONCE(1, "BUG: maximum number of button polling addresses exceeded.");
661 /* Button role specific checks and actions */
662 if (button->role == EM28XX_BUTTON_SNAPSHOT) {
663 /* Register input device */
664 if (em28xx_register_snapshot_button(dev) < 0)
666 } else if (button->role == EM28XX_BUTTON_ILLUMINATION) {
668 if (!em28xx_find_led(dev, EM28XX_LED_ILLUMINATION)) {
669 dev_err(&dev->intf->dev,
670 "BUG: illumination button defined, but no illumination LED.\n");
674 /* Add read address to list of polling addresses */
676 unsigned int index = dev->num_button_polling_addresses;
678 dev->button_polling_addresses[index] = button->reg_r;
679 dev->num_button_polling_addresses++;
681 /* Reduce polling interval if necessary */
682 if (!button->reg_clearing)
683 dev->button_polling_interval =
684 EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL;
691 if (dev->num_button_polling_addresses) {
692 memset(dev->button_polling_last_values, 0,
693 EM28XX_NUM_BUTTON_ADDRESSES_MAX);
694 schedule_delayed_work(&dev->buttons_query_work,
695 msecs_to_jiffies(dev->button_polling_interval));
699 static void em28xx_shutdown_buttons(struct em28xx *dev)
702 cancel_delayed_work_sync(&dev->buttons_query_work);
703 /* Clear polling addresses list */
704 dev->num_button_polling_addresses = 0;
705 /* Deregister input devices */
706 if (dev->sbutton_input_dev) {
707 dev_info(&dev->intf->dev, "Deregistering snapshot button\n");
708 input_unregister_device(dev->sbutton_input_dev);
709 dev->sbutton_input_dev = NULL;
713 static int em28xx_ir_init(struct em28xx *dev)
715 struct usb_device *udev = interface_to_usbdev(dev->intf);
716 struct em28xx_IR *ir;
720 u16 i2c_rc_dev_addr = 0;
722 if (dev->is_audio_only) {
723 /* Shouldn't initialize IR for this interface */
728 INIT_DELAYED_WORK(&dev->buttons_query_work, em28xx_query_buttons);
730 if (dev->board.buttons)
731 em28xx_init_buttons(dev);
733 if (dev->board.has_ir_i2c) {
734 i2c_rc_dev_addr = em28xx_probe_i2c_ir(dev);
735 if (!i2c_rc_dev_addr) {
736 dev->board.has_ir_i2c = 0;
737 dev_warn(&dev->intf->dev,
738 "No i2c IR remote control device found.\n");
744 if (!dev->board.ir_codes && !dev->board.has_ir_i2c) {
745 /* No remote control support */
746 dev_warn(&dev->intf->dev,
747 "Remote control support is not available for this card.\n");
751 dev_info(&dev->intf->dev, "Registering input extension\n");
753 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
756 rc = rc_allocate_device(RC_DRIVER_SCANCODE);
760 /* record handles to ourself */
766 rc->open = em28xx_ir_start;
767 rc->close = em28xx_ir_stop;
769 if (dev->board.has_ir_i2c) { /* external i2c device */
770 switch (dev->model) {
771 case EM2800_BOARD_TERRATEC_CINERGY_200:
772 case EM2820_BOARD_TERRATEC_CINERGY_250:
773 rc->map_name = RC_MAP_EM_TERRATEC;
774 ir->get_key_i2c = em28xx_get_key_terratec;
776 case EM2820_BOARD_PINNACLE_USB_2:
777 rc->map_name = RC_MAP_PINNACLE_GREY;
778 ir->get_key_i2c = em28xx_get_key_pinnacle_usb_grey;
780 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
781 rc->map_name = RC_MAP_HAUPPAUGE;
782 ir->get_key_i2c = em28xx_get_key_em_haup;
783 rc->allowed_protocols = RC_PROTO_BIT_RC5;
785 case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
786 rc->map_name = RC_MAP_WINFAST_USBII_DELUXE;
787 ir->get_key_i2c = em28xx_get_key_winfast_usbii_deluxe;
794 ir->i2c_client = kzalloc(sizeof(*ir->i2c_client), GFP_KERNEL);
797 ir->i2c_client->adapter = &ir->dev->i2c_adap[dev->def_i2c_bus];
798 ir->i2c_client->addr = i2c_rc_dev_addr;
799 ir->i2c_client->flags = 0;
800 /* NOTE: all other fields of i2c_client are unused */
801 } else { /* internal device */
802 switch (dev->chip_id) {
805 rc->allowed_protocols = RC_PROTO_BIT_RC5 |
807 ir->get_key = default_polling_getkey;
811 case CHIP_ID_EM28174:
812 case CHIP_ID_EM28178:
813 ir->get_key = em2874_polling_getkey;
814 rc->allowed_protocols = RC_PROTO_BIT_RC5 |
815 RC_PROTO_BIT_NEC | RC_PROTO_BIT_NECX |
816 RC_PROTO_BIT_NEC32 | RC_PROTO_BIT_RC6_0;
823 rc->change_protocol = em28xx_ir_change_protocol;
824 rc->map_name = dev->board.ir_codes;
826 /* By default, keep protocol field untouched */
827 rc_proto = RC_PROTO_BIT_UNKNOWN;
828 err = em28xx_ir_change_protocol(rc, &rc_proto);
833 /* This is how often we ask the chip for IR information */
834 ir->polling = 100; /* ms */
836 /* init input device */
837 snprintf(ir->name, sizeof(ir->name), "%s IR",
838 dev_name(&dev->intf->dev));
840 usb_make_path(udev, ir->phys, sizeof(ir->phys));
841 strlcat(ir->phys, "/input0", sizeof(ir->phys));
843 rc->device_name = ir->name;
844 rc->input_phys = ir->phys;
845 rc->input_id.bustype = BUS_USB;
846 rc->input_id.version = 1;
847 rc->input_id.vendor = le16_to_cpu(udev->descriptor.idVendor);
848 rc->input_id.product = le16_to_cpu(udev->descriptor.idProduct);
849 rc->dev.parent = &dev->intf->dev;
850 rc->driver_name = MODULE_NAME;
853 err = rc_register_device(rc);
857 dev_info(&dev->intf->dev, "Input extension successfully initialized\n");
862 kfree(ir->i2c_client);
867 em28xx_shutdown_buttons(dev);
871 static int em28xx_ir_fini(struct em28xx *dev)
873 struct em28xx_IR *ir = dev->ir;
875 if (dev->is_audio_only) {
876 /* Shouldn't initialize IR for this interface */
880 dev_info(&dev->intf->dev, "Closing input extension\n");
882 em28xx_shutdown_buttons(dev);
884 /* skip detach on non attached boards */
888 rc_unregister_device(ir->rc);
890 kfree(ir->i2c_client);
897 kref_put(&dev->ref, em28xx_free_device);
902 static int em28xx_ir_suspend(struct em28xx *dev)
904 struct em28xx_IR *ir = dev->ir;
906 if (dev->is_audio_only)
909 dev_info(&dev->intf->dev, "Suspending input extension\n");
911 cancel_delayed_work_sync(&ir->work);
912 cancel_delayed_work_sync(&dev->buttons_query_work);
914 * is canceling delayed work sufficient or does the rc event
915 * kthread needs stopping? kthread is stopped in
916 * ir_raw_event_unregister()
921 static int em28xx_ir_resume(struct em28xx *dev)
923 struct em28xx_IR *ir = dev->ir;
925 if (dev->is_audio_only)
928 dev_info(&dev->intf->dev, "Resuming input extension\n");
930 * if suspend calls ir_raw_event_unregister(), the should call
931 * ir_raw_event_register()
934 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
935 if (dev->num_button_polling_addresses)
936 schedule_delayed_work(&dev->buttons_query_work,
937 msecs_to_jiffies(dev->button_polling_interval));
941 static struct em28xx_ops rc_ops = {
943 .name = "Em28xx Input Extension",
944 .init = em28xx_ir_init,
945 .fini = em28xx_ir_fini,
946 .suspend = em28xx_ir_suspend,
947 .resume = em28xx_ir_resume,
950 static int __init em28xx_rc_register(void)
952 return em28xx_register_extension(&rc_ops);
955 static void __exit em28xx_rc_unregister(void)
957 em28xx_unregister_extension(&rc_ops);
960 MODULE_LICENSE("GPL v2");
961 MODULE_AUTHOR("Mauro Carvalho Chehab");
962 MODULE_DESCRIPTION(DRIVER_DESC " - input interface");
963 MODULE_VERSION(EM28XX_VERSION);
965 module_init(em28xx_rc_register);
966 module_exit(em28xx_rc_unregister);