| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * motu-midi.h - a part of driver for MOTU FireWire series |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (c) 2015-2017 Takashi Sakamoto <o-takashi@sakamocchi.jp> |
|---|
| 5 | | - * |
|---|
| 6 | | - * Licensed under the terms of the GNU General Public License, version 2. |
|---|
| 7 | 6 | */ |
|---|
| 8 | 7 | #include "motu.h" |
|---|
| 9 | 8 | |
|---|
| 10 | | -static int midi_capture_open(struct snd_rawmidi_substream *substream) |
|---|
| 9 | +static int midi_open(struct snd_rawmidi_substream *substream) |
|---|
| 11 | 10 | { |
|---|
| 12 | 11 | struct snd_motu *motu = substream->rmidi->private_data; |
|---|
| 13 | 12 | int err; |
|---|
| .. | .. |
|---|
| 18 | 17 | |
|---|
| 19 | 18 | mutex_lock(&motu->mutex); |
|---|
| 20 | 19 | |
|---|
| 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 | + } |
|---|
| 23 | 27 | |
|---|
| 24 | 28 | mutex_unlock(&motu->mutex); |
|---|
| 25 | 29 | |
|---|
| .. | .. |
|---|
| 29 | 33 | return err; |
|---|
| 30 | 34 | } |
|---|
| 31 | 35 | |
|---|
| 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) |
|---|
| 55 | 37 | { |
|---|
| 56 | 38 | struct snd_motu *motu = substream->rmidi->private_data; |
|---|
| 57 | 39 | |
|---|
| 58 | 40 | mutex_lock(&motu->mutex); |
|---|
| 59 | 41 | |
|---|
| 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; |
|---|
| 76 | 43 | snd_motu_stream_stop_duplex(motu); |
|---|
| 77 | 44 | |
|---|
| 78 | 45 | mutex_unlock(&motu->mutex); |
|---|
| .. | .. |
|---|
| 129 | 96 | int snd_motu_create_midi_devices(struct snd_motu *motu) |
|---|
| 130 | 97 | { |
|---|
| 131 | 98 | 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, |
|---|
| 134 | 101 | .trigger = midi_capture_trigger, |
|---|
| 135 | 102 | }; |
|---|
| 136 | 103 | 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, |
|---|
| 139 | 106 | .trigger = midi_playback_trigger, |
|---|
| 140 | 107 | }; |
|---|
| 141 | 108 | struct snd_rawmidi *rmidi; |
|---|