.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * fireworks_midi.c - a part of driver for Fireworks based devices |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (c) 2009-2010 Clemens Ladisch |
---|
5 | 6 | * Copyright (c) 2013-2014 Takashi Sakamoto |
---|
6 | | - * |
---|
7 | | - * Licensed under the terms of the GNU General Public License, version 2. |
---|
8 | 7 | */ |
---|
9 | 8 | #include "fireworks.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_efw *efw = substream->rmidi->private_data; |
---|
14 | 13 | int err; |
---|
.. | .. |
---|
18 | 17 | goto end; |
---|
19 | 18 | |
---|
20 | 19 | mutex_lock(&efw->mutex); |
---|
21 | | - efw->capture_substreams++; |
---|
22 | | - err = snd_efw_stream_start_duplex(efw, 0); |
---|
23 | | - mutex_unlock(&efw->mutex); |
---|
24 | | - if (err < 0) |
---|
25 | | - snd_efw_stream_lock_release(efw); |
---|
26 | | - |
---|
27 | | -end: |
---|
28 | | - return err; |
---|
29 | | -} |
---|
30 | | - |
---|
31 | | -static int midi_playback_open(struct snd_rawmidi_substream *substream) |
---|
32 | | -{ |
---|
33 | | - struct snd_efw *efw = substream->rmidi->private_data; |
---|
34 | | - int err; |
---|
35 | | - |
---|
36 | | - err = snd_efw_stream_lock_try(efw); |
---|
37 | | - if (err < 0) |
---|
38 | | - goto end; |
---|
39 | | - |
---|
40 | | - mutex_lock(&efw->mutex); |
---|
41 | | - efw->playback_substreams++; |
---|
42 | | - err = snd_efw_stream_start_duplex(efw, 0); |
---|
| 20 | + err = snd_efw_stream_reserve_duplex(efw, 0, 0, 0); |
---|
| 21 | + if (err >= 0) { |
---|
| 22 | + ++efw->substreams_counter; |
---|
| 23 | + err = snd_efw_stream_start_duplex(efw); |
---|
| 24 | + if (err < 0) |
---|
| 25 | + --efw->substreams_counter; |
---|
| 26 | + } |
---|
43 | 27 | mutex_unlock(&efw->mutex); |
---|
44 | 28 | if (err < 0) |
---|
45 | 29 | snd_efw_stream_lock_release(efw); |
---|
.. | .. |
---|
47 | 31 | return err; |
---|
48 | 32 | } |
---|
49 | 33 | |
---|
50 | | -static int midi_capture_close(struct snd_rawmidi_substream *substream) |
---|
| 34 | +static int midi_close(struct snd_rawmidi_substream *substream) |
---|
51 | 35 | { |
---|
52 | 36 | struct snd_efw *efw = substream->rmidi->private_data; |
---|
53 | 37 | |
---|
54 | 38 | mutex_lock(&efw->mutex); |
---|
55 | | - efw->capture_substreams--; |
---|
56 | | - snd_efw_stream_stop_duplex(efw); |
---|
57 | | - mutex_unlock(&efw->mutex); |
---|
58 | | - |
---|
59 | | - snd_efw_stream_lock_release(efw); |
---|
60 | | - return 0; |
---|
61 | | -} |
---|
62 | | - |
---|
63 | | -static int midi_playback_close(struct snd_rawmidi_substream *substream) |
---|
64 | | -{ |
---|
65 | | - struct snd_efw *efw = substream->rmidi->private_data; |
---|
66 | | - |
---|
67 | | - mutex_lock(&efw->mutex); |
---|
68 | | - efw->playback_substreams--; |
---|
| 39 | + --efw->substreams_counter; |
---|
69 | 40 | snd_efw_stream_stop_duplex(efw); |
---|
70 | 41 | mutex_unlock(&efw->mutex); |
---|
71 | 42 | |
---|
.. | .. |
---|
121 | 92 | int snd_efw_create_midi_devices(struct snd_efw *efw) |
---|
122 | 93 | { |
---|
123 | 94 | static const struct snd_rawmidi_ops capture_ops = { |
---|
124 | | - .open = midi_capture_open, |
---|
125 | | - .close = midi_capture_close, |
---|
| 95 | + .open = midi_open, |
---|
| 96 | + .close = midi_close, |
---|
126 | 97 | .trigger = midi_capture_trigger, |
---|
127 | 98 | }; |
---|
128 | 99 | static const struct snd_rawmidi_ops playback_ops = { |
---|
129 | | - .open = midi_playback_open, |
---|
130 | | - .close = midi_playback_close, |
---|
| 100 | + .open = midi_open, |
---|
| 101 | + .close = midi_close, |
---|
131 | 102 | .trigger = midi_playback_trigger, |
---|
132 | 103 | }; |
---|
133 | 104 | struct snd_rawmidi *rmidi; |
---|