[media] tm6000: add detection based on eeprom name
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / tm6000 / tm6000-cards.c
blob6e51486dbe648914c57c41f1d4aef35bfc8df81b
1 /*
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>
34 #include "tm6000.h"
35 #include "tm6000-regs.h"
36 #include "tuner-xc2028.h"
37 #include "xc5000.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;
70 struct tm6000_board {
71 char *name;
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;
77 enum tm6000_inaudio aradio;
78 enum tm6000_inaudio avideo;
80 enum tm6000_devtype type; /* variant of the chipset */
81 int tuner_type; /* type of the tuner */
82 int tuner_addr; /* tuner address */
83 int demod_addr; /* demodulator address */
85 struct tm6000_gpio gpio;
87 char *ir_codes;
90 struct tm6000_board tm6000_boards[] = {
91 [TM6000_BOARD_UNKNOWN] = {
92 .name = "Unknown tm6000 video grabber",
93 .caps = {
94 .has_tuner = 1,
96 .gpio = {
97 .tuner_reset = TM6000_GPIO_1,
100 [TM5600_BOARD_GENERIC] = {
101 .name = "Generic tm5600 board",
102 .type = TM5600,
103 .tuner_type = TUNER_XC2028,
104 .tuner_addr = 0xc2 >> 1,
105 .caps = {
106 .has_tuner = 1,
108 .gpio = {
109 .tuner_reset = TM6000_GPIO_1,
112 [TM6000_BOARD_GENERIC] = {
113 .name = "Generic tm6000 board",
114 .tuner_type = TUNER_XC2028,
115 .tuner_addr = 0xc2 >> 1,
116 .caps = {
117 .has_tuner = 1,
118 .has_dvb = 1,
120 .gpio = {
121 .tuner_reset = TM6000_GPIO_1,
124 [TM6010_BOARD_GENERIC] = {
125 .name = "Generic tm6010 board",
126 .type = TM6010,
127 .tuner_type = TUNER_XC2028,
128 .tuner_addr = 0xc2 >> 1,
129 .demod_addr = 0x1e >> 1,
130 .caps = {
131 .has_tuner = 1,
132 .has_dvb = 1,
133 .has_zl10353 = 1,
134 .has_eeprom = 1,
135 .has_remote = 1,
137 .gpio = {
138 .tuner_reset = TM6010_GPIO_2,
139 .tuner_on = TM6010_GPIO_3,
140 .demod_reset = TM6010_GPIO_1,
141 .demod_on = TM6010_GPIO_4,
142 .power_led = TM6010_GPIO_7,
143 .dvb_led = TM6010_GPIO_5,
144 .ir = TM6010_GPIO_0,
147 [TM5600_BOARD_10MOONS_UT821] = {
148 .name = "10Moons UT 821",
149 .tuner_type = TUNER_XC2028,
150 .eename = { '1', '0', 'M', 'O', 'O', 'N', 'S', '5', '6', '0', '0', 0xff, 0x45, 0x5b},
151 .eename_size = 14,
152 .eename_pos = 0x14,
153 .type = TM5600,
154 .tuner_addr = 0xc2 >> 1,
155 .caps = {
156 .has_tuner = 1,
157 .has_eeprom = 1,
159 .gpio = {
160 .tuner_reset = TM6000_GPIO_1,
163 [TM5600_BOARD_10MOONS_UT330] = {
164 .name = "10Moons UT 330",
165 .tuner_type = TUNER_PHILIPS_FQ1216AME_MK4,
166 .tuner_addr = 0xc8 >> 1,
167 .caps = {
168 .has_tuner = 1,
169 .has_dvb = 0,
170 .has_zl10353 = 0,
171 .has_eeprom = 1,
174 [TM6000_BOARD_ADSTECH_DUAL_TV] = {
175 .name = "ADSTECH Dual TV USB",
176 .tuner_type = TUNER_XC2028,
177 .tuner_addr = 0xc8 >> 1,
178 .caps = {
179 .has_tuner = 1,
180 .has_tda9874 = 1,
181 .has_dvb = 1,
182 .has_zl10353 = 1,
183 .has_eeprom = 1,
186 [TM6000_BOARD_FREECOM_AND_SIMILAR] = {
187 .name = "Freecom Hybrid Stick / Moka DVB-T Receiver Dual",
188 .tuner_type = TUNER_XC2028, /* has a XC3028 */
189 .tuner_addr = 0xc2 >> 1,
190 .demod_addr = 0x1e >> 1,
191 .caps = {
192 .has_tuner = 1,
193 .has_dvb = 1,
194 .has_zl10353 = 1,
195 .has_eeprom = 0,
196 .has_remote = 1,
198 .gpio = {
199 .tuner_reset = TM6000_GPIO_4,
202 [TM6000_BOARD_ADSTECH_MINI_DUAL_TV] = {
203 .name = "ADSTECH Mini Dual TV USB",
204 .tuner_type = TUNER_XC2028, /* has a XC3028 */
205 .tuner_addr = 0xc8 >> 1,
206 .demod_addr = 0x1e >> 1,
207 .caps = {
208 .has_tuner = 1,
209 .has_dvb = 1,
210 .has_zl10353 = 1,
211 .has_eeprom = 0,
213 .gpio = {
214 .tuner_reset = TM6000_GPIO_4,
217 [TM6010_BOARD_HAUPPAUGE_900H] = {
218 .name = "Hauppauge WinTV HVR-900H / WinTV USB2-Stick",
219 .eename = { 'H', 0, 'V', 0, 'R', 0, '9', 0, '0', 0, '0', 0, 'H', 0 },
220 .eename_size = 14,
221 .eename_pos = 0x42,
222 .tuner_type = TUNER_XC2028, /* has a XC3028 */
223 .tuner_addr = 0xc2 >> 1,
224 .demod_addr = 0x1e >> 1,
225 .type = TM6010,
226 .caps = {
227 .has_tuner = 1,
228 .has_dvb = 1,
229 .has_zl10353 = 1,
230 .has_eeprom = 1,
231 .has_remote = 1,
233 .gpio = {
234 .tuner_reset = TM6010_GPIO_2,
235 .tuner_on = TM6010_GPIO_3,
236 .demod_reset = TM6010_GPIO_1,
237 .demod_on = TM6010_GPIO_4,
238 .power_led = TM6010_GPIO_7,
239 .dvb_led = TM6010_GPIO_5,
240 .ir = TM6010_GPIO_0,
243 [TM6010_BOARD_BEHOLD_WANDER] = {
244 .name = "Beholder Wander DVB-T/TV/FM USB2.0",
245 .tuner_type = TUNER_XC5000,
246 .tuner_addr = 0xc2 >> 1,
247 .demod_addr = 0x1e >> 1,
248 .type = TM6010,
249 .avideo = TM6000_AIP_SIF1,
250 .aradio = TM6000_AIP_LINE1,
251 .caps = {
252 .has_tuner = 1,
253 .has_dvb = 1,
254 .has_zl10353 = 1,
255 .has_eeprom = 1,
256 .has_remote = 1,
257 .has_input_comp = 1,
258 .has_input_svid = 1,
260 .gpio = {
261 .tuner_reset = TM6010_GPIO_0,
262 .demod_reset = TM6010_GPIO_1,
263 .power_led = TM6010_GPIO_6,
266 [TM6010_BOARD_BEHOLD_VOYAGER] = {
267 .name = "Beholder Voyager TV/FM USB2.0",
268 .tuner_type = TUNER_XC5000,
269 .tuner_addr = 0xc2 >> 1,
270 .type = TM6010,
271 .avideo = TM6000_AIP_SIF1,
272 .aradio = TM6000_AIP_LINE1,
273 .caps = {
274 .has_tuner = 1,
275 .has_dvb = 0,
276 .has_zl10353 = 0,
277 .has_eeprom = 1,
278 .has_remote = 1,
279 .has_input_comp = 1,
280 .has_input_svid = 1,
282 .gpio = {
283 .tuner_reset = TM6010_GPIO_0,
284 .power_led = TM6010_GPIO_6,
287 [TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE] = {
288 .name = "Terratec Cinergy Hybrid XE / Cinergy Hybrid-Stick",
289 .tuner_type = TUNER_XC2028, /* has a XC3028 */
290 .tuner_addr = 0xc2 >> 1,
291 .demod_addr = 0x1e >> 1,
292 .type = TM6010,
293 .caps = {
294 .has_tuner = 1,
295 .has_dvb = 1,
296 .has_zl10353 = 1,
297 .has_eeprom = 1,
298 .has_remote = 1,
300 .gpio = {
301 .tuner_reset = TM6010_GPIO_2,
302 .tuner_on = TM6010_GPIO_3,
303 .demod_reset = TM6010_GPIO_1,
304 .demod_on = TM6010_GPIO_4,
305 .power_led = TM6010_GPIO_7,
306 .dvb_led = TM6010_GPIO_5,
307 .ir = TM6010_GPIO_0,
309 .ir_codes = RC_MAP_NEC_TERRATEC_CINERGY_XS,
311 [TM5600_BOARD_TERRATEC_GRABSTER] = {
312 .name = "Terratec Grabster AV 150/250 MX",
313 .type = TM5600,
314 .tuner_type = TUNER_ABSENT,
316 [TM6010_BOARD_TWINHAN_TU501] = {
317 .name = "Twinhan TU501(704D1)",
318 .tuner_type = TUNER_XC2028, /* has a XC3028 */
319 .tuner_addr = 0xc2 >> 1,
320 .demod_addr = 0x1e >> 1,
321 .type = TM6010,
322 .caps = {
323 .has_tuner = 1,
324 .has_dvb = 1,
325 .has_zl10353 = 1,
326 .has_eeprom = 1,
327 .has_remote = 1,
329 .gpio = {
330 .tuner_reset = TM6010_GPIO_2,
331 .tuner_on = TM6010_GPIO_3,
332 .demod_reset = TM6010_GPIO_1,
333 .demod_on = TM6010_GPIO_4,
334 .power_led = TM6010_GPIO_7,
335 .dvb_led = TM6010_GPIO_5,
336 .ir = TM6010_GPIO_0,
339 [TM6010_BOARD_BEHOLD_WANDER_LITE] = {
340 .name = "Beholder Wander Lite DVB-T/TV/FM USB2.0",
341 .tuner_type = TUNER_XC5000,
342 .tuner_addr = 0xc2 >> 1,
343 .demod_addr = 0x1e >> 1,
344 .type = TM6010,
345 .avideo = TM6000_AIP_SIF1,
346 .aradio = TM6000_AIP_LINE1,
347 .caps = {
348 .has_tuner = 1,
349 .has_dvb = 1,
350 .has_zl10353 = 1,
351 .has_eeprom = 1,
352 .has_remote = 0,
353 .has_input_comp = 0,
354 .has_input_svid = 0,
356 .gpio = {
357 .tuner_reset = TM6010_GPIO_0,
358 .demod_reset = TM6010_GPIO_1,
359 .power_led = TM6010_GPIO_6,
362 [TM6010_BOARD_BEHOLD_VOYAGER_LITE] = {
363 .name = "Beholder Voyager Lite TV/FM USB2.0",
364 .tuner_type = TUNER_XC5000,
365 .tuner_addr = 0xc2 >> 1,
366 .type = TM6010,
367 .avideo = TM6000_AIP_SIF1,
368 .aradio = TM6000_AIP_LINE1,
369 .caps = {
370 .has_tuner = 1,
371 .has_dvb = 0,
372 .has_zl10353 = 0,
373 .has_eeprom = 1,
374 .has_remote = 0,
375 .has_input_comp = 0,
376 .has_input_svid = 0,
378 .gpio = {
379 .tuner_reset = TM6010_GPIO_0,
380 .power_led = TM6010_GPIO_6,
385 /* table of devices that work with this driver */
386 struct usb_device_id tm6000_id_table[] = {
387 { USB_DEVICE(0x6000, 0x0001), .driver_info = TM5600_BOARD_GENERIC },
388 { USB_DEVICE(0x6000, 0x0002), .driver_info = TM6010_BOARD_GENERIC },
389 { USB_DEVICE(0x06e1, 0xf332), .driver_info = TM6000_BOARD_ADSTECH_DUAL_TV },
390 { USB_DEVICE(0x14aa, 0x0620), .driver_info = TM6000_BOARD_FREECOM_AND_SIMILAR },
391 { USB_DEVICE(0x06e1, 0xb339), .driver_info = TM6000_BOARD_ADSTECH_MINI_DUAL_TV },
392 { USB_DEVICE(0x2040, 0x6600), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
393 { USB_DEVICE(0x2040, 0x6601), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
394 { USB_DEVICE(0x2040, 0x6610), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
395 { USB_DEVICE(0x2040, 0x6611), .driver_info = TM6010_BOARD_HAUPPAUGE_900H },
396 { USB_DEVICE(0x6000, 0xdec0), .driver_info = TM6010_BOARD_BEHOLD_WANDER },
397 { USB_DEVICE(0x6000, 0xdec1), .driver_info = TM6010_BOARD_BEHOLD_VOYAGER },
398 { USB_DEVICE(0x0ccd, 0x0086), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
399 { USB_DEVICE(0x0ccd, 0x00A5), .driver_info = TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE },
400 { USB_DEVICE(0x0ccd, 0x0079), .driver_info = TM5600_BOARD_TERRATEC_GRABSTER },
401 { USB_DEVICE(0x13d3, 0x3240), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
402 { USB_DEVICE(0x13d3, 0x3241), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
403 { USB_DEVICE(0x13d3, 0x3243), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
404 { USB_DEVICE(0x13d3, 0x3264), .driver_info = TM6010_BOARD_TWINHAN_TU501 },
405 { USB_DEVICE(0x6000, 0xdec2), .driver_info = TM6010_BOARD_BEHOLD_WANDER_LITE },
406 { USB_DEVICE(0x6000, 0xdec3), .driver_info = TM6010_BOARD_BEHOLD_VOYAGER_LITE },
407 { },
410 /* Control power led for show some activity */
411 void tm6000_flash_led(struct tm6000_core *dev, u8 state)
413 /* Power LED unconfigured */
414 if (!dev->gpio.power_led)
415 return;
417 /* ON Power LED */
418 if (state) {
419 switch (dev->model) {
420 case TM6010_BOARD_HAUPPAUGE_900H:
421 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
422 case TM6010_BOARD_TWINHAN_TU501:
423 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
424 dev->gpio.power_led, 0x00);
425 break;
426 case TM6010_BOARD_BEHOLD_WANDER:
427 case TM6010_BOARD_BEHOLD_VOYAGER:
428 case TM6010_BOARD_BEHOLD_WANDER_LITE:
429 case TM6010_BOARD_BEHOLD_VOYAGER_LITE:
430 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
431 dev->gpio.power_led, 0x01);
432 break;
435 /* OFF Power LED */
436 else {
437 switch (dev->model) {
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.power_led, 0x01);
443 break;
444 case TM6010_BOARD_BEHOLD_WANDER:
445 case TM6010_BOARD_BEHOLD_VOYAGER:
446 case TM6010_BOARD_BEHOLD_WANDER_LITE:
447 case TM6010_BOARD_BEHOLD_VOYAGER_LITE:
448 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
449 dev->gpio.power_led, 0x00);
450 break;
455 /* Tuner callback to provide the proper gpio changes needed for xc5000 */
456 int tm6000_xc5000_callback(void *ptr, int component, int command, int arg)
458 int rc = 0;
459 struct tm6000_core *dev = ptr;
461 if (dev->tuner_type != TUNER_XC5000)
462 return 0;
464 switch (command) {
465 case XC5000_TUNER_RESET:
466 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
467 dev->gpio.tuner_reset, 0x01);
468 msleep(15);
469 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
470 dev->gpio.tuner_reset, 0x00);
471 msleep(15);
472 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
473 dev->gpio.tuner_reset, 0x01);
474 break;
476 return rc;
478 EXPORT_SYMBOL_GPL(tm6000_xc5000_callback);
480 /* Tuner callback to provide the proper gpio changes needed for xc2028 */
482 int tm6000_tuner_callback(void *ptr, int component, int command, int arg)
484 int rc = 0;
485 struct tm6000_core *dev = ptr;
487 if (dev->tuner_type != TUNER_XC2028)
488 return 0;
490 switch (command) {
491 case XC2028_RESET_CLK:
492 tm6000_ir_wait(dev, 0);
494 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
495 0x02, arg);
496 msleep(10);
497 rc = tm6000_i2c_reset(dev, 10);
498 break;
499 case XC2028_TUNER_RESET:
500 /* Reset codes during load firmware */
501 switch (arg) {
502 case 0:
503 /* newer tuner can faster reset */
504 switch (dev->model) {
505 case TM5600_BOARD_10MOONS_UT821:
506 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
507 dev->gpio.tuner_reset, 0x01);
508 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
509 0x300, 0x01);
510 msleep(10);
511 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
512 dev->gpio.tuner_reset, 0x00);
513 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
514 0x300, 0x00);
515 msleep(10);
516 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
517 dev->gpio.tuner_reset, 0x01);
518 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
519 0x300, 0x01);
520 break;
521 case TM6010_BOARD_HAUPPAUGE_900H:
522 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
523 case TM6010_BOARD_TWINHAN_TU501:
524 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
525 dev->gpio.tuner_reset, 0x01);
526 msleep(60);
527 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
528 dev->gpio.tuner_reset, 0x00);
529 msleep(75);
530 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
531 dev->gpio.tuner_reset, 0x01);
532 msleep(60);
533 break;
534 default:
535 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
536 dev->gpio.tuner_reset, 0x00);
537 msleep(130);
538 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
539 dev->gpio.tuner_reset, 0x01);
540 msleep(130);
541 break;
544 tm6000_ir_wait(dev, 1);
545 break;
546 case 1:
547 tm6000_set_reg(dev, REQ_04_EN_DISABLE_MCU_INT,
548 0x02, 0x01);
549 msleep(10);
550 break;
551 case 2:
552 rc = tm6000_i2c_reset(dev, 100);
553 break;
556 return rc;
558 EXPORT_SYMBOL_GPL(tm6000_tuner_callback);
560 int tm6000_cards_setup(struct tm6000_core *dev)
562 int i, rc;
565 * Board-specific initialization sequence. Handles all GPIO
566 * initialization sequences that are board-specific.
567 * Up to now, all found devices use GPIO1 and GPIO4 at the same way.
568 * Probably, they're all based on some reference device. Due to that,
569 * there's a common routine at the end to handle those GPIO's. Devices
570 * that use different pinups or init sequences can just return at
571 * the board-specific session.
573 switch (dev->model) {
574 case TM6010_BOARD_HAUPPAUGE_900H:
575 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
576 case TM6010_BOARD_TWINHAN_TU501:
577 case TM6010_BOARD_GENERIC:
578 /* Turn xceive 3028 on */
579 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.tuner_on, 0x01);
580 msleep(15);
581 /* Turn zarlink zl10353 on */
582 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
583 msleep(15);
584 /* Reset zarlink zl10353 */
585 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
586 msleep(50);
587 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
588 msleep(15);
589 /* Turn zarlink zl10353 off */
590 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x01);
591 msleep(15);
592 /* ir ? */
593 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.ir, 0x01);
594 msleep(15);
595 /* Power led on (blue) */
596 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x00);
597 msleep(15);
598 /* DVB led off (orange) */
599 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.dvb_led, 0x01);
600 msleep(15);
601 /* Turn zarlink zl10353 on */
602 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_on, 0x00);
603 msleep(15);
604 break;
605 case TM6010_BOARD_BEHOLD_WANDER:
606 case TM6010_BOARD_BEHOLD_WANDER_LITE:
607 /* Power led on (blue) */
608 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
609 msleep(15);
610 /* Reset zarlink zl10353 */
611 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x00);
612 msleep(50);
613 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.demod_reset, 0x01);
614 msleep(15);
615 break;
616 case TM6010_BOARD_BEHOLD_VOYAGER:
617 case TM6010_BOARD_BEHOLD_VOYAGER_LITE:
618 /* Power led on (blue) */
619 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, dev->gpio.power_led, 0x01);
620 msleep(15);
621 break;
622 default:
623 break;
627 * Default initialization. Most of the devices seem to use GPIO1
628 * and GPIO4.on the same way, so, this handles the common sequence
629 * used by most devices.
630 * If a device uses a different sequence or different GPIO pins for
631 * reset, just add the code at the board-specific part
634 if (dev->gpio.tuner_reset) {
635 for (i = 0; i < 2; i++) {
636 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
637 dev->gpio.tuner_reset, 0x00);
638 if (rc < 0) {
639 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
640 return rc;
643 msleep(10); /* Just to be conservative */
644 rc = tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
645 dev->gpio.tuner_reset, 0x01);
646 if (rc < 0) {
647 printk(KERN_ERR "Error %i doing tuner reset\n", rc);
648 return rc;
651 } else {
652 printk(KERN_ERR "Tuner reset is not configured\n");
653 return -1;
656 msleep(50);
658 return 0;
661 static void tm6000_config_tuner(struct tm6000_core *dev)
663 struct tuner_setup tun_setup;
665 /* Load tuner module */
666 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
667 "tuner", dev->tuner_addr, NULL);
669 memset(&tun_setup, 0, sizeof(tun_setup));
670 tun_setup.type = dev->tuner_type;
671 tun_setup.addr = dev->tuner_addr;
673 tun_setup.mode_mask = 0;
674 if (dev->caps.has_tuner)
675 tun_setup.mode_mask |= (T_ANALOG_TV | T_RADIO);
677 switch (dev->tuner_type) {
678 case TUNER_XC2028:
679 tun_setup.tuner_callback = tm6000_tuner_callback;
680 break;
681 case TUNER_XC5000:
682 tun_setup.tuner_callback = tm6000_xc5000_callback;
683 break;
686 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, &tun_setup);
688 switch (dev->tuner_type) {
689 case TUNER_XC2028: {
690 struct v4l2_priv_tun_config xc2028_cfg;
691 struct xc2028_ctrl ctl;
693 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
694 memset(&ctl, 0, sizeof(ctl));
696 ctl.input1 = 1;
697 ctl.read_not_reliable = 0;
698 ctl.msleep = 10;
699 ctl.demod = XC3028_FE_ZARLINK456;
700 ctl.vhfbw7 = 1;
701 ctl.uhfbw8 = 1;
702 xc2028_cfg.tuner = TUNER_XC2028;
703 xc2028_cfg.priv = &ctl;
705 switch (dev->model) {
706 case TM6010_BOARD_HAUPPAUGE_900H:
707 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
708 case TM6010_BOARD_TWINHAN_TU501:
709 ctl.fname = "xc3028L-v36.fw";
710 break;
711 default:
712 if (dev->dev_type == TM6010)
713 ctl.fname = "xc3028-v27.fw";
714 else
715 ctl.fname = "xc3028-v24.fw";
718 printk(KERN_INFO "Setting firmware parameters for xc2028\n");
719 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
720 &xc2028_cfg);
723 break;
724 case TUNER_XC5000:
726 struct v4l2_priv_tun_config xc5000_cfg;
727 struct xc5000_config ctl = {
728 .i2c_address = dev->tuner_addr,
729 .if_khz = 4570,
730 .radio_input = XC5000_RADIO_FM1_MONO,
733 xc5000_cfg.tuner = TUNER_XC5000;
734 xc5000_cfg.priv = &ctl;
736 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_config,
737 &xc5000_cfg);
739 break;
740 default:
741 printk(KERN_INFO "Unknown tuner type. Tuner is not configured.\n");
742 break;
746 static int fill_board_specific_data(struct tm6000_core *dev)
748 int rc;
750 dev->dev_type = tm6000_boards[dev->model].type;
751 dev->tuner_type = tm6000_boards[dev->model].tuner_type;
752 dev->tuner_addr = tm6000_boards[dev->model].tuner_addr;
754 dev->gpio = tm6000_boards[dev->model].gpio;
756 dev->ir_codes = tm6000_boards[dev->model].ir_codes;
758 dev->demod_addr = tm6000_boards[dev->model].demod_addr;
760 dev->caps = tm6000_boards[dev->model].caps;
762 dev->avideo = tm6000_boards[dev->model].avideo;
763 dev->aradio = tm6000_boards[dev->model].aradio;
764 /* initialize hardware */
765 rc = tm6000_init(dev);
766 if (rc < 0)
767 return rc;
769 rc = v4l2_device_register(&dev->udev->dev, &dev->v4l2_dev);
770 if (rc < 0)
771 return rc;
773 /* initialize hardware */
774 rc = tm6000_init(dev);
776 return rc;
780 static void use_alternative_detection_method(struct tm6000_core *dev)
782 int i, model = -1;
784 if (!dev->eedata_size)
785 return;
787 for (i = 0; i < ARRAY_SIZE(tm6000_boards); i++) {
788 if (!tm6000_boards[i].eename_size)
789 continue;
790 if (dev->eedata_size < tm6000_boards[i].eename_pos +
791 tm6000_boards[i].eename_size)
792 continue;
794 if (!memcmp(&dev->eedata[tm6000_boards[i].eename_pos],
795 tm6000_boards[i].eename,
796 tm6000_boards[i].eename_size)) {
797 model = i;
798 break;
801 if (model < 0) {
802 printk(KERN_INFO "Device has eeprom but is currently unknown\n");
803 return;
806 dev->model = model;
808 printk(KERN_INFO "Device identified via eeprom as %s (type = %d)\n",
809 tm6000_boards[model].name, model);
812 static int tm6000_init_dev(struct tm6000_core *dev)
814 struct v4l2_frequency f;
815 int rc = 0;
817 mutex_init(&dev->lock);
818 mutex_lock(&dev->lock);
820 if (!is_generic(dev->model)) {
821 rc = fill_board_specific_data(dev);
822 if (rc < 0)
823 goto err;
825 /* register i2c bus */
826 rc = tm6000_i2c_register(dev);
827 if (rc < 0)
828 goto err;
829 } else {
830 /* register i2c bus */
831 rc = tm6000_i2c_register(dev);
832 if (rc < 0)
833 goto err;
835 use_alternative_detection_method(dev);
837 rc = fill_board_specific_data(dev);
838 if (rc < 0)
839 goto err;
842 /* Default values for STD and resolutions */
843 dev->width = 720;
844 dev->height = 480;
845 dev->norm = V4L2_STD_PAL_M;
847 /* Configure tuner */
848 tm6000_config_tuner(dev);
850 /* Set video standard */
851 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_std, dev->norm);
853 /* Set tuner frequency - also loads firmware on xc2028/xc3028 */
854 f.tuner = 0;
855 f.type = V4L2_TUNER_ANALOG_TV;
856 f.frequency = 3092; /* 193.25 MHz */
857 dev->freq = f.frequency;
858 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, &f);
860 if (dev->caps.has_tda9874)
861 v4l2_i2c_new_subdev(&dev->v4l2_dev, &dev->i2c_adap,
862 "tvaudio", I2C_ADDR_TDA9874, NULL);
864 /* register and initialize V4L2 */
865 rc = tm6000_v4l2_register(dev);
866 if (rc < 0)
867 goto err;
869 tm6000_add_into_devlist(dev);
870 tm6000_init_extension(dev);
872 tm6000_ir_init(dev);
874 mutex_unlock(&dev->lock);
875 return 0;
877 err:
878 mutex_unlock(&dev->lock);
879 return rc;
882 /* high bandwidth multiplier, as encoded in highspeed endpoint descriptors */
883 #define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
885 static void get_max_endpoint(struct usb_device *udev,
886 struct usb_host_interface *alt,
887 char *msgtype,
888 struct usb_host_endpoint *curr_e,
889 struct tm6000_endpoint *tm_ep)
891 u16 tmp = le16_to_cpu(curr_e->desc.wMaxPacketSize);
892 unsigned int size = tmp & 0x7ff;
894 if (udev->speed == USB_SPEED_HIGH)
895 size = size * hb_mult(tmp);
897 if (size > tm_ep->maxsize) {
898 tm_ep->endp = curr_e;
899 tm_ep->maxsize = size;
900 tm_ep->bInterfaceNumber = alt->desc.bInterfaceNumber;
901 tm_ep->bAlternateSetting = alt->desc.bAlternateSetting;
903 printk(KERN_INFO "tm6000: %s endpoint: 0x%02x (max size=%u bytes)\n",
904 msgtype, curr_e->desc.bEndpointAddress,
905 size);
910 * tm6000_usb_probe()
911 * checks for supported devices
913 static int tm6000_usb_probe(struct usb_interface *interface,
914 const struct usb_device_id *id)
916 struct usb_device *usbdev;
917 struct tm6000_core *dev = NULL;
918 int i, rc = 0;
919 int nr = 0;
920 char *speed;
922 usbdev = usb_get_dev(interface_to_usbdev(interface));
924 /* Selects the proper interface */
925 rc = usb_set_interface(usbdev, 0, 1);
926 if (rc < 0)
927 goto err;
929 /* Check to see next free device and mark as used */
930 nr = find_first_zero_bit(&tm6000_devused, TM6000_MAXBOARDS);
931 if (nr >= TM6000_MAXBOARDS) {
932 printk(KERN_ERR "tm6000: Supports only %i tm60xx boards.\n", TM6000_MAXBOARDS);
933 usb_put_dev(usbdev);
934 return -ENOMEM;
937 /* Create and initialize dev struct */
938 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
939 if (dev == NULL) {
940 printk(KERN_ERR "tm6000" ": out of memory!\n");
941 usb_put_dev(usbdev);
942 return -ENOMEM;
944 spin_lock_init(&dev->slock);
946 /* Increment usage count */
947 tm6000_devused |= 1<<nr;
948 snprintf(dev->name, 29, "tm6000 #%d", nr);
950 dev->model = id->driver_info;
951 if ((card[nr] >= 0) && (card[nr] < ARRAY_SIZE(tm6000_boards)))
952 dev->model = card[nr];
954 dev->udev = usbdev;
955 dev->devno = nr;
957 switch (usbdev->speed) {
958 case USB_SPEED_LOW:
959 speed = "1.5";
960 break;
961 case USB_SPEED_UNKNOWN:
962 case USB_SPEED_FULL:
963 speed = "12";
964 break;
965 case USB_SPEED_HIGH:
966 speed = "480";
967 break;
968 default:
969 speed = "unknown";
974 /* Get endpoints */
975 for (i = 0; i < interface->num_altsetting; i++) {
976 int ep;
978 for (ep = 0; ep < interface->altsetting[i].desc.bNumEndpoints; ep++) {
979 struct usb_host_endpoint *e;
980 int dir_out;
982 e = &interface->altsetting[i].endpoint[ep];
984 dir_out = ((e->desc.bEndpointAddress &
985 USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
987 printk(KERN_INFO "tm6000: alt %d, interface %i, class %i\n",
989 interface->altsetting[i].desc.bInterfaceNumber,
990 interface->altsetting[i].desc.bInterfaceClass);
992 switch (e->desc.bmAttributes) {
993 case USB_ENDPOINT_XFER_BULK:
994 if (!dir_out) {
995 get_max_endpoint(usbdev,
996 &interface->altsetting[i],
997 "Bulk IN", e,
998 &dev->bulk_in);
999 } else {
1000 get_max_endpoint(usbdev,
1001 &interface->altsetting[i],
1002 "Bulk OUT", e,
1003 &dev->bulk_out);
1005 break;
1006 case USB_ENDPOINT_XFER_ISOC:
1007 if (!dir_out) {
1008 get_max_endpoint(usbdev,
1009 &interface->altsetting[i],
1010 "ISOC IN", e,
1011 &dev->isoc_in);
1012 } else {
1013 get_max_endpoint(usbdev,
1014 &interface->altsetting[i],
1015 "ISOC OUT", e,
1016 &dev->isoc_out);
1018 break;
1019 case USB_ENDPOINT_XFER_INT:
1020 if (!dir_out) {
1021 get_max_endpoint(usbdev,
1022 &interface->altsetting[i],
1023 "INT IN", e,
1024 &dev->int_in);
1025 } else {
1026 get_max_endpoint(usbdev,
1027 &interface->altsetting[i],
1028 "INT OUT", e,
1029 &dev->int_out);
1031 break;
1037 printk(KERN_INFO "tm6000: New video device @ %s Mbps (%04x:%04x, ifnum %d)\n",
1038 speed,
1039 le16_to_cpu(dev->udev->descriptor.idVendor),
1040 le16_to_cpu(dev->udev->descriptor.idProduct),
1041 interface->altsetting->desc.bInterfaceNumber);
1043 /* check if the the device has the iso in endpoint at the correct place */
1044 if (!dev->isoc_in.endp) {
1045 printk(KERN_ERR "tm6000: probing error: no IN ISOC endpoint!\n");
1046 rc = -ENODEV;
1048 goto err;
1051 /* save our data pointer in this interface device */
1052 usb_set_intfdata(interface, dev);
1054 printk(KERN_INFO "tm6000: Found %s\n", tm6000_boards[dev->model].name);
1056 rc = tm6000_init_dev(dev);
1058 if (rc < 0)
1059 goto err;
1061 return 0;
1063 err:
1064 printk(KERN_ERR "tm6000: Error %d while registering\n", rc);
1066 tm6000_devused &= ~(1<<nr);
1067 usb_put_dev(usbdev);
1069 kfree(dev);
1070 return rc;
1074 * tm6000_usb_disconnect()
1075 * called when the device gets diconencted
1076 * video device will be unregistered on v4l2_close in case it is still open
1078 static void tm6000_usb_disconnect(struct usb_interface *interface)
1080 struct tm6000_core *dev = usb_get_intfdata(interface);
1081 usb_set_intfdata(interface, NULL);
1083 if (!dev)
1084 return;
1086 printk(KERN_INFO "tm6000: disconnecting %s\n", dev->name);
1088 tm6000_ir_fini(dev);
1090 if (dev->gpio.power_led) {
1091 switch (dev->model) {
1092 case TM6010_BOARD_HAUPPAUGE_900H:
1093 case TM6010_BOARD_TERRATEC_CINERGY_HYBRID_XE:
1094 case TM6010_BOARD_TWINHAN_TU501:
1095 /* Power led off */
1096 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
1097 dev->gpio.power_led, 0x01);
1098 msleep(15);
1099 break;
1100 case TM6010_BOARD_BEHOLD_WANDER:
1101 case TM6010_BOARD_BEHOLD_VOYAGER:
1102 case TM6010_BOARD_BEHOLD_WANDER_LITE:
1103 case TM6010_BOARD_BEHOLD_VOYAGER_LITE:
1104 /* Power led off */
1105 tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN,
1106 dev->gpio.power_led, 0x00);
1107 msleep(15);
1108 break;
1111 tm6000_v4l2_unregister(dev);
1113 tm6000_i2c_unregister(dev);
1115 v4l2_device_unregister(&dev->v4l2_dev);
1117 dev->state |= DEV_DISCONNECTED;
1119 usb_put_dev(dev->udev);
1121 tm6000_close_extension(dev);
1122 tm6000_remove_from_devlist(dev);
1124 kfree(dev);
1127 static struct usb_driver tm6000_usb_driver = {
1128 .name = "tm6000",
1129 .probe = tm6000_usb_probe,
1130 .disconnect = tm6000_usb_disconnect,
1131 .id_table = tm6000_id_table,
1134 static int __init tm6000_module_init(void)
1136 int result;
1138 printk(KERN_INFO "tm6000" " v4l2 driver version %d.%d.%d loaded\n",
1139 (TM6000_VERSION >> 16) & 0xff,
1140 (TM6000_VERSION >> 8) & 0xff, TM6000_VERSION & 0xff);
1142 /* register this driver with the USB subsystem */
1143 result = usb_register(&tm6000_usb_driver);
1144 if (result)
1145 printk(KERN_ERR "tm6000"
1146 " usb_register failed. Error number %d.\n", result);
1148 return result;
1151 static void __exit tm6000_module_exit(void)
1153 /* deregister at USB subsystem */
1154 usb_deregister(&tm6000_usb_driver);
1157 module_init(tm6000_module_init);
1158 module_exit(tm6000_module_exit);
1160 MODULE_DESCRIPTION("Trident TVMaster TM5600/TM6000/TM6010 USB2 adapter");
1161 MODULE_AUTHOR("Mauro Carvalho Chehab");
1162 MODULE_LICENSE("GPL");