Skip to contentSkip to conversation

dmaengine: Add support Oxford Semiconductor OXNAS DMA Engine

PATCH In review Neil Armstrong 3 participants 7 messages Jan 4, 2022 – Jan 12, 2022

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

cover dmaengine: Add support Oxford Semiconductor OXNAS DMA Engine

This serie adds support for the DMA engine found in Oxford Semiconductor SoCs, notably in the OX810SE where it's heavily used for SATA transfers.

The driver was on my pipe since 2016 and a courageous person managed to get the SATA driver work up mainline kernel with this driver, so I cleaned it up in order to be upstreamed.

I plan to push the last patch through arm-soc when bindings is applied.

Neil Armstrong (4):
dt-bindings: dma: Add bindings for ox810se dma engine
dmaengine: Add Oxford Semiconductor OXNAS DMA Controller
MAINTAINERS: add OX810SE DMA driver files under Oxnas entry
ARM: dts: ox810se: Add DMA Support

 .../bindings/dma/oxsemi,ox810se-dma.yaml      |   97 ++
 MAINTAINERS                                   |    2 +
 arch/arm/boot/dts/ox810se-wd-mbwe.dts         |    4 +
 arch/arm/boot/dts/ox810se.dtsi                |   21 +
 drivers/dma/Kconfig                           |    8 +
 drivers/dma/Makefile                          |    1 +
 drivers/dma/oxnas_adma.c                      | 1045 +++++++++++++++++
 7 files changed, 1178 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml
 create mode 100644 drivers/dma/oxnas_adma.c

base-commit: fa55b7dcdc43c1aa1ba12bca9d2dd4318c2a0dbf

Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/4 dt-bindings: dma: Add bindings for ox810se dma engine

This adds the YAML dt-bindings for the DMA engine found in the Oxford Semiconductor OX810SE SoC.

---
 .../bindings/dma/oxsemi,ox810se-dma.yaml      | 97 +++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml
Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml new file +97 -0
new file mode 100644
index 000000000000..6efa28e8b124
@@ -0,0 +1,97 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/oxsemi,ox810se-dma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Oxford Semiconductor DMA Controller Device Tree Bindings
+
+maintainers:
+  - Neil Armstrong <[email protected]>
+
+allOf:
+  - $ref: "dma-controller.yaml#"
+
+properties:
+  "#dma-cells":
+    const: 1
+
+  compatible:
+    const: oxsemi,ox810se-dma
+
+  reg:
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: dma
+      - const: sgdma
+
+  interrupts:
+    maxItems: 5
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 2
+
+  reset-names:
+    items:
+      - const: dma
+      - const: sgdma
+
+  dma-channels: true
+
+  oxsemi,targets-types:
+    description:
+      Table with allowed memory ranges and memory type associated.
+    $ref: "/schemas/types.yaml#/definitions/uint32-matrix"
+    minItems: 4
+    items:
+      items:
+        - description:
+            The first cell defines the memory range start address
+        - description:
+            The first cell defines the memory range end address
+        - description:
+            The third cell represents memory type, 0 for SATA,
+            1 for DPE RX, 2 for DPE TX, 5 for AUDIO TX, 6 for AUDIO RX,
+            15 for DRAM MEMORY.
+          enum: [ 0, 1, 2, 5, 6, 15 ]
+
+required:
+  - "#dma-cells"
+  - dma-channels
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - resets
+  - reset-names
+  - oxsemi,targets-types
+
+additionalProperties: false
+
+examples:
+  - |
+    dma: dma-controller@600000 {
+        compatible = "oxsemi,ox810se-dma";
+        reg = <0x600000 0x100000>, <0xc00000 0x100000>;
+        reg-names = "dma", "sgdma";
+        interrupts = <13>, <14>, <15>, <16>, <20>;
+        clocks = <&stdclk 1>;
+        resets = <&reset 8>, <&reset 24>;
+        reset-names = "dma", "sgdma";
+
+        /* Encodes the authorized memory types */
+        oxsemi,targets-types =
+            <0x45900000 0x45a00000 0>,  /* SATA */
+            <0x42000000 0x43000000 0>,  /* SATA DATA */
+            <0x48000000 0x58000000 15>, /* DDR */
+            <0x58000000 0x58020000 15>; /* SRAM */
+
+        #dma-cells = <1>;
+        dma-channels = <5>;
+    };
+...
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH 1/4] dt-bindings: dma: Add bindings for ox810se dma engine

Quoted 36 lines · Neil Armstrong

This adds the YAML dt-bindings for the DMA engine found in the Oxford Semiconductor OX810SE SoC.

---
 .../bindings/dma/oxsemi,ox810se-dma.yaml      | 97 +++++++++++++++++++
 1 file changed, 97 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml
Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml new file +21 -0
new file mode 100644
index 000000000000..6efa28e8b124
@@ -0,0 +1,97 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/dma/oxsemi,ox810se-dma.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Oxford Semiconductor DMA Controller Device Tree Bindings
+
+maintainers:
+  - Neil Armstrong <[email protected]>
+
+allOf:
+  - $ref: "dma-controller.yaml#"
+
+properties:
+  "#dma-cells":
+    const: 1
+
+  compatible:
+    const: oxsemi,ox810se-dma
+

Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml line 31

Quoted 10 lines
Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml new file +10 -0
+  reg:
+    maxItems: 2
+
+  reg-names:
+    items:
+      - const: dma
+      - const: sgdma
+
+  interrupts:
+    maxItems: 5

Need to define what each one is.

Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml line 44

Quoted 13 lines
Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml new file +13 -0
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 2
+
+  reset-names:
+    items:
+      - const: dma
+      - const: sgdma
+
+  dma-channels: true

Constraints on number of channels?

Quoted 24 lines
Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml new file +24 -0
+
+  oxsemi,targets-types:
+    description:
+      Table with allowed memory ranges and memory type associated.
+    $ref: "/schemas/types.yaml#/definitions/uint32-matrix"
+    minItems: 4
+    items:
+      items:
+        - description:
+            The first cell defines the memory range start address
+        - description:
+            The first cell defines the memory range end address
+        - description:
+            The third cell represents memory type, 0 for SATA,
+            1 for DPE RX, 2 for DPE TX, 5 for AUDIO TX, 6 for AUDIO RX,
+            15 for DRAM MEMORY.
+          enum: [ 0, 1, 2, 5, 6, 15 ]
+
+required:
+  - "#dma-cells"
+  - dma-channels
+  - compatible
+  - reg
+  - interrupts

Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml line 78

Quoted 10 lines
Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml new file +10 -0
+  - clocks
+  - resets
+  - reset-names
+  - oxsemi,targets-types
+
+additionalProperties: false
+
+examples:
+  - |
+    dma: dma-controller@600000 {

Drop unused labels.

Quoted 23 lines
Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml new file +19 -0
+        compatible = "oxsemi,ox810se-dma";
+        reg = <0x600000 0x100000>, <0xc00000 0x100000>;
+        reg-names = "dma", "sgdma";
+        interrupts = <13>, <14>, <15>, <16>, <20>;
+        clocks = <&stdclk 1>;
+        resets = <&reset 8>, <&reset 24>;
+        reset-names = "dma", "sgdma";
+
+        /* Encodes the authorized memory types */
+        oxsemi,targets-types =
+            <0x45900000 0x45a00000 0>,  /* SATA */
+            <0x42000000 0x43000000 0>,  /* SATA DATA */
+            <0x48000000 0x58000000 15>, /* DDR */
+            <0x58000000 0x58020000 15>; /* SRAM */
+
+        #dma-cells = <1>;
+        dma-channels = <5>;
+    };
+...
Signature · 1 line
2.25.1
#3 lore raw

PATCH 2/4 dmaengine: Add Oxford Semiconductor OXNAS DMA Controller

In reply to Neil Armstrong

The Oxford Semiconductor OX810SE contains a DMA engine mainly used for the SATA controller which doesn't have an embedded DMA engine.

This DMA engine support single and scatter-gather memory-to-memory transfers and device-to-memory/memory-to-device transfers.

---
 drivers/dma/Kconfig      |    8 +
 drivers/dma/Makefile     |    1 +
 drivers/dma/oxnas_adma.c | 1045 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 1054 insertions(+)
 create mode 100644 drivers/dma/oxnas_adma.c
drivers/dma/Kconfig +8 -0
index 6bcdb4e6a0d1..8925ffd85ac2 100644
@@ -505,6 +505,14 @@ config OWL_DMA
 	help
 	  Enable support for the Actions Semi Owl SoCs DMA controller.
 
+config OXNAS_DMA
+	bool "Oxford Semiconductor OXNAS SoC Family DMA support"
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
+	depends on ARCH_OXNAS || COMPILE_TEST
+	help
+	  Support for Oxford Semiconductor OXNAS SoC Family DMA engine
+
 config PCH_DMA
 	tristate "Intel EG20T PCH / LAPIS Semicon IOH(ML7213/ML7223/ML7831) DMA"
 	depends on PCI && (X86_32 || COMPILE_TEST)
drivers/dma/Makefile +1 -0
index 616d926cf2a5..ba1111785bb8 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_MXS_DMA) += mxs-dma.o
 obj-$(CONFIG_MX3_IPU) += ipu/
 obj-$(CONFIG_NBPFAXI_DMA) += nbpfaxi.o
 obj-$(CONFIG_OWL_DMA) += owl-dma.o
+obj-$(CONFIG_OXNAS_DMA) += oxnas_adma.o
 obj-$(CONFIG_PCH_DMA) += pch_dma.o
 obj-$(CONFIG_PL330_DMA) += pl330.o
 obj-$(CONFIG_PLX_DMA) += plx_dma.o
drivers/dma/oxnas_adma.c new file +1045 -0

1,045 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH 2/4] dmaengine: Add Oxford Semiconductor OXNAS DMA Controller

I love your patch! Perhaps something to improve:

Hi Neil,

I love your patch! Perhaps something to improve:

[auto build test WARNING on fa55b7dcdc43c1aa1ba12bca9d2dd4318c2a0dbf]

url:    https://github.com/0day-ci/linux/commits/Neil-Armstrong/dmaengine-Add-support-Oxford-Semiconductor-OXNAS-DMA-Engine/20220104-225322
base:   fa55b7dcdc43c1aa1ba12bca9d2dd4318c2a0dbf
config: arc-allyesconfig (https://download.01.org/0day-ci/archive/20220105/202201050144.3TpBzQkL-lkp(a)intel.com/config)
compiler: arceb-elf-gcc (GCC) 11.2.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/55f80a9eaf56cb8c1b943a7ea35e3a97aecc628d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Neil-Armstrong/dmaengine-Add-support-Oxford-Semiconductor-OXNAS-DMA-Engine/20220104-225322 git checkout 55f80a9eaf56cb8c1b943a7ea35e3a97aecc628d
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=arc SHELL=/bin/bash drivers/dma/

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

         |                                                               |
         |                                                               unsigned int
         |                                                            %08llx
   In file included from include/linux/printk.h:555,
                    from include/linux/kernel.h:20,
                    from include/linux/cpumask.h:10,
                    from include/linux/mm_types_task.h:14,
                    from include/linux/mm_types.h:5,
                    from include/linux/buildid.h:5,
                    from include/linux/module.h:14,
                    from drivers/dma/oxnas_adma.c:7:
   drivers/dma/oxnas_adma.c:655:37: warning: format '%x' expects argument of type 'unsigned int', but argument 5 has type 'dma_addr_t' {aka 'long long unsigned int'} [-Wformat=]
     655 |         dev_dbg(&dmadev->pdev->dev, "preparing memcpy from %08x to %08x, %lubytes (flags %x)\n",
         |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:134:29: note: in definition of macro '__dynamic_func_call'
     134 |                 func(&id, ##__VA_ARGS__);               \
         |                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:166:9: note: in expansion of macro '_dynamic_func_call'
     166 |         _dynamic_func_call(fmt,__dynamic_dev_dbg,               \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:9: note: in expansion of macro 'dynamic_dev_dbg'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:30: note: in expansion of macro 'dev_fmt'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                              ^~~~~~~
   drivers/dma/oxnas_adma.c:655:9: note: in expansion of macro 'dev_dbg'
     655 |         dev_dbg(&dmadev->pdev->dev, "preparing memcpy from %08x to %08x, %lubytes (flags %x)\n",
         |         ^~~~~~~
   drivers/dma/oxnas_adma.c:655:71: note: format string is defined here
     655 |         dev_dbg(&dmadev->pdev->dev, "preparing memcpy from %08x to %08x, %lubytes (flags %x)\n",
         |                                                                    ~~~^
         |                                                                       |
         |                                                                       unsigned int
         |                                                                    %08llx
   In file included from include/linux/printk.h:555,
                    from include/linux/kernel.h:20,
                    from include/linux/cpumask.h:10,
                    from include/linux/mm_types_task.h:14,
                    from include/linux/mm_types.h:5,
                    from include/linux/buildid.h:5,
                    from include/linux/module.h:14,
                    from drivers/dma/oxnas_adma.c:7:
   drivers/dma/oxnas_adma.c: In function 'oxnas_dma_probe':
   drivers/dma/oxnas_adma.c:869:37: warning: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'dma_addr_t' {aka 'long long unsigned int'} [-Wformat=]
     869 |                 dev_dbg(&pdev->dev, "0x%08x-0x%08x = %d\n",
         |                                     ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:134:29: note: in definition of macro '__dynamic_func_call'
     134 |                 func(&id, ##__VA_ARGS__);               \
         |                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:166:9: note: in expansion of macro '_dynamic_func_call'
     166 |         _dynamic_func_call(fmt,__dynamic_dev_dbg,               \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:9: note: in expansion of macro 'dynamic_dev_dbg'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:30: note: in expansion of macro 'dev_fmt'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                              ^~~~~~~
   drivers/dma/oxnas_adma.c:869:17: note: in expansion of macro 'dev_dbg'
     869 |                 dev_dbg(&pdev->dev, "0x%08x-0x%08x = %d\n",
         |                 ^~~~~~~
   drivers/dma/oxnas_adma.c:869:43: note: format string is defined here
     869 |                 dev_dbg(&pdev->dev, "0x%08x-0x%08x = %d\n",
         |                                        ~~~^
         |                                           |
         |                                           unsigned int
         |                                        %08llx
   In file included from include/linux/printk.h:555,
                    from include/linux/kernel.h:20,
                    from include/linux/cpumask.h:10,
                    from include/linux/mm_types_task.h:14,
                    from include/linux/mm_types.h:5,
                    from include/linux/buildid.h:5,
                    from include/linux/module.h:14,
                    from drivers/dma/oxnas_adma.c:7:
   drivers/dma/oxnas_adma.c:869:37: warning: format '%x' expects argument of type 'unsigned int', but argument 5 has type 'dma_addr_t' {aka 'long long unsigned int'} [-Wformat=]
     869 |                 dev_dbg(&pdev->dev, "0x%08x-0x%08x = %d\n",
         |                                     ^~~~~~~~~~~~~~~~~~~~~~
   include/linux/dynamic_debug.h:134:29: note: in definition of macro '__dynamic_func_call'
     134 |                 func(&id, ##__VA_ARGS__);               \
         |                             ^~~~~~~~~~~
   include/linux/dynamic_debug.h:166:9: note: in expansion of macro '_dynamic_func_call'
     166 |         _dynamic_func_call(fmt,__dynamic_dev_dbg,               \
         |         ^~~~~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:9: note: in expansion of macro 'dynamic_dev_dbg'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |         ^~~~~~~~~~~~~~~
   include/linux/dev_printk.h:155:30: note: in expansion of macro 'dev_fmt'
     155 |         dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
         |                              ^~~~~~~
   drivers/dma/oxnas_adma.c:869:17: note: in expansion of macro 'dev_dbg'
     869 |                 dev_dbg(&pdev->dev, "0x%08x-0x%08x = %d\n",
         |                 ^~~~~~~
   drivers/dma/oxnas_adma.c:869:50: note: format string is defined here
     869 |                 dev_dbg(&pdev->dev, "0x%08x-0x%08x = %d\n",
         |                                               ~~~^
         |                                                  |
         |                                                  unsigned int
         |                                               %08llx
>> drivers/dma/oxnas_adma.c:915:40: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     915 |                         (dma_addr_t)&(((struct oxnas_dma_sg_data *)dmadev->p_sg_data)->entries[i]);
         |                                        ^
>> drivers/dma/oxnas_adma.c:915:25: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     915 |                         (dma_addr_t)&(((struct oxnas_dma_sg_data *)dmadev->p_sg_data)->entries[i]);
         |                         ^
   drivers/dma/oxnas_adma.c:944:39: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
     944 |                         (dma_addr_t)&((struct oxnas_dma_sg_data *)dmadev->p_sg_data)->infos[i];
         |                                       ^
   drivers/dma/oxnas_adma.c:944:25: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     944 |                         (dma_addr_t)&((struct oxnas_dma_sg_data *)dmadev->p_sg_data)->infos[i];
         |                         ^

vim +915 drivers/dma/oxnas_adma.c

794
795 static int oxnas_dma_probe(struct platform_device *pdev)
796 {
797 struct oxnas_dma_device *dmadev;
798 struct resource *res;
799 int hwid, i, ret;
800
801 dmadev = devm_kzalloc(&pdev->dev, sizeof(struct oxnas_dma_device), GFP_KERNEL);
802 if (!dmadev)
803 return -ENOMEM;
804
805 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
806 dmadev->dma_base = devm_ioremap_resource(&pdev->dev, res);
807 if (IS_ERR(dmadev->dma_base))
808 return PTR_ERR(dmadev->dma_base);
809
810 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
811 dmadev->sgdma_base = devm_ioremap_resource(&pdev->dev, res);
812 if (IS_ERR(dmadev->sgdma_base))
813 return PTR_ERR(dmadev->sgdma_base);
814
815 dmadev->dma_rst = devm_reset_control_get(&pdev->dev, "dma");
816 if (IS_ERR(dmadev->dma_rst))
817 return PTR_ERR(dmadev->dma_rst);
818
819 dmadev->sgdma_rst = devm_reset_control_get(&pdev->dev, "sgdma");
820 if (IS_ERR(dmadev->sgdma_rst))
821 return PTR_ERR(dmadev->sgdma_rst);
822
823 dmadev->dma_clk = devm_clk_get(&pdev->dev, 0);
824 if (IS_ERR(dmadev->dma_clk))
825 return PTR_ERR(dmadev->dma_clk);
826
827 ret = of_property_count_elems_of_size(pdev->dev.of_node, "oxsemi,targets-types", 4);
828 if (ret <= 0 || (ret % 3) != 0) {
829 dev_err(&pdev->dev, "malformed or missing oxsemi,targets-types\n");
830 return -EINVAL;
831 }
832
833 dmadev->authorized_types_count = ret / 3;
834 dmadev->authorized_types = devm_kzalloc(&pdev->dev,
835 sizeof(*dmadev->authorized_types) * dmadev->authorized_types_count, GFP_KERNEL);
836
837 if (!dmadev->authorized_types)
838 return -ENOMEM;
839
840 for (i = 0 ; i < dmadev->authorized_types_count ; ++i) {
841 u32 value;
842
843 ret = of_property_read_u32_index(pdev->dev.of_node,
844 "oxsemi,targets-types",
845 (i * 3), &value);
846 if (ret < 0)
847 return ret;
848
849 dmadev->authorized_types[i].start = value;
850 ret = of_property_read_u32_index(pdev->dev.of_node,
851 "oxsemi,targets-types",
852 (i * 3) + 1, &value);
853 if (ret < 0)
854 return ret;
855
856 dmadev->authorized_types[i].end = value;
857 ret = of_property_read_u32_index(pdev->dev.of_node,
858 "oxsemi,targets-types",
859 (i * 3) + 2, &value);
860 if (ret < 0)
861 return ret;
862
863 dmadev->authorized_types[i].type = value;
864 }
865
866 dev_dbg(&pdev->dev, "Authorized memory ranges :\n");
867 dev_dbg(&pdev->dev, " Start - End = Type\n");
868 for (i = 0 ; i < dmadev->authorized_types_count ; ++i)
869 dev_dbg(&pdev->dev, "0x%08x-0x%08x = %d\n",
870 dmadev->authorized_types[i].start,
871 dmadev->authorized_types[i].end,
872 dmadev->authorized_types[i].type);
873
874 dmadev->pdev = pdev;
875
876 spin_lock_init(&dmadev->lock);
877
878 tasklet_init(&dmadev->tasklet, oxnas_dma_sched, (unsigned long)dmadev);
879 INIT_LIST_HEAD(&dmadev->common.channels);
880 INIT_LIST_HEAD(&dmadev->pending);
881 INIT_LIST_HEAD(&dmadev->free_entries);
882
883 /* Enable HW & Clocks */
884 reset_control_reset(dmadev->dma_rst);
885 reset_control_reset(dmadev->sgdma_rst);
886 clk_prepare_enable(dmadev->dma_clk);
887
888 /* Discover the number of channels available */
889 hwid = readl(dmadev->dma_base + DMA_CALC_REG_ADR(0, DMA_INTR_ID));
890 dmadev->channels_count = DMA_INTR_ID_GET_NUM_CHANNELS(hwid);
891 dmadev->hwversion = DMA_INTR_ID_GET_VERSION(hwid);
892
893 dev_dbg(&pdev->dev, "OXNAS DMA v%x with %d channels\n",
894 dmadev->hwversion, dmadev->channels_count);
895
896 /* Limit channels count */
897 if (dmadev->channels_count > MAX_OXNAS_DMA_CHANNELS)
898 dmadev->channels_count = MAX_OXNAS_DMA_CHANNELS;
899
900 /* Allocate coherent memory for sg descriptors */
901 dmadev->sg_data = dma_alloc_coherent(&pdev->dev, sizeof(struct oxnas_dma_sg_data),
902 &dmadev->p_sg_data, GFP_KERNEL);
903 if (!dmadev->sg_data) {
904 ret = -ENOMEM;
905 goto disable_clks;
906 }
907
908 /* Reset SG descritors */
909 memset(dmadev->sg_data, 0, sizeof(struct oxnas_dma_sg_data));
910 atomic_set(&dmadev->free_entries_count, 0);
911
912 /* Initialize and add all sg entries to the free list */
913 for (i = 0 ; i < MAX_OXNAS_SG_ENTRIES ; ++i) {
914 dmadev->sg_data->entries[i].this_paddr =

 > 915				(dma_addr_t)&(((struct oxnas_dma_sg_data *)dmadev->p_sg_data)->entries[i]);

916 INIT_LIST_HEAD(&dmadev->sg_data->entries[i].entry);
917 list_add_tail(&dmadev->sg_data->entries[i].entry,
918 &dmadev->free_entries);
919 atomic_inc(&dmadev->free_entries_count);
920 }
921
922 /* Init all channels */
923 for (i = 0 ; i < dmadev->channels_count ; ++i) {
924 struct oxnas_dma_channel *ch = &dmadev->channels[i];
925
926 ch->dmadev = dmadev;
927 ch->id = i;
928
929 ch->irq = irq_of_parse_and_map(pdev->dev.of_node, i);
930 if (ch->irq <= 0) {
931 dev_err(&pdev->dev, "invalid irq%d from platform\n", i);
932 goto free_coherent;
933 }
934
935 ret = devm_request_irq(&pdev->dev, ch->irq,
936 oxnas_dma_interrupt, 0,
937 "DMA", ch);
938 if (ret < 0) {
939 dev_err(&pdev->dev, "failed to request irq%d\n", i);
940 goto free_coherent;
941 }
942
943 ch->p_sg_info =
944 (dma_addr_t)&((struct oxnas_dma_sg_data *)dmadev->p_sg_data)->infos[i];
945 ch->sg_info = &dmadev->sg_data->infos[i];
946 memset(ch->sg_info, 0, sizeof(struct oxnas_dma_sg_info));
947
948 atomic_set(&ch->active, 0);
949
950 ch->vc.desc_free = oxnas_dma_desc_free;
951 vchan_init(&ch->vc, &dmadev->common);
952 INIT_LIST_HEAD(&ch->node);
953 }
954
955 platform_set_drvdata(pdev, dmadev);
956
957 dma_cap_set(DMA_MEMCPY, dmadev->common.cap_mask);
958 dmadev->common.chancnt = dmadev->channels_count;
959 dmadev->common.device_free_chan_resources = oxnas_dma_free_chan_resources;
960 dmadev->common.device_tx_status = oxnas_dma_tx_status;
961 dmadev->common.device_issue_pending = oxnas_dma_issue_pending;
962 dmadev->common.device_prep_dma_memcpy = oxnas_dma_prep_dma_memcpy;
963 dmadev->common.device_prep_slave_sg = oxnas_dma_prep_slave_sg;
964 dmadev->common.device_config = oxnas_dma_slave_config;
965 dmadev->common.copy_align = DMAENGINE_ALIGN_4_BYTES;
966 dmadev->common.src_addr_widths = DMA_SLAVE_BUSWIDTH_4_BYTES;
967 dmadev->common.dst_addr_widths = DMA_SLAVE_BUSWIDTH_4_BYTES;
968 dmadev->common.directions = BIT(DMA_MEM_TO_MEM);
969 dmadev->common.residue_granularity = DMA_RESIDUE_GRANULARITY_DESCRIPTOR;
970 dmadev->common.dev = &pdev->dev;
971
972 ret = dma_async_device_register(&dmadev->common);
973 if (ret)
974 goto free_coherent;
975
976 ret = of_dma_controller_register(pdev->dev.of_node,
977 of_dma_xlate_by_chan_id,
978 &dmadev->common);
979 if (ret) {
980 dev_warn(&pdev->dev, "Failed to register DMA Controller\n");
981 goto dma_unregister;
982 }
983
984 dev_info(&pdev->dev, "OXNAS DMA Registered\n");
985
986 return 0;
987
988 dma_unregister:
989 dma_async_device_unregister(&dmadev->common);
990
991 free_coherent:
992 dma_free_coherent(&pdev->dev, sizeof(struct oxnas_dma_sg_data),
993 dmadev->sg_data, dmadev->p_sg_data);
994
995 disable_clks:
996 clk_disable_unprepare(dmadev->dma_clk);
997
998 return ret;
999 }
1000

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#5 lore raw

PATCH 3/4 MAINTAINERS: add OX810SE DMA driver files under Oxnas entry

In reply to Neil Armstrong

Add the DMA driver file and bindings in the Oxnas maintainers entry.

---
 MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
index 7a2345ce8521..782332ab0d9b 100644
@@ -2371,8 +2371,10 @@ M:	Neil Armstrong <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
 L:	[email protected] (moderated for non-subscribers)
 S:	Maintained
+F:	Documentation/devicetree/bindings/dma/oxsemi,ox810se-dma.yaml
 F:	arch/arm/boot/dts/ox8*.dts*
 F:	arch/arm/mach-oxnas/
+F:	drivers/dma/oxnas_adma.c
 F:	drivers/power/reset/oxnas-restart.c
 N:	oxnas
 
Signature · 1 line
2.25.1
#6 lore raw

PATCH 4/4 ARM: dts: ox810se: Add DMA Support

In reply to Neil Armstrong

This adds the DMA engine node.

---
 arch/arm/boot/dts/ox810se-wd-mbwe.dts |  4 ++++
 arch/arm/boot/dts/ox810se.dtsi        | 21 +++++++++++++++++++++
 2 files changed, 25 insertions(+)
arch/arm/boot/dts/ox810se-wd-mbwe.dts +4 -0
index 7e2fcb220aea..19e5d510e425 100644
@@ -103,6 +103,10 @@ rtc0: rtc@48 {
 	};
 };
 
+&dma {
+	status = "okay";
+};
+
 &uart1 {
 	status = "okay";
 
arch/arm/boot/dts/ox810se.dtsi +21 -0
index 0755e5864c4a..79b2b49dcfbb 100644
@@ -334,6 +334,27 @@ timer0: timer@200 {
 					interrupts = <4 5>;
 				};
 			};
+
+			dma: dma-controller@600000 {
+				compatible = "oxsemi,ox810se-dma";
+				reg = <0x600000 0x100000>,
+				      <0xc00000 0x100000>;
+				reg-names = "dma", "sgdma";
+				interrupts = <13>, <14>, <15>, <16>, <20>;
+				clocks = <&stdclk 1>;
+				resets = <&reset 8>, <&reset 24>;
+				reset-names = "dma", "sgdma";
+
+				/* Encodes the authorized memory types */
+				oxsemi,targets-types =
+					<0x45900000 0x45a00000 0>,  /* SATA */
+					<0x42000000 0x43000000 0>,  /* SATA DATA */
+					<0x48000000 0x58000000 15>, /* DDR */
+					<0x58000000 0x58020000 15>; /* SRAM */
+
+				#dma-cells = <1>;
+				dma-channels = <5>;
+			};
 		};
 	};
 };
Signature · 1 line
2.25.1