2 * digi00x-midi.h - a part of driver for Digidesign Digi 002/003 family
4 * Copyright (c) 2014-2015 Takashi Sakamoto
6 * Licensed under the terms of the GNU General Public License, version 2.
11 static int midi_open(struct snd_rawmidi_substream *substream)
13 struct snd_dg00x *dg00x = substream->rmidi->private_data;
16 err = snd_dg00x_stream_lock_try(dg00x);
20 mutex_lock(&dg00x->mutex);
21 dg00x->substreams_counter++;
22 err = snd_dg00x_stream_start_duplex(dg00x, 0);
23 mutex_unlock(&dg00x->mutex);
25 snd_dg00x_stream_lock_release(dg00x);
30 static int midi_close(struct snd_rawmidi_substream *substream)
32 struct snd_dg00x *dg00x = substream->rmidi->private_data;
34 mutex_lock(&dg00x->mutex);
35 dg00x->substreams_counter--;
36 snd_dg00x_stream_stop_duplex(dg00x);
37 mutex_unlock(&dg00x->mutex);
39 snd_dg00x_stream_lock_release(dg00x);
43 static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
45 struct snd_dg00x *dg00x = substrm->rmidi->private_data;
48 spin_lock_irqsave(&dg00x->lock, flags);
51 amdtp_dot_midi_trigger(&dg00x->tx_stream,
52 substrm->number, substrm);
54 amdtp_dot_midi_trigger(&dg00x->tx_stream,
55 substrm->number, NULL);
57 spin_unlock_irqrestore(&dg00x->lock, flags);
60 static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
62 struct snd_dg00x *dg00x = substrm->rmidi->private_data;
65 spin_lock_irqsave(&dg00x->lock, flags);
68 amdtp_dot_midi_trigger(&dg00x->rx_stream,
69 substrm->number, substrm);
71 amdtp_dot_midi_trigger(&dg00x->rx_stream,
72 substrm->number, NULL);
74 spin_unlock_irqrestore(&dg00x->lock, flags);
77 static struct snd_rawmidi_ops midi_capture_ops = {
80 .trigger = midi_capture_trigger,
83 static struct snd_rawmidi_ops midi_playback_ops = {
86 .trigger = midi_playback_trigger,
89 static void set_midi_substream_names(struct snd_dg00x *dg00x,
90 struct snd_rawmidi_str *str)
92 struct snd_rawmidi_substream *subs;
94 list_for_each_entry(subs, &str->substreams, list) {
95 snprintf(subs->name, sizeof(subs->name),
97 dg00x->card->shortname, subs->number + 1);
101 int snd_dg00x_create_midi_devices(struct snd_dg00x *dg00x)
103 struct snd_rawmidi *rmidi;
104 struct snd_rawmidi_str *str;
107 err = snd_rawmidi_new(dg00x->card, dg00x->card->driver, 0,
108 DOT_MIDI_OUT_PORTS, DOT_MIDI_IN_PORTS, &rmidi);
112 snprintf(rmidi->name, sizeof(rmidi->name),
113 "%s MIDI", dg00x->card->shortname);
114 rmidi->private_data = dg00x;
116 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
117 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
119 str = &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT];
120 set_midi_substream_names(dg00x, str);
122 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;
123 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
125 str = &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT];
126 set_midi_substream_names(dg00x, str);
128 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;