8 * Copyright (C) by Hannu Savolainen 1993-1997
10 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
11 * Version 2 (June 1991). See the "COPYING" file distributed with this software
15 #include <linux/config.h>
19 #include "sound_config.h"
23 int sound_started
= 0;
24 int sndtable_get_cardcount(void);
26 int snd_find_driver(int type
)
28 int i
, n
= num_sound_drivers
;
30 for (i
= 0; i
< n
; i
++)
31 if (sound_drivers
[i
].card_type
== type
)
37 static void start_services(void)
40 int soundcards_installed
;
42 if (!(soundcards_installed
= sndtable_get_cardcount()))
43 return; /* No cards detected */
47 if (num_audiodevs
) /* Audio devices present */
50 for (dev
= 0; dev
< num_audiodevs
; dev
++)
63 int i
, n
= num_sound_cards
;
68 printk(KERN_DEBUG
"Sound initialization started\n");
70 #ifdef CONFIG_LOWLEVEL_SOUND
72 extern void sound_preinit_lowlevel_drivers(void);
73 sound_preinit_lowlevel_drivers();
78 * Check the number of cards actually defined in the table
81 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
82 num_sound_cards
= i
+ 1;
84 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
86 if (snd_installed_cards
[i
].enabled
)
88 snd_installed_cards
[i
].for_driver_use
= NULL
;
90 if ((drv
= snd_find_driver(snd_installed_cards
[i
].card_type
)) == -1)
92 snd_installed_cards
[i
].enabled
= 0; /*
93 * Mark as not detected
97 snd_installed_cards
[i
].config
.card_subtype
=
98 sound_drivers
[drv
].card_subtype
;
100 if (sound_drivers
[drv
].probe(&snd_installed_cards
[i
].config
))
101 sound_drivers
[drv
].attach(&snd_installed_cards
[i
].config
);
103 snd_installed_cards
[i
].enabled
= 0; /*
104 * Mark as not detected
108 #ifdef CONFIG_LOWLEVEL_SOUND
110 extern void sound_init_lowlevel_drivers(void);
111 sound_init_lowlevel_drivers();
115 printk(KERN_DEBUG
"Sound initialization complete\n");
118 void sndtable_init(void)
124 void sound_unload_drivers(void)
126 int i
, n
= num_sound_cards
;
133 printk(KERN_DEBUG
"Sound unload started\n");
136 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
138 if (snd_installed_cards
[i
].enabled
)
140 if ((drv
= snd_find_driver(snd_installed_cards
[i
].card_type
)) != -1)
142 if (sound_drivers
[drv
].unload
)
144 sound_drivers
[drv
].unload(&snd_installed_cards
[i
].config
);
145 snd_installed_cards
[i
].enabled
= 0;
151 for (i
=0;i
<num_audiodevs
;i
++)
155 printk(KERN_DEBUG
"Sound unload complete\n");
158 void sound_unload_driver(int type
)
160 int i
, drv
= -1, n
= num_sound_cards
;
163 DEB(printk("unload driver %d: ", type
));
165 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
167 if (snd_installed_cards
[i
].card_type
== type
)
169 if (snd_installed_cards
[i
].enabled
)
171 if ((drv
= snd_find_driver(type
)) != -1)
173 DEB(printk(" card %d", i
));
174 if (sound_drivers
[drv
].unload
)
176 sound_drivers
[drv
].unload(&snd_installed_cards
[i
].config
);
177 snd_installed_cards
[i
].enabled
= 0;
187 int sndtable_probe(int unit
, struct address_info
*hw_config
)
191 DEB(printk(KERN_DEBUG
"sndtable_probe(%d)\n", unit
));
197 if (sel
== -1 && num_sound_cards
< max_sound_cards
)
200 i
= sel
= (num_sound_cards
++);
201 snd_installed_cards
[sel
].card_type
= unit
;
202 snd_installed_cards
[sel
].enabled
= 1;
208 snd_installed_cards
[sel
].for_driver_use
= NULL
;
209 snd_installed_cards
[sel
].config
.io_base
= hw_config
->io_base
;
210 snd_installed_cards
[sel
].config
.irq
= hw_config
->irq
;
211 snd_installed_cards
[sel
].config
.dma
= hw_config
->dma
;
212 snd_installed_cards
[sel
].config
.dma2
= hw_config
->dma2
;
213 snd_installed_cards
[sel
].config
.name
= hw_config
->name
;
214 snd_installed_cards
[sel
].config
.always_detect
= hw_config
->always_detect
;
215 snd_installed_cards
[sel
].config
.driver_use_1
= hw_config
->driver_use_1
;
216 snd_installed_cards
[sel
].config
.driver_use_2
= hw_config
->driver_use_2
;
217 snd_installed_cards
[sel
].config
.card_subtype
= hw_config
->card_subtype
;
219 if ((drv
= snd_find_driver(snd_installed_cards
[sel
].card_type
)) == -1)
221 snd_installed_cards
[sel
].enabled
= 0;
222 DEB(printk(KERN_DEBUG
"Failed to find driver\n"));
225 DEB(printk(KERN_DEBUG
"Driver name '%s'\n", sound_drivers
[drv
].name
));
227 hw_config
->card_subtype
= snd_installed_cards
[sel
].config
.card_subtype
= sound_drivers
[drv
].card_subtype
;
229 if (sound_drivers
[drv
].probe(hw_config
))
231 DEB(printk(KERN_DEBUG
"Hardware probed OK\n"));
234 DEB(printk("Failed to find hardware\n"));
235 snd_installed_cards
[sel
].enabled
= 0; /*
236 * Mark as not detected
244 int sndtable_init_card(int unit
, struct address_info
*hw_config
)
246 int i
, n
= num_sound_cards
;
248 DEB(printk("sndtable_init_card(%d) entered\n", unit
));
255 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
257 if (snd_installed_cards
[i
].card_type
== unit
)
261 snd_installed_cards
[i
].config
.io_base
= hw_config
->io_base
;
262 snd_installed_cards
[i
].config
.irq
= hw_config
->irq
;
263 snd_installed_cards
[i
].config
.dma
= hw_config
->dma
;
264 snd_installed_cards
[i
].config
.dma2
= hw_config
->dma2
;
265 snd_installed_cards
[i
].config
.name
= hw_config
->name
;
266 snd_installed_cards
[i
].config
.always_detect
= hw_config
->always_detect
;
267 snd_installed_cards
[i
].config
.driver_use_1
= hw_config
->driver_use_1
;
268 snd_installed_cards
[i
].config
.driver_use_2
= hw_config
->driver_use_2
;
269 snd_installed_cards
[i
].config
.card_subtype
= hw_config
->card_subtype
;
271 if ((drv
= snd_find_driver(snd_installed_cards
[i
].card_type
)) == -1)
272 snd_installed_cards
[i
].enabled
= 0; /*
273 * Mark as not detected
277 DEB(printk(KERN_DEBUG
"Located card - calling attach routine\n"));
278 sound_drivers
[drv
].attach(hw_config
);
280 DEB(printk("attach routine finished\n"));
286 DEB(printk("sndtable_init_card: No card defined with type=%d, num cards: %d\n", unit
, num_sound_cards
));
290 int sndtable_get_cardcount(void)
292 return num_audiodevs
+ num_mixers
+ num_synths
+ num_midis
;
295 int sndtable_identify_card(char *name
)
297 int i
, n
= num_sound_drivers
;
302 for (i
= 0; i
< n
; i
++)
304 if (sound_drivers
[i
].driver_id
!= NULL
)
306 char *id
= sound_drivers
[i
].driver_id
;
309 for (j
= 0; j
< 80 && name
[j
] == id
[j
]; j
++)
310 if (id
[j
] == 0 && name
[j
] == 0) /* Match */
311 return sound_drivers
[i
].card_type
;
317 void sound_setup(char *str
, int *ints
)
319 int i
, n
= num_sound_cards
;
322 * First disable all drivers
325 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
326 snd_installed_cards
[i
].enabled
= 0;
328 if (ints
[0] == 0 || ints
[1] == 0)
331 * Then enable them one by time
334 for (i
= 1; i
<= ints
[0]; i
++)
336 int card_type
, ioaddr
, irq
, dma
, dma2
, ptr
, j
;
339 val
= (unsigned int) ints
[i
];
340 card_type
= (val
& 0x0ff00000) >> 20;
345 * Add any future extensions here
349 ioaddr
= (val
& 0x000fff00) >> 8;
350 irq
= (val
& 0x000000f0) >> 4;
351 dma
= (val
& 0x0000000f);
352 dma2
= (val
& 0xf0000000) >> 28;
355 for (j
= 0; j
< n
&& ptr
== -1; j
++)
357 if (snd_installed_cards
[j
].card_type
== card_type
&&
358 !snd_installed_cards
[j
].enabled
)/*
365 printk(KERN_ERR
"Sound: Invalid setup parameter 0x%08x\n", val
);
368 snd_installed_cards
[ptr
].enabled
= 1;
369 snd_installed_cards
[ptr
].config
.io_base
= ioaddr
;
370 snd_installed_cards
[ptr
].config
.irq
= irq
;
371 snd_installed_cards
[ptr
].config
.dma
= dma
;
372 snd_installed_cards
[ptr
].config
.dma2
= dma2
;
373 snd_installed_cards
[ptr
].config
.name
= NULL
;
374 snd_installed_cards
[ptr
].config
.always_detect
= 0;
375 snd_installed_cards
[ptr
].config
.driver_use_1
= 0;
376 snd_installed_cards
[ptr
].config
.driver_use_2
= 0;
377 snd_installed_cards
[ptr
].config
.card_subtype
= 0;
383 struct address_info
* sound_getconf(int card_type
)
386 int n
= num_sound_cards
;
389 for (j
= 0; j
< n
&& ptr
== -1 && snd_installed_cards
[j
].card_type
; j
++)
391 if (snd_installed_cards
[j
].card_type
== card_type
)
395 return (struct address_info
*) NULL
;
397 return &snd_installed_cards
[ptr
].config
;
402 int sound_install_audiodrv(int vers
, char *name
, struct audio_driver
*driver
,
403 int driver_size
, int flags
, unsigned int format_mask
,
404 void *devc
, int dma1
, int dma2
)
407 struct audio_driver
*d
;
408 struct audio_operations
*op
;
411 if (vers
!= AUDIO_DRIVER_VERSION
|| driver_size
> sizeof(struct audio_driver
))
413 printk(KERN_ERR
"Sound: Incompatible audio driver for %s\n", name
);
416 num
= sound_alloc_audiodev();
420 printk(KERN_ERR
"sound: Too many audio drivers\n");
423 d
= (struct audio_driver
*) (sound_mem_blocks
[sound_nblocks
] = vmalloc(sizeof(struct audio_driver
)));
424 sound_mem_sizes
[sound_nblocks
] = sizeof(struct audio_driver
);
426 if (sound_nblocks
< 1024)
429 op
= (struct audio_operations
*) (sound_mem_blocks
[sound_nblocks
] = vmalloc(sizeof(struct audio_operations
)));
430 sound_mem_sizes
[sound_nblocks
] = sizeof(struct audio_operations
);
432 if (sound_nblocks
< 1024)
434 if (d
== NULL
|| op
== NULL
)
436 printk(KERN_ERR
"Sound: Can't allocate driver for (%s)\n", name
);
437 sound_unload_audiodev(num
);
440 memset((char *) op
, 0, sizeof(struct audio_operations
));
441 if (driver_size
< sizeof(struct audio_driver
))
442 memset((char *) d
, 0, sizeof(struct audio_driver
));
444 memcpy((char *) d
, (char *) driver
, driver_size
);
447 l
= strlen(name
) + 1;
448 if (l
> sizeof(op
->name
))
449 l
= sizeof(op
->name
);
450 strncpy(op
->name
, name
, l
);
453 op
->format_mask
= format_mask
;
459 audio_devs
[num
] = op
;
461 DMAbuf_init(num
, dma1
, dma2
);
463 audio_init_devices();
470 int sound_install_mixer(int vers
, char *name
, struct mixer_operations
*driver
,
471 int driver_size
, void *devc
)
473 struct mixer_operations
*op
;
476 int n
= sound_alloc_mixerdev();
480 printk(KERN_ERR
"Sound: Too many mixer drivers\n");
483 if (vers
!= MIXER_DRIVER_VERSION
||
484 driver_size
> sizeof(struct mixer_operations
))
486 printk(KERN_ERR
"Sound: Incompatible mixer driver for %s\n", name
);
490 /* FIXME: This leaks a mixer_operations struct every time its called
491 until you unload sound! */
493 op
= (struct mixer_operations
*) (sound_mem_blocks
[sound_nblocks
] = vmalloc(sizeof(struct mixer_operations
)));
494 sound_mem_sizes
[sound_nblocks
] = sizeof(struct mixer_operations
);
496 if (sound_nblocks
< 1024)
500 printk(KERN_ERR
"Sound: Can't allocate mixer driver for (%s)\n", name
);
503 memset((char *) op
, 0, sizeof(struct mixer_operations
));
504 memcpy((char *) op
, (char *) driver
, driver_size
);
506 l
= strlen(name
) + 1;
507 if (l
> sizeof(op
->name
))
508 l
= sizeof(op
->name
);
509 strncpy(op
->name
, name
, l
);
517 void sound_unload_audiodev(int dev
)
520 audio_devs
[dev
] = NULL
;
523 int sound_alloc_audiodev(void)
527 for (i
= 0; i
< MAX_AUDIO_DEV
; i
++)
529 if (audio_devs
[i
] == NULL
)
531 if (i
>= num_audiodevs
)
532 num_audiodevs
= i
+ 1;
539 int sound_alloc_mididev(void)
543 for (i
= 0; i
< MAX_MIDI_DEV
; i
++)
545 if (midi_devs
[i
] == NULL
)
555 int sound_alloc_synthdev(void)
559 for (i
= 0; i
< MAX_SYNTH_DEV
; i
++)
561 if (synth_devs
[i
] == NULL
)
571 int sound_alloc_mixerdev(void)
575 for (i
= 0; i
< MAX_MIXER_DEV
; i
++)
577 if (mixer_devs
[i
] == NULL
)
587 int sound_alloc_timerdev(void)
591 for (i
= 0; i
< MAX_TIMER_DEV
; i
++)
593 if (sound_timer_devs
[i
] == NULL
)
595 if (i
>= num_sound_timers
)
603 void sound_unload_mixerdev(int dev
)
606 mixer_devs
[dev
] = NULL
;
609 void sound_unload_mididev(int dev
)
613 midi_devs
[dev
] = NULL
;
617 void sound_unload_synthdev(int dev
)
620 synth_devs
[dev
] = NULL
;
623 void sound_unload_timerdev(int dev
)
626 sound_timer_devs
[dev
] = NULL
;