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