]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
Merge branch 'topic/imx' into for-linus
authorVinod Koul <vkoul@kernel.org>
Fri, 17 Aug 2018 12:29:27 +0000 (17:59 +0530)
committerVinod Koul <vkoul@kernel.org>
Fri, 17 Aug 2018 12:29:27 +0000 (17:59 +0530)
24 files changed:
Documentation/devicetree/bindings/dma/owl-dma.txt [new file with mode: 0644]
Documentation/devicetree/bindings/dma/renesas,rcar-dmac.txt
Documentation/devicetree/bindings/dma/xilinx/xilinx_dma.txt
Documentation/driver-model/devres.txt
crypto/async_tx/async_pq.c
crypto/async_tx/raid6test.c
drivers/dma/Kconfig
drivers/dma/Makefile
drivers/dma/dmaengine.c
drivers/dma/hsu/hsu.c
drivers/dma/idma64.c
drivers/dma/ioat/dma.c
drivers/dma/mic_x100_dma.c
drivers/dma/mv_xor_v2.c
drivers/dma/nbpfaxi.c
drivers/dma/owl-dma.c [new file with mode: 0644]
drivers/dma/sh/rcar-dmac.c
drivers/dma/ste_dma40.c
drivers/dma/stm32-dma.c
drivers/dma/stm32-mdma.c
drivers/dma/xilinx/xilinx_dma.c
include/linux/dma/xilinx_dma.h
include/linux/dmaengine.h
sound/soc/soc-generic-dmaengine-pcm.c

diff --git a/Documentation/devicetree/bindings/dma/owl-dma.txt b/Documentation/devicetree/bindings/dma/owl-dma.txt
new file mode 100644 (file)
index 0000000..03e9bb1
--- /dev/null
@@ -0,0 +1,47 @@
+* Actions Semi Owl SoCs DMA controller
+
+This binding follows the generic DMA bindings defined in dma.txt.
+
+Required properties:
+- compatible: Should be "actions,s900-dma".
+- reg: Should contain DMA registers location and length.
+- interrupts: Should contain 4 interrupts shared by all channel.
+- #dma-cells: Must be <1>. Used to represent the number of integer
+              cells in the dmas property of client device.
+- dma-channels: Physical channels supported.
+- dma-requests: Number of DMA request signals supported by the controller.
+                Refer to Documentation/devicetree/bindings/dma/dma.txt
+- clocks: Phandle and Specifier of the clock feeding the DMA controller.
+
+Example:
+
+Controller:
+                dma: dma-controller@e0260000 {
+                        compatible = "actions,s900-dma";
+                        reg = <0x0 0xe0260000 0x0 0x1000>;
+                        interrupts = <GIC_SPI 57 IRQ_TYPE_LEVEL_HIGH>,
+                                     <GIC_SPI 58 IRQ_TYPE_LEVEL_HIGH>,
+                                     <GIC_SPI 59 IRQ_TYPE_LEVEL_HIGH>,
+                                     <GIC_SPI 60 IRQ_TYPE_LEVEL_HIGH>;
+                        #dma-cells = <1>;
+                        dma-channels = <12>;
+                        dma-requests = <46>;
+                        clocks = <&clock CLK_DMAC>;
+                };
+
+Client:
+
+DMA clients connected to the Actions Semi Owl SoCs DMA controller must
+use the format described in the dma.txt file, using a two-cell specifier
+for each channel.
+
+The two cells in order are:
+1. A phandle pointing to the DMA controller.
+2. The channel id.
+
+uart5: serial@e012a000 {
+        ...
+        dma-names = "tx", "rx";
+        dmas = <&dma 26>, <&dma 27>;
+        ...
+};
index b1ba639554c087c0de5bab69b3b6abb208c6931a..946229c48657cfa255b6ea913b5b41c18929e5ff 100644 (file)
@@ -29,6 +29,7 @@ Required Properties:
                - "renesas,dmac-r8a77965" (R-Car M3-N)
                - "renesas,dmac-r8a77970" (R-Car V3M)
                - "renesas,dmac-r8a77980" (R-Car V3H)
+               - "renesas,dmac-r8a77990" (R-Car E3)
                - "renesas,dmac-r8a77995" (R-Car D3)
 
 - reg: base address and length of the registers block for the DMAC
index a2b8bfaec43cc12654175f22494e3ddbd8f818cf..174af2c45e7774ca5c15de325d4db580cca694e5 100644 (file)
@@ -66,6 +66,8 @@ Optional child node properties:
 Optional child node properties for VDMA:
 - xlnx,genlock-mode: Tells Genlock synchronization is
        enabled/disabled in hardware.
+- xlnx,enable-vert-flip: Tells vertical flip is
+       enabled/disabled in hardware(S2MM path).
 Optional child node properties for AXI DMA:
 -dma-channels: Number of dma channels in child node.
 
index 7c1bb3d0c2229363fcc2eb5d729f911f59c258d9..43681ca0837f8d7c78fa576831c029a50e730203 100644 (file)
@@ -240,6 +240,7 @@ CLOCK
   devm_of_clk_add_hw_provider()
 
 DMA
+  dmaenginem_async_device_register()
   dmam_alloc_coherent()
   dmam_alloc_attrs()
   dmam_declare_coherent_memory()
index 56bd612927ab1688d324fb056e9ff6d2a2f3e037..80dc567801ec0006c395c7f8b796e8fe0f128ef1 100644 (file)
@@ -42,6 +42,8 @@ static struct page *pq_scribble_page;
 #define P(b, d) (b[d-2])
 #define Q(b, d) (b[d-1])
 
+#define MAX_DISKS 255
+
 /**
  * do_async_gen_syndrome - asynchronously calculate P and/or Q
  */
@@ -184,7 +186,7 @@ async_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
        struct dma_device *device = chan ? chan->device : NULL;
        struct dmaengine_unmap_data *unmap = NULL;
 
-       BUG_ON(disks > 255 || !(P(blocks, disks) || Q(blocks, disks)));
+       BUG_ON(disks > MAX_DISKS || !(P(blocks, disks) || Q(blocks, disks)));
 
        if (device)
                unmap = dmaengine_get_unmap_data(device->dev, disks, GFP_NOWAIT);
@@ -196,7 +198,7 @@ async_gen_syndrome(struct page **blocks, unsigned int offset, int disks,
            is_dma_pq_aligned(device, offset, 0, len)) {
                struct dma_async_tx_descriptor *tx;
                enum dma_ctrl_flags dma_flags = 0;
-               unsigned char coefs[src_cnt];
+               unsigned char coefs[MAX_DISKS];
                int i, j;
 
                /* run the p+q asynchronously */
@@ -299,11 +301,11 @@ async_syndrome_val(struct page **blocks, unsigned int offset, int disks,
        struct dma_chan *chan = pq_val_chan(submit, blocks, disks, len);
        struct dma_device *device = chan ? chan->device : NULL;
        struct dma_async_tx_descriptor *tx;
-       unsigned char coefs[disks-2];
+       unsigned char coefs[MAX_DISKS];
        enum dma_ctrl_flags dma_flags = submit->cb_fn ? DMA_PREP_INTERRUPT : 0;
        struct dmaengine_unmap_data *unmap = NULL;
 
-       BUG_ON(disks < 4);
+       BUG_ON(disks < 4 || disks > MAX_DISKS);
 
        if (device)
                unmap = dmaengine_get_unmap_data(device->dev, disks, GFP_NOWAIT);
index dad95f45b88f6566afc62df645151d3a2ae60092..a5edaabae12a1ea1b90b3696209c54624ce8cc7d 100644 (file)
@@ -81,11 +81,13 @@ static void raid6_dual_recov(int disks, size_t bytes, int faila, int failb, stru
                        init_async_submit(&submit, 0, NULL, NULL, NULL, addr_conv);
                        tx = async_gen_syndrome(ptrs, 0, disks, bytes, &submit);
                } else {
-                       struct page *blocks[disks];
+                       struct page *blocks[NDISKS];
                        struct page *dest;
                        int count = 0;
                        int i;
 
+                       BUG_ON(disks > NDISKS);
+
                        /* data+Q failure.  Reconstruct data from P,
                         * then rebuild syndrome
                         */
index d4a4230a7942e6851deceffb8903e669588e1fbd..dacf3f42426de9e54a2c255248e422e313096acc 100644 (file)
@@ -414,6 +414,14 @@ config NBPFAXI_DMA
        help
          Support for "Type-AXI" NBPF DMA IPs from Renesas
 
+config OWL_DMA
+       tristate "Actions Semi Owl SoCs DMA support"
+       depends on ARCH_ACTIONS
+       select DMA_ENGINE
+       select DMA_VIRTUAL_CHANNELS
+       help
+         Enable support for the Actions Semi Owl SoCs DMA controller.
+
 config PCH_DMA
        tristate "Intel EG20T PCH / LAPIS Semicon IOH(ML7213/ML7223/ML7831) DMA"
        depends on PCI && (X86_32 || COMPILE_TEST)
index 203a99d68315cec8b20f57a601824699d6f10dd5..c91702d88b953be2f776da680e59858d05cb63e6 100644 (file)
@@ -52,6 +52,7 @@ obj-$(CONFIG_MV_XOR_V2) += mv_xor_v2.o
 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_PCH_DMA) += pch_dma.o
 obj-$(CONFIG_PL330_DMA) += pl330.o
 obj-$(CONFIG_PPC_BESTCOMM) += bestcomm/
index 08ba8473a284845ecbffab228dded0d3b3b4aaf1..272bed6c8ba79d17cff68cf54d9b0aae20a28546 100644 (file)
@@ -500,12 +500,8 @@ int dma_get_slave_caps(struct dma_chan *chan, struct dma_slave_caps *caps)
        caps->max_burst = device->max_burst;
        caps->residue_granularity = device->residue_granularity;
        caps->descriptor_reuse = device->descriptor_reuse;
-
-       /*
-        * Some devices implement only pause (e.g. to get residuum) but no
-        * resume. However cmd_pause is advertised as pause AND resume.
-        */
-       caps->cmd_pause = !!(device->device_pause && device->device_resume);
+       caps->cmd_pause = !!device->device_pause;
+       caps->cmd_resume = !!device->device_resume;
        caps->cmd_terminate = !!device->device_terminate_all;
 
        return 0;
@@ -774,8 +770,14 @@ struct dma_chan *dma_request_chan_by_mask(const dma_cap_mask_t *mask)
                return ERR_PTR(-ENODEV);
 
        chan = __dma_request_channel(mask, NULL, NULL);
-       if (!chan)
-               chan = ERR_PTR(-ENODEV);
+       if (!chan) {
+               mutex_lock(&dma_list_mutex);
+               if (list_empty(&dma_device_list))
+                       chan = ERR_PTR(-EPROBE_DEFER);
+               else
+                       chan = ERR_PTR(-ENODEV);
+               mutex_unlock(&dma_list_mutex);
+       }
 
        return chan;
 }
@@ -1139,6 +1141,41 @@ void dma_async_device_unregister(struct dma_device *device)
 }
 EXPORT_SYMBOL(dma_async_device_unregister);
 
+static void dmam_device_release(struct device *dev, void *res)
+{
+       struct dma_device *device;
+
+       device = *(struct dma_device **)res;
+       dma_async_device_unregister(device);
+}
+
+/**
+ * dmaenginem_async_device_register - registers DMA devices found
+ * @device: &dma_device
+ *
+ * The operation is managed and will be undone on driver detach.
+ */
+int dmaenginem_async_device_register(struct dma_device *device)
+{
+       void *p;
+       int ret;
+
+       p = devres_alloc(dmam_device_release, sizeof(void *), GFP_KERNEL);
+       if (!p)
+               return -ENOMEM;
+
+       ret = dma_async_device_register(device);
+       if (!ret) {
+               *(struct dma_device **)p = device;
+               devres_add(device->dev, p);
+       } else {
+               devres_free(p);
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL(dmaenginem_async_device_register);
+
 struct dmaengine_unmap_pool {
        struct kmem_cache *cache;
        const char *name;
index 29d04ca71d52ed05e47435a869fd7826ae93aa08..202ffa9f7611c6f5560187c4ab084d461a6713b5 100644 (file)
@@ -413,6 +413,13 @@ static void hsu_dma_free_chan_resources(struct dma_chan *chan)
        vchan_free_chan_resources(to_virt_chan(chan));
 }
 
+static void hsu_dma_synchronize(struct dma_chan *chan)
+{
+       struct hsu_dma_chan *hsuc = to_hsu_dma_chan(chan);
+
+       vchan_synchronize(&hsuc->vchan);
+}
+
 int hsu_dma_probe(struct hsu_dma_chip *chip)
 {
        struct hsu_dma *hsu;
@@ -459,6 +466,7 @@ int hsu_dma_probe(struct hsu_dma_chip *chip)
        hsu->dma.device_pause = hsu_dma_pause;
        hsu->dma.device_resume = hsu_dma_resume;
        hsu->dma.device_terminate_all = hsu_dma_terminate_all;
+       hsu->dma.device_synchronize = hsu_dma_synchronize;
 
        hsu->dma.src_addr_widths = HSU_DMA_BUSWIDTHS;
        hsu->dma.dst_addr_widths = HSU_DMA_BUSWIDTHS;
index e5c911200bdb4a15920181c85e13fe47705214e6..1fbf9cb9b74297c9daa6005c520fa54f90c8dc45 100644 (file)
@@ -496,6 +496,13 @@ static int idma64_terminate_all(struct dma_chan *chan)
        return 0;
 }
 
+static void idma64_synchronize(struct dma_chan *chan)
+{
+       struct idma64_chan *idma64c = to_idma64_chan(chan);
+
+       vchan_synchronize(&idma64c->vchan);
+}
+
 static int idma64_alloc_chan_resources(struct dma_chan *chan)
 {
        struct idma64_chan *idma64c = to_idma64_chan(chan);
@@ -583,6 +590,7 @@ static int idma64_probe(struct idma64_chip *chip)
        idma64->dma.device_pause = idma64_pause;
        idma64->dma.device_resume = idma64_resume;
        idma64->dma.device_terminate_all = idma64_terminate_all;
+       idma64->dma.device_synchronize = idma64_synchronize;
 
        idma64->dma.src_addr_widths = IDMA64_BUSWIDTHS;
        idma64->dma.dst_addr_widths = IDMA64_BUSWIDTHS;
index 8b5b23a8ace9b16265200098cfbb9ef1f05dbadf..23fb2fa040002daeb3e248036efa261b63b3769e 100644 (file)
@@ -688,6 +688,12 @@ static void ioat_restart_channel(struct ioatdma_chan *ioat_chan)
 {
        u64 phys_complete;
 
+       /* set the completion address register again */
+       writel(lower_32_bits(ioat_chan->completion_dma),
+              ioat_chan->reg_base + IOAT_CHANCMP_OFFSET_LOW);
+       writel(upper_32_bits(ioat_chan->completion_dma),
+              ioat_chan->reg_base + IOAT_CHANCMP_OFFSET_HIGH);
+
        ioat_quiesce(ioat_chan, 0);
        if (ioat_cleanup_preamble(ioat_chan, &phys_complete))
                __cleanup(ioat_chan, phys_complete);
index 68dd79783b54a0f2f5c1a0e3578b5acaf8933616..b76cb17d879c635efbfec026da59a5c608ff0a6e 100644 (file)
@@ -470,11 +470,6 @@ static void mic_dma_chan_destroy(struct mic_dma_chan *ch)
        mic_dma_chan_mask_intr(ch);
 }
 
-static void mic_dma_unregister_dma_device(struct mic_dma_device *mic_dma_dev)
-{
-       dma_async_device_unregister(&mic_dma_dev->dma_dev);
-}
-
 static int mic_dma_setup_irq(struct mic_dma_chan *ch)
 {
        ch->cookie =
@@ -630,7 +625,7 @@ static int mic_dma_register_dma_device(struct mic_dma_device *mic_dma_dev,
                list_add_tail(&mic_dma_dev->mic_ch[i].api_ch.device_node,
                              &mic_dma_dev->dma_dev.channels);
        }
-       return dma_async_device_register(&mic_dma_dev->dma_dev);
+       return dmaenginem_async_device_register(&mic_dma_dev->dma_dev);
 }
 
 /*
@@ -678,7 +673,6 @@ static struct mic_dma_device *mic_dma_dev_reg(struct mbus_device *mbdev,
 
 static void mic_dma_dev_unreg(struct mic_dma_device *mic_dma_dev)
 {
-       mic_dma_unregister_dma_device(mic_dma_dev);
        mic_dma_uninit(mic_dma_dev);
        kfree(mic_dma_dev);
 }
index c6589ccf1b9a3a4c49dcae612d86d08ab5c2ebdd..8dc0aa4d73ab839e2aa870547a5697d14d4fc95c 100644 (file)
@@ -174,6 +174,7 @@ struct mv_xor_v2_device {
        int desc_size;
        unsigned int npendings;
        unsigned int hw_queue_idx;
+       struct msi_desc *msi_desc;
 };
 
 /**
@@ -588,11 +589,9 @@ static void mv_xor_v2_tasklet(unsigned long data)
                         */
                        dma_cookie_complete(&next_pending_sw_desc->async_tx);
 
-                       if (next_pending_sw_desc->async_tx.callback)
-                               next_pending_sw_desc->async_tx.callback(
-                               next_pending_sw_desc->async_tx.callback_param);
-
                        dma_descriptor_unmap(&next_pending_sw_desc->async_tx);
+                       dmaengine_desc_get_callback_invoke(
+                                       &next_pending_sw_desc->async_tx, NULL);
                }
 
                dma_run_dependencies(&next_pending_sw_desc->async_tx);
@@ -643,9 +642,9 @@ static int mv_xor_v2_descq_init(struct mv_xor_v2_device *xor_dev)
               xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_SIZE_OFF);
 
        /* write the DESQ address to the DMA enngine*/
-       writel(xor_dev->hw_desq & 0xFFFFFFFF,
+       writel(lower_32_bits(xor_dev->hw_desq),
               xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_BALR_OFF);
-       writel((xor_dev->hw_desq & 0xFFFF00000000) >> 32,
+       writel(upper_32_bits(xor_dev->hw_desq),
               xor_dev->dma_base + MV_XOR_V2_DMA_DESQ_BAHR_OFF);
 
        /*
@@ -780,6 +779,7 @@ static int mv_xor_v2_probe(struct platform_device *pdev)
        msi_desc = first_msi_entry(&pdev->dev);
        if (!msi_desc)
                goto free_msi_irqs;
+       xor_dev->msi_desc = msi_desc;
 
        ret = devm_request_irq(&pdev->dev, msi_desc->irq,
                               mv_xor_v2_interrupt_handler, 0,
@@ -897,8 +897,12 @@ static int mv_xor_v2_remove(struct platform_device *pdev)
                          xor_dev->desc_size * MV_XOR_V2_DESC_NUM,
                          xor_dev->hw_desq_virt, xor_dev->hw_desq);
 
+       devm_free_irq(&pdev->dev, xor_dev->msi_desc->irq, xor_dev);
+
        platform_msi_domain_free_irqs(&pdev->dev);
 
+       tasklet_kill(&xor_dev->irq_tasklet);
+
        clk_disable_unprepare(xor_dev->clk);
 
        return 0;
index 2f9974ddfbb2fde6f20d49689502156936452eb5..8c7b2e8703dabd06bbef253c3f9d2ef6f7c085cb 100644 (file)
@@ -479,6 +479,7 @@ static size_t nbpf_xfer_size(struct nbpf_device *nbpf,
 
        default:
                pr_warn("%s(): invalid bus width %u\n", __func__, width);
+               /* fall through */
        case DMA_SLAVE_BUSWIDTH_1_BYTE:
                size = burst;
        }
diff --git a/drivers/dma/owl-dma.c b/drivers/dma/owl-dma.c
new file mode 100644 (file)
index 0000000..7812a63
--- /dev/null
@@ -0,0 +1,971 @@
+// SPDX-License-Identifier: GPL-2.0+
+//
+// Actions Semi Owl SoCs DMA driver
+//
+// Copyright (c) 2014 Actions Semi Inc.
+// Author: David Liu <liuwei@actions-semi.com>
+//
+// Copyright (c) 2018 Linaro Ltd.
+// Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
+
+#include <linux/bitops.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/dmaengine.h>
+#include <linux/dma-mapping.h>
+#include <linux/dmapool.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/io.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/slab.h>
+#include "virt-dma.h"
+
+#define OWL_DMA_FRAME_MAX_LENGTH               0xfffff
+
+/* Global DMA Controller Registers */
+#define OWL_DMA_IRQ_PD0                                0x00
+#define OWL_DMA_IRQ_PD1                                0x04
+#define OWL_DMA_IRQ_PD2                                0x08
+#define OWL_DMA_IRQ_PD3                                0x0C
+#define OWL_DMA_IRQ_EN0                                0x10
+#define OWL_DMA_IRQ_EN1                                0x14
+#define OWL_DMA_IRQ_EN2                                0x18
+#define OWL_DMA_IRQ_EN3                                0x1C
+#define OWL_DMA_SECURE_ACCESS_CTL              0x20
+#define OWL_DMA_NIC_QOS                                0x24
+#define OWL_DMA_DBGSEL                         0x28
+#define OWL_DMA_IDLE_STAT                      0x2C
+
+/* Channel Registers */
+#define OWL_DMA_CHAN_BASE(i)                   (0x100 + (i) * 0x100)
+#define OWL_DMAX_MODE                          0x00
+#define OWL_DMAX_SOURCE                                0x04
+#define OWL_DMAX_DESTINATION                   0x08
+#define OWL_DMAX_FRAME_LEN                     0x0C
+#define OWL_DMAX_FRAME_CNT                     0x10
+#define OWL_DMAX_REMAIN_FRAME_CNT              0x14
+#define OWL_DMAX_REMAIN_CNT                    0x18
+#define OWL_DMAX_SOURCE_STRIDE                 0x1C
+#define OWL_DMAX_DESTINATION_STRIDE            0x20
+#define OWL_DMAX_START                         0x24
+#define OWL_DMAX_PAUSE                         0x28
+#define OWL_DMAX_CHAINED_CTL                   0x2C
+#define OWL_DMAX_CONSTANT                      0x30
+#define OWL_DMAX_LINKLIST_CTL                  0x34
+#define OWL_DMAX_NEXT_DESCRIPTOR               0x38
+#define OWL_DMAX_CURRENT_DESCRIPTOR_NUM                0x3C
+#define OWL_DMAX_INT_CTL                       0x40
+#define OWL_DMAX_INT_STATUS                    0x44
+#define OWL_DMAX_CURRENT_SOURCE_POINTER                0x48
+#define OWL_DMAX_CURRENT_DESTINATION_POINTER   0x4C
+
+/* OWL_DMAX_MODE Bits */
+#define OWL_DMA_MODE_TS(x)                     (((x) & GENMASK(5, 0)) << 0)
+#define OWL_DMA_MODE_ST(x)                     (((x) & GENMASK(1, 0)) << 8)
+#define        OWL_DMA_MODE_ST_DEV                     OWL_DMA_MODE_ST(0)
+#define        OWL_DMA_MODE_ST_DCU                     OWL_DMA_MODE_ST(2)
+#define        OWL_DMA_MODE_ST_SRAM                    OWL_DMA_MODE_ST(3)
+#define OWL_DMA_MODE_DT(x)                     (((x) & GENMASK(1, 0)) << 10)
+#define        OWL_DMA_MODE_DT_DEV                     OWL_DMA_MODE_DT(0)
+#define        OWL_DMA_MODE_DT_DCU                     OWL_DMA_MODE_DT(2)
+#define        OWL_DMA_MODE_DT_SRAM                    OWL_DMA_MODE_DT(3)
+#define OWL_DMA_MODE_SAM(x)                    (((x) & GENMASK(1, 0)) << 16)
+#define        OWL_DMA_MODE_SAM_CONST                  OWL_DMA_MODE_SAM(0)
+#define        OWL_DMA_MODE_SAM_INC                    OWL_DMA_MODE_SAM(1)
+#define        OWL_DMA_MODE_SAM_STRIDE                 OWL_DMA_MODE_SAM(2)
+#define OWL_DMA_MODE_DAM(x)                    (((x) & GENMASK(1, 0)) << 18)
+#define        OWL_DMA_MODE_DAM_CONST                  OWL_DMA_MODE_DAM(0)
+#define        OWL_DMA_MODE_DAM_INC                    OWL_DMA_MODE_DAM(1)
+#define        OWL_DMA_MODE_DAM_STRIDE                 OWL_DMA_MODE_DAM(2)
+#define OWL_DMA_MODE_PW(x)                     (((x) & GENMASK(2, 0)) << 20)
+#define OWL_DMA_MODE_CB                                BIT(23)
+#define OWL_DMA_MODE_NDDBW(x)                  (((x) & 0x1) << 28)
+#define        OWL_DMA_MODE_NDDBW_32BIT                OWL_DMA_MODE_NDDBW(0)
+#define        OWL_DMA_MODE_NDDBW_8BIT                 OWL_DMA_MODE_NDDBW(1)
+#define OWL_DMA_MODE_CFE                       BIT(29)
+#define OWL_DMA_MODE_LME                       BIT(30)
+#define OWL_DMA_MODE_CME                       BIT(31)
+
+/* OWL_DMAX_LINKLIST_CTL Bits */
+#define OWL_DMA_LLC_SAV(x)                     (((x) & GENMASK(1, 0)) << 8)
+#define        OWL_DMA_LLC_SAV_INC                     OWL_DMA_LLC_SAV(0)
+#define        OWL_DMA_LLC_SAV_LOAD_NEXT               OWL_DMA_LLC_SAV(1)
+#define        OWL_DMA_LLC_SAV_LOAD_PREV               OWL_DMA_LLC_SAV(2)
+#define OWL_DMA_LLC_DAV(x)                     (((x) & GENMASK(1, 0)) << 10)
+#define        OWL_DMA_LLC_DAV_INC                     OWL_DMA_LLC_DAV(0)
+#define        OWL_DMA_LLC_DAV_LOAD_NEXT               OWL_DMA_LLC_DAV(1)
+#define        OWL_DMA_LLC_DAV_LOAD_PREV               OWL_DMA_LLC_DAV(2)
+#define OWL_DMA_LLC_SUSPEND                    BIT(16)
+
+/* OWL_DMAX_INT_CTL Bits */
+#define OWL_DMA_INTCTL_BLOCK                   BIT(0)
+#define OWL_DMA_INTCTL_SUPER_BLOCK             BIT(1)
+#define OWL_DMA_INTCTL_FRAME                   BIT(2)
+#define OWL_DMA_INTCTL_HALF_FRAME              BIT(3)
+#define OWL_DMA_INTCTL_LAST_FRAME              BIT(4)
+
+/* OWL_DMAX_INT_STATUS Bits */
+#define OWL_DMA_INTSTAT_BLOCK                  BIT(0)
+#define OWL_DMA_INTSTAT_SUPER_BLOCK            BIT(1)
+#define OWL_DMA_INTSTAT_FRAME                  BIT(2)
+#define OWL_DMA_INTSTAT_HALF_FRAME             BIT(3)
+#define OWL_DMA_INTSTAT_LAST_FRAME             BIT(4)
+
+/* Pack shift and newshift in a single word */
+#define BIT_FIELD(val, width, shift, newshift) \
+               ((((val) >> (shift)) & ((BIT(width)) - 1)) << (newshift))
+
+/**
+ * struct owl_dma_lli_hw - Hardware link list for dma transfer
+ * @next_lli: physical address of the next link list
+ * @saddr: source physical address
+ * @daddr: destination physical address
+ * @flen: frame length
+ * @fcnt: frame count
+ * @src_stride: source stride
+ * @dst_stride: destination stride
+ * @ctrla: dma_mode and linklist ctrl config
+ * @ctrlb: interrupt config
+ * @const_num: data for constant fill
+ */
+struct owl_dma_lli_hw {
+       u32     next_lli;
+       u32     saddr;
+       u32     daddr;
+       u32     flen:20;
+       u32     fcnt:12;
+       u32     src_stride;
+       u32     dst_stride;
+       u32     ctrla;
+       u32     ctrlb;
+       u32     const_num;
+};
+
+/**
+ * struct owl_dma_lli - Link list for dma transfer
+ * @hw: hardware link list
+ * @phys: physical address of hardware link list
+ * @node: node for txd's lli_list
+ */
+struct owl_dma_lli {
+       struct  owl_dma_lli_hw  hw;
+       dma_addr_t              phys;
+       struct list_head        node;
+};
+
+/**
+ * struct owl_dma_txd - Wrapper for struct dma_async_tx_descriptor
+ * @vd: virtual DMA descriptor
+ * @lli_list: link list of lli nodes
+ */
+struct owl_dma_txd {
+       struct virt_dma_desc    vd;
+       struct list_head        lli_list;
+};
+
+/**
+ * struct owl_dma_pchan - Holder for the physical channels
+ * @id: physical index to this channel
+ * @base: virtual memory base for the dma channel
+ * @vchan: the virtual channel currently being served by this physical channel
+ * @lock: a lock to use when altering an instance of this struct
+ */
+struct owl_dma_pchan {
+       u32                     id;
+       void __iomem            *base;
+       struct owl_dma_vchan    *vchan;
+       spinlock_t              lock;
+};
+
+/**
+ * struct owl_dma_pchan - Wrapper for DMA ENGINE channel
+ * @vc: wrappped virtual channel
+ * @pchan: the physical channel utilized by this channel
+ * @txd: active transaction on this channel
+ */
+struct owl_dma_vchan {
+       struct virt_dma_chan    vc;
+       struct owl_dma_pchan    *pchan;
+       struct owl_dma_txd      *txd;
+};
+
+/**
+ * struct owl_dma - Holder for the Owl DMA controller
+ * @dma: dma engine for this instance
+ * @base: virtual memory base for the DMA controller
+ * @clk: clock for the DMA controller
+ * @lock: a lock to use when change DMA controller global register
+ * @lli_pool: a pool for the LLI descriptors
+ * @nr_pchans: the number of physical channels
+ * @pchans: array of data for the physical channels
+ * @nr_vchans: the number of physical channels
+ * @vchans: array of data for the physical channels
+ */
+struct owl_dma {
+       struct dma_device       dma;
+       void __iomem            *base;
+       struct clk              *clk;
+       spinlock_t              lock;
+       struct dma_pool         *lli_pool;
+       int                     irq;
+
+       unsigned int            nr_pchans;
+       struct owl_dma_pchan    *pchans;
+
+       unsigned int            nr_vchans;
+       struct owl_dma_vchan    *vchans;
+};
+
+static void pchan_update(struct owl_dma_pchan *pchan, u32 reg,
+                        u32 val, bool state)
+{
+       u32 regval;
+
+       regval = readl(pchan->base + reg);
+
+       if (state)
+               regval |= val;
+       else
+               regval &= ~val;
+
+       writel(val, pchan->base + reg);
+}
+
+static void pchan_writel(struct owl_dma_pchan *pchan, u32 reg, u32 data)
+{
+       writel(data, pchan->base + reg);
+}
+
+static u32 pchan_readl(struct owl_dma_pchan *pchan, u32 reg)
+{
+       return readl(pchan->base + reg);
+}
+
+static void dma_update(struct owl_dma *od, u32 reg, u32 val, bool state)
+{
+       u32 regval;
+
+       regval = readl(od->base + reg);
+
+       if (state)
+               regval |= val;
+       else
+               regval &= ~val;
+
+       writel(val, od->base + reg);
+}
+
+static void dma_writel(struct owl_dma *od, u32 reg, u32 data)
+{
+       writel(data, od->base + reg);
+}
+
+static u32 dma_readl(struct owl_dma *od, u32 reg)
+{
+       return readl(od->base + reg);
+}
+
+static inline struct owl_dma *to_owl_dma(struct dma_device *dd)
+{
+       return container_of(dd, struct owl_dma, dma);
+}
+
+static struct device *chan2dev(struct dma_chan *chan)
+{
+       return &chan->dev->device;
+}
+
+static inline struct owl_dma_vchan *to_owl_vchan(struct dma_chan *chan)
+{
+       return container_of(chan, struct owl_dma_vchan, vc.chan);
+}
+
+static inline struct owl_dma_txd *to_owl_txd(struct dma_async_tx_descriptor *tx)
+{
+       return container_of(tx, struct owl_dma_txd, vd.tx);
+}
+
+static inline u32 llc_hw_ctrla(u32 mode, u32 llc_ctl)
+{
+       u32 ctl;
+
+       ctl = BIT_FIELD(mode, 4, 28, 28) |
+             BIT_FIELD(mode, 8, 16, 20) |
+             BIT_FIELD(mode, 4, 8, 16) |
+             BIT_FIELD(mode, 6, 0, 10) |
+             BIT_FIELD(llc_ctl, 2, 10, 8) |
+             BIT_FIELD(llc_ctl, 2, 8, 6);
+
+       return ctl;
+}
+
+static inline u32 llc_hw_ctrlb(u32 int_ctl)
+{
+       u32 ctl;
+
+       ctl = BIT_FIELD(int_ctl, 7, 0, 18);
+
+       return ctl;
+}
+
+static void owl_dma_free_lli(struct owl_dma *od,
+                            struct owl_dma_lli *lli)
+{
+       list_del(&lli->node);
+       dma_pool_free(od->lli_pool, lli, lli->phys);
+}
+
+static struct owl_dma_lli *owl_dma_alloc_lli(struct owl_dma *od)
+{
+       struct owl_dma_lli *lli;
+       dma_addr_t phys;
+
+       lli = dma_pool_alloc(od->lli_pool, GFP_NOWAIT, &phys);
+       if (!lli)
+               return NULL;
+
+       INIT_LIST_HEAD(&lli->node);
+       lli->phys = phys;
+
+       return lli;
+}
+
+static struct owl_dma_lli *owl_dma_add_lli(struct owl_dma_txd *txd,
+                                          struct owl_dma_lli *prev,
+                                          struct owl_dma_lli *next)
+{
+       list_add_tail(&next->node, &txd->lli_list);
+
+       if (prev) {
+               prev->hw.next_lli = next->phys;
+               prev->hw.ctrla |= llc_hw_ctrla(OWL_DMA_MODE_LME, 0);
+       }
+
+       return next;
+}
+
+static inline int owl_dma_cfg_lli(struct owl_dma_vchan *vchan,
+                                 struct owl_dma_lli *lli,
+                                 dma_addr_t src, dma_addr_t dst,
+                                 u32 len, enum dma_transfer_direction dir)
+{
+       struct owl_dma_lli_hw *hw = &lli->hw;
+       u32 mode;
+
+       mode = OWL_DMA_MODE_PW(0);
+
+       switch (dir) {
+       case DMA_MEM_TO_MEM:
+               mode |= OWL_DMA_MODE_TS(0) | OWL_DMA_MODE_ST_DCU |
+                       OWL_DMA_MODE_DT_DCU | OWL_DMA_MODE_SAM_INC |
+                       OWL_DMA_MODE_DAM_INC;
+
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       hw->next_lli = 0; /* One link list by default */
+       hw->saddr = src;
+       hw->daddr = dst;
+
+       hw->fcnt = 1; /* Frame count fixed as 1 */
+       hw->flen = len; /* Max frame length is 1MB */
+       hw->src_stride = 0;
+       hw->dst_stride = 0;
+       hw->ctrla = llc_hw_ctrla(mode,
+                                OWL_DMA_LLC_SAV_LOAD_NEXT |
+                                OWL_DMA_LLC_DAV_LOAD_NEXT);
+
+       hw->ctrlb = llc_hw_ctrlb(OWL_DMA_INTCTL_SUPER_BLOCK);
+
+       return 0;
+}
+
+static struct owl_dma_pchan *owl_dma_get_pchan(struct owl_dma *od,
+                                              struct owl_dma_vchan *vchan)
+{
+       struct owl_dma_pchan *pchan = NULL;
+       unsigned long flags;
+       int i;
+
+       for (i = 0; i < od->nr_pchans; i++) {
+               pchan = &od->pchans[i];
+
+               spin_lock_irqsave(&pchan->lock, flags);
+               if (!pchan->vchan) {
+                       pchan->vchan = vchan;
+                       spin_unlock_irqrestore(&pchan->lock, flags);
+                       break;
+               }
+
+               spin_unlock_irqrestore(&pchan->lock, flags);
+       }
+
+       return pchan;
+}
+
+static int owl_dma_pchan_busy(struct owl_dma *od, struct owl_dma_pchan *pchan)
+{
+       unsigned int val;
+
+       val = dma_readl(od, OWL_DMA_IDLE_STAT);
+
+       return !(val & (1 << pchan->id));
+}
+
+static void owl_dma_terminate_pchan(struct owl_dma *od,
+                                   struct owl_dma_pchan *pchan)
+{
+       unsigned long flags;
+       u32 irq_pd;
+
+       pchan_writel(pchan, OWL_DMAX_START, 0);
+       pchan_update(pchan, OWL_DMAX_INT_STATUS, 0xff, false);
+
+       spin_lock_irqsave(&od->lock, flags);
+       dma_update(od, OWL_DMA_IRQ_EN0, (1 << pchan->id), false);
+
+       irq_pd = dma_readl(od, OWL_DMA_IRQ_PD0);
+       if (irq_pd & (1 << pchan->id)) {
+               dev_warn(od->dma.dev,
+                        "terminating pchan %d that still has pending irq\n",
+                        pchan->id);
+               dma_writel(od, OWL_DMA_IRQ_PD0, (1 << pchan->id));
+       }
+
+       pchan->vchan = NULL;
+
+       spin_unlock_irqrestore(&od->lock, flags);
+}
+
+static int owl_dma_start_next_txd(struct owl_dma_vchan *vchan)
+{
+       struct owl_dma *od = to_owl_dma(vchan->vc.chan.device);
+       struct virt_dma_desc *vd = vchan_next_desc(&vchan->vc);
+       struct owl_dma_pchan *pchan = vchan->pchan;
+       struct owl_dma_txd *txd = to_owl_txd(&vd->tx);
+       struct owl_dma_lli *lli;
+       unsigned long flags;
+       u32 int_ctl;
+
+       list_del(&vd->node);
+
+       vchan->txd = txd;
+
+       /* Wait for channel inactive */
+       while (owl_dma_pchan_busy(od, pchan))
+               cpu_relax();
+
+       lli = list_first_entry(&txd->lli_list,
+                              struct owl_dma_lli, node);
+
+       int_ctl = OWL_DMA_INTCTL_SUPER_BLOCK;
+
+       pchan_writel(pchan, OWL_DMAX_MODE, OWL_DMA_MODE_LME);
+       pchan_writel(pchan, OWL_DMAX_LINKLIST_CTL,
+                    OWL_DMA_LLC_SAV_LOAD_NEXT | OWL_DMA_LLC_DAV_LOAD_NEXT);
+       pchan_writel(pchan, OWL_DMAX_NEXT_DESCRIPTOR, lli->phys);
+       pchan_writel(pchan, OWL_DMAX_INT_CTL, int_ctl);
+
+       /* Clear IRQ status for this pchan */
+       pchan_update(pchan, OWL_DMAX_INT_STATUS, 0xff, false);
+
+       spin_lock_irqsave(&od->lock, flags);
+
+       dma_update(od, OWL_DMA_IRQ_EN0, (1 << pchan->id), true);
+
+       spin_unlock_irqrestore(&od->lock, flags);
+
+       dev_dbg(chan2dev(&vchan->vc.chan), "starting pchan %d\n", pchan->id);
+
+       /* Start DMA transfer for this pchan */
+       pchan_writel(pchan, OWL_DMAX_START, 0x1);
+
+       return 0;
+}
+
+static void owl_dma_phy_free(struct owl_dma *od, struct owl_dma_vchan *vchan)
+{
+       /* Ensure that the physical channel is stopped */
+       owl_dma_terminate_pchan(od, vchan->pchan);
+
+       vchan->pchan = NULL;
+}
+
+static irqreturn_t owl_dma_interrupt(int irq, void *dev_id)
+{
+       struct owl_dma *od = dev_id;
+       struct owl_dma_vchan *vchan;
+       struct owl_dma_pchan *pchan;
+       unsigned long pending;
+       int i;
+       unsigned int global_irq_pending, chan_irq_pending;
+
+       spin_lock(&od->lock);
+
+       pending = dma_readl(od, OWL_DMA_IRQ_PD0);
+
+       /* Clear IRQ status for each pchan */
+       for_each_set_bit(i, &pending, od->nr_pchans) {
+               pchan = &od->pchans[i];
+               pchan_update(pchan, OWL_DMAX_INT_STATUS, 0xff, false);
+       }
+
+       /* Clear pending IRQ */
+       dma_writel(od, OWL_DMA_IRQ_PD0, pending);
+
+       /* Check missed pending IRQ */
+       for (i = 0; i < od->nr_pchans; i++) {
+               pchan = &od->pchans[i];
+               chan_irq_pending = pchan_readl(pchan, OWL_DMAX_INT_CTL) &
+                                  pchan_readl(pchan, OWL_DMAX_INT_STATUS);
+
+               /* Dummy read to ensure OWL_DMA_IRQ_PD0 value is updated */
+               dma_readl(od, OWL_DMA_IRQ_PD0);
+
+               global_irq_pending = dma_readl(od, OWL_DMA_IRQ_PD0);
+
+               if (chan_irq_pending && !(global_irq_pending & BIT(i))) {
+                       dev_dbg(od->dma.dev,
+                               "global and channel IRQ pending match err\n");
+
+                       /* Clear IRQ status for this pchan */
+                       pchan_update(pchan, OWL_DMAX_INT_STATUS,
+                                    0xff, false);
+
+                       /* Update global IRQ pending */
+                       pending |= BIT(i);
+               }
+       }
+
+       spin_unlock(&od->lock);
+
+       for_each_set_bit(i, &pending, od->nr_pchans) {
+               struct owl_dma_txd *txd;
+
+               pchan = &od->pchans[i];
+
+               vchan = pchan->vchan;
+               if (!vchan) {
+                       dev_warn(od->dma.dev, "no vchan attached on pchan %d\n",
+                                pchan->id);
+                       continue;
+               }
+
+               spin_lock(&vchan->vc.lock);
+
+               txd = vchan->txd;
+               if (txd) {
+                       vchan->txd = NULL;
+
+                       vchan_cookie_complete(&txd->vd);
+
+                       /*
+                        * Start the next descriptor (if any),
+                        * otherwise free this channel.
+                        */
+                       if (vchan_next_desc(&vchan->vc))
+                               owl_dma_start_next_txd(vchan);
+                       else
+                               owl_dma_phy_free(od, vchan);
+               }
+
+               spin_unlock(&vchan->vc.lock);
+       }
+
+       return IRQ_HANDLED;
+}
+
+static void owl_dma_free_txd(struct owl_dma *od, struct owl_dma_txd *txd)
+{
+       struct owl_dma_lli *lli, *_lli;
+
+       if (unlikely(!txd))
+               return;
+
+       list_for_each_entry_safe(lli, _lli, &txd->lli_list, node)
+               owl_dma_free_lli(od, lli);
+
+       kfree(txd);
+}
+
+static void owl_dma_desc_free(struct virt_dma_desc *vd)
+{
+       struct owl_dma *od = to_owl_dma(vd->tx.chan->device);
+       struct owl_dma_txd *txd = to_owl_txd(&vd->tx);
+
+       owl_dma_free_txd(od, txd);
+}
+
+static int owl_dma_terminate_all(struct dma_chan *chan)
+{
+       struct owl_dma *od = to_owl_dma(chan->device);
+       struct owl_dma_vchan *vchan = to_owl_vchan(chan);
+       unsigned long flags;
+       LIST_HEAD(head);
+
+       spin_lock_irqsave(&vchan->vc.lock, flags);
+
+       if (vchan->pchan)
+               owl_dma_phy_free(od, vchan);
+
+       if (vchan->txd) {
+               owl_dma_desc_free(&vchan->txd->vd);
+               vchan->txd = NULL;
+       }
+
+       vchan_get_all_descriptors(&vchan->vc, &head);
+       vchan_dma_desc_free_list(&vchan->vc, &head);
+
+       spin_unlock_irqrestore(&vchan->vc.lock, flags);
+
+       return 0;
+}
+
+static u32 owl_dma_getbytes_chan(struct owl_dma_vchan *vchan)
+{
+       struct owl_dma_pchan *pchan;
+       struct owl_dma_txd *txd;
+       struct owl_dma_lli *lli;
+       unsigned int next_lli_phy;
+       size_t bytes;
+
+       pchan = vchan->pchan;
+       txd = vchan->txd;
+
+       if (!pchan || !txd)
+               return 0;
+
+       /* Get remain count of current node in link list */
+       bytes = pchan_readl(pchan, OWL_DMAX_REMAIN_CNT);
+
+       /* Loop through the preceding nodes to get total remaining bytes */
+       if (pchan_readl(pchan, OWL_DMAX_MODE) & OWL_DMA_MODE_LME) {
+               next_lli_phy = pchan_readl(pchan, OWL_DMAX_NEXT_DESCRIPTOR);
+               list_for_each_entry(lli, &txd->lli_list, node) {
+                       /* Start from the next active node */
+                       if (lli->phys == next_lli_phy) {
+                               list_for_each_entry(lli, &txd->lli_list, node)
+                                       bytes += lli->hw.flen;
+                               break;
+                       }
+               }
+       }
+
+       return bytes;
+}
+
+static enum dma_status owl_dma_tx_status(struct dma_chan *chan,
+                                        dma_cookie_t cookie,
+                                        struct dma_tx_state *state)
+{
+       struct owl_dma_vchan *vchan = to_owl_vchan(chan);
+       struct owl_dma_lli *lli;
+       struct virt_dma_desc *vd;
+       struct owl_dma_txd *txd;
+       enum dma_status ret;
+       unsigned long flags;
+       size_t bytes = 0;
+
+       ret = dma_cookie_status(chan, cookie, state);
+       if (ret == DMA_COMPLETE || !state)
+               return ret;
+
+       spin_lock_irqsave(&vchan->vc.lock, flags);
+
+       vd = vchan_find_desc(&vchan->vc, cookie);
+       if (vd) {
+               txd = to_owl_txd(&vd->tx);
+               list_for_each_entry(lli, &txd->lli_list, node)
+                       bytes += lli->hw.flen;
+       } else {
+               bytes = owl_dma_getbytes_chan(vchan);
+       }
+
+       spin_unlock_irqrestore(&vchan->vc.lock, flags);
+
+       dma_set_residue(state, bytes);
+
+       return ret;
+}
+
+static void owl_dma_phy_alloc_and_start(struct owl_dma_vchan *vchan)
+{
+       struct owl_dma *od = to_owl_dma(vchan->vc.chan.device);
+       struct owl_dma_pchan *pchan;
+
+       pchan = owl_dma_get_pchan(od, vchan);
+       if (!pchan)
+               return;
+
+       dev_dbg(od->dma.dev, "allocated pchan %d\n", pchan->id);
+
+       vchan->pchan = pchan;
+       owl_dma_start_next_txd(vchan);
+}
+
+static void owl_dma_issue_pending(struct dma_chan *chan)
+{
+       struct owl_dma_vchan *vchan = to_owl_vchan(chan);
+       unsigned long flags;
+
+       spin_lock_irqsave(&vchan->vc.lock, flags);
+       if (vchan_issue_pending(&vchan->vc)) {
+               if (!vchan->pchan)
+                       owl_dma_phy_alloc_and_start(vchan);
+       }
+       spin_unlock_irqrestore(&vchan->vc.lock, flags);
+}
+
+static struct dma_async_tx_descriptor
+               *owl_dma_prep_memcpy(struct dma_chan *chan,
+                                    dma_addr_t dst, dma_addr_t src,
+                                    size_t len, unsigned long flags)
+{
+       struct owl_dma *od = to_owl_dma(chan->device);
+       struct owl_dma_vchan *vchan = to_owl_vchan(chan);
+       struct owl_dma_txd *txd;
+       struct owl_dma_lli *lli, *prev = NULL;
+       size_t offset, bytes;
+       int ret;
+
+       if (!len)
+               return NULL;
+
+       txd = kzalloc(sizeof(*txd), GFP_NOWAIT);
+       if (!txd)
+               return NULL;
+
+       INIT_LIST_HEAD(&txd->lli_list);
+
+       /* Process the transfer as frame by frame */
+       for (offset = 0; offset < len; offset += bytes) {
+               lli = owl_dma_alloc_lli(od);
+               if (!lli) {
+                       dev_warn(chan2dev(chan), "failed to allocate lli\n");
+                       goto err_txd_free;
+               }
+
+               bytes = min_t(size_t, (len - offset), OWL_DMA_FRAME_MAX_LENGTH);
+
+               ret = owl_dma_cfg_lli(vchan, lli, src + offset, dst + offset,
+                                     bytes, DMA_MEM_TO_MEM);
+               if (ret) {
+                       dev_warn(chan2dev(chan), "failed to config lli\n");
+                       goto err_txd_free;
+               }
+
+               prev = owl_dma_add_lli(txd, prev, lli);
+       }
+
+       return vchan_tx_prep(&vchan->vc, &txd->vd, flags);
+
+err_txd_free:
+       owl_dma_free_txd(od, txd);
+       return NULL;
+}
+
+static void owl_dma_free_chan_resources(struct dma_chan *chan)
+{
+       struct owl_dma_vchan *vchan = to_owl_vchan(chan);
+
+       /* Ensure all queued descriptors are freed */
+       vchan_free_chan_resources(&vchan->vc);
+}
+
+static inline void owl_dma_free(struct owl_dma *od)
+{
+       struct owl_dma_vchan *vchan = NULL;
+       struct owl_dma_vchan *next;
+
+       list_for_each_entry_safe(vchan,
+                                next, &od->dma.channels, vc.chan.device_node) {
+               list_del(&vchan->vc.chan.device_node);
+               tasklet_kill(&vchan->vc.task);
+       }
+}
+
+static int owl_dma_probe(struct platform_device *pdev)
+{
+       struct device_node *np = pdev->dev.of_node;
+       struct owl_dma *od;
+       struct resource *res;
+       int ret, i, nr_channels, nr_requests;
+
+       od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
+       if (!od)
+               return -ENOMEM;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res)
+               return -EINVAL;
+
+       od->base = devm_ioremap_resource(&pdev->dev, res);
+       if (IS_ERR(od->base))
+               return PTR_ERR(od->base);
+
+       ret = of_property_read_u32(np, "dma-channels", &nr_channels);
+       if (ret) {
+               dev_err(&pdev->dev, "can't get dma-channels\n");
+               return ret;
+       }
+
+       ret = of_property_read_u32(np, "dma-requests", &nr_requests);
+       if (ret) {
+               dev_err(&pdev->dev, "can't get dma-requests\n");
+               return ret;
+       }
+
+       dev_info(&pdev->dev, "dma-channels %d, dma-requests %d\n",
+                nr_channels, nr_requests);
+
+       od->nr_pchans = nr_channels;
+       od->nr_vchans = nr_requests;
+
+       pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+
+       platform_set_drvdata(pdev, od);
+       spin_lock_init(&od->lock);
+
+       dma_cap_set(DMA_MEMCPY, od->dma.cap_mask);
+
+       od->dma.dev = &pdev->dev;
+       od->dma.device_free_chan_resources = owl_dma_free_chan_resources;
+       od->dma.device_tx_status = owl_dma_tx_status;
+       od->dma.device_issue_pending = owl_dma_issue_pending;
+       od->dma.device_prep_dma_memcpy = owl_dma_prep_memcpy;
+       od->dma.device_terminate_all = owl_dma_terminate_all;
+       od->dma.src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
+       od->dma.dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES);
+       od->dma.directions = BIT(DMA_MEM_TO_MEM);
+       od->dma.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
+
+       INIT_LIST_HEAD(&od->dma.channels);
+
+       od->clk = devm_clk_get(&pdev->dev, NULL);
+       if (IS_ERR(od->clk)) {
+               dev_err(&pdev->dev, "unable to get clock\n");
+               return PTR_ERR(od->clk);
+       }
+
+       /*
+        * Eventhough the DMA controller is capable of generating 4
+        * IRQ's for DMA priority feature, we only use 1 IRQ for
+        * simplification.
+        */
+       od->irq = platform_get_irq(pdev, 0);
+       ret = devm_request_irq(&pdev->dev, od->irq, owl_dma_interrupt, 0,
+                              dev_name(&pdev->dev), od);
+       if (ret) {
+               dev_err(&pdev->dev, "unable to request IRQ\n");
+               return ret;
+       }
+
+       /* Init physical channel */
+       od->pchans = devm_kcalloc(&pdev->dev, od->nr_pchans,
+                                 sizeof(struct owl_dma_pchan), GFP_KERNEL);
+       if (!od->pchans)
+               return -ENOMEM;
+
+       for (i = 0; i < od->nr_pchans; i++) {
+               struct owl_dma_pchan *pchan = &od->pchans[i];
+
+               pchan->id = i;
+               pchan->base = od->base + OWL_DMA_CHAN_BASE(i);
+       }
+
+       /* Init virtual channel */
+       od->vchans = devm_kcalloc(&pdev->dev, od->nr_vchans,
+                                 sizeof(struct owl_dma_vchan), GFP_KERNEL);
+       if (!od->vchans)
+               return -ENOMEM;
+
+       for (i = 0; i < od->nr_vchans; i++) {
+               struct owl_dma_vchan *vchan = &od->vchans[i];
+
+               vchan->vc.desc_free = owl_dma_desc_free;
+               vchan_init(&vchan->vc, &od->dma);
+       }
+
+       /* Create a pool of consistent memory blocks for hardware descriptors */
+       od->lli_pool = dma_pool_create(dev_name(od->dma.dev), od->dma.dev,
+                                      sizeof(struct owl_dma_lli),
+                                      __alignof__(struct owl_dma_lli),
+                                      0);
+       if (!od->lli_pool) {
+               dev_err(&pdev->dev, "unable to allocate DMA descriptor pool\n");
+               return -ENOMEM;
+       }
+
+       clk_prepare_enable(od->clk);
+
+       ret = dma_async_device_register(&od->dma);
+       if (ret) {
+               dev_err(&pdev->dev, "failed to register DMA engine device\n");
+               goto err_pool_free;
+       }
+
+       return 0;
+
+err_pool_free:
+       clk_disable_unprepare(od->clk);
+       dma_pool_destroy(od->lli_pool);
+
+       return ret;
+}
+
+static int owl_dma_remove(struct platform_device *pdev)
+{
+       struct owl_dma *od = platform_get_drvdata(pdev);
+
+       dma_async_device_unregister(&od->dma);
+
+       /* Mask all interrupts for this execution environment */
+       dma_writel(od, OWL_DMA_IRQ_EN0, 0x0);
+
+       /* Make sure we won't have any further interrupts */
+       devm_free_irq(od->dma.dev, od->irq, od);
+
+       owl_dma_free(od);
+
+       clk_disable_unprepare(od->clk);
+
+       return 0;
+}
+
+static const struct of_device_id owl_dma_match[] = {
+       { .compatible = "actions,s900-dma", },
+       { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, owl_dma_match);
+
+static struct platform_driver owl_dma_driver = {
+       .probe  = owl_dma_probe,
+       .remove = owl_dma_remove,
+       .driver = {
+               .name = "dma-owl",
+               .of_match_table = of_match_ptr(owl_dma_match),
+       },
+};
+
+static int owl_dma_init(void)
+{
+       return platform_driver_register(&owl_dma_driver);
+}
+subsys_initcall(owl_dma_init);
+
+static void __exit owl_dma_exit(void)
+{
+       platform_driver_unregister(&owl_dma_driver);
+}
+module_exit(owl_dma_exit);
+
+MODULE_AUTHOR("David Liu <liuwei@actions-semi.com>");
+MODULE_AUTHOR("Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>");
+MODULE_DESCRIPTION("Actions Semi Owl SoCs DMA driver");
+MODULE_LICENSE("GPL");
index 2a2ccd9c78e4cc1f8e7b7a72b22613530a0c1afe..48ee35e2bce6dd90165e8bdf085f6f1eccf5090a 100644 (file)
@@ -1,13 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Renesas R-Car Gen2 DMA Controller Driver
  *
  * Copyright (C) 2014 Renesas Electronics Inc.
  *
  * Author: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
- *
- * This is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
  */
 
 #include <linux/delay.h>
@@ -431,7 +428,8 @@ static void rcar_dmac_chan_start_xfer(struct rcar_dmac_chan *chan)
                chcr |= RCAR_DMACHCR_DPM_DISABLED | RCAR_DMACHCR_IE;
        }
 
-       rcar_dmac_chan_write(chan, RCAR_DMACHCR, chcr | RCAR_DMACHCR_DE);
+       rcar_dmac_chan_write(chan, RCAR_DMACHCR,
+                            chcr | RCAR_DMACHCR_DE | RCAR_DMACHCR_CAIE);
 }
 
 static int rcar_dmac_init(struct rcar_dmac *dmac)
@@ -761,21 +759,15 @@ static void rcar_dmac_chcr_de_barrier(struct rcar_dmac_chan *chan)
        dev_err(chan->chan.device->dev, "CHCR DE check error\n");
 }
 
-static void rcar_dmac_sync_tcr(struct rcar_dmac_chan *chan)
+static void rcar_dmac_clear_chcr_de(struct rcar_dmac_chan *chan)
 {
        u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR);
 
-       if (!(chcr & RCAR_DMACHCR_DE))
-               return;
-
        /* set DE=0 and flush remaining data */
        rcar_dmac_chan_write(chan, RCAR_DMACHCR, (chcr & ~RCAR_DMACHCR_DE));
 
        /* make sure all remaining data was flushed */
        rcar_dmac_chcr_de_barrier(chan);
-
-       /* back DE */
-       rcar_dmac_chan_write(chan, RCAR_DMACHCR, chcr);
 }
 
 static void rcar_dmac_chan_halt(struct rcar_dmac_chan *chan)
@@ -783,7 +775,8 @@ static void rcar_dmac_chan_halt(struct rcar_dmac_chan *chan)
        u32 chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR);
 
        chcr &= ~(RCAR_DMACHCR_DSE | RCAR_DMACHCR_DSIE | RCAR_DMACHCR_IE |
-                 RCAR_DMACHCR_TE | RCAR_DMACHCR_DE);
+                 RCAR_DMACHCR_TE | RCAR_DMACHCR_DE |
+                 RCAR_DMACHCR_CAE | RCAR_DMACHCR_CAIE);
        rcar_dmac_chan_write(chan, RCAR_DMACHCR, chcr);
        rcar_dmac_chcr_de_barrier(chan);
 }
@@ -812,12 +805,7 @@ static void rcar_dmac_chan_reinit(struct rcar_dmac_chan *chan)
        }
 }
 
-static void rcar_dmac_stop(struct rcar_dmac *dmac)
-{
-       rcar_dmac_write(dmac, RCAR_DMAOR, 0);
-}
-
-static void rcar_dmac_abort(struct rcar_dmac *dmac)
+static void rcar_dmac_stop_all_chan(struct rcar_dmac *dmac)
 {
        unsigned int i;
 
@@ -826,14 +814,24 @@ static void rcar_dmac_abort(struct rcar_dmac *dmac)
                struct rcar_dmac_chan *chan = &dmac->channels[i];
 
                /* Stop and reinitialize the channel. */
-               spin_lock(&chan->lock);
+               spin_lock_irq(&chan->lock);
                rcar_dmac_chan_halt(chan);
-               spin_unlock(&chan->lock);
-
-               rcar_dmac_chan_reinit(chan);
+               spin_unlock_irq(&chan->lock);
        }
 }
 
+static int rcar_dmac_chan_pause(struct dma_chan *chan)
+{
+       unsigned long flags;
+       struct rcar_dmac_chan *rchan = to_rcar_dmac_chan(chan);
+
+       spin_lock_irqsave(&rchan->lock, flags);
+       rcar_dmac_clear_chcr_de(rchan);
+       spin_unlock_irqrestore(&rchan->lock, flags);
+
+       return 0;
+}
+
 /* -----------------------------------------------------------------------------
  * Descriptors preparation
  */
@@ -1355,9 +1353,6 @@ static unsigned int rcar_dmac_chan_get_residue(struct rcar_dmac_chan *chan,
                residue += chunk->size;
        }
 
-       if (desc->direction == DMA_DEV_TO_MEM)
-               rcar_dmac_sync_tcr(chan);
-
        /* Add the residue for the current chunk. */
        residue += rcar_dmac_chan_read(chan, RCAR_DMATCRB) << desc->xfer_shift;
 
@@ -1522,11 +1517,26 @@ static irqreturn_t rcar_dmac_isr_channel(int irq, void *dev)
        u32 mask = RCAR_DMACHCR_DSE | RCAR_DMACHCR_TE;
        struct rcar_dmac_chan *chan = dev;
        irqreturn_t ret = IRQ_NONE;
+       bool reinit = false;
        u32 chcr;
 
        spin_lock(&chan->lock);
 
        chcr = rcar_dmac_chan_read(chan, RCAR_DMACHCR);
+       if (chcr & RCAR_DMACHCR_CAE) {
+               struct rcar_dmac *dmac = to_rcar_dmac(chan->chan.device);
+
+               /*
+                * We don't need to call rcar_dmac_chan_halt()
+                * because channel is already stopped in error case.
+                * We need to clear register and check DE bit as recovery.
+                */
+               rcar_dmac_write(dmac, RCAR_DMACHCLR, 1 << chan->index);
+               rcar_dmac_chcr_de_barrier(chan);
+               reinit = true;
+               goto spin_lock_end;
+       }
+
        if (chcr & RCAR_DMACHCR_TE)
                mask |= RCAR_DMACHCR_DE;
        rcar_dmac_chan_write(chan, RCAR_DMACHCR, chcr & ~mask);
@@ -1539,8 +1549,16 @@ static irqreturn_t rcar_dmac_isr_channel(int irq, void *dev)
        if (chcr & RCAR_DMACHCR_TE)
                ret |= rcar_dmac_isr_transfer_end(chan);
 
+spin_lock_end:
        spin_unlock(&chan->lock);
 
+       if (reinit) {
+               dev_err(chan->chan.device->dev, "Channel Address Error\n");
+
+               rcar_dmac_chan_reinit(chan);
+               ret = IRQ_HANDLED;
+       }
+
        return ret;
 }
 
@@ -1597,24 +1615,6 @@ static irqreturn_t rcar_dmac_isr_channel_thread(int irq, void *dev)
        return IRQ_HANDLED;
 }
 
-static irqreturn_t rcar_dmac_isr_error(int irq, void *data)
-{
-       struct rcar_dmac *dmac = data;
-
-       if (!(rcar_dmac_read(dmac, RCAR_DMAOR) & RCAR_DMAOR_AE))
-               return IRQ_NONE;
-
-       /*
-        * An unrecoverable error occurred on an unknown channel. Halt the DMAC,
-        * abort transfers on all channels, and reinitialize the DMAC.
-        */
-       rcar_dmac_stop(dmac);
-       rcar_dmac_abort(dmac);
-       rcar_dmac_init(dmac);
-
-       return IRQ_HANDLED;
-}
-
 /* -----------------------------------------------------------------------------
  * OF xlate and channel filter
  */
@@ -1784,8 +1784,6 @@ static int rcar_dmac_probe(struct platform_device *pdev)
        struct rcar_dmac *dmac;
        struct resource *mem;
        unsigned int i;
-       char *irqname;
-       int irq;
        int ret;
 
        dmac = devm_kzalloc(&pdev->dev, sizeof(*dmac), GFP_KERNEL);
@@ -1824,17 +1822,6 @@ static int rcar_dmac_probe(struct platform_device *pdev)
        if (IS_ERR(dmac->iomem))
                return PTR_ERR(dmac->iomem);
 
-       irq = platform_get_irq_byname(pdev, "error");
-       if (irq < 0) {
-               dev_err(&pdev->dev, "no error IRQ specified\n");
-               return -ENODEV;
-       }
-
-       irqname = devm_kasprintf(dmac->dev, GFP_KERNEL, "%s:error",
-                                dev_name(dmac->dev));
-       if (!irqname)
-               return -ENOMEM;
-
        /* Enable runtime PM and initialize the device. */
        pm_runtime_enable(&pdev->dev);
        ret = pm_runtime_get_sync(&pdev->dev);
@@ -1871,6 +1858,7 @@ static int rcar_dmac_probe(struct platform_device *pdev)
        engine->device_prep_slave_sg            = rcar_dmac_prep_slave_sg;
        engine->device_prep_dma_cyclic          = rcar_dmac_prep_dma_cyclic;
        engine->device_config                   = rcar_dmac_device_config;
+       engine->device_pause                    = rcar_dmac_chan_pause;
        engine->device_terminate_all            = rcar_dmac_chan_terminate_all;
        engine->device_tx_status                = rcar_dmac_tx_status;
        engine->device_issue_pending            = rcar_dmac_issue_pending;
@@ -1885,14 +1873,6 @@ static int rcar_dmac_probe(struct platform_device *pdev)
                        goto error;
        }
 
-       ret = devm_request_irq(&pdev->dev, irq, rcar_dmac_isr_error, 0,
-                              irqname, dmac);
-       if (ret) {
-               dev_err(&pdev->dev, "failed to request IRQ %u (%d)\n",
-                       irq, ret);
-               return ret;
-       }
-
        /* Register the DMAC as a DMA provider for DT. */
        ret = of_dma_controller_register(pdev->dev.of_node, rcar_dmac_of_xlate,
                                         NULL);
@@ -1932,7 +1912,7 @@ static void rcar_dmac_shutdown(struct platform_device *pdev)
 {
        struct rcar_dmac *dmac = platform_get_drvdata(pdev);
 
-       rcar_dmac_stop(dmac);
+       rcar_dmac_stop_all_chan(dmac);
 }
 
 static const struct of_device_id rcar_dmac_of_ids[] = {
index 1bc149af990e98ed2c08f7858e7953de04862abb..f4edfc56f34ef65dc34e50e38fd3c9aa258364fd 100644 (file)
@@ -555,6 +555,7 @@ struct d40_gen_dmac {
  * @reg_val_backup_v4: Backup of registers that only exits on dma40 v3 and
  * later
  * @reg_val_backup_chan: Backup data for standard channel parameter registers.
+ * @regs_interrupt: Scratch space for registers during interrupt.
  * @gcc_pwr_off_mask: Mask to maintain the channels that can be turned off.
  * @gen_dmac: the struct for generic registers values to represent u8500/8540
  * DMA controller
@@ -592,6 +593,7 @@ struct d40_base {
        u32                               reg_val_backup[BACKUP_REGS_SZ];
        u32                               reg_val_backup_v4[BACKUP_REGS_SZ_MAX];
        u32                              *reg_val_backup_chan;
+       u32                              *regs_interrupt;
        u16                               gcc_pwr_off_mask;
        struct d40_gen_dmac               gen_dmac;
 };
@@ -1637,7 +1639,7 @@ static irqreturn_t d40_handle_interrupt(int irq, void *data)
        struct d40_chan *d40c;
        unsigned long flags;
        struct d40_base *base = data;
-       u32 regs[base->gen_dmac.il_size];
+       u32 *regs = base->regs_interrupt;
        struct d40_interrupt_lookup *il = base->gen_dmac.il;
        u32 il_size = base->gen_dmac.il_size;
 
@@ -3258,13 +3260,22 @@ static struct d40_base * __init d40_hw_detect_init(struct platform_device *pdev)
        if (!base->lcla_pool.alloc_map)
                goto free_backup_chan;
 
+       base->regs_interrupt = kmalloc_array(base->gen_dmac.il_size,
+                                            sizeof(*base->regs_interrupt),
+                                            GFP_KERNEL);
+       if (!base->regs_interrupt)
+               goto free_map;
+
        base->desc_slab = kmem_cache_create(D40_NAME, sizeof(struct d40_desc),
                                            0, SLAB_HWCACHE_ALIGN,
                                            NULL);
        if (base->desc_slab == NULL)
-               goto free_map;
+               goto free_regs;
+
 
        return base;
+ free_regs:
+       kfree(base->regs_interrupt);
  free_map:
        kfree(base->lcla_pool.alloc_map);
  free_backup_chan:
index 8c5807362a257422ea89c805f92dc411bf8ded8e..379e8d534e615cc23d4d3a0281ff9498fedd7e00 100644 (file)
@@ -594,7 +594,7 @@ static void stm32_dma_start_transfer(struct stm32_dma_chan *chan)
 
        chan->busy = true;
 
-       dev_dbg(chan2dev(chan), "vchan %p: started\n", &chan->vchan);
+       dev_dbg(chan2dev(chan), "vchan %pK: started\n", &chan->vchan);
 }
 
 static void stm32_dma_configure_next_sg(struct stm32_dma_chan *chan)
@@ -693,7 +693,7 @@ static void stm32_dma_issue_pending(struct dma_chan *c)
 
        spin_lock_irqsave(&chan->vchan.lock, flags);
        if (vchan_issue_pending(&chan->vchan) && !chan->desc && !chan->busy) {
-               dev_dbg(chan2dev(chan), "vchan %p: issued\n", &chan->vchan);
+               dev_dbg(chan2dev(chan), "vchan %pK: issued\n", &chan->vchan);
                stm32_dma_start_transfer(chan);
 
        }
index 9dc450b7ace6c1c6291064dc6d37255860d74a14..06dd1725375e514710c245305069d61586ac2961 100644 (file)
@@ -1170,7 +1170,7 @@ static void stm32_mdma_start_transfer(struct stm32_mdma_chan *chan)
 
        chan->busy = true;
 
-       dev_dbg(chan2dev(chan), "vchan %p: started\n", &chan->vchan);
+       dev_dbg(chan2dev(chan), "vchan %pK: started\n", &chan->vchan);
 }
 
 static void stm32_mdma_issue_pending(struct dma_chan *c)
@@ -1183,7 +1183,7 @@ static void stm32_mdma_issue_pending(struct dma_chan *c)
        if (!vchan_issue_pending(&chan->vchan))
                goto end;
 
-       dev_dbg(chan2dev(chan), "vchan %p: issued\n", &chan->vchan);
+       dev_dbg(chan2dev(chan), "vchan %pK: issued\n", &chan->vchan);
 
        if (!chan->desc && !chan->busy)
                stm32_mdma_start_transfer(chan);
@@ -1203,7 +1203,7 @@ static int stm32_mdma_pause(struct dma_chan *c)
        spin_unlock_irqrestore(&chan->vchan.lock, flags);
 
        if (!ret)
-               dev_dbg(chan2dev(chan), "vchan %p: pause\n", &chan->vchan);
+               dev_dbg(chan2dev(chan), "vchan %pK: pause\n", &chan->vchan);
 
        return ret;
 }
@@ -1240,7 +1240,7 @@ static int stm32_mdma_resume(struct dma_chan *c)
 
        spin_unlock_irqrestore(&chan->vchan.lock, flags);
 
-       dev_dbg(chan2dev(chan), "vchan %p: resume\n", &chan->vchan);
+       dev_dbg(chan2dev(chan), "vchan %pK: resume\n", &chan->vchan);
 
        return 0;
 }
index 27b523530c4a5a632cd007444b972a9a84e6d017..c1244231259518d08dda4427c977fac160aee76b 100644 (file)
 #define XILINX_VDMA_REG_START_ADDRESS(n)       (0x000c + 4 * (n))
 #define XILINX_VDMA_REG_START_ADDRESS_64(n)    (0x000c + 8 * (n))
 
+#define XILINX_VDMA_REG_ENABLE_VERTICAL_FLIP   0x00ec
+#define XILINX_VDMA_ENABLE_VERTICAL_FLIP       BIT(0)
+
 /* HW specific definitions */
 #define XILINX_DMA_MAX_CHANS_PER_DEVICE        0x20
 
@@ -340,6 +343,7 @@ struct xilinx_dma_tx_descriptor {
  * @start_transfer: Differentiate b/w DMA IP's transfer
  * @stop_transfer: Differentiate b/w DMA IP's quiesce
  * @tdest: TDEST value for mcdma
+ * @has_vflip: S2MM vertical flip
  */
 struct xilinx_dma_chan {
        struct xilinx_dma_device *xdev;
@@ -376,6 +380,7 @@ struct xilinx_dma_chan {
        void (*start_transfer)(struct xilinx_dma_chan *chan);
        int (*stop_transfer)(struct xilinx_dma_chan *chan);
        u16 tdest;
+       bool has_vflip;
 };
 
 /**
@@ -1092,6 +1097,14 @@ static void xilinx_vdma_start_transfer(struct xilinx_dma_chan *chan)
                                desc->async_tx.phys);
 
        /* Configure the hardware using info in the config structure */
+       if (chan->has_vflip) {
+               reg = dma_read(chan, XILINX_VDMA_REG_ENABLE_VERTICAL_FLIP);
+               reg &= ~XILINX_VDMA_ENABLE_VERTICAL_FLIP;
+               reg |= config->vflip_en;
+               dma_write(chan, XILINX_VDMA_REG_ENABLE_VERTICAL_FLIP,
+                         reg);
+       }
+
        reg = dma_ctrl_read(chan, XILINX_DMA_REG_DMACR);
 
        if (config->frm_cnt_en)
@@ -2105,6 +2118,8 @@ int xilinx_vdma_channel_set_config(struct dma_chan *dchan,
        }
 
        chan->config.frm_cnt_en = cfg->frm_cnt_en;
+       chan->config.vflip_en = cfg->vflip_en;
+
        if (cfg->park)
                chan->config.park_frm = cfg->park_frm;
        else
@@ -2428,6 +2443,13 @@ static int xilinx_dma_chan_probe(struct xilinx_dma_device *xdev,
                chan->direction = DMA_DEV_TO_MEM;
                chan->id = chan_id;
                chan->tdest = chan_id - xdev->nr_channels;
+               chan->has_vflip = of_property_read_bool(node,
+                                       "xlnx,enable-vert-flip");
+               if (chan->has_vflip) {
+                       chan->config.vflip_en = dma_read(chan,
+                               XILINX_VDMA_REG_ENABLE_VERTICAL_FLIP) &
+                               XILINX_VDMA_ENABLE_VERTICAL_FLIP;
+               }
 
                chan->ctrl_offset = XILINX_DMA_S2MM_CTRL_OFFSET;
                if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) {
index 34b98f276ed03c0d758d50aef27e95e63c11d52d..5b6e61e4b3aa1e4cc0529cd0e2c33adfd80ba260 100644 (file)
@@ -27,6 +27,7 @@
  * @delay: Delay counter
  * @reset: Reset Channel
  * @ext_fsync: External Frame Sync source
+ * @vflip_en:  Vertical Flip enable
  */
 struct xilinx_vdma_config {
        int frm_dly;
@@ -39,6 +40,7 @@ struct xilinx_vdma_config {
        int delay;
        int reset;
        int ext_fsync;
+       bool vflip_en;
 };
 
 int xilinx_vdma_channel_set_config(struct dma_chan *dchan,
index 861be5cab1dff22b5ae2892eab265585a0c2de29..d49ec5c31944863137f044b4046808dab60fe4ea 100644 (file)
@@ -415,7 +415,9 @@ enum dma_residue_granularity {
  *     each type, the dma controller should set BIT(<TYPE>) and same
  *     should be checked by controller as well
  * @max_burst: max burst capability per-transfer
- * @cmd_pause: true, if pause and thereby resume is supported
+ * @cmd_pause: true, if pause is supported (i.e. for reading residue or
+ *            for resume later)
+ * @cmd_resume: true, if resume is supported
  * @cmd_terminate: true, if terminate cmd is supported
  * @residue_granularity: granularity of the reported transfer residue
  * @descriptor_reuse: if a descriptor can be reused by client and
@@ -427,6 +429,7 @@ struct dma_slave_caps {
        u32 directions;
        u32 max_burst;
        bool cmd_pause;
+       bool cmd_resume;
        bool cmd_terminate;
        enum dma_residue_granularity residue_granularity;
        bool descriptor_reuse;
@@ -1403,6 +1406,7 @@ static inline int dmaengine_desc_free(struct dma_async_tx_descriptor *desc)
 /* --- DMA device --- */
 
 int dma_async_device_register(struct dma_device *device);
+int dmaenginem_async_device_register(struct dma_device *device);
 void dma_async_device_unregister(struct dma_device *device);
 void dma_run_dependencies(struct dma_async_tx_descriptor *tx);
 struct dma_chan *dma_get_slave_channel(struct dma_chan *chan);
index 56a541b9ff9e2340eabc996c803a9b3a7427853c..76c46d79384330fa3f593742ff9e1118b227467a 100644 (file)
@@ -156,7 +156,7 @@ static int dmaengine_pcm_set_runtime_hwparams(struct snd_pcm_substream *substrea
 
        ret = dma_get_slave_caps(chan, &dma_caps);
        if (ret == 0) {
-               if (dma_caps.cmd_pause)
+               if (dma_caps.cmd_pause && dma_caps.cmd_resume)
                        hw.info |= SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME;
                if (dma_caps.residue_granularity <= DMA_RESIDUE_GRANULARITY_SEGMENT)
                        hw.info |= SNDRV_PCM_INFO_BATCH;