]> bbs.cooldavid.org Git - net-next-2.6.git/blame - sound/drivers/virmidi.c
xps: Transmit Packet Steering
[net-next-2.6.git] / sound / drivers / virmidi.c
CommitLineData
1da177e4
LT
1/*
2 * Dummy soundcard for virtual rawmidi devices
3 *
4 * Copyright (c) 2000 by Takashi Iwai <tiwai@suse.de>
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
9 * (at your option) any later version.
10 *
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.
15 *
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
19 *
20 */
21
22/*
23 * VIRTUAL RAW MIDI DEVICE CARDS
24 *
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.
30 *
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.
36 *
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
40 *
41 * - Run application using a midi device (eg. /dev/snd/midiC1D0)
42 */
43
1da177e4
LT
44#include <linux/init.h>
45#include <linux/wait.h>
3564fbb8
TI
46#include <linux/err.h>
47#include <linux/platform_device.h>
1da177e4
LT
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>
53
54/* hack: OSS defines midi_devs, so undefine it (versioned symbols) */
55#undef midi_devs
56
57MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
58MODULE_DESCRIPTION("Dummy soundcard for virtual rawmidi devices");
59MODULE_LICENSE("GPL");
60MODULE_SUPPORTED_DEVICE("{{ALSA,Virtual rawmidi device}}");
61
204bdb1b 62#define MAX_MIDI_DEVICES 4
1da177e4
LT
63
64static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
65static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
c5533bf3 66static int enable[SNDRV_CARDS] = {1, [1 ... (SNDRV_CARDS - 1)] = 0};
1da177e4
LT
67static int midi_devs[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 4};
68
69module_param_array(index, int, NULL, 0444);
70MODULE_PARM_DESC(index, "Index value for virmidi soundcard.");
71module_param_array(id, charp, NULL, 0444);
72MODULE_PARM_DESC(id, "ID string for virmidi soundcard.");
73module_param_array(enable, bool, NULL, 0444);
74MODULE_PARM_DESC(enable, "Enable this soundcard.");
75module_param_array(midi_devs, int, NULL, 0444);
204bdb1b 76MODULE_PARM_DESC(midi_devs, "MIDI devices # (1-4)");
1da177e4 77
4a4d2cfd
TI
78struct snd_card_virmidi {
79 struct snd_card *card;
80 struct snd_rawmidi *midi[MAX_MIDI_DEVICES];
81};
1da177e4 82
f7a9275d
CL
83static struct platform_device *devices[SNDRV_CARDS];
84
1da177e4 85
788c6043 86static int __devinit snd_virmidi_probe(struct platform_device *devptr)
1da177e4 87{
4a4d2cfd 88 struct snd_card *card;
1da177e4
LT
89 struct snd_card_virmidi *vmidi;
90 int idx, err;
3564fbb8 91 int dev = devptr->id;
1da177e4 92
bd7dd77c
TI
93 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
94 sizeof(struct snd_card_virmidi), &card);
95 if (err < 0)
96 return err;
9fe856e4 97 vmidi = card->private_data;
1da177e4
LT
98 vmidi->card = card;
99
100 if (midi_devs[dev] > MAX_MIDI_DEVICES) {
45203832
TI
101 snd_printk(KERN_WARNING
102 "too much midi devices for virmidi %d: "
103 "force to use %d\n", dev, MAX_MIDI_DEVICES);
1da177e4
LT
104 midi_devs[dev] = MAX_MIDI_DEVICES;
105 }
106 for (idx = 0; idx < midi_devs[dev]; idx++) {
4a4d2cfd
TI
107 struct snd_rawmidi *rmidi;
108 struct snd_virmidi_dev *rdev;
1da177e4
LT
109 if ((err = snd_virmidi_new(card, idx, &rmidi)) < 0)
110 goto __nodev;
111 rdev = rmidi->private_data;
112 vmidi->midi[idx] = rmidi;
113 strcpy(rmidi->name, "Virtual Raw MIDI");
114 rdev->seq_mode = SNDRV_VIRMIDI_SEQ_DISPATCH;
115 }
116
117 strcpy(card->driver, "VirMIDI");
118 strcpy(card->shortname, "VirMIDI");
119 sprintf(card->longname, "Virtual MIDI Card %i", dev + 1);
16dab54b 120
3564fbb8 121 snd_card_set_dev(card, &devptr->dev);
16dab54b 122
1da177e4 123 if ((err = snd_card_register(card)) == 0) {
3564fbb8 124 platform_set_drvdata(devptr, card);
1da177e4
LT
125 return 0;
126 }
127 __nodev:
128 snd_card_free(card);
129 return err;
130}
131
788c6043 132static int __devexit snd_virmidi_remove(struct platform_device *devptr)
1da177e4 133{
3564fbb8
TI
134 snd_card_free(platform_get_drvdata(devptr));
135 platform_set_drvdata(devptr, NULL);
136 return 0;
137}
1da177e4 138
3564fbb8
TI
139#define SND_VIRMIDI_DRIVER "snd_virmidi"
140
141static struct platform_driver snd_virmidi_driver = {
142 .probe = snd_virmidi_probe,
788c6043 143 .remove = __devexit_p(snd_virmidi_remove),
3564fbb8
TI
144 .driver = {
145 .name = SND_VIRMIDI_DRIVER
146 },
147};
148
bdec0c72 149static void snd_virmidi_unregister_all(void)
f7a9275d
CL
150{
151 int i;
152
153 for (i = 0; i < ARRAY_SIZE(devices); ++i)
154 platform_device_unregister(devices[i]);
155 platform_driver_unregister(&snd_virmidi_driver);
156}
157
3564fbb8
TI
158static int __init alsa_card_virmidi_init(void)
159{
160 int i, cards, err;
161
162 if ((err = platform_driver_register(&snd_virmidi_driver)) < 0)
163 return err;
164
165 cards = 0;
8278ca8f 166 for (i = 0; i < SNDRV_CARDS; i++) {
3564fbb8 167 struct platform_device *device;
8278ca8f
TI
168 if (! enable[i])
169 continue;
3564fbb8
TI
170 device = platform_device_register_simple(SND_VIRMIDI_DRIVER,
171 i, NULL, 0);
a182ee98
RH
172 if (IS_ERR(device))
173 continue;
7152447d
RH
174 if (!platform_get_drvdata(device)) {
175 platform_device_unregister(device);
176 continue;
177 }
f7a9275d 178 devices[i] = device;
1da177e4
LT
179 cards++;
180 }
181 if (!cards) {
182#ifdef MODULE
183 printk(KERN_ERR "Card-VirMIDI soundcard not found or device busy\n");
184#endif
a182ee98
RH
185 snd_virmidi_unregister_all();
186 return -ENODEV;
1da177e4
LT
187 }
188 return 0;
189}
190
191static void __exit alsa_card_virmidi_exit(void)
192{
f7a9275d 193 snd_virmidi_unregister_all();
1da177e4
LT
194}
195
196module_init(alsa_card_virmidi_init)
197module_exit(alsa_card_virmidi_exit)