bktr_audio.c revision 62112
1/* $FreeBSD: head/sys/dev/bktr/bktr_audio.c 62112 2000-06-26 09:41:32Z 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#include <machine/clock.h>		/* for DELAY */
56#include <pci/pcivar.h>
57
58#if (__FreeBSD_version >=300000)
59#include <machine/bus_memio.h>		/* for bus space */
60#include <machine/bus.h>
61#include <sys/bus.h>
62#endif
63#endif
64
65#ifdef __NetBSD__
66#include <sys/proc.h>
67#include <dev/ic/bt8xx.h>	/* NetBSD location of .h files */
68#include <dev/pci/bktr/bktr_reg.h>
69#include <dev/pci/bktr/bktr_core.h>
70#include <dev/pci/bktr/bktr_tuner.h>
71#include <dev/pci/bktr/bktr_card.h>
72#include <dev/pci/bktr/bktr_audio.h>
73#else
74#include <machine/ioctl_meteor.h>	/* Traditional location of .h files */
75#include <machine/ioctl_bt848.h>        /* extensions to ioctl_meteor.h */
76#include <dev/bktr/bktr_reg.h>
77#include <dev/bktr/bktr_core.h>
78#include <dev/bktr/bktr_tuner.h>
79#include <dev/bktr/bktr_card.h>
80#include <dev/bktr/bktr_audio.h>
81#endif
82
83/*
84 * Prototypes for the GV_BCTV specific functions.
85 */
86void    set_bctv_audio( bktr_ptr_t bktr );
87void    bctv_gpio_write( bktr_ptr_t bktr, int port, int val );
88/*int   bctv_gpio_read( bktr_ptr_t bktr, int port );*/ /* Not used */
89
90
91
92/*
93 * init_audio_devices
94 * Reset any MSP34xx or TDA98xx audio devices.
95 */
96void init_audio_devices( bktr_ptr_t bktr ) {
97
98        /* enable stereo if appropriate on TDA audio chip */
99        if ( bktr->card.dbx )
100                init_BTSC( bktr );
101
102        /* reset the MSP34xx stereo audio chip */
103        if ( bktr->card.msp3400c )
104                msp_dpl_reset( bktr, bktr->msp_addr );
105
106        /* reset the DPL35xx dolby audio chip */
107        if ( bktr->card.dpl3518a )
108                msp_dpl_reset( bktr, bktr->dpl_addr );
109
110}
111
112
113/*
114 *
115 */
116#define AUDIOMUX_DISCOVER_NOT
117int
118set_audio( bktr_ptr_t bktr, int cmd )
119{
120	u_long		temp;
121	volatile u_char	idx;
122
123#if defined( AUDIOMUX_DISCOVER )
124	if ( cmd >= 200 )
125		cmd -= 200;
126	else
127#endif /* AUDIOMUX_DISCOVER */
128
129	/* check for existance of audio MUXes */
130	if ( !bktr->card.audiomuxs[ 4 ] )
131		return( -1 );
132
133	switch (cmd) {
134	case AUDIO_TUNER:
135#ifdef BKTR_REVERSEMUTE
136		bktr->audio_mux_select = 3;
137#else
138		bktr->audio_mux_select = 0;
139#endif
140
141		if (bktr->reverse_mute )
142		      bktr->audio_mux_select = 0;
143		else
144		    bktr->audio_mux_select = 3;
145
146		break;
147	case AUDIO_EXTERN:
148		bktr->audio_mux_select = 1;
149		break;
150	case AUDIO_INTERN:
151		bktr->audio_mux_select = 2;
152		break;
153	case AUDIO_MUTE:
154		bktr->audio_mute_state = TRUE;	/* set mute */
155		break;
156	case AUDIO_UNMUTE:
157		bktr->audio_mute_state = FALSE;	/* clear mute */
158		break;
159	default:
160		printf("%s: audio cmd error %02x\n", bktr_name(bktr),
161		       cmd);
162		return( -1 );
163	}
164
165
166	/* Most cards have a simple audio multiplexer to select the
167	 * audio source. The I/O_GV card has a more advanced multiplexer
168	 * and requires special handling.
169	 */
170        if ( bktr->bt848_card == CARD_IO_GV ) {
171                set_bctv_audio( bktr );
172                return( 0 );
173	}
174
175	/* Proceed with the simpler audio multiplexer code for the majority
176	 * of Bt848 cards.
177	 */
178
179	/*
180	 * Leave the upper bits of the GPIO port alone in case they control
181	 * something like the dbx or teletext chips.  This doesn't guarantee
182	 * success, but follows the rule of least astonishment.
183	 */
184
185	if ( bktr->audio_mute_state == TRUE ) {
186#ifdef BKTR_REVERSEMUTE
187		idx = 0;
188#else
189		idx = 3;
190#endif
191
192		if (bktr->reverse_mute )
193		  idx  = 3;
194		else
195		  idx  = 0;
196
197	}
198	else
199		idx = bktr->audio_mux_select;
200
201	temp = INL(bktr, BKTR_GPIO_DATA) & ~bktr->card.gpio_mux_bits;
202#if defined( AUDIOMUX_DISCOVER )
203	OUTL(bktr, BKTR_GPIO_DATA, temp | (cmd & 0xff));
204	printf("%s: cmd: %d audio mux %x temp %x \n", bktr_name(bktr),
205	       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 */
217void
218temp_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 */
251void
252init_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 */
267int
268set_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
291void
292set_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
342void
343bctv_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
372int
373bctv_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 */
413void 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 */
432void 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    msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */
453    msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0020,0x0001);/* Enable Auto format detection */
454    msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0021,0x0001);/* Auto selection of NICAM/MONO mode */
455  }
456
457
458  /* MSP3410/MSP3415 - European Countries where the fast MSP3410/3415 programming fails */
459  /* SLOW sound scheme */
460  if ( (strncmp("3430G", bktr->msp_version_string, 5) != 0)
461    && (bktr->slow_msp_audio == 1) ){
462    msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0000,0x7300);/* Set volume to 0db gain */
463    msp_dpl_write(bktr, bktr->msp_addr, 0x10, 0x0020,0x0001);/* Enable Auto format detection */
464
465    /* wait for 0.5s max for terrestrial sound autodetection */
466    loops = 10;
467    do {
468      DELAY(100000);
469      auto_detect = msp_dpl_read(bktr, bktr->msp_addr, 0x10, 0x007e);
470      loops++;
471    } while (auto_detect > 0xff && loops < 50);
472    if (bootverbose)printf ("%s: Result of autodetect after %dms: %d\n",
473			    bktr_name(bktr), loops*10, auto_detect);
474
475    /* Now set the audio baseband processing */
476    switch (auto_detect) {
477    case 0:                    /* no TV sound standard detected */
478      break;
479    case 2:                    /* M Dual FM */
480      break;
481    case 3:                    /* B/G Dual FM; German stereo */
482      /* Read the stereo detection value from DSP reg 0x0018 */
483      DELAY(20000);
484      stereo = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x0018);
485      if (bootverbose)printf ("%s: Stereo reg 0x18 a: %d\n",
486			      bktr_name(bktr), stereo);
487      DELAY(20000);
488      stereo = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x0018);
489      if (bootverbose)printf ("%s: Stereo reg 0x18 b: %d\n",
490			      bktr_name(bktr), stereo);
491      DELAY(20000);
492      stereo = msp_dpl_read(bktr, bktr->msp_addr, 0x12, 0x0018);
493      if (bootverbose)printf ("%s: Stereo reg 0x18 c: %d\n",
494			      bktr_name(bktr), stereo);
495      if (stereo > 0x0100 && stereo < 0x8000) { /* Seems to be stereo */
496        msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0008,0x0020);/* Loudspeaker set stereo*/
497        /*
498          set spatial effect strength to 50% enlargement
499          set spatial effect mode b, stereo basewidth enlargment only
500        */
501        msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0005,0x3f28);
502      } else if (stereo > 0x8000) {    /* bilingual mode */
503        if (bootverbose) printf ("%s: Bilingual mode detected\n",
504				 bktr_name(bktr));
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 ("%s: Unknown autodetection result value: %d\n",
536				bktr_name(bktr), auto_detect);
537     }
538
539  }
540
541
542  /* uncomment the following line to enable the MSP34xx 1Khz Tone Generator */
543  /* turn your speaker volume down low before trying this */
544  /* msp_dpl_write(bktr, bktr->msp_addr, 0x12, 0x0014, 0x7f40); */
545}
546
547/* Read the DPL version string */
548void dpl_read_id( bktr_ptr_t bktr ){
549    int rev1=0, rev2=0;
550    rev1 = msp_dpl_read(bktr, bktr->dpl_addr, 0x12, 0x001e);
551    rev2 = msp_dpl_read(bktr, bktr->dpl_addr, 0x12, 0x001f);
552
553    sprintf(bktr->dpl_version_string, "34%02d%c-%c%d",
554      ((rev2>>8)&0xff)-1, (rev1&0xff)+'@', ((rev1>>8)&0xff)+'@', rev2&0x1f);
555}
556
557/* Configure the DPL chip to Auto-detect the audio format */
558void dpl_autodetect( bktr_ptr_t bktr ) {
559
560    /* The following are empiric values tried from the DPL35xx data sheet */
561    msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x000c,0x0320);	/* quasi peak detector source dolby
562								lr 0x03xx; quasi peak detector matrix
563								stereo 0xXX20 */
564    msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0040,0x0060);	/* Surround decoder mode;
565								ADAPTIVE/3D-PANORAMA, that means two
566								speakers and no center speaker, all
567								channels L/R/C/S mixed to L and R */
568    msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0041,0x0620);	/* surround source matrix;I2S2/STEREO*/
569    msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0042,0x1F00);	/* surround delay 31ms max */
570    msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0043,0x0000);	/* automatic surround input balance */
571    msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0044,0x4000);	/* surround spatial effect 50%
572								recommended*/
573    msp_dpl_write(bktr, bktr->dpl_addr, 0x12, 0x0045,0x5400);	/* surround panorama effect 66%
574								recommended with PANORAMA mode
575								in 0x0040 set to panorama */
576}
577
578