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. sound_unload_drivers
  4. sndtable_probe
  5. sndtable_init_card
  6. sndtable_get_cardcount
  7. sndtable_identify_card
  8. sound_setup
  9. sound_getconf
  10. 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 = num_sound_drivers;
  39 
  40   for (i = 0; i < n; 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 = num_sound_cards;
  53   int             drv;
  54 
  55   printk ("Sound initialization started\n");
  56 
  57 /*
  58  * Check the number of cards actually defined in the table
  59  */
  60 
  61   for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
  62     num_sound_cards = i + 1;
  63 
  64   for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
  65     if (snd_installed_cards[i].enabled)
  66       {
  67         snd_installed_cards[i].for_driver_use = NULL;
  68 
  69         if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
  70           snd_installed_cards[i].enabled = 0;   /*
  71                                                  * Mark as not detected
  72                                                  */
  73         else if (sound_drivers[drv].probe (&snd_installed_cards[i].config))
  74           {
  75             printk ("snd%d",
  76                     snd_installed_cards[i].card_type);
  77 
  78             mem_start = sound_drivers[drv].attach (mem_start, &snd_installed_cards[i].config);
  79             printk (" at 0x%x irq %d drq %d",
  80                     snd_installed_cards[i].config.io_base,
  81                     snd_installed_cards[i].config.irq,
  82                     snd_installed_cards[i].config.dma);
  83             if (snd_installed_cards[i].config.dma2 != -1)
  84               printk (",%d\n",
  85                       snd_installed_cards[i].config.dma2);
  86             else
  87               printk ("\n");
  88           }
  89         else
  90           snd_installed_cards[i].enabled = 0;   /*
  91                                                  * Mark as not detected
  92                                                  */
  93       }
  94 
  95   printk ("Sound initialization complete\n");
  96   return mem_start;
  97 }
  98 
  99 void
 100 sound_unload_drivers (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 101 {
 102   int             i, n = num_sound_cards;
 103   int             drv;
 104 
 105   printk ("Sound unload started\n");
 106 
 107   for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
 108     if (snd_installed_cards[i].enabled)
 109       if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) != -1)
 110         if (sound_drivers[drv].unload)
 111           sound_drivers[drv].unload (&snd_installed_cards[i].config);
 112 
 113   printk ("Sound unload complete\n");
 114 }
 115 
 116 int
 117 sndtable_probe (int unit, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 118 {
 119   int             i, sel = -1, n = num_sound_cards;
 120 
 121   if (!unit)
 122     return TRUE;
 123 
 124   for (i = 0; i < n && sel == -1 && snd_installed_cards[i].card_type; i++)
 125     if (snd_installed_cards[i].enabled)
 126       if (snd_installed_cards[i].card_type == unit)
 127         sel = i;
 128 
 129   if (sel == -1 && num_sound_cards < max_sound_cards)
 130     {
 131       int             i;
 132 
 133       i = sel = (num_sound_cards++);
 134 
 135       snd_installed_cards[sel].card_type = unit;
 136       snd_installed_cards[sel].enabled = 1;
 137     }
 138 
 139   if (sel != -1)
 140     {
 141       int             drv;
 142 
 143       snd_installed_cards[sel].for_driver_use = NULL;
 144       snd_installed_cards[sel].config.io_base = hw_config->io_base;
 145       snd_installed_cards[sel].config.irq = hw_config->irq;
 146       snd_installed_cards[sel].config.dma = hw_config->dma;
 147       snd_installed_cards[sel].config.dma2 = hw_config->dma2;
 148       if ((drv = snd_find_driver (snd_installed_cards[sel].card_type)) == -1)
 149         {
 150           snd_installed_cards[sel].enabled = 0;
 151         }
 152       else if (sound_drivers[drv].probe (hw_config))
 153         return TRUE;
 154 
 155       snd_installed_cards[sel].enabled = 0;     /*
 156                                                  * Mark as not detected
 157                                                  */
 158       return FALSE;
 159     }
 160 
 161   return FALSE;
 162 }
 163 
 164 int
 165 sndtable_init_card (int unit, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 166 {
 167   int             i, n = num_sound_cards;
 168 
 169   DDB (printk ("sndtable_init_card(%d) entered\n", unit));
 170 
 171   if (!unit)
 172     {
 173       if (sndtable_init (0) != 0)
 174         panic ("sound: Invalid memory allocation\n");
 175       return TRUE;
 176     }
 177 
 178   for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
 179     if (snd_installed_cards[i].card_type == unit)
 180       {
 181         int             drv;
 182 
 183         snd_installed_cards[i].config.io_base = hw_config->io_base;
 184         snd_installed_cards[i].config.irq = hw_config->irq;
 185         snd_installed_cards[i].config.dma = hw_config->dma;
 186         snd_installed_cards[i].config.dma2 = hw_config->dma2;
 187 
 188         if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
 189           snd_installed_cards[i].enabled = 0;   /*
 190                                                  * Mark as not detected
 191                                                  */
 192         else
 193           {
 194 
 195             DDB (printk ("Located card - calling attach routine\n"));
 196             printk ("snd%d", unit);
 197             if (sound_drivers[drv].attach (0, hw_config) != 0)
 198               panic ("sound: Invalid memory allocation\n");
 199 
 200             DDB (printk ("attach routine finished\n"));
 201             printk (" at 0x%x irq %d drq %d",
 202                     snd_installed_cards[i].config.io_base,
 203                     snd_installed_cards[i].config.irq,
 204                     snd_installed_cards[i].config.dma);
 205             if (snd_installed_cards[i].config.dma2 != -1)
 206               printk (",%d\n",
 207                       snd_installed_cards[i].config.dma2);
 208             else
 209               printk ("\n");
 210           }
 211         return TRUE;
 212       }
 213 
 214   printk ("sndtable_init_card: No card defined with type=%d, num cards: %d\n",
 215           unit, num_sound_cards);
 216   return FALSE;
 217 }
 218 
 219 int
 220 sndtable_get_cardcount (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 221 {
 222   return num_audiodevs + num_mixers + num_synths + num_midis;
 223 }
 224 
 225 int
 226 sndtable_identify_card (char *name)
     /* [previous][next][first][last][top][bottom][index][help] */
 227 {
 228   int             i, n = num_sound_drivers;
 229 
 230   if (name == NULL)
 231     return 0;
 232 
 233   for (i = 0; i < n; i++)
 234     if (sound_drivers[i].driver_id != NULL)
 235       {
 236         char           *id = sound_drivers[i].driver_id;
 237         int             j;
 238 
 239         for (j = 0; j < 80 && name[j] == id[j]; j++)
 240           if (id[j] == 0 && name[j] == 0)       /* Match */
 241             return sound_drivers[i].card_type;
 242       }
 243 
 244   return 0;
 245 }
 246 
 247 void
 248 sound_setup (char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 249 {
 250   int             i, n = num_sound_cards;
 251 
 252   /*
 253      * First disable all drivers
 254    */
 255 
 256   for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
 257     snd_installed_cards[i].enabled = 0;
 258 
 259   if (ints[0] == 0 || ints[1] == 0)
 260     return;
 261   /*
 262      * Then enable them one by time
 263    */
 264 
 265   for (i = 1; i <= ints[0]; i++)
 266     {
 267       int             card_type, ioaddr, irq, dma, ptr, j;
 268       unsigned int    val;
 269 
 270       val = (unsigned int) ints[i];
 271 
 272       card_type = (val & 0x0ff00000) >> 20;
 273 
 274       if (card_type > 127)
 275         {
 276           /*
 277            * Add any future extensions here
 278            */
 279           return;
 280         }
 281 
 282       ioaddr = (val & 0x000fff00) >> 8;
 283       irq = (val & 0x000000f0) >> 4;
 284       dma = (val & 0x0000000f);
 285 
 286       ptr = -1;
 287       for (j = 0; j < n && ptr == -1; j++)
 288         if (snd_installed_cards[j].card_type == card_type &&
 289             !snd_installed_cards[j].enabled)    /*
 290                                                  * Not already found
 291                                                  */
 292           ptr = j;
 293 
 294       if (ptr == -1)
 295         printk ("Sound: Invalid setup parameter 0x%08x\n", val);
 296       else
 297         {
 298           snd_installed_cards[ptr].enabled = 1;
 299           snd_installed_cards[ptr].config.io_base = ioaddr;
 300           snd_installed_cards[ptr].config.irq = irq;
 301           snd_installed_cards[ptr].config.dma = dma;
 302           snd_installed_cards[ptr].config.dma2 = -1;
 303         }
 304     }
 305 }
 306 
 307 
 308 struct address_info *
 309 sound_getconf (int card_type)
     /* [previous][next][first][last][top][bottom][index][help] */
 310 {
 311   int             j, ptr;
 312   int             n = num_sound_cards;
 313 
 314   ptr = -1;
 315   for (j = 0; j < n && ptr == -1 && snd_installed_cards[j].card_type; j++)
 316     if (snd_installed_cards[j].card_type == card_type)
 317       ptr = j;
 318 
 319   if (ptr == -1)
 320     return (struct address_info *) NULL;
 321 
 322   return &snd_installed_cards[ptr].config;
 323 }
 324 
 325 #else
 326 
 327 void
 328 sound_setup (char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 329 {
 330 }
 331 
 332 #endif

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