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