[media] em28xx: get rid of the dependency on module ir-kbd-i2c
[deliverable/linux.git] / drivers / media / usb / em28xx / em28xx-input.c
1 /*
2 handle em28xx IR remotes via linux kernel input layer.
3
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>
8
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.
13
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.
18
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
22 */
23
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
31 #include "em28xx.h"
32
33 #define EM28XX_SNAPSHOT_KEY KEY_CAMERA
34 #define EM28XX_SBUTTON_QUERY_INTERVAL 500
35 #define EM28XX_R0C_USBSUSP_SNAPSHOT 0x20
36
37 static unsigned int ir_debug;
38 module_param(ir_debug, int, 0644);
39 MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
40
41 #define MODULE_NAME "em28xx"
42
43 #define dprintk(fmt, arg...) \
44 if (ir_debug) { \
45 printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \
46 }
47
48 /**********************************************************
49 Polling structure used by em28xx IR's
50 **********************************************************/
51
52 struct em28xx_ir_poll_result {
53 unsigned int toggle_bit:1;
54 unsigned int read_count:7;
55
56 u32 scancode;
57 };
58
59 struct em28xx_IR {
60 struct em28xx *dev;
61 struct rc_dev *rc;
62 char name[32];
63 char phys[32];
64
65 /* poll decoder */
66 int polling;
67 struct delayed_work work;
68 unsigned int full_code:1;
69 unsigned int last_readcount;
70 u64 rc_type;
71
72 /* external device (if used) */
73 struct i2c_client *i2c_dev;
74
75 int (*get_key_i2c)(struct i2c_client *, u32 *, u32 *);
76 int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *);
77 };
78
79 /**********************************************************
80 I2C IR based get keycodes - should be used with ir-kbd-i2c
81 **********************************************************/
82
83 static int em28xx_get_key_terratec(struct i2c_client *i2c_dev,
84 u32 *ir_key, u32 *ir_raw)
85 {
86 unsigned char b;
87
88 /* poll IR chip */
89 if (1 != i2c_master_recv(i2c_dev, &b, 1))
90 return -EIO;
91
92 /* it seems that 0xFE indicates that a button is still hold
93 down, while 0xff indicates that no button is hold
94 down. 0xfe sequences are sometimes interrupted by 0xFF */
95
96 if (b == 0xff)
97 return 0;
98
99 if (b == 0xfe)
100 /* keep old data */
101 return 1;
102
103 *ir_key = b;
104 *ir_raw = b;
105 return 1;
106 }
107
108 static int em28xx_get_key_em_haup(struct i2c_client *i2c_dev,
109 u32 *ir_key, u32 *ir_raw)
110 {
111 unsigned char buf[2];
112 u16 code;
113 int size;
114
115 /* poll IR chip */
116 size = i2c_master_recv(i2c_dev, buf, sizeof(buf));
117
118 if (size != 2)
119 return -EIO;
120
121 /* Does eliminate repeated parity code */
122 if (buf[1] == 0xff)
123 return 0;
124
125 /*
126 * Rearranges bits to the right order.
127 * The bit order were determined experimentally by using
128 * The original Hauppauge Grey IR and another RC5 that uses addr=0x08
129 * The RC5 code has 14 bits, but we've experimentally determined
130 * the meaning for only 11 bits.
131 * So, the code translation is not complete. Yet, it is enough to
132 * work with the provided RC5 IR.
133 */
134 code =
135 ((buf[0] & 0x01) ? 0x0020 : 0) | /* 0010 0000 */
136 ((buf[0] & 0x02) ? 0x0010 : 0) | /* 0001 0000 */
137 ((buf[0] & 0x04) ? 0x0008 : 0) | /* 0000 1000 */
138 ((buf[0] & 0x08) ? 0x0004 : 0) | /* 0000 0100 */
139 ((buf[0] & 0x10) ? 0x0002 : 0) | /* 0000 0010 */
140 ((buf[0] & 0x20) ? 0x0001 : 0) | /* 0000 0001 */
141 ((buf[1] & 0x08) ? 0x1000 : 0) | /* 0001 0000 */
142 ((buf[1] & 0x10) ? 0x0800 : 0) | /* 0000 1000 */
143 ((buf[1] & 0x20) ? 0x0400 : 0) | /* 0000 0100 */
144 ((buf[1] & 0x40) ? 0x0200 : 0) | /* 0000 0010 */
145 ((buf[1] & 0x80) ? 0x0100 : 0); /* 0000 0001 */
146
147 /* return key */
148 *ir_key = code;
149 *ir_raw = code;
150 return 1;
151 }
152
153 static int em28xx_get_key_pinnacle_usb_grey(struct i2c_client *i2c_dev,
154 u32 *ir_key, u32 *ir_raw)
155 {
156 unsigned char buf[3];
157
158 /* poll IR chip */
159
160 if (3 != i2c_master_recv(i2c_dev, buf, 3))
161 return -EIO;
162
163 if (buf[0] != 0x00)
164 return 0;
165
166 *ir_key = buf[2]&0x3f;
167 *ir_raw = buf[2]&0x3f;
168
169 return 1;
170 }
171
172 static int em28xx_get_key_winfast_usbii_deluxe(struct i2c_client *i2c_dev,
173 u32 *ir_key, u32 *ir_raw)
174 {
175 unsigned char subaddr, keydetect, key;
176
177 struct i2c_msg msg[] = { { .addr = i2c_dev->addr, .flags = 0, .buf = &subaddr, .len = 1},
178
179 { .addr = i2c_dev->addr, .flags = I2C_M_RD, .buf = &keydetect, .len = 1} };
180
181 subaddr = 0x10;
182 if (2 != i2c_transfer(i2c_dev->adapter, msg, 2))
183 return -EIO;
184 if (keydetect == 0x00)
185 return 0;
186
187 subaddr = 0x00;
188 msg[1].buf = &key;
189 if (2 != i2c_transfer(i2c_dev->adapter, msg, 2))
190 return -EIO;
191 if (key == 0x00)
192 return 0;
193
194 *ir_key = key;
195 *ir_raw = key;
196 return 1;
197 }
198
199 /**********************************************************
200 Poll based get keycode functions
201 **********************************************************/
202
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)
206 {
207 struct em28xx *dev = ir->dev;
208 int rc;
209 u8 msg[3] = { 0, 0, 0 };
210
211 /* Read key toggle, brand, and key code
212 on registers 0x45, 0x46 and 0x47
213 */
214 rc = dev->em28xx_read_reg_req_len(dev, 0, EM28XX_R45_IR,
215 msg, sizeof(msg));
216 if (rc < 0)
217 return rc;
218
219 /* Infrared toggle (Reg 0x45[7]) */
220 poll_result->toggle_bit = (msg[0] >> 7);
221
222 /* Infrared read count (Reg 0x45[6:0] */
223 poll_result->read_count = (msg[0] & 0x7f);
224
225 /* Remote Control Address/Data (Regs 0x46/0x47) */
226 poll_result->scancode = msg[1] << 8 | msg[2];
227
228 return 0;
229 }
230
231 static int em2874_polling_getkey(struct em28xx_IR *ir,
232 struct em28xx_ir_poll_result *poll_result)
233 {
234 struct em28xx *dev = ir->dev;
235 int rc;
236 u8 msg[5] = { 0, 0, 0, 0, 0 };
237
238 /* Read key toggle, brand, and key code
239 on registers 0x51-55
240 */
241 rc = dev->em28xx_read_reg_req_len(dev, 0, EM2874_R51_IR,
242 msg, sizeof(msg));
243 if (rc < 0)
244 return rc;
245
246 /* Infrared toggle (Reg 0x51[7]) */
247 poll_result->toggle_bit = (msg[0] >> 7);
248
249 /* Infrared read count (Reg 0x51[6:0] */
250 poll_result->read_count = (msg[0] & 0x7f);
251
252 /*
253 * Remote Control Address (Reg 0x52)
254 * Remote Control Data (Reg 0x53-0x55)
255 */
256 switch (ir->rc_type) {
257 case RC_BIT_RC5:
258 poll_result->scancode = msg[1] << 8 | msg[2];
259 break;
260 case RC_BIT_NEC:
261 if ((msg[3] ^ msg[4]) != 0xff) /* 32 bits NEC */
262 poll_result->scancode = (msg[1] << 24) |
263 (msg[2] << 16) |
264 (msg[3] << 8) |
265 msg[4];
266 else if ((msg[1] ^ msg[2]) != 0xff) /* 24 bits NEC */
267 poll_result->scancode = (msg[1] << 16) |
268 (msg[2] << 8) |
269 msg[3];
270 else /* Normal NEC */
271 poll_result->scancode = msg[1] << 8 | msg[3];
272 break;
273 case RC_BIT_RC6_0:
274 poll_result->scancode = msg[1] << 8 | msg[2];
275 break;
276 default:
277 poll_result->scancode = (msg[1] << 24) | (msg[2] << 16) |
278 (msg[3] << 8) | msg[4];
279 break;
280 }
281
282 return 0;
283 }
284
285 /**********************************************************
286 Polling code for em28xx
287 **********************************************************/
288
289 static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir)
290 {
291 static u32 ir_key, ir_raw;
292 int rc;
293
294 rc = ir->get_key_i2c(ir->i2c_dev, &ir_key, &ir_raw);
295 if (rc < 0) {
296 dprintk("ir->get_key_i2c() failed: %d\n", rc);
297 return rc;
298 }
299
300 if (rc) {
301 dprintk("%s: keycode = 0x%04x\n", __func__, ir_key);
302 rc_keydown(ir->rc, ir_key, 0);
303 }
304 return 0;
305 }
306
307 static void em28xx_ir_handle_key(struct em28xx_IR *ir)
308 {
309 int result;
310 struct em28xx_ir_poll_result poll_result;
311
312 /* read the registers containing the IR status */
313 result = ir->get_key(ir, &poll_result);
314 if (unlikely(result < 0)) {
315 dprintk("ir->get_key() failed: %d\n", result);
316 return;
317 }
318
319 if (unlikely(poll_result.read_count != ir->last_readcount)) {
320 dprintk("%s: toggle: %d, count: %d, key 0x%04x\n", __func__,
321 poll_result.toggle_bit, poll_result.read_count,
322 poll_result.scancode);
323 if (ir->full_code)
324 rc_keydown(ir->rc,
325 poll_result.scancode,
326 poll_result.toggle_bit);
327 else
328 rc_keydown(ir->rc,
329 poll_result.scancode & 0xff,
330 poll_result.toggle_bit);
331
332 if (ir->dev->chip_id == CHIP_ID_EM2874 ||
333 ir->dev->chip_id == CHIP_ID_EM2884)
334 /* The em2874 clears the readcount field every time the
335 register is read. The em2860/2880 datasheet says that it
336 is supposed to clear the readcount, but it doesn't. So with
337 the em2874, we are looking for a non-zero read count as
338 opposed to a readcount that is incrementing */
339 ir->last_readcount = 0;
340 else
341 ir->last_readcount = poll_result.read_count;
342 }
343 }
344
345 static void em28xx_i2c_ir_work(struct work_struct *work)
346 {
347 struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work);
348
349 em28xx_i2c_ir_handle_key(ir);
350 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
351 }
352
353 static void em28xx_ir_work(struct work_struct *work)
354 {
355 struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work);
356
357 em28xx_ir_handle_key(ir);
358 schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling));
359 }
360
361 static int em28xx_ir_start(struct rc_dev *rc)
362 {
363 struct em28xx_IR *ir = rc->priv;
364
365 if (ir->i2c_dev) /* external i2c device */
366 INIT_DELAYED_WORK(&ir->work, em28xx_i2c_ir_work);
367 else /* internal device */
368 INIT_DELAYED_WORK(&ir->work, em28xx_ir_work);
369 schedule_delayed_work(&ir->work, 0);
370
371 return 0;
372 }
373
374 static void em28xx_ir_stop(struct rc_dev *rc)
375 {
376 struct em28xx_IR *ir = rc->priv;
377
378 cancel_delayed_work_sync(&ir->work);
379 }
380
381 static int em2860_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type)
382 {
383 struct em28xx_IR *ir = rc_dev->priv;
384 struct em28xx *dev = ir->dev;
385
386 /* Adjust xclk based on IR table for RC5/NEC tables */
387 if (*rc_type & RC_BIT_RC5) {
388 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
389 ir->full_code = 1;
390 *rc_type = RC_BIT_RC5;
391 } else if (*rc_type & RC_BIT_NEC) {
392 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
393 ir->full_code = 1;
394 *rc_type = RC_BIT_NEC;
395 } else if (*rc_type & RC_BIT_UNKNOWN) {
396 *rc_type = RC_BIT_UNKNOWN;
397 } else {
398 *rc_type = ir->rc_type;
399 return -EINVAL;
400 }
401 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
402 EM28XX_XCLK_IR_RC5_MODE);
403
404 ir->rc_type = *rc_type;
405
406 return 0;
407 }
408
409 static int em2874_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type)
410 {
411 struct em28xx_IR *ir = rc_dev->priv;
412 struct em28xx *dev = ir->dev;
413 u8 ir_config = EM2874_IR_RC5;
414
415 /* Adjust xclk and set type based on IR table for RC5/NEC/RC6 tables */
416 if (*rc_type & RC_BIT_RC5) {
417 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
418 ir->full_code = 1;
419 *rc_type = RC_BIT_RC5;
420 } else if (*rc_type & RC_BIT_NEC) {
421 dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE;
422 ir_config = EM2874_IR_NEC | EM2874_IR_NEC_NO_PARITY;
423 ir->full_code = 1;
424 *rc_type = RC_BIT_NEC;
425 } else if (*rc_type & RC_BIT_RC6_0) {
426 dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE;
427 ir_config = EM2874_IR_RC6_MODE_0;
428 ir->full_code = 1;
429 *rc_type = RC_BIT_RC6_0;
430 } else if (*rc_type & RC_BIT_UNKNOWN) {
431 *rc_type = RC_BIT_UNKNOWN;
432 } else {
433 *rc_type = ir->rc_type;
434 return -EINVAL;
435 }
436 em28xx_write_regs(dev, EM2874_R50_IR_CONFIG, &ir_config, 1);
437 em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk,
438 EM28XX_XCLK_IR_RC5_MODE);
439
440 ir->rc_type = *rc_type;
441
442 return 0;
443 }
444 static int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type)
445 {
446 struct em28xx_IR *ir = rc_dev->priv;
447 struct em28xx *dev = ir->dev;
448
449 /* Setup the proper handler based on the chip */
450 switch (dev->chip_id) {
451 case CHIP_ID_EM2860:
452 case CHIP_ID_EM2883:
453 return em2860_ir_change_protocol(rc_dev, rc_type);
454 case CHIP_ID_EM2884:
455 case CHIP_ID_EM2874:
456 case CHIP_ID_EM28174:
457 return em2874_ir_change_protocol(rc_dev, rc_type);
458 default:
459 printk("Unrecognized em28xx chip id 0x%02x: IR not supported\n",
460 dev->chip_id);
461 return -EINVAL;
462 }
463 }
464
465 static struct i2c_client *em28xx_probe_i2c_ir(struct em28xx *dev)
466 {
467 int i = 0;
468 struct i2c_client *i2c_dev = NULL;
469 /* Leadtek winfast tv USBII deluxe can find a non working IR-device */
470 /* at address 0x18, so if that address is needed for another board in */
471 /* the future, please put it after 0x1f. */
472 const unsigned short addr_list[] = {
473 0x1f, 0x30, 0x47, I2C_CLIENT_END
474 };
475
476 while (addr_list[i] != I2C_CLIENT_END) {
477 if (i2c_probe_func_quick_read(&dev->i2c_adap, addr_list[i]) == 1) {
478 i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL);
479 if (i2c_dev) {
480 i2c_dev->addr = addr_list[i];
481 i2c_dev->adapter = &dev->i2c_adap;
482 /* NOTE: as long as we don't register the device
483 * at the i2c subsystem, no other fields need to
484 * be set up */
485 }
486 break;
487 }
488 i++;
489 }
490
491 return i2c_dev;
492 }
493
494 /**********************************************************
495 Handle Webcam snapshot button
496 **********************************************************/
497
498 static void em28xx_query_sbutton(struct work_struct *work)
499 {
500 /* Poll the register and see if the button is depressed */
501 struct em28xx *dev =
502 container_of(work, struct em28xx, sbutton_query_work.work);
503 int ret;
504
505 ret = em28xx_read_reg(dev, EM28XX_R0C_USBSUSP);
506
507 if (ret & EM28XX_R0C_USBSUSP_SNAPSHOT) {
508 u8 cleared;
509 /* Button is depressed, clear the register */
510 cleared = ((u8) ret) & ~EM28XX_R0C_USBSUSP_SNAPSHOT;
511 em28xx_write_regs(dev, EM28XX_R0C_USBSUSP, &cleared, 1);
512
513 /* Not emulate the keypress */
514 input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY,
515 1);
516 /* Now unpress the key */
517 input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY,
518 0);
519 }
520
521 /* Schedule next poll */
522 schedule_delayed_work(&dev->sbutton_query_work,
523 msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL));
524 }
525
526 static void em28xx_register_snapshot_button(struct em28xx *dev)
527 {
528 struct input_dev *input_dev;
529 int err;
530
531 em28xx_info("Registering snapshot button...\n");
532 input_dev = input_allocate_device();
533 if (!input_dev) {
534 em28xx_errdev("input_allocate_device failed\n");
535 return;
536 }
537
538 usb_make_path(dev->udev, dev->snapshot_button_path,
539 sizeof(dev->snapshot_button_path));
540 strlcat(dev->snapshot_button_path, "/sbutton",
541 sizeof(dev->snapshot_button_path));
542 INIT_DELAYED_WORK(&dev->sbutton_query_work, em28xx_query_sbutton);
543
544 input_dev->name = "em28xx snapshot button";
545 input_dev->phys = dev->snapshot_button_path;
546 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
547 set_bit(EM28XX_SNAPSHOT_KEY, input_dev->keybit);
548 input_dev->keycodesize = 0;
549 input_dev->keycodemax = 0;
550 input_dev->id.bustype = BUS_USB;
551 input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
552 input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
553 input_dev->id.version = 1;
554 input_dev->dev.parent = &dev->udev->dev;
555
556 err = input_register_device(input_dev);
557 if (err) {
558 em28xx_errdev("input_register_device failed\n");
559 input_free_device(input_dev);
560 return;
561 }
562
563 dev->sbutton_input_dev = input_dev;
564 schedule_delayed_work(&dev->sbutton_query_work,
565 msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL));
566 return;
567
568 }
569
570 static void em28xx_deregister_snapshot_button(struct em28xx *dev)
571 {
572 if (dev->sbutton_input_dev != NULL) {
573 em28xx_info("Deregistering snapshot button\n");
574 cancel_delayed_work_sync(&dev->sbutton_query_work);
575 input_unregister_device(dev->sbutton_input_dev);
576 dev->sbutton_input_dev = NULL;
577 }
578 return;
579 }
580
581 static int em28xx_ir_init(struct em28xx *dev)
582 {
583 struct em28xx_IR *ir;
584 struct rc_dev *rc;
585 int err = -ENOMEM;
586 u64 rc_type;
587 struct i2c_client *i2c_rc_dev = NULL;
588
589 if (dev->board.has_snapshot_button)
590 em28xx_register_snapshot_button(dev);
591
592 if (dev->board.has_ir_i2c) {
593 i2c_rc_dev = em28xx_probe_i2c_ir(dev);
594 if (!i2c_rc_dev) {
595 dev->board.has_ir_i2c = 0;
596 em28xx_warn("No i2c IR remote control device found.\n");
597 return -ENODEV;
598 }
599 }
600
601 if (dev->board.ir_codes == NULL && !dev->board.has_ir_i2c) {
602 /* No remote control support */
603 em28xx_warn("Remote control support is not available for "
604 "this card.\n");
605 return 0;
606 }
607
608 ir = kzalloc(sizeof(*ir), GFP_KERNEL);
609 rc = rc_allocate_device();
610 if (!ir || !rc)
611 goto error;
612
613 /* record handles to ourself */
614 ir->dev = dev;
615 dev->ir = ir;
616 ir->rc = rc;
617
618 rc->priv = ir;
619 rc->open = em28xx_ir_start;
620 rc->close = em28xx_ir_stop;
621
622 if (dev->board.has_ir_i2c) { /* external i2c device */
623 switch (dev->model) {
624 case EM2800_BOARD_TERRATEC_CINERGY_200:
625 case EM2820_BOARD_TERRATEC_CINERGY_250:
626 rc->map_name = RC_MAP_EM_TERRATEC;
627 ir->get_key_i2c = em28xx_get_key_terratec;
628 break;
629 case EM2820_BOARD_PINNACLE_USB_2:
630 rc->map_name = RC_MAP_PINNACLE_GREY;
631 ir->get_key_i2c = em28xx_get_key_pinnacle_usb_grey;
632 break;
633 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
634 rc->map_name = RC_MAP_HAUPPAUGE;
635 ir->get_key_i2c = em28xx_get_key_em_haup;
636 rc->allowed_protos = RC_BIT_RC5;
637 break;
638 case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
639 rc->map_name = RC_MAP_WINFAST_USBII_DELUXE;
640 ir->get_key_i2c = em28xx_get_key_winfast_usbii_deluxe;
641 break;
642 default:
643 err = -ENODEV;
644 goto error;
645 }
646
647 ir->i2c_dev = i2c_rc_dev;
648 } else { /* internal device */
649 switch (dev->chip_id) {
650 case CHIP_ID_EM2860:
651 case CHIP_ID_EM2883:
652 rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC;
653 ir->get_key = default_polling_getkey;
654 break;
655 case CHIP_ID_EM2884:
656 case CHIP_ID_EM2874:
657 case CHIP_ID_EM28174:
658 ir->get_key = em2874_polling_getkey;
659 rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC |
660 RC_BIT_RC6_0;
661 break;
662 default:
663 err = -ENODEV;
664 goto error;
665 }
666
667 rc->change_protocol = em28xx_ir_change_protocol;
668 rc->map_name = dev->board.ir_codes;
669
670 /* By default, keep protocol field untouched */
671 rc_type = RC_BIT_UNKNOWN;
672 err = em28xx_ir_change_protocol(rc, &rc_type);
673 if (err)
674 goto error;
675 }
676
677 /* This is how often we ask the chip for IR information */
678 ir->polling = 100; /* ms */
679
680 /* init input device */
681 snprintf(ir->name, sizeof(ir->name), "em28xx IR (%s)", dev->name);
682
683 usb_make_path(dev->udev, ir->phys, sizeof(ir->phys));
684 strlcat(ir->phys, "/input0", sizeof(ir->phys));
685
686 rc->input_name = ir->name;
687 rc->input_phys = ir->phys;
688 rc->input_id.bustype = BUS_USB;
689 rc->input_id.version = 1;
690 rc->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor);
691 rc->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct);
692 rc->dev.parent = &dev->udev->dev;
693 rc->driver_name = MODULE_NAME;
694
695 /* all done */
696 err = rc_register_device(rc);
697 if (err)
698 goto error;
699
700 return 0;
701
702 error:
703 if (ir && ir->i2c_dev)
704 kfree(ir->i2c_dev);
705 dev->ir = NULL;
706 rc_free_device(rc);
707 kfree(ir);
708 return err;
709 }
710
711 static int em28xx_ir_fini(struct em28xx *dev)
712 {
713 struct em28xx_IR *ir = dev->ir;
714
715 em28xx_deregister_snapshot_button(dev);
716
717 /* skip detach on non attached boards */
718 if (!ir)
719 return 0;
720
721 if (ir->rc)
722 rc_unregister_device(ir->rc);
723
724 kfree(ir->i2c_dev);
725
726 /* done */
727 kfree(ir);
728 dev->ir = NULL;
729 return 0;
730 }
731
732 static struct em28xx_ops rc_ops = {
733 .id = EM28XX_RC,
734 .name = "Em28xx Input Extension",
735 .init = em28xx_ir_init,
736 .fini = em28xx_ir_fini,
737 };
738
739 static int __init em28xx_rc_register(void)
740 {
741 return em28xx_register_extension(&rc_ops);
742 }
743
744 static void __exit em28xx_rc_unregister(void)
745 {
746 em28xx_unregister_extension(&rc_ops);
747 }
748
749 MODULE_LICENSE("GPL");
750 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
751 MODULE_DESCRIPTION("Em28xx Input driver");
752
753 module_init(em28xx_rc_register);
754 module_exit(em28xx_rc_unregister);
This page took 0.047052 seconds and 5 git commands to generate.