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