All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Mylène Josserand" <mylene.josserand@free-electrons.com>
To: lgirdwood@gmail.com, broonie@kernel.org, perex@perex.cz,
	tiwai@suse.com, maxime.ripard@free-electrons.com, wens@csie.org,
	mturquette@baylibre.com, sboyd@codeaurora.org,
	mark.rutland@arm.com, robh+dt@kernel.org
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
	alsa-devel@alsa-project.org, devicetree@vger.kernel.org,
	linux-sunxi@googlegroups.com,
	thomas.petazzoni@free-electrons.com,
	mylene.josserand@free-electrons.com,
	alexandre.belloni@free-electrons.com
Subject: [PATCH v2 06/10] ASoC: sun8i-codec-analog: Add amplifier event to fix first delay
Date: Tue, 17 Jan 2017 15:02:26 +0100	[thread overview]
Message-ID: <20170117140230.23142-7-mylene.josserand@free-electrons.com> (raw)
In-Reply-To: <20170117140230.23142-1-mylene.josserand@free-electrons.com>

When playing a sound for the first time, a short delay, where the audio
file is not played, can be noticed.
On a second play (right after), the sound is played correctly.
If we wait a short time (~5 sec which corresponds to the aplay
timeout), the delay is back.

This patch fixes it by using an event on headphone amplifier.
It allows to keep the amplifier enable while playing a sound.
A delay of 700ms allows to wait that the amplifier is powered-up
before playing the sound.

Signed-off-by: Mylène Josserand <mylene.josserand@free-electrons.com>
---
 sound/soc/sunxi/sun8i-codec-analog.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/sound/soc/sunxi/sun8i-codec-analog.c b/sound/soc/sunxi/sun8i-codec-analog.c
index af02290ebe49..72331332b72e 100644
--- a/sound/soc/sunxi/sun8i-codec-analog.c
+++ b/sound/soc/sunxi/sun8i-codec-analog.c
@@ -398,11 +398,37 @@ static const struct snd_kcontrol_new sun8i_codec_hp_src[] = {
 		      sun8i_codec_hp_src_enum),
 };
 
+static int sun8i_headphone_amp_event(struct snd_soc_dapm_widget *w,
+				     struct snd_kcontrol *k, int event)
+{
+	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+
+	if (SND_SOC_DAPM_EVENT_ON(event)) {
+		snd_soc_component_update_bits(component, SUN8I_ADDA_PAEN_HP_CTRL,
+					      BIT(SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN),
+					      BIT(SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN));
+		/*
+		 * Need a delay to have the amplifier up. 700ms seems the best
+		 * compromise between the time to let the amplifier up and the
+		 * time not to feel this delay while playing a sound.
+		 */
+		msleep(700);
+	} else if (SND_SOC_DAPM_EVENT_OFF(event)) {
+		snd_soc_component_update_bits(component, SUN8I_ADDA_PAEN_HP_CTRL,
+					      BIT(SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN),
+					      0x0);
+	}
+
+	return 0;
+}
+
 static const struct snd_soc_dapm_widget sun8i_codec_headphone_widgets[] = {
 	SND_SOC_DAPM_MUX("Headphone Source Playback Route",
 			 SND_SOC_NOPM, 0, 0, sun8i_codec_hp_src),
-	SND_SOC_DAPM_OUT_DRV("Headphone Amp", SUN8I_ADDA_PAEN_HP_CTRL,
-			     SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN, 0, NULL, 0),
+	SND_SOC_DAPM_OUT_DRV_E("Headphone Amp", SUN8I_ADDA_PAEN_HP_CTRL,
+			       SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN, 0, NULL, 0,
+			       sun8i_headphone_amp_event,
+			       SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
 	SND_SOC_DAPM_SUPPLY("HPCOM Protection", SUN8I_ADDA_PAEN_HP_CTRL,
 			    SUN8I_ADDA_PAEN_HP_CTRL_COMPTEN, 0, NULL, 0),
 	SND_SOC_DAPM_REG(snd_soc_dapm_supply, "HPCOM", SUN8I_ADDA_PAEN_HP_CTRL,
-- 
2.11.0

WARNING: multiple messages have this Message-ID (diff)
From: mylene.josserand@free-electrons.com (Mylène Josserand)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 06/10] ASoC: sun8i-codec-analog: Add amplifier event to fix first delay
Date: Tue, 17 Jan 2017 15:02:26 +0100	[thread overview]
Message-ID: <20170117140230.23142-7-mylene.josserand@free-electrons.com> (raw)
In-Reply-To: <20170117140230.23142-1-mylene.josserand@free-electrons.com>

When playing a sound for the first time, a short delay, where the audio
file is not played, can be noticed.
On a second play (right after), the sound is played correctly.
If we wait a short time (~5 sec which corresponds to the aplay
timeout), the delay is back.

This patch fixes it by using an event on headphone amplifier.
It allows to keep the amplifier enable while playing a sound.
A delay of 700ms allows to wait that the amplifier is powered-up
before playing the sound.

Signed-off-by: Myl?ne Josserand <mylene.josserand@free-electrons.com>
---
 sound/soc/sunxi/sun8i-codec-analog.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/sound/soc/sunxi/sun8i-codec-analog.c b/sound/soc/sunxi/sun8i-codec-analog.c
index af02290ebe49..72331332b72e 100644
--- a/sound/soc/sunxi/sun8i-codec-analog.c
+++ b/sound/soc/sunxi/sun8i-codec-analog.c
@@ -398,11 +398,37 @@ static const struct snd_kcontrol_new sun8i_codec_hp_src[] = {
 		      sun8i_codec_hp_src_enum),
 };
 
+static int sun8i_headphone_amp_event(struct snd_soc_dapm_widget *w,
+				     struct snd_kcontrol *k, int event)
+{
+	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
+
+	if (SND_SOC_DAPM_EVENT_ON(event)) {
+		snd_soc_component_update_bits(component, SUN8I_ADDA_PAEN_HP_CTRL,
+					      BIT(SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN),
+					      BIT(SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN));
+		/*
+		 * Need a delay to have the amplifier up. 700ms seems the best
+		 * compromise between the time to let the amplifier up and the
+		 * time not to feel this delay while playing a sound.
+		 */
+		msleep(700);
+	} else if (SND_SOC_DAPM_EVENT_OFF(event)) {
+		snd_soc_component_update_bits(component, SUN8I_ADDA_PAEN_HP_CTRL,
+					      BIT(SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN),
+					      0x0);
+	}
+
+	return 0;
+}
+
 static const struct snd_soc_dapm_widget sun8i_codec_headphone_widgets[] = {
 	SND_SOC_DAPM_MUX("Headphone Source Playback Route",
 			 SND_SOC_NOPM, 0, 0, sun8i_codec_hp_src),
-	SND_SOC_DAPM_OUT_DRV("Headphone Amp", SUN8I_ADDA_PAEN_HP_CTRL,
-			     SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN, 0, NULL, 0),
+	SND_SOC_DAPM_OUT_DRV_E("Headphone Amp", SUN8I_ADDA_PAEN_HP_CTRL,
+			       SUN8I_ADDA_PAEN_HP_CTRL_HPPAEN, 0, NULL, 0,
+			       sun8i_headphone_amp_event,
+			       SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_PRE_PMD),
 	SND_SOC_DAPM_SUPPLY("HPCOM Protection", SUN8I_ADDA_PAEN_HP_CTRL,
 			    SUN8I_ADDA_PAEN_HP_CTRL_COMPTEN, 0, NULL, 0),
 	SND_SOC_DAPM_REG(snd_soc_dapm_supply, "HPCOM", SUN8I_ADDA_PAEN_HP_CTRL,
-- 
2.11.0

  parent reply	other threads:[~2017-01-17 14:04 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-17 14:02 [PATCH v2 00/10] Add sun8i A33 audio driver Mylène Josserand
2017-01-17 14:02 ` Mylène Josserand
2017-01-17 14:02 ` Mylène Josserand
2017-01-17 14:02 ` [PATCH v2 01/10] ASoC: sun4i-i2s: Increase DMA max burst to 8 Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand
2017-01-17 16:41   ` Maxime Ripard
2017-01-17 16:41     ` Maxime Ripard
2017-01-17 16:41     ` Maxime Ripard
2017-01-17 18:44   ` Applied "ASoC: sun4i-i2s: Increase DMA max burst to 8" to the asoc tree Mark Brown
2017-01-17 18:44     ` Mark Brown
2017-01-17 18:44     ` Mark Brown
2017-01-17 14:02 ` [PATCH v2 02/10] clk: ccu-sun8i-a33: Add CLK_SET_RATE_PARENT to ac-dig Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand
2017-01-17 16:44   ` Maxime Ripard
2017-01-17 16:44     ` Maxime Ripard
2017-01-17 16:44     ` Maxime Ripard
2017-01-18  7:58     ` Mylene Josserand
2017-01-18  7:58       ` Mylene Josserand
2017-01-17 14:02 ` [PATCH v2 03/10] dt-bindings: sound: Add new reset compatible for sun4i-i2s Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand
2017-01-17 16:46   ` Maxime Ripard
2017-01-17 16:46     ` Maxime Ripard
2017-01-17 16:46     ` Maxime Ripard
2017-01-18  8:23     ` Mylene Josserand
2017-01-18  8:23       ` Mylene Josserand
2017-01-17 14:02 ` [PATCH v2 04/10] ASoC: sun4i-i2s: Add quirks to handle new compatible for reset Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand
2017-01-17 16:47   ` Maxime Ripard
2017-01-17 16:47     ` Maxime Ripard
2017-01-17 16:47     ` Maxime Ripard
2017-01-17 14:02 ` [PATCH v2 05/10] ASoC: Add sun8i digital audio codec Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand
2017-01-17 16:20   ` Mylene Josserand
2017-01-17 16:20     ` Mylene Josserand
2017-01-17 14:02 ` Mylène Josserand [this message]
2017-01-17 14:02   ` [PATCH v2 06/10] ASoC: sun8i-codec-analog: Add amplifier event to fix first delay Mylène Josserand
2017-01-17 16:49   ` Maxime Ripard
2017-01-17 16:49     ` Maxime Ripard
2017-01-17 16:49     ` Maxime Ripard
2017-02-03 12:03   ` Applied "ASoC: sun8i-codec-analog: Add amplifier event to fix first delay" to the asoc tree Mark Brown
2017-02-03 12:03     ` Mark Brown
2017-02-03 12:03     ` Mark Brown
2017-01-17 14:02 ` [PATCH v2 07/10] dt-bindings: sound: Add sun8i audio documentation Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand
2017-01-17 16:50   ` Mark Brown
2017-01-17 16:50     ` Mark Brown
2017-01-18  8:25     ` Mylene Josserand
2017-01-18  8:25       ` Mylene Josserand
2017-01-17 16:51   ` Maxime Ripard
2017-01-17 16:51     ` Maxime Ripard
2017-01-17 16:51     ` Maxime Ripard
2017-01-17 14:02 ` [PATCH v2 08/10] ARM: dts: sun8i: Add audio codec, dai and card for A33 Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand
2017-01-17 16:58   ` Maxime Ripard
2017-01-17 16:58     ` Maxime Ripard
2017-01-17 16:58     ` Maxime Ripard
2017-01-17 14:02 ` [PATCH v2 09/10] ARM: dts: sun8i: parrot: Enable audio nodes Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand
2017-01-17 14:02 ` [PATCH v2 10/10] ARM: dts: sun8i: sinlinx: " Mylène Josserand
2017-01-17 14:02   ` Mylène Josserand

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=20170117140230.23142-7-mylene.josserand@free-electrons.com \
    --to=mylene.josserand@free-electrons.com \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sunxi@googlegroups.com \
    --cc=mark.rutland@arm.com \
    --cc=maxime.ripard@free-electrons.com \
    --cc=mturquette@baylibre.com \
    --cc=perex@perex.cz \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@codeaurora.org \
    --cc=thomas.petazzoni@free-electrons.com \
    --cc=tiwai@suse.com \
    --cc=wens@csie.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.