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
54 #define TM6000_MAXBOARDS 16
55 static unsigned int card
[] = {[0 ... (TM6000_MAXBOARDS
- 1)] = UNSET
};
57 module_param_array(card
, int, NULL
, 0444);
59 static unsigned long tm6000_devused
;
65 struct tm6000_capabilities caps
;
67 enum tm6000_devtype type
; /* variant of the chipset */
68 int tuner_type
; /* type of the tuner */
69 int tuner_addr
; /* tuner address */
70 int demod_addr
; /* demodulator address */
72 struct tm6000_gpio gpio
;
77 struct tm6000_board tm6000_boards
[] = {
78 [TM6000_BOARD_UNKNOWN
] = {
79 .name
= "Unknown tm6000 video grabber",
84 .tuner_reset
= TM6000_GPIO_1
,
87 [TM5600_BOARD_GENERIC
] = {
88 .name
= "Generic tm5600 board",
90 .tuner_type
= TUNER_XC2028
,
91 .tuner_addr
= 0xc2 >> 1,
96 .tuner_reset
= TM6000_GPIO_1
,
99 [TM6000_BOARD_GENERIC
] = {
100 .name
= "Generic tm6000 board",
101 .tuner_type
= TUNER_XC2028
,
102 .tuner_addr
= 0xc2 >> 1,
108 .tuner_reset
= TM6000_GPIO_1
,
111 [TM6010_BOARD_GENERIC
] = {
112 .name
= "Generic tm6010 board",
114 .tuner_type
= TUNER_XC2028
,
115 .tuner_addr
= 0xc2 >> 1,
116 .demod_addr
= 0x1e >> 1,
125 .tuner_reset
= TM6010_GPIO_2
,
126 .tuner_on
= TM6010_GPIO_3
,
127 .demod_reset
= TM6010_GPIO_1
,
128 .demod_on
= TM6010_GPIO_4
,
129 .power_led
= TM6010_GPIO_7
,
130 .dvb_led
= TM6010_GPIO_5
,
134 [TM5600_BOARD_10MOONS_UT821
] = {
135 .name
= "10Moons UT 821",
136 .tuner_type
= TUNER_XC2028
,
138 .tuner_addr
= 0xc2 >> 1,
144 .tuner_reset
= TM6000_GPIO_1
,
147 [TM5600_BOARD_10MOONS_UT330
] = {
148 .name
= "10Moons UT 330",
149 .tuner_type
= TUNER_PHILIPS_FQ1216AME_MK4
,
150 .tuner_addr
= 0xc8 >> 1,
158 [TM6000_BOARD_ADSTECH_DUAL_TV
] = {
159 .name
= "ADSTECH Dual TV USB",
160 .tuner_type
= TUNER_XC2028
,
161 .tuner_addr
= 0xc8 >> 1,
170 [TM6000_BOARD_FREECOM_AND_SIMILAR
] = {
171 .name
= "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
172 .tuner_type
= TUNER_XC2028
, /* has a XC3028 */
173 .tuner_addr
= 0xc2 >> 1,
174 .demod_addr
= 0x1e >> 1,
183 .tuner_reset
= TM6000_GPIO_4
,
186 [TM6000_BOARD_ADSTECH_MINI_DUAL_TV
] = {
187 .name
= "ADSTECH Mini Dual TV USB",
188 .tuner_type
= TUNER_XC2028
, /* has a XC3028 */
189 .tuner_addr
= 0xc8 >> 1,
190 .demod_addr
= 0x1e >> 1,
198 .tuner_reset
= TM6000_GPIO_4
,
201 [TM6010_BOARD_HAUPPAUGE_900H
] = {
202 .name
= "Hauppauge WinTV HVR-900H / WinTV USB2-Stick",
203 .tuner_type
= TUNER_XC2028
, /* has a XC3028 */
204 .tuner_addr
= 0xc2 >> 1,
205 .demod_addr
= 0x1e >> 1,
215 .tuner_reset
= TM6010_GPIO_2
,
216 .tuner_on
= TM6010_GPIO_3
,
217 .demod_reset
= TM6010_GPIO_1
,
218 .demod_on
= TM6010_GPIO_4
,
219 .power_led
= TM6010_GPIO_7
,
220 .dvb_led
= TM6010_GPIO_5
,
224 [TM6010_BOARD_BEHOLD_WANDER
] = {
225 .name
= "Beholder Wander DVB-T/TV/FM USB2.0",
226 .tuner_type
= TUNER_XC5000
,
227 .tuner_addr
= 0xc2 >> 1,
228 .demod_addr
= 0x1e >> 1,
238 .tuner_reset
= TM6010_GPIO_0
,
239 .demod_reset
= TM6010_GPIO_1
,
240 .power_led
= TM6010_GPIO_6
,
243 [TM6010_BOARD_BEHOLD_VOYAGER
] = {
244 .name
= "Beholder Voyager TV/FM USB2.0",
245 .tuner_type
= TUNER_XC5000
,
246 .tuner_addr
= 0xc2 >> 1,
256 .tuner_reset
= TM6010_GPIO_0
,
257 .power_led
= TM6010_GPIO_6
,
260 [TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
] = {
261 .name
= "Terratec Cinergy Hybrid XE / Cinergy Hybrid-Stick",
262 .tuner_type
= TUNER_XC2028
, /* has a XC3028 */
263 .tuner_addr
= 0xc2 >> 1,
264 .demod_addr
= 0x1e >> 1,
274 .tuner_reset
= TM6010_GPIO_2
,
275 .tuner_on
= TM6010_GPIO_3
,
276 .demod_reset
= TM6010_GPIO_1
,
277 .demod_on
= TM6010_GPIO_4
,
278 .power_led
= TM6010_GPIO_7
,
279 .dvb_led
= TM6010_GPIO_5
,
282 .ir_codes
= RC_MAP_NEC_TERRATEC_CINERGY_XS
,
284 [TM6010_BOARD_TWINHAN_TU501
] = {
285 .name
= "Twinhan TU501(704D1)",
286 .tuner_type
= TUNER_XC2028
, /* has a XC3028 */
287 .tuner_addr
= 0xc2 >> 1,
288 .demod_addr
= 0x1e >> 1,
298 .tuner_reset
= TM6010_GPIO_2
,
299 .tuner_on
= TM6010_GPIO_3
,
300 .demod_reset
= TM6010_GPIO_1
,
301 .demod_on
= TM6010_GPIO_4
,
302 .power_led
= TM6010_GPIO_7
,
303 .dvb_led
= TM6010_GPIO_5
,
309 /* table of devices that work with this driver */
310 struct usb_device_id tm6000_id_table
[] = {
311 { USB_DEVICE(0x6000, 0x0001), .driver_info
= TM5600_BOARD_10MOONS_UT821
},
312 { USB_DEVICE(0x6000, 0x0002), .driver_info
= TM6010_BOARD_GENERIC
},
313 { USB_DEVICE(0x06e1, 0xf332), .driver_info
= TM6000_BOARD_ADSTECH_DUAL_TV
},
314 { USB_DEVICE(0x14aa, 0x0620), .driver_info
= TM6000_BOARD_FREECOM_AND_SIMILAR
},
315 { USB_DEVICE(0x06e1, 0xb339), .driver_info
= TM6000_BOARD_ADSTECH_MINI_DUAL_TV
},
316 { USB_DEVICE(0x2040, 0x6600), .driver_info
= TM6010_BOARD_HAUPPAUGE_900H
},
317 { USB_DEVICE(0x2040, 0x6601), .driver_info
= TM6010_BOARD_HAUPPAUGE_900H
},
318 { USB_DEVICE(0x2040, 0x6610), .driver_info
= TM6010_BOARD_HAUPPAUGE_900H
},
319 { USB_DEVICE(0x2040, 0x6611), .driver_info
= TM6010_BOARD_HAUPPAUGE_900H
},
320 { USB_DEVICE(0x6000, 0xdec0), .driver_info
= TM6010_BOARD_BEHOLD_WANDER
},
321 { USB_DEVICE(0x6000, 0xdec1), .driver_info
= TM6010_BOARD_BEHOLD_VOYAGER
},
322 { USB_DEVICE(0x0ccd, 0x0086), .driver_info
= TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
},
323 { USB_DEVICE(0x0ccd, 0x00A5), .driver_info
= TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
},
324 { USB_DEVICE(0x13d3, 0x3240), .driver_info
= TM6010_BOARD_TWINHAN_TU501
},
325 { USB_DEVICE(0x13d3, 0x3241), .driver_info
= TM6010_BOARD_TWINHAN_TU501
},
326 { USB_DEVICE(0x13d3, 0x3243), .driver_info
= TM6010_BOARD_TWINHAN_TU501
},
327 { USB_DEVICE(0x13d3, 0x3264), .driver_info
= TM6010_BOARD_TWINHAN_TU501
},
331 /* Control power led for show some activity */
332 void tm6000_flash_led(struct tm6000_core
*dev
, u8 state
)
334 /* Power LED unconfigured */
335 if (!dev
->gpio
.power_led
)
340 switch (dev
->model
) {
341 case TM6010_BOARD_HAUPPAUGE_900H
:
342 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
343 case TM6010_BOARD_TWINHAN_TU501
:
344 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
345 dev
->gpio
.power_led
, 0x00);
347 case TM6010_BOARD_BEHOLD_WANDER
:
348 case TM6010_BOARD_BEHOLD_VOYAGER
:
349 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
350 dev
->gpio
.power_led
, 0x01);
356 switch (dev
->model
) {
357 case TM6010_BOARD_HAUPPAUGE_900H
:
358 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
359 case TM6010_BOARD_TWINHAN_TU501
:
360 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
361 dev
->gpio
.power_led
, 0x01);
363 case TM6010_BOARD_BEHOLD_WANDER
:
364 case TM6010_BOARD_BEHOLD_VOYAGER
:
365 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
366 dev
->gpio
.power_led
, 0x00);
372 /* Tuner callback to provide the proper gpio changes needed for xc5000 */
373 int tm6000_xc5000_callback(void *ptr
, int component
, int command
, int arg
)
376 struct tm6000_core
*dev
= ptr
;
378 if (dev
->tuner_type
!= TUNER_XC5000
)
382 case XC5000_TUNER_RESET
:
383 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
384 dev
->gpio
.tuner_reset
, 0x01);
386 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
387 dev
->gpio
.tuner_reset
, 0x00);
389 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
390 dev
->gpio
.tuner_reset
, 0x01);
395 EXPORT_SYMBOL_GPL(tm6000_xc5000_callback
);
397 /* Tuner callback to provide the proper gpio changes needed for xc2028 */
399 int tm6000_tuner_callback(void *ptr
, int component
, int command
, int arg
)
402 struct tm6000_core
*dev
= ptr
;
404 if (dev
->tuner_type
!= TUNER_XC2028
)
408 case XC2028_RESET_CLK
:
409 tm6000_ir_wait(dev
, 0);
411 tm6000_set_reg(dev
, REQ_04_EN_DISABLE_MCU_INT
,
414 rc
= tm6000_i2c_reset(dev
, 10);
416 case XC2028_TUNER_RESET
:
417 /* Reset codes during load firmware */
420 /* newer tuner can faster reset */
421 switch (dev
->model
) {
422 case TM5600_BOARD_10MOONS_UT821
:
423 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
424 dev
->gpio
.tuner_reset
, 0x01);
425 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
428 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
429 dev
->gpio
.tuner_reset
, 0x00);
430 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
433 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
434 dev
->gpio
.tuner_reset
, 0x01);
435 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
438 case TM6010_BOARD_HAUPPAUGE_900H
:
439 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
440 case TM6010_BOARD_TWINHAN_TU501
:
441 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
442 dev
->gpio
.tuner_reset
, 0x01);
444 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
445 dev
->gpio
.tuner_reset
, 0x00);
447 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
448 dev
->gpio
.tuner_reset
, 0x01);
452 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
453 dev
->gpio
.tuner_reset
, 0x00);
455 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
456 dev
->gpio
.tuner_reset
, 0x01);
461 tm6000_ir_wait(dev
, 1);
464 tm6000_set_reg(dev
, REQ_04_EN_DISABLE_MCU_INT
,
469 rc
= tm6000_i2c_reset(dev
, 100);
475 EXPORT_SYMBOL_GPL(tm6000_tuner_callback
);
477 int tm6000_cards_setup(struct tm6000_core
*dev
)
482 * Board-specific initialization sequence. Handles all GPIO
483 * initialization sequences that are board-specific.
484 * Up to now, all found devices use GPIO1 and GPIO4 at the same way.
485 * Probably, they're all based on some reference device. Due to that,
486 * there's a common routine at the end to handle those GPIO's. Devices
487 * that use different pinups or init sequences can just return at
488 * the board-specific session.
490 switch (dev
->model
) {
491 case TM6010_BOARD_HAUPPAUGE_900H
:
492 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
493 case TM6010_BOARD_TWINHAN_TU501
:
494 case TM6010_BOARD_GENERIC
:
495 /* Turn xceive 3028 on */
496 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.tuner_on
, 0x01);
498 /* Turn zarlink zl10353 on */
499 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_on
, 0x00);
501 /* Reset zarlink zl10353 */
502 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_reset
, 0x00);
504 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_reset
, 0x01);
506 /* Turn zarlink zl10353 off */
507 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_on
, 0x01);
510 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.ir
, 0x01);
512 /* Power led on (blue) */
513 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.power_led
, 0x00);
515 /* DVB led off (orange) */
516 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.dvb_led
, 0x01);
518 /* Turn zarlink zl10353 on */
519 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_on
, 0x00);
522 case TM6010_BOARD_BEHOLD_WANDER
:
523 /* Power led on (blue) */
524 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.power_led
, 0x01);
526 /* Reset zarlink zl10353 */
527 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_reset
, 0x00);
529 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.demod_reset
, 0x01);
532 case TM6010_BOARD_BEHOLD_VOYAGER
:
533 /* Power led on (blue) */
534 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
, dev
->gpio
.power_led
, 0x01);
542 * Default initialization. Most of the devices seem to use GPIO1
543 * and GPIO4.on the same way, so, this handles the common sequence
544 * used by most devices.
545 * If a device uses a different sequence or different GPIO pins for
546 * reset, just add the code at the board-specific part
549 if (dev
->gpio
.tuner_reset
) {
550 for (i
= 0; i
< 2; i
++) {
551 rc
= tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
552 dev
->gpio
.tuner_reset
, 0x00);
554 printk(KERN_ERR
"Error %i doing tuner reset\n", rc
);
558 msleep(10); /* Just to be conservative */
559 rc
= tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
560 dev
->gpio
.tuner_reset
, 0x01);
562 printk(KERN_ERR
"Error %i doing tuner reset\n", rc
);
567 printk(KERN_ERR
"Tuner reset is not configured\n");
576 static void tm6000_config_tuner(struct tm6000_core
*dev
)
578 struct tuner_setup tun_setup
;
580 /* Load tuner module */
581 v4l2_i2c_new_subdev(&dev
->v4l2_dev
, &dev
->i2c_adap
,
582 "tuner", dev
->tuner_addr
, NULL
);
584 memset(&tun_setup
, 0, sizeof(tun_setup
));
585 tun_setup
.type
= dev
->tuner_type
;
586 tun_setup
.addr
= dev
->tuner_addr
;
588 tun_setup
.mode_mask
= 0;
589 if (dev
->caps
.has_tuner
)
590 tun_setup
.mode_mask
|= (T_ANALOG_TV
| T_RADIO
);
591 if (dev
->caps
.has_dvb
)
592 tun_setup
.mode_mask
|= T_DIGITAL_TV
;
594 switch (dev
->tuner_type
) {
596 tun_setup
.tuner_callback
= tm6000_tuner_callback
;
599 tun_setup
.tuner_callback
= tm6000_xc5000_callback
;
603 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_type_addr
, &tun_setup
);
605 switch (dev
->tuner_type
) {
607 struct v4l2_priv_tun_config xc2028_cfg
;
608 struct xc2028_ctrl ctl
;
610 memset(&xc2028_cfg
, 0, sizeof(xc2028_cfg
));
611 memset(&ctl
, 0, sizeof(ctl
));
614 ctl
.read_not_reliable
= 0;
616 ctl
.demod
= XC3028_FE_ZARLINK456
;
619 xc2028_cfg
.tuner
= TUNER_XC2028
;
620 xc2028_cfg
.priv
= &ctl
;
622 switch (dev
->model
) {
623 case TM6010_BOARD_HAUPPAUGE_900H
:
624 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
625 case TM6010_BOARD_TWINHAN_TU501
:
626 ctl
.fname
= "xc3028L-v36.fw";
629 if (dev
->dev_type
== TM6010
)
630 ctl
.fname
= "xc3028-v27.fw";
632 ctl
.fname
= "xc3028-v24.fw";
635 printk(KERN_INFO
"Setting firmware parameters for xc2028\n");
636 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_config
,
643 struct v4l2_priv_tun_config xc5000_cfg
;
644 struct xc5000_config ctl
= {
645 .i2c_address
= dev
->tuner_addr
,
647 .radio_input
= XC5000_RADIO_FM1
,
650 xc5000_cfg
.tuner
= TUNER_XC5000
;
651 xc5000_cfg
.priv
= &ctl
;
654 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_config
,
659 printk(KERN_INFO
"Unknown tuner type. Tuner is not configured.\n");
664 static int tm6000_init_dev(struct tm6000_core
*dev
)
666 struct v4l2_frequency f
;
669 mutex_init(&dev
->lock
);
671 mutex_lock(&dev
->lock
);
673 /* Initializa board-specific data */
674 dev
->dev_type
= tm6000_boards
[dev
->model
].type
;
675 dev
->tuner_type
= tm6000_boards
[dev
->model
].tuner_type
;
676 dev
->tuner_addr
= tm6000_boards
[dev
->model
].tuner_addr
;
678 dev
->gpio
= tm6000_boards
[dev
->model
].gpio
;
680 dev
->ir_codes
= tm6000_boards
[dev
->model
].ir_codes
;
682 dev
->demod_addr
= tm6000_boards
[dev
->model
].demod_addr
;
684 dev
->caps
= tm6000_boards
[dev
->model
].caps
;
686 /* initialize hardware */
687 rc
= tm6000_init(dev
);
691 rc
= v4l2_device_register(&dev
->udev
->dev
, &dev
->v4l2_dev
);
695 /* register i2c bus */
696 rc
= tm6000_i2c_register(dev
);
700 /* Default values for STD and resolutions */
703 dev
->norm
= V4L2_STD_PAL_M
;
705 /* Configure tuner */
706 tm6000_config_tuner(dev
);
708 /* Set video standard */
709 v4l2_device_call_all(&dev
->v4l2_dev
, 0, core
, s_std
, dev
->norm
);
711 /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
713 f
.type
= V4L2_TUNER_ANALOG_TV
;
714 f
.frequency
= 3092; /* 193.25 MHz */
715 dev
->freq
= f
.frequency
;
716 v4l2_device_call_all(&dev
->v4l2_dev
, 0, tuner
, s_frequency
, &f
);
718 if (dev
->caps
.has_tda9874
)
719 v4l2_i2c_new_subdev(&dev
->v4l2_dev
, &dev
->i2c_adap
,
720 "tvaudio", I2C_ADDR_TDA9874
, NULL
);
722 /* register and initialize V4L2 */
723 rc
= tm6000_v4l2_register(dev
);
727 tm6000_add_into_devlist(dev
);
728 tm6000_init_extension(dev
);
732 mutex_unlock(&dev
->lock
);
736 mutex_unlock(&dev
->lock
);
740 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
741 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
743 static void get_max_endpoint(struct usb_device
*udev
,
744 struct usb_host_interface
*alt
,
746 struct usb_host_endpoint
*curr_e
,
747 struct tm6000_endpoint
*tm_ep
)
749 u16 tmp
= le16_to_cpu(curr_e
->desc
.wMaxPacketSize
);
750 unsigned int size
= tmp
& 0x7ff;
752 if (udev
->speed
== USB_SPEED_HIGH
)
753 size
= size
* hb_mult(tmp
);
755 if (size
> tm_ep
->maxsize
) {
756 tm_ep
->endp
= curr_e
;
757 tm_ep
->maxsize
= size
;
758 tm_ep
->bInterfaceNumber
= alt
->desc
.bInterfaceNumber
;
759 tm_ep
->bAlternateSetting
= alt
->desc
.bAlternateSetting
;
761 printk(KERN_INFO
"tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
762 msgtype
, curr_e
->desc
.bEndpointAddress
,
769 * checks for supported devices
771 static int tm6000_usb_probe(struct usb_interface
*interface
,
772 const struct usb_device_id
*id
)
774 struct usb_device
*usbdev
;
775 struct tm6000_core
*dev
= NULL
;
780 usbdev
= usb_get_dev(interface_to_usbdev(interface
));
782 /* Selects the proper interface */
783 rc
= usb_set_interface(usbdev
, 0, 1);
787 /* Check to see next free device and mark as used */
788 nr
= find_first_zero_bit(&tm6000_devused
, TM6000_MAXBOARDS
);
789 if (nr
>= TM6000_MAXBOARDS
) {
790 printk(KERN_ERR
"tm6000: Supports only %i tm60xx boards.\n", TM6000_MAXBOARDS
);
795 /* Create and initialize dev struct */
796 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
798 printk(KERN_ERR
"tm6000" ": out of memory!\n");
802 spin_lock_init(&dev
->slock
);
804 /* Increment usage count */
805 tm6000_devused
|= 1<<nr
;
806 snprintf(dev
->name
, 29, "tm6000 #%d", nr
);
808 dev
->model
= id
->driver_info
;
809 if ((card
[nr
] >= 0) && (card
[nr
] < ARRAY_SIZE(tm6000_boards
)))
810 dev
->model
= card
[nr
];
815 switch (usbdev
->speed
) {
819 case USB_SPEED_UNKNOWN
:
833 for (i
= 0; i
< interface
->num_altsetting
; i
++) {
836 for (ep
= 0; ep
< interface
->altsetting
[i
].desc
.bNumEndpoints
; ep
++) {
837 struct usb_host_endpoint
*e
;
840 e
= &interface
->altsetting
[i
].endpoint
[ep
];
842 dir_out
= ((e
->desc
.bEndpointAddress
&
843 USB_ENDPOINT_DIR_MASK
) == USB_DIR_OUT
);
845 printk(KERN_INFO
"tm6000: alt %d, interface %i, class %i\n",
847 interface
->altsetting
[i
].desc
.bInterfaceNumber
,
848 interface
->altsetting
[i
].desc
.bInterfaceClass
);
850 switch (e
->desc
.bmAttributes
) {
851 case USB_ENDPOINT_XFER_BULK
:
853 get_max_endpoint(usbdev
,
854 &interface
->altsetting
[i
],
858 get_max_endpoint(usbdev
,
859 &interface
->altsetting
[i
],
864 case USB_ENDPOINT_XFER_ISOC
:
866 get_max_endpoint(usbdev
,
867 &interface
->altsetting
[i
],
871 get_max_endpoint(usbdev
,
872 &interface
->altsetting
[i
],
877 case USB_ENDPOINT_XFER_INT
:
879 get_max_endpoint(usbdev
,
880 &interface
->altsetting
[i
],
884 get_max_endpoint(usbdev
,
885 &interface
->altsetting
[i
],
895 printk(KERN_INFO
"tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
897 le16_to_cpu(dev
->udev
->descriptor
.idVendor
),
898 le16_to_cpu(dev
->udev
->descriptor
.idProduct
),
899 interface
->altsetting
->desc
.bInterfaceNumber
);
901 /* check if the the device has the iso in endpoint at the correct place */
902 if (!dev
->isoc_in
.endp
) {
903 printk(KERN_ERR
"tm6000: probing error: no IN ISOC endpoint!\n");
909 /* save our data pointer in this interface device */
910 usb_set_intfdata(interface
, dev
);
912 printk(KERN_INFO
"tm6000: Found %s\n", tm6000_boards
[dev
->model
].name
);
914 rc
= tm6000_init_dev(dev
);
922 printk(KERN_ERR
"tm6000: Error %d while registering\n", rc
);
924 tm6000_devused
&= ~(1<<nr
);
932 * tm6000_usb_disconnect()
933 * called when the device gets diconencted
934 * video device will be unregistered on v4l2_close in case it is still open
936 static void tm6000_usb_disconnect(struct usb_interface
*interface
)
938 struct tm6000_core
*dev
= usb_get_intfdata(interface
);
939 usb_set_intfdata(interface
, NULL
);
944 printk(KERN_INFO
"tm6000: disconnecting %s\n", dev
->name
);
948 if (dev
->gpio
.power_led
) {
949 switch (dev
->model
) {
950 case TM6010_BOARD_HAUPPAUGE_900H
:
951 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE
:
952 case TM6010_BOARD_TWINHAN_TU501
:
954 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
955 dev
->gpio
.power_led
, 0x01);
958 case TM6010_BOARD_BEHOLD_WANDER
:
959 case TM6010_BOARD_BEHOLD_VOYAGER
:
961 tm6000_set_reg(dev
, REQ_03_SET_GET_MCU_PIN
,
962 dev
->gpio
.power_led
, 0x00);
967 tm6000_v4l2_unregister(dev
);
969 tm6000_i2c_unregister(dev
);
971 v4l2_device_unregister(&dev
->v4l2_dev
);
973 dev
->state
|= DEV_DISCONNECTED
;
975 usb_put_dev(dev
->udev
);
977 tm6000_close_extension(dev
);
978 tm6000_remove_from_devlist(dev
);
983 static struct usb_driver tm6000_usb_driver
= {
985 .probe
= tm6000_usb_probe
,
986 .disconnect
= tm6000_usb_disconnect
,
987 .id_table
= tm6000_id_table
,
990 static int __init
tm6000_module_init(void)
994 printk(KERN_INFO
"tm6000" " v4l2 driver version %d.%d.%d loaded\n",
995 (TM6000_VERSION
>> 16) & 0xff,
996 (TM6000_VERSION
>> 8) & 0xff, TM6000_VERSION
& 0xff);
998 /* register this driver with the USB subsystem */
999 result
= usb_register(&tm6000_usb_driver
);
1001 printk(KERN_ERR
"tm6000"
1002 " usb_register failed. Error number %d.\n", result
);
1007 static void __exit
tm6000_module_exit(void)
1009 /* deregister at USB subsystem */
1010 usb_deregister(&tm6000_usb_driver
);
1013 module_init(tm6000_module_init
);
1014 module_exit(tm6000_module_exit
);
1016 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000/TM6010 USB2 adapter");
1017 MODULE_AUTHOR("Mauro Carvalho Chehab");
1018 MODULE_LICENSE("GPL");