1 // SPDX-License-Identifier: GPL-2.0+
3 // handle em28xx IR remotes via linux kernel input layer.
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/usb/input.h>
28 #include <linux/slab.h>
29 #include <linux/bitrev.h>
31 #define EM28XX_SNAPSHOT_KEY KEY_CAMERA
32 #define EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL 500 /* [ms] */
33 #define EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL 100 /* [ms] */
35 static unsigned int ir_debug;
36 module_param(ir_debug, int, 0644);
37 MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
39 #define MODULE_NAME "em28xx"
41 #define dprintk(fmt, arg...) do { \
43 dev_printk(KERN_DEBUG, &ir->dev->intf->dev, \
44 "input: %s: " fmt, __func__, ## arg); \
48 * Polling structure used by em28xx IR's
51 struct em28xx_ir_poll_result {
52 unsigned int toggle_bit:1;
53 unsigned int read_count:7;
55 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 = ir_nec_bytes_to_scancode(msg[1], msg[2], msg[3], msg[4],
281 &poll_result->protocol);
284 case RC_PROTO_BIT_RC6_0:
285 poll_result->protocol = RC_PROTO_RC6_0;
286 poll_result->scancode = RC_SCANCODE_RC6_0(msg[1], msg[2]);
290 poll_result->protocol = RC_PROTO_UNKNOWN;
291 poll_result->scancode = (msg[1] << 24) | (msg[2] << 16) |
292 (msg[3] << 8) | msg[4];
300 * Polling code for em28xx
303 static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir)
306 enum rc_proto protocol;
309 rc = ir->get_key_i2c(ir->i2c_client, &protocol, &scancode);
311 dprintk("ir->get_key_i2c() failed: %d\n", rc);
316 dprintk("%s: proto = 0x%04x, scancode = 0x%04x\n",
317 __func__, protocol, scancode);
318 rc_keydown(ir->rc, protocol, scancode, 0);
323 static void em28xx_ir_handle_key(struct em28xx_IR *ir)
326 struct em28xx_ir_poll_result poll_result;
328 /* read the registers containing the IR status */
329 result = ir->get_key(ir, &poll_result);
330 if (unlikely(result < 0)) {
331 dprintk("ir->get_key() failed: %d\n", result);
335 if (unlikely(poll_result.read_count != ir->last_readcount)) {
336 dprintk("%s: toggle: %d, count: %d, key 0x%04x\n", __func__,
337 poll_result.toggle_bit, poll_result.read_count,
338 poll_result.scancode);
341 poll_result.protocol,
342 poll_result.scancode,
343 poll_result.toggle_bit);
347 poll_result.scancode & 0xff,
348 poll_result.toggle_bit);
350 if (ir->dev->chip_id == CHIP_ID_EM2874 ||
351 ir->dev->chip_id == CHIP_ID_EM2884)
353 * The em2874 clears the readcount field every time the
354 * register is read. The em2860/2880 datasheet says
355 * that it is supposed to clear the readcount, but it
356 * doesn't. So with the em2874, we are looking for a
357 * non-zero read count as opposed to a readcount
358 * that is incrementing
360 ir->last_readcount = 0;
362 ir->last_readcount = poll_result.read_count;
366 static void em28xx_ir_work(struct work_struct *work)
368 struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work);
370 if (ir->i2c_client) /* external i2c device */
371 em28xx_i2c_ir_handle_key(ir);
372 else /* internal device */
373 em28xx_ir_handle_key(ir);
374 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
377 static int em28xx_ir_start(struct rc_dev *rc)
379 struct em28xx_IR *ir = rc->priv;
381 INIT_DELAYED_WORK(&ir->work, em28xx_ir_work);
382 schedule_delayed_work(&ir->work, 0);
387 static void em28xx_ir_stop(struct rc_dev *rc)
389 struct em28xx_IR *ir = rc->priv;
391 cancel_delayed_work_sync(&ir->work);
394 static int em2860_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_proto)
396 struct em28xx_IR *ir = rc_dev->priv;
397 struct em28xx *dev = ir->dev;
399 /* Adjust xclk based on IR table for RC5/NEC tables */
400 if (*rc_proto & RC_PROTO_BIT_RC5) {
401 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
403 *rc_proto = RC_PROTO_BIT_RC5;
404 } else if (*rc_proto & RC_PROTO_BIT_NEC) {
405 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
407 *rc_proto = RC_PROTO_BIT_NEC;
408 } else if (*rc_proto & RC_PROTO_BIT_UNKNOWN) {
409 *rc_proto = RC_PROTO_BIT_UNKNOWN;
411 *rc_proto = ir->rc_proto;
414 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
415 EM28XX_XCLK_IR_RC5_MODE);
417 ir->rc_proto = *rc_proto;
422 static int em2874_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_proto)
424 struct em28xx_IR *ir = rc_dev->priv;
425 struct em28xx *dev = ir->dev;
426 u8 ir_config = EM2874_IR_RC5;
428 /* Adjust xclk and set type based on IR table for RC5/NEC/RC6 tables */
429 if (*rc_proto & RC_PROTO_BIT_RC5) {
430 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
432 *rc_proto = RC_PROTO_BIT_RC5;
433 } else if (*rc_proto & RC_PROTO_BIT_NEC) {
434 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
435 ir_config = EM2874_IR_NEC | EM2874_IR_NEC_NO_PARITY;
437 *rc_proto = RC_PROTO_BIT_NEC;
438 } else if (*rc_proto & RC_PROTO_BIT_RC6_0) {
439 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
440 ir_config = EM2874_IR_RC6_MODE_0;
442 *rc_proto = RC_PROTO_BIT_RC6_0;
443 } else if (*rc_proto & RC_PROTO_BIT_UNKNOWN) {
444 *rc_proto = RC_PROTO_BIT_UNKNOWN;
446 *rc_proto = ir->rc_proto;
449 em28xx_write_regs(dev, EM2874_R50_IR_CONFIG, &ir_config, 1);
450 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
451 EM28XX_XCLK_IR_RC5_MODE);
453 ir->rc_proto = *rc_proto;
458 static int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_proto)
460 struct em28xx_IR *ir = rc_dev->priv;
461 struct em28xx *dev = ir->dev;
463 /* Setup the proper handler based on the chip */
464 switch (dev->chip_id) {
467 return em2860_ir_change_protocol(rc_dev, rc_proto);
470 case CHIP_ID_EM28174:
471 case CHIP_ID_EM28178:
472 return em2874_ir_change_protocol(rc_dev, rc_proto);
474 dev_err(&ir->dev->intf->dev,
475 "Unrecognized em28xx chip id 0x%02x: IR not supported\n",
481 static int em28xx_probe_i2c_ir(struct em28xx *dev)
485 * Leadtek winfast tv USBII deluxe can find a non working IR-device
486 * at address 0x18, so if that address is needed for another board in
487 * the future, please put it after 0x1f.
489 static const unsigned short addr_list[] = {
490 0x1f, 0x30, 0x47, I2C_CLIENT_END
493 while (addr_list[i] != I2C_CLIENT_END) {
494 if (i2c_probe_func_quick_read(&dev->i2c_adap[dev->def_i2c_bus],
507 static void em28xx_query_buttons(struct work_struct *work)
510 container_of(work, struct em28xx, buttons_query_work.work);
513 bool is_pressed, was_pressed;
514 const struct em28xx_led *led;
516 /* Poll and evaluate all addresses */
517 for (i = 0; i < dev->num_button_polling_addresses; i++) {
518 /* Read value from register */
519 regval = em28xx_read_reg(dev, dev->button_polling_addresses[i]);
522 /* Check states of the buttons and act */
524 while (dev->board.buttons[j].role >= 0 &&
525 dev->board.buttons[j].role < EM28XX_NUM_BUTTON_ROLES) {
526 const struct em28xx_button *button;
528 button = &dev->board.buttons[j];
530 /* Check if button uses the current address */
531 if (button->reg_r != dev->button_polling_addresses[i]) {
535 /* Determine if button is and was pressed last time */
536 is_pressed = regval & button->mask;
537 was_pressed = dev->button_polling_last_values[i]
539 if (button->inverted) {
540 is_pressed = !is_pressed;
541 was_pressed = !was_pressed;
543 /* Clear button state (if needed) */
544 if (is_pressed && button->reg_clearing)
545 em28xx_write_reg(dev, button->reg_clearing,
546 (~regval & button->mask)
547 | (regval & ~button->mask));
548 /* Handle button state */
549 if (!is_pressed || was_pressed) {
553 switch (button->role) {
554 case EM28XX_BUTTON_SNAPSHOT:
555 /* Emulate the keypress */
556 input_report_key(dev->sbutton_input_dev,
557 EM28XX_SNAPSHOT_KEY, 1);
558 /* Unpress the key */
559 input_report_key(dev->sbutton_input_dev,
560 EM28XX_SNAPSHOT_KEY, 0);
562 case EM28XX_BUTTON_ILLUMINATION:
563 led = em28xx_find_led(dev,
564 EM28XX_LED_ILLUMINATION);
565 /* Switch illumination LED on/off */
567 em28xx_toggle_reg_bits(dev,
572 WARN_ONCE(1, "BUG: unhandled button role.");
577 /* Save current value for comparison during the next polling */
578 dev->button_polling_last_values[i] = regval;
580 /* Schedule next poll */
581 schedule_delayed_work(&dev->buttons_query_work,
582 msecs_to_jiffies(dev->button_polling_interval));
585 static int em28xx_register_snapshot_button(struct em28xx *dev)
587 struct usb_device *udev = interface_to_usbdev(dev->intf);
588 struct input_dev *input_dev;
591 dev_info(&dev->intf->dev, "Registering snapshot button...\n");
592 input_dev = input_allocate_device();
596 usb_make_path(udev, dev->snapshot_button_path,
597 sizeof(dev->snapshot_button_path));
598 strlcat(dev->snapshot_button_path, "/sbutton",
599 sizeof(dev->snapshot_button_path));
601 input_dev->name = "em28xx snapshot button";
602 input_dev->phys = dev->snapshot_button_path;
603 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
604 set_bit(EM28XX_SNAPSHOT_KEY, input_dev->keybit);
605 input_dev->keycodesize = 0;
606 input_dev->keycodemax = 0;
607 usb_to_input_id(udev, &input_dev->id);
608 input_dev->dev.parent = &dev->intf->dev;
610 err = input_register_device(input_dev);
612 dev_err(&dev->intf->dev, "input_register_device failed\n");
613 input_free_device(input_dev);
617 dev->sbutton_input_dev = input_dev;
621 static void em28xx_init_buttons(struct em28xx *dev)
624 bool addr_new = false;
626 dev->button_polling_interval = EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL;
627 while (dev->board.buttons[i].role >= 0 &&
628 dev->board.buttons[i].role < EM28XX_NUM_BUTTON_ROLES) {
629 const struct em28xx_button *button = &dev->board.buttons[i];
631 /* Check if polling address is already on the list */
633 for (j = 0; j < dev->num_button_polling_addresses; j++) {
634 if (button->reg_r == dev->button_polling_addresses[j]) {
639 /* Check if max. number of polling addresses is exceeded */
640 if (addr_new && dev->num_button_polling_addresses
641 >= EM28XX_NUM_BUTTON_ADDRESSES_MAX) {
642 WARN_ONCE(1, "BUG: maximum number of button polling addresses exceeded.");
645 /* Button role specific checks and actions */
646 if (button->role == EM28XX_BUTTON_SNAPSHOT) {
647 /* Register input device */
648 if (em28xx_register_snapshot_button(dev) < 0)
650 } else if (button->role == EM28XX_BUTTON_ILLUMINATION) {
652 if (!em28xx_find_led(dev, EM28XX_LED_ILLUMINATION)) {
653 dev_err(&dev->intf->dev,
654 "BUG: illumination button defined, but no illumination LED.\n");
658 /* Add read address to list of polling addresses */
660 unsigned int index = dev->num_button_polling_addresses;
662 dev->button_polling_addresses[index] = button->reg_r;
663 dev->num_button_polling_addresses++;
665 /* Reduce polling interval if necessary */
666 if (!button->reg_clearing)
667 dev->button_polling_interval =
668 EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL;
675 if (dev->num_button_polling_addresses) {
676 memset(dev->button_polling_last_values, 0,
677 EM28XX_NUM_BUTTON_ADDRESSES_MAX);
678 schedule_delayed_work(&dev->buttons_query_work,
679 msecs_to_jiffies(dev->button_polling_interval));
683 static void em28xx_shutdown_buttons(struct em28xx *dev)
686 cancel_delayed_work_sync(&dev->buttons_query_work);
687 /* Clear polling addresses list */
688 dev->num_button_polling_addresses = 0;
689 /* Deregister input devices */
690 if (dev->sbutton_input_dev) {
691 dev_info(&dev->intf->dev, "Deregistering snapshot button\n");
692 input_unregister_device(dev->sbutton_input_dev);
693 dev->sbutton_input_dev = NULL;
697 static int em28xx_ir_init(struct em28xx *dev)
699 struct usb_device *udev = interface_to_usbdev(dev->intf);
700 struct em28xx_IR *ir;
704 u16 i2c_rc_dev_addr = 0;
706 if (dev->is_audio_only) {
707 /* Shouldn't initialize IR for this interface */
712 INIT_DELAYED_WORK(&dev->buttons_query_work, em28xx_query_buttons);
714 if (dev->board.buttons)
715 em28xx_init_buttons(dev);
717 if (dev->board.has_ir_i2c) {
718 i2c_rc_dev_addr = em28xx_probe_i2c_ir(dev);
719 if (!i2c_rc_dev_addr) {
720 dev->board.has_ir_i2c = 0;
721 dev_warn(&dev->intf->dev,
722 "No i2c IR remote control device found.\n");
727 if (!dev->board.ir_codes && !dev->board.has_ir_i2c) {
728 /* No remote control support */
729 dev_warn(&dev->intf->dev,
730 "Remote control support is not available for this card.\n");
734 dev_info(&dev->intf->dev, "Registering input extension\n");
736 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
739 rc = rc_allocate_device(RC_DRIVER_SCANCODE);
743 /* record handles to ourself */
749 rc->open = em28xx_ir_start;
750 rc->close = em28xx_ir_stop;
752 if (dev->board.has_ir_i2c) { /* external i2c device */
753 switch (dev->model) {
754 case EM2800_BOARD_TERRATEC_CINERGY_200:
755 case EM2820_BOARD_TERRATEC_CINERGY_250:
756 rc->map_name = RC_MAP_EM_TERRATEC;
757 ir->get_key_i2c = em28xx_get_key_terratec;
759 case EM2820_BOARD_PINNACLE_USB_2:
760 rc->map_name = RC_MAP_PINNACLE_GREY;
761 ir->get_key_i2c = em28xx_get_key_pinnacle_usb_grey;
763 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
764 rc->map_name = RC_MAP_HAUPPAUGE;
765 ir->get_key_i2c = em28xx_get_key_em_haup;
766 rc->allowed_protocols = RC_PROTO_BIT_RC5;
768 case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
769 rc->map_name = RC_MAP_WINFAST_USBII_DELUXE;
770 ir->get_key_i2c = em28xx_get_key_winfast_usbii_deluxe;
777 ir->i2c_client = kzalloc(sizeof(*ir->i2c_client), GFP_KERNEL);
780 ir->i2c_client->adapter = &ir->dev->i2c_adap[dev->def_i2c_bus];
781 ir->i2c_client->addr = i2c_rc_dev_addr;
782 ir->i2c_client->flags = 0;
783 /* NOTE: all other fields of i2c_client are unused */
784 } else { /* internal device */
785 switch (dev->chip_id) {
788 rc->allowed_protocols = RC_PROTO_BIT_RC5 |
790 ir->get_key = default_polling_getkey;
794 case CHIP_ID_EM28174:
795 case CHIP_ID_EM28178:
796 ir->get_key = em2874_polling_getkey;
797 rc->allowed_protocols = RC_PROTO_BIT_RC5 |
798 RC_PROTO_BIT_NEC | RC_PROTO_BIT_NECX |
799 RC_PROTO_BIT_NEC32 | RC_PROTO_BIT_RC6_0;
806 rc->change_protocol = em28xx_ir_change_protocol;
807 rc->map_name = dev->board.ir_codes;
809 /* By default, keep protocol field untouched */
810 rc_proto = RC_PROTO_BIT_UNKNOWN;
811 err = em28xx_ir_change_protocol(rc, &rc_proto);
816 /* This is how often we ask the chip for IR information */
817 ir->polling = 100; /* ms */
819 usb_make_path(udev, ir->phys, sizeof(ir->phys));
820 strlcat(ir->phys, "/input0", sizeof(ir->phys));
822 rc->device_name = em28xx_boards[dev->model].name;
823 rc->input_phys = ir->phys;
824 usb_to_input_id(udev, &rc->input_id);
825 rc->dev.parent = &dev->intf->dev;
826 rc->driver_name = MODULE_NAME;
829 err = rc_register_device(rc);
833 dev_info(&dev->intf->dev, "Input extension successfully initialized\n");
838 kfree(ir->i2c_client);
845 static int em28xx_ir_fini(struct em28xx *dev)
847 struct em28xx_IR *ir = dev->ir;
849 if (dev->is_audio_only) {
850 /* Shouldn't initialize IR for this interface */
854 dev_info(&dev->intf->dev, "Closing input extension\n");
856 em28xx_shutdown_buttons(dev);
858 /* skip detach on non attached boards */
862 rc_unregister_device(ir->rc);
864 kfree(ir->i2c_client);
871 kref_put(&dev->ref, em28xx_free_device);
876 static int em28xx_ir_suspend(struct em28xx *dev)
878 struct em28xx_IR *ir = dev->ir;
880 if (dev->is_audio_only)
883 dev_info(&dev->intf->dev, "Suspending input extension\n");
885 cancel_delayed_work_sync(&ir->work);
886 cancel_delayed_work_sync(&dev->buttons_query_work);
888 * is canceling delayed work sufficient or does the rc event
889 * kthread needs stopping? kthread is stopped in
890 * ir_raw_event_unregister()
895 static int em28xx_ir_resume(struct em28xx *dev)
897 struct em28xx_IR *ir = dev->ir;
899 if (dev->is_audio_only)
902 dev_info(&dev->intf->dev, "Resuming input extension\n");
904 * if suspend calls ir_raw_event_unregister(), the should call
905 * ir_raw_event_register()
908 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
909 if (dev->num_button_polling_addresses)
910 schedule_delayed_work(&dev->buttons_query_work,
911 msecs_to_jiffies(dev->button_polling_interval));
915 static struct em28xx_ops rc_ops = {
917 .name = "Em28xx Input Extension",
918 .init = em28xx_ir_init,
919 .fini = em28xx_ir_fini,
920 .suspend = em28xx_ir_suspend,
921 .resume = em28xx_ir_resume,
924 static int __init em28xx_rc_register(void)
926 return em28xx_register_extension(&rc_ops);
929 static void __exit em28xx_rc_unregister(void)
931 em28xx_unregister_extension(&rc_ops);
934 MODULE_LICENSE("GPL v2");
935 MODULE_AUTHOR("Mauro Carvalho Chehab");
936 MODULE_DESCRIPTION(DRIVER_DESC " - input interface");
937 MODULE_VERSION(EM28XX_VERSION);
939 module_init(em28xx_rc_register);
940 module_exit(em28xx_rc_unregister);