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