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. start_services
  3. start_cards
  4. sndtable_init
  5. sound_unload_drivers
  6. sound_unload_driver
  7. sndtable_probe
  8. sndtable_init_card
  9. sndtable_get_cardcount
  10. sndtable_identify_card
  11. sound_setup
  12. sound_getconf

   1 /*
   2  * sound/dev_table.c
   3  *
   4  * Device call tables.
   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 #define _DEV_TABLE_C_
  33 #include "sound_config.h"
  34 
  35 int             sound_started = 0;
  36 
  37 int             sndtable_get_cardcount (void);
  38 
  39 int
  40 snd_find_driver (int type)
     /* [previous][next][first][last][top][bottom][index][help] */
  41 {
  42   int             i, n = num_sound_drivers;
  43 
  44   for (i = 0; i < n; i++)
  45     if (sound_drivers[i].card_type == type)
  46       return i;
  47 
  48   return -1;
  49 }
  50 
  51 static long
  52 start_services (long mem_start)
     /* [previous][next][first][last][top][bottom][index][help] */
  53 {
  54   int             soundcards_installed;
  55 
  56   if (!(soundcards_installed = sndtable_get_cardcount ()))
  57     return mem_start;           /* No cards detected */
  58 
  59 #ifdef CONFIG_AUDIO
  60   if (num_audiodevs)            /* Audio devices present */
  61     {
  62       DMAbuf_init (0);
  63       audio_init (0);
  64     }
  65 #endif
  66 
  67 #ifdef CONFIG_MIDI
  68   if (num_midis)
  69     MIDIbuf_init (0);
  70 #endif
  71 
  72 #ifdef CONFIG_SEQUENCER
  73   if (num_midis + num_synths)
  74     sequencer_init (0);
  75 #endif
  76   return mem_start;
  77 }
  78 
  79 static long
  80 start_cards (long mem_start)
     /* [previous][next][first][last][top][bottom][index][help] */
  81 {
  82   int             i, n = num_sound_cards;
  83   int             drv;
  84 
  85   sound_started = 1;
  86   if (trace_init)
  87     printk ("Sound initialization started\n");
  88 
  89 /*
  90  * Check the number of cards actually defined in the table
  91  */
  92 
  93   for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
  94     num_sound_cards = i + 1;
  95 
  96   for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
  97     if (snd_installed_cards[i].enabled)
  98       {
  99         snd_installed_cards[i].for_driver_use = NULL;
 100 
 101         if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
 102           {
 103             snd_installed_cards[i].enabled = 0;         /*
 104                                                          * Mark as not detected
 105                                                          */
 106             continue;
 107           }
 108 
 109         snd_installed_cards[i].config.card_subtype =
 110           sound_drivers[drv].card_subtype;
 111 
 112         if (sound_drivers[drv].probe (&snd_installed_cards[i].config))
 113           {
 114 
 115             mem_start = sound_drivers[drv].attach (mem_start, &snd_installed_cards[i].config);
 116 
 117           }
 118         else
 119           snd_installed_cards[i].enabled = 0;   /*
 120                                                  * Mark as not detected
 121                                                  */
 122       }
 123 
 124   if (trace_init)
 125     printk ("Sound initialization complete\n");
 126   return mem_start;
 127 }
 128 
 129 long
 130 sndtable_init (long mem_start)
     /* [previous][next][first][last][top][bottom][index][help] */
 131 {
 132   return start_cards (mem_start);
 133 }
 134 
 135 void
 136 sound_unload_drivers (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 137 {
 138   int             i, n = num_sound_cards;
 139   int             drv;
 140 
 141   if (!sound_started)
 142     return;
 143 
 144   if (trace_init)
 145     printk ("Sound unload started\n");
 146 
 147   for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
 148     if (snd_installed_cards[i].enabled)
 149       if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) != -1)
 150         if (sound_drivers[drv].unload)
 151           {
 152             sound_drivers[drv].unload (&snd_installed_cards[i].config);
 153             snd_installed_cards[i].enabled = 0;
 154           }
 155 
 156   if (trace_init)
 157     printk ("Sound unload complete\n");
 158 }
 159 
 160 void
 161 sound_unload_driver (int type)
     /* [previous][next][first][last][top][bottom][index][help] */
 162 {
 163   int             i, drv = -1, n = num_sound_cards;
 164 
 165   unsigned long   flags;
 166 
 167   DDB (printk ("unload driver %d: ", type));
 168 
 169   for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
 170     if (snd_installed_cards[i].card_type == type)
 171       {
 172         if (snd_installed_cards[i].enabled)
 173           {
 174             if ((drv = snd_find_driver (type)) != -1)
 175               {
 176                 if (sound_drivers[drv].unload)
 177                   {
 178                     sound_drivers[drv].unload (&snd_installed_cards[i].config);
 179                     snd_installed_cards[i].enabled = 0;
 180                   }
 181               }
 182           }
 183       }
 184 
 185   save_flags (flags);
 186   cli ();
 187 
 188   restore_flags (flags);
 189 
 190 }
 191 
 192 
 193 int
 194 sndtable_probe (int unit, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 195 {
 196   int             i, sel = -1, n = num_sound_cards;
 197 
 198   DDB (printk ("sndtable_probe(%d)\n", unit));
 199 
 200   if (!unit)
 201     return TRUE;
 202 
 203   sound_started = 1;
 204 
 205   for (i = 0; i < n && sel == -1 && snd_installed_cards[i].card_type; i++)
 206     if (snd_installed_cards[i].enabled)
 207       if (snd_installed_cards[i].card_type == unit)
 208         sel = i;
 209 
 210   if (sel == -1 && num_sound_cards < max_sound_cards)
 211     {
 212       int             i;
 213 
 214       i = sel = (num_sound_cards++);
 215 
 216       snd_installed_cards[sel].card_type = unit;
 217       snd_installed_cards[sel].enabled = 1;
 218     }
 219 
 220   if (sel != -1)
 221     {
 222       int             drv;
 223 
 224       snd_installed_cards[sel].for_driver_use = NULL;
 225       snd_installed_cards[sel].config.io_base = hw_config->io_base;
 226       snd_installed_cards[sel].config.irq = hw_config->irq;
 227       snd_installed_cards[sel].config.dma = hw_config->dma;
 228       snd_installed_cards[sel].config.dma2 = hw_config->dma2;
 229       snd_installed_cards[sel].config.name = hw_config->name;
 230       snd_installed_cards[sel].config.always_detect = hw_config->always_detect;
 231       snd_installed_cards[sel].config.driver_use_1 = hw_config->driver_use_1;
 232       snd_installed_cards[sel].config.driver_use_2 = hw_config->driver_use_2;
 233       snd_installed_cards[sel].config.card_subtype = hw_config->card_subtype;
 234       snd_installed_cards[sel].config.osp = hw_config->osp;
 235 
 236       if ((drv = snd_find_driver (snd_installed_cards[sel].card_type)) == -1)
 237         {
 238           snd_installed_cards[sel].enabled = 0;
 239           DDB (printk ("Failed to find driver\n"));
 240           return FALSE;
 241         }
 242       DDB (printk ("Driver name '%s'\n", sound_drivers[drv].name));
 243 
 244       hw_config->card_subtype =
 245         snd_installed_cards[sel].config.card_subtype =
 246         sound_drivers[drv].card_subtype;
 247 
 248       if (sound_drivers[drv].probe (hw_config))
 249         {
 250           return TRUE;
 251           DDB (printk ("Hardware probed OK\n"));
 252         }
 253 
 254       DDB (printk ("Failed to find hardware\n"));
 255       snd_installed_cards[sel].enabled = 0;     /*
 256                                                  * Mark as not detected
 257                                                  */
 258       return FALSE;
 259     }
 260 
 261   return FALSE;
 262 }
 263 
 264 int
 265 sndtable_init_card (int unit, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 266 {
 267   int             i, n = num_sound_cards;
 268 
 269   DDB (printk ("sndtable_init_card(%d) entered\n", unit));
 270 
 271   if (!unit)
 272     {
 273       if (sndtable_init (0) != 0)
 274         panic ("sound: Invalid memory allocation\n");
 275       return TRUE;
 276     }
 277 
 278   for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
 279     if (snd_installed_cards[i].card_type == unit)
 280       {
 281         int             drv;
 282 
 283         snd_installed_cards[i].config.io_base = hw_config->io_base;
 284         snd_installed_cards[i].config.irq = hw_config->irq;
 285         snd_installed_cards[i].config.dma = hw_config->dma;
 286         snd_installed_cards[i].config.dma2 = hw_config->dma2;
 287         snd_installed_cards[i].config.name = hw_config->name;
 288         snd_installed_cards[i].config.always_detect = hw_config->always_detect;
 289         snd_installed_cards[i].config.driver_use_1 = hw_config->driver_use_1;
 290         snd_installed_cards[i].config.driver_use_2 = hw_config->driver_use_2;
 291         snd_installed_cards[i].config.card_subtype = hw_config->card_subtype;
 292         snd_installed_cards[i].config.osp = hw_config->osp;
 293 
 294         if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
 295           snd_installed_cards[i].enabled = 0;   /*
 296                                                  * Mark as not detected
 297                                                  */
 298         else
 299           {
 300 
 301             DDB (printk ("Located card - calling attach routine\n"));
 302             if (sound_drivers[drv].attach (0, hw_config) != 0)
 303               panic ("sound: Invalid memory allocation\n");
 304 
 305             DDB (printk ("attach routine finished\n"));
 306           }
 307         start_services (0);
 308         return TRUE;
 309       }
 310 
 311   DDB (printk ("sndtable_init_card: No card defined with type=%d, num cards: %d\n",
 312                unit, num_sound_cards));
 313   return FALSE;
 314 }
 315 
 316 int
 317 sndtable_get_cardcount (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 318 {
 319   return num_audiodevs + num_mixers + num_synths + num_midis;
 320 }
 321 
 322 int
 323 sndtable_identify_card (char *name)
     /* [previous][next][first][last][top][bottom][index][help] */
 324 {
 325   int             i, n = num_sound_drivers;
 326 
 327   if (name == NULL)
 328     return 0;
 329 
 330   for (i = 0; i < n; i++)
 331     if (sound_drivers[i].driver_id != NULL)
 332       {
 333         char           *id = sound_drivers[i].driver_id;
 334         int             j;
 335 
 336         for (j = 0; j < 80 && name[j] == id[j]; j++)
 337           if (id[j] == 0 && name[j] == 0)       /* Match */
 338             return sound_drivers[i].card_type;
 339       }
 340 
 341   return 0;
 342 }
 343 
 344 void
 345 sound_setup (char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 346 {
 347   int             i, n = num_sound_cards;
 348 
 349   /*
 350      * First disable all drivers
 351    */
 352 
 353   for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
 354     snd_installed_cards[i].enabled = 0;
 355 
 356   if (ints[0] == 0 || ints[1] == 0)
 357     return;
 358   /*
 359      * Then enable them one by time
 360    */
 361 
 362   for (i = 1; i <= ints[0]; i++)
 363     {
 364       int             card_type, ioaddr, irq, dma, ptr, j;
 365       unsigned int    val;
 366 
 367       val = (unsigned int) ints[i];
 368 
 369       card_type = (val & 0x0ff00000) >> 20;
 370 
 371       if (card_type > 127)
 372         {
 373           /*
 374            * Add any future extensions here
 375            */
 376           return;
 377         }
 378 
 379       ioaddr = (val & 0x000fff00) >> 8;
 380       irq = (val & 0x000000f0) >> 4;
 381       dma = (val & 0x0000000f);
 382 
 383       ptr = -1;
 384       for (j = 0; j < n && ptr == -1; j++)
 385         if (snd_installed_cards[j].card_type == card_type &&
 386             !snd_installed_cards[j].enabled)    /*
 387                                                  * Not already found
 388                                                  */
 389           ptr = j;
 390 
 391       if (ptr == -1)
 392         printk ("Sound: Invalid setup parameter 0x%08x\n", val);
 393       else
 394         {
 395           snd_installed_cards[ptr].enabled = 1;
 396           snd_installed_cards[ptr].config.io_base = ioaddr;
 397           snd_installed_cards[ptr].config.irq = irq;
 398           snd_installed_cards[ptr].config.dma = dma;
 399           snd_installed_cards[ptr].config.dma2 = -1;
 400           snd_installed_cards[ptr].config.name = NULL;
 401           snd_installed_cards[ptr].config.always_detect = 0;
 402           snd_installed_cards[ptr].config.driver_use_1 = 0;
 403           snd_installed_cards[ptr].config.driver_use_2 = 0;
 404           snd_installed_cards[ptr].config.card_subtype = 0;
 405           snd_installed_cards[ptr].config.osp = NULL;
 406         }
 407     }
 408 }
 409 
 410 
 411 struct address_info
 412                *
 413 sound_getconf (int card_type)
     /* [previous][next][first][last][top][bottom][index][help] */
 414 {
 415   int             j, ptr;
 416   int             n = num_sound_cards;
 417 
 418   ptr = -1;
 419   for (j = 0; j < n && ptr == -1 && snd_installed_cards[j].card_type; j++)
 420     if (snd_installed_cards[j].card_type == card_type)
 421       ptr = j;
 422 
 423   if (ptr == -1)
 424     return (struct address_info *) NULL;
 425 
 426   return &snd_installed_cards[ptr].config;
 427 }

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