Add Cadence I2S-MC controller driver
Subsystems (3)
v2 cover Add Cadence I2S-MC controller driver
The Cadence Multi-channel I2S (I2S-MC) Controller implements a function of the multi-channel (up to 8-channel) bus. Each stereo channel combines functions of a transmitter and a receiver, and can switch freely between them. Each channel has independent gating, clock and interruption control. It also support some of these channels are used as playback and others can also be used as record in the same time.
Four I2S controllers are used on the StarFive JH8100 SoC. Two of the I2S controllers use two stereo channels, one of them use four channels, and one use eight. It had tested on the fpga with WM8960 and PDM.
Changes since v1:
- Added new compatible for StarFive JH8100 SoC and a special property to be got as the max channels number in the bindings.
- Dropped the useless '|' in the bindings.
- Moved the drivers to a new folder named 'cdns' and modified the name of functions.
v1: https://lore.kernel.org/all/[email protected]/
Xingyu Wu (2):
ASoC: dt-bindings: Add bindings for Cadence I2S-MC controller
ASoC: cdns: Add drivers of Cadence Multi-Channel I2S Controller
.../bindings/sound/cdns,i2s-mc.yaml | 110 +++ MAINTAINERS | 6 + sound/soc/Kconfig | 1 + sound/soc/Makefile | 1 + sound/soc/cdns/Kconfig | 18 + sound/soc/cdns/Makefile | 3 + sound/soc/cdns/cdns-i2s-mc-pcm.c | 262 +++++++ sound/soc/cdns/cdns-i2s-mc.c | 724 ++++++++++++++++++ sound/soc/cdns/cdns-i2s-mc.h | 157 ++++ 9 files changed, 1282 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml create mode 100644 sound/soc/cdns/Kconfig create mode 100644 sound/soc/cdns/Makefile create mode 100644 sound/soc/cdns/cdns-i2s-mc-pcm.c create mode 100644 sound/soc/cdns/cdns-i2s-mc.c create mode 100644 sound/soc/cdns/cdns-i2s-mc.h
Signature · 1 line
2.25.1
PATCH v2 1/2 ASoC: dt-bindings: Add bindings for Cadence I2S-MC controller
Add bindings for the Multi-Channel I2S controller of Cadence.
The Multi-Channel I2S (I2S-MC) implements a function of the 8-channel I2S bus interfasce. Each channel can become receiver or transmitter. Four I2S instances are used on the StarFive JH8100 SoC. One instance of them is limited to 2 channels, two instance are limited to 4 channels, and the other one can use most 8 channels. Add a unique property about 'starfive,i2s-max-channels' to distinguish each instance.
--- .../bindings/sound/cdns,i2s-mc.yaml | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +110 -0
@@ -0,0 +1,110 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/cdns,i2s-mc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Cadence multi-channel I2S controller + +description: + The Cadence I2S Controller implements a function of the multi-channel + (up to 8-channel) bus. It combines functions of a transmitter and a receiver. + +maintainers: + - Xingyu Wu <[email protected]> + +properties: + compatible: + enum: + - cdns,i2s-mc + - starfive,jh8100-i2s + + reg: + maxItems: 1 + + interrupts: + description: + The interrupt line number for the I2S controller. Add this + parameter if the I2S controller that you are using does not + using DMA. + maxItems: 1 + + clocks: + items: + - description: Bit clock + - description: Main ICG clock + - description: Inner master clock + + clock-names: + items: + - const: bclk + - const: icg + - const: mclk_inner + + resets: + maxItems: 1 + + dmas: + items: + - description: TX DMA Channel + - description: RX DMA Channel + minItems: 1 + + dma-names: + items: + - const: tx + - const: rx + minItems: 1 + + "#sound-dai-cells": + const: 0 + +allOf: + - $ref: dai-common.yaml# + - if: + properties: + compatible: + contains: + const: starfive,jh8100-i2s + then: + properties: + starfive,i2s-max-channels: + description: + Number of I2S max stereo channels supported on the StarFive + JH8100 SoC. + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [2, 4, 8] + required: + - starfive,i2s-max-channels + +required: + - compatible + - reg + - clocks + - clock-names + - resets + +oneOf: + - required: + - dmas + - dma-names + - required: + - interrupts + +unevaluatedProperties: false + +examples: + - | + i2s@122b0000 { + compatible = "cdns,i2s-mc"; + reg = <0x122b0000 0x1000>; + clocks = <&syscrg_ne 133>, + <&syscrg_ne 170>, + <&syscrg 50>; + clock-names = "bclk", "icg", + "mclk_inner"; + resets = <&syscrg_ne 43>; + dmas = <&dma 7>, <&dma 6>; + dma-names = "tx", "rx"; + #sound-dai-cells = <0>; + };
Signature · 1 line
2.25.1
Re: [PATCH v2 1/2] ASoC: dt-bindings: Add bindings for Cadence I2S-MC controller
Quoted 31 lines · Xingyu Wu
Add bindings for the Multi-Channel I2S controller of Cadence.
The Multi-Channel I2S (I2S-MC) implements a function of the 8-channel I2S bus interfasce. Each channel can become receiver or transmitter. Four I2S instances are used on the StarFive JH8100 SoC. One instance of them is limited to 2 channels, two instance are limited to 4 channels, and the other one can use most 8 channels. Add a unique property about 'starfive,i2s-max-channels' to distinguish each instance.
Signed-off-by Xingyu Wu <[email protected]>--- .../bindings/sound/cdns,i2s-mc.yaml | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Documentation/devicetree/bindings/sound/cdns,i2s-mc.yamlDocumentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +9
-0@@ -0,0 +1,110 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/cdns,i2s-mc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Cadence multi-channel I2S controller + +description:
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 19
Quoted 10 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +10
-0+ The Cadence I2S Controller implements a function of the multi-channel + (up to 8-channel) bus. It combines functions of a transmitter and a receiver. + +maintainers: + - Xingyu Wu <[email protected]> + +properties: + compatible: + enum: + - cdns,i2s-mc
Why did this appear? Who asked for this? Usually these blocks are not usable on their own.
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 29
Quoted 10 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +10
-0+ - starfive,jh8100-i2s + + reg: + maxItems: 1 + + interrupts: + description: + The interrupt line number for the I2S controller. Add this + parameter if the I2S controller that you are using does not + using DMA.
That's still wrong. You already got comment on this. Either you have interrupt or not. You do not add interrupts, based on your choice or not of having DMA. Drop the comment.
Quoted 36 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +36
-0+ maxItems: 1 + + clocks: + items: + - description: Bit clock + - description: Main ICG clock + - description: Inner master clock + + clock-names: + items: + - const: bclk + - const: icg + - const: mclk_inner + + resets: + maxItems: 1 + + dmas: + items: + - description: TX DMA Channel + - description: RX DMA Channel + minItems: 1 + + dma-names: + items: + - const: tx + - const: rx + minItems: 1 + + "#sound-dai-cells": + const: 0 + +allOf: + - $ref: dai-common.yaml# + - if: + properties:
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 75
Quoted 10 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +10
-0+ compatible: + contains: + const: starfive,jh8100-i2s + then: + properties: + starfive,i2s-max-channels: + description: + Number of I2S max stereo channels supported on the StarFive + JH8100 SoC. + $ref: /schemas/types.yaml#/definitions/uint32
Properties must be defined in top-level. You can disallow the property for other variants, but I claim you won't have here other variants.
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 80
Quoted 5 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +5
-0+ enum: [2, 4, 8] + required: + - starfive,i2s-max-channels + +required:
required goes after properties.
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 92
Quoted 12 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +12
-0+ - compatible + - reg + - clocks + - clock-names + - resets + +oneOf: + - required: + - dmas + - dma-names + - required: + - interrupts
This won't work. Provide both interrupts and dmas, and then test your DTS.
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 95
Quoted 3 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +3
-0+ +unevaluatedProperties: false +
Best regards,
Krzysztof
回复: [PATCH v2 1/2] ASoC: dt-bindings: Add bindings for Cadence I2S-MC controller
Quoted 40 lines · Xingyu Wu
Quoted 38 lines
Add bindings for the Multi-Channel I2S controller of Cadence.
The Multi-Channel I2S (I2S-MC) implements a function of the 8-channel I2S bus interfasce. Each channel can become receiver or transmitter. Four I2S instances are used on the StarFive
JH8100 SoC. One instance of them is limited to 2 channels, two instance are limited to 4 channels, and the other one can use most 8 channels. Add a unique property about 'starfive,i2s-max-channels' to distinguish each instance.Signed-off-by Xingyu Wu <[email protected]>--- .../bindings/sound/cdns,i2s-mc.yaml | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yamlDocumentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +14
-0@@ -0,0 +1,110 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) %YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/cdns,i2s-mc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Cadence multi-channel I2S controller + +description: + The Cadence I2S Controller implements a function of the +multi-channel + (up to 8-channel) bus. It combines functions of a transmitter and a receiver. + +maintainers: + - Xingyu Wu <[email protected]>
Quoted 8 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 19
Quoted 5 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +5
-0+ +properties: + compatible: + enum: + - cdns,i2s-mcWhy did this appear? Who asked for this? Usually these blocks are not usable on their own.
I wonder if I should keep the original IP compatible. Do I not need it?
Quoted 15 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 29
Quoted 11 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +10
-0+ - starfive,jh8100-i2s + + reg: + maxItems: 1 + + interrupts: + description: + The interrupt line number for the I2S controller. Add this + parameter if the I2S controller that you are using does not + using DMA.That's still wrong. You already got comment on this. Either you have interrupt or not. You do not add interrupts, based on your choice or not of having DMA. Drop the comment.
Do I keep this property and drop this description?
Quoted 51 lines
Quoted 37 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +36
-0+ maxItems: 1 + + clocks: + items: + - description: Bit clock + - description: Main ICG clock + - description: Inner master clock + + clock-names: + items: + - const: bclk + - const: icg + - const: mclk_inner + + resets: + maxItems: 1 + + dmas: + items: + - description: TX DMA Channel + - description: RX DMA Channel + minItems: 1 + + dma-names: + items: + - const: tx + - const: rx + minItems: 1 + + "#sound-dai-cells": + const: 0 + +allOf: + - $ref: dai-common.yaml# + - if: + properties:Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 75
Quoted 10 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +10
-0+ compatible: + contains: + const: starfive,jh8100-i2s + then: + properties: + starfive,i2s-max-channels: + description: + Number of I2S max stereo channels supported on the StarFive + JH8100 SoC. + $ref: /schemas/types.yaml#/definitions/uint32Properties must be defined in top-level. You can disallow the property for other variants, but I claim you won't have here other variants.
Quoted 3 lines
https://elixir.bootlin.com/linux/v5.19/source/Documentation/devicetree/bindings/e
xample-schema.yaml#L212
Will fix.
Quoted 8 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 80
Quoted 6 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +5
-0+ enum: [2, 4, 8] + required: + - starfive,i2s-max-channels + +required:required goes after properties.
Will fix.
Quoted 15 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 92
Quoted 13 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +12
-0+ - compatible + - reg + - clocks + - clock-names + - resets + +oneOf: + - required: + - dmas + - dma-names + - required: + - interruptsThis won't work. Provide both interrupts and dmas, and then test your DTS.
I provided both properties in the DTS and test by dtbs_check. Then it printed that:
'More than one condition true in one of shema: ...'
Quoted 7 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 95
Quoted 4 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +3
-0+ +unevaluatedProperties: false +Best regards,
Krzysztof
Best regards,
Xingyu Wu
Re: 回复: [PATCH v2 1/2] ASoC: dt-bindings: Add bindings for Cadence I2S-MC controller
Quoted 3 lines · Xingyu Wu
Quoted 3 lines · Xingyu Wu
Quoted 1 line
Add bindings for the Multi-Channel I2S controller of Cadence.
Your email app responds very weird. You bypassed all possible filters and it is simply not visible that you answer to me. You Reply to everyone, not to me with Cc to others. There is no standard header whom do you quote, e.g. "On 26/03/2024 07:29, Xingyu Wu wrote:"
Please use some decent email system, otherwise I will miss all replies from you.
Quoted 10 lines
Quoted 8 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 19
Quoted 5 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +5
-0+ +properties: + compatible: + enum: + - cdns,i2s-mcWhy did this appear? Who asked for this? Usually these blocks are not usable on their own.
I wonder if I should keep the original IP compatible. Do I not need it?
As I said, it is not usable on its own, so unless you have other arguments then no. But my point was that no one asked for this.
Quoted 17 lines
Quoted 16 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 29
Quoted 12 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +10
-0+ - starfive,jh8100-i2s + + reg: + maxItems: 1 + + interrupts: + description: + The interrupt line number for the I2S controller. Add this + parameter if the I2S controller that you are using does not + using DMA.That's still wrong. You already got comment on this. Either you have interrupt or not. You do not add interrupts, based on your choice or not of having DMA. Drop the comment.
Quoted 1 line
Do I keep this property and drop this description?
Drop description. Keep property, if your hardware has interrupts.
...
Quoted 16 lines
Quoted 15 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 92
Quoted 13 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +12
-0+ - compatible + - reg + - clocks + - clock-names + - resets + +oneOf: + - required: + - dmas + - dma-names + - required: + - interruptsThis won't work. Provide both interrupts and dmas, and then test your DTS.
Quoted 2 lines
I provided both properties in the DTS and test by
dtbs_check. Then it printed that:
'More than one condition true in one of shema: ...'
Exactly. Having both properties is a correct DTS. Interrupts do not disappear just because you decide to describe DMA. It is OS choice what to use if both are provided.
Best regards,
Krzysztof
RE: 回复: [PATCH v2 1/2] ASoC: dt-bindings: Add bindings for Cadence I2S-MC controller
Quoted 4 lines · Krzysztof Kozlowski
Quoted 2 lines · Xingyu Wu
Quoted 2 lines · Xingyu Wu
Quoted 8 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Add bindings for the Multi-Channel I2S controller of Cadence.
Your email app responds very weird. You bypassed all possible filters and it is simply not visible that you answer to me. You Reply to everyone, not to me with Cc to others. There is no standard header whom do you quote, e.g. "On 26/03/2024 07:29, Xingyu Wu wrote:"
Please use some decent email system, otherwise I will miss all replies from you.
Thank you for reminding me. I will correct it.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 19
Quoted 6 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +5
-0+ +properties: + compatible: + enum: + - cdns,i2s-mcWhy did this appear? Who asked for this? Usually these blocks are not usable on their own.
Quoted 4 lines
Quoted 1 line
I wonder if I should keep the original IP compatible. Do I not need it?
As I said, it is not usable on its own, so unless you have other arguments then no. But my point was that no one asked for this.
I want to keep the original IP compatible which can distinguish from the JH8100 SoC. Can I write it like this:
compatible:
enum:
- starfive,jh8100-i2s
const: cdns,i2s-mc
and I write this in the DTS:
compatible = "starfive,jh8100-i2s", "cdns,i2s-mc";
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 29
Quoted 13 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +10
-0+ - starfive,jh8100-i2s + + reg: + maxItems: 1 + + interrupts: + description: + The interrupt line number for the I2S controller. Add this + parameter if the I2S controller that you are using does not + using DMA.That's still wrong. You already got comment on this. Either you have interrupt
Quoted 8 lines
or not.
Quoted 4 lines
Quoted 2 lines
You do not add interrupts, based on your choice or not of having DMA. Drop the comment.
Do I keep this property and drop this description?
Drop description. Keep property, if your hardware has interrupts.
Will drop.
Quoted 18 lines
...
Quoted 16 lines
Quoted 15 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 92
Quoted 13 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +12
-0+ - compatible + - reg + - clocks + - clock-names + - resets + +oneOf: + - required: + - dmas + - dma-names + - required: + - interruptsThis won't work. Provide both interrupts and dmas, and then test your DTS.
Quoted 8 lines
Quoted 1 line
I provided both properties in the DTS and test by
dtbs_check. Then it printedthat:
Quoted 1 line
'More than one condition true in one of shema: ...'
Exactly. Having both properties is a correct DTS. Interrupts do not disappear just because you decide to describe DMA. It is OS choice what to use if both are provided.
But this I2S can only use either DMA or interrupts.
Can I use the config (like SND_SOC_CADENCE_I2S_MC_PCM) to choose DMA or interrupt if having both them in DTS?
Best regards,
Xingyu Wu
Re: 回复: [PATCH v2 1/2] ASoC: dt-bindings: Add bindings for Cadence I2S-MC controller
Quoted 21 lines · Xingyu Wu
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 19
Quoted 5 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +5
-0+ +properties: + compatible: + enum: + - cdns,i2s-mcWhy did this appear? Who asked for this? Usually these blocks are not usable on their own.
Quoted 4 lines
Quoted 1 line
I wonder if I should keep the original IP compatible. Do I not need it?
As I said, it is not usable on its own, so unless you have other arguments then no. But my point was that no one asked for this.
I want to keep the original IP compatible which can distinguish from the JH8100 SoC. Can I write it like this:
compatible:
enum:
- starfive,jh8100-i2s
const: cdns,i2s-mc
Quoted 2 lines
and I write this in the DTS:
compatible = "starfive,jh8100-i2s", "cdns,i2s-mc";
Can you provide any rationale for this? I asked "unless you have other arguments", so where are the arguments?
Nothing was explained in patch changelog. Nothing was provided in this email thread.
Quoted 47 lines
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +4
-0+ - starfive,jh8100-i2s + + reg: + maxItems: 1Quoted 8 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 29
Quoted 6 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +6
-0+ + interrupts: + description: + The interrupt line number for the I2S controller. Add this + parameter if the I2S controller that you are using does not + using DMA.That's still wrong. You already got comment on this. Either you have interrupt
Quoted 8 lines
or not.
Quoted 4 lines
Quoted 2 lines
You do not add interrupts, based on your choice or not of having DMA. Drop the comment.
Do I keep this property and drop this description?
Drop description. Keep property, if your hardware has interrupts.
Will drop.
Quoted 20 lines
...
Quoted 16 lines
Quoted 15 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 92
Quoted 13 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +12
-0+ - compatible + - reg + - clocks + - clock-names + - resets + +oneOf: + - required: + - dmas + - dma-names + - required: + - interruptsThis won't work. Provide both interrupts and dmas, and then test your DTS.
Quoted 1 line
I provided both properties in the DTS and test by
dtbs_check. Then it printedthat:
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
'More than one condition true in one of shema: ...'
Exactly. Having both properties is a correct DTS. Interrupts do not disappear just because you decide to describe DMA. It is OS choice what to use if both are provided.
But this I2S can only use either DMA or interrupts.
Just like many other components. DTS should reflect hardware. Hardware has interrupts and DMA, right?
Quoted 3 lines
Can I use the config (like
SND_SOC_CADENCE_I2S_MC_PCM) to choose DMA or interrupt if having both them in DTS?
Don't know, I tend to focus here on bindings.
Best regards,
Krzysztof
RE: 回复: [PATCH v2 1/2] ASoC: dt-bindings: Add bindings for Cadence I2S-MC controller
Quoted 24 lines · Krzysztof Kozlowski
Quoted 9 lines · Xingyu Wu
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 19
Quoted 5 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +5
-0+ +properties: + compatible: + enum: + - cdns,i2s-mcWhy did this appear? Who asked for this? Usually these blocks are not usable on their own.
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
I wonder if I should keep the original IP compatible. Do I not need it?
As I said, it is not usable on its own, so unless you have other arguments then
no.
Quoted 3 lines
Quoted 1 line
But my point was that no one asked for this.
I want to keep the original IP compatible which can distinguish from the JH8100
SoC.
Quoted 6 lines
Can I write it like this:
compatible:
enum:
- starfive,jh8100-i2s
const: cdns,i2s-mc
Quoted 8 lines
Quoted 2 lines
and I write this in the DTS:
compatible = "starfive,jh8100-i2s", "cdns,i2s-mc";Can you provide any rationale for this? I asked "unless you have other arguments", so where are the arguments?
Nothing was explained in patch changelog. Nothing was provided in this email thread.
I don't know if I understood what mark said[1]. Is it to keep the original IP and add other compatible?
[1] https://lore.kernel.org/all/[email protected]/
Or should I only keep the compatible 'starfive,jh8110-i2s' and change the bindings name to same to this compatible?
Quoted 57 lines
Quoted 57 lines
Quoted 18 lines
Quoted 5 lines
Quoted 5 lines
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +5
-0+ - starfive,jh8100-i2s + + reg: + maxItems: 1 +Quoted 8 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 29
Quoted 5 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +5
-0+ interrupts: + description: + The interrupt line number for the I2S controller. Add this + parameter if the I2S controller that you are using does not + using DMA.That's still wrong. You already got comment on this. Either you have interrupt
Quoted 8 lines
or not.
Quoted 4 lines
Quoted 2 lines
You do not add interrupts, based on your choice or not of having DMA. Drop the comment.
Do I keep this property and drop this description?
Drop description. Keep property, if your hardware has interrupts.
Will drop.
Quoted 27 lines
...
Quoted 16 lines
Quoted 15 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml line 92
Quoted 13 lines
Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml new file +12
-0+ - compatible + - reg + - clocks + - clock-names + - resets + +oneOf: + - required: + - dmas + - dma-names + - required: + - interruptsThis won't work. Provide both interrupts and dmas, and then test your DTS.
Quoted 2 lines
I provided both properties in the DTS and test by
dtbs_check. Then it printedthat:
Quoted 1 line
'More than one condition true in one of shema: ...'
Exactly. Having both properties is a correct DTS. Interrupts do not disappear just because you decide to describe DMA. It is OS choice what to use if both are provided.
Quoted 4 lines
Quoted 1 line
But this I2S can only use either DMA or interrupts.
Just like many other components. DTS should reflect hardware. Hardware has interrupts and DMA, right?
Yes. The hardware can use interrupts and provide the handshake interface of DMA to DMA controller. In software, we can choose only one between them. Do I keep them both in the bindings and provide the selection in the driver?
Quoted 7 lines
Quoted 4 lines
Can I use the config (like
SND_SOC_CADENCE_I2S_MC_PCM) to choose DMA or interrupt if having both them in DTS?Don't know, I tend to focus here on bindings.
Best regards,
Xingyu Wu
Re: 回复: [PATCH v2 1/2] ASoC: dt-bindings: Add bindings for Cadence I2S-MC controller
Quoted 14 lines · Xingyu Wu
Quoted 14 lines
Quoted 1 line
I want to keep the original IP compatible which can distinguish from the JH8100
SoC.
Quoted 8 lines
Can I write it like this:
compatible:
enum:
- starfive,jh8100-i2s
const: cdns,i2s-mcand I write this in the DTS:
compatible = "starfive,jh8100-i2s", "cdns,i2s-mc";Can you provide any rationale for this? I asked "unless you have other arguments", so where are the arguments?
Quoted 8 lines
Quoted 2 lines
Nothing was explained in patch changelog. Nothing was provided in this email thread.
I don't know if I understood what mark said[1]. Is it to keep the original IP and add other compatible?
I stated and I keep my statement that such block is usually not usable on its own and always needs some sort of quirks or SoC-specific implementation. At least this is what I saw in other similar cases, but not exactly I2S.
Therefore I think fallback is not usable here, thus please use only starfive compatible. Drop the fallback. It could be added in the future if I am proven wrong. If you think that fallback is usable alone, please bring some real life case.
Quoted 2 lines
Or should I only keep the compatible 'starfive,jh8110-i2s' and change the bindings name to same to this compatible?
Filename could be cdns,i2s-mc.yaml, assuming that's the name of original IP block.
...
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
But this I2S can only use either DMA or interrupts.
Just like many other components. DTS should reflect hardware. Hardware has interrupts and DMA, right?
Yes. The hardware can use interrupts and provide the handshake interface of DMA to DMA controller. In software, we can choose only one between them. Do I keep them both in the bindings and provide the selection in the driver?
Yes.
Best regards,
Krzysztof
Mark Brown
maintainerRe: 回复: [PATCH v2 1/2] ASoC: dt-bindings: Add bindings for Cadence I2S-MC controller
Quoted 4 lines · Krzysztof Kozlowski
I stated and I keep my statement that such block is usually not usable on its own and always needs some sort of quirks or SoC-specific implementation. At least this is what I saw in other similar cases, but not exactly I2S.
I wouldn't be so pessimistic, especially not for I2S - a good portion of quirks there are extra features rather than things needed for basic operation, a lot of things that might in the past have been quirks for basic operation are these days hidden behind the DT bindings.
Re: 回复: [PATCH v2 1/2] ASoC: dt-bindings: Add bindings for Cadence I2S-MC controller
Quoted 11 lines · Mark Brown
Quoted 4 lines · Krzysztof Kozlowski
I stated and I keep my statement that such block is usually not usable on its own and always needs some sort of quirks or SoC-specific implementation. At least this is what I saw in other similar cases, but not exactly I2S.
I wouldn't be so pessimistic, especially not for I2S - a good portion of quirks there are extra features rather than things needed for basic operation, a lot of things that might in the past have been quirks for basic operation are these days hidden behind the DT bindings.
OK, I trust your judgement, so cdns as fallback seems okay, but I don't think it warrants cdns as used alone. Not particularly because cdns is different, but because we expect specific SoC compatible always.
Thus if cdns,i2s-mc stays, then:
items:
- enum:
- starfive,jh8100-i2s
- cdns,i2s-mc
Best regards,
Krzysztof
RE: 回复: [PATCH v2 1/2] ASoC: dt-bindings: Add bindings for Cadence I2S-MC controller
Quoted 18 lines · Krzysztof Kozlowski
Quoted 11 lines · Mark Brown
Quoted 4 lines · Krzysztof Kozlowski
I stated and I keep my statement that such block is usually not usable on its own and always needs some sort of quirks or SoC-specific implementation. At least this is what I saw in other similar cases, but not exactly I2S.
I wouldn't be so pessimistic, especially not for I2S - a good portion of quirks there are extra features rather than things needed for basic operation, a lot of things that might in the past have been quirks for basic operation are these days hidden behind the DT bindings.
OK, I trust your judgement, so cdns as fallback seems okay, but I don't think it warrants cdns as used alone. Not particularly because cdns is different, but because we expect specific SoC compatible always.
Quoted 7 lines
Thus if cdns,i2s-mc stays, then:
items:
- enum:
- starfive,jh8100-i2s
- cdns,i2s-mc
OK, thanks Krzysztof and Mark. I will modify it in next patch.
Best regards,
Xingyu Wu
PATCH v2 2/2 ASoC: cdns: Add drivers of Cadence Multi-Channel I2S Controller
In reply to Xingyu WuAdd the drivers of Cadence Multi-Channel I2S Controller.
The Cadence I2S Controller implements a function of the multi-channel (up to 8-channel) bus. Each stereo channel combines functions of a transmitter and a receiver. Each channel has independent and internal gating, clock and interruption control. It alos support some of these channels are used as playback and others can also be used as record in the same time.
The I2S-MC is used on the StarFive JH8100 SoC and add the compatible for this.
--- MAINTAINERS | 6 + sound/soc/Kconfig | 1 + sound/soc/Makefile | 1 + sound/soc/cdns/Kconfig | 18 + sound/soc/cdns/Makefile | 3 + sound/soc/cdns/cdns-i2s-mc-pcm.c | 262 +++++++++++ sound/soc/cdns/cdns-i2s-mc.c | 724 +++++++++++++++++++++++++++++++ sound/soc/cdns/cdns-i2s-mc.h | 157 +++++++ 8 files changed, 1172 insertions(+) create mode 100644 sound/soc/cdns/Kconfig create mode 100644 sound/soc/cdns/Makefile create mode 100644 sound/soc/cdns/cdns-i2s-mc-pcm.c create mode 100644 sound/soc/cdns/cdns-i2s-mc.c create mode 100644 sound/soc/cdns/cdns-i2s-mc.h
MAINTAINERS +6 -0
@@ -4560,6 +4560,12 @@ L: [email protected] S: Maintained F: tools/testing/selftests/cachestat/test_cachestat.c +CADENCE MULTI CHANNEL I2S CONTROLLER DRIVER +M: Xingyu Wu <[email protected]> +S: Supported +F: Documentation/devicetree/bindings/sound/cdns,i2s-mc.yaml +F: sound/soc/cdns/cdns-i2s-mc* + CADENCE MIPI-CSI2 BRIDGES M: Maxime Ripard <[email protected]> L: [email protected]
sound/soc/Kconfig +1 -0
@@ -83,6 +83,7 @@ source "sound/soc/apple/Kconfig" source "sound/soc/atmel/Kconfig" source "sound/soc/au1x/Kconfig" source "sound/soc/bcm/Kconfig" +source "sound/soc/cdns/Kconfig" source "sound/soc/cirrus/Kconfig" source "sound/soc/dwc/Kconfig" source "sound/soc/fsl/Kconfig"
sound/soc/Makefile +1 -0
@@ -40,6 +40,7 @@ obj-$(CONFIG_SND_SOC) += amd/ obj-$(CONFIG_SND_SOC) += atmel/ obj-$(CONFIG_SND_SOC) += au1x/ obj-$(CONFIG_SND_SOC) += bcm/ +obj-$(CONFIG_SND_SOC) += cdns/ obj-$(CONFIG_SND_SOC) += cirrus/ obj-$(CONFIG_SND_SOC) += dwc/ obj-$(CONFIG_SND_SOC) += fsl/
sound/soc/cdns/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0-only +config SND_SOC_CADENCE_I2S_MC + tristate "Cadence I2S Multi-Channel Controller Device Driver" + depends on HAVE_CLK + select SND_SOC_GENERIC_DMAENGINE_PCM + help + Say Y or M if you want to add support for I2S driver for the + Cadence Multi-Channel I2S Controller device. The device supports + up to a maximum of 8 channels each for play and record. + +config SND_SOC_CADENCE_I2S_MC_PCM + bool "PCM PIO extension for CDNS I2S MC driver" + depends on SND_SOC_CADENCE_I2S_MC + help + Say Y or N if you want to add a custom ALSA extension that registers + a PCM and uses PIO to transfer data. + This functionality is specially suited for CDNS I2S-MC devices that + don't use DMA controller.
sound/soc/cdns/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_SND_SOC_CADENCE_I2S_MC) += cdns-i2s.o +cdns-i2s-y := cdns-i2s-mc.o +cdns-i2s-$(CONFIG_SND_SOC_CADENCE_I2S_MC_PCM) += cdns-i2s-mc-pcm.o
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +262 -0
262 lines not on this page · raw message
sound/soc/cdns/cdns-i2s-mc.c new file +724 -0
724 lines not on this page · raw message
sound/soc/cdns/cdns-i2s-mc.h new file +157 -0
157 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] ASoC: cdns: Add drivers of Cadence Multi-Channel I2S Controller
sound/soc/cdns/Kconfig line 4
Quoted 11 lines
sound/soc/cdns/Kconfig new file +4
-0@@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0-only +config SND_SOC_CADENCE_I2S_MC + tristate "Cadence I2S Multi-Channel Controller Device Driver" + depends on HAVE_CLK
indentation is off
sound/soc/cdns/Kconfig
Quoted 11 lines
sound/soc/cdns/Kconfig new file +10
-0+ select SND_SOC_GENERIC_DMAENGINE_PCM + help + Say Y or M if you want to add support for I2S driver for the + Cadence Multi-Channel I2S Controller device. The device supports + up to a maximum of 8 channels each for play and record. +// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence Multi-Channel I2S controller PCM driver + * + * Copyright (c) 2022-2023 StarFive Technology Co., Ltd.
2024?
sound/soc/cdns/Kconfig
Quoted 9 lines
+ */
sound/soc/cdns/Kconfig new file +8
-0+ +#include <linux/io.h> +#include <linux/rcupdate.h> +#include <sound/pcm_params.h> +#include "cdns-i2s-mc.h" + +#define PERIOD_BYTES_MIN 4096 +#define BUFFER_BYTES_MAX (3 * 2 * 8 * PERIOD_BYTES_MIN)
what are those 3 and 2 and 8 factors? a comment or the use of macros would help.
sound/soc/cdns/Kconfig
Quoted 8 lines
sound/soc/cdns/Kconfig new file +8
-0+#define PERIODS_MIN 2 + +static unsigned int cdns_i2s_pcm_tx(struct cdns_i2s_dev *dev, + struct snd_pcm_runtime *runtime, + unsigned int tx_ptr, bool *period_elapsed, + snd_pcm_format_t format) +{ + unsigned int period_pos = tx_ptr % runtime->period_size;
not following what the modulo is for, usually it's modulo the buffer size?
sound/soc/cdns/Kconfig
Quoted 13 lines
sound/soc/cdns/Kconfig new file +13
-0+ const u16 (*p16)[2] = (void *)runtime->dma_area; + const u32 (*p32)[2] = (void *)runtime->dma_area; + u32 data[2]; + int i; + + for (i = 0; i < CDNS_I2S_FIFO_DEPTH; i++) { + if (format == SNDRV_PCM_FORMAT_S16_LE) { + data[0] = p16[tx_ptr][0]; + data[1] = p16[tx_ptr][1]; + } else if (format == SNDRV_PCM_FORMAT_S32_LE) { + data[0] = p32[tx_ptr][0]; + data[1] = p32[tx_ptr][1]; + }
what about other formats implied by the use of 'else if' ?
sound/soc/cdns/Kconfig
Quoted 13 lines
sound/soc/cdns/Kconfig new file +12
-0+ + iowrite32(data[0], dev->base + CDNS_FIFO_MEM); + iowrite32(data[1], dev->base + CDNS_FIFO_MEM); + period_pos++; + if (++tx_ptr >= runtime->buffer_size) + tx_ptr = 0; + } + + *period_elapsed = period_pos >= runtime->period_size; + return tx_ptr; +} +static void cdns_i2s_pcm_transfer(struct cdns_i2s_dev *dev, bool push)
'push' really means 'tx' so what not use a simpler naming?
Quoted 52 lines
sound/soc/cdns/Kconfig new file +52
-0+{ + struct snd_pcm_substream *substream; + bool active, period_elapsed; + + rcu_read_lock(); + if (push) + substream = rcu_dereference(dev->tx_substream); + else + substream = rcu_dereference(dev->rx_substream); + + active = substream && snd_pcm_running(substream); + if (active) { + unsigned int ptr; + unsigned int new_ptr; + + if (push) { + ptr = READ_ONCE(dev->tx_ptr); + new_ptr = dev->tx_fn(dev, substream->runtime, ptr, + &period_elapsed, dev->format); + cmpxchg(&dev->tx_ptr, ptr, new_ptr); + } else { + ptr = READ_ONCE(dev->rx_ptr); + new_ptr = dev->rx_fn(dev, substream->runtime, ptr, + &period_elapsed, dev->format); + cmpxchg(&dev->rx_ptr, ptr, new_ptr); + } + + if (period_elapsed) + snd_pcm_period_elapsed(substream); + } + rcu_read_unlock(); +} + +void cdns_i2s_pcm_push_tx(struct cdns_i2s_dev *dev) +{ + cdns_i2s_pcm_transfer(dev, true); +} + +void cdns_i2s_pcm_pop_rx(struct cdns_i2s_dev *dev) +{ + cdns_i2s_pcm_transfer(dev, false); +} + +static int cdns_i2s_pcm_open(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); + struct cdns_i2s_dev *dev = snd_soc_dai_get_drvdata(snd_soc_rtd_to_cpu(rtd, 0)); + + snd_soc_set_runtime_hwparams(substream, &cdns_i2s_pcm_hardware); + snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
sound/soc/cdns/Kconfig
Quoted 10 lines
sound/soc/cdns/Kconfig new file +10
-0+ runtime->private_data = dev; + + return 0; +} + +static int cdns_i2s_pcm_close(struct snd_soc_component *component, + struct snd_pcm_substream *substream) +{ + synchronize_rcu(); + return 0;
runtime->private_data = NULL?
sound/soc/cdns/Kconfig
Quoted 10 lines
sound/soc/cdns/Kconfig new file +10
-0+} + +static int cdns_i2s_pcm_hw_params(struct snd_soc_component *component, + struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + struct cdns_i2s_dev *dev = runtime->private_data; + + dev->format = params_format(hw_params);
don't you need to test if the formats are supported?
Quoted 12 lines
sound/soc/cdns/Kconfig new file +11
-0+ dev->tx_fn = cdns_i2s_pcm_tx; + dev->rx_fn = cdns_i2s_pcm_rx; + + return 0; +} +static int cdns_i2s_start(struct cdns_i2s_dev *i2s, + struct snd_pcm_substream *substream) +{ + struct snd_pcm_runtime *runtime = substream->runtime; + unsigned char max_ch = i2s->max_channels; + unsigned char i2s_ch;
sound/soc/cdns/Kconfig
Quoted 10 lines
sound/soc/cdns/Kconfig new file +10
-0+ int i; + + /* Each channel is stereo */ + i2s_ch = runtime->channels / 2; + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { + if ((i2s_ch + i2s->tx_using_channels) > max_ch) { + dev_err(i2s->dev, + "Max %d channels: using %d for TX, do not support %d for RX\n", + max_ch, i2s->tx_using_channels, i2s_ch); + return -ENOMEM;
ENOMEM is for memory allocation, that looks more like EINVAL?
Quoted 11 lines
sound/soc/cdns/Kconfig new file +11
-0+ } + + i2s->rx_using_channels = i2s_ch; + /* Enable channels from 0 to 'max_ch' as tx */ + for (i = 0; i < i2s_ch; i++) + cdns_i2s_channel_start(i2s, CDNS_I2S_CM_0 << i, + CDNS_I2S_TC_RECEIVER); + + } else { + if ((i2s_ch + i2s->rx_using_channels) > max_ch) { + dev_err(i2s->dev,
sound/soc/cdns/Kconfig
Quoted 10 lines
sound/soc/cdns/Kconfig new file +10
-0+ "Max %d channels: using %d for RX, do not support %d for TX\n", + max_ch, i2s->rx_using_channels, i2s_ch); + return -ENOMEM; + } + + i2s->tx_using_channels = i2s_ch; + /* Enable channels from 'max_ch' to 0 as rx */ + for (i = (max_ch - 1); i > (max_ch - i2s_ch - 1); i--) { + if (i < 0) + return -EINVAL;
that is a test you can probably factor out of the loop before doing anything that's inconsistent.
Quoted 26 lines
sound/soc/cdns/Kconfig new file +26
-0+ + cdns_i2s_channel_start(i2s, CDNS_I2S_CM_0 << i, + CDNS_I2S_TC_TRANSMITTER); + } + } + cdns_i2s_enable_clock(i2s, substream->stream); + + if (i2s->irq >= 0) + cdns_i2s_set_all_irq_mask(i2s, false); + + cdns_i2s_clear_int(i2s); + + return 0; +} + +static int cdns_i2s_stop(struct cdns_i2s_dev *i2s, + struct snd_pcm_substream *substream) +{ + unsigned char i2s_ch; + int i; + + cdns_i2s_clear_int(i2s); + + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { + i2s_ch = i2s->rx_using_channels; + for (i = 0; i < i2s_ch; i++)
sound/soc/cdns/Kconfig
Quoted 10 lines
sound/soc/cdns/Kconfig new file +10
-0+ cdns_i2s_channel_stop(i2s, (CDNS_I2S_CM_0 << i)); + + i2s->rx_using_channels = 0; + } else { + unsigned char max_ch = i2s->max_channels; + + i2s_ch = i2s->tx_using_channels; + for (i = (max_ch - 1); i > (max_ch - i2s_ch - 1); i--) { + if (i < 0) + return -EINVAL;
same here, first test if the channel maps are valid, then do the loop?
Quoted 22 lines
sound/soc/cdns/Kconfig new file +21
-0+ + cdns_i2s_channel_stop(i2s, (CDNS_I2S_CM_0 << i)); + } + + i2s->tx_using_channels = 0; + } + + if (i2s->irq >= 0 && !i2s->tx_using_channels && !i2s->rx_using_channels) + cdns_i2s_set_all_irq_mask(i2s, true); + + return 0; +} +static int cdns_i2s_set_fmt(struct snd_soc_dai *cpu_dai, + unsigned int fmt) +{ + struct cdns_i2s_dev *i2s = snd_soc_dai_get_drvdata(cpu_dai); + int ret = 0; + + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { + case SND_SOC_DAIFMT_CBM_CFM: + i2s->tx_sync_ms_mode = CDNS_I2S_MASTER_MODE;
sound/soc/cdns/Kconfig
Quoted 10 lines
sound/soc/cdns/Kconfig new file +10
-0+ i2s->rx_sync_ms_mode = CDNS_I2S_MASTER_MODE; + cdns_i2s_set_ms_mode(i2s); + break; + case SND_SOC_DAIFMT_CBS_CFS: + i2s->tx_sync_ms_mode = CDNS_I2S_SLAVE_MODE; + i2s->rx_sync_ms_mode = CDNS_I2S_SLAVE_MODE; + cdns_i2s_set_ms_mode(i2s); + break; + case SND_SOC_DAIFMT_CBM_CFS: + case SND_SOC_DAIFMT_CBS_CFM:
that's the old stuff, use CBP/CBC macros please.
sound/soc/cdns/Kconfig
Quoted 11 lines
sound/soc/cdns/Kconfig new file +10
-0+ ret = -EINVAL; + break; + default: + dev_dbg(i2s->dev, "Invalid master/slave format\n"); + ret = -EINVAL; + break; + } + return ret; +} +#ifdef CONFIG_PM
Do we need this or just rely on __unused?
Quoted 63 lines
sound/soc/cdns/Kconfig new file +62
-0+static int cdns_i2s_runtime_suspend(struct device *dev) +{ + struct cdns_i2s_dev *i2s = dev_get_drvdata(dev); + + clk_disable_unprepare(i2s->clks[1].clk); /* ICG clock */ + return 0; +} + +static int cdns_i2s_runtime_resume(struct device *dev) +{ + struct cdns_i2s_dev *i2s = dev_get_drvdata(dev); + + return clk_prepare_enable(i2s->clks[1].clk); /* ICG clock */ +} +#endif +static int cdns_i2s_probe(struct platform_device *pdev) +{ + struct cdns_i2s_dev *i2s; + struct resource *res; + int ret; + + i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); + if (!i2s) { + ret = -ENOMEM; + goto err; + } + platform_set_drvdata(pdev, i2s); + + i2s->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); + if (IS_ERR(i2s->base)) { + ret = PTR_ERR(i2s->base); + goto err; + } + + i2s->dev = &pdev->dev; + i2s->phybase = res->start; + + ret = cdns_i2s_init(i2s); + if (ret) + goto err; + + i2s->irq = platform_get_irq(pdev, 0); + if (i2s->irq >= 0) { + ret = devm_request_irq(&pdev->dev, i2s->irq, cdns_i2s_irq_handler, + 0, pdev->name, i2s); + if (ret < 0) { + dev_err(&pdev->dev, "request_irq failed\n"); + goto err; + } + } + + ret = devm_snd_soc_register_component(&pdev->dev, + &cdns_i2s_component, + &cdns_i2s_dai, 1); + if (ret < 0) { + dev_err(&pdev->dev, "couldn't register component\n"); + goto err; + } + + if (i2s->irq >= 0) + ret = cdns_i2s_pcm_register(pdev); + else
sound/soc/cdns/Kconfig
Quoted 10 lines
sound/soc/cdns/Kconfig new file +10
-0+ ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); + + if (ret) { + dev_err(&pdev->dev, "could not register pcm: %d\n", ret); + goto err; + } + + pm_runtime_enable(&pdev->dev); + if (pm_runtime_enabled(&pdev->dev)) + cdns_i2s_runtime_suspend(&pdev->dev);
that sequence looks suspicious.... Why would you suspend immediately during the probe? You're probably missing all the autosuspend stuff?
Quoted 5 lines
sound/soc/cdns/Kconfig new file +5
-0+ + dev_dbg(&pdev->dev, "I2S supports %d stereo channels with %s.\n", + i2s->max_channels, ((i2s->irq < 0) ? "dma" : "interrupt")); + + return 0;
sound/soc/cdns/Kconfig
Quoted 10 lines
sound/soc/cdns/Kconfig new file +10
-0+ +err: + return ret; +} + +static int cdns_i2s_remove(struct platform_device *pdev) +{ + pm_runtime_disable(&pdev->dev); + if (!pm_runtime_status_suspended(&pdev->dev)) + cdns_i2s_runtime_suspend(&pdev->dev);
... and this one too. Once you've disabled pm_runtime, checking the status is irrelevant...
Quoted 4 lines
sound/soc/cdns/Kconfig new file +4
-0+ + return 0; +} +
Mark Brown
maintainerRe: [PATCH v2 2/2] ASoC: cdns: Add drivers of Cadence Multi-Channel I2S Controller
Quoted 10 lines · Pierre-Louis Bossart
sound/soc/cdns/cdns-i2s-mc-pcm.c line 35
Quoted 8 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +8
-0+for (i =0 ; i <CDNS_I2S_FIFO_DEPTH ; i++) { +if (format ==SNDRV_PCM_FORMAT_S16_LE ) { + data[0 ] = p16[tx_ptr][0 ]; + data[1 ] = p16[tx_ptr][1 ]; + }else if (format ==SNDRV_PCM_FORMAT_S32_LE ) { + data[0 ] = p32[tx_ptr][0 ]; + data[1 ] = p32[tx_ptr][1 ]; + }what about other formats implied by the use of 'else if' ?
In general things like this should be written as switch statements.
回复: [PATCH v2 2/2] ASoC: cdns: Add drivers of Cadence Multi-Channel I2S Controller
Quoted 14 lines · Pierre-Louis Bossart
Quoted 11 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c line 35
Quoted 9 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +8
-0+for (i =0 ; i <CDNS_I2S_FIFO_DEPTH ; i++) { +if (format ==SNDRV_PCM_FORMAT_S16_LE ) { + data[0 ] = p16[tx_ptr][0 ]; + data[1 ] = p16[tx_ptr][1 ]; + }else if (format ==SNDRV_PCM_FORMAT_S32_LE ) { + data[0 ] = p32[tx_ptr][0 ]; + data[1 ] = p32[tx_ptr][1 ]; + }what about other formats implied by the use of 'else if' ?
Quoted 1 line
In general things like this should be written as switch statements.
OK, I will fix it in next version of this patch.
Thanks,
Xingyu Wu
回复: [PATCH v2 2/2] ASoC: cdns: Add drivers of Cadence Multi-Channel I2S Controller
In reply to Pierre-Louis BossartQuoted 10 lines
sound/soc/cdns/Kconfig line 3
Quoted 8 lines
sound/soc/cdns/Kconfig new file renamed from sound/soc/cdns/Kconfig +0
-0mode 100644 index 000000000000..61ef718ebfe7
sound/soc/cdns/Kconfig new file +3
-0@@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0-only config SND_SOC_CADENCE_I2S_MC + tristate "Cadence I2S Multi-Channel Controller Device Driver" + depends on HAVE_CLKindentation is off
Will fix. Thanks.
Quoted 7 lines
Quoted 6 lines
sound/soc/cdns/Kconfig new file +5
-0+ select SND_SOC_GENERIC_DMAENGINE_PCM + help + Say Y or M if you want to add support for I2S driver for the + Cadence Multi-Channel I2S Controller device. The device supports + up to a maximum of 8 channels each for play and record.
Quoted 7 lines
sound/soc/cdns/Kconfig line 13
Quoted 5 lines
sound/soc/cdns/Kconfig new file +5
-0+// SPDX-License-Identifier: GPL-2.0 +/* + * Cadence Multi-Channel I2S controller PCM driver + * + * Copyright (c) 2022-2023 StarFive Technology Co., Ltd.2024?
Will fix.
Quoted 12 lines
sound/soc/cdns/Kconfig
Quoted 10 lines
sound/soc/cdns/Kconfig new file +9
-0+ */ + +#include <linux/io.h> +#include <linux/rcupdate.h> +#include <sound/pcm_params.h> +#include "cdns-i2s-mc.h" + +#define PERIOD_BYTES_MIN 4096 +#define BUFFER_BYTES_MAX (3 * 2 * 8 * PERIOD_BYTES_MIN)what are those 3 and 2 and 8 factors? a comment or the use of macros would help.
Will fix.
Quoted 11 lines
sound/soc/cdns/Kconfig
Quoted 9 lines
sound/soc/cdns/Kconfig new file +8
-0+#define PERIODS_MIN 2 + +static unsigned int cdns_i2s_pcm_tx(struct cdns_i2s_dev *dev, + struct snd_pcm_runtime *runtime, + unsigned int tx_ptr, bool *period_elapsed, + snd_pcm_format_t format) +{ + unsigned int period_pos = tx_ptr % runtime->period_size;not following what the modulo is for, usually it's modulo the buffer size?
This is to see if the new data is divisible by period_size and to determine whether it is enough for a period_size in the later loop.
Quoted 16 lines
Quoted 4 lines
sound/soc/cdns/Kconfig new file +3
-0+ const u16 (*p16)[2] = (void *)runtime->dma_area; + const u32 (*p32)[2] = (void *)runtime->dma_area; + u32 data[2];sound/soc/cdns/Kconfig
Quoted 10 lines
sound/soc/cdns/Kconfig new file +10
-0+ int i; + + for (i = 0; i < CDNS_I2S_FIFO_DEPTH; i++) { + if (format == SNDRV_PCM_FORMAT_S16_LE) { + data[0] = p16[tx_ptr][0]; + data[1] = p16[tx_ptr][1]; + } else if (format == SNDRV_PCM_FORMAT_S32_LE) { + data[0] = p32[tx_ptr][0]; + data[1] = p32[tx_ptr][1]; + }what about other formats implied by the use of 'else if' ?
I think I just support S16_LE and S32_LE in the snd_soc_dai_driver struct, and ALSA device will filter out other formats for me, so I didn't add them. Do I still have to add the other case?
Quoted 12 lines
Quoted 11 lines
sound/soc/cdns/Kconfig new file +11
-0+ + iowrite32(data[0], dev->base + CDNS_FIFO_MEM); + iowrite32(data[1], dev->base + CDNS_FIFO_MEM); + period_pos++; + if (++tx_ptr >= runtime->buffer_size) + tx_ptr = 0; + } + + *period_elapsed = period_pos >= runtime->period_size; + return tx_ptr; +}
Quoted 4 lines
sound/soc/cdns/Kconfig
Quoted 2 lines
sound/soc/cdns/Kconfig new file +2
-0+static void cdns_i2s_pcm_transfer(struct cdns_i2s_dev *dev, bool +push)'push' really means 'tx' so what not use a simpler naming?
Will fix.
Quoted 52 lines
Quoted 41 lines
sound/soc/cdns/Kconfig new file +40
-0+{ + struct snd_pcm_substream *substream; + bool active, period_elapsed; + + rcu_read_lock(); + if (push) + substream = rcu_dereference(dev->tx_substream); + else + substream = rcu_dereference(dev->rx_substream); + + active = substream && snd_pcm_running(substream); + if (active) { + unsigned int ptr; + unsigned int new_ptr; + + if (push) { + ptr = READ_ONCE(dev->tx_ptr); + new_ptr = dev->tx_fn(dev, substream->runtime, ptr, + &period_elapsed, dev->format); + cmpxchg(&dev->tx_ptr, ptr, new_ptr); + } else { + ptr = READ_ONCE(dev->rx_ptr); + new_ptr = dev->rx_fn(dev, substream->runtime, ptr, + &period_elapsed, dev->format); + cmpxchg(&dev->rx_ptr, ptr, new_ptr); + } + + if (period_elapsed) + snd_pcm_period_elapsed(substream); + } + rcu_read_unlock(); +} + +void cdns_i2s_pcm_push_tx(struct cdns_i2s_dev *dev) { + cdns_i2s_pcm_transfer(dev, true); +} + +void cdns_i2s_pcm_pop_rx(struct cdns_i2s_dev *dev) { + cdns_i2s_pcm_transfer(dev, false); +}sound/soc/cdns/Kconfig
Quoted 10 lines
sound/soc/cdns/Kconfig new file +10
-0+ +static int cdns_i2s_pcm_open(struct snd_soc_component *component, + struct snd_pcm_substream *substream) { + struct snd_pcm_runtime *runtime = substream->runtime; + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); + struct cdns_i2s_dev *dev = +snd_soc_dai_get_drvdata(snd_soc_rtd_to_cpu(rtd, 0)); + + snd_soc_set_runtime_hwparams(substream, &cdns_i2s_pcm_hardware); + snd_pcm_hw_constraint_integer(runtime,
SNDRV_PCM_HW_PARAM_PERIODS);
Quoted 11 lines
sound/soc/cdns/Kconfig
Quoted 9 lines
sound/soc/cdns/Kconfig new file +9
-0+ runtime->private_data = dev; + + return 0; +} + +static int cdns_i2s_pcm_close(struct snd_soc_component *component, + struct snd_pcm_substream *substream) { + synchronize_rcu(); + return 0;
runtime->private_data= NULL?
Will add.
Quoted 12 lines
sound/soc/cdns/Kconfig
Quoted 10 lines
sound/soc/cdns/Kconfig new file +9
-0+} + +static int cdns_i2s_pcm_hw_params(struct snd_soc_component *component, + struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) { + struct snd_pcm_runtime *runtime = substream->runtime; + struct cdns_i2s_dev *dev = runtime->private_data; + + dev->format = params_format(hw_params);don't you need to test if the formats are supported?
Will add the test.
Quoted 16 lines
Quoted 16 lines
sound/soc/cdns/Kconfig new file +14
-0+ dev->tx_fn = cdns_i2s_pcm_tx; + dev->rx_fn = cdns_i2s_pcm_rx; + + return 0; +} +static int cdns_i2s_start(struct cdns_i2s_dev *i2s, + struct snd_pcm_substream *substream) { + struct snd_pcm_runtime *runtime = substream->runtime; + unsigned char max_ch = i2s->max_channels; + unsigned char i2s_ch; + int i; + + /* Each channel is stereo */ + i2s_ch = runtime->channels / 2;
Quoted 8 lines
sound/soc/cdns/Kconfig
Quoted 6 lines
sound/soc/cdns/Kconfig new file +6
-0+ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { + if ((i2s_ch + i2s->tx_using_channels) > max_ch) { + dev_err(i2s->dev, + "Max %d channels: using %d for TX, do not support %d for RX\n", + max_ch, i2s->tx_using_channels, i2s_ch); + return -ENOMEM;ENOMEM is for memory allocation, that looks more like EINVAL?
Will fix.
Quoted 17 lines
Quoted 17 lines
sound/soc/cdns/Kconfig new file +16
-0+ } + + i2s->rx_using_channels = i2s_ch; + /* Enable channels from 0 to 'max_ch' as tx */ + for (i = 0; i < i2s_ch; i++) + cdns_i2s_channel_start(i2s, CDNS_I2S_CM_0 << i, + CDNS_I2S_TC_RECEIVER); + + } else { + if ((i2s_ch + i2s->rx_using_channels) > max_ch) { + dev_err(i2s->dev, + "Max %d channels: using %d for RX, do not support %d for TX\n", + max_ch, i2s->rx_using_channels, i2s_ch); + return -ENOMEM; + } +
Quoted 8 lines
sound/soc/cdns/Kconfig
Quoted 5 lines
sound/soc/cdns/Kconfig new file +5
-0+ i2s->tx_using_channels = i2s_ch; + /* Enable channels from 'max_ch' to 0 as rx */ + for (i = (max_ch - 1); i > (max_ch - i2s_ch - 1); i--) { + if (i < 0) + return -EINVAL;that is a test you can probably factor out of the loop before doing anything that's inconsistent.
OK, I will move it out of the loop. Thanks.
Quoted 30 lines
Quoted 30 lines
sound/soc/cdns/Kconfig new file +29
-0+ + cdns_i2s_channel_start(i2s, CDNS_I2S_CM_0 << i, + CDNS_I2S_TC_TRANSMITTER); + } + } + cdns_i2s_enable_clock(i2s, substream->stream); + + if (i2s->irq >= 0) + cdns_i2s_set_all_irq_mask(i2s, false); + + cdns_i2s_clear_int(i2s); + + return 0; +} + +static int cdns_i2s_stop(struct cdns_i2s_dev *i2s, + struct snd_pcm_substream *substream) { + unsigned char i2s_ch; + int i; + + cdns_i2s_clear_int(i2s); + + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { + i2s_ch = i2s->rx_using_channels; + for (i = 0; i < i2s_ch; i++) + cdns_i2s_channel_stop(i2s, (CDNS_I2S_CM_0 << i)); + + i2s->rx_using_channels = 0; + } else {
Quoted 8 lines
sound/soc/cdns/Kconfig
Quoted 6 lines
sound/soc/cdns/Kconfig new file +6
-0+ unsigned char max_ch = i2s->max_channels; + + i2s_ch = i2s->tx_using_channels; + for (i = (max_ch - 1); i > (max_ch - i2s_ch - 1); i--) { + if (i < 0) + return -EINVAL;same here, first test if the channel maps are valid, then do the loop?
Will fix.
Quoted 27 lines
Quoted 27 lines
sound/soc/cdns/Kconfig new file +25
-0+ + cdns_i2s_channel_stop(i2s, (CDNS_I2S_CM_0 << i)); + } + + i2s->tx_using_channels = 0; + } + + if (i2s->irq >= 0 && !i2s->tx_using_channels && !i2s->rx_using_channels) + cdns_i2s_set_all_irq_mask(i2s, true); + + return 0; +} +static int cdns_i2s_set_fmt(struct snd_soc_dai *cpu_dai, + unsigned int fmt) +{ + struct cdns_i2s_dev *i2s = snd_soc_dai_get_drvdata(cpu_dai); + int ret = 0; + + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { + case SND_SOC_DAIFMT_CBM_CFM: + i2s->tx_sync_ms_mode = CDNS_I2S_MASTER_MODE; + i2s->rx_sync_ms_mode = CDNS_I2S_MASTER_MODE; + cdns_i2s_set_ms_mode(i2s); + break; + case SND_SOC_DAIFMT_CBS_CFS:
Quoted 8 lines
sound/soc/cdns/Kconfig
Quoted 6 lines
sound/soc/cdns/Kconfig new file +6
-0+ i2s->tx_sync_ms_mode = CDNS_I2S_SLAVE_MODE; + i2s->rx_sync_ms_mode = CDNS_I2S_SLAVE_MODE; + cdns_i2s_set_ms_mode(i2s); + break; + case SND_SOC_DAIFMT_CBM_CFS: + case SND_SOC_DAIFMT_CBS_CFM:that's the old stuff, use CBP/CBC macros please.
Will fix.
Quoted 11 lines
Quoted 10 lines
sound/soc/cdns/Kconfig new file +9
-0+ ret = -EINVAL; + break; + default: + dev_dbg(i2s->dev, "Invalid master/slave format\n"); + ret = -EINVAL; + break; + } + return ret; +}
Quoted 3 lines
Quoted 1 line
+#ifdef
CONFIG_PMDo we need this or just rely on
__unused?
I think both are OK.
Quoted 65 lines
Quoted 65 lines
sound/soc/cdns/Kconfig new file +63
-0+static int cdns_i2s_runtime_suspend(struct device *dev) { + struct cdns_i2s_dev *i2s = dev_get_drvdata(dev); + + clk_disable_unprepare(i2s->clks[1].clk); /* ICG clock */ + return 0; +} + +static int cdns_i2s_runtime_resume(struct device *dev) { + struct cdns_i2s_dev *i2s = dev_get_drvdata(dev); + + return clk_prepare_enable(i2s->clks[1].clk); /* ICG clock */ } +#endif +static int cdns_i2s_probe(struct platform_device *pdev) { + struct cdns_i2s_dev *i2s; + struct resource *res; + int ret; + + i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL); + if (!i2s) { + ret = -ENOMEM; + goto err; + } + platform_set_drvdata(pdev, i2s); + + i2s->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res); + if (IS_ERR(i2s->base)) { + ret = PTR_ERR(i2s->base); + goto err; + } + + i2s->dev = &pdev->dev; + i2s->phybase = res->start; + + ret = cdns_i2s_init(i2s); + if (ret) + goto err; + + i2s->irq = platform_get_irq(pdev, 0); + if (i2s->irq >= 0) { + ret = devm_request_irq(&pdev->dev, i2s->irq, cdns_i2s_irq_handler, + 0, pdev->name, i2s); + if (ret < 0) { + dev_err(&pdev->dev, "request_irq failed\n"); + goto err; + } + } + + ret = devm_snd_soc_register_component(&pdev->dev, + &cdns_i2s_component, + &cdns_i2s_dai, 1); + if (ret < 0) { + dev_err(&pdev->dev, "couldn't register component\n"); + goto err; + } + + if (i2s->irq >= 0) + ret = cdns_i2s_pcm_register(pdev); + else + ret = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, 0); + + if (ret) { + dev_err(&pdev->dev, "could not register pcm: %d\n", ret); + goto err;
Quoted 8 lines
sound/soc/cdns/Kconfig
Quoted 5 lines
sound/soc/cdns/Kconfig new file +5
-0+ } + + pm_runtime_enable(&pdev->dev); + if (pm_runtime_enabled(&pdev->dev)) + cdns_i2s_runtime_suspend(&pdev->dev);that sequence looks suspicious.... Why would you suspend immediately during the probe? You're probably missing all the autosuspend stuff?
Since I have enabled clocks before, and the device is in the suspend state after pm_runtime_enable(), I need to disable clocks in cdns_i2s_runtime_suspend() to match the suspend state.
Quoted 10 lines
Quoted 10 lines
sound/soc/cdns/Kconfig new file +9
-0+ + dev_dbg(&pdev->dev, "I2S supports %d stereo channels with %s.\n", + i2s->max_channels, ((i2s->irq < 0) ? "dma" : "interrupt")); + + return 0; + +err: + return ret; +}
Quoted 8 lines
sound/soc/cdns/Kconfig
Quoted 5 lines
sound/soc/cdns/Kconfig new file +5
-0+ +static int cdns_i2s_remove(struct platform_device *pdev) { + pm_runtime_disable(&pdev->dev); + if (!pm_runtime_status_suspended(&pdev->dev)) + cdns_i2s_runtime_suspend(&pdev->dev);... and this one too. Once you've disabled
pm_runtime, checking the status is irrelevant...
I think the clocks need to be always enabled after probe if disable pm_runtime, and should be disabled when remove. This will do that.
Quoted 5 lines
sound/soc/cdns/Kconfig
Quoted 5 lines
sound/soc/cdns/Kconfig new file +4
-0+ + return 0; +} +
Best regards,
Xingyu Wu
Re: 回复: [PATCH v2 2/2] ASoC: cdns: Add drivers of Cadence Multi-Channel I2S Controller
Quoted 13 lines
Quoted 12 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c line 22
Quoted 10 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +8
-0+#define PERIODS_MIN 2 + +static unsigned int cdns_i2s_pcm_tx (struct cdns_i2s_dev *dev, +struct snd_pcm_runtime *runtime, +unsigned int tx_ptr,bool *period_elapsed, +snd_pcm_format_t format) +{ +unsigned int period_pos = tx_ptr % runtime->period_size;not following what the modulo is for, usually it's modulo the buffer size?
Quoted 2 lines
This is to see if the new data is divisible by
period_sizeand to determine whether it is enough for aperiod_sizein the later loop.
That didn't answer to my question, the position is usually between 0..buffer_size.1.
Doing increments on a modulo value then comparisons as done below seems rather questionable.
Quoted 19 lines
Quoted 12 lines
Quoted 11 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +11
-0+ +iowrite32 (data[0 ], dev->base +CDNS_FIFO_MEM ); +iowrite32 (data[1 ], dev->base +CDNS_FIFO_MEM ); + period_pos++; +if (++tx_ptr >= runtime->buffer_size) + tx_ptr =0 ; + } + + *period_elapsed = period_pos >= runtime->period_size; +return tx_ptr; +}Quoted 6 lines
sound/soc/cdns/cdns-i2s-mc.c line 674
Quoted 3 lines
sound/soc/cdns/cdns-i2s-mc.c new file +3
-0+pm_runtime_enable (&pdev->dev); +if (pm_runtime_enabled (&pdev->dev)) +cdns_i2s_runtime_suspend (&pdev->dev);that sequence looks suspicious.... Why would you suspend immediately during the probe? You're probably missing all the autosuspend stuff?
Quoted 3 lines
Since I have enabled clocks before, and the device is in the suspend state after
pm_runtime_enable(), I need to disable clocks incdns_i2s_runtime_suspend()to match the suspend state.
That is very odd on two counts
a) if you haven't enabled the clocks, why do you need to disbale them?
b) if you do a pm_runtime_enable(), then the branch if (pm_runtime_enabled) is always true.
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
sound/soc/cdns/cdns-i2s-mc.c new file +9
-0+ +dev_dbg (&pdev->dev,"I2S supports %d stereo channels with %s.\n" , + i2s->max_channels, ((i2s->irq <0 ) ?"dma" :"interrupt" )); + +return 0 ; + +err: +return ret; +}Quoted 8 lines
sound/soc/cdns/cdns-i2s-mc.c line 689
Quoted 5 lines
sound/soc/cdns/cdns-i2s-mc.c new file +5
-0+ +static int cdns_i2s_remove (struct platform_device *pdev) { +pm_runtime_disable (&pdev->dev); +if (!pm_runtime_status_suspended (&pdev->dev)) +cdns_i2s_runtime_suspend (&pdev->dev);... and this one too. Once you've disabled
pm_runtime, checking the status is irrelevant...
Quoted 2 lines
I think the clocks need to be always enabled after probe if disable
pm_runtime, and should be disabled when remove. This will do that.
if you are disabling pm_runtime, then the pm_runtime state becames invalid. When pm_runtime_disable() is added in remove operations, it's mainly to prevent the device from suspending.
RE: 回复: [PATCH v2 2/2] ASoC: cdns: Add drivers of Cadence Multi-Channel I2S Controller
Quoted 14 lines · Pierre-Louis Bossart
Quoted 14 lines
Quoted 13 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c line 22
Quoted 11 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +8
-0+#define PERIODS_MIN 2 + +static unsigned int cdns_i2s_pcm_tx (struct cdns_i2s_dev *dev, +struct snd_pcm_runtime *runtime, +unsigned int tx_ptr,bool *period_elapsed, +snd_pcm_format_t format) +{ +unsigned int period_pos = tx_ptr % runtime->period_size;not following what the modulo is for, usually it's modulo the buffer size?
Quoted 5 lines
Quoted 2 lines
This is to see if the new data is divisible by
period_sizeand to determine whether it is enough for aperiod_sizein the later loop.That didn't answer to my question, the position is usually between 0..buffer_size.1.
Yes, this position will be used later in the cdns_i2s_pcm_pointer(). But this cdns_i2s_pcm_tx() is called by I2S hardware interrupt which would be frequently called several times each period. The period_pos is used to determine whether there is enough a period_size to call snd_pcm_period_elapsed().
Quoted 23 lines
Doing increments on a modulo value then comparisons as done below seems rather questionable.
Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +5
-0+ +iowrite32 (data[0 ], dev->base +CDNS_FIFO_MEM ); +iowrite32 (data[1 ], dev->base +CDNS_FIFO_MEM ); + period_pos++; +if (++tx_ptr >= runtime->buffer_size)sound/soc/cdns/cdns-i2s-mc-pcm.c
Quoted 10 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +9
-0+ tx_ptr =0 ; + } + + *period_elapsed = period_pos >= runtime->period_size; +return tx_ptr; +} +pm_runtime_enable (&pdev->dev); +if (pm_runtime_enabled (&pdev->dev)) +cdns_i2s_runtime_suspend (&pdev->dev);that sequence looks suspicious.... Why would you suspend immediately during the probe? You're probably missing all the autosuspend stuff?
Quoted 9 lines
Quoted 3 lines
Since I have enabled clocks before, and the device is in the suspend state after
pm_runtime_enable(), I need to disable clocks incdns_i2s_runtime_suspend()to match the suspend state.That is very odd on two counts
a) if you haven't enabled the clocks, why do you need to disbale them?
b) if you do apm_runtime_enable(), then the branch if (pm_runtime_enabled) is always true.
a) It must enable clocks first to read and write registers when I2S probe. Then it is done to probe, the clocks are still enabled and the state of pm is suspend. So it need to be disabled to match the state and will resume and be enabled by ALSA.
b) Because CONFIG_PM would be disabled and pm_runtime_enabled() return false , then it is no need to disable clock and I2S still can work.
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 7 lines
sound/soc/cdns/cdns-i2s-mc.c new file +4
-0+ +dev_dbg (&pdev->dev,"I2S supports %d stereo channels with %s.\n" , + i2s->max_channels, ((i2s->irq <0 ) ?"dma" :"interrupt" )); +sound/soc/cdns/cdns-i2s-mc.c line 689
Quoted 10 lines
sound/soc/cdns/cdns-i2s-mc.c new file +10
-0+return 0 ; + +err: +return ret; +} + +static int cdns_i2s_remove (struct platform_device *pdev) { +pm_runtime_disable (&pdev->dev); +if (!pm_runtime_status_suspended (&pdev->dev)) +cdns_i2s_runtime_suspend (&pdev->dev);... and this one too. Once you've disabled
pm_runtime, checking the status is irrelevant...
Quoted 6 lines
Quoted 2 lines
I think the clocks need to be always enabled after probe if disable
pm_runtime, and should be disabled when remove. This will do that.if you are disabling
pm_runtime, then thepm_runtimestate becames invalid. Whenpm_runtime_disable()is added in remove operations, it's mainly to prevent the device from suspending.
Should I use the pm_runtime_enabled() before the pm_runtime_disable()?
Best regards,
Xingyu Wu
Re: 回复: [PATCH v2 2/2] ASoC: cdns: Add drivers of Cadence Multi-Channel I2S Controller
Quoted 60 lines · Xingyu Wu
Quoted 14 lines · Pierre-Louis Bossart
Quoted 14 lines
Quoted 13 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c line 22
Quoted 11 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +8
-0+#define PERIODS_MIN 2 + +static unsigned int cdns_i2s_pcm_tx (struct cdns_i2s_dev *dev, +struct snd_pcm_runtime *runtime, +unsigned int tx_ptr,bool *period_elapsed, +snd_pcm_format_t format) +{ +unsigned int period_pos = tx_ptr % runtime->period_size;not following what the modulo is for, usually it's modulo the buffer size?
Quoted 5 lines
Quoted 2 lines
This is to see if the new data is divisible by
period_sizeand to determine whether it is enough for aperiod_sizein the later loop.That didn't answer to my question, the position is usually between 0..buffer_size.1.
Yes, this position will be used later in the
cdns_i2s_pcm_pointer(). But thiscdns_i2s_pcm_tx()is called by I2S hardware interrupt which would be frequently called several times each period. Theperiod_posis used to determine whether there is enough aperiod_sizeto callsnd_pcm_period_elapsed().Quoted 23 lines
Doing increments on a modulo value then comparisons as done below seems rather questionable.
Quoted 19 lines
Quoted 18 lines
Quoted 5 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +5
-0+ +iowrite32 (data[0 ], dev->base +CDNS_FIFO_MEM ); +iowrite32 (data[1 ], dev->base +CDNS_FIFO_MEM ); + period_pos++; +if (++tx_ptr >= runtime->buffer_size)sound/soc/cdns/cdns-i2s-mc-pcm.c
Quoted 10 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +9
-0+ tx_ptr =0 ; + } + + *period_elapsed = period_pos >= runtime->period_size; +return tx_ptr; +} +pm_runtime_enable (&pdev->dev); +if (pm_runtime_enabled (&pdev->dev)) +cdns_i2s_runtime_suspend (&pdev->dev);that sequence looks suspicious.... Why would you suspend immediately during the probe? You're probably missing all the autosuspend stuff?
Quoted 9 lines
Quoted 3 lines
Since I have enabled clocks before, and the device is in the suspend state after
pm_runtime_enable(), I need to disable clocks incdns_i2s_runtime_suspend()to match the suspend state.That is very odd on two counts
a) if you haven't enabled the clocks, why do you need to disbale them?
b) if you do apm_runtime_enable(), then the branch if (pm_runtime_enabled) is always true.
Quoted 4 lines
a) It must enable clocks first to read and write registers when I2S probe. Then it is done to probe, the clocks are still enabled and the state of pm is suspend. So it need to be disabled to match the state and will resume and be enabled by ALSA.
I think you are missing a pm_runtime_set_active() to reconcile the pm state with the hardware state. The premise of pm_runtime is that on probe your device is active and later on it will suspend. Having pm_runtime_enabled with a suspended device without the framework involved to trigger the transition to suspend is asking for trouble.
Quoted 2 lines
b) Because
CONFIG_PMwould be disabled andpm_runtime_enabled()return false , then it is no need to disable clock and I2S still can work.
Again you are trying to make things more complicated than they need to be. Don't try to actively manage and query states, let the framework do it for you.
Try to probe and bring the device to an active state. Then use pm_runtime_mark_last_busy(), use pm_runtime_enable and let autosuspend do the work for you. If pm_runtime is not enabled the suspend will not happen.
Also keep in mind that pm_runtime_enabled() will return false if the user mucks with the power state in sysfs, it's not only a case of CONFIG_PM being selected or not.
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 21 lines
Quoted 8 lines
sound/soc/cdns/cdns-i2s-mc.c new file +4
-0+ +dev_dbg (&pdev->dev,"I2S supports %d stereo channels with %s.\n" , + i2s->max_channels, ((i2s->irq <0 ) ?"dma" :"interrupt" )); +sound/soc/cdns/cdns-i2s-mc.c line 689
Quoted 10 lines
sound/soc/cdns/cdns-i2s-mc.c new file +10
-0+return 0 ; + +err: +return ret; +} + +static int cdns_i2s_remove (struct platform_device *pdev) { +pm_runtime_disable (&pdev->dev); +if (!pm_runtime_status_suspended (&pdev->dev)) +cdns_i2s_runtime_suspend (&pdev->dev);... and this one too. Once you've disabled
pm_runtime, checking the status is irrelevant...
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I think the clocks need to be always enabled after probe if disable
pm_runtime, and should be disabled when remove. This will do that.if you are disabling
pm_runtime, then thepm_runtimestate becames invalid. Whenpm_runtime_disable()is added in remove operations, it's mainly to prevent the device from suspending.Should I use the
pm_runtime_enabled()before thepm_runtime_disable()?
It doesn't matter, the problem is the second part where you try to check the status of pm_runtime *after* disabling it.
RE: 回复: [PATCH v2 2/2] ASoC: cdns: Add drivers of Cadence Multi-Channel I2S Controller
Quoted 70 lines · Pierre-Louis Bossart
Quoted 9 lines · Xingyu Wu
Quoted 8 lines · Pierre-Louis Bossart
Quoted 8 lines
Quoted 8 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c
Quoted 8 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +5
-0+#define PERIODS_MIN 2 + +static unsigned int cdns_i2s_pcm_tx (struct cdns_i2s_dev *dev, +struct snd_pcm_runtime *runtime, + unsigned int tx_ptr, bool
*period_elapsed,Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c line 22
Quoted 3 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +3
-0+ snd_pcm_format_t format) +{ +unsigned int period_pos = tx_ptr % runtime->period_size;not following what the modulo is for, usually it's modulo the buffer size?
This is to see if the new data is divisible by
period_sizeand to determine whether it is enough for aperiod_sizein the later loop.Quoted 31 lines
Quoted 2 lines
That didn't answer to my question, the position is usually between 0..buffer_size.1.
Yes, this position will be used later in the
cdns_i2s_pcm_pointer(). But thiscdns_i2s_pcm_tx()is called by I2S hardware interrupt which would be frequently called several times each period. Theperiod_posis used to determine whether there is enough aperiod_sizeto callsnd_pcm_period_elapsed().Quoted 22 lines
Doing increments on a modulo value then comparisons as done below seems rather questionable.
Quoted 18 lines
Quoted 18 lines
Quoted 5 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +5
-0+ +iowrite32 (data[0 ], dev->base +CDNS_FIFO_MEM ); +iowrite32 (data[1 ], dev->base +CDNS_FIFO_MEM ); + period_pos++; +if (++tx_ptr >= runtime->buffer_size)sound/soc/cdns/cdns-i2s-mc-pcm.c
Quoted 10 lines
sound/soc/cdns/cdns-i2s-mc-pcm.c new file +9
-0+ tx_ptr =0 ; + } + + *period_elapsed = period_pos >= runtime->period_size; +return tx_ptr; +} +pm_runtime_enable (&pdev->dev); +if (pm_runtime_enabled (&pdev->dev)) +cdns_i2s_runtime_suspend (&pdev->dev);that sequence looks suspicious.... Why would you suspend immediately during the probe? You're probably missing all the autosuspend
stuff?
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
Since I have enabled clocks before, and the device is in the suspend state after
pm_runtime_enable(), I need to disable clocks incdns_i2s_runtime_suspend()to match the suspend state.That is very odd on two counts
a) if you haven't enabled the clocks, why do you need to disbale them?
b) if you do apm_runtime_enable(), then the branch if (pm_runtime_enabled) is always true.Quoted 4 lines
a) It must enable clocks first to read and write registers when I2S probe. Then it is done to probe, the clocks are still enabled and the state of pm is suspend. So it need to be disabled to match the state and will resume and be enabled by ALSA.
Quoted 5 lines
I think you are missing a
pm_runtime_set_active()to reconcile the pm state with the hardware state. The premise ofpm_runtimeis that on probe your device is active and later on it will suspend. Havingpm_runtime_enabledwith a suspended device without the framework involved to trigger the transition to suspend is asking for trouble.
Great, It is better to use pm_runtime_set_active(). I will modify it in next patch.
Quoted 7 lines
Quoted 3 lines
b) Because
CONFIG_PMwould be disabled andpm_runtime_enabled()return false , then it is no need to disable clock and I2S still can work.Again you are trying to make things more complicated than they need to be. Don't try to actively manage and query states, let the framework do it for you.
Quoted 7 lines
Try to probe and bring the device to an active state. Then use
pm_runtime_mark_last_busy(), usepm_runtime_enableand let autosuspend do the work for you. Ifpm_runtimeis not enabled the suspend will not happen.Also keep in mind that
pm_runtime_enabled()will return false if the user mucks with the power state in sysfs, it's not only a case ofCONFIG_PMbeing selected or not.
Noted. Thanks.
Quoted 26 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Review
Quoted 6 lines
(quoted diff) +2
-0+ + dev_dbg(&pdev->dev, "I2S supports %d stereo channelswith %s.\n",
Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 7 lines
Quoted 7 lines
sound/soc/cdns/cdns-i2s-mc.c new file +7
-0+ i2s->max_channels, ((i2s->irq < 0) ? "dma" : "interrupt")); + +return 0 ; + +err: +return ret; +}Quoted 8 lines
sound/soc/cdns/cdns-i2s-mc.c line 689
Quoted 5 lines
sound/soc/cdns/cdns-i2s-mc.c new file +5
-0+ +static int cdns_i2s_remove (struct platform_device *pdev) { +pm_runtime_disable (&pdev->dev); +if (!pm_runtime_status_suspended (&pdev->dev)) +cdns_i2s_runtime_suspend (&pdev->dev);... and this one too. Once you've disabled
pm_runtime, checking the status is irrelevant...I think the clocks need to be always enabled after probe if disable
pm_runtime, and should be disabled when remove. This will do that.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
if you are disabling
pm_runtime, then thepm_runtimestate becames invalid. Whenpm_runtime_disable()is added in remove operations, it's mainly to prevent the device from suspending.Should I use the
pm_runtime_enabled()before thepm_runtime_disable()?It doesn't matter, the problem is the second part where you try to check the status of
pm_runtime*after* disabling it.
Will fix.
Thanks,
Xingyu Wu