* [PATCH 0/2] ASoC: bcm2835-i2s: Fix clock handling
@ 2026-12-03 6:34 phucduc.bui
2026-12-03 6:34 ` [PATCH 1/2] ASoC: bcm2835-i2s: Remove redundant clock start/stop in trigger path phucduc.bui
2026-12-03 6:34 ` [PATCH 2/2] ASoC: bcm2835-i2s: Check clock enable return value phucduc.bui
0 siblings, 2 replies; 5+ messages in thread
From: phucduc.bui @ 2026-12-03 6:34 UTC (permalink / raw)
To: Mark Brown, Florian Fainelli, bcm-kernel-feedback-list
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Ray Jui,
Scott Branden, linux-sound, Kees Cook, linux-rpi-kernel,
linux-arm-kernel, linux-kernel, Kuninori Morimoto, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
Hi all,
This series removes redundant clock operations from the trigger path
and fixes error handling when enabling the clock.
Compile-tested only.
Best regards,
Phuc
bui duc phuc (2):
ASoC: bcm2835-i2s: Remove redundant clock start/stop in trigger path
ASoC: bcm2835-i2s: Check clock enable return value
sound/soc/bcm/bcm2835-i2s.c | 41 ++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 19 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] ASoC: bcm2835-i2s: Remove redundant clock start/stop in trigger path
2026-12-03 6:34 [PATCH 0/2] ASoC: bcm2835-i2s: Fix clock handling phucduc.bui
@ 2026-12-03 6:34 ` phucduc.bui
2026-12-03 6:34 ` [PATCH 2/2] ASoC: bcm2835-i2s: Check clock enable return value phucduc.bui
1 sibling, 0 replies; 5+ messages in thread
From: phucduc.bui @ 2026-12-03 6:34 UTC (permalink / raw)
To: Mark Brown, Florian Fainelli, bcm-kernel-feedback-list
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Ray Jui,
Scott Branden, linux-sound, Kees Cook, linux-rpi-kernel,
linux-arm-kernel, linux-kernel, Kuninori Morimoto, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
bcm2835_i2s_stop() is called from .trigger and .shutdown, and stops
the clock when the DAI is no longer active and SND_SOC_DAIFMT_CONT is
not set. In .trigger the DAI is always active, so the clock is never
stopped there. In .shutdown, bcm2835_i2s_shutdown() stops the clock
itself right after calling bcm2835_i2s_stop() once no stream is left.
The check in bcm2835_i2s_stop() is therefore not needed and can be
removed.
Likewise, the bcm2835_i2s_start_clock() call in .trigger has no
effect, as the clock has already been started in .hw_params and is
not stopped before the stream is started.
Remove both, which also keeps clk_prepare_enable() and
clk_disable_unprepare(), which may sleep, out of the atomic .trigger
callback. Drop the now unused dai argument of bcm2835_i2s_stop() and
the outdated comment in bcm2835_i2s_shutdown().
No functional change intended.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/bcm/bcm2835-i2s.c | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c
index 8702f1d062df..68be1ded6f93 100644
--- a/sound/soc/bcm/bcm2835-i2s.c
+++ b/sound/soc/bcm/bcm2835-i2s.c
@@ -639,8 +639,7 @@ static int bcm2835_i2s_prepare(struct snd_pcm_substream *substream,
}
static void bcm2835_i2s_stop(struct bcm2835_i2s_dev *dev,
- struct snd_pcm_substream *substream,
- struct snd_soc_dai *dai)
+ struct snd_pcm_substream *substream)
{
uint32_t mask;
@@ -651,10 +650,6 @@ static void bcm2835_i2s_stop(struct bcm2835_i2s_dev *dev,
regmap_update_bits(dev->i2s_regmap,
BCM2835_I2S_CS_A_REG, mask, 0);
-
- /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
- if (!snd_soc_dai_active(dai) && !(dev->fmt & SND_SOC_DAIFMT_CONT))
- bcm2835_i2s_stop_clock(dev);
}
static int bcm2835_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
@@ -667,7 +662,6 @@ static int bcm2835_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- bcm2835_i2s_start_clock(dev);
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
mask = BCM2835_I2S_RXON;
@@ -681,7 +675,7 @@ static int bcm2835_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- bcm2835_i2s_stop(dev, substream, dai);
+ bcm2835_i2s_stop(dev, substream);
break;
default:
return -EINVAL;
@@ -720,7 +714,7 @@ static void bcm2835_i2s_shutdown(struct snd_pcm_substream *substream,
{
struct bcm2835_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
- bcm2835_i2s_stop(dev, substream, dai);
+ bcm2835_i2s_stop(dev, substream);
/* If both streams are stopped, disable module and clock */
if (snd_soc_dai_active(dai))
@@ -730,10 +724,6 @@ static void bcm2835_i2s_shutdown(struct snd_pcm_substream *substream,
regmap_update_bits(dev->i2s_regmap, BCM2835_I2S_CS_A_REG,
BCM2835_I2S_EN, 0);
- /*
- * Stopping clock is necessary, because stop does
- * not stop the clock when SND_SOC_DAIFMT_CONT
- */
bcm2835_i2s_stop_clock(dev);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] ASoC: bcm2835-i2s: Check clock enable return value
2026-12-03 6:34 [PATCH 0/2] ASoC: bcm2835-i2s: Fix clock handling phucduc.bui
2026-12-03 6:34 ` [PATCH 1/2] ASoC: bcm2835-i2s: Remove redundant clock start/stop in trigger path phucduc.bui
@ 2026-12-03 6:34 ` phucduc.bui
2026-12-03 6:51 ` sashiko-bot
1 sibling, 1 reply; 5+ messages in thread
From: phucduc.bui @ 2026-12-03 6:34 UTC (permalink / raw)
To: Mark Brown, Florian Fainelli, bcm-kernel-feedback-list
Cc: Liam Girdwood, Jaroslav Kysela, Takashi Iwai, Ray Jui,
Scott Branden, linux-sound, Kees Cook, linux-rpi-kernel,
linux-arm-kernel, linux-kernel, Kuninori Morimoto, bui duc phuc
From: bui duc phuc <phucduc.bui@gmail.com>
bcm2835_i2s_start_clock() ignores the return value of
clk_prepare_enable() and marks the clock as prepared even on failure,
so bcm2835_i2s_stop_clock() later disables a clock that was never
enabled.
Return the error and only set clk_prepared on success. Propagate it
from .hw_params, and skip clearing the FIFOs in
bcm2835_i2s_clear_fifos(), which cannot be done without the clock.
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
sound/soc/bcm/bcm2835-i2s.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c
index 68be1ded6f93..f367ca070e3a 100644
--- a/sound/soc/bcm/bcm2835-i2s.c
+++ b/sound/soc/bcm/bcm2835-i2s.c
@@ -125,22 +125,29 @@ struct bcm2835_i2s_dev {
int clk_rate;
};
-static void bcm2835_i2s_start_clock(struct bcm2835_i2s_dev *dev)
+static int bcm2835_i2s_start_clock(struct bcm2835_i2s_dev *dev)
{
unsigned int provider = dev->fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK;
+ int ret;
if (dev->clk_prepared)
- return;
+ return 0;
switch (provider) {
case SND_SOC_DAIFMT_BP_FP:
case SND_SOC_DAIFMT_BP_FC:
- clk_prepare_enable(dev->clk);
+ ret = clk_prepare_enable(dev->clk);
+ if (ret) {
+ dev_err(dev->dev, "Failed to enable clock: %d\n", ret);
+ return ret;
+ }
dev->clk_prepared = true;
break;
default:
break;
}
+
+ return 0;
}
static void bcm2835_i2s_stop_clock(struct bcm2835_i2s_dev *dev)
@@ -154,6 +161,7 @@ static void bcm2835_i2s_clear_fifos(struct bcm2835_i2s_dev *dev,
bool tx, bool rx)
{
int timeout = 1000;
+ int ret;
uint32_t syncval;
uint32_t csreg;
uint32_t i2s_active_state;
@@ -173,8 +181,11 @@ static void bcm2835_i2s_clear_fifos(struct bcm2835_i2s_dev *dev,
/* Start clock if not running */
clk_was_prepared = dev->clk_prepared;
- if (!clk_was_prepared)
- bcm2835_i2s_start_clock(dev);
+ if (!clk_was_prepared) {
+ ret = bcm2835_i2s_start_clock(dev);
+ if (ret)
+ return;
+ }
/* Stop I2S module */
regmap_update_bits(dev->i2s_regmap, BCM2835_I2S_CS_A_REG, off, 0);
@@ -424,7 +435,9 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
dev->clk_rate = bclk_rate;
}
- bcm2835_i2s_start_clock(dev);
+ ret = bcm2835_i2s_start_clock(dev);
+ if (ret)
+ return ret;
}
/* Setup the frame format */
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] ASoC: bcm2835-i2s: Check clock enable return value
2026-12-03 6:34 ` [PATCH 2/2] ASoC: bcm2835-i2s: Check clock enable return value phucduc.bui
@ 2026-12-03 6:51 ` sashiko-bot
2026-12-03 7:15 ` Bui Duc Phuc
0 siblings, 1 reply; 5+ messages in thread
From: sashiko-bot @ 2026-12-03 6:51 UTC (permalink / raw)
To: phucduc.bui; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] ASoC: bcm2835-i2s: bcm2835_i2s_clear_fifos() drops clock
enable errors
- [Low] ASoC: bcm2835-i2s: missing Fixes trailer for commit 517e7a1537ae
--
commit f71f2eb66ebb99e713f0cc2faab79f0556d20a07
Author: bui duc phuc <phucduc.bui@gmail.com>
> ASoC: bcm2835-i2s: Check clock enable return value
>
> bcm2835_i2s_start_clock() ignores the return value of
> clk_prepare_enable() and marks the clock as prepared even on failure,
> so bcm2835_i2s_stop_clock() later disables a clock that was never
> enabled.
>
> Return the error and only set clk_prepared on success. Propagate it
> from .hw_params, and skip clearing the FIFOs in
> bcm2835_i2s_clear_fifos(), which cannot be done without the clock.
>
> Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
[Severity: Low]
This fixes a clock-imbalance bug introduced by commit 517e7a1537ae
("ASoC: bcm2835: move to use the clock framework"). Should this
include:
Fixes: 517e7a1537ae ("ASoC: bcm2835: move to use the clock framework")
> diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c
> index 68be1ded6f935..f367ca070e3a2 100644
> --- a/sound/soc/bcm/bcm2835-i2s.c
> +++ b/sound/soc/bcm/bcm2835-i2s.c
[ ... ]
> @@ -173,8 +181,11 @@ static void bcm2835_i2s_clear_fifos(struct bcm2835_i2s_dev *dev,
>
> /* Start clock if not running */
> clk_was_prepared = dev->clk_prepared;
> - if (!clk_was_prepared)
> - bcm2835_i2s_start_clock(dev);
> + if (!clk_was_prepared) {
> + ret = bcm2835_i2s_start_clock(dev);
> + if (ret)
> + return;
> + }
[Severity: Medium]
Does discarding ret here let bcm2835_i2s_prepare() return 0 when the
clock fails to enable, leaving the stream prepared with stale FIFO data
and no active clock?
Even with symmetric_sample_bits set, dev->clk_prepared can be false in
bcm2835_i2s_prepare(). ALSA symmetry checks physical width (32 bits for
both S24_LE and S32_LE), whereas bcm2835_i2s_hw_params() derives
bclk_rate from logical width via snd_soc_params_to_bclk().
If an S24_LE stream stops or xruns with a non-empty FIFO, a full-duplex
S32_LE stream in bcm2835_i2s_hw_params() stops the clock and can fail to
restart it. When the first stream then calls bcm2835_i2s_prepare(), the
clock error is dropped and bcm2835_i2s_prepare() returns 0.
Both callers (bcm2835_i2s_hw_params() and bcm2835_i2s_prepare()) already
return int, so bcm2835_i2s_clear_fifos() could return int and propagate
the error.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203063435.13517-1-phucduc.bui@gmail.com?part=2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] ASoC: bcm2835-i2s: Check clock enable return value
2026-12-03 6:51 ` sashiko-bot
@ 2026-12-03 7:15 ` Bui Duc Phuc
0 siblings, 0 replies; 5+ messages in thread
From: Bui Duc Phuc @ 2026-12-03 7:15 UTC (permalink / raw)
To: sashiko-reviews; +Cc: linux-sound
>
> [Severity: Low]
> This fixes a clock-imbalance bug introduced by commit 517e7a1537ae
> ("ASoC: bcm2835: move to use the clock framework"). Should this
> include:
>
> Fixes: 517e7a1537ae ("ASoC: bcm2835: move to use the clock framework")
>
I don't consider this a major issue, so I don't think a Fixes tag is strictly
necessary. However, since I'm preparing v2 anyway, I'll add it.
>
> Both callers (bcm2835_i2s_hw_params() and bcm2835_i2s_prepare()) already
> return int, so bcm2835_i2s_clear_fifos() could return int and propagate
> the error.
>
Good point. I'll change bcm2835_i2s_clear_fifos() to return int and propagate
the error to its callers.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-03 7:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 6:34 [PATCH 0/2] ASoC: bcm2835-i2s: Fix clock handling phucduc.bui
2026-12-03 6:34 ` [PATCH 1/2] ASoC: bcm2835-i2s: Remove redundant clock start/stop in trigger path phucduc.bui
2026-12-03 6:34 ` [PATCH 2/2] ASoC: bcm2835-i2s: Check clock enable return value phucduc.bui
2026-12-03 6:51 ` sashiko-bot
2026-12-03 7:15 ` Bui Duc Phuc
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox