* [PATCH v2 0/2] ASoC: bcm2835-i2s: Fix clock handling
@ 2026-12-04 3:17 phucduc.bui
2026-12-04 3:17 ` [PATCH v2 1/2] ASoC: bcm2835-i2s: Remove redundant clock start/stop in trigger path phucduc.bui
2026-12-04 3:17 ` [PATCH v2 2/2] ASoC: bcm2835-i2s: Check clock enable return value phucduc.bui
0 siblings, 2 replies; 3+ messages in thread
From: phucduc.bui @ 2026-12-04 3:17 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.
Link v1:
https://lore.kernel.org/all/20261203063435.13517-1-phucduc.bui@gmail.com/
Changes in v2:
- Change bcm2835_i2s_clear_fifos() to return int and propagate
the error to its callers.
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 | 58 +++++++++++++++++++++----------------
1 file changed, 33 insertions(+), 25 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v2 1/2] ASoC: bcm2835-i2s: Remove redundant clock start/stop in trigger path
2026-12-04 3:17 [PATCH v2 0/2] ASoC: bcm2835-i2s: Fix clock handling phucduc.bui
@ 2026-12-04 3:17 ` phucduc.bui
2026-12-04 3:17 ` [PATCH v2 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-04 3:17 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] 3+ messages in thread
* [PATCH v2 2/2] ASoC: bcm2835-i2s: Check clock enable return value
2026-12-04 3:17 [PATCH v2 0/2] ASoC: bcm2835-i2s: Fix clock handling phucduc.bui
2026-12-04 3:17 ` [PATCH v2 1/2] ASoC: bcm2835-i2s: Remove redundant clock start/stop in trigger path phucduc.bui
@ 2026-12-04 3:17 ` phucduc.bui
1 sibling, 0 replies; 3+ messages in thread
From: phucduc.bui @ 2026-12-04 3:17 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 .prepare, and skip clearing the FIFOs when the
clock cannot be enabled.
Fixes: 517e7a1537ae ("ASoC: bcm2835: move to use the clock framework")
Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
Changes in v2:
- Change bcm2835_i2s_clear_fifos() to return int and propagate
the error to its callers.
sound/soc/bcm/bcm2835-i2s.c | 42 ++++++++++++++++++++++++++-----------
1 file changed, 30 insertions(+), 12 deletions(-)
diff --git a/sound/soc/bcm/bcm2835-i2s.c b/sound/soc/bcm/bcm2835-i2s.c
index 68be1ded6f93..385e2ba803b8 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)
@@ -150,10 +157,11 @@ static void bcm2835_i2s_stop_clock(struct bcm2835_i2s_dev *dev)
dev->clk_prepared = false;
}
-static void bcm2835_i2s_clear_fifos(struct bcm2835_i2s_dev *dev,
- bool tx, bool rx)
+static int 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 ret;
+ }
/* Stop I2S module */
regmap_update_bits(dev->i2s_regmap, BCM2835_I2S_CS_A_REG, off, 0);
@@ -214,6 +225,8 @@ static void bcm2835_i2s_clear_fifos(struct bcm2835_i2s_dev *dev,
/* Restore I2S state */
regmap_update_bits(dev->i2s_regmap, BCM2835_I2S_CS_A_REG,
BCM2835_I2S_RXON | BCM2835_I2S_TXON, i2s_active_state);
+
+ return 0;
}
static int bcm2835_i2s_set_dai_fmt(struct snd_soc_dai *dai,
@@ -424,7 +437,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 */
@@ -589,7 +604,9 @@ static int bcm2835_i2s_hw_params(struct snd_pcm_substream *substream,
| BCM2835_I2S_RX(0x20), 0xffffffff);
/* Clear FIFOs */
- bcm2835_i2s_clear_fifos(dev, true, true);
+ ret = bcm2835_i2s_clear_fifos(dev, true, true);
+ if (ret)
+ return ret;
dev_dbg(dev->dev,
"slots: %d width: %d rx mask: 0x%02x tx_mask: 0x%02x\n",
@@ -619,6 +636,7 @@ static int bcm2835_i2s_prepare(struct snd_pcm_substream *substream,
{
struct bcm2835_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
uint32_t cs_reg;
+ int ret = 0;
/*
* Clear both FIFOs if the one that should be started
@@ -630,12 +648,12 @@ static int bcm2835_i2s_prepare(struct snd_pcm_substream *substream,
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
&& !(cs_reg & BCM2835_I2S_TXE))
- bcm2835_i2s_clear_fifos(dev, true, false);
+ ret = bcm2835_i2s_clear_fifos(dev, true, false);
else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
&& (cs_reg & BCM2835_I2S_RXD))
- bcm2835_i2s_clear_fifos(dev, false, true);
+ ret = bcm2835_i2s_clear_fifos(dev, false, true);
- return 0;
+ return ret;
}
static void bcm2835_i2s_stop(struct bcm2835_i2s_dev *dev,
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-04 3:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 3:17 [PATCH v2 0/2] ASoC: bcm2835-i2s: Fix clock handling phucduc.bui
2026-12-04 3:17 ` [PATCH v2 1/2] ASoC: bcm2835-i2s: Remove redundant clock start/stop in trigger path phucduc.bui
2026-12-04 3:17 ` [PATCH v2 2/2] ASoC: bcm2835-i2s: Check clock enable return value phucduc.bui
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.