Skip to contentSkip to conversation

ASoC: cdns: Add Cadence I2S-SC and I2S-MC controller support

PATCH RESEND Superseded [email protected] 2 participants 7 messages Nov 4

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover ASoC: cdns: Add Cadence I2S-SC and I2S-MC controller support

From: Joakim Zhang <[email protected]>

This series adds support for the Cadence I2S-SC and I2S-MC controllers integrated in the CIX SKY1 audio subsystem, together with their DT bindings.

I2S-SC provides full-duplex stereo playback and capture in standard I2S, left/right-justified and DSP modes, along with TDM operation supporting up to 16 slots. I2S-MC provides multi-channel playback and capture through a configurable set of its 8 data pins, described by cix,pin-out-num, cix,pin-rx-mask and cix,pin-tx-mask, and exposes a transmit DAI and a receive DAI.

Both drivers register the dmaengine PCM helper, select the audio reference clock parent for the 8 kHz or 11.025 kHz sample rate family and keep the minimum functional-clock to bit-clock ratio required for safe clock domain crossing.

Resending to carry the Reviewed-by tags received on the two binding patches; the patches are otherwise unchanged since v4.

Changes in v4:
- Enforce the dma-names order in the bindings: a single "tx" or "rx" name is still allowed for single-direction instances, but a pair must be "tx", "rx".
- Drop the DMA controller stub node from the binding examples.
- Select REGMAP_MMIO; a COMPILE_TEST build without it would fail to link the regmap MMIO users.
- Include the transmitter and receiver synchronizing-unit reset bits in the masked register write of the I2S-MC DAI probe, so that the write actually programs the state its comment describes.

Changes in v3:
- Add the explicit <linux/bitfield.h> include, which a W=1 build of the FIELD_PREP() sites needs (both drivers).
- Fix the probe error paths: disable the manually enabled clocks and drop the runtime PM usage count on every failure path, unwinding through a single goto label (both drivers).
- Return dev_err_probe() directly instead of logging with it and then returning the error separately (both drivers).

Changes in v2:
- Move the IRQ request after the clocks are enabled and the reset is released, so the handler never runs against unclocked hardware.
- Disable the IRQ before switching the regcache to cache-only mode on suspend, and re-enable it only after the cache is synced on resume; check the status read in the ISR (both drivers).
- Replace the manual runtime PM bookkeeping with devm_pm_runtime_enable() and drop the remove() callbacks (both drivers).
- Switch to RUNTIME_PM_OPS()/SYSTEM_SLEEP_PM_OPS() wrapped in pm_ptr() and drop the __maybe_unused annotations (both drivers).
- Serialize the shared transceiver clock state in prepare() against the trigger() state machine with the existing spinlock (I2S-SC).
- Disable clocks in the reverse order of enablement (both drivers).
- Sort the cdns/ entry into the vendor list in sound/soc/Makefile and switch sound/soc/cdns/Makefile to the '-y' object syntax.
- Clean up the includes and initializer style (both drivers).
- Add a NULL check for the match data in probe (both drivers).
- Factor the MC transmitter and receiver configuration into a shared helper.
- Drop the compatible string from the DMAC stub node in the binding examples.

Joakim Zhang (4):
ASoC: dt-bindings: Add Cadence I2S-SC controller
ASoC: cdns: Add Cadence I2S-SC controller driver
ASoC: dt-bindings: Add Cadence I2S-MC controller
ASoC: cdns: Add Cadence I2S-MC controller driver

 .../bindings/sound/cix,sky1-i2s-mc.yaml       |  119 ++
 .../bindings/sound/cix,sky1-i2s-sc.yaml       |   89 ++
 sound/soc/Kconfig                             |    1 +
 sound/soc/Makefile                            |    1 +
 sound/soc/cdns/Kconfig                        |   23 +
 sound/soc/cdns/Makefile                       |    7 +
 sound/soc/cdns/cdns-i2s-mc.c                  | 1128 ++++++++++++++++
 sound/soc/cdns/cdns-i2s-sc.c                  | 1166 +++++++++++++++++
 8 files changed, 2534 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/cix,sky1-i2s-mc.yaml
 create mode 100644 Documentation/devicetree/bindings/sound/cix,sky1-i2s-sc.yaml
 create mode 100644 sound/soc/cdns/Kconfig
 create mode 100644 sound/soc/cdns/Makefile
 create mode 100644 sound/soc/cdns/cdns-i2s-mc.c
 create mode 100644 sound/soc/cdns/cdns-i2s-sc.c
Signature · 1 line
2.50.1
#1 lore raw

PATCH RESEND v4 1/4 ASoC: dt-bindings: Add Cadence I2S-SC controller

From: Joakim Zhang <[email protected]>

Add the DT binding for the Cadence I2S-SC controller integrated in the CIX SKY1 audio subsystem. I2S-SC is a full-duplex stereo controller supporting standard I2S, left/right-justified and DSP formats, plus TDM operation with up to 16 slots.

---
 .../bindings/sound/cix,sky1-i2s-sc.yaml       | 89 +++++++++++++++++++
 1 file changed, 89 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/cix,sky1-i2s-sc.yaml
Documentation/devicetree/bindings/sound/cix,sky1-i2s-sc.yaml new file +89 -0
new file mode 100644
index 000000000000..9ef11272d0fd
@@ -0,0 +1,89 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/cix,sky1-i2s-sc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cadence I2S-SC controller
+
+maintainers:
+  - Joakim Zhang <[email protected]>
+
+description: |
+  The Cadence I2S-SC controller integrated in the CIX SKY1 audio subsystem.
+  It supports full-duplex stereo playback and capture in standard I2S,
+  left/right-justified and DSP modes, as well as TDM operation with up to
+  16 slots. The transmitter and receiver are started and stopped together
+  by the controller.
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    const: cix,sky1-i2s-sc
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 4
+
+  clock-names:
+    items:
+      - const: hst
+      - const: i2s
+      - const: audio-clk0
+      - const: audio-clk2
+
+  resets:
+    maxItems: 1
+
+  dmas:
+    minItems: 1
+    maxItems: 2
+    description:
+      One DMA channel for instances wired for a single direction, either
+      "tx" or "rx", or two channels for both transmit and receive.
+
+  dma-names:
+    minItems: 1
+    items:
+      - enum: [ tx, rx ]
+      - const: rx
+
+  "#sound-dai-cells":
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - resets
+  - dmas
+  - dma-names
+  - "#sound-dai-cells"
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    i2s@7020000 {
+        compatible = "cix,sky1-i2s-sc";
+        reg = <0x7020000 0x10000>;
+        interrupts = <GIC_SPI 219 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&audss_cru 16>, <&audss_cru 26>,
+                 <&scmi_clk 100>, <&scmi_clk 101>;
+        clock-names = "hst", "i2s", "audio-clk0", "audio-clk2";
+        resets = <&audss_cru 0>;
+        dmas = <&audss_dmac 0>, <&audss_dmac 1>;
+        dma-names = "tx", "rx";
+        #sound-dai-cells = <0>;
+    };
Signature · 1 line
2.50.1
#2 lore raw

PATCH RESEND v4 2/4 ASoC: cdns: Add Cadence I2S-SC controller driver

In reply to [email protected]

From: Joakim Zhang <[email protected]>

Add support for the Cadence I2S-SC controller found in the CIX SKY1 audio subsystem.

The controller provides full-duplex stereo playback and capture in standard I2S, left/right-justified and DSP modes, with mono operation mapped onto the left audio channel. It also supports TDM operation with up to 16 slots per frame, where the PCM channels map onto the active slots of the stream direction while the bit clock covers the whole frame.

The transmitter and receiver share the transceiver enable sequence, so the start/stop state machine is serialized with a spinlock against independently triggered playback and capture PCMs. The driver registers the dmaengine PCM helper, selects the audio reference clock parent for the 8 kHz or 11.025 kHz sample rate family and keeps the minimum functional-clock to bit-clock ratio required for safe clock domain crossing. Runtime and system suspend/resume restore the registers through the regcache.

---
 sound/soc/Kconfig            |    1 +
 sound/soc/Makefile           |    1 +
 sound/soc/cdns/Kconfig       |   12 +
 sound/soc/cdns/Makefile      |    4 +
 sound/soc/cdns/cdns-i2s-sc.c | 1166 ++++++++++++++++++++++++++++++++++
 5 files changed, 1184 insertions(+)
 create mode 100644 sound/soc/cdns/Kconfig
 create mode 100644 sound/soc/cdns/Makefile
 create mode 100644 sound/soc/cdns/cdns-i2s-sc.c
sound/soc/Kconfig +1 -0
index edfdcbf734fe..d9b746ffd701 100644
@@ -108,6 +108,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
index 21d8406767fc..ba3cf6eb937a 100644
@@ -50,6 +50,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 +12 -0
new file mode 100644
index 000000000000..06fd8fd6cb54
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config SND_SOC_CDNS_I2S_SC
+	tristate "Cadence I2S-SC controller support"
+	depends on ARCH_CIX || COMPILE_TEST
+	select SND_SOC_GENERIC_DMAENGINE_PCM
+	select REGMAP_MMIO
+	help
+	  Say Y or M if you want to add support for the Cadence I2S-SC
+	  controller found in the CIX SKY1 audio subsystem. It provides
+	  full-duplex stereo playback and capture in standard I2S and
+	  TDM modes with up to 16 slots.
sound/soc/cdns/Makefile new file +4 -0
new file mode 100644
index 000000000000..6abfeef29e43
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+
+snd-soc-cdns-i2s-sc-y := cdns-i2s-sc.o
+obj-$(CONFIG_SND_SOC_CDNS_I2S_SC) += snd-soc-cdns-i2s-sc.o
sound/soc/cdns/cdns-i2s-sc.c new file +1166 -0

1,166 lines not on this page · raw message

Signature · 1 line
2.50.1
#3 lore raw

Re: [PATCH v4 RESEND 2/4] ASoC: cdns: Add Cadence I2S-SC controller driver

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [Medium] ASoC: cdns: unbalanced clock enable in cdns_i2s_sc_probe() and on unbind - [Medium] ASoC: cdns…

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [Medium] ASoC: cdns: unbalanced clock enable in cdns_i2s_sc_probe() and on unbind
- [Medium] ASoC: cdns: wrong devres ordering for IRQ and PM in cdns_i2s_sc_probe()
- [Medium] ASoC: cdns: cdns_i2s_sc_set_tdm_slot() rejects slots == 0 to disable TDM --

commit 8608e01e4e2208a8765fd0b404456a7e98eea27f
Author: Joakim Zhang <[email protected]>

ASoC: cdns: Add Cadence I2S-SC controller driver

This commit adds an ASoC driver for the Cadence I2S-SC controller found in the CIX SKY1 audio subsystem, supporting full-duplex stereo I2S and up to 16-slot TDM modes with dmaengine PCM and runtime/system PM support.

Quoted 5 lines
sound/soc/cdns/cdns-i2s-sc.c new file +0 -0
new file mode 100644
index 0000000000000..160a0ec573d72

[ ... ]

Quoted 23 lines
sound/soc/cdns/cdns-i2s-sc.c new file +23 -0
+static int cdns_i2s_sc_set_tdm_slot(struct snd_soc_dai *cpu_dai, unsigned int tx_mask,
+				    unsigned int rx_mask, int slots, int slot_width)
+{
+	struct cdns_i2s_sc_priv *i2s_sc_priv = snd_soc_dai_get_drvdata(cpu_dai);
+	struct device *dev = i2s_sc_priv->dev;
+
+	dev_dbg(dev, "tx_mask = 0x%x, rx_mask = 0x%x, slots = %d, slot_width = %d\n",
+		tx_mask, rx_mask, slots, slot_width);
+
+	if (slots < 1 || slots > 16) {
+		dev_err(i2s_sc_priv->dev, "TDM mode supports 1 to 16 slots\n");
+		return -EINVAL;
+	}
+
+	if (slot_width < 8 || slot_width > 32) {
+		dev_err(i2s_sc_priv->dev, "TDM slot width must be 8 to 32 bits\n");
+		return -EINVAL;
+	}
+
+	if ((tx_mask >> slots) || (rx_mask >> slots)) {
+		dev_err(i2s_sc_priv->dev, "TDM slot mask has bits outside the slots\n");
+		return -EINVAL;
+	}

sound/soc/cdns/cdns-i2s-sc.c line 446

Quoted 10 lines
sound/soc/cdns/cdns-i2s-sc.c new file +10 -0
+
+	i2s_sc_priv->tdm_config.slots = slots;
+	i2s_sc_priv->tdm_config.slot_width = slot_width;
+	i2s_sc_priv->tdm_config.rx_mask = rx_mask;
+	i2s_sc_priv->tdm_config.tx_mask = tx_mask;
+
+	i2s_sc_priv->is_tdm_mode = true;
+
+	return 0;
+}

[Severity: Medium]
As reported by Sashiko on v4 [1], snd_soc_dai_set_tdm_slot() allows callers to disable TDM mode by passing slots == 0, in which case tx_mask, rx_mask, and slot_width are ignored.

In cdns_i2s_sc_set_tdm_slot(), checking slots < 1 rejects slots == 0 with -EINVAL, and nothing ever clears i2s_sc_priv->is_tdm_mode back to false.

Should cdns_i2s_sc_set_tdm_slot() handle !slots by setting i2s_sc_priv->is_tdm_mode = false and returning 0?

[ ... ]

Quoted 6 lines
sound/soc/cdns/cdns-i2s-sc.c new file +6 -0
+static int cdns_i2s_sc_probe(struct platform_device *pdev)
+{
+	struct cdns_i2s_sc_priv *i2s_sc_priv;
+	struct resource *res;
+	void __iomem *base;
+	int i, irq, ret;

[ ... ]

Quoted 19 lines
sound/soc/cdns/cdns-i2s-sc.c new file +19 -0
+	pm_runtime_get_noresume(&pdev->dev);
+	pm_runtime_set_active(&pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret) {
+		pm_runtime_put_noidle(&pdev->dev);
+		return dev_err_probe(&pdev->dev, ret, "Failed to enable runtime PM\n");
+	}
+
+	ret = cdns_i2s_sc_clks_enable(i2s_sc_priv);
+	if (ret) {
+		pm_runtime_put_noidle(&pdev->dev);
+		return dev_err_probe(&pdev->dev, ret, "Failed to enable clocks\n");
+	}
+
+	cdns_i2s_sc_rst(i2s_sc_priv);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		ret = irq;

sound/soc/cdns/cdns-i2s-sc.c line 1043

Quoted 10 lines
sound/soc/cdns/cdns-i2s-sc.c new file +10 -0
+		goto err_disable_clks;
+	}
+	i2s_sc_priv->irq = irq;
+
+	ret = devm_request_irq(&pdev->dev, irq, cdns_i2s_sc_isr, 0,
+			       dev_name(&pdev->dev), i2s_sc_priv);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
+		goto err_disable_clks;
+	}

[Severity: Medium]
As reported by Sashiko on v4 [2], devm_pm_runtime_enable() is registered in cdns_i2s_sc_probe() before cdns_i2s_sc_clks_enable(), before i2s_sc_priv->irq is initialized, and before devm_request_irq().

Because devres cleans up in reverse registration order, devm_request_irq() will free the IRQ before devm_pm_runtime_enable() disables runtime PM on unbind or probe failure. While runtime PM is still enabled after the IRQ is freed, can cdns_i2s_sc_runtime_suspend() or cdns_i2s_sc_runtime_resume() run and call disable_irq() or enable_irq() on i2s_sc_priv->irq?

Similarly, if cdns_i2s_sc_clks_enable(), platform_get_irq(), or devm_request_irq() fails in cdns_i2s_sc_probe(), pm_runtime_put_noidle() drops the usage count to zero while runtime PM is still enabled and marked active, before devres disables runtime PM.

Would it be safer to request the IRQ and enable clocks (for example via devm_clk_get_enabled() or a devm action) before enabling runtime PM?

Quoted 19 lines
sound/soc/cdns/cdns-i2s-sc.c new file +19 -0
+
+	/*
+	 * Let pm_runtime_put_sync() disable the clocks, and take regcache effect.
+	 * If CONFIG_PM is not enabled, the clock will stay powered.
+	 */
+	pm_runtime_put_sync(&pdev->dev);
+
+	ret = devm_snd_soc_register_component(&pdev->dev, &cdns_i2s_sc_component,
+					      &cdns_i2s_sc_dai, 1);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "Failed to register soc component\n");
+
+	return 0;
+
+err_disable_clks:
+	cdns_i2s_sc_clks_disable(i2s_sc_priv);
+	pm_runtime_put_noidle(&pdev->dev);
+	return ret;
+}

[ ... ]

sound/soc/cdns/cdns-i2s-sc.c line 1161

Quoted 8 lines
sound/soc/cdns/cdns-i2s-sc.c new file +8 -0
+static struct platform_driver cdns_i2s_sc_driver = {
+	.probe = cdns_i2s_sc_probe,
+	.driver = {
+		.name = DRV_NAME,
+		.pm = pm_ptr(&cdns_i2s_sc_pm_ops),
+		.of_match_table = cdns_i2s_sc_of_match,
+	},
+};

[Severity: Medium]
As reported by Sashiko on v4 [3], clk_hst and clk_i2s are acquired with devm_clk_get() and enabled via cdns_i2s_sc_clks_enable() in cdns_i2s_sc_probe(), relying on pm_runtime_put_sync() to invoke cdns_i2s_sc_runtime_suspend() and disable the clocks.

When CONFIG_PM is disabled, or when runtime suspend is prevented (such as via sysfs power/control), pm_runtime_put_sync() leaves clk_hst and clk_i2s prepared and enabled. If devm_snd_soc_register_component() then fails, or when cdns_i2s_sc_driver is unbound while runtime-active or with !CONFIG_PM (since there is no .remove callback and devm_pm_runtime_enable() only calls pm_runtime_disable()), won't clk_hst and clk_i2s remain prepared and enabled, leaking their clock enable references?

Also, on the error paths in cdns_i2s_sc_probe() before pm_runtime_put_sync(), should pm_runtime_set_suspended(&pdev->dev) be called to undo pm_runtime_set_active(&pdev->dev)?

[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
[3] https://lore.kernel.org/r/[email protected]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

PATCH RESEND v4 3/4 ASoC: dt-bindings: Add Cadence I2S-MC controller

In reply to [email protected]

From: Joakim Zhang <[email protected]>

Add the DT binding for the Cadence I2S-MC multi-channel controller integrated in the CIX SKY1 audio subsystem. The controller exposes a transmit DAI and a receive DAI and moves audio through a configurable set of its 8 data pins. Which pins are wired out and in which direction is fixed by the board design and described by the cix,pin-out-num, cix,pin-rx-mask and cix,pin-tx-mask properties.

---
 .../bindings/sound/cix,sky1-i2s-mc.yaml       | 119 ++++++++++++++++++
 1 file changed, 119 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/sound/cix,sky1-i2s-mc.yaml
Documentation/devicetree/bindings/sound/cix,sky1-i2s-mc.yaml new file +119 -0
new file mode 100644
index 000000000000..e750009edbdb
@@ -0,0 +1,119 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/sound/cix,sky1-i2s-mc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Cadence I2S-MC controller
+
+maintainers:
+  - Joakim Zhang <[email protected]>
+
+description: |
+  The Cadence I2S-MC multi-channel controller integrated in the CIX SKY1
+  audio subsystem. It provides up to 8-channel playback and capture through
+  a configurable number of I2S data pins, and exposes two DAIs: a transmit
+  DAI and a receive DAI.
+
+allOf:
+  - $ref: dai-common.yaml#
+
+properties:
+  compatible:
+    const: cix,sky1-i2s-mc
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 4
+
+  clock-names:
+    items:
+      - const: hst
+      - const: i2s
+      - const: audio-clk0
+      - const: audio-clk2
+
+  resets:
+    maxItems: 1
+
+  dmas:
+    minItems: 1
+    maxItems: 2
+    description:
+      One DMA channel for instances wired for a single direction, either
+      "tx" or "rx", or two channels for both transmit and receive.
+
+  dma-names:
+    minItems: 1
+    items:
+      - enum: [ tx, rx ]
+      - const: rx
+
+  "#sound-dai-cells":
+    const: 1
+    description:
+      Cell selects the DAI, 0 for the transmit DAI (i2s-mc-aif1) and
+      1 for the receive DAI (i2s-mc-aif2).
+
+  cix,pin-out-num:
+    $ref: /schemas/types.yaml#/definitions/uint8
+    minimum: 1
+    maximum: 8
+    description:
+      Number of I2S data output pins wired on this instance. Which of
+      the 8 controller data pins are wired out is fixed by the board
+      design and can be any subset.
+
+  cix,pin-rx-mask:
+    $ref: /schemas/types.yaml#/definitions/uint8
+    description:
+      Bit mask of I2S data pins used for capture, bit N selects data
+      pin N.
+
+  cix,pin-tx-mask:
+    $ref: /schemas/types.yaml#/definitions/uint8
+    description:
+      Bit mask of I2S data pins used for playback, bit N selects data
+      pin N. The rx and tx masks must not overlap, and the number of
+      set bits must not exceed cix,pin-out-num.
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - resets
+  - dmas
+  - dma-names
+  - "#sound-dai-cells"
+  - cix,pin-out-num
+  - cix,pin-rx-mask
+  - cix,pin-tx-mask
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    i2s@7050000 {
+        compatible = "cix,sky1-i2s-mc";
+        reg = <0x7050000 0x10000>;
+        interrupts = <GIC_SPI 222 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&audss_cru 17>, <&audss_cru 27>,
+                 <&scmi_clk 100>, <&scmi_clk 101>;
+        clock-names = "hst", "i2s", "audio-clk0", "audio-clk2";
+        resets = <&audss_cru 1>;
+        dmas = <&audss_dmac 2>, <&audss_dmac 3>;
+        dma-names = "tx", "rx";
+        #sound-dai-cells = <1>;
+        cix,pin-out-num = /bits/ 8 <2>;
+        cix,pin-rx-mask = /bits/ 8 <0x1>;
+        cix,pin-tx-mask = /bits/ 8 <0x2>;
+    };
Signature · 1 line
2.50.1
#5 lore raw

PATCH RESEND v4 4/4 ASoC: cdns: Add Cadence I2S-MC controller driver

In reply to [email protected]

From: Joakim Zhang <[email protected]>

Add support for the Cadence I2S-MC multi-channel controller found in the CIX SKY1 audio subsystem.

The controller moves up to 16 channels through a configurable set of its 8 data pins, each pin carrying two slots. Wired-out pins may sit at any pin index and are described by cix,pin-out-num, cix,pin-rx-mask and cix,pin-tx-mask. The driver exposes a transmit DAI and a receive DAI which can act as clock provider or consumer independently, and streams with fewer channels than the wired pins narrow the enabled pin mask at runtime.

The driver registers the dmaengine PCM helper, selects the audio reference clock parent for the 8 kHz or 11.025 kHz sample rate family and keeps the minimum functional-clock to bit-clock ratio required for safe clock domain crossing, with an extra margin cycle when the bit clock is sourced externally. Runtime and system suspend/resume restore the registers through the regcache.

---
 sound/soc/cdns/Kconfig       |   11 +
 sound/soc/cdns/Makefile      |    3 +
 sound/soc/cdns/cdns-i2s-mc.c | 1128 ++++++++++++++++++++++++++++++++++
 3 files changed, 1142 insertions(+)
 create mode 100644 sound/soc/cdns/cdns-i2s-mc.c
sound/soc/cdns/Kconfig +11 -0
index 06fd8fd6cb54..d0ef3ced06b2 100644
@@ -10,3 +10,14 @@ config SND_SOC_CDNS_I2S_SC
 	  controller found in the CIX SKY1 audio subsystem. It provides
 	  full-duplex stereo playback and capture in standard I2S and
 	  TDM modes with up to 16 slots.
+
+config SND_SOC_CDNS_I2S_MC
+	tristate "Cadence I2S-MC controller support"
+	depends on ARCH_CIX || COMPILE_TEST
+	select SND_SOC_GENERIC_DMAENGINE_PCM
+	select REGMAP_MMIO
+	help
+	  Say Y or M if you want to add support for the Cadence I2S-MC
+	  multi-channel controller found in the CIX SKY1 audio subsystem.
+	  It provides multi-channel playback and capture through a
+	  configurable number of I2S data pins.
sound/soc/cdns/Makefile +3 -0
index 6abfeef29e43..e440bb2bb5ca 100644
@@ -2,3 +2,6 @@
 
 snd-soc-cdns-i2s-sc-y := cdns-i2s-sc.o
 obj-$(CONFIG_SND_SOC_CDNS_I2S_SC) += snd-soc-cdns-i2s-sc.o
+
+snd-soc-cdns-i2s-mc-y := cdns-i2s-mc.o
+obj-$(CONFIG_SND_SOC_CDNS_I2S_MC) += snd-soc-cdns-i2s-mc.o
sound/soc/cdns/cdns-i2s-mc.c new file +1128 -0

1,128 lines not on this page · raw message

Signature · 1 line
2.50.1
#6 lore raw

Re: [PATCH v4 RESEND 4/4] ASoC: cdns: Add Cadence I2S-MC controller driver

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [Medium] ASoC: cdns: shared clk_i2s reparented in cdns_i2s_mc_hw_params() while active - [Medium] ASoC…

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Medium] ASoC: cdns: shared clk_i2s reparented in cdns_i2s_mc_hw_params() while active
- [Medium] ASoC: cdns: clock and runtime PM leak in cdns_i2s_mc_probe() and on unbind
- [Medium] ASoC: cdns: devm_pm_runtime_enable() ordered before IRQ in cdns_i2s_mc_probe()
- [Medium] ASoC: cdns: inverted DATA_WS_DEL bit for DSP_A and DSP_B in cdns_i2s_mc_set_fmt() --

commit c19d92817bbbcb2d8d57a40b0aa755f6cec87691
Author: Joakim Zhang <[email protected]>

ASoC: cdns: Add Cadence I2S-MC controller driver

This commit adds an ASoC driver for the Cadence I2S-MC multi-channel controller in the CIX SKY1 audio subsystem, supporting up to 16 channels across 8 configurable data pins with independent transmit and receive DAIs.

Quoted 5 lines
sound/soc/cdns/cdns-i2s-mc.c new file +0 -0
new file mode 100644
index 0000000000000..defbb93adfe76

[ ... ]

Quoted 7 lines
sound/soc/cdns/cdns-i2s-mc.c new file +7 -0
+static int cdns_i2s_mc_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
+{
+	struct cdns_i2s_mc_priv *i2s_mc_priv = snd_soc_dai_get_drvdata(cpu_dai);
+	struct device *dev = i2s_mc_priv->dev;
+	u32 ctrl = 0, dev_conf = 0;
+
+	dev_dbg(dev, "fmt = 0x%x\n", fmt);

[ ... ]

Quoted 32 lines
sound/soc/cdns/cdns-i2s-mc.c new file +32 -0
+		/* DAI hardware audio formats */
+		switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+		case SND_SOC_DAIFMT_I2S:
+			dev_conf |= I2S_DEV_CONF_TRAN_I2S_ALIGN_LR;
+			dev_conf &= ~(I2S_DEV_CONF_TRAN_APB_ALIGN_LR |
+				      I2S_DEV_CONF_TRAN_DATA_WS_DEL |
+				      I2S_DEV_CONF_TRAN_WS_DSP_MODE);
+			break;
+		case SND_SOC_DAIFMT_RIGHT_J:
+			dev_conf |= I2S_DEV_CONF_TRAN_DATA_WS_DEL;
+			dev_conf &= ~(I2S_DEV_CONF_TRAN_I2S_ALIGN_LR |
+				      I2S_DEV_CONF_TRAN_APB_ALIGN_LR |
+				      I2S_DEV_CONF_TRAN_WS_DSP_MODE);
+			break;
+		case SND_SOC_DAIFMT_LEFT_J:
+			dev_conf |= I2S_DEV_CONF_TRAN_I2S_ALIGN_LR | I2S_DEV_CONF_TRAN_DATA_WS_DEL;
+			dev_conf &= ~(I2S_DEV_CONF_TRAN_APB_ALIGN_LR |
+				      I2S_DEV_CONF_TRAN_WS_DSP_MODE);
+			break;
+		case SND_SOC_DAIFMT_DSP_A:
+			dev_conf |= I2S_DEV_CONF_TRAN_I2S_ALIGN_LR | I2S_DEV_CONF_TRAN_DATA_WS_DEL |
+				    I2S_DEV_CONF_TRAN_WS_DSP_MODE;
+			dev_conf &= ~I2S_DEV_CONF_TRAN_APB_ALIGN_LR;
+			break;
+		case SND_SOC_DAIFMT_DSP_B:
+			dev_conf |= I2S_DEV_CONF_TRAN_I2S_ALIGN_LR | I2S_DEV_CONF_TRAN_WS_DSP_MODE;
+			dev_conf &= ~(I2S_DEV_CONF_TRAN_APB_ALIGN_LR |
+				      I2S_DEV_CONF_TRAN_DATA_WS_DEL);
+			break;
+		default:
+			return -EINVAL;
+		}

[ ... ]

Quoted 19 lines
sound/soc/cdns/cdns-i2s-mc.c new file +19 -0
+		/* DAI hardware audio formats */
+		switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
+		case SND_SOC_DAIFMT_I2S:
+			dev_conf |= I2S_DEV_CONF_REC_I2S_ALIGN_LR;
+			dev_conf &= ~(I2S_DEV_CONF_REC_APB_ALIGN_LR | I2S_DEV_CONF_REC_DATA_WS_DEL |
+				      I2S_DEV_CONF_REC_WS_DSP_MODE);
+			break;
+		case SND_SOC_DAIFMT_RIGHT_J:
+			dev_conf |= I2S_DEV_CONF_REC_DATA_WS_DEL;
+			dev_conf &= ~(I2S_DEV_CONF_REC_I2S_ALIGN_LR |
+				      I2S_DEV_CONF_REC_APB_ALIGN_LR |
+				      I2S_DEV_CONF_REC_WS_DSP_MODE);
+			break;
+		case SND_SOC_DAIFMT_LEFT_J:
+			dev_conf |= I2S_DEV_CONF_REC_I2S_ALIGN_LR | I2S_DEV_CONF_REC_DATA_WS_DEL;
+			dev_conf &= ~(I2S_DEV_CONF_REC_APB_ALIGN_LR | I2S_DEV_CONF_REC_WS_DSP_MODE);
+			break;
+		case SND_SOC_DAIFMT_DSP_A:
+			dev_conf |= I2S_DEV_CONF_REC_I2S_ALIGN_LR | I2S_DEV_CONF_REC_DATA_WS_DEL |

sound/soc/cdns/cdns-i2s-mc.c line 444

Quoted 10 lines
sound/soc/cdns/cdns-i2s-mc.c new file +10 -0
+				    I2S_DEV_CONF_REC_WS_DSP_MODE;
+			dev_conf &= ~I2S_DEV_CONF_REC_APB_ALIGN_LR;
+			break;
+		case SND_SOC_DAIFMT_DSP_B:
+			dev_conf |= I2S_DEV_CONF_REC_I2S_ALIGN_LR | I2S_DEV_CONF_REC_WS_DSP_MODE;
+			dev_conf &= ~(I2S_DEV_CONF_REC_APB_ALIGN_LR | I2S_DEV_CONF_REC_DATA_WS_DEL);
+			break;
+		default:
+			return -EINVAL;
+		}

[Severity: Medium]
Are the data-to-word-select delay bits in dev_conf inverted between the dsp_a and dsp_b cases in cdns_i2s_mc_set_fmt() for both the transmit and receive DAIs?

In the standard i2s case above, clearing the delay bit in dev_conf selects a 1-bit-clock delay after the word-select transition, whereas in the left_j and right_j cases, setting the delay bit selects a 0-bit-clock delay.

However, the dsp_a case sets the delay bit (0-bit delay) and the dsp_b case clears it (1-bit delay), which shifts transmitted and received samples by one bit clock cycle relative to the standard dsp_a (1-bit delay) and dsp_b (0-bit delay) timings.

[ ... ]

Quoted 23 lines
sound/soc/cdns/cdns-i2s-mc.c new file +23 -0
+static int cdns_i2s_mc_hw_params(struct snd_pcm_substream *substream,
+				 struct snd_pcm_hw_params *params,
+				 struct snd_soc_dai *cpu_dai)
+{
+	struct cdns_i2s_mc_priv *i2s_mc_priv = snd_soc_dai_get_drvdata(cpu_dai);
+	struct device *dev = i2s_mc_priv->dev;
+	u32 rate, sample_rate = 0;
+	u32 slots, slot_width, resolution, ctrl;
+	unsigned long i2s_clk_rate;
+	u8 pin_tx_num, pin_rx_num;
+	struct clk *clk_parent;
+	bool is_master_mode;
+	int ret;
+
+	rate = params_rate(params);
+	slot_width = i2s_mc_priv->devtype_data->data_width;
+	dev_dbg(dev, "rate = %d, slot_width = %d\n", rate, slot_width);
+
+	/* switch clk mux to select the appropriate clk parent */
+	if (rate % 8000 == 0) {
+		/* Sampling rate is a multiple of 8KHz, select "audio-clk0" */
+		clk_parent = i2s_mc_priv->clks[AUDIO_CLK0];
+

sound/soc/cdns/cdns-i2s-mc.c line 586

Quoted 10 lines
sound/soc/cdns/cdns-i2s-mc.c new file +10 -0
+		ret = clk_set_parent(i2s_mc_priv->clk_i2s, clk_parent);
+	} else if (rate % 11025 == 0) {
+		/* Sampling rate is a multiple of 11.025KHz, select "audio-clk2" */
+		clk_parent = i2s_mc_priv->clks[AUDIO_CLK2];
+
+		ret = clk_set_parent(i2s_mc_priv->clk_i2s, clk_parent);
+	} else {
+		dev_err(i2s_mc_priv->dev, "Invalid sample rate\n");
+		return -EINVAL;
+	}

[Severity: Medium]
As reported by Sashiko on v4 [1], what happens if playback on i2s-mc-aif1 and capture on i2s-mc-aif2 are configured concurrently with sample rates from different clock families (for example, 48 kHz on one DAI and 44.1 kHz on the other)?

Because cdns_i2s_mc_dai[] exposes two independent DAIs sharing the single i2s_mc_priv->clk_i2s clock without cross-DAI rate family constraints or an active-stream check, calling clk_set_parent(i2s_mc_priv->clk_i2s, clk_parent) in cdns_i2s_mc_hw_params() switches the parent clock underneath an already active stream on the other DAI.

Can this corrupt the running stream's sample rate divider in the sample rate register and violate the minimum functional-clock to bit-clock ratio?

[ ... ]

Quoted 2 lines
sound/soc/cdns/cdns-i2s-mc.c new file +2 -0
+static int cdns_i2s_mc_probe(struct platform_device *pdev)
+{

[ ... ]

Quoted 19 lines
sound/soc/cdns/cdns-i2s-mc.c new file +19 -0
+	pm_runtime_get_noresume(&pdev->dev);
+	pm_runtime_set_active(&pdev->dev);
+	ret = devm_pm_runtime_enable(&pdev->dev);
+	if (ret) {
+		pm_runtime_put_noidle(&pdev->dev);
+		return dev_err_probe(&pdev->dev, ret, "Failed to enable runtime PM\n");
+	}
+
+	ret = cdns_i2s_mc_clks_enable(i2s_mc_priv);
+	if (ret) {
+		pm_runtime_put_noidle(&pdev->dev);
+		return dev_err_probe(&pdev->dev, ret, "Failed to enable clocks\n");
+	}
+
+	cdns_i2s_mc_rst(i2s_mc_priv);
+
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		ret = irq;

sound/soc/cdns/cdns-i2s-mc.c line 1004

Quoted 10 lines
sound/soc/cdns/cdns-i2s-mc.c new file +10 -0
+		goto err_disable_clks;
+	}
+	i2s_mc_priv->irq = irq;
+
+	ret = devm_request_irq(&pdev->dev, irq, cdns_i2s_mc_isr, 0,
+			       dev_name(&pdev->dev), i2s_mc_priv);
+	if (ret) {
+		dev_err(&pdev->dev, "Failed to request irq: %d\n", ret);
+		goto err_disable_clks;
+	}

[Severity: Medium]
As reported by Sashiko on v4 [2], since devm_pm_runtime_enable() is registered before i2s_mc_priv->irq is initialized and before devm_request_irq() is called in cdns_i2s_mc_probe(), devres teardown on driver unbind or late probe failure will free the interrupt before disabling runtime power management.

During teardown, can cdns_i2s_mc_runtime_resume() or cdns_i2s_mc_runtime_suspend() still run and call enable_irq() or disable_irq() on i2s_mc_priv->irq after it has already been freed?

Quoted 9 lines
sound/soc/cdns/cdns-i2s-mc.c new file +9 -0
+
+	/*
+	 * Let pm_runtime_put_sync() disable the clocks, and take regcache effect.
+	 * If CONFIG_PM is not enabled, the clock will stay powered.
+	 */
+	pm_runtime_put_sync(&pdev->dev);
+
+	ret = devm_snd_soc_register_component(&pdev->dev, &cdns_i2s_mc_component,
+					      cdns_i2s_mc_dai, ARRAY_SIZE(cdns_i2s_mc_dai));

sound/soc/cdns/cdns-i2s-mc.c line 1023

Quoted 10 lines
sound/soc/cdns/cdns-i2s-mc.c new file +10 -0
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "Failed to register soc component\n");
+
+	return 0;
+
+err_disable_clks:
+	cdns_i2s_mc_clks_disable(i2s_mc_priv);
+	pm_runtime_put_noidle(&pdev->dev);
+	return ret;
+}

[Severity: Medium]
As reported by Sashiko on v4 [3], does cdns_i2s_mc_probe() leak the prepared and enabled clock references on i2s_mc_priv->clk_hst and i2s_mc_priv->clk_i2s when runtime power management is disabled in the kernel configuration or prevented via sysfs?

Specifically:

1. If devm_snd_soc_register_component() fails when pm_runtime_put_sync() did not suspend the device, cdns_i2s_mc_probe() returns without calling cdns_i2s_mc_clks_disable(i2s_mc_priv).

2. Because cdns_i2s_mc_driver defines no remove callback and registers no devm action to disable the clocks, unbinding the driver while the device is runtime-active or when power management is disabled leaves clk_hst and clk_i2s enabled when devm_clk_get() releases them.

3. On the earlier error paths after pm_runtime_set_active(&pdev->dev), including err_disable_clks, pm_runtime_set_suspended(&pdev->dev) is not called, leaving the runtime power management state marked active with clocks disabled.

[1] https://lore.kernel.org/r/[email protected]
[2] https://lore.kernel.org/r/[email protected]
[3] https://lore.kernel.org/r/[email protected]

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4