Commit 0f6011fd authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: soc-pcm: merge playback/cature_active into stream_active

DAI has playback_active and capture_active to care usage count.
OTOH, we have SNDRV_PCM_STREAM_PLAYBACK/CAPTURE.
But because of this kind of implementation mismatch,
ALSA SoC has many verbose code.

To solve this issue, this patch merge playback_active/capture_active
into stream_active[2];
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Reviewed-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/875zg5botu.wl-kuninori.morimoto.gx@renesas.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent cae06eb9
...@@ -322,8 +322,7 @@ struct snd_soc_dai { ...@@ -322,8 +322,7 @@ struct snd_soc_dai {
struct snd_soc_dai_driver *driver; struct snd_soc_dai_driver *driver;
/* DAI runtime info */ /* DAI runtime info */
unsigned int capture_active; /* stream usage count */ unsigned int stream_active[SNDRV_PCM_STREAM_LAST + 1]; /* usage count */
unsigned int playback_active; /* stream usage count */
unsigned int active; unsigned int active;
......
...@@ -356,9 +356,9 @@ static int cs4271_hw_params(struct snd_pcm_substream *substream, ...@@ -356,9 +356,9 @@ static int cs4271_hw_params(struct snd_pcm_substream *substream,
*/ */
if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK && if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
!dai->capture_active) || !dai->stream_active[SNDRV_PCM_STREAM_CAPTURE]) ||
(substream->stream == SNDRV_PCM_STREAM_CAPTURE && (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
!dai->playback_active)) { !dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK])) {
ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2, ret = regmap_update_bits(cs4271->regmap, CS4271_MODE2,
CS4271_MODE2_PDN, CS4271_MODE2_PDN,
CS4271_MODE2_PDN); CS4271_MODE2_PDN);
......
...@@ -427,9 +427,9 @@ static int dw_i2s_resume(struct snd_soc_component *component) ...@@ -427,9 +427,9 @@ static int dw_i2s_resume(struct snd_soc_component *component)
clk_enable(dev->clk); clk_enable(dev->clk);
for_each_component_dais(component, dai) { for_each_component_dais(component, dai) {
if (dai->playback_active) if (dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK])
dw_i2s_config(dev, SNDRV_PCM_STREAM_PLAYBACK); dw_i2s_config(dev, SNDRV_PCM_STREAM_PLAYBACK);
if (dai->capture_active) if (dai->stream_active[SNDRV_PCM_STREAM_CAPTURE])
dw_i2s_config(dev, SNDRV_PCM_STREAM_CAPTURE); dw_i2s_config(dev, SNDRV_PCM_STREAM_CAPTURE);
} }
......
...@@ -365,19 +365,20 @@ EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime); ...@@ -365,19 +365,20 @@ EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd) void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
{ {
struct snd_soc_dai *codec_dai = rtd->codec_dai; struct snd_soc_dai *codec_dai = rtd->codec_dai;
int playback = SNDRV_PCM_STREAM_PLAYBACK;
mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass); mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
dev_dbg(rtd->dev, dev_dbg(rtd->dev,
"ASoC: pop wq checking: %s status: %s waiting: %s\n", "ASoC: pop wq checking: %s status: %s waiting: %s\n",
codec_dai->driver->playback.stream_name, codec_dai->driver->playback.stream_name,
codec_dai->playback_active ? "active" : "inactive", codec_dai->stream_active[playback] ? "active" : "inactive",
rtd->pop_wait ? "yes" : "no"); rtd->pop_wait ? "yes" : "no");
/* are we waiting on this codec DAI stream */ /* are we waiting on this codec DAI stream */
if (rtd->pop_wait == 1) { if (rtd->pop_wait == 1) {
rtd->pop_wait = 0; rtd->pop_wait = 0;
snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK, snd_soc_dapm_stream_event(rtd, playback,
SND_SOC_DAPM_STREAM_STOP); SND_SOC_DAPM_STREAM_STOP);
} }
...@@ -514,6 +515,7 @@ int snd_soc_suspend(struct device *dev) ...@@ -514,6 +515,7 @@ int snd_soc_suspend(struct device *dev)
struct snd_soc_card *card = dev_get_drvdata(dev); struct snd_soc_card *card = dev_get_drvdata(dev);
struct snd_soc_component *component; struct snd_soc_component *component;
struct snd_soc_pcm_runtime *rtd; struct snd_soc_pcm_runtime *rtd;
int playback = SNDRV_PCM_STREAM_PLAYBACK;
int i; int i;
/* If the card is not initialized yet there is nothing to do */ /* If the card is not initialized yet there is nothing to do */
...@@ -537,9 +539,8 @@ int snd_soc_suspend(struct device *dev) ...@@ -537,9 +539,8 @@ int snd_soc_suspend(struct device *dev)
continue; continue;
for_each_rtd_codec_dai(rtd, i, dai) { for_each_rtd_codec_dai(rtd, i, dai) {
if (dai->playback_active) if (dai->stream_active[playback])
snd_soc_dai_digital_mute(dai, 1, snd_soc_dai_digital_mute(dai, 1, playback);
SNDRV_PCM_STREAM_PLAYBACK);
} }
} }
...@@ -680,14 +681,14 @@ static void soc_resume_deferred(struct work_struct *work) ...@@ -680,14 +681,14 @@ static void soc_resume_deferred(struct work_struct *work)
/* unmute any active DACs */ /* unmute any active DACs */
for_each_card_rtds(card, rtd) { for_each_card_rtds(card, rtd) {
struct snd_soc_dai *dai; struct snd_soc_dai *dai;
int playback = SNDRV_PCM_STREAM_PLAYBACK;
if (rtd->dai_link->ignore_suspend) if (rtd->dai_link->ignore_suspend)
continue; continue;
for_each_rtd_codec_dai(rtd, i, dai) { for_each_rtd_codec_dai(rtd, i, dai) {
if (dai->playback_active) if (dai->stream_active[playback])
snd_soc_dai_digital_mute(dai, 0, snd_soc_dai_digital_mute(dai, 0, playback);
SNDRV_PCM_STREAM_PLAYBACK);
} }
} }
......
...@@ -100,15 +100,9 @@ static void snd_soc_runtime_action(struct snd_soc_pcm_runtime *rtd, ...@@ -100,15 +100,9 @@ static void snd_soc_runtime_action(struct snd_soc_pcm_runtime *rtd,
lockdep_assert_held(&rtd->card->pcm_mutex); lockdep_assert_held(&rtd->card->pcm_mutex);
if (stream == SNDRV_PCM_STREAM_PLAYBACK) { cpu_dai->stream_active[stream] += action;
cpu_dai->playback_active += action; for_each_rtd_codec_dai(rtd, i, codec_dai)
for_each_rtd_codec_dai(rtd, i, codec_dai) codec_dai->stream_active[stream] += action;
codec_dai->playback_active += action;
} else {
cpu_dai->capture_active += action;
for_each_rtd_codec_dai(rtd, i, codec_dai)
codec_dai->capture_active += action;
}
cpu_dai->active += action; cpu_dai->active += action;
cpu_dai->component->active += action; cpu_dai->component->active += action;
...@@ -967,8 +961,11 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream) ...@@ -967,8 +961,11 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
/* apply codec digital mute */ /* apply codec digital mute */
for_each_rtd_codec_dai(rtd, i, codec_dai) { for_each_rtd_codec_dai(rtd, i, codec_dai) {
if ((playback && codec_dai->playback_active == 1) || int playback_active = codec_dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK];
(!playback && codec_dai->capture_active == 1)) int capture_active = codec_dai->stream_active[SNDRV_PCM_STREAM_CAPTURE];
if ((playback && playback_active == 1) ||
(!playback && capture_active == 1))
snd_soc_dai_digital_mute(codec_dai, 1, snd_soc_dai_digital_mute(codec_dai, 1,
substream->stream); substream->stream);
} }
...@@ -2634,7 +2631,8 @@ static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new) ...@@ -2634,7 +2631,8 @@ static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new)
goto capture; goto capture;
/* skip if FE isn't currently playing */ /* skip if FE isn't currently playing */
if (!fe->cpu_dai->playback_active || !fe->codec_dai->playback_active) if (!fe->cpu_dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK] ||
!fe->codec_dai->stream_active[SNDRV_PCM_STREAM_PLAYBACK])
goto capture; goto capture;
paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list); paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list);
...@@ -2665,7 +2663,8 @@ static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new) ...@@ -2665,7 +2663,8 @@ static int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new)
return 0; return 0;
/* skip if FE isn't currently capturing */ /* skip if FE isn't currently capturing */
if (!fe->cpu_dai->capture_active || !fe->codec_dai->capture_active) if (!fe->cpu_dai->stream_active[SNDRV_PCM_STREAM_CAPTURE] ||
!fe->codec_dai->stream_active[SNDRV_PCM_STREAM_CAPTURE])
return 0; return 0;
paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list); paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment