Skip to contentSkip to conversation

dmaengine: Add Loongson Multi-Channel DMA controller support

PATCH Applied Binbin Zhou 4 participants 10 messages Mar 7 – Mar 17

Subsystems (6)
lore
Share & tools
lore

Binbin Zhou

author maintainer
#0 lore raw

v4 cover dmaengine: Add Loongson Multi-Channel DMA controller support

Hi all:

This patchset introduces the Loongson multi-channel DMA controller, which is present in the Loongson-2K0300 and Loongson-2K3000 processors.

It is a multi-channel controller that enables data transfers from memory to memory, device to memory, and memory to device, as well as channel prioritization configurable through the channel configuration registers.

Additionally, since multiple distinct types of DMA controllers exist on the Loongson platform, I have attempted to consolidate all Loongson DMA drivers into a new directory named Loongson for easier management.

Thanks.
Binbin

===========
V4:
- Rebase on dmaengine/next tree;
- Add Reviewed-by tags from Frank and Rob, thanks;

patch(1/6):
- Add depends on restrictions.

patch(6/6):
- Move loongson2_cmc_dma_config{..} close to its users.

Link to V3:
https://lore.kernel.org/dmaengine/[email protected]/

V3:
- Rebase on dmaengine/next tree;

patch(1/6):
- Keep alphabet order;

patch(2/6):
- Add Reviewed-by tag from Frank, thanks;

patch(3/6)/(4/6):
- New patches, format loongson2-apb-dma driver code;

patch(5/6):
- Add description for interrupts property;

patch(6/6):
- Use ffs() helper make the code cleaner;
- Refact loongson2_cmc_dma_chan_irq();
- Simplify locking with guard() and scoped_guard();
- kzalloc()->kzalloc_flex().

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

V2:
patch(1/4):
- Update loongson1-apb-dma.c entry in MAINTAINERS.

patch(2/4):
- New patch, use dmaenginem_async_device_register() helper.

patch(3/4):
- additionalProperties: false replaced by
unevaluatedProperties: false.

patch(4/4):
- Rename filename as loongson2-apb-cmc-dma.c;
- Rename Kconfig item as LOONGSON2_APB_CMC_DMA;
- Rename the variable prefix as loongson2_cmc_dma;
- Use dmaenginem_async_device_register() helper;
- Drop 'dma_' prefix in struct loongson2_mdma_chan_reg;
- Use struct_size();

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

Binbin Zhou (6):
dmaengine: loongson: New directory for Loongson DMA controllers
drivers
dmaengine: loongson: loongson2-apb: Convert to
dmaenginem_async_device_register()
dmaengine: loongson: loongson2-apb: Convert to devm_clk_get_enabled()
dmaengine: loongson: loongson2-apb: Simplify locking with guard() and
scoped_guard()
dt-bindings: dmaengine: Add Loongson Multi-Channel DMA controller
dmaengine: loongson: New driver for the Loongson Multi-Channel DMA
controller

 .../bindings/dma/loongson,ls2k0300-dma.yaml   |  81 ++
 MAINTAINERS                                   |   7 +-
 drivers/dma/Kconfig                           |  25 +-
 drivers/dma/Makefile                          |   3 +-
 drivers/dma/loongson/Kconfig                  |  41 +
 drivers/dma/loongson/Makefile                 |   4 +
 .../dma/{ => loongson}/loongson1-apb-dma.c    |   4 +-
 drivers/dma/loongson/loongson2-apb-cmc-dma.c  | 730 ++++++++++++++++++
 .../dma/{ => loongson}/loongson2-apb-dma.c    |  93 +--
 9 files changed, 903 insertions(+), 85 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/dma/loongson,ls2k0300-dma.yaml
 create mode 100644 drivers/dma/loongson/Kconfig
 create mode 100644 drivers/dma/loongson/Makefile
 rename drivers/dma/{ => loongson}/loongson1-apb-dma.c (99%)
 create mode 100644 drivers/dma/loongson/loongson2-apb-cmc-dma.c
 rename drivers/dma/{ => loongson}/loongson2-apb-dma.c (91%)

base-commit: c8e9b1d9febc83ee94944695a07cfd40a1b29743

Signature · 1 line
2.52.0
author maintainer
#1 lore raw

PATCH v4 1/6 dmaengine: loongson: New directory for Loongson DMA controllers drivers

Gather the Loongson DMA controllers under drivers/dma/loongson/

---
 MAINTAINERS                                   |  3 +-
 drivers/dma/Kconfig                           | 25 ++--------------
 drivers/dma/Makefile                          |  3 +-
 drivers/dma/loongson/Kconfig                  | 30 +++++++++++++++++++
 drivers/dma/loongson/Makefile                 |  3 ++
 .../dma/{ => loongson}/loongson1-apb-dma.c    |  4 +--
 .../dma/{ => loongson}/loongson2-apb-dma.c    |  4 +--
 7 files changed, 42 insertions(+), 30 deletions(-)
 create mode 100644 drivers/dma/loongson/Kconfig
 create mode 100644 drivers/dma/loongson/Makefile
 rename drivers/dma/{ => loongson}/loongson1-apb-dma.c (99%)
 rename drivers/dma/{ => loongson}/loongson2-apb-dma.c (99%)
MAINTAINERS +2 -1
index 55af015174a5..e8cd1e2dac13 100644
@@ -14953,7 +14953,7 @@ M:	Binbin Zhou <[email protected]>
 L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml
-F:	drivers/dma/loongson2-apb-dma.c
+F:	drivers/dma/loongson/loongson2-apb-dma.c
 
 LOONGSON LS2X I2C DRIVER
 M:	Binbin Zhou <[email protected]>
@@ -17721,6 +17721,7 @@ F:	arch/mips/boot/dts/loongson/loongson1*
 F:	arch/mips/configs/loongson1_defconfig
 F:	arch/mips/loongson32/
 F:	drivers/*/*loongson1*
+F:	drivers/dma/loongson/loongson1-apb-dma.c
 F:	drivers/mtd/nand/raw/loongson-nand-controller.c
 F:	drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c
 F:	sound/soc/loongson/loongson1_ac97.c
drivers/dma/Kconfig +2 -23
index 66cda7cc9f7a..1b84c5b11654 100644
@@ -376,29 +376,6 @@ config K3_DMA
 	  Support the DMA engine for Hisilicon K3 platform
 	  devices.
 
-config LOONGSON1_APB_DMA
-	tristate "Loongson1 APB DMA support"
-	depends on MACH_LOONGSON32 || COMPILE_TEST
-	select DMA_ENGINE
-	select DMA_VIRTUAL_CHANNELS
-	help
-	  This selects support for the APB DMA controller in Loongson1 SoCs,
-	  which is required by Loongson1 NAND and audio support.
-
-config LOONGSON2_APB_DMA
-	tristate "Loongson2 APB DMA support"
-	depends on LOONGARCH || COMPILE_TEST
-	select DMA_ENGINE
-	select DMA_VIRTUAL_CHANNELS
-	help
-	  Support for the Loongson2 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 LPC18XX_DMAMUX
 	bool "NXP LPC18xx/43xx DMA MUX for PL080"
 	depends on ARCH_LPC18XX || COMPILE_TEST
@@ -774,6 +751,8 @@ source "drivers/dma/fsl-dpaa2-qdma/Kconfig"
 
 source "drivers/dma/lgm/Kconfig"
 
+source "drivers/dma/loongson/Kconfig"
+
 source "drivers/dma/stm32/Kconfig"
 
 # clients
drivers/dma/Makefile +1 -2
index a54d7688392b..963b10494ee5 100644
@@ -49,8 +49,6 @@ obj-$(CONFIG_INTEL_IDMA64) += idma64.o
 obj-$(CONFIG_INTEL_IOATDMA) += ioat/
 obj-y += idxd/
 obj-$(CONFIG_K3_DMA) += k3dma.o
-obj-$(CONFIG_LOONGSON1_APB_DMA) += loongson1-apb-dma.o
-obj-$(CONFIG_LOONGSON2_APB_DMA) += loongson2-apb-dma.o
 obj-$(CONFIG_LPC18XX_DMAMUX) += lpc18xx-dmamux.o
 obj-$(CONFIG_LPC32XX_DMAMUX) += lpc32xx-dmamux.o
 obj-$(CONFIG_MILBEAUT_HDMAC) += milbeaut-hdmac.o
@@ -87,6 +85,7 @@ obj-$(CONFIG_FSL_DPAA2_QDMA) += fsl-dpaa2-qdma/
 obj-$(CONFIG_INTEL_LDMA) += lgm/
 
 obj-y += amd/
+obj-y += loongson/
 obj-y += mediatek/
 obj-y += qcom/
 obj-y += stm32/
drivers/dma/loongson/Kconfig new file +30 -0
new file mode 100644
index 000000000000..0a865a8fd3a6
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Loongson DMA controllers drivers
+#
+if MACH_LOONGSON32 || MACH_LOONGSON64 || COMPILE_TEST
+
+config LOONGSON1_APB_DMA
+	tristate "Loongson1 APB DMA support"
+	depends on MACH_LOONGSON32 || COMPILE_TEST
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	help
+	  This selects support for the APB DMA controller in Loongson1 SoCs,
+	  which is required by Loongson1 NAND and audio support.
+
+config LOONGSON2_APB_DMA
+	tristate "Loongson2 APB DMA support"
+	depends on MACH_LOONGSON64 || COMPILE_TEST
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	help
+	  Support for the Loongson2 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.
+
+endif
drivers/dma/loongson/Makefile new file +3 -0
new file mode 100644
index 000000000000..6cdd08065e92
@@ -0,0 +1,3 @@
+# 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
drivers/dma/loongson/loongson1-apb-dma.c renamed from drivers/dma/loongson1-apb-dma.c +2 -2
similarity index 99%
rename from drivers/dma/loongson1-apb-dma.c
rename to drivers/dma/loongson/loongson1-apb-dma.c
index 2e347aba9af8..89786cbd20ab 100644
@@ -16,8 +16,8 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
-#include "dmaengine.h"
-#include "virt-dma.h"
+#include "../dmaengine.h"
+#include "../virt-dma.h"
 
 /* Loongson-1 DMA Control Register */
 #define LS1X_DMA_CTRL		0x0
drivers/dma/loongson/loongson2-apb-dma.c renamed from drivers/dma/loongson2-apb-dma.c +2 -2
similarity index 99%
rename from drivers/dma/loongson2-apb-dma.c
rename to drivers/dma/loongson/loongson2-apb-dma.c
index b981475e6779..fc7d9f4a96ec 100644
@@ -17,8 +17,8 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
-#include "dmaengine.h"
-#include "virt-dma.h"
+#include "../dmaengine.h"
+#include "../virt-dma.h"
 
 /* Global Configuration Register */
 #define LDMA_ORDER_ERG		0x0
Signature · 1 line
2.52.0
maintainer Reviewed-by on v4 1/6
#2 lore raw

Re: [PATCH v4 1/6] dmaengine: loongson: New directory for Loongson DMA controllers drivers

Quoted 188 lines · Binbin Zhou

Gather the Loongson DMA controllers under drivers/dma/loongson/

---
 MAINTAINERS                                   |  3 +-
 drivers/dma/Kconfig                           | 25 ++--------------
 drivers/dma/Makefile                          |  3 +-
 drivers/dma/loongson/Kconfig                  | 30 +++++++++++++++++++
 drivers/dma/loongson/Makefile                 |  3 ++
 .../dma/{ => loongson}/loongson1-apb-dma.c    |  4 +--
 .../dma/{ => loongson}/loongson2-apb-dma.c    |  4 +--
 7 files changed, 42 insertions(+), 30 deletions(-)
 create mode 100644 drivers/dma/loongson/Kconfig
 create mode 100644 drivers/dma/loongson/Makefile
 rename drivers/dma/{ => loongson}/loongson1-apb-dma.c (99%)
 rename drivers/dma/{ => loongson}/loongson2-apb-dma.c (99%)
MAINTAINERS +2 -1
index 55af015174a5..e8cd1e2dac13 100644
@@ -14953,7 +14953,7 @@ M:      Binbin Zhou <[email protected]>
 L:     [email protected]
 S:     Maintained
 F:     Documentation/devicetree/bindings/dma/loongson,ls2x-apbdma.yaml
-F:     drivers/dma/loongson2-apb-dma.c
+F:     drivers/dma/loongson/loongson2-apb-dma.c
 
 LOONGSON LS2X I2C DRIVER
 M:     Binbin Zhou <[email protected]>
@@ -17721,6 +17721,7 @@ F:      arch/mips/boot/dts/loongson/loongson1*
 F:     arch/mips/configs/loongson1_defconfig
 F:     arch/mips/loongson32/
 F:     drivers/*/*loongson1*
+F:     drivers/dma/loongson/loongson1-apb-dma.c
 F:     drivers/mtd/nand/raw/loongson-nand-controller.c
 F:     drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c
 F:     sound/soc/loongson/loongson1_ac97.c
drivers/dma/Kconfig +2 -23
index 66cda7cc9f7a..1b84c5b11654 100644
@@ -376,29 +376,6 @@ config K3_DMA
          Support the DMA engine for Hisilicon K3 platform
          devices.
 
-config LOONGSON1_APB_DMA
-       tristate "Loongson1 APB DMA support"
-       depends on MACH_LOONGSON32 || COMPILE_TEST
-       select DMA_ENGINE
-       select DMA_VIRTUAL_CHANNELS
-       help
-         This selects support for the APB DMA controller in Loongson1 SoCs,
-         which is required by Loongson1 NAND and audio support.
-
-config LOONGSON2_APB_DMA
-       tristate "Loongson2 APB DMA support"
-       depends on LOONGARCH || COMPILE_TEST
-       select DMA_ENGINE
-       select DMA_VIRTUAL_CHANNELS
-       help
-         Support for the Loongson2 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 LPC18XX_DMAMUX
        bool "NXP LPC18xx/43xx DMA MUX for PL080"
        depends on ARCH_LPC18XX || COMPILE_TEST
@@ -774,6 +751,8 @@ source "drivers/dma/fsl-dpaa2-qdma/Kconfig"
 
 source "drivers/dma/lgm/Kconfig"
 
+source "drivers/dma/loongson/Kconfig"
+
 source "drivers/dma/stm32/Kconfig"
 
 # clients
drivers/dma/Makefile +1 -2
index a54d7688392b..963b10494ee5 100644
@@ -49,8 +49,6 @@ obj-$(CONFIG_INTEL_IDMA64) += idma64.o
 obj-$(CONFIG_INTEL_IOATDMA) += ioat/
 obj-y += idxd/
 obj-$(CONFIG_K3_DMA) += k3dma.o
-obj-$(CONFIG_LOONGSON1_APB_DMA) += loongson1-apb-dma.o
-obj-$(CONFIG_LOONGSON2_APB_DMA) += loongson2-apb-dma.o
 obj-$(CONFIG_LPC18XX_DMAMUX) += lpc18xx-dmamux.o
 obj-$(CONFIG_LPC32XX_DMAMUX) += lpc32xx-dmamux.o
 obj-$(CONFIG_MILBEAUT_HDMAC) += milbeaut-hdmac.o
@@ -87,6 +85,7 @@ obj-$(CONFIG_FSL_DPAA2_QDMA) += fsl-dpaa2-qdma/
 obj-$(CONFIG_INTEL_LDMA) += lgm/
 
 obj-y += amd/
+obj-y += loongson/
 obj-y += mediatek/
 obj-y += qcom/
 obj-y += stm32/
drivers/dma/loongson/Kconfig new file +30 -0
new file mode 100644
index 000000000000..0a865a8fd3a6
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Loongson DMA controllers drivers
+#
+if MACH_LOONGSON32 || MACH_LOONGSON64 || COMPILE_TEST
+
+config LOONGSON1_APB_DMA
+       tristate "Loongson1 APB DMA support"
+       depends on MACH_LOONGSON32 || COMPILE_TEST
+       select DMA_ENGINE
+       select DMA_VIRTUAL_CHANNELS
+       help
+         This selects support for the APB DMA controller in Loongson1 SoCs,
+         which is required by Loongson1 NAND and audio support.
+
+config LOONGSON2_APB_DMA
+       tristate "Loongson2 APB DMA support"
+       depends on MACH_LOONGSON64 || COMPILE_TEST
+       select DMA_ENGINE
+       select DMA_VIRTUAL_CHANNELS
+       help
+         Support for the Loongson2 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.
+
+endif
drivers/dma/loongson/Makefile new file +3 -0
new file mode 100644
index 000000000000..6cdd08065e92
@@ -0,0 +1,3 @@
+# 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
drivers/dma/loongson/loongson1-apb-dma.c renamed from drivers/dma/loongson1-apb-dma.c +2 -2
similarity index 99%
rename from drivers/dma/loongson1-apb-dma.c
rename to drivers/dma/loongson/loongson1-apb-dma.c
index 2e347aba9af8..89786cbd20ab 100644
@@ -16,8 +16,8 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
-#include "dmaengine.h"
-#include "virt-dma.h"
+#include "../dmaengine.h"
+#include "../virt-dma.h"
 
 /* Loongson-1 DMA Control Register */
 #define LS1X_DMA_CTRL          0x0
drivers/dma/loongson/loongson2-apb-dma.c renamed from drivers/dma/loongson2-apb-dma.c +2 -3
similarity index 99%
rename from drivers/dma/loongson2-apb-dma.c
rename to drivers/dma/loongson/loongson2-apb-dma.c
index b981475e6779..fc7d9f4a96ec 100644
@@ -17,8 +17,8 @@
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
-#include "dmaengine.h"
-#include "virt-dma.h"
+#include "../dmaengine.h"
+#include "../virt-dma.h"
 
 /* Global Configuration Register */
 #define LDMA_ORDER_ERG         0x0
--

2.52.0

Signature · 3 lines
Best regards,

Keguang Zhang
author maintainer
#3 lore raw

PATCH v4 2/6 dmaengine: loongson: loongson2-apb: Convert to dmaenginem_async_device_register()

In reply to Binbin Zhou

Use the dmaenginem_async_device_register() helper function to simplify the probe routine.

---
 drivers/dma/loongson/loongson2-apb-dma.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/dma/loongson/loongson2-apb-dma.c +2 -5
index fc7d9f4a96ec..2d16842e1658 100644
@@ -650,21 +650,19 @@ static int ls2x_dma_probe(struct platform_device *pdev)
 	ddev->dst_addr_widths = LDMA_SLAVE_BUSWIDTHS;
 	ddev->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
 
-	ret = dma_async_device_register(&priv->ddev);
+	ret = dmaenginem_async_device_register(&priv->ddev);
 	if (ret < 0)
 		goto disable_clk;
 
 	ret = of_dma_controller_register(dev->of_node, of_dma_xlate_by_chan_id, priv);
 	if (ret < 0)
-		goto unregister_dmac;
+		goto disable_clk;
 
 	platform_set_drvdata(pdev, priv);
 
 	dev_info(dev, "Loongson LS2X APB DMA driver registered successfully.\n");
 	return 0;
 
-unregister_dmac:
-	dma_async_device_unregister(&priv->ddev);
 disable_clk:
 	clk_disable_unprepare(priv->dma_clk);
 
@@ -680,7 +678,6 @@ static void ls2x_dma_remove(struct platform_device *pdev)
 	struct ls2x_dma_priv *priv = platform_get_drvdata(pdev);
 
 	of_dma_controller_free(pdev->dev.of_node);
-	dma_async_device_unregister(&priv->ddev);
 	clk_disable_unprepare(priv->dma_clk);
 }
 
Signature · 1 line
2.52.0
author maintainer
#4 lore raw

PATCH v4 3/6 dmaengine: loongson: loongson2-apb: Convert to devm_clk_get_enabled()

In reply to Binbin Zhou

Use the devm_clk_get_enabled() helper function to simplify the probe routine.

---
 drivers/dma/loongson/loongson2-apb-dma.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)
drivers/dma/loongson/loongson2-apb-dma.c +5 -17
index 2d16842e1658..adddfafc2f1c 100644
@@ -616,17 +616,13 @@ static int ls2x_dma_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, PTR_ERR(priv->regs),
 				     "devm_platform_ioremap_resource failed.\n");
 
-	priv->dma_clk = devm_clk_get(&pdev->dev, NULL);
+	priv->dma_clk = devm_clk_get_enabled(dev, NULL);
 	if (IS_ERR(priv->dma_clk))
-		return dev_err_probe(dev, PTR_ERR(priv->dma_clk), "devm_clk_get failed.\n");
-
-	ret = clk_prepare_enable(priv->dma_clk);
-	if (ret)
-		return dev_err_probe(dev, ret, "clk_prepare_enable failed.\n");
+		return dev_err_probe(dev, PTR_ERR(priv->dma_clk), "Couldn't start the clock.\n");
 
 	ret = ls2x_dma_chan_init(pdev, priv);
 	if (ret)
-		goto disable_clk;
+		return ret;
 
 	ddev = &priv->ddev;
 	ddev->dev = dev;
@@ -652,21 +648,16 @@ static int ls2x_dma_probe(struct platform_device *pdev)
 
 	ret = dmaenginem_async_device_register(&priv->ddev);
 	if (ret < 0)
-		goto disable_clk;
+		return dev_err_probe(dev, ret, "Failed to register DMA engine device.\n");
 
 	ret = of_dma_controller_register(dev->of_node, of_dma_xlate_by_chan_id, priv);
 	if (ret < 0)
-		goto disable_clk;
+		return dev_err_probe(dev, ret, "Failed to register dma controller.\n");
 
 	platform_set_drvdata(pdev, priv);
 
 	dev_info(dev, "Loongson LS2X APB DMA driver registered successfully.\n");
 	return 0;
-
-disable_clk:
-	clk_disable_unprepare(priv->dma_clk);
-
-	return ret;
 }
 
 /*
@@ -675,10 +666,7 @@ static int ls2x_dma_probe(struct platform_device *pdev)
  */
 static void ls2x_dma_remove(struct platform_device *pdev)
 {
-	struct ls2x_dma_priv *priv = platform_get_drvdata(pdev);
-
 	of_dma_controller_free(pdev->dev.of_node);
-	clk_disable_unprepare(priv->dma_clk);
 }
 
 static const struct of_device_id ls2x_dma_of_match_table[] = {
Signature · 1 line
2.52.0
author maintainer
#5 lore raw

PATCH v4 4/6 dmaengine: loongson: loongson2-apb: Simplify locking with guard() and scoped_guard()

In reply to Binbin Zhou

Use guard() and scoped_guard() infrastructure instead of explicitly acquiring and releasing spinlocks to simplify the code and ensure that all locks are released properly.

---
 drivers/dma/loongson/loongson2-apb-dma.c | 62 +++++++++++-------------
 1 file changed, 29 insertions(+), 33 deletions(-)
drivers/dma/loongson/loongson2-apb-dma.c +29 -33
index adddfafc2f1c..aceb069e71fc 100644
@@ -461,12 +461,11 @@ static int ls2x_dma_slave_config(struct dma_chan *chan,
 static void ls2x_dma_issue_pending(struct dma_chan *chan)
 {
 	struct ls2x_dma_chan *lchan = to_ldma_chan(chan);
-	unsigned long flags;
 
-	spin_lock_irqsave(&lchan->vchan.lock, flags);
+	guard(spinlock_irqsave)(&lchan->vchan.lock);
+
 	if (vchan_issue_pending(&lchan->vchan) && !lchan->desc)
 		ls2x_dma_start_transfer(lchan);
-	spin_unlock_irqrestore(&lchan->vchan.lock, flags);
 }
 
 /*
@@ -478,19 +477,18 @@ static void ls2x_dma_issue_pending(struct dma_chan *chan)
 static int ls2x_dma_terminate_all(struct dma_chan *chan)
 {
 	struct ls2x_dma_chan *lchan = to_ldma_chan(chan);
-	unsigned long flags;
 	LIST_HEAD(head);
 
-	spin_lock_irqsave(&lchan->vchan.lock, flags);
-	/* Setting stop cmd */
-	ls2x_dma_write_cmd(lchan, LDMA_STOP);
-	if (lchan->desc) {
-		vchan_terminate_vdesc(&lchan->desc->vdesc);
-		lchan->desc = NULL;
-	}
+	scoped_guard(spinlock_irqsave, &lchan->vchan.lock) {
+		/* Setting stop cmd */
+		ls2x_dma_write_cmd(lchan, LDMA_STOP);
+		if (lchan->desc) {
+			vchan_terminate_vdesc(&lchan->desc->vdesc);
+			lchan->desc = NULL;
+		}
 
-	vchan_get_all_descriptors(&lchan->vchan, &head);
-	spin_unlock_irqrestore(&lchan->vchan.lock, flags);
+		vchan_get_all_descriptors(&lchan->vchan, &head);
+	}
 
 	vchan_dma_desc_free_list(&lchan->vchan, &head);
 	return 0;
@@ -511,14 +509,13 @@ static void ls2x_dma_synchronize(struct dma_chan *chan)
 static int ls2x_dma_pause(struct dma_chan *chan)
 {
 	struct ls2x_dma_chan *lchan = to_ldma_chan(chan);
-	unsigned long flags;
 
-	spin_lock_irqsave(&lchan->vchan.lock, flags);
+	guard(spinlock_irqsave)(&lchan->vchan.lock);
+
 	if (lchan->desc && lchan->desc->status == DMA_IN_PROGRESS) {
 		ls2x_dma_write_cmd(lchan, LDMA_STOP);
 		lchan->desc->status = DMA_PAUSED;
 	}
-	spin_unlock_irqrestore(&lchan->vchan.lock, flags);
 
 	return 0;
 }
@@ -526,14 +523,13 @@ static int ls2x_dma_pause(struct dma_chan *chan)
 static int ls2x_dma_resume(struct dma_chan *chan)
 {
 	struct ls2x_dma_chan *lchan = to_ldma_chan(chan);
-	unsigned long flags;
 
-	spin_lock_irqsave(&lchan->vchan.lock, flags);
+	guard(spinlock_irqsave)(&lchan->vchan.lock);
+
 	if (lchan->desc && lchan->desc->status == DMA_PAUSED) {
 		lchan->desc->status = DMA_IN_PROGRESS;
 		ls2x_dma_write_cmd(lchan, LDMA_START);
 	}
-	spin_unlock_irqrestore(&lchan->vchan.lock, flags);
 
 	return 0;
 }
@@ -550,22 +546,22 @@ static irqreturn_t ls2x_dma_isr(int irq, void *dev_id)
 	struct ls2x_dma_chan *lchan = dev_id;
 	struct ls2x_dma_desc *desc;
 
-	spin_lock(&lchan->vchan.lock);
-	desc = lchan->desc;
-	if (desc) {
-		if (desc->cyclic) {
-			vchan_cyclic_callback(&desc->vdesc);
-		} else {
-			desc->status = DMA_COMPLETE;
-			vchan_cookie_complete(&desc->vdesc);
-			ls2x_dma_start_transfer(lchan);
+	scoped_guard(spinlock, &lchan->vchan.lock) {
+		desc = lchan->desc;
+		if (desc) {
+			if (desc->cyclic) {
+				vchan_cyclic_callback(&desc->vdesc);
+			} else {
+				desc->status = DMA_COMPLETE;
+				vchan_cookie_complete(&desc->vdesc);
+				ls2x_dma_start_transfer(lchan);
+			}
+
+			/* ls2x_dma_start_transfer() updates lchan->desc */
+			if (!lchan->desc)
+				ls2x_dma_write_cmd(lchan, LDMA_STOP);
 		}
-
-		/* ls2x_dma_start_transfer() updates lchan->desc */
-		if (!lchan->desc)
-			ls2x_dma_write_cmd(lchan, LDMA_STOP);
 	}
-	spin_unlock(&lchan->vchan.lock);
 
 	return IRQ_HANDLED;
 }
Signature · 1 line
2.52.0
author maintainer
#6 lore raw

PATCH v4 5/6 dt-bindings: dmaengine: Add Loongson Multi-Channel DMA controller

In reply to Binbin Zhou

The Loongson-2K0300/Loongson-2K3000 have built-in multi-channel DMA controllers, which are similar except for some of the register offsets and number of channels.

Obviously, this is quite different from the APB DMA controller used in the Loongson-2K0500/Loongson-2K1000, such as the latter being a single-channel DMA controller.

To avoid cluttering a single dt-binding file, add a new yaml file.

---
 .../bindings/dma/loongson,ls2k0300-dma.yaml   | 81 +++++++++++++++++++
 MAINTAINERS                                   |  3 +-
 2 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/dma/loongson,ls2k0300-dma.yaml
Documentation/devicetree/bindings/dma/loongson,ls2k0300-dma.yaml new file +81 -0
new file mode 100644
index 000000000000..c3151d806b55
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/loongson,ls2k0300-dma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Looongson-2 Multi-Channel DMA controller
+
+description:
+  The Loongson-2 Multi-Channel 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:
+    enum:
+      - loongson,ls2k0300-dma
+      - loongson,ls2k3000-dma
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    description:
+      Should contain all of the per-channel DMA interrupts in ascending order
+      with respect to the DMA channel index.
+    minItems: 4
+    maxItems: 8
+
+  clocks:
+    maxItems: 1
+
+  '#dma-cells':
+    const: 2
+    description: |
+      DMA request from clients consists of 2 cells:
+        1. Channel index
+        2. Transfer request factor number, If no transfer factor, use 0.
+           The number is SoC-specific, and this should be specified with
+           relation to the device to use the DMA controller.
+
+  dma-channels:
+    enum: [4, 8]
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - '#dma-cells'
+  - dma-channels
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/clock/loongson,ls2k-clk.h>
+
+    dma-controller@1612c000 {
+        compatible = "loongson,ls2k0300-dma";
+        reg = <0x1612c000 0xff>;
+        interrupt-parent = <&liointc0>;
+        interrupts = <23 IRQ_TYPE_LEVEL_HIGH>,
+                     <24 IRQ_TYPE_LEVEL_HIGH>,
+                     <25 IRQ_TYPE_LEVEL_HIGH>,
+                     <26 IRQ_TYPE_LEVEL_HIGH>,
+                     <27 IRQ_TYPE_LEVEL_HIGH>,
+                     <28 IRQ_TYPE_LEVEL_HIGH>,
+                     <29 IRQ_TYPE_LEVEL_HIGH>,
+                     <30 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clk LS2K0300_CLK_APB_GATE>;
+        #dma-cells = <2>;
+        dma-channels = <8>;
+    };
+...
MAINTAINERS +2 -1
index e8cd1e2dac13..aea29c28d865 100644
@@ -14948,10 +14948,11 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/gpio/loongson,ls-gpio.yaml
 F:	drivers/gpio/gpio-loongson-64bit.c
 
-LOONGSON-2 APB DMA DRIVER
+LOONGSON-2 DMA DRIVER
 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,ls2x-apbdma.yaml
 F:	drivers/dma/loongson/loongson2-apb-dma.c
 
Signature · 1 line
2.52.0
author maintainer
#7 lore raw

PATCH v4 6/6 dmaengine: loongson: New driver for the Loongson Multi-Channel DMA controller

In reply to Binbin Zhou

This DMA controller appears in Loongson-2K0300 and Loongson-2K3000.

It is a chain multi-channel controller that enables data transfers from memory to memory, device to memory, and memory to device, as well as channel prioritization configurable through the channel configuration registers.

In addition, there are slight differences between Loongson-2K0300 and Loongson-2K3000, such as channel register offsets and the number of channels.

---
 MAINTAINERS                                  |   1 +
 drivers/dma/loongson/Kconfig                 |  11 +
 drivers/dma/loongson/Makefile                |   1 +
 drivers/dma/loongson/loongson2-apb-cmc-dma.c | 730 +++++++++++++++++++
 4 files changed, 743 insertions(+)
 create mode 100644 drivers/dma/loongson/loongson2-apb-cmc-dma.c
MAINTAINERS +1 -0
index aea29c28d865..af9fbb3b43e2 100644
@@ -14954,6 +14954,7 @@ L:	[email protected]
 S:	Maintained
 F:	Documentation/devicetree/bindings/dma/loongson,ls2k0300-dma.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
 
 LOONGSON LS2X I2C DRIVER
drivers/dma/loongson/Kconfig +11 -0
index 0a865a8fd3a6..c4e62dce5d4f 100644
@@ -27,4 +27,15 @@ config LOONGSON2_APB_DMA
 	  This DMA controller transfers data from memory to peripheral fifo.
 	  It does not support memory to memory data transfer.
 
+config LOONGSON2_APB_CMC_DMA
+	tristate "Loongson2 Chain Multi-Channel DMA support"
+	depends on MACH_LOONGSON64 || COMPILE_TEST
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	help
+	  Support for the Loongson Chain Multi-Channel DMA controller driver.
+	  It is discovered on the Loongson-2K chip (Loongson-2K0300/Loongson-2K3000),
+	  which has 4/8 channels internally, enabling bidirectional data transfer
+	  between devices and memory.
+
 endif
drivers/dma/loongson/Makefile +1 -0
index 6cdd08065e92..48c19781e729 100644
@@ -1,3 +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
drivers/dma/loongson/loongson2-apb-cmc-dma.c new file +730 -0

730 lines not on this page · raw message

Signature · 1 line
2.52.0
maintainer Reviewed-by on the v4 series
#8 lore raw
In reply to Binbin Zhou
Quoted 6 lines · Binbin Zhou

Hi all:

This patchset introduces the Loongson multi-channel DMA controller, which is present in the Loongson-2K0300 and Loongson-2K3000 processors.

Quoted 7 lines

It is a multi-channel controller that enables data transfers from memory to memory, device to memory, and memory to device, as well as channel prioritization configurable through the channel configuration registers.

Additionally, since multiple distinct types of DMA controllers exist on the Loongson platform, I have attempted to consolidate all Loongson DMA drivers into a new directory named Loongson for easier management.

For the whole series,

Quoted 98 lines

Thanks.
Binbin

===========
V4:
- Rebase on dmaengine/next tree;
- Add Reviewed-by tags from Frank and Rob, thanks;

patch(1/6):
- Add depends on restrictions.

patch(6/6):
- Move loongson2_cmc_dma_config{..} close to its users.

Link to V3:
https://lore.kernel.org/dmaengine/[email protected]/

V3:
- Rebase on dmaengine/next tree;

patch(1/6):
- Keep alphabet order;

patch(2/6):
- Add Reviewed-by tag from Frank, thanks;

patch(3/6)/(4/6):
- New patches, format loongson2-apb-dma driver code;

patch(5/6):
- Add description for interrupts property;

patch(6/6):
- Use ffs() helper make the code cleaner;
- Refact loongson2_cmc_dma_chan_irq();
- Simplify locking with guard() and scoped_guard();
- kzalloc()->kzalloc_flex().

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

V2:
patch(1/4):
- Update loongson1-apb-dma.c entry in MAINTAINERS.

patch(2/4):
- New patch, use dmaenginem_async_device_register() helper.

patch(3/4):
- additionalProperties: false replaced by
unevaluatedProperties: false.

patch(4/4):
- Rename filename as loongson2-apb-cmc-dma.c;
- Rename Kconfig item as LOONGSON2_APB_CMC_DMA;
- Rename the variable prefix as loongson2_cmc_dma;
- Use dmaenginem_async_device_register() helper;
- Drop 'dma_' prefix in struct loongson2_mdma_chan_reg;
- Use struct_size();

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

Binbin Zhou (6):
dmaengine: loongson: New directory for Loongson DMA controllers
drivers
dmaengine: loongson: loongson2-apb: Convert to
dmaenginem_async_device_register()
dmaengine: loongson: loongson2-apb: Convert to devm_clk_get_enabled()
dmaengine: loongson: loongson2-apb: Simplify locking with guard() and
scoped_guard()
dt-bindings: dmaengine: Add Loongson Multi-Channel DMA controller
dmaengine: loongson: New driver for the Loongson Multi-Channel DMA
controller

 .../bindings/dma/loongson,ls2k0300-dma.yaml   |  81 ++
 MAINTAINERS                                   |   7 +-
 drivers/dma/Kconfig                           |  25 +-
 drivers/dma/Makefile                          |   3 +-
 drivers/dma/loongson/Kconfig                  |  41 +
 drivers/dma/loongson/Makefile                 |   4 +
 .../dma/{ => loongson}/loongson1-apb-dma.c    |   4 +-
 drivers/dma/loongson/loongson2-apb-cmc-dma.c  | 730 ++++++++++++++++++
 .../dma/{ => loongson}/loongson2-apb-dma.c    |  93 +--
 9 files changed, 903 insertions(+), 85 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/dma/loongson,ls2k0300-dma.yaml
 create mode 100644 drivers/dma/loongson/Kconfig
 create mode 100644 drivers/dma/loongson/Makefile
 rename drivers/dma/{ => loongson}/loongson1-apb-dma.c (99%)
 create mode 100644 drivers/dma/loongson/loongson2-apb-cmc-dma.c
 rename drivers/dma/{ => loongson}/loongson2-apb-dma.c (91%)

base-commit: c8e9b1d9febc83ee94944695a07cfd40a1b29743 --
2.52.0

maintainer Applied
#9 lore raw
In reply to Binbin Zhou
Quoted 8 lines · Binbin Zhou

This patchset introduces the Loongson multi-channel DMA controller, which is present in the Loongson-2K0300 and Loongson-2K3000 processors.

It is a multi-channel controller that enables data transfers from memory to memory, device to memory, and memory to device, as well as channel prioritization configurable through the channel configuration registers.

[...]

Applied, thanks!

[1/6] dmaengine: loongson: New directory for Loongson DMA controllers drivers

      commit: ffee2dc04e7e06534aaa4fd51ef89645b809b6b8
[2/6] dmaengine: loongson: loongson2-apb: Convert to dmaenginem_async_device_register()
      commit: 7d348227f4961bbf21255281438ee3aebe12830f
[3/6] dmaengine: loongson: loongson2-apb: Convert to devm_clk_get_enabled()
      commit: bdf1621a6a67b6327e2a26a1d47bffcde3be3b26
[4/6] dmaengine: loongson: loongson2-apb: Simplify locking with guard() and scoped_guard()
      commit: 9de4303fc04977d15b257726a6519caca687c43a
[5/6] dt-bindings: dmaengine: Add Loongson Multi-Channel DMA controller
      commit: 7a65e81e8e2e58b0db9f2dedda410ee2b6042859
[6/6] dmaengine: loongson: New driver for the Loongson Multi-Channel DMA controller
      commit: 1c0028e725f156ebabe68b0025f9c8e7a6170ffd

Best regards,

Signature · 1 line
~Vinod