bktr_audio.c revision 139917
1/*- 2 * 1. Redistributions of source code must retain the 3 * Copyright (c) 1997 Amancio Hasty, 1999 Roger Hardiman 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Amancio Hasty and 17 * Roger Hardiman 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34#include <sys/cdefs.h> 35__FBSDID("$FreeBSD: head/sys/dev/bktr/bktr_audio.c 139917 2005-01-08 22:43:33Z imp $"); 36 37/* 38 * This is part of the Driver for Video Capture Cards (Frame grabbers) 39 * and TV Tuner cards using the Brooktree Bt848, Bt848A, Bt849A, Bt878, Bt879 40 * chipset. 41 * Copyright Roger Hardiman and Amancio Hasty. 42 * 43 * bktr_audio : This deals with controlling the audio on TV cards, 44 * controlling the Audio Multiplexer (audio source selector). 45 * controlling any MSP34xx stereo audio decoders. 46 * controlling any DPL35xx dolby surroud sound audio decoders. 47 * initialising TDA98xx audio devices. 48 * 49 */ 50 51#include "opt_bktr.h" /* Include any kernel config options */ 52 53#include <sys/param.h> 54#include <sys/systm.h> 55#include <sys/kernel.h> 56 57#ifdef __FreeBSD__ 58 59#if (__FreeBSD_version < 500000) 60#include <machine/clock.h> /* for DELAY */ 61#include <pci/pcivar.h> 62#else 63#include <sys/lock.h> 64#include <sys/mutex.h> 65#include <sys/selinfo.h> 66#include <dev/pci/pcivar.h> 67#endif 68 69#if (__FreeBSD_version >=300000) 70#include <machine/bus_memio.h> /* for bus space */ 71#include <machine/bus.h> 72#include <sys/bus.h> 73#endif 74#endif 75 76#ifdef __NetBSD__ 77#include <sys/proc.h> 78#include <dev/ic/bt8xx.h> /* NetBSD location of .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 <dev/bktr/ioctl_meteor.h> 86#include <dev/bktr/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/* 95 * Prototypes for the GV_BCTV2 specific functions. 96 */ 97void set_bctv2_audio( bktr_ptr_t bktr ); 98void bctv2_gpio_write( bktr_ptr_t bktr, int port, int val ); 99/*int bctv2_gpio_read( bktr_ptr_t bktr, int port );*/ /* Not used */ 100 101/* 102 * init_audio_devices 103 * Reset any MSP34xx or TDA98xx audio devices. 104 */ 105void init_audio_devices( bktr_ptr_t bktr ) { 106 107 /* enable stereo if appropriate on TDA audio chip */ 108 if ( bktr->card.dbx ) 109 init_BTSC( bktr ); 110 111 /* reset the MSP34xx stereo audio chip */ 112 if ( bktr->card.msp3400c ) 113 msp_dpl_reset( bktr, bktr->msp_addr ); 114 115 /* reset the DPL35xx dolby audio chip */ 116 if ( bktr->card.dpl3518a ) 117 msp_dpl_reset( bktr, bktr->dpl_addr ); 118 119} 120 121 122/* 123 * 124 */ 125#define AUDIOMUX_DISCOVER_NOT 126int 127set_audio( bktr_ptr_t bktr, int cmd ) 128{ 129 u_long temp; 130 volatile u_char idx; 131 132#if defined( AUDIOMUX_DISCOVER ) 133 if ( cmd >= 200 ) 134 cmd -= 200; 135 else 136#endif /* AUDIOMUX_DISCOVER */ 137 138 /* check for existance of audio MUXes */ 139 if ( !bktr->card.audiomuxs[ 4 ] ) 140 return( -1 ); 141 142 switch (cmd) { 143 case AUDIO_TUNER: 144#ifdef BKTR_REVERSEMUTE 145 bktr->audio_mux_select = 3; 146#else 147 bktr->audio_mux_select = 0; 148#endif 149 150 if (bktr->reverse_mute ) 151 bktr->audio_mux_select = 0; 152 else 153 bktr->audio_mux_select = 3; 154 155 break; 156 case AUDIO_EXTERN: 157 bktr->audio_mux_select = 1; 158 break; 159 case AUDIO_INTERN: 160 bktr->audio_mux_select = 2; 161 break; 162 case AUDIO_MUTE: 163 bktr->audio_mute_state = TRUE; /* set mute */ 164 break; 165 case AUDIO_UNMUTE: 166 bktr->audio_mute_state = FALSE; /* clear mute */ 167 break; 168 default: 169 printf("%s: audio cmd error %02x\n", bktr_name(bktr), 170 cmd); 171 return( -1 ); 172 } 173 174 175 /* Most cards have a simple audio multiplexer to select the 176 * audio source. The I/O_GV card has a more advanced multiplexer 177 * and requires special handling. 178 */ 179 if ( bktr->bt848_card == CARD_IO_BCTV2 ) { 180 set_bctv2_audio( bktr ); 181 return( 0 ); 182 } 183 184 /* Proceed with the simpler audio multiplexer code for the majority 185 * of Bt848 cards. 186 */ 187 188 /* 189 * Leave the upper bits of the GPIO port alone in case they control 190 * something like the dbx or teletext chips. This doesn't guarantee 191 * success, but follows the rule of least astonishment. 192 */ 193 194 if ( bktr->audio_mute_state == TRUE ) { 195#ifdef BKTR_REVERSEMUTE 196 idx = 0; 197#else 198 idx = 3; 199#endif 200 201 if (bktr->reverse_mute ) 202 idx = 3; 203 else 204 idx = 0; 205 206 } 207 else 208 idx = bktr->audio_mux_select; 209 210 211 temp = INL(bktr, BKTR_GPIO_DATA) & ~bktr->card.gpio_mux_bits; 212#if defined( AUDIOMUX_DISCOVER ) 213 OUTL(bktr, BKTR_GPIO_DATA, temp | (cmd & 0xff)); 214 printf("%s: cmd: %d audio mux %x temp %x \n", bktr_name(bktr), 215 cmd, bktr->card.audiomuxs[ idx ], temp ); 216#else 217 OUTL(bktr, BKTR_GPIO_DATA, temp | bktr->card.audiomuxs[ idx ]); 218#endif /* AUDIOMUX_DISCOVER */ 219 220 221 222 /* Some new Hauppauge cards do not have an audio mux */ 223 /* Instead we use the MSP34xx chip to select TV audio, Line-In */ 224 /* FM Radio and Mute */ 225 /* Examples of this are the Hauppauge 44xxx MSP34xx models */ 226 /* It is ok to drive both the mux and the MSP34xx chip. */ 227 /* If there is no mux, the MSP does the switching of the audio source */ 228 /* If there is a mux, it does the switching of the audio source */ 229 230 if ((bktr->card.msp3400c) && (bktr->audio_mux_present == 0)) { 231 232 if (bktr->audio_mute_state == TRUE ) { 233 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000, 0x0000); /* volume to MUTE */ 234 } else { 235 if(bktr->audio_mux_select == 0) { /* TV Tuner */ 236 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000, 0x7300); /* 0 db volume */ 237 if (bktr->msp_source_selected != 0) msp_autodetect(bktr); /* setup TV audio mode */ 238 bktr->msp_source_selected = 0; 239 } 240 if(bktr->audio_mux_select == 1) { /* Line In */ 241 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000, 0x7300); /* 0 db volume */ 242 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000d, 0x1900); /* scart prescale */ 243 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008, 0x0220); /* SCART | STEREO */ 244 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0013, 0x0000); /* DSP In = SC1_IN_L/R */ 245 bktr->msp_source_selected = 1; 246 } 247 248 if(bktr->audio_mux_select == 2) { /* FM Radio */ 249 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000, 0x7300); /* 0 db volume */ 250 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000d, 0x1900); /* scart prescale */ 251 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008, 0x0220); /* SCART | STEREO */ 252 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0013, 0x0200); /* DSP In = SC2_IN_L/R */ 253 bktr->msp_source_selected = 2; 254 } 255 } 256 } 257 258 259 return( 0 ); 260} 261 262 263/* 264 * 265 */ 266void 267temp_mute( bktr_ptr_t bktr, int flag ) 268{ 269 static int muteState = FALSE; 270 271 if ( flag == TRUE ) { 272 muteState = bktr->audio_mute_state; 273 set_audio( bktr, AUDIO_MUTE ); /* prevent 'click' */ 274 } 275 else { 276 tsleep( BKTR_SLEEP, PZERO, "tuning", hz/8 ); 277 if ( muteState == FALSE ) 278 set_audio( bktr, AUDIO_UNMUTE ); 279 } 280} 281 282/* address of BTSC/SAP decoder chip */ 283#define TDA9850_WADDR 0xb6 284#define TDA9850_RADDR 0xb7 285 286 287/* registers in the TDA9850 BTSC/dbx chip */ 288#define CON1ADDR 0x04 289#define CON2ADDR 0x05 290#define CON3ADDR 0x06 291#define CON4ADDR 0x07 292#define ALI1ADDR 0x08 293#define ALI2ADDR 0x09 294#define ALI3ADDR 0x0a 295 296/* 297 * initialise the dbx chip 298 * taken from the Linux bttv driver TDA9850 initialisation code 299 */ 300void 301init_BTSC( bktr_ptr_t bktr ) 302{ 303 i2cWrite(bktr, TDA9850_WADDR, CON1ADDR, 0x08); /* noise threshold st */ 304 i2cWrite(bktr, TDA9850_WADDR, CON2ADDR, 0x08); /* noise threshold sap */ 305 i2cWrite(bktr, TDA9850_WADDR, CON3ADDR, 0x40); /* stereo mode */ 306 i2cWrite(bktr, TDA9850_WADDR, CON4ADDR, 0x07); /* 0 dB input gain? */ 307 i2cWrite(bktr, TDA9850_WADDR, ALI1ADDR, 0x10); /* wideband alignment? */ 308 i2cWrite(bktr, TDA9850_WADDR, ALI2ADDR, 0x10); /* spectral alignment? */ 309 i2cWrite(bktr, TDA9850_WADDR, ALI3ADDR, 0x03); 310} 311 312/* 313 * setup the dbx chip 314 * XXX FIXME: alot of work to be done here, this merely unmutes it. 315 */ 316int 317set_BTSC( bktr_ptr_t bktr, int control ) 318{ 319 return( i2cWrite( bktr, TDA9850_WADDR, CON3ADDR, control ) ); 320} 321 322/* 323 * CARD_GV_BCTV2 specific functions. 324 */ 325 326#define BCTV2_AUDIO_MAIN 0x10 /* main audio program */ 327#define BCTV2_AUDIO_SUB 0x20 /* sub audio program */ 328#define BCTV2_AUDIO_BOTH 0x30 /* main(L) + sub(R) program */ 329 330#define BCTV2_GPIO_REG0 1 331#define BCTV2_GPIO_REG1 3 332 333#define BCTV2_GR0_AUDIO_MODE 3 334#define BCTV2_GR0_AUDIO_MAIN 0 /* main program */ 335#define BCTV2_GR0_AUDIO_SUB 3 /* sub program */ 336#define BCTV2_GR0_AUDIO_BOTH 1 /* main(L) + sub(R) */ 337#define BCTV2_GR0_AUDIO_MUTE 4 /* audio mute */ 338#define BCTV2_GR0_AUDIO_MONO 8 /* force mono */ 339 340void 341set_bctv2_audio( bktr_ptr_t bktr ) 342{ 343 int data; 344 345 switch (bktr->audio_mux_select) { 346 case 1: /* external */ 347 case 2: /* internal */ 348 bctv2_gpio_write(bktr, BCTV2_GPIO_REG1, 0); 349 break; 350 default: /* tuner */ 351 bctv2_gpio_write(bktr, BCTV2_GPIO_REG1, 1); 352 break; 353 } 354/* switch (bktr->audio_sap_select) { */ 355 switch (BCTV2_AUDIO_BOTH) { 356 case BCTV2_AUDIO_SUB: 357 data = BCTV2_GR0_AUDIO_SUB; 358 break; 359 case BCTV2_AUDIO_BOTH: 360 data = BCTV2_GR0_AUDIO_BOTH; 361 break; 362 case BCTV2_AUDIO_MAIN: 363 default: 364 data = BCTV2_GR0_AUDIO_MAIN; 365 break; 366 } 367 if (bktr->audio_mute_state == TRUE) 368 data |= BCTV2_GR0_AUDIO_MUTE; 369 370 bctv2_gpio_write(bktr, BCTV2_GPIO_REG0, data); 371 372 return; 373} 374 375/* gpio_data bit assignment */ 376#define BCTV2_GPIO_ADDR_MASK 0x000300 377#define BCTV2_GPIO_WE 0x000400 378#define BCTV2_GPIO_OE 0x000800 379#define BCTV2_GPIO_VAL_MASK 0x00f000 380 381#define BCTV2_GPIO_PORT_MASK 3 382#define BCTV2_GPIO_ADDR_SHIFT 8 383#define BCTV2_GPIO_VAL_SHIFT 12 384 385/* gpio_out_en value for read/write */ 386#define BCTV2_GPIO_OUT_RMASK 0x000f00 387#define BCTV2_GPIO_OUT_WMASK 0x00ff00 388 389#define BCTV2_BITS 100 390 391void 392bctv2_gpio_write( bktr_ptr_t bktr, int port, int val ) 393{ 394 u_long data, outbits; 395 396 port &= BCTV2_GPIO_PORT_MASK; 397 switch (port) { 398 case 1: 399 case 3: 400 data = ((val << BCTV2_GPIO_VAL_SHIFT) & BCTV2_GPIO_VAL_MASK) | 401 ((port << BCTV2_GPIO_ADDR_SHIFT) & BCTV2_GPIO_ADDR_MASK) | 402 BCTV2_GPIO_WE | BCTV2_GPIO_OE; 403 outbits = BCTV2_GPIO_OUT_WMASK; 404 break; 405 default: 406 return; 407 } 408 OUTL(bktr, BKTR_GPIO_OUT_EN, 0); 409 OUTL(bktr, BKTR_GPIO_DATA, data); 410 OUTL(bktr, BKTR_GPIO_OUT_EN, outbits); 411 DELAY(BCTV2_BITS); 412 OUTL(bktr, BKTR_GPIO_DATA, data & ~BCTV2_GPIO_WE); 413 DELAY(BCTV2_BITS); 414 OUTL(bktr, BKTR_GPIO_DATA, data); 415 DELAY(BCTV2_BITS); 416 OUTL(bktr, BKTR_GPIO_DATA, ~0); 417 OUTL(bktr, BKTR_GPIO_OUT_EN, 0); 418} 419 420/* Not yet used 421int 422bctv2_gpio_read( bktr_ptr_t bktr, int port ) 423{ 424 u_long data, outbits, ret; 425 426 port &= BCTV2_GPIO_PORT_MASK; 427 switch (port) { 428 case 1: 429 case 3: 430 data = ((port << BCTV2_GPIO_ADDR_SHIFT) & BCTV2_GPIO_ADDR_MASK) | 431 BCTV2_GPIO_WE | BCTV2_GPIO_OE; 432 outbits = BCTV2_GPIO_OUT_RMASK; 433 break; 434 default: 435 return( -1 ); 436 } 437 OUTL(bktr, BKTR_GPIO_OUT_EN, 0); 438 OUTL(bktr, BKTR_GPIO_DATA, data); 439 OUTL(bktr, BKTR_GPIO_OUT_EN, outbits); 440 DELAY(BCTV2_BITS); 441 OUTL(bktr, BKTR_GPIO_DATA, data & ~BCTV2_GPIO_OE); 442 DELAY(BCTV2_BITS); 443 ret = INL(bktr, BKTR_GPIO_DATA); 444 DELAY(BCTV2_BITS); 445 OUTL(bktr, BKTR_GPIO_DATA, data); 446 DELAY(BCTV2_BITS); 447 OUTL(bktr, BKTR_GPIO_DATA, ~0); 448 OUTL(bktr, BKTR_GPIO_OUT_EN, 0); 449 return( (ret & BCTV2_GPIO_VAL_MASK) >> BCTV2_GPIO_VAL_SHIFT ); 450} 451*/ 452 453/* 454 * setup the MSP34xx Stereo Audio Chip 455 * This uses the Auto Configuration Option on MSP3410D and MSP3415D chips 456 * and DBX mode selection for MSP3430G chips. 457 * For MSP3400C support, the full programming sequence is required and is 458 * not yet supported. 459 */ 460 461/* Read the MSP version string */ 462void msp_read_id( bktr_ptr_t bktr ){ 463 int rev1=0, rev2=0; 464 rev1 = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x001e); 465 rev2 = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x001f); 466 467 sprintf(bktr->msp_version_string, "34%02d%c-%c%d", 468 (rev2>>8)&0xff, (rev1&0xff)+'@', ((rev1>>8)&0xff)+'@', rev2&0x1f); 469 470} 471 472 473/* Configure the MSP chip to Auto-detect the audio format. 474 * For the MSP3430G, we use fast autodetect mode 475 * For the MSP3410/3415 there are two schemes for this 476 * a) Fast autodetection - the chip is put into autodetect mode, and the function 477 * returns immediatly. This works in most cases and is the Default Mode. 478 * b) Slow mode. The function sets the MSP3410/3415 chip, then waits for feedback from 479 * the chip and re-programs it if needed. 480 */ 481void msp_autodetect( bktr_ptr_t bktr ) { 482 483#ifdef BKTR_NEW_MSP34XX_DRIVER 484 485 /* Just wake up the (maybe) sleeping thread, it'll do everything for us */ 486 msp_wake_thread(bktr); 487 488#else 489 int auto_detect, loops; 490 int stereo; 491 492 /* MSP3430G - countries with mono and DBX stereo */ 493 if (strncmp("3430G", bktr->msp_version_string, 5) == 0){ 494 495 msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0030,0x2003);/* Enable Auto format detection */ 496 msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0020,0x0020);/* Standard Select Reg. = BTSC-Stereo*/ 497 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000E,0x2403);/* darned if I know */ 498 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0320);/* Source select = (St or A) */ 499 /* & Ch. Matrix = St */ 500 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */ 501 } 502 503 504 /* MSP3415D SPECIAL CASE Use the Tuner's Mono audio ouput for the MSP */ 505 /* (for Hauppauge 44xxx card with Tuner Type 0x2a) */ 506 else if ( ( (strncmp("3415D", bktr->msp_version_string, 5) == 0) 507 &&(bktr->msp_use_mono_source == 1) 508 ) 509 || (bktr->slow_msp_audio == 2) ){ 510 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000, 0x7300); /* 0 db volume */ 511 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000d, 0x1900); /* scart prescale */ 512 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008, 0x0220); /* SCART | STEREO */ 513 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0013, 0x0100); /* DSP In = MONO IN */ 514 } 515 516 517 /* MSP3410/MSP3415 - countries with mono, stereo using 2 FM channels and NICAM */ 518 /* FAST sound scheme */ 519 else if (bktr->slow_msp_audio == 0) { 520 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */ 521 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0000);/* Spkr Source = default(FM/AM) */ 522 msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0020,0x0001);/* Enable Auto format detection */ 523 msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0021,0x0001);/* Auto selection of NICAM/MONO mode */ 524 } 525 526 527 /* MSP3410/MSP3415 - European Countries where the fast MSP3410/3415 programming fails */ 528 /* SLOW sound scheme */ 529 else if ( bktr->slow_msp_audio == 1) { 530 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */ 531 msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0020,0x0001);/* Enable Auto format detection */ 532 533 /* wait for 0.5s max for terrestrial sound autodetection */ 534 loops = 10; 535 do { 536 DELAY(100000); 537 auto_detect = msp_dpl_read(bktr, bktr->msp_addr, 0x10, 0x007e); 538 loops++; 539 } while (auto_detect > 0xff && loops < 50); 540 if (bootverbose)printf ("%s: Result of autodetect after %dms: %d\n", 541 bktr_name(bktr), loops*10, auto_detect); 542 543 /* Now set the audio baseband processing */ 544 switch (auto_detect) { 545 case 0: /* no TV sound standard detected */ 546 break; 547 case 2: /* M Dual FM */ 548 break; 549 case 3: /* B/G Dual FM; German stereo */ 550 /* Read the stereo detection value from DSP reg 0x0018 */ 551 DELAY(20000); 552 stereo = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x0018); 553 if (bootverbose)printf ("%s: Stereo reg 0x18 a: %d\n", 554 bktr_name(bktr), stereo); 555 DELAY(20000); 556 stereo = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x0018); 557 if (bootverbose)printf ("%s: Stereo reg 0x18 b: %d\n", 558 bktr_name(bktr), stereo); 559 DELAY(20000); 560 stereo = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x0018); 561 if (bootverbose)printf ("%s: Stereo reg 0x18 c: %d\n", 562 bktr_name(bktr), stereo); 563 if (stereo > 0x0100 && stereo < 0x8000) { /* Seems to be stereo */ 564 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0020);/* Loudspeaker set stereo*/ 565 /* 566 set spatial effect strength to 50% enlargement 567 set spatial effect mode b, stereo basewidth enlargment only 568 */ 569 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0005,0x3f28); 570 } else if (stereo > 0x8000) { /* bilingual mode */ 571 if (bootverbose) printf ("%s: Bilingual mode detected\n", 572 bktr_name(bktr)); 573 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0000);/* Loudspeaker */ 574 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0005,0x0000);/* all spatial effects off */ 575 } else { /* must be mono */ 576 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0030);/* Loudspeaker */ 577 /* 578 set spatial effect strength to 50% enlargement 579 set spatial effect mode a, stereo basewidth enlargment 580 and pseudo stereo effect with automatic high-pass filter 581 */ 582 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0005,0x3f08); 583 } 584#if 0 585 /* The reset value for Channel matrix mode is FM/AM and SOUNDA/LEFT */ 586 /* We would like STEREO instead val: 0x0020 */ 587 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0020);/* Loudspeaker */ 588 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0009,0x0020);/* Headphone */ 589 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000a,0x0020);/* SCART1 */ 590 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0041,0x0020);/* SCART2 */ 591 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000b,0x0020);/* I2S */ 592 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000c,0x0020);/* Quasi-Peak Detector Source */ 593 msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000e,0x0001); 594#endif 595 break; 596 case 8: /* B/G FM NICAM */ 597 msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0021,0x0001);/* Auto selection of NICAM/MONO mode */ 598 break; 599 case 9: /* L_AM NICAM or D/K*/ 600 case 10: /* i-FM NICAM */ 601 break; 602 default: 603 if (bootverbose) printf ("%s: Unknown autodetection result value: %d\n", 604 bktr_name(bktr), auto_detect); 605 } 606 607 } 608 609 610 /* uncomment the following line to enable the MSP34xx 1Khz Tone Generator */ 611 /* turn your speaker volume down low before trying this */ 612 /* msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0014, 0x7f40); */ 613 614#endif /* BKTR_NEW_MSP34XX_DRIVER */ 615} 616 617/* Read the DPL version string */ 618void dpl_read_id( bktr_ptr_t bktr ){ 619 int rev1=0, rev2=0; 620 rev1 = msp_dpl_read(bktr, bktr->dpl_addr, 0x12, 0x001e); 621 rev2 = msp_dpl_read(bktr, bktr->dpl_addr, 0x12, 0x001f); 622 623 sprintf(bktr->dpl_version_string, "34%02d%c-%c%d", 624 ((rev2>>8)&0xff)-1, (rev1&0xff)+'@', ((rev1>>8)&0xff)+'@', rev2&0x1f); 625} 626 627/* Configure the DPL chip to Auto-detect the audio format */ 628void dpl_autodetect( bktr_ptr_t bktr ) { 629 630 /* The following are empiric values tried from the DPL35xx data sheet */ 631 msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x000c,0x0320); /* quasi peak detector source dolby 632 lr 0x03xx; quasi peak detector matrix 633 stereo 0xXX20 */ 634 msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0040,0x0060); /* Surround decoder mode; 635 ADAPTIVE/3D-PANORAMA, that means two 636 speakers and no center speaker, all 637 channels L/R/C/S mixed to L and R */ 638 msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0041,0x0620); /* surround source matrix;I2S2/STEREO*/ 639 msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0042,0x1F00); /* surround delay 31ms max */ 640 msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0043,0x0000); /* automatic surround input balance */ 641 msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0044,0x4000); /* surround spatial effect 50% 642 recommended*/ 643 msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0045,0x5400); /* surround panorama effect 66% 644 recommended with PANORAMA mode 645 in 0x0040 set to panorama */ 646} 647 648