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