2 handle em28xx IR remotes via linux kernel input layer.
4 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
5 Markus Rechberger <mrechberger@gmail.com>
6 Mauro Carvalho Chehab <mchehab@infradead.org>
7 Sascha Sommer <saschasommer@freenet.de>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/module.h>
27 #include <linux/init.h>
28 #include <linux/delay.h>
29 #include <linux/interrupt.h>
30 #include <linux/usb.h>
31 #include <linux/slab.h>
32 #include <linux/bitrev.h>
34 #define EM28XX_SNAPSHOT_KEY KEY_CAMERA
35 #define EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL 500 /* [ms] */
36 #define EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL 100 /* [ms] */
38 static unsigned int ir_debug
;
39 module_param(ir_debug
, int, 0644);
40 MODULE_PARM_DESC(ir_debug
, "enable debug messages [IR]");
42 #define MODULE_NAME "em28xx"
44 #define dprintk( fmt, arg...) do { \
46 dev_printk(KERN_DEBUG, &ir->dev->intf->dev, \
47 "input: %s: " fmt, __func__, ## arg); \
50 /**********************************************************
51 Polling structure used by em28xx IR's
52 **********************************************************/
54 struct em28xx_ir_poll_result
{
55 unsigned int toggle_bit
:1;
56 unsigned int read_count
:7;
58 enum rc_proto protocol
;
70 struct delayed_work work
;
71 unsigned int full_code
:1;
72 unsigned int last_readcount
;
75 struct i2c_client
*i2c_client
;
77 int (*get_key_i2c
)(struct i2c_client
*ir
, enum rc_proto
*protocol
,
79 int (*get_key
)(struct em28xx_IR
*, struct em28xx_ir_poll_result
*);
82 /**********************************************************
83 I2C IR based get keycodes - should be used with ir-kbd-i2c
84 **********************************************************/
86 static int em28xx_get_key_terratec(struct i2c_client
*i2c_dev
,
87 enum rc_proto
*protocol
, u32
*scancode
)
92 if (1 != i2c_master_recv(i2c_dev
, &b
, 1))
95 /* it seems that 0xFE indicates that a button is still hold
96 down, while 0xff indicates that no button is hold down. */
105 *protocol
= RC_PROTO_UNKNOWN
;
110 static int em28xx_get_key_em_haup(struct i2c_client
*i2c_dev
,
111 enum rc_proto
*protocol
, u32
*scancode
)
113 unsigned char buf
[2];
117 size
= i2c_master_recv(i2c_dev
, buf
, sizeof(buf
));
122 /* Does eliminate repeated parity code */
127 * Rearranges bits to the right order.
128 * The bit order were determined experimentally by using
129 * The original Hauppauge Grey IR and another RC5 that uses addr=0x08
130 * The RC5 code has 14 bits, but we've experimentally determined
131 * the meaning for only 11 bits.
132 * So, the code translation is not complete. Yet, it is enough to
133 * work with the provided RC5 IR.
135 *protocol
= RC_PROTO_RC5
;
136 *scancode
= (bitrev8(buf
[1]) & 0x1f) << 8 | bitrev8(buf
[0]) >> 2;
140 static int em28xx_get_key_pinnacle_usb_grey(struct i2c_client
*i2c_dev
,
141 enum rc_proto
*protocol
,
144 unsigned char buf
[3];
148 if (3 != i2c_master_recv(i2c_dev
, buf
, 3))
154 *protocol
= RC_PROTO_UNKNOWN
;
155 *scancode
= buf
[2] & 0x3f;
159 static int em28xx_get_key_winfast_usbii_deluxe(struct i2c_client
*i2c_dev
,
160 enum rc_proto
*protocol
,
163 unsigned char subaddr
, keydetect
, key
;
165 struct i2c_msg msg
[] = { { .addr
= i2c_dev
->addr
, .flags
= 0, .buf
= &subaddr
, .len
= 1},
166 { .addr
= i2c_dev
->addr
, .flags
= I2C_M_RD
, .buf
= &keydetect
, .len
= 1} };
169 if (2 != i2c_transfer(i2c_dev
->adapter
, msg
, 2))
171 if (keydetect
== 0x00)
176 if (2 != i2c_transfer(i2c_dev
->adapter
, msg
, 2))
181 *protocol
= RC_PROTO_UNKNOWN
;
186 /**********************************************************
187 Poll based get keycode functions
188 **********************************************************/
190 /* This is for the em2860/em2880 */
191 static int default_polling_getkey(struct em28xx_IR
*ir
,
192 struct em28xx_ir_poll_result
*poll_result
)
194 struct em28xx
*dev
= ir
->dev
;
196 u8 msg
[3] = { 0, 0, 0 };
198 /* Read key toggle, brand, and key code
199 on registers 0x45, 0x46 and 0x47
201 rc
= dev
->em28xx_read_reg_req_len(dev
, 0, EM28XX_R45_IR
,
206 /* Infrared toggle (Reg 0x45[7]) */
207 poll_result
->toggle_bit
= (msg
[0] >> 7);
209 /* Infrared read count (Reg 0x45[6:0] */
210 poll_result
->read_count
= (msg
[0] & 0x7f);
212 /* Remote Control Address/Data (Regs 0x46/0x47) */
213 switch (ir
->rc_proto
) {
214 case RC_PROTO_BIT_RC5
:
215 poll_result
->protocol
= RC_PROTO_RC5
;
216 poll_result
->scancode
= RC_SCANCODE_RC5(msg
[1], msg
[2]);
219 case RC_PROTO_BIT_NEC
:
220 poll_result
->protocol
= RC_PROTO_NEC
;
221 poll_result
->scancode
= RC_SCANCODE_NEC(msg
[1], msg
[2]);
225 poll_result
->protocol
= RC_PROTO_UNKNOWN
;
226 poll_result
->scancode
= msg
[1] << 8 | msg
[2];
233 static int em2874_polling_getkey(struct em28xx_IR
*ir
,
234 struct em28xx_ir_poll_result
*poll_result
)
236 struct em28xx
*dev
= ir
->dev
;
238 u8 msg
[5] = { 0, 0, 0, 0, 0 };
240 /* Read key toggle, brand, and key code
243 rc
= dev
->em28xx_read_reg_req_len(dev
, 0, EM2874_R51_IR
,
248 /* Infrared toggle (Reg 0x51[7]) */
249 poll_result
->toggle_bit
= (msg
[0] >> 7);
251 /* Infrared read count (Reg 0x51[6:0] */
252 poll_result
->read_count
= (msg
[0] & 0x7f);
255 * Remote Control Address (Reg 0x52)
256 * Remote Control Data (Reg 0x53-0x55)
258 switch (ir
->rc_proto
) {
259 case RC_PROTO_BIT_RC5
:
260 poll_result
->protocol
= RC_PROTO_RC5
;
261 poll_result
->scancode
= RC_SCANCODE_RC5(msg
[1], msg
[2]);
264 case RC_PROTO_BIT_NEC
:
265 poll_result
->scancode
= msg
[1] << 8 | msg
[2];
266 if ((msg
[3] ^ msg
[4]) != 0xff) { /* 32 bits NEC */
267 poll_result
->protocol
= RC_PROTO_NEC32
;
268 poll_result
->scancode
= RC_SCANCODE_NEC32((msg
[1] << 24) |
272 } else if ((msg
[1] ^ msg
[2]) != 0xff) { /* 24 bits NEC */
273 poll_result
->protocol
= RC_PROTO_NECX
;
274 poll_result
->scancode
= RC_SCANCODE_NECX(msg
[1] << 8 |
276 } else { /* Normal NEC */
277 poll_result
->protocol
= RC_PROTO_NEC
;
278 poll_result
->scancode
= RC_SCANCODE_NEC(msg
[1], msg
[3]);
282 case RC_PROTO_BIT_RC6_0
:
283 poll_result
->protocol
= RC_PROTO_RC6_0
;
284 poll_result
->scancode
= RC_SCANCODE_RC6_0(msg
[1], msg
[2]);
288 poll_result
->protocol
= RC_PROTO_UNKNOWN
;
289 poll_result
->scancode
= (msg
[1] << 24) | (msg
[2] << 16) |
290 (msg
[3] << 8) | msg
[4];
297 /**********************************************************
298 Polling code for em28xx
299 **********************************************************/
301 static int em28xx_i2c_ir_handle_key(struct em28xx_IR
*ir
)
304 enum rc_proto protocol
;
307 rc
= ir
->get_key_i2c(ir
->i2c_client
, &protocol
, &scancode
);
309 dprintk("ir->get_key_i2c() failed: %d\n", rc
);
314 dprintk("%s: proto = 0x%04x, scancode = 0x%04x\n",
315 __func__
, protocol
, scancode
);
316 rc_keydown(ir
->rc
, protocol
, scancode
, 0);
321 static void em28xx_ir_handle_key(struct em28xx_IR
*ir
)
324 struct em28xx_ir_poll_result poll_result
;
326 /* read the registers containing the IR status */
327 result
= ir
->get_key(ir
, &poll_result
);
328 if (unlikely(result
< 0)) {
329 dprintk("ir->get_key() failed: %d\n", result
);
333 if (unlikely(poll_result
.read_count
!= ir
->last_readcount
)) {
334 dprintk("%s: toggle: %d, count: %d, key 0x%04x\n", __func__
,
335 poll_result
.toggle_bit
, poll_result
.read_count
,
336 poll_result
.scancode
);
339 poll_result
.protocol
,
340 poll_result
.scancode
,
341 poll_result
.toggle_bit
);
345 poll_result
.scancode
& 0xff,
346 poll_result
.toggle_bit
);
348 if (ir
->dev
->chip_id
== CHIP_ID_EM2874
||
349 ir
->dev
->chip_id
== CHIP_ID_EM2884
)
350 /* The em2874 clears the readcount field every time the
351 register is read. The em2860/2880 datasheet says that it
352 is supposed to clear the readcount, but it doesn't. So with
353 the em2874, we are looking for a non-zero read count as
354 opposed to a readcount that is incrementing */
355 ir
->last_readcount
= 0;
357 ir
->last_readcount
= poll_result
.read_count
;
361 static void em28xx_ir_work(struct work_struct
*work
)
363 struct em28xx_IR
*ir
= container_of(work
, struct em28xx_IR
, work
.work
);
365 if (ir
->i2c_client
) /* external i2c device */
366 em28xx_i2c_ir_handle_key(ir
);
367 else /* internal device */
368 em28xx_ir_handle_key(ir
);
369 schedule_delayed_work(&ir
->work
, msecs_to_jiffies(ir
->polling
));
372 static int em28xx_ir_start(struct rc_dev
*rc
)
374 struct em28xx_IR
*ir
= rc
->priv
;
376 INIT_DELAYED_WORK(&ir
->work
, em28xx_ir_work
);
377 schedule_delayed_work(&ir
->work
, 0);
382 static void em28xx_ir_stop(struct rc_dev
*rc
)
384 struct em28xx_IR
*ir
= rc
->priv
;
386 cancel_delayed_work_sync(&ir
->work
);
389 static int em2860_ir_change_protocol(struct rc_dev
*rc_dev
, u64
*rc_proto
)
391 struct em28xx_IR
*ir
= rc_dev
->priv
;
392 struct em28xx
*dev
= ir
->dev
;
394 /* Adjust xclk based on IR table for RC5/NEC tables */
395 if (*rc_proto
& RC_PROTO_BIT_RC5
) {
396 dev
->board
.xclk
|= EM28XX_XCLK_IR_RC5_MODE
;
398 *rc_proto
= RC_PROTO_BIT_RC5
;
399 } else if (*rc_proto
& RC_PROTO_BIT_NEC
) {
400 dev
->board
.xclk
&= ~EM28XX_XCLK_IR_RC5_MODE
;
402 *rc_proto
= RC_PROTO_BIT_NEC
;
403 } else if (*rc_proto
& RC_PROTO_BIT_UNKNOWN
) {
404 *rc_proto
= RC_PROTO_BIT_UNKNOWN
;
406 *rc_proto
= ir
->rc_proto
;
409 em28xx_write_reg_bits(dev
, EM28XX_R0F_XCLK
, dev
->board
.xclk
,
410 EM28XX_XCLK_IR_RC5_MODE
);
412 ir
->rc_proto
= *rc_proto
;
417 static int em2874_ir_change_protocol(struct rc_dev
*rc_dev
, u64
*rc_proto
)
419 struct em28xx_IR
*ir
= rc_dev
->priv
;
420 struct em28xx
*dev
= ir
->dev
;
421 u8 ir_config
= EM2874_IR_RC5
;
423 /* Adjust xclk and set type based on IR table for RC5/NEC/RC6 tables */
424 if (*rc_proto
& RC_PROTO_BIT_RC5
) {
425 dev
->board
.xclk
|= EM28XX_XCLK_IR_RC5_MODE
;
427 *rc_proto
= RC_PROTO_BIT_RC5
;
428 } else if (*rc_proto
& RC_PROTO_BIT_NEC
) {
429 dev
->board
.xclk
&= ~EM28XX_XCLK_IR_RC5_MODE
;
430 ir_config
= EM2874_IR_NEC
| EM2874_IR_NEC_NO_PARITY
;
432 *rc_proto
= RC_PROTO_BIT_NEC
;
433 } else if (*rc_proto
& RC_PROTO_BIT_RC6_0
) {
434 dev
->board
.xclk
|= EM28XX_XCLK_IR_RC5_MODE
;
435 ir_config
= EM2874_IR_RC6_MODE_0
;
437 *rc_proto
= RC_PROTO_BIT_RC6_0
;
438 } else if (*rc_proto
& RC_PROTO_BIT_UNKNOWN
) {
439 *rc_proto
= RC_PROTO_BIT_UNKNOWN
;
441 *rc_proto
= ir
->rc_proto
;
444 em28xx_write_regs(dev
, EM2874_R50_IR_CONFIG
, &ir_config
, 1);
445 em28xx_write_reg_bits(dev
, EM28XX_R0F_XCLK
, dev
->board
.xclk
,
446 EM28XX_XCLK_IR_RC5_MODE
);
448 ir
->rc_proto
= *rc_proto
;
453 static int em28xx_ir_change_protocol(struct rc_dev
*rc_dev
, u64
*rc_proto
)
455 struct em28xx_IR
*ir
= rc_dev
->priv
;
456 struct em28xx
*dev
= ir
->dev
;
458 /* Setup the proper handler based on the chip */
459 switch (dev
->chip_id
) {
462 return em2860_ir_change_protocol(rc_dev
, rc_proto
);
465 case CHIP_ID_EM28174
:
466 case CHIP_ID_EM28178
:
467 return em2874_ir_change_protocol(rc_dev
, rc_proto
);
469 dev_err(&ir
->dev
->intf
->dev
,
470 "Unrecognized em28xx chip id 0x%02x: IR not supported\n",
476 static int em28xx_probe_i2c_ir(struct em28xx
*dev
)
479 /* Leadtek winfast tv USBII deluxe can find a non working IR-device */
480 /* at address 0x18, so if that address is needed for another board in */
481 /* the future, please put it after 0x1f. */
482 const unsigned short addr_list
[] = {
483 0x1f, 0x30, 0x47, I2C_CLIENT_END
486 while (addr_list
[i
] != I2C_CLIENT_END
) {
487 if (i2c_probe_func_quick_read(&dev
->i2c_adap
[dev
->def_i2c_bus
], addr_list
[i
]) == 1)
495 /**********************************************************
497 **********************************************************/
499 static void em28xx_query_buttons(struct work_struct
*work
)
502 container_of(work
, struct em28xx
, buttons_query_work
.work
);
505 bool is_pressed
, was_pressed
;
506 const struct em28xx_led
*led
;
508 /* Poll and evaluate all addresses */
509 for (i
= 0; i
< dev
->num_button_polling_addresses
; i
++) {
510 /* Read value from register */
511 regval
= em28xx_read_reg(dev
, dev
->button_polling_addresses
[i
]);
514 /* Check states of the buttons and act */
516 while (dev
->board
.buttons
[j
].role
>= 0 &&
517 dev
->board
.buttons
[j
].role
< EM28XX_NUM_BUTTON_ROLES
) {
518 struct em28xx_button
*button
= &dev
->board
.buttons
[j
];
519 /* Check if button uses the current address */
520 if (button
->reg_r
!= dev
->button_polling_addresses
[i
]) {
524 /* Determine if button is and was pressed last time */
525 is_pressed
= regval
& button
->mask
;
526 was_pressed
= dev
->button_polling_last_values
[i
]
528 if (button
->inverted
) {
529 is_pressed
= !is_pressed
;
530 was_pressed
= !was_pressed
;
532 /* Clear button state (if needed) */
533 if (is_pressed
&& button
->reg_clearing
)
534 em28xx_write_reg(dev
, button
->reg_clearing
,
535 (~regval
& button
->mask
)
536 | (regval
& ~button
->mask
));
537 /* Handle button state */
538 if (!is_pressed
|| was_pressed
) {
542 switch (button
->role
) {
543 case EM28XX_BUTTON_SNAPSHOT
:
544 /* Emulate the keypress */
545 input_report_key(dev
->sbutton_input_dev
,
546 EM28XX_SNAPSHOT_KEY
, 1);
547 /* Unpress the key */
548 input_report_key(dev
->sbutton_input_dev
,
549 EM28XX_SNAPSHOT_KEY
, 0);
551 case EM28XX_BUTTON_ILLUMINATION
:
552 led
= em28xx_find_led(dev
,
553 EM28XX_LED_ILLUMINATION
);
554 /* Switch illumination LED on/off */
556 em28xx_toggle_reg_bits(dev
,
561 WARN_ONCE(1, "BUG: unhandled button role.");
566 /* Save current value for comparison during the next polling */
567 dev
->button_polling_last_values
[i
] = regval
;
569 /* Schedule next poll */
570 schedule_delayed_work(&dev
->buttons_query_work
,
571 msecs_to_jiffies(dev
->button_polling_interval
));
574 static int em28xx_register_snapshot_button(struct em28xx
*dev
)
576 struct usb_device
*udev
= interface_to_usbdev(dev
->intf
);
577 struct input_dev
*input_dev
;
580 dev_info(&dev
->intf
->dev
, "Registering snapshot button...\n");
581 input_dev
= input_allocate_device();
585 usb_make_path(udev
, dev
->snapshot_button_path
,
586 sizeof(dev
->snapshot_button_path
));
587 strlcat(dev
->snapshot_button_path
, "/sbutton",
588 sizeof(dev
->snapshot_button_path
));
590 input_dev
->name
= "em28xx snapshot button";
591 input_dev
->phys
= dev
->snapshot_button_path
;
592 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
);
593 set_bit(EM28XX_SNAPSHOT_KEY
, input_dev
->keybit
);
594 input_dev
->keycodesize
= 0;
595 input_dev
->keycodemax
= 0;
596 input_dev
->id
.bustype
= BUS_USB
;
597 input_dev
->id
.vendor
= le16_to_cpu(udev
->descriptor
.idVendor
);
598 input_dev
->id
.product
= le16_to_cpu(udev
->descriptor
.idProduct
);
599 input_dev
->id
.version
= 1;
600 input_dev
->dev
.parent
= &dev
->intf
->dev
;
602 err
= input_register_device(input_dev
);
604 dev_err(&dev
->intf
->dev
, "input_register_device failed\n");
605 input_free_device(input_dev
);
609 dev
->sbutton_input_dev
= input_dev
;
613 static void em28xx_init_buttons(struct em28xx
*dev
)
616 bool addr_new
= false;
618 dev
->button_polling_interval
= EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL
;
619 while (dev
->board
.buttons
[i
].role
>= 0 &&
620 dev
->board
.buttons
[i
].role
< EM28XX_NUM_BUTTON_ROLES
) {
621 struct em28xx_button
*button
= &dev
->board
.buttons
[i
];
622 /* Check if polling address is already on the list */
624 for (j
= 0; j
< dev
->num_button_polling_addresses
; j
++) {
625 if (button
->reg_r
== dev
->button_polling_addresses
[j
]) {
630 /* Check if max. number of polling addresses is exceeded */
631 if (addr_new
&& dev
->num_button_polling_addresses
632 >= EM28XX_NUM_BUTTON_ADDRESSES_MAX
) {
633 WARN_ONCE(1, "BUG: maximum number of button polling addresses exceeded.");
636 /* Button role specific checks and actions */
637 if (button
->role
== EM28XX_BUTTON_SNAPSHOT
) {
638 /* Register input device */
639 if (em28xx_register_snapshot_button(dev
) < 0)
641 } else if (button
->role
== EM28XX_BUTTON_ILLUMINATION
) {
643 if (!em28xx_find_led(dev
, EM28XX_LED_ILLUMINATION
)) {
644 dev_err(&dev
->intf
->dev
,
645 "BUG: illumination button defined, but no illumination LED.\n");
649 /* Add read address to list of polling addresses */
651 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
!= NULL
) {
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");
717 if (dev
->board
.ir_codes
== NULL
&& !dev
->board
.has_ir_i2c
) {
718 /* No remote control support */
719 dev_warn(&dev
->intf
->dev
,
720 "Remote control support is not available for this card.\n");
724 dev_info(&dev
->intf
->dev
, "Registering input extension\n");
726 ir
= kzalloc(sizeof(*ir
), GFP_KERNEL
);
729 rc
= rc_allocate_device(RC_DRIVER_SCANCODE
);
733 /* record handles to ourself */
739 rc
->open
= em28xx_ir_start
;
740 rc
->close
= em28xx_ir_stop
;
742 if (dev
->board
.has_ir_i2c
) { /* external i2c device */
743 switch (dev
->model
) {
744 case EM2800_BOARD_TERRATEC_CINERGY_200
:
745 case EM2820_BOARD_TERRATEC_CINERGY_250
:
746 rc
->map_name
= RC_MAP_EM_TERRATEC
;
747 ir
->get_key_i2c
= em28xx_get_key_terratec
;
749 case EM2820_BOARD_PINNACLE_USB_2
:
750 rc
->map_name
= RC_MAP_PINNACLE_GREY
;
751 ir
->get_key_i2c
= em28xx_get_key_pinnacle_usb_grey
;
753 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2
:
754 rc
->map_name
= RC_MAP_HAUPPAUGE
;
755 ir
->get_key_i2c
= em28xx_get_key_em_haup
;
756 rc
->allowed_protocols
= RC_PROTO_BIT_RC5
;
758 case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE
:
759 rc
->map_name
= RC_MAP_WINFAST_USBII_DELUXE
;
760 ir
->get_key_i2c
= em28xx_get_key_winfast_usbii_deluxe
;
767 ir
->i2c_client
= kzalloc(sizeof(struct i2c_client
), GFP_KERNEL
);
770 ir
->i2c_client
->adapter
= &ir
->dev
->i2c_adap
[dev
->def_i2c_bus
];
771 ir
->i2c_client
->addr
= i2c_rc_dev_addr
;
772 ir
->i2c_client
->flags
= 0;
773 /* NOTE: all other fields of i2c_client are unused */
774 } else { /* internal device */
775 switch (dev
->chip_id
) {
778 rc
->allowed_protocols
= RC_PROTO_BIT_RC5
|
780 ir
->get_key
= default_polling_getkey
;
784 case CHIP_ID_EM28174
:
785 case CHIP_ID_EM28178
:
786 ir
->get_key
= em2874_polling_getkey
;
787 rc
->allowed_protocols
= RC_PROTO_BIT_RC5
|
788 RC_PROTO_BIT_NEC
| RC_PROTO_BIT_NECX
|
789 RC_PROTO_BIT_NEC32
| RC_PROTO_BIT_RC6_0
;
796 rc
->change_protocol
= em28xx_ir_change_protocol
;
797 rc
->map_name
= dev
->board
.ir_codes
;
799 /* By default, keep protocol field untouched */
800 rc_proto
= RC_PROTO_BIT_UNKNOWN
;
801 err
= em28xx_ir_change_protocol(rc
, &rc_proto
);
806 /* This is how often we ask the chip for IR information */
807 ir
->polling
= 100; /* ms */
809 /* init input device */
810 snprintf(ir
->name
, sizeof(ir
->name
), "%s IR",
811 dev_name(&dev
->intf
->dev
));
813 usb_make_path(udev
, ir
->phys
, sizeof(ir
->phys
));
814 strlcat(ir
->phys
, "/input0", sizeof(ir
->phys
));
816 rc
->device_name
= ir
->name
;
817 rc
->input_phys
= ir
->phys
;
818 rc
->input_id
.bustype
= BUS_USB
;
819 rc
->input_id
.version
= 1;
820 rc
->input_id
.vendor
= le16_to_cpu(udev
->descriptor
.idVendor
);
821 rc
->input_id
.product
= le16_to_cpu(udev
->descriptor
.idProduct
);
822 rc
->dev
.parent
= &dev
->intf
->dev
;
823 rc
->driver_name
= MODULE_NAME
;
826 err
= rc_register_device(rc
);
830 dev_info(&dev
->intf
->dev
, "Input extension successfully initialized\n");
835 kfree(ir
->i2c_client
);
842 static int em28xx_ir_fini(struct em28xx
*dev
)
844 struct em28xx_IR
*ir
= dev
->ir
;
846 if (dev
->is_audio_only
) {
847 /* Shouldn't initialize IR for this interface */
851 dev_info(&dev
->intf
->dev
, "Closing input extension\n");
853 em28xx_shutdown_buttons(dev
);
855 /* skip detach on non attached boards */
859 rc_unregister_device(ir
->rc
);
861 kfree(ir
->i2c_client
);
868 kref_put(&dev
->ref
, em28xx_free_device
);
873 static int em28xx_ir_suspend(struct em28xx
*dev
)
875 struct em28xx_IR
*ir
= dev
->ir
;
877 if (dev
->is_audio_only
)
880 dev_info(&dev
->intf
->dev
, "Suspending input extension\n");
882 cancel_delayed_work_sync(&ir
->work
);
883 cancel_delayed_work_sync(&dev
->buttons_query_work
);
884 /* is canceling delayed work sufficient or does the rc event
885 kthread needs stopping? kthread is stopped in
886 ir_raw_event_unregister() */
890 static int em28xx_ir_resume(struct em28xx
*dev
)
892 struct em28xx_IR
*ir
= dev
->ir
;
894 if (dev
->is_audio_only
)
897 dev_info(&dev
->intf
->dev
, "Resuming input extension\n");
898 /* if suspend calls ir_raw_event_unregister(), the should call
899 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");
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
);