ASoC: renesas: fsi: Fix system hang by adding SPU clock
Subsystems (5)
v2 cover ASoC: renesas: fsi: Fix system hang by adding SPU clock
From: bui duc phuc <[email protected]>
Hi all,
The FSI on r8a7740 requires the SPU clock to be enabled before accessing its internal registers. Without this clock, register access can lead to a system hang, even when the FSI functional clock is properly enabled. This series adds the missing clocks and aligns their names with those used in the driver.
Following feedback from Morimoto-san, the driver is refactored to improve stability. Clock initialization is moved from the runtime path to the probe function to simplify the flow and avoid redundant setups. Additionally, the shutdown sequence is reordered to ensure the stream is properly stopped before the hardware is shut down.
Changes in v2:
- DT Bindings:
Define "own" clock and add "spu", "icka/b", "diva/b", "xcka/b" to the clock tree.
Use YAML anchors and "if" rules to enforce clock-names and r8a7740 requirements.
Relocate allOf block and update example with full 8-clock configuration.
- DTS:
Rename "fsi" clock to "own" to match driver implementation. Add missing clock names: "icka", "ickb", "xcka", "xckb".
- In the driver:
Refactor clock initialization.
Reorder shutdown: stop stream before hardware shutdown. Move SPU clock enable/disable handling to fsi_hw_startup/shutdown.
v1 links :
https://lore.kernel.org/all/[email protected]/
Testing:
- Verified on r8a7740 (Armadillo-800EVA): FSI slave / Codec master mode.
- FSI master mode is currently compile-tested only. Full verification requires a dedicated HDMI driver (FSIB) or hardware modifications (resoldering board resistors) (FSIA).Full support for fsidiv requires additional DT bindings and a corresponding driver.
bui duc phuc (6):
ASoC: renesas: fsi: Add shared SPU clock support
ASoC: renesas: fsi: Fix hang by enabling SPU clock
ASoC: renesas: fsi: Fix trigger stop ordering
ASoC: renesas: fsi: refactor clock initialization
arm: dts: renesas: r8a7740: Add clocks for FSI
ASoC: dt-bindings: renesas,fsi: add support for multiple clocks
.../bindings/sound/renesas,fsi.yaml | 61 +++++- arch/arm/boot/dts/renesas/r8a7740.dtsi | 12 +- sound/soc/renesas/fsi.c | 181 ++++++++++-------- 3 files changed, 171 insertions(+), 83 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/6 ASoC: renesas: fsi: Add shared SPU clock support
From: bui duc phuc <[email protected]>
Add SPU clock pointer, reference counter, and locking in fsi_master for shared FSIA/FSIB usage, and initialize them in fsi_probe().
---
Changes in v2:
- Add spu_count to track active users of the SPU clock.
- Add clk_lock mutex to prevent race conditions during SPU clock enable/disable operations.
- Initialize spu_count and clk_lock during driver probe.
sound/soc/renesas/fsi.c | 5 +++++ 1 file changed, 5 insertions(+)
sound/soc/renesas/fsi.c +5 -0
@@ -292,8 +292,11 @@ struct fsi_master {void __iomem *base;struct fsi_priv fsia;struct fsi_priv fsib; +struct clk *clk_spu;const struct fsi_core *core; +int spu_count;spinlock_t lock; +struct mutex clk_lock; }; static inline int fsi_stream_is_play(struct fsi_priv *fsi,
@@ -1961,7 +1964,9 @@ static int fsi_probe(struct platform_device *pdev)/* master setting */ master->core = core; + master->spu_count =0 ;spin_lock_init (&master->lock); +mutex_init (&master->clk_lock);/* FSI A setting */ fsi = &master->fsia;
Signature · 1 line
2.43.0
Kuninori Morimoto
maintainerRe: [PATCH v2 1/6] ASoC: renesas: fsi: Add shared SPU clock support
Hi
Quoted 5 lines
Add SPU clock pointer, reference counter, and locking in
fsi_masterfor shared FSIA/FSIB usage, and initialize them infsi_probe().Signed-off-by bui duc phuc <[email protected]>---
(snip)
Quoted 5 lines
sound/soc/renesas/fsi.c +0
-0
sound/soc/renesas/fsi.c struct fsi_master { · line 300
Quoted 9 lines
sound/soc/renesas/fsi.c +3
-0@@ -292,8 +292,11 @@ struct fsi_master {void __iomem *base;struct fsi_priv fsia;struct fsi_priv fsib; +struct clk *clk_spu;const struct fsi_core *core; +int spu_count;spinlock_t lock; +struct mutex clk_lock; };
You added clk_spu in this patch, but not touched.
When I checked whole patch-set, you initialize it at [4/6], but [2/6] is using it. Maybe it works, but is strange.
The total patch orders are opposite, I think.
I think it can be...
As prepare
- Fix trigger stop ordering
- move fsi_clk_init()
- this just moves the function, no change
As adding new feature
- remains
Thank you for your help !!
Best regards
---
Kuninori Morimoto
Re: [PATCH v2 1/6] ASoC: renesas: fsi: Add shared SPU clock support
Hi,
Thanks for the review and explanation.
Quoted 3 lines
You added
clk_spuin this patch, but not touched.
When I checked whole patch-set, you initialize it at [4/6], but [2/6] is using it. Maybe it works, but is strange.
You are right, clk_spu is used before being initialized.
I was not careful with the patch ordering and only ensured the series worked as a whole.
I understand now and will fix the ordering accordingly.
Best regards,
Phuc
PATCH v2 2/6 ASoC: renesas: fsi: Fix hang by enabling SPU clock
In reply to [email protected]From: bui duc phuc <[email protected]>
Enable/disable the shared SPU clock in hw startup/shutdown. Without this, accessing FSI registers may hang the system.
---
Changes in v2:
- Move SPU clock enable/disable handling from fsi_dai_startup/shutdown to fsi_hw_startup/shutdown
sound/soc/renesas/fsi.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
sound/soc/renesas/fsi.c +17 -0
@@ -1492,6 +1492,18 @@ static int fsi_hw_startup(struct fsi_priv *fsi, struct device *dev) {u32 data =0 ; +int ret =0 ; +/* enable spu clock */ +mutex_lock (&fsi->master->clk_lock); +if (fsi->master->clk_spu && fsi->master->spu_count++ ==0 ) { + ret =clk_prepare_enable (fsi->master->clk_spu); +if (ret <0 ) { + fsi->master->spu_count--; +mutex_unlock (&fsi->master->clk_lock); +return ret; + } + } +mutex_unlock (&fsi->master->clk_lock);/* clock setting */ if (fsi_is_clk_master (fsi))
@@ -1549,6 +1561,11 @@ static int fsi_hw_shutdown(struct fsi_priv *fsi,/* stop master clock */ if (fsi_is_clk_master (fsi))return fsi_clk_disable (dev, fsi); +/* stop spu clock */ +mutex_lock (&fsi->master->clk_lock); +if (fsi->master->clk_spu && --fsi->master->spu_count ==0 ) +clk_disable_unprepare (fsi->master->clk_spu); +mutex_unlock (&fsi->master->clk_lock);return 0 ; }
Signature · 1 line
2.43.0
Kuninori Morimoto
maintainerRe: [PATCH v2 2/6] ASoC: renesas: fsi: Fix hang by enabling SPU clock
Hi
Hi
Quoted 6 lines
Enable/disable the shared SPU clock in hw startup/shutdown. Without this, accessing FSI registers may hang the system.
Suggested-by Kuninori Morimoto <[email protected]>Signed-off-by bui duc phuc <[email protected]>---
(snip)
Quoted 6 lines
sound/soc/renesas/fsi.c +2
-0@@ -1492,6 +1492,18 @@ static int fsi_hw_startup(struct fsi_priv *fsi, struct device *dev) {u32 data =0 ; +int ret =0 ; +/* enable spu clock */
sound/soc/renesas/fsi.c static int fsi_hw_startup(struct fsi_priv *fsi, · line 1506
Quoted 10 lines
sound/soc/renesas/fsi.c +10
-0+mutex_lock (&fsi->master->clk_lock); +if (fsi->master->clk_spu && fsi->master->spu_count++ ==0 ) { + ret =clk_prepare_enable (fsi->master->clk_spu); +if (ret <0 ) { + fsi->master->spu_count--; +mutex_unlock (&fsi->master->clk_lock); +return ret; + } + } +mutex_unlock (&fsi->master->clk_lock);
1st, please insert white line between "int ret = 0;" and "/* enable spu clock */".
2nd, besically, FSI already has "lock", and using it for several protecting. Please re-use it, and don't add random new-lock. It makes code confusable. Then, please use guard().
3rd, I don't like above count inc/dec, and mutex_unlock() style, because the code unnecessarily complicated. It can be...
int ret = 0;
if (master->clk_spu) {
guard(spinlock_irqsave)(&master->lock);
if (master->spu_count == 0)
ret = clk_prepare_enable(master->clk_spu);
master->spu_count++;
}
if (ret < 0)
return ret;I'm not 100% sure, but I guess you need to count up spu_count anyway regardless of clk_prepare_enable() result ?
Thank you for your help !!
Best regards
---
Kuninori Morimoto
Re: [PATCH v2 2/6] ASoC: renesas: fsi: Fix hang by enabling SPU clock
Hi Morimoto-san,
Thank you for your detailed review and feedback.
Quoted 6 lines
1st, please insert white line between "int ret = 0;" and "/* enable spu clock */".
2nd, besically, FSI already has "lock", and using it for several protecting. Please re-use it, and don't add random new-lock. It makes code confusable. Then, please use
guard().
I will fix the coding style and use
guard(spinlock_irqsave)(&master->lock) in v3.
It’s much better than adding a new lock.
Quoted 16 lines
3rd, I don't like above count inc/dec, and
mutex_unlock()style, because the code unnecessarily complicated. It can be...int ret = 0; if (master->clk_spu) { guard(spinlock_irqsave)(&master->lock); if (master->spu_count == 0) ret = clk_prepare_enable(master->clk_spu); master->spu_count++; } if (ret < 0) return ret;
Quoted 2 lines
I'm not 100% sure, but I guess you need to count up
spu_countanyway regardless ofclk_prepare_enable()result ?
Regarding spu_count, I’m not entirely sure, but if we increment it even on failure,
the counter might become unbalanced and clk_prepare_enable() may not be retried on the next call.
Would it be better to increment spu_count only on success to keep the state consistent?
Also, I have a question about the context here.
Since fsi_hw_startup() and fsi_hw_shutdown() are called from fsi_dai_trigger(), I think this runs in an atomic context, but please correct me if I'm wrong. If so, is it safe to call clk_prepare_enable() under guard(spinlock_irqsave)? Since clk_prepare() can sleep, I’m wondering if this could potentially cause a "scheduling while atomic" issue.
Would it make more sense to move clk_prepare() to init time (in new fsi_clk_init() ),
and only use clk_enable() / clk_disable() in the trigger path?
Best regards,
Phuc
Quoted 61 lines · Kuninori Morimoto
Hi
Hi
Quoted 6 lines
Enable/disable the shared SPU clock in hw startup/shutdown. Without this, accessing FSI registers may hang the system.
Suggested-by Kuninori Morimoto <[email protected]>Signed-off-by bui duc phuc <[email protected]>---
(snip)
Quoted 6 lines
sound/soc/renesas/fsi.c +2
-0@@ -1492,6 +1492,18 @@ static int fsi_hw_startup(struct fsi_priv *fsi, struct device *dev) {u32 data =0 ; +int ret =0 ; +/* enable spu clock */ sound/soc/renesas/fsi.c static int fsi_hw_startup(struct fsi_priv *fsi, · line 1506
Quoted 10 lines
sound/soc/renesas/fsi.c +10
-0+mutex_lock (&fsi->master->clk_lock); +if (fsi->master->clk_spu && fsi->master->spu_count++ ==0 ) { + ret =clk_prepare_enable (fsi->master->clk_spu); +if (ret <0 ) { + fsi->master->spu_count--; +mutex_unlock (&fsi->master->clk_lock); +return ret; + } + } +mutex_unlock (&fsi->master->clk_lock);1st, please insert white line between "int ret = 0;" and "/* enable spu clock */".
2nd, besically, FSI already has "lock", and using it for several protecting. Please re-use it, and don't add random new-lock. It makes code confusable. Then, please use
guard().3rd, I don't like above count inc/dec, and
mutex_unlock()style, because the code unnecessarily complicated. It can be...int ret = 0; if (master->clk_spu) { guard(spinlock_irqsave)(&master->lock); if (master->spu_count == 0) ret = clk_prepare_enable(master->clk_spu); master->spu_count++; } if (ret < 0) return ret;I'm not 100% sure, but I guess you need to count up
spu_countanyway regardless ofclk_prepare_enable()result ?Thank you for your help !!
Best regards
---
Kuninori Morimoto
Kuninori Morimoto
maintainerRe: [PATCH v2 2/6] ASoC: renesas: fsi: Fix hang by enabling SPU clock
Hi Bui
Quoted 6 lines
Regarding
spu_count, I’m not entirely sure, but if we increment it even on failure,
the counter might become unbalanced andclk_prepare_enable()may not be retried on the next call.
Would it be better to incrementspu_countonly on success to keep the state consistent?
It depens on how you create the error case :)
I don't mind super much about detail of it.
Quoted 9 lines
Since
fsi_hw_startup()andfsi_hw_shutdown()are called fromfsi_dai_trigger(), I think this runs in an atomic context, but please correct me if I'm wrong. If so, is it safe to callclk_prepare_enable()underguard(spinlock_irqsave)? Sinceclk_prepare()can sleep, I’m wondering if this could potentially cause a "scheduling while atomic" issue.Would it make more sense to move
clk_prepare()to init time (in newfsi_clk_init()),
and only useclk_enable()/clk_disable()in the trigger path?
I don't remember detail of SH-Mobile clock driver, but yes.
Thank you for your help !!
Best regards
---
Kuninori Morimoto
Re: [PATCH v2 2/6] ASoC: renesas: fsi: Fix hang by enabling SPU clock
Hi Morimoto-san,
Quoted 11 lines
Quoted 9 lines
I d> Since
fsi_hw_startup()andfsi_hw_shutdown()are called fromfsi_dai_trigger(), I think this runs in an atomic context, but please correct me if I'm wrong. If so, is it safe to callclk_prepare_enable()underguard(spinlock_irqsave)? Sinceclk_prepare()can sleep, I’m wondering if this could potentially cause a "scheduling while atomic" issue.Would it make more sense to move
clk_prepare()to init time (in newfsi_clk_init()),
and only useclk_enable()/clk_disable()in the trigger path?I don't remember detail of SH-Mobile clock driver, but yes.
Thank you. I will update it in the next version.
Best Regards,
Phuc
PATCH v2 3/6 ASoC: renesas: fsi: Fix trigger stop ordering
In reply to [email protected]From: bui duc phuc <[email protected]>
Reorder calls to execute fsi_stream_stop() before fsi_hw_shutdown(). This ensures that all register accesses are completed before the clock is disabled, preventing the system hang observed on r8a7740.
--- sound/soc/renesas/fsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/renesas/fsi.c +1 -1
@@ -1606,9 +1606,9 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, ret =fsi_stream_transfer (io);break ;case SNDRV_PCM_TRIGGER_STOP : +fsi_stream_stop (fsi, io);if (!ret) ret =fsi_hw_shutdown (fsi, dai->dev); -fsi_stream_stop (fsi, io);fsi_stream_quit (fsi, io);break ; }
Signature · 1 line
2.43.0
Kuninori Morimoto
maintainerRe: [PATCH v2 3/6] ASoC: renesas: fsi: Fix trigger stop ordering
Hi
Quoted 9 lines
From: bui duc phuc <[email protected]>
Reorder calls to execute
fsi_stream_stop()beforefsi_hw_shutdown(). This ensures that all register accesses are completed before the clock is disabled, preventing the system hang observed on r8a7740.Suggested-by Kuninori Morimoto <[email protected]>Signed-off-by bui duc phuc <[email protected]>---
This patch should appearing much earlier.
Quoted 21 lines
sound/soc/renesas/fsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)sound/soc/renesas/fsi.c +1
-1@@ -1606,9 +1606,9 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, ret =fsi_stream_transfer (io);break ;case SNDRV_PCM_TRIGGER_STOP : +fsi_stream_stop (fsi, io);if (!ret) ret =fsi_hw_shutdown (fsi, dai->dev); -fsi_stream_stop (fsi, io);fsi_stream_quit (fsi, io);break ; }Signature · 1 line
2.43.0
Re: [PATCH v2 3/6] ASoC: renesas: fsi: Fix trigger stop ordering
Hi Morimoto-san,
Quoted 1 line
This patch should appearing much earlier.
Thanks for your guidance.
I will reorder the patch series to place this fix earlier in the sequence.
Best regards,
Phuc
Quoted 37 lines · Kuninori Morimoto
Hi
Quoted 9 lines
From: bui duc phuc <[email protected]>
Reorder calls to execute
fsi_stream_stop()beforefsi_hw_shutdown(). This ensures that all register accesses are completed before the clock is disabled, preventing the system hang observed on r8a7740.Suggested-by Kuninori Morimoto <[email protected]>Signed-off-by bui duc phuc <[email protected]>---
This patch should appearing much earlier.
Quoted 21 lines
sound/soc/renesas/fsi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)sound/soc/renesas/fsi.c +1
-2@@ -1606,9 +1606,9 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd, ret =fsi_stream_transfer (io);break ;case SNDRV_PCM_TRIGGER_STOP : +fsi_stream_stop (fsi, io);if (!ret) ret =fsi_hw_shutdown (fsi, dai->dev); -fsi_stream_stop (fsi, io);fsi_stream_quit (fsi, io);break ; } --2.43.0
Re: [PATCH v2 3/6] ASoC: renesas: fsi: Fix trigger stop ordering
Hi Morimoto-san,
Even after reordering the sequence as follows:
fsi_stream_stop(fsi, io);
if (!ret)
ret = fsi_hw_shutdown(fsi, dai->dev);I had previously tested this change and did not observe any issues. However, in more recent testing under different conditions, I noticed a system hang.
It seems that the interrupt handler may still be invoked after interrupts are disabled and the SPU clock is turned off. The following log was observed:
root@localhost:~#
root@localhost:~# aplay /audio/file_example_WAV_2MG.wav [ 51.580000] >>>>>DEBUG: enter fsi_dai_startup Playing WAVE '/audio/file_example_WAV_2MG.wav' : Signed 16 bit Little Endian, Rat[ 51.590000] wm8978 1-001a : Imprecise sampling rate: 48000Hz, consider using PLL e 44100 Hz, Stereo [ 51.640000] >>>>>DEBUG: enter fsi_hw_startup [ 51.640000] >>>>>DEBUG: enter fsi_pio_start_stop, enable : 1 [ 62.610000] >>>>>DEBUG: enter fsi_pio_start_stop, enable : 0 [ 62.610000] >>>>>DEBUG: enter fsi_hw_shutdown [ 62.610000] FSI BUG: READ after clock OFF [ 62.610000] CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 7.0.0-09892-g26b66fbaf162-dirty #5 VOLUNTARY [ 62.610000] Hardware name: Generic R8A7740 (Flattened Device Tree) [ 62.610000] Call trace: [ 62.610000] unwind_backtrace from show_stack+0x10/0x14 [ 62.610000] show_stack from dump_stack_lvl+0x50/0x64 [ 62.610000] dump_stack_lvl from __fsi_reg_read+0x30/0x5c [ 62.610000] __fsi_reg_read from fsi_count_fifo_err+0x14/0x88 [ 62.610000] fsi_count_fifo_err from fsi_interrupt+0xa0/0xc0 [ 62.610000] fsi_interrupt from __handle_irq_event_percpu+0x1a8/0x1ec [ 62.610000] __handle_irq_event_percpu from handle_irq_event_percpu+0xc/0x38 [ 62.610000] handle_irq_event_percpu from handle_irq_event+0x44/0x68 [ 62.610000] handle_irq_event from handle_fasteoi_irq+0xa8/0x130 [ 62.610000] handle_fasteoi_irq from handle_irq_desc+0x64/0x7c [ 62.610000] handle_irq_desc from gic_handle_irq+0x60/0x70 [ 62.610000] gic_handle_irq from generic_handle_arch_irq+0x28/0x3c [ 62.610000] generic_handle_arch_irq from __irq_svc+0x88/0xb0 [ 62.610000] Exception stack(0xc0d01f48 to 0xc0d01f90) [ 62.610000] 1f40: 00000003 00000001 000176c4 40000000 00000000 00000000 [ 62.610000] 1f60: c0d03f98 c0d07880 c0d90b82 c0d03fd4 c0aea642 00000000 99cea980 c0d01f98 [ 62.610000] 1f80: c08228f4 c0822c68 600f0013 ffffffff [ 62.610000] __irq_svc from default_idle_call+0x24/0x30 [ 62.610000] default_idle_call from do_idle+0xcc/0x124 [ 62.610000] do_idle from cpu_startup_entry+0x28/0x2c [ 62.610000] cpu_startup_entry from rest_init+0x94/0xb0 [ 62.610000] rest_init from start_kernel+0x608/0x6bc [ 62.610000] FSI BUG: READ after clock OFF [ 62.610000] CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 7.0.0-09892-g26b66fbaf162-dirty #5 VOLUNTARY [ 62.610000] Hardware name: Generic R8A7740 (Flattened Device Tree) [ 62.610000] Call trace: [ 62.610000] unwind_backtrace from show_stack+0x10/0x14 [ 62.610000] show_stack from dump_stack_lvl+0x50/0x64 [ 62.610000] dump_stack_lvl from __fsi_reg_read+0x30/0x5c [ 62.610000] __fsi_reg_read from fsi_count_fifo_err+0x24/0x88 [ 62.610000] fsi_count_fifo_err from fsi_interrupt+0xa0/0xc0 [ 62.610000] fsi_interrupt from __handle_irq_event_percpu+0x1a8/0x1ec [ 62.610000] __handle_irq_event_percpu from handle_irq_event_percpu+0xc/0x38 [ 62.610000] handle_irq_event_percpu from handle_irq_event+0x44/0x68 [ 62.610000] handle_irq_event from handle_fasteoi_irq+0xa8/0x130 [ 62.610000] handle_fasteoi_irq from handle_irq_desc+0x64/0x7c [ 62.610000] handle_irq_desc from gic_handle_irq+0x60/0x70 [ 62.610000] gic_handle_irq from generic_handle_arch_irq+0x28/0x3c [ 62.610000] generic_handle_arch_irq from __irq_svc+0x88/0xb0 [ 62.610000] Exception stack(0xc0d01f48 to 0xc0d01f90) [ 62.610000] 1f40: 00000003 00000001 000176c4 40000000 00000000 00000000 [ 62.610000] 1f60: c0d03f98 c0d07880 c0d90b82 c0d03fd4 c0aea642 00000000 99cea980 c0d01f98 [ 62.610000] 1f80: c08228f4 c0822c68 600f0013 ffffffff [ 62.610000] __irq_svc from default_idle_call+0x24/0x30 [ 62.610000] default_idle_call from do_idle+0xcc/0x124 [ 62.610000] do_idle from cpu_startup_entry+0x28/0x2c [ 62.610000] cpu_startup_entry from rest_init+0x94/0xb0 [ 62.610000] rest_init from start_kernel+0x608/0x6bc
.......
In fsi_pio_start_stop(), I also tried adding the following:
if (enable)
fsi_irq_enable(fsi, io);
else {
fsi_irq_disable(fsi, io);
+ disable_irq_nosync(master->irq);
+ fsi_irq_clear_status(fsi);
}However, this still does not resolve the issue where the interrupt handler may still be invoked after the SPU clock has been turned off.
Do you have any suggestions on this issue?
If we still want to keep the SPU clock enable/disable inside hw_start/hw_shutdown,
we need to properly handle this race condition where the interrupt handler is still being triggered after hw_shutdown.
Otherwise, moving the SPU clock control into dai_start/dai_shutdown seems to be a safer approach,
since at that point all interrupts have already been fully processed.
Best regards,
Phuc
Re: [PATCH v2 3/6] ASoC: renesas: fsi: Fix trigger stop ordering
Hi Morimoto-san,
I’ve looked into this further and would like to share my findings and get your feedback on the next direction for addressing the issue.
The sequence is as follows:
(1) IRQ fires → handler starts
(2) handler is running
(3) playback ends → ALSA issues STOP
(4) fsi_dai_trigger(STOP)
→ active_streams = 0
→ fsi_hw_shutdown()
→ clock OFF
(5) IRQ handler continues
→ fsi_count_fifo_err()
→ register access → system hang
Since the trigger() runs in atomic context, we cannot use APIs like disable_irq() / disable_irq_sync()
to synchronize with the IRQ handler.
As a possible approach, I’m considering guarding against register access in the IRQ path when no streams are active,
for example by adding:
if (master->active_streams == 0)
return;
at the beginning of:
+ fsi_count_fifo_err()
+ fsi_irq_clear_status()
To support this, we would need to track the active streams by:
+ adding a running flag per stream
+ adding an active_streams counter in struct fsi_master
and update them in trigger():
if (!io->running) {
io->running = true;
master->active_streams++;
}if (io->running) {
io->running = false;
master->active_streams--;
}With this approach, even if a pending IRQ is handled after shutdown, the handler would avoid accessing registers, preventing the system hang.
I’d appreciate your feedback on whether this approach looks reasonable or if there is a better way to handle this.
The issue is reproducible when playback reaches EOF, while not observed in some other stop scenarios such as manual interruption.
Best regards,
Phuc
Re: [PATCH v2 3/6] ASoC: renesas: fsi: Fix trigger stop ordering
Hi Morimoto-san,
Since there are quite a few related patches, I will send v3 directly.
Regarding the optimization approach for in-flight IRQ handlers, please feel free to provide your feedback on the v3 patch series.
I will make further adjustments in the next versions if needed.
Best Regards,
Phuc,
PATCH v2 4/6 ASoC: renesas: fsi: refactor clock initialization
In reply to [email protected]From: bui duc phuc <[email protected]>
Move fsi_clk_init() out of set_fmt() and handle clock master logic internally. This simplifies the flow and aligns with probe-time initialization.
---
Note: Due to hardware limitations, only slave mode has been verified. Testing master mode requires resoldering board resistors or developing an HDMI driver, so master mode logic is currently compile-tested only. Full support for fsidiv requires additional DT bindings and a corresponding driver.
sound/soc/renesas/fsi.c | 157 +++++++++++++++++++++------------------- 1 file changed, 81 insertions(+), 76 deletions(-)
sound/soc/renesas/fsi.c +81 -76
@@ -709,73 +709,6 @@ static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable)fsi_core_mask_set (master, b_mclk, mask, val); } -/* -* clock function -*/ -static int fsi_clk_init (struct device *dev, -struct fsi_priv *fsi, -int xck, -int ick, -int div, -int (*set_rate)(struct device *dev, -struct fsi_priv *fsi)) -{ -struct fsi_clk *clock = &fsi->clock; -int is_porta =fsi_is_port_a (fsi); - - clock->xck =NULL ; - clock->ick =NULL ; - clock->div =NULL ; - clock->rate =0 ; - clock->count =0 ; - clock->set_rate = set_rate; - - clock->own =devm_clk_get (dev,NULL ); -if (IS_ERR (clock->own)) -return -EINVAL ; - -/* external clock */ -if (xck) { - clock->xck =devm_clk_get (dev, is_porta ?"xcka" :"xckb" ); -if (IS_ERR (clock->xck)) { -dev_err (dev,"can't get xck clock\n" ); -return -EINVAL ; - } -if (clock->xck == clock->own) { -dev_err (dev,"cpu doesn't support xck clock\n" ); -return -EINVAL ; - } - } - -/* FSIACLK/FSIBCLK */ -if (ick) { - clock->ick =devm_clk_get (dev, is_porta ?"icka" :"ickb" ); -if (IS_ERR (clock->ick)) { -dev_err (dev,"can't get ick clock\n" ); -return -EINVAL ; - } -if (clock->ick == clock->own) { -dev_err (dev,"cpu doesn't support ick clock\n" ); -return -EINVAL ; - } - } - -/* FSI-DIV */ -if (div) { - clock->div =devm_clk_get (dev, is_porta ?"diva" :"divb" ); -if (IS_ERR (clock->div)) { -dev_err (dev,"can't get div clock\n" ); -return -EINVAL ; - } -if (clock->div == clock->own) { -dev_err (dev,"cpu doesn't support div clock\n" ); -return -EINVAL ; - } - } - -return 0 ; -} -#define fsi_clk_invalid (fsi) fsi_clk_valid(fsi, 0)static void fsi_clk_valid (struct fsi_priv *fsi,unsigned long rate) {
@@ -921,6 +854,10 @@ static int fsi_clk_set_rate_external(struct device *dev,int ackmd, bpfmd;int ret =0 ; +if (!xck || !ick) { +dev_err (dev,"External (xck) or Internal (ick) clock is missing\n" ); +return -EINVAL ; + }/* check clock rate */ xrate =clk_get_rate (xck);if (xrate % rate) {
@@ -957,6 +894,11 @@ static int fsi_clk_set_rate_cpg(struct device *dev,int ackmd, bpfmd;int ret = -EINVAL ; +if (!ick || !div) { +dev_err (dev,"Internal (ick) or Divider (div) clock is missing\n" ); +return -EINVAL ; + } +if (!(12288000 % rate)) target =12288000 ;if (!(11289600 % rate))
@@ -1029,6 +971,76 @@ static int fsi_clk_set_rate_cpg(struct device *dev,return ret; } +/* +* clock function +*/ +static int fsi_clk_init (struct device *dev,struct fsi_priv *fsi,int is_cpg) +{ +struct fsi_clk *clock = &fsi->clock; +struct fsi_master *master = fsi->master; +int is_porta =fsi_is_port_a (fsi); +int xck, ick, div; + +if (is_cpg) { + xck =0 ; ick =1 ; div =1 ; + clock->set_rate = fsi_clk_set_rate_cpg; + }else { + xck =1 ; ick =1 ; div =0 ; + clock->set_rate = fsi_clk_set_rate_external; + } + + clock->xck =NULL ; + clock->ick =NULL ; + clock->div =NULL ; + clock->rate =0 ; + clock->count =0 ; + + clock->own =devm_clk_get (dev,NULL ); +if (IS_ERR (clock->own)) +return -EINVAL ; + +if (!master->clk_spu) { + master->clk_spu =devm_clk_get_optional (dev,"spu" ); +if (IS_ERR (master->clk_spu)) +return PTR_ERR (master->clk_spu); + } + +/* external clock */ +if (xck) { + clock->xck =devm_clk_get_optional (dev, is_porta ?"xcka" :"xckb" ); +if (IS_ERR (clock->xck)) +return dev_err_probe (dev,PTR_ERR (clock->xck),"Can't get xck clock\n" ); +if (clock->xck == clock->own) { +dev_err (dev,"cpu doesn't support xck clock\n" ); +return -EINVAL ; + } + } + +/* FSIACLK/FSIBCLK */ +if (ick) { + clock->ick =devm_clk_get_optional (dev, is_porta ?"icka" :"ickb" ); +if (IS_ERR (clock->ick)) +return dev_err_probe (dev,PTR_ERR (clock->ick),"Can't get ick clock\n" ); +if (clock->ick == clock->own) { +dev_err (dev,"cpu doesn't support ick clock\n" ); +return -EINVAL ; + } + } + +/* FSI-DIV */ +if (div) { + clock->div =devm_clk_get_optional (dev, is_porta ?"diva" :"divb" ); +if (IS_ERR (clock->div)) +return dev_err_probe (dev,PTR_ERR (clock->div),"Can't get div clock\n" ); +if (clock->div == clock->own) { +dev_err (dev,"cpu doesn't support div clock\n" ); +return -EINVAL ; + } + } + +return 0 ; +} +static void fsi_pointer_update (struct fsi_stream *io,int size) { io->buff_sample_pos += size;
@@ -1684,15 +1696,6 @@ static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)break ; } -if (fsi_is_clk_master (fsi)) { -if (fsi->clk_cpg) -fsi_clk_init (dai->dev, fsi,0 ,1 ,1 , - fsi_clk_set_rate_cpg); -else -fsi_clk_init (dai->dev, fsi,1 ,1 ,0 , - fsi_clk_set_rate_external); - } -/* set format */ if (fsi_is_spdif (fsi)) ret =fsi_set_fmt_spdif (fsi);
@@ -1992,6 +1995,7 @@ static int fsi_probe(struct platform_device *pdev) fsi->master = master;fsi_port_info_init (fsi, &info.port_a);fsi_handler_init (fsi, &info.port_a); +fsi_clk_init (&pdev->dev, fsi, !!(info.port_a.flags &SH_FSI_CLK_CPG )); ret =fsi_stream_probe (fsi, &pdev->dev);if (ret <0 ) {dev_err (&pdev->dev,"FSIA stream probe failed\n" );
@@ -2005,6 +2009,7 @@ static int fsi_probe(struct platform_device *pdev) fsi->master = master;fsi_port_info_init (fsi, &info.port_b);fsi_handler_init (fsi, &info.port_b); +fsi_clk_init (&pdev->dev, fsi, !!(info.port_b.flags &SH_FSI_CLK_CPG )); ret =fsi_stream_probe (fsi, &pdev->dev);if (ret <0 ) {dev_err (&pdev->dev,"FSIB stream probe failed\n" );
Signature · 1 line
2.43.0
Kuninori Morimoto
maintainerRe: [PATCH v2 4/6] ASoC: renesas: fsi: refactor clock initialization
Hi
Quoted 7 lines
Move
fsi_clk_init()out ofset_fmt()and handle clock master logic internally. This simplifies the flow and aligns with probe-time initialization.Suggested-by Kuninori Morimoto <[email protected]>Signed-off-by bui duc phuc <[email protected]>---
(snip)
sound/soc/renesas/fsi.c static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable) · line 721
Quoted 10 lines
sound/soc/renesas/fsi.c +0
-10-/* -* clock function -*/ -static int fsi_clk_init (struct device *dev, -struct fsi_priv *fsi, -int xck, -int ick, -int div, -int (*set_rate)(struct device *dev, -struct fsi_priv *fsi))
I have mentioned in previous mail to just move fsi_clk_init(), but why do you need to move it ? It works without any issue without moving function, I guess ?
This patch 1) moves fsi_clk_init() 2) and update it. So there are too many diffs. Difficult to review.
Note is that the comment /* clock function */ is not only for fsi_clk_init() but for all fsi_clk_xxx() functions. Here is that position.
sound/soc/renesas/fsi.c static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) · line 1694
Quoted 12 lines
sound/soc/renesas/fsi.c +0
-8@@ -1684,15 +1696,6 @@ static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)break ; } -if (fsi_is_clk_master (fsi)) { -if (fsi->clk_cpg) -fsi_clk_init (dai->dev, fsi,0 ,1 ,1 , - fsi_clk_set_rate_cpg); -else -fsi_clk_init (dai->dev, fsi,1 ,1 ,0 , - fsi_clk_set_rate_external); - }
You removes fsi_is_clk_master() check in new fsi_clk_init() ?
Quoted 9 lines
sound/soc/renesas/fsi.c +1
-0@@ -1992,6 +1995,7 @@ static int fsi_probe(struct platform_device *pdev) fsi->master = master;fsi_port_info_init (fsi, &info.port_a);fsi_handler_init (fsi, &info.port_a); +fsi_clk_init (&pdev->dev, fsi, !!(info.port_a.flags &SH_FSI_CLK_CPG )); ret =fsi_stream_probe (fsi, &pdev->dev);if (ret <0 ) {dev_err (&pdev->dev,"FSIA stream probe failed\n" );
sound/soc/renesas/fsi.c static int fsi_probe(struct platform_device *pdev) · line 2015
Quoted 7 lines
sound/soc/renesas/fsi.c +1
-0@@ -2005,6 +2009,7 @@ static int fsi_probe(struct platform_device *pdev) fsi->master = master;fsi_port_info_init (fsi, &info.port_b);fsi_handler_init (fsi, &info.port_b); +fsi_clk_init (&pdev->dev, fsi, !!(info.port_b.flags &SH_FSI_CLK_CPG )); ret =fsi_stream_probe (fsi, &pdev->dev);if (ret <0 ) {dev_err (&pdev->dev,"FSIB stream probe failed\n" );
Why don't use fsi->clk_cpg ? And why you need to call fsi_clk_init() twice ?
Thank you for your help !!
Best regards
---
Kuninori Morimoto
Re: [PATCH v2 4/6] ASoC: renesas: fsi: refactor clock initialization
Hi Morimoto-san,
Thank you for the review.
Quoted 3 lines
I have mentioned in previous mail to just move
fsi_clk_init(), but why do you need to move it ? It works without any issue without moving function, I guess ?
I moved fsi_clk_init() below the two functions fsi_clk_set_rate_cpg and fsi_clk_set_rate_external because, inside fsi_clk_init(), I assign these functions to clock->set_rate. Moving the function was necessary to avoid compilation errors.
+ if (is_cpg) {
+ xck = 0; ick = 1; div = 1;
+ clock->set_rate = fsi_clk_set_rate_cpg;
+ } else {
+ xck = 1; ick = 1; div = 0;
+ clock->set_rate = fsi_clk_set_rate_external;
+ }
Would you prefer that I use forward declarations instead of changing the function order?
Quoted 2 lines
Note is that the comment /* clock function */ is not only for
fsi_clk_init()but for allfsi_clk_xxx()functions. Here is that position.
Understood, I will fix the comment placement accordingly.
Quoted 10 lines
sound/soc/renesas/fsi.c static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) · line 1694
Quoted 8 lines
sound/soc/renesas/fsi.c +0
-8-if (fsi_is_clk_master (fsi)) { -if (fsi->clk_cpg) -fsi_clk_init (dai->dev, fsi,0 ,1 ,1 , - fsi_clk_set_rate_cpg); -else -fsi_clk_init (dai->dev, fsi,1 ,1 ,0 , - fsi_clk_set_rate_external); - }You removes
fsi_is_clk_master()check in newfsi_clk_init()?
At the probe stage, the Master/Slave status has not yet been determined because it depends on a subsequent set_fmt() call. Therefore, I am not using the fsi_is_clk_master() function inside the new fsi_clk_init() during the probe process.
Instead, the new fsi_clk_init() function acquires all resources (including the mandatory SPU clock) upfront using devm_clk_get_optional().
The actual fsi_is_clk_master() check remains strictly enforced in fsi_hw_startup() before enabling any functional clocks.
/* start master clock */
if (fsi_is_clk_master(fsi))
return fsi_clk_enable(dev, fsi);
Quoted 1 line
Why don't use
fsi->clk_cpg?
You're right, using fsi->clk_cpg is cleaner since it's already initialized in fsi_port_info_init().
I will use it in the next version.
Quoted 1 line
And why you need to call
fsi_clk_init()twice ?
The FSI controller has two independent ports (Port A and Port B). Each port requires its own clock resource initialization and configuration.
Best regards,
Phuc
Kuninori Morimoto
maintainerRe: [PATCH v2 4/6] ASoC: renesas: fsi: refactor clock initialization
Hi Bui
Quoted 8 lines
Quoted 3 lines
I have mentioned in previous mail to just move
fsi_clk_init(), but why do you need to move it ? It works without any issue without moving function, I guess ?I moved
fsi_clk_init()below the two functionsfsi_clk_set_rate_cpgandfsi_clk_set_rate_externalbecause, insidefsi_clk_init(), I assign these functions toclock->set_rate. Moving the function was necessary to avoid compilation errors.
Ah, OK.
So the patch 1) moves fsi_clk_init() and 2) update it. It is including many features in 1 patch. Please separate it.
One note here is that /* clock function */ is for all fsi_clk_xxx(), so don't move it.
Quoted 3 lines
Quoted 1 line
And why you need to call
fsi_clk_init()twice ?The FSI controller has two independent ports (Port A and Port B). Each port requires its own clock resource initialization and configuration.
Ah, yes indeed.
Thank you for your help !!
Best regards
---
Kuninori Morimoto
Re: [PATCH v2 4/6] ASoC: renesas: fsi: refactor clock initialization
Hi Morimoto-san,
Quoted 6 lines
Ah, OK.
So the patch 1) movesfsi_clk_init()and 2) update it. It is including many features in 1 patch. Please separate it.One note here is that /* clock function */ is for all
fsi_clk_xxx(), so don't move it.
Thank you for your guidance.
I will split this into two separate patches accordingly.
Best regards,
Phuc
Quoted 32 lines · Kuninori Morimoto
Hi Bui
Quoted 8 lines
Quoted 3 lines
I have mentioned in previous mail to just move
fsi_clk_init(), but why do you need to move it ? It works without any issue without moving function, I guess ?I moved
fsi_clk_init()below the two functionsfsi_clk_set_rate_cpgandfsi_clk_set_rate_externalbecause, insidefsi_clk_init(), I assign these functions toclock->set_rate. Moving the function was necessary to avoid compilation errors.Ah, OK.
So the patch 1) movesfsi_clk_init()and 2) update it. It is including many features in 1 patch. Please separate it.One note here is that /* clock function */ is for all
fsi_clk_xxx(), so don't move it.Quoted 3 lines
Quoted 1 line
And why you need to call
fsi_clk_init()twice ?The FSI controller has two independent ports (Port A and Port B). Each port requires its own clock resource initialization and configuration.
Ah, yes indeed.
Thank you for your help !!
Best regards
---
Kuninori Morimoto
PATCH v2 5/6 arm: dts: renesas: r8a7740: Add clocks for FSI
In reply to [email protected]From: bui duc phuc <[email protected]>
Add the SPU clock to the FSI node to ensure it is enabled before register access, preventing potential system hangs.
Also complete the FSI clock tree by adding:
- CPG DIV6 clocks (icka/b) as functional parents
- External clocks (xcka/b) from the board
Define fsib nodes to support the clock hierarchy.
---
Changes in v2:
- Rename "fsi" clock to "own" to match driver implementation.
- Add missing clock names: "icka", "ickb", "xcka", "xckb".
arch/arm/boot/dts/renesas/r8a7740.dtsi | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
arch/arm/boot/dts/renesas/r8a7740.dtsi +11 -1
@@ -393,7 +393,11 @@ sh_fsi2: sound@fe1f0000 { compatible = "renesas,fsi2-r8a7740", "renesas,sh_fsi2"; reg = <0xfe1f0000 0x400>; interrupts = <GIC_SPI 9 0x4>; - clocks = <&mstp3_clks R8A7740_CLK_FSI>; + clocks = <&mstp3_clks R8A7740_CLK_FSI>, <&spu_clk>, + <&fsia_clk>, <&fsib_clk>, <&fsiack_clk>, + <&fsibck_clk>; + clock-names = "own", "spu", "icka", "ickb", "xcka", + "xckb"; power-domains = <&pd_a4mp>; status = "disabled"; };
@@ -614,6 +618,12 @@ vou_clk: vou@e6150088 { <0>; #clock-cells = <0>; }; + fsib_clk: fsib@e6150090 { + compatible = "renesas,r8a7740-div6-clock", "renesas,cpg-div6-clock"; + reg = <0xe6150090 4>; + clocks = <&pllc1_div2_clk>, <&fsibck_clk>, <0>, <0>; + #clock-cells = <0>; + }; stpro_clk: stpro@e615009c { compatible = "renesas,r8a7740-div6-clock", "renesas,cpg-div6-clock"; reg = <0xe615009c 4>;
Signature · 1 line
2.43.0
PATCH v2 6/6 ASoC: dt-bindings: renesas,fsi: add support for multiple clocks
In reply to [email protected]From: bui duc phuc <[email protected]>
The FSI on r8a7740 requires the SPU bus/bridge clock to be enabled before accessing its registers. Without this clock, any register access leads to a system hang as the FSI block sits behind the SPU bus.
Update the binding to support a flexible positional clock list to properly describe the hardware clock tree, including:
- SPU bus/bridge clock (spu) for register access.
- CPG DIV6 clocks (icka/b) as functional clock parents.
- FSI internal dividers (diva/b) for audio clock generation.
- External clock inputs (xcka/b) provided by the board.
---
Changes in v2:
- Rename FSI module clock to "own" to match driver.
- Add "spu", "icka/b", "diva/b", "xcka/b" clock names.
- Use YAML anchors to constrain clock-names properly.
- Add "if" rule to require "spu" clock for r8a7740.
- Update example with full clock configuration.
- Clean up schema by moving allOf location.
.../bindings/sound/renesas,fsi.yaml | 61 +++++++++++++++++-- 1 file changed, 56 insertions(+), 5 deletions(-)
Documentation/devicetree/bindings/sound/renesas,fsi.yaml +56 -5
@@ -9,9 +9,6 @@ title: Renesas FIFO-buffered Serial Interface (FSI) maintainers: - Kuninori Morimoto <[email protected]> -allOf: - - $ref: dai-common.yaml# - properties: $nodename: pattern: "^sound@.*"
@@ -38,7 +35,36 @@ properties: maxItems: 1 clocks: - maxItems: 1 + description: | + Clock driving the FSI Controller. The first clock must be + the module clock ("own"). + minItems: 1 + maxItems: 8 + + clock-names: + description: | + Names of clocks corresponding to entries in "clocks": + - "own": Main FSI module clock (must be first and always present) + - "spu": SPU bus/bridge clock. On R8A7740, this clock must be + enabled to allow register access as the FSI block is connected + behind the SPU bus. + - "icka" / "ickb": CPG DIV6 functional clocks for FSI port A/B + - "diva"/"divb": Internal FSI dividers for port A/B used for + audio clock generation + - "xcka"/"xckb": External clock inputs for FSI port A/B + provided by the board + minItems: 1 + items: + - const: own + - &fsi_all_clks + enum: [spu, icka, ickb, diva, divb, xcka, xckb] + - &fsi_no_spu_clks + enum: [icka, ickb, diva, divb, xcka, xckb] + - *fsi_no_spu_clks + - *fsi_no_spu_clks + - *fsi_no_spu_clks + - *fsi_no_spu_clks + - *fsi_no_spu_clks power-domains: maxItems: 1
@@ -69,6 +95,27 @@ required: unevaluatedProperties: false +allOf: + - $ref: dai-common.yaml# + - if: + properties: + compatible: + contains: + const: renesas,fsi2-r8a7740 + then: + properties: + clock-names: + minItems: 2 + items: + - const: own + - const: spu + - *fsi_no_spu_clks + - *fsi_no_spu_clks + - *fsi_no_spu_clks + - *fsi_no_spu_clks + - *fsi_no_spu_clks + - *fsi_no_spu_clks + examples: - | #include <dt-bindings/clock/r8a7740-clock.h>
@@ -77,7 +124,11 @@ examples: compatible = "renesas,fsi2-r8a7740", "renesas,sh_fsi2"; reg = <0xfe1f0000 0x400>; interrupts = <GIC_SPI 9 0x4>; - clocks = <&mstp3_clks R8A7740_CLK_FSI>; + clocks = <&mstp3_clks R8A7740_CLK_FSI>, <&spu_clk>, + <&fsia_clk>, <&fsib_clk>, <&fsidiva_clk>, + <&fsidivb_clk>,<&fsiack_clk>,<&fsibck_clk>; + clock-names = "own", "spu", "icka", "ickb", + "diva", "divb", "xcka", "xckb"; power-domains = <&pd_a4mp>; #sound-dai-cells = <1>;
Signature · 1 line
2.43.0
Re: [PATCH v2 6/6] ASoC: dt-bindings: renesas,fsi: add support for multiple clocks
Quoted 6 lines · On Mon, Apr 13, 2026 at 05:07:00PM +0700, [email protected] wrote:
From: bui duc phuc <[email protected]>
The FSI on r8a7740 requires the SPU bus/bridge clock to be enabled before accessing its registers. Without this clock, any register access leads to a system hang as the FSI block sits behind the SPU bus.
Update the binding to support a flexible positional clock list to properly
Flexible is not allowed. Provide reasons for exception.
Quoted 47 lines
describe the hardware clock tree, including:
- SPU bus/bridge clock (spu) for register access.
- CPG DIV6 clocks (icka/b) as functional clock parents.
- FSI internal dividers (diva/b) for audio clock generation.
- External clock inputs (xcka/b) provided by the board.Signed-off-by bui duc phuc <[email protected]>---
Changes in v2:
- Rename FSI module clock to "own" to match driver.
- Add "spu", "icka/b", "diva/b", "xcka/b" clock names.
- Use YAML anchors to constrain clock-names properly.
- Add "if" rule to require "spu" clock for r8a7740.
- Update example with full clock configuration.
- Clean up schema by moving allOf location..../bindings/sound/renesas,fsi.yaml | 61 +++++++++++++++++-- 1 file changed, 56 insertions(+), 5 deletions(-)Documentation/devicetree/bindings/sound/renesas,fsi.yaml +8
-4@@ -9,9 +9,6 @@ title: Renesas FIFO-buffered Serial Interface (FSI) maintainers: - Kuninori Morimoto <[email protected]> -allOf: - - $ref: dai-common.yaml# - properties: $nodename: pattern: "^sound@.*"@@ -38,7 +35,36 @@ properties: maxItems: 1 clocks: - maxItems: 1 + description: | + Clock driving the FSI Controller. The first clock must be + the module clock ("own"). + minItems: 1 + maxItems: 8 + + clock-names: + description: |
Documentation/devicetree/bindings/sound/renesas,fsi.yaml properties: · line 55
Quoted 10 lines
Documentation/devicetree/bindings/sound/renesas,fsi.yaml +10
-0+ Names of clocks corresponding to entries in "clocks": + - "own": Main FSI module clock (must be first and always present) + - "spu": SPU bus/bridge clock. On R8A7740, this clock must be + enabled to allow register access as the FSI block is connected + behind the SPU bus. + - "icka" / "ickb": CPG DIV6 functional clocks for FSI port A/B + - "diva"/"divb": Internal FSI dividers for port A/B used for + audio clock generation + - "xcka"/"xckb": External clock inputs for FSI port A/B + provided by the board
This goes to the "clocks:"
Documentation/devicetree/bindings/sound/renesas,fsi.yaml properties: · line 59
Quoted 4 lines
Documentation/devicetree/bindings/sound/renesas,fsi.yaml +4
-0+ minItems: 1 + items: + - const: own + - &fsi_all_clks
I don't understand this syntax.
Best regards,
Krzysztof
Re: [PATCH v2 6/6] ASoC: dt-bindings: renesas,fsi: add support for multiple clocks
Hi Krzysztof,
Thank you for your detailed review and feedback.
Quoted 1 line
Flexible is not allowed. Provide reasons for exception.
I understand and will remove this approach and replace it with explicit valid clock combinations.
Quoted 1 line
This goes to the "clocks:"
Understood, I will move the description to "clocks".
Quoted 6 lines
Documentation/devicetree/bindings/sound/renesas,fsi.yaml properties: · line 59
Quoted 4 lines
Documentation/devicetree/bindings/sound/renesas,fsi.yaml +4
-0+ minItems: 1 + items: + - const: own + - &fsi_all_clksI don't understand this syntax.
Understood, I will drop the YAML anchor and use explicit constraints instead.
I will update it to the following structure:
clocks:
description: |
Clock driving the FSI Controller :
- "own": Main FSI module clock (must be first and always present)
- "spu": SPU bus/bridge clock. On R8A7740, this clock must be enabled to allow register access as the FSI block is connected behind the SPU bus.
- "icka" / "ickb": CPG DIV6 functional clocks for FSI port A/B
- "diva"/"divb": Internal FSI dividers for port A/B used for audio clock generation
- "xcka"/"xckb": External clock inputs for FSI port A/B provided by the board
minItems: 1
maxItems: 8
clock-names:
minItems: 1
maxItems: 8
allOf:
- $ref: dai-common.yaml#
- if:
properties:
compatible:
contains:
const: renesas,fsi2-r8a7740
then:
properties:
clock-names:
oneOf:
- items:
- const: own
- const: spu
- items:
- const: own
- const: spu
- const: ickb
- const: divb
Best regards,
Phuc
Re: [PATCH v2 6/6] ASoC: dt-bindings: renesas,fsi: add support for multiple clocks
Hi Bui,
Quoted 20 lines · Bui Duc Phuc
Quoted 1 line
Flexible is not allowed. Provide reasons for exception.
I understand and will remove this approach and replace it with explicit valid clock combinations.
Quoted 1 line
This goes to the "clocks:"
Understood, I will move the description to "clocks".
Quoted 6 lines
Documentation/devicetree/bindings/sound/renesas,fsi.yaml properties: · line 59
Quoted 4 lines
Documentation/devicetree/bindings/sound/renesas,fsi.yaml +4
-0+ minItems: 1 + items: + - const: own + - &fsi_all_clksI don't understand this syntax.
Understood, I will drop the YAML anchor and use explicit constraints instead.
I will update it to the following structure:
Quoted 14 lines
clocks:
description: |
Clock driving the FSI Controller :
- "own": Main FSI module clock (must be first and always present)
- "spu": SPU bus/bridge clock. On R8A7740, this clock must be enabled to allow register access as the FSI block is connected behind the SPU bus.
- "icka" / "ickb": CPG DIV6 functional clocks for FSI port A/B
- "diva"/"divb": Internal FSI dividers for port A/B used for audio clock generation
- "xcka"/"xckb": External clock inputs for FSI port A/B provided by the board
minItems: 1
maxItems: 8
'move the description to "clocks"' means:
clocks:
minItems: 1
items:
- description: Main FSI module clock
- description: SPU bus/bridge clock [...]
[...[
Quoted 4 lines
clock-names:
minItems: 1
maxItems: 8
and:
clock-names:
minItems: 1
items:
- const: "fck"
- const: "spu"
[...]
But this imposes a fixed order, and would prevent optional clocks in the middle of the list.
So you may be better off using a similar description like in Documentation/devicetree/bindings/serial/renesas,scif.yaml
clock-names:
minItems: 1
maxItems: 8
items:
- fck # Main FSI module clock
- spu # optional SPU bus/bridge clock [...]
- icka # optional CPG DIV6 functional clocks for FSI port A
- ickb # optional CPG DIV6 functional clocks for FSI port B [...]
Quoted 12 lines
allOf:
- $ref: dai-common.yaml#
- if:
properties:
compatible:
contains:
const: renesas,fsi2-r8a7740
then:
properties:
clock-names:
oneOf:
Quoted 8 lines
- items:
- const: own
- const: spu
- items:
- const: own
- const: spu
- const: ickb
- const: divb
+ the above making it stricter.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH v2 6/6] ASoC: dt-bindings: renesas,fsi: add support for multiple clocks
Hi Geert,
Thanks for your feedback.
Quoted 2 lines
Where does this match the driver?
Usually the functional clock is called "fck".
Regarding the clock name "own", I used it because of the following implementation in the current driver:
clock->own = devm_clk_get(dev, NULL);
if (IS_ERR(clock->own))
return -EINVAL;The driver currently fetches the first clock in the list (index 0) and stores it in a variable named own.
That is why I named it "own" in the DT bindings to match.
However, I have noticed that other DTS files commonly use "fck" for the functional clock.
Are you suggesting that I should also rename the variable from "own" to "fck" in the driver code ??
For example:
clocks = <&mstp2_clks R8A7740_CLK_SCIFA1>;
clock-names = "fck";But from the hardware manual, MSTP refers to a "Module Stop Clock", not a "functional clock".
So I'm not sure if using "fck" here is appropriate. Could you explain the reasoning behind calling this clock "fck"?
Regarding the FSI clocks, they can be categorized into two types:
audio clocks and module clocks (which may include bus/bridge clocks). The driver itself does not explicitly handle the enabling/disabling of the module clock; it only manages the audio clocks.
From my code tracing:
At boot: The kernel automatically attaches the PM domain and
prepares the clocks during device initialization.
During playback (aplay): The FSI driver doesn't enable the module
clock directly. Instead, it is handled via:
genpd_runtime_resume -> pm_clk_resume -> clk_core_enable ->
cpg_mstp_clock_endisable.
Since this module clock is essential for register access, it must always be the first entry in the clocks property (index 0) so devm_clk_get(dev, NULL)
can fetch it correctly, right?
Please let me know if my understanding is incorrect.
Best regards,
Phuc
Re: [PATCH v2 6/6] ASoC: dt-bindings: renesas,fsi: add support for multiple clocks
Hi Geert,
Thanks you for your review and suggestion.
I think this approach looks very good.
Quoted 9 lines
clock-names:
minItems: 1
maxItems: 8
items:
- fck # Main FSI module clock
- spu # optional SPU bus/bridge clock [...]
- icka # optional CPG DIV6 functional clocks for FSI port A
- ickb # optional CPG DIV6 functional clocks for FSI port B [...]
Just to confirm: using this approach with a fixed order and optional entries as described would not be
considered "flexible" in the sense that Krzysztof objected to, right?
Best regards,
Phuc
Re: [PATCH v2 6/6] ASoC: dt-bindings: renesas,fsi: add support for multiple clocks
In reply to Bui Duc PhucHi Phuc,
Quoted 6 lines · Bui Duc Phuc
Quoted 2 lines
Where does this match the driver?
Usually the functional clock is called "fck".Regarding the clock name "own", I used it because of the following implementation in the current driver:
Quoted 7 lines
clock->own = devm_clk_get(dev, NULL); if (IS_ERR(clock->own)) return -EINVAL;The driver currently fetches the first clock in the list (index 0) and stores it in a variable named own.
That is why I named it "own" in the DT bindings to match.
Thanks, I hadn't looked at variables names (I searched for "own" including double quotes).
Quoted 4 lines
However, I have noticed that other DTS files commonly use "fck" for the functional clock.
Are you suggesting that I should also rename the variable from "own" to "fck" in the driver code ??
I think there is no need to rename the variable.
Quoted 9 lines
For example:
clocks = <&mstp2_clks R8A7740_CLK_SCIFA1>; clock-names = "fck";But from the hardware manual, MSTP refers to a "Module Stop Clock", not a "functional clock".
So I'm not sure if using "fck" here is appropriate. Could you explain the reasoning behind calling this clock "fck"?
It is the main clock that needs to be enabled to make the device function. This is independent from the notion of it being a "Module Stop Clock" or not, and became sort of a convention.
Quoted 11 lines
Regarding the FSI clocks, they can be categorized into two types:
audio clocks and module clocks (which may include bus/bridge clocks). The driver itself does not explicitly handle the enabling/disabling of the module clock; it only manages the audio clocks.
From my code tracing:
At boot: The kernel automatically attaches the PM domain and
prepares the clocks during device initialization.
During playback (aplay): The FSI driver doesn't enable the module
clock directly. Instead, it is handled via:genpd_runtime_resume -> pm_clk_resume -> clk_core_enable ->
cpg_mstp_clock_endisable.
Correct. On most (all?) Renesas SoCs, devices are part of a clock domain, and their functional clocks are managed by Runtime PM.
Quoted 4 lines
Since this module clock is essential for register access, it must always be the first entry in the clocks property (index 0) so
devm_clk_get(dev, NULL)
can fetch it correctly, right?
It is not strictly needed to be the first clock, and mostly a relic of the past, when clocks weren't accessed by name, but by index.
Also, many devices have only a single clock, so don't need a name.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Re: [PATCH v2 6/6] ASoC: dt-bindings: renesas,fsi: add support for multiple clocks
Hi Geert,
Quoted 10 lines
It is the main clock that needs to be enabled to make the device function. This is independent from the notion of it being a "Module Stop Clock" or not, and became sort of a convention.
Correct. On most (all?) Renesas SoCs, devices are part of a clock domain, and their functional clocks are managed by Runtime PM.
It is not strictly needed to be the first clock, and mostly a relic of the past, when clocks weren't accessed by name, but by index.
Also, many devices have only a single clock, so don't need a name.
Thank you for the clarification. It was very helpful and cleared up my confusion about the clock naming and ordering.
I really appreciate your support.
Best regards,
Phuc
Re: [PATCH v2 6/6] ASoC: dt-bindings: renesas,fsi: add support for multiple clocks
In reply to [email protected]Hi Bui,
Quoted 12 lines · On Mon, 13 Apr 2026 at 12:07, <[email protected]> wrote:
From: bui duc phuc <[email protected]>
The FSI on r8a7740 requires the SPU bus/bridge clock to be enabled before accessing its registers. Without this clock, any register access leads to a system hang as the FSI block sits behind the SPU bus.
Update the binding to support a flexible positional clock list to properly describe the hardware clock tree, including:
- SPU bus/bridge clock (spu) for register access.
- CPG DIV6 clocks (icka/b) as functional clock parents.
- FSI internal dividers (diva/b) for audio clock generation.
- External clock inputs (xcka/b) provided by the board.
Quoted 1 line
Signed-off-by bui duc phuc <[email protected]>
Thanks for the update!
Quoted 2 lines
Changes in v2:
- Rename FSI module clock to "own" to match driver.
Where does this match the driver?
Usually the functional clock is called "fck".
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds