1119418Sobrien/*-
251694Sroger * 1. Redistributions of source code must retain the
351694Sroger * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman
451694Sroger * All rights reserved.
551694Sroger *
651694Sroger * Redistribution and use in source and binary forms, with or without
751694Sroger * modification, are permitted provided that the following conditions
851694Sroger * are met:
951694Sroger * 1. Redistributions of source code must retain the above copyright
1051694Sroger *    notice, this list of conditions and the following disclaimer.
1151694Sroger * 2. Redistributions in binary form must reproduce the above copyright
1251694Sroger *    notice, this list of conditions and the following disclaimer in the
1351694Sroger *    documentation and/or other materials provided with the distribution.
1451694Sroger * 3. All advertising materials mentioning features or use of this software
1551694Sroger *    must display the following acknowledgement:
1651694Sroger *      This product includes software developed by Amancio Hasty and
1751694Sroger *      Roger Hardiman
1851694Sroger * 4. The name of the author may not be used to endorse or promote products
1951694Sroger *    derived from this software without specific prior written permission.
2051694Sroger *
2151694Sroger * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2251694Sroger * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2351694Sroger * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2451694Sroger * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
2551694Sroger * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2651694Sroger * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2751694Sroger * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2851694Sroger * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2951694Sroger * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
3051694Sroger * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3151694Sroger * POSSIBILITY OF SUCH DAMAGE.
3251694Sroger */
3351694Sroger
34119418Sobrien#include <sys/cdefs.h>
35119418Sobrien__FBSDID("$FreeBSD$");
36119418Sobrien
37119418Sobrien/*
38119418Sobrien * This is part of the Driver for Video Capture Cards (Frame grabbers)
39119418Sobrien * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879
40119418Sobrien * chipset.
41119418Sobrien * Copyright Roger Hardiman and Amancio Hasty.
42119418Sobrien *
43119418Sobrien * bktr_card : This deals with identifying TV cards.
44119418Sobrien *               trying to find the card make and model of card.
45119418Sobrien *               trying to find the type of tuner fitted.
46119418Sobrien *               reading the configuration EEPROM.
47119418Sobrien *               locating i2c devices.
48119418Sobrien */
49119418Sobrien
5059014Sroger#include "opt_bktr.h"		/* Include any kernel config options */
5152257Sroger
5251694Sroger#include <sys/param.h>
5351694Sroger#include <sys/systm.h>
5451694Sroger
5559014Sroger#ifdef __FreeBSD__
5667306Sroger
5767306Sroger#if (__FreeBSD_version < 500000)
5867306Sroger#include <machine/clock.h>              /* for DELAY */
59119277Simp#include <pci/pcivar.h>
60119277Simp#else
61139917Simp#include <sys/lock.h>
62139917Simp#include <sys/mutex.h>
63139917Simp#include <sys/selinfo.h>
64119277Simp#include <dev/pci/pcivar.h>
6567306Sroger#endif
6667306Sroger
6759014Sroger#include <machine/bus.h>
6859014Sroger#include <sys/bus.h>
6959014Sroger#endif
7059014Sroger
7159014Sroger#ifdef __NetBSD__
7262112Sroger#include <dev/ic/bt8xx.h>	/* NetBSD location for .h files */
7362112Sroger#include <dev/pci/bktr/bktr_reg.h>
7462112Sroger#include <dev/pci/bktr/bktr_core.h>
7562112Sroger#include <dev/pci/bktr/bktr_tuner.h>
7662112Sroger#include <dev/pci/bktr/bktr_card.h>
7762112Sroger#include <dev/pci/bktr/bktr_audio.h>
7859014Sroger#else
79123291Sobrien#include <dev/bktr/ioctl_meteor.h>
80123291Sobrien#include <dev/bktr/ioctl_bt848.h>	/* extensions to ioctl_meteor.h */
8151694Sroger#include <dev/bktr/bktr_reg.h>
8251694Sroger#include <dev/bktr/bktr_core.h>
8351694Sroger#include <dev/bktr/bktr_tuner.h>
8451694Sroger#include <dev/bktr/bktr_card.h>
8551694Sroger#include <dev/bktr/bktr_audio.h>
8659014Sroger#endif
8759014Sroger
8867306Sroger/* Include the PCI Vendor definitions */
8967306Sroger#ifdef __NetBSD__
9067306Sroger#include <dev/pci/pcidevs.h>
9167306Sroger#include <dev/pci/pcireg.h>
9267306Sroger#endif
9367306Sroger
9451694Sroger/* Various defines */
9551694Sroger#define HAUP_REMOTE_INT_WADDR   0x30
9651694Sroger#define HAUP_REMOTE_INT_RADDR   0x31
9751694Sroger
9851694Sroger#define HAUP_REMOTE_EXT_WADDR   0x34
9951694Sroger#define HAUP_REMOTE_EXT_RADDR   0x35
10051694Sroger
10151694Sroger/* address of BTSC/SAP decoder chip */
10251694Sroger#define TDA9850_WADDR           0xb6
10351694Sroger#define TDA9850_RADDR           0xb7
10451694Sroger
10551694Sroger/* address of MSP3400C chip */
10651694Sroger#define MSP3400C_WADDR          0x80
10751694Sroger#define MSP3400C_RADDR          0x81
10851694Sroger
10952593Sroger/* address of DPL3518A chip */
11052593Sroger#define DPL3518A_WADDR          0x84
11152593Sroger#define DPL3518A_RADDR          0x85
11251694Sroger
11351694Sroger/* EEProm (128 * 8) on an STB card */
11451694Sroger#define X24C01_WADDR            0xae
11551694Sroger#define X24C01_RADDR            0xaf
11651694Sroger
11751694Sroger
11851694Sroger/* EEProm (256 * 8) on a Hauppauge card */
11951694Sroger/* and on most BT878s cards to store the sub-system vendor id */
12051694Sroger#define PFC8582_WADDR           0xa0
12151694Sroger#define PFC8582_RADDR		0xa1
12251694Sroger
123153084Sru#if defined(BKTR_SYSTEM_DEFAULT) && BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL
12451694Sroger#define DEFAULT_TUNER   PHILIPS_PALI
12551694Sroger#else
12651694Sroger#define DEFAULT_TUNER   PHILIPS_NTSC
12751694Sroger#endif
12851694Sroger
12951694Sroger
13051694Sroger
13151694Sroger
13251694Sroger/*
13351694Sroger * the data for each type of card
13451694Sroger *
13551694Sroger * Note:
13651694Sroger *   these entried MUST be kept in the order defined by the CARD_XXX defines!
13751694Sroger */
13851694Srogerstatic const struct CARDTYPE cards[] = {
13951694Sroger
14051694Sroger	{  CARD_UNKNOWN,			/* the card id */
14151694Sroger	  "Unknown",				/* the 'name' */
14251694Sroger	   NULL,				/* the tuner */
14351694Sroger	   0,					/* the tuner i2c address */
14451694Sroger	   0,					/* dbx unknown */
14551694Sroger	   0,
14652593Sroger	   0,
14751694Sroger	   0,					/* EEProm unknown */
14851694Sroger	   0,					/* EEProm unknown */
14951694Sroger	   { 0, 0, 0, 0, 0 },
15051694Sroger	   0 },					/* GPIO mask */
15151694Sroger
15251694Sroger	{  CARD_MIRO,				/* the card id */
15367306Sroger	  "Pinnacle/Miro TV",			/* the 'name' */
15451694Sroger	   NULL,				/* the tuner */
15551694Sroger	   0,					/* the tuner i2c address */
15651694Sroger	   0,					/* dbx unknown */
15751694Sroger	   0,
15852593Sroger	   0,
15951694Sroger	   0,					/* EEProm unknown */
16051694Sroger	   0,					/* size unknown */
16151694Sroger	   { 0x02, 0x01, 0x00, 0x0a, 1 },	/* audio MUX values */
16251694Sroger	   0x0f },				/* GPIO mask */
16351694Sroger
16451694Sroger	{  CARD_HAUPPAUGE,			/* the card id */
16551694Sroger	  "Hauppauge WinCast/TV",		/* the 'name' */
16651694Sroger	   NULL,				/* the tuner */
16751694Sroger	   0,					/* the tuner i2c address */
16851694Sroger	   0,					/* dbx is optional */
16951694Sroger	   0,
17052593Sroger	   0,
17151694Sroger	   PFC8582_WADDR,			/* EEProm type */
17251694Sroger	   (u_char)(256 / EEPROMBLOCKSIZE),	/* 256 bytes */
17351694Sroger	   { 0x00, 0x02, 0x01, 0x04, 1 },	/* audio MUX values */
17451694Sroger	   0x0f },				/* GPIO mask */
17551694Sroger
17651694Sroger	{  CARD_STB,				/* the card id */
17751694Sroger	  "STB TV/PCI",				/* the 'name' */
17851694Sroger	   NULL,				/* the tuner */
17951694Sroger	   0,					/* the tuner i2c address */
18051694Sroger	   0,					/* dbx is optional */
18151694Sroger	   0,
18252593Sroger	   0,
18351694Sroger	   X24C01_WADDR,			/* EEProm type */
18451694Sroger	   (u_char)(128 / EEPROMBLOCKSIZE),	/* 128 bytes */
18551694Sroger	   { 0x00, 0x01, 0x02, 0x02, 1 }, 	/* audio MUX values */
18651694Sroger	   0x0f },				/* GPIO mask */
18751694Sroger
18851694Sroger	{  CARD_INTEL,				/* the card id */
18951694Sroger	  "Intel Smart Video III/VideoLogic Captivator PCI", /* the 'name' */
19051694Sroger	   NULL,				/* the tuner */
19151694Sroger	   0,					/* the tuner i2c address */
19251694Sroger	   0,
19351694Sroger	   0,
19451694Sroger	   0,
19551694Sroger	   0,
19652593Sroger	   0,
19751694Sroger	   { 0, 0, 0, 0, 0 }, 			/* audio MUX values */
19851694Sroger	   0x00 },				/* GPIO mask */
19951694Sroger
20051694Sroger	{  CARD_IMS_TURBO,			/* the card id */
20151694Sroger	  "IMS TV Turbo",			/* the 'name' */
20251694Sroger	   NULL,				/* the tuner */
20351694Sroger	   0,					/* the tuner i2c address */
20451694Sroger	   0,					/* dbx is optional */
20551694Sroger	   0,
20652593Sroger	   0,
20751694Sroger	   PFC8582_WADDR,			/* EEProm type */
20851694Sroger	   (u_char)(256 / EEPROMBLOCKSIZE),	/* 256 bytes */
20951694Sroger	   { 0x01, 0x02, 0x01, 0x00, 1 },	/* audio MUX values */
21051694Sroger	   0x0f },				/* GPIO mask */
21151694Sroger
212141671Sjulian	{  CARD_AVER_MEDIA,			/* the card id */
213141671Sjulian	  "AVer Media TV/FM",                   /* the 'name' */
214141671Sjulian	   NULL,                                /* the tuner */
21551694Sroger	   0,					/* the tuner i2c address */
216141671Sjulian	   0,                                   /* dbx is optional */
21752593Sroger	   0,
218141671Sjulian	   0,
219141671Sjulian	   0,                                   /* EEProm type */
220141671Sjulian	   0,                                   /* EEProm size */
221141671Sjulian	   { 0x0c, 0x08, 0x04, 0x00, 1 },	/* audio MUX values */
22252593Sroger	   0x1f },				/* GPIO mask */
22351694Sroger
224141671Sjulian	{  CARD_OSPREY,				/* the card id */
225141671Sjulian	  "MMAC Osprey",                   	/* the 'name' */
226141671Sjulian	   NULL,                                /* the tuner */
22751694Sroger	   0,					/* the tuner i2c address */
228141671Sjulian	   0,                                   /* dbx is optional */
22952593Sroger	   0,
230141671Sjulian	   0,
23151694Sroger	   PFC8582_WADDR,			/* EEProm type */
23251694Sroger	   (u_char)(256 / EEPROMBLOCKSIZE),	/* 256 bytes */
233141671Sjulian	   { 0x00, 0x00, 0x00, 0x00, 0 },	/* audio MUX values */
23451694Sroger	   0 },					/* GPIO mask */
23551694Sroger
236141671Sjulian	{  CARD_NEC_PK,                         /* the card id */
237141671Sjulian	  "NEC PK-UG-X017",                     /* the 'name' */
238141671Sjulian	   NULL,                                /* the tuner */
239141671Sjulian	   0,                                   /* the tuner i2c address */
240141671Sjulian	   0,                                   /* dbx is optional */
24152593Sroger	   0,
242141671Sjulian	   0,
243141671Sjulian	   0,                                   /* EEProm type */
244141671Sjulian	   0,                                   /* EEProm size */
245141671Sjulian	   { 0x01, 0x02, 0x01, 0x00, 1 },	/* audio MUX values */
24651694Sroger	   0x0f },				/* GPIO mask */
24751694Sroger
248141671Sjulian	{  CARD_IO_BCTV2,                       /* the card id */
249141671Sjulian	  "I/O DATA GV-BCTV2/PCI",              /* the 'name' */
250141671Sjulian	   NULL,                                /* the tuner */
251141671Sjulian	   0,                                   /* the tuner i2c address */
252141671Sjulian	   0,                                   /* dbx is optional */
25352593Sroger	   0,
254141671Sjulian	   0,
255141671Sjulian	   0,                                   /* EEProm type */
256141671Sjulian	   0,                                   /* EEProm size */
257141671Sjulian	   { 0x00, 0x00, 0x00, 0x00, 1 },	/* Has special MUX handler */
25851694Sroger	   0x0f },				/* GPIO mask */
25951694Sroger
260141671Sjulian	{  CARD_FLYVIDEO,			/* the card id */
261141671Sjulian	  "FlyVideo",				/* the 'name' */
262141671Sjulian	   NULL,				/* the tuner */
263141671Sjulian	   0,					/* the tuner i2c address */
264141671Sjulian	   0,					/* dbx is optional */
265141671Sjulian	   0,					/* msp34xx is optional */
266141671Sjulian	   0,					/* dpl3518a is optional */
26751694Sroger	   0xac,				/* EEProm type */
26851694Sroger	   (u_char)(256 / EEPROMBLOCKSIZE),	/* 256 bytes */
269141671Sjulian	   { 0x000, 0x800, 0x400, 0x8dff00, 1 },/* audio MUX values */
27051694Sroger	   0x8dff00 },				/* GPIO mask */
27151694Sroger
27251694Sroger	{  CARD_ZOLTRIX,			/* the card id */
27351694Sroger	  "Zoltrix",				/* the 'name' */
274141671Sjulian	   NULL,				/* the tuner */
275141671Sjulian	   0,					/* the tuner i2c address */
276141671Sjulian	   0,					/* dbx is optional */
277141671Sjulian	   0,					/* msp34xx is optional */
278141671Sjulian	   0,					/* dpl3518a is optional */
27951694Sroger	   0,					/* EEProm type */
28051694Sroger	   0,					/* EEProm size */
28151694Sroger	   { 0x04, 0x01, 0x00, 0x0a, 1 },	/* audio MUX values */
28251694Sroger	   0x0f },				/* GPIO mask */
28351694Sroger
28451694Sroger	{  CARD_KISS,				/* the card id */
28551694Sroger	  "KISS TV/FM PCI",			/* the 'name' */
286141671Sjulian	   NULL,				/* the tuner */
287141671Sjulian	   0,					/* the tuner i2c address */
288141671Sjulian	   0,					/* dbx is optional */
289141671Sjulian	   0,					/* msp34xx is optional */
290141671Sjulian	   0,					/* dpl3518a is optional */
29151694Sroger	   0,					/* EEProm type */
29251694Sroger	   0,					/* EEProm size */
29351694Sroger	   { 0x0c, 0x00, 0x0b, 0x0b, 1 },	/* audio MUX values */
29451694Sroger	   0x0f },				/* GPIO mask */
29551694Sroger
29651694Sroger	{  CARD_VIDEO_HIGHWAY_XTREME,		/* the card id */
29751694Sroger	  "Video Highway Xtreme",		/* the 'name' */
298141671Sjulian	   NULL,				/* the tuner */
29951725Sroger	   0,
30051725Sroger	   0,
30151725Sroger	   0,
30252593Sroger	   0,
30351694Sroger	   0,					/* EEProm type */
30451694Sroger	   0,					/* EEProm size */
30551694Sroger	   { 0x00, 0x02, 0x01, 0x04, 1 },	/* audio MUX values */
30651694Sroger	   0x0f },				/* GPIO mask */
30751694Sroger
30851725Sroger	{  CARD_ASKEY_DYNALINK_MAGIC_TVIEW,	/* the card id */
30951725Sroger	  "Askey/Dynalink Magic TView",		/* the 'name' */
31051725Sroger	   NULL,				/* the tuner */
31151725Sroger	   0,
31251725Sroger	   0,
31351725Sroger	   0,
31452593Sroger	   0,
31551725Sroger	   0,					/* EEProm type */
31651725Sroger	   0,					/* EEProm size */
31756531Sroger	   { 0x400, 0xE00, 0x400, 0xC00, 1 },	/* audio MUX values */
31856531Sroger	   0xE00 },				/* GPIO mask */
31951725Sroger
32051725Sroger	{  CARD_LEADTEK,			/* the card id */
32151725Sroger	  "Leadtek Winfast TV 2000",		/* the 'name' */
32251725Sroger	   NULL,				/* the tuner */
32351725Sroger	   0,
32451725Sroger	   0,
32551725Sroger	   0,
32652593Sroger	   0,
32751725Sroger	   0,					/* EEProm type */
32851725Sroger	   0,					/* EEProm size */
32951925Sroger	   /* Tuner, Extern, Intern, Mute, Enabled */
33059014Sroger	   { 0x621000, 0x621000, 0x621000, 0xE21000, 1 }, /* audio MUX values */
33151925Sroger	   0xfff000 },				/* GPIO mask */
33251725Sroger
333141671Sjulian	{  CARD_TERRATVPLUS,                    /* the card id */
334141671Sjulian	  "TerraTVplus",                        /* the 'name' */
335141671Sjulian	   NULL,                                /* the tuner */
33659014Sroger	   0,
33759014Sroger	   0,
33859014Sroger	   0,
33959014Sroger	   0,
34059014Sroger	   0,					/* EEProm type */
34159014Sroger	   0,					/* EEProm size */
342141671Sjulian	   { 0x20000, 0x00000, 0x30000, 0x40000, 1 }, /* audio MUX values*/
343141671Sjulian	   0x70000 },                           /* GPIO mask */
34451925Sroger
345141671Sjulian	{  CARD_IO_BCTV3,                       /* the card id */
346141671Sjulian	  "I/O DATA GV-BCTV3/PCI",              /* the 'name' */
347141671Sjulian	   NULL,                                /* the tuner */
348141671Sjulian	   0,                                   /* the tuner i2c address */
349141671Sjulian	   0,                                   /* dbx is optional */
350110237Sorion	   0,
351141671Sjulian	   0,
352141671Sjulian	   0,                                   /* EEProm type */
353141671Sjulian	   0,                                   /* EEProm size */
354110237Sorion	   /* Tuner, Extern, Intern, Mute, Enabled */
355110237Sorion	   { 0x10000, 0, 0x10000, 0, 1 },	/* audio MUX values */
356110237Sorion	   0x10f00 },				/* GPIO mask */
357110237Sorion
358133300Ssanpei	{  CARD_AOPEN_VA1000,			/* the card id */
359133300Ssanpei	  "AOpen VA1000",			/* the 'name' */
360133300Ssanpei	   NULL,				/* the tuner */
361133300Ssanpei	   0,					/* the tuner i2c address */
362133300Ssanpei	   0,					/* dbx is optional */
363133300Ssanpei	   0,
364133300Ssanpei	   0,
365133300Ssanpei	   0,					/* EEProm unknown */
366133300Ssanpei	   0,					/* size unknown */
367133300Ssanpei	   { 0x02, 0x00, 0x00, 0x00, 1 },	/* audio MUX values */
368133300Ssanpei	   0x18e0 },				/* GPIO mask */
369133300Ssanpei
370138936Sjulian	{  CARD_PINNACLE_PCTV_RAVE,		/* the card id */
371138936Sjulian	  "Pinnacle PCTV Rave",			/* the 'name' */
372138936Sjulian	   NULL,				/* the tuner */
373138936Sjulian	   0,					/* the tuner i2c address */
374138936Sjulian	   0,					/* dbx unknown */
375138936Sjulian	   0,
376138936Sjulian	   0,
377138936Sjulian	   0,					/* EEProm unknown */
378138936Sjulian	   0,					/* size unknown */
379138936Sjulian	   { 0x02, 0x01, 0x00, 0x0a, 1 },	/* audio MUX values */
380138936Sjulian	   0x03000F },				/* GPIO mask */
381138936Sjulian
382141671Sjulian	{  CARD_PIXELVIEW_PLAYTV_PAK,       /* the card id */
383141671Sjulian	   "PixelView PlayTV Pak",              /* the 'name' */
384141671Sjulian	    NULL,                               /* the tuner */
385141671Sjulian	    0,                                  /* the tuner i2c address */
386141671Sjulian	    0,                                  /* dbx is optional */
387141671Sjulian	    0,
388141671Sjulian	    0,
389141671Sjulian	    PFC8582_WADDR,                      /* EEProm type */
390141671Sjulian	    (u_char)(256 / EEPROMBLOCKSIZE),    /* 256 bytes */
391141671Sjulian	    { 0x20000, 0x80000, 0, 0xa8000, 1 },        /* audio MUX values */
392141671Sjulian	    0xAA0000 },                         /* GPIO mask */
393139563Sjulian
394152375Snetchild	{  CARD_TERRATVALUE,                    /* the card id */
395152375Snetchild	   "TerraTec TValue",                   /* the 'name' */
396152375Snetchild	   NULL,                                /* the tuner */
397152375Snetchild	   0,                                   /* the tuner i2c address */
398152375Snetchild	   0,                                   /* dbx is optional */
399152375Snetchild	   0,
400152375Snetchild	   0,
401152375Snetchild	   0,                                   /* EEProm type */
402152375Snetchild	   0,                                   /* EEProm size */
403152375Snetchild	   /* Tuner, Extern, Intern, Mute, Enabled */
404152375Snetchild	   { 0x500, 0x900, 0x300, 0x900, 1 },	/* audio MUX values */
405152375Snetchild	   0xffff00 },				/* GPIO mask */
406152375Snetchild
407152375Snetchild	{  CARD_PIXELVIEW_PLAYTV_PRO_REV_4C,    /* the card id */
408152375Snetchild	   "PixelView PlayTV Pro REV-4C ",      /* the 'name' */
409152375Snetchild	   NULL,                                /* the tuner */
410152375Snetchild	   0,                                   /* the tuner i2c address */
411152375Snetchild	   0,                                   /* dbx is optional */
412152375Snetchild	   0,
413152375Snetchild	   0,
414152375Snetchild	   0,                                   /* EEProm type */
415152375Snetchild	   0,                                   /* EEProm size */
416152375Snetchild	   { 0x01, 0x04, 0x01, 0x03, 1 },       /* audio MUX values */
417152375Snetchild	   0x00ffffff },
41851694Sroger};
41951694Sroger
42051694Srogerstruct bt848_card_sig bt848_card_signature[1]= {
42151694Sroger  /* IMS TURBO TV : card 5 */
422110297Sorion    {  5,9, {00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 02, 00, 00, 00}}
42351694Sroger
42451694Sroger
42551694Sroger};
42651694Sroger
42751694Sroger
42851694Sroger/*
42951694Sroger * Write to the configuration EEPROM on the card.
43051694Sroger * This is dangerous and will mess up your card. Therefore it is not
43151694Sroger * implemented.
43251694Sroger */
43351694Srogerint
43451694SrogerwriteEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data )
43551694Sroger{
436141671Sjulian	return( -1 );
43751694Sroger}
43851694Sroger
43951694Sroger/*
44051694Sroger * Read the contents of the configuration EEPROM on the card.
44167306Sroger * (This is not fitted to all makes of card. All Hauppauge cards have them
44251694Sroger * and so do newer Bt878 based cards.
44351694Sroger */
44451694Srogerint
44551694SrogerreadEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data )
44651694Sroger{
44751694Sroger	int	x;
44851694Sroger	int	addr;
44951694Sroger	int	max;
45051694Sroger	int	byte;
45151694Sroger
45251694Sroger	/* get the address of the EEProm */
45351694Sroger	addr = (int)(bktr->card.eepromAddr & 0xff);
45451694Sroger	if ( addr == 0 )
45551694Sroger		return( -1 );
45651694Sroger
45751694Sroger	max = (int)(bktr->card.eepromSize * EEPROMBLOCKSIZE);
45851694Sroger	if ( (offset + count) > max )
45951694Sroger		return( -1 );
46051694Sroger
46151694Sroger	/* set the start address */
46251694Sroger	if ( i2cWrite( bktr, addr, offset, -1 ) == -1 )
46351694Sroger		return( -1 );
46451694Sroger
46551694Sroger	/* the read cycle */
46651694Sroger	for ( x = 0; x < count; ++x ) {
46751694Sroger		if ( (byte = i2cRead( bktr, (addr | 1) )) == -1 )
46851694Sroger			return( -1 );
46951694Sroger		data[ x ] = byte;
47051694Sroger	}
47151694Sroger
47251694Sroger	return( 0 );
47351694Sroger}
47451694Sroger
47551694Sroger
47651694Sroger#define ABSENT		(-1)
47751694Sroger
47851694Sroger/*
47951694Sroger * get a signature of the card
48051694Sroger * read all 128 possible i2c read addresses from 0x01 thru 0xff
48151694Sroger * build a bit array with a 1 bit for each i2c device that responds
48251694Sroger *
48351694Sroger * XXX FIXME: use offset & count args
48451694Sroger */
48551694Srogerint
48651694SrogersignCard( bktr_ptr_t bktr, int offset, int count, u_char* sig )
48751694Sroger{
48851694Sroger	int	x;
48951694Sroger
49051694Sroger	for ( x = 0; x < 16; ++x )
49151694Sroger		sig[ x ] = 0;
49251694Sroger
49351694Sroger	for ( x = 0; x < count; ++x ) {
49451694Sroger		if ( i2cRead( bktr, (2 * x) + 1 ) != ABSENT ) {
49551694Sroger			sig[ x / 8 ] |= (1 << (x % 8) );
49651694Sroger		}
49751694Sroger	}
49851694Sroger
49951694Sroger	return( 0 );
50051694Sroger}
50151694Sroger
50251694Sroger
50351694Sroger/*
50451694Sroger * check_for_i2c_devices.
50551694Sroger * Some BT848 cards have no tuner and no additional i2c devices
50651694Sroger * eg stereo decoder. These are used for video conferencing or capture from
50751694Sroger * a video camera. (eg VideoLogic Captivator PCI, Intel SmartCapture card).
50851694Sroger *
50951694Sroger * Determine if there are any i2c devices present. There are none present if
51051694Sroger *  a) reading from all 128 devices returns ABSENT (-1) for each one
51151694Sroger *     (eg VideoLogic Captivator PCI with BT848)
51251694Sroger *  b) reading from all 128 devices returns 0 for each one
51351694Sroger *     (eg VideoLogic Captivator PCI rev. 2F with BT848A)
51451694Sroger */
51551694Srogerstatic int check_for_i2c_devices( bktr_ptr_t bktr ){
51651694Sroger  int x, temp_read;
51751694Sroger  int i2c_all_0 = 1;
51851694Sroger  int i2c_all_absent = 1;
51951694Sroger  for ( x = 0; x < 128; ++x ) {
52051694Sroger    temp_read = i2cRead( bktr, (2 * x) + 1 );
52151694Sroger    if (temp_read != 0)      i2c_all_0 = 0;
52251694Sroger    if (temp_read != ABSENT) i2c_all_absent = 0;
52351694Sroger  }
52451694Sroger
52551694Sroger  if ((i2c_all_0) || (i2c_all_absent)) return 0;
52651694Sroger  else return 1;
52751694Sroger}
52851694Sroger
52951694Sroger
53051694Sroger/*
53151694Sroger * Temic/Philips datasheets say tuners can be at i2c addresses 0xc0, 0xc2,
53251694Sroger * 0xc4 or 0xc6, settable by links on the tuner.
53351694Sroger * Determine the actual address used on the TV card by probing read addresses.
53451694Sroger */
53551694Srogerstatic int locate_tuner_address( bktr_ptr_t bktr) {
53651694Sroger  if (i2cRead( bktr, 0xc1) != ABSENT) return 0xc0;
53751694Sroger  if (i2cRead( bktr, 0xc3) != ABSENT) return 0xc2;
53851694Sroger  if (i2cRead( bktr, 0xc5) != ABSENT) return 0xc4;
53951694Sroger  if (i2cRead( bktr, 0xc7) != ABSENT) return 0xc6;
54051694Sroger  return -1; /* no tuner found */
54151694Sroger}
54251694Sroger
54351694Sroger
54451694Sroger/*
54551694Sroger * Search for a configuration EEPROM on the i2c bus by looking at i2c addresses
54651694Sroger * where EEPROMs are usually found.
54751694Sroger * On some cards, the EEPROM appears in several locations, but all in the
54851694Sroger * range 0xa0 to 0xae.
54951694Sroger */
55051694Srogerstatic int locate_eeprom_address( bktr_ptr_t bktr) {
55151694Sroger  if (i2cRead( bktr, 0xa0) != ABSENT) return 0xa0;
55251694Sroger  if (i2cRead( bktr, 0xac) != ABSENT) return 0xac;
55351694Sroger  if (i2cRead( bktr, 0xae) != ABSENT) return 0xae;
55451694Sroger  return -1; /* no eeprom found */
55551694Sroger}
55651694Sroger
55751694Sroger
55851694Sroger/*
55951694Sroger * determine the card brand/model
56062112Sroger * BKTR_OVERRIDE_CARD, BKTR_OVERRIDE_TUNER, BKTR_OVERRIDE_DBX and
56162112Sroger * BKTR_OVERRIDE_MSP can be used to select a specific device,
56262112Sroger * regardless of the autodetection and i2c device checks.
56351694Sroger *
56451694Sroger * The scheme used for probing cards faces these problems:
56551694Sroger *  It is impossible to work out which type of tuner is actually fitted,
56651694Sroger *  (the driver cannot tell if the Tuner is PAL or NTSC, Temic or Philips)
56751694Sroger *  It is impossible to determine what audio-mux hardware is connected.
56851694Sroger *  It is impossible to determine if there is extra hardware connected to the
56951694Sroger *  GPIO pins  (eg radio chips or MSP34xx reset logic)
57051694Sroger *
57151694Sroger * However some makes of card (eg Hauppauge) come with a configuration eeprom
57251694Sroger * which tells us the make of the card. Most eeproms also tell us the
573218909Sbrucec * tuner type and other features of the cards.
57451694Sroger *
57551694Sroger * The current probe code works as follows
57651694Sroger * A) If the card uses a Bt878/879:
57751694Sroger *   1) Read the sub-system vendor id from the configuration EEPROM.
57851694Sroger *      Select the required tuner, audio mux arrangement and any other
57951694Sroger *      onboard features. If this fails, move to step B.
58051694Sroger * B) If it card uses a Bt848, 848A, 849A or an unknown Bt878/879:
58151694Sroger *   1) Look for I2C devices. If there are none fitted, it is an Intel or
58251694Sroger *      VideoLogic cards.
58351694Sroger *   2) Look for a configuration EEPROM.
58451694Sroger *   2a) If there is one at I2C address 0xa0 it may be
58551694Sroger *       a Hauppauge or an Osprey. Check the EEPROM contents to determine which
58651694Sroger *       one it is. For Hauppauge, select the tuner type and audio hardware.
58751694Sroger *   2b) If there is an EEPROM at I2C address 0xa8 it will be an STB card.
58851694Sroger *       We still have to guess on the tuner type.
58951694Sroger *
59051694Sroger * C) If we do not know the card type from (A) or (B), guess at the tuner
59151694Sroger *    type based on the I2C address of the tuner.
59251694Sroger *
59351694Sroger * D) After determining the Tuner Type, we probe the i2c bus for other
59451694Sroger *    devices at known locations, eg IR-Remote Control, MSP34xx and TDA
59551694Sroger *    stereo chips.
59651694Sroger */
59751694Sroger
59851694Sroger
59951694Sroger/*
60051694Sroger * These are the sub-system vendor ID codes stored in the
60151694Sroger * configuration EEPROM used on Bt878/879 cards. They should match the
60251694Sroger * number assigned to the company by the PCI Special Interest Group
60351694Sroger */
60467306Sroger#ifndef __NetBSD__
60567306Sroger#define PCI_VENDOR_HAUPPAUGE	0x0070
60667306Sroger#define PCI_VENDOR_AVERMEDIA	0x1461
60767306Sroger#define PCI_VENDOR_STB		0x10B4
60867306Sroger#define PCI_VENDOR_ASKEY	0x144F
609152375Snetchild#define PCI_VENDOR_TERRATEC	0x153B
61067306Sroger#endif
61167306Sroger/* Following not confirmed with http://members.hyperlink.net.au/~chart,
61267306Sroger   so not added to NetBSD's pcidevs */
61367306Sroger#define PCI_VENDOR_LEADTEK_ALT	0x6606
614116106Sfjoe#define PCI_VENDOR_LEADTEK_ALT_2	0x6607
615116106Sfjoe#define PCI_VENDOR_LEADTEK_ALT_3	0x107d
61667306Sroger#define PCI_VENDOR_FLYVIDEO	0x1851
61767306Sroger#define PCI_VENDOR_FLYVIDEO_2	0x1852
618110237Sorion#define PCI_VENDOR_IODATA	0x10fc
619141669Sjulian#define PCI_VENDOR_PINNACLE_ALT	0xBD11	/* They got their own ID backwards? */
620138936Sjulian#define PCI_VENDOR_PINNACLE_NEW	0x11BD
62151694Sroger
622110237Sorion#define MODEL_IODATA_GV_BCTV3_PCI	0x4020
623152375Snetchild#define	MODEL_TERRATVALUE_1117		0x1117
624152375Snetchild#define MODEL_TERRATVALUE_1118		0x1118
625152375Snetchild#define	MODEL_TERRATVALUE_1119		0x1119
626152375Snetchild#define	MODEL_TERRATVALUE_111A		0x111a
627152375Snetchild#define MODEL_TERRATVALUE_1134		0x1134
62851694Sroger
62951694Srogervoid
63051694SrogerprobeCard( bktr_ptr_t bktr, int verbose, int unit )
63151694Sroger{
63251694Sroger	int		card, i,j, card_found;
63351694Sroger	int		status;
63451694Sroger	u_char 		probe_signature[128], *probe_temp;
635141671Sjulian	int   		any_i2c_devices;
63651694Sroger	u_char 		eeprom[256];
63751694Sroger	int 		tuner_i2c_address = -1;
63851694Sroger	int 		eeprom_i2c_address = -1;
63951694Sroger
64051694Sroger	/* Select all GPIO bits as inputs */
64159014Sroger	OUTL(bktr, BKTR_GPIO_OUT_EN, 0);
64251694Sroger	if (bootverbose)
64362112Sroger	    printf("%s: GPIO is 0x%08x\n", bktr_name(bktr),
64462112Sroger		   INL(bktr, BKTR_GPIO_DATA));
64551694Sroger
64651694Sroger#ifdef HAUPPAUGE_MSP_RESET
64751694Sroger	/* Reset the MSP34xx audio chip. This resolves bootup card
64851694Sroger	 * detection problems with old Bt848 based Hauppauge cards with
64951694Sroger	 * MSP34xx stereo audio chips. This must be user enabled because
65051694Sroger	 * at this point the probe function does not know the card type. */
651141671Sjulian	OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5));
652141671Sjulian	OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5));  /* write '1' */
653141671Sjulian	DELAY(2500); /* wait 2.5ms */
654141671Sjulian	OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */
655141671Sjulian	DELAY(2500); /* wait 2.5ms */
656141671Sjulian	OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5));  /* write '1' */
657141671Sjulian	DELAY(2500); /* wait 2.5ms */
65851694Sroger#endif
65951694Sroger
66051694Sroger	/* Check for the presence of i2c devices */
661141671Sjulian	any_i2c_devices = check_for_i2c_devices( bktr );
66251694Sroger
66351694Sroger
66451694Sroger	/* Check for a user specified override on the card selection */
66562112Sroger#if defined( BKTR_OVERRIDE_CARD )
66662112Sroger	bktr->card = cards[ (card = BKTR_OVERRIDE_CARD) ];
66751694Sroger	goto checkEEPROM;
66851694Sroger#endif
66951694Sroger	if (bktr->bt848_card != -1 ) {
67051694Sroger	  bktr->card = cards[ (card = bktr->bt848_card) ];
67151694Sroger	  goto checkEEPROM;
67251694Sroger	}
67351694Sroger
67451694Sroger
67551694Sroger	/* No override, so try and determine the make of the card */
67651694Sroger
677141671Sjulian	/* On BT878/879 cards, read the sub-system vendor id */
67851694Sroger	/* This identifies the manufacturer of the card and the model */
67951694Sroger	/* In theory this can be read from PCI registers but this does not */
68051694Sroger	/* appear to work on the FlyVideo 98. Hauppauge also warned that */
68151694Sroger	/* the PCI registers are sometimes not loaded correctly. */
68251694Sroger	/* Therefore, I will read the sub-system vendor ID from the EEPROM */
68351694Sroger	/* (just like the Bt878 does during power up initialisation) */
68451694Sroger
685141671Sjulian	if ((bktr->id==BROOKTREE_878) || (bktr->id==BROOKTREE_879)) {
68651694Sroger	    /* Try and locate the EEPROM */
68751694Sroger	    eeprom_i2c_address = locate_eeprom_address( bktr );
68851694Sroger	    if (eeprom_i2c_address != -1) {
68951694Sroger
690141671Sjulian		unsigned int subsystem_vendor_id; /* vendors PCI-SIG ID */
691141671Sjulian		unsigned int subsystem_id;        /* board model number */
69251694Sroger		unsigned int byte_252, byte_253, byte_254, byte_255;
69351694Sroger
69451694Sroger		bktr->card = cards[ (card = CARD_UNKNOWN) ];
69551694Sroger		bktr->card.eepromAddr = eeprom_i2c_address;
69651694Sroger		bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
69751694Sroger
698141671Sjulian		readEEProm(bktr, 0, 256, (u_char *) &eeprom );
699141671Sjulian		byte_252 = (unsigned int)eeprom[252];
700141671Sjulian		byte_253 = (unsigned int)eeprom[253];
701141671Sjulian		byte_254 = (unsigned int)eeprom[254];
702141671Sjulian		byte_255 = (unsigned int)eeprom[255];
703141671Sjulian
704141671Sjulian		subsystem_id        = (byte_252 << 8) | byte_253;
705141671Sjulian		subsystem_vendor_id = (byte_254 << 8) | byte_255;
70651694Sroger
707141671Sjulian		if ( bootverbose )
708141671Sjulian		    printf("%s: subsystem 0x%04x 0x%04x\n", bktr_name(bktr),
70959014Sroger			   subsystem_vendor_id, subsystem_id);
71051694Sroger
711141671Sjulian		if (subsystem_vendor_id == PCI_VENDOR_AVERMEDIA) {
712141671Sjulian		    bktr->card = cards[ (card = CARD_AVER_MEDIA) ];
71351694Sroger		    bktr->card.eepromAddr = eeprom_i2c_address;
71451694Sroger		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
715141671Sjulian		    goto checkTuner;
716141671Sjulian		}
71751694Sroger
718141671Sjulian		if (subsystem_vendor_id == PCI_VENDOR_HAUPPAUGE) {
719141671Sjulian		    bktr->card = cards[ (card = CARD_HAUPPAUGE) ];
72051694Sroger		    bktr->card.eepromAddr = eeprom_i2c_address;
72151694Sroger		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
722141671Sjulian		    goto checkTuner;
723141671Sjulian		}
72451694Sroger
725141671Sjulian		if ((subsystem_vendor_id == PCI_VENDOR_FLYVIDEO)
726141671Sjulian		 || (subsystem_vendor_id == PCI_VENDOR_FLYVIDEO_2) ) {
727141671Sjulian		    bktr->card = cards[ (card = CARD_FLYVIDEO) ];
72851694Sroger		    bktr->card.eepromAddr = eeprom_i2c_address;
72951694Sroger		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
730141671Sjulian		    goto checkTuner;
731141671Sjulian		}
73251694Sroger
733141671Sjulian		if (subsystem_vendor_id == PCI_VENDOR_STB) {
734141671Sjulian		    bktr->card = cards[ (card = CARD_STB) ];
73551694Sroger		    bktr->card.eepromAddr = eeprom_i2c_address;
73651694Sroger		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
737141671Sjulian		    goto checkTuner;
738141671Sjulian		}
73951694Sroger
740141671Sjulian		if (subsystem_vendor_id == PCI_VENDOR_ASKEY) {
741141671Sjulian		    bktr->card = cards[ (card = CARD_ASKEY_DYNALINK_MAGIC_TVIEW) ];
74251725Sroger		    bktr->card.eepromAddr = eeprom_i2c_address;
74351725Sroger		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
744141671Sjulian		    goto checkTuner;
745141671Sjulian		}
74651725Sroger
747141671Sjulian		if ((subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT)
748116106Sfjoe		 || (subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT_2)
749116106Sfjoe		 || (subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT_3)) {
750141671Sjulian		    bktr->card = cards[ (card = CARD_LEADTEK) ];
75151725Sroger		    bktr->card.eepromAddr = eeprom_i2c_address;
75251725Sroger		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
753141671Sjulian		    goto checkTuner;
754141671Sjulian		}
75551725Sroger
756141669Sjulian		if (subsystem_vendor_id == PCI_VENDOR_PINNACLE_ALT ||
757141669Sjulian		    subsystem_vendor_id == PCI_VENDOR_PINNACLE_NEW) {
758141671Sjulian		    bktr->card = cards[ (card = CARD_MIRO) ];
75967306Sroger		    bktr->card.eepromAddr = eeprom_i2c_address;
76067306Sroger		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
761141671Sjulian		    goto checkTuner;
762141671Sjulian		}
76367306Sroger
764141669Sjulian		if (subsystem_vendor_id == PCI_VENDOR_IODATA &&
765141669Sjulian		    subsystem_id == MODEL_IODATA_GV_BCTV3_PCI) {
766110237Sorion		    bktr->card = cards[ (card = CARD_IO_BCTV3) ];
767110237Sorion		    bktr->card.eepromAddr = eeprom_i2c_address;
768110237Sorion		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
769110237Sorion		    goto checkTuner;
770110237Sorion		}
771110237Sorion
772152375Snetchild		if (subsystem_vendor_id == PCI_VENDOR_TERRATEC) {
773152375Snetchild		    switch (subsystem_id) {
774152375Snetchild			case MODEL_TERRATVALUE_1117:
775152375Snetchild			case MODEL_TERRATVALUE_1118:
776152375Snetchild			case MODEL_TERRATVALUE_1119:
777152375Snetchild			case MODEL_TERRATVALUE_111A:
778152375Snetchild			case MODEL_TERRATVALUE_1134:
779152375Snetchild	 		    bktr->card = cards[ (card = CARD_TERRATVALUE) ];
780152375Snetchild			    bktr->card.eepromAddr = eeprom_i2c_address;
781152375Snetchild			    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
782152375Snetchild			    goto checkTuner;
783152375Snetchild		    }
784152375Snetchild		}
785152375Snetchild
786141671Sjulian		/* Vendor is unknown. We will use the standard probe code */
78751694Sroger		/* which may not give best results */
788141671Sjulian		printf("%s: Warning - card vendor 0x%04x (model 0x%04x) unknown.\n",
78962112Sroger		       bktr_name(bktr), subsystem_vendor_id, subsystem_id);
790141671Sjulian	    }
79151694Sroger	    else
79251694Sroger	    {
793141671Sjulian		printf("%s: Card has no configuration EEPROM. Cannot determine card make.\n",
79462112Sroger		       bktr_name(bktr));
79551694Sroger	    }
79651694Sroger	} /* end of bt878/bt879 card detection code */
79751694Sroger
79851694Sroger	/* If we get to this point, we must have a Bt848/848A/849A card */
79951694Sroger	/* or a Bt878/879 with an unknown subsystem vendor id */
800141671Sjulian	/* Try and determine the make of card by clever i2c probing */
80151694Sroger
80251694Sroger   	/* Check for i2c devices. If none, move on */
80351694Sroger	if (!any_i2c_devices) {
80451694Sroger		bktr->card = cards[ (card = CARD_INTEL) ];
80551694Sroger		bktr->card.eepromAddr = 0;
80651694Sroger		bktr->card.eepromSize = 0;
80751694Sroger		goto checkTuner;
80851694Sroger	}
80951694Sroger
810141671Sjulian	/* Look for Hauppauge, STB and Osprey cards by the presence */
81151694Sroger	/* of an EEPROM */
812141671Sjulian	/* Note: Bt878 based cards also use EEPROMs so we can only do this */
813141671Sjulian	/* test on BT848/848A and 849A based cards. */
81451694Sroger	if ((bktr->id==BROOKTREE_848)  ||
81551694Sroger	    (bktr->id==BROOKTREE_848A) ||
81651694Sroger	    (bktr->id==BROOKTREE_849A)) {
81751694Sroger
818141671Sjulian	    /* At i2c address 0xa0, look for Hauppauge and Osprey cards */
819141671Sjulian	    if ( (status = i2cRead( bktr, PFC8582_RADDR )) != ABSENT ) {
82051694Sroger
82151694Sroger		    /* Read the eeprom contents */
82251694Sroger		    bktr->card = cards[ (card = CARD_UNKNOWN) ];
82351694Sroger		    bktr->card.eepromAddr = PFC8582_WADDR;
82451694Sroger		    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
825141671Sjulian		    readEEProm(bktr, 0, 128, (u_char *) &eeprom );
82651694Sroger
82751694Sroger		    /* For Hauppauge, check the EEPROM begins with 0x84 */
82851694Sroger		    if (eeprom[0] == 0x84) {
829141671Sjulian			    bktr->card = cards[ (card = CARD_HAUPPAUGE) ];
83051694Sroger			    bktr->card.eepromAddr = PFC8582_WADDR;
83151694Sroger			    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
832141671Sjulian			    goto checkTuner;
83351694Sroger		    }
83451694Sroger
83551694Sroger		    /* For Osprey, check the EEPROM begins with "MMAC" */
83651694Sroger		    if (  (eeprom[0] == 'M') &&(eeprom[1] == 'M')
83751694Sroger			&&(eeprom[2] == 'A') &&(eeprom[3] == 'C')) {
838141671Sjulian			    bktr->card = cards[ (card = CARD_OSPREY) ];
83951694Sroger			    bktr->card.eepromAddr = PFC8582_WADDR;
84051694Sroger			    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
841141671Sjulian			    goto checkTuner;
84251694Sroger		    }
84362112Sroger		    printf("%s: Warning: Unknown card type. EEPROM data not recognised\n",
84462112Sroger			   bktr_name(bktr));
84562112Sroger		    printf("%s: %x %x %x %x\n", bktr_name(bktr),
84662112Sroger			   eeprom[0],eeprom[1],eeprom[2],eeprom[3]);
847141671Sjulian	    }
84851694Sroger
849141671Sjulian	    /* look for an STB card */
850141671Sjulian	    if ( (status = i2cRead( bktr, X24C01_RADDR )) != ABSENT ) {
851141671Sjulian		    bktr->card = cards[ (card = CARD_STB) ];
85251694Sroger		    bktr->card.eepromAddr = X24C01_WADDR;
85351694Sroger		    bktr->card.eepromSize = (u_char)(128 / EEPROMBLOCKSIZE);
854141671Sjulian		    goto checkTuner;
855141671Sjulian	    }
85651694Sroger
85751694Sroger	}
85851694Sroger
85951694Sroger	signCard( bktr, 1, 128, (u_char *)  &probe_signature );
86051694Sroger
86151694Sroger	if (bootverbose) {
86262112Sroger	  printf("%s: card signature: ", bktr_name(bktr));
86351694Sroger	  for (j = 0; j < Bt848_MAX_SIGN; j++) {
86451694Sroger	    printf(" %02x ", probe_signature[j]);
86551694Sroger	  }
86651694Sroger	  printf("\n\n");
86751694Sroger	}
86851694Sroger	for (i = 0;
86951694Sroger	     i < (sizeof bt848_card_signature)/ sizeof (struct bt848_card_sig);
87051694Sroger	     i++ ) {
87151694Sroger
87251694Sroger	  card_found = 1;
87351694Sroger	  probe_temp = (u_char *) &bt848_card_signature[i].signature;
87451694Sroger
87551694Sroger	  for (j = 0; j < Bt848_MAX_SIGN; j++) {
87651694Sroger	    if ((probe_temp[j] & 0xf) != (probe_signature[j] & 0xf)) {
87751694Sroger	      card_found = 0;
87851694Sroger	      break;
87951694Sroger	    }
88051694Sroger
88151694Sroger	  }
88251694Sroger	  if (card_found) {
88351694Sroger	    bktr->card = cards[ card = bt848_card_signature[i].card];
88451694Sroger	    eeprom_i2c_address = locate_eeprom_address( bktr );
88551694Sroger	    if (eeprom_i2c_address != -1) {
88651694Sroger		bktr->card.eepromAddr = eeprom_i2c_address;
88751694Sroger		bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
88851694Sroger	    } else {
88951694Sroger		bktr->card.eepromAddr = 0;
89051694Sroger		bktr->card.eepromSize = 0;
89151694Sroger	    }
89254262Sroger	    tuner_i2c_address = locate_tuner_address( bktr );
89354262Sroger	    select_tuner( bktr, bt848_card_signature[i].tuner );
89451694Sroger	    goto checkDBX;
89551694Sroger	  }
89651694Sroger	}
89751694Sroger
89851694Sroger	/* We do not know the card type. Default to Miro */
89951694Sroger	bktr->card = cards[ (card = CARD_MIRO) ];
90051694Sroger
90151694Sroger
90251694SrogercheckEEPROM:
90351694Sroger	/* look for a configuration eeprom */
90451694Sroger	eeprom_i2c_address = locate_eeprom_address( bktr );
90551694Sroger	if (eeprom_i2c_address != -1) {
90651694Sroger	    bktr->card.eepromAddr = eeprom_i2c_address;
90751694Sroger	    bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE);
90851694Sroger	} else {
90951694Sroger	    bktr->card.eepromAddr = 0;
91051694Sroger	    bktr->card.eepromSize = 0;
91151694Sroger	}
91251694Sroger
91351694Sroger
91451694SrogercheckTuner:
91551694Sroger
916146588Scognet#if !defined( BKTR_OVERRIDE_TUNER )
917146588Scognet	if (card == CARD_MIRO && mt2032_init(bktr) == 0 &&
918146588Scognet	    bktr->bt848_tuner == -1) {
919140655Sjulian		bktr->card = cards[ (card = CARD_PINNACLE_PCTV_RAVE) ];
920140655Sjulian		select_tuner( bktr, TUNER_MT2032 );
921140655Sjulian		goto checkDBX;
922140655Sjulian	}
923146588Scognet#endif
924140655Sjulian
92551694Sroger	/* look for a tuner */
92651694Sroger	tuner_i2c_address = locate_tuner_address( bktr );
92751694Sroger	if ( tuner_i2c_address == -1 ) {
92851694Sroger		select_tuner( bktr, NO_TUNER );
92951694Sroger		goto checkDBX;
93051694Sroger	}
93151694Sroger
93262112Sroger#if defined( BKTR_OVERRIDE_TUNER )
93362112Sroger	select_tuner( bktr, BKTR_OVERRIDE_TUNER );
93451694Sroger	goto checkDBX;
93551694Sroger#endif
93651694Sroger	if (bktr->bt848_tuner != -1 ) {
93751694Sroger	  select_tuner( bktr, bktr->bt848_tuner & 0xff );
93851694Sroger	  goto checkDBX;
93951694Sroger	}
94051694Sroger
94151694Sroger	/* Check for i2c devices */
94251694Sroger	if (!any_i2c_devices) {
94351694Sroger		select_tuner( bktr, NO_TUNER );
94451694Sroger		goto checkDBX;
94551694Sroger	}
94651694Sroger
94751694Sroger	/* differentiate type of tuner */
94851694Sroger
94951694Sroger	switch (card) {
95051694Sroger	case CARD_MIRO:
95159014Sroger	    switch (((INL(bktr, BKTR_GPIO_DATA) >> 10)-1)&7) {
95251694Sroger	    case 0: select_tuner( bktr, TEMIC_PAL ); break;
95351694Sroger	    case 1: select_tuner( bktr, PHILIPS_PAL ); break;
95451694Sroger	    case 2: select_tuner( bktr, PHILIPS_NTSC ); break;
95551694Sroger	    case 3: select_tuner( bktr, PHILIPS_SECAM ); break;
95651694Sroger	    case 4: select_tuner( bktr, NO_TUNER ); break;
95751694Sroger	    case 5: select_tuner( bktr, PHILIPS_PALI ); break;
95851694Sroger	    case 6: select_tuner( bktr, TEMIC_NTSC ); break;
95951694Sroger	    case 7: select_tuner( bktr, TEMIC_PALI ); break;
96051694Sroger	    }
96151694Sroger	    goto checkDBX;
96251694Sroger	    break;
96351694Sroger
96451694Sroger	case CARD_HAUPPAUGE:
96551694Sroger	    /* Hauppauge kindly supplied the following Tuner Table */
96651694Sroger	    /* FIXME: I think the tuners the driver selects for types */
96751694Sroger	    /* 0x08 and 0x15 may be incorrect but no one has complained. */
96862214Sroger	    /* Old Temic tuners had their own API, but newer Temic tuners */
96962214Sroger	    /* have the same API as Philips tuners */
97051694Sroger	    /*
97162214Sroger  ID  Tuner Model           Format			We select Format
97262214Sroger 0x00 NONE
97362214Sroger 0x01 EXTERNAL
97462214Sroger 0x02 OTHER
97562214Sroger 0x03 Philips FI1216        BG
97662214Sroger 0x04 Philips FI1216MF      BGLL'			PHILIPS_SECAM
97762214Sroger 0x05 Philips FI1236        MN 				PHILIPS_NTSC
97862214Sroger 0x06 Philips FI1246        I 				PHILIPS_PALI
97962214Sroger 0x07 Philips FI1256        DK
98062214Sroger 0x08 Philips FI1216 MK2    BG 				PHILIPS_PALI
98162214Sroger 0x09 Philips FI1216MF MK2  BGLL' 			PHILIPS_SECAM
98262214Sroger 0x0a Philips FI1236 MK2    MN 				PHILIPS_NTSC
98362214Sroger 0x0b Philips FI1246 MK2    I 				PHILIPS_PALI
98462214Sroger 0x0c Philips FI1256 MK2    DK
98562214Sroger 0x0d Temic 4032FY5         NTSC			TEMIC_NTSC
98662214Sroger 0x0e Temic 4002FH5         BG				TEMIC_PAL
98762214Sroger 0x0f Temic 4062FY5         I 				TEMIC_PALI
98862214Sroger 0x10 Philips FR1216 MK2    BG
98962214Sroger 0x11 Philips FR1216MF MK2  BGLL' 			PHILIPS_FR1236_SECAM
99062214Sroger 0x12 Philips FR1236 MK2    MN 				PHILIPS_FR1236_NTSC
99162214Sroger 0x13 Philips FR1246 MK2    I
99262214Sroger 0x14 Philips FR1256 MK2    DK
99362214Sroger 0x15 Philips FM1216        BG 				PHILIPS_FR1216_PAL
99462214Sroger 0x16 Philips FM1216MF      BGLL' 			PHILIPS_FR1236_SECAM
99562214Sroger 0x17 Philips FM1236        MN 				PHILIPS_FR1236_NTSC
99662214Sroger 0x18 Philips FM1246        I
99762214Sroger 0x19 Philips FM1256        DK
99862214Sroger 0x1a Temic 4036FY5         MN (FI1236 MK2 clone)	PHILIPS_NTSC
99962214Sroger 0x1b Samsung TCPN9082D     MN
100062214Sroger 0x1c Samsung TCPM9092P     Pal BG/I/DK
100162214Sroger 0x1d Temic 4006FH5         BG				PHILIPS_PALI
100262214Sroger 0x1e Samsung TCPN9085D     MN/Radio
100362214Sroger 0x1f Samsung TCPB9085P     Pal BG/I/DK / Radio
100462214Sroger 0x20 Samsung TCPL9091P     Pal BG & Secam L/L'
100562214Sroger 0x21 Temic 4039FY5         NTSC Radio
100662214Sroger 0x22 Philips FQ1216ME      Pal BGIDK & Secam L/L'
100762214Sroger 0x23 Temic 4066FY5         Pal I (FI1246 MK2 clone)	PHILIPS_PALI
100862214Sroger 0x24 Philips TD1536        MN/ATSCDigital
100962214Sroger 0x25 Philips TD1536D       MN/ATSCDigital DUAL INPUT
101062214Sroger 0x26 Philips FMR1236       M/N FM(no demod)
101162214Sroger 0x27 Philips FI1256MP      B/G, D/K
101262214Sroger 0x28 Samsung TCPQ9091P     BG/I/DK, L/L'
101362214Sroger 0x29 Temic 4006FN5         BG/I/DK
101468071Sroger 0x2a Temic 4009FR5         BG FM			PHILIPS_FR1216_PAL
101562214Sroger 0x2b Temic 4046FM5         B/G, I, D/K, L/L'
101668071Sroger 0x2c Temic 4009FN5         B/G, I, D/K, FM (no demod)
101762214Sroger 0x2d Philips TD1536D_FH_44 MN/ATSCDigital DUAL INPUT
101851694Sroger	    */
101951694Sroger
102051694Sroger
102151694Sroger	    /* Determine the model number from the eeprom */
102251694Sroger	    if (bktr->card.eepromAddr != 0) {
1023141671Sjulian		/* eeprom data block structure */
1024141671Sjulian		unsigned char *block_1, *block_2, *block_3, *block_4;
1025141671Sjulian		int block_1_data_size,  block_2_data_size, block_3_data_size;
1026141671Sjulian		int block_1_total_size, block_2_total_size, block_3_total_size;
102768071Sroger		int block_4_header_size;
102851694Sroger
102968071Sroger		unsigned int model,revision;
103068071Sroger		unsigned char tuner_code;
103168071Sroger		unsigned char no_audio_mux;
103268071Sroger
103351694Sroger		readEEProm(bktr, 0, 128, (u_char *) &eeprom );
103451694Sroger
1035141671Sjulian		/* LOCATE THE EEPROM DATA BLOCKS */
1036141671Sjulian		block_1 = &eeprom[0];
1037141671Sjulian		block_1_data_size = (block_1[2] << 8 | block_1[1]);
1038141671Sjulian		block_1_total_size = block_1_data_size + 3; /* Header bytes */
103968071Sroger
1040141671Sjulian		block_2 = &eeprom[block_1_total_size];
1041141671Sjulian		block_2_data_size = (block_2[2] << 8 | block_2[1]);
1042141671Sjulian		block_2_total_size = block_2_data_size + 3; /* Header bytes */
104368071Sroger
1044141671Sjulian		block_3 = &eeprom[block_1_total_size + block_2_total_size];
1045141671Sjulian		block_3_data_size = (block_3[0] &0x07);
1046141671Sjulian		block_3_total_size = block_3_data_size + 1; /* Header size */
104768071Sroger
1048141671Sjulian		block_4 = &eeprom[block_1_total_size +block_2_total_size +block_3_total_size];
1049141671Sjulian		block_4_header_size = 1;
105068071Sroger
105168071Sroger		model    = (block_1[12] << 8  | block_1[11]);
105268071Sroger		revision = (block_1[15] << 16 | block_1[14] << 8 | block_1[13]);
105368071Sroger
105468071Sroger		tuner_code = block_1[9];
105568071Sroger
105668071Sroger		no_audio_mux = ((block_3[3] >> 7) &0x01);
105768071Sroger
105868071Sroger		if (no_audio_mux) bktr->audio_mux_present = 0;
1059141671Sjulian
106051694Sroger		if (verbose)
106162112Sroger		    printf("%s: Hauppauge Model %d %c%c%c%c\n",
106262112Sroger			   bktr_name(bktr),
106362112Sroger			   model,
106462112Sroger			   ((revision >> 18) & 0x3f) + 32,
106562112Sroger			   ((revision >> 12) & 0x3f) + 32,
106662112Sroger			   ((revision >>  6) & 0x3f) + 32,
106762112Sroger			   ((revision >>  0) & 0x3f) + 32 );
106851694Sroger
1069141671Sjulian		/* Determine the tuner type from the eeprom */
107068071Sroger
107151694Sroger		switch (tuner_code) {
107251694Sroger
107354262Sroger		  case 0x5:
1074141671Sjulian		  case 0x0a:
1075141671Sjulian		  case 0x1a:
107654262Sroger		    select_tuner( bktr, PHILIPS_NTSC );
107754262Sroger		    goto checkDBX;
107854262Sroger
107953123Sroger		  case 0x4:
1080141671Sjulian		  case 0x9:
108153123Sroger		    select_tuner( bktr, PHILIPS_SECAM );
108251694Sroger		    goto checkDBX;
108351694Sroger
1084141671Sjulian		  case 0x11:
1085141671Sjulian		  case 0x16:
108653123Sroger		    select_tuner( bktr, PHILIPS_FR1236_SECAM );
108753123Sroger		    goto checkDBX;
108853123Sroger
1089141671Sjulian		  case 0x12:
1090141671Sjulian		  case 0x17:
1091110149Sorion		  case 0x21:
109251694Sroger		    select_tuner( bktr, PHILIPS_FR1236_NTSC );
109351694Sroger		    goto checkDBX;
109451694Sroger
109551694Sroger		  case 0x6:
1096141671Sjulian		  case 0x8:
1097141671Sjulian		  case 0xb:
1098141671Sjulian		  case 0x1d:
1099141671Sjulian		  case 0x23:
110051694Sroger		    select_tuner( bktr, PHILIPS_PALI );
110151694Sroger		    goto checkDBX;
110251694Sroger
1103141671Sjulian		  case 0xd:
110451694Sroger		    select_tuner( bktr, TEMIC_NTSC );
110551694Sroger		    goto checkDBX;
110651694Sroger
1107141671Sjulian		  case 0xe:
110851694Sroger		    select_tuner( bktr, TEMIC_PAL );
110951694Sroger		    goto checkDBX;
111051694Sroger
1111141671Sjulian		  case 0xf:
111251694Sroger		    select_tuner( bktr, TEMIC_PALI );
111351694Sroger		    goto checkDBX;
111451694Sroger
1115141671Sjulian		  case 0x15:
111651694Sroger		    select_tuner( bktr, PHILIPS_FR1216_PAL );
111751694Sroger		    goto checkDBX;
111851694Sroger
1119141671Sjulian		  case 0x2a:
112068071Sroger		    bktr->msp_use_mono_source = 1;
112168071Sroger		    select_tuner( bktr, PHILIPS_FR1216_PAL );
112268071Sroger		    goto checkDBX;
112368071Sroger
1124141671Sjulian		  default :
112562112Sroger		    printf("%s: Warning - Unknown Hauppauge Tuner 0x%x\n",
112662112Sroger			   bktr_name(bktr), tuner_code);
112751694Sroger		}
112851694Sroger	    }
112951694Sroger	    break;
113051694Sroger
113151694Sroger
113251694Sroger	case CARD_AVER_MEDIA:
113351694Sroger	    /* AVerMedia kindly supplied some details of their EEPROM contents
113451694Sroger	     * which allow us to auto select the Tuner Type.
113551694Sroger	     * Only the newer AVerMedia cards actually have an EEPROM.
113651694Sroger	     */
113751694Sroger	    if (bktr->card.eepromAddr != 0) {
113851694Sroger
113951694Sroger		u_char tuner_make;   /* Eg Philips, Temic */
114051694Sroger		u_char tuner_tv_fm;  /* TV or TV with FM Radio */
114151694Sroger		u_char tuner_format; /* Eg NTSC, PAL, SECAM */
114251694Sroger		int    tuner;
114351694Sroger
114451694Sroger		int tuner_0_table[] = {
114551694Sroger			PHILIPS_NTSC,  PHILIPS_PAL,
114651694Sroger			PHILIPS_PAL,   PHILIPS_PAL,
114751694Sroger			PHILIPS_PAL,   PHILIPS_PAL,
114851694Sroger			PHILIPS_SECAM, PHILIPS_SECAM,
114951694Sroger			PHILIPS_SECAM, PHILIPS_PAL};
115051694Sroger
115151694Sroger		int tuner_0_fm_table[] = {
115251694Sroger			PHILIPS_FR1236_NTSC,  PHILIPS_FR1216_PAL,
115351694Sroger			PHILIPS_FR1216_PAL,   PHILIPS_FR1216_PAL,
115451694Sroger			PHILIPS_FR1216_PAL,   PHILIPS_FR1216_PAL,
115551694Sroger			PHILIPS_FR1236_SECAM, PHILIPS_FR1236_SECAM,
115651694Sroger			PHILIPS_FR1236_SECAM, PHILIPS_FR1216_PAL};
115751694Sroger
115851694Sroger		int tuner_1_table[] = {
115951694Sroger			TEMIC_NTSC,  TEMIC_PAL,   TEMIC_PAL,
116051694Sroger			TEMIC_PAL,   TEMIC_PAL,   TEMIC_PAL,
116151694Sroger			TEMIC_SECAM, TEMIC_SECAM, TEMIC_SECAM,
116251694Sroger			TEMIC_PAL};
116351694Sroger
116451694Sroger
116551694Sroger		/* Extract information from the EEPROM data */
116651694Sroger	    	readEEProm(bktr, 0, 128, (u_char *) &eeprom );
116751694Sroger
116851694Sroger		tuner_make   = (eeprom[0x41] & 0x7);
116951694Sroger		tuner_tv_fm  = (eeprom[0x41] & 0x18) >> 3;
117051694Sroger		tuner_format = (eeprom[0x42] & 0xf0) >> 4;
117151694Sroger
117251694Sroger		/* Treat tuner make 0 (Philips) and make 2 (LG) the same */
117351694Sroger		if ( ((tuner_make == 0) || (tuner_make == 2))
117451694Sroger		    && (tuner_format <= 9) && (tuner_tv_fm == 0) ) {
117551694Sroger			tuner = tuner_0_table[tuner_format];
117651694Sroger			select_tuner( bktr, tuner );
117751694Sroger			goto checkDBX;
117851694Sroger		}
117951694Sroger
118051694Sroger		if ( ((tuner_make == 0) || (tuner_make == 2))
118151694Sroger		    && (tuner_format <= 9) && (tuner_tv_fm == 1) ) {
118251694Sroger			tuner = tuner_0_fm_table[tuner_format];
118351694Sroger			select_tuner( bktr, tuner );
118451694Sroger			goto checkDBX;
118551694Sroger		}
118651694Sroger
118751694Sroger		if ( (tuner_make == 1) && (tuner_format <= 9) ) {
118851694Sroger			tuner = tuner_1_table[tuner_format];
118951694Sroger			select_tuner( bktr, tuner );
119051694Sroger			goto checkDBX;
119151694Sroger		}
119251694Sroger
119362112Sroger	    	printf("%s: Warning - Unknown AVerMedia Tuner Make %d Format %d\n",
119462112Sroger			bktr_name(bktr), tuner_make, tuner_format);
119551694Sroger	    }
119651694Sroger	    break;
119759014Sroger
119857162Speter	case CARD_LEADTEK:
1199153084Sru#if defined(BKTR_SYSTEM_DEFAULT) && BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL
120057162Speter	    select_tuner( bktr, PHILIPS_FR1216_PAL );
120157162Speter#else
120257162Speter	    select_tuner( bktr, PHILIPS_FR1236_NTSC );
120357162Speter#endif
1204141671Sjulian	    goto checkDBX;
120557162Speter	    break;
120651694Sroger
1207110237Sorion	case CARD_IO_BCTV3:
1208110237Sorion	    select_tuner( bktr, ALPS_TSCH5 ); /* ALPS_TSCH6, in fact. */
1209110237Sorion	    goto checkDBX;
1210110237Sorion	    break;
1211110237Sorion
1212152375Snetchild	case CARD_TERRATVALUE:
1213152375Snetchild	    select_tuner( bktr, PHILIPS_PAL); /* Phlips PAL tuner */
1214152375Snetchild	    goto checkDBX;
1215152375Snetchild	    break;
1216152375Snetchild
121751694Sroger	} /* end switch(card) */
121851694Sroger
121951694Sroger
1220141671Sjulian	/* At this point, a goto checkDBX has not occured */
1221141671Sjulian	/* We have not been able to select a Tuner */
1222141671Sjulian	/* Some cards make use of the tuner address to */
1223141671Sjulian	/* identify the make/model of tuner */
122451694Sroger
1225141671Sjulian	/* At address 0xc0/0xc1 we often find a TEMIC NTSC */
1226141671Sjulian	if ( i2cRead( bktr, 0xc1 ) != ABSENT ) {
122751694Sroger	    select_tuner( bktr, TEMIC_NTSC );
1228141671Sjulian	    goto checkDBX;
1229141671Sjulian	}
123051694Sroger
1231141671Sjulian	/* At address 0xc6/0xc7 we often find a PHILIPS NTSC Tuner */
1232141671Sjulian	if ( i2cRead( bktr, 0xc7 ) != ABSENT ) {
123351694Sroger	    select_tuner( bktr, PHILIPS_NTSC );
1234141671Sjulian	    goto checkDBX;
1235141671Sjulian	}
123651694Sroger
1237141671Sjulian	/* Address 0xc2/0xc3 is default (or common address) for several */
123851694Sroger	/* tuners and we cannot tell which is which. */
123951694Sroger	/* And for all other tuner i2c addresses, select the default */
124051694Sroger	select_tuner( bktr, DEFAULT_TUNER );
124151694Sroger
124251694Sroger
124351694SrogercheckDBX:
124462112Sroger#if defined( BKTR_OVERRIDE_DBX )
124562112Sroger	bktr->card.dbx = BKTR_OVERRIDE_DBX;
124651694Sroger	goto checkMSP;
124751694Sroger#endif
124851694Sroger   /* Check for i2c devices */
124951694Sroger	if (!any_i2c_devices) {
125051694Sroger		goto checkMSP;
125151694Sroger	}
125251694Sroger
125351694Sroger	/* probe for BTSC (dbx) chip */
125451694Sroger	if ( i2cRead( bktr, TDA9850_RADDR ) != ABSENT )
125551694Sroger		bktr->card.dbx = 1;
125651694Sroger
125751694SrogercheckMSP:
125851694Sroger	/* If this is a Hauppauge Bt878 card, we need to enable the
125951694Sroger	 * MSP 34xx audio chip.
126051694Sroger	 * If this is a Hauppauge Bt848 card, reset the MSP device.
126151694Sroger	 * The MSP reset line is wired to GPIO pin 5. On Bt878 cards a pulldown
126251694Sroger	 * resistor holds the device in reset until we set GPIO pin 5.
1263141671Sjulian	 */
126451694Sroger
126551694Sroger	/* Optionally skip the MSP reset. This is handy if you initialise the
126651694Sroger	 * MSP audio in another operating system (eg Windows) first and then
126751694Sroger	 * do a soft reboot.
126851694Sroger	 */
126951694Sroger
127051694Sroger#ifndef BKTR_NO_MSP_RESET
127151694Sroger	if (card == CARD_HAUPPAUGE) {
1272141671Sjulian	    OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5));
1273141671Sjulian	    OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5));  /* write '1' */
1274141671Sjulian	    DELAY(2500); /* wait 2.5ms */
1275141671Sjulian	    OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */
1276141671Sjulian	    DELAY(2500); /* wait 2.5ms */
1277141671Sjulian	    OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5));  /* write '1' */
1278141671Sjulian	    DELAY(2500); /* wait 2.5ms */
1279141671Sjulian	}
128051694Sroger#endif
128151694Sroger
128262112Sroger#if defined( BKTR_OVERRIDE_MSP )
128362112Sroger	bktr->card.msp3400c = BKTR_OVERRIDE_MSP;
128451694Sroger	goto checkMSPEnd;
128551694Sroger#endif
128651694Sroger
128751694Sroger	/* Check for i2c devices */
128851694Sroger	if (!any_i2c_devices) {
128951694Sroger		goto checkMSPEnd;
129051694Sroger	}
129151694Sroger
129251694Sroger	if ( i2cRead( bktr, MSP3400C_RADDR ) != ABSENT ) {
129351694Sroger		bktr->card.msp3400c = 1;
129451694Sroger	}
129551694Sroger
129651694SrogercheckMSPEnd:
129751694Sroger
129851694Sroger	if (bktr->card.msp3400c) {
129951694Sroger		bktr->msp_addr = MSP3400C_WADDR;
130051694Sroger		msp_read_id( bktr );
130162112Sroger		printf("%s: Detected a MSP%s at 0x%x\n", bktr_name(bktr),
130262112Sroger		       bktr->msp_version_string,
130362112Sroger		       bktr->msp_addr);
130451694Sroger
130551694Sroger	}
130651694Sroger
130752593Sroger/* Check for Dolby Surround Sound DPL3518A sound chip */
130852593Sroger	if ( i2cRead( bktr, DPL3518A_RADDR ) != ABSENT ) {
130952593Sroger		bktr->card.dpl3518a = 1;
131052593Sroger	}
131151694Sroger
131252593Sroger	if (bktr->card.dpl3518a) {
131352593Sroger		bktr->dpl_addr = DPL3518A_WADDR;
131459014Sroger		dpl_read_id( bktr );
131562112Sroger		printf("%s: Detected a DPL%s at 0x%x\n", bktr_name(bktr),
131662112Sroger		       bktr->dpl_version_string,
131762112Sroger		       bktr->dpl_addr);
131852593Sroger	}
131952593Sroger
132051694Sroger/* Start of Check Remote */
1321141671Sjulian	/* Check for the Hauppauge IR Remote Control */
1322141671Sjulian	/* If there is an external unit, the internal will be ignored */
132351694Sroger
1324141671Sjulian	bktr->remote_control = 0; /* initial value */
132551694Sroger
1326141671Sjulian	if (any_i2c_devices) {
1327141671Sjulian	    if (i2cRead( bktr, HAUP_REMOTE_EXT_RADDR ) != ABSENT )
1328141671Sjulian		{
1329141671Sjulian		bktr->remote_control      = 1;
1330141671Sjulian		bktr->remote_control_addr = HAUP_REMOTE_EXT_RADDR;
1331141671Sjulian		}
1332141671Sjulian	    else if (i2cRead( bktr, HAUP_REMOTE_INT_RADDR ) != ABSENT )
1333141671Sjulian		{
1334141671Sjulian		bktr->remote_control      = 1;
1335141671Sjulian		bktr->remote_control_addr = HAUP_REMOTE_INT_RADDR;
1336141671Sjulian		}
133751694Sroger
1338141671Sjulian	}
1339141671Sjulian	/* If a remote control is found, poll it 5 times to turn off the LED */
1340141671Sjulian	if (bktr->remote_control) {
1341141671Sjulian		int i;
1342141671Sjulian		for (i=0; i<5; i++)
1343141671Sjulian			i2cRead( bktr, bktr->remote_control_addr );
1344141671Sjulian	}
134551694Sroger/* End of Check Remote */
134651694Sroger
134751694Sroger#if defined( BKTR_USE_PLL )
134851694Sroger	bktr->xtal_pll_mode = BT848_USE_PLL;
134951694Sroger	goto checkPLLEnd;
135051694Sroger#endif
135151694Sroger	/* Default is to use XTALS and not PLL mode */
135251694Sroger	bktr->xtal_pll_mode = BT848_USE_XTALS;
135351694Sroger
135451725Sroger	/* Enable PLL mode for OSPREY users */
135551725Sroger	if (card == CARD_OSPREY)
135651725Sroger		bktr->xtal_pll_mode = BT848_USE_PLL;
135751725Sroger
135851725Sroger	/* Enable PLL mode for Video Highway Xtreme users */
135951725Sroger	if (card == CARD_VIDEO_HIGHWAY_XTREME)
136051725Sroger		bktr->xtal_pll_mode = BT848_USE_PLL;
136151725Sroger
136251725Sroger
136351725Sroger	/* Most (perhaps all) Bt878 cards need to be switched to PLL mode */
136451725Sroger	/* as they only fit the NTSC crystal to their cards */
136552593Sroger	/* Default to enabling PLL mode for all Bt878/879 cards */
136651725Sroger
136752593Sroger	if ((bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) )
136851694Sroger		bktr->xtal_pll_mode = BT848_USE_PLL;
136951694Sroger
137051694Sroger
137151694Sroger#if defined( BKTR_USE_PLL )
137251694SrogercheckPLLEnd:
137351694Sroger#endif
137451694Sroger
137551694Sroger
137651694Sroger	bktr->card.tuner_pllAddr = tuner_i2c_address;
137751694Sroger
137851694Sroger	if ( verbose ) {
137962112Sroger		printf( "%s: %s", bktr_name(bktr), bktr->card.name );
138051694Sroger		if ( bktr->card.tuner )
138151694Sroger			printf( ", %s tuner", bktr->card.tuner->name );
138251694Sroger		if ( bktr->card.dbx )
138351694Sroger			printf( ", dbx stereo" );
138451694Sroger		if ( bktr->card.msp3400c )
138551694Sroger			printf( ", msp3400c stereo" );
138652593Sroger		if ( bktr->card.dpl3518a )
138752593Sroger			printf( ", dpl3518a dolby" );
1388141671Sjulian		if ( bktr->remote_control )
1389141671Sjulian			printf( ", remote control" );
139051694Sroger		printf( ".\n" );
139151694Sroger	}
139251694Sroger}
139351694Sroger
139451694Sroger#undef ABSENT
1395