Skip to contentSkip to conversation

Add Loongson-2K0300 APB DMA mux support

PATCH In review Binbin Zhou 2 participants 4 messages Oct 26

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v3 cover Add Loongson-2K0300 APB DMA mux support

Hi all:

Loongson-2K0300 integrates a CMC DMA controller with 8 physical channels. Peripheral DMA requests are not hard-wired to these channels; they are routed through the CHIP_CTRL13/14/15 DMA_MAP fields.

This series adds support for that DMA request router.

Patch 1 adds the DT binding constants for the peripheral request IDs and yaml file for the DMA mux.
Patch 2 adds the driver, Kconfig symbol and Makefile entry.

The driver registers with of_dma_router_register(). In the route allocation callback it validates the <request> <channel> <flags> specifier, programs the SoC-specific route register, and forwards <channel> <flags> to the parent CMC DMA controller.

Thanks.
Binbin.

=========
V3:
Patch(1/2):
- Merged the two commits containing the dt-binding header file and the YAML file; no other changes were made;
- Add Acked-by tag from Conor.

Patch(2/2):
- Append the dmamux object to the existing CMC DMA line;
- Add loongson2_dmamux_assign_bits() helper, no functional change;
- Add Reviewed-by tag from Frank.

Link to V2:
https://lore.kernel.org/all/[email protected]/

V2:
Patch(1/3):
- Drop LS2K0300_DMA_REQ_MAX as it is not part of the ABI;
Patch(2/3):
- A more detailed description of dma-cells;
- Add the dma_requests constraint
Patch(3/3):
- Drop loongson2_dmamux_map->shift;
- Move of_parse_phandle() into loongson2_dmamux_route_allocate() avoid UAF;
- Drop loongson2_dmamux->dma_np;
- Check dma_requests;
- Add devm_add_action_or_reset() instead of .remove();
- Replace metux() with spinlock(), which has lower overhead;
- Add loongson2_dmamux_route_free().

Link to V1:
https://lore.kernel.org/all/[email protected]/

Binbin Zhou (2):
dt-bindings: dma: Document DMA mux support for Loongson-2K0300
dmaengine: loongson: Add Loongson-2K0300 APB DMA mux driver

 .../dma/loongson,ls2k0300-dmamux.yaml         |  72 ++++
 MAINTAINERS                                   |   3 +
 drivers/dma/loongson/Makefile                 |   2 +-
 drivers/dma/loongson/loongson2-apb-dmamux.c   | 404 ++++++++++++++++++
 .../dt-bindings/dma/loongson,ls2k-dmamux.h    |  53 +++
 5 files changed, 533 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/dma/loongson,ls2k0300-dmamux.yaml
 create mode 100644 drivers/dma/loongson/loongson2-apb-dmamux.c
 create mode 100644 include/dt-bindings/dma/loongson,ls2k-dmamux.h

base-commit: aff5e6a77fc69a7c490246465940d18422d7c631

Signature · 1 line
2.52.0
#1 lore raw

PATCH v3 1/2 dt-bindings: dma: Document DMA mux support for Loongson-2K0300

The DMA mux on Loongson-2K0300 is not a standalone hardware block. It is implemented as part of the chip configuration registers CHIP_CTRL13/14/15, which route peripheral DMA requests to the physical channels of the CMC DMA controller.

Document this as a DMA router. The #dma-cells = <3> specifier contains the peripheral request ID, the target CMC DMA channel, and channel configuration flags forwarded to the parent DMA controller.

---
 .../dma/loongson,ls2k0300-dmamux.yaml         | 72 +++++++++++++++++++
 MAINTAINERS                                   |  2 +
 .../dt-bindings/dma/loongson,ls2k-dmamux.h    | 53 ++++++++++++++
 3 files changed, 127 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/loongson,ls2k0300-dmamux.yaml
 create mode 100644 include/dt-bindings/dma/loongson,ls2k-dmamux.h
Documentation/devicetree/bindings/dma/loongson,ls2k0300-dmamux.yaml new file +72 -0
new file mode 100644
index 000000000000..df607d9ff599
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/loongson,ls2k0300-dmamux.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Loongson-2 APB DMA MUX (DMA request router)
+
+maintainers:
+  - Binbin Zhou <[email protected]>
+
+allOf:
+  - $ref: /schemas/dma/dma-router.yaml#
+
+properties:
+  compatible:
+    const: loongson,ls2k0300-dmamux
+
+  reg:
+    maxItems: 1
+
+  '#dma-cells':
+    const: 3
+    description: |
+      Each cell represents the following:
+      1. Peripheral request ID: This describes the corresponding bit field
+         for that peripheral in the configuration register; see (
+         include/dt-bindings/dma/loongson,ls2k-dmamux.h) for details.
+      2. Physical DMA channel (0-7): This not only represents the DMA
+         channel used by the peripheral but is also converted into a value for
+         the corresponding bit field in the configuration register, indicating
+         the legitimacy of that peripheral using that channel.
+         Specifically:
+         - I2S/SPI/UART/I2C: Require adjacent channels in pairs; valid
+            values are 0/1, 2/3, 4/5, 6/7;
+         - SM3/SM4/DES/AES: Single channel; valid values are limited to 0/1;
+         - CAN/ADC: Single channel; valid values range from 0 to 7.
+      3. DMA Channel Configuration: A 32-bit mask used to specify
+         device-specific DMA channel configurations.
+         - Bit 6: Peripheral Address Increment Mode
+            0x0: Disabled
+            0x1: Enabled
+         - Bit 7: Memory Address Increment Mode
+            0x0: Disabled
+            0x1: Enabled
+         - Bits 12-13: Priority
+            0x0: Low
+            0x1: Medium
+            0x2: High
+            0x3: Very High
+
+  dma-requests:
+    const: 22
+
+required:
+  - compatible
+  - reg
+  - dma-requests
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/dma/loongson,ls2k-dmamux.h>
+    dma-router@16000134 {
+        compatible = "loongson,ls2k0300-dmamux";
+        reg = <0x16000134 0xc>;
+        #dma-cells = <3>;
+        dma-masters = <&dma>;
+        dma-requests = <22>;
+    };
+...
MAINTAINERS +2 -0
index 42f5165019ee..78622b255f88 100644
@@ -15351,9 +15351,11 @@ M:	Binbin Zhou <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/dma/loongson,ls2k0300-dma.yaml
+F:	Documentation/devicetree/bindings/dma/loongson,ls2k0300-dmamux.yaml
 F:	Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml
 F:	drivers/dma/loongson/loongson2-apb-cmc-dma.c
 F:	drivers/dma/loongson/loongson2-apb-dma.c
+F:	include/dt-bindings/dma/loongson,ls2k-dmamux.h
 
 LOONGSON LS2X I2C DRIVER
 M:	Binbin Zhou <[email protected]>
include/dt-bindings/dma/loongson,ls2k-dmamux.h new file +53 -0

53 lines not on this page · raw message

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

Re: [PATCH v3 1/2] dt-bindings: dma: Document DMA mux support for Loongson-2K0300

Quoted 5 lines · Binbin Zhou

The DMA mux on Loongson-2K0300 is not a standalone hardware block. It is implemented as part of the chip configuration registers CHIP_CTRL13/14/15, which route peripheral DMA requests to the physical channels of the CMC DMA controller.

Quoted 7 lines

Document this as a DMA router. The #dma-cells = <3> specifier contains the peripheral request ID, the target CMC DMA channel, and channel configuration flags forwarded to the parent DMA controller.

---

Quoted 163 lines
 .../dma/loongson,ls2k0300-dmamux.yaml         | 72 +++++++++++++++++++
 MAINTAINERS                                   |  2 +
 .../dt-bindings/dma/loongson,ls2k-dmamux.h    | 53 ++++++++++++++
 3 files changed, 127 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/loongson,ls2k0300-dmamux.yaml
 create mode 100644 include/dt-bindings/dma/loongson,ls2k-dmamux.h
Documentation/devicetree/bindings/dma/loongson,ls2k0300-dmamux.yaml new file +72 -0
new file mode 100644
index 000000000000..df607d9ff599
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/loongson,ls2k0300-dmamux.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Loongson-2 APB DMA MUX (DMA request router)
+
+maintainers:
+  - Binbin Zhou <[email protected]>
+
+allOf:
+  - $ref: /schemas/dma/dma-router.yaml#
+
+properties:
+  compatible:
+    const: loongson,ls2k0300-dmamux
+
+  reg:
+    maxItems: 1
+
+  '#dma-cells':
+    const: 3
+    description: |
+      Each cell represents the following:
+      1. Peripheral request ID: This describes the corresponding bit field
+         for that peripheral in the configuration register; see (
+         include/dt-bindings/dma/loongson,ls2k-dmamux.h) for details.
+      2. Physical DMA channel (0-7): This not only represents the DMA
+         channel used by the peripheral but is also converted into a value for
+         the corresponding bit field in the configuration register, indicating
+         the legitimacy of that peripheral using that channel.
+         Specifically:
+         - I2S/SPI/UART/I2C: Require adjacent channels in pairs; valid
+            values are 0/1, 2/3, 4/5, 6/7;
+         - SM3/SM4/DES/AES: Single channel; valid values are limited to 0/1;
+         - CAN/ADC: Single channel; valid values range from 0 to 7.
+      3. DMA Channel Configuration: A 32-bit mask used to specify
+         device-specific DMA channel configurations.
+         - Bit 6: Peripheral Address Increment Mode
+            0x0: Disabled
+            0x1: Enabled
+         - Bit 7: Memory Address Increment Mode
+            0x0: Disabled
+            0x1: Enabled
+         - Bits 12-13: Priority
+            0x0: Low
+            0x1: Medium
+            0x2: High
+            0x3: Very High
+
+  dma-requests:
+    const: 22
+
+required:
+  - compatible
+  - reg
+  - dma-requests
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/dma/loongson,ls2k-dmamux.h>
+    dma-router@16000134 {
+        compatible = "loongson,ls2k0300-dmamux";
+        reg = <0x16000134 0xc>;
+        #dma-cells = <3>;
+        dma-masters = <&dma>;
+        dma-requests = <22>;
+    };
+...
MAINTAINERS +2 -0
index 42f5165019ee..78622b255f88 100644
@@ -15351,9 +15351,11 @@ M:	Binbin Zhou <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/dma/loongson,ls2k0300-dma.yaml
+F:	Documentation/devicetree/bindings/dma/loongson,ls2k0300-dmamux.yaml
 F:	Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml
 F:	drivers/dma/loongson/loongson2-apb-cmc-dma.c
 F:	drivers/dma/loongson/loongson2-apb-dma.c
+F:	include/dt-bindings/dma/loongson,ls2k-dmamux.h
 
 LOONGSON LS2X I2C DRIVER
 M:	Binbin Zhou <[email protected]>
include/dt-bindings/dma/loongson,ls2k-dmamux.h new file +53 -1
new file mode 100644
index 000000000000..1e2907ab069d
@@ -0,0 +1,53 @@
+/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
+/*
+ * Loongson-2 SoC DMA Mux dt-bindings
+ *
+ * DMA specifier format:
+ *   dmas = <&dma_mux <request> <channel> <flags>>;
+ *
+ * The <channel> cell selects a physical CMC DMA channel (0-7)
+ * For peripherals using channel pairs (UART, I2C, SPI2/3, I2S),
+ * the channel number selects the pair: 0/1 -> pair 0, 2/3 -> pair 1,
+ * 4/5 -> pair 2, 6/7 -> pair 3.
+ *
+ * Copyright (C) 2026 Loongson Technology Corporation Limited
+ */
+
+#ifndef _DT_BINDINGS_DMA_LOONGSON_LS2K_DMAMUX_H
+#define _DT_BINDINGS_DMA_LOONGSON_LS2K_DMAMUX_H
+
+/* UART controllers */
+#define LS2K0300_DMA_UART0		0
+#define LS2K0300_DMA_UART1		1
+#define LS2K0300_DMA_UART2		2
+#define LS2K0300_DMA_UART3		3
+#define LS2K0300_DMA_UART4		4
+#define LS2K0300_DMA_UART5		5
+#define LS2K0300_DMA_UART6		6
+#define LS2K0300_DMA_UART7		7
+#define LS2K0300_DMA_UART8		8
+#define LS2K0300_DMA_UART9		9
+
+/* I2C controllers */
+#define LS2K0300_DMA_I2C0		10
+#define LS2K0300_DMA_I2C1		11
+#define LS2K0300_DMA_I2C2		12
+#define LS2K0300_DMA_I2C3		13
+
+/* SPI controllers (IO mode) */
+#define LS2K0300_DMA_SPI2		14
+#define LS2K0300_DMA_SPI3		15
+
+/* I2S controller */
+#define LS2K0300_DMA_I2S		16
+
+/* ADC controller */
+#define LS2K0300_DMA_ADC		17
+
+/* CAN-FD controllers */
+#define LS2K0300_DMA_CAN0		18
+#define LS2K0300_DMA_CAN1		19
+#define LS2K0300_DMA_CAN2		20
+#define LS2K0300_DMA_CAN3		21
+
+#endif /* _DT_BINDINGS_DMA_LOONGSON_LS2K_DMAMUX_H */
--

2.52.0

#3 lore raw

PATCH v3 2/2 dmaengine: loongson: Add Loongson-2K0300 APB DMA mux driver

In reply to Binbin Zhou

The Loongson-2K0300 DMA mux is not a standalone DMA controller. It is implemented as a set of routing fields in the chip global configuration registers CHIP_CTRL13/14/15, which select which physical channel of the on-chip CMC DMA controller handles each peripheral DMA request.

Add a driver that exposes these routing fields as an OF DMA router. The router's allocation callback validates the <request> <channel> <flags> specifier, programs the corresponding CHIP_CTRL register field, and then rewrites the specifier to <channel> <flags> so that the parent CMC DMA controller's xlate is used.

---
 MAINTAINERS                                 |   1 +
 drivers/dma/loongson/Makefile               |   2 +-
 drivers/dma/loongson/loongson2-apb-dmamux.c | 404 ++++++++++++++++++++
 3 files changed, 406 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma/loongson/loongson2-apb-dmamux.c
MAINTAINERS +1 -0
index 78622b255f88..0b0c6ea41c64 100644
@@ -15355,6 +15355,7 @@ F:	Documentation/devicetree/bindings/dma/loongson,ls2k0300-dmamux.yaml
 F:	Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml
 F:	drivers/dma/loongson/loongson2-apb-cmc-dma.c
 F:	drivers/dma/loongson/loongson2-apb-dma.c
+F:	drivers/dma/loongson/loongson2-apb-dmamux.c
 F:	include/dt-bindings/dma/loongson,ls2k-dmamux.h
 
 LOONGSON LS2X I2C DRIVER
drivers/dma/loongson/Makefile +1 -1
index 48c19781e729..3e2aafb7e331 100644
@@ -1,4 +1,4 @@
 # SPDX-License-Identifier: GPL-2.0-only
 obj-$(CONFIG_LOONGSON1_APB_DMA) += loongson1-apb-dma.o
 obj-$(CONFIG_LOONGSON2_APB_DMA) += loongson2-apb-dma.o
-obj-$(CONFIG_LOONGSON2_APB_CMC_DMA) += loongson2-apb-cmc-dma.o
+obj-$(CONFIG_LOONGSON2_APB_CMC_DMA) += loongson2-apb-cmc-dma.o loongson2-apb-dmamux.o
drivers/dma/loongson/loongson2-apb-dmamux.c new file +404 -0

404 lines not on this page · raw message

Signature · 1 line
2.52.0