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. sndtable_probe
  4. sndtable_init_card
  5. sndtable_get_cardcount
  6. sound_setup
  7. sound_chconf
  8. sound_getconf
  9. 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 = sizeof (sound_drivers) / sizeof (struct driver_info);
  39 
  40   for (i = 0; i < (n - 1); 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 = sizeof (snd_installed_cards) / sizeof (struct card_info);
  53   int             drv;
  54 
  55   printk ("Sound initialization started\n");
  56 
  57   for (i = 0; i < (n - 1); i++)
  58     if (snd_installed_cards[i].enabled)
  59       if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
  60         snd_installed_cards[i].enabled = 0;     /*
  61                                                  * Mark as not detected
  62                                                  */
  63       else if (sound_drivers[drv].probe (&snd_installed_cards[i].config))
  64         {
  65 #ifndef SHORT_BANNERS
  66           printk ("snd%d",
  67                   snd_installed_cards[i].card_type);
  68 #endif
  69 
  70           mem_start = sound_drivers[drv].attach (mem_start, &snd_installed_cards[i].config);
  71 #ifndef SHORT_BANNERS
  72           printk (" at 0x%x irq %d drq %d\n",
  73                   snd_installed_cards[i].config.io_base,
  74                   snd_installed_cards[i].config.irq,
  75                   snd_installed_cards[i].config.dma);
  76 #endif
  77         }
  78       else
  79         snd_installed_cards[i].enabled = 0;     /*
  80                                                  * Mark as not detected
  81                                                  */
  82   printk ("Sound initialization complete\n");
  83   return mem_start;
  84 }
  85 
  86 int
  87 sndtable_probe (int unit, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
  88 {
  89   int             i, n = sizeof (snd_installed_cards) / sizeof (struct card_info);
  90 
  91   if (!unit)
  92     return TRUE;
  93 
  94   for (i = 0; i < (n - 1); i++)
  95     if (snd_installed_cards[i].enabled)
  96       if (snd_installed_cards[i].card_type == unit)
  97         {
  98           int             drv;
  99 
 100           snd_installed_cards[i].config.io_base = hw_config->io_base;
 101           snd_installed_cards[i].config.irq = hw_config->irq;
 102           snd_installed_cards[i].config.dma = hw_config->dma;
 103           if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
 104             snd_installed_cards[i].enabled = 0;         /*
 105                                                          * Mark as not
 106                                                          * detected
 107                                                          */
 108           else if (sound_drivers[drv].probe (hw_config))
 109             return 1;
 110           snd_installed_cards[i].enabled = 0;   /*
 111                                                  * Mark as not detected
 112                                                  */
 113           return 0;
 114         }
 115 
 116   return FALSE;
 117 }
 118 
 119 int
 120 sndtable_init_card (int unit, struct address_info *hw_config)
     /* [previous][next][first][last][top][bottom][index][help] */
 121 {
 122   int             i, n = sizeof (snd_installed_cards) / sizeof (struct card_info);
 123 
 124   if (!unit)
 125     {
 126       if (sndtable_init (0) != 0)
 127         panic ("snd: Invalid memory allocation\n");
 128       return TRUE;
 129     }
 130 
 131   for (i = 0; i < (n - 1); i++)
 132     if (snd_installed_cards[i].card_type == unit)
 133       {
 134         int             drv;
 135 
 136         snd_installed_cards[i].config.io_base = hw_config->io_base;
 137         snd_installed_cards[i].config.irq = hw_config->irq;
 138         snd_installed_cards[i].config.dma = hw_config->dma;
 139 
 140         if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
 141           snd_installed_cards[i].enabled = 0;   /*
 142                                                  * Mark as not detected
 143                                                  */
 144         else if (sound_drivers[drv].attach (0, hw_config) != 0)
 145           panic ("snd#: Invalid memory allocation\n");
 146         return TRUE;
 147       }
 148 
 149   return FALSE;
 150 }
 151 
 152 int
 153 sndtable_get_cardcount (void)
     /* [previous][next][first][last][top][bottom][index][help] */
 154 {
 155   return num_audiodevs + num_mixers + num_synths + num_midis;
 156 }
 157 
 158 #ifdef linux
 159 void
 160 sound_setup (char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 161 {
 162   int             i, n = sizeof (snd_installed_cards) / sizeof (struct card_info);
 163 
 164   /*
 165      * First disable all drivers
 166    */
 167 
 168   for (i = 0; i < n; i++)
 169     snd_installed_cards[i].enabled = 0;
 170 
 171   if (ints[0] == 0 || ints[1] == 0)
 172     return;
 173   /*
 174      * Then enable them one by time
 175    */
 176 
 177   for (i = 1; i <= ints[0]; i++)
 178     {
 179       int             card_type, ioaddr, irq, dma, ptr, j;
 180       unsigned int    val;
 181 
 182       val = (unsigned int) ints[i];
 183 
 184       card_type = (val & 0x0ff00000) >> 20;
 185 
 186       if (card_type > 127)
 187         {
 188           /*
 189            * Add any future extensions here
 190            */
 191           return;
 192         }
 193 
 194       ioaddr = (val & 0x000fff00) >> 8;
 195       irq = (val & 0x000000f0) >> 4;
 196       dma = (val & 0x0000000f);
 197 
 198       ptr = -1;
 199       for (j = 0; j < n && ptr == -1; j++)
 200         if (snd_installed_cards[j].card_type == card_type &&
 201             !snd_installed_cards[j].enabled)    /*
 202                                                  * Not already found
 203                                                  */
 204           ptr = j;
 205 
 206       if (ptr == -1)
 207         printk ("Sound: Invalid setup parameter 0x%08x\n", val);
 208       else
 209         {
 210           snd_installed_cards[ptr].enabled = 1;
 211           snd_installed_cards[ptr].config.io_base = ioaddr;
 212           snd_installed_cards[ptr].config.irq = irq;
 213           snd_installed_cards[ptr].config.dma = dma;
 214         }
 215     }
 216 }
 217 
 218 #else
 219 void
 220 sound_chconf (int card_type, int ioaddr, int irq, int dma)
     /* [previous][next][first][last][top][bottom][index][help] */
 221 {
 222   int             i, n = sizeof (snd_installed_cards) / sizeof (struct card_info);
 223 
 224   int             ptr, j;
 225 
 226   ptr = -1;
 227   for (j = 0; j < n && ptr == -1; j++)
 228     if (snd_installed_cards[j].card_type == card_type &&
 229         !snd_installed_cards[j].enabled)        /*
 230                                                  * Not already found
 231                                                  */
 232       ptr = j;
 233 
 234   if (ptr != -1)
 235     {
 236       snd_installed_cards[ptr].enabled = 1;
 237       if (ioaddr)
 238         snd_installed_cards[ptr].config.io_base = ioaddr;
 239       if (irq)
 240         snd_installed_cards[ptr].config.irq = irq;
 241       if (dma)
 242         snd_installed_cards[ptr].config.dma = dma;
 243     }
 244 }
 245 
 246 #endif
 247 
 248 struct address_info *
 249 sound_getconf (int card_type)
     /* [previous][next][first][last][top][bottom][index][help] */
 250 {
 251   int             j, ptr;
 252   int             n = sizeof (snd_installed_cards) / sizeof (struct card_info);
 253 
 254   ptr = -1;
 255   for (j = 0; j < n && ptr == -1; j++)
 256     if (snd_installed_cards[j].card_type == card_type)
 257       ptr = j;
 258 
 259   if (ptr == -1)
 260     return (struct address_info *) NULL;
 261 
 262   return &snd_installed_cards[ptr].config;
 263 }
 264 
 265 #else
 266 
 267 void
 268 sound_setup (char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 269 {
 270 }
 271 
 272 #endif

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