root/drivers/sound/gus_card.c

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

DEFINITIONS

This source file includes following definitions.
  1. attach_gus_card
  2. probe_gus
  3. unload_gus
  4. gusintr
  5. probe_gus_db16
  6. attach_gus_db16
  7. unload_gus_db16

   1 /*
   2  * sound/gus_card.c
   3  *
   4  * Detection routine for the Gravis Ultrasound.
   5  */
   6 /*
   7  * Copyright by Hannu Savolainen 1993-1996
   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 #include <linux/config.h>
  30 
  31 
  32 #include "sound_config.h"
  33 
  34 #if defined(CONFIG_GUS)
  35 
  36 #include "gus_hw.h"
  37 
  38 void            gusintr (int irq, void *dev_id, struct pt_regs *dummy);
  39 
  40 int             gus_base, gus_irq, gus_dma;
  41 extern int      gus_wave_volume;
  42 extern int      gus_pcm_volume;
  43 extern int      have_gus_max;
  44 
  45 int            *gus_osp;
  46 
  47 long
  48 attach_gus_card (long mem_start, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50   int             io_addr;
  51 
  52   gus_osp = hw_config->osp;
  53   snd_set_irq_handler (hw_config->irq, gusintr, "Gravis Ultrasound", hw_config->osp);
  54 
  55   if (gus_wave_detect (hw_config->io_base))     /*
  56                                                  * Try first the default
  57                                                  */
  58     {
  59       mem_start = gus_wave_init (mem_start, hw_config);
  60 
  61       request_region (hw_config->io_base, 16, "GUS");
  62       request_region (hw_config->io_base + 0x100, 12, "GUS");   /* 0x10c-> is MAX */
  63 
  64       if (sound_alloc_dma (hw_config->dma, "GUS"))
  65         printk ("gus_card.c: Can't allocate DMA channel\n");
  66       if (hw_config->dma2 != -1 && hw_config->dma2 != hw_config->dma)
  67         if (sound_alloc_dma (hw_config->dma2, "GUS(2)"))
  68           printk ("gus_card.c: Can't allocate DMA channel2\n");
  69 #ifdef CONFIG_MIDI
  70       mem_start = gus_midi_init (mem_start);
  71 #endif
  72       return mem_start;
  73     }
  74 
  75 #ifndef EXCLUDE_GUS_IODETECT
  76 
  77   /*
  78    * Look at the possible base addresses (0x2X0, X=1, 2, 3, 4, 5, 6)
  79    */
  80 
  81   for (io_addr = 0x210; io_addr <= 0x260; io_addr += 0x10)
  82     if (io_addr != hw_config->io_base)  /*
  83                                          * Already tested
  84                                          */
  85       if (gus_wave_detect (io_addr))
  86         {
  87           hw_config->io_base = io_addr;
  88 
  89           printk (" WARNING! GUS found at %x, config was %x ", io_addr, hw_config->io_base);
  90           mem_start = gus_wave_init (mem_start, hw_config);
  91           request_region (io_addr, 16, "GUS");
  92           request_region (io_addr + 0x100, 12, "GUS");  /* 0x10c-> is MAX */
  93           if (sound_alloc_dma (hw_config->dma, "GUS"))
  94             printk ("gus_card.c: Can't allocate DMA channel\n");
  95           if (hw_config->dma2 != -1 && hw_config->dma2 != hw_config->dma)
  96             if (sound_alloc_dma (hw_config->dma2, "GUS"))
  97               printk ("gus_card.c: Can't allocate DMA channel2\n");
  98 #ifdef CONFIG_MIDI
  99           mem_start = gus_midi_init (mem_start);
 100 #endif
 101           return mem_start;
 102         }
 103 
 104 #endif
 105 
 106   return mem_start;             /*
 107                                  * Not detected
 108                                  */
 109 }
 110 
 111 int
 112 probe_gus (struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 113 {
 114   int             io_addr, irq;
 115 
 116   gus_osp = hw_config->osp;
 117 
 118   irq = hw_config->irq;
 119 
 120   if (hw_config->card_subtype == 0)     /* GUS/MAX/ACE */
 121     if (irq != 3 && irq != 5 && irq != 7 && irq != 9 &&
 122         irq != 11 && irq != 12 && irq != 15)
 123       {
 124         printk ("GUS: Unsupported IRQ %d\n", irq);
 125         return 0;
 126       }
 127 
 128   if (!check_region (hw_config->io_base, 16))
 129     if (!check_region (hw_config->io_base + 0x100, 16))
 130       if (gus_wave_detect (hw_config->io_base))
 131         return 1;
 132 
 133 #ifndef EXCLUDE_GUS_IODETECT
 134 
 135   /*
 136    * Look at the possible base addresses (0x2X0, X=1, 2, 3, 4, 5, 6)
 137    */
 138 
 139   for (io_addr = 0x210; io_addr <= 0x260; io_addr += 0x10)
 140     if (io_addr != hw_config->io_base)  /*
 141                                          * Already tested
 142                                          */
 143       if (!check_region (io_addr, 16))
 144         if (!check_region (io_addr + 0x100, 16))
 145           if (gus_wave_detect (io_addr))
 146             {
 147               hw_config->io_base = io_addr;
 148               return 1;
 149             }
 150 
 151 #endif
 152 
 153   return 0;
 154 }
 155 
 156 void
 157 unload_gus (struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 158 {
 159   DDB (printk ("unload_gus(%x)\n", hw_config->io_base));
 160 
 161   gus_wave_unload ();
 162 
 163   release_region (hw_config->io_base, 16);
 164   release_region (hw_config->io_base + 0x100, 12);      /* 0x10c-> is MAX */
 165   snd_release_irq (hw_config->irq);
 166 
 167   sound_free_dma (hw_config->dma);
 168 
 169   if (hw_config->dma2 != -1 && hw_config->dma2 != hw_config->dma)
 170     sound_free_dma (hw_config->dma2);
 171 }
 172 
 173 void
 174 gusintr (int irq, void *dev_id, struct pt_regs *dummy)
     /* [previous][next][first][last][top][bottom][index][help] */
 175 {
 176   unsigned char   src;
 177   extern int      gus_timer_enabled;
 178 
 179   sti ();
 180 
 181 #ifdef CONFIG_GUSMAX
 182   if (have_gus_max)
 183     ad1848_interrupt (irq, NULL, NULL);
 184 #endif
 185 
 186   while (1)
 187     {
 188       if (!(src = inb (u_IrqStatus)))
 189         return;
 190 
 191       if (src & DMA_TC_IRQ)
 192         {
 193           guswave_dma_irq ();
 194         }
 195 
 196       if (src & (MIDI_TX_IRQ | MIDI_RX_IRQ))
 197         {
 198 #ifdef CONFIG_MIDI
 199           gus_midi_interrupt (0);
 200 #endif
 201         }
 202 
 203       if (src & (GF1_TIMER1_IRQ | GF1_TIMER2_IRQ))
 204         {
 205 #ifdef CONFIG_SEQUENCER
 206           if (gus_timer_enabled)
 207             {
 208               sound_timer_interrupt ();
 209             }
 210 
 211           gus_write8 (0x45, 0); /* Ack IRQ */
 212           gus_timer_command (4, 0x80);  /* Reset IRQ flags */
 213 
 214 #else
 215           gus_write8 (0x45, 0); /* Stop timers */
 216 #endif
 217         }
 218 
 219       if (src & (WAVETABLE_IRQ | ENVELOPE_IRQ))
 220         {
 221           gus_voice_irq ();
 222         }
 223     }
 224 }
 225 
 226 #endif
 227 
 228 /*
 229  * Some extra code for the 16 bit sampling option
 230  */
 231 #if defined(CONFIG_GUS16)
 232 
 233 int
 234 probe_gus_db16 (struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 235 {
 236   return ad1848_detect (hw_config->io_base, NULL, hw_config->osp);
 237 }
 238 
 239 long
 240 attach_gus_db16 (long mem_start, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 241 {
 242 #ifdef CONFIG_GUS
 243   gus_pcm_volume = 100;
 244   gus_wave_volume = 90;
 245 #endif
 246 
 247   ad1848_init ("GUS 16 bit sampling", hw_config->io_base,
 248                hw_config->irq,
 249                hw_config->dma,
 250                hw_config->dma, 0,
 251                hw_config->osp);
 252   return mem_start;
 253 }
 254 
 255 void
 256 unload_gus_db16 (struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 257 {
 258 
 259   ad1848_unload (hw_config->io_base,
 260                  hw_config->irq,
 261                  hw_config->dma,
 262                  hw_config->dma, 0);
 263 }
 264 #endif

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