hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/sound/firewire/motu/motu-midi.c
....@@ -1,13 +1,12 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * motu-midi.h - a part of driver for MOTU FireWire series
34 *
45 * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp>
5
- *
6
- * Licensed under the terms of the GNU General Public License, version 2.
76 */
87 #include "motu.h"
98
10
-static int midi_capture_open(struct snd_rawmidi_substream *substream)
9
+static int midi_open(struct snd_rawmidi_substream *substream)
1110 {
1211 struct snd_motu *motu = substream->rmidi->private_data;
1312 int err;
....@@ -18,8 +17,13 @@
1817
1918 mutex_lock(&motu->mutex);
2019
21
- motu->capture_substreams++;
22
- err = snd_motu_stream_start_duplex(motu, 0);
20
+ err = snd_motu_stream_reserve_duplex(motu, 0, 0, 0);
21
+ if (err >= 0) {
22
+ ++motu->substreams_counter;
23
+ err = snd_motu_stream_start_duplex(motu);
24
+ if (err < 0)
25
+ --motu->substreams_counter;
26
+ }
2327
2428 mutex_unlock(&motu->mutex);
2529
....@@ -29,50 +33,13 @@
2933 return err;
3034 }
3135
32
-static int midi_playback_open(struct snd_rawmidi_substream *substream)
33
-{
34
- struct snd_motu *motu = substream->rmidi->private_data;
35
- int err;
36
-
37
- err = snd_motu_stream_lock_try(motu);
38
- if (err < 0)
39
- return err;
40
-
41
- mutex_lock(&motu->mutex);
42
-
43
- motu->playback_substreams++;
44
- err = snd_motu_stream_start_duplex(motu, 0);
45
-
46
- mutex_unlock(&motu->mutex);
47
-
48
- if (err < 0)
49
- snd_motu_stream_lock_release(motu);
50
-
51
- return err;
52
-}
53
-
54
-static int midi_capture_close(struct snd_rawmidi_substream *substream)
36
+static int midi_close(struct snd_rawmidi_substream *substream)
5537 {
5638 struct snd_motu *motu = substream->rmidi->private_data;
5739
5840 mutex_lock(&motu->mutex);
5941
60
- motu->capture_substreams--;
61
- snd_motu_stream_stop_duplex(motu);
62
-
63
- mutex_unlock(&motu->mutex);
64
-
65
- snd_motu_stream_lock_release(motu);
66
- return 0;
67
-}
68
-
69
-static int midi_playback_close(struct snd_rawmidi_substream *substream)
70
-{
71
- struct snd_motu *motu = substream->rmidi->private_data;
72
-
73
- mutex_lock(&motu->mutex);
74
-
75
- motu->playback_substreams--;
42
+ --motu->substreams_counter;
7643 snd_motu_stream_stop_duplex(motu);
7744
7845 mutex_unlock(&motu->mutex);
....@@ -129,13 +96,13 @@
12996 int snd_motu_create_midi_devices(struct snd_motu *motu)
13097 {
13198 static const struct snd_rawmidi_ops capture_ops = {
132
- .open = midi_capture_open,
133
- .close = midi_capture_close,
99
+ .open = midi_open,
100
+ .close = midi_close,
134101 .trigger = midi_capture_trigger,
135102 };
136103 static const struct snd_rawmidi_ops playback_ops = {
137
- .open = midi_playback_open,
138
- .close = midi_playback_close,
104
+ .open = midi_open,
105
+ .close = midi_close,
139106 .trigger = midi_playback_trigger,
140107 };
141108 struct snd_rawmidi *rmidi;