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. set_pas_irq
  6. pas_set_intr
  7. pas_remove_intr
  8. config_pas_hw
  9. detect_pas_hw
  10. attach_pas_card
  11. probe_pas

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

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