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