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