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