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"
22 int sound_started
= 0;
23 int sndtable_get_cardcount(void);
25 int snd_find_driver(int type
)
27 int i
, n
= num_sound_drivers
;
29 for (i
= 0; i
< n
; i
++)
30 if (sound_drivers
[i
].card_type
== type
)
36 static void start_services(void)
39 int soundcards_installed
;
41 if (!(soundcards_installed
= sndtable_get_cardcount()))
42 return; /* No cards detected */
46 if (num_audiodevs
) /* Audio devices present */
49 for (dev
= 0; dev
< num_audiodevs
; dev
++)
62 int i
, n
= num_sound_cards
;
67 printk(KERN_DEBUG
"Sound initialization started\n");
69 #ifdef CONFIG_LOWLEVEL_SOUND
71 extern void sound_preinit_lowlevel_drivers(void);
72 sound_preinit_lowlevel_drivers();
77 * Check the number of cards actually defined in the table
80 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
81 num_sound_cards
= i
+ 1;
83 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
85 if (snd_installed_cards
[i
].enabled
)
87 snd_installed_cards
[i
].for_driver_use
= NULL
;
89 if ((drv
= snd_find_driver(snd_installed_cards
[i
].card_type
)) == -1)
91 snd_installed_cards
[i
].enabled
= 0; /*
92 * Mark as not detected
96 snd_installed_cards
[i
].config
.card_subtype
=
97 sound_drivers
[drv
].card_subtype
;
99 if (sound_drivers
[drv
].probe(&snd_installed_cards
[i
].config
))
100 sound_drivers
[drv
].attach(&snd_installed_cards
[i
].config
);
102 snd_installed_cards
[i
].enabled
= 0; /*
103 * Mark as not detected
107 #ifdef CONFIG_LOWLEVEL_SOUND
109 extern void sound_init_lowlevel_drivers(void);
110 sound_init_lowlevel_drivers();
114 printk(KERN_DEBUG
"Sound initialization complete\n");
117 void sndtable_init(void)
123 void sound_unload_drivers(void)
125 int i
, n
= num_sound_cards
;
132 printk(KERN_DEBUG
"Sound unload started\n");
135 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
137 if (snd_installed_cards
[i
].enabled
)
139 if ((drv
= snd_find_driver(snd_installed_cards
[i
].card_type
)) != -1)
141 if (sound_drivers
[drv
].unload
)
143 sound_drivers
[drv
].unload(&snd_installed_cards
[i
].config
);
144 snd_installed_cards
[i
].enabled
= 0;
150 for (i
=0;i
<num_audiodevs
;i
++)
154 printk(KERN_DEBUG
"Sound unload complete\n");
157 void sound_unload_driver(int type
)
159 int i
, drv
= -1, n
= num_sound_cards
;
162 DEB(printk("unload driver %d: ", type
));
164 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
166 if (snd_installed_cards
[i
].card_type
== type
)
168 if (snd_installed_cards
[i
].enabled
)
170 if ((drv
= snd_find_driver(type
)) != -1)
172 DEB(printk(" card %d", i
));
173 if (sound_drivers
[drv
].unload
)
175 sound_drivers
[drv
].unload(&snd_installed_cards
[i
].config
);
176 snd_installed_cards
[i
].enabled
= 0;
186 int sndtable_probe(int unit
, struct address_info
*hw_config
)
190 DEB(printk(KERN_DEBUG
"sndtable_probe(%d)\n", unit
));
196 if (sel
== -1 && num_sound_cards
< max_sound_cards
)
199 i
= sel
= (num_sound_cards
++);
200 snd_installed_cards
[sel
].card_type
= unit
;
201 snd_installed_cards
[sel
].enabled
= 1;
207 snd_installed_cards
[sel
].for_driver_use
= NULL
;
208 snd_installed_cards
[sel
].config
.io_base
= hw_config
->io_base
;
209 snd_installed_cards
[sel
].config
.irq
= hw_config
->irq
;
210 snd_installed_cards
[sel
].config
.dma
= hw_config
->dma
;
211 snd_installed_cards
[sel
].config
.dma2
= hw_config
->dma2
;
212 snd_installed_cards
[sel
].config
.name
= hw_config
->name
;
213 snd_installed_cards
[sel
].config
.always_detect
= hw_config
->always_detect
;
214 snd_installed_cards
[sel
].config
.driver_use_1
= hw_config
->driver_use_1
;
215 snd_installed_cards
[sel
].config
.driver_use_2
= hw_config
->driver_use_2
;
216 snd_installed_cards
[sel
].config
.card_subtype
= hw_config
->card_subtype
;
218 if ((drv
= snd_find_driver(snd_installed_cards
[sel
].card_type
)) == -1)
220 snd_installed_cards
[sel
].enabled
= 0;
221 DEB(printk(KERN_DEBUG
"Failed to find driver\n"));
224 DEB(printk(KERN_DEBUG
"Driver name '%s'\n", sound_drivers
[drv
].name
));
226 hw_config
->card_subtype
= snd_installed_cards
[sel
].config
.card_subtype
= sound_drivers
[drv
].card_subtype
;
228 if (sound_drivers
[drv
].probe(hw_config
))
230 DEB(printk(KERN_DEBUG
"Hardware probed OK\n"));
233 DEB(printk("Failed to find hardware\n"));
234 snd_installed_cards
[sel
].enabled
= 0; /*
235 * Mark as not detected
243 int sndtable_init_card(int unit
, struct address_info
*hw_config
)
245 int i
, n
= num_sound_cards
;
247 DEB(printk("sndtable_init_card(%d) entered\n", unit
));
254 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
256 if (snd_installed_cards
[i
].card_type
== unit
)
260 snd_installed_cards
[i
].config
.io_base
= hw_config
->io_base
;
261 snd_installed_cards
[i
].config
.irq
= hw_config
->irq
;
262 snd_installed_cards
[i
].config
.dma
= hw_config
->dma
;
263 snd_installed_cards
[i
].config
.dma2
= hw_config
->dma2
;
264 snd_installed_cards
[i
].config
.name
= hw_config
->name
;
265 snd_installed_cards
[i
].config
.always_detect
= hw_config
->always_detect
;
266 snd_installed_cards
[i
].config
.driver_use_1
= hw_config
->driver_use_1
;
267 snd_installed_cards
[i
].config
.driver_use_2
= hw_config
->driver_use_2
;
268 snd_installed_cards
[i
].config
.card_subtype
= hw_config
->card_subtype
;
270 if ((drv
= snd_find_driver(snd_installed_cards
[i
].card_type
)) == -1)
271 snd_installed_cards
[i
].enabled
= 0; /*
272 * Mark as not detected
276 DEB(printk(KERN_DEBUG
"Located card - calling attach routine\n"));
277 sound_drivers
[drv
].attach(hw_config
);
279 DEB(printk("attach routine finished\n"));
285 DEB(printk("sndtable_init_card: No card defined with type=%d, num cards: %d\n", unit
, num_sound_cards
));
289 int sndtable_get_cardcount(void)
291 return num_audiodevs
+ num_mixers
+ num_synths
+ num_midis
;
294 int sndtable_identify_card(char *name
)
296 int i
, n
= num_sound_drivers
;
301 for (i
= 0; i
< n
; i
++)
303 if (sound_drivers
[i
].driver_id
!= NULL
)
305 char *id
= sound_drivers
[i
].driver_id
;
308 for (j
= 0; j
< 80 && name
[j
] == id
[j
]; j
++)
309 if (id
[j
] == 0 && name
[j
] == 0) /* Match */
310 return sound_drivers
[i
].card_type
;
316 void sound_setup(char *str
, int *ints
)
318 int i
, n
= num_sound_cards
;
321 * First disable all drivers
324 for (i
= 0; i
< n
&& snd_installed_cards
[i
].card_type
; i
++)
325 snd_installed_cards
[i
].enabled
= 0;
327 if (ints
[0] == 0 || ints
[1] == 0)
330 * Then enable them one by time
333 for (i
= 1; i
<= ints
[0]; i
++)
335 int card_type
, ioaddr
, irq
, dma
, dma2
, ptr
, j
;
338 val
= (unsigned int) ints
[i
];
339 card_type
= (val
& 0x0ff00000) >> 20;
344 * Add any future extensions here
348 ioaddr
= (val
& 0x000fff00) >> 8;
349 irq
= (val
& 0x000000f0) >> 4;
350 dma
= (val
& 0x0000000f);
351 dma2
= (val
& 0xf0000000) >> 28;
354 for (j
= 0; j
< n
&& ptr
== -1; j
++)
356 if (snd_installed_cards
[j
].card_type
== card_type
&&
357 !snd_installed_cards
[j
].enabled
)/*
364 printk(KERN_ERR
"Sound: Invalid setup parameter 0x%08x\n", val
);
367 snd_installed_cards
[ptr
].enabled
= 1;
368 snd_installed_cards
[ptr
].config
.io_base
= ioaddr
;
369 snd_installed_cards
[ptr
].config
.irq
= irq
;
370 snd_installed_cards
[ptr
].config
.dma
= dma
;
371 snd_installed_cards
[ptr
].config
.dma2
= dma2
;
372 snd_installed_cards
[ptr
].config
.name
= NULL
;
373 snd_installed_cards
[ptr
].config
.always_detect
= 0;
374 snd_installed_cards
[ptr
].config
.driver_use_1
= 0;
375 snd_installed_cards
[ptr
].config
.driver_use_2
= 0;
376 snd_installed_cards
[ptr
].config
.card_subtype
= 0;
382 struct address_info
* sound_getconf(int card_type
)
385 int n
= num_sound_cards
;
388 for (j
= 0; j
< n
&& ptr
== -1 && snd_installed_cards
[j
].card_type
; j
++)
390 if (snd_installed_cards
[j
].card_type
== card_type
)
394 return (struct address_info
*) NULL
;
396 return &snd_installed_cards
[ptr
].config
;
401 int sound_install_audiodrv(int vers
, char *name
, struct audio_driver
*driver
,
402 int driver_size
, int flags
, unsigned int format_mask
,
403 void *devc
, int dma1
, int dma2
)
406 struct audio_driver
*d
;
407 struct audio_operations
*op
;
410 if (vers
!= AUDIO_DRIVER_VERSION
|| driver_size
> sizeof(struct audio_driver
))
412 printk(KERN_ERR
"Sound: Incompatible audio driver for %s\n", name
);
415 num
= sound_alloc_audiodev();
419 printk(KERN_ERR
"sound: Too many audio drivers\n");
422 d
= (struct audio_driver
*) (sound_mem_blocks
[sound_nblocks
] = vmalloc(sizeof(struct audio_driver
)));
424 if (sound_nblocks
< 1024)
427 op
= (struct audio_operations
*) (sound_mem_blocks
[sound_nblocks
] = vmalloc(sizeof(struct audio_operations
)));
429 if (sound_nblocks
< 1024)
431 if (d
== NULL
|| op
== NULL
)
433 printk(KERN_ERR
"Sound: Can't allocate driver for (%s)\n", name
);
434 sound_unload_audiodev(num
);
437 memset((char *) op
, 0, sizeof(struct audio_operations
));
438 init_waitqueue_head(&op
->in_sleeper
);
439 init_waitqueue_head(&op
->out_sleeper
);
440 init_waitqueue_head(&op
->poll_sleeper
);
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
)));
495 if (sound_nblocks
< 1024)
499 printk(KERN_ERR
"Sound: Can't allocate mixer driver for (%s)\n", name
);
502 memset((char *) op
, 0, sizeof(struct mixer_operations
));
503 memcpy((char *) op
, (char *) driver
, driver_size
);
505 l
= strlen(name
) + 1;
506 if (l
> sizeof(op
->name
))
507 l
= sizeof(op
->name
);
508 strncpy(op
->name
, name
, l
);
516 void sound_unload_audiodev(int dev
)
521 audio_devs
[dev
] = NULL
;
522 unregister_sound_dsp((dev
<<4)+3);
526 int sound_alloc_audiodev(void)
528 int i
= register_sound_dsp(&oss_sound_fops
, -1);
533 num_audiodevs
= i
+ 1;
537 int sound_alloc_mididev(void)
540 int i
= register_sound_midi(&oss_sound_fops
, -1);
552 int sound_alloc_synthdev(void)
556 for (i
= 0; i
< MAX_SYNTH_DEV
; i
++)
558 if (synth_devs
[i
] == NULL
)
568 int sound_alloc_mixerdev(void)
570 int i
= register_sound_mixer(&oss_sound_fops
, -1);
579 int sound_alloc_timerdev(void)
583 for (i
= 0; i
< MAX_TIMER_DEV
; i
++)
585 if (sound_timer_devs
[i
] == NULL
)
587 if (i
>= num_sound_timers
)
595 void sound_unload_mixerdev(int dev
)
599 mixer_devs
[dev
] = NULL
;
600 unregister_sound_mixer(dev
<<4);
604 void sound_unload_mididev(int dev
)
609 midi_devs
[dev
] = NULL
;
610 unregister_sound_midi((dev
<<4)+2);
615 void sound_unload_synthdev(int dev
)
618 synth_devs
[dev
] = NULL
;
621 void sound_unload_timerdev(int dev
)
624 sound_timer_devs
[dev
] = NULL
;