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