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