This source file includes following definitions.
- snd_find_driver
- start_services
- start_cards
- sndtable_init
- sound_unload_drivers
- sound_unload_driver
- sndtable_probe
- sndtable_init_card
- sndtable_get_cardcount
- sndtable_identify_card
- sound_setup
- sound_getconf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)
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)
53 {
54 int soundcards_installed;
55
56 if (!(soundcards_installed = sndtable_get_cardcount ()))
57 return mem_start;
58
59 #ifdef CONFIG_AUDIO
60 if (num_audiodevs)
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)
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
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
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
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)
131 {
132 return start_cards (mem_start);
133 }
134
135 void
136 sound_unload_drivers (void)
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)
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)
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
257
258 return FALSE;
259 }
260
261 return FALSE;
262 }
263
264 int
265 sndtable_init_card (int unit, struct address_info *hw_config)
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
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)
318 {
319 return num_audiodevs + num_mixers + num_synths + num_midis;
320 }
321
322 int
323 sndtable_identify_card (char *name)
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)
338 return sound_drivers[i].card_type;
339 }
340
341 return 0;
342 }
343
344 void
345 sound_setup (char *str, int *ints)
346 {
347 int i, n = num_sound_cards;
348
349
350
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
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
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
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)
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 }