1 // SPDX-License-Identifier: GPL-2.0-only
3 * motu-midi.h - a part of driver for MOTU FireWire series
5 * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
9 static int midi_open(struct snd_rawmidi_substream
*substream
)
11 struct snd_motu
*motu
= substream
->rmidi
->private_data
;
14 err
= snd_motu_stream_lock_try(motu
);
18 mutex_lock(&motu
->mutex
);
20 err
= snd_motu_stream_reserve_duplex(motu
, 0, 0, 0);
22 ++motu
->substreams_counter
;
23 err
= snd_motu_stream_start_duplex(motu
);
25 --motu
->substreams_counter
;
28 mutex_unlock(&motu
->mutex
);
31 snd_motu_stream_lock_release(motu
);
36 static int midi_close(struct snd_rawmidi_substream
*substream
)
38 struct snd_motu
*motu
= substream
->rmidi
->private_data
;
40 mutex_lock(&motu
->mutex
);
42 --motu
->substreams_counter
;
43 snd_motu_stream_stop_duplex(motu
);
45 mutex_unlock(&motu
->mutex
);
47 snd_motu_stream_lock_release(motu
);
51 static void midi_capture_trigger(struct snd_rawmidi_substream
*substrm
, int up
)
53 struct snd_motu
*motu
= substrm
->rmidi
->private_data
;
56 spin_lock_irqsave(&motu
->lock
, flags
);
59 amdtp_motu_midi_trigger(&motu
->tx_stream
, substrm
->number
,
62 amdtp_motu_midi_trigger(&motu
->tx_stream
, substrm
->number
,
65 spin_unlock_irqrestore(&motu
->lock
, flags
);
68 static void midi_playback_trigger(struct snd_rawmidi_substream
*substrm
, int up
)
70 struct snd_motu
*motu
= substrm
->rmidi
->private_data
;
73 spin_lock_irqsave(&motu
->lock
, flags
);
76 amdtp_motu_midi_trigger(&motu
->rx_stream
, substrm
->number
,
79 amdtp_motu_midi_trigger(&motu
->rx_stream
, substrm
->number
,
82 spin_unlock_irqrestore(&motu
->lock
, flags
);
85 static void set_midi_substream_names(struct snd_motu
*motu
,
86 struct snd_rawmidi_str
*str
)
88 struct snd_rawmidi_substream
*subs
;
90 list_for_each_entry(subs
, &str
->substreams
, list
) {
91 snprintf(subs
->name
, sizeof(subs
->name
),
92 "%s MIDI %d", motu
->card
->shortname
, subs
->number
+ 1);
96 int snd_motu_create_midi_devices(struct snd_motu
*motu
)
98 static const struct snd_rawmidi_ops capture_ops
= {
101 .trigger
= midi_capture_trigger
,
103 static const struct snd_rawmidi_ops playback_ops
= {
106 .trigger
= midi_playback_trigger
,
108 struct snd_rawmidi
*rmidi
;
109 struct snd_rawmidi_str
*str
;
112 /* create midi ports */
113 err
= snd_rawmidi_new(motu
->card
, motu
->card
->driver
, 0, 1, 1, &rmidi
);
117 snprintf(rmidi
->name
, sizeof(rmidi
->name
),
118 "%s MIDI", motu
->card
->shortname
);
119 rmidi
->private_data
= motu
;
121 rmidi
->info_flags
|= SNDRV_RAWMIDI_INFO_INPUT
|
122 SNDRV_RAWMIDI_INFO_OUTPUT
|
123 SNDRV_RAWMIDI_INFO_DUPLEX
;
125 snd_rawmidi_set_ops(rmidi
, SNDRV_RAWMIDI_STREAM_INPUT
,
127 str
= &rmidi
->streams
[SNDRV_RAWMIDI_STREAM_INPUT
];
128 set_midi_substream_names(motu
, str
);
130 snd_rawmidi_set_ops(rmidi
, SNDRV_RAWMIDI_STREAM_OUTPUT
,
132 str
= &rmidi
->streams
[SNDRV_RAWMIDI_STREAM_OUTPUT
];
133 set_midi_substream_names(motu
, str
);