24 #include <linux/module.h>
29 #include <linux/slab.h>
33 #define EM28XX_SNAPSHOT_KEY KEY_CAMERA
34 #define EM28XX_SBUTTON_QUERY_INTERVAL 500
35 #define EM28XX_R0C_USBSUSP_SNAPSHOT 0x20
37 static unsigned int ir_debug;
41 #define MODULE_NAME "em28xx"
43 #define i2cdprintk(fmt, arg...) \
45 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
48 #define dprintk(fmt, arg...) \
50 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
83 static int em28xx_get_key_terratec(
struct IR_i2c *
ir,
u32 *ir_key,
u32 *ir_raw)
111 static int em28xx_get_key_em_haup(
struct IR_i2c *ir,
u32 *ir_key,
u32 *ir_raw)
113 unsigned char buf[2];
139 ((buf[0] & 0x01) ? 0x0020 : 0) |
140 ((buf[0] & 0x02) ? 0x0010 : 0) |
141 ((buf[0] & 0x04) ? 0x0008 : 0) |
142 ((buf[0] & 0x08) ? 0x0004 : 0) |
143 ((buf[0] & 0x10) ? 0x0002 : 0) |
144 ((buf[0] & 0x20) ? 0x0001 : 0) |
145 ((buf[1] & 0x08) ? 0x1000 : 0) |
146 ((buf[1] & 0x10) ? 0x0800 : 0) |
147 ((buf[1] & 0x20) ? 0x0400 : 0) |
148 ((buf[1] & 0x40) ? 0x0200 : 0) |
149 ((buf[1] & 0x80) ? 0x0100 : 0);
151 i2cdprintk(
"ir hauppauge (em2840): code=0x%02x (rcv=0x%02x%02x)\n",
152 code, buf[1], buf[0]);
160 static int em28xx_get_key_pinnacle_usb_grey(
struct IR_i2c *ir,
u32 *ir_key,
163 unsigned char buf[3];
176 *ir_key = buf[2]&0x3f;
177 *ir_raw = buf[2]&0x3f;
182 static int em28xx_get_key_winfast_usbii_deluxe(
struct IR_i2c *ir,
u32 *ir_key,
185 unsigned char subaddr, keydetect,
key;
187 struct i2c_msg msg[] = { { .addr = ir->
c->addr, .flags = 0, .buf = &subaddr, .len = 1},
189 { .addr = ir->
c->addr, .flags =
I2C_M_RD, .buf = &keydetect, .len = 1} };
196 if (keydetect == 0x00)
218 static int default_polling_getkey(
struct em28xx_IR *ir,
223 u8 msg[3] = { 0, 0, 0 };
243 poll_result->
rc_data[0] = msg[2];
248 static int em2874_polling_getkey(
struct em28xx_IR *ir,
253 u8 msg[5] = { 0, 0, 0, 0, 0 };
273 poll_result->
rc_data[0] = msg[2];
274 poll_result->
rc_data[1] = msg[3];
275 poll_result->
rc_data[2] = msg[4];
284 static void em28xx_ir_handle_key(
struct em28xx_IR *ir)
290 result = ir->
get_key(ir, &poll_result);
292 dprintk(
"ir->get_key() failed %d\n", result);
297 dprintk(
"%s: toggle: %d, count: %d, key 0x%02x%02x\n", __func__,
327 em28xx_ir_handle_key(ir);
331 static int em28xx_ir_start(
struct rc_dev *rc)
341 static void em28xx_ir_stop(
struct rc_dev *rc)
348 static int em28xx_ir_change_protocol(
struct rc_dev *
rc_dev,
u64 rc_type)
374 ir->
get_key = default_polling_getkey;
379 ir->
get_key = em2874_polling_getkey;
383 printk(
"Unrecognized em28xx chip id 0x%02x: IR not supported\n",
391 static void em28xx_register_i2c_ir(
struct em28xx *dev)
397 const unsigned short addr_list[] = {
406 switch (dev->
model) {
410 dev->
init_data.get_key = em28xx_get_key_terratec;
411 dev->
init_data.name =
"i2c IR (EM28XX Terratec)";
415 dev->
init_data.get_key = em28xx_get_key_pinnacle_usb_grey;
416 dev->
init_data.name =
"i2c IR (EM28XX Pinnacle PCTV)";
420 dev->
init_data.get_key = em28xx_get_key_em_haup;
421 dev->
init_data.name =
"i2c IR (EM2840 Hauppauge)";
425 dev->
init_data.get_key = em28xx_get_key_winfast_usbii_deluxe;
426 dev->
init_data.name =
"i2c IR (EM2820 Winfast TV USBII Deluxe)";
439 static void em28xx_query_sbutton(
struct work_struct *work)
451 cleared = ((
u8) ret) & ~EM28XX_R0C_USBSUSP_SNAPSHOT;
467 static void em28xx_register_snapshot_button(
struct em28xx *dev)
469 struct input_dev *input_dev;
473 input_dev = input_allocate_device();
485 input_dev->name =
"em28xx snapshot button";
489 input_dev->keycodesize = 0;
490 input_dev->keycodemax = 0;
491 input_dev->id.bustype =
BUS_USB;
494 input_dev->id.version = 1;
495 input_dev->dev.parent = &dev->
udev->dev;
497 err = input_register_device(input_dev);
500 input_free_device(input_dev);
511 static void em28xx_deregister_snapshot_button(
struct em28xx *dev)
522 static int em28xx_ir_init(
struct em28xx *dev)
530 em28xx_warn(
"Remote control support is not available for "
552 rc->
open = em28xx_ir_start;
553 rc->
close = em28xx_ir_stop;
576 rc->
dev.parent = &dev->
udev->dev;
585 em28xx_register_i2c_ir(dev);
587 #if defined(CONFIG_MODULES) && defined(MODULE)
588 if (dev->
board.has_ir_i2c)
589 request_module(
"ir-kbd-i2c");
591 if (dev->
board.has_snapshot_button)
592 em28xx_register_snapshot_button(dev);
604 static int em28xx_ir_fini(
struct em28xx *dev)
608 em28xx_deregister_snapshot_button(dev);
625 .name =
"Em28xx Input Extension",
626 .init = em28xx_ir_init,
627 .fini = em28xx_ir_fini,
630 static int __init em28xx_rc_register(
void)
635 static void __exit em28xx_rc_unregister(
void)