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