Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1 | /* |
| 2 | * DMA driver for Xilinx Video DMA Engine |
| 3 | * |
| 4 | * Copyright (C) 2010-2014 Xilinx, Inc. All rights reserved. |
| 5 | * |
| 6 | * Based on the Freescale DMA driver. |
| 7 | * |
| 8 | * Description: |
| 9 | * The AXI Video Direct Memory Access (AXI VDMA) core is a soft Xilinx IP |
| 10 | * core that provides high-bandwidth direct memory access between memory |
| 11 | * and AXI4-Stream type video target peripherals. The core provides efficient |
| 12 | * two dimensional DMA operations with independent asynchronous read (S2MM) |
| 13 | * and write (MM2S) channel operation. It can be configured to have either |
| 14 | * one channel or two channels. If configured as two channels, one is to |
| 15 | * transmit to the video device (MM2S) and another is to receive from the |
| 16 | * video device (S2MM). Initialization, status, interrupt and management |
| 17 | * registers are accessed through an AXI4-Lite slave interface. |
| 18 | * |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 19 | * The AXI Direct Memory Access (AXI DMA) core is a soft Xilinx IP core that |
| 20 | * provides high-bandwidth one dimensional direct memory access between memory |
| 21 | * and AXI4-Stream target peripherals. It supports one receive and one |
| 22 | * transmit channel, both of them optional at synthesis time. |
| 23 | * |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 24 | * The AXI CDMA, is a soft IP, which provides high-bandwidth Direct Memory |
| 25 | * Access (DMA) between a memory-mapped source address and a memory-mapped |
| 26 | * destination address. |
| 27 | * |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 28 | * This program is free software: you can redistribute it and/or modify |
| 29 | * it under the terms of the GNU General Public License as published by |
| 30 | * the Free Software Foundation, either version 2 of the License, or |
| 31 | * (at your option) any later version. |
| 32 | */ |
| 33 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 34 | #include <linux/bitops.h> |
| 35 | #include <linux/dmapool.h> |
Kedareswara rao Appana | 937abe8 | 2015-03-02 23:24:24 +0530 | [diff] [blame] | 36 | #include <linux/dma/xilinx_dma.h> |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 37 | #include <linux/init.h> |
| 38 | #include <linux/interrupt.h> |
| 39 | #include <linux/io.h> |
Kedareswara rao Appana | 9495f26 | 2016-02-26 19:33:54 +0530 | [diff] [blame] | 40 | #include <linux/iopoll.h> |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 41 | #include <linux/module.h> |
| 42 | #include <linux/of_address.h> |
| 43 | #include <linux/of_dma.h> |
| 44 | #include <linux/of_platform.h> |
| 45 | #include <linux/of_irq.h> |
| 46 | #include <linux/slab.h> |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 47 | #include <linux/clk.h> |
Kedareswara rao Appana | f0cba68 | 2016-06-07 19:21:15 +0530 | [diff] [blame^] | 48 | #include <linux/io-64-nonatomic-lo-hi.h> |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 49 | |
| 50 | #include "../dmaengine.h" |
| 51 | |
| 52 | /* Register/Descriptor Offsets */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 53 | #define XILINX_DMA_MM2S_CTRL_OFFSET 0x0000 |
| 54 | #define XILINX_DMA_S2MM_CTRL_OFFSET 0x0030 |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 55 | #define XILINX_VDMA_MM2S_DESC_OFFSET 0x0050 |
| 56 | #define XILINX_VDMA_S2MM_DESC_OFFSET 0x00a0 |
| 57 | |
| 58 | /* Control Registers */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 59 | #define XILINX_DMA_REG_DMACR 0x0000 |
| 60 | #define XILINX_DMA_DMACR_DELAY_MAX 0xff |
| 61 | #define XILINX_DMA_DMACR_DELAY_SHIFT 24 |
| 62 | #define XILINX_DMA_DMACR_FRAME_COUNT_MAX 0xff |
| 63 | #define XILINX_DMA_DMACR_FRAME_COUNT_SHIFT 16 |
| 64 | #define XILINX_DMA_DMACR_ERR_IRQ BIT(14) |
| 65 | #define XILINX_DMA_DMACR_DLY_CNT_IRQ BIT(13) |
| 66 | #define XILINX_DMA_DMACR_FRM_CNT_IRQ BIT(12) |
| 67 | #define XILINX_DMA_DMACR_MASTER_SHIFT 8 |
| 68 | #define XILINX_DMA_DMACR_FSYNCSRC_SHIFT 5 |
| 69 | #define XILINX_DMA_DMACR_FRAMECNT_EN BIT(4) |
| 70 | #define XILINX_DMA_DMACR_GENLOCK_EN BIT(3) |
| 71 | #define XILINX_DMA_DMACR_RESET BIT(2) |
| 72 | #define XILINX_DMA_DMACR_CIRC_EN BIT(1) |
| 73 | #define XILINX_DMA_DMACR_RUNSTOP BIT(0) |
| 74 | #define XILINX_DMA_DMACR_FSYNCSRC_MASK GENMASK(6, 5) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 75 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 76 | #define XILINX_DMA_REG_DMASR 0x0004 |
| 77 | #define XILINX_DMA_DMASR_EOL_LATE_ERR BIT(15) |
| 78 | #define XILINX_DMA_DMASR_ERR_IRQ BIT(14) |
| 79 | #define XILINX_DMA_DMASR_DLY_CNT_IRQ BIT(13) |
| 80 | #define XILINX_DMA_DMASR_FRM_CNT_IRQ BIT(12) |
| 81 | #define XILINX_DMA_DMASR_SOF_LATE_ERR BIT(11) |
| 82 | #define XILINX_DMA_DMASR_SG_DEC_ERR BIT(10) |
| 83 | #define XILINX_DMA_DMASR_SG_SLV_ERR BIT(9) |
| 84 | #define XILINX_DMA_DMASR_EOF_EARLY_ERR BIT(8) |
| 85 | #define XILINX_DMA_DMASR_SOF_EARLY_ERR BIT(7) |
| 86 | #define XILINX_DMA_DMASR_DMA_DEC_ERR BIT(6) |
| 87 | #define XILINX_DMA_DMASR_DMA_SLAVE_ERR BIT(5) |
| 88 | #define XILINX_DMA_DMASR_DMA_INT_ERR BIT(4) |
| 89 | #define XILINX_DMA_DMASR_IDLE BIT(1) |
| 90 | #define XILINX_DMA_DMASR_HALTED BIT(0) |
| 91 | #define XILINX_DMA_DMASR_DELAY_MASK GENMASK(31, 24) |
| 92 | #define XILINX_DMA_DMASR_FRAME_COUNT_MASK GENMASK(23, 16) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 93 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 94 | #define XILINX_DMA_REG_CURDESC 0x0008 |
| 95 | #define XILINX_DMA_REG_TAILDESC 0x0010 |
| 96 | #define XILINX_DMA_REG_REG_INDEX 0x0014 |
| 97 | #define XILINX_DMA_REG_FRMSTORE 0x0018 |
| 98 | #define XILINX_DMA_REG_THRESHOLD 0x001c |
| 99 | #define XILINX_DMA_REG_FRMPTR_STS 0x0024 |
| 100 | #define XILINX_DMA_REG_PARK_PTR 0x0028 |
| 101 | #define XILINX_DMA_PARK_PTR_WR_REF_SHIFT 8 |
| 102 | #define XILINX_DMA_PARK_PTR_RD_REF_SHIFT 0 |
| 103 | #define XILINX_DMA_REG_VDMA_VERSION 0x002c |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 104 | |
| 105 | /* Register Direct Mode Registers */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 106 | #define XILINX_DMA_REG_VSIZE 0x0000 |
| 107 | #define XILINX_DMA_REG_HSIZE 0x0004 |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 108 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 109 | #define XILINX_DMA_REG_FRMDLY_STRIDE 0x0008 |
| 110 | #define XILINX_DMA_FRMDLY_STRIDE_FRMDLY_SHIFT 24 |
| 111 | #define XILINX_DMA_FRMDLY_STRIDE_STRIDE_SHIFT 0 |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 112 | |
| 113 | #define XILINX_VDMA_REG_START_ADDRESS(n) (0x000c + 4 * (n)) |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 114 | #define XILINX_VDMA_REG_START_ADDRESS_64(n) (0x000c + 8 * (n)) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 115 | |
| 116 | /* HW specific definitions */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 117 | #define XILINX_DMA_MAX_CHANS_PER_DEVICE 0x2 |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 118 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 119 | #define XILINX_DMA_DMAXR_ALL_IRQ_MASK \ |
| 120 | (XILINX_DMA_DMASR_FRM_CNT_IRQ | \ |
| 121 | XILINX_DMA_DMASR_DLY_CNT_IRQ | \ |
| 122 | XILINX_DMA_DMASR_ERR_IRQ) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 123 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 124 | #define XILINX_DMA_DMASR_ALL_ERR_MASK \ |
| 125 | (XILINX_DMA_DMASR_EOL_LATE_ERR | \ |
| 126 | XILINX_DMA_DMASR_SOF_LATE_ERR | \ |
| 127 | XILINX_DMA_DMASR_SG_DEC_ERR | \ |
| 128 | XILINX_DMA_DMASR_SG_SLV_ERR | \ |
| 129 | XILINX_DMA_DMASR_EOF_EARLY_ERR | \ |
| 130 | XILINX_DMA_DMASR_SOF_EARLY_ERR | \ |
| 131 | XILINX_DMA_DMASR_DMA_DEC_ERR | \ |
| 132 | XILINX_DMA_DMASR_DMA_SLAVE_ERR | \ |
| 133 | XILINX_DMA_DMASR_DMA_INT_ERR) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * Recoverable errors are DMA Internal error, SOF Early, EOF Early |
| 137 | * and SOF Late. They are only recoverable when C_FLUSH_ON_FSYNC |
| 138 | * is enabled in the h/w system. |
| 139 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 140 | #define XILINX_DMA_DMASR_ERR_RECOVER_MASK \ |
| 141 | (XILINX_DMA_DMASR_SOF_LATE_ERR | \ |
| 142 | XILINX_DMA_DMASR_EOF_EARLY_ERR | \ |
| 143 | XILINX_DMA_DMASR_SOF_EARLY_ERR | \ |
| 144 | XILINX_DMA_DMASR_DMA_INT_ERR) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 145 | |
| 146 | /* Axi VDMA Flush on Fsync bits */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 147 | #define XILINX_DMA_FLUSH_S2MM 3 |
| 148 | #define XILINX_DMA_FLUSH_MM2S 2 |
| 149 | #define XILINX_DMA_FLUSH_BOTH 1 |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 150 | |
| 151 | /* Delay loop counter to prevent hardware failure */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 152 | #define XILINX_DMA_LOOP_COUNT 1000000 |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 153 | |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 154 | /* AXI DMA Specific Registers/Offsets */ |
| 155 | #define XILINX_DMA_REG_SRCDSTADDR 0x18 |
| 156 | #define XILINX_DMA_REG_BTT 0x28 |
| 157 | |
| 158 | /* AXI DMA Specific Masks/Bit fields */ |
| 159 | #define XILINX_DMA_MAX_TRANS_LEN GENMASK(22, 0) |
| 160 | #define XILINX_DMA_CR_COALESCE_MAX GENMASK(23, 16) |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 161 | #define XILINX_DMA_CR_CYCLIC_BD_EN_MASK BIT(4) |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 162 | #define XILINX_DMA_CR_COALESCE_SHIFT 16 |
| 163 | #define XILINX_DMA_BD_SOP BIT(27) |
| 164 | #define XILINX_DMA_BD_EOP BIT(26) |
| 165 | #define XILINX_DMA_COALESCE_MAX 255 |
| 166 | #define XILINX_DMA_NUM_APP_WORDS 5 |
| 167 | |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 168 | /* AXI CDMA Specific Registers/Offsets */ |
| 169 | #define XILINX_CDMA_REG_SRCADDR 0x18 |
| 170 | #define XILINX_CDMA_REG_DSTADDR 0x20 |
| 171 | |
| 172 | /* AXI CDMA Specific Masks */ |
| 173 | #define XILINX_CDMA_CR_SGMODE BIT(3) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 174 | |
| 175 | /** |
| 176 | * struct xilinx_vdma_desc_hw - Hardware Descriptor |
| 177 | * @next_desc: Next Descriptor Pointer @0x00 |
| 178 | * @pad1: Reserved @0x04 |
| 179 | * @buf_addr: Buffer address @0x08 |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 180 | * @buf_addr_msb: MSB of Buffer address @0x0C |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 181 | * @vsize: Vertical Size @0x10 |
| 182 | * @hsize: Horizontal Size @0x14 |
| 183 | * @stride: Number of bytes between the first |
| 184 | * pixels of each horizontal line @0x18 |
| 185 | */ |
| 186 | struct xilinx_vdma_desc_hw { |
| 187 | u32 next_desc; |
| 188 | u32 pad1; |
| 189 | u32 buf_addr; |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 190 | u32 buf_addr_msb; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 191 | u32 vsize; |
| 192 | u32 hsize; |
| 193 | u32 stride; |
| 194 | } __aligned(64); |
| 195 | |
| 196 | /** |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 197 | * struct xilinx_axidma_desc_hw - Hardware Descriptor for AXI DMA |
| 198 | * @next_desc: Next Descriptor Pointer @0x00 |
Kedareswara rao Appana | f0cba68 | 2016-06-07 19:21:15 +0530 | [diff] [blame^] | 199 | * @next_desc_msb: MSB of Next Descriptor Pointer @0x04 |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 200 | * @buf_addr: Buffer address @0x08 |
Kedareswara rao Appana | f0cba68 | 2016-06-07 19:21:15 +0530 | [diff] [blame^] | 201 | * @buf_addr_msb: MSB of Buffer address @0x0C |
| 202 | * @pad1: Reserved @0x10 |
| 203 | * @pad2: Reserved @0x14 |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 204 | * @control: Control field @0x18 |
| 205 | * @status: Status field @0x1C |
| 206 | * @app: APP Fields @0x20 - 0x30 |
| 207 | */ |
| 208 | struct xilinx_axidma_desc_hw { |
| 209 | u32 next_desc; |
Kedareswara rao Appana | f0cba68 | 2016-06-07 19:21:15 +0530 | [diff] [blame^] | 210 | u32 next_desc_msb; |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 211 | u32 buf_addr; |
Kedareswara rao Appana | f0cba68 | 2016-06-07 19:21:15 +0530 | [diff] [blame^] | 212 | u32 buf_addr_msb; |
| 213 | u32 pad1; |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 214 | u32 pad2; |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 215 | u32 control; |
| 216 | u32 status; |
| 217 | u32 app[XILINX_DMA_NUM_APP_WORDS]; |
| 218 | } __aligned(64); |
| 219 | |
| 220 | /** |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 221 | * struct xilinx_cdma_desc_hw - Hardware Descriptor |
| 222 | * @next_desc: Next Descriptor Pointer @0x00 |
| 223 | * @pad1: Reserved @0x04 |
| 224 | * @src_addr: Source address @0x08 |
| 225 | * @pad2: Reserved @0x0C |
| 226 | * @dest_addr: Destination address @0x10 |
| 227 | * @pad3: Reserved @0x14 |
| 228 | * @control: Control field @0x18 |
| 229 | * @status: Status field @0x1C |
| 230 | */ |
| 231 | struct xilinx_cdma_desc_hw { |
| 232 | u32 next_desc; |
| 233 | u32 pad1; |
| 234 | u32 src_addr; |
| 235 | u32 pad2; |
| 236 | u32 dest_addr; |
| 237 | u32 pad3; |
| 238 | u32 control; |
| 239 | u32 status; |
| 240 | } __aligned(64); |
| 241 | |
| 242 | /** |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 243 | * struct xilinx_vdma_tx_segment - Descriptor segment |
| 244 | * @hw: Hardware descriptor |
| 245 | * @node: Node in the descriptor segments list |
| 246 | * @phys: Physical address of segment |
| 247 | */ |
| 248 | struct xilinx_vdma_tx_segment { |
| 249 | struct xilinx_vdma_desc_hw hw; |
| 250 | struct list_head node; |
| 251 | dma_addr_t phys; |
| 252 | } __aligned(64); |
| 253 | |
| 254 | /** |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 255 | * struct xilinx_axidma_tx_segment - Descriptor segment |
| 256 | * @hw: Hardware descriptor |
| 257 | * @node: Node in the descriptor segments list |
| 258 | * @phys: Physical address of segment |
| 259 | */ |
| 260 | struct xilinx_axidma_tx_segment { |
| 261 | struct xilinx_axidma_desc_hw hw; |
| 262 | struct list_head node; |
| 263 | dma_addr_t phys; |
| 264 | } __aligned(64); |
| 265 | |
| 266 | /** |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 267 | * struct xilinx_cdma_tx_segment - Descriptor segment |
| 268 | * @hw: Hardware descriptor |
| 269 | * @node: Node in the descriptor segments list |
| 270 | * @phys: Physical address of segment |
| 271 | */ |
| 272 | struct xilinx_cdma_tx_segment { |
| 273 | struct xilinx_cdma_desc_hw hw; |
| 274 | struct list_head node; |
| 275 | dma_addr_t phys; |
| 276 | } __aligned(64); |
| 277 | |
| 278 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 279 | * struct xilinx_dma_tx_descriptor - Per Transaction structure |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 280 | * @async_tx: Async transaction descriptor |
| 281 | * @segments: TX segments list |
| 282 | * @node: Node in the channel descriptors list |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 283 | * @cyclic: Check for cyclic transfers. |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 284 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 285 | struct xilinx_dma_tx_descriptor { |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 286 | struct dma_async_tx_descriptor async_tx; |
| 287 | struct list_head segments; |
| 288 | struct list_head node; |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 289 | bool cyclic; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 290 | }; |
| 291 | |
| 292 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 293 | * struct xilinx_dma_chan - Driver specific DMA channel structure |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 294 | * @xdev: Driver specific device structure |
| 295 | * @ctrl_offset: Control registers offset |
| 296 | * @desc_offset: TX descriptor registers offset |
| 297 | * @lock: Descriptor operation lock |
| 298 | * @pending_list: Descriptors waiting |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 299 | * @active_list: Descriptors ready to submit |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 300 | * @done_list: Complete descriptors |
| 301 | * @common: DMA common channel |
| 302 | * @desc_pool: Descriptors pool |
| 303 | * @dev: The dma device |
| 304 | * @irq: Channel IRQ |
| 305 | * @id: Channel ID |
| 306 | * @direction: Transfer direction |
| 307 | * @num_frms: Number of frames |
| 308 | * @has_sg: Support scatter transfers |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 309 | * @cyclic: Check for cyclic transfers. |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 310 | * @genlock: Support genlock mode |
| 311 | * @err: Channel has errors |
| 312 | * @tasklet: Cleanup work after irq |
| 313 | * @config: Device configuration info |
| 314 | * @flush_on_fsync: Flush on Frame sync |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 315 | * @desc_pendingcount: Descriptor pending count |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 316 | * @ext_addr: Indicates 64 bit addressing is supported by dma channel |
Kedareswara rao Appana | a65cf512 | 2016-04-06 10:38:09 +0530 | [diff] [blame] | 317 | * @desc_submitcount: Descriptor h/w submitted count |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 318 | * @residue: Residue for AXI DMA |
| 319 | * @seg_v: Statically allocated segments base |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 320 | * @cyclic_seg_v: Statically allocated segment base for cyclic transfers |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 321 | * @start_transfer: Differentiate b/w DMA IP's transfer |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 322 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 323 | struct xilinx_dma_chan { |
| 324 | struct xilinx_dma_device *xdev; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 325 | u32 ctrl_offset; |
| 326 | u32 desc_offset; |
| 327 | spinlock_t lock; |
| 328 | struct list_head pending_list; |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 329 | struct list_head active_list; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 330 | struct list_head done_list; |
| 331 | struct dma_chan common; |
| 332 | struct dma_pool *desc_pool; |
| 333 | struct device *dev; |
| 334 | int irq; |
| 335 | int id; |
| 336 | enum dma_transfer_direction direction; |
| 337 | int num_frms; |
| 338 | bool has_sg; |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 339 | bool cyclic; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 340 | bool genlock; |
| 341 | bool err; |
| 342 | struct tasklet_struct tasklet; |
| 343 | struct xilinx_vdma_config config; |
| 344 | bool flush_on_fsync; |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 345 | u32 desc_pendingcount; |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 346 | bool ext_addr; |
Kedareswara rao Appana | a65cf512 | 2016-04-06 10:38:09 +0530 | [diff] [blame] | 347 | u32 desc_submitcount; |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 348 | u32 residue; |
| 349 | struct xilinx_axidma_tx_segment *seg_v; |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 350 | struct xilinx_axidma_tx_segment *cyclic_seg_v; |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 351 | void (*start_transfer)(struct xilinx_dma_chan *chan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 352 | }; |
| 353 | |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 354 | struct xilinx_dma_config { |
| 355 | enum xdma_ip_type dmatype; |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 356 | int (*clk_init)(struct platform_device *pdev, struct clk **axi_clk, |
| 357 | struct clk **tx_clk, struct clk **txs_clk, |
| 358 | struct clk **rx_clk, struct clk **rxs_clk); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 359 | }; |
| 360 | |
| 361 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 362 | * struct xilinx_dma_device - DMA device structure |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 363 | * @regs: I/O mapped base address |
| 364 | * @dev: Device Structure |
| 365 | * @common: DMA device structure |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 366 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 367 | * @has_sg: Specifies whether Scatter-Gather is present or not |
| 368 | * @flush_on_fsync: Flush on frame sync |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 369 | * @ext_addr: Indicates 64 bit addressing is supported by dma device |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 370 | * @pdev: Platform device structure pointer |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 371 | * @dma_config: DMA config structure |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 372 | * @axi_clk: DMA Axi4-lite interace clock |
| 373 | * @tx_clk: DMA mm2s clock |
| 374 | * @txs_clk: DMA mm2s stream clock |
| 375 | * @rx_clk: DMA s2mm clock |
| 376 | * @rxs_clk: DMA s2mm stream clock |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 377 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 378 | struct xilinx_dma_device { |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 379 | void __iomem *regs; |
| 380 | struct device *dev; |
| 381 | struct dma_device common; |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 382 | struct xilinx_dma_chan *chan[XILINX_DMA_MAX_CHANS_PER_DEVICE]; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 383 | bool has_sg; |
| 384 | u32 flush_on_fsync; |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 385 | bool ext_addr; |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 386 | struct platform_device *pdev; |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 387 | const struct xilinx_dma_config *dma_config; |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 388 | struct clk *axi_clk; |
| 389 | struct clk *tx_clk; |
| 390 | struct clk *txs_clk; |
| 391 | struct clk *rx_clk; |
| 392 | struct clk *rxs_clk; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 393 | }; |
| 394 | |
| 395 | /* Macros */ |
| 396 | #define to_xilinx_chan(chan) \ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 397 | container_of(chan, struct xilinx_dma_chan, common) |
| 398 | #define to_dma_tx_descriptor(tx) \ |
| 399 | container_of(tx, struct xilinx_dma_tx_descriptor, async_tx) |
| 400 | #define xilinx_dma_poll_timeout(chan, reg, val, cond, delay_us, timeout_us) \ |
Kedareswara rao Appana | 9495f26 | 2016-02-26 19:33:54 +0530 | [diff] [blame] | 401 | readl_poll_timeout(chan->xdev->regs + chan->ctrl_offset + reg, val, \ |
| 402 | cond, delay_us, timeout_us) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 403 | |
| 404 | /* IO accessors */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 405 | static inline u32 dma_read(struct xilinx_dma_chan *chan, u32 reg) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 406 | { |
| 407 | return ioread32(chan->xdev->regs + reg); |
| 408 | } |
| 409 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 410 | static inline void dma_write(struct xilinx_dma_chan *chan, u32 reg, u32 value) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 411 | { |
| 412 | iowrite32(value, chan->xdev->regs + reg); |
| 413 | } |
| 414 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 415 | static inline void vdma_desc_write(struct xilinx_dma_chan *chan, u32 reg, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 416 | u32 value) |
| 417 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 418 | dma_write(chan, chan->desc_offset + reg, value); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 419 | } |
| 420 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 421 | static inline u32 dma_ctrl_read(struct xilinx_dma_chan *chan, u32 reg) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 422 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 423 | return dma_read(chan, chan->ctrl_offset + reg); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 424 | } |
| 425 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 426 | static inline void dma_ctrl_write(struct xilinx_dma_chan *chan, u32 reg, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 427 | u32 value) |
| 428 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 429 | dma_write(chan, chan->ctrl_offset + reg, value); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 430 | } |
| 431 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 432 | static inline void dma_ctrl_clr(struct xilinx_dma_chan *chan, u32 reg, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 433 | u32 clr) |
| 434 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 435 | dma_ctrl_write(chan, reg, dma_ctrl_read(chan, reg) & ~clr); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 436 | } |
| 437 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 438 | static inline void dma_ctrl_set(struct xilinx_dma_chan *chan, u32 reg, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 439 | u32 set) |
| 440 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 441 | dma_ctrl_write(chan, reg, dma_ctrl_read(chan, reg) | set); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 442 | } |
| 443 | |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 444 | /** |
| 445 | * vdma_desc_write_64 - 64-bit descriptor write |
| 446 | * @chan: Driver specific VDMA channel |
| 447 | * @reg: Register to write |
| 448 | * @value_lsb: lower address of the descriptor. |
| 449 | * @value_msb: upper address of the descriptor. |
| 450 | * |
| 451 | * Since vdma driver is trying to write to a register offset which is not a |
| 452 | * multiple of 64 bits(ex : 0x5c), we are writing as two separate 32 bits |
| 453 | * instead of a single 64 bit register write. |
| 454 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 455 | static inline void vdma_desc_write_64(struct xilinx_dma_chan *chan, u32 reg, |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 456 | u32 value_lsb, u32 value_msb) |
| 457 | { |
| 458 | /* Write the lsb 32 bits*/ |
| 459 | writel(value_lsb, chan->xdev->regs + chan->desc_offset + reg); |
| 460 | |
| 461 | /* Write the msb 32 bits */ |
| 462 | writel(value_msb, chan->xdev->regs + chan->desc_offset + reg + 4); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 463 | } |
| 464 | |
Kedareswara rao Appana | f0cba68 | 2016-06-07 19:21:15 +0530 | [diff] [blame^] | 465 | static inline void dma_writeq(struct xilinx_dma_chan *chan, u32 reg, u64 value) |
| 466 | { |
| 467 | lo_hi_writeq(value, chan->xdev->regs + chan->ctrl_offset + reg); |
| 468 | } |
| 469 | |
| 470 | static inline void xilinx_write(struct xilinx_dma_chan *chan, u32 reg, |
| 471 | dma_addr_t addr) |
| 472 | { |
| 473 | if (chan->ext_addr) |
| 474 | dma_writeq(chan, reg, addr); |
| 475 | else |
| 476 | dma_ctrl_write(chan, reg, addr); |
| 477 | } |
| 478 | |
| 479 | static inline void xilinx_axidma_buf(struct xilinx_dma_chan *chan, |
| 480 | struct xilinx_axidma_desc_hw *hw, |
| 481 | dma_addr_t buf_addr, size_t sg_used, |
| 482 | size_t period_len) |
| 483 | { |
| 484 | if (chan->ext_addr) { |
| 485 | hw->buf_addr = lower_32_bits(buf_addr + sg_used + period_len); |
| 486 | hw->buf_addr_msb = upper_32_bits(buf_addr + sg_used + |
| 487 | period_len); |
| 488 | } else { |
| 489 | hw->buf_addr = buf_addr + sg_used + period_len; |
| 490 | } |
| 491 | } |
| 492 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 493 | /* ----------------------------------------------------------------------------- |
| 494 | * Descriptors and segments alloc and free |
| 495 | */ |
| 496 | |
| 497 | /** |
| 498 | * xilinx_vdma_alloc_tx_segment - Allocate transaction segment |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 499 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 500 | * |
| 501 | * Return: The allocated segment on success and NULL on failure. |
| 502 | */ |
| 503 | static struct xilinx_vdma_tx_segment * |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 504 | xilinx_vdma_alloc_tx_segment(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 505 | { |
| 506 | struct xilinx_vdma_tx_segment *segment; |
| 507 | dma_addr_t phys; |
| 508 | |
Julia Lawall | 2ba4f8a | 2016-04-29 22:09:09 +0200 | [diff] [blame] | 509 | segment = dma_pool_zalloc(chan->desc_pool, GFP_ATOMIC, &phys); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 510 | if (!segment) |
| 511 | return NULL; |
| 512 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 513 | segment->phys = phys; |
| 514 | |
| 515 | return segment; |
| 516 | } |
| 517 | |
| 518 | /** |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 519 | * xilinx_cdma_alloc_tx_segment - Allocate transaction segment |
| 520 | * @chan: Driver specific DMA channel |
| 521 | * |
| 522 | * Return: The allocated segment on success and NULL on failure. |
| 523 | */ |
| 524 | static struct xilinx_cdma_tx_segment * |
| 525 | xilinx_cdma_alloc_tx_segment(struct xilinx_dma_chan *chan) |
| 526 | { |
| 527 | struct xilinx_cdma_tx_segment *segment; |
| 528 | dma_addr_t phys; |
| 529 | |
Kedareswara rao Appana | 6214786 | 2016-05-18 13:17:31 +0530 | [diff] [blame] | 530 | segment = dma_pool_zalloc(chan->desc_pool, GFP_ATOMIC, &phys); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 531 | if (!segment) |
| 532 | return NULL; |
| 533 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 534 | segment->phys = phys; |
| 535 | |
| 536 | return segment; |
| 537 | } |
| 538 | |
| 539 | /** |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 540 | * xilinx_axidma_alloc_tx_segment - Allocate transaction segment |
| 541 | * @chan: Driver specific DMA channel |
| 542 | * |
| 543 | * Return: The allocated segment on success and NULL on failure. |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 544 | */ |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 545 | static struct xilinx_axidma_tx_segment * |
| 546 | xilinx_axidma_alloc_tx_segment(struct xilinx_dma_chan *chan) |
| 547 | { |
| 548 | struct xilinx_axidma_tx_segment *segment; |
| 549 | dma_addr_t phys; |
| 550 | |
Kedareswara rao Appana | 6214786 | 2016-05-18 13:17:31 +0530 | [diff] [blame] | 551 | segment = dma_pool_zalloc(chan->desc_pool, GFP_ATOMIC, &phys); |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 552 | if (!segment) |
| 553 | return NULL; |
| 554 | |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 555 | segment->phys = phys; |
| 556 | |
| 557 | return segment; |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * xilinx_dma_free_tx_segment - Free transaction segment |
| 562 | * @chan: Driver specific DMA channel |
| 563 | * @segment: DMA transaction segment |
| 564 | */ |
| 565 | static void xilinx_dma_free_tx_segment(struct xilinx_dma_chan *chan, |
| 566 | struct xilinx_axidma_tx_segment *segment) |
| 567 | { |
| 568 | dma_pool_free(chan->desc_pool, segment, segment->phys); |
| 569 | } |
| 570 | |
| 571 | /** |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 572 | * xilinx_cdma_free_tx_segment - Free transaction segment |
| 573 | * @chan: Driver specific DMA channel |
| 574 | * @segment: DMA transaction segment |
| 575 | */ |
| 576 | static void xilinx_cdma_free_tx_segment(struct xilinx_dma_chan *chan, |
| 577 | struct xilinx_cdma_tx_segment *segment) |
| 578 | { |
| 579 | dma_pool_free(chan->desc_pool, segment, segment->phys); |
| 580 | } |
| 581 | |
| 582 | /** |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 583 | * xilinx_vdma_free_tx_segment - Free transaction segment |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 584 | * @chan: Driver specific DMA channel |
| 585 | * @segment: DMA transaction segment |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 586 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 587 | static void xilinx_vdma_free_tx_segment(struct xilinx_dma_chan *chan, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 588 | struct xilinx_vdma_tx_segment *segment) |
| 589 | { |
| 590 | dma_pool_free(chan->desc_pool, segment, segment->phys); |
| 591 | } |
| 592 | |
| 593 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 594 | * xilinx_dma_tx_descriptor - Allocate transaction descriptor |
| 595 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 596 | * |
| 597 | * Return: The allocated descriptor on success and NULL on failure. |
| 598 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 599 | static struct xilinx_dma_tx_descriptor * |
| 600 | xilinx_dma_alloc_tx_descriptor(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 601 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 602 | struct xilinx_dma_tx_descriptor *desc; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 603 | |
| 604 | desc = kzalloc(sizeof(*desc), GFP_KERNEL); |
| 605 | if (!desc) |
| 606 | return NULL; |
| 607 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 608 | INIT_LIST_HEAD(&desc->segments); |
| 609 | |
| 610 | return desc; |
| 611 | } |
| 612 | |
| 613 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 614 | * xilinx_dma_free_tx_descriptor - Free transaction descriptor |
| 615 | * @chan: Driver specific DMA channel |
| 616 | * @desc: DMA transaction descriptor |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 617 | */ |
| 618 | static void |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 619 | xilinx_dma_free_tx_descriptor(struct xilinx_dma_chan *chan, |
| 620 | struct xilinx_dma_tx_descriptor *desc) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 621 | { |
| 622 | struct xilinx_vdma_tx_segment *segment, *next; |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 623 | struct xilinx_cdma_tx_segment *cdma_segment, *cdma_next; |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 624 | struct xilinx_axidma_tx_segment *axidma_segment, *axidma_next; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 625 | |
| 626 | if (!desc) |
| 627 | return; |
| 628 | |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 629 | if (chan->xdev->dma_config->dmatype == XDMA_TYPE_VDMA) { |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 630 | list_for_each_entry_safe(segment, next, &desc->segments, node) { |
| 631 | list_del(&segment->node); |
| 632 | xilinx_vdma_free_tx_segment(chan, segment); |
| 633 | } |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 634 | } else if (chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) { |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 635 | list_for_each_entry_safe(cdma_segment, cdma_next, |
| 636 | &desc->segments, node) { |
| 637 | list_del(&cdma_segment->node); |
| 638 | xilinx_cdma_free_tx_segment(chan, cdma_segment); |
| 639 | } |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 640 | } else { |
| 641 | list_for_each_entry_safe(axidma_segment, axidma_next, |
| 642 | &desc->segments, node) { |
| 643 | list_del(&axidma_segment->node); |
| 644 | xilinx_dma_free_tx_segment(chan, axidma_segment); |
| 645 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | kfree(desc); |
| 649 | } |
| 650 | |
| 651 | /* Required functions */ |
| 652 | |
| 653 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 654 | * xilinx_dma_free_desc_list - Free descriptors list |
| 655 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 656 | * @list: List to parse and delete the descriptor |
| 657 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 658 | static void xilinx_dma_free_desc_list(struct xilinx_dma_chan *chan, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 659 | struct list_head *list) |
| 660 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 661 | struct xilinx_dma_tx_descriptor *desc, *next; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 662 | |
| 663 | list_for_each_entry_safe(desc, next, list, node) { |
| 664 | list_del(&desc->node); |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 665 | xilinx_dma_free_tx_descriptor(chan, desc); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 666 | } |
| 667 | } |
| 668 | |
| 669 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 670 | * xilinx_dma_free_descriptors - Free channel descriptors |
| 671 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 672 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 673 | static void xilinx_dma_free_descriptors(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 674 | { |
| 675 | unsigned long flags; |
| 676 | |
| 677 | spin_lock_irqsave(&chan->lock, flags); |
| 678 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 679 | xilinx_dma_free_desc_list(chan, &chan->pending_list); |
| 680 | xilinx_dma_free_desc_list(chan, &chan->done_list); |
| 681 | xilinx_dma_free_desc_list(chan, &chan->active_list); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 682 | |
| 683 | spin_unlock_irqrestore(&chan->lock, flags); |
| 684 | } |
| 685 | |
| 686 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 687 | * xilinx_dma_free_chan_resources - Free channel resources |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 688 | * @dchan: DMA channel |
| 689 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 690 | static void xilinx_dma_free_chan_resources(struct dma_chan *dchan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 691 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 692 | struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 693 | |
| 694 | dev_dbg(chan->dev, "Free all channel resources.\n"); |
| 695 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 696 | xilinx_dma_free_descriptors(chan); |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 697 | if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) { |
| 698 | xilinx_dma_free_tx_segment(chan, chan->cyclic_seg_v); |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 699 | xilinx_dma_free_tx_segment(chan, chan->seg_v); |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 700 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 701 | dma_pool_destroy(chan->desc_pool); |
| 702 | chan->desc_pool = NULL; |
| 703 | } |
| 704 | |
| 705 | /** |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 706 | * xilinx_dma_chan_handle_cyclic - Cyclic dma callback |
| 707 | * @chan: Driver specific dma channel |
| 708 | * @desc: dma transaction descriptor |
| 709 | * @flags: flags for spin lock |
| 710 | */ |
| 711 | static void xilinx_dma_chan_handle_cyclic(struct xilinx_dma_chan *chan, |
| 712 | struct xilinx_dma_tx_descriptor *desc, |
| 713 | unsigned long *flags) |
| 714 | { |
| 715 | dma_async_tx_callback callback; |
| 716 | void *callback_param; |
| 717 | |
| 718 | callback = desc->async_tx.callback; |
| 719 | callback_param = desc->async_tx.callback_param; |
| 720 | if (callback) { |
| 721 | spin_unlock_irqrestore(&chan->lock, *flags); |
| 722 | callback(callback_param); |
| 723 | spin_lock_irqsave(&chan->lock, *flags); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 728 | * xilinx_dma_chan_desc_cleanup - Clean channel descriptors |
| 729 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 730 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 731 | static void xilinx_dma_chan_desc_cleanup(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 732 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 733 | struct xilinx_dma_tx_descriptor *desc, *next; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 734 | unsigned long flags; |
| 735 | |
| 736 | spin_lock_irqsave(&chan->lock, flags); |
| 737 | |
| 738 | list_for_each_entry_safe(desc, next, &chan->done_list, node) { |
| 739 | dma_async_tx_callback callback; |
| 740 | void *callback_param; |
| 741 | |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 742 | if (desc->cyclic) { |
| 743 | xilinx_dma_chan_handle_cyclic(chan, desc, &flags); |
| 744 | break; |
| 745 | } |
| 746 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 747 | /* Remove from the list of running transactions */ |
| 748 | list_del(&desc->node); |
| 749 | |
| 750 | /* Run the link descriptor callback function */ |
| 751 | callback = desc->async_tx.callback; |
| 752 | callback_param = desc->async_tx.callback_param; |
| 753 | if (callback) { |
| 754 | spin_unlock_irqrestore(&chan->lock, flags); |
| 755 | callback(callback_param); |
| 756 | spin_lock_irqsave(&chan->lock, flags); |
| 757 | } |
| 758 | |
| 759 | /* Run any dependencies, then free the descriptor */ |
| 760 | dma_run_dependencies(&desc->async_tx); |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 761 | xilinx_dma_free_tx_descriptor(chan, desc); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | spin_unlock_irqrestore(&chan->lock, flags); |
| 765 | } |
| 766 | |
| 767 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 768 | * xilinx_dma_do_tasklet - Schedule completion tasklet |
| 769 | * @data: Pointer to the Xilinx DMA channel structure |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 770 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 771 | static void xilinx_dma_do_tasklet(unsigned long data) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 772 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 773 | struct xilinx_dma_chan *chan = (struct xilinx_dma_chan *)data; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 774 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 775 | xilinx_dma_chan_desc_cleanup(chan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 779 | * xilinx_dma_alloc_chan_resources - Allocate channel resources |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 780 | * @dchan: DMA channel |
| 781 | * |
| 782 | * Return: '0' on success and failure value on error |
| 783 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 784 | static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 785 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 786 | struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 787 | |
| 788 | /* Has this channel already been allocated? */ |
| 789 | if (chan->desc_pool) |
| 790 | return 0; |
| 791 | |
| 792 | /* |
| 793 | * We need the descriptor to be aligned to 64bytes |
| 794 | * for meeting Xilinx VDMA specification requirement. |
| 795 | */ |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 796 | if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) { |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 797 | chan->desc_pool = dma_pool_create("xilinx_dma_desc_pool", |
| 798 | chan->dev, |
| 799 | sizeof(struct xilinx_axidma_tx_segment), |
| 800 | __alignof__(struct xilinx_axidma_tx_segment), |
| 801 | 0); |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 802 | } else if (chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) { |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 803 | chan->desc_pool = dma_pool_create("xilinx_cdma_desc_pool", |
| 804 | chan->dev, |
| 805 | sizeof(struct xilinx_cdma_tx_segment), |
| 806 | __alignof__(struct xilinx_cdma_tx_segment), |
| 807 | 0); |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 808 | } else { |
| 809 | chan->desc_pool = dma_pool_create("xilinx_vdma_desc_pool", |
| 810 | chan->dev, |
| 811 | sizeof(struct xilinx_vdma_tx_segment), |
| 812 | __alignof__(struct xilinx_vdma_tx_segment), |
| 813 | 0); |
| 814 | } |
| 815 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 816 | if (!chan->desc_pool) { |
| 817 | dev_err(chan->dev, |
| 818 | "unable to allocate channel %d descriptor pool\n", |
| 819 | chan->id); |
| 820 | return -ENOMEM; |
| 821 | } |
| 822 | |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 823 | if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) { |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 824 | /* |
| 825 | * For AXI DMA case after submitting a pending_list, keep |
| 826 | * an extra segment allocated so that the "next descriptor" |
| 827 | * pointer on the tail descriptor always points to a |
| 828 | * valid descriptor, even when paused after reaching taildesc. |
| 829 | * This way, it is possible to issue additional |
| 830 | * transfers without halting and restarting the channel. |
| 831 | */ |
| 832 | chan->seg_v = xilinx_axidma_alloc_tx_segment(chan); |
| 833 | |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 834 | /* |
| 835 | * For cyclic DMA mode we need to program the tail Descriptor |
| 836 | * register with a value which is not a part of the BD chain |
| 837 | * so allocating a desc segment during channel allocation for |
| 838 | * programming tail descriptor. |
| 839 | */ |
| 840 | chan->cyclic_seg_v = xilinx_axidma_alloc_tx_segment(chan); |
| 841 | } |
| 842 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 843 | dma_cookie_init(dchan); |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 844 | |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 845 | if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) { |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 846 | /* For AXI DMA resetting once channel will reset the |
| 847 | * other channel as well so enable the interrupts here. |
| 848 | */ |
| 849 | dma_ctrl_set(chan, XILINX_DMA_REG_DMACR, |
| 850 | XILINX_DMA_DMAXR_ALL_IRQ_MASK); |
| 851 | } |
| 852 | |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 853 | if ((chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) && chan->has_sg) |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 854 | dma_ctrl_set(chan, XILINX_DMA_REG_DMACR, |
| 855 | XILINX_CDMA_CR_SGMODE); |
| 856 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 861 | * xilinx_dma_tx_status - Get DMA transaction status |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 862 | * @dchan: DMA channel |
| 863 | * @cookie: Transaction identifier |
| 864 | * @txstate: Transaction state |
| 865 | * |
| 866 | * Return: DMA transaction status |
| 867 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 868 | static enum dma_status xilinx_dma_tx_status(struct dma_chan *dchan, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 869 | dma_cookie_t cookie, |
| 870 | struct dma_tx_state *txstate) |
| 871 | { |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 872 | struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); |
| 873 | struct xilinx_dma_tx_descriptor *desc; |
| 874 | struct xilinx_axidma_tx_segment *segment; |
| 875 | struct xilinx_axidma_desc_hw *hw; |
| 876 | enum dma_status ret; |
| 877 | unsigned long flags; |
| 878 | u32 residue = 0; |
| 879 | |
| 880 | ret = dma_cookie_status(dchan, cookie, txstate); |
| 881 | if (ret == DMA_COMPLETE || !txstate) |
| 882 | return ret; |
| 883 | |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 884 | if (chan->xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) { |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 885 | spin_lock_irqsave(&chan->lock, flags); |
| 886 | |
| 887 | desc = list_last_entry(&chan->active_list, |
| 888 | struct xilinx_dma_tx_descriptor, node); |
| 889 | if (chan->has_sg) { |
| 890 | list_for_each_entry(segment, &desc->segments, node) { |
| 891 | hw = &segment->hw; |
| 892 | residue += (hw->control - hw->status) & |
| 893 | XILINX_DMA_MAX_TRANS_LEN; |
| 894 | } |
| 895 | } |
| 896 | spin_unlock_irqrestore(&chan->lock, flags); |
| 897 | |
| 898 | chan->residue = residue; |
| 899 | dma_set_residue(txstate, chan->residue); |
| 900 | } |
| 901 | |
| 902 | return ret; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 906 | * xilinx_dma_is_running - Check if DMA channel is running |
| 907 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 908 | * |
| 909 | * Return: '1' if running, '0' if not. |
| 910 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 911 | static bool xilinx_dma_is_running(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 912 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 913 | return !(dma_ctrl_read(chan, XILINX_DMA_REG_DMASR) & |
| 914 | XILINX_DMA_DMASR_HALTED) && |
| 915 | (dma_ctrl_read(chan, XILINX_DMA_REG_DMACR) & |
| 916 | XILINX_DMA_DMACR_RUNSTOP); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 920 | * xilinx_dma_is_idle - Check if DMA channel is idle |
| 921 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 922 | * |
| 923 | * Return: '1' if idle, '0' if not. |
| 924 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 925 | static bool xilinx_dma_is_idle(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 926 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 927 | return dma_ctrl_read(chan, XILINX_DMA_REG_DMASR) & |
| 928 | XILINX_DMA_DMASR_IDLE; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 932 | * xilinx_dma_halt - Halt DMA channel |
| 933 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 934 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 935 | static void xilinx_dma_halt(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 936 | { |
Kedareswara rao Appana | 6949063 | 2016-03-03 23:02:42 +0530 | [diff] [blame] | 937 | int err; |
Kedareswara rao Appana | 9495f26 | 2016-02-26 19:33:54 +0530 | [diff] [blame] | 938 | u32 val; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 939 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 940 | dma_ctrl_clr(chan, XILINX_DMA_REG_DMACR, XILINX_DMA_DMACR_RUNSTOP); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 941 | |
| 942 | /* Wait for the hardware to halt */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 943 | err = xilinx_dma_poll_timeout(chan, XILINX_DMA_REG_DMASR, val, |
| 944 | (val & XILINX_DMA_DMASR_HALTED), 0, |
| 945 | XILINX_DMA_LOOP_COUNT); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 946 | |
Kedareswara rao Appana | 9495f26 | 2016-02-26 19:33:54 +0530 | [diff] [blame] | 947 | if (err) { |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 948 | dev_err(chan->dev, "Cannot stop channel %p: %x\n", |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 949 | chan, dma_ctrl_read(chan, XILINX_DMA_REG_DMASR)); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 950 | chan->err = true; |
| 951 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 955 | * xilinx_dma_start - Start DMA channel |
| 956 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 957 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 958 | static void xilinx_dma_start(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 959 | { |
Kedareswara rao Appana | 6949063 | 2016-03-03 23:02:42 +0530 | [diff] [blame] | 960 | int err; |
Kedareswara rao Appana | 9495f26 | 2016-02-26 19:33:54 +0530 | [diff] [blame] | 961 | u32 val; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 962 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 963 | dma_ctrl_set(chan, XILINX_DMA_REG_DMACR, XILINX_DMA_DMACR_RUNSTOP); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 964 | |
| 965 | /* Wait for the hardware to start */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 966 | err = xilinx_dma_poll_timeout(chan, XILINX_DMA_REG_DMASR, val, |
| 967 | !(val & XILINX_DMA_DMASR_HALTED), 0, |
| 968 | XILINX_DMA_LOOP_COUNT); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 969 | |
Kedareswara rao Appana | 9495f26 | 2016-02-26 19:33:54 +0530 | [diff] [blame] | 970 | if (err) { |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 971 | dev_err(chan->dev, "Cannot start channel %p: %x\n", |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 972 | chan, dma_ctrl_read(chan, XILINX_DMA_REG_DMASR)); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 973 | |
| 974 | chan->err = true; |
| 975 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | /** |
| 979 | * xilinx_vdma_start_transfer - Starts VDMA transfer |
| 980 | * @chan: Driver specific channel struct pointer |
| 981 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 982 | static void xilinx_vdma_start_transfer(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 983 | { |
| 984 | struct xilinx_vdma_config *config = &chan->config; |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 985 | struct xilinx_dma_tx_descriptor *desc, *tail_desc; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 986 | u32 reg; |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 987 | struct xilinx_vdma_tx_segment *tail_segment; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 988 | |
Kedareswara rao Appana | 26c5e36 | 2016-02-26 19:33:52 +0530 | [diff] [blame] | 989 | /* This function was invoked with lock held */ |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 990 | if (chan->err) |
| 991 | return; |
| 992 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 993 | if (list_empty(&chan->pending_list)) |
Kedareswara rao Appana | 26c5e36 | 2016-02-26 19:33:52 +0530 | [diff] [blame] | 994 | return; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 995 | |
| 996 | desc = list_first_entry(&chan->pending_list, |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 997 | struct xilinx_dma_tx_descriptor, node); |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 998 | tail_desc = list_last_entry(&chan->pending_list, |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 999 | struct xilinx_dma_tx_descriptor, node); |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1000 | |
| 1001 | tail_segment = list_last_entry(&tail_desc->segments, |
| 1002 | struct xilinx_vdma_tx_segment, node); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1003 | |
| 1004 | /* If it is SG mode and hardware is busy, cannot submit */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1005 | if (chan->has_sg && xilinx_dma_is_running(chan) && |
| 1006 | !xilinx_dma_is_idle(chan)) { |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1007 | dev_dbg(chan->dev, "DMA controller still busy\n"); |
Kedareswara rao Appana | 26c5e36 | 2016-02-26 19:33:52 +0530 | [diff] [blame] | 1008 | return; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | /* |
| 1012 | * If hardware is idle, then all descriptors on the running lists are |
| 1013 | * done, start new transfers |
| 1014 | */ |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1015 | if (chan->has_sg) |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1016 | dma_ctrl_write(chan, XILINX_DMA_REG_CURDESC, |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1017 | desc->async_tx.phys); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1018 | |
| 1019 | /* Configure the hardware using info in the config structure */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1020 | reg = dma_ctrl_read(chan, XILINX_DMA_REG_DMACR); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1021 | |
| 1022 | if (config->frm_cnt_en) |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1023 | reg |= XILINX_DMA_DMACR_FRAMECNT_EN; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1024 | else |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1025 | reg &= ~XILINX_DMA_DMACR_FRAMECNT_EN; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1026 | |
Kedareswara rao Appana | e2b538a | 2016-02-26 19:33:53 +0530 | [diff] [blame] | 1027 | /* Configure channel to allow number frame buffers */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1028 | dma_ctrl_write(chan, XILINX_DMA_REG_FRMSTORE, |
Kedareswara rao Appana | e2b538a | 2016-02-26 19:33:53 +0530 | [diff] [blame] | 1029 | chan->desc_pendingcount); |
| 1030 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1031 | /* |
| 1032 | * With SG, start with circular mode, so that BDs can be fetched. |
| 1033 | * In direct register mode, if not parking, enable circular mode |
| 1034 | */ |
| 1035 | if (chan->has_sg || !config->park) |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1036 | reg |= XILINX_DMA_DMACR_CIRC_EN; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1037 | |
| 1038 | if (config->park) |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1039 | reg &= ~XILINX_DMA_DMACR_CIRC_EN; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1040 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1041 | dma_ctrl_write(chan, XILINX_DMA_REG_DMACR, reg); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1042 | |
| 1043 | if (config->park && (config->park_frm >= 0) && |
| 1044 | (config->park_frm < chan->num_frms)) { |
| 1045 | if (chan->direction == DMA_MEM_TO_DEV) |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1046 | dma_write(chan, XILINX_DMA_REG_PARK_PTR, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1047 | config->park_frm << |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1048 | XILINX_DMA_PARK_PTR_RD_REF_SHIFT); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1049 | else |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1050 | dma_write(chan, XILINX_DMA_REG_PARK_PTR, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1051 | config->park_frm << |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1052 | XILINX_DMA_PARK_PTR_WR_REF_SHIFT); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | /* Start the hardware */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1056 | xilinx_dma_start(chan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1057 | |
| 1058 | if (chan->err) |
Kedareswara rao Appana | 26c5e36 | 2016-02-26 19:33:52 +0530 | [diff] [blame] | 1059 | return; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1060 | |
| 1061 | /* Start the transfer */ |
| 1062 | if (chan->has_sg) { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1063 | dma_ctrl_write(chan, XILINX_DMA_REG_TAILDESC, |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1064 | tail_segment->phys); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1065 | } else { |
| 1066 | struct xilinx_vdma_tx_segment *segment, *last = NULL; |
| 1067 | int i = 0; |
| 1068 | |
Kedareswara rao Appana | a65cf512 | 2016-04-06 10:38:09 +0530 | [diff] [blame] | 1069 | if (chan->desc_submitcount < chan->num_frms) |
| 1070 | i = chan->desc_submitcount; |
| 1071 | |
| 1072 | list_for_each_entry(segment, &desc->segments, node) { |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 1073 | if (chan->ext_addr) |
| 1074 | vdma_desc_write_64(chan, |
| 1075 | XILINX_VDMA_REG_START_ADDRESS_64(i++), |
| 1076 | segment->hw.buf_addr, |
| 1077 | segment->hw.buf_addr_msb); |
| 1078 | else |
| 1079 | vdma_desc_write(chan, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1080 | XILINX_VDMA_REG_START_ADDRESS(i++), |
| 1081 | segment->hw.buf_addr); |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 1082 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1083 | last = segment; |
| 1084 | } |
| 1085 | |
| 1086 | if (!last) |
Kedareswara rao Appana | 26c5e36 | 2016-02-26 19:33:52 +0530 | [diff] [blame] | 1087 | return; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1088 | |
| 1089 | /* HW expects these parameters to be same for one transaction */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1090 | vdma_desc_write(chan, XILINX_DMA_REG_HSIZE, last->hw.hsize); |
| 1091 | vdma_desc_write(chan, XILINX_DMA_REG_FRMDLY_STRIDE, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1092 | last->hw.stride); |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1093 | vdma_desc_write(chan, XILINX_DMA_REG_VSIZE, last->hw.vsize); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1094 | } |
| 1095 | |
Kedareswara rao Appana | a65cf512 | 2016-04-06 10:38:09 +0530 | [diff] [blame] | 1096 | if (!chan->has_sg) { |
| 1097 | list_del(&desc->node); |
| 1098 | list_add_tail(&desc->node, &chan->active_list); |
| 1099 | chan->desc_submitcount++; |
| 1100 | chan->desc_pendingcount--; |
| 1101 | if (chan->desc_submitcount == chan->num_frms) |
| 1102 | chan->desc_submitcount = 0; |
| 1103 | } else { |
| 1104 | list_splice_tail_init(&chan->pending_list, &chan->active_list); |
| 1105 | chan->desc_pendingcount = 0; |
| 1106 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | /** |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 1110 | * xilinx_cdma_start_transfer - Starts cdma transfer |
| 1111 | * @chan: Driver specific channel struct pointer |
| 1112 | */ |
| 1113 | static void xilinx_cdma_start_transfer(struct xilinx_dma_chan *chan) |
| 1114 | { |
| 1115 | struct xilinx_dma_tx_descriptor *head_desc, *tail_desc; |
| 1116 | struct xilinx_cdma_tx_segment *tail_segment; |
| 1117 | u32 ctrl_reg = dma_read(chan, XILINX_DMA_REG_DMACR); |
| 1118 | |
| 1119 | if (chan->err) |
| 1120 | return; |
| 1121 | |
| 1122 | if (list_empty(&chan->pending_list)) |
| 1123 | return; |
| 1124 | |
| 1125 | head_desc = list_first_entry(&chan->pending_list, |
| 1126 | struct xilinx_dma_tx_descriptor, node); |
| 1127 | tail_desc = list_last_entry(&chan->pending_list, |
| 1128 | struct xilinx_dma_tx_descriptor, node); |
| 1129 | tail_segment = list_last_entry(&tail_desc->segments, |
| 1130 | struct xilinx_cdma_tx_segment, node); |
| 1131 | |
| 1132 | if (chan->desc_pendingcount <= XILINX_DMA_COALESCE_MAX) { |
| 1133 | ctrl_reg &= ~XILINX_DMA_CR_COALESCE_MAX; |
| 1134 | ctrl_reg |= chan->desc_pendingcount << |
| 1135 | XILINX_DMA_CR_COALESCE_SHIFT; |
| 1136 | dma_ctrl_write(chan, XILINX_DMA_REG_DMACR, ctrl_reg); |
| 1137 | } |
| 1138 | |
| 1139 | if (chan->has_sg) { |
| 1140 | dma_ctrl_write(chan, XILINX_DMA_REG_CURDESC, |
| 1141 | head_desc->async_tx.phys); |
| 1142 | |
| 1143 | /* Update tail ptr register which will start the transfer */ |
| 1144 | dma_ctrl_write(chan, XILINX_DMA_REG_TAILDESC, |
| 1145 | tail_segment->phys); |
| 1146 | } else { |
| 1147 | /* In simple mode */ |
| 1148 | struct xilinx_cdma_tx_segment *segment; |
| 1149 | struct xilinx_cdma_desc_hw *hw; |
| 1150 | |
| 1151 | segment = list_first_entry(&head_desc->segments, |
| 1152 | struct xilinx_cdma_tx_segment, |
| 1153 | node); |
| 1154 | |
| 1155 | hw = &segment->hw; |
| 1156 | |
| 1157 | dma_ctrl_write(chan, XILINX_CDMA_REG_SRCADDR, hw->src_addr); |
| 1158 | dma_ctrl_write(chan, XILINX_CDMA_REG_DSTADDR, hw->dest_addr); |
| 1159 | |
| 1160 | /* Start the transfer */ |
| 1161 | dma_ctrl_write(chan, XILINX_DMA_REG_BTT, |
| 1162 | hw->control & XILINX_DMA_MAX_TRANS_LEN); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | list_splice_tail_init(&chan->pending_list, &chan->active_list); |
| 1166 | chan->desc_pendingcount = 0; |
| 1167 | } |
| 1168 | |
| 1169 | /** |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 1170 | * xilinx_dma_start_transfer - Starts DMA transfer |
| 1171 | * @chan: Driver specific channel struct pointer |
| 1172 | */ |
| 1173 | static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan) |
| 1174 | { |
| 1175 | struct xilinx_dma_tx_descriptor *head_desc, *tail_desc; |
| 1176 | struct xilinx_axidma_tx_segment *tail_segment, *old_head, *new_head; |
| 1177 | u32 reg; |
| 1178 | |
| 1179 | if (chan->err) |
| 1180 | return; |
| 1181 | |
| 1182 | if (list_empty(&chan->pending_list)) |
| 1183 | return; |
| 1184 | |
| 1185 | /* If it is SG mode and hardware is busy, cannot submit */ |
| 1186 | if (chan->has_sg && xilinx_dma_is_running(chan) && |
| 1187 | !xilinx_dma_is_idle(chan)) { |
| 1188 | dev_dbg(chan->dev, "DMA controller still busy\n"); |
| 1189 | return; |
| 1190 | } |
| 1191 | |
| 1192 | head_desc = list_first_entry(&chan->pending_list, |
| 1193 | struct xilinx_dma_tx_descriptor, node); |
| 1194 | tail_desc = list_last_entry(&chan->pending_list, |
| 1195 | struct xilinx_dma_tx_descriptor, node); |
| 1196 | tail_segment = list_last_entry(&tail_desc->segments, |
| 1197 | struct xilinx_axidma_tx_segment, node); |
| 1198 | |
| 1199 | old_head = list_first_entry(&head_desc->segments, |
| 1200 | struct xilinx_axidma_tx_segment, node); |
| 1201 | new_head = chan->seg_v; |
| 1202 | /* Copy Buffer Descriptor fields. */ |
| 1203 | new_head->hw = old_head->hw; |
| 1204 | |
| 1205 | /* Swap and save new reserve */ |
| 1206 | list_replace_init(&old_head->node, &new_head->node); |
| 1207 | chan->seg_v = old_head; |
| 1208 | |
| 1209 | tail_segment->hw.next_desc = chan->seg_v->phys; |
| 1210 | head_desc->async_tx.phys = new_head->phys; |
| 1211 | |
| 1212 | reg = dma_ctrl_read(chan, XILINX_DMA_REG_DMACR); |
| 1213 | |
| 1214 | if (chan->desc_pendingcount <= XILINX_DMA_COALESCE_MAX) { |
| 1215 | reg &= ~XILINX_DMA_CR_COALESCE_MAX; |
| 1216 | reg |= chan->desc_pendingcount << |
| 1217 | XILINX_DMA_CR_COALESCE_SHIFT; |
| 1218 | dma_ctrl_write(chan, XILINX_DMA_REG_DMACR, reg); |
| 1219 | } |
| 1220 | |
| 1221 | if (chan->has_sg) |
Kedareswara rao Appana | f0cba68 | 2016-06-07 19:21:15 +0530 | [diff] [blame^] | 1222 | xilinx_write(chan, XILINX_DMA_REG_CURDESC, |
| 1223 | head_desc->async_tx.phys); |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 1224 | |
| 1225 | xilinx_dma_start(chan); |
| 1226 | |
| 1227 | if (chan->err) |
| 1228 | return; |
| 1229 | |
| 1230 | /* Start the transfer */ |
| 1231 | if (chan->has_sg) { |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 1232 | if (chan->cyclic) |
Kedareswara rao Appana | f0cba68 | 2016-06-07 19:21:15 +0530 | [diff] [blame^] | 1233 | xilinx_write(chan, XILINX_DMA_REG_TAILDESC, |
| 1234 | chan->cyclic_seg_v->phys); |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 1235 | else |
Kedareswara rao Appana | f0cba68 | 2016-06-07 19:21:15 +0530 | [diff] [blame^] | 1236 | xilinx_write(chan, XILINX_DMA_REG_TAILDESC, |
| 1237 | tail_segment->phys); |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 1238 | } else { |
| 1239 | struct xilinx_axidma_tx_segment *segment; |
| 1240 | struct xilinx_axidma_desc_hw *hw; |
| 1241 | |
| 1242 | segment = list_first_entry(&head_desc->segments, |
| 1243 | struct xilinx_axidma_tx_segment, |
| 1244 | node); |
| 1245 | hw = &segment->hw; |
| 1246 | |
Kedareswara rao Appana | f0cba68 | 2016-06-07 19:21:15 +0530 | [diff] [blame^] | 1247 | xilinx_write(chan, XILINX_DMA_REG_SRCDSTADDR, hw->buf_addr); |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 1248 | |
| 1249 | /* Start the transfer */ |
| 1250 | dma_ctrl_write(chan, XILINX_DMA_REG_BTT, |
| 1251 | hw->control & XILINX_DMA_MAX_TRANS_LEN); |
| 1252 | } |
| 1253 | |
| 1254 | list_splice_tail_init(&chan->pending_list, &chan->active_list); |
| 1255 | chan->desc_pendingcount = 0; |
| 1256 | } |
| 1257 | |
| 1258 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1259 | * xilinx_dma_issue_pending - Issue pending transactions |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1260 | * @dchan: DMA channel |
| 1261 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1262 | static void xilinx_dma_issue_pending(struct dma_chan *dchan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1263 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1264 | struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); |
Kedareswara rao Appana | 26c5e36 | 2016-02-26 19:33:52 +0530 | [diff] [blame] | 1265 | unsigned long flags; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1266 | |
Kedareswara rao Appana | 26c5e36 | 2016-02-26 19:33:52 +0530 | [diff] [blame] | 1267 | spin_lock_irqsave(&chan->lock, flags); |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 1268 | chan->start_transfer(chan); |
Kedareswara rao Appana | 26c5e36 | 2016-02-26 19:33:52 +0530 | [diff] [blame] | 1269 | spin_unlock_irqrestore(&chan->lock, flags); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1273 | * xilinx_dma_complete_descriptor - Mark the active descriptor as complete |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1274 | * @chan : xilinx DMA channel |
| 1275 | * |
| 1276 | * CONTEXT: hardirq |
| 1277 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1278 | static void xilinx_dma_complete_descriptor(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1279 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1280 | struct xilinx_dma_tx_descriptor *desc, *next; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1281 | |
Kedareswara rao Appana | 26c5e36 | 2016-02-26 19:33:52 +0530 | [diff] [blame] | 1282 | /* This function was invoked with lock held */ |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1283 | if (list_empty(&chan->active_list)) |
Kedareswara rao Appana | 26c5e36 | 2016-02-26 19:33:52 +0530 | [diff] [blame] | 1284 | return; |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1285 | |
| 1286 | list_for_each_entry_safe(desc, next, &chan->active_list, node) { |
| 1287 | list_del(&desc->node); |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 1288 | if (!desc->cyclic) |
| 1289 | dma_cookie_complete(&desc->async_tx); |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1290 | list_add_tail(&desc->node, &chan->done_list); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1291 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1295 | * xilinx_dma_reset - Reset DMA channel |
| 1296 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1297 | * |
| 1298 | * Return: '0' on success and failure value on error |
| 1299 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1300 | static int xilinx_dma_reset(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1301 | { |
Kedareswara rao Appana | 6949063 | 2016-03-03 23:02:42 +0530 | [diff] [blame] | 1302 | int err; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1303 | u32 tmp; |
| 1304 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1305 | dma_ctrl_set(chan, XILINX_DMA_REG_DMACR, XILINX_DMA_DMACR_RESET); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1306 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1307 | /* Wait for the hardware to finish reset */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1308 | err = xilinx_dma_poll_timeout(chan, XILINX_DMA_REG_DMACR, tmp, |
| 1309 | !(tmp & XILINX_DMA_DMACR_RESET), 0, |
| 1310 | XILINX_DMA_LOOP_COUNT); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1311 | |
Kedareswara rao Appana | 9495f26 | 2016-02-26 19:33:54 +0530 | [diff] [blame] | 1312 | if (err) { |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1313 | dev_err(chan->dev, "reset timeout, cr %x, sr %x\n", |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1314 | dma_ctrl_read(chan, XILINX_DMA_REG_DMACR), |
| 1315 | dma_ctrl_read(chan, XILINX_DMA_REG_DMASR)); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1316 | return -ETIMEDOUT; |
| 1317 | } |
| 1318 | |
| 1319 | chan->err = false; |
| 1320 | |
Kedareswara rao Appana | 9495f26 | 2016-02-26 19:33:54 +0530 | [diff] [blame] | 1321 | return err; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1322 | } |
| 1323 | |
| 1324 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1325 | * xilinx_dma_chan_reset - Reset DMA channel and enable interrupts |
| 1326 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1327 | * |
| 1328 | * Return: '0' on success and failure value on error |
| 1329 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1330 | static int xilinx_dma_chan_reset(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1331 | { |
| 1332 | int err; |
| 1333 | |
| 1334 | /* Reset VDMA */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1335 | err = xilinx_dma_reset(chan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1336 | if (err) |
| 1337 | return err; |
| 1338 | |
| 1339 | /* Enable interrupts */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1340 | dma_ctrl_set(chan, XILINX_DMA_REG_DMACR, |
| 1341 | XILINX_DMA_DMAXR_ALL_IRQ_MASK); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1342 | |
| 1343 | return 0; |
| 1344 | } |
| 1345 | |
| 1346 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1347 | * xilinx_dma_irq_handler - DMA Interrupt handler |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1348 | * @irq: IRQ number |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1349 | * @data: Pointer to the Xilinx DMA channel structure |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1350 | * |
| 1351 | * Return: IRQ_HANDLED/IRQ_NONE |
| 1352 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1353 | static irqreturn_t xilinx_dma_irq_handler(int irq, void *data) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1354 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1355 | struct xilinx_dma_chan *chan = data; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1356 | u32 status; |
| 1357 | |
| 1358 | /* Read the status and ack the interrupts. */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1359 | status = dma_ctrl_read(chan, XILINX_DMA_REG_DMASR); |
| 1360 | if (!(status & XILINX_DMA_DMAXR_ALL_IRQ_MASK)) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1361 | return IRQ_NONE; |
| 1362 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1363 | dma_ctrl_write(chan, XILINX_DMA_REG_DMASR, |
| 1364 | status & XILINX_DMA_DMAXR_ALL_IRQ_MASK); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1365 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1366 | if (status & XILINX_DMA_DMASR_ERR_IRQ) { |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1367 | /* |
| 1368 | * An error occurred. If C_FLUSH_ON_FSYNC is enabled and the |
| 1369 | * error is recoverable, ignore it. Otherwise flag the error. |
| 1370 | * |
| 1371 | * Only recoverable errors can be cleared in the DMASR register, |
| 1372 | * make sure not to write to other error bits to 1. |
| 1373 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1374 | u32 errors = status & XILINX_DMA_DMASR_ALL_ERR_MASK; |
Kedareswara rao Appana | 48a59ed | 2016-04-06 10:44:55 +0530 | [diff] [blame] | 1375 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1376 | dma_ctrl_write(chan, XILINX_DMA_REG_DMASR, |
| 1377 | errors & XILINX_DMA_DMASR_ERR_RECOVER_MASK); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1378 | |
| 1379 | if (!chan->flush_on_fsync || |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1380 | (errors & ~XILINX_DMA_DMASR_ERR_RECOVER_MASK)) { |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1381 | dev_err(chan->dev, |
| 1382 | "Channel %p has errors %x, cdr %x tdr %x\n", |
| 1383 | chan, errors, |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1384 | dma_ctrl_read(chan, XILINX_DMA_REG_CURDESC), |
| 1385 | dma_ctrl_read(chan, XILINX_DMA_REG_TAILDESC)); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1386 | chan->err = true; |
| 1387 | } |
| 1388 | } |
| 1389 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1390 | if (status & XILINX_DMA_DMASR_DLY_CNT_IRQ) { |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1391 | /* |
| 1392 | * Device takes too long to do the transfer when user requires |
| 1393 | * responsiveness. |
| 1394 | */ |
| 1395 | dev_dbg(chan->dev, "Inter-packet latency too long\n"); |
| 1396 | } |
| 1397 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1398 | if (status & XILINX_DMA_DMASR_FRM_CNT_IRQ) { |
Kedareswara rao Appana | 26c5e36 | 2016-02-26 19:33:52 +0530 | [diff] [blame] | 1399 | spin_lock(&chan->lock); |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1400 | xilinx_dma_complete_descriptor(chan); |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 1401 | chan->start_transfer(chan); |
Kedareswara rao Appana | 26c5e36 | 2016-02-26 19:33:52 +0530 | [diff] [blame] | 1402 | spin_unlock(&chan->lock); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | tasklet_schedule(&chan->tasklet); |
| 1406 | return IRQ_HANDLED; |
| 1407 | } |
| 1408 | |
| 1409 | /** |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1410 | * append_desc_queue - Queuing descriptor |
| 1411 | * @chan: Driver specific dma channel |
| 1412 | * @desc: dma transaction descriptor |
| 1413 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1414 | static void append_desc_queue(struct xilinx_dma_chan *chan, |
| 1415 | struct xilinx_dma_tx_descriptor *desc) |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1416 | { |
| 1417 | struct xilinx_vdma_tx_segment *tail_segment; |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1418 | struct xilinx_dma_tx_descriptor *tail_desc; |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 1419 | struct xilinx_axidma_tx_segment *axidma_tail_segment; |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 1420 | struct xilinx_cdma_tx_segment *cdma_tail_segment; |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1421 | |
| 1422 | if (list_empty(&chan->pending_list)) |
| 1423 | goto append; |
| 1424 | |
| 1425 | /* |
| 1426 | * Add the hardware descriptor to the chain of hardware descriptors |
| 1427 | * that already exists in memory. |
| 1428 | */ |
| 1429 | tail_desc = list_last_entry(&chan->pending_list, |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1430 | struct xilinx_dma_tx_descriptor, node); |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 1431 | if (chan->xdev->dma_config->dmatype == XDMA_TYPE_VDMA) { |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 1432 | tail_segment = list_last_entry(&tail_desc->segments, |
| 1433 | struct xilinx_vdma_tx_segment, |
| 1434 | node); |
| 1435 | tail_segment->hw.next_desc = (u32)desc->async_tx.phys; |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 1436 | } else if (chan->xdev->dma_config->dmatype == XDMA_TYPE_CDMA) { |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 1437 | cdma_tail_segment = list_last_entry(&tail_desc->segments, |
| 1438 | struct xilinx_cdma_tx_segment, |
| 1439 | node); |
| 1440 | cdma_tail_segment->hw.next_desc = (u32)desc->async_tx.phys; |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 1441 | } else { |
| 1442 | axidma_tail_segment = list_last_entry(&tail_desc->segments, |
| 1443 | struct xilinx_axidma_tx_segment, |
| 1444 | node); |
| 1445 | axidma_tail_segment->hw.next_desc = (u32)desc->async_tx.phys; |
| 1446 | } |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1447 | |
| 1448 | /* |
| 1449 | * Add the software descriptor and all children to the list |
| 1450 | * of pending transactions |
| 1451 | */ |
| 1452 | append: |
| 1453 | list_add_tail(&desc->node, &chan->pending_list); |
| 1454 | chan->desc_pendingcount++; |
| 1455 | |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 1456 | if (chan->has_sg && (chan->xdev->dma_config->dmatype == XDMA_TYPE_VDMA) |
| 1457 | && unlikely(chan->desc_pendingcount > chan->num_frms)) { |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1458 | dev_dbg(chan->dev, "desc pendingcount is too high\n"); |
| 1459 | chan->desc_pendingcount = chan->num_frms; |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1464 | * xilinx_dma_tx_submit - Submit DMA transaction |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1465 | * @tx: Async transaction descriptor |
| 1466 | * |
| 1467 | * Return: cookie value on success and failure value on error |
| 1468 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1469 | static dma_cookie_t xilinx_dma_tx_submit(struct dma_async_tx_descriptor *tx) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1470 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1471 | struct xilinx_dma_tx_descriptor *desc = to_dma_tx_descriptor(tx); |
| 1472 | struct xilinx_dma_chan *chan = to_xilinx_chan(tx->chan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1473 | dma_cookie_t cookie; |
| 1474 | unsigned long flags; |
| 1475 | int err; |
| 1476 | |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 1477 | if (chan->cyclic) { |
| 1478 | xilinx_dma_free_tx_descriptor(chan, desc); |
| 1479 | return -EBUSY; |
| 1480 | } |
| 1481 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1482 | if (chan->err) { |
| 1483 | /* |
| 1484 | * If reset fails, need to hard reset the system. |
| 1485 | * Channel is no longer functional |
| 1486 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1487 | err = xilinx_dma_chan_reset(chan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1488 | if (err < 0) |
| 1489 | return err; |
| 1490 | } |
| 1491 | |
| 1492 | spin_lock_irqsave(&chan->lock, flags); |
| 1493 | |
| 1494 | cookie = dma_cookie_assign(tx); |
| 1495 | |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1496 | /* Put this transaction onto the tail of the pending queue */ |
| 1497 | append_desc_queue(chan, desc); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1498 | |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 1499 | if (desc->cyclic) |
| 1500 | chan->cyclic = true; |
| 1501 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1502 | spin_unlock_irqrestore(&chan->lock, flags); |
| 1503 | |
| 1504 | return cookie; |
| 1505 | } |
| 1506 | |
| 1507 | /** |
| 1508 | * xilinx_vdma_dma_prep_interleaved - prepare a descriptor for a |
| 1509 | * DMA_SLAVE transaction |
| 1510 | * @dchan: DMA channel |
| 1511 | * @xt: Interleaved template pointer |
| 1512 | * @flags: transfer ack flags |
| 1513 | * |
| 1514 | * Return: Async transaction descriptor on success and NULL on failure |
| 1515 | */ |
| 1516 | static struct dma_async_tx_descriptor * |
| 1517 | xilinx_vdma_dma_prep_interleaved(struct dma_chan *dchan, |
| 1518 | struct dma_interleaved_template *xt, |
| 1519 | unsigned long flags) |
| 1520 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1521 | struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); |
| 1522 | struct xilinx_dma_tx_descriptor *desc; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1523 | struct xilinx_vdma_tx_segment *segment, *prev = NULL; |
| 1524 | struct xilinx_vdma_desc_hw *hw; |
| 1525 | |
| 1526 | if (!is_slave_direction(xt->dir)) |
| 1527 | return NULL; |
| 1528 | |
| 1529 | if (!xt->numf || !xt->sgl[0].size) |
| 1530 | return NULL; |
| 1531 | |
Srikanth Thokala | a5e48e2 | 2014-11-05 20:37:01 +0200 | [diff] [blame] | 1532 | if (xt->frame_size != 1) |
| 1533 | return NULL; |
| 1534 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1535 | /* Allocate a transaction descriptor. */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1536 | desc = xilinx_dma_alloc_tx_descriptor(chan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1537 | if (!desc) |
| 1538 | return NULL; |
| 1539 | |
| 1540 | dma_async_tx_descriptor_init(&desc->async_tx, &chan->common); |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1541 | desc->async_tx.tx_submit = xilinx_dma_tx_submit; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1542 | async_tx_ack(&desc->async_tx); |
| 1543 | |
| 1544 | /* Allocate the link descriptor from DMA pool */ |
| 1545 | segment = xilinx_vdma_alloc_tx_segment(chan); |
| 1546 | if (!segment) |
| 1547 | goto error; |
| 1548 | |
| 1549 | /* Fill in the hardware descriptor */ |
| 1550 | hw = &segment->hw; |
| 1551 | hw->vsize = xt->numf; |
| 1552 | hw->hsize = xt->sgl[0].size; |
Srikanth Thokala | 6d80f45 | 2014-11-05 20:37:02 +0200 | [diff] [blame] | 1553 | hw->stride = (xt->sgl[0].icg + xt->sgl[0].size) << |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1554 | XILINX_DMA_FRMDLY_STRIDE_STRIDE_SHIFT; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1555 | hw->stride |= chan->config.frm_dly << |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1556 | XILINX_DMA_FRMDLY_STRIDE_FRMDLY_SHIFT; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1557 | |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 1558 | if (xt->dir != DMA_MEM_TO_DEV) { |
| 1559 | if (chan->ext_addr) { |
| 1560 | hw->buf_addr = lower_32_bits(xt->dst_start); |
| 1561 | hw->buf_addr_msb = upper_32_bits(xt->dst_start); |
| 1562 | } else { |
| 1563 | hw->buf_addr = xt->dst_start; |
| 1564 | } |
| 1565 | } else { |
| 1566 | if (chan->ext_addr) { |
| 1567 | hw->buf_addr = lower_32_bits(xt->src_start); |
| 1568 | hw->buf_addr_msb = upper_32_bits(xt->src_start); |
| 1569 | } else { |
| 1570 | hw->buf_addr = xt->src_start; |
| 1571 | } |
| 1572 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1573 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1574 | /* Insert the segment into the descriptor segments list. */ |
| 1575 | list_add_tail(&segment->node, &desc->segments); |
| 1576 | |
| 1577 | prev = segment; |
| 1578 | |
| 1579 | /* Link the last hardware descriptor with the first. */ |
| 1580 | segment = list_first_entry(&desc->segments, |
| 1581 | struct xilinx_vdma_tx_segment, node); |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 1582 | desc->async_tx.phys = segment->phys; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1583 | |
| 1584 | return &desc->async_tx; |
| 1585 | |
| 1586 | error: |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1587 | xilinx_dma_free_tx_descriptor(chan, desc); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1588 | return NULL; |
| 1589 | } |
| 1590 | |
| 1591 | /** |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 1592 | * xilinx_cdma_prep_memcpy - prepare descriptors for a memcpy transaction |
| 1593 | * @dchan: DMA channel |
| 1594 | * @dma_dst: destination address |
| 1595 | * @dma_src: source address |
| 1596 | * @len: transfer length |
| 1597 | * @flags: transfer ack flags |
| 1598 | * |
| 1599 | * Return: Async transaction descriptor on success and NULL on failure |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1600 | */ |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 1601 | static struct dma_async_tx_descriptor * |
| 1602 | xilinx_cdma_prep_memcpy(struct dma_chan *dchan, dma_addr_t dma_dst, |
| 1603 | dma_addr_t dma_src, size_t len, unsigned long flags) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1604 | { |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 1605 | struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); |
| 1606 | struct xilinx_dma_tx_descriptor *desc; |
| 1607 | struct xilinx_cdma_tx_segment *segment, *prev; |
| 1608 | struct xilinx_cdma_desc_hw *hw; |
| 1609 | |
| 1610 | if (!len || len > XILINX_DMA_MAX_TRANS_LEN) |
| 1611 | return NULL; |
| 1612 | |
| 1613 | desc = xilinx_dma_alloc_tx_descriptor(chan); |
| 1614 | if (!desc) |
| 1615 | return NULL; |
| 1616 | |
| 1617 | dma_async_tx_descriptor_init(&desc->async_tx, &chan->common); |
| 1618 | desc->async_tx.tx_submit = xilinx_dma_tx_submit; |
| 1619 | |
| 1620 | /* Allocate the link descriptor from DMA pool */ |
| 1621 | segment = xilinx_cdma_alloc_tx_segment(chan); |
| 1622 | if (!segment) |
| 1623 | goto error; |
| 1624 | |
| 1625 | hw = &segment->hw; |
| 1626 | hw->control = len; |
| 1627 | hw->src_addr = dma_src; |
| 1628 | hw->dest_addr = dma_dst; |
| 1629 | |
| 1630 | /* Fill the previous next descriptor with current */ |
| 1631 | prev = list_last_entry(&desc->segments, |
| 1632 | struct xilinx_cdma_tx_segment, node); |
| 1633 | prev->hw.next_desc = segment->phys; |
| 1634 | |
| 1635 | /* Insert the segment into the descriptor segments list. */ |
| 1636 | list_add_tail(&segment->node, &desc->segments); |
| 1637 | |
| 1638 | prev = segment; |
| 1639 | |
| 1640 | /* Link the last hardware descriptor with the first. */ |
| 1641 | segment = list_first_entry(&desc->segments, |
| 1642 | struct xilinx_cdma_tx_segment, node); |
| 1643 | desc->async_tx.phys = segment->phys; |
| 1644 | prev->hw.next_desc = segment->phys; |
| 1645 | |
| 1646 | return &desc->async_tx; |
| 1647 | |
| 1648 | error: |
| 1649 | xilinx_dma_free_tx_descriptor(chan, desc); |
| 1650 | return NULL; |
| 1651 | } |
| 1652 | |
| 1653 | /** |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 1654 | * xilinx_dma_prep_slave_sg - prepare descriptors for a DMA_SLAVE transaction |
| 1655 | * @dchan: DMA channel |
| 1656 | * @sgl: scatterlist to transfer to/from |
| 1657 | * @sg_len: number of entries in @scatterlist |
| 1658 | * @direction: DMA direction |
| 1659 | * @flags: transfer ack flags |
| 1660 | * @context: APP words of the descriptor |
| 1661 | * |
| 1662 | * Return: Async transaction descriptor on success and NULL on failure |
| 1663 | */ |
| 1664 | static struct dma_async_tx_descriptor *xilinx_dma_prep_slave_sg( |
| 1665 | struct dma_chan *dchan, struct scatterlist *sgl, unsigned int sg_len, |
| 1666 | enum dma_transfer_direction direction, unsigned long flags, |
| 1667 | void *context) |
| 1668 | { |
| 1669 | struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); |
| 1670 | struct xilinx_dma_tx_descriptor *desc; |
| 1671 | struct xilinx_axidma_tx_segment *segment = NULL, *prev = NULL; |
| 1672 | u32 *app_w = (u32 *)context; |
| 1673 | struct scatterlist *sg; |
| 1674 | size_t copy; |
| 1675 | size_t sg_used; |
| 1676 | unsigned int i; |
| 1677 | |
| 1678 | if (!is_slave_direction(direction)) |
| 1679 | return NULL; |
| 1680 | |
| 1681 | /* Allocate a transaction descriptor. */ |
| 1682 | desc = xilinx_dma_alloc_tx_descriptor(chan); |
| 1683 | if (!desc) |
| 1684 | return NULL; |
| 1685 | |
| 1686 | dma_async_tx_descriptor_init(&desc->async_tx, &chan->common); |
| 1687 | desc->async_tx.tx_submit = xilinx_dma_tx_submit; |
| 1688 | |
| 1689 | /* Build transactions using information in the scatter gather list */ |
| 1690 | for_each_sg(sgl, sg, sg_len, i) { |
| 1691 | sg_used = 0; |
| 1692 | |
| 1693 | /* Loop until the entire scatterlist entry is used */ |
| 1694 | while (sg_used < sg_dma_len(sg)) { |
| 1695 | struct xilinx_axidma_desc_hw *hw; |
| 1696 | |
| 1697 | /* Get a free segment */ |
| 1698 | segment = xilinx_axidma_alloc_tx_segment(chan); |
| 1699 | if (!segment) |
| 1700 | goto error; |
| 1701 | |
| 1702 | /* |
| 1703 | * Calculate the maximum number of bytes to transfer, |
| 1704 | * making sure it is less than the hw limit |
| 1705 | */ |
| 1706 | copy = min_t(size_t, sg_dma_len(sg) - sg_used, |
| 1707 | XILINX_DMA_MAX_TRANS_LEN); |
| 1708 | hw = &segment->hw; |
| 1709 | |
| 1710 | /* Fill in the descriptor */ |
Kedareswara rao Appana | f0cba68 | 2016-06-07 19:21:15 +0530 | [diff] [blame^] | 1711 | xilinx_axidma_buf(chan, hw, sg_dma_address(sg), |
| 1712 | sg_used, 0); |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 1713 | |
| 1714 | hw->control = copy; |
| 1715 | |
| 1716 | if (chan->direction == DMA_MEM_TO_DEV) { |
| 1717 | if (app_w) |
| 1718 | memcpy(hw->app, app_w, sizeof(u32) * |
| 1719 | XILINX_DMA_NUM_APP_WORDS); |
| 1720 | } |
| 1721 | |
| 1722 | if (prev) |
| 1723 | prev->hw.next_desc = segment->phys; |
| 1724 | |
| 1725 | prev = segment; |
| 1726 | sg_used += copy; |
| 1727 | |
| 1728 | /* |
| 1729 | * Insert the segment into the descriptor segments |
| 1730 | * list. |
| 1731 | */ |
| 1732 | list_add_tail(&segment->node, &desc->segments); |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | segment = list_first_entry(&desc->segments, |
| 1737 | struct xilinx_axidma_tx_segment, node); |
| 1738 | desc->async_tx.phys = segment->phys; |
| 1739 | prev->hw.next_desc = segment->phys; |
| 1740 | |
| 1741 | /* For the last DMA_MEM_TO_DEV transfer, set EOP */ |
| 1742 | if (chan->direction == DMA_MEM_TO_DEV) { |
| 1743 | segment->hw.control |= XILINX_DMA_BD_SOP; |
| 1744 | segment = list_last_entry(&desc->segments, |
| 1745 | struct xilinx_axidma_tx_segment, |
| 1746 | node); |
| 1747 | segment->hw.control |= XILINX_DMA_BD_EOP; |
| 1748 | } |
| 1749 | |
| 1750 | return &desc->async_tx; |
| 1751 | |
| 1752 | error: |
| 1753 | xilinx_dma_free_tx_descriptor(chan, desc); |
| 1754 | return NULL; |
| 1755 | } |
| 1756 | |
| 1757 | /** |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 1758 | * xilinx_dma_prep_dma_cyclic - prepare descriptors for a DMA_SLAVE transaction |
| 1759 | * @chan: DMA channel |
| 1760 | * @sgl: scatterlist to transfer to/from |
| 1761 | * @sg_len: number of entries in @scatterlist |
| 1762 | * @direction: DMA direction |
| 1763 | * @flags: transfer ack flags |
| 1764 | */ |
| 1765 | static struct dma_async_tx_descriptor *xilinx_dma_prep_dma_cyclic( |
| 1766 | struct dma_chan *dchan, dma_addr_t buf_addr, size_t buf_len, |
| 1767 | size_t period_len, enum dma_transfer_direction direction, |
| 1768 | unsigned long flags) |
| 1769 | { |
| 1770 | struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); |
| 1771 | struct xilinx_dma_tx_descriptor *desc; |
| 1772 | struct xilinx_axidma_tx_segment *segment, *head_segment, *prev = NULL; |
| 1773 | size_t copy, sg_used; |
| 1774 | unsigned int num_periods; |
| 1775 | int i; |
| 1776 | u32 reg; |
| 1777 | |
Arnd Bergmann | f67c3bd | 2016-06-13 17:07:33 +0200 | [diff] [blame] | 1778 | if (!period_len) |
| 1779 | return NULL; |
| 1780 | |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 1781 | num_periods = buf_len / period_len; |
| 1782 | |
Arnd Bergmann | f67c3bd | 2016-06-13 17:07:33 +0200 | [diff] [blame] | 1783 | if (!num_periods) |
| 1784 | return NULL; |
| 1785 | |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 1786 | if (!is_slave_direction(direction)) |
| 1787 | return NULL; |
| 1788 | |
| 1789 | /* Allocate a transaction descriptor. */ |
| 1790 | desc = xilinx_dma_alloc_tx_descriptor(chan); |
| 1791 | if (!desc) |
| 1792 | return NULL; |
| 1793 | |
| 1794 | chan->direction = direction; |
| 1795 | dma_async_tx_descriptor_init(&desc->async_tx, &chan->common); |
| 1796 | desc->async_tx.tx_submit = xilinx_dma_tx_submit; |
| 1797 | |
| 1798 | for (i = 0; i < num_periods; ++i) { |
| 1799 | sg_used = 0; |
| 1800 | |
| 1801 | while (sg_used < period_len) { |
| 1802 | struct xilinx_axidma_desc_hw *hw; |
| 1803 | |
| 1804 | /* Get a free segment */ |
| 1805 | segment = xilinx_axidma_alloc_tx_segment(chan); |
| 1806 | if (!segment) |
| 1807 | goto error; |
| 1808 | |
| 1809 | /* |
| 1810 | * Calculate the maximum number of bytes to transfer, |
| 1811 | * making sure it is less than the hw limit |
| 1812 | */ |
| 1813 | copy = min_t(size_t, period_len - sg_used, |
| 1814 | XILINX_DMA_MAX_TRANS_LEN); |
| 1815 | hw = &segment->hw; |
Kedareswara rao Appana | f0cba68 | 2016-06-07 19:21:15 +0530 | [diff] [blame^] | 1816 | xilinx_axidma_buf(chan, hw, buf_addr, sg_used, |
| 1817 | period_len * i); |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 1818 | hw->control = copy; |
| 1819 | |
| 1820 | if (prev) |
| 1821 | prev->hw.next_desc = segment->phys; |
| 1822 | |
| 1823 | prev = segment; |
| 1824 | sg_used += copy; |
| 1825 | |
| 1826 | /* |
| 1827 | * Insert the segment into the descriptor segments |
| 1828 | * list. |
| 1829 | */ |
| 1830 | list_add_tail(&segment->node, &desc->segments); |
| 1831 | } |
| 1832 | } |
| 1833 | |
| 1834 | head_segment = list_first_entry(&desc->segments, |
| 1835 | struct xilinx_axidma_tx_segment, node); |
| 1836 | desc->async_tx.phys = head_segment->phys; |
| 1837 | |
| 1838 | desc->cyclic = true; |
| 1839 | reg = dma_ctrl_read(chan, XILINX_DMA_REG_DMACR); |
| 1840 | reg |= XILINX_DMA_CR_CYCLIC_BD_EN_MASK; |
| 1841 | dma_ctrl_write(chan, XILINX_DMA_REG_DMACR, reg); |
| 1842 | |
| 1843 | /* For the last DMA_MEM_TO_DEV transfer, set EOP */ |
| 1844 | if (direction == DMA_MEM_TO_DEV) { |
Kedareswara rao Appana | e167a0b | 2016-06-09 11:32:12 +0530 | [diff] [blame] | 1845 | head_segment->hw.control |= XILINX_DMA_BD_SOP; |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 1846 | segment = list_last_entry(&desc->segments, |
| 1847 | struct xilinx_axidma_tx_segment, |
| 1848 | node); |
| 1849 | segment->hw.control |= XILINX_DMA_BD_EOP; |
| 1850 | segment->hw.next_desc = (u32) head_segment->phys; |
| 1851 | } |
| 1852 | |
| 1853 | return &desc->async_tx; |
| 1854 | |
| 1855 | error: |
| 1856 | xilinx_dma_free_tx_descriptor(chan, desc); |
| 1857 | return NULL; |
| 1858 | } |
| 1859 | |
| 1860 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1861 | * xilinx_dma_terminate_all - Halt the channel and free descriptors |
| 1862 | * @chan: Driver specific DMA Channel pointer |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1863 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1864 | static int xilinx_dma_terminate_all(struct dma_chan *dchan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1865 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1866 | struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 1867 | u32 reg; |
| 1868 | |
| 1869 | if (chan->cyclic) |
| 1870 | xilinx_dma_chan_reset(chan); |
Maxime Ripard | ba71404 | 2014-11-17 14:42:38 +0100 | [diff] [blame] | 1871 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1872 | /* Halt the DMA engine */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1873 | xilinx_dma_halt(chan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1874 | |
| 1875 | /* Remove and free all of the descriptors in the lists */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1876 | xilinx_dma_free_descriptors(chan); |
Maxime Ripard | ba71404 | 2014-11-17 14:42:38 +0100 | [diff] [blame] | 1877 | |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 1878 | if (chan->cyclic) { |
| 1879 | reg = dma_ctrl_read(chan, XILINX_DMA_REG_DMACR); |
| 1880 | reg &= ~XILINX_DMA_CR_CYCLIC_BD_EN_MASK; |
| 1881 | dma_ctrl_write(chan, XILINX_DMA_REG_DMACR, reg); |
| 1882 | chan->cyclic = false; |
| 1883 | } |
| 1884 | |
Maxime Ripard | ba71404 | 2014-11-17 14:42:38 +0100 | [diff] [blame] | 1885 | return 0; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1889 | * xilinx_dma_channel_set_config - Configure VDMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1890 | * Run-time configuration for Axi VDMA, supports: |
| 1891 | * . halt the channel |
| 1892 | * . configure interrupt coalescing and inter-packet delay threshold |
| 1893 | * . start/stop parking |
| 1894 | * . enable genlock |
| 1895 | * |
| 1896 | * @dchan: DMA channel |
| 1897 | * @cfg: VDMA device configuration pointer |
| 1898 | * |
| 1899 | * Return: '0' on success and failure value on error |
| 1900 | */ |
| 1901 | int xilinx_vdma_channel_set_config(struct dma_chan *dchan, |
| 1902 | struct xilinx_vdma_config *cfg) |
| 1903 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1904 | struct xilinx_dma_chan *chan = to_xilinx_chan(dchan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1905 | u32 dmacr; |
| 1906 | |
| 1907 | if (cfg->reset) |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1908 | return xilinx_dma_chan_reset(chan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1909 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1910 | dmacr = dma_ctrl_read(chan, XILINX_DMA_REG_DMACR); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1911 | |
| 1912 | chan->config.frm_dly = cfg->frm_dly; |
| 1913 | chan->config.park = cfg->park; |
| 1914 | |
| 1915 | /* genlock settings */ |
| 1916 | chan->config.gen_lock = cfg->gen_lock; |
| 1917 | chan->config.master = cfg->master; |
| 1918 | |
| 1919 | if (cfg->gen_lock && chan->genlock) { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1920 | dmacr |= XILINX_DMA_DMACR_GENLOCK_EN; |
| 1921 | dmacr |= cfg->master << XILINX_DMA_DMACR_MASTER_SHIFT; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | chan->config.frm_cnt_en = cfg->frm_cnt_en; |
| 1925 | if (cfg->park) |
| 1926 | chan->config.park_frm = cfg->park_frm; |
| 1927 | else |
| 1928 | chan->config.park_frm = -1; |
| 1929 | |
| 1930 | chan->config.coalesc = cfg->coalesc; |
| 1931 | chan->config.delay = cfg->delay; |
| 1932 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1933 | if (cfg->coalesc <= XILINX_DMA_DMACR_FRAME_COUNT_MAX) { |
| 1934 | dmacr |= cfg->coalesc << XILINX_DMA_DMACR_FRAME_COUNT_SHIFT; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1935 | chan->config.coalesc = cfg->coalesc; |
| 1936 | } |
| 1937 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1938 | if (cfg->delay <= XILINX_DMA_DMACR_DELAY_MAX) { |
| 1939 | dmacr |= cfg->delay << XILINX_DMA_DMACR_DELAY_SHIFT; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1940 | chan->config.delay = cfg->delay; |
| 1941 | } |
| 1942 | |
| 1943 | /* FSync Source selection */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1944 | dmacr &= ~XILINX_DMA_DMACR_FSYNCSRC_MASK; |
| 1945 | dmacr |= cfg->ext_fsync << XILINX_DMA_DMACR_FSYNCSRC_SHIFT; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1946 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1947 | dma_ctrl_write(chan, XILINX_DMA_REG_DMACR, dmacr); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1948 | |
| 1949 | return 0; |
| 1950 | } |
| 1951 | EXPORT_SYMBOL(xilinx_vdma_channel_set_config); |
| 1952 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1953 | /* ----------------------------------------------------------------------------- |
| 1954 | * Probe and remove |
| 1955 | */ |
| 1956 | |
| 1957 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1958 | * xilinx_dma_chan_remove - Per Channel remove function |
| 1959 | * @chan: Driver specific DMA channel |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1960 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1961 | static void xilinx_dma_chan_remove(struct xilinx_dma_chan *chan) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1962 | { |
| 1963 | /* Disable all interrupts */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 1964 | dma_ctrl_clr(chan, XILINX_DMA_REG_DMACR, |
| 1965 | XILINX_DMA_DMAXR_ALL_IRQ_MASK); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 1966 | |
| 1967 | if (chan->irq > 0) |
| 1968 | free_irq(chan->irq, chan); |
| 1969 | |
| 1970 | tasklet_kill(&chan->tasklet); |
| 1971 | |
| 1972 | list_del(&chan->common.device_node); |
| 1973 | } |
| 1974 | |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 1975 | static int axidma_clk_init(struct platform_device *pdev, struct clk **axi_clk, |
| 1976 | struct clk **tx_clk, struct clk **rx_clk, |
| 1977 | struct clk **sg_clk, struct clk **tmp_clk) |
| 1978 | { |
| 1979 | int err; |
| 1980 | |
| 1981 | *tmp_clk = NULL; |
| 1982 | |
| 1983 | *axi_clk = devm_clk_get(&pdev->dev, "s_axi_lite_aclk"); |
| 1984 | if (IS_ERR(*axi_clk)) { |
| 1985 | err = PTR_ERR(*axi_clk); |
| 1986 | dev_err(&pdev->dev, "failed to get axi_aclk (%u)\n", err); |
| 1987 | return err; |
| 1988 | } |
| 1989 | |
| 1990 | *tx_clk = devm_clk_get(&pdev->dev, "m_axi_mm2s_aclk"); |
| 1991 | if (IS_ERR(*tx_clk)) |
| 1992 | *tx_clk = NULL; |
| 1993 | |
| 1994 | *rx_clk = devm_clk_get(&pdev->dev, "m_axi_s2mm_aclk"); |
| 1995 | if (IS_ERR(*rx_clk)) |
| 1996 | *rx_clk = NULL; |
| 1997 | |
| 1998 | *sg_clk = devm_clk_get(&pdev->dev, "m_axi_sg_aclk"); |
| 1999 | if (IS_ERR(*sg_clk)) |
| 2000 | *sg_clk = NULL; |
| 2001 | |
| 2002 | err = clk_prepare_enable(*axi_clk); |
| 2003 | if (err) { |
| 2004 | dev_err(&pdev->dev, "failed to enable axi_clk (%u)\n", err); |
| 2005 | return err; |
| 2006 | } |
| 2007 | |
| 2008 | err = clk_prepare_enable(*tx_clk); |
| 2009 | if (err) { |
| 2010 | dev_err(&pdev->dev, "failed to enable tx_clk (%u)\n", err); |
| 2011 | goto err_disable_axiclk; |
| 2012 | } |
| 2013 | |
| 2014 | err = clk_prepare_enable(*rx_clk); |
| 2015 | if (err) { |
| 2016 | dev_err(&pdev->dev, "failed to enable rx_clk (%u)\n", err); |
| 2017 | goto err_disable_txclk; |
| 2018 | } |
| 2019 | |
| 2020 | err = clk_prepare_enable(*sg_clk); |
| 2021 | if (err) { |
| 2022 | dev_err(&pdev->dev, "failed to enable sg_clk (%u)\n", err); |
| 2023 | goto err_disable_rxclk; |
| 2024 | } |
| 2025 | |
| 2026 | return 0; |
| 2027 | |
| 2028 | err_disable_rxclk: |
| 2029 | clk_disable_unprepare(*rx_clk); |
| 2030 | err_disable_txclk: |
| 2031 | clk_disable_unprepare(*tx_clk); |
| 2032 | err_disable_axiclk: |
| 2033 | clk_disable_unprepare(*axi_clk); |
| 2034 | |
| 2035 | return err; |
| 2036 | } |
| 2037 | |
| 2038 | static int axicdma_clk_init(struct platform_device *pdev, struct clk **axi_clk, |
| 2039 | struct clk **dev_clk, struct clk **tmp_clk, |
| 2040 | struct clk **tmp1_clk, struct clk **tmp2_clk) |
| 2041 | { |
| 2042 | int err; |
| 2043 | |
| 2044 | *tmp_clk = NULL; |
| 2045 | *tmp1_clk = NULL; |
| 2046 | *tmp2_clk = NULL; |
| 2047 | |
| 2048 | *axi_clk = devm_clk_get(&pdev->dev, "s_axi_lite_aclk"); |
| 2049 | if (IS_ERR(*axi_clk)) { |
| 2050 | err = PTR_ERR(*axi_clk); |
| 2051 | dev_err(&pdev->dev, "failed to get axi_clk (%u)\n", err); |
| 2052 | return err; |
| 2053 | } |
| 2054 | |
| 2055 | *dev_clk = devm_clk_get(&pdev->dev, "m_axi_aclk"); |
| 2056 | if (IS_ERR(*dev_clk)) { |
| 2057 | err = PTR_ERR(*dev_clk); |
| 2058 | dev_err(&pdev->dev, "failed to get dev_clk (%u)\n", err); |
| 2059 | return err; |
| 2060 | } |
| 2061 | |
| 2062 | err = clk_prepare_enable(*axi_clk); |
| 2063 | if (err) { |
| 2064 | dev_err(&pdev->dev, "failed to enable axi_clk (%u)\n", err); |
| 2065 | return err; |
| 2066 | } |
| 2067 | |
| 2068 | err = clk_prepare_enable(*dev_clk); |
| 2069 | if (err) { |
| 2070 | dev_err(&pdev->dev, "failed to enable dev_clk (%u)\n", err); |
| 2071 | goto err_disable_axiclk; |
| 2072 | } |
| 2073 | |
| 2074 | return 0; |
| 2075 | |
| 2076 | err_disable_axiclk: |
| 2077 | clk_disable_unprepare(*axi_clk); |
| 2078 | |
| 2079 | return err; |
| 2080 | } |
| 2081 | |
| 2082 | static int axivdma_clk_init(struct platform_device *pdev, struct clk **axi_clk, |
| 2083 | struct clk **tx_clk, struct clk **txs_clk, |
| 2084 | struct clk **rx_clk, struct clk **rxs_clk) |
| 2085 | { |
| 2086 | int err; |
| 2087 | |
| 2088 | *axi_clk = devm_clk_get(&pdev->dev, "s_axi_lite_aclk"); |
| 2089 | if (IS_ERR(*axi_clk)) { |
| 2090 | err = PTR_ERR(*axi_clk); |
| 2091 | dev_err(&pdev->dev, "failed to get axi_aclk (%u)\n", err); |
| 2092 | return err; |
| 2093 | } |
| 2094 | |
| 2095 | *tx_clk = devm_clk_get(&pdev->dev, "m_axi_mm2s_aclk"); |
| 2096 | if (IS_ERR(*tx_clk)) |
| 2097 | *tx_clk = NULL; |
| 2098 | |
| 2099 | *txs_clk = devm_clk_get(&pdev->dev, "m_axis_mm2s_aclk"); |
| 2100 | if (IS_ERR(*txs_clk)) |
| 2101 | *txs_clk = NULL; |
| 2102 | |
| 2103 | *rx_clk = devm_clk_get(&pdev->dev, "m_axi_s2mm_aclk"); |
| 2104 | if (IS_ERR(*rx_clk)) |
| 2105 | *rx_clk = NULL; |
| 2106 | |
| 2107 | *rxs_clk = devm_clk_get(&pdev->dev, "s_axis_s2mm_aclk"); |
| 2108 | if (IS_ERR(*rxs_clk)) |
| 2109 | *rxs_clk = NULL; |
| 2110 | |
| 2111 | err = clk_prepare_enable(*axi_clk); |
| 2112 | if (err) { |
| 2113 | dev_err(&pdev->dev, "failed to enable axi_clk (%u)\n", err); |
| 2114 | return err; |
| 2115 | } |
| 2116 | |
| 2117 | err = clk_prepare_enable(*tx_clk); |
| 2118 | if (err) { |
| 2119 | dev_err(&pdev->dev, "failed to enable tx_clk (%u)\n", err); |
| 2120 | goto err_disable_axiclk; |
| 2121 | } |
| 2122 | |
| 2123 | err = clk_prepare_enable(*txs_clk); |
| 2124 | if (err) { |
| 2125 | dev_err(&pdev->dev, "failed to enable txs_clk (%u)\n", err); |
| 2126 | goto err_disable_txclk; |
| 2127 | } |
| 2128 | |
| 2129 | err = clk_prepare_enable(*rx_clk); |
| 2130 | if (err) { |
| 2131 | dev_err(&pdev->dev, "failed to enable rx_clk (%u)\n", err); |
| 2132 | goto err_disable_txsclk; |
| 2133 | } |
| 2134 | |
| 2135 | err = clk_prepare_enable(*rxs_clk); |
| 2136 | if (err) { |
| 2137 | dev_err(&pdev->dev, "failed to enable rxs_clk (%u)\n", err); |
| 2138 | goto err_disable_rxclk; |
| 2139 | } |
| 2140 | |
| 2141 | return 0; |
| 2142 | |
| 2143 | err_disable_rxclk: |
| 2144 | clk_disable_unprepare(*rx_clk); |
| 2145 | err_disable_txsclk: |
| 2146 | clk_disable_unprepare(*txs_clk); |
| 2147 | err_disable_txclk: |
| 2148 | clk_disable_unprepare(*tx_clk); |
| 2149 | err_disable_axiclk: |
| 2150 | clk_disable_unprepare(*axi_clk); |
| 2151 | |
| 2152 | return err; |
| 2153 | } |
| 2154 | |
| 2155 | static void xdma_disable_allclks(struct xilinx_dma_device *xdev) |
| 2156 | { |
| 2157 | clk_disable_unprepare(xdev->rxs_clk); |
| 2158 | clk_disable_unprepare(xdev->rx_clk); |
| 2159 | clk_disable_unprepare(xdev->txs_clk); |
| 2160 | clk_disable_unprepare(xdev->tx_clk); |
| 2161 | clk_disable_unprepare(xdev->axi_clk); |
| 2162 | } |
| 2163 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2164 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2165 | * xilinx_dma_chan_probe - Per Channel Probing |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2166 | * It get channel features from the device tree entry and |
| 2167 | * initialize special channel handling routines |
| 2168 | * |
| 2169 | * @xdev: Driver specific device structure |
| 2170 | * @node: Device node |
| 2171 | * |
| 2172 | * Return: '0' on success and failure value on error |
| 2173 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2174 | static int xilinx_dma_chan_probe(struct xilinx_dma_device *xdev, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2175 | struct device_node *node) |
| 2176 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2177 | struct xilinx_dma_chan *chan; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2178 | bool has_dre = false; |
| 2179 | u32 value, width; |
| 2180 | int err; |
| 2181 | |
| 2182 | /* Allocate and initialize the channel structure */ |
| 2183 | chan = devm_kzalloc(xdev->dev, sizeof(*chan), GFP_KERNEL); |
| 2184 | if (!chan) |
| 2185 | return -ENOMEM; |
| 2186 | |
| 2187 | chan->dev = xdev->dev; |
| 2188 | chan->xdev = xdev; |
| 2189 | chan->has_sg = xdev->has_sg; |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 2190 | chan->desc_pendingcount = 0x0; |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 2191 | chan->ext_addr = xdev->ext_addr; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2192 | |
| 2193 | spin_lock_init(&chan->lock); |
| 2194 | INIT_LIST_HEAD(&chan->pending_list); |
| 2195 | INIT_LIST_HEAD(&chan->done_list); |
Kedareswara rao Appana | 7096f36 | 2016-02-26 19:33:51 +0530 | [diff] [blame] | 2196 | INIT_LIST_HEAD(&chan->active_list); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2197 | |
| 2198 | /* Retrieve the channel properties from the device tree */ |
| 2199 | has_dre = of_property_read_bool(node, "xlnx,include-dre"); |
| 2200 | |
| 2201 | chan->genlock = of_property_read_bool(node, "xlnx,genlock-mode"); |
| 2202 | |
| 2203 | err = of_property_read_u32(node, "xlnx,datawidth", &value); |
| 2204 | if (err) { |
| 2205 | dev_err(xdev->dev, "missing xlnx,datawidth property\n"); |
| 2206 | return err; |
| 2207 | } |
| 2208 | width = value >> 3; /* Convert bits to bytes */ |
| 2209 | |
| 2210 | /* If data width is greater than 8 bytes, DRE is not in hw */ |
| 2211 | if (width > 8) |
| 2212 | has_dre = false; |
| 2213 | |
| 2214 | if (!has_dre) |
| 2215 | xdev->common.copy_align = fls(width - 1); |
| 2216 | |
| 2217 | if (of_device_is_compatible(node, "xlnx,axi-vdma-mm2s-channel")) { |
| 2218 | chan->direction = DMA_MEM_TO_DEV; |
| 2219 | chan->id = 0; |
| 2220 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2221 | chan->ctrl_offset = XILINX_DMA_MM2S_CTRL_OFFSET; |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2222 | if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) { |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2223 | chan->desc_offset = XILINX_VDMA_MM2S_DESC_OFFSET; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2224 | |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2225 | if (xdev->flush_on_fsync == XILINX_DMA_FLUSH_BOTH || |
| 2226 | xdev->flush_on_fsync == XILINX_DMA_FLUSH_MM2S) |
| 2227 | chan->flush_on_fsync = true; |
| 2228 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2229 | } else if (of_device_is_compatible(node, |
| 2230 | "xlnx,axi-vdma-s2mm-channel")) { |
| 2231 | chan->direction = DMA_DEV_TO_MEM; |
| 2232 | chan->id = 1; |
| 2233 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2234 | chan->ctrl_offset = XILINX_DMA_S2MM_CTRL_OFFSET; |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2235 | if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) { |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2236 | chan->desc_offset = XILINX_VDMA_S2MM_DESC_OFFSET; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2237 | |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2238 | if (xdev->flush_on_fsync == XILINX_DMA_FLUSH_BOTH || |
| 2239 | xdev->flush_on_fsync == XILINX_DMA_FLUSH_S2MM) |
| 2240 | chan->flush_on_fsync = true; |
| 2241 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2242 | } else { |
| 2243 | dev_err(xdev->dev, "Invalid channel compatible node\n"); |
| 2244 | return -EINVAL; |
| 2245 | } |
| 2246 | |
| 2247 | /* Request the interrupt */ |
| 2248 | chan->irq = irq_of_parse_and_map(node, 0); |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2249 | err = request_irq(chan->irq, xilinx_dma_irq_handler, IRQF_SHARED, |
| 2250 | "xilinx-dma-controller", chan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2251 | if (err) { |
| 2252 | dev_err(xdev->dev, "unable to request IRQ %d\n", chan->irq); |
| 2253 | return err; |
| 2254 | } |
| 2255 | |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2256 | if (xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2257 | chan->start_transfer = xilinx_dma_start_transfer; |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2258 | else if (xdev->dma_config->dmatype == XDMA_TYPE_CDMA) |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 2259 | chan->start_transfer = xilinx_cdma_start_transfer; |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2260 | else |
| 2261 | chan->start_transfer = xilinx_vdma_start_transfer; |
| 2262 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2263 | /* Initialize the tasklet */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2264 | tasklet_init(&chan->tasklet, xilinx_dma_do_tasklet, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2265 | (unsigned long)chan); |
| 2266 | |
| 2267 | /* |
| 2268 | * Initialize the DMA channel and add it to the DMA engine channels |
| 2269 | * list. |
| 2270 | */ |
| 2271 | chan->common.device = &xdev->common; |
| 2272 | |
| 2273 | list_add_tail(&chan->common.device_node, &xdev->common.channels); |
| 2274 | xdev->chan[chan->id] = chan; |
| 2275 | |
| 2276 | /* Reset the channel */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2277 | err = xilinx_dma_chan_reset(chan); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2278 | if (err < 0) { |
| 2279 | dev_err(xdev->dev, "Reset channel failed\n"); |
| 2280 | return err; |
| 2281 | } |
| 2282 | |
| 2283 | return 0; |
| 2284 | } |
| 2285 | |
| 2286 | /** |
| 2287 | * of_dma_xilinx_xlate - Translation function |
| 2288 | * @dma_spec: Pointer to DMA specifier as found in the device tree |
| 2289 | * @ofdma: Pointer to DMA controller data |
| 2290 | * |
| 2291 | * Return: DMA channel pointer on success and NULL on error |
| 2292 | */ |
| 2293 | static struct dma_chan *of_dma_xilinx_xlate(struct of_phandle_args *dma_spec, |
| 2294 | struct of_dma *ofdma) |
| 2295 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2296 | struct xilinx_dma_device *xdev = ofdma->of_dma_data; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2297 | int chan_id = dma_spec->args[0]; |
| 2298 | |
Linus Torvalds | a0d3c7c | 2016-05-19 11:47:18 -0700 | [diff] [blame] | 2299 | if (chan_id >= XILINX_DMA_MAX_CHANS_PER_DEVICE || !xdev->chan[chan_id]) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2300 | return NULL; |
| 2301 | |
| 2302 | return dma_get_slave_channel(&xdev->chan[chan_id]->common); |
| 2303 | } |
| 2304 | |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2305 | static const struct xilinx_dma_config axidma_config = { |
| 2306 | .dmatype = XDMA_TYPE_AXIDMA, |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 2307 | .clk_init = axidma_clk_init, |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2308 | }; |
| 2309 | |
| 2310 | static const struct xilinx_dma_config axicdma_config = { |
| 2311 | .dmatype = XDMA_TYPE_CDMA, |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 2312 | .clk_init = axicdma_clk_init, |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2313 | }; |
| 2314 | |
| 2315 | static const struct xilinx_dma_config axivdma_config = { |
| 2316 | .dmatype = XDMA_TYPE_VDMA, |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 2317 | .clk_init = axivdma_clk_init, |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2318 | }; |
| 2319 | |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2320 | static const struct of_device_id xilinx_dma_of_ids[] = { |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2321 | { .compatible = "xlnx,axi-dma-1.00.a", .data = &axidma_config }, |
| 2322 | { .compatible = "xlnx,axi-cdma-1.00.a", .data = &axicdma_config }, |
| 2323 | { .compatible = "xlnx,axi-vdma-1.00.a", .data = &axivdma_config }, |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2324 | {} |
| 2325 | }; |
| 2326 | MODULE_DEVICE_TABLE(of, xilinx_dma_of_ids); |
| 2327 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2328 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2329 | * xilinx_dma_probe - Driver probe function |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2330 | * @pdev: Pointer to the platform_device structure |
| 2331 | * |
| 2332 | * Return: '0' on success and failure value on error |
| 2333 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2334 | static int xilinx_dma_probe(struct platform_device *pdev) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2335 | { |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 2336 | int (*clk_init)(struct platform_device *, struct clk **, struct clk **, |
| 2337 | struct clk **, struct clk **, struct clk **) |
| 2338 | = axivdma_clk_init; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2339 | struct device_node *node = pdev->dev.of_node; |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2340 | struct xilinx_dma_device *xdev; |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2341 | struct device_node *child, *np = pdev->dev.of_node; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2342 | struct resource *io; |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 2343 | u32 num_frames, addr_width; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2344 | int i, err; |
| 2345 | |
| 2346 | /* Allocate and initialize the DMA engine structure */ |
| 2347 | xdev = devm_kzalloc(&pdev->dev, sizeof(*xdev), GFP_KERNEL); |
| 2348 | if (!xdev) |
| 2349 | return -ENOMEM; |
| 2350 | |
| 2351 | xdev->dev = &pdev->dev; |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2352 | if (np) { |
| 2353 | const struct of_device_id *match; |
| 2354 | |
| 2355 | match = of_match_node(xilinx_dma_of_ids, np); |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 2356 | if (match && match->data) { |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2357 | xdev->dma_config = match->data; |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 2358 | clk_init = xdev->dma_config->clk_init; |
| 2359 | } |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2360 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2361 | |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 2362 | err = clk_init(pdev, &xdev->axi_clk, &xdev->tx_clk, &xdev->txs_clk, |
| 2363 | &xdev->rx_clk, &xdev->rxs_clk); |
| 2364 | if (err) |
| 2365 | return err; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2366 | |
| 2367 | /* Request and map I/O memory */ |
| 2368 | io = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2369 | xdev->regs = devm_ioremap_resource(&pdev->dev, io); |
| 2370 | if (IS_ERR(xdev->regs)) |
| 2371 | return PTR_ERR(xdev->regs); |
| 2372 | |
| 2373 | /* Retrieve the DMA engine properties from the device tree */ |
| 2374 | xdev->has_sg = of_property_read_bool(node, "xlnx,include-sg"); |
| 2375 | |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2376 | if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) { |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2377 | err = of_property_read_u32(node, "xlnx,num-fstores", |
| 2378 | &num_frames); |
| 2379 | if (err < 0) { |
| 2380 | dev_err(xdev->dev, |
| 2381 | "missing xlnx,num-fstores property\n"); |
| 2382 | return err; |
| 2383 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2384 | |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2385 | err = of_property_read_u32(node, "xlnx,flush-fsync", |
| 2386 | &xdev->flush_on_fsync); |
| 2387 | if (err < 0) |
| 2388 | dev_warn(xdev->dev, |
| 2389 | "missing xlnx,flush-fsync property\n"); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2390 | } |
| 2391 | |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 2392 | err = of_property_read_u32(node, "xlnx,addrwidth", &addr_width); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2393 | if (err < 0) |
Kedareswara rao Appana | b72db40 | 2016-04-06 10:38:08 +0530 | [diff] [blame] | 2394 | dev_warn(xdev->dev, "missing xlnx,addrwidth property\n"); |
| 2395 | |
| 2396 | if (addr_width > 32) |
| 2397 | xdev->ext_addr = true; |
| 2398 | else |
| 2399 | xdev->ext_addr = false; |
| 2400 | |
| 2401 | /* Set the dma mask bits */ |
| 2402 | dma_set_mask(xdev->dev, DMA_BIT_MASK(addr_width)); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2403 | |
| 2404 | /* Initialize the DMA engine */ |
| 2405 | xdev->common.dev = &pdev->dev; |
| 2406 | |
| 2407 | INIT_LIST_HEAD(&xdev->common.channels); |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2408 | if (!(xdev->dma_config->dmatype == XDMA_TYPE_CDMA)) { |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 2409 | dma_cap_set(DMA_SLAVE, xdev->common.cap_mask); |
| 2410 | dma_cap_set(DMA_PRIVATE, xdev->common.cap_mask); |
| 2411 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2412 | |
| 2413 | xdev->common.device_alloc_chan_resources = |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2414 | xilinx_dma_alloc_chan_resources; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2415 | xdev->common.device_free_chan_resources = |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2416 | xilinx_dma_free_chan_resources; |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2417 | xdev->common.device_terminate_all = xilinx_dma_terminate_all; |
| 2418 | xdev->common.device_tx_status = xilinx_dma_tx_status; |
| 2419 | xdev->common.device_issue_pending = xilinx_dma_issue_pending; |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2420 | if (xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) { |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 2421 | dma_cap_set(DMA_CYCLIC, xdev->common.cap_mask); |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2422 | xdev->common.device_prep_slave_sg = xilinx_dma_prep_slave_sg; |
Kedareswara rao Appana | 92d794d | 2016-05-18 13:17:30 +0530 | [diff] [blame] | 2423 | xdev->common.device_prep_dma_cyclic = |
| 2424 | xilinx_dma_prep_dma_cyclic; |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2425 | /* Residue calculation is supported by only AXI DMA */ |
| 2426 | xdev->common.residue_granularity = |
| 2427 | DMA_RESIDUE_GRANULARITY_SEGMENT; |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2428 | } else if (xdev->dma_config->dmatype == XDMA_TYPE_CDMA) { |
Kedareswara rao Appana | 07b0e7d | 2016-04-07 10:59:45 +0530 | [diff] [blame] | 2429 | dma_cap_set(DMA_MEMCPY, xdev->common.cap_mask); |
| 2430 | xdev->common.device_prep_dma_memcpy = xilinx_cdma_prep_memcpy; |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2431 | } else { |
| 2432 | xdev->common.device_prep_interleaved_dma = |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2433 | xilinx_vdma_dma_prep_interleaved; |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2434 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2435 | |
| 2436 | platform_set_drvdata(pdev, xdev); |
| 2437 | |
| 2438 | /* Initialize the channels */ |
| 2439 | for_each_child_of_node(node, child) { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2440 | err = xilinx_dma_chan_probe(xdev, child); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2441 | if (err < 0) |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 2442 | goto disable_clks; |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2443 | } |
| 2444 | |
Kedareswara rao Appana | fb23666 | 2016-05-13 12:33:29 +0530 | [diff] [blame] | 2445 | if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) { |
Kedareswara rao Appana | c0bba3a | 2016-04-07 10:59:43 +0530 | [diff] [blame] | 2446 | for (i = 0; i < XILINX_DMA_MAX_CHANS_PER_DEVICE; i++) |
| 2447 | if (xdev->chan[i]) |
| 2448 | xdev->chan[i]->num_frms = num_frames; |
| 2449 | } |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2450 | |
| 2451 | /* Register the DMA engine with the core */ |
| 2452 | dma_async_device_register(&xdev->common); |
| 2453 | |
| 2454 | err = of_dma_controller_register(node, of_dma_xilinx_xlate, |
| 2455 | xdev); |
| 2456 | if (err < 0) { |
| 2457 | dev_err(&pdev->dev, "Unable to register DMA to DT\n"); |
| 2458 | dma_async_device_unregister(&xdev->common); |
| 2459 | goto error; |
| 2460 | } |
| 2461 | |
| 2462 | dev_info(&pdev->dev, "Xilinx AXI VDMA Engine Driver Probed!!\n"); |
| 2463 | |
| 2464 | return 0; |
| 2465 | |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 2466 | disable_clks: |
| 2467 | xdma_disable_allclks(xdev); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2468 | error: |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2469 | for (i = 0; i < XILINX_DMA_MAX_CHANS_PER_DEVICE; i++) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2470 | if (xdev->chan[i]) |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2471 | xilinx_dma_chan_remove(xdev->chan[i]); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2472 | |
| 2473 | return err; |
| 2474 | } |
| 2475 | |
| 2476 | /** |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2477 | * xilinx_dma_remove - Driver remove function |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2478 | * @pdev: Pointer to the platform_device structure |
| 2479 | * |
| 2480 | * Return: Always '0' |
| 2481 | */ |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2482 | static int xilinx_dma_remove(struct platform_device *pdev) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2483 | { |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2484 | struct xilinx_dma_device *xdev = platform_get_drvdata(pdev); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2485 | int i; |
| 2486 | |
| 2487 | of_dma_controller_free(pdev->dev.of_node); |
| 2488 | |
| 2489 | dma_async_device_unregister(&xdev->common); |
| 2490 | |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2491 | for (i = 0; i < XILINX_DMA_MAX_CHANS_PER_DEVICE; i++) |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2492 | if (xdev->chan[i]) |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2493 | xilinx_dma_chan_remove(xdev->chan[i]); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2494 | |
Kedareswara rao Appana | ba16db3 | 2016-05-13 12:33:31 +0530 | [diff] [blame] | 2495 | xdma_disable_allclks(xdev); |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2496 | |
| 2497 | return 0; |
| 2498 | } |
| 2499 | |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2500 | static struct platform_driver xilinx_vdma_driver = { |
| 2501 | .driver = { |
| 2502 | .name = "xilinx-vdma", |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2503 | .of_match_table = xilinx_dma_of_ids, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2504 | }, |
Kedareswara rao Appana | 42c1a2e | 2016-04-07 10:59:41 +0530 | [diff] [blame] | 2505 | .probe = xilinx_dma_probe, |
| 2506 | .remove = xilinx_dma_remove, |
Srikanth Thokala | 9cd4360 | 2014-04-23 20:23:26 +0530 | [diff] [blame] | 2507 | }; |
| 2508 | |
| 2509 | module_platform_driver(xilinx_vdma_driver); |
| 2510 | |
| 2511 | MODULE_AUTHOR("Xilinx, Inc."); |
| 2512 | MODULE_DESCRIPTION("Xilinx VDMA driver"); |
| 2513 | MODULE_LICENSE("GPL v2"); |