Alsa-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Subject: [alsa-devel] [PATCH 55/55] ALSA: usb-audio: Support PCM sync_stop
Date: Tue, 10 Dec 2019 07:34:54 +0100
Message-ID: <20191210063454.31603-56-tiwai@suse.de> (raw)
In-Reply-To: <20191210063454.31603-1-tiwai@suse.de>

USB-audio driver had some implementation of its own sync-stop
mechanism.  This patch moved a part of it to the common PCM sync_stop
ops.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/usb/pcm.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 33c1e971e61e..8a52996041e9 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -260,18 +260,31 @@ static int start_endpoints(struct snd_usb_substream *subs)
 	return 0;
 }
 
-static void stop_endpoints(struct snd_usb_substream *subs, bool wait)
+static void sync_pending_stops(struct snd_usb_substream *subs)
+{
+	snd_usb_endpoint_sync_pending_stop(subs->sync_endpoint);
+	snd_usb_endpoint_sync_pending_stop(subs->data_endpoint);
+}
+
+static void stop_endpoints(struct snd_usb_substream *subs)
 {
 	if (test_and_clear_bit(SUBSTREAM_FLAG_SYNC_EP_STARTED, &subs->flags))
 		snd_usb_endpoint_stop(subs->sync_endpoint);
 
 	if (test_and_clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags))
 		snd_usb_endpoint_stop(subs->data_endpoint);
+}
 
-	if (wait) {
-		snd_usb_endpoint_sync_pending_stop(subs->sync_endpoint);
-		snd_usb_endpoint_sync_pending_stop(subs->data_endpoint);
+/* PCM sync_stop callback */
+static int snd_usb_pcm_sync_stop(struct snd_pcm_substream *substream)
+{
+	struct snd_usb_substream *subs = substream->runtime->private_data;
+
+	if (!snd_usb_lock_shutdown(subs->stream->chip)) {
+		sync_pending_stops(subs);
+		snd_usb_unlock_shutdown(subs->stream->chip);
 	}
+	return 0;
 }
 
 static int search_roland_implicit_fb(struct usb_device *dev, int ifnum,
@@ -697,7 +710,8 @@ static int configure_endpoint(struct snd_usb_substream *subs)
 	int ret;
 
 	/* format changed */
-	stop_endpoints(subs, true);
+	stop_endpoints(subs);
+	sync_pending_stops(subs);
 	ret = snd_usb_endpoint_set_params(subs->data_endpoint,
 					  subs->pcm_format,
 					  subs->channels,
@@ -842,7 +856,8 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
 	subs->cur_rate = 0;
 	subs->period_bytes = 0;
 	if (!snd_usb_lock_shutdown(subs->stream->chip)) {
-		stop_endpoints(subs, true);
+		stop_endpoints(subs);
+		sync_pending_stops(subs);
 		snd_usb_endpoint_deactivate(subs->sync_endpoint);
 		snd_usb_endpoint_deactivate(subs->data_endpoint);
 		snd_usb_unlock_shutdown(subs->stream->chip);
@@ -877,9 +892,6 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
 		goto unlock;
 	}
 
-	snd_usb_endpoint_sync_pending_stop(subs->sync_endpoint);
-	snd_usb_endpoint_sync_pending_stop(subs->data_endpoint);
-
 	ret = snd_usb_pcm_change_state(subs, UAC3_PD_STATE_D0);
 	if (ret < 0)
 		goto unlock;
@@ -1337,7 +1349,6 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream)
 	struct snd_usb_substream *subs = &as->substream[direction];
 	int ret;
 
-	stop_endpoints(subs, true);
 	snd_media_stop_pipeline(subs);
 
 	if (!as->chip->keep_iface &&
@@ -1714,7 +1725,7 @@ static int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substrea
 		subs->running = 1;
 		return 0;
 	case SNDRV_PCM_TRIGGER_STOP:
-		stop_endpoints(subs, false);
+		stop_endpoints(subs);
 		subs->running = 0;
 		return 0;
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
@@ -1744,7 +1755,7 @@ static int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream
 		subs->running = 1;
 		return 0;
 	case SNDRV_PCM_TRIGGER_STOP:
-		stop_endpoints(subs, false);
+		stop_endpoints(subs);
 		subs->running = 0;
 		return 0;
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
@@ -1767,6 +1778,7 @@ static const struct snd_pcm_ops snd_usb_playback_ops = {
 	.hw_free =	snd_usb_hw_free,
 	.prepare =	snd_usb_pcm_prepare,
 	.trigger =	snd_usb_substream_playback_trigger,
+	.sync_stop =	snd_usb_pcm_sync_stop,
 	.pointer =	snd_usb_pcm_pointer,
 };
 
@@ -1777,6 +1789,7 @@ static const struct snd_pcm_ops snd_usb_capture_ops = {
 	.hw_free =	snd_usb_hw_free,
 	.prepare =	snd_usb_pcm_prepare,
 	.trigger =	snd_usb_substream_capture_trigger,
+	.sync_stop =	snd_usb_pcm_sync_stop,
 	.pointer =	snd_usb_pcm_pointer,
 };
 
-- 
2.16.4

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

      parent reply index

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-10  6:33 [alsa-devel] [PATCH 00/55] ALSA: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 01/55] ALSA: ad1889: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 02/55] ALSA: ali5451: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 03/55] ALSA: als300: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 04/55] ALSA: atiixp: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 05/55] ALSA: au88x0: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 06/55] ALSA: aw2: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 07/55] ALSA: azt3328: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 08/55] ALSA: bt87x: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 09/55] ALSA: ca0106: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 10/55] ALSA: cmipci: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 11/55] ALSA: cs4281: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 12/55] ALSA: cs46xx: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 13/55] ALSA: cs5535audio: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 14/55] ALSA: ctxfi: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 15/55] ALSA: echoaudio: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 16/55] ALSA: emu10k1: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 17/55] ALSA: ens137x: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 18/55] ALSA: es1938: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 19/55] ALSA: es1968: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 20/55] ALSA: fm801: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 21/55] ALSA: hda: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 22/55] ALSA: ice1712: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 23/55] ALSA: ice1724: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 24/55] ALSA: intel8x0: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 25/55] ALSA: korg1212: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 26/55] ALSA: lola: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 27/55] ALSA: maestro3: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 28/55] ALSA: nm256: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 29/55] ALSA: oxygen: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 30/55] ALSA: riptide: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 31/55] ALSA: rme32: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 32/55] ALSA: rme96: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 33/55] ALSA: rme9652: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 34/55] ALSA: sis7019: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 35/55] ALSA: sonicvibes: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 36/55] ALSA: trident: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 37/55] ALSA: via82xx: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 38/55] ALSA: ymfpci: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 39/55] ALSA: ad1816a: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 40/55] ALSA: es1688: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 41/55] ALSA: es18xx: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 42/55] ALSA: gus: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 43/55] ALSA: msnd: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 44/55] ALSA: opl3sa2: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 45/55] ALSA: opti9xx: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 46/55] ALSA: sb: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 47/55] ALSA: wavefront: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 48/55] ALSA: wss: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 49/55] ALSA: lx6464es: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 50/55] ALSA: mixart: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 51/55] ALSA: pcxhr: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 52/55] ALSA: vx222: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 53/55] ALSA: pdaudiocf: " Takashi Iwai
2019-12-10  6:34 ` [alsa-devel] [PATCH 54/55] ALSA: vxpocket: " Takashi Iwai
2019-12-10  6:34 ` Takashi Iwai [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191210063454.31603-56-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Alsa-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/alsa-devel/0 alsa-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 alsa-devel alsa-devel/ https://lore.kernel.org/alsa-devel \
		alsa-devel@alsa-project.org
	public-inbox-index alsa-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.alsa-project.alsa-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git