The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/video/bktr/bktr_audio.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 372a2141b45d2e3f4ee49dff93b1d608


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.