[PATCH] fix semaphore handling in __unregister_chrdev_region
[linux/fpc-iii.git] / sound / drivers / virmidi.c
blob5937711e950562c922b5fcb9600c00edc2bfe77b
1 /*
2 * Dummy soundcard for virtual rawmidi devices
4 * Copyright (c) 2000 by Takashi Iwai <tiwai@suse.de>
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
23 * VIRTUAL RAW MIDI DEVICE CARDS
25 * This dummy card contains up to 4 virtual rawmidi devices.
26 * They are not real rawmidi devices but just associated with sequencer
27 * clients, so that any input/output sources can be connected as a raw
28 * MIDI device arbitrary.
29 * Also, multiple access is allowed to a single rawmidi device.
31 * Typical usage is like following:
32 * - Load snd-virmidi module.
33 * # modprobe snd-virmidi index=2
34 * Then, sequencer clients 72:0 to 75:0 will be created, which are
35 * mapped from /dev/snd/midiC1D0 to /dev/snd/midiC1D3, respectively.
37 * - Connect input/output via aconnect.
38 * % aconnect 64:0 72:0 # keyboard input redirection 64:0 -> 72:0
39 * % aconnect 72:0 65:0 # output device redirection 72:0 -> 65:0
41 * - Run application using a midi device (eg. /dev/snd/midiC1D0)
44 #include <sound/driver.h>
45 #include <linux/init.h>
46 #include <linux/wait.h>
47 #include <linux/sched.h>
48 #include <linux/moduleparam.h>
49 #include <sound/core.h>
50 #include <sound/seq_kernel.h>
51 #include <sound/seq_virmidi.h>
52 #include <sound/initval.h>
54 /* hack: OSS defines midi_devs, so undefine it (versioned symbols) */
55 #undef midi_devs
57 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
58 MODULE_DESCRIPTION("Dummy soundcard for virtual rawmidi devices");
59 MODULE_LICENSE("GPL");
60 MODULE_SUPPORTED_DEVICE("{{ALSA,Virtual rawmidi device}}");
62 #define MAX_MIDI_DEVICES 8
64 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
65 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
66 static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0};
67 static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 4};
69 module_param_array(index, int, NULL, 0444);
70 MODULE_PARM_DESC(index, "Index value for virmidi soundcard.");
71 module_param_array(id, charp, NULL, 0444);
72 MODULE_PARM_DESC(id, "ID string for virmidi soundcard.");
73 module_param_array(enable, bool, NULL, 0444);
74 MODULE_PARM_DESC(enable, "Enable this soundcard.");
75 module_param_array(midi_devs, int, NULL, 0444);
76 MODULE_PARM_DESC(midi_devs, "MIDI devices # (1-8)");
78 typedef struct snd_card_virmidi {
79 snd_card_t *card;
80 snd_rawmidi_t *midi[MAX_MIDI_DEVICES];
81 } snd_card_virmidi_t;
83 static snd_card_t *snd_virmidi_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
86 static int __init snd_card_virmidi_probe(int dev)
88 snd_card_t *card;
89 struct snd_card_virmidi *vmidi;
90 int idx, err;
92 if (!enable[dev])
93 return -ENODEV;
94 card = snd_card_new(index[dev], id[dev], THIS_MODULE,
95 sizeof(struct snd_card_virmidi));
96 if (card == NULL)
97 return -ENOMEM;
98 vmidi = (struct snd_card_virmidi *)card->private_data;
99 vmidi->card = card;
101 if (midi_devs[dev] > MAX_MIDI_DEVICES) {
102 snd_printk("too much midi devices for virmidi %d: force to use %d\n", dev, MAX_MIDI_DEVICES);
103 midi_devs[dev] = MAX_MIDI_DEVICES;
105 for (idx = 0; idx < midi_devs[dev]; idx++) {
106 snd_rawmidi_t *rmidi;
107 snd_virmidi_dev_t *rdev;
108 if ((err = snd_virmidi_new(card, idx, &rmidi)) < 0)
109 goto __nodev;
110 rdev = rmidi->private_data;
111 vmidi->midi[idx] = rmidi;
112 strcpy(rmidi->name, "Virtual Raw MIDI");
113 rdev->seq_mode = SNDRV_VIRMIDI_SEQ_DISPATCH;
116 strcpy(card->driver, "VirMIDI");
117 strcpy(card->shortname, "VirMIDI");
118 sprintf(card->longname, "Virtual MIDI Card %i", dev + 1);
119 if ((err = snd_card_register(card)) == 0) {
120 snd_virmidi_cards[dev] = card;
121 return 0;
123 __nodev:
124 snd_card_free(card);
125 return err;
128 static int __init alsa_card_virmidi_init(void)
130 int dev, cards;
132 for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
133 if (snd_card_virmidi_probe(dev) < 0) {
134 #ifdef MODULE
135 printk(KERN_ERR "Card-VirMIDI #%i not found or device busy\n", dev + 1);
136 #endif
137 break;
139 cards++;
141 if (!cards) {
142 #ifdef MODULE
143 printk(KERN_ERR "Card-VirMIDI soundcard not found or device busy\n");
144 #endif
145 return -ENODEV;
147 return 0;
150 static void __exit alsa_card_virmidi_exit(void)
152 int dev;
154 for (dev = 0; dev < SNDRV_CARDS; dev++)
155 snd_card_free(snd_virmidi_cards[dev]);
158 module_init(alsa_card_virmidi_init)
159 module_exit(alsa_card_virmidi_exit)