Skip to content

Commit 0f5482e

Browse files
takaswietiwai
authored andcommitted
ALSA: firewire-motu: share PCM buffer size for both direction
This commit allows ALSA firewire-motu driver to share PCM buffer size for both capture and playback PCM substream. When AMDTP domain starts for one of the PCM substream, buffer size of the PCM substream is stores to AMDTP domain structure. Some AMDTP streams have already run with the buffer size when another PCM substream starts, therefore the PCM substream has a constraint to its buffer size. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Link: https://lore.kernel.org/r/20191017155424.885-9-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 128307d commit 0f5482e

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

sound/firewire/motu/motu-midi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ static int midi_open(struct snd_rawmidi_substream *substream)
1717

1818
mutex_lock(&motu->mutex);
1919

20-
err = snd_motu_stream_reserve_duplex(motu, 0, 0);
20+
err = snd_motu_stream_reserve_duplex(motu, 0, 0, 0);
2121
if (err >= 0) {
2222
++motu->substreams_counter;
2323
err = snd_motu_stream_start_duplex(motu);

sound/firewire/motu/motu-pcm.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ static int pcm_open(struct snd_pcm_substream *substream)
162162
if (src != SND_MOTU_CLOCK_SOURCE_INTERNAL ||
163163
(motu->substreams_counter > 0 && d->events_per_period > 0)) {
164164
unsigned int frames_per_period = d->events_per_period;
165+
unsigned int frames_per_buffer = d->events_per_buffer;
165166
unsigned int rate;
166167

167168
err = protocol->get_clock_rate(motu, &rate);
@@ -179,6 +180,14 @@ static int pcm_open(struct snd_pcm_substream *substream)
179180
mutex_unlock(&motu->mutex);
180181
goto err_locked;
181182
}
183+
184+
err = snd_pcm_hw_constraint_minmax(substream->runtime,
185+
SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
186+
frames_per_buffer, frames_per_buffer);
187+
if (err < 0) {
188+
mutex_unlock(&motu->mutex);
189+
goto err_locked;
190+
}
182191
}
183192
}
184193

@@ -216,10 +225,11 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
216225
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
217226
unsigned int rate = params_rate(hw_params);
218227
unsigned int frames_per_period = params_period_size(hw_params);
228+
unsigned int frames_per_buffer = params_buffer_size(hw_params);
219229

220230
mutex_lock(&motu->mutex);
221231
err = snd_motu_stream_reserve_duplex(motu, rate,
222-
frames_per_period);
232+
frames_per_period, frames_per_buffer);
223233
if (err >= 0)
224234
++motu->substreams_counter;
225235
mutex_unlock(&motu->mutex);

sound/firewire/motu/motu-stream.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ int snd_motu_stream_cache_packet_formats(struct snd_motu *motu)
134134
}
135135

136136
int snd_motu_stream_reserve_duplex(struct snd_motu *motu, unsigned int rate,
137-
unsigned int frames_per_period)
137+
unsigned int frames_per_period,
138+
unsigned int frames_per_buffer)
138139
{
139140
unsigned int curr_rate;
140141
int err;
@@ -174,7 +175,7 @@ int snd_motu_stream_reserve_duplex(struct snd_motu *motu, unsigned int rate,
174175
}
175176

176177
err = amdtp_domain_set_events_per_period(&motu->domain,
177-
frames_per_period, 0);
178+
frames_per_period, frames_per_buffer);
178179
if (err < 0) {
179180
fw_iso_resources_free(&motu->tx_resources);
180181
fw_iso_resources_free(&motu->rx_resources);

sound/firewire/motu/motu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ int snd_motu_stream_init_duplex(struct snd_motu *motu);
155155
void snd_motu_stream_destroy_duplex(struct snd_motu *motu);
156156
int snd_motu_stream_cache_packet_formats(struct snd_motu *motu);
157157
int snd_motu_stream_reserve_duplex(struct snd_motu *motu, unsigned int rate,
158-
unsigned int frames_per_period);
158+
unsigned int frames_per_period,
159+
unsigned int frames_per_buffer);
159160
int snd_motu_stream_start_duplex(struct snd_motu *motu);
160161
void snd_motu_stream_stop_duplex(struct snd_motu *motu);
161162
int snd_motu_stream_lock_try(struct snd_motu *motu);

0 commit comments

Comments
 (0)