ALSA: firewire-tascam: share PCM buffer size for both direction
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Thu, 17 Oct 2019 15:54:19 +0000 (00:54 +0900)
committerTakashi Iwai <tiwai@suse.de>
Fri, 18 Oct 2019 02:35:50 +0000 (04:35 +0200)
This commit allows ALSA firewire-tascam 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-8-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/firewire/tascam/tascam-pcm.c
sound/firewire/tascam/tascam-stream.c
sound/firewire/tascam/tascam.h

index 6cd3a420fbdf249aa10975ea122a087ac6798970..b18664fdf9558b27db094f95fd0b4964b154608b 100644 (file)
@@ -66,6 +66,7 @@ static int pcm_open(struct snd_pcm_substream *substream)
        // at current one.
        if (clock != SND_TSCM_CLOCK_INTERNAL || tscm->substreams_counter > 0) {
                unsigned int frames_per_period = d->events_per_period;
+               unsigned int frames_per_buffer = d->events_per_buffer;
                unsigned int rate;
 
                err = snd_tscm_stream_get_rate(tscm, &rate);
@@ -83,6 +84,14 @@ static int pcm_open(struct snd_pcm_substream *substream)
                        mutex_unlock(&tscm->mutex);
                        goto err_locked;
                }
+
+               err = snd_pcm_hw_constraint_minmax(substream->runtime,
+                                       SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
+                                       frames_per_buffer, frames_per_buffer);
+               if (err < 0) {
+                       mutex_unlock(&tscm->mutex);
+                       goto err_locked;
+               }
        }
 
        mutex_unlock(&tscm->mutex);
@@ -118,10 +127,11 @@ static int pcm_hw_params(struct snd_pcm_substream *substream,
        if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
                unsigned int rate = params_rate(hw_params);
                unsigned int frames_per_period = params_period_size(hw_params);
+               unsigned int frames_per_buffer = params_buffer_size(hw_params);
 
                mutex_lock(&tscm->mutex);
                err = snd_tscm_stream_reserve_duplex(tscm, rate,
-                                                    frames_per_period);
+                                       frames_per_period, frames_per_buffer);
                if (err >= 0)
                        ++tscm->substreams_counter;
                mutex_unlock(&tscm->mutex);
index 1e4d44ed8bedc89045eb7e495b0d539710cb9676..a9b3b7eb6d216ad1d4ea1f0165f0fb8d83ea7f42 100644 (file)
@@ -384,7 +384,8 @@ void snd_tscm_stream_destroy_duplex(struct snd_tscm *tscm)
 }
 
 int snd_tscm_stream_reserve_duplex(struct snd_tscm *tscm, unsigned int rate,
-                                  unsigned int frames_per_period)
+                                  unsigned int frames_per_period,
+                                  unsigned int frames_per_buffer)
 {
        unsigned int curr_rate;
        int err;
@@ -416,7 +417,7 @@ int snd_tscm_stream_reserve_duplex(struct snd_tscm *tscm, unsigned int rate,
                }
 
                err = amdtp_domain_set_events_per_period(&tscm->domain,
-                                                       frames_per_period, 0);
+                                       frames_per_period, frames_per_buffer);
                if (err < 0) {
                        fw_iso_resources_free(&tscm->tx_resources);
                        fw_iso_resources_free(&tscm->rx_resources);
index 32e72a25bf46ddfedfa450adcc5d816b45b7e147..78b7a08986a1d311860b467b1ec29c03fec02845 100644 (file)
@@ -169,7 +169,8 @@ int snd_tscm_stream_init_duplex(struct snd_tscm *tscm);
 void snd_tscm_stream_update_duplex(struct snd_tscm *tscm);
 void snd_tscm_stream_destroy_duplex(struct snd_tscm *tscm);
 int snd_tscm_stream_reserve_duplex(struct snd_tscm *tscm, unsigned int rate,
-                                  unsigned int frames_per_period);
+                                  unsigned int frames_per_period,
+                                  unsigned int frames_per_buffer);
 int snd_tscm_stream_start_duplex(struct snd_tscm *tscm, unsigned int rate);
 void snd_tscm_stream_stop_duplex(struct snd_tscm *tscm);