Jump to content

Avoid A13 Audio Stand-by


FrikoAnPulento

Recommended Posts

Hello,

I've recently build a custom image for Olimex's A13 SOM

(details here)

### armbian-release:

# PLEASE DO NOT EDIT THIS FILE
BOARD=olimex-som-a13
BOARD_NAME="SOM-A13"
BOARDFAMILY=sun5i
BUILD_REPOSITORY_URL=https://github.com/olimex/build
BUILD_REPOSITORY_COMMIT=65b71245
VERSION=5.92
LINUXFAMILY=sunxi
BRANCH=next
ARCH=arm
IMAGE_TYPE=user-built
BOARD_TYPE=csc
INITRD_ARCH=arm
KERNEL_IMAGE_TYPE=zImage

 

uname -r

5.0.21-sunxi

 

I am able to play audio via DAC output using alsa.

 

What I've noticed is that when I play and audio file for the first time (in the last 5 seconds) it starts very quiet, than the volume increases to a normal loudness.

If I play the same file again immediately after its end the volume is normal.

 

After 5 seconds without playing anything I hear a "click" from the speaker and after that, if I play a file, it starts again very quiet.

 

I tried with both mplayer and mpg123, so I think the problem is in alsa settings.

I've searched about alsa standby, but I didn't find anything.

 

Can someone help me?

 

In the attachments my /var/lib/alsa/asound.state

 

 

asound.state

Link to comment
Share on other sites

Ok, it seems like the problem lays in the hardware.

In latest kernel's sun4i-codec driver I found this:

static int sun4i_codec_spk_event(struct snd_soc_dapm_widget *w,
                 struct snd_kcontrol *k, int event)
{
    struct sun4i_codec *scodec = snd_soc_card_get_drvdata(w->dapm->card);

    gpiod_set_value_cansleep(scodec->gpio_pa,
                 !!SND_SOC_DAPM_EVENT_ON(event));

    if (SND_SOC_DAPM_EVENT_ON(event)) {
        /*
         * Need a delay to wait for DAC to push the data. 700ms seems
         * to be the best compromise not to feel this delay while
         * playing a sound.
         */
        msleep(700);
    }

    return 0;
}

 

I've added the same msleep(700) to my kernel via userpatches and I solved the problem.

(I know I should use the last kernel version, but I'm bounded to olimex's patches to make armbian work on A13, and they didn't update them)

Link to comment
Share on other sites

Find a bettere solution:

msleep introduces audio latency.

I need to have real time audio, so I've changed my approach to this:

First, I've disabled power management for A13's power amplifier:

From e3838f63a589e8e49b071f0c3d8646bc9cd01582 Mon Sep 17 00:00:00 2001
From: Marjan Trexom <****>
Date: Tue, 8 Sep 2020 12:15:20 +0200
Subject: [PATCH] disable EN_DA and PA_EN

---
 sound/soc/sunxi/sun4i-codec.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sound/soc/sunxi/sun4i-codec.c b/sound/soc/sunxi/sun4i-codec.c
index a84e83085..018cc9656 100644
--- a/sound/soc/sunxi/sun4i-codec.c
+++ b/sound/soc/sunxi/sun4i-codec.c
@@ -706,8 +706,8 @@ static const struct snd_soc_dapm_widget sun4i_codec_codec_dapm_widgets[] = {
 			    NULL, 0),
 
 	/* Digital parts of the DACs */
-	SND_SOC_DAPM_SUPPLY("DAC", SUN4I_CODEC_DAC_DPC,
-			    SUN4I_CODEC_DAC_DPC_EN_DA, 0,
+	SND_SOC_DAPM_SUPPLY("DAC", SND_SOC_NOPM,
+			    0, 0,
 			    NULL, 0),
 
 	/* Analog parts of the ADCs */
@@ -743,8 +743,8 @@ static const struct snd_soc_dapm_widget sun4i_codec_codec_dapm_widgets[] = {
 			 SUN4I_CODEC_ADC_ACTL_PREG1EN, 0, NULL, 0),
 
 	/* Power Amplifier */
-	SND_SOC_DAPM_MIXER("Power Amplifier", SUN4I_CODEC_ADC_ACTL,
-			   SUN4I_CODEC_ADC_ACTL_PA_EN, 0,
+	SND_SOC_DAPM_MIXER("Power Amplifier", SND_SOC_NOPM,
+			   0, 0,
 			   sun4i_codec_pa_mixer_controls,
 			   ARRAY_SIZE(sun4i_codec_pa_mixer_controls)),
 	SND_SOC_DAPM_SWITCH("Power Amplifier Mute", SND_SOC_NOPM, 0, 0,
-- 
2.17.1

Than, power amplifier was off by default (DAPM is responsible for turning on various widgets), so I've manually edit the register bit in the probe function

From 78fbd23b3eae8e442e5a7d67814a961bd5579e73 Mon Sep 17 00:00:00 2001
From: Marjan Trexom <****>
Date: Tue, 8 Sep 2020 16:01:00 +0200
Subject: [PATCH] Manually Enable PA in probe

---
 sound/soc/sunxi/sun4i-codec.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/sound/soc/sunxi/sun4i-codec.c b/sound/soc/sunxi/sun4i-codec.c
index 018cc9656..db6b1f18d 100644
--- a/sound/soc/sunxi/sun4i-codec.c
+++ b/sound/soc/sunxi/sun4i-codec.c
@@ -224,6 +224,26 @@
 
 /* TODO H3 DAP (Digital Audio Processing) bits */
 
+/* register bit change*/
+int codec_wrreg_bit(void __iomem *reg, unsigned int bit, unsigned int bvalue)
+{
+	int change;
+	unsigned int old, new, mask, value;
+
+	mask=0x1<<bit;
+	value=bvalue<<bit;
+	
+	old	=	readl((reg));
+	new	=	(old & ~mask) | value;
+	change = old != new;
+
+	if (change){
+		writel((new),(reg));
+	}
+
+	return change;
+}
+
 struct sun4i_codec {
 	struct device	*dev;
 	struct regmap	*regmap;
@@ -1701,6 +1721,9 @@ static int sun4i_codec_probe(struct platform_device *pdev)
 		goto err_assert_reset;
 	}
 
+	codec_wrreg_bit(base+SUN4I_CODEC_DAC_DPC, SUN4I_CODEC_DAC_DPC_EN_DA,	0x1);
+	codec_wrreg_bit(base+SUN4I_CODEC_ADC_ACTL, SUN4I_CODEC_ADC_ACTL_PA_EN,	0x1);
+
 	return 0;
 
 err_assert_reset:
-- 
2.17.1

Now you can enjoy real-time audio on your A13 without annoying fade in!

 

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines