Import 1.3.39
[davej-history.git] / drivers / sound / dev_table.c
blob6b4fd45ceff924537e204cb2fd027757ad1d84d2
1 /*
2 * sound/dev_table.c
4 * Device call tables.
6 * Copyright by Hannu Savolainen 1993
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.
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.
30 #define _DEV_TABLE_C_
31 #include "sound_config.h"
33 #ifdef CONFIGURE_SOUNDCARD
35 int sound_started = 0;
37 int sndtable_get_cardcount (void);
39 int
40 snd_find_driver (int type)
42 int i, n = num_sound_drivers;
44 for (i = 0; i < n; i++)
45 if (sound_drivers[i].card_type == type)
46 return i;
48 return -1;
52 static long
53 start_cards (long mem_start)
55 int i, n = num_sound_cards;
56 int drv;
58 sound_started = 1;
59 printk ("Sound initialization started\n");
62 * Check the number of cards actually defined in the table
65 for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
66 num_sound_cards = i + 1;
68 for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
69 if (snd_installed_cards[i].enabled)
71 snd_installed_cards[i].for_driver_use = NULL;
73 if ((drv = snd_find_driver (snd_installed_cards[i].card_type)) == -1)
75 snd_installed_cards[i].enabled = 0; /*
76 * Mark as not detected
78 continue;
81 snd_installed_cards[i].config.card_subtype =
82 sound_drivers[drv].card_subtype;
84 if (sound_drivers[drv].probe (&snd_installed_cards[i].config))
86 int tmp;
88 printk ("snd%d",
89 snd_installed_cards[i].card_type);
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);
95 if ((tmp = snd_installed_cards[i].config.irq) != 0)
96 printk (" irq %d",
97 (tmp > 0) ? tmp : -tmp);
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");
108 else
109 snd_installed_cards[i].enabled = 0; /*
110 * Mark as not detected
114 printk ("Sound initialization complete\n");
115 return mem_start;
118 long
119 sndtable_init (long mem_start)
121 return start_cards (mem_start);
124 void
125 sound_unload_drivers (void)
127 int i, n = num_sound_cards;
128 int drv;
130 if (!sound_started)
131 return;
133 printk ("Sound unload started\n");
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)
140 sound_drivers[drv].unload (&snd_installed_cards[i].config);
141 snd_installed_cards[i].enabled = 0;
144 printk ("Sound unload complete\n");
147 void
148 sound_unload_driver (int type)
150 int i, drv = -1, n = num_sound_cards;
152 unsigned long flags;
154 DDB (printk ("unload driver %d: ", type));
156 for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
157 if (snd_installed_cards[i].card_type == type)
159 if (snd_installed_cards[i].enabled)
161 if ((drv = snd_find_driver (type)) != -1)
163 if (sound_drivers[drv].unload)
165 sound_drivers[drv].unload (&snd_installed_cards[i].config);
166 snd_installed_cards[i].enabled = 0;
172 save_flags (flags);
173 cli ();
175 restore_flags (flags);
181 sndtable_probe (int unit, struct address_info *hw_config)
183 int i, sel = -1, n = num_sound_cards;
185 if (!unit)
186 return TRUE;
188 sound_started = 1;
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;
195 if (sel == -1 && num_sound_cards < max_sound_cards)
197 int i;
199 i = sel = (num_sound_cards++);
201 snd_installed_cards[sel].card_type = unit;
202 snd_installed_cards[sel].enabled = 1;
205 if (sel != -1)
207 int drv;
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;
221 if ((drv = snd_find_driver (snd_installed_cards[sel].card_type)) == -1)
223 snd_installed_cards[sel].enabled = 0;
224 return FALSE;
228 snd_installed_cards[sel].config.card_subtype =
229 sound_drivers[drv].card_subtype;
231 if (sound_drivers[drv].probe (hw_config))
232 return TRUE;
234 snd_installed_cards[sel].enabled = 0; /*
235 * Mark as not detected
237 return FALSE;
240 return FALSE;
244 sndtable_init_card (int unit, struct address_info *hw_config)
246 int i, n = num_sound_cards;
248 DDB (printk ("sndtable_init_card(%d) entered\n", unit));
250 if (!unit)
252 if (sndtable_init (0) != 0)
253 panic ("sound: Invalid memory allocation\n");
254 return TRUE;
257 for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
258 if (snd_installed_cards[i].card_type == unit)
260 int drv;
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;
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
277 else
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");
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");
296 return TRUE;
299 printk ("sndtable_init_card: No card defined with type=%d, num cards: %d\n",
300 unit, num_sound_cards);
301 return FALSE;
305 sndtable_get_cardcount (void)
307 return num_audiodevs + num_mixers + num_synths + num_midis;
311 sndtable_identify_card (char *name)
313 int i, n = num_sound_drivers;
315 if (name == NULL)
316 return 0;
318 for (i = 0; i < n; i++)
319 if (sound_drivers[i].driver_id != NULL)
321 char *id = sound_drivers[i].driver_id;
322 int j;
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;
329 return 0;
332 void
333 sound_setup (char *str, int *ints)
335 int i, n = num_sound_cards;
338 * First disable all drivers
341 for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
342 snd_installed_cards[i].enabled = 0;
344 if (ints[0] == 0 || ints[1] == 0)
345 return;
347 * Then enable them one by time
350 for (i = 1; i <= ints[0]; i++)
352 int card_type, ioaddr, irq, dma, ptr, j;
353 unsigned int val;
355 val = (unsigned int) ints[i];
357 card_type = (val & 0x0ff00000) >> 20;
359 if (card_type > 127)
362 * Add any future extensions here
364 return;
367 ioaddr = (val & 0x000fff00) >> 8;
368 irq = (val & 0x000000f0) >> 4;
369 dma = (val & 0x0000000f);
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
377 ptr = j;
379 if (ptr == -1)
380 printk ("Sound: Invalid setup parameter 0x%08x\n", val);
381 else
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;
399 struct address_info
401 sound_getconf (int card_type)
403 int j, ptr;
404 int n = num_sound_cards;
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;
411 if (ptr == -1)
412 return (struct address_info *) NULL;
414 return &snd_installed_cards[ptr].config;
419 #endif