sound.c (97f2aab6698f3ab2552c41c1024a65ffd0763a6d) sound.c (512bbd6a85230f16389f0dd51925472e72fc8a91)
1/*
2 * Advanced Linux Sound Architecture
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 *
5 *
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

--- 94 unchanged lines hidden (view full) ---

103 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
104 default: return;
105 }
106 request_module(str);
107}
108
109#endif /* request_module support */
110
1/*
2 * Advanced Linux Sound Architecture
3 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 *
5 *
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

--- 94 unchanged lines hidden (view full) ---

103 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
104 default: return;
105 }
106 request_module(str);
107}
108
109#endif /* request_module support */
110
111static snd_minor_t *snd_minor_search(int minor)
111static struct snd_minor *snd_minor_search(int minor)
112{
113 struct list_head *list;
112{
113 struct list_head *list;
114 snd_minor_t *mptr;
114 struct snd_minor *mptr;
115
116 list_for_each(list, &snd_minors_hash[SNDRV_MINOR_CARD(minor)]) {
115
116 list_for_each(list, &snd_minors_hash[SNDRV_MINOR_CARD(minor)]) {
117 mptr = list_entry(list, snd_minor_t, list);
117 mptr = list_entry(list, struct snd_minor, list);
118 if (mptr->number == minor)
119 return mptr;
120 }
121 return NULL;
122}
123
124static int snd_open(struct inode *inode, struct file *file)
125{
126 int minor = iminor(inode);
127 int card = SNDRV_MINOR_CARD(minor);
128 int dev = SNDRV_MINOR_DEVICE(minor);
118 if (mptr->number == minor)
119 return mptr;
120 }
121 return NULL;
122}
123
124static int snd_open(struct inode *inode, struct file *file)
125{
126 int minor = iminor(inode);
127 int card = SNDRV_MINOR_CARD(minor);
128 int dev = SNDRV_MINOR_DEVICE(minor);
129 snd_minor_t *mptr = NULL;
129 struct snd_minor *mptr = NULL;
130 struct file_operations *old_fops;
131 int err = 0;
132
133 if (dev != SNDRV_MINOR_GLOBAL) {
134 if (snd_cards[card] == NULL) {
135#ifdef CONFIG_KMOD
136 snd_request_card(card);
137 if (snd_cards[card] == NULL)

--- 21 unchanged lines hidden (view full) ---

159}
160
161static struct file_operations snd_fops =
162{
163 .owner = THIS_MODULE,
164 .open = snd_open
165};
166
130 struct file_operations *old_fops;
131 int err = 0;
132
133 if (dev != SNDRV_MINOR_GLOBAL) {
134 if (snd_cards[card] == NULL) {
135#ifdef CONFIG_KMOD
136 snd_request_card(card);
137 if (snd_cards[card] == NULL)

--- 21 unchanged lines hidden (view full) ---

159}
160
161static struct file_operations snd_fops =
162{
163 .owner = THIS_MODULE,
164 .open = snd_open
165};
166
167static int snd_kernel_minor(int type, snd_card_t * card, int dev)
167static int snd_kernel_minor(int type, struct snd_card *card, int dev)
168{
169 int minor;
170
171 switch (type) {
172 case SNDRV_DEVICE_TYPE_SEQUENCER:
173 case SNDRV_DEVICE_TYPE_TIMER:
174 minor = type;
175 break;

--- 15 unchanged lines hidden (view full) ---

191 return minor;
192}
193
194/**
195 * snd_register_device - Register the ALSA device file for the card
196 * @type: the device type, SNDRV_DEVICE_TYPE_XXX
197 * @card: the card instance
198 * @dev: the device index
168{
169 int minor;
170
171 switch (type) {
172 case SNDRV_DEVICE_TYPE_SEQUENCER:
173 case SNDRV_DEVICE_TYPE_TIMER:
174 minor = type;
175 break;

--- 15 unchanged lines hidden (view full) ---

191 return minor;
192}
193
194/**
195 * snd_register_device - Register the ALSA device file for the card
196 * @type: the device type, SNDRV_DEVICE_TYPE_XXX
197 * @card: the card instance
198 * @dev: the device index
199 * @reg: the snd_minor_t record
199 * @reg: the struct snd_minor record
200 * @name: the device file name
201 *
202 * Registers an ALSA device file for the given card.
203 * The operators have to be set in reg parameter.
204 *
205 * Retrurns zero if successful, or a negative error code on failure.
206 */
200 * @name: the device file name
201 *
202 * Registers an ALSA device file for the given card.
203 * The operators have to be set in reg parameter.
204 *
205 * Retrurns zero if successful, or a negative error code on failure.
206 */
207int snd_register_device(int type, snd_card_t * card, int dev, snd_minor_t * reg, const char *name)
207int snd_register_device(int type, struct snd_card *card, int dev, struct snd_minor * reg, const char *name)
208{
209 int minor = snd_kernel_minor(type, card, dev);
208{
209 int minor = snd_kernel_minor(type, card, dev);
210 snd_minor_t *preg;
210 struct snd_minor *preg;
211 struct device *device = NULL;
212
213 if (minor < 0)
214 return minor;
215 snd_assert(name, return -EINVAL);
211 struct device *device = NULL;
212
213 if (minor < 0)
214 return minor;
215 snd_assert(name, return -EINVAL);
216 preg = (snd_minor_t *)kmalloc(sizeof(snd_minor_t) + strlen(name) + 1, GFP_KERNEL);
216 preg = kmalloc(sizeof(struct snd_minor) + strlen(name) + 1, GFP_KERNEL);
217 if (preg == NULL)
218 return -ENOMEM;
219 *preg = *reg;
220 preg->number = minor;
221 preg->device = dev;
222 strcpy(preg->name, name);
223 down(&sound_mutex);
224 if (snd_minor_search(minor)) {

--- 18 unchanged lines hidden (view full) ---

243 * @card: the card instance
244 * @dev: the device index
245 *
246 * Unregisters the device file already registered via
247 * snd_register_device().
248 *
249 * Returns zero if sucecessful, or a negative error code on failure
250 */
217 if (preg == NULL)
218 return -ENOMEM;
219 *preg = *reg;
220 preg->number = minor;
221 preg->device = dev;
222 strcpy(preg->name, name);
223 down(&sound_mutex);
224 if (snd_minor_search(minor)) {

--- 18 unchanged lines hidden (view full) ---

243 * @card: the card instance
244 * @dev: the device index
245 *
246 * Unregisters the device file already registered via
247 * snd_register_device().
248 *
249 * Returns zero if sucecessful, or a negative error code on failure
250 */
251int snd_unregister_device(int type, snd_card_t * card, int dev)
251int snd_unregister_device(int type, struct snd_card *card, int dev)
252{
253 int minor = snd_kernel_minor(type, card, dev);
252{
253 int minor = snd_kernel_minor(type, card, dev);
254 snd_minor_t *mptr;
254 struct snd_minor *mptr;
255
256 if (minor < 0)
257 return minor;
258 down(&sound_mutex);
259 if ((mptr = snd_minor_search(minor)) == NULL) {
260 up(&sound_mutex);
261 return -EINVAL;
262 }

--- 7 unchanged lines hidden (view full) ---

270 kfree(mptr);
271 return 0;
272}
273
274/*
275 * INFO PART
276 */
277
255
256 if (minor < 0)
257 return minor;
258 down(&sound_mutex);
259 if ((mptr = snd_minor_search(minor)) == NULL) {
260 up(&sound_mutex);
261 return -EINVAL;
262 }

--- 7 unchanged lines hidden (view full) ---

270 kfree(mptr);
271 return 0;
272}
273
274/*
275 * INFO PART
276 */
277
278static snd_info_entry_t *snd_minor_info_entry = NULL;
278static struct snd_info_entry *snd_minor_info_entry = NULL;
279
279
280static void snd_minor_info_read(snd_info_entry_t *entry, snd_info_buffer_t * buffer)
280static void snd_minor_info_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
281{
282 int card, device;
283 struct list_head *list;
281{
282 int card, device;
283 struct list_head *list;
284 snd_minor_t *mptr;
284 struct snd_minor *mptr;
285
286 down(&sound_mutex);
287 for (card = 0; card < SNDRV_CARDS; card++) {
288 list_for_each(list, &snd_minors_hash[card]) {
285
286 down(&sound_mutex);
287 for (card = 0; card < SNDRV_CARDS; card++) {
288 list_for_each(list, &snd_minors_hash[card]) {
289 mptr = list_entry(list, snd_minor_t, list);
289 mptr = list_entry(list, struct snd_minor, list);
290 if (SNDRV_MINOR_DEVICE(mptr->number) != SNDRV_MINOR_GLOBAL) {
291 if ((device = mptr->device) >= 0)
292 snd_iprintf(buffer, "%3i: [%i-%2i]: %s\n", mptr->number, card, device, mptr->comment);
293 else
294 snd_iprintf(buffer, "%3i: [%i] : %s\n", mptr->number, card, mptr->comment);
295 } else {
296 snd_iprintf(buffer, "%3i: : %s\n", mptr->number, mptr->comment);
297 }
298 }
299 }
300 up(&sound_mutex);
301}
302
303int __init snd_minor_info_init(void)
304{
290 if (SNDRV_MINOR_DEVICE(mptr->number) != SNDRV_MINOR_GLOBAL) {
291 if ((device = mptr->device) >= 0)
292 snd_iprintf(buffer, "%3i: [%i-%2i]: %s\n", mptr->number, card, device, mptr->comment);
293 else
294 snd_iprintf(buffer, "%3i: [%i] : %s\n", mptr->number, card, mptr->comment);
295 } else {
296 snd_iprintf(buffer, "%3i: : %s\n", mptr->number, mptr->comment);
297 }
298 }
299 }
300 up(&sound_mutex);
301}
302
303int __init snd_minor_info_init(void)
304{
305 snd_info_entry_t *entry;
305 struct snd_info_entry *entry;
306
307 entry = snd_info_create_module_entry(THIS_MODULE, "devices", NULL);
308 if (entry) {
309 entry->c.text.read_size = PAGE_SIZE;
310 entry->c.text.read = snd_minor_info_read;
311 if (snd_info_register(entry) < 0) {
312 snd_info_free_entry(entry);
313 entry = NULL;

--- 172 unchanged lines hidden ---
306
307 entry = snd_info_create_module_entry(THIS_MODULE, "devices", NULL);
308 if (entry) {
309 entry->c.text.read_size = PAGE_SIZE;
310 entry->c.text.read = snd_minor_info_read;
311 if (snd_info_register(entry) < 0) {
312 snd_info_free_entry(entry);
313 entry = NULL;

--- 172 unchanged lines hidden ---