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

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