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>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/delay.h>
15 #include <linux/interrupt.h>
16 #include <linux/usb.h>
17 #include <linux/usb/input.h>
18 #include <linux/slab.h>
19 #include <linux/bitrev.h>
21 #define EM28XX_SNAPSHOT_KEY KEY_CAMERA
22 #define EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL 500 /* [ms] */
23 #define EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL 100 /* [ms] */
25 static unsigned int ir_debug
;
26 module_param(ir_debug
, int, 0644);
27 MODULE_PARM_DESC(ir_debug
, "enable debug messages [IR]");
29 #define MODULE_NAME "em28xx"
31 #define dprintk(fmt, arg...) do { \
33 dev_printk(KERN_DEBUG, &ir->dev->intf->dev, \
34 "input: %s: " fmt, __func__, ## arg); \
38 * Polling structure used by em28xx IR's
41 struct em28xx_ir_poll_result
{
42 unsigned int toggle_bit
:1;
43 unsigned int read_count
:7;
45 enum rc_proto protocol
;
56 struct delayed_work work
;
57 unsigned int full_code
:1;
58 unsigned int last_readcount
;
61 struct i2c_client
*i2c_client
;
63 int (*get_key_i2c
)(struct i2c_client
*ir
, enum rc_proto
*protocol
,
65 int (*get_key
)(struct em28xx_IR
*ir
, struct em28xx_ir_poll_result
*r
);
69 * I2C IR based get keycodes - should be used with ir-kbd-i2c
72 static int em28xx_get_key_terratec(struct i2c_client
*i2c_dev
,
73 enum rc_proto
*protocol
, u32
*scancode
)
79 rc
= i2c_master_recv(i2c_dev
, &b
, 1);
87 * it seems that 0xFE indicates that a button is still hold
88 * down, while 0xff indicates that no button is hold down.
98 *protocol
= RC_PROTO_UNKNOWN
;
103 static int em28xx_get_key_em_haup(struct i2c_client
*i2c_dev
,
104 enum rc_proto
*protocol
, u32
*scancode
)
106 unsigned char buf
[2];
110 size
= i2c_master_recv(i2c_dev
, buf
, sizeof(buf
));
115 /* Does eliminate repeated parity code */
120 * Rearranges bits to the right order.
121 * The bit order were determined experimentally by using
122 * The original Hauppauge Grey IR and another RC5 that uses addr=0x08
123 * The RC5 code has 14 bits, but we've experimentally determined
124 * the meaning for only 11 bits.
125 * So, the code translation is not complete. Yet, it is enough to
126 * work with the provided RC5 IR.
128 *protocol
= RC_PROTO_RC5
;
129 *scancode
= (bitrev8(buf
[1]) & 0x1f) << 8 | bitrev8(buf
[0]) >> 2;
133 static int em28xx_get_key_pinnacle_usb_grey(struct i2c_client
*i2c_dev
,
134 enum rc_proto
*protocol
,
137 unsigned char buf
[3];
141 if (i2c_master_recv(i2c_dev
, buf
, 3) != 3)
147 *protocol
= RC_PROTO_UNKNOWN
;
148 *scancode
= buf
[2] & 0x3f;
152 static int em28xx_get_key_winfast_usbii_deluxe(struct i2c_client
*i2c_dev
,
153 enum rc_proto
*protocol
,
156 unsigned char subaddr
, keydetect
, key
;
158 struct i2c_msg msg
[] = {
160 .addr
= i2c_dev
->addr
,
162 .buf
= &subaddr
, .len
= 1
164 .addr
= i2c_dev
->addr
,
172 if (i2c_transfer(i2c_dev
->adapter
, msg
, 2) != 2)
174 if (keydetect
== 0x00)
179 if (i2c_transfer(i2c_dev
->adapter
, msg
, 2) != 2)
184 *protocol
= RC_PROTO_UNKNOWN
;
190 * Poll based get keycode functions
193 /* This is for the em2860/em2880 */
194 static int default_polling_getkey(struct em28xx_IR
*ir
,
195 struct em28xx_ir_poll_result
*poll_result
)
197 struct em28xx
*dev
= ir
->dev
;
199 u8 msg
[3] = { 0, 0, 0 };
202 * Read key toggle, brand, and key code
203 * on registers 0x45, 0x46 and 0x47
205 rc
= dev
->em28xx_read_reg_req_len(dev
, 0, EM28XX_R45_IR
,
210 /* Infrared toggle (Reg 0x45[7]) */
211 poll_result
->toggle_bit
= (msg
[0] >> 7);
213 /* Infrared read count (Reg 0x45[6:0] */
214 poll_result
->read_count
= (msg
[0] & 0x7f);
216 /* Remote Control Address/Data (Regs 0x46/0x47) */
217 switch (ir
->rc_proto
) {
218 case RC_PROTO_BIT_RC5
:
219 poll_result
->protocol
= RC_PROTO_RC5
;
220 poll_result
->scancode
= RC_SCANCODE_RC5(msg
[1], msg
[2]);
223 case RC_PROTO_BIT_NEC
:
224 poll_result
->protocol
= RC_PROTO_NEC
;
225 poll_result
->scancode
= RC_SCANCODE_NEC(msg
[1], msg
[2]);
229 poll_result
->protocol
= RC_PROTO_UNKNOWN
;
230 poll_result
->scancode
= msg
[1] << 8 | msg
[2];
237 static int em2874_polling_getkey(struct em28xx_IR
*ir
,
238 struct em28xx_ir_poll_result
*poll_result
)
240 struct em28xx
*dev
= ir
->dev
;
242 u8 msg
[5] = { 0, 0, 0, 0, 0 };
245 * Read key toggle, brand, and key code
246 * on registers 0x51-55
248 rc
= dev
->em28xx_read_reg_req_len(dev
, 0, EM2874_R51_IR
,
253 /* Infrared toggle (Reg 0x51[7]) */
254 poll_result
->toggle_bit
= (msg
[0] >> 7);
256 /* Infrared read count (Reg 0x51[6:0] */
257 poll_result
->read_count
= (msg
[0] & 0x7f);
260 * Remote Control Address (Reg 0x52)
261 * Remote Control Data (Reg 0x53-0x55)
263 switch (ir
->rc_proto
) {
264 case RC_PROTO_BIT_RC5
:
265 poll_result
->protocol
= RC_PROTO_RC5
;
266 poll_result
->scancode
= RC_SCANCODE_RC5(msg
[1], msg
[2]);
269 case RC_PROTO_BIT_NEC
:
270 poll_result
->scancode
= ir_nec_bytes_to_scancode(msg
[1], msg
[2], msg
[3], msg
[4],
271 &poll_result
->protocol
);
274 case RC_PROTO_BIT_RC6_0
:
275 poll_result
->protocol
= RC_PROTO_RC6_0
;
276 poll_result
->scancode
= RC_SCANCODE_RC6_0(msg
[1], msg
[2]);
280 poll_result
->protocol
= RC_PROTO_UNKNOWN
;
281 poll_result
->scancode
= (msg
[1] << 24) | (msg
[2] << 16) |
282 (msg
[3] << 8) | msg
[4];
290 * Polling code for em28xx
293 static int em28xx_i2c_ir_handle_key(struct em28xx_IR
*ir
)
296 enum rc_proto protocol
;
299 rc
= ir
->get_key_i2c(ir
->i2c_client
, &protocol
, &scancode
);
301 dprintk("ir->get_key_i2c() failed: %d\n", rc
);
306 dprintk("%s: proto = 0x%04x, scancode = 0x%04x\n",
307 __func__
, protocol
, scancode
);
308 rc_keydown(ir
->rc
, protocol
, scancode
, 0);
313 static void em28xx_ir_handle_key(struct em28xx_IR
*ir
)
316 struct em28xx_ir_poll_result poll_result
;
318 /* read the registers containing the IR status */
319 result
= ir
->get_key(ir
, &poll_result
);
320 if (unlikely(result
< 0)) {
321 dprintk("ir->get_key() failed: %d\n", result
);
325 if (unlikely(poll_result
.read_count
!= ir
->last_readcount
)) {
326 dprintk("%s: toggle: %d, count: %d, key 0x%04x\n", __func__
,
327 poll_result
.toggle_bit
, poll_result
.read_count
,
328 poll_result
.scancode
);
331 poll_result
.protocol
,
332 poll_result
.scancode
,
333 poll_result
.toggle_bit
);
337 poll_result
.scancode
& 0xff,
338 poll_result
.toggle_bit
);
340 if (ir
->dev
->chip_id
== CHIP_ID_EM2874
||
341 ir
->dev
->chip_id
== CHIP_ID_EM2884
)
343 * The em2874 clears the readcount field every time the
344 * register is read. The em2860/2880 datasheet says
345 * that it is supposed to clear the readcount, but it
346 * doesn't. So with the em2874, we are looking for a
347 * non-zero read count as opposed to a readcount
348 * that is incrementing
350 ir
->last_readcount
= 0;
352 ir
->last_readcount
= poll_result
.read_count
;
356 static void em28xx_ir_work(struct work_struct
*work
)
358 struct em28xx_IR
*ir
= container_of(work
, struct em28xx_IR
, work
.work
);
360 if (ir
->i2c_client
) /* external i2c device */
361 em28xx_i2c_ir_handle_key(ir
);
362 else /* internal device */
363 em28xx_ir_handle_key(ir
);
364 schedule_delayed_work(&ir
->work
, msecs_to_jiffies(ir
->polling
));
367 static int em28xx_ir_start(struct rc_dev
*rc
)
369 struct em28xx_IR
*ir
= rc
->priv
;
371 INIT_DELAYED_WORK(&ir
->work
, em28xx_ir_work
);
372 schedule_delayed_work(&ir
->work
, 0);
377 static void em28xx_ir_stop(struct rc_dev
*rc
)
379 struct em28xx_IR
*ir
= rc
->priv
;
381 cancel_delayed_work_sync(&ir
->work
);
384 static int em2860_ir_change_protocol(struct rc_dev
*rc_dev
, u64
*rc_proto
)
386 struct em28xx_IR
*ir
= rc_dev
->priv
;
387 struct em28xx
*dev
= ir
->dev
;
389 /* Adjust xclk based on IR table for RC5/NEC tables */
390 if (*rc_proto
& RC_PROTO_BIT_RC5
) {
391 dev
->board
.xclk
|= EM28XX_XCLK_IR_RC5_MODE
;
393 *rc_proto
= RC_PROTO_BIT_RC5
;
394 } else if (*rc_proto
& RC_PROTO_BIT_NEC
) {
395 dev
->board
.xclk
&= ~EM28XX_XCLK_IR_RC5_MODE
;
397 *rc_proto
= RC_PROTO_BIT_NEC
;
398 } else if (*rc_proto
& RC_PROTO_BIT_UNKNOWN
) {
399 *rc_proto
= RC_PROTO_BIT_UNKNOWN
;
401 *rc_proto
= ir
->rc_proto
;
404 em28xx_write_reg_bits(dev
, EM28XX_R0F_XCLK
, dev
->board
.xclk
,
405 EM28XX_XCLK_IR_RC5_MODE
);
407 ir
->rc_proto
= *rc_proto
;
412 static int em2874_ir_change_protocol(struct rc_dev
*rc_dev
, u64
*rc_proto
)
414 struct em28xx_IR
*ir
= rc_dev
->priv
;
415 struct em28xx
*dev
= ir
->dev
;
416 u8 ir_config
= EM2874_IR_RC5
;
418 /* Adjust xclk and set type based on IR table for RC5/NEC/RC6 tables */
419 if (*rc_proto
& RC_PROTO_BIT_RC5
) {
420 dev
->board
.xclk
|= EM28XX_XCLK_IR_RC5_MODE
;
422 *rc_proto
= RC_PROTO_BIT_RC5
;
423 } else if (*rc_proto
& RC_PROTO_BIT_NEC
) {
424 dev
->board
.xclk
&= ~EM28XX_XCLK_IR_RC5_MODE
;
425 ir_config
= EM2874_IR_NEC
| EM2874_IR_NEC_NO_PARITY
;
427 *rc_proto
= RC_PROTO_BIT_NEC
;
428 } else if (*rc_proto
& RC_PROTO_BIT_RC6_0
) {
429 dev
->board
.xclk
|= EM28XX_XCLK_IR_RC5_MODE
;
430 ir_config
= EM2874_IR_RC6_MODE_0
;
432 *rc_proto
= RC_PROTO_BIT_RC6_0
;
433 } else if (*rc_proto
& RC_PROTO_BIT_UNKNOWN
) {
434 *rc_proto
= RC_PROTO_BIT_UNKNOWN
;
436 *rc_proto
= ir
->rc_proto
;
439 em28xx_write_regs(dev
, EM2874_R50_IR_CONFIG
, &ir_config
, 1);
440 em28xx_write_reg_bits(dev
, EM28XX_R0F_XCLK
, dev
->board
.xclk
,
441 EM28XX_XCLK_IR_RC5_MODE
);
443 ir
->rc_proto
= *rc_proto
;
448 static int em28xx_ir_change_protocol(struct rc_dev
*rc_dev
, u64
*rc_proto
)
450 struct em28xx_IR
*ir
= rc_dev
->priv
;
451 struct em28xx
*dev
= ir
->dev
;
453 /* Setup the proper handler based on the chip */
454 switch (dev
->chip_id
) {
457 return em2860_ir_change_protocol(rc_dev
, rc_proto
);
460 case CHIP_ID_EM28174
:
461 case CHIP_ID_EM28178
:
462 return em2874_ir_change_protocol(rc_dev
, rc_proto
);
464 dev_err(&ir
->dev
->intf
->dev
,
465 "Unrecognized em28xx chip id 0x%02x: IR not supported\n",
471 static int em28xx_probe_i2c_ir(struct em28xx
*dev
)
475 * Leadtek winfast tv USBII deluxe can find a non working IR-device
476 * at address 0x18, so if that address is needed for another board in
477 * the future, please put it after 0x1f.
479 static const unsigned short addr_list
[] = {
480 0x1f, 0x30, 0x47, I2C_CLIENT_END
483 while (addr_list
[i
] != I2C_CLIENT_END
) {
484 if (i2c_probe_func_quick_read(&dev
->i2c_adap
[dev
->def_i2c_bus
],
497 static void em28xx_query_buttons(struct work_struct
*work
)
500 container_of(work
, struct em28xx
, buttons_query_work
.work
);
503 bool is_pressed
, was_pressed
;
504 const struct em28xx_led
*led
;
506 /* Poll and evaluate all addresses */
507 for (i
= 0; i
< dev
->num_button_polling_addresses
; i
++) {
508 /* Read value from register */
509 regval
= em28xx_read_reg(dev
, dev
->button_polling_addresses
[i
]);
512 /* Check states of the buttons and act */
514 while (dev
->board
.buttons
[j
].role
>= 0 &&
515 dev
->board
.buttons
[j
].role
< EM28XX_NUM_BUTTON_ROLES
) {
516 const struct em28xx_button
*button
;
518 button
= &dev
->board
.buttons
[j
];
520 /* Check if button uses the current address */
521 if (button
->reg_r
!= dev
->button_polling_addresses
[i
]) {
525 /* Determine if button is and was pressed last time */
526 is_pressed
= regval
& button
->mask
;
527 was_pressed
= dev
->button_polling_last_values
[i
]
529 if (button
->inverted
) {
530 is_pressed
= !is_pressed
;
531 was_pressed
= !was_pressed
;
533 /* Clear button state (if needed) */
534 if (is_pressed
&& button
->reg_clearing
)
535 em28xx_write_reg(dev
, button
->reg_clearing
,
536 (~regval
& button
->mask
)
537 | (regval
& ~button
->mask
));
538 /* Handle button state */
539 if (!is_pressed
|| was_pressed
) {
543 switch (button
->role
) {
544 case EM28XX_BUTTON_SNAPSHOT
:
545 /* Emulate the keypress */
546 input_report_key(dev
->sbutton_input_dev
,
547 EM28XX_SNAPSHOT_KEY
, 1);
548 /* Unpress the key */
549 input_report_key(dev
->sbutton_input_dev
,
550 EM28XX_SNAPSHOT_KEY
, 0);
552 case EM28XX_BUTTON_ILLUMINATION
:
553 led
= em28xx_find_led(dev
,
554 EM28XX_LED_ILLUMINATION
);
555 /* Switch illumination LED on/off */
557 em28xx_toggle_reg_bits(dev
,
562 WARN_ONCE(1, "BUG: unhandled button role.");
567 /* Save current value for comparison during the next polling */
568 dev
->button_polling_last_values
[i
] = regval
;
570 /* Schedule next poll */
571 schedule_delayed_work(&dev
->buttons_query_work
,
572 msecs_to_jiffies(dev
->button_polling_interval
));
575 static int em28xx_register_snapshot_button(struct em28xx
*dev
)
577 struct usb_device
*udev
= interface_to_usbdev(dev
->intf
);
578 struct input_dev
*input_dev
;
581 dev_info(&dev
->intf
->dev
, "Registering snapshot button...\n");
582 input_dev
= input_allocate_device();
586 usb_make_path(udev
, dev
->snapshot_button_path
,
587 sizeof(dev
->snapshot_button_path
));
588 strlcat(dev
->snapshot_button_path
, "/sbutton",
589 sizeof(dev
->snapshot_button_path
));
591 input_dev
->name
= "em28xx snapshot button";
592 input_dev
->phys
= dev
->snapshot_button_path
;
593 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
);
594 set_bit(EM28XX_SNAPSHOT_KEY
, input_dev
->keybit
);
595 input_dev
->keycodesize
= 0;
596 input_dev
->keycodemax
= 0;
597 usb_to_input_id(udev
, &input_dev
->id
);
598 input_dev
->dev
.parent
= &dev
->intf
->dev
;
600 err
= input_register_device(input_dev
);
602 dev_err(&dev
->intf
->dev
, "input_register_device failed\n");
603 input_free_device(input_dev
);
607 dev
->sbutton_input_dev
= input_dev
;
611 static void em28xx_init_buttons(struct em28xx
*dev
)
614 bool addr_new
= false;
616 dev
->button_polling_interval
= EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL
;
617 while (dev
->board
.buttons
[i
].role
>= 0 &&
618 dev
->board
.buttons
[i
].role
< EM28XX_NUM_BUTTON_ROLES
) {
619 const struct em28xx_button
*button
= &dev
->board
.buttons
[i
];
621 /* Check if polling address is already on the list */
623 for (j
= 0; j
< dev
->num_button_polling_addresses
; j
++) {
624 if (button
->reg_r
== dev
->button_polling_addresses
[j
]) {
629 /* Check if max. number of polling addresses is exceeded */
630 if (addr_new
&& dev
->num_button_polling_addresses
631 >= EM28XX_NUM_BUTTON_ADDRESSES_MAX
) {
632 WARN_ONCE(1, "BUG: maximum number of button polling addresses exceeded.");
635 /* Button role specific checks and actions */
636 if (button
->role
== EM28XX_BUTTON_SNAPSHOT
) {
637 /* Register input device */
638 if (em28xx_register_snapshot_button(dev
) < 0)
640 } else if (button
->role
== EM28XX_BUTTON_ILLUMINATION
) {
642 if (!em28xx_find_led(dev
, EM28XX_LED_ILLUMINATION
)) {
643 dev_err(&dev
->intf
->dev
,
644 "BUG: illumination button defined, but no illumination LED.\n");
648 /* Add read address to list of polling addresses */
650 unsigned int index
= dev
->num_button_polling_addresses
;
652 dev
->button_polling_addresses
[index
] = button
->reg_r
;
653 dev
->num_button_polling_addresses
++;
655 /* Reduce polling interval if necessary */
656 if (!button
->reg_clearing
)
657 dev
->button_polling_interval
=
658 EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL
;
665 if (dev
->num_button_polling_addresses
) {
666 memset(dev
->button_polling_last_values
, 0,
667 EM28XX_NUM_BUTTON_ADDRESSES_MAX
);
668 schedule_delayed_work(&dev
->buttons_query_work
,
669 msecs_to_jiffies(dev
->button_polling_interval
));
673 static void em28xx_shutdown_buttons(struct em28xx
*dev
)
676 cancel_delayed_work_sync(&dev
->buttons_query_work
);
677 /* Clear polling addresses list */
678 dev
->num_button_polling_addresses
= 0;
679 /* Deregister input devices */
680 if (dev
->sbutton_input_dev
) {
681 dev_info(&dev
->intf
->dev
, "Deregistering snapshot button\n");
682 input_unregister_device(dev
->sbutton_input_dev
);
683 dev
->sbutton_input_dev
= NULL
;
687 static int em28xx_ir_init(struct em28xx
*dev
)
689 struct usb_device
*udev
= interface_to_usbdev(dev
->intf
);
690 struct em28xx_IR
*ir
;
694 u16 i2c_rc_dev_addr
= 0;
696 if (dev
->is_audio_only
) {
697 /* Shouldn't initialize IR for this interface */
702 INIT_DELAYED_WORK(&dev
->buttons_query_work
, em28xx_query_buttons
);
704 if (dev
->board
.buttons
)
705 em28xx_init_buttons(dev
);
707 if (dev
->board
.has_ir_i2c
) {
708 i2c_rc_dev_addr
= em28xx_probe_i2c_ir(dev
);
709 if (!i2c_rc_dev_addr
) {
710 dev
->board
.has_ir_i2c
= 0;
711 dev_warn(&dev
->intf
->dev
,
712 "No i2c IR remote control device found.\n");
718 if (!dev
->board
.ir_codes
&& !dev
->board
.has_ir_i2c
) {
719 /* No remote control support */
720 dev_warn(&dev
->intf
->dev
,
721 "Remote control support is not available for this card.\n");
725 dev_info(&dev
->intf
->dev
, "Registering input extension\n");
727 ir
= kzalloc(sizeof(*ir
), GFP_KERNEL
);
730 rc
= rc_allocate_device(RC_DRIVER_SCANCODE
);
734 /* record handles to ourself */
740 rc
->open
= em28xx_ir_start
;
741 rc
->close
= em28xx_ir_stop
;
743 if (dev
->board
.has_ir_i2c
) { /* external i2c device */
744 switch (dev
->model
) {
745 case EM2800_BOARD_TERRATEC_CINERGY_200
:
746 case EM2820_BOARD_TERRATEC_CINERGY_250
:
747 rc
->map_name
= RC_MAP_EM_TERRATEC
;
748 ir
->get_key_i2c
= em28xx_get_key_terratec
;
750 case EM2820_BOARD_PINNACLE_USB_2
:
751 rc
->map_name
= RC_MAP_PINNACLE_GREY
;
752 ir
->get_key_i2c
= em28xx_get_key_pinnacle_usb_grey
;
754 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2
:
755 rc
->map_name
= RC_MAP_HAUPPAUGE
;
756 ir
->get_key_i2c
= em28xx_get_key_em_haup
;
757 rc
->allowed_protocols
= RC_PROTO_BIT_RC5
;
759 case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE
:
760 rc
->map_name
= RC_MAP_WINFAST_USBII_DELUXE
;
761 ir
->get_key_i2c
= em28xx_get_key_winfast_usbii_deluxe
;
768 ir
->i2c_client
= kzalloc(sizeof(*ir
->i2c_client
), GFP_KERNEL
);
771 ir
->i2c_client
->adapter
= &ir
->dev
->i2c_adap
[dev
->def_i2c_bus
];
772 ir
->i2c_client
->addr
= i2c_rc_dev_addr
;
773 ir
->i2c_client
->flags
= 0;
774 /* NOTE: all other fields of i2c_client are unused */
775 } else { /* internal device */
776 switch (dev
->chip_id
) {
779 rc
->allowed_protocols
= RC_PROTO_BIT_RC5
|
781 ir
->get_key
= default_polling_getkey
;
785 case CHIP_ID_EM28174
:
786 case CHIP_ID_EM28178
:
787 ir
->get_key
= em2874_polling_getkey
;
788 rc
->allowed_protocols
= RC_PROTO_BIT_RC5
|
789 RC_PROTO_BIT_NEC
| RC_PROTO_BIT_NECX
|
790 RC_PROTO_BIT_NEC32
| RC_PROTO_BIT_RC6_0
;
797 rc
->change_protocol
= em28xx_ir_change_protocol
;
798 rc
->map_name
= dev
->board
.ir_codes
;
800 /* By default, keep protocol field untouched */
801 rc_proto
= RC_PROTO_BIT_UNKNOWN
;
802 err
= em28xx_ir_change_protocol(rc
, &rc_proto
);
807 /* This is how often we ask the chip for IR information */
808 ir
->polling
= 100; /* ms */
810 usb_make_path(udev
, ir
->phys
, sizeof(ir
->phys
));
811 strlcat(ir
->phys
, "/input0", sizeof(ir
->phys
));
813 rc
->device_name
= em28xx_boards
[dev
->model
].name
;
814 rc
->input_phys
= ir
->phys
;
815 usb_to_input_id(udev
, &rc
->input_id
);
816 rc
->dev
.parent
= &dev
->intf
->dev
;
817 rc
->driver_name
= MODULE_NAME
;
820 err
= rc_register_device(rc
);
824 dev_info(&dev
->intf
->dev
, "Input extension successfully initialized\n");
829 kfree(ir
->i2c_client
);
834 em28xx_shutdown_buttons(dev
);
838 static int em28xx_ir_fini(struct em28xx
*dev
)
840 struct em28xx_IR
*ir
= dev
->ir
;
842 if (dev
->is_audio_only
) {
843 /* Shouldn't initialize IR for this interface */
847 dev_info(&dev
->intf
->dev
, "Closing input extension\n");
849 em28xx_shutdown_buttons(dev
);
851 /* skip detach on non attached boards */
855 rc_unregister_device(ir
->rc
);
857 kfree(ir
->i2c_client
);
864 kref_put(&dev
->ref
, em28xx_free_device
);
869 static int em28xx_ir_suspend(struct em28xx
*dev
)
871 struct em28xx_IR
*ir
= dev
->ir
;
873 if (dev
->is_audio_only
)
876 dev_info(&dev
->intf
->dev
, "Suspending input extension\n");
878 cancel_delayed_work_sync(&ir
->work
);
879 cancel_delayed_work_sync(&dev
->buttons_query_work
);
881 * is canceling delayed work sufficient or does the rc event
882 * kthread needs stopping? kthread is stopped in
883 * ir_raw_event_unregister()
888 static int em28xx_ir_resume(struct em28xx
*dev
)
890 struct em28xx_IR
*ir
= dev
->ir
;
892 if (dev
->is_audio_only
)
895 dev_info(&dev
->intf
->dev
, "Resuming input extension\n");
897 * if suspend calls ir_raw_event_unregister(), the should call
898 * ir_raw_event_register()
901 schedule_delayed_work(&ir
->work
, msecs_to_jiffies(ir
->polling
));
902 if (dev
->num_button_polling_addresses
)
903 schedule_delayed_work(&dev
->buttons_query_work
,
904 msecs_to_jiffies(dev
->button_polling_interval
));
908 static struct em28xx_ops rc_ops
= {
910 .name
= "Em28xx Input Extension",
911 .init
= em28xx_ir_init
,
912 .fini
= em28xx_ir_fini
,
913 .suspend
= em28xx_ir_suspend
,
914 .resume
= em28xx_ir_resume
,
917 static int __init
em28xx_rc_register(void)
919 return em28xx_register_extension(&rc_ops
);
922 static void __exit
em28xx_rc_unregister(void)
924 em28xx_unregister_extension(&rc_ops
);
927 MODULE_LICENSE("GPL v2");
928 MODULE_AUTHOR("Mauro Carvalho Chehab");
929 MODULE_DESCRIPTION(DRIVER_DESC
" - input interface");
930 MODULE_VERSION(EM28XX_VERSION
);
932 module_init(em28xx_rc_register
);
933 module_exit(em28xx_rc_unregister
);