slc90e66 update
[linux-2.6/history.git] / sound / core / sound_oss.c
blob21ce042c818d0e074201e115809b71165848642c
1 /*
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 #define __NO_VERSION__
23 #include <sound/driver.h>
25 #ifdef CONFIG_SND_OSSEMUL
27 #if !defined(CONFIG_SOUND) && !defined(CONFIG_SOUND_MODULE)
28 #error "Enable the OSS soundcore multiplexer (CONFIG_SOUND) in the kernel."
29 #endif
31 #include <linux/init.h>
32 #include <linux/slab.h>
33 #include <linux/time.h>
34 #include <sound/core.h>
35 #include <sound/minors.h>
36 #include <sound/info.h>
37 #include <linux/sound.h>
39 #define SNDRV_OS_MINORS 256
41 static struct list_head snd_oss_minors_hash[SNDRV_CARDS];
43 static DECLARE_MUTEX(sound_oss_mutex);
45 static snd_minor_t *snd_oss_minor_search(int minor)
47 struct list_head *list;
48 snd_minor_t *mptr;
50 list_for_each(list, &snd_oss_minors_hash[SNDRV_MINOR_OSS_CARD(minor)]) {
51 mptr = list_entry(list, snd_minor_t, list);
52 if (mptr->number == minor)
53 return mptr;
55 return NULL;
58 static int snd_oss_kernel_minor(int type, snd_card_t * card, int dev)
60 int minor;
62 switch (type) {
63 case SNDRV_OSS_DEVICE_TYPE_MIXER:
64 snd_assert(card != NULL && dev <= 1, return -EINVAL);
65 minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_MIXER1 : SNDRV_MINOR_OSS_MIXER));
66 break;
67 case SNDRV_OSS_DEVICE_TYPE_SEQUENCER:
68 minor = SNDRV_MINOR_OSS_SEQUENCER;
69 break;
70 case SNDRV_OSS_DEVICE_TYPE_MUSIC:
71 minor = SNDRV_MINOR_OSS_MUSIC;
72 break;
73 case SNDRV_OSS_DEVICE_TYPE_PCM:
74 snd_assert(card != NULL && dev <= 1, return -EINVAL);
75 minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_PCM1 : SNDRV_MINOR_OSS_PCM));
76 break;
77 case SNDRV_OSS_DEVICE_TYPE_MIDI:
78 snd_assert(card != NULL && dev <= 1, return -EINVAL);
79 minor = SNDRV_MINOR_OSS(card->number, (dev ? SNDRV_MINOR_OSS_MIDI1 : SNDRV_MINOR_OSS_MIDI));
80 break;
81 case SNDRV_OSS_DEVICE_TYPE_DMFM:
82 minor = SNDRV_MINOR_OSS(card->number, SNDRV_MINOR_OSS_DMFM);
83 break;
84 case SNDRV_OSS_DEVICE_TYPE_SNDSTAT:
85 minor = SNDRV_MINOR_OSS_SNDSTAT;
86 break;
87 default:
88 return -EINVAL;
90 snd_assert(minor >= 0 && minor < SNDRV_OS_MINORS, return -EINVAL);
91 return minor;
94 int snd_register_oss_device(int type, snd_card_t * card, int dev, snd_minor_t * reg, const char *name)
96 int minor = snd_oss_kernel_minor(type, card, dev);
97 int minor_unit;
98 snd_minor_t *preg;
99 int cidx = SNDRV_MINOR_OSS_CARD(minor);
100 int track2 = -1;
101 int register1 = -1, register2 = -1;
103 if (minor < 0)
104 return minor;
105 preg = (snd_minor_t *)kmalloc(sizeof(snd_minor_t), GFP_KERNEL);
106 if (preg == NULL)
107 return -ENOMEM;
108 *preg = *reg;
109 preg->number = minor;
110 preg->device = dev;
111 preg->dev = NULL;
112 down(&sound_oss_mutex);
113 list_add_tail(&preg->list, &snd_oss_minors_hash[cidx]);
114 minor_unit = SNDRV_MINOR_OSS_DEVICE(minor);
115 switch (minor_unit) {
116 case SNDRV_MINOR_OSS_PCM:
117 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_AUDIO);
118 break;
119 case SNDRV_MINOR_OSS_MIDI:
120 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI);
121 break;
122 case SNDRV_MINOR_OSS_MIDI1:
123 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI1);
124 break;
126 register1 = register_sound_special(reg->f_ops, minor);
127 if (register1 != minor)
128 goto __end;
129 if (track2 >= 0) {
130 register2 = register_sound_special(reg->f_ops, track2);
131 if (register2 != track2)
132 goto __end;
134 up(&sound_oss_mutex);
135 return 0;
137 __end:
138 if (register2 >= 0)
139 unregister_sound_special(register2);
140 if (register1 >= 0)
141 unregister_sound_special(register1);
142 list_del(&preg->list);
143 up(&sound_oss_mutex);
144 kfree(preg);
145 return -EBUSY;
148 int snd_unregister_oss_device(int type, snd_card_t * card, int dev)
150 int minor = snd_oss_kernel_minor(type, card, dev);
151 int cidx = SNDRV_MINOR_OSS_CARD(minor);
152 int track2 = -1;
153 snd_minor_t *mptr;
155 if (minor < 0)
156 return minor;
157 down(&sound_oss_mutex);
158 mptr = snd_oss_minor_search(minor);
159 if (mptr == NULL) {
160 up(&sound_oss_mutex);
161 return -ENOENT;
163 unregister_sound_special(minor);
164 switch (SNDRV_MINOR_OSS_DEVICE(minor)) {
165 case SNDRV_MINOR_OSS_PCM:
166 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_AUDIO);
167 break;
168 case SNDRV_MINOR_OSS_MIDI:
169 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI);
170 break;
171 case SNDRV_MINOR_OSS_MIDI1:
172 track2 = SNDRV_MINOR_OSS(cidx, SNDRV_MINOR_OSS_DMMIDI1);
173 break;
175 if (track2 >= 0)
176 unregister_sound_special(track2);
177 list_del(&mptr->list);
178 up(&sound_oss_mutex);
179 kfree(mptr);
180 return 0;
184 * INFO PART
187 static snd_info_entry_t *snd_minor_info_oss_entry = NULL;
189 static void snd_minor_info_oss_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer)
191 int card, dev;
192 struct list_head *list;
193 snd_minor_t *mptr;
195 down(&sound_oss_mutex);
196 for (card = 0; card < SNDRV_CARDS; card++) {
197 list_for_each(list, &snd_oss_minors_hash[card]) {
198 mptr = list_entry(list, snd_minor_t, list);
199 dev = SNDRV_MINOR_OSS_DEVICE(mptr->number);
200 if (dev != SNDRV_MINOR_OSS_SNDSTAT &&
201 dev != SNDRV_MINOR_OSS_SEQUENCER &&
202 dev != SNDRV_MINOR_OSS_MUSIC)
203 snd_iprintf(buffer, "%3i: [%i-%2i]: %s\n", mptr->number, card, dev, mptr->comment);
204 else
205 snd_iprintf(buffer, "%3i: : %s\n", mptr->number, mptr->comment);
208 up(&sound_oss_mutex);
211 int __init snd_minor_info_oss_init(void)
213 snd_info_entry_t *entry;
215 entry = snd_info_create_module_entry(THIS_MODULE, "devices", snd_oss_root);
216 if (entry) {
217 entry->content = SNDRV_INFO_CONTENT_TEXT;
218 entry->c.text.read_size = PAGE_SIZE;
219 entry->c.text.read = snd_minor_info_oss_read;
220 if (snd_info_register(entry) < 0) {
221 snd_info_free_entry(entry);
222 entry = NULL;
225 snd_minor_info_oss_entry = entry;
226 return 0;
229 int __exit snd_minor_info_oss_done(void)
231 if (snd_minor_info_oss_entry)
232 snd_info_unregister(snd_minor_info_oss_entry);
233 return 0;
236 int __init snd_oss_init_module(void)
238 int card;
240 for (card = 0; card < SNDRV_CARDS; card++)
241 INIT_LIST_HEAD(&snd_oss_minors_hash[card]);
242 return 0;
245 void snd_oss_cleanup_module(void)
249 #endif /* CONFIG_SND_OSSEMUL */