2 * Advanced Linux Sound Architecture
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <sound/driver.h>
24 #ifdef CONFIG_SND_OSSEMUL
26 #if !defined(CONFIG_SOUND) && !(defined(MODULE) && defined(CONFIG_SOUND_MODULE))
27 #error "Enable the OSS soundcore multiplexer (CONFIG_SOUND) in the kernel."
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/time.h>
33 #include <sound/core.h>
34 #include <sound/minors.h>
35 #include <sound/info.h>
36 #include <linux/sound.h>
38 #define SNDRV_OS_MINORS 256
40 static struct list_head snd_oss_minors_hash[SNDRV_CARDS];
42 static DECLARE_MUTEX(sound_oss_mutex);
44 static snd_minor_t *snd_oss_minor_search(int minor)
46 struct list_head *list;
49 list_for_each(list, &snd_oss_minors_hash[SNDRV_MINOR_OSS_CARD(minor)]) {
50 mptr = list_entry(list, snd_minor_t, list);
51 if (mptr->number == minor)
57 static int snd_oss_kernel_minor(int type, snd_card_t * card, int dev)
62 case SNDRV_OSS_DEVICE_TYPE_MIXER:
63 snd_assert(card != NULL && dev <= 1, return -EINVAL);
64 minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_MIXER1 : SNDRV_MINOR_OSS_MIXER));
66 case SNDRV_OSS_DEVICE_TYPE_SEQUENCER:
67 minor = SNDRV_MINOR_OSS_SEQUENCER;
69 case SNDRV_OSS_DEVICE_TYPE_MUSIC:
70 minor = SNDRV_MINOR_OSS_MUSIC;
72 case SNDRV_OSS_DEVICE_TYPE_PCM:
73 snd_assert(card != NULL && dev <= 1, return -EINVAL);
74 minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_PCM1 : SNDRV_MINOR_OSS_PCM));
76 case SNDRV_OSS_DEVICE_TYPE_MIDI:
77 snd_assert(card != NULL && dev <= 1, return -EINVAL);
78 minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_MIDI1 : SNDRV_MINOR_OSS_MIDI));
80 case SNDRV_OSS_DEVICE_TYPE_DMFM:
81 minor = SNDRV_MINOR_OSS(card->number, SNDRV_MINOR_OSS_DMFM);
83 case SNDRV_OSS_DEVICE_TYPE_SNDSTAT:
84 minor = SNDRV_MINOR_OSS_SNDSTAT;
89 snd_assert(minor >= 0 && minor < SNDRV_OS_MINORS, return -EINVAL);
93 int snd_register_oss_device(int type, snd_card_t * card, int dev, snd_minor_t * reg, const char *name)
95 int minor = snd_oss_kernel_minor(type, card, dev);
98 int cidx = SNDRV_MINOR_OSS_CARD(minor);
100 int register1 = -1, register2 = -1;
101 struct device *carddev = NULL;
105 preg = (snd_minor_t *)kmalloc(sizeof(snd_minor_t), GFP_KERNEL);
109 preg->number = minor;
111 down(&sound_oss_mutex);
112 list_add_tail(&preg->list, &snd_oss_minors_hash[cidx]);
113 minor_unit = SNDRV_MINOR_OSS_DEVICE(minor);
114 switch (minor_unit) {
115 case SNDRV_MINOR_OSS_PCM:
116 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_AUDIO);
118 case SNDRV_MINOR_OSS_MIDI:
119 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI);
121 case SNDRV_MINOR_OSS_MIDI1:
122 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI1);
127 register1 = register_sound_special_device(reg->f_ops, minor, carddev);
128 if (register1 != minor)
131 register2 = register_sound_special_device(reg->f_ops, track2, carddev);
132 if (register2 != track2)
135 up(&sound_oss_mutex);
140 unregister_sound_special(register2);
142 unregister_sound_special(register1);
143 list_del(&preg->list);
144 up(&sound_oss_mutex);
149 int snd_unregister_oss_device(int type, snd_card_t * card, int dev)
151 int minor = snd_oss_kernel_minor(type, card, dev);
152 int cidx = SNDRV_MINOR_OSS_CARD(minor);
158 down(&sound_oss_mutex);
159 mptr = snd_oss_minor_search(minor);
161 up(&sound_oss_mutex);
164 unregister_sound_special(minor);
165 switch (SNDRV_MINOR_OSS_DEVICE(minor)) {
166 case SNDRV_MINOR_OSS_PCM:
167 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_AUDIO);
169 case SNDRV_MINOR_OSS_MIDI:
170 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI);
172 case SNDRV_MINOR_OSS_MIDI1:
173 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI1);
177 unregister_sound_special(track2);
178 list_del(&mptr->list);
179 up(&sound_oss_mutex);
188 #ifdef CONFIG_PROC_FS
190 static snd_info_entry_t *snd_minor_info_oss_entry = NULL;
192 static void snd_minor_info_oss_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer)
195 struct list_head *list;
198 down(&sound_oss_mutex);
199 for (card = 0; card < SNDRV_CARDS; card++) {
200 list_for_each(list, &snd_oss_minors_hash[card]) {
201 mptr = list_entry(list, snd_minor_t, list);
202 dev = SNDRV_MINOR_OSS_DEVICE(mptr->number);
203 if (dev != SNDRV_MINOR_OSS_SNDSTAT &&
204 dev != SNDRV_MINOR_OSS_SEQUENCER &&
205 dev != SNDRV_MINOR_OSS_MUSIC)
206 snd_iprintf(buffer, "%3i: [%i-%2i]: %s\n", mptr->number, card, dev, mptr->comment);
208 snd_iprintf(buffer, "%3i: : %s\n", mptr->number, mptr->comment);
211 up(&sound_oss_mutex);
214 #endif /* CONFIG_PROC_FS */
216 int __init snd_minor_info_oss_init(void)
218 #ifdef CONFIG_PROC_FS
219 snd_info_entry_t *entry;
221 entry = snd_info_create_module_entry(THIS_MODULE, "devices", snd_oss_root);
223 entry->c.text.read_size = PAGE_SIZE;
224 entry->c.text.read = snd_minor_info_oss_read;
225 if (snd_info_register(entry) < 0) {
226 snd_info_free_entry(entry);
230 snd_minor_info_oss_entry = entry;
235 int __exit snd_minor_info_oss_done(void)
237 #ifdef CONFIG_PROC_FS
238 if (snd_minor_info_oss_entry)
239 snd_info_unregister(snd_minor_info_oss_entry);
244 int __init snd_oss_init_module(void)
248 for (card = 0; card < SNDRV_CARDS; card++)
249 INIT_LIST_HEAD(&snd_oss_minors_hash[card]);
253 #endif /* CONFIG_SND_OSSEMUL */