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