Skip to contentSkip to conversation

New driver for the Loongson LS2X APB DMA Controller

PATCH Superseded Binbin Zhou 3 participants 5 messages May 31, 2023 – Jun 2, 2023

Subsystems (4)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Binbin Zhou

author maintainer
#0 lore raw

cover New driver for the Loongson LS2X APB DMA Controller

Hi all:

This patchset introduces you to the Loongson LS2X apbdma controller.

The Loongson LS2X APB DMA controller is available on Loongson-2K chips. It is a single-channel, configurable DMA controller IP core based on the AXI bus, whose main function is to integrate DMA functionality on a chip dedicated to carrying data between memory and peripherals in APB bus (e.g. nand).

Thanks.

Binbin Zhou (2):
dt-bindings: dmaengine: Add Loongson LS2X APB DMA controller
dmaengine: ls2x-apb: new driver for the Loongson LS2X APB DMA
controller

 .../bindings/dma/loongson,ls2x-apbdma.yaml    |  61 ++
 drivers/dma/Kconfig                           |  14 +
 drivers/dma/Makefile                          |   1 +
 drivers/dma/ls2x-apb-dma.c                    | 642 ++++++++++++++++++
 4 files changed, 718 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml
 create mode 100644 drivers/dma/ls2x-apb-dma.c
Signature · 1 line
2.39.1
author maintainer
#1 lore raw

PATCH 1/2 dt-bindings: dmaengine: Add Loongson LS2X APB DMA controller

Add Loongson LS2X APB DMA controller binding with DT schema format using json-schema.

---
 .../bindings/dma/loongson,ls2x-apbdma.yaml    | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml
Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml new file +61 -0
new file mode 100644
index 000000000000..9df32dd98aaf
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/loongson,ls2x-apbdma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Loongson LS2X APB DMA controller
+
+description: |
+  The Loongson LS2X APB DMA controller is used for transferring data
+  between system memory and the peripherals on the APB bus.
+
+maintainers:
+  - Binbin Zhou <[email protected]>
+
+allOf:
+  - $ref: dma-controller.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - const: loongson,ls2k1000-apbdma
+      - items:
+          - const: loongson,ls2k0500-apbdma
+          - const: loongson,ls2k1000-apbdma
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  "#dma-cells":
+    const: 1
+
+  dma-channels:
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - "#dma-cells"
+  - dma-channels
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    apbdma0: dma-controller@1fe00c00 {
+        compatible = "loongson,ls2k1000-apbdma";
+        reg = <0x1fe00c00 0x8>;
+        interrupt-parent = <&liointc1>;
+        interrupts = <12 IRQ_TYPE_LEVEL_HIGH>;
+        #dma-cells = <1>;
+        dma-channels = <1>;
+    };
+
+...
Signature · 1 line
2.39.1
author maintainer
#3 lore raw

PATCH 2/2 dmaengine: ls2x-apb: new driver for the Loongson LS2X APB DMA controller

In reply to Binbin Zhou

The Loongson LS2X APB DMA controller is available on Loongson-2K chips.

It is a single-channel, configurable DMA controller IP core based on the AXI bus, whose main function is to integrate DMA functionality on a chip dedicated to carrying data between memory and peripherals in APB bus (e.g. nand).

---
 drivers/dma/Kconfig        |  14 +
 drivers/dma/Makefile       |   1 +
 drivers/dma/ls2x-apb-dma.c | 642 +++++++++++++++++++++++++++++++++++++
 3 files changed, 657 insertions(+)
 create mode 100644 drivers/dma/ls2x-apb-dma.c
drivers/dma/Kconfig +14 -0
index f5f422f9b850..c6019cd6c3b3 100644
@@ -376,6 +376,20 @@ config LPC18XX_DMAMUX
 	  Enable support for DMA on NXP LPC18xx/43xx platforms
 	  with PL080 and multiplexed DMA request lines.
 
+config LS2X_APB_DMA
+	tristate "Loongson LS2X APB DMA support"
+	depends on LOONGARCH || COMPILE_TEST
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	help
+	  Support for the Loongson LS2X APB DMA controller driver. The
+	  DMA controller is having single DMA channel which can be
+	  configured for different peripherals like audio, nand, sdio
+	  etc which is in APB bus.
+
+	  This DMA controller transfers data from memory to peripheral fifo.
+	  It does not support memory to memory data transfer.
+
 config MCF_EDMA
 	tristate "Freescale eDMA engine support, ColdFire mcf5441x SoCs"
 	depends on M5441x || COMPILE_TEST
drivers/dma/Makefile +1 -0
index a4fd1ce29510..9b28ddb1ea3b 100644
@@ -46,6 +46,7 @@ obj-$(CONFIG_INTEL_IOATDMA) += ioat/
 obj-y += idxd/
 obj-$(CONFIG_K3_DMA) += k3dma.o
 obj-$(CONFIG_LPC18XX_DMAMUX) += lpc18xx-dmamux.o
+obj-$(CONFIG_LS2X_APB_DMA) += ls2x-apb-dma.o
 obj-$(CONFIG_MILBEAUT_HDMAC) += milbeaut-hdmac.o
 obj-$(CONFIG_MILBEAUT_XDMAC) += milbeaut-xdmac.o
 obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
drivers/dma/ls2x-apb-dma.c new file +642 -0

642 lines not on this page · raw message

Signature · 1 line
2.39.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] dt-bindings: dmaengine: Add Loongson LS2X APB DMA controller

In reply to Binbin Zhou
Quoted 15 lines · Binbin Zhou

Add Loongson LS2X APB DMA controller binding with DT schema format using json-schema.

---
 .../bindings/dma/loongson,ls2x-apbdma.yaml    | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml
Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml new file +0 -0
new file mode 100644
index 000000000000..9df32dd98aaf

Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml line 9

Quoted 9 lines
Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml new file +9 -0
@@ -0,0 +1,61 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/loongson,ls2x-apbdma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Loongson LS2X APB DMA controller
+
+description: |

As a minor nit, the | shouldn't be required here.

Quoted 6 lines
Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml new file +6 -0
+  The Loongson LS2X APB DMA controller is used for transferring data
+  between system memory and the peripherals on the APB bus.
+
+maintainers:
+  - Binbin Zhou <[email protected]>
+

Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml line 25

Quoted 10 lines
Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml new file +10 -0
+allOf:
+  - $ref: dma-controller.yaml#
+
+properties:
+  compatible:
+    oneOf:
+      - const: loongson,ls2k1000-apbdma
+      - items:
+          - const: loongson,ls2k0500-apbdma
+          - const: loongson,ls2k1000-apbdma

Sweet, good to see fallbacks in use here ;)

Quoted 17 lines
Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml new file +17 -0
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  "#dma-cells":
+    const: 1
+
+  dma-channels:
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts

Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml line 52

Quoted 10 lines
Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml new file +10 -0
+  - "#dma-cells"
+  - dma-channels
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    apbdma0: dma-controller@1fe00c00 {

Nothing references the apbdma0 label so it can be dropped. Otherwise,

Thanks,
Conor.

Quoted 12 lines
Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml new file +9 -0
+        compatible = "loongson,ls2k1000-apbdma";
+        reg = <0x1fe00c00 0x8>;
+        interrupt-parent = <&liointc1>;
+        interrupts = <12 IRQ_TYPE_LEVEL_HIGH>;
+        #dma-cells = <1>;
+        dma-channels = <1>;
+    };
+
+...
Signature · 1 line
2.39.1
#4 lore raw

Re: [PATCH 2/2] dmaengine: ls2x-apb: new driver for the Loongson LS2X APB DMA controller

In reply to Binbin Zhou
kernel test robot noticed the following build errors:

Hi Binbin,

kernel test robot noticed the following build errors:

[auto build test ERROR on vkoul-dmaengine/next]
[also build test ERROR on robh/for-next linus/master v6.4-rc4 next-20230602] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Binbin-Zhou/dt-bindings-dmaengine-Add-Loongson-LS2X-APB-DMA-controller/20230531-165211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vkoul/dmaengine.git next
patch link:    https://lore.kernel.org/r/f65ebee39b5e1827af08d9e8d1f260928915f9b0.1685448898.git.zhoubinbin%40loongson.cn
patch subject: [PATCH 2/2] dmaengine: ls2x-apb: new driver for the Loongson LS2X APB DMA controller
config: arm-allmodconfig (https://download.01.org/0day-ci/archive/20230602/[email protected]/config)
compiler: arm-linux-gnueabi-gcc (GCC) 12.3.0

reproduce (this is a W=1 build):
mkdir -p ~/bin
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/c78b43fba2c7874dc293c0e2aba22c4e74500283
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Binbin-Zhou/dt-bindings-dmaengine-Add-Loongson-LS2X-APB-DMA-controller/20230531-165211 git checkout c78b43fba2c7874dc293c0e2aba22c4e74500283
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=arm olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.3.0 ~/bin/make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/dma/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/dma/ls2x-apb-dma.c: In function 'ls2x_dma_write_cmd':

>> drivers/dma/ls2x-apb-dma.c:179:15: error: implicit declaration of function 'readq'; did you mean 'readw'? [-Werror=implicit-function-declaration]
     179 |         val = readq(priv->regs + LDMA_ORDER_ERG) & LDMA_ASK_ADDR_MASK;
         |               ^~~~~
         |               readw
   In file included from include/linux/ratelimit_types.h:5,
                    from include/linux/ratelimit.h:5,
                    from include/linux/dev_printk.h:16,
                    from include/linux/device.h:15,
                    from include/linux/dmaengine.h:8,
                    from drivers/dma/ls2x-apb-dma.c:8:
   include/linux/bits.h:35:18: warning: right shift count is negative [-Wshift-count-negative]
      35 |          (~UL(0) >> (BITS_PER_LONG - 1 - (h))))
         |                  ^~
   include/linux/bits.h:37:38: note: in expansion of macro '__GENMASK'
      37 |         (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
         |                                      ^~~~~~~~~
   drivers/dma/ls2x-apb-dma.c:33:33: note: in expansion of macro 'GENMASK'
      33 | #define LDMA_ASK_ADDR_MASK      GENMASK(63, 5) /* Ask Addr Mask */
         |                                 ^~~~~~~
   drivers/dma/ls2x-apb-dma.c:179:52: note: in expansion of macro 'LDMA_ASK_ADDR_MASK'
     179 |         val = readq(priv->regs + LDMA_ORDER_ERG) & LDMA_ASK_ADDR_MASK;
         |                                                    ^~~~~~~~~~~~~~~~~~
>> drivers/dma/ls2x-apb-dma.c:181:9: error: implicit declaration of function 'writeq'; did you mean 'writew'? [-Werror=implicit-function-declaration]
     181 |         writeq(val, priv->regs + LDMA_ORDER_ERG);
         |         ^~~~~~
         |         writew
   drivers/dma/ls2x-apb-dma.c: In function 'ls2x_dma_start_transfer':
   include/linux/bits.h:35:18: warning: right shift count is negative [-Wshift-count-negative]
      35 |          (~UL(0) >> (BITS_PER_LONG - 1 - (h))))
         |                  ^~
   include/linux/bits.h:37:38: note: in expansion of macro '__GENMASK'
      37 |         (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l))
         |                                      ^~~~~~~~~
   drivers/dma/ls2x-apb-dma.c:33:33: note: in expansion of macro 'GENMASK'
      33 | #define LDMA_ASK_ADDR_MASK      GENMASK(63, 5) /* Ask Addr Mask */
         |                                 ^~~~~~~
   drivers/dma/ls2x-apb-dma.c:204:31: note: in expansion of macro 'LDMA_ASK_ADDR_MASK'
     204 |         val = (ldma_sg->llp & LDMA_ASK_ADDR_MASK) | LDMA_64BIT_EN | LDMA_START;
         |                               ^~~~~~~~~~~~~~~~~~
   In file included from include/linux/device/driver.h:21,
                    from include/linux/device.h:32:
   drivers/dma/ls2x-apb-dma.c: At top level:
>> drivers/dma/ls2x-apb-dma.c:628:25: error: 'ls2x_dma_dt_ids' undeclared here (not in a function); did you mean 'ls2x_dma_isr'?
     628 | MODULE_DEVICE_TABLE(of, ls2x_dma_dt_ids);
         |                         ^~~~~~~~~~~~~~~
   include/linux/module.h:244:15: note: in definition of macro 'MODULE_DEVICE_TABLE'
     244 | extern typeof(name) __mod_##type##__##name##_device_table               \
         |               ^~~~
>> include/linux/module.h:244:21: error: '__mod_of__ls2x_dma_dt_ids_device_table' aliased to undefined symbol 'ls2x_dma_dt_ids'
     244 | extern typeof(name) __mod_##type##__##name##_device_table               \
         |                     ^~~~~~
   drivers/dma/ls2x-apb-dma.c:628:1: note: in expansion of macro 'MODULE_DEVICE_TABLE'
     628 | MODULE_DEVICE_TABLE(of, ls2x_dma_dt_ids);
         | ^~~~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +179 drivers/dma/ls2x-apb-dma.c

173
174 static void ls2x_dma_write_cmd(struct ls2x_dma_chan *lchan, bool cmd)
175 {
176 u64 val = 0;
177 struct ls2x_dma_priv *priv = to_ldma_priv(lchan->vchan.chan.device);
178

 > 179		val = readq(priv->regs + LDMA_ORDER_ERG) & LDMA_ASK_ADDR_MASK;
   180		val |= LDMA_64BIT_EN | cmd;
 > 181		writeq(val, priv->regs + LDMA_ORDER_ERG);

182 }
183

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki