From 0d39cd0e449925a6221da48835ef962cd72f330f Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Mon, 7 Oct 2019 20:05:23 +0900 Subject: ALSA: firewire-motu: register the size of PCM period to AMDTP domain This commit is a preparation to share the size of PCM period between PCM substreams on AMDTP streams in the same domain. At this time, the size of PCM period in PCM substream which starts AMDTP streams in the same domain is recorded. Signed-off-by: Takashi Sakamoto Link: https://lore.kernel.org/r/20191007110532.30270-9-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai --- sound/firewire/motu/motu-pcm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'sound/firewire/motu/motu-pcm.c') diff --git a/sound/firewire/motu/motu-pcm.c b/sound/firewire/motu/motu-pcm.c index aa2e584da6fe..9a54c562494b 100644 --- a/sound/firewire/motu/motu-pcm.c +++ b/sound/firewire/motu/motu-pcm.c @@ -202,9 +202,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); mutex_lock(&motu->mutex); - err = snd_motu_stream_reserve_duplex(motu, rate); + err = snd_motu_stream_reserve_duplex(motu, rate, + frames_per_period); if (err >= 0) ++motu->substreams_counter; mutex_unlock(&motu->mutex); -- cgit From 3fd80b2003882b6a328caff9e6b3a14bed61f27c Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Mon, 7 Oct 2019 20:05:31 +0900 Subject: ALSA: firewire-motu: use the same size of period for PCM substream in AMDTP streams In current implementation, when opening a PCM substream, it's needed to check whether the opposite PCM substream runs. This is to assign effectual constraints (e.g. sampling rate) to opened PCM substream. The number of PCM substreams and MIDI substreams on AMDTP streams in domain is recorded in own structure. Usage of this count is an alternative of the above check. This is better because the count is incremented in pcm.hw_params earlier than pcm.trigger. This idea has one issue because it's incremented for MIDI substreams as well. In current implementation, for a case that any MIDI substream run and a PCM substream is going to start, PCM application to start the PCM substream can decide hardware parameters by restart packet streaming. Just checking the substream count can brings regression. Now AMDTP domain structure has a member for the size of PCM period in PCM substream which starts AMDTP streams in domain. When the value has zero and the substream count is greater than 1, it means that any MIDI substream starts AMDTP streams in domain. Usage of the value can resolve the above issue. This commit replaces the check with the substream count and the value for the size of PCM period. Signed-off-by: Takashi Sakamoto Link: https://lore.kernel.org/r/20191007110532.30270-17-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai --- sound/firewire/motu/motu-pcm.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'sound/firewire/motu/motu-pcm.c') diff --git a/sound/firewire/motu/motu-pcm.c b/sound/firewire/motu/motu-pcm.c index 9a54c562494b..7bbf8b86a33d 100644 --- a/sound/firewire/motu/motu-pcm.c +++ b/sound/firewire/motu/motu-pcm.c @@ -134,8 +134,8 @@ static int pcm_open(struct snd_pcm_substream *substream) { struct snd_motu *motu = substream->private_data; const struct snd_motu_protocol *const protocol = motu->spec->protocol; + struct amdtp_domain *d = &motu->domain; enum snd_motu_clock_source src; - unsigned int rate; int err; err = snd_motu_stream_lock_try(motu); @@ -152,28 +152,41 @@ static int pcm_open(struct snd_pcm_substream *substream) if (err < 0) goto err_locked; - /* - * When source of clock is not internal or any PCM streams are running, - * available sampling rate is limited at current sampling rate. - */ err = protocol->get_clock_source(motu, &src); if (err < 0) goto err_locked; + + // When source of clock is not internal or any stream is reserved for + // transmission of PCM frames, the available sampling rate is limited + // at current one. if (src != SND_MOTU_CLOCK_SOURCE_INTERNAL || - amdtp_stream_pcm_running(&motu->tx_stream) || - amdtp_stream_pcm_running(&motu->rx_stream)) { + (motu->substreams_counter > 0 && d->events_per_period > 0)) { + unsigned int frames_per_period = d->events_per_period; + unsigned int rate; + err = protocol->get_clock_rate(motu, &rate); if (err < 0) goto err_locked; + substream->runtime->hw.rate_min = rate; substream->runtime->hw.rate_max = rate; + + if (frames_per_period > 0) { + err = snd_pcm_hw_constraint_minmax(substream->runtime, + SNDRV_PCM_HW_PARAM_PERIOD_SIZE, + frames_per_period, frames_per_period); + if (err < 0) { + mutex_unlock(&motu->mutex); + goto err_locked; + } + } } snd_pcm_set_sync(substream); mutex_unlock(&motu->mutex); - return err; + return 0; err_locked: mutex_unlock(&motu->mutex); snd_motu_stream_lock_release(motu); -- cgit From 0f5482e7875bc2d507e6d92fcc8de22ff75fbdda Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Fri, 18 Oct 2019 00:54:20 +0900 Subject: 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 Link: https://lore.kernel.org/r/20191017155424.885-9-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai --- sound/firewire/motu/motu-pcm.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'sound/firewire/motu/motu-pcm.c') diff --git a/sound/firewire/motu/motu-pcm.c b/sound/firewire/motu/motu-pcm.c index 7bbf8b86a33d..00e693da0cad 100644 --- a/sound/firewire/motu/motu-pcm.c +++ b/sound/firewire/motu/motu-pcm.c @@ -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); -- cgit From f890f9a04b361b2209c38e3317e6290a98e6ff6e Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Fri, 18 Oct 2019 15:19:07 +0900 Subject: ALSA: firewire-lib: replace pointer callback to flush isoc contexts in AMDTP domain An isoc context for AMDTP stream is flushed to queue packet by a call of pcm.pointer. This commit extends this for AMDTP domain. Signed-off-by: Takashi Sakamoto Link: https://lore.kernel.org/r/20191018061911.24909-3-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai --- sound/firewire/motu/motu-pcm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sound/firewire/motu/motu-pcm.c') diff --git a/sound/firewire/motu/motu-pcm.c b/sound/firewire/motu/motu-pcm.c index 00e693da0cad..13e2577c2a07 100644 --- a/sound/firewire/motu/motu-pcm.c +++ b/sound/firewire/motu/motu-pcm.c @@ -320,13 +320,13 @@ static snd_pcm_uframes_t capture_pointer(struct snd_pcm_substream *substream) { struct snd_motu *motu = substream->private_data; - return amdtp_stream_pcm_pointer(&motu->tx_stream); + return amdtp_domain_stream_pcm_pointer(&motu->domain, &motu->tx_stream); } static snd_pcm_uframes_t playback_pointer(struct snd_pcm_substream *substream) { struct snd_motu *motu = substream->private_data; - return amdtp_stream_pcm_pointer(&motu->rx_stream); + return amdtp_domain_stream_pcm_pointer(&motu->domain, &motu->rx_stream); } static int capture_ack(struct snd_pcm_substream *substream) -- cgit From e6dcc92fcea07f23c13996b7bb6a2a32ed4c6ed5 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Fri, 18 Oct 2019 15:19:08 +0900 Subject: ALSA: firewire-lib: replace ack callback to flush isoc contexts in AMDTP domain An isoc context for AMDTP stream is flushed to queue packet by a call of pcm.ack. This commit extends this for AMDTP domain. Signed-off-by: Takashi Sakamoto Link: https://lore.kernel.org/r/20191018061911.24909-4-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai --- sound/firewire/motu/motu-pcm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sound/firewire/motu/motu-pcm.c') diff --git a/sound/firewire/motu/motu-pcm.c b/sound/firewire/motu/motu-pcm.c index 13e2577c2a07..55d3d6661731 100644 --- a/sound/firewire/motu/motu-pcm.c +++ b/sound/firewire/motu/motu-pcm.c @@ -333,14 +333,14 @@ static int capture_ack(struct snd_pcm_substream *substream) { struct snd_motu *motu = substream->private_data; - return amdtp_stream_pcm_ack(&motu->tx_stream); + return amdtp_domain_stream_pcm_ack(&motu->domain, &motu->tx_stream); } static int playback_ack(struct snd_pcm_substream *substream) { struct snd_motu *motu = substream->private_data; - return amdtp_stream_pcm_ack(&motu->rx_stream); + return amdtp_domain_stream_pcm_ack(&motu->domain, &motu->rx_stream); } int snd_motu_create_pcm_devices(struct snd_motu *motu) -- cgit From 3f58f004bff3273d102583e0b2f478526cf9d3c8 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Wed, 30 Oct 2019 17:06:41 +0900 Subject: ALSA: firewire-motu: detect SPH source of sampling clock In MOTU FireWire series, devices have a mode to generate sampling clock from a sequence of source packet header (SPH) included in each data block of received packet. This mode is used for several purposes such as mode for SMPTE time code, sync to the other sound cards and so on. This commit adds support for the SPH mode. Signed-off-by: Takashi Sakamoto Link: https://lore.kernel.org/r/20191030080644.1704-4-o-takashi@sakamocchi.jp Signed-off-by: Takashi Iwai --- sound/firewire/motu/motu-pcm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sound/firewire/motu/motu-pcm.c') diff --git a/sound/firewire/motu/motu-pcm.c b/sound/firewire/motu/motu-pcm.c index 55d3d6661731..490408b49157 100644 --- a/sound/firewire/motu/motu-pcm.c +++ b/sound/firewire/motu/motu-pcm.c @@ -159,7 +159,8 @@ static int pcm_open(struct snd_pcm_substream *substream) // When source of clock is not internal or any stream is reserved for // transmission of PCM frames, the available sampling rate is limited // at current one. - if (src != SND_MOTU_CLOCK_SOURCE_INTERNAL || + if ((src != SND_MOTU_CLOCK_SOURCE_INTERNAL && + src != SND_MOTU_CLOCK_SOURCE_SPH) || (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; -- cgit From a3f4f2d5d02095d098ff03c4d0bdbae2e53a5bba Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Tue, 5 Nov 2019 16:18:42 +0100 Subject: ALSA: firewire: Convert to the common vmalloc memalloc The recent change (*) in the ALSA memalloc core allows us to drop the special vmalloc-specific allocation and page handling. This patch coverts to the common code. (*) 1fe7f397cfe2: ALSA: memalloc: Add vmalloc buffer allocation support 7e8edae39fd1: ALSA: pcm: Handle special page mapping in the default mmap handler Link: https://lore.kernel.org/r/20191105151856.10785-11-tiwai@suse.de Signed-off-by: Takashi Iwai --- sound/firewire/motu/motu-pcm.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'sound/firewire/motu/motu-pcm.c') diff --git a/sound/firewire/motu/motu-pcm.c b/sound/firewire/motu/motu-pcm.c index 490408b49157..349b4d09e84f 100644 --- a/sound/firewire/motu/motu-pcm.c +++ b/sound/firewire/motu/motu-pcm.c @@ -218,8 +218,7 @@ static int pcm_hw_params(struct snd_pcm_substream *substream, struct snd_motu *motu = substream->private_data; int err; - err = snd_pcm_lib_alloc_vmalloc_buffer(substream, - params_buffer_bytes(hw_params)); + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); if (err < 0) return err; @@ -252,7 +251,7 @@ static int pcm_hw_free(struct snd_pcm_substream *substream) mutex_unlock(&motu->mutex); - return snd_pcm_lib_free_vmalloc_buffer(substream); + return snd_pcm_lib_free_pages(substream); } static int capture_prepare(struct snd_pcm_substream *substream) @@ -356,7 +355,6 @@ int snd_motu_create_pcm_devices(struct snd_motu *motu) .trigger = capture_trigger, .pointer = capture_pointer, .ack = capture_ack, - .page = snd_pcm_lib_get_vmalloc_page, }; static const struct snd_pcm_ops playback_ops = { .open = pcm_open, @@ -368,7 +366,6 @@ int snd_motu_create_pcm_devices(struct snd_motu *motu) .trigger = playback_trigger, .pointer = playback_pointer, .ack = playback_ack, - .page = snd_pcm_lib_get_vmalloc_page, }; struct snd_pcm *pcm; int err; @@ -381,6 +378,8 @@ int snd_motu_create_pcm_devices(struct snd_motu *motu) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &capture_ops); snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &playback_ops); + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_VMALLOC, + NULL, 0, 0); return 0; } -- cgit