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
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
28 #include <linux/usb.h>
29 #include <linux/slab.h>
30 #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...) \
46 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
49 /**********************************************************
50 Polling structure used by em28xx IR's
51 **********************************************************/
53 struct em28xx_ir_poll_result
{
54 unsigned int toggle_bit
:1;
55 unsigned int read_count
:7;
57 enum rc_type protocol
;
69 struct delayed_work work
;
70 unsigned int full_code
:1;
71 unsigned int last_readcount
;
74 struct i2c_client
*i2c_client
;
76 int (*get_key_i2c
)(struct i2c_client
*ir
, enum rc_type
*protocol
, u32
*scancode
);
77 int (*get_key
)(struct em28xx_IR
*, struct em28xx_ir_poll_result
*);
80 /**********************************************************
81 I2C IR based get keycodes - should be used with ir-kbd-i2c
82 **********************************************************/
84 static int em28xx_get_key_terratec(struct i2c_client
*i2c_dev
,
85 enum rc_type
*protocol
, u32
*scancode
)
90 if (1 != i2c_master_recv(i2c_dev
, &b
, 1))
93 /* it seems that 0xFE indicates that a button is still hold
94 down, while 0xff indicates that no button is hold down. */
103 *protocol
= RC_TYPE_UNKNOWN
;
108 static int em28xx_get_key_em_haup(struct i2c_client
*i2c_dev
,
109 enum rc_type
*protocol
, u32
*scancode
)
111 unsigned char buf
[2];
115 size
= i2c_master_recv(i2c_dev
, buf
, sizeof(buf
));
120 /* Does eliminate repeated parity code */
125 * Rearranges bits to the right order.
126 * The bit order were determined experimentally by using
127 * The original Hauppauge Grey IR and another RC5 that uses addr=0x08
128 * The RC5 code has 14 bits, but we've experimentally determined
129 * the meaning for only 11 bits.
130 * So, the code translation is not complete. Yet, it is enough to
131 * work with the provided RC5 IR.
133 *protocol
= RC_TYPE_RC5
;
134 *scancode
= (bitrev8(buf
[1]) & 0x1f) << 8 | bitrev8(buf
[0]) >> 2;
138 static int em28xx_get_key_pinnacle_usb_grey(struct i2c_client
*i2c_dev
,
139 enum rc_type
*protocol
, u32
*scancode
)
141 unsigned char buf
[3];
145 if (3 != i2c_master_recv(i2c_dev
, buf
, 3))
151 *protocol
= RC_TYPE_UNKNOWN
;
152 *scancode
= buf
[2] & 0x3f;
156 static int em28xx_get_key_winfast_usbii_deluxe(struct i2c_client
*i2c_dev
,
157 enum rc_type
*protocol
, u32
*scancode
)
159 unsigned char subaddr
, keydetect
, key
;
161 struct i2c_msg msg
[] = { { .addr
= i2c_dev
->addr
, .flags
= 0, .buf
= &subaddr
, .len
= 1},
162 { .addr
= i2c_dev
->addr
, .flags
= I2C_M_RD
, .buf
= &keydetect
, .len
= 1} };
165 if (2 != i2c_transfer(i2c_dev
->adapter
, msg
, 2))
167 if (keydetect
== 0x00)
172 if (2 != i2c_transfer(i2c_dev
->adapter
, msg
, 2))
177 *protocol
= RC_TYPE_UNKNOWN
;
182 /**********************************************************
183 Poll based get keycode functions
184 **********************************************************/
186 /* This is for the em2860/em2880 */
187 static int default_polling_getkey(struct em28xx_IR
*ir
,
188 struct em28xx_ir_poll_result
*poll_result
)
190 struct em28xx
*dev
= ir
->dev
;
192 u8 msg
[3] = { 0, 0, 0 };
194 /* Read key toggle, brand, and key code
195 on registers 0x45, 0x46 and 0x47
197 rc
= dev
->em28xx_read_reg_req_len(dev
, 0, EM28XX_R45_IR
,
202 /* Infrared toggle (Reg 0x45[7]) */
203 poll_result
->toggle_bit
= (msg
[0] >> 7);
205 /* Infrared read count (Reg 0x45[6:0] */
206 poll_result
->read_count
= (msg
[0] & 0x7f);
208 /* Remote Control Address/Data (Regs 0x46/0x47) */
209 switch (ir
->rc_type
) {
211 poll_result
->protocol
= RC_TYPE_RC5
;
212 poll_result
->scancode
= RC_SCANCODE_RC5(msg
[1], msg
[2]);
216 poll_result
->protocol
= RC_TYPE_NEC
;
217 poll_result
->scancode
= RC_SCANCODE_NEC(msg
[1], msg
[2]);
221 poll_result
->protocol
= RC_TYPE_UNKNOWN
;
222 poll_result
->scancode
= msg
[1] << 8 | msg
[2];
229 static int em2874_polling_getkey(struct em28xx_IR
*ir
,
230 struct em28xx_ir_poll_result
*poll_result
)
232 struct em28xx
*dev
= ir
->dev
;
234 u8 msg
[5] = { 0, 0, 0, 0, 0 };
236 /* Read key toggle, brand, and key code
239 rc
= dev
->em28xx_read_reg_req_len(dev
, 0, EM2874_R51_IR
,
244 /* Infrared toggle (Reg 0x51[7]) */
245 poll_result
->toggle_bit
= (msg
[0] >> 7);
247 /* Infrared read count (Reg 0x51[6:0] */
248 poll_result
->read_count
= (msg
[0] & 0x7f);
251 * Remote Control Address (Reg 0x52)
252 * Remote Control Data (Reg 0x53-0x55)
254 switch (ir
->rc_type
) {
256 poll_result
->protocol
= RC_TYPE_RC5
;
257 poll_result
->scancode
= RC_SCANCODE_RC5(msg
[1], msg
[2]);
261 poll_result
->protocol
= RC_TYPE_RC5
;
262 poll_result
->scancode
= msg
[1] << 8 | msg
[2];
263 if ((msg
[3] ^ msg
[4]) != 0xff) /* 32 bits NEC */
264 poll_result
->scancode
= RC_SCANCODE_NEC32((msg
[1] << 24) |
268 else if ((msg
[1] ^ msg
[2]) != 0xff) /* 24 bits NEC */
269 poll_result
->scancode
= RC_SCANCODE_NECX(msg
[1] << 8 |
271 else /* Normal NEC */
272 poll_result
->scancode
= RC_SCANCODE_NEC(msg
[1], msg
[3]);
276 poll_result
->protocol
= RC_TYPE_RC6_0
;
277 poll_result
->scancode
= RC_SCANCODE_RC6_0(msg
[1], msg
[2]);
281 poll_result
->protocol
= RC_TYPE_UNKNOWN
;
282 poll_result
->scancode
= (msg
[1] << 24) | (msg
[2] << 16) |
283 (msg
[3] << 8) | msg
[4];
290 /**********************************************************
291 Polling code for em28xx
292 **********************************************************/
294 static int em28xx_i2c_ir_handle_key(struct em28xx_IR
*ir
)
297 enum rc_type protocol
;
300 rc
= ir
->get_key_i2c(ir
->i2c_client
, &protocol
, &scancode
);
302 dprintk("ir->get_key_i2c() failed: %d\n", rc
);
307 dprintk("%s: proto = 0x%04x, scancode = 0x%04x\n",
308 __func__
, protocol
, scancode
);
309 rc_keydown(ir
->rc
, protocol
, scancode
, 0);
314 static void em28xx_ir_handle_key(struct em28xx_IR
*ir
)
317 struct em28xx_ir_poll_result poll_result
;
319 /* read the registers containing the IR status */
320 result
= ir
->get_key(ir
, &poll_result
);
321 if (unlikely(result
< 0)) {
322 dprintk("ir->get_key() failed: %d\n", result
);
326 if (unlikely(poll_result
.read_count
!= ir
->last_readcount
)) {
327 dprintk("%s: toggle: %d, count: %d, key 0x%04x\n", __func__
,
328 poll_result
.toggle_bit
, poll_result
.read_count
,
329 poll_result
.scancode
);
332 poll_result
.protocol
,
333 poll_result
.scancode
,
334 poll_result
.toggle_bit
);
338 poll_result
.scancode
& 0xff,
339 poll_result
.toggle_bit
);
341 if (ir
->dev
->chip_id
== CHIP_ID_EM2874
||
342 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 that it
345 is supposed to clear the readcount, but it doesn't. So with
346 the em2874, we are looking for a non-zero read count as
347 opposed to a readcount that is incrementing */
348 ir
->last_readcount
= 0;
350 ir
->last_readcount
= poll_result
.read_count
;
354 static void em28xx_ir_work(struct work_struct
*work
)
356 struct em28xx_IR
*ir
= container_of(work
, struct em28xx_IR
, work
.work
);
358 if (ir
->i2c_client
) /* external i2c device */
359 em28xx_i2c_ir_handle_key(ir
);
360 else /* internal device */
361 em28xx_ir_handle_key(ir
);
362 schedule_delayed_work(&ir
->work
, msecs_to_jiffies(ir
->polling
));
365 static int em28xx_ir_start(struct rc_dev
*rc
)
367 struct em28xx_IR
*ir
= rc
->priv
;
369 INIT_DELAYED_WORK(&ir
->work
, em28xx_ir_work
);
370 schedule_delayed_work(&ir
->work
, 0);
375 static void em28xx_ir_stop(struct rc_dev
*rc
)
377 struct em28xx_IR
*ir
= rc
->priv
;
379 cancel_delayed_work_sync(&ir
->work
);
382 static int em2860_ir_change_protocol(struct rc_dev
*rc_dev
, u64
*rc_type
)
384 struct em28xx_IR
*ir
= rc_dev
->priv
;
385 struct em28xx
*dev
= ir
->dev
;
387 /* Adjust xclk based on IR table for RC5/NEC tables */
388 if (*rc_type
& RC_BIT_RC5
) {
389 dev
->board
.xclk
|= EM28XX_XCLK_IR_RC5_MODE
;
391 *rc_type
= RC_BIT_RC5
;
392 } else if (*rc_type
& RC_BIT_NEC
) {
393 dev
->board
.xclk
&= ~EM28XX_XCLK_IR_RC5_MODE
;
395 *rc_type
= RC_BIT_NEC
;
396 } else if (*rc_type
& RC_BIT_UNKNOWN
) {
397 *rc_type
= RC_BIT_UNKNOWN
;
399 *rc_type
= ir
->rc_type
;
402 em28xx_write_reg_bits(dev
, EM28XX_R0F_XCLK
, dev
->board
.xclk
,
403 EM28XX_XCLK_IR_RC5_MODE
);
405 ir
->rc_type
= *rc_type
;
410 static int em2874_ir_change_protocol(struct rc_dev
*rc_dev
, u64
*rc_type
)
412 struct em28xx_IR
*ir
= rc_dev
->priv
;
413 struct em28xx
*dev
= ir
->dev
;
414 u8 ir_config
= EM2874_IR_RC5
;
416 /* Adjust xclk and set type based on IR table for RC5/NEC/RC6 tables */
417 if (*rc_type
& RC_BIT_RC5
) {
418 dev
->board
.xclk
|= EM28XX_XCLK_IR_RC5_MODE
;
420 *rc_type
= RC_BIT_RC5
;
421 } else if (*rc_type
& RC_BIT_NEC
) {
422 dev
->board
.xclk
&= ~EM28XX_XCLK_IR_RC5_MODE
;
423 ir_config
= EM2874_IR_NEC
| EM2874_IR_NEC_NO_PARITY
;
425 *rc_type
= RC_BIT_NEC
;
426 } else if (*rc_type
& RC_BIT_RC6_0
) {
427 dev
->board
.xclk
|= EM28XX_XCLK_IR_RC5_MODE
;
428 ir_config
= EM2874_IR_RC6_MODE_0
;
430 *rc_type
= RC_BIT_RC6_0
;
431 } else if (*rc_type
& RC_BIT_UNKNOWN
) {
432 *rc_type
= RC_BIT_UNKNOWN
;
434 *rc_type
= ir
->rc_type
;
437 em28xx_write_regs(dev
, EM2874_R50_IR_CONFIG
, &ir_config
, 1);
438 em28xx_write_reg_bits(dev
, EM28XX_R0F_XCLK
, dev
->board
.xclk
,
439 EM28XX_XCLK_IR_RC5_MODE
);
441 ir
->rc_type
= *rc_type
;
445 static int em28xx_ir_change_protocol(struct rc_dev
*rc_dev
, u64
*rc_type
)
447 struct em28xx_IR
*ir
= rc_dev
->priv
;
448 struct em28xx
*dev
= ir
->dev
;
450 /* Setup the proper handler based on the chip */
451 switch (dev
->chip_id
) {
454 return em2860_ir_change_protocol(rc_dev
, rc_type
);
457 case CHIP_ID_EM28174
:
458 case CHIP_ID_EM28178
:
459 return em2874_ir_change_protocol(rc_dev
, rc_type
);
461 printk("Unrecognized em28xx chip id 0x%02x: IR not supported\n",
467 static int em28xx_probe_i2c_ir(struct em28xx
*dev
)
470 /* Leadtek winfast tv USBII deluxe can find a non working IR-device */
471 /* at address 0x18, so if that address is needed for another board in */
472 /* the future, please put it after 0x1f. */
473 const unsigned short addr_list
[] = {
474 0x1f, 0x30, 0x47, I2C_CLIENT_END
477 while (addr_list
[i
] != I2C_CLIENT_END
) {
478 if (i2c_probe_func_quick_read(&dev
->i2c_adap
[dev
->def_i2c_bus
], addr_list
[i
]) == 1)
486 /**********************************************************
488 **********************************************************/
490 static void em28xx_query_buttons(struct work_struct
*work
)
493 container_of(work
, struct em28xx
, buttons_query_work
.work
);
496 bool is_pressed
, was_pressed
;
497 const struct em28xx_led
*led
;
499 /* Poll and evaluate all addresses */
500 for (i
= 0; i
< dev
->num_button_polling_addresses
; i
++) {
501 /* Read value from register */
502 regval
= em28xx_read_reg(dev
, dev
->button_polling_addresses
[i
]);
505 /* Check states of the buttons and act */
507 while (dev
->board
.buttons
[j
].role
>= 0 &&
508 dev
->board
.buttons
[j
].role
< EM28XX_NUM_BUTTON_ROLES
) {
509 struct em28xx_button
*button
= &dev
->board
.buttons
[j
];
510 /* Check if button uses the current address */
511 if (button
->reg_r
!= dev
->button_polling_addresses
[i
]) {
515 /* Determine if button is and was pressed last time */
516 is_pressed
= regval
& button
->mask
;
517 was_pressed
= dev
->button_polling_last_values
[i
]
519 if (button
->inverted
) {
520 is_pressed
= !is_pressed
;
521 was_pressed
= !was_pressed
;
523 /* Clear button state (if needed) */
524 if (is_pressed
&& button
->reg_clearing
)
525 em28xx_write_reg(dev
, button
->reg_clearing
,
526 (~regval
& button
->mask
)
527 | (regval
& ~button
->mask
));
528 /* Handle button state */
529 if (!is_pressed
|| was_pressed
) {
533 switch (button
->role
) {
534 case EM28XX_BUTTON_SNAPSHOT
:
535 /* Emulate the keypress */
536 input_report_key(dev
->sbutton_input_dev
,
537 EM28XX_SNAPSHOT_KEY
, 1);
538 /* Unpress the key */
539 input_report_key(dev
->sbutton_input_dev
,
540 EM28XX_SNAPSHOT_KEY
, 0);
542 case EM28XX_BUTTON_ILLUMINATION
:
543 led
= em28xx_find_led(dev
,
544 EM28XX_LED_ILLUMINATION
);
545 /* Switch illumination LED on/off */
547 em28xx_toggle_reg_bits(dev
,
552 WARN_ONCE(1, "BUG: unhandled button role.");
557 /* Save current value for comparison during the next polling */
558 dev
->button_polling_last_values
[i
] = regval
;
560 /* Schedule next poll */
561 schedule_delayed_work(&dev
->buttons_query_work
,
562 msecs_to_jiffies(dev
->button_polling_interval
));
565 static int em28xx_register_snapshot_button(struct em28xx
*dev
)
567 struct input_dev
*input_dev
;
570 em28xx_info("Registering snapshot button...\n");
571 input_dev
= input_allocate_device();
575 usb_make_path(dev
->udev
, dev
->snapshot_button_path
,
576 sizeof(dev
->snapshot_button_path
));
577 strlcat(dev
->snapshot_button_path
, "/sbutton",
578 sizeof(dev
->snapshot_button_path
));
580 input_dev
->name
= "em28xx snapshot button";
581 input_dev
->phys
= dev
->snapshot_button_path
;
582 input_dev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
);
583 set_bit(EM28XX_SNAPSHOT_KEY
, input_dev
->keybit
);
584 input_dev
->keycodesize
= 0;
585 input_dev
->keycodemax
= 0;
586 input_dev
->id
.bustype
= BUS_USB
;
587 input_dev
->id
.vendor
= le16_to_cpu(dev
->udev
->descriptor
.idVendor
);
588 input_dev
->id
.product
= le16_to_cpu(dev
->udev
->descriptor
.idProduct
);
589 input_dev
->id
.version
= 1;
590 input_dev
->dev
.parent
= &dev
->udev
->dev
;
592 err
= input_register_device(input_dev
);
594 em28xx_errdev("input_register_device failed\n");
595 input_free_device(input_dev
);
599 dev
->sbutton_input_dev
= input_dev
;
603 static void em28xx_init_buttons(struct em28xx
*dev
)
606 bool addr_new
= false;
608 dev
->button_polling_interval
= EM28XX_BUTTONS_DEBOUNCED_QUERY_INTERVAL
;
609 while (dev
->board
.buttons
[i
].role
>= 0 &&
610 dev
->board
.buttons
[i
].role
< EM28XX_NUM_BUTTON_ROLES
) {
611 struct em28xx_button
*button
= &dev
->board
.buttons
[i
];
612 /* Check if polling address is already on the list */
614 for (j
= 0; j
< dev
->num_button_polling_addresses
; j
++) {
615 if (button
->reg_r
== dev
->button_polling_addresses
[j
]) {
620 /* Check if max. number of polling addresses is exceeded */
621 if (addr_new
&& dev
->num_button_polling_addresses
622 >= EM28XX_NUM_BUTTON_ADDRESSES_MAX
) {
623 WARN_ONCE(1, "BUG: maximum number of button polling addresses exceeded.");
626 /* Button role specific checks and actions */
627 if (button
->role
== EM28XX_BUTTON_SNAPSHOT
) {
628 /* Register input device */
629 if (em28xx_register_snapshot_button(dev
) < 0)
631 } else if (button
->role
== EM28XX_BUTTON_ILLUMINATION
) {
633 if (!em28xx_find_led(dev
, EM28XX_LED_ILLUMINATION
)) {
634 em28xx_errdev("BUG: illumination button defined, but no illumination LED.\n");
638 /* Add read address to list of polling addresses */
640 unsigned int index
= dev
->num_button_polling_addresses
;
641 dev
->button_polling_addresses
[index
] = button
->reg_r
;
642 dev
->num_button_polling_addresses
++;
644 /* Reduce polling interval if necessary */
645 if (!button
->reg_clearing
)
646 dev
->button_polling_interval
=
647 EM28XX_BUTTONS_VOLATILE_QUERY_INTERVAL
;
654 if (dev
->num_button_polling_addresses
) {
655 memset(dev
->button_polling_last_values
, 0,
656 EM28XX_NUM_BUTTON_ADDRESSES_MAX
);
657 schedule_delayed_work(&dev
->buttons_query_work
,
658 msecs_to_jiffies(dev
->button_polling_interval
));
662 static void em28xx_shutdown_buttons(struct em28xx
*dev
)
665 cancel_delayed_work_sync(&dev
->buttons_query_work
);
666 /* Clear polling addresses list */
667 dev
->num_button_polling_addresses
= 0;
668 /* Deregister input devices */
669 if (dev
->sbutton_input_dev
!= NULL
) {
670 em28xx_info("Deregistering snapshot button\n");
671 input_unregister_device(dev
->sbutton_input_dev
);
672 dev
->sbutton_input_dev
= NULL
;
676 static int em28xx_ir_init(struct em28xx
*dev
)
678 struct em28xx_IR
*ir
;
682 u16 i2c_rc_dev_addr
= 0;
684 if (dev
->is_audio_only
) {
685 /* Shouldn't initialize IR for this interface */
690 INIT_DELAYED_WORK(&dev
->buttons_query_work
, em28xx_query_buttons
);
692 if (dev
->board
.buttons
)
693 em28xx_init_buttons(dev
);
695 if (dev
->board
.has_ir_i2c
) {
696 i2c_rc_dev_addr
= em28xx_probe_i2c_ir(dev
);
697 if (!i2c_rc_dev_addr
) {
698 dev
->board
.has_ir_i2c
= 0;
699 em28xx_warn("No i2c IR remote control device found.\n");
704 if (dev
->board
.ir_codes
== NULL
&& !dev
->board
.has_ir_i2c
) {
705 /* No remote control support */
706 em28xx_warn("Remote control support is not available for "
711 em28xx_info("Registering input extension\n");
713 ir
= kzalloc(sizeof(*ir
), GFP_KERNEL
);
716 rc
= rc_allocate_device();
720 /* record handles to ourself */
726 rc
->open
= em28xx_ir_start
;
727 rc
->close
= em28xx_ir_stop
;
729 if (dev
->board
.has_ir_i2c
) { /* external i2c device */
730 switch (dev
->model
) {
731 case EM2800_BOARD_TERRATEC_CINERGY_200
:
732 case EM2820_BOARD_TERRATEC_CINERGY_250
:
733 rc
->map_name
= RC_MAP_EM_TERRATEC
;
734 ir
->get_key_i2c
= em28xx_get_key_terratec
;
736 case EM2820_BOARD_PINNACLE_USB_2
:
737 rc
->map_name
= RC_MAP_PINNACLE_GREY
;
738 ir
->get_key_i2c
= em28xx_get_key_pinnacle_usb_grey
;
740 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2
:
741 rc
->map_name
= RC_MAP_HAUPPAUGE
;
742 ir
->get_key_i2c
= em28xx_get_key_em_haup
;
743 rc
->allowed_protocols
= RC_BIT_RC5
;
745 case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE
:
746 rc
->map_name
= RC_MAP_WINFAST_USBII_DELUXE
;
747 ir
->get_key_i2c
= em28xx_get_key_winfast_usbii_deluxe
;
754 ir
->i2c_client
= kzalloc(sizeof(struct i2c_client
), GFP_KERNEL
);
757 ir
->i2c_client
->adapter
= &ir
->dev
->i2c_adap
[dev
->def_i2c_bus
];
758 ir
->i2c_client
->addr
= i2c_rc_dev_addr
;
759 ir
->i2c_client
->flags
= 0;
760 /* NOTE: all other fields of i2c_client are unused */
761 } else { /* internal device */
762 switch (dev
->chip_id
) {
765 rc
->allowed_protocols
= RC_BIT_RC5
| RC_BIT_NEC
;
766 ir
->get_key
= default_polling_getkey
;
770 case CHIP_ID_EM28174
:
771 case CHIP_ID_EM28178
:
772 ir
->get_key
= em2874_polling_getkey
;
773 rc
->allowed_protocols
= RC_BIT_RC5
| RC_BIT_NEC
|
781 rc
->change_protocol
= em28xx_ir_change_protocol
;
782 rc
->map_name
= dev
->board
.ir_codes
;
784 /* By default, keep protocol field untouched */
785 rc_type
= RC_BIT_UNKNOWN
;
786 err
= em28xx_ir_change_protocol(rc
, &rc_type
);
791 /* This is how often we ask the chip for IR information */
792 ir
->polling
= 100; /* ms */
794 /* init input device */
795 snprintf(ir
->name
, sizeof(ir
->name
), "em28xx IR (%s)", dev
->name
);
797 usb_make_path(dev
->udev
, ir
->phys
, sizeof(ir
->phys
));
798 strlcat(ir
->phys
, "/input0", sizeof(ir
->phys
));
800 rc
->input_name
= ir
->name
;
801 rc
->input_phys
= ir
->phys
;
802 rc
->input_id
.bustype
= BUS_USB
;
803 rc
->input_id
.version
= 1;
804 rc
->input_id
.vendor
= le16_to_cpu(dev
->udev
->descriptor
.idVendor
);
805 rc
->input_id
.product
= le16_to_cpu(dev
->udev
->descriptor
.idProduct
);
806 rc
->dev
.parent
= &dev
->udev
->dev
;
807 rc
->driver_name
= MODULE_NAME
;
810 err
= rc_register_device(rc
);
814 em28xx_info("Input extension successfully initalized\n");
819 kfree(ir
->i2c_client
);
826 static int em28xx_ir_fini(struct em28xx
*dev
)
828 struct em28xx_IR
*ir
= dev
->ir
;
830 if (dev
->is_audio_only
) {
831 /* Shouldn't initialize IR for this interface */
835 em28xx_info("Closing input extension\n");
837 em28xx_shutdown_buttons(dev
);
839 /* skip detach on non attached boards */
843 rc_unregister_device(ir
->rc
);
845 kfree(ir
->i2c_client
);
852 kref_put(&dev
->ref
, em28xx_free_device
);
857 static int em28xx_ir_suspend(struct em28xx
*dev
)
859 struct em28xx_IR
*ir
= dev
->ir
;
861 if (dev
->is_audio_only
)
864 em28xx_info("Suspending input extension\n");
866 cancel_delayed_work_sync(&ir
->work
);
867 cancel_delayed_work_sync(&dev
->buttons_query_work
);
868 /* is canceling delayed work sufficient or does the rc event
869 kthread needs stopping? kthread is stopped in
870 ir_raw_event_unregister() */
874 static int em28xx_ir_resume(struct em28xx
*dev
)
876 struct em28xx_IR
*ir
= dev
->ir
;
878 if (dev
->is_audio_only
)
881 em28xx_info("Resuming input extension\n");
882 /* if suspend calls ir_raw_event_unregister(), the should call
883 ir_raw_event_register() */
885 schedule_delayed_work(&ir
->work
, msecs_to_jiffies(ir
->polling
));
886 if (dev
->num_button_polling_addresses
)
887 schedule_delayed_work(&dev
->buttons_query_work
,
888 msecs_to_jiffies(dev
->button_polling_interval
));
892 static struct em28xx_ops rc_ops
= {
894 .name
= "Em28xx Input Extension",
895 .init
= em28xx_ir_init
,
896 .fini
= em28xx_ir_fini
,
897 .suspend
= em28xx_ir_suspend
,
898 .resume
= em28xx_ir_resume
,
901 static int __init
em28xx_rc_register(void)
903 return em28xx_register_extension(&rc_ops
);
906 static void __exit
em28xx_rc_unregister(void)
908 em28xx_unregister_extension(&rc_ops
);
911 MODULE_LICENSE("GPL");
912 MODULE_AUTHOR("Mauro Carvalho Chehab");
913 MODULE_DESCRIPTION(DRIVER_DESC
" - input interface");
914 MODULE_VERSION(EM28XX_VERSION
);
916 module_init(em28xx_rc_register
);
917 module_exit(em28xx_rc_unregister
);