Commit da18396f authored by Mark Brown's avatar Mark Brown

ASoC: core: Allow digital mute for capture

Help avoid noise from the power up of the capture path propagating through
into the start of the recording (especially noise caused by the ramp of
microphone biases) by keeping the capture muted until after we've finished
powering things up with DAPM in the same manner we do for playback. This
allows us to take advantage of soft mute support in the hardware more
effectively and is more consistent.

The core code using the existing digital mute operation is updated to take
advantage of this. Some additional cases in the soc-pcm code and suspend
will need separate handling but these are less practically relevant than
the main runtime stream start/stop case.

Rather than refactor the digital mute function in every single driver a
new operation is added for drivers taking advantage of this functionality,
the old operation should be phased out over time.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by Vinod Koul <vinod.koul@intel.com>
Acked-by: default avatarLiam Girdwood <liam.r.girdwood@linux.intel.com>
parent e38b9b74
...@@ -126,7 +126,8 @@ int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai, ...@@ -126,7 +126,8 @@ int snd_soc_dai_set_channel_map(struct snd_soc_dai *dai,
int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate); int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate);
/* Digital Audio Interface mute */ /* Digital Audio Interface mute */
int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute); int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
int direction);
struct snd_soc_dai_ops { struct snd_soc_dai_ops {
/* /*
...@@ -157,6 +158,7 @@ struct snd_soc_dai_ops { ...@@ -157,6 +158,7 @@ struct snd_soc_dai_ops {
* Called by soc-core to minimise any pops. * Called by soc-core to minimise any pops.
*/ */
int (*digital_mute)(struct snd_soc_dai *dai, int mute); int (*digital_mute)(struct snd_soc_dai *dai, int mute);
int (*mute_stream)(struct snd_soc_dai *dai, int mute, int stream);
/* /*
* ALSA PCM audio operations - all optional. * ALSA PCM audio operations - all optional.
......
...@@ -116,12 +116,13 @@ static int soc_compr_free(struct snd_compr_stream *cstream) ...@@ -116,12 +116,13 @@ static int soc_compr_free(struct snd_compr_stream *cstream)
if (cstream->direction == SND_COMPRESS_PLAYBACK) { if (cstream->direction == SND_COMPRESS_PLAYBACK) {
cpu_dai->playback_active--; cpu_dai->playback_active--;
codec_dai->playback_active--; codec_dai->playback_active--;
snd_soc_dai_digital_mute(codec_dai, 1);
} else { } else {
cpu_dai->capture_active--; cpu_dai->capture_active--;
codec_dai->capture_active--; codec_dai->capture_active--;
} }
snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction);
cpu_dai->active--; cpu_dai->active--;
codec_dai->active--; codec_dai->active--;
codec->active--; codec->active--;
...@@ -178,15 +179,13 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd) ...@@ -178,15 +179,13 @@ static int soc_compr_trigger(struct snd_compr_stream *cstream, int cmd)
goto out; goto out;
} }
if (cstream->direction == SND_COMPRESS_PLAYBACK) { switch (cmd) {
switch (cmd) { case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_START: snd_soc_dai_digital_mute(codec_dai, 0, cstream->direction);
snd_soc_dai_digital_mute(codec_dai, 0); break;
break; case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_STOP: snd_soc_dai_digital_mute(codec_dai, 1, cstream->direction);
snd_soc_dai_digital_mute(codec_dai, 1); break;
break;
}
} }
out: out:
......
...@@ -3540,12 +3540,20 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate); ...@@ -3540,12 +3540,20 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
* snd_soc_dai_digital_mute - configure DAI system or master clock. * snd_soc_dai_digital_mute - configure DAI system or master clock.
* @dai: DAI * @dai: DAI
* @mute: mute enable * @mute: mute enable
* @direction: stream to mute
* *
* Mutes the DAI DAC. * Mutes the DAI DAC.
*/ */
int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
int direction)
{ {
if (dai->driver && dai->driver->ops->digital_mute) if (!dai->driver)
return -ENOTSUPP;
if (dai->driver->ops->mute_stream)
return dai->driver->ops->mute_stream(dai, mute, direction);
else if (direction == SNDRV_PCM_STREAM_PLAYBACK &&
dai->driver->ops->digital_mute)
return dai->driver->ops->digital_mute(dai, mute); return dai->driver->ops->digital_mute(dai, mute);
else else
return -ENOTSUPP; return -ENOTSUPP;
......
...@@ -3247,14 +3247,16 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w, ...@@ -3247,14 +3247,16 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
break; break;
case SND_SOC_DAPM_POST_PMU: case SND_SOC_DAPM_POST_PMU:
ret = snd_soc_dai_digital_mute(sink, 0); ret = snd_soc_dai_digital_mute(sink, 0,
SNDRV_PCM_STREAM_PLAYBACK);
if (ret != 0 && ret != -ENOTSUPP) if (ret != 0 && ret != -ENOTSUPP)
dev_warn(sink->dev, "ASoC: Failed to unmute: %d\n", ret); dev_warn(sink->dev, "ASoC: Failed to unmute: %d\n", ret);
ret = 0; ret = 0;
break; break;
case SND_SOC_DAPM_PRE_PMD: case SND_SOC_DAPM_PRE_PMD:
ret = snd_soc_dai_digital_mute(sink, 1); ret = snd_soc_dai_digital_mute(sink, 1,
SNDRV_PCM_STREAM_PLAYBACK);
if (ret != 0 && ret != -ENOTSUPP) if (ret != 0 && ret != -ENOTSUPP)
dev_warn(sink->dev, "ASoC: Failed to mute: %d\n", ret); dev_warn(sink->dev, "ASoC: Failed to mute: %d\n", ret);
ret = 0; ret = 0;
......
...@@ -383,8 +383,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream) ...@@ -383,8 +383,7 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
/* Muting the DAC suppresses artifacts caused during digital /* Muting the DAC suppresses artifacts caused during digital
* shutdown, for example from stopping clocks. * shutdown, for example from stopping clocks.
*/ */
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) snd_soc_dai_digital_mute(codec_dai, 1, substream->stream);
snd_soc_dai_digital_mute(codec_dai, 1);
if (cpu_dai->driver->ops->shutdown) if (cpu_dai->driver->ops->shutdown)
cpu_dai->driver->ops->shutdown(substream, cpu_dai); cpu_dai->driver->ops->shutdown(substream, cpu_dai);
...@@ -488,7 +487,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream) ...@@ -488,7 +487,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
snd_soc_dapm_stream_event(rtd, substream->stream, snd_soc_dapm_stream_event(rtd, substream->stream,
SND_SOC_DAPM_STREAM_START); SND_SOC_DAPM_STREAM_START);
snd_soc_dai_digital_mute(codec_dai, 0); snd_soc_dai_digital_mute(codec_dai, 0, substream->stream);
out: out:
mutex_unlock(&rtd->pcm_mutex); mutex_unlock(&rtd->pcm_mutex);
...@@ -586,7 +585,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream) ...@@ -586,7 +585,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
/* apply codec digital mute */ /* apply codec digital mute */
if (!codec->active) if (!codec->active)
snd_soc_dai_digital_mute(codec_dai, 1); snd_soc_dai_digital_mute(codec_dai, 1, substream->stream);
/* free any machine hw params */ /* free any machine hw params */
if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free) if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
......
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