* [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; 3+ 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 [flat|nested] 3+ 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
1 sibling, 0 replies; 3+ 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 [flat|nested] 3+ messages in thread