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/slab.h>
27 #include <media/v4l2-common.h>
28 #include <media/tuner.h>
29 #include <media/tvaudio.h>
30 #include <media/i2c-addr.h>
31 #include <media/rc-map.h>
34 #include "tm6000-regs.h"
35 #include "tuner-xc2028.h"
38 #define TM6000_BOARD_UNKNOWN 0
39 #define TM5600_BOARD_GENERIC 1
40 #define TM6000_BOARD_GENERIC 2
41 #define TM6010_BOARD_GENERIC 3
42 #define TM5600_BOARD_10MOONS_UT821 4
43 #define TM5600_BOARD_10MOONS_UT330 5
44 #define TM6000_BOARD_ADSTECH_DUAL_TV 6
45 #define TM6000_BOARD_FREECOM_AND_SIMILAR 7
46 #define TM6000_BOARD_ADSTECH_MINI_DUAL_TV 8
47 #define TM6010_BOARD_HAUPPAUGE_900H 9
48 #define TM6010_BOARD_BEHOLD_WANDER 10
49 #define TM6010_BOARD_BEHOLD_VOYAGER 11
50 #define TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE 12
51 #define TM6010_BOARD_TWINHAN_TU501 13
52 #define TM6010_BOARD_BEHOLD_WANDER_LITE 14
53 #define TM6010_BOARD_BEHOLD_VOYAGER_LITE 15
54 #define TM5600_BOARD_TERRATEC_GRABSTER 16
56 #define is_generic(model) ((model == TM6000_BOARD_UNKNOWN) || \
57 (model == TM5600_BOARD_GENERIC) || \
58 (model == TM6000_BOARD_GENERIC) || \
59 (model == TM6010_BOARD_GENERIC))
61 #define TM6000_MAXBOARDS 16
62 static unsigned int card
[] = {[0 ... (TM6000_MAXBOARDS
- 1)] = UNSET
};
64 module_param_array(card
, int, NULL
, 0444);
66 static unsigned long tm6000_devused
;
71 char eename
[16]; /* EEPROM name */
72 unsigned eename_size
; /* size of EEPROM name */
73 unsigned eename_pos
; /* Position where it appears at ROM */
75 struct tm6000_capabilities caps
;
77 enum tm6000_devtype type
; /* variant of the chipset */
78 int tuner_type
; /* type of the tuner */
79 int tuner_addr
; /* tuner address */
80 int demod_addr
; /* demodulator address */
82 struct tm6000_gpio gpio
;
84 struct tm6000_input vinput
[3];
85 struct tm6000_input rinput
;
90 struct tm6000_board tm6000_boards
[] = {
91 [TM6000_BOARD_UNKNOWN
] = {
92 .name
= "Unknown tm6000 video grabber",
98 .tuner_reset
= TM6000_GPIO_1
,
101 .type
= TM6000_INPUT_TV
,
102 .vmux
= TM6000_VMUX_VIDEO_B
,
103 .amux
= TM6000_AMUX_ADC1
,
105 .type
= TM6000_INPUT_COMPOSITE1
,
106 .vmux
= TM6000_VMUX_VIDEO_A
,
107 .amux
= TM6000_AMUX_ADC2
,
109 .type
= TM6000_INPUT_SVIDEO
,
110 .vmux
= TM6000_VMUX_VIDEO_AB
,
111 .amux
= TM6000_AMUX_ADC2
,
115 [TM5600_BOARD_GENERIC
] = {
116 .name
= "Generic tm5600 board",
118 .tuner_type
= TUNER_XC2028
,
119 .tuner_addr
= 0xc2 >> 1,
125 .tuner_reset
= TM6000_GPIO_1
,
128 .type
= TM6000_INPUT_TV
,
129 .vmux
= TM6000_VMUX_VIDEO_B
,
130 .amux
= TM6000_AMUX_ADC1
,
132 .type
= TM6000_INPUT_COMPOSITE1
,
133 .vmux
= TM6000_VMUX_VIDEO_A
,
134 .amux
= TM6000_AMUX_ADC2
,
136 .type
= TM6000_INPUT_SVIDEO
,
137 .vmux
= TM6000_VMUX_VIDEO_AB
,
138 .amux
= TM6000_AMUX_ADC2
,
142 [TM6000_BOARD_GENERIC
] = {
143 .name
= "Generic tm6000 board",
144 .tuner_type
= TUNER_XC2028
,
145 .tuner_addr
= 0xc2 >> 1,
151 .tuner_reset
= TM6000_GPIO_1
,
154 .type
= TM6000_INPUT_TV
,
155 .vmux
= TM6000_VMUX_VIDEO_B
,
156 .amux
= TM6000_AMUX_ADC1
,
158 .type
= TM6000_INPUT_COMPOSITE1
,
159 .vmux
= TM6000_VMUX_VIDEO_A
,
160 .amux
= TM6000_AMUX_ADC2
,
162 .type
= TM6000_INPUT_SVIDEO
,
163 .vmux
= TM6000_VMUX_VIDEO_AB
,
164 .amux
= TM6000_AMUX_ADC2
,
168 [TM6010_BOARD_GENERIC
] = {
169 .name
= "Generic tm6010 board",
171 .tuner_type
= TUNER_XC2028
,
172 .tuner_addr
= 0xc2 >> 1,
173 .demod_addr
= 0x1e >> 1,
182 .tuner_reset
= TM6010_GPIO_2
,
183 .tuner_on
= TM6010_GPIO_3
,
184 .demod_reset
= TM6010_GPIO_1
,
185 .demod_on
= TM6010_GPIO_4
,
186 .power_led
= TM6010_GPIO_7
,
187 .dvb_led
= TM6010_GPIO_5
,
191 .type
= TM6000_INPUT_TV
,
192 .vmux
= TM6000_VMUX_VIDEO_B
,
193 .amux
= TM6000_AMUX_SIF1
,
195 .type
= TM6000_INPUT_COMPOSITE1
,
196 .vmux
= TM6000_VMUX_VIDEO_A
,
197 .amux
= TM6000_AMUX_ADC2
,
199 .type
= TM6000_INPUT_SVIDEO
,
200 .vmux
= TM6000_VMUX_VIDEO_AB
,
201 .amux
= TM6000_AMUX_ADC2
,
205 [TM5600_BOARD_10MOONS_UT821
] = {
206 .name
= "10Moons UT 821",
207 .tuner_type
= TUNER_XC2028
,
208 .eename
= { '1', '0', 'M', 'O', 'O', 'N', 'S', '5', '6', '0', '0', 0xff, 0x45, 0x5b},
212 .tuner_addr
= 0xc2 >> 1,
218 .tuner_reset
= TM6000_GPIO_1
,
221 .type
= TM6000_INPUT_TV
,
222 .vmux
= TM6000_VMUX_VIDEO_B
,
223 .amux
= TM6000_AMUX_ADC1
,
225 .type
= TM6000_INPUT_COMPOSITE1
,
226 .vmux
= TM6000_VMUX_VIDEO_A
,
227 .amux
= TM6000_AMUX_ADC2
,
229 .type
= TM6000_INPUT_SVIDEO
,
230 .vmux
= TM6000_VMUX_VIDEO_AB
,
231 .amux
= TM6000_AMUX_ADC2
,
235 [TM5600_BOARD_10MOONS_UT330
] = {
236 .name
= "10Moons UT 330",
237 .tuner_type
= TUNER_PHILIPS_FQ1216AME_MK4
,
238 .tuner_addr
= 0xc8 >> 1,
246 .type
= TM6000_INPUT_TV
,
247 .vmux
= TM6000_VMUX_VIDEO_B
,
248 .amux
= TM6000_AMUX_ADC1
,
250 .type
= TM6000_INPUT_COMPOSITE1
,
251 .vmux
= TM6000_VMUX_VIDEO_A
,
252 .amux
= TM6000_AMUX_ADC2
,
254 .type
= TM6000_INPUT_SVIDEO
,
255 .vmux
= TM6000_VMUX_VIDEO_AB
,
256 .amux
= TM6000_AMUX_ADC2
,
260 [TM6000_BOARD_ADSTECH_DUAL_TV
] = {
261 .name
= "ADSTECH Dual TV USB",
262 .tuner_type
= TUNER_XC2028
,
263 .tuner_addr
= 0xc8 >> 1,
272 .type
= TM6000_INPUT_TV
,
273 .vmux
= TM6000_VMUX_VIDEO_B
,
274 .amux
= TM6000_AMUX_ADC1
,
276 .type
= TM6000_INPUT_COMPOSITE1
,
277 .vmux
= TM6000_VMUX_VIDEO_A
,
278 .amux
= TM6000_AMUX_ADC2
,
280 .type
= TM6000_INPUT_SVIDEO
,
281 .vmux
= TM6000_VMUX_VIDEO_AB
,
282 .amux
= TM6000_AMUX_ADC2
,
286 [TM6000_BOARD_FREECOM_AND_SIMILAR
] = {
287 .name
= "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
288 .tuner_type
= TUNER_XC2028
, /* has a XC3028 */
289 .tuner_addr
= 0xc2 >> 1,
290 .demod_addr
= 0x1e >> 1,
299 .tuner_reset
= TM6000_GPIO_4
,
302 .type
= TM6000_INPUT_TV
,
303 .vmux
= TM6000_VMUX_VIDEO_B
,
304 .amux
= TM6000_AMUX_ADC1
,
306 .type
= TM6000_INPUT_COMPOSITE1
,
307 .vmux
= TM6000_VMUX_VIDEO_A
,
308 .amux
= TM6000_AMUX_ADC2
,
310 .type
= TM6000_INPUT_SVIDEO
,
311 .vmux
= TM6000_VMUX_VIDEO_AB
,
312 .amux
= TM6000_AMUX_ADC2
,
316 [TM6000_BOARD_ADSTECH_MINI_DUAL_TV
] = {
317 .name
= "ADSTECH Mini Dual TV USB",
318 .tuner_type
= TUNER_XC2028
, /* has a XC3028 */
319 .tuner_addr
= 0xc8 >> 1,
320 .demod_addr
= 0x1e >> 1,
328 .tuner_reset
= TM6000_GPIO_4
,
331 .type
= TM6000_INPUT_TV
,
332 .vmux
= TM6000_VMUX_VIDEO_B
,
333 .amux
= TM6000_AMUX_ADC1
,
335 .type
= TM6000_INPUT_COMPOSITE1
,
336 .vmux
= TM6000_VMUX_VIDEO_A
,
337 .amux
= TM6000_AMUX_ADC2
,
339 .type
= TM6000_INPUT_SVIDEO
,
340 .vmux
= TM6000_VMUX_VIDEO_AB
,
341 .amux
= TM6000_AMUX_ADC2
,
345 [TM6010_BOARD_HAUPPAUGE_900H
] = {
346 .name
= "Hauppauge WinTV HVR-900H / WinTV USB2-Stick",
347 .eename
= { 'H', 0, 'V', 0, 'R', 0, '9', 0, '0', 0, '0', 0, 'H', 0 },
350 .tuner_type
= TUNER_XC2028
, /* has a XC3028 */
351 .tuner_addr
= 0xc2 >> 1,
352 .demod_addr
= 0x1e >> 1,
362 .tuner_reset
= TM6010_GPIO_2
,
363 .tuner_on
= TM6010_GPIO_3
,
364 .demod_reset
= TM6010_GPIO_1
,
365 .demod_on
= TM6010_GPIO_4
,
366 .power_led
= TM6010_GPIO_7
,
367 .dvb_led
= TM6010_GPIO_5
,
371 .type
= TM6000_INPUT_TV
,
372 .vmux
= TM6000_VMUX_VIDEO_B
,
373 .amux
= TM6000_AMUX_SIF1
,
375 .type
= TM6000_INPUT_COMPOSITE1
,
376 .vmux
= TM6000_VMUX_VIDEO_A
,
377 .amux
= TM6000_AMUX_ADC2
,
379 .type
= TM6000_INPUT_SVIDEO
,
380 .vmux
= TM6000_VMUX_VIDEO_AB
,
381 .amux
= TM6000_AMUX_ADC2
,
385 [TM6010_BOARD_BEHOLD_WANDER
] = {
386 .name
= "Beholder Wander DVB-T/TV/FM USB2.0",
387 .tuner_type
= TUNER_XC5000
,
388 .tuner_addr
= 0xc2 >> 1,
389 .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,
437 .tuner_reset
= TM6010_GPIO_0
,
438 .power_led
= TM6010_GPIO_6
,
441 .type
= TM6000_INPUT_TV
,
442 .vmux
= TM6000_VMUX_VIDEO_B
,
443 .amux
= TM6000_AMUX_SIF1
,
445 .type
= TM6000_INPUT_COMPOSITE1
,
446 .vmux
= TM6000_VMUX_VIDEO_A
,
447 .amux
= TM6000_AMUX_ADC2
,
449 .type
= TM6000_INPUT_SVIDEO
,
450 .vmux
= TM6000_VMUX_VIDEO_AB
,
451 .amux
= TM6000_AMUX_ADC2
,
455 .type
= TM6000_INPUT_RADIO
,
456 .amux
= TM6000_AMUX_ADC1
,
459 [TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
] = {
460 .name
= "Terratec Cinergy Hybrid XE / Cinergy Hybrid-Stick",
461 .tuner_type
= TUNER_XC2028
, /* has a XC3028 */
462 .tuner_addr
= 0xc2 >> 1,
463 .demod_addr
= 0x1e >> 1,
473 .tuner_reset
= TM6010_GPIO_2
,
474 .tuner_on
= TM6010_GPIO_3
,
475 .demod_reset
= TM6010_GPIO_1
,
476 .demod_on
= TM6010_GPIO_4
,
477 .power_led
= TM6010_GPIO_7
,
478 .dvb_led
= TM6010_GPIO_5
,
481 .ir_codes
= RC_MAP_NEC_TERRATEC_CINERGY_XS
,
483 .type
= TM6000_INPUT_TV
,
484 .vmux
= TM6000_VMUX_VIDEO_B
,
485 .amux
= TM6000_AMUX_SIF1
,
487 .type
= TM6000_INPUT_COMPOSITE1
,
488 .vmux
= TM6000_VMUX_VIDEO_A
,
489 .amux
= TM6000_AMUX_ADC2
,
491 .type
= TM6000_INPUT_SVIDEO
,
492 .vmux
= TM6000_VMUX_VIDEO_AB
,
493 .amux
= TM6000_AMUX_ADC2
,
497 [TM5600_BOARD_TERRATEC_GRABSTER
] = {
498 .name
= "Terratec Grabster AV 150/250 MX",
500 .tuner_type
= TUNER_ABSENT
,
502 .type
= TM6000_INPUT_TV
,
503 .vmux
= TM6000_VMUX_VIDEO_B
,
504 .amux
= TM6000_AMUX_ADC1
,
506 .type
= TM6000_INPUT_COMPOSITE1
,
507 .vmux
= TM6000_VMUX_VIDEO_A
,
508 .amux
= TM6000_AMUX_ADC2
,
510 .type
= TM6000_INPUT_SVIDEO
,
511 .vmux
= TM6000_VMUX_VIDEO_AB
,
512 .amux
= TM6000_AMUX_ADC2
,
516 [TM6010_BOARD_TWINHAN_TU501
] = {
517 .name
= "Twinhan TU501(704D1)",
518 .tuner_type
= TUNER_XC2028
, /* has a XC3028 */
519 .tuner_addr
= 0xc2 >> 1,
520 .demod_addr
= 0x1e >> 1,
530 .tuner_reset
= TM6010_GPIO_2
,
531 .tuner_on
= TM6010_GPIO_3
,
532 .demod_reset
= TM6010_GPIO_1
,
533 .demod_on
= TM6010_GPIO_4
,
534 .power_led
= TM6010_GPIO_7
,
535 .dvb_led
= TM6010_GPIO_5
,
539 .type
= TM6000_INPUT_TV
,
540 .vmux
= TM6000_VMUX_VIDEO_B
,
541 .amux
= TM6000_AMUX_SIF1
,
543 .type
= TM6000_INPUT_COMPOSITE1
,
544 .vmux
= TM6000_VMUX_VIDEO_A
,
545 .amux
= TM6000_AMUX_ADC2
,
547 .type
= TM6000_INPUT_SVIDEO
,
548 .vmux
= TM6000_VMUX_VIDEO_AB
,
549 .amux
= TM6000_AMUX_ADC2
,
553 [TM6010_BOARD_BEHOLD_WANDER_LITE
] = {
554 .name
= "Beholder Wander Lite DVB-T/TV/FM USB2.0",
555 .tuner_type
= TUNER_XC5000
,
556 .tuner_addr
= 0xc2 >> 1,
557 .demod_addr
= 0x1e >> 1,
568 .tuner_reset
= TM6010_GPIO_0
,
569 .demod_reset
= TM6010_GPIO_1
,
570 .power_led
= TM6010_GPIO_6
,
573 .type
= TM6000_INPUT_TV
,
574 .vmux
= TM6000_VMUX_VIDEO_B
,
575 .amux
= TM6000_AMUX_SIF1
,
579 .type
= TM6000_INPUT_RADIO
,
580 .amux
= TM6000_AMUX_ADC1
,
583 [TM6010_BOARD_BEHOLD_VOYAGER_LITE
] = {
584 .name
= "Beholder Voyager Lite TV/FM USB2.0",
585 .tuner_type
= TUNER_XC5000
,
586 .tuner_addr
= 0xc2 >> 1,
597 .tuner_reset
= TM6010_GPIO_0
,
598 .power_led
= TM6010_GPIO_6
,
601 .type
= TM6000_INPUT_TV
,
602 .vmux
= TM6000_VMUX_VIDEO_B
,
603 .amux
= TM6000_AMUX_SIF1
,
607 .type
= TM6000_INPUT_RADIO
,
608 .amux
= TM6000_AMUX_ADC1
,
613 /* table of devices that work with this driver */
614 struct usb_device_id tm6000_id_table
[] = {
615 { USB_DEVICE(0x6000, 0x0001), .driver_info
= TM5600_BOARD_GENERIC
},
616 { USB_DEVICE(0x6000, 0x0002), .driver_info
= TM6010_BOARD_GENERIC
},
617 { USB_DEVICE(0x06e1, 0xf332), .driver_info
= TM6000_BOARD_ADSTECH_DUAL_TV
},
618 { USB_DEVICE(0x14aa, 0x0620), .driver_info
= TM6000_BOARD_FREECOM_AND_SIMILAR
},
619 { USB_DEVICE(0x06e1, 0xb339), .driver_info
= TM6000_BOARD_ADSTECH_MINI_DUAL_TV
},
620 { USB_DEVICE(0x2040, 0x6600), .driver_info
= TM6010_BOARD_HAUPPAUGE_900H
},
621 { USB_DEVICE(0x2040, 0x6601), .driver_info
= TM6010_BOARD_HAUPPAUGE_900H
},
622 { USB_DEVICE(0x2040, 0x6610), .driver_info
= TM6010_BOARD_HAUPPAUGE_900H
},
623 { USB_DEVICE(0x2040, 0x6611), .driver_info
= TM6010_BOARD_HAUPPAUGE_900H
},
624 { USB_DEVICE(0x6000, 0xdec0), .driver_info
= TM6010_BOARD_BEHOLD_WANDER
},
625 { USB_DEVICE(0x6000, 0xdec1), .driver_info
= TM6010_BOARD_BEHOLD_VOYAGER
},
626 { USB_DEVICE(0x0ccd, 0x0086), .driver_info
= TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
},
627 { USB_DEVICE(0x0ccd, 0x00A5), .driver_info
= TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
},
628 { USB_DEVICE(0x0ccd, 0x0079), .driver_info
= TM5600_BOARD_TERRATEC_GRABSTER
},
629 { USB_DEVICE(0x13d3, 0x3240), .driver_info
= TM6010_BOARD_TWINHAN_TU501
},
630 { USB_DEVICE(0x13d3, 0x3241), .driver_info
= TM6010_BOARD_TWINHAN_TU501
},
631 { USB_DEVICE(0x13d3, 0x3243), .driver_info
= TM6010_BOARD_TWINHAN_TU501
},
632 { USB_DEVICE(0x13d3, 0x3264), .driver_info
= TM6010_BOARD_TWINHAN_TU501
},
633 { USB_DEVICE(0x6000, 0xdec2), .driver_info
= TM6010_BOARD_BEHOLD_WANDER_LITE
},
634 { USB_DEVICE(0x6000, 0xdec3), .driver_info
= TM6010_BOARD_BEHOLD_VOYAGER_LITE
},
638 /* Control power led for show some activity */
639 void tm6000_flash_led(struct tm6000_core
*dev
, u8 state
)
641 /* Power LED unconfigured */
642 if (!dev
->gpio
.power_led
)
647 switch (dev
->model
) {
648 case TM6010_BOARD_HAUPPAUGE_900H
:
649 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
650 case TM6010_BOARD_TWINHAN_TU501
:
651 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
652 dev
->gpio
.power_led
, 0x00);
654 case TM6010_BOARD_BEHOLD_WANDER
:
655 case TM6010_BOARD_BEHOLD_VOYAGER
:
656 case TM6010_BOARD_BEHOLD_WANDER_LITE
:
657 case TM6010_BOARD_BEHOLD_VOYAGER_LITE
:
658 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
659 dev
->gpio
.power_led
, 0x01);
665 switch (dev
->model
) {
666 case TM6010_BOARD_HAUPPAUGE_900H
:
667 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
668 case TM6010_BOARD_TWINHAN_TU501
:
669 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
670 dev
->gpio
.power_led
, 0x01);
672 case TM6010_BOARD_BEHOLD_WANDER
:
673 case TM6010_BOARD_BEHOLD_VOYAGER
:
674 case TM6010_BOARD_BEHOLD_WANDER_LITE
:
675 case TM6010_BOARD_BEHOLD_VOYAGER_LITE
:
676 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
677 dev
->gpio
.power_led
, 0x00);
683 /* Tuner callback to provide the proper gpio changes needed for xc5000 */
684 int tm6000_xc5000_callback(void *ptr
, int component
, int command
, int arg
)
687 struct tm6000_core
*dev
= ptr
;
689 if (dev
->tuner_type
!= TUNER_XC5000
)
693 case XC5000_TUNER_RESET
:
694 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
695 dev
->gpio
.tuner_reset
, 0x01);
697 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
698 dev
->gpio
.tuner_reset
, 0x00);
700 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
701 dev
->gpio
.tuner_reset
, 0x01);
706 EXPORT_SYMBOL_GPL(tm6000_xc5000_callback
);
708 /* Tuner callback to provide the proper gpio changes needed for xc2028 */
710 int tm6000_tuner_callback(void *ptr
, int component
, int command
, int arg
)
713 struct tm6000_core
*dev
= ptr
;
715 if (dev
->tuner_type
!= TUNER_XC2028
)
719 case XC2028_RESET_CLK
:
720 tm6000_ir_wait(dev
, 0);
722 tm6000_set_reg(dev
, REQ_04_EN_DISABLE_MCU_INT
,
725 rc
= tm6000_i2c_reset(dev
, 10);
727 case XC2028_TUNER_RESET
:
728 /* Reset codes during load firmware */
731 /* newer tuner can faster reset */
732 switch (dev
->model
) {
733 case TM5600_BOARD_10MOONS_UT821
:
734 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
735 dev
->gpio
.tuner_reset
, 0x01);
736 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
739 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
740 dev
->gpio
.tuner_reset
, 0x00);
741 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
744 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
745 dev
->gpio
.tuner_reset
, 0x01);
746 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
749 case TM6010_BOARD_HAUPPAUGE_900H
:
750 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
751 case TM6010_BOARD_TWINHAN_TU501
:
752 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
753 dev
->gpio
.tuner_reset
, 0x01);
755 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
756 dev
->gpio
.tuner_reset
, 0x00);
758 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
759 dev
->gpio
.tuner_reset
, 0x01);
763 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
764 dev
->gpio
.tuner_reset
, 0x00);
766 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
767 dev
->gpio
.tuner_reset
, 0x01);
772 tm6000_ir_wait(dev
, 1);
775 tm6000_set_reg(dev
, REQ_04_EN_DISABLE_MCU_INT
,
780 rc
= tm6000_i2c_reset(dev
, 100);
786 EXPORT_SYMBOL_GPL(tm6000_tuner_callback
);
788 int tm6000_cards_setup(struct tm6000_core
*dev
)
793 * Board-specific initialization sequence. Handles all GPIO
794 * initialization sequences that are board-specific.
795 * Up to now, all found devices use GPIO1 and GPIO4 at the same way.
796 * Probably, they're all based on some reference device. Due to that,
797 * there's a common routine at the end to handle those GPIO's. Devices
798 * that use different pinups or init sequences can just return at
799 * the board-specific session.
801 switch (dev
->model
) {
802 case TM6010_BOARD_HAUPPAUGE_900H
:
803 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
804 case TM6010_BOARD_TWINHAN_TU501
:
805 case TM6010_BOARD_GENERIC
:
806 /* Turn xceive 3028 on */
807 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.tuner_on
, 0x01);
809 /* Turn zarlink zl10353 on */
810 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_on
, 0x00);
812 /* Reset zarlink zl10353 */
813 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_reset
, 0x00);
815 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_reset
, 0x01);
817 /* Turn zarlink zl10353 off */
818 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_on
, 0x01);
821 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.ir
, 0x01);
823 /* Power led on (blue) */
824 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.power_led
, 0x00);
826 /* DVB led off (orange) */
827 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.dvb_led
, 0x01);
829 /* Turn zarlink zl10353 on */
830 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_on
, 0x00);
833 case TM6010_BOARD_BEHOLD_WANDER
:
834 case TM6010_BOARD_BEHOLD_WANDER_LITE
:
835 /* Power led on (blue) */
836 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.power_led
, 0x01);
838 /* Reset zarlink zl10353 */
839 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_reset
, 0x00);
841 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_reset
, 0x01);
844 case TM6010_BOARD_BEHOLD_VOYAGER
:
845 case TM6010_BOARD_BEHOLD_VOYAGER_LITE
:
846 /* Power led on (blue) */
847 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.power_led
, 0x01);
855 * Default initialization. Most of the devices seem to use GPIO1
856 * and GPIO4.on the same way, so, this handles the common sequence
857 * used by most devices.
858 * If a device uses a different sequence or different GPIO pins for
859 * reset, just add the code at the board-specific part
862 if (dev
->gpio
.tuner_reset
) {
863 for (i
= 0; i
< 2; i
++) {
864 rc
= tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
865 dev
->gpio
.tuner_reset
, 0x00);
867 printk(KERN_ERR
"Error %i doing tuner reset\n", rc
);
871 msleep(10); /* Just to be conservative */
872 rc
= tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
873 dev
->gpio
.tuner_reset
, 0x01);
875 printk(KERN_ERR
"Error %i doing tuner reset\n", rc
);
880 printk(KERN_ERR
"Tuner reset is not configured\n");
889 static void tm6000_config_tuner(struct tm6000_core
*dev
)
891 struct tuner_setup tun_setup
;
893 /* Load tuner module */
894 v4l2_i2c_new_subdev(&dev
->v4l2_dev
, &dev
->i2c_adap
,
895 "tuner", dev
->tuner_addr
, NULL
);
897 memset(&tun_setup
, 0, sizeof(tun_setup
));
898 tun_setup
.type
= dev
->tuner_type
;
899 tun_setup
.addr
= dev
->tuner_addr
;
901 tun_setup
.mode_mask
= 0;
902 if (dev
->caps
.has_tuner
)
903 tun_setup
.mode_mask
|= (T_ANALOG_TV
| T_RADIO
);
905 switch (dev
->tuner_type
) {
907 tun_setup
.tuner_callback
= tm6000_tuner_callback
;
910 tun_setup
.tuner_callback
= tm6000_xc5000_callback
;
914 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_type_addr
, &tun_setup
);
916 switch (dev
->tuner_type
) {
918 struct v4l2_priv_tun_config xc2028_cfg
;
919 struct xc2028_ctrl ctl
;
921 memset(&xc2028_cfg
, 0, sizeof(xc2028_cfg
));
922 memset(&ctl
, 0, sizeof(ctl
));
924 ctl
.demod
= XC3028_FE_ZARLINK456
;
926 xc2028_cfg
.tuner
= TUNER_XC2028
;
927 xc2028_cfg
.priv
= &ctl
;
929 switch (dev
->model
) {
930 case TM6010_BOARD_HAUPPAUGE_900H
:
931 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
932 case TM6010_BOARD_TWINHAN_TU501
:
933 ctl
.fname
= "xc3028L-v36.fw";
936 if (dev
->dev_type
== TM6010
)
937 ctl
.fname
= "xc3028-v27.fw";
939 ctl
.fname
= "xc3028-v24.fw";
942 printk(KERN_INFO
"Setting firmware parameters for xc2028\n");
943 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_config
,
950 struct v4l2_priv_tun_config xc5000_cfg
;
951 struct xc5000_config ctl
= {
952 .i2c_address
= dev
->tuner_addr
,
954 .radio_input
= XC5000_RADIO_FM1_MONO
,
957 xc5000_cfg
.tuner
= TUNER_XC5000
;
958 xc5000_cfg
.priv
= &ctl
;
960 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_config
,
965 printk(KERN_INFO
"Unknown tuner type. Tuner is not configured.\n");
970 static int fill_board_specific_data(struct tm6000_core
*dev
)
974 dev
->dev_type
= tm6000_boards
[dev
->model
].type
;
975 dev
->tuner_type
= tm6000_boards
[dev
->model
].tuner_type
;
976 dev
->tuner_addr
= tm6000_boards
[dev
->model
].tuner_addr
;
978 dev
->gpio
= tm6000_boards
[dev
->model
].gpio
;
980 dev
->ir_codes
= tm6000_boards
[dev
->model
].ir_codes
;
982 dev
->demod_addr
= tm6000_boards
[dev
->model
].demod_addr
;
984 dev
->caps
= tm6000_boards
[dev
->model
].caps
;
986 dev
->vinput
[0] = tm6000_boards
[dev
->model
].vinput
[0];
987 dev
->vinput
[1] = tm6000_boards
[dev
->model
].vinput
[1];
988 dev
->vinput
[2] = tm6000_boards
[dev
->model
].vinput
[2];
989 dev
->rinput
= tm6000_boards
[dev
->model
].rinput
;
991 /* initialize hardware */
992 rc
= tm6000_init(dev
);
996 return v4l2_device_register(&dev
->udev
->dev
, &dev
->v4l2_dev
);
1000 static void use_alternative_detection_method(struct tm6000_core
*dev
)
1004 if (!dev
->eedata_size
)
1007 for (i
= 0; i
< ARRAY_SIZE(tm6000_boards
); i
++) {
1008 if (!tm6000_boards
[i
].eename_size
)
1010 if (dev
->eedata_size
< tm6000_boards
[i
].eename_pos
+
1011 tm6000_boards
[i
].eename_size
)
1014 if (!memcmp(&dev
->eedata
[tm6000_boards
[i
].eename_pos
],
1015 tm6000_boards
[i
].eename
,
1016 tm6000_boards
[i
].eename_size
)) {
1022 printk(KERN_INFO
"Device has eeprom but is currently unknown\n");
1028 printk(KERN_INFO
"Device identified via eeprom as %s (type = %d)\n",
1029 tm6000_boards
[model
].name
, model
);
1032 static int tm6000_init_dev(struct tm6000_core
*dev
)
1034 struct v4l2_frequency f
;
1037 mutex_init(&dev
->lock
);
1038 mutex_lock(&dev
->lock
);
1040 if (!is_generic(dev
->model
)) {
1041 rc
= fill_board_specific_data(dev
);
1045 /* register i2c bus */
1046 rc
= tm6000_i2c_register(dev
);
1050 /* register i2c bus */
1051 rc
= tm6000_i2c_register(dev
);
1055 use_alternative_detection_method(dev
);
1057 rc
= fill_board_specific_data(dev
);
1062 /* Default values for STD and resolutions */
1065 dev
->norm
= V4L2_STD_PAL_M
;
1067 /* Configure tuner */
1068 tm6000_config_tuner(dev
);
1070 /* Set video standard */
1071 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, s_std
, dev
->norm
);
1073 /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
1075 f
.type
= V4L2_TUNER_ANALOG_TV
;
1076 f
.frequency
= 3092; /* 193.25 MHz */
1077 dev
->freq
= f
.frequency
;
1078 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_frequency
, &f
);
1080 if (dev
->caps
.has_tda9874
)
1081 v4l2_i2c_new_subdev(&dev
->v4l2_dev
, &dev
->i2c_adap
,
1082 "tvaudio", I2C_ADDR_TDA9874
, NULL
);
1084 /* register and initialize V4L2 */
1085 rc
= tm6000_v4l2_register(dev
);
1089 tm6000_add_into_devlist(dev
);
1090 tm6000_init_extension(dev
);
1092 tm6000_ir_init(dev
);
1094 mutex_unlock(&dev
->lock
);
1098 mutex_unlock(&dev
->lock
);
1102 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
1103 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
1105 static void get_max_endpoint(struct usb_device
*udev
,
1106 struct usb_host_interface
*alt
,
1108 struct usb_host_endpoint
*curr_e
,
1109 struct tm6000_endpoint
*tm_ep
)
1111 u16 tmp
= le16_to_cpu(curr_e
->desc
.wMaxPacketSize
);
1112 unsigned int size
= tmp
& 0x7ff;
1114 if (udev
->speed
== USB_SPEED_HIGH
)
1115 size
= size
* hb_mult(tmp
);
1117 if (size
> tm_ep
->maxsize
) {
1118 tm_ep
->endp
= curr_e
;
1119 tm_ep
->maxsize
= size
;
1120 tm_ep
->bInterfaceNumber
= alt
->desc
.bInterfaceNumber
;
1121 tm_ep
->bAlternateSetting
= alt
->desc
.bAlternateSetting
;
1123 printk(KERN_INFO
"tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
1124 msgtype
, curr_e
->desc
.bEndpointAddress
,
1130 * tm6000_usb_probe()
1131 * checks for supported devices
1133 static int tm6000_usb_probe(struct usb_interface
*interface
,
1134 const struct usb_device_id
*id
)
1136 struct usb_device
*usbdev
;
1137 struct tm6000_core
*dev
= NULL
;
1142 usbdev
= usb_get_dev(interface_to_usbdev(interface
));
1144 /* Selects the proper interface */
1145 rc
= usb_set_interface(usbdev
, 0, 1);
1149 /* Check to see next free device and mark as used */
1150 nr
= find_first_zero_bit(&tm6000_devused
, TM6000_MAXBOARDS
);
1151 if (nr
>= TM6000_MAXBOARDS
) {
1152 printk(KERN_ERR
"tm6000: Supports only %i tm60xx boards.\n", TM6000_MAXBOARDS
);
1153 usb_put_dev(usbdev
);
1157 /* Create and initialize dev struct */
1158 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
1160 printk(KERN_ERR
"tm6000" ": out of memory!\n");
1161 usb_put_dev(usbdev
);
1164 spin_lock_init(&dev
->slock
);
1166 /* Increment usage count */
1167 tm6000_devused
|= 1<<nr
;
1168 snprintf(dev
->name
, 29, "tm6000 #%d", nr
);
1170 dev
->model
= id
->driver_info
;
1171 if ((card
[nr
] >= 0) && (card
[nr
] < ARRAY_SIZE(tm6000_boards
)))
1172 dev
->model
= card
[nr
];
1177 switch (usbdev
->speed
) {
1181 case USB_SPEED_UNKNOWN
:
1182 case USB_SPEED_FULL
:
1185 case USB_SPEED_HIGH
:
1195 for (i
= 0; i
< interface
->num_altsetting
; i
++) {
1198 for (ep
= 0; ep
< interface
->altsetting
[i
].desc
.bNumEndpoints
; ep
++) {
1199 struct usb_host_endpoint
*e
;
1202 e
= &interface
->altsetting
[i
].endpoint
[ep
];
1204 dir_out
= ((e
->desc
.bEndpointAddress
&
1205 USB_ENDPOINT_DIR_MASK
) == USB_DIR_OUT
);
1207 printk(KERN_INFO
"tm6000: alt %d, interface %i, class %i\n",
1209 interface
->altsetting
[i
].desc
.bInterfaceNumber
,
1210 interface
->altsetting
[i
].desc
.bInterfaceClass
);
1212 switch (e
->desc
.bmAttributes
) {
1213 case USB_ENDPOINT_XFER_BULK
:
1215 get_max_endpoint(usbdev
,
1216 &interface
->altsetting
[i
],
1220 get_max_endpoint(usbdev
,
1221 &interface
->altsetting
[i
],
1226 case USB_ENDPOINT_XFER_ISOC
:
1228 get_max_endpoint(usbdev
,
1229 &interface
->altsetting
[i
],
1233 get_max_endpoint(usbdev
,
1234 &interface
->altsetting
[i
],
1239 case USB_ENDPOINT_XFER_INT
:
1241 get_max_endpoint(usbdev
,
1242 &interface
->altsetting
[i
],
1246 get_max_endpoint(usbdev
,
1247 &interface
->altsetting
[i
],
1257 printk(KERN_INFO
"tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
1259 le16_to_cpu(dev
->udev
->descriptor
.idVendor
),
1260 le16_to_cpu(dev
->udev
->descriptor
.idProduct
),
1261 interface
->altsetting
->desc
.bInterfaceNumber
);
1263 /* check if the the device has the iso in endpoint at the correct place */
1264 if (!dev
->isoc_in
.endp
) {
1265 printk(KERN_ERR
"tm6000: probing error: no IN ISOC endpoint!\n");
1271 /* save our data pointer in this interface device */
1272 usb_set_intfdata(interface
, dev
);
1274 printk(KERN_INFO
"tm6000: Found %s\n", tm6000_boards
[dev
->model
].name
);
1276 rc
= tm6000_init_dev(dev
);
1284 printk(KERN_ERR
"tm6000: Error %d while registering\n", rc
);
1286 tm6000_devused
&= ~(1<<nr
);
1287 usb_put_dev(usbdev
);
1294 * tm6000_usb_disconnect()
1295 * called when the device gets diconencted
1296 * video device will be unregistered on v4l2_close in case it is still open
1298 static void tm6000_usb_disconnect(struct usb_interface
*interface
)
1300 struct tm6000_core
*dev
= usb_get_intfdata(interface
);
1301 usb_set_intfdata(interface
, NULL
);
1306 printk(KERN_INFO
"tm6000: disconnecting %s\n", dev
->name
);
1308 tm6000_ir_fini(dev
);
1310 if (dev
->gpio
.power_led
) {
1311 switch (dev
->model
) {
1312 case TM6010_BOARD_HAUPPAUGE_900H
:
1313 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
1314 case TM6010_BOARD_TWINHAN_TU501
:
1316 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
1317 dev
->gpio
.power_led
, 0x01);
1320 case TM6010_BOARD_BEHOLD_WANDER
:
1321 case TM6010_BOARD_BEHOLD_VOYAGER
:
1322 case TM6010_BOARD_BEHOLD_WANDER_LITE
:
1323 case TM6010_BOARD_BEHOLD_VOYAGER_LITE
:
1325 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
1326 dev
->gpio
.power_led
, 0x00);
1331 tm6000_v4l2_unregister(dev
);
1333 tm6000_i2c_unregister(dev
);
1335 v4l2_device_unregister(&dev
->v4l2_dev
);
1337 dev
->state
|= DEV_DISCONNECTED
;
1339 usb_put_dev(dev
->udev
);
1341 tm6000_close_extension(dev
);
1342 tm6000_remove_from_devlist(dev
);
1347 static struct usb_driver tm6000_usb_driver
= {
1349 .probe
= tm6000_usb_probe
,
1350 .disconnect
= tm6000_usb_disconnect
,
1351 .id_table
= tm6000_id_table
,
1354 static int __init
tm6000_module_init(void)
1358 printk(KERN_INFO
"tm6000" " v4l2 driver version %d.%d.%d loaded\n",
1359 (TM6000_VERSION
>> 16) & 0xff,
1360 (TM6000_VERSION
>> 8) & 0xff, TM6000_VERSION
& 0xff);
1362 /* register this driver with the USB subsystem */
1363 result
= usb_register(&tm6000_usb_driver
);
1365 printk(KERN_ERR
"tm6000"
1366 " usb_register failed. Error number %d.\n", result
);
1371 static void __exit
tm6000_module_exit(void)
1373 /* deregister at USB subsystem */
1374 usb_deregister(&tm6000_usb_driver
);
1377 module_init(tm6000_module_init
);
1378 module_exit(tm6000_module_exit
);
1380 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000/TM6010 USB2 adapter");
1381 MODULE_AUTHOR("Mauro Carvalho Chehab");
1382 MODULE_LICENSE("GPL");