Skip to content

Commit 76c4ecb

Browse files
takaswietiwai
authored andcommitted
ALSA: firewire-digi00x: share PCM buffer size for both direction
This commit allows ALSA firewire-digi00x 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-7-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent ecb40fd commit 76c4ecb

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

sound/firewire/digi00x/digi00x-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
return err;
1818

1919
mutex_lock(&dg00x->mutex);
20-
err = snd_dg00x_stream_reserve_duplex(dg00x, 0, 0);
20+
err = snd_dg00x_stream_reserve_duplex(dg00x, 0, 0, 0);
2121
if (err >= 0) {
2222
++dg00x->substreams_counter;
2323
err = snd_dg00x_stream_start_duplex(dg00x);

sound/firewire/digi00x/digi00x-pcm.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static int pcm_open(struct snd_pcm_substream *substream)
135135
if ((clock != SND_DG00X_CLOCK_INTERNAL) ||
136136
(dg00x->substreams_counter > 0 && d->events_per_period > 0)) {
137137
unsigned int frames_per_period = d->events_per_period;
138+
unsigned int frames_per_buffer = d->events_per_buffer;
138139
unsigned int rate;
139140

140141
err = snd_dg00x_stream_get_external_rate(dg00x, &rate);
@@ -153,6 +154,14 @@ static int pcm_open(struct snd_pcm_substream *substream)
153154
mutex_unlock(&dg00x->mutex);
154155
goto err_locked;
155156
}
157+
158+
err = snd_pcm_hw_constraint_minmax(substream->runtime,
159+
SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
160+
frames_per_buffer, frames_per_buffer);
161+
if (err < 0) {
162+
mutex_unlock(&dg00x->mutex);
163+
goto err_locked;
164+
}
156165
}
157166
}
158167

@@ -189,10 +198,11 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
189198
if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
190199
unsigned int rate = params_rate(hw_params);
191200
unsigned int frames_per_period = params_period_size(hw_params);
201+
unsigned int frames_per_buffer = params_buffer_size(hw_params);
192202

193203
mutex_lock(&dg00x->mutex);
194204
err = snd_dg00x_stream_reserve_duplex(dg00x, rate,
195-
frames_per_period);
205+
frames_per_period, frames_per_buffer);
196206
if (err >= 0)
197207
++dg00x->substreams_counter;
198208
mutex_unlock(&dg00x->mutex);

sound/firewire/digi00x/digi00x-stream.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ void snd_dg00x_stream_destroy_duplex(struct snd_dg00x *dg00x)
284284
}
285285

286286
int snd_dg00x_stream_reserve_duplex(struct snd_dg00x *dg00x, unsigned int rate,
287-
unsigned int frames_per_period)
287+
unsigned int frames_per_period,
288+
unsigned int frames_per_buffer)
288289
{
289290
unsigned int curr_rate;
290291
int err;
@@ -318,7 +319,7 @@ int snd_dg00x_stream_reserve_duplex(struct snd_dg00x *dg00x, unsigned int rate,
318319
}
319320

320321
err = amdtp_domain_set_events_per_period(&dg00x->domain,
321-
frames_per_period, 0);
322+
frames_per_period, frames_per_buffer);
322323
if (err < 0) {
323324
fw_iso_resources_free(&dg00x->rx_resources);
324325
fw_iso_resources_free(&dg00x->tx_resources);

sound/firewire/digi00x/digi00x.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ int snd_dg00x_stream_check_external_clock(struct snd_dg00x *dg00x,
142142
bool *detect);
143143
int snd_dg00x_stream_init_duplex(struct snd_dg00x *dg00x);
144144
int snd_dg00x_stream_reserve_duplex(struct snd_dg00x *dg00x, unsigned int rate,
145-
unsigned int frames_per_period);
145+
unsigned int frames_per_period,
146+
unsigned int frames_per_buffer);
146147
int snd_dg00x_stream_start_duplex(struct snd_dg00x *dg00x);
147148
void snd_dg00x_stream_stop_duplex(struct snd_dg00x *dg00x);
148149
void snd_dg00x_stream_update_duplex(struct snd_dg00x *dg00x);

0 commit comments

Comments
 (0)