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