LCOV - code coverage report
Current view: top level - dev/pci/bktr - bktr_audio.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 182 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 11 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.13