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