public inbox for linux-mediatek@lists.infradead.org
 help / color / mirror / Atom feed
From: KaiChieh Chuang <kaichieh.chuang@mediatek.com>
To: broonie@kernel.org
Cc: alsa-devel@alsa-project.org, linux-mediatek@lists.infradead.org,
	wsd_upstream@mediatek.com, kaichieh.chuang@mediatek.com
Subject: [PATCH 1/2] ASoC: dpcm: fix BE dai not hw_free and shutdown
Date: Tue, 22 May 2018 17:13:27 +0800	[thread overview]
Message-ID: <1526980408-1935-2-git-send-email-kaichieh.chuang@mediatek.com> (raw)
In-Reply-To: <1526980408-1935-1-git-send-email-kaichieh.chuang@mediatek.com>

In case, one BE is used by two FE1/FE2
FE1--->BE-->
FE2--->

When FE1/FE2 call dpcm_be_dai_hw_free() together
the BE users will be 2 (> 1), hence cannot be hw_free.
The be state will leave at, ex. SND_SOC_DPCM_STATE_STOP

Later FE1/FE2 call dpcm_be_dai_shutdown(),
will be skip due to wrong state.
Leaving the BE not being hw_free and shutdown.

This patch add a flag in snd_soc_dpcm to denote
the hw_free cannot be excute for this fe->be dpcm.
The BE dai will be hw_free later when calling
dpcm_be_dai_shutdown() if still in invalid state.

Signed-off-by: KaiChieh Chuang <kaichieh.chuang@mediatek.com>
---
 include/sound/soc-dpcm.h |  2 ++
 sound/soc/soc-pcm.c      | 17 ++++++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/include/sound/soc-dpcm.h b/include/sound/soc-dpcm.h
index 8060590..52d9b5d 100644
--- a/include/sound/soc-dpcm.h
+++ b/include/sound/soc-dpcm.h
@@ -86,6 +86,8 @@ struct snd_soc_dpcm {
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *debugfs_state;
 #endif
+
+	bool be_hw_free_deferred;
 };
 
 /*
diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
index 87c9af2..481604a 100644
--- a/sound/soc/soc-pcm.c
+++ b/sound/soc/soc-pcm.c
@@ -1866,8 +1866,16 @@ int dpcm_be_dai_shutdown(struct snd_soc_pcm_runtime *fe, int stream)
 			continue;
 
 		if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_FREE) &&
-		    (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN))
-			continue;
+		    (be->dpcm[stream].state != SND_SOC_DPCM_STATE_OPEN)) {
+			if (dpcm->be_hw_free_deferred) {
+				soc_pcm_hw_free(be_substream);
+				be->dpcm[stream].state =
+					SND_SOC_DPCM_STATE_HW_FREE;
+				dpcm->be_hw_free_deferred = false;
+			} else {
+				continue;
+			}
+		}
 
 		dev_dbg(be->dev, "ASoC: close BE %s\n",
 			be->dai_link->name);
@@ -1924,8 +1932,10 @@ int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
 				continue;
 
 		/* do not free hw if this BE is used by other FE */
-		if (be->dpcm[stream].users > 1)
+		if (be->dpcm[stream].users > 1) {
+			dpcm->be_hw_free_deferred = true;
 			continue;
+		}
 
 		if ((be->dpcm[stream].state != SND_SOC_DPCM_STATE_HW_PARAMS) &&
 		    (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PREPARE) &&
@@ -1941,6 +1951,7 @@ int dpcm_be_dai_hw_free(struct snd_soc_pcm_runtime *fe, int stream)
 		soc_pcm_hw_free(be_substream);
 
 		be->dpcm[stream].state = SND_SOC_DPCM_STATE_HW_FREE;
+		dpcm->be_hw_free_deferred = false;
 	}
 
 	return 0;
-- 
1.9.1

  reply	other threads:[~2018-05-22  9:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-22  9:13 [PATCH 0/2] ASoC: dpcm: fix BE dai not hw_free and shutdown KaiChieh Chuang
2018-05-22  9:13 ` KaiChieh Chuang [this message]
2018-05-25 11:31   ` [PATCH 1/2] " Mark Brown
2018-05-22  9:13 ` [PATCH 2/2] ASoC: dpcm: symmetry constraint on FE substream KaiChieh Chuang
2018-05-29 14:59   ` Applied "ASoC: dpcm: symmetry constraint on FE substream" to the asoc tree Mark Brown

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=1526980408-1935-2-git-send-email-kaichieh.chuang@mediatek.com \
    --to=kaichieh.chuang@mediatek.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=wsd_upstream@mediatek.com \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox