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 /* This port is for asynchronous transaction. */
17 if (substream->number == 0)
20 err = snd_dg00x_stream_lock_try(dg00x);
24 mutex_lock(&dg00x->mutex);
25 dg00x->substreams_counter++;
26 err = snd_dg00x_stream_start_duplex(dg00x, 0);
27 mutex_unlock(&dg00x->mutex);
29 snd_dg00x_stream_lock_release(dg00x);
34 static int midi_close(struct snd_rawmidi_substream *substream)
36 struct snd_dg00x *dg00x = substream->rmidi->private_data;
38 /* This port is for asynchronous transaction. */
39 if (substream->number == 0)
42 mutex_lock(&dg00x->mutex);
43 dg00x->substreams_counter--;
44 snd_dg00x_stream_stop_duplex(dg00x);
45 mutex_unlock(&dg00x->mutex);
47 snd_dg00x_stream_lock_release(dg00x);
51 static void midi_capture_trigger(struct snd_rawmidi_substream *substrm, int up)
53 struct snd_dg00x *dg00x = substrm->rmidi->private_data;
56 spin_lock_irqsave(&dg00x->lock, flags);
58 /* This port is for asynchronous transaction. */
59 if (substrm->number == 0) {
61 dg00x->in_control = substrm;
63 dg00x->in_control = NULL;
66 amdtp_dot_midi_trigger(&dg00x->tx_stream,
67 substrm->number - 1, substrm);
69 amdtp_dot_midi_trigger(&dg00x->tx_stream,
70 substrm->number - 1, NULL);
73 spin_unlock_irqrestore(&dg00x->lock, flags);
76 static void midi_playback_trigger(struct snd_rawmidi_substream *substrm, int up)
78 struct snd_dg00x *dg00x = substrm->rmidi->private_data;
81 spin_lock_irqsave(&dg00x->lock, flags);
83 /* This port is for asynchronous transaction. */
84 if (substrm->number == 0) {
86 snd_fw_async_midi_port_run(&dg00x->out_control,
90 amdtp_dot_midi_trigger(&dg00x->rx_stream,
91 substrm->number - 1, substrm);
93 amdtp_dot_midi_trigger(&dg00x->rx_stream,
94 substrm->number - 1, NULL);
97 spin_unlock_irqrestore(&dg00x->lock, flags);
100 static struct snd_rawmidi_ops midi_capture_ops = {
103 .trigger = midi_capture_trigger,
106 static struct snd_rawmidi_ops midi_playback_ops = {
109 .trigger = midi_playback_trigger,
112 static void set_midi_substream_names(struct snd_dg00x *dg00x,
113 struct snd_rawmidi_str *str)
115 struct snd_rawmidi_substream *subs;
117 list_for_each_entry(subs, &str->substreams, list) {
118 if (subs->number > 0)
119 snprintf(subs->name, sizeof(subs->name),
121 dg00x->card->shortname, subs->number);
123 /* This port is for asynchronous transaction. */
124 snprintf(subs->name, sizeof(subs->name),
126 dg00x->card->shortname);
130 int snd_dg00x_create_midi_devices(struct snd_dg00x *dg00x)
132 struct snd_rawmidi *rmidi;
133 struct snd_rawmidi_str *str;
136 err = snd_rawmidi_new(dg00x->card, dg00x->card->driver, 0,
137 DOT_MIDI_OUT_PORTS + 1, DOT_MIDI_IN_PORTS + 1, &rmidi);
141 snprintf(rmidi->name, sizeof(rmidi->name),
142 "%s MIDI", dg00x->card->shortname);
143 rmidi->private_data = dg00x;
145 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
146 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
148 str = &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT];
149 set_midi_substream_names(dg00x, str);
151 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT;
152 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT,
154 str = &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT];
155 set_midi_substream_names(dg00x, str);
157 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_DUPLEX;