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