Home | History | Annotate | Line # | Download | only in bktr
bktr_card.c revision 1.11
      1 /*	$NetBSD: bktr_card.c,v 1.11 2001/11/13 07:29:36 lukem Exp $	*/
      2 
      3 /* FreeBSD: src/sys/dev/bktr/bktr_card.c,v 1.16 2000/10/31 13:09:56 roger Exp */
      4 
      5 /*
      6  * This is part of the Driver for Video Capture Cards (Frame grabbers)
      7  * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879
      8  * chipset.
      9  * Copyright Roger Hardiman and Amancio Hasty.
     10  *
     11  * bktr_card : This deals with identifying TV cards.
     12  *               trying to find the card make and model of card.
     13  *               trying to find the type of tuner fitted.
     14  *               reading the configuration EEPROM.
     15  *               locating i2c devices.
     16  *
     17  */
     18 
     19 /*
     20  * 1. Redistributions of source code must retain the
     21  * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman
     22  * All rights reserved.
     23  *
     24  * Redistribution and use in source and binary forms, with or without
     25  * modification, are permitted provided that the following conditions
     26  * are met:
     27  * 1. Redistributions of source code must retain the above copyright
     28  *    notice, this list of conditions and the following disclaimer.
     29  * 2. Redistributions in binary form must reproduce the above copyright
     30  *    notice, this list of conditions and the following disclaimer in the
     31  *    documentation and/or other materials provided with the distribution.
     32  * 3. All advertising materials mentioning features or use of this software
     33  *    must display the following acknowledgement:
     34  *      This product includes software developed by Amancio Hasty and
     35  *      Roger Hardiman
     36  * 4. The name of the author may not be used to endorse or promote products
     37  *    derived from this software without specific prior written permission.
     38  *
     39  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     40  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     41  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     42  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     43  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     44  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     45  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     46  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     47  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     49  * POSSIBILITY OF SUCH DAMAGE.
     50  */
     51 
     52 #include <sys/cdefs.h>
     53 __KERNEL_RCSID(0, "$NetBSD: bktr_card.c,v 1.11 2001/11/13 07:29:36 lukem Exp $");
     54 
     55 #include "opt_bktr.h"		/* Include any kernel config options */
     56 
     57 #include <sys/param.h>
     58 #include <sys/systm.h>
     59 #include <sys/vnode.h>
     60 
     61 #ifdef __FreeBSD__
     62 
     63 #if (__FreeBSD_version < 500000)
     64 #include <machine/clock.h>              /* for DELAY */
     65 #endif
     66 
     67 #include <pci/pcivar.h>
     68 
     69 #if (__FreeBSD_version >=300000)
     70 #include <machine/bus_memio.h>	/* for bus space */
     71 #include <machine/bus.h>
     72 #include <sys/bus.h>
     73 #endif
     74 #endif
     75 
     76 #ifdef __NetBSD__
     77 #include <dev/ic/bt8xx.h>	/* NetBSD location for .h files */
     78 #include <dev/pci/bktr/bktr_reg.h>
     79 #include <dev/pci/bktr/bktr_core.h>
     80 #include <dev/pci/bktr/bktr_tuner.h>
     81 #include <dev/pci/bktr/bktr_card.h>
     82 #include <dev/pci/bktr/bktr_audio.h>
     83 #else
     84 #include <machine/ioctl_meteor.h>	/* Traditional location for .h files */
     85 #include <machine/ioctl_bt848.h>        /* extensions to ioctl_meteor.h */
     86 #include <dev/bktr/bktr_reg.h>
     87 #include <dev/bktr/bktr_core.h>
     88 #include <dev/bktr/bktr_tuner.h>
     89 #include <dev/bktr/bktr_card.h>
     90 #include <dev/bktr/bktr_audio.h>
     91 #endif
     92 
     93 /* Include the PCI Vendor definitions */
     94 #ifdef __NetBSD__
     95 #include <dev/pci/pcidevs.h>
     96 #include <dev/pci/pcireg.h>
     97 #endif
     98 
     99 /* Various defines */
    100 #define HAUP_REMOTE_INT_WADDR   0x30
    101 #define HAUP_REMOTE_INT_RADDR   0x31
    102 
    103 #define HAUP_REMOTE_EXT_WADDR   0x34
    104 #define HAUP_REMOTE_EXT_RADDR   0x35
    105 
    106 /* address of BTSC/SAP decoder chip */
    107 #define TDA9850_WADDR           0xb6
    108 #define TDA9850_RADDR           0xb7
    109 
    110 /* address of MSP3400C chip */
    111 #define MSP3400C_WADDR          0x80
    112 #define MSP3400C_RADDR          0x81
    113 
    114 /* address of DPL3518A chip */
    115 #define DPL3518A_WADDR          0x84
    116 #define DPL3518A_RADDR          0x85
    117 
    118 /* EEProm (128 * 8) on an STB card */
    119 #define X24C01_WADDR            0xae
    120 #define X24C01_RADDR            0xaf
    121 
    122 
    123 /* EEProm (256 * 8) on a Hauppauge card */
    124 /* and on most BT878s cards to store the sub-system vendor id */
    125 #define PFC8582_WADDR           0xa0
    126 #define PFC8582_RADDR		0xa1
    127 
    128 #if BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL
    129 #define DEFAULT_TUNER   PHILIPS_PALI
    130 #else
    131 #define DEFAULT_TUNER   PHILIPS_NTSC
    132 #endif
    133 
    134 
    135 
    136 
    137 /*
    138  * the data for each type of card
    139  *
    140  * Note:
    141  *   these entried MUST be kept in the order defined by the CARD_XXX defines!
    142  */
    143 static const struct CARDTYPE cards[] = {
    144 
    145 	{  CARD_UNKNOWN,			/* the card id */
    146 	  "Unknown",				/* the 'name' */
    147 	   NULL,				/* the tuner */
    148 	   0,					/* the tuner i2c address */
    149 	   0,					/* dbx unknown */
    150 	   0,
    151 	   0,
    152 	   0,					/* EEProm unknown */
    153 	   0,					/* EEProm unknown */
    154 	   { 0, 0, 0, 0, 0 },
    155 	   0 },					/* GPIO mask */
    156 
    157 	{  CARD_MIRO,				/* the card id */
    158 	  "Pinnacle/Miro TV",			/* the 'name' */
    159 	   NULL,				/* the tuner */
    160 	   0,					/* the tuner i2c address */
    161 	   0,					/* dbx unknown */
    162 	   0,
    163 	   0,
    164 	   0,					/* EEProm unknown */
    165 	   0,					/* size unknown */
    166 	   { 0x02, 0x01, 0x00, 0x0a, 1 },	/* audio MUX values */
    167 	   0x0f },				/* GPIO mask */
    168 
    169 	{  CARD_HAUPPAUGE,			/* the card id */
    170 	  "Hauppauge WinCast/TV",		/* the 'name' */
    171 	   NULL,				/* the tuner */
    172 	   0,					/* the tuner i2c address */
    173 	   0,					/* dbx is optional */
    174 	   0,
    175 	   0,
    176 	   PFC8582_WADDR,			/* EEProm type */
    177 	   (u_char)(256 / EEPROMBLOCKSIZE),	/* 256 bytes */
    178 	   { 0x00, 0x02, 0x01, 0x04, 1 },	/* audio MUX values */
    179 	   0x0f },				/* GPIO mask */
    180 
    181 	{  CARD_STB,				/* the card id */
    182 	  "STB TV/PCI",				/* the 'name' */
    183 	   NULL,				/* the tuner */
    184 	   0,					/* the tuner i2c address */
    185 	   0,					/* dbx is optional */
    186 	   0,
    187 	   0,
    188 	   X24C01_WADDR,			/* EEProm type */
    189 	   (u_char)(128 / EEPROMBLOCKSIZE),	/* 128 bytes */
    190 	   { 0x00, 0x01, 0x02, 0x02, 1 }, 	/* audio MUX values */
    191 	   0x0f },				/* GPIO mask */
    192 
    193 	{  CARD_INTEL,				/* the card id */
    194 	  "Intel Smart Video III/VideoLogic Captivator PCI", /* the 'name' */
    195 	   NULL,				/* the tuner */
    196 	   0,					/* the tuner i2c address */
    197 	   0,
    198 	   0,
    199 	   0,
    200 	   0,
    201 	   0,
    202 	   { 0, 0, 0, 0, 0 }, 			/* audio MUX values */
    203 	   0x00 },				/* GPIO mask */
    204 
    205 	{  CARD_IMS_TURBO,			/* the card id */
    206 	  "IMS TV Turbo",			/* the 'name' */
    207 	   NULL,				/* the tuner */
    208 	   0,					/* the tuner i2c address */
    209 	   0,					/* dbx is optional */
    210 	   0,
    211 	   0,
    212 	   PFC8582_WADDR,			/* EEProm type */
    213 	   (u_char)(256 / EEPROMBLOCKSIZE),	/* 256 bytes */
    214 	   { 0x01, 0x02, 0x01, 0x00, 1 },	/* audio MUX values */
    215 	   0x0f },				/* GPIO mask */
    216 
    217         {  CARD_AVER_MEDIA,			/* the card id */
    218           "AVer Media TV/FM",                   /* the 'name' */
    219            NULL,                                /* the tuner */
    220 	   0,					/* the tuner i2c address */
    221            0,                                   /* dbx is optional */
    222            0,
    223 	   0,
    224            0,                                   /* EEProm type */
    225            0,                                   /* EEProm size */
    226            { 0x0c, 0x08, 0x04, 0x00, 1 },	/* audio MUX values */
    227 	   0x1f },				/* GPIO mask */
    228 
    229         {  CARD_OSPREY,				/* the card id */
    230           "MMAC Osprey",                   	/* the 'name' */
    231            NULL,                                /* the tuner */
    232 	   0,					/* the tuner i2c address */
    233            0,                                   /* dbx is optional */
    234 	   0,
    235            0,
    236 	   PFC8582_WADDR,			/* EEProm type */
    237 	   (u_char)(256 / EEPROMBLOCKSIZE),	/* 256 bytes */
    238            { 0x00, 0x00, 0x00, 0x00, 0 },	/* audio MUX values */
    239 	   0 },					/* GPIO mask */
    240 
    241         {  CARD_NEC_PK,                         /* the card id */
    242           "NEC PK-UG-X017",                     /* the 'name' */
    243            NULL,                                /* the tuner */
    244            0,                                   /* the tuner i2c address */
    245            0,                                   /* dbx is optional */
    246 	   0,
    247            0,
    248            0,                                   /* EEProm type */
    249            0,                                   /* EEProm size */
    250            { 0x01, 0x02, 0x01, 0x00, 1 },	/* audio MUX values */
    251 	   0x0f },				/* GPIO mask */
    252 
    253         {  CARD_IO_GV,                          /* the card id */
    254           "I/O DATA GV-BCTV2/PCI",              /* the 'name' */
    255            NULL,                                /* the tuner */
    256            0,                                   /* the tuner i2c address */
    257            0,                                   /* dbx is optional */
    258            0,
    259 	   0,
    260            0,                                   /* EEProm type */
    261            0,                                   /* EEProm size */
    262            { 0x00, 0x00, 0x00, 0x00, 1 },	/* Has special MUX handler */
    263 	   0x0f },				/* GPIO mask */
    264 
    265         {  CARD_FLYVIDEO,			/* the card id */
    266           "FlyVideo",				/* the 'name' */
    267            NULL,				/* the tuner */
    268            0,					/* the tuner i2c address */
    269            0,					/* dbx is optional */
    270            0,					/* msp34xx is optional */
    271            0,					/* dpl3518a is optional */
    272 	   0xac,				/* EEProm type */
    273 	   (u_char)(256 / EEPROMBLOCKSIZE),	/* 256 bytes */
    274            { 0x000, 0x800, 0x400, 0x8dff00, 1 },/* audio MUX values */
    275 	   0x8dff00 },				/* GPIO mask */
    276 
    277 	{  CARD_ZOLTRIX,			/* the card id */
    278 	  "Zoltrix",				/* the 'name' */
    279            NULL,				/* the tuner */
    280            0,					/* the tuner i2c address */
    281            0,					/* dbx is optional */
    282            0,					/* msp34xx is optional */
    283            0,					/* dpl3518a is optional */
    284 	   0,					/* EEProm type */
    285 	   0,					/* EEProm size */
    286 	   { 0x04, 0x01, 0x00, 0x0a, 1 },	/* audio MUX values */
    287 	   0x0f },				/* GPIO mask */
    288 
    289 	{  CARD_KISS,				/* the card id */
    290 	  "KISS TV/FM PCI",			/* the 'name' */
    291            NULL,				/* the tuner */
    292            0,					/* the tuner i2c address */
    293            0,					/* dbx is optional */
    294            0,					/* msp34xx is optional */
    295            0,					/* dpl3518a is optional */
    296 	   0,					/* EEProm type */
    297 	   0,					/* EEProm size */
    298 	   { 0x0c, 0x00, 0x0b, 0x0b, 1 },	/* audio MUX values */
    299 	   0x0f },				/* GPIO mask */
    300 
    301 	{  CARD_VIDEO_HIGHWAY_XTREME,		/* the card id */
    302 	  "Video Highway Xtreme",		/* the 'name' */
    303            NULL,				/* the tuner */
    304 	   0,
    305 	   0,
    306 	   0,
    307 	   0,
    308 	   0,					/* EEProm type */
    309 	   0,					/* EEProm size */
    310 	   { 0x00, 0x02, 0x01, 0x04, 1 },	/* audio MUX values */
    311 	   0x0f },				/* GPIO mask */
    312 
    313 	{  CARD_ASKEY_DYNALINK_MAGIC_TVIEW,	/* the card id */
    314 	  "Askey/Dynalink Magic TView",		/* the 'name' */
    315 	   NULL,				/* the tuner */
    316 	   0,
    317 	   0,
    318 	   0,
    319 	   0,
    320 	   0,					/* EEProm type */
    321 	   0,					/* EEProm size */
    322 	   { 0x400, 0xE00, 0x400, 0xC00, 1 },	/* audio MUX values */
    323 	   0xE00 },				/* GPIO mask */
    324 
    325 	{  CARD_LEADTEK,			/* the card id */
    326 	  "Leadtek Winfast TV 2000",		/* the 'name' */
    327 	   NULL,				/* the tuner */
    328 	   0,
    329 	   0,
    330 	   0,
    331 	   0,
    332 	   0,					/* EEProm type */
    333 	   0,					/* EEProm size */
    334 	   /* Tuner, Extern, Intern, Mute, Enabled */
    335 	   { 0x621000, 0x621000, 0x621000, 0xE21000, 1 }, /* audio MUX values */
    336 	   0xfff000 },				/* GPIO mask */
    337 
    338         {  CARD_TERRATVPLUS,                    /* the card id */
    339           "TerraTVplus",                        /* the 'name' */
    340            NULL,                                /* the tuner */
    341 	   0,
    342 	   0,
    343 	   0,
    344 	   0,
    345 	   0,					/* EEProm type */
    346 	   0,					/* EEProm size */
    347            { 0x20000, 0x00000, 0x30000, 0x40000, 1 }, /* audio MUX values*/
    348            0x70000 },                           /* GPIO mask */
    349 
    350 };
    351 
    352 struct bt848_card_sig bt848_card_signature[1]= {
    353   /* IMS TURBO TV : card 5 */
    354     {  5,9, {00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 02, 00, 00, 00}}
    355 
    356 
    357 };
    358 
    359 
    360 /*
    361  * Write to the configuration EEPROM on the card.
    362  * This is dangerous and will mess up your card. Therefore it is not
    363  * implemented.
    364  */
    365 int
    366 writeEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data )
    367 {
    368         return( -1 );
    369 }
    370 
    371 /*
    372  * Read the contents of the configuration EEPROM on the card.
    373  * (This is not fitted to all makes of card. All Hauppauge cards have them
    374  * and so do newer Bt878 based cards.
    375  */
    376 int
    377 readEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data )
    378 {
    379 	int	x;
    380 	int	addr;
    381 	int	max;
    382 	int	byte;
    383 
    384 	/* get the address of the EEProm */
    385 	addr = (int)(bktr->card.eepromAddr & 0xff);
    386 	if ( addr == 0 )
    387 		return( -1 );
    388 
    389 	max = (int)(bktr->card.eepromSize * EEPROMBLOCKSIZE);
    390 	if ( (offset + count) > max )
    391 		return( -1 );
    392 
    393 	/* set the start address */
    394 	if ( i2cWrite( bktr, addr, offset, -1 ) == -1 )
    395 		return( -1 );
    396 
    397 	/* the read cycle */
    398 	for ( x = 0; x < count; ++x ) {
    399 		if ( (byte = i2cRead( bktr, (addr | 1) )) == -1 )
    400 			return( -1 );
    401 		data[ x ] = byte;
    402 	}
    403 
    404 	return( 0 );
    405 }
    406 
    407 
    408 #define ABSENT		(-1)
    409 
    410 /*
    411  * get a signature of the card
    412  * read all 128 possible i2c read addresses from 0x01 thru 0xff
    413  * build a bit array with a 1 bit for each i2c device that responds
    414  *
    415  * XXX FIXME: use offset & count args
    416  */
    417 int
    418 signCard( bktr_ptr_t bktr, int offset, int count, u_char* sig )
    419 {
    420 	int	x;
    421 
    422 	for ( x = 0; x < 16; ++x )
    423 		sig[ x ] = 0;
    424 
    425 	for ( x = 0; x < count; ++x ) {
    426 		if ( i2cRead( bktr, (2 * x) + 1 ) != ABSENT ) {
    427 			sig[ x / 8 ] |= (1 << (x % 8) );
    428 		}
    429 	}
    430 
    431 	return( 0 );
    432 }
    433 
    434 
    435 /*
    436  * check_for_i2c_devices.
    437  * Some BT848 cards have no tuner and no additional i2c devices
    438  * eg stereo decoder. These are used for video conferencing or capture from
    439  * a video camera. (eg VideoLogic Captivator PCI, Intel SmartCapture card).
    440  *
    441  * Determine if there are any i2c devices present. There are none present if
    442  *  a) reading from all 128 devices returns ABSENT (-1) for each one
    443  *     (eg VideoLogic Captivator PCI with BT848)
    444  *  b) reading from all 128 devices returns 0 for each one
    445  *     (eg VideoLogic Captivator PCI rev. 2F with BT848A)
    446  */
    447 static int check_for_i2c_devices( bktr_ptr_t bktr ){
    448   int x, temp_read;
    449   int i2c_all_0 = 1;
    450   int i2c_all_absent = 1;
    451   for ( x = 0; x < 128; ++x ) {
    452     temp_read = i2cRead( bktr, (2 * x) + 1 );
    453     if (temp_read != 0)      i2c_all_0 = 0;
    454     if (temp_read != ABSENT) i2c_all_absent = 0;
    455   }
    456 
    457   if ((i2c_all_0) || (i2c_all_absent)) return 0;
    458   else return 1;
    459 }
    460 
    461 
    462 /*
    463  * Temic/Philips datasheets say tuners can be at i2c addresses 0xc0, 0xc2,
    464  * 0xc4 or 0xc6, settable by links on the tuner.
    465  * Determine the actual address used on the TV card by probing read addresses.
    466  */
    467 static int locate_tuner_address( bktr_ptr_t bktr) {
    468   if (i2cRead( bktr, 0xc1) != ABSENT) return 0xc0;
    469   if (i2cRead( bktr, 0xc3) != ABSENT) return 0xc2;
    470   if (i2cRead( bktr, 0xc5) != ABSENT) return 0xc4;
    471   if (i2cRead( bktr, 0xc7) != ABSENT) return 0xc6;
    472   return -1; /* no tuner found */
    473 }
    474 
    475 
    476 /*
    477  * Search for a configuration EEPROM on the i2c bus by looking at i2c addresses
    478  * where EEPROMs are usually found.
    479  * On some cards, the EEPROM appears in several locations, but all in the
    480  * range 0xa0 to 0xae.
    481  */
    482 static int locate_eeprom_address( bktr_ptr_t bktr) {
    483   if (i2cRead( bktr, 0xa0) != ABSENT) return 0xa0;
    484   if (i2cRead( bktr, 0xac) != ABSENT) return 0xac;
    485   if (i2cRead( bktr, 0xae) != ABSENT) return 0xae;
    486   return -1; /* no eeprom found */
    487 }
    488 
    489 
    490 /*
    491  * determine the card brand/model
    492  * BKTR_OVERRIDE_CARD, BKTR_OVERRIDE_TUNER, BKTR_OVERRIDE_DBX and
    493  * BKTR_OVERRIDE_MSP can be used to select a specific device,
    494  * regardless of the autodetection and i2c device checks.
    495  *
    496  * The scheme used for probing cards faces these problems:
    497  *  It is impossible to work out which type of tuner is actually fitted,
    498  *  (the driver cannot tell if the Tuner is PAL or NTSC, Temic or Philips)
    499  *  It is impossible to determine what audio-mux hardware is connected.
    500  *  It is impossible to determine if there is extra hardware connected to the
    501  *  GPIO pins  (eg radio chips or MSP34xx reset logic)
    502  *
    503  * However some makes of card (eg Hauppauge) come with a configuration eeprom
    504  * which tells us the make of the card. Most eeproms also tell us the
    505  * tuner type and other features of the the cards.
    506  *
    507  * The current probe code works as follows
    508  * A) If the card uses a Bt878/879:
    509  *   1) Read the sub-system vendor id from the configuration EEPROM.
    510  *      Select the required tuner, audio mux arrangement and any other
    511  *      onboard features. If this fails, move to step B.
    512  * B) If it card uses a Bt848, 848A, 849A or an unknown Bt878/879:
    513  *   1) Look for I2C devices. If there are none fitted, it is an Intel or
    514  *      VideoLogic cards.
    515  *   2) Look for a configuration EEPROM.
    516  *   2a) If there is one at I2C address 0xa0 it may be
    517  *       a Hauppauge or an Osprey. Check the EEPROM contents to determine which
    518  *       one it is. For Hauppauge, select the tuner type and audio hardware.
    519  *   2b) If there is an EEPROM at I2C address 0xa8 it will be an STB card.
    520  *       We still have to guess on the tuner type.
    521  *
    522  * C) If we do not know the card type from (A) or (B), guess at the tuner
    523  *    type based on the I2C address of the tuner.
    524  *
    525  * D) After determining the Tuner Type, we probe the i2c bus for other
    526  *    devices at known locations, eg IR-Remote Control, MSP34xx and TDA
    527  *    stereo chips.
    528  */
    529 
    530 
    531 /*
    532  * These are the sub-system vendor ID codes stored in the
    533  * configuration EEPROM used on Bt878/879 cards. They should match the
    534  * number assigned to the company by the PCI Special Interest Group
    535  */
    536 #ifndef __NetBSD__
    537 #define PCI_VENDOR_HAUPPAUGE	0x0070
    538 #define PCI_VENDOR_AVERMEDIA	0x1461
    539 #define PCI_VENDOR_STB		0x10B4
    540 #define PCI_VENDOR_ASKEY	0x144F
    541 #endif
    542 /* Following not confirmed with http://members.hyperlink.net.au/~chart,
    543    so not added to NetBSD's pcidevs */
    544 #define PCI_VENDOR_LEADTEK_ALT	0x6606
    545 #define PCI_VENDOR_FLYVIDEO	0x1851
    546 #define PCI_VENDOR_FLYVIDEO_2	0x1852
    547 #define PCI_VENDOR_PINNACLE_ALT	0xBD11
    548 
    549 void
    550 probeCard( bktr_ptr_t bktr, int verbose, int unit )
    551 {
    552 	int		card, i,j, card_found;
    553 	int		status;
    554 	u_char 		probe_signature[128], *probe_temp;
    555         int   		any_i2c_devices;
    556 	u_char 		eeprom[256];
    557 	int 		tuner_i2c_address = -1;
    558 	int 		eeprom_i2c_address = -1;
    559 
    560 	/* Select all GPIO bits as inputs */
    561 	OUTL(bktr, BKTR_GPIO_OUT_EN, 0);
    562 	if (bootverbose)
    563 	    printf("%s: GPIO is 0x%08x\n", bktr_name(bktr),
    564 		   INL(bktr, BKTR_GPIO_DATA));
    565 
    566 #ifdef HAUPPAUGE_MSP_RESET
    567 	/* Reset the MSP34xx audio chip. This resolves bootup card
    568 	 * detection problems with old Bt848 based Hauppauge cards with
    569 	 * MSP34xx stereo audio chips. This must be user enabled because
    570 	 * at this point the probe function does not know the card type. */
    571         OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5));
    572         OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5));  /* write '1' */
    573         DELAY(2500); /* wait 2.5ms */
    574         OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */
    575         DELAY(2500); /* wait 2.5ms */
    576         OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5));  /* write '1' */
    577         DELAY(2500); /* wait 2.5ms */
    578 #endif
    579 
    580 	/* Check for the presence of i2c devices */
    581         any_i2c_devices = check_for_i2c_devices( bktr );
    582 
    583 
    584 	/* Check for a user specified override on the card selection */
    585 #if defined( BKTR_OVERRIDE_CARD )
    586 	bktr->card = cards[ (card = BKTR_OVERRIDE_CARD) ];
    587 	goto checkEEPROM;
    588 #endif
    589 	if (bktr->bt848_card != -1 ) {
    590 	  bktr->card = cards[ (card = bktr->bt848_card) ];
    591 	  goto checkEEPROM;
    592 	}
    593 
    594 
    595 	/* No override, so try and determine the make of the card */
    596 
    597         /* On BT878/879 cards, read the sub-system vendor id */
    598 	/* This identifies the manufacturer of the card and the model */
    599 	/* In theory this can be read from PCI registers but this does not */
    600 	/* appear to work on the FlyVideo 98. Hauppauge also warned that */
    601 	/* the PCI registers are sometimes not loaded correctly. */
    602 	/* Therefore, I will read the sub-system vendor ID from the EEPROM */
    603 	/* (just like the Bt878 does during power up initialisation) */
    604 
    605         if ((bktr->id==BROOKTREE_878) || (bktr->id==BROOKTREE_879)) {
    606 	    /* Try and locate the EEPROM */
    607 	    eeprom_i2c_address = locate_eeprom_address( bktr );
    608 	    if (eeprom_i2c_address != -1) {
    609 
    610                 unsigned int subsystem_vendor_id; /* vendors PCI-SIG ID */
    611                 unsigned int subsystem_id;        /* board model number */
    612 		unsigned int byte_252, byte_253, byte_254, byte_255;
    613 
    614 		bktr->card = cards[ (card = CARD_UNKNOWN) ];
    615 		bktr->card.eepromAddr = eeprom_i2c_address;
    616 		bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
    617 
    618 	        readEEProm(bktr, 0, 256, (u_char *) &eeprom );
    619                 byte_252 = (unsigned int)eeprom[252];
    620                 byte_253 = (unsigned int)eeprom[253];
    621                 byte_254 = (unsigned int)eeprom[254];
    622                 byte_255 = (unsigned int)eeprom[255];
    623 
    624                 subsystem_id        = (byte_252 << 8) | byte_253;
    625                 subsystem_vendor_id = (byte_254 << 8) | byte_255;
    626 
    627 	        if ( bootverbose )
    628 	            printf("%s: subsystem 0x%04x 0x%04x\n", bktr_name(bktr),
    629 			   subsystem_vendor_id, subsystem_id);
    630 
    631                 if (subsystem_vendor_id == PCI_VENDOR_AVERMEDIA) {
    632                     bktr->card = cards[ (card = CARD_AVER_MEDIA) ];
    633 		    bktr->card.eepromAddr = eeprom_i2c_address;
    634 		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
    635                     goto checkTuner;
    636                 }
    637 
    638                 if (subsystem_vendor_id == PCI_VENDOR_HAUPPAUGE) {
    639                     bktr->card = cards[ (card = CARD_HAUPPAUGE) ];
    640 		    bktr->card.eepromAddr = eeprom_i2c_address;
    641 		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
    642                     goto checkTuner;
    643                 }
    644 
    645                 if ((subsystem_vendor_id == PCI_VENDOR_FLYVIDEO)
    646                  || (subsystem_vendor_id == PCI_VENDOR_FLYVIDEO_2) ) {
    647                     bktr->card = cards[ (card = CARD_FLYVIDEO) ];
    648 		    bktr->card.eepromAddr = eeprom_i2c_address;
    649 		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
    650                     goto checkTuner;
    651                 }
    652 
    653                 if (subsystem_vendor_id == PCI_VENDOR_STB) {
    654                     bktr->card = cards[ (card = CARD_STB) ];
    655 		    bktr->card.eepromAddr = eeprom_i2c_address;
    656 		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
    657                     goto checkTuner;
    658                 }
    659 
    660                 if (subsystem_vendor_id == PCI_VENDOR_ASKEY) {
    661                     bktr->card = cards[ (card = CARD_ASKEY_DYNALINK_MAGIC_TVIEW) ];
    662 		    bktr->card.eepromAddr = eeprom_i2c_address;
    663 		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
    664                     goto checkTuner;
    665                 }
    666 
    667                 if (subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT) {
    668                     bktr->card = cards[ (card = CARD_LEADTEK) ];
    669 		    bktr->card.eepromAddr = eeprom_i2c_address;
    670 		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
    671                     goto checkTuner;
    672                 }
    673 
    674 		if (subsystem_vendor_id == PCI_VENDOR_PINNACLE_ALT) {
    675                     bktr->card = cards[ (card = CARD_MIRO) ];
    676 		    bktr->card.eepromAddr = eeprom_i2c_address;
    677 		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
    678                     goto checkTuner;
    679                 }
    680 
    681                 /* Vendor is unknown. We will use the standard probe code */
    682 		/* which may not give best results */
    683                 printf("%s: Warning - card vendor 0x%04x (model 0x%04x) unknown.\n",
    684 		       bktr_name(bktr), subsystem_vendor_id, subsystem_id);
    685             }
    686 	    else
    687 	    {
    688                 printf("%s: Card has no configuration EEPROM. Cannot determine card make.\n",
    689 		       bktr_name(bktr));
    690 	    }
    691 	} /* end of bt878/bt879 card detection code */
    692 
    693 	/* If we get to this point, we must have a Bt848/848A/849A card */
    694 	/* or a Bt878/879 with an unknown subsystem vendor id */
    695         /* Try and determine the make of card by clever i2c probing */
    696 
    697    	/* Check for i2c devices. If none, move on */
    698 	if (!any_i2c_devices) {
    699 		bktr->card = cards[ (card = CARD_INTEL) ];
    700 		bktr->card.eepromAddr = 0;
    701 		bktr->card.eepromSize = 0;
    702 		goto checkTuner;
    703 	}
    704 
    705         /* Look for Hauppauge, STB and Osprey cards by the presence */
    706 	/* of an EEPROM */
    707         /* Note: Bt878 based cards also use EEPROMs so we can only do this */
    708         /* test on BT848/848A and 849A based cards. */
    709 	if ((bktr->id==BROOKTREE_848)  ||
    710 	    (bktr->id==BROOKTREE_848A) ||
    711 	    (bktr->id==BROOKTREE_849A)) {
    712 
    713             /* At i2c address 0xa0, look for Hauppauge and Osprey cards */
    714             if ( (status = i2cRead( bktr, PFC8582_RADDR )) != ABSENT ) {
    715 
    716 		    /* Read the eeprom contents */
    717 		    bktr->card = cards[ (card = CARD_UNKNOWN) ];
    718 		    bktr->card.eepromAddr = PFC8582_WADDR;
    719 		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
    720 	            readEEProm(bktr, 0, 128, (u_char *) &eeprom );
    721 
    722 		    /* For Hauppauge, check the EEPROM begins with 0x84 */
    723 		    if (eeprom[0] == 0x84) {
    724                             bktr->card = cards[ (card = CARD_HAUPPAUGE) ];
    725 			    bktr->card.eepromAddr = PFC8582_WADDR;
    726 			    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
    727                             goto checkTuner;
    728 		    }
    729 
    730 		    /* For Osprey, check the EEPROM begins with "MMAC" */
    731 		    if (  (eeprom[0] == 'M') &&(eeprom[1] == 'M')
    732 			&&(eeprom[2] == 'A') &&(eeprom[3] == 'C')) {
    733                             bktr->card = cards[ (card = CARD_OSPREY) ];
    734 			    bktr->card.eepromAddr = PFC8582_WADDR;
    735 			    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
    736                             goto checkTuner;
    737 		    }
    738 		    printf("%s: Warning: Unknown card type. EEPROM data not recognised\n",
    739 			   bktr_name(bktr));
    740 		    printf("%s: %x %x %x %x\n", bktr_name(bktr),
    741 			   eeprom[0],eeprom[1],eeprom[2],eeprom[3]);
    742             }
    743 
    744             /* look for an STB card */
    745             if ( (status = i2cRead( bktr, X24C01_RADDR )) != ABSENT ) {
    746                     bktr->card = cards[ (card = CARD_STB) ];
    747 		    bktr->card.eepromAddr = X24C01_WADDR;
    748 		    bktr->card.eepromSize = (u_char)(128 / EEPROMBLOCKSIZE);
    749                     goto checkTuner;
    750             }
    751 
    752 	}
    753 
    754 	signCard( bktr, 1, 128, (u_char *)  &probe_signature );
    755 
    756 	if (bootverbose) {
    757 	  printf("%s: card signature: ", bktr_name(bktr));
    758 	  for (j = 0; j < Bt848_MAX_SIGN; j++) {
    759 	    printf(" %02x ", probe_signature[j]);
    760 	  }
    761 	  printf("\n\n");
    762 	}
    763 	for (i = 0;
    764 	     i < (sizeof bt848_card_signature)/ sizeof (struct bt848_card_sig);
    765 	     i++ ) {
    766 
    767 	  card_found = 1;
    768 	  probe_temp = (u_char *) &bt848_card_signature[i].signature;
    769 
    770 	  for (j = 0; j < Bt848_MAX_SIGN; j++) {
    771 	    if ((probe_temp[j] & 0xf) != (probe_signature[j] & 0xf)) {
    772 	      card_found = 0;
    773 	      break;
    774 	    }
    775 
    776 	  }
    777 	  if (card_found) {
    778 	    bktr->card = cards[ card = bt848_card_signature[i].card];
    779 	    eeprom_i2c_address = locate_eeprom_address( bktr );
    780 	    if (eeprom_i2c_address != -1) {
    781 		bktr->card.eepromAddr = eeprom_i2c_address;
    782 		bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
    783 	    } else {
    784 		bktr->card.eepromAddr = 0;
    785 		bktr->card.eepromSize = 0;
    786 	    }
    787 	    tuner_i2c_address = locate_tuner_address( bktr );
    788 	    select_tuner( bktr, bt848_card_signature[i].tuner );
    789 	    goto checkDBX;
    790 	  }
    791 	}
    792 
    793 	/* We do not know the card type. Default to Miro */
    794 	bktr->card = cards[ (card = CARD_MIRO) ];
    795 
    796 
    797 checkEEPROM:
    798 	/* look for a configuration eeprom */
    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);
    803 	} else {
    804 	    bktr->card.eepromAddr = 0;
    805 	    bktr->card.eepromSize = 0;
    806 	}
    807 
    808 
    809 checkTuner:
    810 
    811 	/* look for a tuner */
    812 	tuner_i2c_address = locate_tuner_address( bktr );
    813 	if ( tuner_i2c_address == -1 ) {
    814 		select_tuner( bktr, NO_TUNER );
    815 		goto checkDBX;
    816 	}
    817 
    818 #if defined( BKTR_OVERRIDE_TUNER )
    819 	select_tuner( bktr, BKTR_OVERRIDE_TUNER );
    820 	goto checkDBX;
    821 #endif
    822 	if (bktr->bt848_tuner != -1 ) {
    823 	  select_tuner( bktr, bktr->bt848_tuner & 0xff );
    824 	  goto checkDBX;
    825 	}
    826 
    827 	/* Check for i2c devices */
    828 	if (!any_i2c_devices) {
    829 		select_tuner( bktr, NO_TUNER );
    830 		goto checkDBX;
    831 	}
    832 
    833 	/* differentiate type of tuner */
    834 
    835 	switch (card) {
    836 	case CARD_MIRO:
    837 	    switch (((INL(bktr, BKTR_GPIO_DATA) >> 10)-1)&7) {
    838 	    case 0: select_tuner( bktr, TEMIC_PAL ); break;
    839 	    case 1: select_tuner( bktr, PHILIPS_PAL ); break;
    840 	    case 2: select_tuner( bktr, PHILIPS_NTSC ); break;
    841 	    case 3: select_tuner( bktr, PHILIPS_SECAM ); break;
    842 	    case 4: select_tuner( bktr, NO_TUNER ); break;
    843 	    case 5: select_tuner( bktr, PHILIPS_PALI ); break;
    844 	    case 6: select_tuner( bktr, TEMIC_NTSC ); break;
    845 	    case 7: select_tuner( bktr, TEMIC_PALI ); break;
    846 	    }
    847 	    goto checkDBX;
    848 	    break;
    849 
    850 	case CARD_HAUPPAUGE:
    851 	    /* Hauppauge kindly supplied the following Tuner Table */
    852 	    /* FIXME: I think the tuners the driver selects for types */
    853 	    /* 0x08 and 0x15 may be incorrect but no one has complained. */
    854 	    /* Old Temic tuners had their own API, but newer Temic tuners */
    855 	    /* have the same API as Philips tuners */
    856 	    /*
    857   ID  Tuner Model           Format			We select Format
    858  0x00 NONE
    859  0x01 EXTERNAL
    860  0x02 OTHER
    861  0x03 Philips FI1216        BG
    862  0x04 Philips FI1216MF      BGLL'			PHILIPS_SECAM
    863  0x05 Philips FI1236        MN 				PHILIPS_NTSC
    864  0x06 Philips FI1246        I 				PHILIPS_PALI
    865  0x07 Philips FI1256        DK
    866  0x08 Philips FI1216 MK2    BG 				PHILIPS_PALI
    867  0x09 Philips FI1216MF MK2  BGLL' 			PHILIPS_SECAM
    868  0x0a Philips FI1236 MK2    MN 				PHILIPS_NTSC
    869  0x0b Philips FI1246 MK2    I 				PHILIPS_PALI
    870  0x0c Philips FI1256 MK2    DK
    871  0x0d Temic 4032FY5         NTSC			TEMIC_NTSC
    872  0x0e Temic 4002FH5         BG				TEMIC_PAL
    873  0x0f Temic 4062FY5         I 				TEMIC_PALI
    874  0x10 Philips FR1216 MK2    BG
    875  0x11 Philips FR1216MF MK2  BGLL' 			PHILIPS_FR1236_SECAM
    876  0x12 Philips FR1236 MK2    MN 				PHILIPS_FR1236_NTSC
    877  0x13 Philips FR1246 MK2    I
    878  0x14 Philips FR1256 MK2    DK
    879  0x15 Philips FM1216        BG 				PHILIPS_FR1216_PAL
    880  0x16 Philips FM1216MF      BGLL' 			PHILIPS_FR1236_SECAM
    881  0x17 Philips FM1236        MN 				PHILIPS_FR1236_NTSC
    882  0x18 Philips FM1246        I
    883  0x19 Philips FM1256        DK
    884  0x1a Temic 4036FY5         MN (FI1236 MK2 clone)	PHILIPS_NTSC
    885  0x1b Samsung TCPN9082D     MN
    886  0x1c Samsung TCPM9092P     Pal BG/I/DK
    887  0x1d Temic 4006FH5         BG				PHILIPS_PALI
    888  0x1e Samsung TCPN9085D     MN/Radio
    889  0x1f Samsung TCPB9085P     Pal BG/I/DK / Radio
    890  0x20 Samsung TCPL9091P     Pal BG & Secam L/L'
    891  0x21 Temic 4039FY5         NTSC Radio
    892  0x22 Philips FQ1216ME      Pal BGIDK & Secam L/L'
    893  0x23 Temic 4066FY5         Pal I (FI1246 MK2 clone)	PHILIPS_PALI
    894  0x24 Philips TD1536        MN/ATSCDigital
    895  0x25 Philips TD1536D       MN/ATSCDigital DUAL INPUT
    896  0x26 Philips FMR1236       M/N FM(no demod)
    897  0x27 Philips FI1256MP      B/G, D/K
    898  0x28 Samsung TCPQ9091P     BG/I/DK, L/L'
    899  0x29 Temic 4006FN5         BG/I/DK
    900  0x2a Temic 4009FR5         BG FM			PHILIPS_FR1216_PAL
    901  0x2b Temic 4046FM5         B/G, I, D/K, L/L'
    902  0x2c Temic 4009FN5         B/G, I, D/K, FM (no demod)
    903  0x2d Philips TD1536D_FH_44 MN/ATSCDigital DUAL INPUT
    904 	    */
    905 
    906 
    907 	    /* Determine the model number from the eeprom */
    908 	    if (bktr->card.eepromAddr != 0) {
    909 	        /* eeprom data block structure */
    910 	        unsigned char *block_1, *block_2, *block_3, *block_4;
    911 	        int block_1_data_size,  block_2_data_size, block_3_data_size;
    912 	        int block_1_total_size, block_2_total_size, block_3_total_size;
    913 		int block_4_header_size;
    914 
    915 		unsigned int model,revision;
    916 		unsigned char tuner_code;
    917 		unsigned char no_audio_mux;
    918 
    919 		readEEProm(bktr, 0, 128, (u_char *) &eeprom );
    920 
    921 	        /* LOCATE THE EEPROM DATA BLOCKS */
    922 	        block_1 = &eeprom[0];
    923 	        block_1_data_size = (block_1[2] << 8 | block_1[1]);
    924 	        block_1_total_size = block_1_data_size + 3; /* Header bytes */
    925 
    926 	        block_2 = &eeprom[block_1_total_size];
    927 	        block_2_data_size = (block_2[2] << 8 | block_2[1]);
    928 	        block_2_total_size = block_2_data_size + 3; /* Header bytes */
    929 
    930 	        block_3 = &eeprom[block_1_total_size + block_2_total_size];
    931 	        block_3_data_size = (block_3[0] &0x07);
    932 	        block_3_total_size = block_3_data_size + 1; /* Header size */
    933 
    934 	        block_4 = &eeprom[block_1_total_size +block_2_total_size +block_3_total_size];
    935 	        block_4_header_size = 1;
    936 
    937 		model    = (block_1[12] << 8  | block_1[11]);
    938 		revision = (block_1[15] << 16 | block_1[14] << 8 | block_1[13]);
    939 
    940 		tuner_code = block_1[9];
    941 
    942 		no_audio_mux = ((block_3[3] >> 7) &0x01);
    943 
    944 		if (no_audio_mux) bktr->audio_mux_present = 0;
    945 
    946 		if (verbose)
    947 		    printf("%s: Hauppauge Model %d %c%c%c%c\n",
    948 			   bktr_name(bktr),
    949 			   model,
    950 			   ((revision >> 18) & 0x3f) + 32,
    951 			   ((revision >> 12) & 0x3f) + 32,
    952 			   ((revision >>  6) & 0x3f) + 32,
    953 			   ((revision >>  0) & 0x3f) + 32 );
    954 
    955 	        /* Determine the tuner type from the eeprom */
    956 
    957 		switch (tuner_code) {
    958 
    959 		  case 0x5:
    960                   case 0x0a:
    961                   case 0x1a:
    962 		    select_tuner( bktr, PHILIPS_NTSC );
    963 		    goto checkDBX;
    964 
    965 		  case 0x4:
    966                   case 0x9:
    967 		    select_tuner( bktr, PHILIPS_SECAM );
    968 		    goto checkDBX;
    969 
    970                   case 0x11:
    971 	          case 0x16:
    972 		    select_tuner( bktr, PHILIPS_FR1236_SECAM );
    973 		    goto checkDBX;
    974 
    975                   case 0x12:
    976 	          case 0x17:
    977 		    select_tuner( bktr, PHILIPS_FR1236_NTSC );
    978 		    goto checkDBX;
    979 
    980 		  case 0x6:
    981 	          case 0x8:
    982 	          case 0xb:
    983 	          case 0x1d:
    984 	          case 0x23:
    985 		    select_tuner( bktr, PHILIPS_PALI );
    986 		    goto checkDBX;
    987 
    988 	          case 0xd:
    989 		    select_tuner( bktr, TEMIC_NTSC );
    990 		    goto checkDBX;
    991 
    992                   case 0xe:
    993 		    select_tuner( bktr, TEMIC_PAL );
    994 		    goto checkDBX;
    995 
    996 	          case 0xf:
    997 		    select_tuner( bktr, TEMIC_PALI );
    998 		    goto checkDBX;
    999 
   1000                   case 0x15:
   1001 		    select_tuner( bktr, PHILIPS_FR1216_PAL );
   1002 		    goto checkDBX;
   1003 
   1004                   case 0x2a:
   1005 		    bktr->msp_use_mono_source = 1;
   1006 		    select_tuner( bktr, PHILIPS_FR1216_PAL );
   1007 		    goto checkDBX;
   1008 
   1009 	          default :
   1010 		    printf("%s: Warning - Unknown Hauppauge Tuner 0x%x\n",
   1011 			   bktr_name(bktr), tuner_code);
   1012 		}
   1013 	    }
   1014 	    break;
   1015 
   1016 
   1017 	case CARD_AVER_MEDIA:
   1018 	    /* AVerMedia kindly supplied some details of their EEPROM contents
   1019 	     * which allow us to auto select the Tuner Type.
   1020 	     * Only the newer AVerMedia cards actually have an EEPROM.
   1021 	     */
   1022 	    if (bktr->card.eepromAddr != 0) {
   1023 
   1024 		u_char tuner_make;   /* Eg Philips, Temic */
   1025 		u_char tuner_tv_fm;  /* TV or TV with FM Radio */
   1026 		u_char tuner_format; /* Eg NTSC, PAL, SECAM */
   1027 		int    tuner;
   1028 
   1029 		int tuner_0_table[] = {
   1030 			PHILIPS_NTSC,  PHILIPS_PAL,
   1031 			PHILIPS_PAL,   PHILIPS_PAL,
   1032 			PHILIPS_PAL,   PHILIPS_PAL,
   1033 			PHILIPS_SECAM, PHILIPS_SECAM,
   1034 			PHILIPS_SECAM, PHILIPS_PAL};
   1035 
   1036 		int tuner_0_fm_table[] = {
   1037 			PHILIPS_FR1236_NTSC,  PHILIPS_FR1216_PAL,
   1038 			PHILIPS_FR1216_PAL,   PHILIPS_FR1216_PAL,
   1039 			PHILIPS_FR1216_PAL,   PHILIPS_FR1216_PAL,
   1040 			PHILIPS_FR1236_SECAM, PHILIPS_FR1236_SECAM,
   1041 			PHILIPS_FR1236_SECAM, PHILIPS_FR1216_PAL};
   1042 
   1043 		int tuner_1_table[] = {
   1044 			TEMIC_NTSC,  TEMIC_PAL,   TEMIC_PAL,
   1045 			TEMIC_PAL,   TEMIC_PAL,   TEMIC_PAL,
   1046 			TEMIC_SECAM, TEMIC_SECAM, TEMIC_SECAM,
   1047 			TEMIC_PAL};
   1048 
   1049 
   1050 		/* Extract information from the EEPROM data */
   1051 	    	readEEProm(bktr, 0, 128, (u_char *) &eeprom );
   1052 
   1053 		tuner_make   = (eeprom[0x41] & 0x7);
   1054 		tuner_tv_fm  = (eeprom[0x41] & 0x18) >> 3;
   1055 		tuner_format = (eeprom[0x42] & 0xf0) >> 4;
   1056 
   1057 		/* Treat tuner make 0 (Philips) and make 2 (LG) the same */
   1058 		if ( ((tuner_make == 0) || (tuner_make == 2))
   1059 		    && (tuner_format <= 9) && (tuner_tv_fm == 0) ) {
   1060 			tuner = tuner_0_table[tuner_format];
   1061 			select_tuner( bktr, tuner );
   1062 			goto checkDBX;
   1063 		}
   1064 
   1065 		if ( ((tuner_make == 0) || (tuner_make == 2))
   1066 		    && (tuner_format <= 9) && (tuner_tv_fm == 1) ) {
   1067 			tuner = tuner_0_fm_table[tuner_format];
   1068 			select_tuner( bktr, tuner );
   1069 			goto checkDBX;
   1070 		}
   1071 
   1072 		if ( (tuner_make == 1) && (tuner_format <= 9) ) {
   1073 			tuner = tuner_1_table[tuner_format];
   1074 			select_tuner( bktr, tuner );
   1075 			goto checkDBX;
   1076 		}
   1077 
   1078 	    	printf("%s: Warning - Unknown AVerMedia Tuner Make %d Format %d\n",
   1079 			bktr_name(bktr), tuner_make, tuner_format);
   1080 	    }
   1081 	    break;
   1082 
   1083 	case CARD_LEADTEK:
   1084 #if BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL
   1085 	    select_tuner( bktr, PHILIPS_FR1216_PAL );
   1086 #else
   1087 	    select_tuner( bktr, PHILIPS_FR1236_NTSC );
   1088 #endif
   1089             goto checkDBX;
   1090 	    break;
   1091 
   1092 	} /* end switch(card) */
   1093 
   1094 
   1095         /* At this point, a goto checkDBX has not occurred */
   1096         /* We have not been able to select a Tuner */
   1097         /* Some cards make use of the tuner address to */
   1098         /* identify the make/model of tuner */
   1099 
   1100         /* At address 0xc0/0xc1 we often find a TEMIC NTSC */
   1101         if ( i2cRead( bktr, 0xc1 ) != ABSENT ) {
   1102 	    select_tuner( bktr, TEMIC_NTSC );
   1103             goto checkDBX;
   1104         }
   1105 
   1106         /* At address 0xc6/0xc7 we often find a PHILIPS NTSC Tuner */
   1107         if ( i2cRead( bktr, 0xc7 ) != ABSENT ) {
   1108 	    select_tuner( bktr, PHILIPS_NTSC );
   1109             goto checkDBX;
   1110         }
   1111 
   1112         /* Address 0xc2/0xc3 is default (or common address) for several */
   1113 	/* tuners and we cannot tell which is which. */
   1114 	/* And for all other tuner i2c addresses, select the default */
   1115 	select_tuner( bktr, DEFAULT_TUNER );
   1116 
   1117 
   1118 checkDBX:
   1119 #if defined( BKTR_OVERRIDE_DBX )
   1120 	bktr->card.dbx = BKTR_OVERRIDE_DBX;
   1121 	goto checkMSP;
   1122 #endif
   1123    /* Check for i2c devices */
   1124 	if (!any_i2c_devices) {
   1125 		goto checkMSP;
   1126 	}
   1127 
   1128 	/* probe for BTSC (dbx) chip */
   1129 	if ( i2cRead( bktr, TDA9850_RADDR ) != ABSENT )
   1130 		bktr->card.dbx = 1;
   1131 
   1132 checkMSP:
   1133 	/* If this is a Hauppauge Bt878 card, we need to enable the
   1134 	 * MSP 34xx audio chip.
   1135 	 * If this is a Hauppauge Bt848 card, reset the MSP device.
   1136 	 * The MSP reset line is wired to GPIO pin 5. On Bt878 cards a pulldown
   1137 	 * resistor holds the device in reset until we set GPIO pin 5.
   1138          */
   1139 
   1140 	/* Optionally skip the MSP reset. This is handy if you initialise the
   1141 	 * MSP audio in another operating system (eg Windows) first and then
   1142 	 * do a soft reboot.
   1143 	 */
   1144 
   1145 #ifndef BKTR_NO_MSP_RESET
   1146 	if (card == CARD_HAUPPAUGE) {
   1147             OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5));
   1148             OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5));  /* write '1' */
   1149             DELAY(2500); /* wait 2.5ms */
   1150             OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */
   1151             DELAY(2500); /* wait 2.5ms */
   1152             OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5));  /* write '1' */
   1153             DELAY(2500); /* wait 2.5ms */
   1154         }
   1155 #endif
   1156 
   1157 #if defined( BKTR_OVERRIDE_MSP )
   1158 	bktr->card.msp3400c = BKTR_OVERRIDE_MSP;
   1159 	goto checkMSPEnd;
   1160 #endif
   1161 
   1162 	/* Check for i2c devices */
   1163 	if (!any_i2c_devices) {
   1164 		goto checkMSPEnd;
   1165 	}
   1166 
   1167 	if ( i2cRead( bktr, MSP3400C_RADDR ) != ABSENT ) {
   1168 		bktr->card.msp3400c = 1;
   1169 	}
   1170 
   1171 checkMSPEnd:
   1172 
   1173 	if (bktr->card.msp3400c) {
   1174 		bktr->msp_addr = MSP3400C_WADDR;
   1175 		msp_read_id( bktr );
   1176 		printf("%s: Detected a MSP%s at 0x%x\n", bktr_name(bktr),
   1177 		       bktr->msp_version_string,
   1178 		       bktr->msp_addr);
   1179 
   1180 	}
   1181 
   1182 /* Check for Dolby Surround Sound DPL3518A sound chip */
   1183 	if ( i2cRead( bktr, DPL3518A_RADDR ) != ABSENT ) {
   1184 		bktr->card.dpl3518a = 1;
   1185 	}
   1186 
   1187 	if (bktr->card.dpl3518a) {
   1188 		bktr->dpl_addr = DPL3518A_WADDR;
   1189 		dpl_read_id( bktr );
   1190 		printf("%s: Detected a DPL%s at 0x%x\n", bktr_name(bktr),
   1191 		       bktr->dpl_version_string,
   1192 		       bktr->dpl_addr);
   1193 	}
   1194 
   1195 /* Start of Check Remote */
   1196         /* Check for the Hauppauge IR Remote Control */
   1197         /* If there is an external unit, the internal will be ignored */
   1198 
   1199         bktr->remote_control = 0; /* initial value */
   1200 
   1201         if (any_i2c_devices) {
   1202             if (i2cRead( bktr, HAUP_REMOTE_EXT_RADDR ) != ABSENT )
   1203                 {
   1204                 bktr->remote_control      = 1;
   1205                 bktr->remote_control_addr = HAUP_REMOTE_EXT_RADDR;
   1206                 }
   1207             else if (i2cRead( bktr, HAUP_REMOTE_INT_RADDR ) != ABSENT )
   1208                 {
   1209                 bktr->remote_control      = 1;
   1210                 bktr->remote_control_addr = HAUP_REMOTE_INT_RADDR;
   1211                 }
   1212 
   1213         }
   1214         /* If a remote control is found, poll it 5 times to turn off the LED */
   1215         if (bktr->remote_control) {
   1216                 int i;
   1217                 for (i=0; i<5; i++)
   1218                         i2cRead( bktr, bktr->remote_control_addr );
   1219         }
   1220 /* End of Check Remote */
   1221 
   1222 #if defined( BKTR_USE_PLL )
   1223 	bktr->xtal_pll_mode = BT848_USE_PLL;
   1224 	goto checkPLLEnd;
   1225 #endif
   1226 	/* Default is to use XTALS and not PLL mode */
   1227 	bktr->xtal_pll_mode = BT848_USE_XTALS;
   1228 
   1229 	/* Enable PLL mode for OSPREY users */
   1230 	if (card == CARD_OSPREY)
   1231 		bktr->xtal_pll_mode = BT848_USE_PLL;
   1232 
   1233 	/* Enable PLL mode for Video Highway Xtreme users */
   1234 	if (card == CARD_VIDEO_HIGHWAY_XTREME)
   1235 		bktr->xtal_pll_mode = BT848_USE_PLL;
   1236 
   1237 
   1238 	/* Most (perhaps all) Bt878 cards need to be switched to PLL mode */
   1239 	/* as they only fit the NTSC crystal to their cards */
   1240 	/* Default to enabling PLL mode for all Bt878/879 cards */
   1241 
   1242 	if ((bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) )
   1243 		bktr->xtal_pll_mode = BT848_USE_PLL;
   1244 
   1245 
   1246 #if defined( BKTR_USE_PLL )
   1247 checkPLLEnd:
   1248 #endif
   1249 
   1250 
   1251 	bktr->card.tuner_pllAddr = tuner_i2c_address;
   1252 
   1253 	if ( verbose ) {
   1254 		printf( "%s: %s", bktr_name(bktr), bktr->card.name );
   1255 		if ( bktr->card.tuner )
   1256 			printf( ", %s tuner", bktr->card.tuner->name );
   1257 		if ( bktr->card.dbx )
   1258 			printf( ", dbx stereo" );
   1259 		if ( bktr->card.msp3400c )
   1260 			printf( ", msp3400c stereo" );
   1261 		if ( bktr->card.dpl3518a )
   1262 			printf( ", dpl3518a dolby" );
   1263                 if ( bktr->remote_control )
   1264                         printf( ", remote control" );
   1265 		printf( ".\n" );
   1266 	}
   1267 }
   1268 
   1269 #undef ABSENT
   1270