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
28 * $FreeBSD: src/sys/i386/isa/sound/dev_table.c,v 1.18 1999/12/20 18:04:59 eivind Exp $
32 #include <i386/isa/sound/sound_config.h>
36 int sound_started = 0;
38 int sndtable_get_cardcount(void);
39 int snd_find_driver(int type);
40 static void sndtable_init(void);
41 int sndtable_probe(int unit, struct address_info * hw_config);
42 int sndtable_init_card(int unit, struct address_info * hw_config);
43 static void start_services(void);
44 static void start_cards(void);
45 struct address_info *sound_getconf(int card_type);
48 snd_find_driver(int type)
50 int i, n = num_sound_drivers;
52 for (i = 0; i < n; i++)
53 if (sound_drivers[i].card_type == type)
62 int soundcards_installed;
64 if (!(soundcards_installed = sndtable_get_cardcount()))
65 return ; /* No cards detected */
68 if (num_audiodevs) /* Audio devices present */
74 /* MIDIbuf_init(0) */;
77 #ifdef CONFIG_SEQUENCER
78 if (num_midis + num_synths)
86 int drv, i, n = num_sound_cards;
87 struct card_info *ci = snd_installed_cards ;
91 printf("Sound initialization started\n");
94 * Check the number of cards actually defined in the table
97 for (i = 0; i < n && snd_installed_cards[i].card_type; i++)
98 num_sound_cards = i + 1;
100 for (i = 0; i < n && ci->card_type; ci++, i++)
102 if ((drv = snd_find_driver(ci->card_type)) == -1) {
103 ci->enabled = 0; /* Mark as not detected */
106 ci->config.card_subtype = sound_drivers[drv].card_subtype;
108 if (sound_drivers[drv].probe(&(ci->config)))
109 sound_drivers[drv].attach(&(ci->config));
111 ci->enabled = 0; /* Mark as not detected */
114 printf("Sound initialization complete\n");
124 * sndtable_probe probes a specific device. unit is the voxware unit number.
128 sndtable_probe(int unit, struct address_info * hw_config)
130 int i, sel = -1, n = num_sound_cards;
131 struct card_info *ci = snd_installed_cards ;
133 DDB(printf("-- sndtable_probe(%d)\n", unit));
137 * for some reason unit 0 always succeeds ?
144 for (i=0; i<n && sel== -1 && ci->card_type; ci++, i++)
145 if ( (ci->enabled) && (ci->card_type == unit) ) {
146 /* DDB(printf("-- found card %d\n", i) ); */
147 sel = i; /* and break */
151 * not found. Creates a new entry in the table for this unit.
153 if (sel == -1 && num_sound_cards < max_sound_cards) {
156 i = sel = (num_sound_cards++);
157 DDB(printf("-- installing card %d\n", i) );
159 ci = &snd_installed_cards[sel] ;
160 ci->card_type = unit;
163 /* DDB(printf("-- installed card %d\n", sel) ); */
167 ci->config.io_base = hw_config->io_base;
168 ci->config.irq = hw_config->irq;
169 ci->config.dma = hw_config->dma;
170 ci->config.dma2 = hw_config->dma2;
171 ci->config.name = hw_config->name;
172 ci->config.always_detect = hw_config->always_detect;
173 ci->config.card_subtype = hw_config->card_subtype;
174 ci->config.osp = hw_config->osp;
176 if ((drv = snd_find_driver(ci->card_type)) == -1) {
178 DDB(printf("Failed to find driver\n"));
181 DDB(printf("-- Driver name '%s' probe 0x%08x\n",
182 sound_drivers[drv].name, sound_drivers[drv].probe));
184 hw_config->card_subtype =
185 ci->config.card_subtype = sound_drivers[drv].card_subtype;
187 if (sound_drivers[drv].probe(hw_config)) {
188 DDB(printf("-- Hardware probed OK\n"));
191 DDB(printf("-- Failed to find hardware\n"));
192 ci->enabled = 0; /* mark as not detected */
199 sndtable_init_card(int unit, struct address_info * hw_config)
201 int i, n = num_sound_cards;
202 struct card_info *ci = snd_installed_cards ;
204 DDB(printf("sndtable_init_card(%d) entered\n", unit));
210 for (i = 0; i < n && ci->card_type; ci++, i++)
211 if (ci->card_type == unit) {
214 ci->config.io_base = hw_config->io_base;
215 ci->config.irq = hw_config->irq;
216 ci->config.dma = hw_config->dma;
217 ci->config.dma2 = hw_config->dma2;
218 ci->config.name = hw_config->name;
219 ci->config.always_detect = hw_config->always_detect;
220 ci->config.card_subtype = hw_config->card_subtype;
221 ci->config.osp = hw_config->osp;
223 if ((drv = snd_find_driver(ci->card_type)) == -1)
224 ci->enabled = 0; /* Mark not fnd */
226 DDB(printf("Located card - calling attach routine\n"));
227 sound_drivers[drv].attach(hw_config) ;
228 DDB(printf("attach routine finished\n"));
233 DDB(printf("sndtable_init_card: No card defined with type=%d, num cards: %d\n",
234 unit, num_sound_cards));
239 sndtable_get_cardcount(void)
241 return num_audiodevs + num_mixers + num_synths + num_midis;
244 struct address_info *
245 sound_getconf(int card_type)
247 int j, ptr = -1, n = num_sound_cards;
249 for (j = 0; j < n && ptr == -1 && snd_installed_cards[j].card_type; j++)
250 if (snd_installed_cards[j].card_type == card_type)
254 return (struct address_info *) NULL;
256 return &snd_installed_cards[ptr].config;