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
31 #include "sound_config.h"
33 #ifdef CONFIGURE_SOUNDCARD
35 int sound_started
= 0;
37 int sndtable_get_cardcount (void);
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
)
53 start_cards (long mem_start
)
55 int i
, n
= num_sound_cards
;
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
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
))
89 snd_installed_cards
[i
].card_type
);
91 mem_start
= sound_drivers
[drv
].attach (mem_start
, &snd_installed_cards
[i
].config
);
93 snd_installed_cards
[i
].config
.io_base
);
95 if ((tmp
= snd_installed_cards
[i
].config
.irq
) != 0)
97 (tmp
> 0) ? tmp
: -tmp
);
99 if (snd_installed_cards
[i
].config
.dma
>= 0)
101 snd_installed_cards
[i
].config
.dma
);
102 if (snd_installed_cards
[i
].config
.dma2
!= -1)
104 snd_installed_cards
[i
].config
.dma2
);
109 snd_installed_cards
[i
].enabled
= 0; /*
110 * Mark as not detected
114 printk ("Sound initialization complete\n");
119 sndtable_init (long mem_start
)
121 return start_cards (mem_start
);
125 sound_unload_drivers (void)
127 int i
, n
= num_sound_cards
;
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");
148 sound_unload_driver (int type
)
150 int i
, drv
= -1, n
= num_sound_cards
;
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;
175 restore_flags (flags
);
181 sndtable_probe (int unit
, struct address_info
*hw_config
)
183 int i
, sel
= -1, n
= num_sound_cards
;
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
)
195 if (sel
== -1 && num_sound_cards
< max_sound_cards
)
199 i
= sel
= (num_sound_cards
++);
201 snd_installed_cards
[sel
].card_type
= unit
;
202 snd_installed_cards
[sel
].enabled
= 1;
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;
228 snd_installed_cards
[sel
].config
.card_subtype
=
229 sound_drivers
[drv
].card_subtype
;
231 if (sound_drivers
[drv
].probe (hw_config
))
234 snd_installed_cards
[sel
].enabled
= 0; /*
235 * Mark as not detected
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
));
252 if (sndtable_init (0) != 0)
253 panic ("sound: Invalid memory allocation\n");
257 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
258 if (snd_installed_cards
[i
].card_type
== unit
)
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
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)
292 snd_installed_cards
[i
].config
.dma2
);
299 printk ("sndtable_init_card: No card defined with type=%d, num cards: %d\n",
300 unit
, num_sound_cards
);
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
;
318 for (i
= 0; i
< n
; i
++)
319 if (sound_drivers
[i
].driver_id
!= NULL
)
321 char *id
= sound_drivers
[i
].driver_id
;
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
;
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)
347 * Then enable them one by time
350 for (i
= 1; i
<= ints
[0]; i
++)
352 int card_type
, ioaddr
, irq
, dma
, ptr
, j
;
355 val
= (unsigned int) ints
[i
];
357 card_type
= (val
& 0x0ff00000) >> 20;
362 * Add any future extensions here
367 ioaddr
= (val
& 0x000fff00) >> 8;
368 irq
= (val
& 0x000000f0) >> 4;
369 dma
= (val
& 0x0000000f);
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
) /*
380 printk ("Sound: Invalid setup parameter 0x%08x\n", val
);
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
;
401 sound_getconf (int card_type
)
404 int n
= num_sound_cards
;
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
)
412 return (struct address_info
*) NULL
;
414 return &snd_installed_cards
[ptr
].config
;