Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1 | /* |
| 2 | * TI EDMA DMA engine driver |
| 3 | * |
| 4 | * Copyright 2012 Texas Instruments |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation version 2. |
| 9 | * |
| 10 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any |
| 11 | * kind, whether express or implied; without even the implied warranty |
| 12 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/dmaengine.h> |
| 17 | #include <linux/dma-mapping.h> |
Lad, Prabhakar | b7a4fd5 | 2015-02-04 13:03:27 +0000 | [diff] [blame] | 18 | #include <linux/edma.h> |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 19 | #include <linux/err.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/interrupt.h> |
| 22 | #include <linux/list.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/platform_device.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/spinlock.h> |
Peter Ujfalusi | ed64610 | 2014-07-31 13:12:38 +0300 | [diff] [blame] | 27 | #include <linux/of.h> |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 28 | |
Matt Porter | 3ad7a42 | 2013-03-06 11:15:31 -0500 | [diff] [blame] | 29 | #include <linux/platform_data/edma.h> |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 30 | |
| 31 | #include "dmaengine.h" |
| 32 | #include "virt-dma.h" |
| 33 | |
| 34 | /* |
| 35 | * This will go away when the private EDMA API is folded |
| 36 | * into this driver and the platform device(s) are |
| 37 | * instantiated in the arch code. We can only get away |
| 38 | * with this simplification because DA8XX may not be built |
| 39 | * in the same kernel image with other DaVinci parts. This |
| 40 | * avoids having to sprinkle dmaengine driver platform devices |
| 41 | * and data throughout all the existing board files. |
| 42 | */ |
| 43 | #ifdef CONFIG_ARCH_DAVINCI_DA8XX |
| 44 | #define EDMA_CTLRS 2 |
| 45 | #define EDMA_CHANS 32 |
| 46 | #else |
| 47 | #define EDMA_CTLRS 1 |
| 48 | #define EDMA_CHANS 64 |
| 49 | #endif /* CONFIG_ARCH_DAVINCI_DA8XX */ |
| 50 | |
Joel Fernandes | 2abd5f1 | 2013-09-23 18:05:15 -0500 | [diff] [blame] | 51 | /* |
| 52 | * Max of 20 segments per channel to conserve PaRAM slots |
| 53 | * Also note that MAX_NR_SG should be atleast the no.of periods |
| 54 | * that are required for ASoC, otherwise DMA prep calls will |
| 55 | * fail. Today davinci-pcm is the only user of this driver and |
| 56 | * requires atleast 17 slots, so we setup the default to 20. |
| 57 | */ |
| 58 | #define MAX_NR_SG 20 |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 59 | #define EDMA_MAX_SLOTS MAX_NR_SG |
| 60 | #define EDMA_DESCRIPTORS 16 |
| 61 | |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 62 | struct edma_pset { |
Thomas Gleixner | c2da234 | 2014-04-28 14:29:57 -0500 | [diff] [blame] | 63 | u32 len; |
| 64 | dma_addr_t addr; |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 65 | struct edmacc_param param; |
| 66 | }; |
| 67 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 68 | struct edma_desc { |
| 69 | struct virt_dma_desc vdesc; |
| 70 | struct list_head node; |
Thomas Gleixner | c2da234 | 2014-04-28 14:29:57 -0500 | [diff] [blame] | 71 | enum dma_transfer_direction direction; |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 72 | int cyclic; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 73 | int absync; |
| 74 | int pset_nr; |
Thomas Gleixner | 740b41f | 2014-04-28 14:34:11 -0500 | [diff] [blame] | 75 | struct edma_chan *echan; |
Joel Fernandes | 04361d8 | 2014-04-28 15:19:31 -0500 | [diff] [blame] | 76 | int processed; |
| 77 | |
| 78 | /* |
| 79 | * The following 4 elements are used for residue accounting. |
| 80 | * |
| 81 | * - processed_stat: the number of SG elements we have traversed |
| 82 | * so far to cover accounting. This is updated directly to processed |
| 83 | * during edma_callback and is always <= processed, because processed |
| 84 | * refers to the number of pending transfer (programmed to EDMA |
| 85 | * controller), where as processed_stat tracks number of transfers |
| 86 | * accounted for so far. |
| 87 | * |
| 88 | * - residue: The amount of bytes we have left to transfer for this desc |
| 89 | * |
| 90 | * - residue_stat: The residue in bytes of data we have covered |
| 91 | * so far for accounting. This is updated directly to residue |
| 92 | * during callbacks to keep it current. |
| 93 | * |
| 94 | * - sg_len: Tracks the length of the current intermediate transfer, |
| 95 | * this is required to update the residue during intermediate transfer |
| 96 | * completion callback. |
| 97 | */ |
| 98 | int processed_stat; |
| 99 | u32 sg_len; |
| 100 | u32 residue; |
| 101 | u32 residue_stat; |
| 102 | |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 103 | struct edma_pset pset[0]; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | struct edma_cc; |
| 107 | |
| 108 | struct edma_chan { |
| 109 | struct virt_dma_chan vchan; |
| 110 | struct list_head node; |
| 111 | struct edma_desc *edesc; |
| 112 | struct edma_cc *ecc; |
| 113 | int ch_num; |
| 114 | bool alloced; |
| 115 | int slot[EDMA_MAX_SLOTS]; |
Joel Fernandes | c5f4799 | 2013-08-29 18:05:43 -0500 | [diff] [blame] | 116 | int missed; |
Matt Porter | 661f7cb | 2013-01-10 13:41:04 -0500 | [diff] [blame] | 117 | struct dma_slave_config cfg; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | struct edma_cc { |
| 121 | int ctlr; |
| 122 | struct dma_device dma_slave; |
| 123 | struct edma_chan slave_chans[EDMA_CHANS]; |
| 124 | int num_slave_chans; |
| 125 | int dummy_slot; |
| 126 | }; |
| 127 | |
| 128 | static inline struct edma_cc *to_edma_cc(struct dma_device *d) |
| 129 | { |
| 130 | return container_of(d, struct edma_cc, dma_slave); |
| 131 | } |
| 132 | |
| 133 | static inline struct edma_chan *to_edma_chan(struct dma_chan *c) |
| 134 | { |
| 135 | return container_of(c, struct edma_chan, vchan.chan); |
| 136 | } |
| 137 | |
| 138 | static inline struct edma_desc |
| 139 | *to_edma_desc(struct dma_async_tx_descriptor *tx) |
| 140 | { |
| 141 | return container_of(tx, struct edma_desc, vdesc.tx); |
| 142 | } |
| 143 | |
| 144 | static void edma_desc_free(struct virt_dma_desc *vdesc) |
| 145 | { |
| 146 | kfree(container_of(vdesc, struct edma_desc, vdesc)); |
| 147 | } |
| 148 | |
| 149 | /* Dispatch a queued descriptor to the controller (caller holds lock) */ |
| 150 | static void edma_execute(struct edma_chan *echan) |
| 151 | { |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 152 | struct virt_dma_desc *vdesc; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 153 | struct edma_desc *edesc; |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 154 | struct device *dev = echan->vchan.chan.device->dev; |
| 155 | int i, j, left, nslots; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 156 | |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 157 | /* If either we processed all psets or we're still not started */ |
| 158 | if (!echan->edesc || |
| 159 | echan->edesc->pset_nr == echan->edesc->processed) { |
| 160 | /* Get next vdesc */ |
| 161 | vdesc = vchan_next_desc(&echan->vchan); |
| 162 | if (!vdesc) { |
| 163 | echan->edesc = NULL; |
| 164 | return; |
| 165 | } |
| 166 | list_del(&vdesc->node); |
| 167 | echan->edesc = to_edma_desc(&vdesc->tx); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 168 | } |
| 169 | |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 170 | edesc = echan->edesc; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 171 | |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 172 | /* Find out how many left */ |
| 173 | left = edesc->pset_nr - edesc->processed; |
| 174 | nslots = min(MAX_NR_SG, left); |
Thomas Gleixner | 740b41f | 2014-04-28 14:34:11 -0500 | [diff] [blame] | 175 | edesc->sg_len = 0; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 176 | |
| 177 | /* Write descriptor PaRAM set(s) */ |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 178 | for (i = 0; i < nslots; i++) { |
| 179 | j = i + edesc->processed; |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 180 | edma_write_slot(echan->slot[i], &edesc->pset[j].param); |
Thomas Gleixner | 740b41f | 2014-04-28 14:34:11 -0500 | [diff] [blame] | 181 | edesc->sg_len += edesc->pset[j].len; |
Peter Ujfalusi | 83bb312 | 2014-04-14 14:42:02 +0300 | [diff] [blame] | 182 | dev_vdbg(echan->vchan.chan.device->dev, |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 183 | "\n pset[%d]:\n" |
| 184 | " chnum\t%d\n" |
| 185 | " slot\t%d\n" |
| 186 | " opt\t%08x\n" |
| 187 | " src\t%08x\n" |
| 188 | " dst\t%08x\n" |
| 189 | " abcnt\t%08x\n" |
| 190 | " ccnt\t%08x\n" |
| 191 | " bidx\t%08x\n" |
| 192 | " cidx\t%08x\n" |
| 193 | " lkrld\t%08x\n", |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 194 | j, echan->ch_num, echan->slot[i], |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 195 | edesc->pset[j].param.opt, |
| 196 | edesc->pset[j].param.src, |
| 197 | edesc->pset[j].param.dst, |
| 198 | edesc->pset[j].param.a_b_cnt, |
| 199 | edesc->pset[j].param.ccnt, |
| 200 | edesc->pset[j].param.src_dst_bidx, |
| 201 | edesc->pset[j].param.src_dst_cidx, |
| 202 | edesc->pset[j].param.link_bcntrld); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 203 | /* Link to the previous slot if not the last set */ |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 204 | if (i != (nslots - 1)) |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 205 | edma_link(echan->slot[i], echan->slot[i+1]); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 206 | } |
| 207 | |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 208 | edesc->processed += nslots; |
| 209 | |
Joel Fernandes | b267b3b | 2013-08-29 18:05:44 -0500 | [diff] [blame] | 210 | /* |
| 211 | * If this is either the last set in a set of SG-list transactions |
| 212 | * then setup a link to the dummy slot, this results in all future |
| 213 | * events being absorbed and that's OK because we're done |
| 214 | */ |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 215 | if (edesc->processed == edesc->pset_nr) { |
| 216 | if (edesc->cyclic) |
| 217 | edma_link(echan->slot[nslots-1], echan->slot[1]); |
| 218 | else |
| 219 | edma_link(echan->slot[nslots-1], |
| 220 | echan->ecc->dummy_slot); |
| 221 | } |
Joel Fernandes | b267b3b | 2013-08-29 18:05:44 -0500 | [diff] [blame] | 222 | |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 223 | if (edesc->processed <= MAX_NR_SG) { |
Peter Ujfalusi | 9aac909 | 2014-04-24 10:29:50 +0300 | [diff] [blame] | 224 | dev_dbg(dev, "first transfer starting on channel %d\n", |
| 225 | echan->ch_num); |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 226 | edma_start(echan->ch_num); |
Sekhar Nori | 5fc68a6 | 2014-03-19 11:25:50 +0530 | [diff] [blame] | 227 | } else { |
| 228 | dev_dbg(dev, "chan: %d: completed %d elements, resuming\n", |
| 229 | echan->ch_num, edesc->processed); |
| 230 | edma_resume(echan->ch_num); |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 231 | } |
Joel Fernandes | c5f4799 | 2013-08-29 18:05:43 -0500 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * This happens due to setup times between intermediate transfers |
| 235 | * in long SG lists which have to be broken up into transfers of |
| 236 | * MAX_NR_SG |
| 237 | */ |
| 238 | if (echan->missed) { |
Peter Ujfalusi | 9aac909 | 2014-04-24 10:29:50 +0300 | [diff] [blame] | 239 | dev_dbg(dev, "missed event on channel %d\n", echan->ch_num); |
Joel Fernandes | c5f4799 | 2013-08-29 18:05:43 -0500 | [diff] [blame] | 240 | edma_clean_channel(echan->ch_num); |
| 241 | edma_stop(echan->ch_num); |
| 242 | edma_start(echan->ch_num); |
| 243 | edma_trigger_channel(echan->ch_num); |
| 244 | echan->missed = 0; |
| 245 | } |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 246 | } |
| 247 | |
Maxime Ripard | aa7c09b | 2014-11-17 14:42:13 +0100 | [diff] [blame] | 248 | static int edma_terminate_all(struct dma_chan *chan) |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 249 | { |
Maxime Ripard | aa7c09b | 2014-11-17 14:42:13 +0100 | [diff] [blame] | 250 | struct edma_chan *echan = to_edma_chan(chan); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 251 | unsigned long flags; |
| 252 | LIST_HEAD(head); |
| 253 | |
| 254 | spin_lock_irqsave(&echan->vchan.lock, flags); |
| 255 | |
| 256 | /* |
| 257 | * Stop DMA activity: we assume the callback will not be called |
| 258 | * after edma_dma() returns (even if it does, it will see |
| 259 | * echan->edesc is NULL and exit.) |
| 260 | */ |
| 261 | if (echan->edesc) { |
Peter Ujfalusi | 8e8805d | 2014-07-08 13:46:38 +0300 | [diff] [blame] | 262 | int cyclic = echan->edesc->cyclic; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 263 | echan->edesc = NULL; |
| 264 | edma_stop(echan->ch_num); |
Peter Ujfalusi | 8e8805d | 2014-07-08 13:46:38 +0300 | [diff] [blame] | 265 | /* Move the cyclic channel back to default queue */ |
| 266 | if (cyclic) |
| 267 | edma_assign_channel_eventq(echan->ch_num, |
| 268 | EVENTQ_DEFAULT); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | vchan_get_all_descriptors(&echan->vchan, &head); |
| 272 | spin_unlock_irqrestore(&echan->vchan.lock, flags); |
| 273 | vchan_dma_desc_free_list(&echan->vchan, &head); |
| 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
Maxime Ripard | aa7c09b | 2014-11-17 14:42:13 +0100 | [diff] [blame] | 278 | static int edma_slave_config(struct dma_chan *chan, |
Matt Porter | 661f7cb | 2013-01-10 13:41:04 -0500 | [diff] [blame] | 279 | struct dma_slave_config *cfg) |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 280 | { |
Maxime Ripard | aa7c09b | 2014-11-17 14:42:13 +0100 | [diff] [blame] | 281 | struct edma_chan *echan = to_edma_chan(chan); |
| 282 | |
Matt Porter | 661f7cb | 2013-01-10 13:41:04 -0500 | [diff] [blame] | 283 | if (cfg->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES || |
| 284 | cfg->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES) |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 285 | return -EINVAL; |
| 286 | |
Matt Porter | 661f7cb | 2013-01-10 13:41:04 -0500 | [diff] [blame] | 287 | memcpy(&echan->cfg, cfg, sizeof(echan->cfg)); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
Maxime Ripard | aa7c09b | 2014-11-17 14:42:13 +0100 | [diff] [blame] | 292 | static int edma_dma_pause(struct dma_chan *chan) |
Peter Ujfalusi | 72c7b67 | 2014-04-14 14:41:59 +0300 | [diff] [blame] | 293 | { |
Maxime Ripard | aa7c09b | 2014-11-17 14:42:13 +0100 | [diff] [blame] | 294 | struct edma_chan *echan = to_edma_chan(chan); |
| 295 | |
Peter Ujfalusi | 72c7b67 | 2014-04-14 14:41:59 +0300 | [diff] [blame] | 296 | /* Pause/Resume only allowed with cyclic mode */ |
Sebastian Andrzej Siewior | 639559a | 2014-09-29 20:06:45 +0200 | [diff] [blame] | 297 | if (!echan->edesc || !echan->edesc->cyclic) |
Peter Ujfalusi | 72c7b67 | 2014-04-14 14:41:59 +0300 | [diff] [blame] | 298 | return -EINVAL; |
| 299 | |
| 300 | edma_pause(echan->ch_num); |
| 301 | return 0; |
| 302 | } |
| 303 | |
Maxime Ripard | aa7c09b | 2014-11-17 14:42:13 +0100 | [diff] [blame] | 304 | static int edma_dma_resume(struct dma_chan *chan) |
Peter Ujfalusi | 72c7b67 | 2014-04-14 14:41:59 +0300 | [diff] [blame] | 305 | { |
Maxime Ripard | aa7c09b | 2014-11-17 14:42:13 +0100 | [diff] [blame] | 306 | struct edma_chan *echan = to_edma_chan(chan); |
| 307 | |
Peter Ujfalusi | 72c7b67 | 2014-04-14 14:41:59 +0300 | [diff] [blame] | 308 | /* Pause/Resume only allowed with cyclic mode */ |
| 309 | if (!echan->edesc->cyclic) |
| 310 | return -EINVAL; |
| 311 | |
| 312 | edma_resume(echan->ch_num); |
| 313 | return 0; |
| 314 | } |
| 315 | |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 316 | /* |
| 317 | * A PaRAM set configuration abstraction used by other modes |
| 318 | * @chan: Channel who's PaRAM set we're configuring |
| 319 | * @pset: PaRAM set to initialize and setup. |
| 320 | * @src_addr: Source address of the DMA |
| 321 | * @dst_addr: Destination address of the DMA |
| 322 | * @burst: In units of dev_width, how much to send |
| 323 | * @dev_width: How much is the dev_width |
| 324 | * @dma_length: Total length of the DMA transfer |
| 325 | * @direction: Direction of the transfer |
| 326 | */ |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 327 | static int edma_config_pset(struct dma_chan *chan, struct edma_pset *epset, |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 328 | dma_addr_t src_addr, dma_addr_t dst_addr, u32 burst, |
| 329 | enum dma_slave_buswidth dev_width, unsigned int dma_length, |
| 330 | enum dma_transfer_direction direction) |
| 331 | { |
| 332 | struct edma_chan *echan = to_edma_chan(chan); |
| 333 | struct device *dev = chan->device->dev; |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 334 | struct edmacc_param *param = &epset->param; |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 335 | int acnt, bcnt, ccnt, cidx; |
| 336 | int src_bidx, dst_bidx, src_cidx, dst_cidx; |
| 337 | int absync; |
| 338 | |
| 339 | acnt = dev_width; |
Peter Ujfalusi | b2b617d | 2014-04-14 14:41:58 +0300 | [diff] [blame] | 340 | |
| 341 | /* src/dst_maxburst == 0 is the same case as src/dst_maxburst == 1 */ |
| 342 | if (!burst) |
| 343 | burst = 1; |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 344 | /* |
| 345 | * If the maxburst is equal to the fifo width, use |
| 346 | * A-synced transfers. This allows for large contiguous |
| 347 | * buffer transfers using only one PaRAM set. |
| 348 | */ |
| 349 | if (burst == 1) { |
| 350 | /* |
| 351 | * For the A-sync case, bcnt and ccnt are the remainder |
| 352 | * and quotient respectively of the division of: |
| 353 | * (dma_length / acnt) by (SZ_64K -1). This is so |
| 354 | * that in case bcnt over flows, we have ccnt to use. |
| 355 | * Note: In A-sync tranfer only, bcntrld is used, but it |
| 356 | * only applies for sg_dma_len(sg) >= SZ_64K. |
| 357 | * In this case, the best way adopted is- bccnt for the |
| 358 | * first frame will be the remainder below. Then for |
| 359 | * every successive frame, bcnt will be SZ_64K-1. This |
| 360 | * is assured as bcntrld = 0xffff in end of function. |
| 361 | */ |
| 362 | absync = false; |
| 363 | ccnt = dma_length / acnt / (SZ_64K - 1); |
| 364 | bcnt = dma_length / acnt - ccnt * (SZ_64K - 1); |
| 365 | /* |
| 366 | * If bcnt is non-zero, we have a remainder and hence an |
| 367 | * extra frame to transfer, so increment ccnt. |
| 368 | */ |
| 369 | if (bcnt) |
| 370 | ccnt++; |
| 371 | else |
| 372 | bcnt = SZ_64K - 1; |
| 373 | cidx = acnt; |
| 374 | } else { |
| 375 | /* |
| 376 | * If maxburst is greater than the fifo address_width, |
| 377 | * use AB-synced transfers where A count is the fifo |
| 378 | * address_width and B count is the maxburst. In this |
| 379 | * case, we are limited to transfers of C count frames |
| 380 | * of (address_width * maxburst) where C count is limited |
| 381 | * to SZ_64K-1. This places an upper bound on the length |
| 382 | * of an SG segment that can be handled. |
| 383 | */ |
| 384 | absync = true; |
| 385 | bcnt = burst; |
| 386 | ccnt = dma_length / (acnt * bcnt); |
| 387 | if (ccnt > (SZ_64K - 1)) { |
| 388 | dev_err(dev, "Exceeded max SG segment size\n"); |
| 389 | return -EINVAL; |
| 390 | } |
| 391 | cidx = acnt * bcnt; |
| 392 | } |
| 393 | |
Thomas Gleixner | c2da234 | 2014-04-28 14:29:57 -0500 | [diff] [blame] | 394 | epset->len = dma_length; |
| 395 | |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 396 | if (direction == DMA_MEM_TO_DEV) { |
| 397 | src_bidx = acnt; |
| 398 | src_cidx = cidx; |
| 399 | dst_bidx = 0; |
| 400 | dst_cidx = 0; |
Thomas Gleixner | c2da234 | 2014-04-28 14:29:57 -0500 | [diff] [blame] | 401 | epset->addr = src_addr; |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 402 | } else if (direction == DMA_DEV_TO_MEM) { |
| 403 | src_bidx = 0; |
| 404 | src_cidx = 0; |
| 405 | dst_bidx = acnt; |
| 406 | dst_cidx = cidx; |
Thomas Gleixner | c2da234 | 2014-04-28 14:29:57 -0500 | [diff] [blame] | 407 | epset->addr = dst_addr; |
Joel Fernandes | 8cc3e30 | 2014-04-18 21:50:33 -0500 | [diff] [blame] | 408 | } else if (direction == DMA_MEM_TO_MEM) { |
| 409 | src_bidx = acnt; |
| 410 | src_cidx = cidx; |
| 411 | dst_bidx = acnt; |
| 412 | dst_cidx = cidx; |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 413 | } else { |
| 414 | dev_err(dev, "%s: direction not implemented yet\n", __func__); |
| 415 | return -EINVAL; |
| 416 | } |
| 417 | |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 418 | param->opt = EDMA_TCC(EDMA_CHAN_SLOT(echan->ch_num)); |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 419 | /* Configure A or AB synchronized transfers */ |
| 420 | if (absync) |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 421 | param->opt |= SYNCDIM; |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 422 | |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 423 | param->src = src_addr; |
| 424 | param->dst = dst_addr; |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 425 | |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 426 | param->src_dst_bidx = (dst_bidx << 16) | src_bidx; |
| 427 | param->src_dst_cidx = (dst_cidx << 16) | src_cidx; |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 428 | |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 429 | param->a_b_cnt = bcnt << 16 | acnt; |
| 430 | param->ccnt = ccnt; |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 431 | /* |
| 432 | * Only time when (bcntrld) auto reload is required is for |
| 433 | * A-sync case, and in this case, a requirement of reload value |
| 434 | * of SZ_64K-1 only is assured. 'link' is initially set to NULL |
| 435 | * and then later will be populated by edma_execute. |
| 436 | */ |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 437 | param->link_bcntrld = 0xffffffff; |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 438 | return absync; |
| 439 | } |
| 440 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 441 | static struct dma_async_tx_descriptor *edma_prep_slave_sg( |
| 442 | struct dma_chan *chan, struct scatterlist *sgl, |
| 443 | unsigned int sg_len, enum dma_transfer_direction direction, |
| 444 | unsigned long tx_flags, void *context) |
| 445 | { |
| 446 | struct edma_chan *echan = to_edma_chan(chan); |
| 447 | struct device *dev = chan->device->dev; |
| 448 | struct edma_desc *edesc; |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 449 | dma_addr_t src_addr = 0, dst_addr = 0; |
Matt Porter | 661f7cb | 2013-01-10 13:41:04 -0500 | [diff] [blame] | 450 | enum dma_slave_buswidth dev_width; |
| 451 | u32 burst; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 452 | struct scatterlist *sg; |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 453 | int i, nslots, ret; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 454 | |
| 455 | if (unlikely(!echan || !sgl || !sg_len)) |
| 456 | return NULL; |
| 457 | |
Matt Porter | 661f7cb | 2013-01-10 13:41:04 -0500 | [diff] [blame] | 458 | if (direction == DMA_DEV_TO_MEM) { |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 459 | src_addr = echan->cfg.src_addr; |
Matt Porter | 661f7cb | 2013-01-10 13:41:04 -0500 | [diff] [blame] | 460 | dev_width = echan->cfg.src_addr_width; |
| 461 | burst = echan->cfg.src_maxburst; |
| 462 | } else if (direction == DMA_MEM_TO_DEV) { |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 463 | dst_addr = echan->cfg.dst_addr; |
Matt Porter | 661f7cb | 2013-01-10 13:41:04 -0500 | [diff] [blame] | 464 | dev_width = echan->cfg.dst_addr_width; |
| 465 | burst = echan->cfg.dst_maxburst; |
| 466 | } else { |
Peter Ujfalusi | e6fad59 | 2014-04-14 14:42:05 +0300 | [diff] [blame] | 467 | dev_err(dev, "%s: bad direction: %d\n", __func__, direction); |
Matt Porter | 661f7cb | 2013-01-10 13:41:04 -0500 | [diff] [blame] | 468 | return NULL; |
| 469 | } |
| 470 | |
| 471 | if (dev_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) { |
Peter Ujfalusi | c594c89 | 2014-04-14 14:42:03 +0300 | [diff] [blame] | 472 | dev_err(dev, "%s: Undefined slave buswidth\n", __func__); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 473 | return NULL; |
| 474 | } |
| 475 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 476 | edesc = kzalloc(sizeof(*edesc) + sg_len * |
| 477 | sizeof(edesc->pset[0]), GFP_ATOMIC); |
| 478 | if (!edesc) { |
Peter Ujfalusi | c594c89 | 2014-04-14 14:42:03 +0300 | [diff] [blame] | 479 | dev_err(dev, "%s: Failed to allocate a descriptor\n", __func__); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 480 | return NULL; |
| 481 | } |
| 482 | |
| 483 | edesc->pset_nr = sg_len; |
Thomas Gleixner | b6205c3 | 2014-04-28 14:18:45 -0500 | [diff] [blame] | 484 | edesc->residue = 0; |
Thomas Gleixner | c2da234 | 2014-04-28 14:29:57 -0500 | [diff] [blame] | 485 | edesc->direction = direction; |
Thomas Gleixner | 740b41f | 2014-04-28 14:34:11 -0500 | [diff] [blame] | 486 | edesc->echan = echan; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 487 | |
Joel Fernandes | 6fbe24d | 2013-08-29 18:05:40 -0500 | [diff] [blame] | 488 | /* Allocate a PaRAM slot, if needed */ |
| 489 | nslots = min_t(unsigned, MAX_NR_SG, sg_len); |
| 490 | |
| 491 | for (i = 0; i < nslots; i++) { |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 492 | if (echan->slot[i] < 0) { |
| 493 | echan->slot[i] = |
| 494 | edma_alloc_slot(EDMA_CTLR(echan->ch_num), |
| 495 | EDMA_SLOT_ANY); |
| 496 | if (echan->slot[i] < 0) { |
Valentin Ilie | 4b6271a | 2013-10-24 16:14:22 +0300 | [diff] [blame] | 497 | kfree(edesc); |
Peter Ujfalusi | c594c89 | 2014-04-14 14:42:03 +0300 | [diff] [blame] | 498 | dev_err(dev, "%s: Failed to allocate slot\n", |
| 499 | __func__); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 500 | return NULL; |
| 501 | } |
| 502 | } |
Joel Fernandes | 6fbe24d | 2013-08-29 18:05:40 -0500 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /* Configure PaRAM sets for each SG */ |
| 506 | for_each_sg(sgl, sg, sg_len, i) { |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 507 | /* Get address for each SG */ |
| 508 | if (direction == DMA_DEV_TO_MEM) |
| 509 | dst_addr = sg_dma_address(sg); |
| 510 | else |
| 511 | src_addr = sg_dma_address(sg); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 512 | |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 513 | ret = edma_config_pset(chan, &edesc->pset[i], src_addr, |
| 514 | dst_addr, burst, dev_width, |
| 515 | sg_dma_len(sg), direction); |
Vinod Koul | b967aec | 2013-10-30 13:07:18 +0530 | [diff] [blame] | 516 | if (ret < 0) { |
| 517 | kfree(edesc); |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 518 | return NULL; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 519 | } |
| 520 | |
Joel Fernandes | fd00903 | 2013-09-23 18:05:13 -0500 | [diff] [blame] | 521 | edesc->absync = ret; |
Thomas Gleixner | b6205c3 | 2014-04-28 14:18:45 -0500 | [diff] [blame] | 522 | edesc->residue += sg_dma_len(sg); |
Joel Fernandes | 6fbe24d | 2013-08-29 18:05:40 -0500 | [diff] [blame] | 523 | |
| 524 | /* If this is the last in a current SG set of transactions, |
| 525 | enable interrupts so that next set is processed */ |
| 526 | if (!((i+1) % MAX_NR_SG)) |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 527 | edesc->pset[i].param.opt |= TCINTEN; |
Joel Fernandes | 6fbe24d | 2013-08-29 18:05:40 -0500 | [diff] [blame] | 528 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 529 | /* If this is the last set, enable completion interrupt flag */ |
| 530 | if (i == sg_len - 1) |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 531 | edesc->pset[i].param.opt |= TCINTEN; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 532 | } |
Thomas Gleixner | 740b41f | 2014-04-28 14:34:11 -0500 | [diff] [blame] | 533 | edesc->residue_stat = edesc->residue; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 534 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 535 | return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags); |
| 536 | } |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 537 | |
Lad, Prabhakar | b7a4fd5 | 2015-02-04 13:03:27 +0000 | [diff] [blame] | 538 | static struct dma_async_tx_descriptor *edma_prep_dma_memcpy( |
Joel Fernandes | 8cc3e30 | 2014-04-18 21:50:33 -0500 | [diff] [blame] | 539 | struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, |
| 540 | size_t len, unsigned long tx_flags) |
| 541 | { |
| 542 | int ret; |
| 543 | struct edma_desc *edesc; |
| 544 | struct device *dev = chan->device->dev; |
| 545 | struct edma_chan *echan = to_edma_chan(chan); |
| 546 | |
| 547 | if (unlikely(!echan || !len)) |
| 548 | return NULL; |
| 549 | |
| 550 | edesc = kzalloc(sizeof(*edesc) + sizeof(edesc->pset[0]), GFP_ATOMIC); |
| 551 | if (!edesc) { |
| 552 | dev_dbg(dev, "Failed to allocate a descriptor\n"); |
| 553 | return NULL; |
| 554 | } |
| 555 | |
| 556 | edesc->pset_nr = 1; |
| 557 | |
| 558 | ret = edma_config_pset(chan, &edesc->pset[0], src, dest, 1, |
| 559 | DMA_SLAVE_BUSWIDTH_4_BYTES, len, DMA_MEM_TO_MEM); |
| 560 | if (ret < 0) |
| 561 | return NULL; |
| 562 | |
| 563 | edesc->absync = ret; |
| 564 | |
| 565 | /* |
| 566 | * Enable intermediate transfer chaining to re-trigger channel |
| 567 | * on completion of every TR, and enable transfer-completion |
| 568 | * interrupt on completion of the whole transfer. |
| 569 | */ |
Joel Fernandes | b0cce4c | 2014-04-28 15:30:32 -0500 | [diff] [blame] | 570 | edesc->pset[0].param.opt |= ITCCHEN; |
| 571 | edesc->pset[0].param.opt |= TCINTEN; |
Joel Fernandes | 8cc3e30 | 2014-04-18 21:50:33 -0500 | [diff] [blame] | 572 | |
| 573 | return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags); |
| 574 | } |
| 575 | |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 576 | static struct dma_async_tx_descriptor *edma_prep_dma_cyclic( |
| 577 | struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len, |
| 578 | size_t period_len, enum dma_transfer_direction direction, |
Laurent Pinchart | 31c1e5a | 2014-08-01 12:20:10 +0200 | [diff] [blame] | 579 | unsigned long tx_flags) |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 580 | { |
| 581 | struct edma_chan *echan = to_edma_chan(chan); |
| 582 | struct device *dev = chan->device->dev; |
| 583 | struct edma_desc *edesc; |
| 584 | dma_addr_t src_addr, dst_addr; |
| 585 | enum dma_slave_buswidth dev_width; |
| 586 | u32 burst; |
| 587 | int i, ret, nslots; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 588 | |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 589 | if (unlikely(!echan || !buf_len || !period_len)) |
| 590 | return NULL; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 591 | |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 592 | if (direction == DMA_DEV_TO_MEM) { |
| 593 | src_addr = echan->cfg.src_addr; |
| 594 | dst_addr = buf_addr; |
| 595 | dev_width = echan->cfg.src_addr_width; |
| 596 | burst = echan->cfg.src_maxburst; |
| 597 | } else if (direction == DMA_MEM_TO_DEV) { |
| 598 | src_addr = buf_addr; |
| 599 | dst_addr = echan->cfg.dst_addr; |
| 600 | dev_width = echan->cfg.dst_addr_width; |
| 601 | burst = echan->cfg.dst_maxburst; |
| 602 | } else { |
Peter Ujfalusi | e6fad59 | 2014-04-14 14:42:05 +0300 | [diff] [blame] | 603 | dev_err(dev, "%s: bad direction: %d\n", __func__, direction); |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 604 | return NULL; |
| 605 | } |
| 606 | |
| 607 | if (dev_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) { |
Peter Ujfalusi | c594c89 | 2014-04-14 14:42:03 +0300 | [diff] [blame] | 608 | dev_err(dev, "%s: Undefined slave buswidth\n", __func__); |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 609 | return NULL; |
| 610 | } |
| 611 | |
| 612 | if (unlikely(buf_len % period_len)) { |
| 613 | dev_err(dev, "Period should be multiple of Buffer length\n"); |
| 614 | return NULL; |
| 615 | } |
| 616 | |
| 617 | nslots = (buf_len / period_len) + 1; |
| 618 | |
| 619 | /* |
| 620 | * Cyclic DMA users such as audio cannot tolerate delays introduced |
| 621 | * by cases where the number of periods is more than the maximum |
| 622 | * number of SGs the EDMA driver can handle at a time. For DMA types |
| 623 | * such as Slave SGs, such delays are tolerable and synchronized, |
| 624 | * but the synchronization is difficult to achieve with Cyclic and |
| 625 | * cannot be guaranteed, so we error out early. |
| 626 | */ |
| 627 | if (nslots > MAX_NR_SG) |
| 628 | return NULL; |
| 629 | |
| 630 | edesc = kzalloc(sizeof(*edesc) + nslots * |
| 631 | sizeof(edesc->pset[0]), GFP_ATOMIC); |
| 632 | if (!edesc) { |
Peter Ujfalusi | c594c89 | 2014-04-14 14:42:03 +0300 | [diff] [blame] | 633 | dev_err(dev, "%s: Failed to allocate a descriptor\n", __func__); |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 634 | return NULL; |
| 635 | } |
| 636 | |
| 637 | edesc->cyclic = 1; |
| 638 | edesc->pset_nr = nslots; |
Thomas Gleixner | 740b41f | 2014-04-28 14:34:11 -0500 | [diff] [blame] | 639 | edesc->residue = edesc->residue_stat = buf_len; |
Thomas Gleixner | c2da234 | 2014-04-28 14:29:57 -0500 | [diff] [blame] | 640 | edesc->direction = direction; |
Thomas Gleixner | 740b41f | 2014-04-28 14:34:11 -0500 | [diff] [blame] | 641 | edesc->echan = echan; |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 642 | |
Peter Ujfalusi | 83bb312 | 2014-04-14 14:42:02 +0300 | [diff] [blame] | 643 | dev_dbg(dev, "%s: channel=%d nslots=%d period_len=%zu buf_len=%zu\n", |
| 644 | __func__, echan->ch_num, nslots, period_len, buf_len); |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 645 | |
| 646 | for (i = 0; i < nslots; i++) { |
| 647 | /* Allocate a PaRAM slot, if needed */ |
| 648 | if (echan->slot[i] < 0) { |
| 649 | echan->slot[i] = |
| 650 | edma_alloc_slot(EDMA_CTLR(echan->ch_num), |
| 651 | EDMA_SLOT_ANY); |
| 652 | if (echan->slot[i] < 0) { |
Christian Engelmayer | e3ddc97 | 2013-12-30 20:48:39 +0100 | [diff] [blame] | 653 | kfree(edesc); |
Peter Ujfalusi | c594c89 | 2014-04-14 14:42:03 +0300 | [diff] [blame] | 654 | dev_err(dev, "%s: Failed to allocate slot\n", |
| 655 | __func__); |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 656 | return NULL; |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | if (i == nslots - 1) { |
| 661 | memcpy(&edesc->pset[i], &edesc->pset[0], |
| 662 | sizeof(edesc->pset[0])); |
| 663 | break; |
| 664 | } |
| 665 | |
| 666 | ret = edma_config_pset(chan, &edesc->pset[i], src_addr, |
| 667 | dst_addr, burst, dev_width, period_len, |
| 668 | direction); |
Christian Engelmayer | e3ddc97 | 2013-12-30 20:48:39 +0100 | [diff] [blame] | 669 | if (ret < 0) { |
| 670 | kfree(edesc); |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 671 | return NULL; |
Christian Engelmayer | e3ddc97 | 2013-12-30 20:48:39 +0100 | [diff] [blame] | 672 | } |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 673 | |
| 674 | if (direction == DMA_DEV_TO_MEM) |
| 675 | dst_addr += period_len; |
| 676 | else |
| 677 | src_addr += period_len; |
| 678 | |
Peter Ujfalusi | 83bb312 | 2014-04-14 14:42:02 +0300 | [diff] [blame] | 679 | dev_vdbg(dev, "%s: Configure period %d of buf:\n", __func__, i); |
| 680 | dev_vdbg(dev, |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 681 | "\n pset[%d]:\n" |
| 682 | " chnum\t%d\n" |
| 683 | " slot\t%d\n" |
| 684 | " opt\t%08x\n" |
| 685 | " src\t%08x\n" |
| 686 | " dst\t%08x\n" |
| 687 | " abcnt\t%08x\n" |
| 688 | " ccnt\t%08x\n" |
| 689 | " bidx\t%08x\n" |
| 690 | " cidx\t%08x\n" |
| 691 | " lkrld\t%08x\n", |
| 692 | i, echan->ch_num, echan->slot[i], |
Thomas Gleixner | b5088ad | 2014-04-28 14:23:55 -0500 | [diff] [blame] | 693 | edesc->pset[i].param.opt, |
| 694 | edesc->pset[i].param.src, |
| 695 | edesc->pset[i].param.dst, |
| 696 | edesc->pset[i].param.a_b_cnt, |
| 697 | edesc->pset[i].param.ccnt, |
| 698 | edesc->pset[i].param.src_dst_bidx, |
| 699 | edesc->pset[i].param.src_dst_cidx, |
| 700 | edesc->pset[i].param.link_bcntrld); |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 701 | |
| 702 | edesc->absync = ret; |
| 703 | |
| 704 | /* |
Peter Ujfalusi | a1f146f | 2014-07-16 15:29:21 +0300 | [diff] [blame] | 705 | * Enable period interrupt only if it is requested |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 706 | */ |
Peter Ujfalusi | a1f146f | 2014-07-16 15:29:21 +0300 | [diff] [blame] | 707 | if (tx_flags & DMA_PREP_INTERRUPT) |
| 708 | edesc->pset[i].param.opt |= TCINTEN; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 709 | } |
| 710 | |
Peter Ujfalusi | 8e8805d | 2014-07-08 13:46:38 +0300 | [diff] [blame] | 711 | /* Place the cyclic channel to highest priority queue */ |
| 712 | edma_assign_channel_eventq(echan->ch_num, EVENTQ_0); |
| 713 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 714 | return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags); |
| 715 | } |
| 716 | |
| 717 | static void edma_callback(unsigned ch_num, u16 ch_status, void *data) |
| 718 | { |
| 719 | struct edma_chan *echan = data; |
| 720 | struct device *dev = echan->vchan.chan.device->dev; |
| 721 | struct edma_desc *edesc; |
Joel Fernandes | c5f4799 | 2013-08-29 18:05:43 -0500 | [diff] [blame] | 722 | struct edmacc_param p; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 723 | |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 724 | edesc = echan->edesc; |
| 725 | |
| 726 | /* Pause the channel for non-cyclic */ |
| 727 | if (!edesc || (edesc && !edesc->cyclic)) |
| 728 | edma_pause(echan->ch_num); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 729 | |
| 730 | switch (ch_status) { |
Vinod Koul | db60d8d | 2013-10-30 18:22:30 +0530 | [diff] [blame] | 731 | case EDMA_DMA_COMPLETE: |
Joel Fernandes | 406efb1 | 2014-04-17 00:58:33 -0500 | [diff] [blame] | 732 | spin_lock(&echan->vchan.lock); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 733 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 734 | if (edesc) { |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 735 | if (edesc->cyclic) { |
| 736 | vchan_cyclic_callback(&edesc->vdesc); |
| 737 | } else if (edesc->processed == edesc->pset_nr) { |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 738 | dev_dbg(dev, "Transfer complete, stopping channel %d\n", ch_num); |
Thomas Gleixner | b6205c3 | 2014-04-28 14:18:45 -0500 | [diff] [blame] | 739 | edesc->residue = 0; |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 740 | edma_stop(echan->ch_num); |
| 741 | vchan_cookie_complete(&edesc->vdesc); |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 742 | edma_execute(echan); |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 743 | } else { |
| 744 | dev_dbg(dev, "Intermediate transfer complete on channel %d\n", ch_num); |
Thomas Gleixner | 740b41f | 2014-04-28 14:34:11 -0500 | [diff] [blame] | 745 | |
| 746 | /* Update statistics for tx_status */ |
| 747 | edesc->residue -= edesc->sg_len; |
| 748 | edesc->residue_stat = edesc->residue; |
| 749 | edesc->processed_stat = edesc->processed; |
| 750 | |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 751 | edma_execute(echan); |
Joel Fernandes | 5340706 | 2013-09-03 10:02:46 -0500 | [diff] [blame] | 752 | } |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 753 | } |
| 754 | |
Joel Fernandes | 406efb1 | 2014-04-17 00:58:33 -0500 | [diff] [blame] | 755 | spin_unlock(&echan->vchan.lock); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 756 | |
| 757 | break; |
Vinod Koul | db60d8d | 2013-10-30 18:22:30 +0530 | [diff] [blame] | 758 | case EDMA_DMA_CC_ERROR: |
Joel Fernandes | 406efb1 | 2014-04-17 00:58:33 -0500 | [diff] [blame] | 759 | spin_lock(&echan->vchan.lock); |
Joel Fernandes | c5f4799 | 2013-08-29 18:05:43 -0500 | [diff] [blame] | 760 | |
| 761 | edma_read_slot(EDMA_CHAN_SLOT(echan->slot[0]), &p); |
| 762 | |
| 763 | /* |
| 764 | * Issue later based on missed flag which will be sure |
| 765 | * to happen as: |
| 766 | * (1) we finished transmitting an intermediate slot and |
| 767 | * edma_execute is coming up. |
| 768 | * (2) or we finished current transfer and issue will |
| 769 | * call edma_execute. |
| 770 | * |
| 771 | * Important note: issuing can be dangerous here and |
| 772 | * lead to some nasty recursion when we are in a NULL |
| 773 | * slot. So we avoid doing so and set the missed flag. |
| 774 | */ |
| 775 | if (p.a_b_cnt == 0 && p.ccnt == 0) { |
| 776 | dev_dbg(dev, "Error occurred, looks like slot is null, just setting miss\n"); |
| 777 | echan->missed = 1; |
| 778 | } else { |
| 779 | /* |
| 780 | * The slot is already programmed but the event got |
| 781 | * missed, so its safe to issue it here. |
| 782 | */ |
| 783 | dev_dbg(dev, "Error occurred but slot is non-null, TRIGGERING\n"); |
| 784 | edma_clean_channel(echan->ch_num); |
| 785 | edma_stop(echan->ch_num); |
| 786 | edma_start(echan->ch_num); |
| 787 | edma_trigger_channel(echan->ch_num); |
| 788 | } |
| 789 | |
Joel Fernandes | 406efb1 | 2014-04-17 00:58:33 -0500 | [diff] [blame] | 790 | spin_unlock(&echan->vchan.lock); |
Joel Fernandes | c5f4799 | 2013-08-29 18:05:43 -0500 | [diff] [blame] | 791 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 792 | break; |
| 793 | default: |
| 794 | break; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | /* Alloc channel resources */ |
| 799 | static int edma_alloc_chan_resources(struct dma_chan *chan) |
| 800 | { |
| 801 | struct edma_chan *echan = to_edma_chan(chan); |
| 802 | struct device *dev = chan->device->dev; |
| 803 | int ret; |
| 804 | int a_ch_num; |
| 805 | LIST_HEAD(descs); |
| 806 | |
| 807 | a_ch_num = edma_alloc_channel(echan->ch_num, edma_callback, |
| 808 | chan, EVENTQ_DEFAULT); |
| 809 | |
| 810 | if (a_ch_num < 0) { |
| 811 | ret = -ENODEV; |
| 812 | goto err_no_chan; |
| 813 | } |
| 814 | |
| 815 | if (a_ch_num != echan->ch_num) { |
| 816 | dev_err(dev, "failed to allocate requested channel %u:%u\n", |
| 817 | EDMA_CTLR(echan->ch_num), |
| 818 | EDMA_CHAN_SLOT(echan->ch_num)); |
| 819 | ret = -ENODEV; |
| 820 | goto err_wrong_chan; |
| 821 | } |
| 822 | |
| 823 | echan->alloced = true; |
| 824 | echan->slot[0] = echan->ch_num; |
| 825 | |
Peter Ujfalusi | 9aac909 | 2014-04-24 10:29:50 +0300 | [diff] [blame] | 826 | dev_dbg(dev, "allocated channel %d for %u:%u\n", echan->ch_num, |
Ezequiel Garcia | 0e772c6 | 2013-12-13 11:06:18 -0300 | [diff] [blame] | 827 | EDMA_CTLR(echan->ch_num), EDMA_CHAN_SLOT(echan->ch_num)); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 828 | |
| 829 | return 0; |
| 830 | |
| 831 | err_wrong_chan: |
| 832 | edma_free_channel(a_ch_num); |
| 833 | err_no_chan: |
| 834 | return ret; |
| 835 | } |
| 836 | |
| 837 | /* Free channel resources */ |
| 838 | static void edma_free_chan_resources(struct dma_chan *chan) |
| 839 | { |
| 840 | struct edma_chan *echan = to_edma_chan(chan); |
| 841 | struct device *dev = chan->device->dev; |
| 842 | int i; |
| 843 | |
| 844 | /* Terminate transfers */ |
| 845 | edma_stop(echan->ch_num); |
| 846 | |
| 847 | vchan_free_chan_resources(&echan->vchan); |
| 848 | |
| 849 | /* Free EDMA PaRAM slots */ |
| 850 | for (i = 1; i < EDMA_MAX_SLOTS; i++) { |
| 851 | if (echan->slot[i] >= 0) { |
| 852 | edma_free_slot(echan->slot[i]); |
| 853 | echan->slot[i] = -1; |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | /* Free EDMA channel */ |
| 858 | if (echan->alloced) { |
| 859 | edma_free_channel(echan->ch_num); |
| 860 | echan->alloced = false; |
| 861 | } |
| 862 | |
Ezequiel Garcia | 0e772c6 | 2013-12-13 11:06:18 -0300 | [diff] [blame] | 863 | dev_dbg(dev, "freeing channel for %u\n", echan->ch_num); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | /* Send pending descriptor to hardware */ |
| 867 | static void edma_issue_pending(struct dma_chan *chan) |
| 868 | { |
| 869 | struct edma_chan *echan = to_edma_chan(chan); |
| 870 | unsigned long flags; |
| 871 | |
| 872 | spin_lock_irqsave(&echan->vchan.lock, flags); |
| 873 | if (vchan_issue_pending(&echan->vchan) && !echan->edesc) |
| 874 | edma_execute(echan); |
| 875 | spin_unlock_irqrestore(&echan->vchan.lock, flags); |
| 876 | } |
| 877 | |
Thomas Gleixner | 740b41f | 2014-04-28 14:34:11 -0500 | [diff] [blame] | 878 | static u32 edma_residue(struct edma_desc *edesc) |
| 879 | { |
| 880 | bool dst = edesc->direction == DMA_DEV_TO_MEM; |
| 881 | struct edma_pset *pset = edesc->pset; |
| 882 | dma_addr_t done, pos; |
| 883 | int i; |
| 884 | |
| 885 | /* |
| 886 | * We always read the dst/src position from the first RamPar |
| 887 | * pset. That's the one which is active now. |
| 888 | */ |
| 889 | pos = edma_get_position(edesc->echan->slot[0], dst); |
| 890 | |
| 891 | /* |
| 892 | * Cyclic is simple. Just subtract pset[0].addr from pos. |
| 893 | * |
| 894 | * We never update edesc->residue in the cyclic case, so we |
| 895 | * can tell the remaining room to the end of the circular |
| 896 | * buffer. |
| 897 | */ |
| 898 | if (edesc->cyclic) { |
| 899 | done = pos - pset->addr; |
| 900 | edesc->residue_stat = edesc->residue - done; |
| 901 | return edesc->residue_stat; |
| 902 | } |
| 903 | |
| 904 | /* |
| 905 | * For SG operation we catch up with the last processed |
| 906 | * status. |
| 907 | */ |
| 908 | pset += edesc->processed_stat; |
| 909 | |
| 910 | for (i = edesc->processed_stat; i < edesc->processed; i++, pset++) { |
| 911 | /* |
| 912 | * If we are inside this pset address range, we know |
| 913 | * this is the active one. Get the current delta and |
| 914 | * stop walking the psets. |
| 915 | */ |
| 916 | if (pos >= pset->addr && pos < pset->addr + pset->len) |
| 917 | return edesc->residue_stat - (pos - pset->addr); |
| 918 | |
| 919 | /* Otherwise mark it done and update residue_stat. */ |
| 920 | edesc->processed_stat++; |
| 921 | edesc->residue_stat -= pset->len; |
| 922 | } |
| 923 | return edesc->residue_stat; |
| 924 | } |
| 925 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 926 | /* Check request completion status */ |
| 927 | static enum dma_status edma_tx_status(struct dma_chan *chan, |
| 928 | dma_cookie_t cookie, |
| 929 | struct dma_tx_state *txstate) |
| 930 | { |
| 931 | struct edma_chan *echan = to_edma_chan(chan); |
| 932 | struct virt_dma_desc *vdesc; |
| 933 | enum dma_status ret; |
| 934 | unsigned long flags; |
| 935 | |
| 936 | ret = dma_cookie_status(chan, cookie, txstate); |
Vinod Koul | 9d386ec | 2013-10-16 13:42:15 +0530 | [diff] [blame] | 937 | if (ret == DMA_COMPLETE || !txstate) |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 938 | return ret; |
| 939 | |
| 940 | spin_lock_irqsave(&echan->vchan.lock, flags); |
Thomas Gleixner | de13593 | 2014-04-28 14:19:51 -0500 | [diff] [blame] | 941 | if (echan->edesc && echan->edesc->vdesc.tx.cookie == cookie) |
Thomas Gleixner | 740b41f | 2014-04-28 14:34:11 -0500 | [diff] [blame] | 942 | txstate->residue = edma_residue(echan->edesc); |
Thomas Gleixner | de13593 | 2014-04-28 14:19:51 -0500 | [diff] [blame] | 943 | else if ((vdesc = vchan_find_desc(&echan->vchan, cookie))) |
| 944 | txstate->residue = to_edma_desc(&vdesc->tx)->residue; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 945 | spin_unlock_irqrestore(&echan->vchan.lock, flags); |
| 946 | |
| 947 | return ret; |
| 948 | } |
| 949 | |
| 950 | static void __init edma_chan_init(struct edma_cc *ecc, |
| 951 | struct dma_device *dma, |
| 952 | struct edma_chan *echans) |
| 953 | { |
| 954 | int i, j; |
| 955 | |
| 956 | for (i = 0; i < EDMA_CHANS; i++) { |
| 957 | struct edma_chan *echan = &echans[i]; |
| 958 | echan->ch_num = EDMA_CTLR_CHAN(ecc->ctlr, i); |
| 959 | echan->ecc = ecc; |
| 960 | echan->vchan.desc_free = edma_desc_free; |
| 961 | |
| 962 | vchan_init(&echan->vchan, dma); |
| 963 | |
| 964 | INIT_LIST_HEAD(&echan->node); |
| 965 | for (j = 0; j < EDMA_MAX_SLOTS; j++) |
| 966 | echan->slot[j] = -1; |
| 967 | } |
| 968 | } |
| 969 | |
Peter Ujfalusi | 2c88ee6 | 2014-04-14 14:42:01 +0300 | [diff] [blame] | 970 | #define EDMA_DMA_BUSWIDTHS (BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \ |
| 971 | BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \ |
Peter Ujfalusi | e4a899d | 2014-07-03 07:51:56 +0300 | [diff] [blame] | 972 | BIT(DMA_SLAVE_BUSWIDTH_3_BYTES) | \ |
Peter Ujfalusi | 2c88ee6 | 2014-04-14 14:42:01 +0300 | [diff] [blame] | 973 | BIT(DMA_SLAVE_BUSWIDTH_4_BYTES)) |
| 974 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 975 | static void edma_dma_init(struct edma_cc *ecc, struct dma_device *dma, |
| 976 | struct device *dev) |
| 977 | { |
| 978 | dma->device_prep_slave_sg = edma_prep_slave_sg; |
Joel Fernandes | 50a9c70 | 2013-10-31 16:31:23 -0500 | [diff] [blame] | 979 | dma->device_prep_dma_cyclic = edma_prep_dma_cyclic; |
Joel Fernandes | 8cc3e30 | 2014-04-18 21:50:33 -0500 | [diff] [blame] | 980 | dma->device_prep_dma_memcpy = edma_prep_dma_memcpy; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 981 | dma->device_alloc_chan_resources = edma_alloc_chan_resources; |
| 982 | dma->device_free_chan_resources = edma_free_chan_resources; |
| 983 | dma->device_issue_pending = edma_issue_pending; |
| 984 | dma->device_tx_status = edma_tx_status; |
Maxime Ripard | aa7c09b | 2014-11-17 14:42:13 +0100 | [diff] [blame] | 985 | dma->device_config = edma_slave_config; |
| 986 | dma->device_pause = edma_dma_pause; |
| 987 | dma->device_resume = edma_dma_resume; |
| 988 | dma->device_terminate_all = edma_terminate_all; |
Maxime Ripard | 9f59cd0 | 2014-11-17 14:42:47 +0100 | [diff] [blame] | 989 | |
| 990 | dma->src_addr_widths = EDMA_DMA_BUSWIDTHS; |
| 991 | dma->dst_addr_widths = EDMA_DMA_BUSWIDTHS; |
| 992 | dma->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); |
| 993 | dma->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; |
| 994 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 995 | dma->dev = dev; |
| 996 | |
Joel Fernandes | 8cc3e30 | 2014-04-18 21:50:33 -0500 | [diff] [blame] | 997 | /* |
| 998 | * code using dma memcpy must make sure alignment of |
| 999 | * length is at dma->copy_align boundary. |
| 1000 | */ |
| 1001 | dma->copy_align = DMA_SLAVE_BUSWIDTH_4_BYTES; |
| 1002 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1003 | INIT_LIST_HEAD(&dma->channels); |
| 1004 | } |
| 1005 | |
Bill Pemberton | 463a1f8 | 2012-11-19 13:22:55 -0500 | [diff] [blame] | 1006 | static int edma_probe(struct platform_device *pdev) |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1007 | { |
| 1008 | struct edma_cc *ecc; |
| 1009 | int ret; |
| 1010 | |
Russell King | 94cb0e7 | 2013-06-27 13:45:16 +0100 | [diff] [blame] | 1011 | ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); |
| 1012 | if (ret) |
| 1013 | return ret; |
| 1014 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1015 | ecc = devm_kzalloc(&pdev->dev, sizeof(*ecc), GFP_KERNEL); |
| 1016 | if (!ecc) { |
| 1017 | dev_err(&pdev->dev, "Can't allocate controller\n"); |
| 1018 | return -ENOMEM; |
| 1019 | } |
| 1020 | |
| 1021 | ecc->ctlr = pdev->id; |
| 1022 | ecc->dummy_slot = edma_alloc_slot(ecc->ctlr, EDMA_SLOT_ANY); |
| 1023 | if (ecc->dummy_slot < 0) { |
| 1024 | dev_err(&pdev->dev, "Can't allocate PaRAM dummy slot\n"); |
Peter Ujfalusi | 04d537d | 2014-07-31 13:12:37 +0300 | [diff] [blame] | 1025 | return ecc->dummy_slot; |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | dma_cap_zero(ecc->dma_slave.cap_mask); |
| 1029 | dma_cap_set(DMA_SLAVE, ecc->dma_slave.cap_mask); |
Peter Ujfalusi | 232b223d | 2014-04-14 14:42:00 +0300 | [diff] [blame] | 1030 | dma_cap_set(DMA_CYCLIC, ecc->dma_slave.cap_mask); |
Joel Fernandes | 8cc3e30 | 2014-04-18 21:50:33 -0500 | [diff] [blame] | 1031 | dma_cap_set(DMA_MEMCPY, ecc->dma_slave.cap_mask); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1032 | |
| 1033 | edma_dma_init(ecc, &ecc->dma_slave, &pdev->dev); |
| 1034 | |
| 1035 | edma_chan_init(ecc, &ecc->dma_slave, ecc->slave_chans); |
| 1036 | |
| 1037 | ret = dma_async_device_register(&ecc->dma_slave); |
| 1038 | if (ret) |
| 1039 | goto err_reg1; |
| 1040 | |
| 1041 | platform_set_drvdata(pdev, ecc); |
| 1042 | |
| 1043 | dev_info(&pdev->dev, "TI EDMA DMA engine driver\n"); |
| 1044 | |
| 1045 | return 0; |
| 1046 | |
| 1047 | err_reg1: |
| 1048 | edma_free_slot(ecc->dummy_slot); |
| 1049 | return ret; |
| 1050 | } |
| 1051 | |
Greg Kroah-Hartman | 4bf27b8 | 2012-12-21 15:09:59 -0800 | [diff] [blame] | 1052 | static int edma_remove(struct platform_device *pdev) |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1053 | { |
| 1054 | struct device *dev = &pdev->dev; |
| 1055 | struct edma_cc *ecc = dev_get_drvdata(dev); |
| 1056 | |
| 1057 | dma_async_device_unregister(&ecc->dma_slave); |
| 1058 | edma_free_slot(ecc->dummy_slot); |
| 1059 | |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | static struct platform_driver edma_driver = { |
| 1064 | .probe = edma_probe, |
Bill Pemberton | a7d6e3e | 2012-11-19 13:20:04 -0500 | [diff] [blame] | 1065 | .remove = edma_remove, |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1066 | .driver = { |
| 1067 | .name = "edma-dma-engine", |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1068 | }, |
| 1069 | }; |
| 1070 | |
| 1071 | bool edma_filter_fn(struct dma_chan *chan, void *param) |
| 1072 | { |
| 1073 | if (chan->device->dev->driver == &edma_driver.driver) { |
| 1074 | struct edma_chan *echan = to_edma_chan(chan); |
| 1075 | unsigned ch_req = *(unsigned *)param; |
| 1076 | return ch_req == echan->ch_num; |
| 1077 | } |
| 1078 | return false; |
| 1079 | } |
| 1080 | EXPORT_SYMBOL(edma_filter_fn); |
| 1081 | |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1082 | static int edma_init(void) |
| 1083 | { |
Arnd Bergmann | 5305e4d | 2014-10-24 18:14:01 +0200 | [diff] [blame] | 1084 | return platform_driver_register(&edma_driver); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1085 | } |
| 1086 | subsys_initcall(edma_init); |
| 1087 | |
| 1088 | static void __exit edma_exit(void) |
| 1089 | { |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1090 | platform_driver_unregister(&edma_driver); |
| 1091 | } |
| 1092 | module_exit(edma_exit); |
| 1093 | |
Josh Boyer | d71505b | 2013-09-04 10:32:50 -0400 | [diff] [blame] | 1094 | MODULE_AUTHOR("Matt Porter <matt.porter@linaro.org>"); |
Matt Porter | c2dde5f | 2012-08-22 21:09:34 -0400 | [diff] [blame] | 1095 | MODULE_DESCRIPTION("TI EDMA DMA engine driver"); |
| 1096 | MODULE_LICENSE("GPL v2"); |