1 /* $FreeBSD: src/sys/dev/bktr/bktr_card.c,v 1.9.2.5 2003/02/08 02:04:57 orion Exp $ */
2 /* $DragonFly: src/sys/dev/video/bktr/bktr_card.c,v 1.3 2003/08/07 21:17:15 dillon Exp $ */
5 * This is part of the Driver for Video Capture Cards (Frame grabbers)
6 * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879
8 * Copyright Roger Hardiman and Amancio Hasty.
10 * bktr_card : This deals with identifying TV cards.
11 * trying to find the card make and model of card.
12 * trying to find the type of tuner fitted.
13 * reading the configuration EEPROM.
14 * locating i2c devices.
19 * 1. Redistributions of source code must retain the
20 * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman
21 * All rights reserved.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the above copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * This product includes software developed by Amancio Hasty and
35 * 4. The name of the author may not be used to endorse or promote products
36 * derived from this software without specific prior written permission.
38 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
39 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
40 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
42 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
44 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
47 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
48 * POSSIBILITY OF SUCH DAMAGE.
51 #include "opt_bktr.h" /* Include any kernel config options */
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 #include <sys/vnode.h>
59 #if (__FreeBSD_version < 500000)
60 #include <machine/clock.h> /* for DELAY */
63 #include <bus/pci/pcivar.h>
65 #if (__FreeBSD_version >=300000)
66 #include <machine/bus_memio.h> /* for bus space */
67 #include <machine/bus.h>
73 #include <dev/ic/bt8xx.h> /* NetBSD location for .h files */
74 #include <dev/pci/bktr/bktr_reg.h>
75 #include <dev/pci/bktr/bktr_core.h>
76 #include <dev/pci/bktr/bktr_tuner.h>
77 #include <dev/pci/bktr/bktr_card.h>
78 #include <dev/pci/bktr/bktr_audio.h>
80 #include <machine/ioctl_meteor.h> /* Traditional location for .h files */
81 #include <machine/ioctl_bt848.h> /* extensions to ioctl_meteor.h */
83 #include "bktr_core.h"
84 #include "bktr_tuner.h"
85 #include "bktr_card.h"
86 #include "bktr_audio.h"
89 /* Include the PCI Vendor definitions */
91 #include <dev/pci/pcidevs.h>
92 #include <dev/pci/pcireg.h>
96 #define HAUP_REMOTE_INT_WADDR 0x30
97 #define HAUP_REMOTE_INT_RADDR 0x31
99 #define HAUP_REMOTE_EXT_WADDR 0x34
100 #define HAUP_REMOTE_EXT_RADDR 0x35
102 /* address of BTSC/SAP decoder chip */
103 #define TDA9850_WADDR 0xb6
104 #define TDA9850_RADDR 0xb7
106 /* address of MSP3400C chip */
107 #define MSP3400C_WADDR 0x80
108 #define MSP3400C_RADDR 0x81
110 /* address of DPL3518A chip */
111 #define DPL3518A_WADDR 0x84
112 #define DPL3518A_RADDR 0x85
114 /* EEProm (128 * 8) on an STB card */
115 #define X24C01_WADDR 0xae
116 #define X24C01_RADDR 0xaf
119 /* EEProm (256 * 8) on a Hauppauge card */
120 /* and on most BT878s cards to store the sub-system vendor id */
121 #define PFC8582_WADDR 0xa0
122 #define PFC8582_RADDR 0xa1
124 #if BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL
125 #define DEFAULT_TUNER PHILIPS_PALI
127 #define DEFAULT_TUNER PHILIPS_NTSC
134 * the data for each type of card
137 * these entried MUST be kept in the order defined by the CARD_XXX defines!
139 static const struct CARDTYPE cards[] = {
141 { CARD_UNKNOWN, /* the card id */
142 "Unknown", /* the 'name' */
143 NULL, /* the tuner */
144 0, /* the tuner i2c address */
148 0, /* EEProm unknown */
149 0, /* EEProm unknown */
153 { CARD_MIRO, /* the card id */
154 "Pinnacle/Miro TV", /* the 'name' */
155 NULL, /* the tuner */
156 0, /* the tuner i2c address */
160 0, /* EEProm unknown */
161 0, /* size unknown */
162 { 0x02, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */
163 0x0f }, /* GPIO mask */
165 { CARD_HAUPPAUGE, /* the card id */
166 "Hauppauge WinCast/TV", /* the 'name' */
167 NULL, /* the tuner */
168 0, /* the tuner i2c address */
169 0, /* dbx is optional */
172 PFC8582_WADDR, /* EEProm type */
173 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
174 { 0x00, 0x02, 0x01, 0x04, 1 }, /* audio MUX values */
175 0x0f }, /* GPIO mask */
177 { CARD_STB, /* the card id */
178 "STB TV/PCI", /* the 'name' */
179 NULL, /* the tuner */
180 0, /* the tuner i2c address */
181 0, /* dbx is optional */
184 X24C01_WADDR, /* EEProm type */
185 (u_char)(128 / EEPROMBLOCKSIZE), /* 128 bytes */
186 { 0x00, 0x01, 0x02, 0x02, 1 }, /* audio MUX values */
187 0x0f }, /* GPIO mask */
189 { CARD_INTEL, /* the card id */
190 "Intel Smart Video III/VideoLogic Captivator PCI", /* the 'name' */
191 NULL, /* the tuner */
192 0, /* the tuner i2c address */
198 { 0, 0, 0, 0, 0 }, /* audio MUX values */
199 0x00 }, /* GPIO mask */
201 { CARD_IMS_TURBO, /* the card id */
202 "IMS TV Turbo", /* the 'name' */
203 NULL, /* the tuner */
204 0, /* the tuner i2c address */
205 0, /* dbx is optional */
208 PFC8582_WADDR, /* EEProm type */
209 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
210 { 0x01, 0x02, 0x01, 0x00, 1 }, /* audio MUX values */
211 0x0f }, /* GPIO mask */
213 { CARD_AVER_MEDIA, /* the card id */
214 "AVer Media TV/FM", /* the 'name' */
215 NULL, /* the tuner */
216 0, /* the tuner i2c address */
217 0, /* dbx is optional */
222 { 0x0c, 0x08, 0x04, 0x00, 1 }, /* audio MUX values */
223 0x1f }, /* GPIO mask */
225 { CARD_OSPREY, /* the card id */
226 "MMAC Osprey", /* the 'name' */
227 NULL, /* the tuner */
228 0, /* the tuner i2c address */
229 0, /* dbx is optional */
232 PFC8582_WADDR, /* EEProm type */
233 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
234 { 0x00, 0x00, 0x00, 0x00, 0 }, /* audio MUX values */
237 { CARD_NEC_PK, /* the card id */
238 "NEC PK-UG-X017", /* the 'name' */
239 NULL, /* the tuner */
240 0, /* the tuner i2c address */
241 0, /* dbx is optional */
246 { 0x01, 0x02, 0x01, 0x00, 1 }, /* audio MUX values */
247 0x0f }, /* GPIO mask */
249 { CARD_IO_BCTV2, /* the card id */
250 "I/O DATA GV-BCTV2/PCI", /* the 'name' */
251 NULL, /* the tuner */
252 0, /* the tuner i2c address */
253 0, /* dbx is optional */
258 { 0x00, 0x00, 0x00, 0x00, 1 }, /* Has special MUX handler */
259 0x0f }, /* GPIO mask */
261 { CARD_FLYVIDEO, /* the card id */
262 "FlyVideo", /* the 'name' */
263 NULL, /* the tuner */
264 0, /* the tuner i2c address */
265 0, /* dbx is optional */
266 0, /* msp34xx is optional */
267 0, /* dpl3518a is optional */
268 0xac, /* EEProm type */
269 (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */
270 { 0x000, 0x800, 0x400, 0x8dff00, 1 },/* audio MUX values */
271 0x8dff00 }, /* GPIO mask */
273 { CARD_ZOLTRIX, /* the card id */
274 "Zoltrix", /* the 'name' */
275 NULL, /* the tuner */
276 0, /* the tuner i2c address */
277 0, /* dbx is optional */
278 0, /* msp34xx is optional */
279 0, /* dpl3518a is optional */
282 { 0x04, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */
283 0x0f }, /* GPIO mask */
285 { CARD_KISS, /* the card id */
286 "KISS TV/FM PCI", /* the 'name' */
287 NULL, /* the tuner */
288 0, /* the tuner i2c address */
289 0, /* dbx is optional */
290 0, /* msp34xx is optional */
291 0, /* dpl3518a is optional */
294 { 0x0c, 0x00, 0x0b, 0x0b, 1 }, /* audio MUX values */
295 0x0f }, /* GPIO mask */
297 { CARD_VIDEO_HIGHWAY_XTREME, /* the card id */
298 "Video Highway Xtreme", /* the 'name' */
299 NULL, /* the tuner */
306 { 0x00, 0x02, 0x01, 0x04, 1 }, /* audio MUX values */
307 0x0f }, /* GPIO mask */
309 { CARD_ASKEY_DYNALINK_MAGIC_TVIEW, /* the card id */
310 "Askey/Dynalink Magic TView", /* the 'name' */
311 NULL, /* the tuner */
318 { 0x400, 0xE00, 0x400, 0xC00, 1 }, /* audio MUX values */
319 0xE00 }, /* GPIO mask */
321 { CARD_LEADTEK, /* the card id */
322 "Leadtek Winfast TV 2000", /* the 'name' */
323 NULL, /* the tuner */
330 /* Tuner, Extern, Intern, Mute, Enabled */
331 { 0x621000, 0x621000, 0x621000, 0xE21000, 1 }, /* audio MUX values */
332 0xfff000 }, /* GPIO mask */
334 { CARD_TERRATVPLUS, /* the card id */
335 "TerraTVplus", /* the 'name' */
336 NULL, /* the tuner */
343 { 0x20000, 0x00000, 0x30000, 0x40000, 1 }, /* audio MUX values*/
344 0x70000 }, /* GPIO mask */
346 { CARD_IO_BCTV3, /* the card id */
347 "I/O DATA GV-BCTV3/PCI", /* the 'name' */
348 NULL, /* the tuner */
349 0, /* the tuner i2c address */
350 0, /* dbx is optional */
355 /* Tuner, Extern, Intern, Mute, Enabled */
356 { 0x10000, 0, 0x10000, 0, 1 }, /* audio MUX values */
357 0x10f00 }, /* GPIO mask */
361 struct bt848_card_sig bt848_card_signature[1]= {
362 /* IMS TURBO TV : card 5 */
363 { 5,9, {00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 02, 00, 00, 00}}
370 * Write to the configuration EEPROM on the card.
371 * This is dangerous and will mess up your card. Therefore it is not
375 writeEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data )
381 * Read the contents of the configuration EEPROM on the card.
382 * (This is not fitted to all makes of card. All Hauppauge cards have them
383 * and so do newer Bt878 based cards.
386 readEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data )
393 /* get the address of the EEProm */
394 addr = (int)(bktr->card.eepromAddr & 0xff);
398 max = (int)(bktr->card.eepromSize * EEPROMBLOCKSIZE);
399 if ( (offset + count) > max )
402 /* set the start address */
403 if ( i2cWrite( bktr, addr, offset, -1 ) == -1 )
407 for ( x = 0; x < count; ++x ) {
408 if ( (byte = i2cRead( bktr, (addr | 1) )) == -1 )
420 * get a signature of the card
421 * read all 128 possible i2c read addresses from 0x01 thru 0xff
422 * build a bit array with a 1 bit for each i2c device that responds
424 * XXX FIXME: use offset & count args
427 signCard( bktr_ptr_t bktr, int offset, int count, u_char* sig )
431 for ( x = 0; x < 16; ++x )
434 for ( x = 0; x < count; ++x ) {
435 if ( i2cRead( bktr, (2 * x) + 1 ) != ABSENT ) {
436 sig[ x / 8 ] |= (1 << (x % 8) );
445 * check_for_i2c_devices.
446 * Some BT848 cards have no tuner and no additional i2c devices
447 * eg stereo decoder. These are used for video conferencing or capture from
448 * a video camera. (eg VideoLogic Captivator PCI, Intel SmartCapture card).
450 * Determine if there are any i2c devices present. There are none present if
451 * a) reading from all 128 devices returns ABSENT (-1) for each one
452 * (eg VideoLogic Captivator PCI with BT848)
453 * b) reading from all 128 devices returns 0 for each one
454 * (eg VideoLogic Captivator PCI rev. 2F with BT848A)
456 static int check_for_i2c_devices( bktr_ptr_t bktr ){
459 int i2c_all_absent = 1;
460 for ( x = 0; x < 128; ++x ) {
461 temp_read = i2cRead( bktr, (2 * x) + 1 );
462 if (temp_read != 0) i2c_all_0 = 0;
463 if (temp_read != ABSENT) i2c_all_absent = 0;
466 if ((i2c_all_0) || (i2c_all_absent)) return 0;
472 * Temic/Philips datasheets say tuners can be at i2c addresses 0xc0, 0xc2,
473 * 0xc4 or 0xc6, settable by links on the tuner.
474 * Determine the actual address used on the TV card by probing read addresses.
476 static int locate_tuner_address( bktr_ptr_t bktr) {
477 if (i2cRead( bktr, 0xc1) != ABSENT) return 0xc0;
478 if (i2cRead( bktr, 0xc3) != ABSENT) return 0xc2;
479 if (i2cRead( bktr, 0xc5) != ABSENT) return 0xc4;
480 if (i2cRead( bktr, 0xc7) != ABSENT) return 0xc6;
481 return -1; /* no tuner found */
486 * Search for a configuration EEPROM on the i2c bus by looking at i2c addresses
487 * where EEPROMs are usually found.
488 * On some cards, the EEPROM appears in several locations, but all in the
489 * range 0xa0 to 0xae.
491 static int locate_eeprom_address( bktr_ptr_t bktr) {
492 if (i2cRead( bktr, 0xa0) != ABSENT) return 0xa0;
493 if (i2cRead( bktr, 0xac) != ABSENT) return 0xac;
494 if (i2cRead( bktr, 0xae) != ABSENT) return 0xae;
495 return -1; /* no eeprom found */
500 * determine the card brand/model
501 * BKTR_OVERRIDE_CARD, BKTR_OVERRIDE_TUNER, BKTR_OVERRIDE_DBX and
502 * BKTR_OVERRIDE_MSP can be used to select a specific device,
503 * regardless of the autodetection and i2c device checks.
505 * The scheme used for probing cards faces these problems:
506 * It is impossible to work out which type of tuner is actually fitted,
507 * (the driver cannot tell if the Tuner is PAL or NTSC, Temic or Philips)
508 * It is impossible to determine what audio-mux hardware is connected.
509 * It is impossible to determine if there is extra hardware connected to the
510 * GPIO pins (eg radio chips or MSP34xx reset logic)
512 * However some makes of card (eg Hauppauge) come with a configuration eeprom
513 * which tells us the make of the card. Most eeproms also tell us the
514 * tuner type and other features of the the cards.
516 * The current probe code works as follows
517 * A) If the card uses a Bt878/879:
518 * 1) Read the sub-system vendor id from the configuration EEPROM.
519 * Select the required tuner, audio mux arrangement and any other
520 * onboard features. If this fails, move to step B.
521 * B) If it card uses a Bt848, 848A, 849A or an unknown Bt878/879:
522 * 1) Look for I2C devices. If there are none fitted, it is an Intel or
524 * 2) Look for a configuration EEPROM.
525 * 2a) If there is one at I2C address 0xa0 it may be
526 * a Hauppauge or an Osprey. Check the EEPROM contents to determine which
527 * one it is. For Hauppauge, select the tuner type and audio hardware.
528 * 2b) If there is an EEPROM at I2C address 0xa8 it will be an STB card.
529 * We still have to guess on the tuner type.
531 * C) If we do not know the card type from (A) or (B), guess at the tuner
532 * type based on the I2C address of the tuner.
534 * D) After determining the Tuner Type, we probe the i2c bus for other
535 * devices at known locations, eg IR-Remote Control, MSP34xx and TDA
541 * These are the sub-system vendor ID codes stored in the
542 * configuration EEPROM used on Bt878/879 cards. They should match the
543 * number assigned to the company by the PCI Special Interest Group
546 #define PCI_VENDOR_HAUPPAUGE 0x0070
547 #define PCI_VENDOR_AVERMEDIA 0x1461
548 #define PCI_VENDOR_STB 0x10B4
549 #define PCI_VENDOR_ASKEY 0x144F
551 /* Following not confirmed with http://members.hyperlink.net.au/~chart,
552 so not added to NetBSD's pcidevs */
553 #define PCI_VENDOR_LEADTEK_ALT 0x6606
554 #define PCI_VENDOR_FLYVIDEO 0x1851
555 #define PCI_VENDOR_FLYVIDEO_2 0x1852
556 #define PCI_VENDOR_PINNACLE_ALT 0xBD11
557 #define PCI_VENDOR_IODATA 0x10fc
559 #define MODEL_IODATA_GV_BCTV3_PCI 0x4020
562 probeCard( bktr_ptr_t bktr, int verbose, int unit )
564 int card, i,j, card_found;
566 u_char probe_signature[128], *probe_temp;
569 int tuner_i2c_address = -1;
570 int eeprom_i2c_address = -1;
572 /* Select all GPIO bits as inputs */
573 OUTL(bktr, BKTR_GPIO_OUT_EN, 0);
575 printf("%s: GPIO is 0x%08x\n", bktr_name(bktr),
576 INL(bktr, BKTR_GPIO_DATA));
578 #ifdef HAUPPAUGE_MSP_RESET
579 /* Reset the MSP34xx audio chip. This resolves bootup card
580 * detection problems with old Bt848 based Hauppauge cards with
581 * MSP34xx stereo audio chips. This must be user enabled because
582 * at this point the probe function does not know the card type. */
583 OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5));
584 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */
585 DELAY(2500); /* wait 2.5ms */
586 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */
587 DELAY(2500); /* wait 2.5ms */
588 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */
589 DELAY(2500); /* wait 2.5ms */
592 /* Check for the presence of i2c devices */
593 any_i2c_devices = check_for_i2c_devices( bktr );
596 /* Check for a user specified override on the card selection */
597 #if defined( BKTR_OVERRIDE_CARD )
598 bktr->card = cards[ (card = BKTR_OVERRIDE_CARD) ];
601 if (bktr->bt848_card != -1 ) {
602 bktr->card = cards[ (card = bktr->bt848_card) ];
607 /* No override, so try and determine the make of the card */
609 /* On BT878/879 cards, read the sub-system vendor id */
610 /* This identifies the manufacturer of the card and the model */
611 /* In theory this can be read from PCI registers but this does not */
612 /* appear to work on the FlyVideo 98. Hauppauge also warned that */
613 /* the PCI registers are sometimes not loaded correctly. */
614 /* Therefore, I will read the sub-system vendor ID from the EEPROM */
615 /* (just like the Bt878 does during power up initialisation) */
617 if ((bktr->id==BROOKTREE_878) || (bktr->id==BROOKTREE_879)) {
618 /* Try and locate the EEPROM */
619 eeprom_i2c_address = locate_eeprom_address( bktr );
620 if (eeprom_i2c_address != -1) {
622 unsigned int subsystem_vendor_id; /* vendors PCI-SIG ID */
623 unsigned int subsystem_id; /* board model number */
624 unsigned int byte_252, byte_253, byte_254, byte_255;
626 bktr->card = cards[ (card = CARD_UNKNOWN) ];
627 bktr->card.eepromAddr = eeprom_i2c_address;
628 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
630 readEEProm(bktr, 0, 256, (u_char *) &eeprom );
631 byte_252 = (unsigned int)eeprom[252];
632 byte_253 = (unsigned int)eeprom[253];
633 byte_254 = (unsigned int)eeprom[254];
634 byte_255 = (unsigned int)eeprom[255];
636 subsystem_id = (byte_252 << 8) | byte_253;
637 subsystem_vendor_id = (byte_254 << 8) | byte_255;
640 printf("%s: subsystem 0x%04x 0x%04x\n", bktr_name(bktr),
641 subsystem_vendor_id, subsystem_id);
643 if (subsystem_vendor_id == PCI_VENDOR_AVERMEDIA) {
644 bktr->card = cards[ (card = CARD_AVER_MEDIA) ];
645 bktr->card.eepromAddr = eeprom_i2c_address;
646 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
650 if (subsystem_vendor_id == PCI_VENDOR_HAUPPAUGE) {
651 bktr->card = cards[ (card = CARD_HAUPPAUGE) ];
652 bktr->card.eepromAddr = eeprom_i2c_address;
653 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
657 if ((subsystem_vendor_id == PCI_VENDOR_FLYVIDEO)
658 || (subsystem_vendor_id == PCI_VENDOR_FLYVIDEO_2) ) {
659 bktr->card = cards[ (card = CARD_FLYVIDEO) ];
660 bktr->card.eepromAddr = eeprom_i2c_address;
661 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
665 if (subsystem_vendor_id == PCI_VENDOR_STB) {
666 bktr->card = cards[ (card = CARD_STB) ];
667 bktr->card.eepromAddr = eeprom_i2c_address;
668 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
672 if (subsystem_vendor_id == PCI_VENDOR_ASKEY) {
673 bktr->card = cards[ (card = CARD_ASKEY_DYNALINK_MAGIC_TVIEW) ];
674 bktr->card.eepromAddr = eeprom_i2c_address;
675 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
679 if (subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT) {
680 bktr->card = cards[ (card = CARD_LEADTEK) ];
681 bktr->card.eepromAddr = eeprom_i2c_address;
682 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
686 if (subsystem_vendor_id == PCI_VENDOR_PINNACLE_ALT) {
687 bktr->card = cards[ (card = CARD_MIRO) ];
688 bktr->card.eepromAddr = eeprom_i2c_address;
689 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
693 if (subsystem_vendor_id == 0x10fc &&
694 subsystem_id == 0x4020) {
695 bktr->card = cards[ (card = CARD_IO_BCTV3) ];
696 bktr->card.eepromAddr = eeprom_i2c_address;
697 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
701 /* Vendor is unknown. We will use the standard probe code */
702 /* which may not give best results */
703 printf("%s: Warning - card vendor 0x%04x (model 0x%04x) unknown.\n",
704 bktr_name(bktr), subsystem_vendor_id, subsystem_id);
708 printf("%s: Card has no configuration EEPROM. Cannot determine card make.\n",
711 } /* end of bt878/bt879 card detection code */
713 /* If we get to this point, we must have a Bt848/848A/849A card */
714 /* or a Bt878/879 with an unknown subsystem vendor id */
715 /* Try and determine the make of card by clever i2c probing */
717 /* Check for i2c devices. If none, move on */
718 if (!any_i2c_devices) {
719 bktr->card = cards[ (card = CARD_INTEL) ];
720 bktr->card.eepromAddr = 0;
721 bktr->card.eepromSize = 0;
725 /* Look for Hauppauge, STB and Osprey cards by the presence */
727 /* Note: Bt878 based cards also use EEPROMs so we can only do this */
728 /* test on BT848/848A and 849A based cards. */
729 if ((bktr->id==BROOKTREE_848) ||
730 (bktr->id==BROOKTREE_848A) ||
731 (bktr->id==BROOKTREE_849A)) {
733 /* At i2c address 0xa0, look for Hauppauge and Osprey cards */
734 if ( (status = i2cRead( bktr, PFC8582_RADDR )) != ABSENT ) {
736 /* Read the eeprom contents */
737 bktr->card = cards[ (card = CARD_UNKNOWN) ];
738 bktr->card.eepromAddr = PFC8582_WADDR;
739 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
740 readEEProm(bktr, 0, 128, (u_char *) &eeprom );
742 /* For Hauppauge, check the EEPROM begins with 0x84 */
743 if (eeprom[0] == 0x84) {
744 bktr->card = cards[ (card = CARD_HAUPPAUGE) ];
745 bktr->card.eepromAddr = PFC8582_WADDR;
746 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
750 /* For Osprey, check the EEPROM begins with "MMAC" */
751 if ( (eeprom[0] == 'M') &&(eeprom[1] == 'M')
752 &&(eeprom[2] == 'A') &&(eeprom[3] == 'C')) {
753 bktr->card = cards[ (card = CARD_OSPREY) ];
754 bktr->card.eepromAddr = PFC8582_WADDR;
755 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
758 printf("%s: Warning: Unknown card type. EEPROM data not recognised\n",
760 printf("%s: %x %x %x %x\n", bktr_name(bktr),
761 eeprom[0],eeprom[1],eeprom[2],eeprom[3]);
764 /* look for an STB card */
765 if ( (status = i2cRead( bktr, X24C01_RADDR )) != ABSENT ) {
766 bktr->card = cards[ (card = CARD_STB) ];
767 bktr->card.eepromAddr = X24C01_WADDR;
768 bktr->card.eepromSize = (u_char)(128 / EEPROMBLOCKSIZE);
774 signCard( bktr, 1, 128, (u_char *) &probe_signature );
777 printf("%s: card signature: ", bktr_name(bktr));
778 for (j = 0; j < Bt848_MAX_SIGN; j++) {
779 printf(" %02x ", probe_signature[j]);
784 i < (sizeof bt848_card_signature)/ sizeof (struct bt848_card_sig);
788 probe_temp = (u_char *) &bt848_card_signature[i].signature;
790 for (j = 0; j < Bt848_MAX_SIGN; j++) {
791 if ((probe_temp[j] & 0xf) != (probe_signature[j] & 0xf)) {
798 bktr->card = cards[ card = bt848_card_signature[i].card];
799 eeprom_i2c_address = locate_eeprom_address( bktr );
800 if (eeprom_i2c_address != -1) {
801 bktr->card.eepromAddr = eeprom_i2c_address;
802 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
804 bktr->card.eepromAddr = 0;
805 bktr->card.eepromSize = 0;
807 tuner_i2c_address = locate_tuner_address( bktr );
808 select_tuner( bktr, bt848_card_signature[i].tuner );
813 /* We do not know the card type. Default to Miro */
814 bktr->card = cards[ (card = CARD_MIRO) ];
818 /* look for a configuration eeprom */
819 eeprom_i2c_address = locate_eeprom_address( bktr );
820 if (eeprom_i2c_address != -1) {
821 bktr->card.eepromAddr = eeprom_i2c_address;
822 bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
824 bktr->card.eepromAddr = 0;
825 bktr->card.eepromSize = 0;
831 /* look for a tuner */
832 tuner_i2c_address = locate_tuner_address( bktr );
833 if ( tuner_i2c_address == -1 ) {
834 select_tuner( bktr, NO_TUNER );
838 #if defined( BKTR_OVERRIDE_TUNER )
839 select_tuner( bktr, BKTR_OVERRIDE_TUNER );
842 if (bktr->bt848_tuner != -1 ) {
843 select_tuner( bktr, bktr->bt848_tuner & 0xff );
847 /* Check for i2c devices */
848 if (!any_i2c_devices) {
849 select_tuner( bktr, NO_TUNER );
853 /* differentiate type of tuner */
857 switch (((INL(bktr, BKTR_GPIO_DATA) >> 10)-1)&7) {
858 case 0: select_tuner( bktr, TEMIC_PAL ); break;
859 case 1: select_tuner( bktr, PHILIPS_PAL ); break;
860 case 2: select_tuner( bktr, PHILIPS_NTSC ); break;
861 case 3: select_tuner( bktr, PHILIPS_SECAM ); break;
862 case 4: select_tuner( bktr, NO_TUNER ); break;
863 case 5: select_tuner( bktr, PHILIPS_PALI ); break;
864 case 6: select_tuner( bktr, TEMIC_NTSC ); break;
865 case 7: select_tuner( bktr, TEMIC_PALI ); break;
871 /* Hauppauge kindly supplied the following Tuner Table */
872 /* FIXME: I think the tuners the driver selects for types */
873 /* 0x08 and 0x15 may be incorrect but no one has complained. */
874 /* Old Temic tuners had their own API, but newer Temic tuners */
875 /* have the same API as Philips tuners */
877 ID Tuner Model Format We select Format
881 0x03 Philips FI1216 BG
882 0x04 Philips FI1216MF BGLL' PHILIPS_SECAM
883 0x05 Philips FI1236 MN PHILIPS_NTSC
884 0x06 Philips FI1246 I PHILIPS_PALI
885 0x07 Philips FI1256 DK
886 0x08 Philips FI1216 MK2 BG PHILIPS_PALI
887 0x09 Philips FI1216MF MK2 BGLL' PHILIPS_SECAM
888 0x0a Philips FI1236 MK2 MN PHILIPS_NTSC
889 0x0b Philips FI1246 MK2 I PHILIPS_PALI
890 0x0c Philips FI1256 MK2 DK
891 0x0d Temic 4032FY5 NTSC TEMIC_NTSC
892 0x0e Temic 4002FH5 BG TEMIC_PAL
893 0x0f Temic 4062FY5 I TEMIC_PALI
894 0x10 Philips FR1216 MK2 BG
895 0x11 Philips FR1216MF MK2 BGLL' PHILIPS_FR1236_SECAM
896 0x12 Philips FR1236 MK2 MN PHILIPS_FR1236_NTSC
897 0x13 Philips FR1246 MK2 I
898 0x14 Philips FR1256 MK2 DK
899 0x15 Philips FM1216 BG PHILIPS_FR1216_PAL
900 0x16 Philips FM1216MF BGLL' PHILIPS_FR1236_SECAM
901 0x17 Philips FM1236 MN PHILIPS_FR1236_NTSC
902 0x18 Philips FM1246 I
903 0x19 Philips FM1256 DK
904 0x1a Temic 4036FY5 MN (FI1236 MK2 clone) PHILIPS_NTSC
905 0x1b Samsung TCPN9082D MN
906 0x1c Samsung TCPM9092P Pal BG/I/DK
907 0x1d Temic 4006FH5 BG PHILIPS_PALI
908 0x1e Samsung TCPN9085D MN/Radio
909 0x1f Samsung TCPB9085P Pal BG/I/DK / Radio
910 0x20 Samsung TCPL9091P Pal BG & Secam L/L'
911 0x21 Temic 4039FY5 NTSC Radio
912 0x22 Philips FQ1216ME Pal BGIDK & Secam L/L'
913 0x23 Temic 4066FY5 Pal I (FI1246 MK2 clone) PHILIPS_PALI
914 0x24 Philips TD1536 MN/ATSCDigital
915 0x25 Philips TD1536D MN/ATSCDigital DUAL INPUT
916 0x26 Philips FMR1236 M/N FM(no demod)
917 0x27 Philips FI1256MP B/G, D/K
918 0x28 Samsung TCPQ9091P BG/I/DK, L/L'
919 0x29 Temic 4006FN5 BG/I/DK
920 0x2a Temic 4009FR5 BG FM PHILIPS_FR1216_PAL
921 0x2b Temic 4046FM5 B/G, I, D/K, L/L'
922 0x2c Temic 4009FN5 B/G, I, D/K, FM (no demod)
923 0x2d Philips TD1536D_FH_44 MN/ATSCDigital DUAL INPUT
927 /* Determine the model number from the eeprom */
928 if (bktr->card.eepromAddr != 0) {
929 /* eeprom data block structure */
930 unsigned char *block_1, *block_2, *block_3, *block_4;
931 int block_1_data_size, block_2_data_size, block_3_data_size;
932 int block_1_total_size, block_2_total_size, block_3_total_size;
933 int block_4_header_size;
935 unsigned int model,revision;
936 unsigned char tuner_code;
937 unsigned char no_audio_mux;
939 readEEProm(bktr, 0, 128, (u_char *) &eeprom );
941 /* LOCATE THE EEPROM DATA BLOCKS */
942 block_1 = &eeprom[0];
943 block_1_data_size = (block_1[2] << 8 | block_1[1]);
944 block_1_total_size = block_1_data_size + 3; /* Header bytes */
946 block_2 = &eeprom[block_1_total_size];
947 block_2_data_size = (block_2[2] << 8 | block_2[1]);
948 block_2_total_size = block_2_data_size + 3; /* Header bytes */
950 block_3 = &eeprom[block_1_total_size + block_2_total_size];
951 block_3_data_size = (block_3[0] &0x07);
952 block_3_total_size = block_3_data_size + 1; /* Header size */
954 block_4 = &eeprom[block_1_total_size +block_2_total_size +block_3_total_size];
955 block_4_header_size = 1;
957 model = (block_1[12] << 8 | block_1[11]);
958 revision = (block_1[15] << 16 | block_1[14] << 8 | block_1[13]);
960 tuner_code = block_1[9];
962 no_audio_mux = ((block_3[3] >> 7) &0x01);
964 if (no_audio_mux) bktr->audio_mux_present = 0;
967 printf("%s: Hauppauge Model %d %c%c%c%c\n",
970 ((revision >> 18) & 0x3f) + 32,
971 ((revision >> 12) & 0x3f) + 32,
972 ((revision >> 6) & 0x3f) + 32,
973 ((revision >> 0) & 0x3f) + 32 );
975 /* Determine the tuner type from the eeprom */
977 switch (tuner_code) {
982 select_tuner( bktr, PHILIPS_NTSC );
987 select_tuner( bktr, PHILIPS_SECAM );
992 select_tuner( bktr, PHILIPS_FR1236_SECAM );
998 select_tuner( bktr, PHILIPS_FR1236_NTSC );
1006 select_tuner( bktr, PHILIPS_PALI );
1010 select_tuner( bktr, TEMIC_NTSC );
1014 select_tuner( bktr, TEMIC_PAL );
1018 select_tuner( bktr, TEMIC_PALI );
1022 select_tuner( bktr, PHILIPS_FR1216_PAL );
1026 bktr->msp_use_mono_source = 1;
1027 select_tuner( bktr, PHILIPS_FR1216_PAL );
1031 printf("%s: Warning - Unknown Hauppauge Tuner 0x%x\n",
1032 bktr_name(bktr), tuner_code);
1038 case CARD_AVER_MEDIA:
1039 /* AVerMedia kindly supplied some details of their EEPROM contents
1040 * which allow us to auto select the Tuner Type.
1041 * Only the newer AVerMedia cards actually have an EEPROM.
1043 if (bktr->card.eepromAddr != 0) {
1045 u_char tuner_make; /* Eg Philips, Temic */
1046 u_char tuner_tv_fm; /* TV or TV with FM Radio */
1047 u_char tuner_format; /* Eg NTSC, PAL, SECAM */
1050 int tuner_0_table[] = {
1051 PHILIPS_NTSC, PHILIPS_PAL,
1052 PHILIPS_PAL, PHILIPS_PAL,
1053 PHILIPS_PAL, PHILIPS_PAL,
1054 PHILIPS_SECAM, PHILIPS_SECAM,
1055 PHILIPS_SECAM, PHILIPS_PAL};
1057 int tuner_0_fm_table[] = {
1058 PHILIPS_FR1236_NTSC, PHILIPS_FR1216_PAL,
1059 PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL,
1060 PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL,
1061 PHILIPS_FR1236_SECAM, PHILIPS_FR1236_SECAM,
1062 PHILIPS_FR1236_SECAM, PHILIPS_FR1216_PAL};
1064 int tuner_1_table[] = {
1065 TEMIC_NTSC, TEMIC_PAL, TEMIC_PAL,
1066 TEMIC_PAL, TEMIC_PAL, TEMIC_PAL,
1067 TEMIC_SECAM, TEMIC_SECAM, TEMIC_SECAM,
1071 /* Extract information from the EEPROM data */
1072 readEEProm(bktr, 0, 128, (u_char *) &eeprom );
1074 tuner_make = (eeprom[0x41] & 0x7);
1075 tuner_tv_fm = (eeprom[0x41] & 0x18) >> 3;
1076 tuner_format = (eeprom[0x42] & 0xf0) >> 4;
1078 /* Treat tuner make 0 (Philips) and make 2 (LG) the same */
1079 if ( ((tuner_make == 0) || (tuner_make == 2))
1080 && (tuner_format <= 9) && (tuner_tv_fm == 0) ) {
1081 tuner = tuner_0_table[tuner_format];
1082 select_tuner( bktr, tuner );
1086 if ( ((tuner_make == 0) || (tuner_make == 2))
1087 && (tuner_format <= 9) && (tuner_tv_fm == 1) ) {
1088 tuner = tuner_0_fm_table[tuner_format];
1089 select_tuner( bktr, tuner );
1093 if ( (tuner_make == 1) && (tuner_format <= 9) ) {
1094 tuner = tuner_1_table[tuner_format];
1095 select_tuner( bktr, tuner );
1099 printf("%s: Warning - Unknown AVerMedia Tuner Make %d Format %d\n",
1100 bktr_name(bktr), tuner_make, tuner_format);
1105 #if BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL
1106 select_tuner( bktr, PHILIPS_FR1216_PAL );
1108 select_tuner( bktr, PHILIPS_FR1236_NTSC );
1114 select_tuner( bktr, ALPS_TSCH5 ); /* ALPS_TSCH6, in fact. */
1118 } /* end switch(card) */
1121 /* At this point, a goto checkDBX has not occured */
1122 /* We have not been able to select a Tuner */
1123 /* Some cards make use of the tuner address to */
1124 /* identify the make/model of tuner */
1126 /* At address 0xc0/0xc1 we often find a TEMIC NTSC */
1127 if ( i2cRead( bktr, 0xc1 ) != ABSENT ) {
1128 select_tuner( bktr, TEMIC_NTSC );
1132 /* At address 0xc6/0xc7 we often find a PHILIPS NTSC Tuner */
1133 if ( i2cRead( bktr, 0xc7 ) != ABSENT ) {
1134 select_tuner( bktr, PHILIPS_NTSC );
1138 /* Address 0xc2/0xc3 is default (or common address) for several */
1139 /* tuners and we cannot tell which is which. */
1140 /* And for all other tuner i2c addresses, select the default */
1141 select_tuner( bktr, DEFAULT_TUNER );
1145 #if defined( BKTR_OVERRIDE_DBX )
1146 bktr->card.dbx = BKTR_OVERRIDE_DBX;
1149 /* Check for i2c devices */
1150 if (!any_i2c_devices) {
1154 /* probe for BTSC (dbx) chip */
1155 if ( i2cRead( bktr, TDA9850_RADDR ) != ABSENT )
1159 /* If this is a Hauppauge Bt878 card, we need to enable the
1160 * MSP 34xx audio chip.
1161 * If this is a Hauppauge Bt848 card, reset the MSP device.
1162 * The MSP reset line is wired to GPIO pin 5. On Bt878 cards a pulldown
1163 * resistor holds the device in reset until we set GPIO pin 5.
1166 /* Optionally skip the MSP reset. This is handy if you initialise the
1167 * MSP audio in another operating system (eg Windows) first and then
1171 #ifndef BKTR_NO_MSP_RESET
1172 if (card == CARD_HAUPPAUGE) {
1173 OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5));
1174 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */
1175 DELAY(2500); /* wait 2.5ms */
1176 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */
1177 DELAY(2500); /* wait 2.5ms */
1178 OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */
1179 DELAY(2500); /* wait 2.5ms */
1183 #if defined( BKTR_OVERRIDE_MSP )
1184 bktr->card.msp3400c = BKTR_OVERRIDE_MSP;
1188 /* Check for i2c devices */
1189 if (!any_i2c_devices) {
1193 if ( i2cRead( bktr, MSP3400C_RADDR ) != ABSENT ) {
1194 bktr->card.msp3400c = 1;
1199 if (bktr->card.msp3400c) {
1200 bktr->msp_addr = MSP3400C_WADDR;
1201 msp_read_id( bktr );
1202 printf("%s: Detected a MSP%s at 0x%x\n", bktr_name(bktr),
1203 bktr->msp_version_string,
1208 /* Check for Dolby Surround Sound DPL3518A sound chip */
1209 if ( i2cRead( bktr, DPL3518A_RADDR ) != ABSENT ) {
1210 bktr->card.dpl3518a = 1;
1213 if (bktr->card.dpl3518a) {
1214 bktr->dpl_addr = DPL3518A_WADDR;
1215 dpl_read_id( bktr );
1216 printf("%s: Detected a DPL%s at 0x%x\n", bktr_name(bktr),
1217 bktr->dpl_version_string,
1221 /* Start of Check Remote */
1222 /* Check for the Hauppauge IR Remote Control */
1223 /* If there is an external unit, the internal will be ignored */
1225 bktr->remote_control = 0; /* initial value */
1227 if (any_i2c_devices) {
1228 if (i2cRead( bktr, HAUP_REMOTE_EXT_RADDR ) != ABSENT )
1230 bktr->remote_control = 1;
1231 bktr->remote_control_addr = HAUP_REMOTE_EXT_RADDR;
1233 else if (i2cRead( bktr, HAUP_REMOTE_INT_RADDR ) != ABSENT )
1235 bktr->remote_control = 1;
1236 bktr->remote_control_addr = HAUP_REMOTE_INT_RADDR;
1240 /* If a remote control is found, poll it 5 times to turn off the LED */
1241 if (bktr->remote_control) {
1244 i2cRead( bktr, bktr->remote_control_addr );
1246 /* End of Check Remote */
1248 #if defined( BKTR_USE_PLL )
1249 bktr->xtal_pll_mode = BT848_USE_PLL;
1252 /* Default is to use XTALS and not PLL mode */
1253 bktr->xtal_pll_mode = BT848_USE_XTALS;
1255 /* Enable PLL mode for OSPREY users */
1256 if (card == CARD_OSPREY)
1257 bktr->xtal_pll_mode = BT848_USE_PLL;
1259 /* Enable PLL mode for Video Highway Xtreme users */
1260 if (card == CARD_VIDEO_HIGHWAY_XTREME)
1261 bktr->xtal_pll_mode = BT848_USE_PLL;
1264 /* Most (perhaps all) Bt878 cards need to be switched to PLL mode */
1265 /* as they only fit the NTSC crystal to their cards */
1266 /* Default to enabling PLL mode for all Bt878/879 cards */
1268 if ((bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) )
1269 bktr->xtal_pll_mode = BT848_USE_PLL;
1272 #if defined( BKTR_USE_PLL )
1277 bktr->card.tuner_pllAddr = tuner_i2c_address;
1280 printf( "%s: %s", bktr_name(bktr), bktr->card.name );
1281 if ( bktr->card.tuner )
1282 printf( ", %s tuner", bktr->card.tuner->name );
1283 if ( bktr->card.dbx )
1284 printf( ", dbx stereo" );
1285 if ( bktr->card.msp3400c )
1286 printf( ", msp3400c stereo" );
1287 if ( bktr->card.dpl3518a )
1288 printf( ", dpl3518a dolby" );
1289 if ( bktr->remote_control )
1290 printf( ", remote control" );