ASoC: dwc: Fix several issues in the I2S driver
v3 cover ASoC: dwc: Fix several issues in the I2S driver
From: bui duc phuc <[email protected]>
Hi all,
This series addresses several issues in the DesignWare I2S driver, including clock rate calculation, DAI configuration, channel limits, DMA FIFO sizing, and error handling.
Changes in v2:
- Move the indentation and typo fixes into a separate commit.
- Add a separate patch to propagate optional IRQ lookup errors.
- Add Maxim Kochetkov's Reviewed-by tag.
Changes in v3:
- Add a Fixes tag to "ASoC: dwc: Fix DMA fifo_size calculation", as suggested by Sashiko.
- Ensure the reset is asserted when IRQ lookup fails, as suggested by Sashiko.
Link v1:
https://lore.kernel.org/all/[email protected]/
Link v2:
https://lore.kernel.org/all/[email protected]/
Compile-tested only.
Best regards,
Phuc
bui duc phuc (6):
ASoC: dwc: Fix bit clock rate in TDM mode
ASoC: dwc: Fix error handling in dw_i2s_set_fmt()
ASoC: dwc: Fix channels_max derived from COMP_PARAM_1
ASoC: dwc: Fix DMA fifo_size calculation
ASoC: dwc: Propagate optional IRQ lookup errors
ASoC: dwc: Remove redundant error messages
sound/soc/dwc/dwc-i2s.c | 59 +++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 34 deletions(-)
Signature · 1 line
2.43.0
PATCH v3 1/6 ASoC: dwc: Fix bit clock rate in TDM mode
From: bui duc phuc <[email protected]>
The bit clock is computed as rate * data_width * 2, which only fits a two-slot I2S frame. Use rate * data_width * tdm_slots in TDM mode.
---
Changes in v2:
- Move the indentation fixes into a separate commit.
- Add Maxim Kochetkov's Reviewed-by tag.
sound/soc/dwc/dwc-i2s.c | 3 +++ 1 file changed, 3 insertions(+)
sound/soc/dwc/dwc-i2s.c +3 -0
@@ -332,6 +332,9 @@ static int dw_i2s_hw_params(struct snd_pcm_substream *substream, }else {u32 bitclk = config->sample_rate * config->data_width *2 ; +if (dev->tdm_slots) + bitclk = config->sample_rate * + config->data_width * dev->tdm_slots; ret =clk_set_rate (dev->clk, bitclk);if (ret) {
Signature · 1 line
2.43.0
PATCH v3 2/6 ASoC: dwc: Fix error handling in dw_i2s_set_fmt()
In reply to [email protected]From: bui duc phuc <[email protected]>
Return early when an unsupported clock provider format is encountered, preventing the function from updating frame_offset before returning an error.
---
Changes in v2:
- Move the typo fixes into a separate commit.
- Add Maxim Kochetkov's Reviewed-by tag.
sound/soc/dwc/dwc-i2s.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-)
sound/soc/dwc/dwc-i2s.c +6 -16
@@ -390,29 +390,19 @@ static int dw_i2s_trigger(struct snd_pcm_substream *substream,static int dw_i2s_set_fmt (struct snd_soc_dai *cpu_dai,unsigned int fmt) {struct dw_i2s_dev *dev =snd_soc_dai_get_drvdata (cpu_dai); -int ret =0 ;switch (fmt &SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK ) {case SND_SOC_DAIFMT_BC_FC : -if (dev->capability &DW_I2S_SLAVE ) - ret =0 ; -else - ret = -EINVAL ; +if (!(dev->capability &DW_I2S_SLAVE )) +return -EINVAL ;break ;case SND_SOC_DAIFMT_BP_FP : -if (dev->capability &DW_I2S_MASTER ) - ret =0 ; -else - ret = -EINVAL ; -break ; -case SND_SOC_DAIFMT_BC_FP : -case SND_SOC_DAIFMT_BP_FC : - ret = -EINVAL ; +if (!(dev->capability &DW_I2S_MASTER )) +return -EINVAL ;break ;default :dev_dbg (dev->dev,"dwc : Invalid clock provider format\n" ); - ret = -EINVAL ; -break ; +return -EINVAL ; }switch (fmt &SND_SOC_DAIFMT_FORMAT_MASK ) {
@@ -431,7 +421,7 @@ static int dw_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)return -EINVAL ; } -return ret; +return 0 ; } static int dw_i2s_set_tdm_slot(struct snd_soc_dai *cpu_dai, unsigned int tx_mask,
Signature · 1 line
2.43.0
PATCH v3 3/6 ASoC: dwc: Fix channels_max derived from COMP_PARAM_1
In reply to [email protected]From: bui duc phuc <[email protected]>
The I2S_TX_CHANNELS (bits 10:9) and I2S_RX_CHANNELS (bits 8:7) fields of I2S_COMP_PARAM_1 encode the number of hardware channels minus one, i.e. values 0..3 mean 1..4 channels. In I2S mode each hardware channel is one serial data line carrying a left/right pair, so the maximum number of audio channels is 2 * (N + 1).
The current code uses 1 << (N + 1), which only produces the correct result for N < 2. For N >= 2, it overestimates the maximum number of audio channels.
Use 2 * (N + 1) for both playback and capture.
---
Changes in v2:
- Add Maxim Kochetkov's Reviewed-by tag.
sound/soc/dwc/dwc-i2s.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/dwc/dwc-i2s.c +2 -2
@@ -605,7 +605,7 @@ static int dw_configure_dai(struct dw_i2s_dev *dev, idx =1 ; dw_i2s_dai->playback.channels_min =MIN_CHANNEL_NUM ; dw_i2s_dai->playback.channels_max = -1 << (COMP1_TX_CHANNELS (comp1) +1 ); +2 * (COMP1_TX_CHANNELS (comp1) +1 ); dw_i2s_dai->playback.formats = formats[idx]; dw_i2s_dai->playback.rates = rates; }
@@ -619,7 +619,7 @@ static int dw_configure_dai(struct dw_i2s_dev *dev, idx =1 ; dw_i2s_dai->capture.channels_min =MIN_CHANNEL_NUM ; dw_i2s_dai->capture.channels_max = -1 << (COMP1_RX_CHANNELS (comp1) +1 ); +2 * (COMP1_RX_CHANNELS (comp1) +1 ); dw_i2s_dai->capture.formats = formats[idx]; dw_i2s_dai->capture.rates = rates; }
Signature · 1 line
2.43.0
PATCH v3 4/6 ASoC: dwc: Fix DMA fifo_size calculation
In reply to [email protected]From: bui duc phuc <[email protected]>
fifo_size should be the FIFO size in bytes (depth * width / 8), but the code shifts by 8 instead of 3. For capture the parentheses also make it always 0.
Use depth * width / 8 for both directions.
---
Changes in v3:
- Add a Fixes tag, as suggested by Sashiko.
sound/soc/dwc/dwc-i2s.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
sound/soc/dwc/dwc-i2s.c +4 -4
@@ -664,14 +664,14 @@ static int dw_configure_dai_by_pd(struct dw_i2s_dev *dev, idx2 =COMP1_TX_WORDSIZE_0 (comp1); dev->play_dma_data.dt.addr = res->start +I2S_TXDMA ; dev->play_dma_data.dt.fifo_size = dev->fifo_th *2 * - (fifo_width[idx2]) >>8 ; + fifo_width[idx2] /8 ; dev->play_dma_data.dt.maxburst =16 ; }if (COMP1_RX_ENABLED (comp1)) { idx2 =COMP2_RX_WORDSIZE_0 (comp2); dev->capture_dma_data.dt.addr = res->start +I2S_RXDMA ; dev->capture_dma_data.dt.fifo_size = dev->fifo_th *2 * - (fifo_width[idx2] >>8 ); + fifo_width[idx2] /8 ; dev->capture_dma_data.dt.maxburst =16 ; } }else {
@@ -711,7 +711,7 @@ static int dw_configure_dai_by_dt(struct dw_i2s_dev *dev, dev->capability |=DWC_I2S_PLAY ; dev->play_dma_data.dt.addr = res->start +I2S_TXDMA ; dev->play_dma_data.dt.fifo_size = fifo_depth * - (fifo_width[idx2]) >>8 ; + fifo_width[idx2] /8 ; dev->play_dma_data.dt.maxburst =16 ; }if (COMP1_RX_ENABLED (comp1)) {
@@ -720,7 +720,7 @@ static int dw_configure_dai_by_dt(struct dw_i2s_dev *dev, dev->capability |=DWC_I2S_RECORD ; dev->capture_dma_data.dt.addr = res->start +I2S_RXDMA ; dev->capture_dma_data.dt.fifo_size = fifo_depth * - (fifo_width[idx2] >>8 ); + fifo_width[idx2] /8 ; dev->capture_dma_data.dt.maxburst =16 ; }
Signature · 1 line
2.43.0
PATCH v3 5/6 ASoC: dwc: Propagate optional IRQ lookup errors
In reply to [email protected]From: bui duc phuc <[email protected]>
platform_get_irq_optional() can return errors other than -EPROBE_DEFER. Propagate these errors instead of silently continuing, while treating -ENXIO as the absence of an IRQ.
Use dev_err_probe() to report IRQ lookup failures and ensure the reset is asserted when IRQ lookup fails.
---
Changes in v3:
- Ensure the reset is asserted when IRQ lookup fails, as suggested by Sashiko.
- Add a Fixes tag
sound/soc/dwc/dwc-i2s.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
sound/soc/dwc/dwc-i2s.c +4 -2
@@ -961,8 +961,10 @@ static int dw_i2s_probe(struct platform_device *pdev) } irq =platform_get_irq_optional (pdev,0 ); -if (irq == -EPROBE_DEFER ) -return irq; +if (irq <0 && irq != -ENXIO ) { + ret =dev_err_probe (&pdev->dev, irq,"failed to get IRQ\n" ); + goto err_assert_reset; + }if (irq >0 ) { ret =devm_request_irq (&pdev->dev, irq, i2s_irq_handler,0 , pdev->name, dev);
Signature · 1 line
2.43.0
PATCH v3 6/6 ASoC: dwc: Remove redundant error messages
In reply to [email protected]From: bui duc phuc <[email protected]>
The underlying functions already report these errors deeper in the call chain, making the additional dev_err_probe() and dev_err() calls unnecessary.
Also fix the indentation of the affected code and correct a typo in the DAI format error message.
---
Changes in v2:
- Add the indentation and typo fixes to this commit.
sound/soc/dwc/dwc-i2s.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
sound/soc/dwc/dwc-i2s.c +6 -10
@@ -331,7 +331,7 @@ static int dw_i2s_hw_params(struct snd_pcm_substream *substream, } }else {u32 bitclk = config->sample_rate * - config->data_width *2 ; + config->data_width *2 ;if (dev->tdm_slots) bitclk = config->sample_rate * config->data_width * dev->tdm_slots;
@@ -417,7 +417,7 @@ static int dw_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt) dev->frame_offset =0 ;break ;default : -dev_err (dev->dev,"DAI format unsupported" ); +dev_err (dev->dev,"DAI format unsupported\n" );return -EINVAL ; }
@@ -752,7 +752,7 @@ static int jh7110_i2s_crg_master_init(struct dw_i2s_dev *dev) ret =clk_bulk_get (dev->dev,ARRAY_SIZE (clks), clks);if (ret) -return dev_err_probe (dev->dev, ret,"failed to get i2s clocks\n" ); +return ret; mclk = clks[0 ].clk; mclk_ext = clks[1 ].clk;
@@ -830,7 +830,7 @@ static int jh7110_i2s_crg_slave_init(struct dw_i2s_dev *dev) ret =clk_bulk_get (dev->dev,ARRAY_SIZE (clks), clks);if (ret) -return dev_err_probe (dev->dev, ret,"failed to get i2s clocks\n" ); +return ret; mclk = clks[0 ].clk; mclk_ext = clks[1 ].clk;
@@ -968,10 +968,8 @@ static int dw_i2s_probe(struct platform_device *pdev)if (irq >0 ) { ret =devm_request_irq (&pdev->dev, irq, i2s_irq_handler,0 , pdev->name, dev); -if (ret <0 ) { -dev_err (&pdev->dev,"failed to request irq\n" ); +if (ret <0 ) goto err_assert_reset; - } } dev->i2s_reg_comp1 =I2S_COMP_PARAM_1 ;
@@ -1012,10 +1010,8 @@ static int dw_i2s_probe(struct platform_device *pdev)dev_set_drvdata (&pdev->dev, dev); ret =devm_snd_soc_register_component (&pdev->dev, &dw_i2s_component, dw_i2s_dai,1 ); -if (ret !=0 ) { -dev_err (&pdev->dev,"not able to register dai\n" ); +if (ret) goto err_assert_reset; - }if (!pdata || dev->is_jh7110) {if (irq >=0 ) {
Signature · 1 line
2.43.0
Mark Brown
maintainerQuoted 11 lines · On Wed, 11 Nov 2026 09:27:25 +0700, [email protected] wrote:
ASoC: dwc: Fix several issues in the I2S driver
From: bui duc phuc <[email protected]>
Hi all,
This series addresses several issues in the DesignWare I2S driver, including clock rate calculation, DAI configuration, channel limits, DMA FIFO sizing, and error handling.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.5
Thanks!
[1/6] ASoC: dwc: Fix bit clock rate in TDM mode
https://git.kernel.org/broonie/sound/c/1b1af8e535b1 [2/6] ASoC: dwc: Fix error handling in dw_i2s_set_fmt() https://git.kernel.org/broonie/sound/c/6d814b962a87 [3/6] ASoC: dwc: Fix channels_max derived from COMP_PARAM_1 https://git.kernel.org/broonie/sound/c/0b67b15489be [4/6] ASoC: dwc: Fix DMA fifo_size calculation https://git.kernel.org/broonie/sound/c/89c6374420f7 [5/6] ASoC: dwc: Propagate optional IRQ lookup errors https://git.kernel.org/broonie/sound/c/5d836a3a1e51 [6/6] ASoC: dwc: Remove redundant error messages https://git.kernel.org/broonie/sound/c/6d871a9e6a16
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark