Skip to contentSkip to conversation

Enable DMA mode on Intel Keem Bay platform

PATCH Superseded Michael Sit Wei Hong 3 participants 7 messages Dec 15, 2020 – Jan 13, 2021

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Enable DMA mode on Intel Keem Bay platform

v1: Initial patch version, to enable DMA mode on Intel Keembay platform.

Michael Sit Wei Hong (2):
dt-bindings: sound: intel, keembay-i2s: Add info for device to use DMA
ASoC: Intel: KMB: Enable DMA transfer mode

 .../bindings/sound/intel,keembay-i2s.yaml     |  14 ++
 sound/soc/intel/Kconfig                       |   2 +
 sound/soc/intel/keembay/kmb_platform.c        | 157 ++++++++++++++++--
 sound/soc/intel/keembay/kmb_platform.h        |   9 +
 4 files changed, 167 insertions(+), 15 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 dt-bindings: sound: intel, keembay-i2s: Add info for device to use DMA

Add descriptions for entries needed for audio device to use DMA channels for audio playback and capture.

---
 .../bindings/sound/intel,keembay-i2s.yaml          | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Documentation/devicetree/bindings/sound/intel,keembay-i2s.yaml +14 -0
index d346e61ab708..e0658f122cbb 100644
@@ -45,6 +45,18 @@ properties:
       - const: osc
       - const: apb_clk
 
+  dmas:
+    items:
+      - description: DMA controller phandle and DMA channel
+                     for TX and RX
+
+  dma-names:
+    items:
+      - description: "tx" for the transmit channel
+                     "rx" for the receive channel
+      - const: tx
+      - const: rx
+
 required:
   - compatible
   - "#sound-dai-cells"
@@ -70,4 +82,6 @@ examples:
          interrupts = <GIC_SPI 120 IRQ_TYPE_LEVEL_HIGH>;
          clock-names = "osc", "apb_clk";
          clocks = <&scmi_clk KEEM_BAY_PSS_AUX_I2S3>, <&scmi_clk KEEM_BAY_PSS_I2S3>;
+         dmas = <&axi_dma0 29 &axi_dma0 33>;
+         dma-names = "tx", "rx";
      };
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/2 ASoC: Intel: KMB: Enable DMA transfer mode

In reply to Michael Sit Wei Hong

Enable DMA transfer mode for Intel Keem Bay ASoC platform driver.

The driver will search the device tree for DMA resources at boot time to enable DMA transfer mode, and will proceed to use DMA transfer if the resource is available, otherwise the default PIO mode will be used.

---
 sound/soc/intel/Kconfig                |   2 +
 sound/soc/intel/keembay/kmb_platform.c | 157 ++++++++++++++++++++++---
 sound/soc/intel/keembay/kmb_platform.h |   9 ++
 3 files changed, 153 insertions(+), 15 deletions(-)
sound/soc/intel/Kconfig +2 -0
index a5b446d5af19..6114dadfc52f 100644
@@ -200,6 +200,8 @@ config SND_SOC_INTEL_KEEMBAY
 	tristate "Keembay Platforms"
 	depends on ARM64 || COMPILE_TEST
 	depends on COMMON_CLK
+	select SND_DMAENGINE_PCM
+	select SND_SOC_GENERIC_DMAENGINE_PCM
 	help
 	  If you have a Intel Keembay platform then enable this option
 	  by saying Y or m.
sound/soc/intel/keembay/kmb_platform.c +142 -15

248 lines not on this page · raw message

sound/soc/intel/keembay/kmb_platform.h +9 -0
index 9756b132c12f..fd5341b66279 100644
@@ -12,6 +12,7 @@
 #include <linux/bits.h>
 #include <linux/bitfield.h>
 #include <linux/types.h>
+#include <sound/dmaengine_pcm.h>
 
 /* Register values with reference to KMB databook v1.1 */
 /* common register for all channel */
@@ -103,7 +104,12 @@
 #define DW_I2S_MASTER	BIT(3)
 
 #define I2S_RXDMA	0x01C0
+#define I2S_RRXDMA	0x01C4
 #define I2S_TXDMA	0x01C8
+#define I2S_RTXDMA	0x01CC
+#define I2S_DMACR	0x0200
+#define I2S_DMAEN_RXBLOCK	(1 << 16)
+#define I2S_DMAEN_TXBLOCK	(1 << 17)
 
 /*
  * struct i2s_clk_config_data - represent i2s clk configuration data
@@ -131,6 +137,9 @@ struct kmb_i2s_info {
 	u32 xfer_resolution;
 	u32 fifo_th;
 	bool master;
+	/* data related to DMA transfers b/w i2s and DMAC */
+	struct snd_dmaengine_dai_dma_data play_dma_data;
+	struct snd_dmaengine_dai_dma_data capture_dma_data;
 
 	struct i2s_clk_config_data config;
 	int (*i2s_clk_cfg)(struct i2s_clk_config_data *config);
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH 2/2] ASoC: Intel: KMB: Enable DMA transfer mode

Quoted 19 lines · Michael Sit Wei Hong

[...]

sound/soc/intel/keembay/kmb_platform.c +18 -0
+static inline void kmb_i2s_enable_dma(struct kmb_i2s_info *kmb_i2s, u32 stream)
+{
+	u32 dma_reg;
+
+	dma_reg = readl(kmb_i2s->i2s_base + I2S_DMACR);
+	/* Enable DMA handshake for stream */
+	if (stream == SNDRV_PCM_STREAM_PLAYBACK)
+		dma_reg |= I2S_DMAEN_TXBLOCK;
+	else
+		dma_reg |= I2S_DMAEN_RXBLOCK;
+
+	writel(dma_reg, kmb_i2s->i2s_base + I2S_DMACR);
+}
+
+static inline void kmb_i2s_disable_dma(struct kmb_i2s_info *kmb_i2s, u32 stream)
+{
+	u32 dma_reg;
+

sound/soc/intel/keembay/kmb_platform.c static const struct snd_soc_component_driver kmb_component = { · line 392

Quoted 10 lines
sound/soc/intel/keembay/kmb_platform.c +10 -0
+	dma_reg = readl(kmb_i2s->i2s_base + I2S_DMACR);
+	/* Disable DMA handshake for stream */
+	if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		dma_reg &= ~I2S_DMAEN_TXBLOCK;
+		writel(1, kmb_i2s->i2s_base + I2S_RTXDMA);
+	} else {
+		dma_reg &= ~I2S_DMAEN_RXBLOCK;
+		writel(1, kmb_i2s->i2s_base + I2S_RRXDMA);
+	}
+	writel(dma_reg, kmb_i2s->i2s_base + I2S_DMACR);

Does this need locking? I believe it is possible for the startup callback of the playback and capture stream to be called concurrently.

Quoted 18 lines
sound/soc/intel/keembay/kmb_platform.c +7 -1
+}
+
  static void kmb_i2s_start(struct kmb_i2s_info *kmb_i2s,
  			  struct snd_pcm_substream *substream)
  {
@@ -356,7 +405,11 @@ static void kmb_i2s_start(struct kmb_i2s_info *kmb_i2s,
  	else
  		writel(1, kmb_i2s->i2s_base + IRER);
 
-	kmb_i2s_irq_trigger(kmb_i2s, substream->stream, config->chan_nr, true);
+	if (kmb_i2s->use_pio)
+		kmb_i2s_irq_trigger(kmb_i2s, substream->stream,
+				    config->chan_nr, true);
+	else
+		kmb_i2s_enable_dma(kmb_i2s, substream->stream);
 
  	if (kmb_i2s->master)
  		writel(1, kmb_i2s->i2s_base + CER);

[...]

#4 lore raw

RE: [PATCH 2/2] ASoC: Intel: KMB: Enable DMA transfer mode

Quoted 41 lines

-----Original Message-----
From: Lars-Peter Clausen <[email protected]>
Sent: Tuesday, 15 December, 2020 5:41 PM
To: Sit, Michael Wei Hong <[email protected]>; [email protected]
Cc: Rojewski, Cezary <[email protected]>; [email protected]; Sia, Jee Heng <[email protected]>; pierre- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/2] ASoC: Intel: KMB: Enable DMA transfer mode

Quoted 2 lines · Michael Sit Wei Hong

[...]
+static inline void kmb_i2s_enable_dma(struct kmb_i2s_info

*kmb_i2s,

sound/soc/intel/keembay/kmb_platform.c static const struct snd_soc_component_driver kmb_component = {

Quoted 13 lines
sound/soc/intel/keembay/kmb_platform.c +13 -0
+u32 stream) {
+	u32 dma_reg;
+
+	dma_reg = readl(kmb_i2s->i2s_base + I2S_DMACR);
+	/* Enable DMA handshake for stream */
+	if (stream == SNDRV_PCM_STREAM_PLAYBACK)
+		dma_reg |= I2S_DMAEN_TXBLOCK;
+	else
+		dma_reg |= I2S_DMAEN_RXBLOCK;
+
+	writel(dma_reg, kmb_i2s->i2s_base + I2S_DMACR); }
+
+static inline void kmb_i2s_disable_dma(struct kmb_i2s_info

*kmb_i2s,

Quoted 9 lines
sound/soc/intel/keembay/kmb_platform.c +9 -0
+u32 stream) {
+	u32 dma_reg;
+
+	dma_reg = readl(kmb_i2s->i2s_base + I2S_DMACR);
+	/* Disable DMA handshake for stream */
+	if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		dma_reg &= ~I2S_DMAEN_TXBLOCK;
+		writel(1, kmb_i2s->i2s_base + I2S_RTXDMA);
+	} else {
Quoted 9 lines

sound/soc/intel/keembay/kmb_platform.c static const struct snd_soc_component_driver kmb_component = { · line 392

Quoted 4 lines
sound/soc/intel/keembay/kmb_platform.c +4 -0
+		dma_reg &= ~I2S_DMAEN_RXBLOCK;
+		writel(1, kmb_i2s->i2s_base + I2S_RRXDMA);
+	}
+	writel(dma_reg, kmb_i2s->i2s_base + I2S_DMACR);

Does this need locking? I believe it is possible for the startup callback of the playback and capture stream to be called concurrently.

Pierre did raised this concern previously and checked that the upper layers has already a locking mechanism in place before this is called. If we look at the uses of snd_soc_dai_startup() and snd_soc_dai_shutdown(), they are all protected by mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);

Quoted 23 lines

sound/soc/intel/keembay/kmb_platform.c static void kmb_i2s_start(struct

Quoted 6 lines
sound/soc/intel/keembay/kmb_platform.c +2 -0
+}
+
  static void kmb_i2s_start(struct kmb_i2s_info *kmb_i2s,
  			  struct snd_pcm_substream *substream)
  {
@@ -356,7 +405,11 @@ static void kmb_i2s_start(struct

kmb_i2s_info *kmb_i2s,

sound/soc/intel/keembay/kmb_platform.c static void kmb_i2s_start(struct kmb_i2s_info *kmb_i2s,

Quoted 4 lines
sound/soc/intel/keembay/kmb_platform.c +0 -1
  	else
  		writel(1, kmb_i2s->i2s_base + IRER);
 
-	kmb_i2s_irq_trigger(kmb_i2s, substream->stream,

config->chan_nr, true);

Quoted 10 lines
sound/soc/intel/keembay/kmb_platform.c +5 -0
+	if (kmb_i2s->use_pio)
+		kmb_i2s_irq_trigger(kmb_i2s, substream-
 stream,
+				    config->chan_nr, true);
+	else
+		kmb_i2s_enable_dma(kmb_i2s, substream-
 stream);
 
  	if (kmb_i2s->master)
  		writel(1, kmb_i2s->i2s_base + CER);

[...]

#5 lore raw

RE: [PATCH 2/2] ASoC: Intel: KMB: Enable DMA transfer mode

Quoted 64 lines

-----Original Message-----
From: Alsa-devel <[email protected]> On Behalf Of Sit, Michael Wei Hong
Sent: Tuesday, 15 December, 2020 6:15 PM
To: Lars-Peter Clausen <[email protected]>; alsa-devel@alsa- project.org
Cc: Rojewski, Cezary <[email protected]>; [email protected]; Sia, Jee Heng <[email protected]>; pierre- [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH 2/2] ASoC: Intel: KMB: Enable DMA transfer mode

Quoted 6 lines

-----Original Message-----
From: Lars-Peter Clausen <[email protected]>
Sent: Tuesday, 15 December, 2020 5:41 PM
To: Sit, Michael Wei Hong <[email protected]>; [email protected]
Cc: Rojewski, Cezary <[email protected]>;

[email protected]; Sia,

Quoted 4 lines

Jee Heng <[email protected]>; pierre- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/2] ASoC: Intel: KMB: Enable DMA

transfer mode

Quoted 19 lines · Michael Sit Wei Hong
Quoted 2 lines

[...]
+static inline void kmb_i2s_enable_dma(struct kmb_i2s_info

*kmb_i2s,

sound/soc/intel/keembay/kmb_platform.c static const struct snd_soc_component_driver kmb_component = {

Quoted 13 lines
sound/soc/intel/keembay/kmb_platform.c +13 -0
+u32 stream) {
+	u32 dma_reg;
+
+	dma_reg = readl(kmb_i2s->i2s_base + I2S_DMACR);
+	/* Enable DMA handshake for stream */
+	if (stream == SNDRV_PCM_STREAM_PLAYBACK)
+		dma_reg |= I2S_DMAEN_TXBLOCK;
+	else
+		dma_reg |= I2S_DMAEN_RXBLOCK;
+
+	writel(dma_reg, kmb_i2s->i2s_base + I2S_DMACR); }
+
+static inline void kmb_i2s_disable_dma(struct kmb_i2s_info

*kmb_i2s,

Quoted 16 lines

sound/soc/intel/keembay/kmb_platform.c static const struct snd_soc_component_driver kmb_component = { · line 392

Quoted 13 lines
sound/soc/intel/keembay/kmb_platform.c +13 -0
+u32 stream) {
+	u32 dma_reg;
+
+	dma_reg = readl(kmb_i2s->i2s_base + I2S_DMACR);
+	/* Disable DMA handshake for stream */
+	if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
+		dma_reg &= ~I2S_DMAEN_TXBLOCK;
+		writel(1, kmb_i2s->i2s_base + I2S_RTXDMA);
+	} else {
+		dma_reg &= ~I2S_DMAEN_RXBLOCK;
+		writel(1, kmb_i2s->i2s_base + I2S_RRXDMA);
+	}
+	writel(dma_reg, kmb_i2s->i2s_base + I2S_DMACR);

Does this need locking? I believe it is possible for the startup callback of the playback and capture stream to be called

Quoted 32 lines

concurrently.

Quoted 1 line

Pierre did raised this concern previously and checked that the upper layers has already a locking mechanism in place before this is called.
If we look at the uses of snd_soc_dai_startup() and snd_soc_dai_shutdown(), they are all protected by mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card-

Quoted 24 lines

pcm_subclass);

sound/soc/intel/keembay/kmb_platform.c static void kmb_i2s_start(struct

Quoted 6 lines
sound/soc/intel/keembay/kmb_platform.c +2 -0
+}
+
  static void kmb_i2s_start(struct kmb_i2s_info *kmb_i2s,
  			  struct snd_pcm_substream *substream)
  {
@@ -356,7 +405,11 @@ static void kmb_i2s_start(struct

kmb_i2s_info *kmb_i2s,

sound/soc/intel/keembay/kmb_platform.c static void kmb_i2s_start(struct kmb_i2s_info *kmb_i2s,

Quoted 4 lines
sound/soc/intel/keembay/kmb_platform.c +0 -1
  	else
  		writel(1, kmb_i2s->i2s_base + IRER);
 
-	kmb_i2s_irq_trigger(kmb_i2s, substream->stream,

config->chan_nr, true);

Quoted 10 lines
sound/soc/intel/keembay/kmb_platform.c +5 -0
+	if (kmb_i2s->use_pio)
+		kmb_i2s_irq_trigger(kmb_i2s, substream-
 stream,
+				    config->chan_nr, true);
+	else
+		kmb_i2s_enable_dma(kmb_i2s, substream-
 stream);
 
  	if (kmb_i2s->master)
  		writel(1, kmb_i2s->i2s_base + CER);

[...]

Any further comments on this patch set?

maintainer
#6 lore raw
In reply to Michael Sit Wei Hong
Quoted 9 lines · Michael Sit Wei Hong

Michael Sit Wei Hong (2):
dt-bindings: sound: intel, keembay-i2s: Add info for device to use DMA
ASoC: Intel: KMB: Enable DMA transfer mode

 .../bindings/sound/intel,keembay-i2s.yaml     |  14 ++
 sound/soc/intel/Kconfig                       |   2 +
 sound/soc/intel/keembay/kmb_platform.c        | 157 ++++++++++++++++--
 sound/soc/intel/keembay/kmb_platform.h        |   9 +
 4 files changed, 167 insertions(+), 15 deletions(-)

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] dt-bindings: sound: intel, keembay-i2s: Add info for device to use DMA

      commit: 9ddaa1e6181b3d33080f2ed7c27cb0bba819e562
[2/2] ASoC: Intel: KMB: Enable DMA transfer mode
      commit: 11b943c06a1c1baafb0325896e666d77f5ac78b8

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark