From: Valerio Setti <vsetti@baylibre.com>
To: Jerome Brunet <jbrunet@baylibre.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Kevin Hilman <khilman@baylibre.com>,
Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
linux-sound@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-amlogic@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 3/7] ASoC: meson: aiu-encoder-i2s: ensure clk divider gets disabled in hw_free
Date: Mon, 12 Oct 2026 17:14:07 +0200 [thread overview]
Message-ID: <d90324be-c43d-4d28-9f1a-e28e437031e8@baylibre.com> (raw)
In-Reply-To: <1j5wzdzyqm.fsf@starbuckisacylon.baylibre.com>
Hi, thanks for the feedback and sorry for the late reply.
>> diff --git a/sound/soc/meson/aiu-encoder-i2s.c b/sound/soc/meson/aiu-encoder-i2s.c
>> index 58dce9f08c9d..70ea39c77b32 100644
>> --- a/sound/soc/meson/aiu-encoder-i2s.c
>> +++ b/sound/soc/meson/aiu-encoder-i2s.c
>> @@ -219,16 +219,14 @@ static int aiu_encoder_i2s_hw_free(struct snd_pcm_substream *substream,
>> struct snd_soc_dai *dai)
>> {
>> struct gx_stream *ts = snd_soc_dai_get_dma_data(dai, substream);
>> + struct gx_stream *other = snd_soc_dai_dma_data_get(dai, !substream->stream);
>
> Not sure about peeking on the other path like this :/
Yeah, I know this is perhaps not the nicest approach, but it's the same
one I used for the bs-quirk handling (see the "startup()" and
"hw_params()" callbacks). Since there can only be the playback and the
capture stream, checking the other stream's "clk_enabled" is equivalent
to a user counter in "gx_iface", without adding a second piece of state
that has to be kept in sync with it.
Is that acceptable to you?
>> struct snd_soc_component *component = dai->component;
>>
>> - /*
>> - * If this is the last substream being closed then disable the i2s
>> - * clock divider.
>> - */
>> - if (snd_soc_dai_active(dai) <= 1)
>> - aiu_encoder_i2s_divider_enable(component, 0);
>> -
>> if (ts->clk_enabled) {
>> + /* Disable the clk divider only if also the other stream is not using it */
>> + if (!other || !other->clk_enabled)
>> + aiu_encoder_i2s_divider_enable(component, false);
>> +
>
> Looks like a race condition is possible here if one stream closes while
> the other one starts.
>
> I think you need a common structure between the 2 paths (with a counter
> possibly) and it needs to be protected by a lock.
>
I might be wrong, but I'm not sure a race condition can happen while
managing these 2 clocks. Here's what I found:
- "iface->mclk" and "i2s_divider" are enabled/disabled on
"prepare()"/"hw_free()" respectively.
- when "prepare()"/"hw_free()" are called the framework holds the
"card->pcm_mutex".
So when one stream performs one operation, either "prepare()" or
"hw_free()", it can read and modify (if needed) "ts->clk_enabled" both
for itself and for the other stream safely.
Am I missing something?
--
Valerio
next prev parent reply other threads:[~2026-10-12 15:14 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 16:06 [PATCH v4 0/7] ASoC: meson: gx: add base support for I2S audio input Valerio Setti
2026-10-01 16:06 ` [PATCH v4 1/7] ASoC: dt-bindings: add amlogic,gxbb-audin Valerio Setti
2026-10-02 9:42 ` Krzysztof Kozlowski
2026-10-01 16:06 ` [PATCH v4 2/7] ASoC: meson: build gx-formatter as a separate module Valerio Setti
2026-10-07 8:34 ` Jerome Brunet
2026-10-01 16:06 ` [PATCH v4 3/7] ASoC: meson: aiu-encoder-i2s: ensure clk divider gets disabled in hw_free Valerio Setti
2026-10-07 8:44 ` Jerome Brunet
2026-10-12 15:14 ` Valerio Setti [this message]
2026-10-01 16:06 ` [PATCH v4 4/7] ASoC: meson: add AUDIN driver Valerio Setti
2026-10-01 16:06 ` [PATCH v4 5/7] ASoC: meson: aiu: add I2S Capture DAI Valerio Setti
2026-10-07 8:48 ` Jerome Brunet
2026-10-01 16:06 ` [PATCH v4 6/7] ASoC: meson: gx-card: add support for audin FIFO Valerio Setti
2026-10-07 8:50 ` Jerome Brunet
2026-10-01 16:06 ` [PATCH v4 7/7] arm64: dts: amlogic: gx: add AUDIN node Valerio Setti
2026-10-07 8:54 ` Jerome Brunet
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=d90324be-c43d-4d28-9f1a-e28e437031e8@baylibre.com \
--to=vsetti@baylibre.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jbrunet@baylibre.com \
--cc=khilman@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=martin.blumenstingl@googlemail.com \
--cc=neil.armstrong@linaro.org \
--cc=perex@perex.cz \
--cc=robh@kernel.org \
--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
all inboxes | Powered by JetHome®