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

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

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