root/drivers/sound/pas2_card.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. pas_read
  2. pas_write
  3. pas2_msg
  4. pasintr
  5. pas_set_intr
  6. pas_remove_intr
  7. config_pas_hw
  8. detect_pas_hw
  9. attach_pas_card
  10. probe_pas

   1 #define _PAS2_CARD_C_
   2 /*
   3  * sound/pas2_card.c
   4  *
   5  * Detection routine for the Pro Audio Spectrum cards.
   6  *
   7  * Copyright by Hannu Savolainen 1993
   8  *
   9  * Redistribution and use in source and binary forms, with or without
  10  * modification, are permitted provided that the following conditions are
  11  * met: 1. Redistributions of source code must retain the above copyright
  12  * notice, this list of conditions and the following disclaimer. 2.
  13  * Redistributions in binary form must reproduce the above copyright notice,
  14  * this list of conditions and the following disclaimer in the documentation
  15  * and/or other materials provided with the distribution.
  16  *
  17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
  18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  21  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27  * SUCH DAMAGE.
  28  *
  29  */
  30 
  31 #include "sound_config.h"
  32 
  33 #if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_PAS)
  34 
  35 #define DEFINE_TRANSLATIONS
  36 #include "pas.h"
  37 
  38 /*
  39  * The Address Translation code is used to convert I/O register addresses to
  40  * be relative to the given base -register
  41  */
  42 
  43 int             translat_code;
  44 static int      pas_intr_mask = 0;
  45 static int      pas_irq = 0;
  46 
  47 char            pas_model;
  48 static char    *pas_model_names[] =
  49 {"", "Pro AudioSpectrum+", "CDPC", "Pro AudioSpectrum 16", "Pro AudioSpectrum 16D"};
  50 
  51 /*
  52  * pas_read() and pas_write() are equivalents of INB() and OUTB()
  53  */
  54 /*
  55  * These routines perform the I/O address translation required
  56  */
  57 /*
  58  * to support other than the default base address
  59  */
  60 extern void mix_write (unsigned char data, int ioaddr);
  61 
  62 unsigned char
  63 pas_read (int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
  64 {
  65   return INB (ioaddr ^ translat_code);
  66 }
  67 
  68 void
  69 pas_write (unsigned char data, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
  70 {
  71   OUTB (data, ioaddr ^ translat_code);
  72 }
  73 
  74 void
  75 pas2_msg (char *foo)
     /* [previous][next][first][last][top][bottom][index][help] */
  76 {
  77   printk ("    PAS2: %s.\n", foo);
  78 }
  79 
  80 /******************* Begin of the Interrupt Handler ********************/
  81 
  82 void
  83 pasintr (INT_HANDLER_PARMS (irq, dummy))
     /* [previous][next][first][last][top][bottom][index][help] */
  84 {
  85   int             status;
  86 
  87   status = pas_read (INTERRUPT_STATUS);
  88   pas_write (status, INTERRUPT_STATUS);         /*
  89                                                    * Clear interrupt
  90                                                  */
  91 
  92   if (status & I_S_PCM_SAMPLE_BUFFER_IRQ)
  93     {
  94 #ifndef EXCLUDE_AUDIO
  95       pas_pcm_interrupt (status, 1);
  96 #endif
  97       status &= ~I_S_PCM_SAMPLE_BUFFER_IRQ;
  98     }
  99   if (status & I_S_MIDI_IRQ)
 100     {
 101 #ifndef EXCLUDE_MIDI
 102 #ifdef EXCLUDE_PRO_MIDI
 103       pas_midi_interrupt ();
 104 #endif
 105 #endif
 106       status &= ~I_S_MIDI_IRQ;
 107     }
 108 
 109 }
 110 
 111 int
 112 pas_set_intr (int mask)
     /* [previous][next][first][last][top][bottom][index][help] */
 113 {
 114   int             err;
 115 
 116   if (!mask)
 117     return 0;
 118 
 119   if (!pas_intr_mask)
 120     {
 121       if ((err = snd_set_irq_handler (pas_irq, pasintr, "PAS16")) < 0)
 122         return err;
 123     }
 124   pas_intr_mask |= mask;
 125 
 126   pas_write (pas_intr_mask, INTERRUPT_MASK);
 127   return 0;
 128 }
 129 
 130 int
 131 pas_remove_intr (int mask)
     /* [previous][next][first][last][top][bottom][index][help] */
 132 {
 133   if (!mask)
 134     return 0;
 135 
 136   pas_intr_mask &= ~mask;
 137   pas_write (pas_intr_mask, INTERRUPT_MASK);
 138 
 139   if (!pas_intr_mask)
 140     {
 141       snd_release_irq (pas_irq);
 142     }
 143   return 0;
 144 }
 145 
 146 /******************* End of the Interrupt handler **********************/
 147 
 148 /******************* Begin of the Initialization Code ******************/
 149 
 150 int
 151 config_pas_hw (struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 152 {
 153   char            ok = 1;
 154   unsigned        int_ptrs;     /* scsi/sound interrupt pointers */
 155 
 156   pas_irq = hw_config->irq;
 157 
 158   pas_write (0x00, INTERRUPT_MASK);
 159 
 160   pas_write (0x36, SAMPLE_COUNTER_CONTROL);     /*
 161                                                  * Local timer control *
 162                                                  * register
 163                                                  */
 164 
 165   pas_write (0x36, SAMPLE_RATE_TIMER);  /*
 166                                          * Sample rate timer (16 bit)
 167                                          */
 168   pas_write (0, SAMPLE_RATE_TIMER);
 169 
 170   pas_write (0x74, SAMPLE_COUNTER_CONTROL);     /*
 171                                                  * Local timer control *
 172                                                  * register
 173                                                  */
 174 
 175   pas_write (0x74, SAMPLE_BUFFER_COUNTER);      /*
 176                                                  * Sample count register (16
 177                                                  * * bit)
 178                                                  */
 179   pas_write (0, SAMPLE_BUFFER_COUNTER);
 180 
 181   pas_write (F_F_PCM_BUFFER_COUNTER | F_F_PCM_RATE_COUNTER | F_F_MIXER_UNMUTE | 1, FILTER_FREQUENCY);
 182   pas_write (P_C_PCM_DMA_ENABLE | P_C_PCM_MONO | P_C_PCM_DAC_MODE | P_C_MIXER_CROSS_L_TO_L | P_C_MIXER_CROSS_R_TO_R, PCM_CONTROL);
 183   pas_write (S_M_PCM_RESET | S_M_FM_RESET | S_M_SB_RESET | S_M_MIXER_RESET      /*
 184                                                                                  * |
 185                                                                                  * S_M_OPL3_DUAL_MONO
 186                                                                                  */ , SERIAL_MIXER);
 187 
 188   pas_write (I_C_1_BOOT_RESET_ENABLE
 189 #ifdef PAS_JOYSTICK_ENABLE
 190              | I_C_1_JOYSTICK_ENABLE
 191 #endif
 192              ,IO_CONFIGURATION_1);
 193 
 194   if (pas_irq < 0 || pas_irq > 15)
 195     {
 196       printk ("PAS2: Invalid IRQ %d", pas_irq);
 197       ok = 0;
 198     }
 199   else
 200     {
 201       int_ptrs = pas_read (IO_CONFIGURATION_3);
 202       int_ptrs |= I_C_3_PCM_IRQ_translate[pas_irq] & 0xf;
 203       pas_write (int_ptrs, IO_CONFIGURATION_3);
 204       if (!I_C_3_PCM_IRQ_translate[pas_irq])
 205         {
 206           printk ("PAS2: Invalid IRQ %d", pas_irq);
 207           ok = 0;
 208         }
 209     }
 210 
 211   if (hw_config->dma < 0 || hw_config->dma > 7)
 212     {
 213       printk ("PAS2: Invalid DMA selection %d", hw_config->dma);
 214       ok = 0;
 215     }
 216   else
 217     {
 218       pas_write (I_C_2_PCM_DMA_translate[hw_config->dma], IO_CONFIGURATION_2);
 219       if (!I_C_2_PCM_DMA_translate[hw_config->dma])
 220         {
 221           printk ("PAS2: Invalid DMA selection %d", hw_config->dma);
 222           ok = 0;
 223         }
 224     }
 225 
 226   /*
 227      * This fixes the timing problems of the PAS due to the Symphony chipset
 228      * as per Media Vision.  Only define this if your PAS doesn't work correctly.
 229    */
 230 #ifdef SYMPHONY_PAS
 231   OUTB (0x05, 0xa8);
 232   OUTB (0x60, 0xa9);
 233 #endif
 234 
 235 #ifdef BROKEN_BUS_CLOCK
 236   pas_write (S_C_1_PCS_ENABLE | S_C_1_PCS_STEREO | S_C_1_PCS_REALSOUND | S_C_1_FM_EMULATE_CLOCK, SYSTEM_CONFIGURATION_1);
 237 #else
 238   /*
 239    * pas_write(S_C_1_PCS_ENABLE, SYSTEM_CONFIGURATION_1);
 240    */
 241   pas_write (S_C_1_PCS_ENABLE | S_C_1_PCS_STEREO | S_C_1_PCS_REALSOUND, SYSTEM_CONFIGURATION_1);
 242 #endif
 243   pas_write (0x18, SYSTEM_CONFIGURATION_3);     /*
 244                                                  * ???
 245                                                  */
 246 
 247   pas_write (F_F_MIXER_UNMUTE | 0x01, FILTER_FREQUENCY);        /*
 248                                                                  * Sets mute
 249                                                                  * off and *
 250                                                                  * selects
 251                                                                  * filter
 252                                                                  * rate * of
 253                                                                  * 17.897 kHz
 254                                                                  */
 255 #if 1
 256     pas_write (8, PRESCALE_DIVIDER);
 257 #else
 258   if (pas_model == PAS_16 || pas_model == PAS_16D)
 259     pas_write (8, PRESCALE_DIVIDER);
 260   else
 261     pas_write (0, PRESCALE_DIVIDER);
 262 #endif
 263 
 264   mix_write (P_M_MV508_ADDRESS | 5, PARALLEL_MIXER);
 265   mix_write (5, PARALLEL_MIXER);
 266 
 267 #if !defined(EXCLUDE_SB_EMULATION) || !defined(EXCLUDE_SB)
 268 
 269   {
 270     struct address_info *sb_config;
 271 
 272     if ((sb_config = sound_getconf (SNDCARD_SB)))
 273       {
 274         unsigned char   irq_dma;
 275 
 276         /*
 277          * Turn on Sound Blaster compatibility
 278          */
 279         /*
 280          * bit 1 = SB emulation
 281          */
 282         /*
 283          * bit 0 = MPU401 emulation (CDPC only :-( )
 284          */
 285         pas_write (0x02, COMPATIBILITY_ENABLE);
 286 
 287         /*
 288          * "Emulation address"
 289          */
 290         pas_write ((sb_config->io_base >> 4) & 0x0f, EMULATION_ADDRESS);
 291 
 292         if (!E_C_SB_DMA_translate[sb_config->dma])
 293           printk ("\n\nPAS16 Warning: Invalid SB DMA %d\n\n",
 294                   sb_config->dma);
 295 
 296         if (!E_C_SB_IRQ_translate[sb_config->irq])
 297           printk ("\n\nPAS16 Warning: Invalid SB IRQ %d\n\n",
 298                   sb_config->irq);
 299 
 300         irq_dma = E_C_SB_DMA_translate[sb_config->dma] |
 301           E_C_SB_IRQ_translate[sb_config->irq];
 302 
 303         pas_write (irq_dma, EMULATION_CONFIGURATION);
 304       }
 305   }
 306 #else
 307   pas_write (0x00, COMPATIBILITY_ENABLE);
 308 #endif
 309 
 310   if (!ok)
 311     pas2_msg ("Driver not enabled");
 312 
 313   return ok;
 314 }
 315 
 316 int
 317 detect_pas_hw (struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 318 {
 319   unsigned char   board_id, foo;
 320 
 321   /*
 322    * WARNING: Setting an option like W:1 or so that disables warm boot reset
 323    * of the card will screw up this detect code something fierce. Adding code
 324    * to handle this means possibly interfering with other cards on the bus if
 325    * you have something on base port 0x388. SO be forewarned.
 326    */
 327 
 328   OUTB (0xBC, MASTER_DECODE);   /*
 329                                  * Talk to first board
 330                                  */
 331   OUTB (hw_config->io_base >> 2, MASTER_DECODE);        /*
 332                                                          * Set base address
 333                                                          */
 334   translat_code = PAS_DEFAULT_BASE ^ hw_config->io_base;
 335   pas_write (1, WAIT_STATE);    /*
 336                                  * One wait-state
 337                                  */
 338 
 339   board_id = pas_read (INTERRUPT_MASK);
 340 
 341   if (board_id == 0xff)
 342     return 0;
 343 
 344   /*
 345    * We probably have a PAS-series board, now check for a PAS2-series board
 346    * by trying to change the board revision bits. PAS2-series hardware won't
 347    * let you do this - the bits are read-only.
 348    */
 349 
 350   foo = board_id ^ 0xe0;
 351 
 352   pas_write (foo, INTERRUPT_MASK);
 353   foo = INB (INTERRUPT_MASK);
 354   pas_write (board_id, INTERRUPT_MASK);
 355 
 356   if (board_id != foo)          /*
 357                                  * Not a PAS2
 358                                  */
 359     return 0;
 360 
 361   pas_model = pas_read (CHIP_REV);
 362 
 363   return pas_model;
 364 }
 365 
 366 long
 367 attach_pas_card (long mem_start, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 368 {
 369   pas_irq = hw_config->irq;
 370 
 371   if (detect_pas_hw (hw_config))
 372     {
 373 
 374       if ((pas_model = pas_read (CHIP_REV)))
 375         {
 376           printk (" <%s rev %d>", pas_model_names[(int) pas_model], pas_read (BOARD_REV_ID));
 377         }
 378 
 379       if (config_pas_hw (hw_config))
 380         {
 381 
 382 #ifndef EXCLUDE_AUDIO
 383           mem_start = pas_pcm_init (mem_start, hw_config);
 384 #endif
 385 
 386 #if !defined(EXCLUDE_SB_EMULATION) && !defined(EXCLUDE_SB)
 387 
 388           sb_dsp_disable_midi ();       /*
 389                                          * The SB emulation don't support *
 390                                          * midi
 391                                          */
 392 #endif
 393 
 394 #ifndef EXCLUDE_YM3812
 395           enable_opl3_mode (0x388, 0x38a, 0);
 396 #endif
 397 
 398 #ifndef EXCLUDE_MIDI
 399 #ifdef EXCLUDE_PRO_MIDI
 400           mem_start = pas_midi_init (mem_start);
 401 #endif
 402 #endif
 403 
 404           pas_init_mixer ();
 405         }
 406     }
 407 
 408   return mem_start;
 409 }
 410 
 411 int
 412 probe_pas (struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 413 {
 414   return detect_pas_hw (hw_config);
 415 }
 416 
 417 #endif

/* [previous][next][first][last][top][bottom][index][help] */