Index: head/sys/dev/bktr/bktr_card.c =================================================================== --- head/sys/dev/bktr/bktr_card.c (revision 334284) +++ head/sys/dev/bktr/bktr_card.c (revision 334285) @@ -1,1396 +1,1408 @@ /*- * SPDX-License-Identifier: BSD-4-Clause * * 1. Redistributions of source code must retain the * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Amancio Hasty and * Roger Hardiman * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); /* * This is part of the Driver for Video Capture Cards (Frame grabbers) * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879 * chipset. * Copyright Roger Hardiman and Amancio Hasty. * * bktr_card : This deals with identifying TV cards. * trying to find the card make and model of card. * trying to find the type of tuner fitted. * reading the configuration EEPROM. * locating i2c devices. */ #include "opt_bktr.h" /* Include any kernel config options */ #include #include #ifdef __FreeBSD__ #if (__FreeBSD_version < 500000) #include /* for DELAY */ #include #else #include #include #include #include #endif #include #include #endif #ifdef __NetBSD__ #include /* NetBSD location for .h files */ #include #include #include #include #include #else #include #include /* extensions to ioctl_meteor.h */ #include #include #include #include #include #endif /* Include the PCI Vendor definitions */ #ifdef __NetBSD__ #include #include #endif /* Various defines */ #define HAUP_REMOTE_INT_WADDR 0x30 #define HAUP_REMOTE_INT_RADDR 0x31 #define HAUP_REMOTE_EXT_WADDR 0x34 #define HAUP_REMOTE_EXT_RADDR 0x35 /* address of BTSC/SAP decoder chip */ #define TDA9850_WADDR 0xb6 #define TDA9850_RADDR 0xb7 /* address of MSP3400C chip */ #define MSP3400C_WADDR 0x80 #define MSP3400C_RADDR 0x81 /* address of DPL3518A chip */ #define DPL3518A_WADDR 0x84 #define DPL3518A_RADDR 0x85 /* EEProm (128 * 8) on an STB card */ #define X24C01_WADDR 0xae #define X24C01_RADDR 0xaf /* EEProm (256 * 8) on a Hauppauge card */ /* and on most BT878s cards to store the sub-system vendor id */ #define PFC8582_WADDR 0xa0 #define PFC8582_RADDR 0xa1 #if defined(BKTR_SYSTEM_DEFAULT) && BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL #define DEFAULT_TUNER PHILIPS_PALI #else #define DEFAULT_TUNER PHILIPS_NTSC #endif /* * the data for each type of card * * Note: * these entried MUST be kept in the order defined by the CARD_XXX defines! */ static const struct CARDTYPE cards[] = { { CARD_UNKNOWN, /* the card id */ "Unknown", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx unknown */ 0, 0, 0, /* EEProm unknown */ 0, /* EEProm unknown */ { 0, 0, 0, 0, 0 }, 0 }, /* GPIO mask */ { CARD_MIRO, /* the card id */ "Pinnacle/Miro TV", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx unknown */ 0, 0, 0, /* EEProm unknown */ 0, /* size unknown */ { 0x02, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */ 0x0f }, /* GPIO mask */ { CARD_HAUPPAUGE, /* the card id */ "Hauppauge WinCast/TV", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, 0, PFC8582_WADDR, /* EEProm type */ (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */ { 0x00, 0x02, 0x01, 0x04, 1 }, /* audio MUX values */ 0x0f }, /* GPIO mask */ { CARD_STB, /* the card id */ "STB TV/PCI", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, 0, X24C01_WADDR, /* EEProm type */ (u_char)(128 / EEPROMBLOCKSIZE), /* 128 bytes */ { 0x00, 0x01, 0x02, 0x02, 1 }, /* audio MUX values */ 0x0f }, /* GPIO mask */ { CARD_INTEL, /* the card id */ "Intel Smart Video III/VideoLogic Captivator PCI", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, 0, 0, 0, 0, { 0, 0, 0, 0, 0 }, /* audio MUX values */ 0x00 }, /* GPIO mask */ { CARD_IMS_TURBO, /* the card id */ "IMS TV Turbo", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, 0, PFC8582_WADDR, /* EEProm type */ (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */ { 0x01, 0x02, 0x01, 0x00, 1 }, /* audio MUX values */ 0x0f }, /* GPIO mask */ { CARD_AVER_MEDIA, /* the card id */ "AVer Media TV/FM", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, 0, 0, /* EEProm type */ 0, /* EEProm size */ { 0x0c, 0x08, 0x04, 0x00, 1 }, /* audio MUX values */ 0x1f }, /* GPIO mask */ { CARD_OSPREY, /* the card id */ "MMAC Osprey", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, 0, PFC8582_WADDR, /* EEProm type */ (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */ { 0x00, 0x00, 0x00, 0x00, 0 }, /* audio MUX values */ 0 }, /* GPIO mask */ { CARD_NEC_PK, /* the card id */ "NEC PK-UG-X017", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, 0, 0, /* EEProm type */ 0, /* EEProm size */ { 0x01, 0x02, 0x01, 0x00, 1 }, /* audio MUX values */ 0x0f }, /* GPIO mask */ { CARD_IO_BCTV2, /* the card id */ "I/O DATA GV-BCTV2/PCI", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, 0, 0, /* EEProm type */ 0, /* EEProm size */ { 0x00, 0x00, 0x00, 0x00, 1 }, /* Has special MUX handler */ 0x0f }, /* GPIO mask */ { CARD_FLYVIDEO, /* the card id */ "FlyVideo", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, /* msp34xx is optional */ 0, /* dpl3518a is optional */ 0xac, /* EEProm type */ (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */ { 0x000, 0x800, 0x400, 0x8dff00, 1 },/* audio MUX values */ 0x8dff00 }, /* GPIO mask */ { CARD_ZOLTRIX, /* the card id */ "Zoltrix", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, /* msp34xx is optional */ 0, /* dpl3518a is optional */ 0, /* EEProm type */ 0, /* EEProm size */ { 0x04, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */ 0x0f }, /* GPIO mask */ { CARD_KISS, /* the card id */ "KISS TV/FM PCI", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, /* msp34xx is optional */ 0, /* dpl3518a is optional */ 0, /* EEProm type */ 0, /* EEProm size */ { 0x0c, 0x00, 0x0b, 0x0b, 1 }, /* audio MUX values */ 0x0f }, /* GPIO mask */ { CARD_VIDEO_HIGHWAY_XTREME, /* the card id */ "Video Highway Xtreme", /* the 'name' */ NULL, /* the tuner */ 0, 0, 0, 0, 0, /* EEProm type */ 0, /* EEProm size */ { 0x00, 0x02, 0x01, 0x04, 1 }, /* audio MUX values */ 0x0f }, /* GPIO mask */ { CARD_ASKEY_DYNALINK_MAGIC_TVIEW, /* the card id */ "Askey/Dynalink Magic TView", /* the 'name' */ NULL, /* the tuner */ 0, 0, 0, 0, 0, /* EEProm type */ 0, /* EEProm size */ { 0x400, 0xE00, 0x400, 0xC00, 1 }, /* audio MUX values */ 0xE00 }, /* GPIO mask */ { CARD_LEADTEK, /* the card id */ "Leadtek Winfast TV 2000", /* the 'name' */ NULL, /* the tuner */ 0, 0, 0, 0, 0, /* EEProm type */ 0, /* EEProm size */ /* Tuner, Extern, Intern, Mute, Enabled */ { 0x621000, 0x621000, 0x621000, 0xE21000, 1 }, /* audio MUX values */ 0xfff000 }, /* GPIO mask */ { CARD_TERRATVPLUS, /* the card id */ "TerraTVplus", /* the 'name' */ NULL, /* the tuner */ 0, 0, 0, 0, 0, /* EEProm type */ 0, /* EEProm size */ { 0x20000, 0x00000, 0x30000, 0x40000, 1 }, /* audio MUX values*/ 0x70000 }, /* GPIO mask */ { CARD_IO_BCTV3, /* the card id */ "I/O DATA GV-BCTV3/PCI", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, 0, 0, /* EEProm type */ 0, /* EEProm size */ /* Tuner, Extern, Intern, Mute, Enabled */ { 0x10000, 0, 0x10000, 0, 1 }, /* audio MUX values */ 0x10f00 }, /* GPIO mask */ { CARD_AOPEN_VA1000, /* the card id */ "AOpen VA1000", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, 0, 0, /* EEProm unknown */ 0, /* size unknown */ { 0x02, 0x00, 0x00, 0x00, 1 }, /* audio MUX values */ 0x18e0 }, /* GPIO mask */ { CARD_PINNACLE_PCTV_RAVE, /* the card id */ "Pinnacle PCTV Rave", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx unknown */ 0, 0, 0, /* EEProm unknown */ 0, /* size unknown */ { 0x02, 0x01, 0x00, 0x0a, 1 }, /* audio MUX values */ 0x03000F }, /* GPIO mask */ { CARD_PIXELVIEW_PLAYTV_PAK, /* the card id */ "PixelView PlayTV Pak", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, 0, PFC8582_WADDR, /* EEProm type */ (u_char)(256 / EEPROMBLOCKSIZE), /* 256 bytes */ { 0x20000, 0x80000, 0, 0xa8000, 1 }, /* audio MUX values */ 0xAA0000 }, /* GPIO mask */ { CARD_TERRATVALUE, /* the card id */ "TerraTec TValue", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, 0, 0, /* EEProm type */ 0, /* EEProm size */ /* Tuner, Extern, Intern, Mute, Enabled */ { 0x500, 0x900, 0x300, 0x900, 1 }, /* audio MUX values */ 0xffff00 }, /* GPIO mask */ { CARD_PIXELVIEW_PLAYTV_PRO_REV_4C, /* the card id */ "PixelView PlayTV Pro REV-4C ", /* the 'name' */ NULL, /* the tuner */ 0, /* the tuner i2c address */ 0, /* dbx is optional */ 0, 0, 0, /* EEProm type */ 0, /* EEProm size */ { 0x01, 0x04, 0x01, 0x03, 1 }, /* audio MUX values */ 0x00ffffff }, + { CARD_LEADTEK_WINFAST_2000_XP, /* the card id */ + "Leadtek Winfast 2000 XP", /* the 'name' */ + NULL, /* the tuner */ + 0, /* the tuner i2c address */ + 0, /* dbx is optional */ + 0, + 0, + 0, /* EEProm unknown */ + 0, /* size unknown */ + { 0x122000, 0x1000, 0x620000, 0x0000, 1 }, /* audio MUX values */ + 0xb33000 }, /* GPIO mask */ + }; struct bt848_card_sig bt848_card_signature[1]= { /* IMS TURBO TV : card 5 */ { 5,9, {00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 02, 00, 00, 00}} }; /* * Write to the configuration EEPROM on the card. * This is dangerous and will mess up your card. Therefore it is not * implemented. */ int writeEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data ) { return( -1 ); } /* * Read the contents of the configuration EEPROM on the card. * (This is not fitted to all makes of card. All Hauppauge cards have them * and so do newer Bt878 based cards. */ int readEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data ) { int x; int addr; int max; int byte; /* get the address of the EEProm */ addr = (int)(bktr->card.eepromAddr & 0xff); if ( addr == 0 ) return( -1 ); max = (int)(bktr->card.eepromSize * EEPROMBLOCKSIZE); if ( (offset + count) > max ) return( -1 ); /* set the start address */ if ( i2cWrite( bktr, addr, offset, -1 ) == -1 ) return( -1 ); /* the read cycle */ for ( x = 0; x < count; ++x ) { if ( (byte = i2cRead( bktr, (addr | 1) )) == -1 ) return( -1 ); data[ x ] = byte; } return( 0 ); } #define ABSENT (-1) /* * get a signature of the card * read all 128 possible i2c read addresses from 0x01 thru 0xff * build a bit array with a 1 bit for each i2c device that responds * * XXX FIXME: use offset & count args */ int signCard( bktr_ptr_t bktr, int offset, int count, u_char* sig ) { int x; for ( x = 0; x < 16; ++x ) sig[ x ] = 0; for ( x = 0; x < count; ++x ) { if ( i2cRead( bktr, (2 * x) + 1 ) != ABSENT ) { sig[ x / 8 ] |= (1 << (x % 8) ); } } return( 0 ); } /* * check_for_i2c_devices. * Some BT848 cards have no tuner and no additional i2c devices * eg stereo decoder. These are used for video conferencing or capture from * a video camera. (eg VideoLogic Captivator PCI, Intel SmartCapture card). * * Determine if there are any i2c devices present. There are none present if * a) reading from all 128 devices returns ABSENT (-1) for each one * (eg VideoLogic Captivator PCI with BT848) * b) reading from all 128 devices returns 0 for each one * (eg VideoLogic Captivator PCI rev. 2F with BT848A) */ static int check_for_i2c_devices( bktr_ptr_t bktr ){ int x, temp_read; int i2c_all_0 = 1; int i2c_all_absent = 1; for ( x = 0; x < 128; ++x ) { temp_read = i2cRead( bktr, (2 * x) + 1 ); if (temp_read != 0) i2c_all_0 = 0; if (temp_read != ABSENT) i2c_all_absent = 0; } if ((i2c_all_0) || (i2c_all_absent)) return 0; else return 1; } /* * Temic/Philips datasheets say tuners can be at i2c addresses 0xc0, 0xc2, * 0xc4 or 0xc6, settable by links on the tuner. * Determine the actual address used on the TV card by probing read addresses. */ static int locate_tuner_address( bktr_ptr_t bktr) { if (i2cRead( bktr, 0xc1) != ABSENT) return 0xc0; if (i2cRead( bktr, 0xc3) != ABSENT) return 0xc2; if (i2cRead( bktr, 0xc5) != ABSENT) return 0xc4; if (i2cRead( bktr, 0xc7) != ABSENT) return 0xc6; return -1; /* no tuner found */ } /* * Search for a configuration EEPROM on the i2c bus by looking at i2c addresses * where EEPROMs are usually found. * On some cards, the EEPROM appears in several locations, but all in the * range 0xa0 to 0xae. */ static int locate_eeprom_address( bktr_ptr_t bktr) { if (i2cRead( bktr, 0xa0) != ABSENT) return 0xa0; if (i2cRead( bktr, 0xac) != ABSENT) return 0xac; if (i2cRead( bktr, 0xae) != ABSENT) return 0xae; return -1; /* no eeprom found */ } /* * determine the card brand/model * BKTR_OVERRIDE_CARD, BKTR_OVERRIDE_TUNER, BKTR_OVERRIDE_DBX and * BKTR_OVERRIDE_MSP can be used to select a specific device, * regardless of the autodetection and i2c device checks. * * The scheme used for probing cards faces these problems: * It is impossible to work out which type of tuner is actually fitted, * (the driver cannot tell if the Tuner is PAL or NTSC, Temic or Philips) * It is impossible to determine what audio-mux hardware is connected. * It is impossible to determine if there is extra hardware connected to the * GPIO pins (eg radio chips or MSP34xx reset logic) * * However some makes of card (eg Hauppauge) come with a configuration eeprom * which tells us the make of the card. Most eeproms also tell us the * tuner type and other features of the cards. * * The current probe code works as follows * A) If the card uses a Bt878/879: * 1) Read the sub-system vendor id from the configuration EEPROM. * Select the required tuner, audio mux arrangement and any other * onboard features. If this fails, move to step B. * B) If it card uses a Bt848, 848A, 849A or an unknown Bt878/879: * 1) Look for I2C devices. If there are none fitted, it is an Intel or * VideoLogic cards. * 2) Look for a configuration EEPROM. * 2a) If there is one at I2C address 0xa0 it may be * a Hauppauge or an Osprey. Check the EEPROM contents to determine which * one it is. For Hauppauge, select the tuner type and audio hardware. * 2b) If there is an EEPROM at I2C address 0xa8 it will be an STB card. * We still have to guess on the tuner type. * * C) If we do not know the card type from (A) or (B), guess at the tuner * type based on the I2C address of the tuner. * * D) After determining the Tuner Type, we probe the i2c bus for other * devices at known locations, eg IR-Remote Control, MSP34xx and TDA * stereo chips. */ /* * These are the sub-system vendor ID codes stored in the * configuration EEPROM used on Bt878/879 cards. They should match the * number assigned to the company by the PCI Special Interest Group */ #ifndef __NetBSD__ #define PCI_VENDOR_HAUPPAUGE 0x0070 #define PCI_VENDOR_AVERMEDIA 0x1461 #define PCI_VENDOR_STB 0x10B4 #define PCI_VENDOR_ASKEY 0x144F #define PCI_VENDOR_TERRATEC 0x153B #endif /* Following not confirmed with http://members.hyperlink.net.au/~chart, so not added to NetBSD's pcidevs */ #define PCI_VENDOR_LEADTEK_ALT 0x6606 #define PCI_VENDOR_LEADTEK_ALT_2 0x6607 #define PCI_VENDOR_LEADTEK_ALT_3 0x107d #define PCI_VENDOR_FLYVIDEO 0x1851 #define PCI_VENDOR_FLYVIDEO_2 0x1852 #define PCI_VENDOR_IODATA 0x10fc #define PCI_VENDOR_PINNACLE_ALT 0xBD11 /* They got their own ID backwards? */ #define PCI_VENDOR_PINNACLE_NEW 0x11BD #define MODEL_IODATA_GV_BCTV3_PCI 0x4020 #define MODEL_TERRATVALUE_1117 0x1117 #define MODEL_TERRATVALUE_1118 0x1118 #define MODEL_TERRATVALUE_1119 0x1119 #define MODEL_TERRATVALUE_111A 0x111a #define MODEL_TERRATVALUE_1134 0x1134 void probeCard( bktr_ptr_t bktr, int verbose, int unit ) { int card, i,j, card_found; int status; u_char probe_signature[128], *probe_temp; int any_i2c_devices; u_char eeprom[256]; int tuner_i2c_address = -1; int eeprom_i2c_address = -1; /* Select all GPIO bits as inputs */ OUTL(bktr, BKTR_GPIO_OUT_EN, 0); if (bootverbose) printf("%s: GPIO is 0x%08x\n", bktr_name(bktr), INL(bktr, BKTR_GPIO_DATA)); #ifdef HAUPPAUGE_MSP_RESET /* Reset the MSP34xx audio chip. This resolves bootup card * detection problems with old Bt848 based Hauppauge cards with * MSP34xx stereo audio chips. This must be user enabled because * at this point the probe function does not know the card type. */ OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5)); OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */ DELAY(2500); /* wait 2.5ms */ OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */ DELAY(2500); /* wait 2.5ms */ OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */ DELAY(2500); /* wait 2.5ms */ #endif /* Check for the presence of i2c devices */ any_i2c_devices = check_for_i2c_devices( bktr ); /* Check for a user specified override on the card selection */ #if defined( BKTR_OVERRIDE_CARD ) bktr->card = cards[ (card = BKTR_OVERRIDE_CARD) ]; goto checkEEPROM; #endif if (bktr->bt848_card != -1 ) { bktr->card = cards[ (card = bktr->bt848_card) ]; goto checkEEPROM; } /* No override, so try and determine the make of the card */ /* On BT878/879 cards, read the sub-system vendor id */ /* This identifies the manufacturer of the card and the model */ /* In theory this can be read from PCI registers but this does not */ /* appear to work on the FlyVideo 98. Hauppauge also warned that */ /* the PCI registers are sometimes not loaded correctly. */ /* Therefore, I will read the sub-system vendor ID from the EEPROM */ /* (just like the Bt878 does during power up initialisation) */ if ((bktr->id==BROOKTREE_878) || (bktr->id==BROOKTREE_879)) { /* Try and locate the EEPROM */ eeprom_i2c_address = locate_eeprom_address( bktr ); if (eeprom_i2c_address != -1) { unsigned int subsystem_vendor_id; /* vendors PCI-SIG ID */ unsigned int subsystem_id; /* board model number */ unsigned int byte_252, byte_253, byte_254, byte_255; bktr->card = cards[ (card = CARD_UNKNOWN) ]; bktr->card.eepromAddr = eeprom_i2c_address; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); readEEProm(bktr, 0, 256, (u_char *) &eeprom ); byte_252 = (unsigned int)eeprom[252]; byte_253 = (unsigned int)eeprom[253]; byte_254 = (unsigned int)eeprom[254]; byte_255 = (unsigned int)eeprom[255]; subsystem_id = (byte_252 << 8) | byte_253; subsystem_vendor_id = (byte_254 << 8) | byte_255; if ( bootverbose ) printf("%s: subsystem 0x%04x 0x%04x\n", bktr_name(bktr), subsystem_vendor_id, subsystem_id); if (subsystem_vendor_id == PCI_VENDOR_AVERMEDIA) { bktr->card = cards[ (card = CARD_AVER_MEDIA) ]; bktr->card.eepromAddr = eeprom_i2c_address; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); goto checkTuner; } if (subsystem_vendor_id == PCI_VENDOR_HAUPPAUGE) { bktr->card = cards[ (card = CARD_HAUPPAUGE) ]; bktr->card.eepromAddr = eeprom_i2c_address; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); goto checkTuner; } if ((subsystem_vendor_id == PCI_VENDOR_FLYVIDEO) || (subsystem_vendor_id == PCI_VENDOR_FLYVIDEO_2) ) { bktr->card = cards[ (card = CARD_FLYVIDEO) ]; bktr->card.eepromAddr = eeprom_i2c_address; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); goto checkTuner; } if (subsystem_vendor_id == PCI_VENDOR_STB) { bktr->card = cards[ (card = CARD_STB) ]; bktr->card.eepromAddr = eeprom_i2c_address; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); goto checkTuner; } if (subsystem_vendor_id == PCI_VENDOR_ASKEY) { bktr->card = cards[ (card = CARD_ASKEY_DYNALINK_MAGIC_TVIEW) ]; bktr->card.eepromAddr = eeprom_i2c_address; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); goto checkTuner; } if ((subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT) || (subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT_2) || (subsystem_vendor_id == PCI_VENDOR_LEADTEK_ALT_3)) { bktr->card = cards[ (card = CARD_LEADTEK) ]; bktr->card.eepromAddr = eeprom_i2c_address; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); goto checkTuner; } if (subsystem_vendor_id == PCI_VENDOR_PINNACLE_ALT || subsystem_vendor_id == PCI_VENDOR_PINNACLE_NEW) { bktr->card = cards[ (card = CARD_MIRO) ]; bktr->card.eepromAddr = eeprom_i2c_address; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); goto checkTuner; } if (subsystem_vendor_id == PCI_VENDOR_IODATA && subsystem_id == MODEL_IODATA_GV_BCTV3_PCI) { bktr->card = cards[ (card = CARD_IO_BCTV3) ]; bktr->card.eepromAddr = eeprom_i2c_address; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); goto checkTuner; } if (subsystem_vendor_id == PCI_VENDOR_TERRATEC) { switch (subsystem_id) { case MODEL_TERRATVALUE_1117: case MODEL_TERRATVALUE_1118: case MODEL_TERRATVALUE_1119: case MODEL_TERRATVALUE_111A: case MODEL_TERRATVALUE_1134: bktr->card = cards[ (card = CARD_TERRATVALUE) ]; bktr->card.eepromAddr = eeprom_i2c_address; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); goto checkTuner; } } /* Vendor is unknown. We will use the standard probe code */ /* which may not give best results */ printf("%s: Warning - card vendor 0x%04x (model 0x%04x) unknown.\n", bktr_name(bktr), subsystem_vendor_id, subsystem_id); } else { printf("%s: Card has no configuration EEPROM. Cannot determine card make.\n", bktr_name(bktr)); } } /* end of bt878/bt879 card detection code */ /* If we get to this point, we must have a Bt848/848A/849A card */ /* or a Bt878/879 with an unknown subsystem vendor id */ /* Try and determine the make of card by clever i2c probing */ /* Check for i2c devices. If none, move on */ if (!any_i2c_devices) { bktr->card = cards[ (card = CARD_INTEL) ]; bktr->card.eepromAddr = 0; bktr->card.eepromSize = 0; goto checkTuner; } /* Look for Hauppauge, STB and Osprey cards by the presence */ /* of an EEPROM */ /* Note: Bt878 based cards also use EEPROMs so we can only do this */ /* test on BT848/848A and 849A based cards. */ if ((bktr->id==BROOKTREE_848) || (bktr->id==BROOKTREE_848A) || (bktr->id==BROOKTREE_849A)) { /* At i2c address 0xa0, look for Hauppauge and Osprey cards */ if ( (status = i2cRead( bktr, PFC8582_RADDR )) != ABSENT ) { /* Read the eeprom contents */ bktr->card = cards[ (card = CARD_UNKNOWN) ]; bktr->card.eepromAddr = PFC8582_WADDR; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); readEEProm(bktr, 0, 128, (u_char *) &eeprom ); /* For Hauppauge, check the EEPROM begins with 0x84 */ if (eeprom[0] == 0x84) { bktr->card = cards[ (card = CARD_HAUPPAUGE) ]; bktr->card.eepromAddr = PFC8582_WADDR; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); goto checkTuner; } /* For Osprey, check the EEPROM begins with "MMAC" */ if ( (eeprom[0] == 'M') &&(eeprom[1] == 'M') &&(eeprom[2] == 'A') &&(eeprom[3] == 'C')) { bktr->card = cards[ (card = CARD_OSPREY) ]; bktr->card.eepromAddr = PFC8582_WADDR; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); goto checkTuner; } printf("%s: Warning: Unknown card type. EEPROM data not recognised\n", bktr_name(bktr)); printf("%s: %x %x %x %x\n", bktr_name(bktr), eeprom[0],eeprom[1],eeprom[2],eeprom[3]); } /* look for an STB card */ if ( (status = i2cRead( bktr, X24C01_RADDR )) != ABSENT ) { bktr->card = cards[ (card = CARD_STB) ]; bktr->card.eepromAddr = X24C01_WADDR; bktr->card.eepromSize = (u_char)(128 / EEPROMBLOCKSIZE); goto checkTuner; } } signCard( bktr, 1, 128, (u_char *) &probe_signature ); if (bootverbose) { printf("%s: card signature: ", bktr_name(bktr)); for (j = 0; j < Bt848_MAX_SIGN; j++) { printf(" %02x ", probe_signature[j]); } printf("\n\n"); } for (i = 0; i < (sizeof bt848_card_signature)/ sizeof (struct bt848_card_sig); i++ ) { card_found = 1; probe_temp = (u_char *) &bt848_card_signature[i].signature; for (j = 0; j < Bt848_MAX_SIGN; j++) { if ((probe_temp[j] & 0xf) != (probe_signature[j] & 0xf)) { card_found = 0; break; } } if (card_found) { bktr->card = cards[ card = bt848_card_signature[i].card]; eeprom_i2c_address = locate_eeprom_address( bktr ); if (eeprom_i2c_address != -1) { bktr->card.eepromAddr = eeprom_i2c_address; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); } else { bktr->card.eepromAddr = 0; bktr->card.eepromSize = 0; } tuner_i2c_address = locate_tuner_address( bktr ); select_tuner( bktr, bt848_card_signature[i].tuner ); goto checkDBX; } } /* We do not know the card type. Default to Miro */ bktr->card = cards[ (card = CARD_MIRO) ]; checkEEPROM: /* look for a configuration eeprom */ eeprom_i2c_address = locate_eeprom_address( bktr ); if (eeprom_i2c_address != -1) { bktr->card.eepromAddr = eeprom_i2c_address; bktr->card.eepromSize = (u_char)(256 / EEPROMBLOCKSIZE); } else { bktr->card.eepromAddr = 0; bktr->card.eepromSize = 0; } checkTuner: #if !defined( BKTR_OVERRIDE_TUNER ) if (card == CARD_MIRO && mt2032_init(bktr) == 0 && bktr->bt848_tuner == -1) { bktr->card = cards[ (card = CARD_PINNACLE_PCTV_RAVE) ]; select_tuner( bktr, TUNER_MT2032 ); goto checkDBX; } #endif /* look for a tuner */ tuner_i2c_address = locate_tuner_address( bktr ); if ( tuner_i2c_address == -1 ) { select_tuner( bktr, NO_TUNER ); goto checkDBX; } #if defined( BKTR_OVERRIDE_TUNER ) select_tuner( bktr, BKTR_OVERRIDE_TUNER ); goto checkDBX; #endif if (bktr->bt848_tuner != -1 ) { select_tuner( bktr, bktr->bt848_tuner & 0xff ); goto checkDBX; } /* Check for i2c devices */ if (!any_i2c_devices) { select_tuner( bktr, NO_TUNER ); goto checkDBX; } /* differentiate type of tuner */ switch (card) { case CARD_MIRO: switch (((INL(bktr, BKTR_GPIO_DATA) >> 10)-1)&7) { case 0: select_tuner( bktr, TEMIC_PAL ); break; case 1: select_tuner( bktr, PHILIPS_PAL ); break; case 2: select_tuner( bktr, PHILIPS_NTSC ); break; case 3: select_tuner( bktr, PHILIPS_SECAM ); break; case 4: select_tuner( bktr, NO_TUNER ); break; case 5: select_tuner( bktr, PHILIPS_PALI ); break; case 6: select_tuner( bktr, TEMIC_NTSC ); break; case 7: select_tuner( bktr, TEMIC_PALI ); break; } goto checkDBX; break; case CARD_HAUPPAUGE: /* Hauppauge kindly supplied the following Tuner Table */ /* FIXME: I think the tuners the driver selects for types */ /* 0x08 and 0x15 may be incorrect but no one has complained. */ /* Old Temic tuners had their own API, but newer Temic tuners */ /* have the same API as Philips tuners */ /* ID Tuner Model Format We select Format 0x00 NONE 0x01 EXTERNAL 0x02 OTHER 0x03 Philips FI1216 BG 0x04 Philips FI1216MF BGLL' PHILIPS_SECAM 0x05 Philips FI1236 MN PHILIPS_NTSC 0x06 Philips FI1246 I PHILIPS_PALI 0x07 Philips FI1256 DK 0x08 Philips FI1216 MK2 BG PHILIPS_PALI 0x09 Philips FI1216MF MK2 BGLL' PHILIPS_SECAM 0x0a Philips FI1236 MK2 MN PHILIPS_NTSC 0x0b Philips FI1246 MK2 I PHILIPS_PALI 0x0c Philips FI1256 MK2 DK 0x0d Temic 4032FY5 NTSC TEMIC_NTSC 0x0e Temic 4002FH5 BG TEMIC_PAL 0x0f Temic 4062FY5 I TEMIC_PALI 0x10 Philips FR1216 MK2 BG 0x11 Philips FR1216MF MK2 BGLL' PHILIPS_FR1236_SECAM 0x12 Philips FR1236 MK2 MN PHILIPS_FR1236_NTSC 0x13 Philips FR1246 MK2 I 0x14 Philips FR1256 MK2 DK 0x15 Philips FM1216 BG PHILIPS_FR1216_PAL 0x16 Philips FM1216MF BGLL' PHILIPS_FR1236_SECAM 0x17 Philips FM1236 MN PHILIPS_FR1236_NTSC 0x18 Philips FM1246 I 0x19 Philips FM1256 DK 0x1a Temic 4036FY5 MN (FI1236 MK2 clone) PHILIPS_NTSC 0x1b Samsung TCPN9082D MN 0x1c Samsung TCPM9092P Pal BG/I/DK 0x1d Temic 4006FH5 BG PHILIPS_PALI 0x1e Samsung TCPN9085D MN/Radio 0x1f Samsung TCPB9085P Pal BG/I/DK / Radio 0x20 Samsung TCPL9091P Pal BG & Secam L/L' 0x21 Temic 4039FY5 NTSC Radio 0x22 Philips FQ1216ME Pal BGIDK & Secam L/L' 0x23 Temic 4066FY5 Pal I (FI1246 MK2 clone) PHILIPS_PALI 0x24 Philips TD1536 MN/ATSCDigital 0x25 Philips TD1536D MN/ATSCDigital DUAL INPUT 0x26 Philips FMR1236 M/N FM(no demod) 0x27 Philips FI1256MP B/G, D/K 0x28 Samsung TCPQ9091P BG/I/DK, L/L' 0x29 Temic 4006FN5 BG/I/DK 0x2a Temic 4009FR5 BG FM PHILIPS_FR1216_PAL 0x2b Temic 4046FM5 B/G, I, D/K, L/L' 0x2c Temic 4009FN5 B/G, I, D/K, FM (no demod) 0x2d Philips TD1536D_FH_44 MN/ATSCDigital DUAL INPUT */ /* Determine the model number from the eeprom */ if (bktr->card.eepromAddr != 0) { /* eeprom data block structure */ unsigned char *block_1, *block_2, *block_3, *block_4; int block_1_data_size, block_2_data_size, block_3_data_size; int block_1_total_size, block_2_total_size, block_3_total_size; int block_4_header_size; unsigned int model,revision; unsigned char tuner_code; unsigned char no_audio_mux; readEEProm(bktr, 0, 128, (u_char *) &eeprom ); /* LOCATE THE EEPROM DATA BLOCKS */ block_1 = &eeprom[0]; block_1_data_size = (block_1[2] << 8 | block_1[1]); block_1_total_size = block_1_data_size + 3; /* Header bytes */ block_2 = &eeprom[block_1_total_size]; block_2_data_size = (block_2[2] << 8 | block_2[1]); block_2_total_size = block_2_data_size + 3; /* Header bytes */ block_3 = &eeprom[block_1_total_size + block_2_total_size]; block_3_data_size = (block_3[0] &0x07); block_3_total_size = block_3_data_size + 1; /* Header size */ block_4 = &eeprom[block_1_total_size +block_2_total_size +block_3_total_size]; block_4_header_size = 1; model = (block_1[12] << 8 | block_1[11]); revision = (block_1[15] << 16 | block_1[14] << 8 | block_1[13]); tuner_code = block_1[9]; no_audio_mux = ((block_3[3] >> 7) &0x01); if (no_audio_mux) bktr->audio_mux_present = 0; if (verbose) printf("%s: Hauppauge Model %d %c%c%c%c\n", bktr_name(bktr), model, ((revision >> 18) & 0x3f) + 32, ((revision >> 12) & 0x3f) + 32, ((revision >> 6) & 0x3f) + 32, ((revision >> 0) & 0x3f) + 32 ); /* Determine the tuner type from the eeprom */ switch (tuner_code) { case 0x5: case 0x0a: case 0x1a: select_tuner( bktr, PHILIPS_NTSC ); goto checkDBX; case 0x4: case 0x9: select_tuner( bktr, PHILIPS_SECAM ); goto checkDBX; case 0x11: case 0x16: select_tuner( bktr, PHILIPS_FR1236_SECAM ); goto checkDBX; case 0x12: case 0x17: case 0x21: select_tuner( bktr, PHILIPS_FR1236_NTSC ); goto checkDBX; case 0x6: case 0x8: case 0xb: case 0x1d: case 0x23: select_tuner( bktr, PHILIPS_PALI ); goto checkDBX; case 0xd: select_tuner( bktr, TEMIC_NTSC ); goto checkDBX; case 0xe: select_tuner( bktr, TEMIC_PAL ); goto checkDBX; case 0xf: select_tuner( bktr, TEMIC_PALI ); goto checkDBX; case 0x15: select_tuner( bktr, PHILIPS_FR1216_PAL ); goto checkDBX; case 0x2a: bktr->msp_use_mono_source = 1; select_tuner( bktr, PHILIPS_FR1216_PAL ); goto checkDBX; default : printf("%s: Warning - Unknown Hauppauge Tuner 0x%x\n", bktr_name(bktr), tuner_code); } } break; case CARD_AVER_MEDIA: /* AVerMedia kindly supplied some details of their EEPROM contents * which allow us to auto select the Tuner Type. * Only the newer AVerMedia cards actually have an EEPROM. */ if (bktr->card.eepromAddr != 0) { u_char tuner_make; /* Eg Philips, Temic */ u_char tuner_tv_fm; /* TV or TV with FM Radio */ u_char tuner_format; /* Eg NTSC, PAL, SECAM */ int tuner; int tuner_0_table[] = { PHILIPS_NTSC, PHILIPS_PAL, PHILIPS_PAL, PHILIPS_PAL, PHILIPS_PAL, PHILIPS_PAL, PHILIPS_SECAM, PHILIPS_SECAM, PHILIPS_SECAM, PHILIPS_PAL}; int tuner_0_fm_table[] = { PHILIPS_FR1236_NTSC, PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL, PHILIPS_FR1216_PAL, PHILIPS_FR1236_SECAM, PHILIPS_FR1236_SECAM, PHILIPS_FR1236_SECAM, PHILIPS_FR1216_PAL}; int tuner_1_table[] = { TEMIC_NTSC, TEMIC_PAL, TEMIC_PAL, TEMIC_PAL, TEMIC_PAL, TEMIC_PAL, TEMIC_SECAM, TEMIC_SECAM, TEMIC_SECAM, TEMIC_PAL}; /* Extract information from the EEPROM data */ readEEProm(bktr, 0, 128, (u_char *) &eeprom ); tuner_make = (eeprom[0x41] & 0x7); tuner_tv_fm = (eeprom[0x41] & 0x18) >> 3; tuner_format = (eeprom[0x42] & 0xf0) >> 4; /* Treat tuner make 0 (Philips) and make 2 (LG) the same */ if ( ((tuner_make == 0) || (tuner_make == 2)) && (tuner_format <= 9) && (tuner_tv_fm == 0) ) { tuner = tuner_0_table[tuner_format]; select_tuner( bktr, tuner ); goto checkDBX; } if ( ((tuner_make == 0) || (tuner_make == 2)) && (tuner_format <= 9) && (tuner_tv_fm == 1) ) { tuner = tuner_0_fm_table[tuner_format]; select_tuner( bktr, tuner ); goto checkDBX; } if ( (tuner_make == 1) && (tuner_format <= 9) ) { tuner = tuner_1_table[tuner_format]; select_tuner( bktr, tuner ); goto checkDBX; } printf("%s: Warning - Unknown AVerMedia Tuner Make %d Format %d\n", bktr_name(bktr), tuner_make, tuner_format); } break; case CARD_LEADTEK: #if defined(BKTR_SYSTEM_DEFAULT) && BKTR_SYSTEM_DEFAULT == BROOKTREE_PAL select_tuner( bktr, PHILIPS_FR1216_PAL ); #else select_tuner( bktr, PHILIPS_FR1236_NTSC ); #endif goto checkDBX; break; case CARD_IO_BCTV3: select_tuner( bktr, ALPS_TSCH5 ); /* ALPS_TSCH6, in fact. */ goto checkDBX; break; case CARD_TERRATVALUE: select_tuner( bktr, PHILIPS_PAL); /* Phlips PAL tuner */ goto checkDBX; break; } /* end switch(card) */ /* At this point, a goto checkDBX has not occurred */ /* We have not been able to select a Tuner */ /* Some cards make use of the tuner address to */ /* identify the make/model of tuner */ /* At address 0xc0/0xc1 we often find a TEMIC NTSC */ if ( i2cRead( bktr, 0xc1 ) != ABSENT ) { select_tuner( bktr, TEMIC_NTSC ); goto checkDBX; } /* At address 0xc6/0xc7 we often find a PHILIPS NTSC Tuner */ if ( i2cRead( bktr, 0xc7 ) != ABSENT ) { select_tuner( bktr, PHILIPS_NTSC ); goto checkDBX; } /* Address 0xc2/0xc3 is default (or common address) for several */ /* tuners and we cannot tell which is which. */ /* And for all other tuner i2c addresses, select the default */ select_tuner( bktr, DEFAULT_TUNER ); checkDBX: #if defined( BKTR_OVERRIDE_DBX ) bktr->card.dbx = BKTR_OVERRIDE_DBX; goto checkMSP; #endif /* Check for i2c devices */ if (!any_i2c_devices) { goto checkMSP; } /* probe for BTSC (dbx) chip */ if ( i2cRead( bktr, TDA9850_RADDR ) != ABSENT ) bktr->card.dbx = 1; checkMSP: /* If this is a Hauppauge Bt878 card, we need to enable the * MSP 34xx audio chip. * If this is a Hauppauge Bt848 card, reset the MSP device. * The MSP reset line is wired to GPIO pin 5. On Bt878 cards a pulldown * resistor holds the device in reset until we set GPIO pin 5. */ /* Optionally skip the MSP reset. This is handy if you initialise the * MSP audio in another operating system (eg Windows) first and then * do a soft reboot. */ #ifndef BKTR_NO_MSP_RESET if (card == CARD_HAUPPAUGE) { OUTL(bktr, BKTR_GPIO_OUT_EN, INL(bktr, BKTR_GPIO_OUT_EN) | (1<<5)); OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */ DELAY(2500); /* wait 2.5ms */ OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) & ~(1<<5)); /* write '0' */ DELAY(2500); /* wait 2.5ms */ OUTL(bktr, BKTR_GPIO_DATA, INL(bktr, BKTR_GPIO_DATA) | (1<<5)); /* write '1' */ DELAY(2500); /* wait 2.5ms */ } #endif #if defined( BKTR_OVERRIDE_MSP ) bktr->card.msp3400c = BKTR_OVERRIDE_MSP; goto checkMSPEnd; #endif /* Check for i2c devices */ if (!any_i2c_devices) { goto checkMSPEnd; } if ( i2cRead( bktr, MSP3400C_RADDR ) != ABSENT ) { bktr->card.msp3400c = 1; } checkMSPEnd: if (bktr->card.msp3400c) { bktr->msp_addr = MSP3400C_WADDR; msp_read_id( bktr ); printf("%s: Detected a MSP%s at 0x%x\n", bktr_name(bktr), bktr->msp_version_string, bktr->msp_addr); } /* Check for Dolby Surround Sound DPL3518A sound chip */ if ( i2cRead( bktr, DPL3518A_RADDR ) != ABSENT ) { bktr->card.dpl3518a = 1; } if (bktr->card.dpl3518a) { bktr->dpl_addr = DPL3518A_WADDR; dpl_read_id( bktr ); printf("%s: Detected a DPL%s at 0x%x\n", bktr_name(bktr), bktr->dpl_version_string, bktr->dpl_addr); } /* Start of Check Remote */ /* Check for the Hauppauge IR Remote Control */ /* If there is an external unit, the internal will be ignored */ bktr->remote_control = 0; /* initial value */ if (any_i2c_devices) { if (i2cRead( bktr, HAUP_REMOTE_EXT_RADDR ) != ABSENT ) { bktr->remote_control = 1; bktr->remote_control_addr = HAUP_REMOTE_EXT_RADDR; } else if (i2cRead( bktr, HAUP_REMOTE_INT_RADDR ) != ABSENT ) { bktr->remote_control = 1; bktr->remote_control_addr = HAUP_REMOTE_INT_RADDR; } } /* If a remote control is found, poll it 5 times to turn off the LED */ if (bktr->remote_control) { int i; for (i=0; i<5; i++) i2cRead( bktr, bktr->remote_control_addr ); } /* End of Check Remote */ #if defined( BKTR_USE_PLL ) bktr->xtal_pll_mode = BT848_USE_PLL; goto checkPLLEnd; #endif /* Default is to use XTALS and not PLL mode */ bktr->xtal_pll_mode = BT848_USE_XTALS; /* Enable PLL mode for OSPREY users */ if (card == CARD_OSPREY) bktr->xtal_pll_mode = BT848_USE_PLL; /* Enable PLL mode for Video Highway Xtreme users */ if (card == CARD_VIDEO_HIGHWAY_XTREME) bktr->xtal_pll_mode = BT848_USE_PLL; /* Most (perhaps all) Bt878 cards need to be switched to PLL mode */ /* as they only fit the NTSC crystal to their cards */ /* Default to enabling PLL mode for all Bt878/879 cards */ if ((bktr->id==BROOKTREE_878 || bktr->id==BROOKTREE_879) ) bktr->xtal_pll_mode = BT848_USE_PLL; #if defined( BKTR_USE_PLL ) checkPLLEnd: #endif bktr->card.tuner_pllAddr = tuner_i2c_address; if ( verbose ) { printf( "%s: %s", bktr_name(bktr), bktr->card.name ); if ( bktr->card.tuner ) printf( ", %s tuner", bktr->card.tuner->name ); if ( bktr->card.dbx ) printf( ", dbx stereo" ); if ( bktr->card.msp3400c ) printf( ", msp3400c stereo" ); if ( bktr->card.dpl3518a ) printf( ", dpl3518a dolby" ); if ( bktr->remote_control ) printf( ", remote control" ); printf( ".\n" ); } } #undef ABSENT Index: head/sys/dev/bktr/bktr_card.h =================================================================== --- head/sys/dev/bktr/bktr_card.h (revision 334284) +++ head/sys/dev/bktr/bktr_card.h (revision 334285) @@ -1,96 +1,97 @@ /* $FreeBSD$ */ /* * This is part of the Driver for Video Capture Cards (Frame grabbers) * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879 * chipset. * Copyright Roger Hardiman and Amancio Hasty. * * bktr_card : This deals with identifying TV cards. * trying to find the card make and model of card. * trying to find the type of tuner fitted. * reading the configuration EEPROM. * locating i2c devices. * */ /*- * SPDX-License-Identifier: BSD-4-Clause * * 1. Redistributions of source code must retain the * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Amancio Hasty and * Roger Hardiman * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* * If probeCard() fails to detect the correct card on boot you can * override it by setting adding the following option to your kernel config * options BKTR_OVERRIDE_CARD * eg options BKTR_OVERRIDE CARD=1 * * or using the sysclt hw.bt848.card * eg sysctl hw.bt848.card=1 * * where is one of the following card defines. */ #define CARD_UNKNOWN 0 #define CARD_MIRO 1 #define CARD_HAUPPAUGE 2 #define CARD_STB 3 #define CARD_INTEL 4 /* Also for VideoLogic Captivator PCI */ #define CARD_IMS_TURBO 5 #define CARD_AVER_MEDIA 6 #define CARD_OSPREY 7 #define CARD_NEC_PK 8 #define CARD_IO_BCTV2 9 #define CARD_FLYVIDEO 10 #define CARD_ZOLTRIX 11 #define CARD_KISS 12 #define CARD_VIDEO_HIGHWAY_XTREME 13 #define CARD_ASKEY_DYNALINK_MAGIC_TVIEW 14 #define CARD_LEADTEK 15 #define CARD_TERRATVPLUS 16 #define CARD_IO_BCTV3 17 #define CARD_AOPEN_VA1000 18 #define CARD_PINNACLE_PCTV_RAVE 19 #define CARD_PIXELVIEW_PLAYTV_PAK 20 #define CARD_TERRATVALUE 21 #define CARD_PIXELVIEW_PLAYTV_PRO_REV_4C 22 -#define Bt848_MAX_CARD 23 +#define CARD_LEADTEK_WINFAST_2000_XP 23 +#define Bt848_MAX_CARD 24 #define CARD_IO_GV CARD_IO_BCTV2 int signCard( bktr_ptr_t bktr, int offset, int count, u_char* sig ); void probeCard( bktr_ptr_t bktr, int verbose, int unit); int writeEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data ); int readEEProm( bktr_ptr_t bktr, int offset, int count, u_char *data ); Index: head/sys/dev/bktr/bktr_tuner.c =================================================================== --- head/sys/dev/bktr/bktr_tuner.c (revision 334284) +++ head/sys/dev/bktr/bktr_tuner.c (revision 334285) @@ -1,1426 +1,1436 @@ /*- * SPDX-License-Identifier: BSD-4-Clause * * 1. Redistributions of source code must retain the * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Amancio Hasty and * Roger Hardiman * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); /* * This is part of the Driver for Video Capture Cards (Frame grabbers) * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879 * chipset. * Copyright Roger Hardiman and Amancio Hasty. * * bktr_tuner : This deals with controlling the tuner fitted to TV cards. */ #include #include #include #ifdef __NetBSD__ #include #endif #ifdef __FreeBSD__ #if (__FreeBSD_version < 500000) #include /* for DELAY */ #include #else #include #include #include #include #endif #include #include #endif #ifdef __NetBSD__ #include /* NetBSD .h file location */ #include #include #include #include #else #include #include /* extensions to ioctl_meteor.h */ #include #include #include #include #endif #if defined( TUNER_AFC ) #define AFC_DELAY 10000 /* 10 millisend delay */ #define AFC_BITS 0x07 #define AFC_FREQ_MINUS_125 0x00 #define AFC_FREQ_MINUS_62 0x01 #define AFC_FREQ_CENTERED 0x02 #define AFC_FREQ_PLUS_62 0x03 #define AFC_FREQ_PLUS_125 0x04 #define AFC_MAX_STEP (5 * FREQFACTOR) /* no more than 5 MHz */ #endif /* TUNER_AFC */ #define TTYPE_XXX 0 #define TTYPE_NTSC 1 #define TTYPE_NTSC_J 2 #define TTYPE_PAL 3 #define TTYPE_PAL_M 4 #define TTYPE_PAL_N 5 #define TTYPE_SECAM 6 #define TSA552x_CB_MSB (0x80) #define TSA552x_CB_CP (1<<6) /* set this for fast tuning */ #define TSA552x_CB_T2 (1<<5) /* test mode - Normally set to 0 */ #define TSA552x_CB_T1 (1<<4) /* test mode - Normally set to 0 */ #define TSA552x_CB_T0 (1<<3) /* test mode - Normally set to 1 */ #define TSA552x_CB_RSA (1<<2) /* 0 for 31.25 khz, 1 for 62.5 kHz */ #define TSA552x_CB_RSB (1<<1) /* 0 for FM 50kHz steps, 1 = Use RSA*/ #define TSA552x_CB_OS (1<<0) /* Set to 0 for normal operation */ #define TSA552x_RADIO (TSA552x_CB_MSB | \ TSA552x_CB_T0) /* raise the charge pump voltage for fast tuning */ #define TSA552x_FCONTROL (TSA552x_CB_MSB | \ TSA552x_CB_CP | \ TSA552x_CB_T0 | \ TSA552x_CB_RSA | \ TSA552x_CB_RSB) /* lower the charge pump voltage for better residual oscillator FM */ #define TSA552x_SCONTROL (TSA552x_CB_MSB | \ TSA552x_CB_T0 | \ TSA552x_CB_RSA | \ TSA552x_CB_RSB) /* The control value for the ALPS TSCH5 Tuner */ #define TSCH5_FCONTROL 0x82 #define TSCH5_RADIO 0x86 /* The control value for the ALPS TSBH1 Tuner */ #define TSBH1_FCONTROL 0xce static void mt2032_set_tv_freq(bktr_ptr_t bktr, unsigned int freq); static const struct TUNER tuners[] = { /* XXX FIXME: fill in the band-switch crosspoints */ /* NO_TUNER */ { "", /* the 'name' */ TTYPE_XXX, /* input type */ { 0x00, /* control byte for Tuner PLL */ 0x00, 0x00, 0x00 }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0x00, 0x00, 0x00,0x00} }, /* the band-switch values */ /* TEMIC_NTSC */ { "Temic NTSC", /* the 'name' */ TTYPE_NTSC, /* input type */ { TSA552x_SCONTROL, /* control byte for Tuner PLL */ TSA552x_SCONTROL, TSA552x_SCONTROL, 0x00 }, { 0x00, 0x00}, /* band-switch crosspoints */ { 0x02, 0x04, 0x01, 0x00 } }, /* the band-switch values */ /* TEMIC_PAL */ { "Temic PAL", /* the 'name' */ TTYPE_PAL, /* input type */ { TSA552x_SCONTROL, /* control byte for Tuner PLL */ TSA552x_SCONTROL, TSA552x_SCONTROL, 0x00 }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0x02, 0x04, 0x01, 0x00 } }, /* the band-switch values */ /* TEMIC_SECAM */ { "Temic SECAM", /* the 'name' */ TTYPE_SECAM, /* input type */ { TSA552x_SCONTROL, /* control byte for Tuner PLL */ TSA552x_SCONTROL, TSA552x_SCONTROL, 0x00 }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0x02, 0x04, 0x01,0x00 } }, /* the band-switch values */ /* PHILIPS_NTSC */ { "Philips NTSC", /* the 'name' */ TTYPE_NTSC, /* input type */ { TSA552x_SCONTROL, /* control byte for Tuner PLL */ TSA552x_SCONTROL, TSA552x_SCONTROL, 0x00 }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0xa0, 0x90, 0x30, 0x00 } }, /* the band-switch values */ /* PHILIPS_PAL */ { "Philips PAL", /* the 'name' */ TTYPE_PAL, /* input type */ { TSA552x_SCONTROL, /* control byte for Tuner PLL */ TSA552x_SCONTROL, TSA552x_SCONTROL, 0x00 }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0xa0, 0x90, 0x30, 0x00 } }, /* the band-switch values */ /* PHILIPS_SECAM */ { "Philips SECAM", /* the 'name' */ TTYPE_SECAM, /* input type */ { TSA552x_SCONTROL, /* control byte for Tuner PLL */ TSA552x_SCONTROL, TSA552x_SCONTROL, 0x00 }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0xa7, 0x97, 0x37, 0x00 } }, /* the band-switch values */ /* TEMIC_PAL I */ { "Temic PAL I", /* the 'name' */ TTYPE_PAL, /* input type */ { TSA552x_SCONTROL, /* control byte for Tuner PLL */ TSA552x_SCONTROL, TSA552x_SCONTROL, 0x00 }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0x02, 0x04, 0x01,0x00 } }, /* the band-switch values */ /* PHILIPS_PALI */ { "Philips PAL I", /* the 'name' */ TTYPE_PAL, /* input type */ { TSA552x_SCONTROL, /* control byte for Tuner PLL */ TSA552x_SCONTROL, TSA552x_SCONTROL, 0x00 }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0xa0, 0x90, 0x30,0x00 } }, /* the band-switch values */ /* PHILIPS_FR1236_NTSC */ { "Philips FR1236 NTSC FM", /* the 'name' */ TTYPE_NTSC, /* input type */ { TSA552x_FCONTROL, /* control byte for Tuner PLL */ TSA552x_FCONTROL, TSA552x_FCONTROL, TSA552x_RADIO }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0xa0, 0x90, 0x30,0xa4 } }, /* the band-switch values */ /* PHILIPS_FR1216_PAL */ { "Philips FR1216 PAL FM" , /* the 'name' */ TTYPE_PAL, /* input type */ { TSA552x_FCONTROL, /* control byte for Tuner PLL */ TSA552x_FCONTROL, TSA552x_FCONTROL, TSA552x_RADIO }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0xa0, 0x90, 0x30, 0xa4 } }, /* the band-switch values */ /* PHILIPS_FR1236_SECAM */ { "Philips FR1236 SECAM FM", /* the 'name' */ TTYPE_SECAM, /* input type */ { TSA552x_FCONTROL, /* control byte for Tuner PLL */ TSA552x_FCONTROL, TSA552x_FCONTROL, TSA552x_RADIO }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0xa7, 0x97, 0x37, 0xa4 } }, /* the band-switch values */ /* ALPS TSCH5 NTSC */ { "ALPS TSCH5 NTSC FM", /* the 'name' */ TTYPE_NTSC, /* input type */ { TSCH5_FCONTROL, /* control byte for Tuner PLL */ TSCH5_FCONTROL, TSCH5_FCONTROL, TSCH5_RADIO }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0x14, 0x12, 0x11, 0x04 } }, /* the band-switch values */ /* ALPS TSBH1 NTSC */ { "ALPS TSBH1 NTSC", /* the 'name' */ TTYPE_NTSC, /* input type */ { TSBH1_FCONTROL, /* control byte for Tuner PLL */ TSBH1_FCONTROL, TSBH1_FCONTROL, 0x00 }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0x01, 0x02, 0x08, 0x00 } }, /* the band-switch values */ /* MT2032 Microtune */ { "MT2032", /* the 'name' */ TTYPE_PAL, /* input type */ { TSA552x_SCONTROL, /* control byte for Tuner PLL */ TSA552x_SCONTROL, TSA552x_SCONTROL, 0x00 }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0xa0, 0x90, 0x30, 0x00 } }, /* the band-switch values */ /* LG TPI8PSB12P PAL */ { "LG TPI8PSB12P PAL", /* the 'name' */ TTYPE_PAL, /* input type */ { TSA552x_SCONTROL, /* control byte for Tuner PLL */ TSA552x_SCONTROL, TSA552x_SCONTROL, 0x00 }, { 0x00, 0x00 }, /* band-switch crosspoints */ { 0xa0, 0x90, 0x30, 0x8e } }, /* the band-switch values */ + + /* PHILIPS FI1216 */ + { "PHILIPS_FI1216", /* the 'name' */ + TTYPE_PAL, /* input type */ + { TSBH1_FCONTROL, /* control byte for Tuner PLL */ + TSBH1_FCONTROL, + TSBH1_FCONTROL, + 0x00 }, + { 0x00, 0x00 }, /* band-switch crosspoints */ + { 0x01, 0x02, 0x04, 0x00 } }, /* the band-switch values */ }; /* scaling factor for frequencies expressed as ints */ #define FREQFACTOR 16 /* * Format: * entry 0: MAX legal channel * entry 1: IF frequency * expressed as fi{mHz} * 16, * eg 45.75mHz == 45.75 * 16 = 732 * entry 2: [place holder/future] * entry 3: base of channel record 0 * entry 3 + (x*3): base of channel record 'x' * entry LAST: NULL channel entry marking end of records * * Record: * int 0: base channel * int 1: frequency of base channel, * expressed as fb{mHz} * 16, * int 2: offset frequency between channels, * expressed as fo{mHz} * 16, */ /* * North American Broadcast Channels: * * 2: 55.25 mHz - 4: 67.25 mHz * 5: 77.25 mHz - 6: 83.25 mHz * 7: 175.25 mHz - 13: 211.25 mHz * 14: 471.25 mHz - 83: 885.25 mHz * * IF freq: 45.75 mHz */ #define OFFSET 6.00 static int nabcst[] = { 83, (int)( 45.75 * FREQFACTOR), 0, 14, (int)(471.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 7, (int)(175.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 5, (int)( 77.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 2, (int)( 55.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 0 }; #undef OFFSET /* * North American Cable Channels, IRC: * * 2: 55.25 mHz - 4: 67.25 mHz * 5: 77.25 mHz - 6: 83.25 mHz * 7: 175.25 mHz - 13: 211.25 mHz * 14: 121.25 mHz - 22: 169.25 mHz * 23: 217.25 mHz - 94: 643.25 mHz * 95: 91.25 mHz - 99: 115.25 mHz * * IF freq: 45.75 mHz */ #define OFFSET 6.00 static int irccable[] = { 116, (int)( 45.75 * FREQFACTOR), 0, 100, (int)(649.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 95, (int)( 91.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 23, (int)(217.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 14, (int)(121.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 7, (int)(175.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 5, (int)( 77.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 2, (int)( 55.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 0 }; #undef OFFSET /* * North American Cable Channels, HRC: * * 2: 54 mHz - 4: 66 mHz * 5: 78 mHz - 6: 84 mHz * 7: 174 mHz - 13: 210 mHz * 14: 120 mHz - 22: 168 mHz * 23: 216 mHz - 94: 642 mHz * 95: 90 mHz - 99: 114 mHz * * IF freq: 45.75 mHz */ #define OFFSET 6.00 static int hrccable[] = { 116, (int)( 45.75 * FREQFACTOR), 0, 100, (int)(648.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 95, (int)( 90.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 23, (int)(216.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 14, (int)(120.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 7, (int)(174.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 5, (int)( 78.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 2, (int)( 54.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 0 }; #undef OFFSET /* * Western European broadcast channels: * * (there are others that appear to vary between countries - rmt) * * here's the table Philips provides: * caution, some of the offsets don't compute... * * 1 4525 700 N21 * * 2 4825 700 E2 * 3 5525 700 E3 * 4 6225 700 E4 * * 5 17525 700 E5 * 6 18225 700 E6 * 7 18925 700 E7 * 8 19625 700 E8 * 9 20325 700 E9 * 10 21025 700 E10 * 11 21725 700 E11 * 12 22425 700 E12 * * 13 5375 700 ITA * 14 6225 700 ITB * * 15 8225 700 ITC * * 16 17525 700 ITD * 17 18325 700 ITE * * 18 19225 700 ITF * 19 20125 700 ITG * 20 21025 700 ITH * * 21 47125 800 E21 * 22 47925 800 E22 * 23 48725 800 E23 * 24 49525 800 E24 * 25 50325 800 E25 * 26 51125 800 E26 * 27 51925 800 E27 * 28 52725 800 E28 * 29 53525 800 E29 * 30 54325 800 E30 * 31 55125 800 E31 * 32 55925 800 E32 * 33 56725 800 E33 * 34 57525 800 E34 * 35 58325 800 E35 * 36 59125 800 E36 * 37 59925 800 E37 * 38 60725 800 E38 * 39 61525 800 E39 * 40 62325 800 E40 * 41 63125 800 E41 * 42 63925 800 E42 * 43 64725 800 E43 * 44 65525 800 E44 * 45 66325 800 E45 * 46 67125 800 E46 * 47 67925 800 E47 * 48 68725 800 E48 * 49 69525 800 E49 * 50 70325 800 E50 * 51 71125 800 E51 * 52 71925 800 E52 * 53 72725 800 E53 * 54 73525 800 E54 * 55 74325 800 E55 * 56 75125 800 E56 * 57 75925 800 E57 * 58 76725 800 E58 * 59 77525 800 E59 * 60 78325 800 E60 * 61 79125 800 E61 * 62 79925 800 E62 * 63 80725 800 E63 * 64 81525 800 E64 * 65 82325 800 E65 * 66 83125 800 E66 * 67 83925 800 E67 * 68 84725 800 E68 * 69 85525 800 E69 * * 70 4575 800 IA * 71 5375 800 IB * 72 6175 800 IC * * 74 6925 700 S01 * 75 7625 700 S02 * 76 8325 700 S03 * * 80 10525 700 S1 * 81 11225 700 S2 * 82 11925 700 S3 * 83 12625 700 S4 * 84 13325 700 S5 * 85 14025 700 S6 * 86 14725 700 S7 * 87 15425 700 S8 * 88 16125 700 S9 * 89 16825 700 S10 * 90 23125 700 S11 * 91 23825 700 S12 * 92 24525 700 S13 * 93 25225 700 S14 * 94 25925 700 S15 * 95 26625 700 S16 * 96 27325 700 S17 * 97 28025 700 S18 * 98 28725 700 S19 * 99 29425 700 S20 * * * Channels S21 - S41 are taken from * http://gemma.apple.com:80/dev/technotes/tn/tn1012.html * * 100 30325 800 S21 * 101 31125 800 S22 * 102 31925 800 S23 * 103 32725 800 S24 * 104 33525 800 S25 * 105 34325 800 S26 * 106 35125 800 S27 * 107 35925 800 S28 * 108 36725 800 S29 * 109 37525 800 S30 * 110 38325 800 S31 * 111 39125 800 S32 * 112 39925 800 S33 * 113 40725 800 S34 * 114 41525 800 S35 * 115 42325 800 S36 * 116 43125 800 S37 * 117 43925 800 S38 * 118 44725 800 S39 * 119 45525 800 S40 * 120 46325 800 S41 * * 121 3890 000 IFFREQ * */ static int weurope[] = { 121, (int)( 38.90 * FREQFACTOR), 0, 100, (int)(303.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 90, (int)(231.25 * FREQFACTOR), (int)(7.00 * FREQFACTOR), 80, (int)(105.25 * FREQFACTOR), (int)(7.00 * FREQFACTOR), 74, (int)( 69.25 * FREQFACTOR), (int)(7.00 * FREQFACTOR), 21, (int)(471.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 17, (int)(183.25 * FREQFACTOR), (int)(9.00 * FREQFACTOR), 16, (int)(175.25 * FREQFACTOR), (int)(9.00 * FREQFACTOR), 15, (int)(82.25 * FREQFACTOR), (int)(8.50 * FREQFACTOR), 13, (int)(53.75 * FREQFACTOR), (int)(8.50 * FREQFACTOR), 5, (int)(175.25 * FREQFACTOR), (int)(7.00 * FREQFACTOR), 2, (int)(48.25 * FREQFACTOR), (int)(7.00 * FREQFACTOR), 0 }; /* * Japanese Broadcast Channels: * * 1: 91.25MHz - 3: 103.25MHz * 4: 171.25MHz - 7: 189.25MHz * 8: 193.25MHz - 12: 217.25MHz (VHF) * 13: 471.25MHz - 62: 765.25MHz (UHF) * * IF freq: 58.75 mHz */ #define OFFSET 6.00 #define IF_FREQ 58.75 static int jpnbcst[] = { 62, (int)(IF_FREQ * FREQFACTOR), 0, 13, (int)(471.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 8, (int)(193.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 4, (int)(171.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 1, (int)( 91.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 0 }; #undef IF_FREQ #undef OFFSET /* * Japanese Cable Channels: * * 1: 91.25MHz - 3: 103.25MHz * 4: 171.25MHz - 7: 189.25MHz * 8: 193.25MHz - 12: 217.25MHz * 13: 109.25MHz - 21: 157.25MHz * 22: 165.25MHz * 23: 223.25MHz - 63: 463.25MHz * * IF freq: 58.75 mHz */ #define OFFSET 6.00 #define IF_FREQ 58.75 static int jpncable[] = { 63, (int)(IF_FREQ * FREQFACTOR), 0, 23, (int)(223.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 22, (int)(165.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 13, (int)(109.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 8, (int)(193.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 4, (int)(171.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 1, (int)( 91.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 0 }; #undef IF_FREQ #undef OFFSET /* * xUSSR Broadcast Channels: * * 1: 49.75MHz - 2: 59.25MHz * 3: 77.25MHz - 5: 93.25MHz * 6: 175.25MHz - 12: 223.25MHz * 13-20 - not exist * 21: 471.25MHz - 34: 575.25MHz * 35: 583.25MHz - 69: 855.25MHz * * Cable channels * * 70: 111.25MHz - 77: 167.25MHz * 78: 231.25MHz -107: 463.25MHz * * IF freq: 38.90 MHz */ #define IF_FREQ 38.90 static int xussr[] = { 107, (int)(IF_FREQ * FREQFACTOR), 0, 78, (int)(231.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 70, (int)(111.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 35, (int)(583.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 21, (int)(471.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 6, (int)(175.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 3, (int)( 77.25 * FREQFACTOR), (int)(8.00 * FREQFACTOR), 1, (int)( 49.75 * FREQFACTOR), (int)(9.50 * FREQFACTOR), 0 }; #undef IF_FREQ /* * Australian broadcast channels */ #define OFFSET 7.00 #define IF_FREQ 38.90 static int australia[] = { 83, (int)(IF_FREQ * FREQFACTOR), 0, 28, (int)(527.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 10, (int)(209.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 6, (int)(175.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 4, (int)( 95.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 3, (int)( 86.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 1, (int)( 57.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), 0 }; #undef OFFSET #undef IF_FREQ /* * France broadcast channels */ #define OFFSET 8.00 #define IF_FREQ 38.90 static int france[] = { 69, (int)(IF_FREQ * FREQFACTOR), 0, 21, (int)(471.25 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), /* 21 -> 69 */ 5, (int)(176.00 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), /* 5 -> 10 */ 4, (int)( 63.75 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), /* 4 */ 3, (int)( 60.50 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), /* 3 */ 1, (int)( 47.75 * FREQFACTOR), (int)(OFFSET * FREQFACTOR), /* 1 2 */ 0 }; #undef OFFSET #undef IF_FREQ static struct { int *ptr; char name[BT848_MAX_CHNLSET_NAME_LEN]; } freqTable[] = { {NULL, ""}, {nabcst, "nabcst"}, {irccable, "cableirc"}, {hrccable, "cablehrc"}, {weurope, "weurope"}, {jpnbcst, "jpnbcst"}, {jpncable, "jpncable"}, {xussr, "xussr"}, {australia, "australia"}, {france, "france"}, }; #define TBL_CHNL freqTable[ bktr->tuner.chnlset ].ptr[ x ] #define TBL_BASE_FREQ freqTable[ bktr->tuner.chnlset ].ptr[ x + 1 ] #define TBL_OFFSET freqTable[ bktr->tuner.chnlset ].ptr[ x + 2 ] static int frequency_lookup( bktr_ptr_t bktr, int channel ) { int x; /* check for "> MAX channel" */ x = 0; if ( channel > TBL_CHNL ) return( -1 ); /* search the table for data */ for ( x = 3; TBL_CHNL; x += 3 ) { if ( channel >= TBL_CHNL ) { return( TBL_BASE_FREQ + ((channel - TBL_CHNL) * TBL_OFFSET) ); } } /* not found, must be below the MIN channel */ return( -1 ); } #undef TBL_OFFSET #undef TBL_BASE_FREQ #undef TBL_CHNL #define TBL_IF (bktr->format_params == BT848_IFORM_F_NTSCJ || \ bktr->format_params == BT848_IFORM_F_NTSCM ? \ nabcst[1] : weurope[1]) /* Initialise the tuner structures in the bktr_softc */ /* This is needed as the tuner details are no longer globally declared */ void select_tuner( bktr_ptr_t bktr, int tuner_type ) { if (tuner_type < Bt848_MAX_TUNER) { bktr->card.tuner = &tuners[ tuner_type ]; } else { bktr->card.tuner = NULL; } } /* * Tuner Notes: * Programming the tuner properly is quite complicated. * Here are some notes, based on a FM1246 data sheet for a PAL-I tuner. * The tuner (front end) covers 45.75 Mhz - 855.25 Mhz and an FM band of * 87.5 Mhz to 108.0 Mhz. * * RF and IF. RF = radio frequencies, it is the transmitted signal. * IF is the Intermediate Frequency (the offset from the base * signal where the video, color, audio and NICAM signals are. * * Eg, Picture at 38.9 Mhz, Colour at 34.47 MHz, sound at 32.9 MHz * NICAM at 32.348 Mhz. * Strangely enough, there is an IF (intermediate frequency) for * FM Radio which is 10.7 Mhz. * * The tuner also works in Bands. Philips bands are * FM radio band 87.50 to 108.00 MHz * Low band 45.75 to 170.00 MHz * Mid band 170.00 to 450.00 MHz * High band 450.00 to 855.25 MHz * * * Now we need to set the PLL on the tuner to the required freuqncy. * It has a programmable divisor. * For TV we want * N = 16 (freq RF(pc) + freq IF(pc)) pc is picture carrier and RF and IF * are in MHz. * For RADIO we want a different equation. * freq IF is 10.70 MHz (so the data sheet tells me) * N = (freq RF + freq IF) / step size * The step size must be set to 50 khz (so the data sheet tells me) * (note this is 50 kHz, the other things are in MHz) * so we end up with N = 20x(freq RF + 10.7) * */ #define LOW_BAND 0 #define MID_BAND 1 #define HIGH_BAND 2 #define FM_RADIO_BAND 3 /* Check if these are correct for other than Philips PAL */ #define STATUSBIT_COLD 0x80 #define STATUSBIT_LOCK 0x40 #define STATUSBIT_TV 0x20 #define STATUSBIT_STEREO 0x10 /* valid if FM (aka not TV) */ #define STATUSBIT_ADC 0x07 /* * set the frequency of the tuner * If 'type' is TV_FREQUENCY, the frequency is freq MHz*16 * If 'type' is FM_RADIO_FREQUENCY, the frequency is freq MHz * 100 * (note *16 gives is 4 bits of fraction, eg steps of nnn.0625) * */ int tv_freq( bktr_ptr_t bktr, int frequency, int type ) { const struct TUNER* tuner; u_char addr; u_char control; u_char band; int N; int band_select = 0; #if defined( TEST_TUNER_AFC ) int oldFrequency, afcDelta; #endif tuner = bktr->card.tuner; if ( tuner == NULL ) return( -1 ); if (tuner == &tuners[TUNER_MT2032]) { mt2032_set_tv_freq(bktr, frequency); return 0; } if (type == TV_FREQUENCY) { /* * select the band based on frequency * XXX FIXME: get the cross-over points from the tuner struct */ if ( frequency < (160 * FREQFACTOR ) ) band_select = LOW_BAND; else if ( frequency < (454 * FREQFACTOR ) ) band_select = MID_BAND; else band_select = HIGH_BAND; #if defined( TEST_TUNER_AFC ) if ( bktr->tuner.afc ) frequency -= 4; #endif /* * N = 16 * { fRF(pc) + fIF(pc) } * or N = 16* fRF(pc) + 16*fIF(pc) } * where: * pc is picture carrier, fRF & fIF are in MHz * * fortunatly, frequency is passed in as MHz * 16 * and the TBL_IF frequency is also stored in MHz * 16 */ N = frequency + TBL_IF; /* set the address of the PLL */ addr = bktr->card.tuner_pllAddr; control = tuner->pllControl[ band_select ]; band = tuner->bandAddrs[ band_select ]; if(!(band && control)) /* Don't try to set un- */ return(-1); /* supported modes. */ if ( frequency > bktr->tuner.frequency ) { i2cWrite( bktr, addr, (N>>8) & 0x7f, N & 0xff ); i2cWrite( bktr, addr, control, band ); } else { i2cWrite( bktr, addr, control, band ); i2cWrite( bktr, addr, (N>>8) & 0x7f, N & 0xff ); } #if defined( TUNER_AFC ) if ( bktr->tuner.afc == TRUE ) { #if defined( TEST_TUNER_AFC ) oldFrequency = frequency; #endif if ( (N = do_afc( bktr, addr, N )) < 0 ) { /* AFC failed, restore requested frequency */ N = frequency + TBL_IF; #if defined( TEST_TUNER_AFC ) printf("%s: do_afc: failed to lock\n", bktr_name(bktr)); #endif i2cWrite( bktr, addr, (N>>8) & 0x7f, N & 0xff ); } else frequency = N - TBL_IF; #if defined( TEST_TUNER_AFC ) printf("%s: do_afc: returned freq %d (%d %% %d)\n", bktr_name(bktr), frequency, frequency / 16, frequency % 16); afcDelta = frequency - oldFrequency; printf("%s: changed by: %d clicks (%d mod %d)\n", bktr_name(bktr), afcDelta, afcDelta / 16, afcDelta % 16); #endif } #endif /* TUNER_AFC */ bktr->tuner.frequency = frequency; } if ( type == FM_RADIO_FREQUENCY ) { band_select = FM_RADIO_BAND; /* * N = { fRF(pc) + fIF(pc) }/step_size * The step size is 50kHz for FM radio. * (eg after 102.35MHz comes 102.40 MHz) * fIF is 10.7 MHz (as detailed in the specs) * * frequency is passed in as MHz * 100 * * So, we have N = (frequency/100 + 10.70) /(50/1000) */ N = (frequency + 1070)/5; /* set the address of the PLL */ addr = bktr->card.tuner_pllAddr; control = tuner->pllControl[ band_select ]; band = tuner->bandAddrs[ band_select ]; if(!(band && control)) /* Don't try to set un- */ return(-1); /* supported modes. */ band |= bktr->tuner.radio_mode; /* tuner.radio_mode is set in * the ioctls RADIO_SETMODE * and RADIO_GETMODE */ i2cWrite( bktr, addr, control, band ); i2cWrite( bktr, addr, (N>>8) & 0x7f, N & 0xff ); bktr->tuner.frequency = (N * 5) - 1070; } return( 0 ); } #if defined( TUNER_AFC ) /* * */ int do_afc( bktr_ptr_t bktr, int addr, int frequency ) { int step; int status; int origFrequency; origFrequency = frequency; /* wait for first setting to take effect */ tsleep( BKTR_SLEEP, PZERO, "tuning", hz/8 ); if ( (status = i2cRead( bktr, addr + 1 )) < 0 ) return( -1 ); #if defined( TEST_TUNER_AFC ) printf( "%s: Original freq: %d, status: 0x%02x\n", bktr_name(bktr), frequency, status ); #endif for ( step = 0; step < AFC_MAX_STEP; ++step ) { if ( (status = i2cRead( bktr, addr + 1 )) < 0 ) goto fubar; if ( !(status & 0x40) ) { #if defined( TEST_TUNER_AFC ) printf( "%s: no lock!\n", bktr_name(bktr) ); #endif goto fubar; } switch( status & AFC_BITS ) { case AFC_FREQ_CENTERED: #if defined( TEST_TUNER_AFC ) printf( "%s: Centered, freq: %d, status: 0x%02x\n", bktr_name(bktr), frequency, status ); #endif return( frequency ); case AFC_FREQ_MINUS_125: case AFC_FREQ_MINUS_62: #if defined( TEST_TUNER_AFC ) printf( "%s: Low, freq: %d, status: 0x%02x\n", bktr_name(bktr), frequency, status ); #endif --frequency; break; case AFC_FREQ_PLUS_62: case AFC_FREQ_PLUS_125: #if defined( TEST_TUNER_AFC ) printf( "%s: Hi, freq: %d, status: 0x%02x\n", bktr_name(bktr), frequency, status ); #endif ++frequency; break; } i2cWrite( bktr, addr, (frequency>>8) & 0x7f, frequency & 0xff ); DELAY( AFC_DELAY ); } fubar: i2cWrite( bktr, addr, (origFrequency>>8) & 0x7f, origFrequency & 0xff ); return( -1 ); } #endif /* TUNER_AFC */ #undef TBL_IF /* * Get the Tuner status and signal strength */ int get_tuner_status( bktr_ptr_t bktr ) { if (bktr->card.tuner == &tuners[TUNER_MT2032]) return 0; return i2cRead( bktr, bktr->card.tuner_pllAddr + 1 ); } /* * set the channel of the tuner */ int tv_channel( bktr_ptr_t bktr, int channel ) { int frequency; /* calculate the frequency according to tuner type */ if ( (frequency = frequency_lookup( bktr, channel )) < 0 ) return( -1 ); /* set the new frequency */ if ( tv_freq( bktr, frequency, TV_FREQUENCY ) < 0 ) return( -1 ); /* OK to update records */ return( (bktr->tuner.channel = channel) ); } /* * get channelset name */ int tuner_getchnlset(struct bktr_chnlset *chnlset) { if (( chnlset->index < CHNLSET_MIN ) || ( chnlset->index > CHNLSET_MAX )) return( EINVAL ); memcpy(&chnlset->name, &freqTable[chnlset->index].name, BT848_MAX_CHNLSET_NAME_LEN); chnlset->max_channel=freqTable[chnlset->index].ptr[0]; return( 0 ); } #define TDA9887_ADDR 0x86 static int TDA9887_init(bktr_ptr_t bktr, int output2_enable) { u_char addr = TDA9887_ADDR; i2cWrite(bktr, addr, 0, output2_enable ? 0x50 : 0xd0); i2cWrite(bktr, addr, 1, 0x6e); /* takeover point / de-emphasis */ /* PAL BG: 0x09 PAL I: 0x0a NTSC: 0x04 */ #ifdef MT2032_NTSC i2cWrite(bktr, addr, 2, 0x04); #else i2cWrite(bktr, addr, 2, 0x09); #endif return 0; } #define MT2032_OPTIMIZE_VCO 1 /* holds the value of XOGC register after init */ static int MT2032_XOGC = 4; /* card.tuner_pllAddr not set during init */ #define MT2032_ADDR 0xc0 #ifndef MT2032_ADDR #define MT2032_ADDR (bktr->card.tuner_pllAddr) #endif static int _MT2032_GetRegister(bktr_ptr_t bktr, u_char regNum) { int ch; if (i2cWrite(bktr, MT2032_ADDR, regNum, -1) == -1) { if (bootverbose) printf("%s: MT2032 write failed (i2c addr %#x)\n", bktr_name(bktr), MT2032_ADDR); return -1; } if ((ch = i2cRead(bktr, MT2032_ADDR + 1)) == -1) { if (bootverbose) printf("%s: MT2032 get register %d failed\n", bktr_name(bktr), regNum); return -1; } return ch; } static void _MT2032_SetRegister(bktr_ptr_t bktr, u_char regNum, u_char data) { i2cWrite(bktr, MT2032_ADDR, regNum, data); } #define MT2032_GetRegister(r) _MT2032_GetRegister(bktr,r) #define MT2032_SetRegister(r,d) _MT2032_SetRegister(bktr,r,d) int mt2032_init(bktr_ptr_t bktr) { u_char rdbuf[22]; int xogc, xok = 0; int i; int x; TDA9887_init(bktr, 0); for (i = 0; i < 21; i++) { if ((x = MT2032_GetRegister(i)) == -1) break; rdbuf[i] = x; } if (i < 21) return -1; printf("%s: MT2032: Companycode=%02x%02x Part=%02x Revision=%02x\n", bktr_name(bktr), rdbuf[0x11], rdbuf[0x12], rdbuf[0x13], rdbuf[0x14]); if (rdbuf[0x13] != 4) { printf("%s: MT2032 not found or unknown type\n", bktr_name(bktr)); return -1; } /* Initialize Registers per spec. */ MT2032_SetRegister(2, 0xff); MT2032_SetRegister(3, 0x0f); MT2032_SetRegister(4, 0x1f); MT2032_SetRegister(6, 0xe4); MT2032_SetRegister(7, 0x8f); MT2032_SetRegister(8, 0xc3); MT2032_SetRegister(9, 0x4e); MT2032_SetRegister(10, 0xec); MT2032_SetRegister(13, 0x32); /* Adjust XOGC (register 7), wait for XOK */ xogc = 7; do { DELAY(10000); xok = MT2032_GetRegister(0x0e) & 0x01; if (xok == 1) { break; } xogc--; if (xogc == 3) { xogc = 4; /* min. 4 per spec */ break; } MT2032_SetRegister(7, 0x88 + xogc); } while (xok != 1); TDA9887_init(bktr, 1); MT2032_XOGC = xogc; return 0; } static int MT2032_SpurCheck(int f1, int f2, int spectrum_from, int spectrum_to) { int n1 = 1, n2, f; f1 = f1 / 1000; /* scale to kHz to avoid 32bit overflows */ f2 = f2 / 1000; spectrum_from /= 1000; spectrum_to /= 1000; do { n2 = -n1; f = n1 * (f1 - f2); do { n2--; f = f - f2; if ((f > spectrum_from) && (f < spectrum_to)) { return 1; } } while ((f > (f2 - spectrum_to)) || (n2 > -5)); n1++; } while (n1 < 5); return 0; } static int MT2032_ComputeFreq( int rfin, int if1, int if2, int spectrum_from, int spectrum_to, unsigned char *buf, int *ret_sel, int xogc ) { /* all in Hz */ int fref, lo1, lo1n, lo1a, s, sel; int lo1freq, desired_lo1, desired_lo2, lo2, lo2n, lo2a, lo2num, lo2freq; int nLO1adjust; fref = 5250 * 1000; /* 5.25MHz */ /* per spec 2.3.1 */ desired_lo1 = rfin + if1; lo1 = (2 * (desired_lo1 / 1000) + (fref / 1000)) / (2 * fref / 1000); lo1freq = lo1 * fref; desired_lo2 = lo1freq - rfin - if2; /* per spec 2.3.2 */ for (nLO1adjust = 1; nLO1adjust < 3; nLO1adjust++) { if (!MT2032_SpurCheck(lo1freq, desired_lo2, spectrum_from, spectrum_to)) { break; } if (lo1freq < desired_lo1) { lo1 += nLO1adjust; } else { lo1 -= nLO1adjust; } lo1freq = lo1 * fref; desired_lo2 = lo1freq - rfin - if2; } /* per spec 2.3.3 */ s = lo1freq / 1000 / 1000; if (MT2032_OPTIMIZE_VCO) { if (s > 1890) { sel = 0; } else if (s > 1720) { sel = 1; } else if (s > 1530) { sel = 2; } else if (s > 1370) { sel = 3; } else { sel = 4;/* >1090 */ } } else { if (s > 1790) { sel = 0;/* <1958 */ } else if (s > 1617) { sel = 1; } else if (s > 1449) { sel = 2; } else if (s > 1291) { sel = 3; } else { sel = 4;/* >1090 */ } } *ret_sel = sel; /* per spec 2.3.4 */ lo1n = lo1 / 8; lo1a = lo1 - (lo1n * 8); lo2 = desired_lo2 / fref; lo2n = lo2 / 8; lo2a = lo2 - (lo2n * 8); /* scale to fit in 32bit arith */ lo2num = ((desired_lo2 / 1000) % (fref / 1000)) * 3780 / (fref / 1000); lo2freq = (lo2a + 8 * lo2n) * fref + lo2num * (fref / 1000) / 3780 * 1000; if (lo1a < 0 || lo1a > 7 || lo1n < 17 || lo1n > 48 || lo2a < 0 || lo2a > 7 || lo2n < 17 || lo2n > 30) { printf("MT2032: parameter out of range\n"); return -1; } /* set up MT2032 register map for transfer over i2c */ buf[0] = lo1n - 1; buf[1] = lo1a | (sel << 4); buf[2] = 0x86; /* LOGC */ buf[3] = 0x0f; /* reserved */ buf[4] = 0x1f; buf[5] = (lo2n - 1) | (lo2a << 5); if (rfin < 400 * 1000 * 1000) { buf[6] = 0xe4; } else { buf[6] = 0xf4; /* set PKEN per rev 1.2 */ } buf[7] = 8 + xogc; buf[8] = 0xc3; /* reserved */ buf[9] = 0x4e; /* reserved */ buf[10] = 0xec; /* reserved */ buf[11] = (lo2num & 0xff); buf[12] = (lo2num >> 8) | 0x80; /* Lo2RST */ return 0; } static int MT2032_CheckLOLock(bktr_ptr_t bktr) { int t, lock = 0; for (t = 0; t < 10; t++) { lock = MT2032_GetRegister(0x0e) & 0x06; if (lock == 6) { break; } DELAY(1000); } return lock; } static int MT2032_OptimizeVCO(bktr_ptr_t bktr, int sel, int lock) { int tad1, lo1a; tad1 = MT2032_GetRegister(0x0f) & 0x07; if (tad1 == 0) { return lock; } if (tad1 == 1) { return lock; } if (tad1 == 2) { if (sel == 0) { return lock; } else { sel--; } } else { if (sel < 4) { sel++; } else { return lock; } } lo1a = MT2032_GetRegister(0x01) & 0x07; MT2032_SetRegister(0x01, lo1a | (sel << 4)); lock = MT2032_CheckLOLock(bktr); return lock; } static int MT2032_SetIFFreq(bktr_ptr_t bktr, int rfin, int if1, int if2, int from, int to) { u_char buf[21]; int lint_try, sel, lock = 0; if (MT2032_ComputeFreq(rfin, if1, if2, from, to, &buf[0], &sel, MT2032_XOGC) == -1) return -1; TDA9887_init(bktr, 0); /* send only the relevant registers per Rev. 1.2 */ MT2032_SetRegister(0, buf[0x00]); MT2032_SetRegister(1, buf[0x01]); MT2032_SetRegister(2, buf[0x02]); MT2032_SetRegister(5, buf[0x05]); MT2032_SetRegister(6, buf[0x06]); MT2032_SetRegister(7, buf[0x07]); MT2032_SetRegister(11, buf[0x0B]); MT2032_SetRegister(12, buf[0x0C]); /* wait for PLLs to lock (per manual), retry LINT if not. */ for (lint_try = 0; lint_try < 2; lint_try++) { lock = MT2032_CheckLOLock(bktr); if (MT2032_OPTIMIZE_VCO) { lock = MT2032_OptimizeVCO(bktr, sel, lock); } if (lock == 6) { break; } /* set LINT to re-init PLLs */ MT2032_SetRegister(7, 0x80 + 8 + MT2032_XOGC); DELAY(10000); MT2032_SetRegister(7, 8 + MT2032_XOGC); } if (lock != 6) printf("%s: PLL didn't lock\n", bktr_name(bktr)); MT2032_SetRegister(2, 0x20); TDA9887_init(bktr, 1); return 0; } static void mt2032_set_tv_freq(bktr_ptr_t bktr, unsigned int freq) { int if2,from,to; int stat, tad; #ifdef MT2032_NTSC from=40750*1000; to=46750*1000; if2=45750*1000; #else from=32900*1000; to=39900*1000; if2=38900*1000; #endif if (MT2032_SetIFFreq(bktr, freq*62500 /* freq*1000*1000/16 */, 1090*1000*1000, if2, from, to) == 0) { bktr->tuner.frequency = freq; stat = MT2032_GetRegister(0x0e); tad = MT2032_GetRegister(0x0f); if (bootverbose) printf("%s: frequency set to %d, st = %#x, tad = %#x\n", bktr_name(bktr), freq*62500, stat, tad); } } Index: head/sys/dev/bktr/bktr_tuner.h =================================================================== --- head/sys/dev/bktr/bktr_tuner.h (revision 334284) +++ head/sys/dev/bktr/bktr_tuner.h (revision 334285) @@ -1,106 +1,107 @@ /* $FreeBSD$ */ /* * This is part of the Driver for Video Capture Cards (Frame grabbers) * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879 * chipset. * Copyright Roger Hardiman and Amancio Hasty. * * bktr_tuner : This deals with controlling the tuner fitted to TV cards. * */ /*- * SPDX-License-Identifier: BSD-4-Clause * * 1. Redistributions of source code must retain the * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Amancio Hasty and * Roger Hardiman * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /* Definitions for Tuners */ #define NO_TUNER 0 #define TEMIC_NTSC 1 #define TEMIC_PAL 2 #define TEMIC_SECAM 3 #define PHILIPS_NTSC 4 #define PHILIPS_PAL 5 #define PHILIPS_SECAM 6 #define TEMIC_PALI 7 #define PHILIPS_PALI 8 #define PHILIPS_FR1236_NTSC 9 /* These have FM radio support */ #define PHILIPS_FR1216_PAL 10 /* These have FM radio support */ #define PHILIPS_FR1236_SECAM 11 /* These have FM radio support */ #define ALPS_TSCH5 12 #define ALPS_TSBH1 13 #define TUNER_MT2032 14 #define LG_TPI8PSB12P_PAL 15 -#define Bt848_MAX_TUNER 16 +#define PHILIPS_FI1216 16 +#define Bt848_MAX_TUNER 17 /* experimental code for Automatic Frequency Control */ #define TUNER_AFC /* * Fill in the tuner entries in the bktr_softc based on the selected tuner * type (from the list of tuners above) */ void select_tuner( bktr_ptr_t bktr, int tuner_type ); /* * The Channel Set maps TV channels eg Ch 36, Ch 51, onto frequencies * and is country specific. */ int tuner_getchnlset( struct bktr_chnlset *chnlset ); /* * tv_channel sets the tuner to channel 'n' using the current Channel Set * tv_freq sets the tuner to a specific frequency for TV or for FM Radio * get_tuner_status can be used to get the signal strength. */ #define TV_FREQUENCY 0 #define FM_RADIO_FREQUENCY 1 int tv_channel( bktr_ptr_t bktr, int channel ); int tv_freq( bktr_ptr_t bktr, int frequency, int type ); int get_tuner_status( bktr_ptr_t bktr ); #if defined( TUNER_AFC ) int do_afc( bktr_ptr_t bktr, int addr, int frequency ); #endif /* TUNER_AFC */ int mt2032_init(bktr_ptr_t bktr); /* * This is for start-up convenience only, NOT mandatory. */ #if !defined( DEFAULT_CHNLSET ) #define DEFAULT_CHNLSET CHNLSET_WEUROPE #endif