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