Paul Cercueil | d8b9626 | 2019-05-04 23:34:32 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Ingenic JZ4780 DMA controller |
| 4 | * |
| 5 | * Copyright (c) 2015 Imagination Technologies |
| 6 | * Author: Alex Smith <alex@alex-smith.me.uk> |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/clk.h> |
| 10 | #include <linux/dmapool.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/interrupt.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/of.h> |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 15 | #include <linux/of_device.h> |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 16 | #include <linux/of_dma.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/slab.h> |
| 19 | |
| 20 | #include "dmaengine.h" |
| 21 | #include "virt-dma.h" |
| 22 | |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 23 | /* Global registers. */ |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 24 | #define JZ_DMA_REG_DMAC 0x00 |
| 25 | #define JZ_DMA_REG_DIRQP 0x04 |
| 26 | #define JZ_DMA_REG_DDR 0x08 |
| 27 | #define JZ_DMA_REG_DDRS 0x0c |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 28 | #define JZ_DMA_REG_DCKE 0x10 |
| 29 | #define JZ_DMA_REG_DCKES 0x14 |
| 30 | #define JZ_DMA_REG_DCKEC 0x18 |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 31 | #define JZ_DMA_REG_DMACP 0x1c |
| 32 | #define JZ_DMA_REG_DSIRQP 0x20 |
| 33 | #define JZ_DMA_REG_DSIRQM 0x24 |
| 34 | #define JZ_DMA_REG_DCIRQP 0x28 |
| 35 | #define JZ_DMA_REG_DCIRQM 0x2c |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 36 | |
| 37 | /* Per-channel registers. */ |
| 38 | #define JZ_DMA_REG_CHAN(n) (n * 0x20) |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 39 | #define JZ_DMA_REG_DSA 0x00 |
| 40 | #define JZ_DMA_REG_DTA 0x04 |
| 41 | #define JZ_DMA_REG_DTC 0x08 |
| 42 | #define JZ_DMA_REG_DRT 0x0c |
| 43 | #define JZ_DMA_REG_DCS 0x10 |
| 44 | #define JZ_DMA_REG_DCM 0x14 |
| 45 | #define JZ_DMA_REG_DDA 0x18 |
| 46 | #define JZ_DMA_REG_DSD 0x1c |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 47 | |
| 48 | #define JZ_DMA_DMAC_DMAE BIT(0) |
| 49 | #define JZ_DMA_DMAC_AR BIT(2) |
| 50 | #define JZ_DMA_DMAC_HLT BIT(3) |
Paul Cercueil | 17a8e30 | 2018-08-29 23:32:52 +0200 | [diff] [blame] | 51 | #define JZ_DMA_DMAC_FAIC BIT(27) |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 52 | #define JZ_DMA_DMAC_FMSC BIT(31) |
| 53 | |
| 54 | #define JZ_DMA_DRT_AUTO 0x8 |
| 55 | |
| 56 | #define JZ_DMA_DCS_CTE BIT(0) |
| 57 | #define JZ_DMA_DCS_HLT BIT(2) |
| 58 | #define JZ_DMA_DCS_TT BIT(3) |
| 59 | #define JZ_DMA_DCS_AR BIT(4) |
| 60 | #define JZ_DMA_DCS_DES8 BIT(30) |
| 61 | |
| 62 | #define JZ_DMA_DCM_LINK BIT(0) |
| 63 | #define JZ_DMA_DCM_TIE BIT(1) |
| 64 | #define JZ_DMA_DCM_STDE BIT(2) |
| 65 | #define JZ_DMA_DCM_TSZ_SHIFT 8 |
| 66 | #define JZ_DMA_DCM_TSZ_MASK (0x7 << JZ_DMA_DCM_TSZ_SHIFT) |
| 67 | #define JZ_DMA_DCM_DP_SHIFT 12 |
| 68 | #define JZ_DMA_DCM_SP_SHIFT 14 |
| 69 | #define JZ_DMA_DCM_DAI BIT(22) |
| 70 | #define JZ_DMA_DCM_SAI BIT(23) |
| 71 | |
| 72 | #define JZ_DMA_SIZE_4_BYTE 0x0 |
| 73 | #define JZ_DMA_SIZE_1_BYTE 0x1 |
| 74 | #define JZ_DMA_SIZE_2_BYTE 0x2 |
| 75 | #define JZ_DMA_SIZE_16_BYTE 0x3 |
| 76 | #define JZ_DMA_SIZE_32_BYTE 0x4 |
| 77 | #define JZ_DMA_SIZE_64_BYTE 0x5 |
| 78 | #define JZ_DMA_SIZE_128_BYTE 0x6 |
| 79 | |
| 80 | #define JZ_DMA_WIDTH_32_BIT 0x0 |
| 81 | #define JZ_DMA_WIDTH_8_BIT 0x1 |
| 82 | #define JZ_DMA_WIDTH_16_BIT 0x2 |
| 83 | |
| 84 | #define JZ_DMA_BUSWIDTHS (BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \ |
| 85 | BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \ |
| 86 | BIT(DMA_SLAVE_BUSWIDTH_4_BYTES)) |
| 87 | |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 88 | #define JZ4780_DMA_CTRL_OFFSET 0x1000 |
| 89 | |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 90 | /* macros for use with jz4780_dma_soc_data.flags */ |
| 91 | #define JZ_SOC_DATA_ALLOW_LEGACY_DT BIT(0) |
| 92 | #define JZ_SOC_DATA_PROGRAMMABLE_DMA BIT(1) |
| 93 | #define JZ_SOC_DATA_PER_CHAN_PM BIT(2) |
Paul Cercueil | ae9156b | 2018-08-29 23:32:51 +0200 | [diff] [blame] | 94 | #define JZ_SOC_DATA_NO_DCKES_DCKEC BIT(3) |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 95 | |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 96 | /** |
| 97 | * struct jz4780_dma_hwdesc - descriptor structure read by the DMA controller. |
| 98 | * @dcm: value for the DCM (channel command) register |
| 99 | * @dsa: source address |
| 100 | * @dta: target address |
| 101 | * @dtc: transfer count (number of blocks of the transfer size specified in DCM |
| 102 | * to transfer) in the low 24 bits, offset of the next descriptor from the |
| 103 | * descriptor base address in the upper 8 bits. |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 104 | */ |
| 105 | struct jz4780_dma_hwdesc { |
| 106 | uint32_t dcm; |
| 107 | uint32_t dsa; |
| 108 | uint32_t dta; |
| 109 | uint32_t dtc; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | /* Size of allocations for hardware descriptor blocks. */ |
| 113 | #define JZ_DMA_DESC_BLOCK_SIZE PAGE_SIZE |
| 114 | #define JZ_DMA_MAX_DESC \ |
| 115 | (JZ_DMA_DESC_BLOCK_SIZE / sizeof(struct jz4780_dma_hwdesc)) |
| 116 | |
| 117 | struct jz4780_dma_desc { |
| 118 | struct virt_dma_desc vdesc; |
| 119 | |
| 120 | struct jz4780_dma_hwdesc *desc; |
| 121 | dma_addr_t desc_phys; |
| 122 | unsigned int count; |
| 123 | enum dma_transaction_type type; |
| 124 | uint32_t status; |
| 125 | }; |
| 126 | |
| 127 | struct jz4780_dma_chan { |
| 128 | struct virt_dma_chan vchan; |
| 129 | unsigned int id; |
| 130 | struct dma_pool *desc_pool; |
| 131 | |
| 132 | uint32_t transfer_type; |
| 133 | uint32_t transfer_shift; |
| 134 | struct dma_slave_config config; |
| 135 | |
| 136 | struct jz4780_dma_desc *desc; |
| 137 | unsigned int curr_hwdesc; |
| 138 | }; |
| 139 | |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 140 | struct jz4780_dma_soc_data { |
| 141 | unsigned int nb_channels; |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 142 | unsigned int transfer_ord_max; |
| 143 | unsigned long flags; |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 144 | }; |
| 145 | |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 146 | struct jz4780_dma_dev { |
| 147 | struct dma_device dma_device; |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 148 | void __iomem *chn_base; |
| 149 | void __iomem *ctrl_base; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 150 | struct clk *clk; |
| 151 | unsigned int irq; |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 152 | const struct jz4780_dma_soc_data *soc_data; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 153 | |
| 154 | uint32_t chan_reserved; |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 155 | struct jz4780_dma_chan chan[]; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
Alex Smith | 026fd40 | 2015-07-24 17:24:24 +0100 | [diff] [blame] | 158 | struct jz4780_dma_filter_data { |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 159 | uint32_t transfer_type; |
| 160 | int channel; |
| 161 | }; |
| 162 | |
| 163 | static inline struct jz4780_dma_chan *to_jz4780_dma_chan(struct dma_chan *chan) |
| 164 | { |
| 165 | return container_of(chan, struct jz4780_dma_chan, vchan.chan); |
| 166 | } |
| 167 | |
| 168 | static inline struct jz4780_dma_desc *to_jz4780_dma_desc( |
| 169 | struct virt_dma_desc *vdesc) |
| 170 | { |
| 171 | return container_of(vdesc, struct jz4780_dma_desc, vdesc); |
| 172 | } |
| 173 | |
| 174 | static inline struct jz4780_dma_dev *jz4780_dma_chan_parent( |
| 175 | struct jz4780_dma_chan *jzchan) |
| 176 | { |
| 177 | return container_of(jzchan->vchan.chan.device, struct jz4780_dma_dev, |
| 178 | dma_device); |
| 179 | } |
| 180 | |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 181 | static inline uint32_t jz4780_dma_chn_readl(struct jz4780_dma_dev *jzdma, |
| 182 | unsigned int chn, unsigned int reg) |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 183 | { |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 184 | return readl(jzdma->chn_base + reg + JZ_DMA_REG_CHAN(chn)); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 187 | static inline void jz4780_dma_chn_writel(struct jz4780_dma_dev *jzdma, |
| 188 | unsigned int chn, unsigned int reg, uint32_t val) |
| 189 | { |
| 190 | writel(val, jzdma->chn_base + reg + JZ_DMA_REG_CHAN(chn)); |
| 191 | } |
| 192 | |
| 193 | static inline uint32_t jz4780_dma_ctrl_readl(struct jz4780_dma_dev *jzdma, |
| 194 | unsigned int reg) |
| 195 | { |
| 196 | return readl(jzdma->ctrl_base + reg); |
| 197 | } |
| 198 | |
| 199 | static inline void jz4780_dma_ctrl_writel(struct jz4780_dma_dev *jzdma, |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 200 | unsigned int reg, uint32_t val) |
| 201 | { |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 202 | writel(val, jzdma->ctrl_base + reg); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 205 | static inline void jz4780_dma_chan_enable(struct jz4780_dma_dev *jzdma, |
| 206 | unsigned int chn) |
| 207 | { |
Paul Cercueil | ae9156b | 2018-08-29 23:32:51 +0200 | [diff] [blame] | 208 | if (jzdma->soc_data->flags & JZ_SOC_DATA_PER_CHAN_PM) { |
| 209 | unsigned int reg; |
| 210 | |
| 211 | if (jzdma->soc_data->flags & JZ_SOC_DATA_NO_DCKES_DCKEC) |
| 212 | reg = JZ_DMA_REG_DCKE; |
| 213 | else |
| 214 | reg = JZ_DMA_REG_DCKES; |
| 215 | |
| 216 | jz4780_dma_ctrl_writel(jzdma, reg, BIT(chn)); |
| 217 | } |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static inline void jz4780_dma_chan_disable(struct jz4780_dma_dev *jzdma, |
| 221 | unsigned int chn) |
| 222 | { |
Paul Cercueil | ae9156b | 2018-08-29 23:32:51 +0200 | [diff] [blame] | 223 | if ((jzdma->soc_data->flags & JZ_SOC_DATA_PER_CHAN_PM) && |
| 224 | !(jzdma->soc_data->flags & JZ_SOC_DATA_NO_DCKES_DCKEC)) |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 225 | jz4780_dma_ctrl_writel(jzdma, JZ_DMA_REG_DCKEC, BIT(chn)); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static struct jz4780_dma_desc *jz4780_dma_desc_alloc( |
| 229 | struct jz4780_dma_chan *jzchan, unsigned int count, |
| 230 | enum dma_transaction_type type) |
| 231 | { |
| 232 | struct jz4780_dma_desc *desc; |
| 233 | |
| 234 | if (count > JZ_DMA_MAX_DESC) |
| 235 | return NULL; |
| 236 | |
| 237 | desc = kzalloc(sizeof(*desc), GFP_NOWAIT); |
| 238 | if (!desc) |
| 239 | return NULL; |
| 240 | |
| 241 | desc->desc = dma_pool_alloc(jzchan->desc_pool, GFP_NOWAIT, |
| 242 | &desc->desc_phys); |
| 243 | if (!desc->desc) { |
| 244 | kfree(desc); |
| 245 | return NULL; |
| 246 | } |
| 247 | |
| 248 | desc->count = count; |
| 249 | desc->type = type; |
| 250 | return desc; |
| 251 | } |
| 252 | |
| 253 | static void jz4780_dma_desc_free(struct virt_dma_desc *vdesc) |
| 254 | { |
| 255 | struct jz4780_dma_desc *desc = to_jz4780_dma_desc(vdesc); |
| 256 | struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(vdesc->tx.chan); |
| 257 | |
| 258 | dma_pool_free(jzchan->desc_pool, desc->desc, desc->desc_phys); |
| 259 | kfree(desc); |
| 260 | } |
| 261 | |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 262 | static uint32_t jz4780_dma_transfer_size(struct jz4780_dma_chan *jzchan, |
| 263 | unsigned long val, uint32_t *shift) |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 264 | { |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 265 | struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan); |
Alex Smith | dc578f3 | 2015-07-24 17:24:21 +0100 | [diff] [blame] | 266 | int ord = ffs(val) - 1; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 267 | |
Alex Smith | dc578f3 | 2015-07-24 17:24:21 +0100 | [diff] [blame] | 268 | /* |
| 269 | * 8 byte transfer sizes unsupported so fall back on 4. If it's larger |
| 270 | * than the maximum, just limit it. It is perfectly safe to fall back |
| 271 | * in this way since we won't exceed the maximum burst size supported |
| 272 | * by the device, the only effect is reduced efficiency. This is better |
| 273 | * than refusing to perform the request at all. |
| 274 | */ |
| 275 | if (ord == 3) |
| 276 | ord = 2; |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 277 | else if (ord > jzdma->soc_data->transfer_ord_max) |
| 278 | ord = jzdma->soc_data->transfer_ord_max; |
Alex Smith | dc578f3 | 2015-07-24 17:24:21 +0100 | [diff] [blame] | 279 | |
| 280 | *shift = ord; |
| 281 | |
| 282 | switch (ord) { |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 283 | case 0: |
| 284 | return JZ_DMA_SIZE_1_BYTE; |
| 285 | case 1: |
| 286 | return JZ_DMA_SIZE_2_BYTE; |
| 287 | case 2: |
| 288 | return JZ_DMA_SIZE_4_BYTE; |
| 289 | case 4: |
| 290 | return JZ_DMA_SIZE_16_BYTE; |
| 291 | case 5: |
| 292 | return JZ_DMA_SIZE_32_BYTE; |
| 293 | case 6: |
| 294 | return JZ_DMA_SIZE_64_BYTE; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 295 | default: |
Alex Smith | dc578f3 | 2015-07-24 17:24:21 +0100 | [diff] [blame] | 296 | return JZ_DMA_SIZE_128_BYTE; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | |
Alex Smith | 839896e | 2015-07-24 17:24:22 +0100 | [diff] [blame] | 300 | static int jz4780_dma_setup_hwdesc(struct jz4780_dma_chan *jzchan, |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 301 | struct jz4780_dma_hwdesc *desc, dma_addr_t addr, size_t len, |
| 302 | enum dma_transfer_direction direction) |
| 303 | { |
| 304 | struct dma_slave_config *config = &jzchan->config; |
| 305 | uint32_t width, maxburst, tsz; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 306 | |
| 307 | if (direction == DMA_MEM_TO_DEV) { |
| 308 | desc->dcm = JZ_DMA_DCM_SAI; |
| 309 | desc->dsa = addr; |
| 310 | desc->dta = config->dst_addr; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 311 | |
| 312 | width = config->dst_addr_width; |
| 313 | maxburst = config->dst_maxburst; |
| 314 | } else { |
| 315 | desc->dcm = JZ_DMA_DCM_DAI; |
| 316 | desc->dsa = config->src_addr; |
| 317 | desc->dta = addr; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 318 | |
| 319 | width = config->src_addr_width; |
| 320 | maxburst = config->src_maxburst; |
| 321 | } |
| 322 | |
| 323 | /* |
| 324 | * This calculates the maximum transfer size that can be used with the |
| 325 | * given address, length, width and maximum burst size. The address |
| 326 | * must be aligned to the transfer size, the total length must be |
| 327 | * divisible by the transfer size, and we must not use more than the |
| 328 | * maximum burst specified by the user. |
| 329 | */ |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 330 | tsz = jz4780_dma_transfer_size(jzchan, addr | len | (width * maxburst), |
Alex Smith | dc578f3 | 2015-07-24 17:24:21 +0100 | [diff] [blame] | 331 | &jzchan->transfer_shift); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 332 | |
| 333 | switch (width) { |
| 334 | case DMA_SLAVE_BUSWIDTH_1_BYTE: |
| 335 | case DMA_SLAVE_BUSWIDTH_2_BYTES: |
| 336 | break; |
| 337 | case DMA_SLAVE_BUSWIDTH_4_BYTES: |
| 338 | width = JZ_DMA_WIDTH_32_BIT; |
| 339 | break; |
| 340 | default: |
| 341 | return -EINVAL; |
| 342 | } |
| 343 | |
| 344 | desc->dcm |= tsz << JZ_DMA_DCM_TSZ_SHIFT; |
| 345 | desc->dcm |= width << JZ_DMA_DCM_SP_SHIFT; |
| 346 | desc->dcm |= width << JZ_DMA_DCM_DP_SHIFT; |
| 347 | |
Alex Smith | dc578f3 | 2015-07-24 17:24:21 +0100 | [diff] [blame] | 348 | desc->dtc = len >> jzchan->transfer_shift; |
Alex Smith | 839896e | 2015-07-24 17:24:22 +0100 | [diff] [blame] | 349 | return 0; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | static struct dma_async_tx_descriptor *jz4780_dma_prep_slave_sg( |
| 353 | struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len, |
Alex Smith | 46fa5168 | 2015-07-24 17:24:20 +0100 | [diff] [blame] | 354 | enum dma_transfer_direction direction, unsigned long flags, |
| 355 | void *context) |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 356 | { |
| 357 | struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan); |
| 358 | struct jz4780_dma_desc *desc; |
| 359 | unsigned int i; |
| 360 | int err; |
| 361 | |
| 362 | desc = jz4780_dma_desc_alloc(jzchan, sg_len, DMA_SLAVE); |
| 363 | if (!desc) |
| 364 | return NULL; |
| 365 | |
| 366 | for (i = 0; i < sg_len; i++) { |
| 367 | err = jz4780_dma_setup_hwdesc(jzchan, &desc->desc[i], |
Alex Smith | 839896e | 2015-07-24 17:24:22 +0100 | [diff] [blame] | 368 | sg_dma_address(&sgl[i]), |
| 369 | sg_dma_len(&sgl[i]), |
| 370 | direction); |
Colin Ian King | fc878ef | 2016-09-29 18:45:05 +0100 | [diff] [blame] | 371 | if (err < 0) { |
| 372 | jz4780_dma_desc_free(&jzchan->desc->vdesc); |
Alex Smith | 839896e | 2015-07-24 17:24:22 +0100 | [diff] [blame] | 373 | return NULL; |
Colin Ian King | fc878ef | 2016-09-29 18:45:05 +0100 | [diff] [blame] | 374 | } |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 375 | |
| 376 | desc->desc[i].dcm |= JZ_DMA_DCM_TIE; |
| 377 | |
| 378 | if (i != (sg_len - 1)) { |
| 379 | /* Automatically proceeed to the next descriptor. */ |
| 380 | desc->desc[i].dcm |= JZ_DMA_DCM_LINK; |
| 381 | |
| 382 | /* |
| 383 | * The upper 8 bits of the DTC field in the descriptor |
| 384 | * must be set to (offset from descriptor base of next |
| 385 | * descriptor >> 4). |
| 386 | */ |
| 387 | desc->desc[i].dtc |= |
| 388 | (((i + 1) * sizeof(*desc->desc)) >> 4) << 24; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | return vchan_tx_prep(&jzchan->vchan, &desc->vdesc, flags); |
| 393 | } |
| 394 | |
| 395 | static struct dma_async_tx_descriptor *jz4780_dma_prep_dma_cyclic( |
| 396 | struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, |
| 397 | size_t period_len, enum dma_transfer_direction direction, |
| 398 | unsigned long flags) |
| 399 | { |
| 400 | struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan); |
| 401 | struct jz4780_dma_desc *desc; |
| 402 | unsigned int periods, i; |
| 403 | int err; |
| 404 | |
| 405 | if (buf_len % period_len) |
| 406 | return NULL; |
| 407 | |
| 408 | periods = buf_len / period_len; |
| 409 | |
| 410 | desc = jz4780_dma_desc_alloc(jzchan, periods, DMA_CYCLIC); |
| 411 | if (!desc) |
| 412 | return NULL; |
| 413 | |
| 414 | for (i = 0; i < periods; i++) { |
| 415 | err = jz4780_dma_setup_hwdesc(jzchan, &desc->desc[i], buf_addr, |
Alex Smith | 839896e | 2015-07-24 17:24:22 +0100 | [diff] [blame] | 416 | period_len, direction); |
Colin Ian King | fc878ef | 2016-09-29 18:45:05 +0100 | [diff] [blame] | 417 | if (err < 0) { |
| 418 | jz4780_dma_desc_free(&jzchan->desc->vdesc); |
Alex Smith | 839896e | 2015-07-24 17:24:22 +0100 | [diff] [blame] | 419 | return NULL; |
Colin Ian King | fc878ef | 2016-09-29 18:45:05 +0100 | [diff] [blame] | 420 | } |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 421 | |
| 422 | buf_addr += period_len; |
| 423 | |
| 424 | /* |
| 425 | * Set the link bit to indicate that the controller should |
| 426 | * automatically proceed to the next descriptor. In |
| 427 | * jz4780_dma_begin(), this will be cleared if we need to issue |
| 428 | * an interrupt after each period. |
| 429 | */ |
| 430 | desc->desc[i].dcm |= JZ_DMA_DCM_TIE | JZ_DMA_DCM_LINK; |
| 431 | |
| 432 | /* |
| 433 | * The upper 8 bits of the DTC field in the descriptor must be |
| 434 | * set to (offset from descriptor base of next descriptor >> 4). |
| 435 | * If this is the last descriptor, link it back to the first, |
| 436 | * i.e. leave offset set to 0, otherwise point to the next one. |
| 437 | */ |
| 438 | if (i != (periods - 1)) { |
| 439 | desc->desc[i].dtc |= |
| 440 | (((i + 1) * sizeof(*desc->desc)) >> 4) << 24; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | return vchan_tx_prep(&jzchan->vchan, &desc->vdesc, flags); |
| 445 | } |
| 446 | |
Vinod Koul | 4f5db8c | 2016-09-02 15:27:55 +0530 | [diff] [blame] | 447 | static struct dma_async_tx_descriptor *jz4780_dma_prep_dma_memcpy( |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 448 | struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, |
| 449 | size_t len, unsigned long flags) |
| 450 | { |
| 451 | struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan); |
| 452 | struct jz4780_dma_desc *desc; |
| 453 | uint32_t tsz; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 454 | |
| 455 | desc = jz4780_dma_desc_alloc(jzchan, 1, DMA_MEMCPY); |
| 456 | if (!desc) |
| 457 | return NULL; |
| 458 | |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 459 | tsz = jz4780_dma_transfer_size(jzchan, dest | src | len, |
Alex Smith | dc578f3 | 2015-07-24 17:24:21 +0100 | [diff] [blame] | 460 | &jzchan->transfer_shift); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 461 | |
Paul Cercueil | 5eed7d8 | 2018-08-29 23:32:47 +0200 | [diff] [blame] | 462 | jzchan->transfer_type = JZ_DMA_DRT_AUTO; |
| 463 | |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 464 | desc->desc[0].dsa = src; |
| 465 | desc->desc[0].dta = dest; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 466 | desc->desc[0].dcm = JZ_DMA_DCM_TIE | JZ_DMA_DCM_SAI | JZ_DMA_DCM_DAI | |
| 467 | tsz << JZ_DMA_DCM_TSZ_SHIFT | |
| 468 | JZ_DMA_WIDTH_32_BIT << JZ_DMA_DCM_SP_SHIFT | |
| 469 | JZ_DMA_WIDTH_32_BIT << JZ_DMA_DCM_DP_SHIFT; |
Alex Smith | 839896e | 2015-07-24 17:24:22 +0100 | [diff] [blame] | 470 | desc->desc[0].dtc = len >> jzchan->transfer_shift; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 471 | |
| 472 | return vchan_tx_prep(&jzchan->vchan, &desc->vdesc, flags); |
| 473 | } |
| 474 | |
| 475 | static void jz4780_dma_begin(struct jz4780_dma_chan *jzchan) |
| 476 | { |
| 477 | struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan); |
| 478 | struct virt_dma_desc *vdesc; |
| 479 | unsigned int i; |
| 480 | dma_addr_t desc_phys; |
| 481 | |
| 482 | if (!jzchan->desc) { |
| 483 | vdesc = vchan_next_desc(&jzchan->vchan); |
| 484 | if (!vdesc) |
| 485 | return; |
| 486 | |
| 487 | list_del(&vdesc->node); |
| 488 | |
| 489 | jzchan->desc = to_jz4780_dma_desc(vdesc); |
| 490 | jzchan->curr_hwdesc = 0; |
| 491 | |
| 492 | if (jzchan->desc->type == DMA_CYCLIC && vdesc->tx.callback) { |
| 493 | /* |
| 494 | * The DMA controller doesn't support triggering an |
| 495 | * interrupt after processing each descriptor, only |
| 496 | * after processing an entire terminated list of |
| 497 | * descriptors. For a cyclic DMA setup the list of |
| 498 | * descriptors is not terminated so we can never get an |
| 499 | * interrupt. |
| 500 | * |
| 501 | * If the user requested a callback for a cyclic DMA |
| 502 | * setup then we workaround this hardware limitation |
| 503 | * here by degrading to a set of unlinked descriptors |
| 504 | * which we will submit in sequence in response to the |
| 505 | * completion of processing the previous descriptor. |
| 506 | */ |
| 507 | for (i = 0; i < jzchan->desc->count; i++) |
| 508 | jzchan->desc->desc[i].dcm &= ~JZ_DMA_DCM_LINK; |
| 509 | } |
| 510 | } else { |
| 511 | /* |
| 512 | * There is an existing transfer, therefore this must be one |
| 513 | * for which we unlinked the descriptors above. Advance to the |
| 514 | * next one in the list. |
| 515 | */ |
| 516 | jzchan->curr_hwdesc = |
| 517 | (jzchan->curr_hwdesc + 1) % jzchan->desc->count; |
| 518 | } |
| 519 | |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 520 | /* Enable the channel's clock. */ |
| 521 | jz4780_dma_chan_enable(jzdma, jzchan->id); |
| 522 | |
Paul Cercueil | 5eed7d8 | 2018-08-29 23:32:47 +0200 | [diff] [blame] | 523 | /* Use 4-word descriptors. */ |
| 524 | jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DCS, 0); |
| 525 | |
| 526 | /* Set transfer type. */ |
| 527 | jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DRT, |
| 528 | jzchan->transfer_type); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 529 | |
Daniel Silsby | 9e4e3a4 | 2018-08-29 23:32:55 +0200 | [diff] [blame] | 530 | /* |
| 531 | * Set the transfer count. This is redundant for a descriptor-driven |
| 532 | * transfer. However, there can be a delay between the transfer start |
| 533 | * time and when DTCn reg contains the new transfer count. Setting |
| 534 | * it explicitly ensures residue is computed correctly at all times. |
| 535 | */ |
| 536 | jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DTC, |
| 537 | jzchan->desc->desc[jzchan->curr_hwdesc].dtc); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 538 | |
| 539 | /* Write descriptor address and initiate descriptor fetch. */ |
| 540 | desc_phys = jzchan->desc->desc_phys + |
| 541 | (jzchan->curr_hwdesc * sizeof(*jzchan->desc->desc)); |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 542 | jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DDA, desc_phys); |
| 543 | jz4780_dma_ctrl_writel(jzdma, JZ_DMA_REG_DDRS, BIT(jzchan->id)); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 544 | |
| 545 | /* Enable the channel. */ |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 546 | jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DCS, |
Paul Cercueil | 5eed7d8 | 2018-08-29 23:32:47 +0200 | [diff] [blame] | 547 | JZ_DMA_DCS_CTE); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | static void jz4780_dma_issue_pending(struct dma_chan *chan) |
| 551 | { |
| 552 | struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan); |
| 553 | unsigned long flags; |
| 554 | |
| 555 | spin_lock_irqsave(&jzchan->vchan.lock, flags); |
| 556 | |
| 557 | if (vchan_issue_pending(&jzchan->vchan) && !jzchan->desc) |
| 558 | jz4780_dma_begin(jzchan); |
| 559 | |
| 560 | spin_unlock_irqrestore(&jzchan->vchan.lock, flags); |
| 561 | } |
| 562 | |
Alex Smith | 46fa5168 | 2015-07-24 17:24:20 +0100 | [diff] [blame] | 563 | static int jz4780_dma_terminate_all(struct dma_chan *chan) |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 564 | { |
Alex Smith | 46fa5168 | 2015-07-24 17:24:20 +0100 | [diff] [blame] | 565 | struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 566 | struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan); |
| 567 | unsigned long flags; |
| 568 | LIST_HEAD(head); |
| 569 | |
| 570 | spin_lock_irqsave(&jzchan->vchan.lock, flags); |
| 571 | |
| 572 | /* Clear the DMA status and stop the transfer. */ |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 573 | jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DCS, 0); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 574 | if (jzchan->desc) { |
Peter Ujfalusi | f0dd52c | 2017-11-14 16:32:08 +0200 | [diff] [blame] | 575 | vchan_terminate_vdesc(&jzchan->desc->vdesc); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 576 | jzchan->desc = NULL; |
| 577 | } |
| 578 | |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 579 | jz4780_dma_chan_disable(jzdma, jzchan->id); |
| 580 | |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 581 | vchan_get_all_descriptors(&jzchan->vchan, &head); |
| 582 | |
| 583 | spin_unlock_irqrestore(&jzchan->vchan.lock, flags); |
| 584 | |
| 585 | vchan_dma_desc_free_list(&jzchan->vchan, &head); |
| 586 | return 0; |
| 587 | } |
| 588 | |
Peter Ujfalusi | f0dd52c | 2017-11-14 16:32:08 +0200 | [diff] [blame] | 589 | static void jz4780_dma_synchronize(struct dma_chan *chan) |
| 590 | { |
| 591 | struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan); |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 592 | struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan); |
Peter Ujfalusi | f0dd52c | 2017-11-14 16:32:08 +0200 | [diff] [blame] | 593 | |
| 594 | vchan_synchronize(&jzchan->vchan); |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 595 | jz4780_dma_chan_disable(jzdma, jzchan->id); |
Peter Ujfalusi | f0dd52c | 2017-11-14 16:32:08 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Alex Smith | 46fa5168 | 2015-07-24 17:24:20 +0100 | [diff] [blame] | 598 | static int jz4780_dma_config(struct dma_chan *chan, |
| 599 | struct dma_slave_config *config) |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 600 | { |
Alex Smith | 46fa5168 | 2015-07-24 17:24:20 +0100 | [diff] [blame] | 601 | struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan); |
| 602 | |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 603 | if ((config->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES) |
| 604 | || (config->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES)) |
| 605 | return -EINVAL; |
| 606 | |
| 607 | /* Copy the reset of the slave configuration, it is used later. */ |
| 608 | memcpy(&jzchan->config, config, sizeof(jzchan->config)); |
| 609 | |
| 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | static size_t jz4780_dma_desc_residue(struct jz4780_dma_chan *jzchan, |
| 614 | struct jz4780_dma_desc *desc, unsigned int next_sg) |
| 615 | { |
| 616 | struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan); |
Daniel Silsby | f3c045d | 2018-08-29 23:32:54 +0200 | [diff] [blame] | 617 | unsigned int count = 0; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 618 | unsigned int i; |
| 619 | |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 620 | for (i = next_sg; i < desc->count; i++) |
Daniel Silsby | f3c045d | 2018-08-29 23:32:54 +0200 | [diff] [blame] | 621 | count += desc->desc[i].dtc & GENMASK(23, 0); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 622 | |
Daniel Silsby | f3c045d | 2018-08-29 23:32:54 +0200 | [diff] [blame] | 623 | if (next_sg != 0) |
| 624 | count += jz4780_dma_chn_readl(jzdma, jzchan->id, |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 625 | JZ_DMA_REG_DTC); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 626 | |
Daniel Silsby | f3c045d | 2018-08-29 23:32:54 +0200 | [diff] [blame] | 627 | return count << jzchan->transfer_shift; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | static enum dma_status jz4780_dma_tx_status(struct dma_chan *chan, |
| 631 | dma_cookie_t cookie, struct dma_tx_state *txstate) |
| 632 | { |
| 633 | struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan); |
| 634 | struct virt_dma_desc *vdesc; |
| 635 | enum dma_status status; |
| 636 | unsigned long flags; |
Daniel Silsby | 1f0b0f2 | 2018-08-29 23:32:57 +0200 | [diff] [blame] | 637 | unsigned long residue = 0; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 638 | |
| 639 | status = dma_cookie_status(chan, cookie, txstate); |
| 640 | if ((status == DMA_COMPLETE) || (txstate == NULL)) |
| 641 | return status; |
| 642 | |
| 643 | spin_lock_irqsave(&jzchan->vchan.lock, flags); |
| 644 | |
| 645 | vdesc = vchan_find_desc(&jzchan->vchan, cookie); |
| 646 | if (vdesc) { |
| 647 | /* On the issued list, so hasn't been processed yet */ |
Daniel Silsby | 1f0b0f2 | 2018-08-29 23:32:57 +0200 | [diff] [blame] | 648 | residue = jz4780_dma_desc_residue(jzchan, |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 649 | to_jz4780_dma_desc(vdesc), 0); |
| 650 | } else if (cookie == jzchan->desc->vdesc.tx.cookie) { |
Daniel Silsby | 1f0b0f2 | 2018-08-29 23:32:57 +0200 | [diff] [blame] | 651 | residue = jz4780_dma_desc_residue(jzchan, jzchan->desc, |
Daniel Silsby | 83ef4fb | 2018-08-29 23:32:56 +0200 | [diff] [blame] | 652 | jzchan->curr_hwdesc + 1); |
Daniel Silsby | 1f0b0f2 | 2018-08-29 23:32:57 +0200 | [diff] [blame] | 653 | } |
| 654 | dma_set_residue(txstate, residue); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 655 | |
| 656 | if (vdesc && jzchan->desc && vdesc == &jzchan->desc->vdesc |
Alex Smith | 839896e | 2015-07-24 17:24:22 +0100 | [diff] [blame] | 657 | && jzchan->desc->status & (JZ_DMA_DCS_AR | JZ_DMA_DCS_HLT)) |
| 658 | status = DMA_ERROR; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 659 | |
| 660 | spin_unlock_irqrestore(&jzchan->vchan.lock, flags); |
| 661 | return status; |
| 662 | } |
| 663 | |
| 664 | static void jz4780_dma_chan_irq(struct jz4780_dma_dev *jzdma, |
| 665 | struct jz4780_dma_chan *jzchan) |
| 666 | { |
| 667 | uint32_t dcs; |
| 668 | |
| 669 | spin_lock(&jzchan->vchan.lock); |
| 670 | |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 671 | dcs = jz4780_dma_chn_readl(jzdma, jzchan->id, JZ_DMA_REG_DCS); |
| 672 | jz4780_dma_chn_writel(jzdma, jzchan->id, JZ_DMA_REG_DCS, 0); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 673 | |
| 674 | if (dcs & JZ_DMA_DCS_AR) { |
| 675 | dev_warn(&jzchan->vchan.chan.dev->device, |
| 676 | "address error (DCS=0x%x)\n", dcs); |
| 677 | } |
| 678 | |
| 679 | if (dcs & JZ_DMA_DCS_HLT) { |
| 680 | dev_warn(&jzchan->vchan.chan.dev->device, |
| 681 | "channel halt (DCS=0x%x)\n", dcs); |
| 682 | } |
| 683 | |
| 684 | if (jzchan->desc) { |
| 685 | jzchan->desc->status = dcs; |
| 686 | |
| 687 | if ((dcs & (JZ_DMA_DCS_AR | JZ_DMA_DCS_HLT)) == 0) { |
| 688 | if (jzchan->desc->type == DMA_CYCLIC) { |
| 689 | vchan_cyclic_callback(&jzchan->desc->vdesc); |
| 690 | } else { |
| 691 | vchan_cookie_complete(&jzchan->desc->vdesc); |
| 692 | jzchan->desc = NULL; |
| 693 | } |
| 694 | |
| 695 | jz4780_dma_begin(jzchan); |
| 696 | } |
| 697 | } else { |
| 698 | dev_err(&jzchan->vchan.chan.dev->device, |
| 699 | "channel IRQ with no active transfer\n"); |
| 700 | } |
| 701 | |
| 702 | spin_unlock(&jzchan->vchan.lock); |
| 703 | } |
| 704 | |
| 705 | static irqreturn_t jz4780_dma_irq_handler(int irq, void *data) |
| 706 | { |
| 707 | struct jz4780_dma_dev *jzdma = data; |
| 708 | uint32_t pending, dmac; |
| 709 | int i; |
| 710 | |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 711 | pending = jz4780_dma_ctrl_readl(jzdma, JZ_DMA_REG_DIRQP); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 712 | |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 713 | for (i = 0; i < jzdma->soc_data->nb_channels; i++) { |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 714 | if (!(pending & (1<<i))) |
| 715 | continue; |
| 716 | |
| 717 | jz4780_dma_chan_irq(jzdma, &jzdma->chan[i]); |
| 718 | } |
| 719 | |
| 720 | /* Clear halt and address error status of all channels. */ |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 721 | dmac = jz4780_dma_ctrl_readl(jzdma, JZ_DMA_REG_DMAC); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 722 | dmac &= ~(JZ_DMA_DMAC_HLT | JZ_DMA_DMAC_AR); |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 723 | jz4780_dma_ctrl_writel(jzdma, JZ_DMA_REG_DMAC, dmac); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 724 | |
| 725 | /* Clear interrupt pending status. */ |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 726 | jz4780_dma_ctrl_writel(jzdma, JZ_DMA_REG_DIRQP, 0); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 727 | |
| 728 | return IRQ_HANDLED; |
| 729 | } |
| 730 | |
| 731 | static int jz4780_dma_alloc_chan_resources(struct dma_chan *chan) |
| 732 | { |
| 733 | struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan); |
| 734 | |
| 735 | jzchan->desc_pool = dma_pool_create(dev_name(&chan->dev->device), |
| 736 | chan->device->dev, |
| 737 | JZ_DMA_DESC_BLOCK_SIZE, |
| 738 | PAGE_SIZE, 0); |
| 739 | if (!jzchan->desc_pool) { |
| 740 | dev_err(&chan->dev->device, |
| 741 | "failed to allocate descriptor pool\n"); |
| 742 | return -ENOMEM; |
| 743 | } |
| 744 | |
| 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | static void jz4780_dma_free_chan_resources(struct dma_chan *chan) |
| 749 | { |
| 750 | struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan); |
| 751 | |
| 752 | vchan_free_chan_resources(&jzchan->vchan); |
| 753 | dma_pool_destroy(jzchan->desc_pool); |
| 754 | jzchan->desc_pool = NULL; |
| 755 | } |
| 756 | |
| 757 | static bool jz4780_dma_filter_fn(struct dma_chan *chan, void *param) |
| 758 | { |
| 759 | struct jz4780_dma_chan *jzchan = to_jz4780_dma_chan(chan); |
| 760 | struct jz4780_dma_dev *jzdma = jz4780_dma_chan_parent(jzchan); |
Alex Smith | 026fd40 | 2015-07-24 17:24:24 +0100 | [diff] [blame] | 761 | struct jz4780_dma_filter_data *data = param; |
| 762 | |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 763 | |
| 764 | if (data->channel > -1) { |
| 765 | if (data->channel != jzchan->id) |
| 766 | return false; |
| 767 | } else if (jzdma->chan_reserved & BIT(jzchan->id)) { |
| 768 | return false; |
| 769 | } |
| 770 | |
| 771 | jzchan->transfer_type = data->transfer_type; |
| 772 | |
| 773 | return true; |
| 774 | } |
| 775 | |
| 776 | static struct dma_chan *jz4780_of_dma_xlate(struct of_phandle_args *dma_spec, |
| 777 | struct of_dma *ofdma) |
| 778 | { |
| 779 | struct jz4780_dma_dev *jzdma = ofdma->of_dma_data; |
| 780 | dma_cap_mask_t mask = jzdma->dma_device.cap_mask; |
Alex Smith | 026fd40 | 2015-07-24 17:24:24 +0100 | [diff] [blame] | 781 | struct jz4780_dma_filter_data data; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 782 | |
| 783 | if (dma_spec->args_count != 2) |
| 784 | return NULL; |
| 785 | |
| 786 | data.transfer_type = dma_spec->args[0]; |
| 787 | data.channel = dma_spec->args[1]; |
| 788 | |
| 789 | if (data.channel > -1) { |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 790 | if (data.channel >= jzdma->soc_data->nb_channels) { |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 791 | dev_err(jzdma->dma_device.dev, |
| 792 | "device requested non-existent channel %u\n", |
| 793 | data.channel); |
| 794 | return NULL; |
| 795 | } |
| 796 | |
| 797 | /* Can only select a channel marked as reserved. */ |
| 798 | if (!(jzdma->chan_reserved & BIT(data.channel))) { |
| 799 | dev_err(jzdma->dma_device.dev, |
| 800 | "device requested unreserved channel %u\n", |
| 801 | data.channel); |
| 802 | return NULL; |
| 803 | } |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 804 | |
Alex Smith | d3273e1 | 2015-07-24 17:24:23 +0100 | [diff] [blame] | 805 | jzdma->chan[data.channel].transfer_type = data.transfer_type; |
| 806 | |
| 807 | return dma_get_slave_channel( |
| 808 | &jzdma->chan[data.channel].vchan.chan); |
| 809 | } else { |
Baolin Wang | c88ba7b | 2019-05-20 19:32:17 +0800 | [diff] [blame^] | 810 | return __dma_request_channel(&mask, jz4780_dma_filter_fn, &data, |
| 811 | ofdma->of_node); |
Alex Smith | d3273e1 | 2015-07-24 17:24:23 +0100 | [diff] [blame] | 812 | } |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | static int jz4780_dma_probe(struct platform_device *pdev) |
| 816 | { |
| 817 | struct device *dev = &pdev->dev; |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 818 | const struct jz4780_dma_soc_data *soc_data; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 819 | struct jz4780_dma_dev *jzdma; |
| 820 | struct jz4780_dma_chan *jzchan; |
| 821 | struct dma_device *dd; |
| 822 | struct resource *res; |
| 823 | int i, ret; |
| 824 | |
Paul Cercueil | 54f919a | 2018-08-29 23:32:44 +0200 | [diff] [blame] | 825 | if (!dev->of_node) { |
| 826 | dev_err(dev, "This driver must be probed from devicetree\n"); |
| 827 | return -EINVAL; |
| 828 | } |
| 829 | |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 830 | soc_data = device_get_match_data(dev); |
| 831 | if (!soc_data) |
| 832 | return -EINVAL; |
| 833 | |
Gustavo A. R. Silva | ed414d5 | 2018-12-24 00:52:17 -0600 | [diff] [blame] | 834 | jzdma = devm_kzalloc(dev, struct_size(jzdma, chan, |
| 835 | soc_data->nb_channels), GFP_KERNEL); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 836 | if (!jzdma) |
| 837 | return -ENOMEM; |
| 838 | |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 839 | jzdma->soc_data = soc_data; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 840 | platform_set_drvdata(pdev, jzdma); |
| 841 | |
| 842 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 843 | if (!res) { |
| 844 | dev_err(dev, "failed to get I/O memory\n"); |
| 845 | return -EINVAL; |
| 846 | } |
| 847 | |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 848 | jzdma->chn_base = devm_ioremap_resource(dev, res); |
| 849 | if (IS_ERR(jzdma->chn_base)) |
| 850 | return PTR_ERR(jzdma->chn_base); |
| 851 | |
| 852 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 853 | if (res) { |
| 854 | jzdma->ctrl_base = devm_ioremap_resource(dev, res); |
| 855 | if (IS_ERR(jzdma->ctrl_base)) |
| 856 | return PTR_ERR(jzdma->ctrl_base); |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 857 | } else if (soc_data->flags & JZ_SOC_DATA_ALLOW_LEGACY_DT) { |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 858 | /* |
| 859 | * On JZ4780, if the second memory resource was not supplied, |
| 860 | * assume we're using an old devicetree, and calculate the |
| 861 | * offset to the control registers. |
| 862 | */ |
| 863 | jzdma->ctrl_base = jzdma->chn_base + JZ4780_DMA_CTRL_OFFSET; |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 864 | } else { |
| 865 | dev_err(dev, "failed to get I/O memory\n"); |
| 866 | return -EINVAL; |
Paul Cercueil | 3363358 | 2018-08-29 23:32:46 +0200 | [diff] [blame] | 867 | } |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 868 | |
Alex Smith | 839896e | 2015-07-24 17:24:22 +0100 | [diff] [blame] | 869 | ret = platform_get_irq(pdev, 0); |
| 870 | if (ret < 0) { |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 871 | dev_err(dev, "failed to get IRQ: %d\n", ret); |
Alex Smith | 839896e | 2015-07-24 17:24:22 +0100 | [diff] [blame] | 872 | return ret; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Alex Smith | 839896e | 2015-07-24 17:24:22 +0100 | [diff] [blame] | 875 | jzdma->irq = ret; |
| 876 | |
Alex Smith | d509a83 | 2015-07-24 17:24:26 +0100 | [diff] [blame] | 877 | ret = request_irq(jzdma->irq, jz4780_dma_irq_handler, 0, dev_name(dev), |
| 878 | jzdma); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 879 | if (ret) { |
| 880 | dev_err(dev, "failed to request IRQ %u!\n", jzdma->irq); |
Alex Smith | 839896e | 2015-07-24 17:24:22 +0100 | [diff] [blame] | 881 | return ret; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | jzdma->clk = devm_clk_get(dev, NULL); |
| 885 | if (IS_ERR(jzdma->clk)) { |
| 886 | dev_err(dev, "failed to get clock\n"); |
Alex Smith | d509a83 | 2015-07-24 17:24:26 +0100 | [diff] [blame] | 887 | ret = PTR_ERR(jzdma->clk); |
| 888 | goto err_free_irq; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | clk_prepare_enable(jzdma->clk); |
| 892 | |
| 893 | /* Property is optional, if it doesn't exist the value will remain 0. */ |
| 894 | of_property_read_u32_index(dev->of_node, "ingenic,reserved-channels", |
| 895 | 0, &jzdma->chan_reserved); |
| 896 | |
| 897 | dd = &jzdma->dma_device; |
| 898 | |
| 899 | dma_cap_set(DMA_MEMCPY, dd->cap_mask); |
| 900 | dma_cap_set(DMA_SLAVE, dd->cap_mask); |
| 901 | dma_cap_set(DMA_CYCLIC, dd->cap_mask); |
| 902 | |
| 903 | dd->dev = dev; |
Maxime Ripard | 77a68e5 | 2015-07-20 10:41:32 +0200 | [diff] [blame] | 904 | dd->copy_align = DMAENGINE_ALIGN_4_BYTES; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 905 | dd->device_alloc_chan_resources = jz4780_dma_alloc_chan_resources; |
| 906 | dd->device_free_chan_resources = jz4780_dma_free_chan_resources; |
| 907 | dd->device_prep_slave_sg = jz4780_dma_prep_slave_sg; |
| 908 | dd->device_prep_dma_cyclic = jz4780_dma_prep_dma_cyclic; |
| 909 | dd->device_prep_dma_memcpy = jz4780_dma_prep_dma_memcpy; |
Alex Smith | 46fa5168 | 2015-07-24 17:24:20 +0100 | [diff] [blame] | 910 | dd->device_config = jz4780_dma_config; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 911 | dd->device_terminate_all = jz4780_dma_terminate_all; |
Peter Ujfalusi | f0dd52c | 2017-11-14 16:32:08 +0200 | [diff] [blame] | 912 | dd->device_synchronize = jz4780_dma_synchronize; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 913 | dd->device_tx_status = jz4780_dma_tx_status; |
| 914 | dd->device_issue_pending = jz4780_dma_issue_pending; |
| 915 | dd->src_addr_widths = JZ_DMA_BUSWIDTHS; |
| 916 | dd->dst_addr_widths = JZ_DMA_BUSWIDTHS; |
| 917 | dd->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); |
| 918 | dd->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; |
| 919 | |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 920 | /* |
| 921 | * Enable DMA controller, mark all channels as not programmable. |
| 922 | * Also set the FMSC bit - it increases MSC performance, so it makes |
| 923 | * little sense not to enable it. |
| 924 | */ |
Paul Cercueil | 17a8e30 | 2018-08-29 23:32:52 +0200 | [diff] [blame] | 925 | jz4780_dma_ctrl_writel(jzdma, JZ_DMA_REG_DMAC, JZ_DMA_DMAC_DMAE | |
| 926 | JZ_DMA_DMAC_FAIC | JZ_DMA_DMAC_FMSC); |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 927 | |
| 928 | if (soc_data->flags & JZ_SOC_DATA_PROGRAMMABLE_DMA) |
| 929 | jz4780_dma_ctrl_writel(jzdma, JZ_DMA_REG_DMACP, 0); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 930 | |
| 931 | INIT_LIST_HEAD(&dd->channels); |
| 932 | |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 933 | for (i = 0; i < soc_data->nb_channels; i++) { |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 934 | jzchan = &jzdma->chan[i]; |
| 935 | jzchan->id = i; |
| 936 | |
| 937 | vchan_init(&jzchan->vchan, dd); |
| 938 | jzchan->vchan.desc_free = jz4780_dma_desc_free; |
| 939 | } |
| 940 | |
Huang Shijie | 0f5a5e5 | 2018-08-06 16:52:28 +0800 | [diff] [blame] | 941 | ret = dmaenginem_async_device_register(dd); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 942 | if (ret) { |
| 943 | dev_err(dev, "failed to register device\n"); |
| 944 | goto err_disable_clk; |
| 945 | } |
| 946 | |
| 947 | /* Register with OF DMA helpers. */ |
| 948 | ret = of_dma_controller_register(dev->of_node, jz4780_of_dma_xlate, |
| 949 | jzdma); |
| 950 | if (ret) { |
| 951 | dev_err(dev, "failed to register OF DMA controller\n"); |
Huang Shijie | 0f5a5e5 | 2018-08-06 16:52:28 +0800 | [diff] [blame] | 952 | goto err_disable_clk; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | dev_info(dev, "JZ4780 DMA controller initialised\n"); |
| 956 | return 0; |
| 957 | |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 958 | err_disable_clk: |
| 959 | clk_disable_unprepare(jzdma->clk); |
Alex Smith | d509a83 | 2015-07-24 17:24:26 +0100 | [diff] [blame] | 960 | |
| 961 | err_free_irq: |
| 962 | free_irq(jzdma->irq, jzdma); |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 963 | return ret; |
| 964 | } |
| 965 | |
| 966 | static int jz4780_dma_remove(struct platform_device *pdev) |
| 967 | { |
| 968 | struct jz4780_dma_dev *jzdma = platform_get_drvdata(pdev); |
Alex Smith | ae9c02b | 2015-07-24 17:24:27 +0100 | [diff] [blame] | 969 | int i; |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 970 | |
| 971 | of_dma_controller_free(pdev->dev.of_node); |
Alex Smith | ae9c02b | 2015-07-24 17:24:27 +0100 | [diff] [blame] | 972 | |
Alex Smith | d509a83 | 2015-07-24 17:24:26 +0100 | [diff] [blame] | 973 | free_irq(jzdma->irq, jzdma); |
Alex Smith | ae9c02b | 2015-07-24 17:24:27 +0100 | [diff] [blame] | 974 | |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 975 | for (i = 0; i < jzdma->soc_data->nb_channels; i++) |
Alex Smith | ae9c02b | 2015-07-24 17:24:27 +0100 | [diff] [blame] | 976 | tasklet_kill(&jzdma->chan[i].vchan.task); |
| 977 | |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 978 | return 0; |
| 979 | } |
| 980 | |
Paul Cercueil | ffaaa8c | 2018-08-29 23:32:50 +0200 | [diff] [blame] | 981 | static const struct jz4780_dma_soc_data jz4740_dma_soc_data = { |
| 982 | .nb_channels = 6, |
| 983 | .transfer_ord_max = 5, |
| 984 | }; |
| 985 | |
Paul Cercueil | ae9156b | 2018-08-29 23:32:51 +0200 | [diff] [blame] | 986 | static const struct jz4780_dma_soc_data jz4725b_dma_soc_data = { |
| 987 | .nb_channels = 6, |
| 988 | .transfer_ord_max = 5, |
| 989 | .flags = JZ_SOC_DATA_PER_CHAN_PM | JZ_SOC_DATA_NO_DCKES_DCKEC, |
| 990 | }; |
| 991 | |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 992 | static const struct jz4780_dma_soc_data jz4770_dma_soc_data = { |
| 993 | .nb_channels = 6, |
| 994 | .transfer_ord_max = 6, |
| 995 | .flags = JZ_SOC_DATA_PER_CHAN_PM, |
| 996 | }; |
| 997 | |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 998 | static const struct jz4780_dma_soc_data jz4780_dma_soc_data = { |
| 999 | .nb_channels = 32, |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 1000 | .transfer_ord_max = 7, |
| 1001 | .flags = JZ_SOC_DATA_ALLOW_LEGACY_DT | JZ_SOC_DATA_PROGRAMMABLE_DMA, |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 1002 | }; |
| 1003 | |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 1004 | static const struct of_device_id jz4780_dma_dt_match[] = { |
Paul Cercueil | ffaaa8c | 2018-08-29 23:32:50 +0200 | [diff] [blame] | 1005 | { .compatible = "ingenic,jz4740-dma", .data = &jz4740_dma_soc_data }, |
Paul Cercueil | ae9156b | 2018-08-29 23:32:51 +0200 | [diff] [blame] | 1006 | { .compatible = "ingenic,jz4725b-dma", .data = &jz4725b_dma_soc_data }, |
Paul Cercueil | 29870eb | 2018-08-29 23:32:49 +0200 | [diff] [blame] | 1007 | { .compatible = "ingenic,jz4770-dma", .data = &jz4770_dma_soc_data }, |
Paul Cercueil | 6147b03 | 2018-08-29 23:32:45 +0200 | [diff] [blame] | 1008 | { .compatible = "ingenic,jz4780-dma", .data = &jz4780_dma_soc_data }, |
Alex Smith | d894fc6 | 2015-03-18 16:16:36 +0000 | [diff] [blame] | 1009 | {}, |
| 1010 | }; |
| 1011 | MODULE_DEVICE_TABLE(of, jz4780_dma_dt_match); |
| 1012 | |
| 1013 | static struct platform_driver jz4780_dma_driver = { |
| 1014 | .probe = jz4780_dma_probe, |
| 1015 | .remove = jz4780_dma_remove, |
| 1016 | .driver = { |
| 1017 | .name = "jz4780-dma", |
| 1018 | .of_match_table = of_match_ptr(jz4780_dma_dt_match), |
| 1019 | }, |
| 1020 | }; |
| 1021 | |
| 1022 | static int __init jz4780_dma_init(void) |
| 1023 | { |
| 1024 | return platform_driver_register(&jz4780_dma_driver); |
| 1025 | } |
| 1026 | subsys_initcall(jz4780_dma_init); |
| 1027 | |
| 1028 | static void __exit jz4780_dma_exit(void) |
| 1029 | { |
| 1030 | platform_driver_unregister(&jz4780_dma_driver); |
| 1031 | } |
| 1032 | module_exit(jz4780_dma_exit); |
| 1033 | |
| 1034 | MODULE_AUTHOR("Alex Smith <alex@alex-smith.me.uk>"); |
| 1035 | MODULE_DESCRIPTION("Ingenic JZ4780 DMA controller driver"); |
| 1036 | MODULE_LICENSE("GPL"); |