Home | History | Annotate | Line # | Download | only in bktr
bktr_audio.c revision 1.1
      1 /*	$NetBSD: bktr_audio.c,v 1.1 2000/05/07 00:16:17 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 #endif
     64 
     65 #if (__FreeBSD_version >=300000)
     66 #include <machine/bus_memio.h>		/* for bus space */
     67 #include <machine/bus.h>
     68 #include <sys/bus.h>
     69 #endif
     70 
     71 #ifdef __NetBSD__
     72 #include <dev/ic/ioctl_meteor.h>	/* NetBSD location of .h files */
     73 #include <dev/ic/ioctl_bt848.h>
     74 #else
     75 #include <machine/ioctl_meteor.h>	/* Traditional location of .h files */
     76 #include <machine/ioctl_bt848.h>        /* extensions to ioctl_meteor.h */
     77 #endif
     78 #include <dev/bktr/bktr_reg.h>
     79 #include <dev/bktr/bktr_core.h>
     80 #include <dev/bktr/bktr_tuner.h>
     81 #include <dev/bktr/bktr_card.h>
     82 #include <dev/bktr/bktr_audio.h>
     83 
     84 
     85 /*
     86  * Prototypes for the GV_BCTV specific functions.
     87  */
     88 void    set_bctv_audio( bktr_ptr_t bktr );
     89 void    bctv_gpio_write( bktr_ptr_t bktr, int port, int val );
     90 /*int   bctv_gpio_read( bktr_ptr_t bktr, int port );*/ /* Not used */
     91 
     92 
     93 
     94 /*
     95  * init_audio_devices
     96  * Reset any MSP34xx or TDA98xx audio devices.
     97  */
     98 void init_audio_devices( bktr_ptr_t bktr ) {
     99 
    100         /* enable stereo if appropriate on TDA audio chip */
    101         if ( bktr->card.dbx )
    102                 init_BTSC( bktr );
    103 
    104         /* reset the MSP34xx stereo audio chip */
    105         if ( bktr->card.msp3400c )
    106                 msp_dpl_reset( bktr, bktr->msp_addr );
    107 
    108         /* reset the DPL35xx dolby audio chip */
    109         if ( bktr->card.dpl3518a )
    110                 msp_dpl_reset( bktr, bktr->dpl_addr );
    111 
    112 }
    113 
    114 
    115 /*
    116  *
    117  */
    118 #define AUDIOMUX_DISCOVER_NOT
    119 int
    120 set_audio( bktr_ptr_t bktr, int cmd )
    121 {
    122 	u_long		temp;
    123 	volatile u_char	idx;
    124 
    125 #if defined( AUDIOMUX_DISCOVER )
    126 	if ( cmd >= 200 )
    127 		cmd -= 200;
    128 	else
    129 #endif /* AUDIOMUX_DISCOVER */
    130 
    131 	/* check for existance of audio MUXes */
    132 	if ( !bktr->card.audiomuxs[ 4 ] )
    133 		return( -1 );
    134 
    135 	switch (cmd) {
    136 	case AUDIO_TUNER:
    137 #ifdef BKTR_REVERSEMUTE
    138 		bktr->audio_mux_select = 3;
    139 #else
    140 		bktr->audio_mux_select = 0;
    141 #endif
    142 
    143 		if (bktr->reverse_mute )
    144 		      bktr->audio_mux_select = 0;
    145 		else
    146 		    bktr->audio_mux_select = 3;
    147 
    148 		break;
    149 	case AUDIO_EXTERN:
    150 		bktr->audio_mux_select = 1;
    151 		break;
    152 	case AUDIO_INTERN:
    153 		bktr->audio_mux_select = 2;
    154 		break;
    155 	case AUDIO_MUTE:
    156 		bktr->audio_mute_state = TRUE;	/* set mute */
    157 		break;
    158 	case AUDIO_UNMUTE:
    159 		bktr->audio_mute_state = FALSE;	/* clear mute */
    160 		break;
    161 	default:
    162 		printf("bktr: audio cmd error %02x\n", cmd);
    163 		return( -1 );
    164 	}
    165 
    166 
    167 	/* Most cards have a simple audio multiplexer to select the
    168 	 * audio source. The I/O_GV card has a more advanced multiplexer
    169 	 * and requires special handling.
    170 	 */
    171         if ( bktr->bt848_card == CARD_IO_GV ) {
    172                 set_bctv_audio( bktr );
    173                 return( 0 );
    174 	}
    175 
    176 	/* Proceed with the simpler audio multiplexer code for the majority
    177 	 * of Bt848 cards.
    178 	 */
    179 
    180 	/*
    181 	 * Leave the upper bits of the GPIO port alone in case they control
    182 	 * something like the dbx or teletext chips.  This doesn't guarantee
    183 	 * success, but follows the rule of least astonishment.
    184 	 */
    185 
    186 	if ( bktr->audio_mute_state == TRUE ) {
    187 #ifdef BKTR_REVERSEMUTE
    188 		idx = 0;
    189 #else
    190 		idx = 3;
    191 #endif
    192 
    193 		if (bktr->reverse_mute )
    194 		  idx  = 3;
    195 		else
    196 		  idx  = 0;
    197 
    198 	}
    199 	else
    200 		idx = bktr->audio_mux_select;
    201 
    202 	temp = INL(bktr, BKTR_GPIO_DATA) & ~bktr->card.gpio_mux_bits;
    203 #if defined( AUDIOMUX_DISCOVER )
    204 	OUTL(bktr, BKTR_GPIO_DATA, temp | (cmd & 0xff));
    205 	printf("cmd: %d audio mux %x temp %x \n", cmd,bktr->card.audiomuxs[ idx ], temp );
    206 #else
    207 	OUTL(bktr, BKTR_GPIO_DATA, temp | bktr->card.audiomuxs[ idx ]);
    208 #endif /* AUDIOMUX_DISCOVER */
    209 
    210 	return( 0 );
    211 }
    212 
    213 
    214 /*
    215  *
    216  */
    217 void
    218 temp_mute( bktr_ptr_t bktr, int flag )
    219 {
    220 	static int	muteState = FALSE;
    221 
    222 	if ( flag == TRUE ) {
    223 		muteState = bktr->audio_mute_state;
    224 		set_audio( bktr, AUDIO_MUTE );		/* prevent 'click' */
    225 	}
    226 	else {
    227 		tsleep( BKTR_SLEEP, PZERO, "tuning", hz/8 );
    228 		if ( muteState == FALSE )
    229 			set_audio( bktr, AUDIO_UNMUTE );
    230 	}
    231 }
    232 
    233 /* address of BTSC/SAP decoder chip */
    234 #define TDA9850_WADDR           0xb6
    235 #define TDA9850_RADDR           0xb7
    236 
    237 
    238 /* registers in the TDA9850 BTSC/dbx chip */
    239 #define CON1ADDR                0x04
    240 #define CON2ADDR                0x05
    241 #define CON3ADDR                0x06
    242 #define CON4ADDR                0x07
    243 #define ALI1ADDR                0x08
    244 #define ALI2ADDR                0x09
    245 #define ALI3ADDR                0x0a
    246 
    247 /*
    248  * initialise the dbx chip
    249  * taken from the Linux bttv driver TDA9850 initialisation code
    250  */
    251 void
    252 init_BTSC( bktr_ptr_t bktr )
    253 {
    254     i2cWrite(bktr, TDA9850_WADDR, CON1ADDR, 0x08); /* noise threshold st */
    255     i2cWrite(bktr, TDA9850_WADDR, CON2ADDR, 0x08); /* noise threshold sap */
    256     i2cWrite(bktr, TDA9850_WADDR, CON3ADDR, 0x40); /* stereo mode */
    257     i2cWrite(bktr, TDA9850_WADDR, CON4ADDR, 0x07); /* 0 dB input gain? */
    258     i2cWrite(bktr, TDA9850_WADDR, ALI1ADDR, 0x10); /* wideband alignment? */
    259     i2cWrite(bktr, TDA9850_WADDR, ALI2ADDR, 0x10); /* spectral alignment? */
    260     i2cWrite(bktr, TDA9850_WADDR, ALI3ADDR, 0x03);
    261 }
    262 
    263 /*
    264  * setup the dbx chip
    265  * XXX FIXME: alot of work to be done here, this merely unmutes it.
    266  */
    267 int
    268 set_BTSC( bktr_ptr_t bktr, int control )
    269 {
    270 	return( i2cWrite( bktr, TDA9850_WADDR, CON3ADDR, control ) );
    271 }
    272 
    273 /*
    274  * CARD_GV_BCTV specific functions.
    275  */
    276 
    277 #define BCTV_AUDIO_MAIN              0x10    /* main audio program */
    278 #define BCTV_AUDIO_SUB               0x20    /* sub audio program */
    279 #define BCTV_AUDIO_BOTH              0x30    /* main(L) + sub(R) program */
    280 
    281 #define BCTV_GPIO_REG0          1
    282 #define BCTV_GPIO_REG1          3
    283 
    284 #define BCTV_GR0_AUDIO_MODE     3
    285 #define BCTV_GR0_AUDIO_MAIN     0       /* main program */
    286 #define BCTV_GR0_AUDIO_SUB      3       /* sub program */
    287 #define BCTV_GR0_AUDIO_BOTH     1       /* main(L) + sub(R) */
    288 #define BCTV_GR0_AUDIO_MUTE     4       /* audio mute */
    289 #define BCTV_GR0_AUDIO_MONO     8       /* force mono */
    290 
    291 void
    292 set_bctv_audio( bktr_ptr_t bktr )
    293 {
    294         int data;
    295 
    296         switch (bktr->audio_mux_select) {
    297         case 1:         /* external */
    298         case 2:         /* internal */
    299                 bctv_gpio_write(bktr, BCTV_GPIO_REG1, 0);
    300                 break;
    301         default:        /* tuner */
    302                 bctv_gpio_write(bktr, BCTV_GPIO_REG1, 1);
    303                 break;
    304         }
    305 /*      switch (bktr->audio_sap_select) { */
    306         switch (BCTV_AUDIO_BOTH) {
    307         case BCTV_AUDIO_SUB:
    308                 data = BCTV_GR0_AUDIO_SUB;
    309                 break;
    310         case BCTV_AUDIO_BOTH:
    311                 data = BCTV_GR0_AUDIO_BOTH;
    312                 break;
    313         case BCTV_AUDIO_MAIN:
    314         default:
    315                 data = BCTV_GR0_AUDIO_MAIN;
    316                 break;
    317         }
    318         if (bktr->audio_mute_state == TRUE)
    319                 data |= BCTV_GR0_AUDIO_MUTE;
    320 
    321         bctv_gpio_write(bktr, BCTV_GPIO_REG0, data);
    322 
    323         return;
    324 }
    325 
    326 /* gpio_data bit assignment */
    327 #define BCTV_GPIO_ADDR_MASK     0x000300
    328 #define BCTV_GPIO_WE            0x000400
    329 #define BCTV_GPIO_OE            0x000800
    330 #define BCTV_GPIO_VAL_MASK      0x00f000
    331 
    332 #define BCTV_GPIO_PORT_MASK     3
    333 #define BCTV_GPIO_ADDR_SHIFT    8
    334 #define BCTV_GPIO_VAL_SHIFT     12
    335 
    336 /* gpio_out_en value for read/write */
    337 #define BCTV_GPIO_OUT_RMASK     0x000f00
    338 #define BCTV_GPIO_OUT_WMASK     0x00ff00
    339 
    340 #define BCTV_BITS       100
    341 
    342 void
    343 bctv_gpio_write( bktr_ptr_t bktr, int port, int val )
    344 {
    345         u_long data, outbits;
    346 
    347         port &= BCTV_GPIO_PORT_MASK;
    348         switch (port) {
    349         case 1:
    350         case 3:
    351                 data = ((val << BCTV_GPIO_VAL_SHIFT) & BCTV_GPIO_VAL_MASK) |
    352                        ((port << BCTV_GPIO_ADDR_SHIFT) & BCTV_GPIO_ADDR_MASK) |
    353                        BCTV_GPIO_WE | BCTV_GPIO_OE;
    354                 outbits = BCTV_GPIO_OUT_WMASK;
    355                 break;
    356         default:
    357                 return;
    358         }
    359         OUTL(bktr, BKTR_GPIO_OUT_EN, 0);
    360         OUTL(bktr, BKTR_GPIO_DATA, data);
    361         OUTL(bktr, BKTR_GPIO_OUT_EN, outbits);
    362         DELAY(BCTV_BITS);
    363         OUTL(bktr, BKTR_GPIO_DATA, data & ~BCTV_GPIO_WE);
    364         DELAY(BCTV_BITS);
    365         OUTL(bktr, BKTR_GPIO_DATA, data);
    366         DELAY(BCTV_BITS);
    367         OUTL(bktr, BKTR_GPIO_DATA, ~0);
    368         OUTL(bktr, BKTR_GPIO_OUT_EN, 0);
    369 }
    370 
    371 /* Not yet used
    372 int
    373 bctv_gpio_read( bktr_ptr_t bktr, int port )
    374 {
    375         u_long data, outbits, ret;
    376 
    377         port &= BCTV_GPIO_PORT_MASK;
    378         switch (port) {
    379         case 1:
    380         case 3:
    381                 data = ((port << BCTV_GPIO_ADDR_SHIFT) & BCTV_GPIO_ADDR_MASK) |
    382                        BCTV_GPIO_WE | BCTV_GPIO_OE;
    383                 outbits = BCTV_GPIO_OUT_RMASK;
    384                 break;
    385         default:
    386                 return( -1 );
    387         }
    388         OUTL(bktr, BKTR_GPIO_OUT_EN, 0);
    389         OUTL(bktr, BKTR_GPIO_DATA, data);
    390         OUTL(bktr, BKTR_GPIO_OUT_EN, outbits);
    391         DELAY(BCTV_BITS);
    392         OUTL(bktr, BKTR_GPIO_DATA, data & ~BCTV_GPIO_OE);
    393         DELAY(BCTV_BITS);
    394         ret = INL(bktr, BKTR_GPIO_DATA);
    395         DELAY(BCTV_BITS);
    396         OUTL(bktr, BKTR_GPIO_DATA, data);
    397         DELAY(BCTV_BITS);
    398         OUTL(bktr, BKTR_GPIO_DATA, ~0);
    399         OUTL(bktr, BKTR_GPIO_OUT_EN, 0);
    400         return( (ret & BCTV_GPIO_VAL_MASK) >> BCTV_GPIO_VAL_SHIFT );
    401 }
    402 */
    403 
    404 /*
    405  * setup the MSP34xx Stereo Audio Chip
    406  * This uses the Auto Configuration Option on MSP3410D and MSP3415D chips
    407  * and DBX mode selection for MSP3430G chips.
    408  * For MSP3400C support, the full programming sequence is required and is
    409  * not yet supported.
    410  */
    411 
    412 /* Read the MSP version string */
    413 void msp_read_id( bktr_ptr_t bktr ){
    414     int rev1=0, rev2=0;
    415     rev1 = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x001e);
    416     rev2 = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x001f);
    417 
    418     sprintf(bktr->msp_version_string, "34%02d%c-%c%d",
    419       (rev2>>8)&0xff, (rev1&0xff)+'@', ((rev1>>8)&0xff)+'@', rev2&0x1f);
    420 
    421 }
    422 
    423 
    424 /* Configure the MSP chip to Auto-detect the audio format.
    425  * For the MSP3430G, we use fast autodetect mode
    426  * For the MSP3410/3415 there are two schemes for this
    427  *  a) Fast autodetection - the chip is put into autodetect mode, and the function
    428  *     returns immediatly. This works in most cases and is the Default Mode.
    429  *  b) Slow mode. The function sets the MSP3410/3415 chip, then waits for feedback from
    430  *     the chip and re-programs it if needed.
    431  */
    432 void msp_autodetect( bktr_ptr_t bktr ) {
    433   int auto_detect, loops;
    434   int stereo;
    435 
    436   /* MSP3430G - countries with mono and DBX stereo */
    437   if (strncmp("3430G", bktr->msp_version_string, 5) == 0){
    438 
    439     msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0030,0x2003);/* Enable Auto format detection */
    440     msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0020,0x0020);/* Standard Select Reg. = BTSC-Stereo*/
    441     msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000E,0x2403);/* darned if I know */
    442     msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0320);/* Source select = (St or A) */
    443 					                     /* & Ch. Matrix = St */
    444     msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */
    445   }
    446 
    447 
    448   /* MSP3410/MSP3415 - countries with mono, stereo using 2 FM channels and NICAM */
    449   /* FAST sound scheme */
    450   if ( (strncmp("3430G", bktr->msp_version_string, 5) != 0)
    451     && (bktr->slow_msp_audio == 0) ){
    452     if(bootverbose)printf("inside fast MSP autodetect code\n");
    453     msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */
    454     msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0020,0x0001);/* Enable Auto format detection */
    455     msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0021,0x0001);/* Auto selection of NICAM/MONO mode */
    456   }
    457 
    458 
    459   /* MSP3410/MSP3415 - European Countries where the fast MSP3410/3415 programming fails */
    460   /* SLOW sound scheme */
    461   if ( (strncmp("3430G", bktr->msp_version_string, 5) != 0)
    462     && (bktr->slow_msp_audio == 1) ){
    463     if (bootverbose)printf("inside slow MSP autodetect code\n");
    464     msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */
    465     msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0020,0x0001);/* Enable Auto format detection */
    466 
    467     /* wait for 0.5s max for terrestrial sound autodetection */
    468     loops = 10;
    469     do {
    470       DELAY(100000);
    471       auto_detect = msp_dpl_read(bktr, bktr->msp_addr, 0x10, 0x007e);
    472       loops++;
    473     } while (auto_detect > 0xff && loops < 50);
    474     if (bootverbose)printf ("Result of autodetect after %dms: %d\n", loops*10, auto_detect);
    475 
    476     /* Now set the audio baseband processing */
    477     switch (auto_detect) {
    478     case 0:                    /* no TV sound standard detected */
    479       break;
    480     case 2:                    /* M Dual FM */
    481       break;
    482     case 3:                    /* B/G Dual FM; German stereo */
    483       /* Read the stereo detection value from DSP reg 0x0018 */
    484       DELAY(20000);
    485       stereo = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x0018);
    486       if (bootverbose)printf ("Stereo reg 0x18 a: %d\n", stereo);
    487       DELAY(20000);
    488       stereo = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x0018);
    489       if (bootverbose)printf ("Stereo reg 0x18 b: %d\n", stereo);
    490       DELAY(20000);
    491       stereo = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x0018);
    492       if (bootverbose)printf ("Stereo reg 0x18 c: %d\n", stereo);
    493       if (stereo > 0x0100 && stereo < 0x8000) { /* Seems to be stereo */
    494         msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0020);/* Loudspeaker set stereo*/
    495         /*
    496           set spatial effect strength to 50% enlargement
    497           set spatial effect mode b, stereo basewidth enlargment only
    498         */
    499         msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0005,0x3f28);
    500       } else if (stereo > 0x8000) {    /* bilingual mode */
    501         if (bootverbose) printf ("Bilingual mode detected\n");
    502         msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0000);/* Loudspeaker */
    503         msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0005,0x0000);/* all spatial effects off */
    504        } else {                 /* must be mono */
    505         msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0030);/* Loudspeaker */
    506         /*
    507           set spatial effect strength to 50% enlargement
    508           set spatial effect mode a, stereo basewidth enlargment
    509           and pseudo stereo effect with automatic high-pass filter
    510         */
    511         msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0005,0x3f08);
    512       }
    513 #if 0
    514        /* The reset value for Channel matrix mode is FM/AM and SOUNDA/LEFT */
    515        /* We would like STEREO instead val: 0x0020 */
    516        msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0020);/* Loudspeaker */
    517        msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0009,0x0020);/* Headphone */
    518        msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000a,0x0020);/* SCART1 */
    519        msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0041,0x0020);/* SCART2 */
    520        msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000b,0x0020);/* I2S */
    521        msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000c,0x0020);/* Quasi-Peak Detector Source */
    522        msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x000e,0x0001);
    523 #endif
    524       break;
    525     case 8:                    /* B/G FM NICAM */
    526        msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0021,0x0001);/* Auto selection of NICAM/MONO mode */
    527        break;
    528      case 9:                    /* L_AM NICAM or D/K*/
    529      case 10:                   /* i-FM NICAM */
    530        break;
    531      default:
    532        if (bootverbose) printf ("Unkown autodetection result value: %d\n", auto_detect);
    533      }
    534 
    535   }
    536 
    537 
    538   /* uncomment the following line to enable the MSP34xx 1Khz Tone Generator */
    539   /* turn your speaker volume down low before trying this */
    540   /* msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0014, 0x7f40); */
    541 }
    542 
    543 /* Read the DPL version string */
    544 void dpl_read_id( bktr_ptr_t bktr ){
    545     int rev1=0, rev2=0;
    546     rev1 = msp_dpl_read(bktr, bktr->dpl_addr, 0x12, 0x001e);
    547     rev2 = msp_dpl_read(bktr, bktr->dpl_addr, 0x12, 0x001f);
    548 
    549     sprintf(bktr->dpl_version_string, "34%02d%c-%c%d",
    550       ((rev2>>8)&0xff)-1, (rev1&0xff)+'@', ((rev1>>8)&0xff)+'@', rev2&0x1f);
    551 }
    552 
    553 /* Configure the DPL chip to Auto-detect the audio format */
    554 void dpl_autodetect( bktr_ptr_t bktr ) {
    555 
    556     /* The following are empiric values tried from the DPL35xx data sheet */
    557     msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x000c,0x0320);	/* quasi peak detector source dolby
    558 								lr 0x03xx; quasi peak detector matrix
    559 								stereo 0xXX20 */
    560     msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0040,0x0060);	/* Surround decoder mode;
    561 								ADAPTIVE/3D-PANORAMA, that means two
    562 								speakers and no center speaker, all
    563 								channels L/R/C/S mixed to L and R */
    564     msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0041,0x0620);	/* surround source matrix;I2S2/STEREO*/
    565     msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0042,0x1F00);	/* surround delay 31ms max */
    566     msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0043,0x0000);	/* automatic surround input balance */
    567     msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0044,0x4000);	/* surround spatial effect 50%
    568 								recommended*/
    569     msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0045,0x5400);	/* surround panorama effect 66%
    570 								recommended with PANORAMA mode
    571 								in 0x0040 set to panorama */
    572 }
    573 
    574