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

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