linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Rosin <peda@axentia.se>
To: "Péter Ujfalusi" <peter.ujfalusi@gmail.com>,
	"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Takashi Iwai <tiwai@suse.com>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Kirill Marinushkin <kmarinushkin@birdec.com>,
	Mark Brown <broonie@kernel.org>
Subject: Re: [PATCH] ASoC: pcm512x: Mend accesses to the I2S_1 and I2S_2 registers
Date: Tue, 21 Sep 2021 10:48:01 +0200	[thread overview]
Message-ID: <8b96eb7b-8829-443f-481c-ab1772ece098@axentia.se> (raw)
In-Reply-To: <27f903d9-a74e-182e-b715-4124cf666f45@axentia.se>

[-- Attachment #1: Type: text/plain, Size: 1478 bytes --]

On 2021-09-21 10:10, Peter Rosin wrote:
>>> Can you try the attached patch w/o without the defaults for i2s_1/2?
>>> Not even compile tested...
>>
>> [added a couple of underscores]
>>
>> I get this early during boot/probe
>> [    1.506291] pcm512x 0-004c: pcm512x_set_fmt: failed to read I2S_1: -16
>> [    1.512905] pcm512x 0-004c: pcm512x_set_fmt: failed to read PLL_EN: -16
>> [    1.519517] pcm512x 0-004c: Failed to set data format: -16
>> [    1.525045] pcm512x 0-004c: Failed to set data offset: -16
>>
>> and then this later, triggered from userspace when an app opens
>> the device
>> [   14.620344] pcm512x 0-004c: pcm512x_hw_params: I2S_1: 0x2
>>
>> So, reading *can* work.
> 
> I added some traces and verified that accesses to I2S_1/2 fail (as do
> PLL_EN accesses) when the chip is in Powerdown mode (pcm512x_suspend
> has set the RQPD bit in the POWER register), which it is when
> pcm512x_set_fmt runs. During pcm512x_hw_params the chip is in Standby
> mode instead (pcm512x_resume has cleared the RQPD bit, but the RQST
> bit is set).
> 
> So, my patch seems wrong, and the I2S_1/2 accesses instead need to
> move to some point where the chip is not in Powerdown mode.
> 
> Or, is the problem that pcm512x_set_fmt is called while the codec is
> suspended and the chip thus is in Powerdown mode? Because, that
> seems problematic to me?

Ok, so the attached works for me as well. But I don't know if it's
appropriate to resume/suspend like that?

Cheers,
Peter

[-- Attachment #2: 0001-ASoC-pcm512x-Mend-accesses-to-the-I2S_1-and-I2S_2-re.patch --]
[-- Type: text/plain, Size: 1778 bytes --]

From ac4d55c7741a13d4f209a63cce94a9acbbbf4f25 Mon Sep 17 00:00:00 2001
From: Peter Rosin <peda@axentia.se>
Date: Tue, 21 Sep 2021 10:31:27 +0200
Subject: [PATCH v2] ASoC: pcm512x: Mend accesses to the I2S_1 and I2S_2
 registers

Commit 25d27c4f68d2 ("ASoC: pcm512x: Add support for more data formats")
breaks the TSE-850 device, which is using a pcm5142 in I2S and
CBM_CFS mode (maybe not relevant). Without this fix, the result
is:

pcm512x 0-004c: Failed to set data format: -16

The root cause is that the chip is in Powerdown mode when
pcm512x_set_fmt runs. So, bring the chip out of suspend for
the update of the format.

Fixes: 25d27c4f68d2 ("ASoC: pcm512x: Add support for more data formats")
Signed-off-by: Peter Rosin <peda@axentia.se>
---
 sound/soc/codecs/pcm512x.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/sound/soc/codecs/pcm512x.c b/sound/soc/codecs/pcm512x.c
index 4dc844f3c1fc..07cde6d45233 100644
--- a/sound/soc/codecs/pcm512x.c
+++ b/sound/soc/codecs/pcm512x.c
@@ -1339,6 +1339,7 @@ static int pcm512x_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 	int offset = 0;
 	int clock_output;
 	int master_mode;
+	int resuspend = 0;
 	int ret;
 
 	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
@@ -1396,6 +1397,11 @@ static int pcm512x_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 		return -EINVAL;
 	}
 
+	if (pm_runtime_suspended(component->dev)) {
+		resuspend = 1;
+		pm_runtime_resume(component->dev);
+	}
+
 	ret = regmap_update_bits(pcm512x->regmap, PCM512x_I2S_1,
 				 PCM512x_AFMT, afmt);
 	if (ret != 0) {
@@ -1410,6 +1416,9 @@ static int pcm512x_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
 		return ret;
 	}
 
+	if (resuspend)
+		pm_runtime_suspend(component->dev);
+
 	pcm512x->fmt = fmt;
 
 	return 0;
-- 
2.20.1


  reply	other threads:[~2021-09-21  8:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20 14:49 [PATCH] ASoC: pcm512x: Mend accesses to the I2S_1 and I2S_2 registers Peter Rosin
     [not found] ` <ae4b25f1-2b2c-d937-e23d-0f7d23bdf0c4@gmail.com>
2021-09-20 19:37   ` Peter Rosin
2021-09-20 21:29     ` Mark Brown
2021-09-21  6:37       ` Peter Rosin
2021-09-21 11:11         ` Mark Brown
2021-09-21  4:20     ` Péter Ujfalusi
2021-09-21  6:52       ` Peter Rosin
2021-09-21  8:10         ` Peter Rosin
2021-09-21  8:48           ` Peter Rosin [this message]
2021-09-21 12:01             ` Mark Brown
2021-09-21 13:30               ` Peter Rosin
2021-09-21 15:25 ` 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=8b96eb7b-8829-443f-481c-ab1772ece098@axentia.se \
    --to=peda@axentia.se \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=kmarinushkin@birdec.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter.ujfalusi@gmail.com \
    --cc=tiwai@suse.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;
as well as URLs for NNTP newsgroup(s).