ALSA: firewire-motu: share PCM buffer size for both direction
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Thu, 17 Oct 2019 15:54:20 +0000 (00:54 +0900)
committerTakashi Iwai <tiwai@suse.de>
Fri, 18 Oct 2019 02:35:51 +0000 (04:35 +0200)
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>
sound/firewire/motu/motu-midi.c
sound/firewire/motu/motu-pcm.c
sound/firewire/motu/motu-stream.c
sound/firewire/motu/motu.h

index 997dd6c8ec319db06569d9e31d638fc9e36317bf..2365f7dfde2664dfa3990e2e8ab848b2de5ada4d 100644 (file)
@@ -17,7 +17,7 @@ static int midi_open(struct snd_rawmidi_substream *substream)
 
        mutex_lock(&motu->mutex);
 
-       err = snd_motu_stream_reserve_duplex(motu, 0, 0);
+       err = snd_motu_stream_reserve_duplex(motu, 0, 0, 0);
        if (err >= 0) {
                ++motu->substreams_counter;
                err = snd_motu_stream_start_duplex(motu);
index 7bbf8b86a33df2faa58a6b5ad406f808fa9a9614..00e693da0cad1992be8de5bcbaa070e6e8218fb9 100644 (file)
@@ -162,6 +162,7 @@ static int pcm_open(struct snd_pcm_substream *substream)
        if (src != SND_MOTU_CLOCK_SOURCE_INTERNAL ||
            (motu->substreams_counter > 0 && d->events_per_period > 0)) {
                unsigned int frames_per_period = d->events_per_period;
+               unsigned int frames_per_buffer = d->events_per_buffer;
                unsigned int rate;
 
                err = protocol->get_clock_rate(motu, &rate);
@@ -179,6 +180,14 @@ static int pcm_open(struct snd_pcm_substream *substream)
                                mutex_unlock(&motu->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(&motu->mutex);
+                               goto err_locked;
+                       }
                }
        }
 
@@ -216,10 +225,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(&motu->mutex);
                err = snd_motu_stream_reserve_duplex(motu, rate,
-                                                    frames_per_period);
+                                       frames_per_period, frames_per_buffer);
                if (err >= 0)
                        ++motu->substreams_counter;
                mutex_unlock(&motu->mutex);
index 97245c67073271886baa63ae44589a818d1d9ea5..9975770c9b1ffa6575acd782b319ab00bc190cf2 100644 (file)
@@ -134,7 +134,8 @@ int snd_motu_stream_cache_packet_formats(struct snd_motu *motu)
 }
 
 int snd_motu_stream_reserve_duplex(struct snd_motu *motu, unsigned int rate,
-                                  unsigned int frames_per_period)
+                                  unsigned int frames_per_period,
+                                  unsigned int frames_per_buffer)
 {
        unsigned int curr_rate;
        int err;
@@ -174,7 +175,7 @@ int snd_motu_stream_reserve_duplex(struct snd_motu *motu, unsigned int rate,
                }
 
                err = amdtp_domain_set_events_per_period(&motu->domain,
-                                                        frames_per_period, 0);
+                                       frames_per_period, frames_per_buffer);
                if (err < 0) {
                        fw_iso_resources_free(&motu->tx_resources);
                        fw_iso_resources_free(&motu->rx_resources);
index a419e6e7daed19bfde622634ca4845c3e52ae092..35ed8b6bb8e857c45105f723ce29022f4607979a 100644 (file)
@@ -155,7 +155,8 @@ int snd_motu_stream_init_duplex(struct snd_motu *motu);
 void snd_motu_stream_destroy_duplex(struct snd_motu *motu);
 int snd_motu_stream_cache_packet_formats(struct snd_motu *motu);
 int snd_motu_stream_reserve_duplex(struct snd_motu *motu, unsigned int rate,
-                                  unsigned int frames_per_period);
+                                  unsigned int frames_per_period,
+                                  unsigned int frames_per_buffer);
 int snd_motu_stream_start_duplex(struct snd_motu *motu);
 void snd_motu_stream_stop_duplex(struct snd_motu *motu);
 int snd_motu_stream_lock_try(struct snd_motu *motu);