mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paweł Anikiel" <pan@semihalf.com>
To: alsa-devel@alsa-project.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, lgirdwood@gmail.com,
	broonie@kernel.org
Cc: perex@perex.cz, tiwai@suse.com, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, dinguyen@kernel.org,
	lars@metafoo.de, nuno.sa@analog.com, upstream@semihalf.com,
	amstan@chromium.org, "Paweł Anikiel" <pan@semihalf.com>
Subject: [PATCH v2 7/7] ASoC: ssm2602: Add workaround for playback distortions
Date: Mon,  8 May 2023 13:30:37 +0200	[thread overview]
Message-ID: <20230508113037.137627-8-pan@semihalf.com> (raw)
In-Reply-To: <20230508113037.137627-1-pan@semihalf.com>

Apply a workaround for what appears to be a hardware quirk.

The problem seems to happen when enabling "whole chip power" (bit D7
register R6) for the very first time after the chip receives power. If
either "output" (D4) or "DAC" (D3) aren't powered on at that time,
playback becomes very distorted later on.

This happens on the Google Chameleon v3, as well as on a ZYBO Z7-10:
https://ez.analog.com/audio/f/q-a/543726/solved-ssm2603-right-output-offset-issue/480229
I suspect this happens only when using an external MCLK signal (which
is the case for both of these boards).

Here are some experiments run on a Google Chameleon v3. These were run
in userspace using a wrapper around the i2cset utility:
ssmset() {
        i2cset -y 0 0x1a $(($1*2)) $2
}

For each of the following sequences, we apply power to the ssm2603
chip, set the configuration registers R0-R5 and R7-R8, run the selected
sequence, and check for distortions on playback.

  ssmset 0x09 0x01 # core
  ssmset 0x06 0x07 # chip, out, dac
  OK

  ssmset 0x09 0x01 # core
  ssmset 0x06 0x87 # out, dac
  ssmset 0x06 0x07 # chip
  OK

  (disable MCLK)
  ssmset 0x09 0x01 # core
  ssmset 0x06 0x1f # chip
  ssmset 0x06 0x07 # out, dac
  (enable MCLK)
  OK

  ssmset 0x09 0x01 # core
  ssmset 0x06 0x1f # chip
  ssmset 0x06 0x07 # out, dac
  NOT OK

  ssmset 0x06 0x1f # chip
  ssmset 0x09 0x01 # core
  ssmset 0x06 0x07 # out, dac
  NOT OK

  ssmset 0x09 0x01 # core
  ssmset 0x06 0x0f # chip, out
  ssmset 0x06 0x07 # dac
  NOT OK

  ssmset 0x09 0x01 # core
  ssmset 0x06 0x17 # chip, dac
  ssmset 0x06 0x07 # out
  NOT OK

For each of the following sequences, we apply power to the ssm2603
chip, run the selected sequence, issue a reset with R15, configure
R0-R5 and R7-R8, run one of the NOT OK sequences from above, and check
for distortions.

  ssmset 0x09 0x01 # core
  ssmset 0x06 0x07 # chip, out, dac
  OK

  (disable MCLK)
  ssmset 0x09 0x01 # core
  ssmset 0x06 0x07 # chip, out, dac
  (enable MCLK after reset)
  NOT OK

  ssmset 0x09 0x01 # core
  ssmset 0x06 0x17 # chip, dac
  NOT OK

  ssmset 0x09 0x01 # core
  ssmset 0x06 0x0f # chip, out
  NOT OK

  ssmset 0x06 0x07 # chip, out, dac
  NOT OK

Signed-off-by: Paweł Anikiel <pan@semihalf.com>
---
 sound/soc/codecs/ssm2602.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c
index 00b60369b029..c29324403e9d 100644
--- a/sound/soc/codecs/ssm2602.c
+++ b/sound/soc/codecs/ssm2602.c
@@ -53,6 +53,18 @@ static const struct reg_default ssm2602_reg[SSM2602_CACHEREGNUM] = {
 	{ .reg = 0x09, .def = 0x0000 }
 };
 
+/*
+ * ssm2602 register patch
+ * Workaround for playback distortions after power up: activates digital
+ * core, and then powers on output, DAC, and whole chip at the same time
+ */
+
+static const struct reg_sequence ssm2602_patch[] = {
+	{ SSM2602_ACTIVE, 0x01 },
+	{ SSM2602_PWR,    0x07 },
+	{ SSM2602_RESET,  0x00 },
+};
+
 
 /*Appending several "None"s just for OSS mixer use*/
 static const char *ssm2602_input_select[] = {
@@ -598,6 +610,9 @@ static int ssm260x_component_probe(struct snd_soc_component *component)
 		return ret;
 	}
 
+	regmap_register_patch(ssm2602->regmap, ssm2602_patch,
+			      ARRAY_SIZE(ssm2602_patch));
+
 	/* set the update bits */
 	regmap_update_bits(ssm2602->regmap, SSM2602_LINVOL,
 			    LINVOL_LRIN_BOTH, LINVOL_LRIN_BOTH);
-- 
2.40.1.521.gf1e218fcd8-goog


  parent reply	other threads:[~2023-05-08 11:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-08 11:30 [PATCH v2 0/7] Add Chameleon v3 ASoC audio Paweł Anikiel
2023-05-08 11:30 ` [PATCH v2 1/7] ASoC: Add Google Chameleon v3 i2s driver Paweł Anikiel
2023-05-08 11:30 ` [PATCH v2 2/7] ASoC: Add Google Chameleon v3 codec driver Paweł Anikiel
2023-05-08 11:30 ` [PATCH v2 3/7] ASoC: dt-bindings: Add Google Chameleon v3 i2s device Paweł Anikiel
2023-05-08 12:27   ` Rob Herring
2023-05-09  6:14     ` Krzysztof Kozlowski
2023-05-09  6:15   ` Krzysztof Kozlowski
2023-05-08 11:30 ` [PATCH v2 4/7] ASoC: dt-bindings: Add Google Chameleon v3 audio codec Paweł Anikiel
2023-05-08 12:27   ` Rob Herring
2023-05-09  6:18   ` Krzysztof Kozlowski
2023-05-09  9:54     ` Mark Brown
2023-05-09 10:39       ` Paweł Anikiel
2023-05-08 11:30 ` [PATCH v2 5/7] ARM: dts: chameleonv3: Add mute gpio hog Paweł Anikiel
2023-05-08 11:30 ` [PATCH v2 6/7] ARM: dts: chameleonv3: Add Chameleon v3 audio Paweł Anikiel
2023-05-08 11:30 ` Paweł Anikiel [this message]
2023-05-12  4:19 ` (subset) [PATCH v2 0/7] Add Chameleon v3 ASoC audio Mark Brown
2023-05-18 22:29 ` 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=20230508113037.137627-8-pan@semihalf.com \
    --to=pan@semihalf.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=amstan@chromium.org \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dinguyen@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=perex@perex.cz \
    --cc=robh+dt@kernel.org \
    --cc=tiwai@suse.com \
    --cc=upstream@semihalf.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

all inboxes | Powered by JetHome®