root/drivers/sound/dev_table.c

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

DEFINITIONS

This source file includes following definitions.
  1. snd_find_driver
  2. sndtable_init
  3. sndtable_probe
  4. sndtable_init_card
  5. sndtable_get_cardcount
  6. sound_setup
  7. sound_chconf
  8. sound_getconf
  9. sound_setup

   1 /*
   2  * sound/dev_table.c
   3  *
   4  * Device call tables.
   5  *
   6  * Copyright by Hannu Savolainen 1993
   7  *
   8  * Redistribution and use in source and binary forms, with or without
   9  * modification, are permitted provided that the following conditions are
  10  * met: 1. Redistributions of source code must retain the above copyright
  11  * notice, this list of conditions and the following disclaimer. 2.
  12  * Redistributions in binary form must reproduce the above copyright notice,
  13  * this list of conditions and the following disclaimer in the documentation
  14  * and/or other materials provided with the distribution.
  15  *
  16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
  17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26  * SUCH DAMAGE.
  27  *
  28  */
  29 
  30 #define _DEV_TABLE_C_
  31 #include "sound_config.h"
  32 
  33 #ifdef CONFIGURE_SOUNDCARD
  34 
  35 int
  36 snd_find_driver (int type)
     /* [previous][next][first][last][top][bottom][index][help] */
  37 {
  38   int             i, n = sizeof (sound_drivers) / sizeof (struct driver_info);
  39 
  40   for (i = 0; i < (n - 1); i++)
  41     if (sound_drivers[i].card_type == type)
  42       return i;
  43 
  44   return -1;                    /*
  45                                  * Not found
  46                                  */
  47 }
  48 
  49 long
  50 sndtable_init (long mem_start)
     /* [previous][next][first][last][top][bottom][index][help] */
  51 {
  52   int             i, n = sizeof (snd_installed_cards) / sizeof (struct card_info);
  53   int             drv;
  54 
  55   for (i = 0; i < (n - 1); i++)
  56     if (snd_installed_cards[i].enabled)
  57       if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
  58         snd_installed_cards[i].enabled = 0;     /*
  59                                                  * Mark as not detected
  60                                                  */
  61       else if (sound_drivers[drv].probe (&snd_installed_cards[i].config))
  62         {
  63 #ifndef SHORT_BANNERS
  64           printk ("snd%d",
  65                   snd_installed_cards[i].card_type);
  66 #endif
  67 
  68           mem_start = sound_drivers[drv].attach (mem_start, &snd_installed_cards[i].config);
  69 #ifndef SHORT_BANNERS
  70           printk (" at 0x%x irq %d drq %d\n",
  71                   snd_installed_cards[i].config.io_base,
  72                   snd_installed_cards[i].config.irq,
  73                   snd_installed_cards[i].config.dma);
  74 #endif
  75         }
  76       else
  77         snd_installed_cards[i].enabled = 0;     /*
  78                                                  * Mark as not detected
  79                                                  */
  80   return mem_start;
  81 }
  82 
  83 int
  84 sndtable_probe (int unit, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
  85   {
  86     int             i, n = sizeof (snd_installed_cards) / sizeof (struct card_info);
  87 
  88     if (!unit)
  89       return TRUE;
  90 
  91     for (i = 0; i < (n - 1); i++)
  92       if (snd_installed_cards[i].enabled)
  93         if (snd_installed_cards[i].card_type == unit)
  94           {
  95             int             drv;
  96 
  97             snd_installed_cards[i].config.io_base = hw_config->io_base;
  98             snd_installed_cards[i].config.irq = hw_config->irq;
  99             snd_installed_cards[i].config.dma = hw_config->dma;
 100             if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
 101               snd_installed_cards[i].enabled = 0;       /*
 102                                                          * Mark as not
 103                                                          * detected
 104                                                          */
 105             else if (sound_drivers[drv].probe (hw_config))
 106               return 1;
 107             snd_installed_cards[i].enabled = 0; /*
 108                                                  * Mark as not detected
 109                                                  */
 110             return 0;
 111           }
 112 
 113     return FALSE;
 114   }
 115 
 116 int
 117 sndtable_init_card (int unit, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 118   {
 119     int             i, n = sizeof (snd_installed_cards) / sizeof (struct card_info);
 120 
 121     if (!unit)
 122       {
 123         if (sndtable_init (0) != 0)
 124           panic ("snd: Invalid memory allocation\n");
 125         return TRUE;
 126       }
 127 
 128     for (i = 0; i < (n - 1); i++)
 129       if (snd_installed_cards[i].card_type == unit)
 130         {
 131           int             drv;
 132 
 133           snd_installed_cards[i].config.io_base = hw_config->io_base;
 134           snd_installed_cards[i].config.irq = hw_config->irq;
 135           snd_installed_cards[i].config.dma = hw_config->dma;
 136 
 137           if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
 138             snd_installed_cards[i].enabled = 0; /*
 139                                                  * Mark as not detected
 140                                                  */
 141           else if (sound_drivers[drv].attach (0, hw_config) != 0)
 142             panic ("snd#: Invalid memory allocation\n");
 143           return TRUE;
 144         }
 145 
 146     return FALSE;
 147   }
 148 
 149 int
 150 sndtable_get_cardcount (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 151 {
 152   return num_audiodevs + num_mixers + num_synths + num_midis;
 153 }
 154 
 155 #ifdef linux
 156 void
 157 sound_setup (char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 158 {
 159   int             i, n = sizeof (snd_installed_cards) / sizeof (struct card_info);
 160 
 161   /*
 162  * First disable all drivers
 163  */
 164 
 165   for (i = 0; i < n; i++)
 166     snd_installed_cards[i].enabled = 0;
 167 
 168   if (ints[0] == 0 || ints[1] == 0)
 169     return;
 170   /*
 171  * Then enable them one by time
 172  */
 173 
 174   for (i = 1; i <= ints[0]; i++)
 175     {
 176       int             card_type, ioaddr, irq, dma, ptr, j;
 177       unsigned int    val;
 178 
 179       val = (unsigned int) ints[i];
 180 
 181       card_type = (val & 0x0ff00000) >> 20;
 182 
 183       if (card_type > 127)
 184         {
 185           /*
 186            * Add any future extensions here
 187            */
 188           return;
 189         }
 190 
 191       ioaddr = (val & 0x000fff00) >> 8;
 192       irq = (val & 0x000000f0) >> 4;
 193       dma = (val & 0x0000000f);
 194 
 195       ptr = -1;
 196       for (j = 0; j < n && ptr == -1; j++)
 197         if (snd_installed_cards[j].card_type == card_type &&
 198             !snd_installed_cards[j].enabled)    /*
 199                                                  * Not already found
 200                                                  */
 201           ptr = j;
 202 
 203       if (ptr == -1)
 204         printk ("Sound: Invalid setup parameter 0x%08x\n", val);
 205       else
 206         {
 207           snd_installed_cards[ptr].enabled = 1;
 208           snd_installed_cards[ptr].config.io_base = ioaddr;
 209           snd_installed_cards[ptr].config.irq = irq;
 210           snd_installed_cards[ptr].config.dma = dma;
 211         }
 212     }
 213 }
 214 
 215 #else
 216 void
 217 sound_chconf (int card_type, int ioaddr, int irq, int dma)
     /* [previous][next][first][last][top][bottom][index][help] */
 218 {
 219   int             i, n = sizeof (snd_installed_cards) / sizeof (struct card_info);
 220 
 221   int             ptr, j;
 222 
 223   ptr = -1;
 224   for (j = 0; j < n && ptr == -1; j++)
 225     if (snd_installed_cards[j].card_type == card_type &&
 226         !snd_installed_cards[j].enabled)        /*
 227                                                  * Not already found
 228                                                  */
 229       ptr = j;
 230 
 231   if (ptr != -1)
 232     {
 233       snd_installed_cards[ptr].enabled = 1;
 234       if (ioaddr)
 235         snd_installed_cards[ptr].config.io_base = ioaddr;
 236       if (irq)
 237         snd_installed_cards[ptr].config.irq = irq;
 238       if (dma)
 239         snd_installed_cards[ptr].config.dma = dma;
 240     }
 241 }
 242 
 243 #endif
 244 
 245 struct address_info *
 246 sound_getconf (int card_type)
     /* [previous][next][first][last][top][bottom][index][help] */
 247 {
 248   int             j, ptr;
 249   int             n = sizeof (snd_installed_cards) / sizeof (struct card_info);
 250 
 251   ptr = -1;
 252   for (j = 0; j < n && ptr == -1; j++)
 253     if (snd_installed_cards[j].card_type == card_type)
 254       ptr = j;
 255 
 256   if (ptr == -1)
 257     return (struct address_info *) NULL;
 258 
 259   return &snd_installed_cards[ptr].config;
 260 }
 261 
 262 #else
 263 
 264 void
 265 sound_setup (char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 266 {
 267 }
 268 
 269 #endif

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