.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * bebob_midi.c - a part of driver for BeBoB based devices |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2013-2014 Takashi Sakamoto |
---|
5 | | - * |
---|
6 | | - * Licensed under the terms of the GNU General Public License, version 2. |
---|
7 | 6 | */ |
---|
8 | 7 | |
---|
9 | 8 | #include "bebob.h" |
---|
10 | 9 | |
---|
11 | | -static int midi_capture_open(struct snd_rawmidi_substream *substream) |
---|
| 10 | +static int midi_open(struct snd_rawmidi_substream *substream) |
---|
12 | 11 | { |
---|
13 | 12 | struct snd_bebob *bebob = substream->rmidi->private_data; |
---|
14 | 13 | int err; |
---|
15 | 14 | |
---|
16 | 15 | err = snd_bebob_stream_lock_try(bebob); |
---|
17 | 16 | if (err < 0) |
---|
18 | | - goto end; |
---|
| 17 | + return err; |
---|
19 | 18 | |
---|
20 | 19 | mutex_lock(&bebob->mutex); |
---|
21 | | - bebob->substreams_counter++; |
---|
22 | | - err = snd_bebob_stream_start_duplex(bebob, 0); |
---|
| 20 | + err = snd_bebob_stream_reserve_duplex(bebob, 0, 0, 0); |
---|
| 21 | + if (err >= 0) { |
---|
| 22 | + ++bebob->substreams_counter; |
---|
| 23 | + err = snd_bebob_stream_start_duplex(bebob); |
---|
| 24 | + if (err < 0) |
---|
| 25 | + --bebob->substreams_counter; |
---|
| 26 | + } |
---|
23 | 27 | mutex_unlock(&bebob->mutex); |
---|
24 | 28 | if (err < 0) |
---|
25 | 29 | snd_bebob_stream_lock_release(bebob); |
---|
26 | | -end: |
---|
| 30 | + |
---|
27 | 31 | return err; |
---|
28 | 32 | } |
---|
29 | 33 | |
---|
30 | | -static int midi_playback_open(struct snd_rawmidi_substream *substream) |
---|
31 | | -{ |
---|
32 | | - struct snd_bebob *bebob = substream->rmidi->private_data; |
---|
33 | | - int err; |
---|
34 | | - |
---|
35 | | - err = snd_bebob_stream_lock_try(bebob); |
---|
36 | | - if (err < 0) |
---|
37 | | - goto end; |
---|
38 | | - |
---|
39 | | - mutex_lock(&bebob->mutex); |
---|
40 | | - bebob->substreams_counter++; |
---|
41 | | - err = snd_bebob_stream_start_duplex(bebob, 0); |
---|
42 | | - mutex_unlock(&bebob->mutex); |
---|
43 | | - if (err < 0) |
---|
44 | | - snd_bebob_stream_lock_release(bebob); |
---|
45 | | -end: |
---|
46 | | - return err; |
---|
47 | | -} |
---|
48 | | - |
---|
49 | | -static int midi_capture_close(struct snd_rawmidi_substream *substream) |
---|
50 | | -{ |
---|
51 | | - struct snd_bebob *bebob = substream->rmidi->private_data; |
---|
52 | | - |
---|
53 | | - mutex_lock(&bebob->mutex); |
---|
54 | | - bebob->substreams_counter--; |
---|
55 | | - snd_bebob_stream_stop_duplex(bebob); |
---|
56 | | - mutex_unlock(&bebob->mutex); |
---|
57 | | - |
---|
58 | | - snd_bebob_stream_lock_release(bebob); |
---|
59 | | - return 0; |
---|
60 | | -} |
---|
61 | | - |
---|
62 | | -static int midi_playback_close(struct snd_rawmidi_substream *substream) |
---|
| 34 | +static int midi_close(struct snd_rawmidi_substream *substream) |
---|
63 | 35 | { |
---|
64 | 36 | struct snd_bebob *bebob = substream->rmidi->private_data; |
---|
65 | 37 | |
---|
.. | .. |
---|
121 | 93 | int snd_bebob_create_midi_devices(struct snd_bebob *bebob) |
---|
122 | 94 | { |
---|
123 | 95 | static const struct snd_rawmidi_ops capture_ops = { |
---|
124 | | - .open = midi_capture_open, |
---|
125 | | - .close = midi_capture_close, |
---|
| 96 | + .open = midi_open, |
---|
| 97 | + .close = midi_close, |
---|
126 | 98 | .trigger = midi_capture_trigger, |
---|
127 | 99 | }; |
---|
128 | 100 | static const struct snd_rawmidi_ops playback_ops = { |
---|
129 | | - .open = midi_playback_open, |
---|
130 | | - .close = midi_playback_close, |
---|
| 101 | + .open = midi_open, |
---|
| 102 | + .close = midi_close, |
---|
131 | 103 | .trigger = midi_playback_trigger, |
---|
132 | 104 | }; |
---|
133 | 105 | struct snd_rawmidi *rmidi; |
---|