2 * Advanced Linux Sound Architecture
3 * Copyright (c) by Jaroslav Kysela <perex@perex.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 #ifdef CONFIG_SND_OSSEMUL
24 #if !defined(CONFIG_SOUND) && !(defined(MODULE) && defined(CONFIG_SOUND_MODULE))
25 #error "Enable the OSS soundcore multiplexer (CONFIG_SOUND) in the kernel."
28 #include <linux/init.h>
29 #include <linux/export.h>
30 #include <linux/slab.h>
31 #include <linux/time.h>
32 #include <sound/core.h>
33 #include <sound/minors.h>
34 #include <sound/info.h>
35 #include <linux/sound.h>
36 #include <linux/mutex.h>
38 #define SNDRV_OSS_MINORS 128
40 static struct snd_minor
*snd_oss_minors
[SNDRV_OSS_MINORS
];
41 static DEFINE_MUTEX(sound_oss_mutex
);
43 void *snd_lookup_oss_minor_data(unsigned int minor
, int type
)
45 struct snd_minor
*mreg
;
48 if (minor
>= ARRAY_SIZE(snd_oss_minors
))
50 mutex_lock(&sound_oss_mutex
);
51 mreg
= snd_oss_minors
[minor
];
52 if (mreg
&& mreg
->type
== type
)
53 private_data
= mreg
->private_data
;
56 mutex_unlock(&sound_oss_mutex
);
60 EXPORT_SYMBOL(snd_lookup_oss_minor_data
);
62 static int snd_oss_kernel_minor(int type
, struct snd_card
*card
, int dev
)
67 case SNDRV_OSS_DEVICE_TYPE_MIXER
:
68 if (snd_BUG_ON(!card
|| dev
< 0 || dev
> 1))
70 minor
= SNDRV_MINOR_OSS(card
->number
, (dev
? SNDRV_MINOR_OSS_MIXER1
: SNDRV_MINOR_OSS_MIXER
));
72 case SNDRV_OSS_DEVICE_TYPE_SEQUENCER
:
73 minor
= SNDRV_MINOR_OSS_SEQUENCER
;
75 case SNDRV_OSS_DEVICE_TYPE_MUSIC
:
76 minor
= SNDRV_MINOR_OSS_MUSIC
;
78 case SNDRV_OSS_DEVICE_TYPE_PCM
:
79 if (snd_BUG_ON(!card
|| dev
< 0 || dev
> 1))
81 minor
= SNDRV_MINOR_OSS(card
->number
, (dev
? SNDRV_MINOR_OSS_PCM1
: SNDRV_MINOR_OSS_PCM
));
83 case SNDRV_OSS_DEVICE_TYPE_MIDI
:
84 if (snd_BUG_ON(!card
|| dev
< 0 || dev
> 1))
86 minor
= SNDRV_MINOR_OSS(card
->number
, (dev
? SNDRV_MINOR_OSS_MIDI1
: SNDRV_MINOR_OSS_MIDI
));
88 case SNDRV_OSS_DEVICE_TYPE_DMFM
:
89 minor
= SNDRV_MINOR_OSS(card
->number
, SNDRV_MINOR_OSS_DMFM
);
91 case SNDRV_OSS_DEVICE_TYPE_SNDSTAT
:
92 minor
= SNDRV_MINOR_OSS_SNDSTAT
;
97 if (minor
< 0 || minor
>= SNDRV_OSS_MINORS
)
102 int snd_register_oss_device(int type
, struct snd_card
*card
, int dev
,
103 const struct file_operations
*f_ops
, void *private_data
,
106 int minor
= snd_oss_kernel_minor(type
, card
, dev
);
108 struct snd_minor
*preg
;
109 int cidx
= SNDRV_MINOR_OSS_CARD(minor
);
111 int register1
= -1, register2
= -1;
112 struct device
*carddev
= snd_card_get_device_link(card
);
114 if (card
&& card
->number
>= 8)
115 return 0; /* ignore silently */
118 preg
= kmalloc(sizeof(struct snd_minor
), GFP_KERNEL
);
122 preg
->card
= card
? card
->number
: -1;
125 preg
->private_data
= private_data
;
126 mutex_lock(&sound_oss_mutex
);
127 snd_oss_minors
[minor
] = preg
;
128 minor_unit
= SNDRV_MINOR_OSS_DEVICE(minor
);
129 switch (minor_unit
) {
130 case SNDRV_MINOR_OSS_PCM
:
131 track2
= SNDRV_MINOR_OSS(cidx
, SNDRV_MINOR_OSS_AUDIO
);
133 case SNDRV_MINOR_OSS_MIDI
:
134 track2
= SNDRV_MINOR_OSS(cidx
, SNDRV_MINOR_OSS_DMMIDI
);
136 case SNDRV_MINOR_OSS_MIDI1
:
137 track2
= SNDRV_MINOR_OSS(cidx
, SNDRV_MINOR_OSS_DMMIDI1
);
140 register1
= register_sound_special_device(f_ops
, minor
, carddev
);
141 if (register1
!= minor
)
144 register2
= register_sound_special_device(f_ops
, track2
,
146 if (register2
!= track2
)
148 snd_oss_minors
[track2
] = preg
;
150 mutex_unlock(&sound_oss_mutex
);
155 unregister_sound_special(register2
);
157 unregister_sound_special(register1
);
158 snd_oss_minors
[minor
] = NULL
;
159 mutex_unlock(&sound_oss_mutex
);
164 EXPORT_SYMBOL(snd_register_oss_device
);
166 int snd_unregister_oss_device(int type
, struct snd_card
*card
, int dev
)
168 int minor
= snd_oss_kernel_minor(type
, card
, dev
);
169 int cidx
= SNDRV_MINOR_OSS_CARD(minor
);
171 struct snd_minor
*mptr
;
173 if (card
&& card
->number
>= 8)
177 mutex_lock(&sound_oss_mutex
);
178 mptr
= snd_oss_minors
[minor
];
180 mutex_unlock(&sound_oss_mutex
);
183 unregister_sound_special(minor
);
184 switch (SNDRV_MINOR_OSS_DEVICE(minor
)) {
185 case SNDRV_MINOR_OSS_PCM
:
186 track2
= SNDRV_MINOR_OSS(cidx
, SNDRV_MINOR_OSS_AUDIO
);
188 case SNDRV_MINOR_OSS_MIDI
:
189 track2
= SNDRV_MINOR_OSS(cidx
, SNDRV_MINOR_OSS_DMMIDI
);
191 case SNDRV_MINOR_OSS_MIDI1
:
192 track2
= SNDRV_MINOR_OSS(cidx
, SNDRV_MINOR_OSS_DMMIDI1
);
196 unregister_sound_special(track2
);
197 snd_oss_minors
[track2
] = NULL
;
199 snd_oss_minors
[minor
] = NULL
;
200 mutex_unlock(&sound_oss_mutex
);
205 EXPORT_SYMBOL(snd_unregister_oss_device
);
211 #ifdef CONFIG_PROC_FS
213 static struct snd_info_entry
*snd_minor_info_oss_entry
;
215 static const char *snd_oss_device_type_name(int type
)
218 case SNDRV_OSS_DEVICE_TYPE_MIXER
:
220 case SNDRV_OSS_DEVICE_TYPE_SEQUENCER
:
221 case SNDRV_OSS_DEVICE_TYPE_MUSIC
:
223 case SNDRV_OSS_DEVICE_TYPE_PCM
:
224 return "digital audio";
225 case SNDRV_OSS_DEVICE_TYPE_MIDI
:
227 case SNDRV_OSS_DEVICE_TYPE_DMFM
:
228 return "hardware dependent";
234 static void snd_minor_info_oss_read(struct snd_info_entry
*entry
,
235 struct snd_info_buffer
*buffer
)
238 struct snd_minor
*mptr
;
240 mutex_lock(&sound_oss_mutex
);
241 for (minor
= 0; minor
< SNDRV_OSS_MINORS
; ++minor
) {
242 if (!(mptr
= snd_oss_minors
[minor
]))
245 snd_iprintf(buffer
, "%3i: [%i-%2i]: %s\n", minor
,
246 mptr
->card
, mptr
->device
,
247 snd_oss_device_type_name(mptr
->type
));
249 snd_iprintf(buffer
, "%3i: : %s\n", minor
,
250 snd_oss_device_type_name(mptr
->type
));
252 mutex_unlock(&sound_oss_mutex
);
256 int __init
snd_minor_info_oss_init(void)
258 struct snd_info_entry
*entry
;
260 entry
= snd_info_create_module_entry(THIS_MODULE
, "devices", snd_oss_root
);
262 entry
->c
.text
.read
= snd_minor_info_oss_read
;
263 if (snd_info_register(entry
) < 0) {
264 snd_info_free_entry(entry
);
268 snd_minor_info_oss_entry
= entry
;
272 int __exit
snd_minor_info_oss_done(void)
274 snd_info_free_entry(snd_minor_info_oss_entry
);
277 #endif /* CONFIG_PROC_FS */
279 #endif /* CONFIG_SND_OSSEMUL */