ASoC: add xtensa xtfpga I2S interface and platform
Subsystems (4)
Max Filippov
maintainerPATCH 1/1 ASoC: add xtensa xtfpga I2S interface and platform
XTFPGA boards providean audio subsystem that consists of TI CDCE706 clock synthesizer, I2S transmitter and TLV320AIC23 audio codec.
I2S transmitter has MMIO-based interface that resembles that of the OpenCores I2S transmitter. I2S transmitter is always a master on I2S bus. There's no specialized audio DMA, sample data are transferred to I2S transmitter FIFO by CPU through memory-mapped queue interface.
--- .../devicetree/bindings/sound/cdns,xtfpga-i2s.txt | 18 + MAINTAINERS | 1 + sound/soc/Kconfig | 1 + sound/soc/Makefile | 1 + sound/soc/xtensa/Kconfig | 14 + sound/soc/xtensa/Makefile | 1 + sound/soc/xtensa/xtfpga-i2s.c | 647 +++++++++++++++++++++ 7 files changed, 683 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/cdns,xtfpga-i2s.txt create mode 100644 sound/soc/xtensa/Kconfig create mode 100644 sound/soc/xtensa/Makefile create mode 100644 sound/soc/xtensa/xtfpga-i2s.c
Documentation/devicetree/bindings/sound/cdns,xtfpga-i2s.txt new file +18 -0
@@ -0,0 +1,18 @@ +Bindings for I2S controller built into xtfpga Xtensa bitstreams. + +Required properties: +- compatible: shall be "cdns,xtfpga-i2s". +- reg: memory region (address and length) with device registers. +- interrupts: interrupt for the device. +- clocks: phandle to the clk used as master clock. I2S bus clock + is derived from it. + +Examples: + + i2s0: xtfpga-i2s@0d080000 { + #sound-dai-cells = <0>; + compatible = "cdns,xtfpga-i2s"; + reg = <0x0d080000 0x40>; + interrupts = <2 1>; + clocks = <&cdce706 4>; + };
MAINTAINERS +1 -0
@@ -10204,6 +10204,7 @@ M: Max Filippov <[email protected]> L: [email protected] S: Maintained F: drivers/spi/spi-xtensa-xtfpga.c +F: sound/soc/xtensa/xtfpga-i2s.c YAM DRIVER FOR AX.25 M: Jean-Paul Roubelat <[email protected]>
sound/soc/Kconfig +1 -0
@@ -56,6 +56,7 @@ source "sound/soc/spear/Kconfig" source "sound/soc/tegra/Kconfig" source "sound/soc/txx9/Kconfig" source "sound/soc/ux500/Kconfig" +source "sound/soc/xtensa/Kconfig" # Supported codecs source "sound/soc/codecs/Kconfig"
sound/soc/Makefile +1 -0
@@ -33,3 +33,4 @@ obj-$(CONFIG_SND_SOC) += spear/ obj-$(CONFIG_SND_SOC) += tegra/ obj-$(CONFIG_SND_SOC) += txx9/ obj-$(CONFIG_SND_SOC) += ux500/ +obj-$(CONFIG_SND_SOC) += xtensa/
sound/soc/xtensa/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +config SND_SOC_XTFPGA_I2S + tristate + select REGMAP_MMIO + +config SND_SOC_XTENSA_XTFPGA + tristate "SoC Audio for xtensa xtfpga" + depends on XTENSA_PLATFORM_XTFPGA + select SND_SOC_XTFPGA_I2S + select SND_SOC_TLV320AIC23_SPI + select SND_SIMPLE_CARD + help + Say Y or M if you want to add support for codecs attached to + xtfpga daughter board. You will also need to select the platform + to support below.
sound/soc/xtensa/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_SND_SOC_XTFPGA_I2S) += xtfpga-i2s.o
sound/soc/xtensa/xtfpga-i2s.c new file +647 -0
647 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Mark Brown
maintainersound/soc/xtensa/Kconfig line 10
Quoted 6 lines · Max Filippov
sound/soc/xtensa/Kconfig new file +6
-0+config SND_SOC_XTENSA_XTFPGA + tristate "SoC Audio for xtensa xtfpga" + depends on XTENSA_PLATFORM_XTFPGA + select SND_SOC_XTFPGA_I2S + select SND_SOC_TLV320AIC23_SPI + select SND_SIMPLE_CARD
I've only got this far in the file and have to leave now so I'll look properly at the actual code later but the above shouldn't have the CODEC or card driver selected, if the I2S driver is well written it should be usable independently of either.
sound/soc/xtensa/Makefile line 1
Quoted 3 lines
+++ b/sound/soc/xtensa/Makefile
sound/soc/xtensa/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-$(CONFIG_SND_SOC_XTFPGA_I2S) += xtfpga-i2s.o
Please follow the style for all other ASoC drivers and name the module snd-soc-foo.
Quoted 17 lines
sound/soc/xtensa/xtfpga-i2s.c new file +17
-0+static void xtfpga_i2s_push_tx (struct xtfpga_i2s *i2s) +{ +struct snd_pcm_substream *tx_substream; +struct snd_pcm_runtime *runtime; + +rcu_read_lock (); + tx_substream =rcu_dereference (i2s->tx_substream); + runtime = tx_substream->runtime; +#define xtfpga_i2s_tx_loop (i2s, runtime, channels, sample_bits) \ + do { \ + const u##sample_bits (*p)[channels] = \ + (void *)runtime->dma_area; \ + for (; i2s->tx_fifo_sz < i2s->tx_fifo_high; \ + i2s->tx_fifo_sz += 2) { \ + iowrite32(p[i2s->tx_ptr][0], \ + i2s->regs + XTFPGA_I2S_CHAN0_DATA); \ + iowrite32(p[i2s->tx_ptr][channels - 1], \
sound/soc/xtensa/xtfpga-i2s.c line 127
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c new file +10
-0+ i2s->regs + XTFPGA_I2S_CHAN0_DATA); \ +if (++i2s->tx_ptr >= runtime->buffer_size) \ + i2s->tx_ptr =0 ; \ + } \ + }while (0 ) + +switch (runtime->sample_bits | (runtime->channels <<8 )) { +case 0x110 : +xtfpga_i2s_tx_loop (i2s, runtime,1 ,16 ); +break ;
This really needs some rework to be legible. I'd suggest making your macro an inline function and either replacing these magic numbers in the switch statement with defines or just writing the code clearly and letting the compiler figure it out.
Some documentation explaining what your RCU usage is all about would also be good... I'm not clear why it's being used, none of the FIQ drivers do this and I can't entirely figure out what we're defending against other than the tasklet which we should be stopping anyway and why what we're doing is safe.
I would also expect to see the data transfer and I2S bits more split out, presumably this IP can actually be used in designs with a DMA controller and one would expect that for practical systems this would be the common case?
sound/soc/xtensa/xtfpga-i2s.c line 212
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c new file +10
-0+if (int_status &XTFPGA_I2S_INT_UNDERRUN ) { + i2s->tx_fifo_sz =0 ; +regmap_update_bits (i2s->regmap,XTFPGA_I2S_CONFIG , +XTFPGA_I2S_CONFIG_INT_ENABLE | +XTFPGA_I2S_CONFIG_TX_ENABLE ,0 ); + }else { + i2s->tx_fifo_sz = i2s->tx_fifo_low; +regmap_update_bits (i2s->regmap,XTFPGA_I2S_CONFIG , +XTFPGA_I2S_CONFIG_INT_ENABLE ,0 ); + }
We're trying to implement a NAPI style thing here?
sound/soc/xtensa/xtfpga-i2s.c line 231
Quoted 5 lines
sound/soc/xtensa/xtfpga-i2s.c new file +5
-0+if (tx_active) { +if (i2s->tx_fifo_high <256 ) +xtfpga_i2s_refill_fifo (i2s); +else +tasklet_hi_schedule (&i2s->refill_fifo);
How does the interrupt handler avoid getting into a fight with the tasklet if the interrupt line is shared?
Quoted 6 lines
sound/soc/xtensa/xtfpga-i2s.c new file +6
-0+static int xtfpga_i2s_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai) +{ +struct xtfpga_i2s *i2s =snd_soc_dai_get_drvdata (dai); +unsigned srate =params_rate (params);
sound/soc/xtensa/xtfpga-i2s.c line 313
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c new file +10
-0+unsigned channels =params_channels (params); +unsigned period_size =params_period_size (params); +unsigned sample_size =snd_pcm_format_width (params_format (params)); +unsigned freq, ratio, level; +int err; + +switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16_LE : +case SNDRV_PCM_FORMAT_S32_LE : +break ;
This looks buggy, we're accepting two different formats but not storing anything or telling the hardware - especially concerning given that this is a master only driver.
Quoted 7 lines
sound/soc/xtensa/xtfpga-i2s.c new file +7
-0+regmap_update_bits (i2s->regmap,XTFPGA_I2S_CONFIG , +XTFPGA_I2S_CONFIG_RES_MASK , + sample_size <<XTFPGA_I2S_CONFIG_RES_BASE ); + +if (i2s->clk_enabled) { +clk_disable_unprepare (i2s->clk); + i2s->clk_enabled = false;
sound/soc/xtensa/xtfpga-i2s.c line 335
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c new file +10
-0+ } + freq =256 * srate; + err =clk_set_rate (i2s->clk, freq); +if (err <0 ) +return err; + + err =clk_prepare_enable (i2s->clk); +if (err <0 ) +return err; + i2s->clk_enabled = true;
This stuff with the clock seems complicated, why not just leave it disabled when not in use and take advantage of the reference counting the core already has?
sound/soc/xtensa/xtfpga-i2s.c line 338
Quoted 2 lines
sound/soc/xtensa/xtfpga-i2s.c new file +2
-0+ ratio = (freq - srate * sample_size *8 ) / + (srate * sample_size *4 );
What ratio exactly? This needs more brackets in the first line and a comment explaining what it's calculating.
sound/soc/xtensa/xtfpga-i2s.c line 349
Quoted 6 lines
sound/soc/xtensa/xtfpga-i2s.c new file +6
-0+ i2s->tx_fifo_low =XTFPGA_I2S_FIFO_SIZE /2 ; +for (level =1 ; +/* period_size * 2: FIFO always gets 2 samples per frame */ + i2s->tx_fifo_low /2 >= period_size *2 ; + ++level) + i2s->tx_fifo_low /=2 ;
This can't come out with a bad value?
Max Filippov
maintainerQuoted 9 lines · Mark Brown
sound/soc/xtensa/Kconfig line 10
Quoted 6 lines · Max Filippov
sound/soc/xtensa/Kconfig new file +6
-0+config SND_SOC_XTENSA_XTFPGA + tristate "SoC Audio for xtensa xtfpga" + depends on XTENSA_PLATFORM_XTFPGA + select SND_SOC_XTFPGA_I2S + select SND_SOC_TLV320AIC23_SPI + select SND_SIMPLE_CARD
Quoted 4 lines
I've only got this far in the file and have to leave now so I'll look properly at the actual code later but the above shouldn't have the CODEC or card driver selected, if the I2S driver is well written it should be usable independently of either.
The above entry is for the whole sound subsystem of that SoC. An entry for I2S driver is above it.
Quoted 6 lines
sound/soc/xtensa/Makefile line 1
Quoted 3 lines
+++ b/sound/soc/xtensa/Makefile
sound/soc/xtensa/Makefile new file +1
-0@@ -0,0 +1 @@ +obj-$(CONFIG_SND_SOC_XTFPGA_I2S) += xtfpga-i2s.oPlease follow the style for all other ASoC drivers and name the module snd-soc-foo.
Ok.
Quoted 24 lines
Quoted 24 lines
sound/soc/xtensa/xtfpga-i2s.c new file +24
-0+static void xtfpga_i2s_push_tx (struct xtfpga_i2s *i2s) +{ +struct snd_pcm_substream *tx_substream; +struct snd_pcm_runtime *runtime; + +rcu_read_lock (); + tx_substream =rcu_dereference (i2s->tx_substream); + runtime = tx_substream->runtime; +#define xtfpga_i2s_tx_loop (i2s, runtime, channels, sample_bits) \ + do { \ + const u##sample_bits (*p)[channels] = \ + (void *)runtime->dma_area; \ + for (; i2s->tx_fifo_sz < i2s->tx_fifo_high; \ + i2s->tx_fifo_sz += 2) { \ + iowrite32(p[i2s->tx_ptr][0], \ + i2s->regs + XTFPGA_I2S_CHAN0_DATA); \ + iowrite32(p[i2s->tx_ptr][channels - 1], \ + i2s->regs + XTFPGA_I2S_CHAN0_DATA); \ + if (++i2s->tx_ptr >= runtime->buffer_size) \ + i2s->tx_ptr = 0; \ + } \ + } while (0) + +switch (runtime->sample_bits | (runtime->channels <<8 )) {
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 127
Quoted 3 lines
sound/soc/xtensa/xtfpga-i2s.c new file +3
-0+case 0x110 : +xtfpga_i2s_tx_loop (i2s, runtime,1 ,16 ); +break ;This really needs some rework to be legible. I'd suggest making your macro an inline function and either replacing these magic numbers in the switch statement with defines or just writing the code clearly and letting the compiler figure it out.
Ok, I'll rewrite it.
Quoted 5 lines
Some documentation explaining what your RCU usage is all about would also be good... I'm not clear why it's being used, none of the FIQ drivers do this and I can't entirely figure out what we're defending against other than the tasklet which we should be stopping anyway and why what we're doing is safe.
Ok, I'll document it. I'm synchronizing trigger callback with both interrupt handler and the tasklet. All that they need to know is whether we're playing a stream or not, so I protect the stream pointer with RCU. A spinlock for protection of a single pointer seems too big for me.
Quoted 4 lines
I would also expect to see the data transfer and I2S bits more split out, presumably this IP can actually be used in designs with a DMA controller and one would expect that for practical systems this would be the common case?
I don't know of other designs that use this IP block. Can we do it when we get such users?
Quoted 11 lines
sound/soc/xtensa/xtfpga-i2s.c line 212
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c new file +10
-0+if (int_status &XTFPGA_I2S_INT_UNDERRUN ) { + i2s->tx_fifo_sz =0 ; +regmap_update_bits (i2s->regmap,XTFPGA_I2S_CONFIG , +XTFPGA_I2S_CONFIG_INT_ENABLE | +XTFPGA_I2S_CONFIG_TX_ENABLE ,0 ); + }else { + i2s->tx_fifo_sz = i2s->tx_fifo_low; +regmap_update_bits (i2s->regmap,XTFPGA_I2S_CONFIG , +XTFPGA_I2S_CONFIG_INT_ENABLE ,0 ); + }
Quoted 1 line
We're trying to implement a NAPI style thing here?
No, there's no way to retrieve the exact FIFO level from the hardware, there's no such register. But there are two interrupt reasons: one when the FIFO is below preset level and another when FIFO is empty. So this code tracks the FIFO level according to the interrupt reason.
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 231
Quoted 5 lines
sound/soc/xtensa/xtfpga-i2s.c new file +5
-0+if (tx_active) { +if (i2s->tx_fifo_high <256 ) +xtfpga_i2s_refill_fifo (i2s); +else +tasklet_hi_schedule (&i2s->refill_fifo);How does the interrupt handler avoid getting into a fight with the tasklet if the interrupt line is shared?
IRQ is masked in the I2S controller once we're in the interrupt handler and is not re-enabled until we're done with FIFO, which happens at the very end of a tasklet. But if the line could ever be shared interrupt handler logic that checks if IRQ came from our device needs an additional check. Thanks for pointing that out.
Quoted 12 lines
Quoted 12 lines
sound/soc/xtensa/xtfpga-i2s.c new file +12
-0+static int xtfpga_i2s_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params, +struct snd_soc_dai *dai) +{ +struct xtfpga_i2s *i2s =snd_soc_dai_get_drvdata (dai); +unsigned srate =params_rate (params); +unsigned channels =params_channels (params); +unsigned period_size =params_period_size (params); +unsigned sample_size =snd_pcm_format_width (params_format (params)); +unsigned freq, ratio, level; +int err; +
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 313
Quoted 4 lines
sound/soc/xtensa/xtfpga-i2s.c new file +4
-0+switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16_LE : +case SNDRV_PCM_FORMAT_S32_LE : +break ;This looks buggy, we're accepting two different formats but not storing anything or telling the hardware - especially concerning given that this is a master only driver.
xtfpga_i2s_push_tx does the right thing based on runtime->sample_bits value.
Quoted 13 lines
Quoted 13 lines
sound/soc/xtensa/xtfpga-i2s.c new file +13
-0+regmap_update_bits (i2s->regmap,XTFPGA_I2S_CONFIG , +XTFPGA_I2S_CONFIG_RES_MASK , + sample_size <<XTFPGA_I2S_CONFIG_RES_BASE ); + +if (i2s->clk_enabled) { +clk_disable_unprepare (i2s->clk); + i2s->clk_enabled = false; + } + freq =256 * srate; + err =clk_set_rate (i2s->clk, freq); +if (err <0 ) +return err; +
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 335
Quoted 4 lines
sound/soc/xtensa/xtfpga-i2s.c new file +4
-0+ err =clk_prepare_enable (i2s->clk); +if (err <0 ) +return err; + i2s->clk_enabled = true;This stuff with the clock seems complicated, why not just leave it disabled when not in use and take advantage of the reference counting the core already has?
Because this callback is said to be potentially called multiple times per initialization. Is it not?
Quoted 5 lines
sound/soc/xtensa/xtfpga-i2s.c line 338
Quoted 2 lines
sound/soc/xtensa/xtfpga-i2s.c new file +2
-0+ ratio = (freq - srate * sample_size *8 ) / + (srate * sample_size *4 );What ratio exactly? This needs more brackets in the first line and a comment explaining what it's calculating.
It controls the divider in the I2S controller that derives I2S bus frequency from the master clock. The manual basically says 'use the following equation to determine the ratio value'.
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 349
Quoted 6 lines
sound/soc/xtensa/xtfpga-i2s.c new file +6
-0+ i2s->tx_fifo_low =XTFPGA_I2S_FIFO_SIZE /2 ; +for (level =1 ; +/* period_size * 2: FIFO always gets 2 samples per frame */ + i2s->tx_fifo_low /2 >= period_size *2 ; + ++level) + i2s->tx_fifo_low /=2 ;This can't come out with a bad value?
I've tested it in the range of frequencies that we support -- works well.
Signature · 2 lines
Thanks. -- Max
Mark Brown
maintainerQuoted 10 lines · Max Filippov
Quoted 8 lines · Mark Brown
Quoted 6 lines · Max Filippov
sound/soc/xtensa/Kconfig new file +6
-0+config SND_SOC_XTENSA_XTFPGA + tristate "SoC Audio for xtensa xtfpga" + depends on XTENSA_PLATFORM_XTFPGA + select SND_SOC_XTFPGA_I2S + select SND_SOC_TLV320AIC23_SPI + select SND_SIMPLE_CARD
Quoted 7 lines
Quoted 4 lines
I've only got this far in the file and have to leave now so I'll look properly at the actual code later but the above shouldn't have the CODEC or card driver selected, if the I2S driver is well written it should be usable independently of either.
The above entry is for the whole sound subsystem of that SoC. An entry for I2S driver is above it.
Then this just shouldn't exist at all, adding Kconfig entries for all the simple-card devices would defeat the point of having simple-card which is why we don't do it for other systems.
Quoted 10 lines
Quoted 5 lines
Some documentation explaining what your RCU usage is all about would also be good... I'm not clear why it's being used, none of the FIQ drivers do this and I can't entirely figure out what we're defending against other than the tasklet which we should be stopping anyway and why what we're doing is safe.
Ok, I'll document it. I'm synchronizing trigger callback with both interrupt handler and the tasklet. All that they need to know is whether we're playing a stream or not, so I protect the stream pointer with RCU. A spinlock for protection of a single pointer seems too big for me.
So atomics don't work? Simple flags are one of the few cases where they might cover it... again, the fact that this isn't similar to other code doing the same thing is worrying.
Quoted 7 lines
Quoted 4 lines
I would also expect to see the data transfer and I2S bits more split out, presumably this IP can actually be used in designs with a DMA controller and one would expect that for practical systems this would be the common case?
I don't know of other designs that use this IP block. Can we do it when we get such users?
It's also about ensuring that the code is cleanly split up so that someone can actually go in and add the required support later (and TBH it'd be better to just add a DMA controller on the FPGA, everyone will be much happier).
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c new file +10
-0+if (int_status &XTFPGA_I2S_INT_UNDERRUN ) { + i2s->tx_fifo_sz =0 ; +regmap_update_bits (i2s->regmap,XTFPGA_I2S_CONFIG , +XTFPGA_I2S_CONFIG_INT_ENABLE | +XTFPGA_I2S_CONFIG_TX_ENABLE ,0 ); + }else { + i2s->tx_fifo_sz = i2s->tx_fifo_low; +regmap_update_bits (i2s->regmap,XTFPGA_I2S_CONFIG , +XTFPGA_I2S_CONFIG_INT_ENABLE ,0 ); + }
Quoted 6 lines
Quoted 1 line
We're trying to implement a NAPI style thing here?
No, there's no way to retrieve the exact FIFO level from the hardware, there's no such register. But there are two interrupt reasons: one when the FIFO is below preset level and another when FIFO is empty. So this code tracks the FIFO level according to the interrupt reason.
...and then it appears to try to implement something like NAPI?
Quoted 11 lines
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 313
Quoted 4 lines
sound/soc/xtensa/xtfpga-i2s.c new file +4
-0+switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16_LE : +case SNDRV_PCM_FORMAT_S32_LE : +break ;This looks buggy, we're accepting two different formats but not storing anything or telling the hardware - especially concerning given that this is a master only driver.
xtfpga_i2s_push_txdoes the right thing based onruntime->sample_bitsvalue.
So add a comment then. The thing I was saying about the data push code being hard to understand apply generally.
Quoted 11 lines
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 335
Quoted 4 lines
sound/soc/xtensa/xtfpga-i2s.c new file +4
-0+ err =clk_prepare_enable (i2s->clk); +if (err <0 ) +return err; + i2s->clk_enabled = true;This stuff with the clock seems complicated, why not just leave it disabled when not in use and take advantage of the reference counting the core already has?
Because this callback is said to be potentially called multiple times per initialization. Is it not?
It can but but I'm not seeing any connection between that and the idea of not keeping the clock enabled when the device isn't in use?
Quoted 10 lines
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 349
Quoted 6 lines
sound/soc/xtensa/xtfpga-i2s.c new file +6
-0+ i2s->tx_fifo_low =XTFPGA_I2S_FIFO_SIZE /2 ; +for (level =1 ; +/* period_size * 2: FIFO always gets 2 samples per frame */ + i2s->tx_fifo_low /2 >= period_size *2 ; + ++level) + i2s->tx_fifo_low /=2 ;This can't come out with a bad value?
I've tested it in the range of frequencies that we support -- works well.
I'm not sure I find that terribly convincing, I'd like to be able to look at the code and tell that it's not going to blow up. This again comes back to the general comment about clarity - the code *looks* suspicious (strange indentation of the for loop with a comment in the middle of the statement itself for example).
On 10/27/2014 08:07 PM, Max Filippov wrote:
A few minor things.
[...]
Quoted 30 lines
sound/soc/xtensa/xtfpga-i2s.c new file +30
-0+static irqreturn_t xtfpga_i2s_interrupt (int irq,void *dev_id) +{ +struct xtfpga_i2s *i2s = dev_id; +struct snd_pcm_substream *tx_substream; +int tx_active; +unsigned int_status; + +regmap_read (i2s->regmap,XTFPGA_I2S_INT_STATUS , &int_status); +if (!(int_status &XTFPGA_I2S_INT_VALID )) +return IRQ_NONE ; + +if (int_status &XTFPGA_I2S_INT_UNDERRUN ) { + i2s->tx_fifo_sz =0 ; +regmap_update_bits (i2s->regmap,XTFPGA_I2S_CONFIG , +XTFPGA_I2S_CONFIG_INT_ENABLE | +XTFPGA_I2S_CONFIG_TX_ENABLE ,0 ); + }else { + i2s->tx_fifo_sz = i2s->tx_fifo_low; +regmap_update_bits (i2s->regmap,XTFPGA_I2S_CONFIG , +XTFPGA_I2S_CONFIG_INT_ENABLE ,0 ); + } + +rcu_read_lock (); + tx_substream =rcu_dereference (i2s->tx_substream); + tx_active = tx_substream &&snd_pcm_running (tx_substream); +if (tx_active) { +snd_pcm_period_elapsed (tx_substream); +if (int_status &XTFPGA_I2S_INT_UNDERRUN ) +dev_dbg_ratelimited (i2s->dev,"%s: underrun\n" , + __func__);
sound/soc/xtensa/xtfpga-i2s.c line 231
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c new file +10
-0+ tx_substream =rcu_dereference (i2s->tx_substream); + tx_active = tx_substream &&snd_pcm_running (tx_substream); + } +rcu_read_unlock (); + +if (tx_active) { +if (i2s->tx_fifo_high <256 ) +xtfpga_i2s_refill_fifo (i2s); +else +tasklet_hi_schedule (&i2s->refill_fifo);
Maybe use threaded IRQs instead of IRQ + tasklet.
Quoted 6 lines
sound/soc/xtensa/xtfpga-i2s.c new file +6
-0+ }else { +xtfpga_i2s_irq_update_config (i2s, int_status); + } + +return IRQ_HANDLED ; +}
[...]
Quoted 11 lines
sound/soc/xtensa/xtfpga-i2s.c new file +11
-0+ +static int xtfpga_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +{ +int ret; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +case SNDRV_PCM_TRIGGER_STOP : +case SNDRV_PCM_TRIGGER_SUSPEND :
sound/soc/xtensa/xtfpga-i2s.c line 459
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c new file +10
-0+case SNDRV_PCM_TRIGGER_PAUSE_PUSH : + ret =0 ; +break ; + +default : + ret = -EINVAL ; +break ; + } +return ret; +}
If you don't do anything you don't need the handler. The core will handle things if it is NULL.
Quoted 1 line
+static struct
snd_pcm_opsxtfpga_pcm_ops= {
const
Quoted 7 lines
sound/soc/xtensa/xtfpga-i2s.c new file +7
-0+ .open = xtfpga_pcm_open, + .close = xtfpga_pcm_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = xtfpga_pcm_hw_params, + .trigger = xtfpga_pcm_trigger, + .pointer = xtfpga_pcm_pointer, +};
[...]
sound/soc/xtensa/xtfpga-i2s.c line 538
Quoted 12 lines
sound/soc/xtensa/xtfpga-i2s.c new file +12
-0+static int xtfpga_i2s_probe (struct platform_device *pdev) +{ +struct xtfpga_i2s *i2s; +struct resource *mem, *irq; +int err; + + i2s =devm_kzalloc (&pdev->dev,sizeof (*i2s),GFP_KERNEL ); +if (!i2s) { + err = -ENOMEM ; + goto err; + } +dev_set_drvdata (&pdev->dev, i2s);
platform_set_drvdata(...)
sound/soc/xtensa/xtfpga-i2s.c line 547
Quoted 9 lines
sound/soc/xtensa/xtfpga-i2s.c new file +9
-0+ i2s->dev = &pdev->dev; +dev_dbg (&pdev->dev,"dev: %p, i2s: %p\n" , &pdev->dev, i2s); + + mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!mem) { +dev_err (&pdev->dev,"No memory resource\n" ); + err = -ENODEV ; + goto err; + }
devm_ioremap_resource will check if mem is NULL and print a error message, so the check above can be removed.
Quoted 12 lines
sound/soc/xtensa/xtfpga-i2s.c new file +12
-0+ i2s->regs =devm_ioremap_resource (&pdev->dev, mem); +if (IS_ERR (i2s->regs)) { + err =PTR_ERR (i2s->regs); + goto err; + } + + i2s->regmap =devm_regmap_init_mmio (&pdev->dev, i2s->regs, + &xtfpga_i2s_regmap_config); +if (IS_ERR (i2s->regmap)) { +dev_err (&pdev->dev,"regmap init failed\n" ); + err =PTR_ERR (i2s->regmap); + goto err;
sound/soc/xtensa/xtfpga-i2s.c line 569
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c new file +10
-0+ } + + i2s->clk =devm_clk_get (&pdev->dev,NULL ); +if (IS_ERR (i2s->clk)) { +dev_err (&pdev->dev,"couldn't get clock\n" ); + err =PTR_ERR (i2s->clk); + goto err; + } + + irq =platform_get_resource (pdev,IORESOURCE_IRQ ,0 );
platform_get_irq(...)
Quoted 4 lines
sound/soc/xtensa/xtfpga-i2s.c new file +4
-0+if (!irq) { +dev_err (&pdev->dev,"No IRQ resource\n" ); + err = -ENODEV ; + goto err;
sound/soc/xtensa/xtfpga-i2s.c line 583
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c new file +10
-0+ } + err =devm_request_irq (&pdev->dev, irq->start, xtfpga_i2s_interrupt, +IRQF_SHARED , pdev->name, i2s); +if (err <0 ) { +dev_err (&pdev->dev,"request_irq failed\n" ); + goto err; + } +tasklet_init (&i2s->refill_fifo, xtfpga_i2s_refill_fifo_tasklet, + (unsigned long )i2s); +
Since the tasklet is is used in the interrupt handler it should initialized before the IRQ is requested.
Quoted 17 lines
sound/soc/xtensa/xtfpga-i2s.c new file +17
-0+regmap_write (i2s->regmap,XTFPGA_I2S_CONFIG , + (0x1 <<XTFPGA_I2S_CONFIG_CHANNEL_BASE )); +regmap_write (i2s->regmap,XTFPGA_I2S_INT_STATUS ,XTFPGA_I2S_INT_VALID ); +regmap_write (i2s->regmap,XTFPGA_I2S_INT_MASK ,XTFPGA_I2S_INT_UNDERRUN ); + + err =snd_soc_register_platform (&pdev->dev, &xtfpga_soc_platform); +if (err <0 ) { +dev_err (&pdev->dev,"couldn't register platform\n" ); + goto err; + } + err =devm_snd_soc_register_component (&pdev->dev, + &xtfpga_i2s_component, + xtfpga_i2s_dai, +ARRAY_SIZE (xtfpga_i2s_dai)); +if (err <0 ) +dev_err (&pdev->dev,"couldn't register component\n" ); +err:
sound/soc/xtensa/xtfpga-i2s.c line 610
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c new file +10
-0+if (err) +dev_err (&pdev->dev,"%s: err = %d\n" , __func__, err); +return err; +} + +static int xtfpga_i2s_remove (struct platform_device *pdev) +{ +struct xtfpga_i2s *i2s =dev_get_drvdata (&pdev->dev); + +if (i2s) {
This will always be non NULL.
Quoted 13 lines
sound/soc/xtensa/xtfpga-i2s.c new file +13
-0+tasklet_kill (&i2s->refill_fifo); +if (i2s->regmap && !IS_ERR (i2s->regmap)) { +regmap_write (i2s->regmap,XTFPGA_I2S_CONFIG ,0 ); +regmap_write (i2s->regmap,XTFPGA_I2S_INT_MASK ,0 ); +regmap_write (i2s->regmap,XTFPGA_I2S_INT_STATUS , +XTFPGA_I2S_INT_VALID ); + } +if (i2s->clk_enabled) +clk_disable_unprepare (i2s->clk); + } + +return 0 ; +}
[...]
Mark Brown
maintainerQuoted 9 lines · Lars-Peter Clausen
sound/soc/xtensa/xtfpga-i2s.c line 231
Quoted 5 lines · Max Filippov
sound/soc/xtensa/xtfpga-i2s.c new file +5
-0+if (tx_active) { +if (i2s->tx_fifo_high <256 ) +xtfpga_i2s_refill_fifo (i2s); +else +tasklet_hi_schedule (&i2s->refill_fifo);Maybe use threaded IRQs instead of IRQ + tasklet.
Is that going to play nicely with the fact that the interrupt can be shared and the desire to (AFAICT) do NAPI style stuff with the interrupt disabled for long periods?
Quoted 11 lines · Mark Brown
Quoted 9 lines · Lars-Peter Clausen
sound/soc/xtensa/xtfpga-i2s.c line 231
Quoted 5 lines · Max Filippov
sound/soc/xtensa/xtfpga-i2s.c new file +5
-0+if (tx_active) { +if (i2s->tx_fifo_high <256 ) +xtfpga_i2s_refill_fifo (i2s); +else +tasklet_hi_schedule (&i2s->refill_fifo);Maybe use threaded IRQs instead of IRQ + tasklet.
Quoted 4 lines
Is that going to play nicely with the fact that the interrupt can be shared and the desire to (AFAICT) do NAPI style stuff with the interrupt disabled for long periods?
Threaded interrupts got support for interrupt sharing a while ago, so I guess yes. I think it will even work better than the tasklet approach. You can configure the IRQ to disable itself as long as the thread is running.
- Lars
At Tue, 28 Oct 2014 17:39:13 +0100,
Quoted 13 lines · Lars-Peter Clausen
Quoted 11 lines · Mark Brown
Quoted 9 lines · Lars-Peter Clausen
sound/soc/xtensa/xtfpga-i2s.c line 231
Quoted 5 lines · Max Filippov
sound/soc/xtensa/xtfpga-i2s.c new file +5
-0+if (tx_active) { +if (i2s->tx_fifo_high <256 ) +xtfpga_i2s_refill_fifo (i2s); +else +tasklet_hi_schedule (&i2s->refill_fifo);Maybe use threaded IRQs instead of IRQ + tasklet.
Quoted 8 lines
Quoted 4 lines
Is that going to play nicely with the fact that the interrupt can be shared and the desire to (AFAICT) do NAPI style stuff with the interrupt disabled for long periods?
Threaded interrupts got support for interrupt sharing a while ago, so I guess yes. I think it will even work better than the tasklet approach. You can configure the IRQ to disable itself as long as the thread is running.
Yes, I tested the threaded irq with PCI drivers using shared irqs and worked well.
Takashi
Max Filippov
maintainerQuoted 16 lines · Mark Brown
Quoted 14 lines · Max Filippov
Quoted 13 lines · Mark Brown
sound/soc/xtensa/Kconfig line 10
Quoted 6 lines · Max Filippov
sound/soc/xtensa/Kconfig new file +6
-0+config SND_SOC_XTENSA_XTFPGA + tristate "SoC Audio for xtensa xtfpga" + depends on XTENSA_PLATFORM_XTFPGA + select SND_SOC_XTFPGA_I2S + select SND_SOC_TLV320AIC23_SPI + select SND_SIMPLE_CARDI've only got this far in the file and have to leave now so I'll look properly at the actual code later but the above shouldn't have the CODEC or card driver selected, if the I2S driver is well written it should be usable independently of either.
Quoted 6 lines
Quoted 2 lines
The above entry is for the whole sound subsystem of that SoC. An entry for I2S driver is above it.
Then this just shouldn't exist at all, adding
Kconfigentries for all the simple-card devices would defeat the point of having simple-card which is why we don't do it for other systems.
sound/soc/sh/Kconfig does that as well.
Not having single config item to enable at once all relevant drivers feels a bit strange... But ok, I'll drop that.
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Some documentation explaining what your RCU usage is all about would also be good... I'm not clear why it's being used, none of the FIQ drivers do this and I can't entirely figure out what we're defending against other than the tasklet which we should be stopping anyway and why what we're doing is safe.
Quoted 8 lines
Quoted 4 lines
Ok, I'll document it. I'm synchronizing trigger callback with both interrupt handler and the tasklet. All that they need to know is whether we're playing a stream or not, so I protect the stream pointer with RCU. A spinlock for protection of a single pointer seems too big for me.
So atomics don't work? Simple flags are one of the few cases where they might cover it... again, the fact that this isn't similar to other code doing the same thing is worrying.
tx_substream use pattern is the same as of a typical RCU variable. RCU wrappers combine ACCESS_ONCE and barriers that I'd otherwise have to write myself.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
I would also expect to see the data transfer and I2S bits more split out, presumably this IP can actually be used in designs with a DMA controller and one would expect that for practical systems this would be the common case?
I don't know of other designs that use this IP block. Can we do it when we get such users?
It's also about ensuring that the code is cleanly split up so that someone can actually go in and add the required support later (and TBH
Can you point me to an example of such split, so that I don't write it in an unusual way?
Quoted 2 lines
it'd be better to just add a DMA controller on the FPGA, everyone will be much happier).
Hardware people think different and it's been like that for more than 5 years.
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c new file +10
-0+if (int_status &XTFPGA_I2S_INT_UNDERRUN ) { + i2s->tx_fifo_sz =0 ; +regmap_update_bits (i2s->regmap,XTFPGA_I2S_CONFIG , +XTFPGA_I2S_CONFIG_INT_ENABLE | +XTFPGA_I2S_CONFIG_TX_ENABLE ,0 ); + }else { + i2s->tx_fifo_sz = i2s->tx_fifo_low; +regmap_update_bits (i2s->regmap,XTFPGA_I2S_CONFIG , +XTFPGA_I2S_CONFIG_INT_ENABLE ,0 ); + }
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
We're trying to implement a NAPI style thing here?
No, there's no way to retrieve the exact FIFO level from the hardware, there's no such register. But there are two interrupt reasons: one when the FIFO is below preset level and another when FIFO is empty. So this code tracks the FIFO level according to the interrupt reason.
...and then it appears to try to implement something like NAPI?
If the programmed FIFO level is low enough I refill FIFO right in the interrupt handler. If I use tasklet for such short FIFOs the sound becomes choppy.
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 313
Quoted 4 lines
sound/soc/xtensa/xtfpga-i2s.c new file +4
-0+switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S16_LE : +case SNDRV_PCM_FORMAT_S32_LE : +break ;This looks buggy, we're accepting two different formats but not storing anything or telling the hardware - especially concerning given that this is a master only driver.
Quoted 5 lines
Quoted 2 lines
xtfpga_i2s_push_txdoes the right thing based onruntime->sample_bitsvalue.So add a comment then. The thing I was saying about the data push code being hard to understand apply generally.
Ok.
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 335
Quoted 4 lines
sound/soc/xtensa/xtfpga-i2s.c new file +4
-0+ err =clk_prepare_enable (i2s->clk); +if (err <0 ) +return err; + i2s->clk_enabled = true;This stuff with the clock seems complicated, why not just leave it disabled when not in use and take advantage of the reference counting the core already has?
Quoted 5 lines
Quoted 2 lines
Because this callback is said to be potentially called multiple times per initialization. Is it not?
It can but but I'm not seeing any connection between that and the idea of not keeping the clock enabled when the device isn't in use?
hw_params callback can change MCLK rate, so it has to disable and enable the clock anyway, and since enable can fail it does not guarantee that the clock will be left in the same state. Or should I adjust MCLK rate w/o disabling the clock?
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 349
Quoted 6 lines
sound/soc/xtensa/xtfpga-i2s.c new file +6
-0+ i2s->tx_fifo_low =XTFPGA_I2S_FIFO_SIZE /2 ; +for (level =1 ; +/* period_size * 2: FIFO always gets 2 samples per frame */ + i2s->tx_fifo_low /2 >= period_size *2 ; + ++level) + i2s->tx_fifo_low /=2 ;This can't come out with a bad value?
Quoted 7 lines
Quoted 1 line
I've tested it in the range of frequencies that we support -- works well.
I'm not sure I find that terribly convincing, I'd like to be able to look at the code and tell that it's not going to blow up. This again comes back to the general comment about clarity - the code *looks* suspicious (strange indentation of the for loop with a comment in the middle of the statement itself for example).
The level field in the control register is 4 bit wide, so the allowed range of level is 0..15. FIFO size is 8192 entries, level = 1 corresponds to FIFO size / 2, level = 14 -- to FIFO size of 0. I guess this function won't get period_size of 0?
Signature · 2 lines
Thanks. -- Max
Mark Brown
maintainerQuoted 9 lines · Lars-Peter Clausen
Quoted 3 lines · Mark Brown
Is that going to play nicely with the fact that the interrupt can be shared and the desire to (AFAICT) do NAPI style stuff with the interrupt disabled for long periods?
Threaded interrupts got support for interrupt sharing a while ago, so I guess yes. I think it will even work better than the tasklet approach. You can configure the IRQ to disable itself as long as the thread is running.
I know you *can* share threaded interrupts, I'm just not sure that hogging the threaded handler plays nicely with other users. Though now I look at this again tx_fifo_high is a "constant" so it's not actually trying to do a NAPI type mitigation thing and this is really just an open coded threaded interrupt as you say.
Max Filippov
maintainerHi Lars-Peter,
Quoted 6 lines · Lars-Peter Clausen
On 10/27/2014 08:07 PM, Max Filippov wrote:
A few minor things.
[...]
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 231
Quoted 6 lines
sound/soc/xtensa/xtfpga-i2s.c new file +6
-0+static irqreturn_t xtfpga_i2s_interrupt (int irq,void *dev_id) + if (tx_active) { +if (i2s->tx_fifo_high <256 ) +xtfpga_i2s_refill_fifo (i2s); +else +tasklet_hi_schedule (&i2s->refill_fifo);Maybe use threaded IRQs instead of IRQ + tasklet.
Ok, I'll look at it.
Quoted 4 lines
Quoted 1 line
+static int xtfpga_pcm_trigger(struct
snd_pcm_substream*substream, intIf you don't do anything you don't need the handler. The core will handle things if it is NULL.
Ok.
Quoted 3 lines
Quoted 1 line
+static struct
snd_pcm_opsxtfpga_pcm_ops= {const
Ok.
Quoted 4 lines
sound/soc/xtensa/xtfpga-i2s.c line 538
Quoted 2 lines
sound/soc/xtensa/xtfpga-i2s.c new file +2
-0+static int xtfpga_i2s_probe(struct platform_device *pdev) + dev_set_drvdata(&pdev->dev, i2s);
platform_set_drvdata(...)
Ok.
Quoted 10 lines
sound/soc/xtensa/xtfpga-i2s.c line 547
Quoted 9 lines
sound/soc/xtensa/xtfpga-i2s.c new file +9
-0+ i2s->dev = &pdev->dev; +dev_dbg (&pdev->dev,"dev: %p, i2s: %p\n" , &pdev->dev, i2s); + + mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!mem) { +dev_err (&pdev->dev,"No memory resource\n" ); + err = -ENODEV ; + goto err; + }
Quoted 2 lines
devm_ioremap_resourcewill check if mem is NULL and print a error message, so the check above can be removed.
Ok.
Quoted 3 lines
Quoted 1 line
+ irq =
platform_get_resource(pdev, IORESOURCE_IRQ, 0);
platform_get_irq(...)
Ok.
Quoted 12 lines
sound/soc/xtensa/xtfpga-i2s.c line 583
Quoted 10 lines
+ err = devm_request_irq(&pdev->dev,
irq->start,xtfpga_i2s_interrupt,sound/soc/xtensa/xtfpga-i2s.c new file +8
-0+ IRQF_SHARED, pdev->name, i2s); +if (err <0 ) { +dev_err (&pdev->dev,"request_irq failed\n" ); + goto err; + } +tasklet_init (&i2s->refill_fifo, xtfpga_i2s_refill_fifo_tasklet, + (unsigned long )i2s); +
Quoted 2 lines
Since the tasklet is is used in the interrupt handler it should initialized before the IRQ is requested.
Ok.
Quoted 8 lines
sound/soc/xtensa/xtfpga-i2s.c line 610
Quoted 5 lines
sound/soc/xtensa/xtfpga-i2s.c new file +5
-0+static int xtfpga_i2s_remove (struct platform_device *pdev) +{ +struct xtfpga_i2s *i2s =dev_get_drvdata (&pdev->dev); + +if (i2s) {This will always be non NULL.
Ok.
Signature · 2 lines
Thanks. -- Max
Mark Brown
maintainerQuoted 9 lines · Max Filippov
Quoted 3 lines · Mark Brown
Then this just shouldn't exist at all, adding
Kconfigentries for all the simple-card devices would defeat the point of having simple-card which is why we don't do it for other systems.
sound/soc/sh/Kconfigdoes that as well.
Not having single config item to enable at once all relevant drivers feels a bit strange... But ok, I'll drop that.
This is new code, not a replacement of old code.
Quoted 7 lines
Quoted 3 lines
So atomics don't work? Simple flags are one of the few cases where they might cover it... again, the fact that this isn't similar to other code doing the same thing is worrying.
tx_substreamuse pattern is the same as of a typical RCU variable. RCU wrappers combineACCESS_ONCEand barriers that I'd otherwise have to write myself.
You *really* need to explain how it's supposed to work - right now it's not at all obvious, like I say the fact that this is a rarely used idiom is not helping. For example when we tear down the stream we just assign the pointer in _stop() but don't bother with a sync until the stream is closed - why? We also appear to be doing several different dereferences of the pointer inside a single rcu_read_lock() for some reason which is worrying.
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
I would also expect to see the data transfer and I2S bits more split out, presumably this IP can actually be used in designs with a DMA controller and one would expect that for practical systems this would be the common case?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I don't know of other designs that use this IP block. Can we do it when we get such users?
It's also about ensuring that the code is cleanly split up so that someone can actually go in and add the required support later (and TBH
Can you point me to an example of such split, so that I don't write it in an unusual way?
Essentially all drivers are split this way...
Quoted 5 lines
Quoted 2 lines
it'd be better to just add a DMA controller on the FPGA, everyone will be much happier).
Hardware people think different and it's been like that for more than 5 years.
They appear to be the only hardware people who think this way, while we do have some FIQ based PIO stuff in mainline all the examples I can think of are there because people didn't work out how to drive the DMA controller yet (and even there we're using FIQs not bashing things in from a regular interrupt).
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
Because this callback is said to be potentially called multiple times per initialization. Is it not?
It can but but I'm not seeing any connection between that and the idea of not keeping the clock enabled when the device isn't in use?
hw_paramscallback can change MCLK rate, so it has to disable and enable the clock anyway, and since enable can fail it does not guarantee that the clock will be left in the same state. Or should I adjust MCLK rate w/o disabling the clock?
So yet again: why not just enable the clock only when the device is in use? If it's being configured it stands to reason that the device isn't actively in use...
Quoted 10 lines
Quoted 5 lines
I'm not sure I find that terribly convincing, I'd like to be able to look at the code and tell that it's not going to blow up. This again comes back to the general comment about clarity - the code *looks* suspicious (strange indentation of the for loop with a comment in the middle of the statement itself for example).
The level field in the control register is 4 bit wide, so the allowed range of level is 0..15. FIFO size is 8192 entries, level = 1 corresponds to FIFO size / 2, level = 14 -- to FIFO size of 0. I guess this function won't get
period_sizeof 0?
So if the IP gets changed and the code gets blown up this could well explode then... which doesn't seem entirely unlikely considering this is a FPGA platform so presumably this is easy to update. To repeat this is about clarity and the code looking like it's probably hiding bugs as much as if the code actually works if you really sit down and study it.
Max Filippov
maintainerQuoted 10 lines · Mark Brown
Quoted 8 lines · Max Filippov
Quoted 3 lines · Mark Brown
So atomics don't work? Simple flags are one of the few cases where they might cover it... again, the fact that this isn't similar to other code doing the same thing is worrying.
tx_substreamuse pattern is the same as of a typical RCU variable. RCU wrappers combineACCESS_ONCEand barriers that I'd otherwise have to write myself.
Quoted 5 lines
You *really* need to explain how it's supposed to work - right now it's not at all obvious, like I say the fact that this is a rarely used idiom is not helping. For example when we tear down the stream we just assign the pointer in
_stop()but don't bother with a sync until the stream is closed - why?
Because we can't wait in stop and syncing is not time critical, we can do it any time before the stream becomes invalid.
Quoted 3 lines
We also appear to be doing several different dereferences
of the pointer inside a singlercu_read_lock()for some reason which is worrying.
I've cleaned that up.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
it'd be better to just add a DMA controller on the FPGA, everyone will be much happier).
Hardware people think different and it's been like that for more than 5 years.
They appear to be the only hardware people who think this way, while we
The whole audio subsystem on xtfpga boards is there for, I think, a single
purpose: for the demonstration of CPU audio processing capabilities. That's why it's that simple.
Quoted 4 lines
do have some FIQ based PIO stuff in mainline all the examples I can think of are there because people didn't work out how to drive the DMA controller yet (and even there we're using FIQs not bashing things in from a regular interrupt).
Currently we don't support fast interrupt handlers written in C on xtensa.
Quoted 6 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Because this callback is said to be potentially called multiple times per initialization. Is it not?
It can but but I'm not seeing any connection between that and the idea of not keeping the clock enabled when the device isn't in use?
Quoted 8 lines
Quoted 4 lines
hw_paramscallback can change MCLK rate, so it has to disable and enable the clock anyway, and since enable can fail it does not guarantee that the clock will be left in the same state. Or should I adjust MCLK rate w/o disabling the clock?So yet again: why not just enable the clock only when the device is in use? If it's being configured it stands to reason that the device isn't actively in use...
Mark, I don't get it, sorry ): My clock synthesizer is I2C controlled, so I can't prepare/unprepare it in the trigger callback. When should I do it?
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
I'm not sure I find that terribly convincing, I'd like to be able to look at the code and tell that it's not going to blow up. This again comes back to the general comment about clarity - the code *looks* suspicious (strange indentation of the for loop with a comment in the middle of the statement itself for example).
The level field in the control register is 4 bit wide, so the allowed range of level is 0..15. FIFO size is 8192 entries, level = 1 corresponds to FIFO size / 2, level = 14 -- to FIFO size of 0. I guess this function won't get
period_sizeof 0?
Quoted 5 lines
So if the IP gets changed and the code gets blown up this could well explode then... which doesn't seem entirely unlikely considering this is a FPGA platform so presumably this is easy to update. To repeat this is about clarity and the code looking like it's probably hiding bugs as much as if the code actually works if you really sit down and study it.
The calculation does not depend on the actual hardware, but on the constant definitions in the same file. They need to be updated if the hardware changes. I'll try to rewrite it in a cleaner way.
Signature · 2 lines
Thanks. -- Max
Mark Brown
maintainerQuoted 10 lines · Max Filippov
Quoted 5 lines · Mark Brown
You *really* need to explain how it's supposed to work - right now it's not at all obvious, like I say the fact that this is a rarely used idiom is not helping. For example when we tear down the stream we just assign the pointer in
_stop()but don't bother with a sync until the stream is closed - why?Because we can't wait in stop and syncing is not time critical, we can do it any time before the stream becomes invalid.
To be clear: the important part is that someone reading the code can understand what's going on.
Quoted 11 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
it'd be better to just add a DMA controller on the FPGA, everyone will be much happier).
Hardware people think different and it's been like that for more than 5 years.
They appear to be the only hardware people who think this way, while we
The whole audio subsystem on xtfpga boards is there for, I think, a single
purpose: for the demonstration of CPU audio processing capabilities. That's why it's that simple.
This means that the demos include cycles spent taking interrupts and stuffing data into the FIFO (with associated cache impacts) instead of signal processing which isn't usually helpful for benchmarks.
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
hw_paramscallback can change MCLK rate, so it has to disable and enable the clock anyway, and since enable can fail it does not guarantee that the clock will be left in the same state. Or should I adjust MCLK rate w/o disabling the clock?So yet again: why not just enable the clock only when the device is in use? If it's being configured it stands to reason that the device isn't actively in use...
Mark, I don't get it, sorry ): My clock synthesizer is I2C controlled, so I can't prepare/unprepare it in the trigger callback. When should I do it?
Runtime PM is the normal way of doing it.
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
The level field in the control register is 4 bit wide, so the allowed range of level is 0..15. FIFO size is 8192 entries, level = 1 corresponds to FIFO size / 2, level = 14 -- to FIFO size of 0. I guess this function won't get
period_sizeof 0?So if the IP gets changed and the code gets blown up this could well explode then... which doesn't seem entirely unlikely considering this is a FPGA platform so presumably this is easy to update. To repeat this is about clarity and the code looking like it's probably hiding bugs as much as if the code actually works if you really sit down and study it.
Quoted 3 lines
The calculation does not depend on the actual hardware, but on the constant definitions in the same file. They need to be updated if the hardware changes. I'll try to rewrite it in a cleaner way.
Right, my point is that if someone changes the hardware they'll just update the constants and then things will break.
Max Filippov
maintainerQuoted 9 lines · Mark Brown
Quoted 7 lines · Max Filippov
Quoted 5 lines · Mark Brown
You *really* need to explain how it's supposed to work - right now it's not at all obvious, like I say the fact that this is a rarely used idiom is not helping. For example when we tear down the stream we just assign the pointer in
_stop()but don't bother with a sync until the stream is closed - why?
Quoted 5 lines
Quoted 2 lines
Because we can't wait in stop and syncing is not time critical, we can do it any time before the stream becomes invalid.
To be clear: the important part is that someone reading the code can understand what's going on.
Ok, I'll change it.
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw_paramscallback can change MCLK rate, so it has to disable and enable the clock anyway, and since enable can fail it does not guarantee that the clock will be left in the same state. Or should I adjust MCLK rate w/o disabling the clock?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
So yet again: why not just enable the clock only when the device is in use? If it's being configured it stands to reason that the device isn't actively in use...
Mark, I don't get it, sorry ): My clock synthesizer is I2C controlled, so I can't prepare/unprepare it in the trigger callback. When should I do it?
Runtime PM is the normal way of doing it.
Ok, thanks.
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
The level field in the control register is 4 bit wide, so the allowed range of level is 0..15. FIFO size is 8192 entries, level = 1 corresponds to FIFO size / 2, level = 14 -- to FIFO size of 0. I guess this function won't get
period_sizeof 0?So if the IP gets changed and the code gets blown up this could well explode then... which doesn't seem entirely unlikely considering this is a FPGA platform so presumably this is easy to update. To repeat this is about clarity and the code looking like it's probably hiding bugs as much as if the code actually works if you really sit down and study it.
Quoted 6 lines
Quoted 3 lines
The calculation does not depend on the actual hardware, but on the constant definitions in the same file. They need to be updated if the hardware changes. I'll try to rewrite it in a cleaner way.
Right, my point is that if someone changes the hardware they'll just update the constants and then things will break.
Ok, I've rewritten it in a safer manner.
Signature · 2 lines
Thanks. -- Max
Max Filippov
maintainerQuoted 10 lines · Mark Brown
Quoted 8 lines · Max Filippov
Quoted 7 lines · Mark Brown
Quoted 7 lines
Quoted 4 lines
I would also expect to see the data transfer and I2S bits more split out, presumably this IP can actually be used in designs with a DMA controller and one would expect that for practical systems this would be the common case?
I don't know of other designs that use this IP block. Can we do it when we get such users?
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
It's also about ensuring that the code is cleanly split up so that someone can actually go in and add the required support later (and TBH
Can you point me to an example of such split, so that I don't write it in an unusual way?
Essentially all drivers are split this way...
But all of them have DMA registers and I2S registers completely separated, right? How do I share registers between pcm and i2s parts?
Signature · 2 lines
Thanks. -- Max
Mark Brown
maintainerQuoted 6 lines · Max Filippov
Quoted 4 lines · Mark Brown
Quoted 2 lines · Max Filippov
Quoted 2 lines
It's also about ensuring that the code is cleanly split up so that someone can actually go in and add the required support later (and TBH
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Can you point me to an example of such split, so that I don't write it in an unusual way?
Essentially all drivers are split this way...
But all of them have DMA registers and I2S registers completely separated, right? How do I share registers between pcm and i2s parts?
Just keep the code physically separate so the DMA bits are hanging off the DMA operations and the interface setup bits are hanging off the DAI operations rather than all mixed in together.
Max Filippov
maintainerQuoted 10 lines · Mark Brown
Quoted 8 lines · Max Filippov
Quoted 7 lines · Mark Brown
Quoted 5 lines · Max Filippov
Quoted 2 lines
It's also about ensuring that the code is cleanly split up so that someone can actually go in and add the required support later (and TBH
Can you point me to an example of such split, so that I don't write it in an unusual way?
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Essentially all drivers are split this way...
But all of them have DMA registers and I2S registers completely separated, right? How do I share registers between pcm and i2s parts?
Just keep the code physically separate so the DMA bits are hanging off the DMA operations and the interface setup bits are hanging off the DAI operations rather than all mixed in together.
Ok. Should I also move them to a separate file, or one file is good for now?
Signature · 2 lines
Thanks. -- Max
Mark Brown
maintainerQuoted 7 lines · Max Filippov
Quoted 3 lines · Mark Brown
Just keep the code physically separate so the DMA bits are hanging off the DMA operations and the interface setup bits are hanging off the DAI operations rather than all mixed in together.
Ok. Should I also move them to a separate file, or one file is good for now?
It's probably not essential to split at this point.