RE: [RESEND PATCH v3 2/2] dma: Add Xilinx AXI Central Direct Memory Access Engine driver support

2015-03-27 Thread Appana Durga Kedareswara Rao
Ping !

> -Original Message-
> From: Kedareswara rao Appana [mailto:appana.durga@xilinx.com]
> Sent: Wednesday, March 25, 2015 10:39 AM
> To: Michal Simek; Soren Brinkmann; vinod.k...@intel.com;
> dan.j.willi...@intel.com
> Cc: app...@xilinx.com; dmaeng...@vger.kernel.org; linux-arm-
> ker...@lists.infradead.org; linux-kernel@vger.kernel.org; Appana Durga
> Kedareswara Rao; Srikanth Thokala
> Subject: [RESEND PATCH v3 2/2] dma: Add Xilinx AXI Central Direct Memory
> Access Engine driver support
>
> This is the driver for the AXI Central Direct Memory Access (AXI
> CDMA) core, which is a soft Xilinx IP core that provides high-bandwidth Direct
> Memory Access (DMA) between a memory-mapped source address and a
> memory-mapped destination address.
>
> This module works on Zynq (ARM Based SoC) and Microblaze platforms.
>
> Signed-off-by: Srikanth Thokala 
> Signed-off-by: Kedareswara rao Appana 
> ---
> This patch is rebased on top of dma: xilinx-dma: move header file to common
> location.
>
> Changes in v3:
> - Check for CDMA idle condition before changing the configuration.
> - Modified the xilinx_dma.h header file location to the
>   include/linux/dma/xilinx_dma.h
> Changes in v2:
> - Rebased on 3.16-rc7.
>
>  drivers/dma/Kconfig  |   12 +
>  drivers/dma/xilinx/Makefile  |1 +
>  drivers/dma/xilinx/xilinx_cdma.c | 1000
> ++
>  include/linux/dma/xilinx_dma.h   |   15 +-
>  4 files changed, 1027 insertions(+), 1 deletion(-)  create mode 100644
> drivers/dma/xilinx/xilinx_cdma.c
>
> diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig index
> a874b6e..1bc17c6 100644
> --- a/drivers/dma/Kconfig
> +++ b/drivers/dma/Kconfig
> @@ -425,6 +425,18 @@ config IMG_MDC_DMA
>   help
> Enable support for the IMG multi-threaded DMA controller (MDC).
>
> +config XILINX_CDMA
> + tristate "Xilinx AXI CDMA Engine"
> + depends on (ARCH_ZYNQ || MICROBLAZE)
> + select DMA_ENGINE
> + help
> +   Enable support for Xilinx AXI CDMA Soft IP.
> +
> + The AXI CDMA is a soft IP which provides high-bandwidth
> + Direct Memory Access (DMA) between a memory-mapped source
> + address and a memory-mapped destination address using the
> + AXI4 protocol.
> +
>  config DMA_ENGINE
>   bool
>
> diff --git a/drivers/dma/xilinx/Makefile b/drivers/dma/xilinx/Makefile index
> 3c4e9f2..e1dee77 100644
> --- a/drivers/dma/xilinx/Makefile
> +++ b/drivers/dma/xilinx/Makefile
> @@ -1 +1,2 @@
>  obj-$(CONFIG_XILINX_VDMA) += xilinx_vdma.o
> +obj-$(CONFIG_XILINX_CDMA) += xilinx_cdma.o
> diff --git a/drivers/dma/xilinx/xilinx_cdma.c
> b/drivers/dma/xilinx/xilinx_cdma.c
> new file mode 100644
> index 000..ff82fab
> --- /dev/null
> +++ b/drivers/dma/xilinx/xilinx_cdma.c
> @@ -0,0 +1,1000 @@
> +/*
> + * DMA driver for Xilinx Central DMA Engine
> + *
> + * Copyright (C) 2010 - 2015 Xilinx, Inc. All rights reserved.
> + *
> + * Based on the Freescale DMA driver.
> + *
> + * Description:
> + *  The AXI CDMA, is a soft IP, which provides high-bandwidth Direct
> +Memory
> + *  Access (DMA) between a memory-mapped source address and a
> +memory-mapped
> + *  destination address.
> + *
> + * This program is free software: you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "../dmaengine.h"
> +
> +/* Register Offsets */
> +#define XILINX_CDMA_CONTROL_OFFSET 0x00
> +#define XILINX_CDMA_STATUS_OFFSET  0x04
> +#define XILINX_CDMA_CDESC_OFFSET   0x08
> +#define XILINX_CDMA_TDESC_OFFSET   0x10
> +#define XILINX_CDMA_SRCADDR_OFFSET 0x18
> +#define XILINX_CDMA_DSTADDR_OFFSET 0x20
> +#define XILINX_CDMA_BTT_OFFSET 0x28
> +
> +/* General register bits definitions */
> +#define XILINX_CDMA_CR_RESET   BIT(2)
> +#define XILINX_CDMA_CR_SGMODE  BIT(3)
> +
> +#define XILINX_CDMA_SR_IDLEBIT(1)
> +
> +#define XILINX_CDMA_XR_IRQ_IOC_MASKBIT(12)
> +#define XILINX_CDMA_XR_IRQ_DELAY_MASK  BIT(13) #define
> +XILINX_CDMA_XR_IRQ_ERROR_MASK  BIT(14)
> +#define XILINX_CDMA_XR_IRQ_ALL_MASKGENMASK(14, 12)
> +
> +#define XILINX_CDMA_XR_DELAY_MASK  GENMASK(31, 24)
> +#define XILINX_CDMA_XR_COALESCE_MASK   GENMASK(23, 16)
> +
> +#define XILIN

[RESEND PATCH v3 2/2] dma: Add Xilinx AXI Central Direct Memory Access Engine driver support

2015-03-24 Thread Kedareswara rao Appana
This is the driver for the AXI Central Direct Memory Access (AXI
CDMA) core, which is a soft Xilinx IP core that provides high-bandwidth
Direct Memory Access (DMA) between a memory-mapped source address and a
memory-mapped destination address.

This module works on Zynq (ARM Based SoC) and Microblaze platforms.

Signed-off-by: Srikanth Thokala 
Signed-off-by: Kedareswara rao Appana 
---
This patch is rebased on top of dma: xilinx-dma: move header file
to common location.

Changes in v3:
- Check for CDMA idle condition before changing the configuration.
- Modified the xilinx_dma.h header file location to the
  include/linux/dma/xilinx_dma.h
Changes in v2:
- Rebased on 3.16-rc7.

 drivers/dma/Kconfig  |   12 +
 drivers/dma/xilinx/Makefile  |1 +
 drivers/dma/xilinx/xilinx_cdma.c | 1000 ++
 include/linux/dma/xilinx_dma.h   |   15 +-
 4 files changed, 1027 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma/xilinx/xilinx_cdma.c

diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
index a874b6e..1bc17c6 100644
--- a/drivers/dma/Kconfig
+++ b/drivers/dma/Kconfig
@@ -425,6 +425,18 @@ config IMG_MDC_DMA
help
  Enable support for the IMG multi-threaded DMA controller (MDC).
 
+config XILINX_CDMA
+   tristate "Xilinx AXI CDMA Engine"
+   depends on (ARCH_ZYNQ || MICROBLAZE)
+   select DMA_ENGINE
+   help
+ Enable support for Xilinx AXI CDMA Soft IP.
+
+   The AXI CDMA is a soft IP which provides high-bandwidth
+   Direct Memory Access (DMA) between a memory-mapped source
+   address and a memory-mapped destination address using the
+   AXI4 protocol.
+
 config DMA_ENGINE
bool
 
diff --git a/drivers/dma/xilinx/Makefile b/drivers/dma/xilinx/Makefile
index 3c4e9f2..e1dee77 100644
--- a/drivers/dma/xilinx/Makefile
+++ b/drivers/dma/xilinx/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_XILINX_VDMA) += xilinx_vdma.o
+obj-$(CONFIG_XILINX_CDMA) += xilinx_cdma.o
diff --git a/drivers/dma/xilinx/xilinx_cdma.c b/drivers/dma/xilinx/xilinx_cdma.c
new file mode 100644
index 000..ff82fab
--- /dev/null
+++ b/drivers/dma/xilinx/xilinx_cdma.c
@@ -0,0 +1,1000 @@
+/*
+ * DMA driver for Xilinx Central DMA Engine
+ *
+ * Copyright (C) 2010 - 2015 Xilinx, Inc. All rights reserved.
+ *
+ * Based on the Freescale DMA driver.
+ *
+ * Description:
+ *  The AXI CDMA, is a soft IP, which provides high-bandwidth Direct Memory
+ *  Access (DMA) between a memory-mapped source address and a memory-mapped
+ *  destination address.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../dmaengine.h"
+
+/* Register Offsets */
+#define XILINX_CDMA_CONTROL_OFFSET 0x00
+#define XILINX_CDMA_STATUS_OFFSET  0x04
+#define XILINX_CDMA_CDESC_OFFSET   0x08
+#define XILINX_CDMA_TDESC_OFFSET   0x10
+#define XILINX_CDMA_SRCADDR_OFFSET 0x18
+#define XILINX_CDMA_DSTADDR_OFFSET 0x20
+#define XILINX_CDMA_BTT_OFFSET 0x28
+
+/* General register bits definitions */
+#define XILINX_CDMA_CR_RESET   BIT(2)
+#define XILINX_CDMA_CR_SGMODE  BIT(3)
+
+#define XILINX_CDMA_SR_IDLEBIT(1)
+
+#define XILINX_CDMA_XR_IRQ_IOC_MASKBIT(12)
+#define XILINX_CDMA_XR_IRQ_DELAY_MASK  BIT(13)
+#define XILINX_CDMA_XR_IRQ_ERROR_MASK  BIT(14)
+#define XILINX_CDMA_XR_IRQ_ALL_MASKGENMASK(14, 12)
+
+#define XILINX_CDMA_XR_DELAY_MASK  GENMASK(31, 24)
+#define XILINX_CDMA_XR_COALESCE_MASK   GENMASK(23, 16)
+
+#define XILINX_CDMA_DELAY_MAX  GENMASK(7, 0)
+#define XILINX_CDMA_DELAY_SHIFT24
+
+#define XILINX_CDMA_COALESCE_MAX   GENMASK(7, 0)
+#define XILINX_CDMA_COALESCE_SHIFT 16
+
+/* Delay loop counter to prevent hardware failure */
+#define XILINX_CDMA_RESET_LOOP 100
+
+/* Maximum transfer length */
+#define XILINX_CDMA_MAX_TRANS_LEN  GENMASK(22, 0)
+
+/**
+ * struct xilinx_cdma_desc_hw - Hardware Descriptor
+ * @next_desc: Next Descriptor Pointer @0x00
+ * @pad1: Reserved @0x04
+ * @src_addr: Source address @0x08
+ * @pad2: Reserved @0x0C
+ * @dest_addr: Destination address @0x10
+ * @pad3: Reserved @0x14
+ * @control: Control field @0x18
+ * @status: Status field @0x1C
+ */
+struct xilinx_cdma_desc_hw {
+   u32 next_desc;
+   u32 pad1;
+   u32 src_addr;
+   u32 pad2;
+   u32 dest_addr;
+   u32 pad3;
+   u32 control;
+   u32 status;
+} __aligned(64);
+
+/**
+ * struct xilinx_cdma_tx_segment - Descriptor segment
+ * @hw: Hardware descriptor
+ * @node: Node in the descriptor segments list
+ * @phys: Physical address of segment
+ */
+struct xilinx_cdma_tx_segment {
+   struct