Skip to contentSkip to conversation

Add Amlogic general DMA

PATCH Superseded Xianwei Zhao 3 participants 7 messages Mar 9 – Mar 19

Subsystems (3)

v6 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v6 cover Add Amlogic general DMA

Add DMA driver and bindigns for the Amlogic SoCs.

---
Changes in v6:
- Some minor modifications according to Frank's suggestion.
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Rename head file and rename macro definition.
- Rename the subject in [2/3] from "dma" to "dmaengine".
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Support split transfer when data len > MAX_LEN.
- When a module fails or exits, perform de-initialization.
- Some other minor modifications.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Adjust the format of binding according to Frank's suggestion.
- Some code format modified according to Frank's suggestion.
- Support one prep_sg and one submit, drop multi prep_sg and one submit.
- Keep pre state when resume from pause status.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Introduce what the DMA is used for in the A9 SoC.
- Some minor modifications were made according to Krzysztof's suggestions.
- Some modifications were made according to Neil's suggestions.
- Fix a build error.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Xianwei Zhao (3):
dt-bindings: dma: Add Amlogic A9 SoC DMA
dmaengine: amlogic: Add general DMA driver for A9
MAINTAINERS: Add an entry for Amlogic DMA driver

 .../devicetree/bindings/dma/amlogic,a9-dma.yaml    |  65 +++
 MAINTAINERS                                        |   7 +
 drivers/dma/Kconfig                                |   9 +
 drivers/dma/Makefile                               |   1 +
 drivers/dma/amlogic-dma.c                          | 585 +++++++++++++++++++++
 include/dt-bindings/dma/amlogic,a9-dma.h           |   8 +
 6 files changed, 675 insertions(+)

---
base-commit: 3d2d1059cae3abab771576a7ee7f59d9627cfb8e
change-id: 20251215-amlogic-dma-79477d5cd264

Best regards,

Signature · 1 line
Xianwei Zhao <[email protected]>
#1 lore raw

PATCH v6 1/3 dt-bindings: dma: Add Amlogic A9 SoC DMA

Add documentation describing the Amlogic A9 SoC DMA. And add the properties specific values defines into a new include file.

---
 .../devicetree/bindings/dma/amlogic,a9-dma.yaml    | 65 ++++++++++++++++++++++
 include/dt-bindings/dma/amlogic,a9-dma.h           |  8 +++
 2 files changed, 73 insertions(+)
Documentation/devicetree/bindings/dma/amlogic,a9-dma.yaml new file +65 -0
new file mode 100644
index 000000000000..efd7b2602c33
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/amlogic,a9-dma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Amlogic general DMA controller
+
+description:
+  This is a general-purpose peripheral DMA controller. It currently supports
+  major peripherals including I2C, I3C, PIO, and CAN-BUS. Transmit and receive
+  for the same peripheral use two separate channels, controlled by different
+  register sets. I2C and I3C transfer data in 1-byte units, while PIO and
+  CAN-BUS transfer data in 4-byte units. From the controller’s perspective,
+  there is no significant difference.
+
+maintainers:
+  - Xianwei Zhao <[email protected]>
+
+properties:
+  compatible:
+    const: amlogic,a9-dma
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    maxItems: 1
+
+  clock-names:
+    const: sys
+
+  '#dma-cells':
+    const: 2
+
+  dma-channels:
+    maximum: 64
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - '#dma-cells'
+  - dma-channels
+
+allOf:
+  - $ref: dma-controller.yaml#
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    dma-controller@fe400000{
+        compatible = "amlogic,a9-dma";
+        reg = <0xfe400000 0x4000>;
+        interrupts = <GIC_SPI 35 IRQ_TYPE_EDGE_RISING>;
+        clocks = <&clkc 45>;
+        #dma-cells = <2>;
+        dma-channels = <28>;
+    };
include/dt-bindings/dma/amlogic,a9-dma.h new file +8 -0
new file mode 100644
index 000000000000..c59c2fd4b956
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: (GPL-2.0 OR MIT) */
+
+#ifndef __DT_BINDINGS_DMA_AMLOGIC_DMA_H__
+#define __DT_BINDINGS_DMA_AMLOGIC_DMA_H__
+
+#define DMA_TX			0
+#define DMA_RX			1
+#endif /* __DT_BINDINGS_DMA_AMLOGIC_DMA_H__ */
Signature · 1 line
2.52.0
#2 lore raw

PATCH v6 2/3 dmaengine: amlogic: Add general DMA driver for A9

In reply to Xianwei Zhao

Amlogic A9 SoCs include a general-purpose DMA controller that can be used by multiple peripherals, such as I2C PIO and I3C. Each peripheral group is associated with a dedicated DMA channel in hardware.

---
 drivers/dma/Kconfig       |   9 +
 drivers/dma/Makefile      |   1 +
 drivers/dma/amlogic-dma.c | 585 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 595 insertions(+)
drivers/dma/Kconfig +9 -0
index 66cda7cc9f7a..8d4578513acf 100644
@@ -85,6 +85,15 @@ config AMCC_PPC440SPE_ADMA
 	help
 	  Enable support for the AMCC PPC440SPe RAID engines.
 
+config AMLOGIC_DMA
+	tristate "Amlogic general DMA support"
+	depends on ARCH_MESON || COMPILE_TEST
+	select DMA_ENGINE
+	select REGMAP_MMIO
+	help
+	  Enable support for the Amlogic general DMA engines. THis DMA
+	  controller is used some Amlogic SoCs, such as A9.
+
 config APPLE_ADMAC
 	tristate "Apple ADMAC support"
 	depends on ARCH_APPLE || COMPILE_TEST
drivers/dma/Makefile +1 -0
index a54d7688392b..fc28dade5b69 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_DMATEST) += dmatest.o
 obj-$(CONFIG_ALTERA_MSGDMA) += altera-msgdma.o
 obj-$(CONFIG_AMBA_PL08X) += amba-pl08x.o
 obj-$(CONFIG_AMCC_PPC440SPE_ADMA) += ppc4xx/
+obj-$(CONFIG_AMLOGIC_DMA) += amlogic-dma.o
 obj-$(CONFIG_APPLE_ADMAC) += apple-admac.o
 obj-$(CONFIG_ARM_DMA350) += arm-dma350.o
 obj-$(CONFIG_AT_HDMAC) += at_hdmac.o
drivers/dma/amlogic-dma.c new file +585 -0

585 lines not on this page · raw message

Signature · 1 line
2.52.0
Reviewed-by on v6 2/3
#3 lore raw

Re: [PATCH v6 2/3] dmaengine: amlogic: Add general DMA driver for A9

Quoted 8 lines · On Mon, Mar 09, 2026 at 06:33:53AM +0000, Xianwei Zhao via B4 Relay wrote:

From: Xianwei Zhao <[email protected]>

Amlogic A9 SoCs include a general-purpose DMA controller that can be used by multiple peripherals, such as I2C PIO and I3C. Each peripheral group is associated with a dedicated DMA channel in hardware.

---

maintainer
#4 lore raw

Re: [PATCH v6 2/3] dmaengine: amlogic: Add general DMA driver for A9

In reply to Xianwei Zhao

drivers/dma/amlogic-dma.c line 145

Quoted 6 lines · On 09-03-26, 06:33, Xianwei Zhao via B4 Relay wrote:

From: Xianwei Zhao <[email protected]>

drivers/dma/amlogic-dma.c new file +4 -0
+static dma_cookie_t aml_dma_tx_submit(struct dma_async_tx_descriptor *tx)
+{
+	return dma_cookie_assign(tx);
+}

You lost tx, why was it not saved into a queue?

Quoted 13 lines
drivers/dma/amlogic-dma.c new file +13 -0
+static struct dma_async_tx_descriptor *aml_dma_prep_slave_sg
+		(struct dma_chan *chan, struct scatterlist *sgl,
+		unsigned int sg_len, enum dma_transfer_direction direction,
+		unsigned long flags, void *context)
+{
+	struct aml_dma_chan *aml_chan = to_aml_dma_chan(chan);
+	struct aml_dma_dev *aml_dma = aml_chan->aml_dma;
+	struct aml_dma_sg_link *sg_link;
+	struct scatterlist *sg;
+	int idx = 0;
+	u64 paddr;
+	u32 reg, link_count, avail, chan_id;
+	u32 i;

drivers/dma/amlogic-dma.c line 218

Quoted 10 lines
drivers/dma/amlogic-dma.c new file +10 -0
+
+	if (aml_chan->direction != direction) {
+		dev_err(aml_dma->dma_device.dev, "direction not support\n");
+		return NULL;
+	}
+
+	switch (aml_chan->status) {
+	case DMA_IN_PROGRESS:
+		dev_err(aml_dma->dma_device.dev, "not support multi tx_desciptor\n");
+		return NULL;

And why is that. You are preparing a descriptor and keep it ready and submit after the current one finishes

Quoted 34 lines
drivers/dma/amlogic-dma.c new file +34 -0
+
+	case DMA_COMPLETE:
+		aml_chan->data_len = 0;
+		chan_id = aml_chan->chan_id;
+		reg = (direction == DMA_DEV_TO_MEM) ? WCH_INT_MASK : RCH_INT_MASK;
+		regmap_set_bits(aml_dma->regmap, reg, BIT(chan_id));
+
+		break;
+	default:
+		dev_err(aml_dma->dma_device.dev, "status error\n");
+		return NULL;
+	}
+
+	link_count = sg_nents_for_dma(sgl, sg_len, SG_MAX_LEN);
+
+	if (link_count > DMA_MAX_LINK) {
+		dev_err(aml_dma->dma_device.dev,
+			"maximum number of sg exceeded: %d > %d\n",
+			sg_len, DMA_MAX_LINK);
+		aml_chan->status = DMA_ERROR;
+		return NULL;
+	}
+
+	aml_chan->status = DMA_IN_PROGRESS;
+
+	for_each_sg(sgl, sg, sg_len, i) {
+		avail = sg_dma_len(sg);
+		paddr = sg->dma_address;
+		while (avail > SG_MAX_LEN) {
+			sg_link = &aml_chan->sg_link[idx++];
+			/* set dma address and len  to sglink*/
+			sg_link->address = paddr;
+			sg_link->ctl = FIELD_PREP(LINK_LEN, SG_MAX_LEN);
+			paddr = paddr + SG_MAX_LEN;

drivers/dma/amlogic-dma.c line 262

Quoted 10 lines
drivers/dma/amlogic-dma.c new file +10 -0
+			avail = avail - SG_MAX_LEN;
+		}
+		sg_link = &aml_chan->sg_link[idx++];
+		/* set dma address and len  to sglink*/
+		sg_link->address = paddr;
+		sg_link->ctl = FIELD_PREP(LINK_LEN, avail);
+
+		aml_chan->data_len += sg_dma_len(sg);
+	}
+	aml_chan->sg_link_cnt = idx;

There is no descriptor management here. You are directly writing to channel. This is _very_ inefficient and defeats the use of dmaengine.

Please revise the driver. Implement queues to manage multiple txns and we have vchan to help you implement these, so take use of that

Signature · 1 line
~Vinod
#5 lore raw

Re: [PATCH v6 2/3] dmaengine: amlogic: Add general DMA driver for A9

Hi Vinod,
Thanks for your advice.

Quoted 82 lines · Vinod Koul

drivers/dma/amlogic-dma.c line 145

Quoted 5 lines · On 09-03-26, 06:33, Xianwei Zhao via B4 Relay wrote:

From: Xianwei Zhao<[email protected]>

drivers/dma/amlogic-dma.c new file +4 -0
+static dma_cookie_t aml_dma_tx_submit(struct dma_async_tx_descriptor *tx)
+{
+     return dma_cookie_assign(tx);
+}

You lost tx, why was it not saved into a queue?

Quoted 13 lines
drivers/dma/amlogic-dma.c new file +13 -0
+static struct dma_async_tx_descriptor *aml_dma_prep_slave_sg
+             (struct dma_chan *chan, struct scatterlist *sgl,
+             unsigned int sg_len, enum dma_transfer_direction direction,
+             unsigned long flags, void *context)
+{
+     struct aml_dma_chan *aml_chan = to_aml_dma_chan(chan);
+     struct aml_dma_dev *aml_dma = aml_chan->aml_dma;
+     struct aml_dma_sg_link *sg_link;
+     struct scatterlist *sg;
+     int idx = 0;
+     u64 paddr;
+     u32 reg, link_count, avail, chan_id;
+     u32 i;

drivers/dma/amlogic-dma.c line 218

Quoted 10 lines
drivers/dma/amlogic-dma.c new file +10 -0
+
+     if (aml_chan->direction != direction) {
+             dev_err(aml_dma->dma_device.dev, "direction not support\n");
+             return NULL;
+     }
+
+     switch (aml_chan->status) {
+     case DMA_IN_PROGRESS:
+             dev_err(aml_dma->dma_device.dev, "not support multi tx_desciptor\n");
+             return NULL;

And why is that. You are preparing a descriptor and keep it ready and submit after the current one finishes

Quoted 34 lines
drivers/dma/amlogic-dma.c new file +34 -0
+
+     case DMA_COMPLETE:
+             aml_chan->data_len = 0;
+             chan_id = aml_chan->chan_id;
+             reg = (direction == DMA_DEV_TO_MEM) ? WCH_INT_MASK : RCH_INT_MASK;
+             regmap_set_bits(aml_dma->regmap, reg, BIT(chan_id));
+
+             break;
+     default:
+             dev_err(aml_dma->dma_device.dev, "status error\n");
+             return NULL;
+     }
+
+     link_count = sg_nents_for_dma(sgl, sg_len, SG_MAX_LEN);
+
+     if (link_count > DMA_MAX_LINK) {
+             dev_err(aml_dma->dma_device.dev,
+                     "maximum number of sg exceeded: %d > %d\n",
+                     sg_len, DMA_MAX_LINK);
+             aml_chan->status = DMA_ERROR;
+             return NULL;
+     }
+
+     aml_chan->status = DMA_IN_PROGRESS;
+
+     for_each_sg(sgl, sg, sg_len, i) {
+             avail = sg_dma_len(sg);
+             paddr = sg->dma_address;
+             while (avail > SG_MAX_LEN) {
+                     sg_link = &aml_chan->sg_link[idx++];
+                     /* set dma address and len  to sglink*/
+                     sg_link->address = paddr;
+                     sg_link->ctl = FIELD_PREP(LINK_LEN, SG_MAX_LEN);
+                     paddr = paddr + SG_MAX_LEN;

drivers/dma/amlogic-dma.c line 262

Quoted 10 lines
drivers/dma/amlogic-dma.c new file +10 -0
+                     avail = avail - SG_MAX_LEN;
+             }
+             sg_link = &aml_chan->sg_link[idx++];
+             /* set dma address and len  to sglink*/
+             sg_link->address = paddr;
+             sg_link->ctl = FIELD_PREP(LINK_LEN, avail);
+
+             aml_chan->data_len += sg_dma_len(sg);
+     }
+     aml_chan->sg_link_cnt = idx;

There is no descriptor management here. You are directly writing to channel. This is_very_ inefficient and defeats the use of dmaengine.

Quoted 3 lines

Please revise the driver. Implement queues to manage multiple txns and we have vchan to help you implement these, so take use of that

I will take use vchan to support mltiple txns.

Quoted 2 lines

--
~Vinod

#6 lore raw

PATCH v6 3/3 MAINTAINERS: Add an entry for Amlogic DMA driver

In reply to Xianwei Zhao

Add Amlogic DMA controller entry to MAINTAINERS to clarify the maintainers.

---
 MAINTAINERS | 7 +++++++
 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
index 55af015174a5..e9c52dfba2df 100644
@@ -1316,6 +1316,13 @@ F:	Documentation/devicetree/bindings/perf/amlogic,g12-ddr-pmu.yaml
 F:	drivers/perf/amlogic/
 F:	include/soc/amlogic/
 
+AMLOGIC DMA DRIVER
+M:	Xianwei Zhao <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/dma/amlogic,a9-dma.yaml
+F:	drivers/dma/amlogic-dma.c
+
 AMLOGIC ISP DRIVER
 M:	Keke Li <[email protected]>
 L:	[email protected]
Signature · 1 line
2.52.0