2 * tm6000-cards.c - driver for TM5600/TM6000/TM6010 USB video capture devices
4 * Copyright (C) 2006-2007 Mauro Carvalho Chehab <mchehab@infradead.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation version 2
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/pci.h>
23 #include <linux/delay.h>
24 #include <linux/i2c.h>
25 #include <linux/usb.h>
26 #include <linux/version.h>
27 #include <linux/slab.h>
28 #include <media/v4l2-common.h>
29 #include <media/tuner.h>
30 #include <media/tvaudio.h>
31 #include <media/i2c-addr.h>
32 #include <media/rc-map.h>
35 #include "tm6000-regs.h"
36 #include "tuner-xc2028.h"
39 #define TM6000_BOARD_UNKNOWN 0
40 #define TM5600_BOARD_GENERIC 1
41 #define TM6000_BOARD_GENERIC 2
42 #define TM6010_BOARD_GENERIC 3
43 #define TM5600_BOARD_10MOONS_UT821 4
44 #define TM5600_BOARD_10MOONS_UT330 5
45 #define TM6000_BOARD_ADSTECH_DUAL_TV 6
46 #define TM6000_BOARD_FREECOM_AND_SIMILAR 7
47 #define TM6000_BOARD_ADSTECH_MINI_DUAL_TV 8
48 #define TM6010_BOARD_HAUPPAUGE_900H 9
49 #define TM6010_BOARD_BEHOLD_WANDER 10
50 #define TM6010_BOARD_BEHOLD_VOYAGER 11
51 #define TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE 12
52 #define TM6010_BOARD_TWINHAN_TU501 13
53 #define TM6010_BOARD_BEHOLD_WANDER_LITE 14
54 #define TM6010_BOARD_BEHOLD_VOYAGER_LITE 15
55 #define TM5600_BOARD_TERRATEC_GRABSTER 16
57 #define is_generic(model) ((model == TM6000_BOARD_UNKNOWN) || \
58 (model == TM5600_BOARD_GENERIC) || \
59 (model == TM6000_BOARD_GENERIC) || \
60 (model == TM6010_BOARD_GENERIC))
62 #define TM6000_MAXBOARDS 16
63 static unsigned int card[] = {[0 ... (TM6000_MAXBOARDS - 1)] = UNSET };
65 module_param_array(card, int, NULL, 0444);
67 static unsigned long tm6000_devused;
72 char eename[16]; /* EEPROM name */
73 unsigned eename_size; /* size of EEPROM name */
74 unsigned eename_pos; /* Position where it appears at ROM */
76 struct tm6000_capabilities caps;
78 enum tm6000_devtype type; /* variant of the chipset */
79 int tuner_type; /* type of the tuner */
80 int tuner_addr; /* tuner address */
81 int demod_addr; /* demodulator address */
83 struct tm6000_gpio gpio;
85 struct tm6000_input vinput[3];
86 struct tm6000_input rinput;
90 struct tm6000_board tm6000_boards[] = {
91 [TM6000_BOARD_UNKNOWN] = {
92 .name = "Unknown tm6000 video grabber",
97 .tuner_reset = TM6000_GPIO_1,
100 .type = TM6000_INPUT_TV,
101 .vmux = TM6000_VMUX_VIDEO_B,
102 .amux = TM6000_AMUX_ADC1,
104 .type = TM6000_INPUT_COMPOSITE1,
105 .vmux = TM6000_VMUX_VIDEO_A,
106 .amux = TM6000_AMUX_ADC2,
108 .type = TM6000_INPUT_SVIDEO,
109 .vmux = TM6000_VMUX_VIDEO_AB,
110 .amux = TM6000_AMUX_ADC2,
114 [TM5600_BOARD_GENERIC] = {
115 .name = "Generic tm5600 board",
117 .tuner_type = TUNER_XC2028,
118 .tuner_addr = 0xc2 >> 1,
123 .tuner_reset = TM6000_GPIO_1,
126 .type = TM6000_INPUT_TV,
127 .vmux = TM6000_VMUX_VIDEO_B,
128 .amux = TM6000_AMUX_ADC1,
130 .type = TM6000_INPUT_COMPOSITE1,
131 .vmux = TM6000_VMUX_VIDEO_A,
132 .amux = TM6000_AMUX_ADC2,
134 .type = TM6000_INPUT_SVIDEO,
135 .vmux = TM6000_VMUX_VIDEO_AB,
136 .amux = TM6000_AMUX_ADC2,
140 [TM6000_BOARD_GENERIC] = {
141 .name = "Generic tm6000 board",
142 .tuner_type = TUNER_XC2028,
143 .tuner_addr = 0xc2 >> 1,
149 .tuner_reset = TM6000_GPIO_1,
152 .type = TM6000_INPUT_TV,
153 .vmux = TM6000_VMUX_VIDEO_B,
154 .amux = TM6000_AMUX_ADC1,
156 .type = TM6000_INPUT_COMPOSITE1,
157 .vmux = TM6000_VMUX_VIDEO_A,
158 .amux = TM6000_AMUX_ADC2,
160 .type = TM6000_INPUT_SVIDEO,
161 .vmux = TM6000_VMUX_VIDEO_AB,
162 .amux = TM6000_AMUX_ADC2,
166 [TM6010_BOARD_GENERIC] = {
167 .name = "Generic tm6010 board",
169 .tuner_type = TUNER_XC2028,
170 .tuner_addr = 0xc2 >> 1,
171 .demod_addr = 0x1e >> 1,
180 .tuner_reset = TM6010_GPIO_2,
181 .tuner_on = TM6010_GPIO_3,
182 .demod_reset = TM6010_GPIO_1,
183 .demod_on = TM6010_GPIO_4,
184 .power_led = TM6010_GPIO_7,
185 .dvb_led = TM6010_GPIO_5,
189 .type = TM6000_INPUT_TV,
190 .vmux = TM6000_VMUX_VIDEO_B,
191 .amux = TM6000_AMUX_SIF1,
193 .type = TM6000_INPUT_COMPOSITE1,
194 .vmux = TM6000_VMUX_VIDEO_A,
195 .amux = TM6000_AMUX_ADC2,
197 .type = TM6000_INPUT_SVIDEO,
198 .vmux = TM6000_VMUX_VIDEO_AB,
199 .amux = TM6000_AMUX_ADC2,
203 [TM5600_BOARD_10MOONS_UT821] = {
204 .name = "10Moons UT 821",
205 .tuner_type = TUNER_XC2028,
206 .eename = { '1', '0', 'M', 'O', 'O', 'N', 'S', '5', '6', '0', '0', 0xff, 0x45, 0x5b},
210 .tuner_addr = 0xc2 >> 1,
216 .tuner_reset = TM6000_GPIO_1,
219 .type = TM6000_INPUT_TV,
220 .vmux = TM6000_VMUX_VIDEO_B,
221 .amux = TM6000_AMUX_ADC1,
223 .type = TM6000_INPUT_COMPOSITE1,
224 .vmux = TM6000_VMUX_VIDEO_A,
225 .amux = TM6000_AMUX_ADC2,
227 .type = TM6000_INPUT_SVIDEO,
228 .vmux = TM6000_VMUX_VIDEO_AB,
229 .amux = TM6000_AMUX_ADC2,
233 [TM5600_BOARD_10MOONS_UT330] = {
234 .name = "10Moons UT 330",
235 .tuner_type = TUNER_PHILIPS_FQ1216AME_MK4,
236 .tuner_addr = 0xc8 >> 1,
244 .type = TM6000_INPUT_TV,
245 .vmux = TM6000_VMUX_VIDEO_B,
246 .amux = TM6000_AMUX_ADC1,
248 .type = TM6000_INPUT_COMPOSITE1,
249 .vmux = TM6000_VMUX_VIDEO_A,
250 .amux = TM6000_AMUX_ADC2,
252 .type = TM6000_INPUT_SVIDEO,
253 .vmux = TM6000_VMUX_VIDEO_AB,
254 .amux = TM6000_AMUX_ADC2,
258 [TM6000_BOARD_ADSTECH_DUAL_TV] = {
259 .name = "ADSTECH Dual TV USB",
260 .tuner_type = TUNER_XC2028,
261 .tuner_addr = 0xc8 >> 1,
270 .type = TM6000_INPUT_TV,
271 .vmux = TM6000_VMUX_VIDEO_B,
272 .amux = TM6000_AMUX_ADC1,
274 .type = TM6000_INPUT_COMPOSITE1,
275 .vmux = TM6000_VMUX_VIDEO_A,
276 .amux = TM6000_AMUX_ADC2,
278 .type = TM6000_INPUT_SVIDEO,
279 .vmux = TM6000_VMUX_VIDEO_AB,
280 .amux = TM6000_AMUX_ADC2,
284 [TM6000_BOARD_FREECOM_AND_SIMILAR] = {
285 .name = "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
286 .tuner_type = TUNER_XC2028, /* has a XC3028 */
287 .tuner_addr = 0xc2 >> 1,
288 .demod_addr = 0x1e >> 1,
297 .tuner_reset = TM6000_GPIO_4,
300 .type = TM6000_INPUT_TV,
301 .vmux = TM6000_VMUX_VIDEO_B,
302 .amux = TM6000_AMUX_ADC1,
304 .type = TM6000_INPUT_COMPOSITE1,
305 .vmux = TM6000_VMUX_VIDEO_A,
306 .amux = TM6000_AMUX_ADC2,
308 .type = TM6000_INPUT_SVIDEO,
309 .vmux = TM6000_VMUX_VIDEO_AB,
310 .amux = TM6000_AMUX_ADC2,
314 [TM6000_BOARD_ADSTECH_MINI_DUAL_TV] = {
315 .name = "ADSTECH Mini Dual TV USB",
316 .tuner_type = TUNER_XC2028, /* has a XC3028 */
317 .tuner_addr = 0xc8 >> 1,
318 .demod_addr = 0x1e >> 1,
326 .tuner_reset = TM6000_GPIO_4,
329 .type = TM6000_INPUT_TV,
330 .vmux = TM6000_VMUX_VIDEO_B,
331 .amux = TM6000_AMUX_ADC1,
333 .type = TM6000_INPUT_COMPOSITE1,
334 .vmux = TM6000_VMUX_VIDEO_A,
335 .amux = TM6000_AMUX_ADC2,
337 .type = TM6000_INPUT_SVIDEO,
338 .vmux = TM6000_VMUX_VIDEO_AB,
339 .amux = TM6000_AMUX_ADC2,
343 [TM6010_BOARD_HAUPPAUGE_900H] = {
344 .name = "Hauppauge WinTV HVR-900H / WinTV USB2-Stick",
345 .eename = { 'H', 0, 'V', 0, 'R', 0, '9', 0, '0', 0, '0', 0, 'H', 0 },
348 .tuner_type = TUNER_XC2028, /* has a XC3028 */
349 .tuner_addr = 0xc2 >> 1,
350 .demod_addr = 0x1e >> 1,
360 .tuner_reset = TM6010_GPIO_2,
361 .tuner_on = TM6010_GPIO_3,
362 .demod_reset = TM6010_GPIO_1,
363 .demod_on = TM6010_GPIO_4,
364 .power_led = TM6010_GPIO_7,
365 .dvb_led = TM6010_GPIO_5,
369 .type = TM6000_INPUT_TV,
370 .vmux = TM6000_VMUX_VIDEO_B,
371 .amux = TM6000_AMUX_SIF1,
373 .type = TM6000_INPUT_COMPOSITE1,
374 .vmux = TM6000_VMUX_VIDEO_A,
375 .amux = TM6000_AMUX_ADC2,
377 .type = TM6000_INPUT_SVIDEO,
378 .vmux = TM6000_VMUX_VIDEO_AB,
379 .amux = TM6000_AMUX_ADC2,
383 [TM6010_BOARD_BEHOLD_WANDER] = {
384 .name = "Beholder Wander DVB-T/TV/FM USB2.0",
385 .tuner_type = TUNER_XC5000,
386 .tuner_addr = 0xc2 >> 1,
387 .demod_addr = 0x1e >> 1,
400 .tuner_reset = TM6010_GPIO_0,
401 .demod_reset = TM6010_GPIO_1,
402 .power_led = TM6010_GPIO_6,
405 .type = TM6000_INPUT_TV,
406 .vmux = TM6000_VMUX_VIDEO_B,
407 .amux = TM6000_AMUX_SIF1,
409 .type = TM6000_INPUT_COMPOSITE1,
410 .vmux = TM6000_VMUX_VIDEO_A,
411 .amux = TM6000_AMUX_ADC2,
413 .type = TM6000_INPUT_SVIDEO,
414 .vmux = TM6000_VMUX_VIDEO_AB,
415 .amux = TM6000_AMUX_ADC2,
419 .type = TM6000_INPUT_RADIO,
420 .amux = TM6000_AMUX_ADC1,
423 [TM6010_BOARD_BEHOLD_VOYAGER] = {
424 .name = "Beholder Voyager TV/FM USB2.0",
425 .tuner_type = TUNER_XC5000,
426 .tuner_addr = 0xc2 >> 1,
439 .tuner_reset = TM6010_GPIO_0,
440 .power_led = TM6010_GPIO_6,
443 .type = TM6000_INPUT_TV,
444 .vmux = TM6000_VMUX_VIDEO_B,
445 .amux = TM6000_AMUX_SIF1,
447 .type = TM6000_INPUT_COMPOSITE1,
448 .vmux = TM6000_VMUX_VIDEO_A,
449 .amux = TM6000_AMUX_ADC2,
451 .type = TM6000_INPUT_SVIDEO,
452 .vmux = TM6000_VMUX_VIDEO_AB,
453 .amux = TM6000_AMUX_ADC2,
457 .type = TM6000_INPUT_RADIO,
458 .amux = TM6000_AMUX_ADC1,
461 [TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE] = {
462 .name = "Terratec Cinergy Hybrid XE / Cinergy Hybrid-Stick",
463 .tuner_type = TUNER_XC2028, /* has a XC3028 */
464 .tuner_addr = 0xc2 >> 1,
465 .demod_addr = 0x1e >> 1,
475 .tuner_reset = TM6010_GPIO_2,
476 .tuner_on = TM6010_GPIO_3,
477 .demod_reset = TM6010_GPIO_1,
478 .demod_on = TM6010_GPIO_4,
479 .power_led = TM6010_GPIO_7,
480 .dvb_led = TM6010_GPIO_5,
483 .ir_codes = RC_MAP_NEC_TERRATEC_CINERGY_XS,
485 .type = TM6000_INPUT_TV,
486 .vmux = TM6000_VMUX_VIDEO_B,
487 .amux = TM6000_AMUX_SIF1,
489 .type = TM6000_INPUT_COMPOSITE1,
490 .vmux = TM6000_VMUX_VIDEO_A,
491 .amux = TM6000_AMUX_ADC2,
493 .type = TM6000_INPUT_SVIDEO,
494 .vmux = TM6000_VMUX_VIDEO_AB,
495 .amux = TM6000_AMUX_ADC2,
499 [TM5600_BOARD_TERRATEC_GRABSTER] = {
500 .name = "Terratec Grabster AV 150/250 MX",
502 .tuner_type = TUNER_ABSENT,
504 .type = TM6000_INPUT_TV,
505 .vmux = TM6000_VMUX_VIDEO_B,
506 .amux = TM6000_AMUX_ADC1,
508 .type = TM6000_INPUT_COMPOSITE1,
509 .vmux = TM6000_VMUX_VIDEO_A,
510 .amux = TM6000_AMUX_ADC2,
512 .type = TM6000_INPUT_SVIDEO,
513 .vmux = TM6000_VMUX_VIDEO_AB,
514 .amux = TM6000_AMUX_ADC2,
518 [TM6010_BOARD_TWINHAN_TU501] = {
519 .name = "Twinhan TU501(704D1)",
520 .tuner_type = TUNER_XC2028, /* has a XC3028 */
521 .tuner_addr = 0xc2 >> 1,
522 .demod_addr = 0x1e >> 1,
532 .tuner_reset = TM6010_GPIO_2,
533 .tuner_on = TM6010_GPIO_3,
534 .demod_reset = TM6010_GPIO_1,
535 .demod_on = TM6010_GPIO_4,
536 .power_led = TM6010_GPIO_7,
537 .dvb_led = TM6010_GPIO_5,
541 .type = TM6000_INPUT_TV,
542 .vmux = TM6000_VMUX_VIDEO_B,
543 .amux = TM6000_AMUX_SIF1,
545 .type = TM6000_INPUT_COMPOSITE1,
546 .vmux = TM6000_VMUX_VIDEO_A,
547 .amux = TM6000_AMUX_ADC2,
549 .type = TM6000_INPUT_SVIDEO,
550 .vmux = TM6000_VMUX_VIDEO_AB,
551 .amux = TM6000_AMUX_ADC2,
555 [TM6010_BOARD_BEHOLD_WANDER_LITE] = {
556 .name = "Beholder Wander Lite DVB-T/TV/FM USB2.0",
557 .tuner_type = TUNER_XC5000,
558 .tuner_addr = 0xc2 >> 1,
559 .demod_addr = 0x1e >> 1,
572 .tuner_reset = TM6010_GPIO_0,
573 .demod_reset = TM6010_GPIO_1,
574 .power_led = TM6010_GPIO_6,
577 .type = TM6000_INPUT_TV,
578 .vmux = TM6000_VMUX_VIDEO_B,
579 .amux = TM6000_AMUX_SIF1,
583 .type = TM6000_INPUT_RADIO,
584 .amux = TM6000_AMUX_ADC1,
587 [TM6010_BOARD_BEHOLD_VOYAGER_LITE] = {
588 .name = "Beholder Voyager Lite TV/FM USB2.0",
589 .tuner_type = TUNER_XC5000,
590 .tuner_addr = 0xc2 >> 1,
603 .tuner_reset = TM6010_GPIO_0,
604 .power_led = TM6010_GPIO_6,
607 .type = TM6000_INPUT_TV,
608 .vmux = TM6000_VMUX_VIDEO_B,
609 .amux = TM6000_AMUX_SIF1,
613 .type = TM6000_INPUT_RADIO,
614 .amux = TM6000_AMUX_ADC1,
619 /* table of devices that work with this driver */
620 struct usb_device_id tm6000_id_table[] = {
621 { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_GENERIC },
622 { USB_DEVICE(0x6000, 0x0002), .driver_info = TM6010_BOARD_GENERIC },
623 { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
624 { USB_DEVICE(0x14aa, 0x0620), .driver_info = TM6000_BOARD_FREECOM_AND_SIMILAR },
625 { USB_DEVICE(0x06e1, 0xb339), .driver_info = TM6000_BOARD_ADSTECH_MINI_DUAL_TV },
626 { USB_DEVICE(0x2040, 0x6600), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
627 { USB_DEVICE(0x2040, 0x6601), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
628 { USB_DEVICE(0x2040, 0x6610), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
629 { USB_DEVICE(0x2040, 0x6611), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
630 { USB_DEVICE(0x6000, 0xdec0), .driver_info = TM6010_BOARD_BEHOLD_WANDER },
631 { USB_DEVICE(0x6000, 0xdec1), .driver_info = TM6010_BOARD_BEHOLD_VOYAGER },
632 { USB_DEVICE(0x0ccd, 0x0086), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
633 { USB_DEVICE(0x0ccd, 0x00A5), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
634 { USB_DEVICE(0x0ccd, 0x0079), .driver_info = TM5600_BOARD_TERRATEC_GRABSTER },
635 { USB_DEVICE(0x13d3, 0x3240), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
636 { USB_DEVICE(0x13d3, 0x3241), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
637 { USB_DEVICE(0x13d3, 0x3243), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
638 { USB_DEVICE(0x13d3, 0x3264), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
639 { USB_DEVICE(0x6000, 0xdec2), .driver_info = TM6010_BOARD_BEHOLD_WANDER_LITE },
640 { USB_DEVICE(0x6000, 0xdec3), .driver_info = TM6010_BOARD_BEHOLD_VOYAGER_LITE },
644 /* Control power led for show some activity */
645 void tm6000_flash_led(struct tm6000_core *dev, u8 state)
647 /* Power LED unconfigured */
648 if (!dev->gpio.power_led)
653 switch (dev->model) {
654 case TM6010_BOARD_HAUPPAUGE_900H:
655 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
656 case TM6010_BOARD_TWINHAN_TU501:
657 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
658 dev->gpio.power_led, 0x00);
660 case TM6010_BOARD_BEHOLD_WANDER:
661 case TM6010_BOARD_BEHOLD_VOYAGER:
662 case TM6010_BOARD_BEHOLD_WANDER_LITE:
663 case TM6010_BOARD_BEHOLD_VOYAGER_LITE:
664 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
665 dev->gpio.power_led, 0x01);
671 switch (dev->model) {
672 case TM6010_BOARD_HAUPPAUGE_900H:
673 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
674 case TM6010_BOARD_TWINHAN_TU501:
675 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
676 dev->gpio.power_led, 0x01);
678 case TM6010_BOARD_BEHOLD_WANDER:
679 case TM6010_BOARD_BEHOLD_VOYAGER:
680 case TM6010_BOARD_BEHOLD_WANDER_LITE:
681 case TM6010_BOARD_BEHOLD_VOYAGER_LITE:
682 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
683 dev->gpio.power_led, 0x00);
689 /* Tuner callback to provide the proper gpio changes needed for xc5000 */
690 int tm6000_xc5000_callback(void *ptr, int component, int command, int arg)
693 struct tm6000_core *dev = ptr;
695 if (dev->tuner_type != TUNER_XC5000)
699 case XC5000_TUNER_RESET:
700 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
701 dev->gpio.tuner_reset, 0x01);
703 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
704 dev->gpio.tuner_reset, 0x00);
706 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
707 dev->gpio.tuner_reset, 0x01);
712 EXPORT_SYMBOL_GPL(tm6000_xc5000_callback);
714 /* Tuner callback to provide the proper gpio changes needed for xc2028 */
716 int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
719 struct tm6000_core *dev = ptr;
721 if (dev->tuner_type != TUNER_XC2028)
725 case XC2028_RESET_CLK:
726 tm6000_ir_wait(dev, 0);
728 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
731 rc = tm6000_i2c_reset(dev, 10);
733 case XC2028_TUNER_RESET:
734 /* Reset codes during load firmware */
737 /* newer tuner can faster reset */
738 switch (dev->model) {
739 case TM5600_BOARD_10MOONS_UT821:
740 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
741 dev->gpio.tuner_reset, 0x01);
742 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
745 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
746 dev->gpio.tuner_reset, 0x00);
747 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
750 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
751 dev->gpio.tuner_reset, 0x01);
752 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
755 case TM6010_BOARD_HAUPPAUGE_900H:
756 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
757 case TM6010_BOARD_TWINHAN_TU501:
758 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
759 dev->gpio.tuner_reset, 0x01);
761 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
762 dev->gpio.tuner_reset, 0x00);
764 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
765 dev->gpio.tuner_reset, 0x01);
769 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
770 dev->gpio.tuner_reset, 0x00);
772 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
773 dev->gpio.tuner_reset, 0x01);
778 tm6000_ir_wait(dev, 1);
781 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
786 rc = tm6000_i2c_reset(dev, 100);
792 EXPORT_SYMBOL_GPL(tm6000_tuner_callback);
794 int tm6000_cards_setup(struct tm6000_core *dev)
799 * Board-specific initialization sequence. Handles all GPIO
800 * initialization sequences that are board-specific.
801 * Up to now, all found devices use GPIO1 and GPIO4 at the same way.
802 * Probably, they're all based on some reference device. Due to that,
803 * there's a common routine at the end to handle those GPIO's. Devices
804 * that use different pinups or init sequences can just return at
805 * the board-specific session.
807 switch (dev->model) {
808 case TM6010_BOARD_HAUPPAUGE_900H:
809 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
810 case TM6010_BOARD_TWINHAN_TU501:
811 case TM6010_BOARD_GENERIC:
812 /* Turn xceive 3028 on */
813 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.tuner_on, 0x01);
815 /* Turn zarlink zl10353 on */
816 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
818 /* Reset zarlink zl10353 */
819 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
821 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
823 /* Turn zarlink zl10353 off */
824 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x01);
827 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.ir, 0x01);
829 /* Power led on (blue) */
830 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x00);
832 /* DVB led off (orange) */
833 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.dvb_led, 0x01);
835 /* Turn zarlink zl10353 on */
836 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
839 case TM6010_BOARD_BEHOLD_WANDER:
840 case TM6010_BOARD_BEHOLD_WANDER_LITE:
841 /* Power led on (blue) */
842 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
844 /* Reset zarlink zl10353 */
845 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
847 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
850 case TM6010_BOARD_BEHOLD_VOYAGER:
851 case TM6010_BOARD_BEHOLD_VOYAGER_LITE:
852 /* Power led on (blue) */
853 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
861 * Default initialization. Most of the devices seem to use GPIO1
862 * and GPIO4.on the same way, so, this handles the common sequence
863 * used by most devices.
864 * If a device uses a different sequence or different GPIO pins for
865 * reset, just add the code at the board-specific part
868 if (dev->gpio.tuner_reset) {
869 for (i = 0; i < 2; i++) {
870 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
871 dev->gpio.tuner_reset, 0x00);
873 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
877 msleep(10); /* Just to be conservative */
878 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
879 dev->gpio.tuner_reset, 0x01);
881 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
886 printk(KERN_ERR "Tuner reset is not configured\n");
895 static void tm6000_config_tuner(struct tm6000_core *dev)
897 struct tuner_setup tun_setup;
899 /* Load tuner module */
900 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
901 "tuner", dev->tuner_addr, NULL);
903 memset(&tun_setup, 0, sizeof(tun_setup));
904 tun_setup.type = dev->tuner_type;
905 tun_setup.addr = dev->tuner_addr;
907 tun_setup.mode_mask = 0;
908 if (dev->caps.has_tuner)
909 tun_setup.mode_mask |= (T_ANALOG_TV | T_RADIO);
911 switch (dev->tuner_type) {
913 tun_setup.tuner_callback = tm6000_tuner_callback;
916 tun_setup.tuner_callback = tm6000_xc5000_callback;
920 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
922 switch (dev->tuner_type) {
924 struct v4l2_priv_tun_config xc2028_cfg;
925 struct xc2028_ctrl ctl;
927 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
928 memset(&ctl, 0, sizeof(ctl));
931 ctl.read_not_reliable = 0;
933 ctl.demod = XC3028_FE_ZARLINK456;
936 xc2028_cfg.tuner = TUNER_XC2028;
937 xc2028_cfg.priv = &ctl;
939 switch (dev->model) {
940 case TM6010_BOARD_HAUPPAUGE_900H:
941 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
942 case TM6010_BOARD_TWINHAN_TU501:
943 ctl.fname = "xc3028L-v36.fw";
946 if (dev->dev_type == TM6010)
947 ctl.fname = "xc3028-v27.fw";
949 ctl.fname = "xc3028-v24.fw";
952 printk(KERN_INFO "Setting firmware parameters for xc2028\n");
953 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
960 struct v4l2_priv_tun_config xc5000_cfg;
961 struct xc5000_config ctl = {
962 .i2c_address = dev->tuner_addr,
964 .radio_input = XC5000_RADIO_FM1_MONO,
967 xc5000_cfg.tuner = TUNER_XC5000;
968 xc5000_cfg.priv = &ctl;
970 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
975 printk(KERN_INFO "Unknown tuner type. Tuner is not configured.\n");
980 static int fill_board_specific_data(struct tm6000_core *dev)
984 dev->dev_type = tm6000_boards[dev->model].type;
985 dev->tuner_type = tm6000_boards[dev->model].tuner_type;
986 dev->tuner_addr = tm6000_boards[dev->model].tuner_addr;
988 dev->gpio = tm6000_boards[dev->model].gpio;
990 dev->ir_codes = tm6000_boards[dev->model].ir_codes;
992 dev->demod_addr = tm6000_boards[dev->model].demod_addr;
994 dev->caps = tm6000_boards[dev->model].caps;
996 dev->vinput[0] = tm6000_boards[dev->model].vinput[0];
997 dev->vinput[1] = tm6000_boards[dev->model].vinput[1];
998 dev->vinput[2] = tm6000_boards[dev->model].vinput[2];
999 dev->rinput = tm6000_boards[dev->model].rinput;
1001 /* initialize hardware */
1002 rc = tm6000_init(dev);
1006 rc = v4l2_device_register(&dev->udev->dev, &dev->v4l2_dev);
1010 /* initialize hardware */
1011 rc = tm6000_init(dev);
1017 static void use_alternative_detection_method(struct tm6000_core *dev)
1021 if (!dev->eedata_size)
1024 for (i = 0; i < ARRAY_SIZE(tm6000_boards); i++) {
1025 if (!tm6000_boards[i].eename_size)
1027 if (dev->eedata_size < tm6000_boards[i].eename_pos +
1028 tm6000_boards[i].eename_size)
1031 if (!memcmp(&dev->eedata[tm6000_boards[i].eename_pos],
1032 tm6000_boards[i].eename,
1033 tm6000_boards[i].eename_size)) {
1039 printk(KERN_INFO "Device has eeprom but is currently unknown\n");
1045 printk(KERN_INFO "Device identified via eeprom as %s (type = %d)\n",
1046 tm6000_boards[model].name, model);
1049 static int tm6000_init_dev(struct tm6000_core *dev)
1051 struct v4l2_frequency f;
1054 mutex_init(&dev->lock);
1055 mutex_lock(&dev->lock);
1057 if (!is_generic(dev->model)) {
1058 rc = fill_board_specific_data(dev);
1062 /* register i2c bus */
1063 rc = tm6000_i2c_register(dev);
1067 /* register i2c bus */
1068 rc = tm6000_i2c_register(dev);
1072 use_alternative_detection_method(dev);
1074 rc = fill_board_specific_data(dev);
1079 /* Default values for STD and resolutions */
1082 dev->norm = V4L2_STD_PAL_M;
1084 /* Configure tuner */
1085 tm6000_config_tuner(dev);
1087 /* Set video standard */
1088 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
1090 /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
1092 f.type = V4L2_TUNER_ANALOG_TV;
1093 f.frequency = 3092; /* 193.25 MHz */
1094 dev->freq = f.frequency;
1095 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
1097 if (dev->caps.has_tda9874)
1098 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
1099 "tvaudio", I2C_ADDR_TDA9874, NULL);
1101 /* register and initialize V4L2 */
1102 rc = tm6000_v4l2_register(dev);
1106 tm6000_add_into_devlist(dev);
1107 tm6000_init_extension(dev);
1109 tm6000_ir_init(dev);
1111 mutex_unlock(&dev->lock);
1115 mutex_unlock(&dev->lock);
1119 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
1120 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
1122 static void get_max_endpoint(struct usb_device *udev,
1123 struct usb_host_interface *alt,
1125 struct usb_host_endpoint *curr_e,
1126 struct tm6000_endpoint *tm_ep)
1128 u16 tmp = le16_to_cpu(curr_e->desc.wMaxPacketSize);
1129 unsigned int size = tmp & 0x7ff;
1131 if (udev->speed == USB_SPEED_HIGH)
1132 size = size * hb_mult(tmp);
1134 if (size > tm_ep->maxsize) {
1135 tm_ep->endp = curr_e;
1136 tm_ep->maxsize = size;
1137 tm_ep->bInterfaceNumber = alt->desc.bInterfaceNumber;
1138 tm_ep->bAlternateSetting = alt->desc.bAlternateSetting;
1140 printk(KERN_INFO "tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
1141 msgtype, curr_e->desc.bEndpointAddress,
1147 * tm6000_usb_probe()
1148 * checks for supported devices
1150 static int tm6000_usb_probe(struct usb_interface *interface,
1151 const struct usb_device_id *id)
1153 struct usb_device *usbdev;
1154 struct tm6000_core *dev = NULL;
1159 usbdev = usb_get_dev(interface_to_usbdev(interface));
1161 /* Selects the proper interface */
1162 rc = usb_set_interface(usbdev, 0, 1);
1166 /* Check to see next free device and mark as used */
1167 nr = find_first_zero_bit(&tm6000_devused, TM6000_MAXBOARDS);
1168 if (nr >= TM6000_MAXBOARDS) {
1169 printk(KERN_ERR "tm6000: Supports only %i tm60xx boards.\n", TM6000_MAXBOARDS);
1170 usb_put_dev(usbdev);
1174 /* Create and initialize dev struct */
1175 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1177 printk(KERN_ERR "tm6000" ": out of memory!\n");
1178 usb_put_dev(usbdev);
1181 spin_lock_init(&dev->slock);
1183 /* Increment usage count */
1184 tm6000_devused |= 1<<nr;
1185 snprintf(dev->name, 29, "tm6000 #%d", nr);
1187 dev->model = id->driver_info;
1188 if ((card[nr] >= 0) && (card[nr] < ARRAY_SIZE(tm6000_boards)))
1189 dev->model = card[nr];
1194 switch (usbdev->speed) {
1198 case USB_SPEED_UNKNOWN:
1199 case USB_SPEED_FULL:
1202 case USB_SPEED_HIGH:
1212 for (i = 0; i < interface->num_altsetting; i++) {
1215 for (ep = 0; ep < interface->altsetting[i].desc.bNumEndpoints; ep++) {
1216 struct usb_host_endpoint *e;
1219 e = &interface->altsetting[i].endpoint[ep];
1221 dir_out = ((e->desc.bEndpointAddress &
1222 USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
1224 printk(KERN_INFO "tm6000: alt %d, interface %i, class %i\n",
1226 interface->altsetting[i].desc.bInterfaceNumber,
1227 interface->altsetting[i].desc.bInterfaceClass);
1229 switch (e->desc.bmAttributes) {
1230 case USB_ENDPOINT_XFER_BULK:
1232 get_max_endpoint(usbdev,
1233 &interface->altsetting[i],
1237 get_max_endpoint(usbdev,
1238 &interface->altsetting[i],
1243 case USB_ENDPOINT_XFER_ISOC:
1245 get_max_endpoint(usbdev,
1246 &interface->altsetting[i],
1250 get_max_endpoint(usbdev,
1251 &interface->altsetting[i],
1256 case USB_ENDPOINT_XFER_INT:
1258 get_max_endpoint(usbdev,
1259 &interface->altsetting[i],
1263 get_max_endpoint(usbdev,
1264 &interface->altsetting[i],
1274 printk(KERN_INFO "tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
1276 le16_to_cpu(dev->udev->descriptor.idVendor),
1277 le16_to_cpu(dev->udev->descriptor.idProduct),
1278 interface->altsetting->desc.bInterfaceNumber);
1280 /* check if the the device has the iso in endpoint at the correct place */
1281 if (!dev->isoc_in.endp) {
1282 printk(KERN_ERR "tm6000: probing error: no IN ISOC endpoint!\n");
1288 /* save our data pointer in this interface device */
1289 usb_set_intfdata(interface, dev);
1291 printk(KERN_INFO "tm6000: Found %s\n", tm6000_boards[dev->model].name);
1293 rc = tm6000_init_dev(dev);
1301 printk(KERN_ERR "tm6000: Error %d while registering\n", rc);
1303 tm6000_devused &= ~(1<<nr);
1304 usb_put_dev(usbdev);
1311 * tm6000_usb_disconnect()
1312 * called when the device gets diconencted
1313 * video device will be unregistered on v4l2_close in case it is still open
1315 static void tm6000_usb_disconnect(struct usb_interface *interface)
1317 struct tm6000_core *dev = usb_get_intfdata(interface);
1318 usb_set_intfdata(interface, NULL);
1323 printk(KERN_INFO "tm6000: disconnecting %s\n", dev->name);
1325 tm6000_ir_fini(dev);
1327 if (dev->gpio.power_led) {
1328 switch (dev->model) {
1329 case TM6010_BOARD_HAUPPAUGE_900H:
1330 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
1331 case TM6010_BOARD_TWINHAN_TU501:
1333 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
1334 dev->gpio.power_led, 0x01);
1337 case TM6010_BOARD_BEHOLD_WANDER:
1338 case TM6010_BOARD_BEHOLD_VOYAGER:
1339 case TM6010_BOARD_BEHOLD_WANDER_LITE:
1340 case TM6010_BOARD_BEHOLD_VOYAGER_LITE:
1342 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
1343 dev->gpio.power_led, 0x00);
1348 tm6000_v4l2_unregister(dev);
1350 tm6000_i2c_unregister(dev);
1352 v4l2_device_unregister(&dev->v4l2_dev);
1354 dev->state |= DEV_DISCONNECTED;
1356 usb_put_dev(dev->udev);
1358 tm6000_close_extension(dev);
1359 tm6000_remove_from_devlist(dev);
1364 static struct usb_driver tm6000_usb_driver = {
1366 .probe = tm6000_usb_probe,
1367 .disconnect = tm6000_usb_disconnect,
1368 .id_table = tm6000_id_table,
1371 static int __init tm6000_module_init(void)
1375 printk(KERN_INFO "tm6000" " v4l2 driver version %d.%d.%d loaded\n",
1376 (TM6000_VERSION >> 16) & 0xff,
1377 (TM6000_VERSION >> 8) & 0xff, TM6000_VERSION & 0xff);
1379 /* register this driver with the USB subsystem */
1380 result = usb_register(&tm6000_usb_driver);
1382 printk(KERN_ERR "tm6000"
1383 " usb_register failed. Error number %d.\n", result);
1388 static void __exit tm6000_module_exit(void)
1390 /* deregister at USB subsystem */
1391 usb_deregister(&tm6000_usb_driver);
1394 module_init(tm6000_module_init);
1395 module_exit(tm6000_module_exit);
1397 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000/TM6010 USB2 adapter");
1398 MODULE_AUTHOR("Mauro Carvalho Chehab");
1399 MODULE_LICENSE("GPL");