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