blob: f9075129d27c4f97830ea67fb9f878dc8a53fe1f [file] [log] [blame]
Matt Porterc2dde5f2012-08-22 21:09:34 -04001/*
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 Porter3ad7a422013-03-06 11:15:31 -050027#include <linux/platform_data/edma.h>
Matt Porterc2dde5f2012-08-22 21:09:34 -040028
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
49/* Max of 16 segments per channel to conserve PaRAM slots */
50#define MAX_NR_SG 16
51#define EDMA_MAX_SLOTS MAX_NR_SG
52#define EDMA_DESCRIPTORS 16
53
54struct edma_desc {
55 struct virt_dma_desc vdesc;
56 struct list_head node;
57 int absync;
58 int pset_nr;
59 struct edmacc_param pset[0];
60};
61
62struct edma_cc;
63
64struct edma_chan {
65 struct virt_dma_chan vchan;
66 struct list_head node;
67 struct edma_desc *edesc;
68 struct edma_cc *ecc;
69 int ch_num;
70 bool alloced;
71 int slot[EDMA_MAX_SLOTS];
Matt Porter661f7cb2013-01-10 13:41:04 -050072 struct dma_slave_config cfg;
Matt Porterc2dde5f2012-08-22 21:09:34 -040073};
74
75struct edma_cc {
76 int ctlr;
77 struct dma_device dma_slave;
78 struct edma_chan slave_chans[EDMA_CHANS];
79 int num_slave_chans;
80 int dummy_slot;
81};
82
83static inline struct edma_cc *to_edma_cc(struct dma_device *d)
84{
85 return container_of(d, struct edma_cc, dma_slave);
86}
87
88static inline struct edma_chan *to_edma_chan(struct dma_chan *c)
89{
90 return container_of(c, struct edma_chan, vchan.chan);
91}
92
93static inline struct edma_desc
94*to_edma_desc(struct dma_async_tx_descriptor *tx)
95{
96 return container_of(tx, struct edma_desc, vdesc.tx);
97}
98
99static void edma_desc_free(struct virt_dma_desc *vdesc)
100{
101 kfree(container_of(vdesc, struct edma_desc, vdesc));
102}
103
104/* Dispatch a queued descriptor to the controller (caller holds lock) */
105static void edma_execute(struct edma_chan *echan)
106{
107 struct virt_dma_desc *vdesc = vchan_next_desc(&echan->vchan);
108 struct edma_desc *edesc;
109 int i;
110
111 if (!vdesc) {
112 echan->edesc = NULL;
113 return;
114 }
115
116 list_del(&vdesc->node);
117
118 echan->edesc = edesc = to_edma_desc(&vdesc->tx);
119
120 /* Write descriptor PaRAM set(s) */
121 for (i = 0; i < edesc->pset_nr; i++) {
122 edma_write_slot(echan->slot[i], &edesc->pset[i]);
123 dev_dbg(echan->vchan.chan.device->dev,
124 "\n pset[%d]:\n"
125 " chnum\t%d\n"
126 " slot\t%d\n"
127 " opt\t%08x\n"
128 " src\t%08x\n"
129 " dst\t%08x\n"
130 " abcnt\t%08x\n"
131 " ccnt\t%08x\n"
132 " bidx\t%08x\n"
133 " cidx\t%08x\n"
134 " lkrld\t%08x\n",
135 i, echan->ch_num, echan->slot[i],
136 edesc->pset[i].opt,
137 edesc->pset[i].src,
138 edesc->pset[i].dst,
139 edesc->pset[i].a_b_cnt,
140 edesc->pset[i].ccnt,
141 edesc->pset[i].src_dst_bidx,
142 edesc->pset[i].src_dst_cidx,
143 edesc->pset[i].link_bcntrld);
144 /* Link to the previous slot if not the last set */
145 if (i != (edesc->pset_nr - 1))
146 edma_link(echan->slot[i], echan->slot[i+1]);
147 /* Final pset links to the dummy pset */
148 else
149 edma_link(echan->slot[i], echan->ecc->dummy_slot);
150 }
151
152 edma_start(echan->ch_num);
153}
154
155static int edma_terminate_all(struct edma_chan *echan)
156{
157 unsigned long flags;
158 LIST_HEAD(head);
159
160 spin_lock_irqsave(&echan->vchan.lock, flags);
161
162 /*
163 * Stop DMA activity: we assume the callback will not be called
164 * after edma_dma() returns (even if it does, it will see
165 * echan->edesc is NULL and exit.)
166 */
167 if (echan->edesc) {
168 echan->edesc = NULL;
169 edma_stop(echan->ch_num);
170 }
171
172 vchan_get_all_descriptors(&echan->vchan, &head);
173 spin_unlock_irqrestore(&echan->vchan.lock, flags);
174 vchan_dma_desc_free_list(&echan->vchan, &head);
175
176 return 0;
177}
178
Matt Porterc2dde5f2012-08-22 21:09:34 -0400179static int edma_slave_config(struct edma_chan *echan,
Matt Porter661f7cb2013-01-10 13:41:04 -0500180 struct dma_slave_config *cfg)
Matt Porterc2dde5f2012-08-22 21:09:34 -0400181{
Matt Porter661f7cb2013-01-10 13:41:04 -0500182 if (cfg->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES ||
183 cfg->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES)
Matt Porterc2dde5f2012-08-22 21:09:34 -0400184 return -EINVAL;
185
Matt Porter661f7cb2013-01-10 13:41:04 -0500186 memcpy(&echan->cfg, cfg, sizeof(echan->cfg));
Matt Porterc2dde5f2012-08-22 21:09:34 -0400187
188 return 0;
189}
190
191static int edma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
192 unsigned long arg)
193{
194 int ret = 0;
195 struct dma_slave_config *config;
196 struct edma_chan *echan = to_edma_chan(chan);
197
198 switch (cmd) {
199 case DMA_TERMINATE_ALL:
200 edma_terminate_all(echan);
201 break;
202 case DMA_SLAVE_CONFIG:
203 config = (struct dma_slave_config *)arg;
204 ret = edma_slave_config(echan, config);
205 break;
206 default:
207 ret = -ENOSYS;
208 }
209
210 return ret;
211}
212
213static struct dma_async_tx_descriptor *edma_prep_slave_sg(
214 struct dma_chan *chan, struct scatterlist *sgl,
215 unsigned int sg_len, enum dma_transfer_direction direction,
216 unsigned long tx_flags, void *context)
217{
218 struct edma_chan *echan = to_edma_chan(chan);
219 struct device *dev = chan->device->dev;
220 struct edma_desc *edesc;
Matt Porter661f7cb2013-01-10 13:41:04 -0500221 dma_addr_t dev_addr;
222 enum dma_slave_buswidth dev_width;
223 u32 burst;
Matt Porterc2dde5f2012-08-22 21:09:34 -0400224 struct scatterlist *sg;
Matt Porterc2dde5f2012-08-22 21:09:34 -0400225 int acnt, bcnt, ccnt, src, dst, cidx;
226 int src_bidx, dst_bidx, src_cidx, dst_cidx;
Joel Fernandes6fbe24d2013-08-29 18:05:40 -0500227 int i, nslots;
Matt Porterc2dde5f2012-08-22 21:09:34 -0400228
229 if (unlikely(!echan || !sgl || !sg_len))
230 return NULL;
231
Matt Porter661f7cb2013-01-10 13:41:04 -0500232 if (direction == DMA_DEV_TO_MEM) {
233 dev_addr = echan->cfg.src_addr;
234 dev_width = echan->cfg.src_addr_width;
235 burst = echan->cfg.src_maxburst;
236 } else if (direction == DMA_MEM_TO_DEV) {
237 dev_addr = echan->cfg.dst_addr;
238 dev_width = echan->cfg.dst_addr_width;
239 burst = echan->cfg.dst_maxburst;
240 } else {
241 dev_err(dev, "%s: bad direction?\n", __func__);
242 return NULL;
243 }
244
245 if (dev_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) {
Matt Porterc2dde5f2012-08-22 21:09:34 -0400246 dev_err(dev, "Undefined slave buswidth\n");
247 return NULL;
248 }
249
250 if (sg_len > MAX_NR_SG) {
251 dev_err(dev, "Exceeded max SG segments %d > %d\n",
252 sg_len, MAX_NR_SG);
253 return NULL;
254 }
255
256 edesc = kzalloc(sizeof(*edesc) + sg_len *
257 sizeof(edesc->pset[0]), GFP_ATOMIC);
258 if (!edesc) {
259 dev_dbg(dev, "Failed to allocate a descriptor\n");
260 return NULL;
261 }
262
263 edesc->pset_nr = sg_len;
264
Joel Fernandes6fbe24d2013-08-29 18:05:40 -0500265 /* Allocate a PaRAM slot, if needed */
266 nslots = min_t(unsigned, MAX_NR_SG, sg_len);
267
268 for (i = 0; i < nslots; i++) {
Matt Porterc2dde5f2012-08-22 21:09:34 -0400269 if (echan->slot[i] < 0) {
270 echan->slot[i] =
271 edma_alloc_slot(EDMA_CTLR(echan->ch_num),
272 EDMA_SLOT_ANY);
273 if (echan->slot[i] < 0) {
274 dev_err(dev, "Failed to allocate slot\n");
275 return NULL;
276 }
277 }
Joel Fernandes6fbe24d2013-08-29 18:05:40 -0500278 }
279
280 /* Configure PaRAM sets for each SG */
281 for_each_sg(sgl, sg, sg_len, i) {
Matt Porterc2dde5f2012-08-22 21:09:34 -0400282
Matt Porter661f7cb2013-01-10 13:41:04 -0500283 acnt = dev_width;
Matt Porterc2dde5f2012-08-22 21:09:34 -0400284
285 /*
286 * If the maxburst is equal to the fifo width, use
287 * A-synced transfers. This allows for large contiguous
288 * buffer transfers using only one PaRAM set.
289 */
Matt Porter661f7cb2013-01-10 13:41:04 -0500290 if (burst == 1) {
Matt Porterc2dde5f2012-08-22 21:09:34 -0400291 edesc->absync = false;
292 ccnt = sg_dma_len(sg) / acnt / (SZ_64K - 1);
293 bcnt = sg_dma_len(sg) / acnt - ccnt * (SZ_64K - 1);
294 if (bcnt)
295 ccnt++;
296 else
297 bcnt = SZ_64K - 1;
298 cidx = acnt;
299 /*
300 * If maxburst is greater than the fifo address_width,
301 * use AB-synced transfers where A count is the fifo
302 * address_width and B count is the maxburst. In this
303 * case, we are limited to transfers of C count frames
304 * of (address_width * maxburst) where C count is limited
305 * to SZ_64K-1. This places an upper bound on the length
306 * of an SG segment that can be handled.
307 */
308 } else {
309 edesc->absync = true;
Matt Porter661f7cb2013-01-10 13:41:04 -0500310 bcnt = burst;
Matt Porterc2dde5f2012-08-22 21:09:34 -0400311 ccnt = sg_dma_len(sg) / (acnt * bcnt);
312 if (ccnt > (SZ_64K - 1)) {
313 dev_err(dev, "Exceeded max SG segment size\n");
314 return NULL;
315 }
316 cidx = acnt * bcnt;
317 }
318
319 if (direction == DMA_MEM_TO_DEV) {
320 src = sg_dma_address(sg);
Matt Porter661f7cb2013-01-10 13:41:04 -0500321 dst = dev_addr;
Matt Porterc2dde5f2012-08-22 21:09:34 -0400322 src_bidx = acnt;
323 src_cidx = cidx;
324 dst_bidx = 0;
325 dst_cidx = 0;
326 } else {
Matt Porter661f7cb2013-01-10 13:41:04 -0500327 src = dev_addr;
Matt Porterc2dde5f2012-08-22 21:09:34 -0400328 dst = sg_dma_address(sg);
329 src_bidx = 0;
330 src_cidx = 0;
331 dst_bidx = acnt;
332 dst_cidx = cidx;
333 }
334
335 edesc->pset[i].opt = EDMA_TCC(EDMA_CHAN_SLOT(echan->ch_num));
336 /* Configure A or AB synchronized transfers */
337 if (edesc->absync)
338 edesc->pset[i].opt |= SYNCDIM;
Joel Fernandes6fbe24d2013-08-29 18:05:40 -0500339
340 /* If this is the last in a current SG set of transactions,
341 enable interrupts so that next set is processed */
342 if (!((i+1) % MAX_NR_SG))
343 edesc->pset[i].opt |= TCINTEN;
344
Matt Porterc2dde5f2012-08-22 21:09:34 -0400345 /* If this is the last set, enable completion interrupt flag */
346 if (i == sg_len - 1)
347 edesc->pset[i].opt |= TCINTEN;
348
349 edesc->pset[i].src = src;
350 edesc->pset[i].dst = dst;
351
352 edesc->pset[i].src_dst_bidx = (dst_bidx << 16) | src_bidx;
353 edesc->pset[i].src_dst_cidx = (dst_cidx << 16) | src_cidx;
354
355 edesc->pset[i].a_b_cnt = bcnt << 16 | acnt;
356 edesc->pset[i].ccnt = ccnt;
357 edesc->pset[i].link_bcntrld = 0xffffffff;
358
359 }
360
361 return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags);
362}
363
364static void edma_callback(unsigned ch_num, u16 ch_status, void *data)
365{
366 struct edma_chan *echan = data;
367 struct device *dev = echan->vchan.chan.device->dev;
368 struct edma_desc *edesc;
369 unsigned long flags;
370
371 /* Stop the channel */
372 edma_stop(echan->ch_num);
373
374 switch (ch_status) {
375 case DMA_COMPLETE:
376 dev_dbg(dev, "transfer complete on channel %d\n", ch_num);
377
378 spin_lock_irqsave(&echan->vchan.lock, flags);
379
380 edesc = echan->edesc;
381 if (edesc) {
382 edma_execute(echan);
383 vchan_cookie_complete(&edesc->vdesc);
384 }
385
386 spin_unlock_irqrestore(&echan->vchan.lock, flags);
387
388 break;
389 case DMA_CC_ERROR:
390 dev_dbg(dev, "transfer error on channel %d\n", ch_num);
391 break;
392 default:
393 break;
394 }
395}
396
397/* Alloc channel resources */
398static int edma_alloc_chan_resources(struct dma_chan *chan)
399{
400 struct edma_chan *echan = to_edma_chan(chan);
401 struct device *dev = chan->device->dev;
402 int ret;
403 int a_ch_num;
404 LIST_HEAD(descs);
405
406 a_ch_num = edma_alloc_channel(echan->ch_num, edma_callback,
407 chan, EVENTQ_DEFAULT);
408
409 if (a_ch_num < 0) {
410 ret = -ENODEV;
411 goto err_no_chan;
412 }
413
414 if (a_ch_num != echan->ch_num) {
415 dev_err(dev, "failed to allocate requested channel %u:%u\n",
416 EDMA_CTLR(echan->ch_num),
417 EDMA_CHAN_SLOT(echan->ch_num));
418 ret = -ENODEV;
419 goto err_wrong_chan;
420 }
421
422 echan->alloced = true;
423 echan->slot[0] = echan->ch_num;
424
425 dev_info(dev, "allocated channel for %u:%u\n",
426 EDMA_CTLR(echan->ch_num), EDMA_CHAN_SLOT(echan->ch_num));
427
428 return 0;
429
430err_wrong_chan:
431 edma_free_channel(a_ch_num);
432err_no_chan:
433 return ret;
434}
435
436/* Free channel resources */
437static void edma_free_chan_resources(struct dma_chan *chan)
438{
439 struct edma_chan *echan = to_edma_chan(chan);
440 struct device *dev = chan->device->dev;
441 int i;
442
443 /* Terminate transfers */
444 edma_stop(echan->ch_num);
445
446 vchan_free_chan_resources(&echan->vchan);
447
448 /* Free EDMA PaRAM slots */
449 for (i = 1; i < EDMA_MAX_SLOTS; i++) {
450 if (echan->slot[i] >= 0) {
451 edma_free_slot(echan->slot[i]);
452 echan->slot[i] = -1;
453 }
454 }
455
456 /* Free EDMA channel */
457 if (echan->alloced) {
458 edma_free_channel(echan->ch_num);
459 echan->alloced = false;
460 }
461
462 dev_info(dev, "freeing channel for %u\n", echan->ch_num);
463}
464
465/* Send pending descriptor to hardware */
466static void edma_issue_pending(struct dma_chan *chan)
467{
468 struct edma_chan *echan = to_edma_chan(chan);
469 unsigned long flags;
470
471 spin_lock_irqsave(&echan->vchan.lock, flags);
472 if (vchan_issue_pending(&echan->vchan) && !echan->edesc)
473 edma_execute(echan);
474 spin_unlock_irqrestore(&echan->vchan.lock, flags);
475}
476
477static size_t edma_desc_size(struct edma_desc *edesc)
478{
479 int i;
480 size_t size;
481
482 if (edesc->absync)
483 for (size = i = 0; i < edesc->pset_nr; i++)
484 size += (edesc->pset[i].a_b_cnt & 0xffff) *
485 (edesc->pset[i].a_b_cnt >> 16) *
486 edesc->pset[i].ccnt;
487 else
488 size = (edesc->pset[0].a_b_cnt & 0xffff) *
489 (edesc->pset[0].a_b_cnt >> 16) +
490 (edesc->pset[0].a_b_cnt & 0xffff) *
491 (SZ_64K - 1) * edesc->pset[0].ccnt;
492
493 return size;
494}
495
496/* Check request completion status */
497static enum dma_status edma_tx_status(struct dma_chan *chan,
498 dma_cookie_t cookie,
499 struct dma_tx_state *txstate)
500{
501 struct edma_chan *echan = to_edma_chan(chan);
502 struct virt_dma_desc *vdesc;
503 enum dma_status ret;
504 unsigned long flags;
505
506 ret = dma_cookie_status(chan, cookie, txstate);
507 if (ret == DMA_SUCCESS || !txstate)
508 return ret;
509
510 spin_lock_irqsave(&echan->vchan.lock, flags);
511 vdesc = vchan_find_desc(&echan->vchan, cookie);
512 if (vdesc) {
513 txstate->residue = edma_desc_size(to_edma_desc(&vdesc->tx));
514 } else if (echan->edesc && echan->edesc->vdesc.tx.cookie == cookie) {
515 struct edma_desc *edesc = echan->edesc;
516 txstate->residue = edma_desc_size(edesc);
Matt Porterc2dde5f2012-08-22 21:09:34 -0400517 }
518 spin_unlock_irqrestore(&echan->vchan.lock, flags);
519
520 return ret;
521}
522
523static void __init edma_chan_init(struct edma_cc *ecc,
524 struct dma_device *dma,
525 struct edma_chan *echans)
526{
527 int i, j;
528
529 for (i = 0; i < EDMA_CHANS; i++) {
530 struct edma_chan *echan = &echans[i];
531 echan->ch_num = EDMA_CTLR_CHAN(ecc->ctlr, i);
532 echan->ecc = ecc;
533 echan->vchan.desc_free = edma_desc_free;
534
535 vchan_init(&echan->vchan, dma);
536
537 INIT_LIST_HEAD(&echan->node);
538 for (j = 0; j < EDMA_MAX_SLOTS; j++)
539 echan->slot[j] = -1;
540 }
541}
542
543static void edma_dma_init(struct edma_cc *ecc, struct dma_device *dma,
544 struct device *dev)
545{
546 dma->device_prep_slave_sg = edma_prep_slave_sg;
547 dma->device_alloc_chan_resources = edma_alloc_chan_resources;
548 dma->device_free_chan_resources = edma_free_chan_resources;
549 dma->device_issue_pending = edma_issue_pending;
550 dma->device_tx_status = edma_tx_status;
551 dma->device_control = edma_control;
552 dma->dev = dev;
553
554 INIT_LIST_HEAD(&dma->channels);
555}
556
Bill Pemberton463a1f82012-11-19 13:22:55 -0500557static int edma_probe(struct platform_device *pdev)
Matt Porterc2dde5f2012-08-22 21:09:34 -0400558{
559 struct edma_cc *ecc;
560 int ret;
561
562 ecc = devm_kzalloc(&pdev->dev, sizeof(*ecc), GFP_KERNEL);
563 if (!ecc) {
564 dev_err(&pdev->dev, "Can't allocate controller\n");
565 return -ENOMEM;
566 }
567
568 ecc->ctlr = pdev->id;
569 ecc->dummy_slot = edma_alloc_slot(ecc->ctlr, EDMA_SLOT_ANY);
570 if (ecc->dummy_slot < 0) {
571 dev_err(&pdev->dev, "Can't allocate PaRAM dummy slot\n");
572 return -EIO;
573 }
574
575 dma_cap_zero(ecc->dma_slave.cap_mask);
576 dma_cap_set(DMA_SLAVE, ecc->dma_slave.cap_mask);
577
578 edma_dma_init(ecc, &ecc->dma_slave, &pdev->dev);
579
580 edma_chan_init(ecc, &ecc->dma_slave, ecc->slave_chans);
581
582 ret = dma_async_device_register(&ecc->dma_slave);
583 if (ret)
584 goto err_reg1;
585
586 platform_set_drvdata(pdev, ecc);
587
588 dev_info(&pdev->dev, "TI EDMA DMA engine driver\n");
589
590 return 0;
591
592err_reg1:
593 edma_free_slot(ecc->dummy_slot);
594 return ret;
595}
596
Greg Kroah-Hartman4bf27b82012-12-21 15:09:59 -0800597static int edma_remove(struct platform_device *pdev)
Matt Porterc2dde5f2012-08-22 21:09:34 -0400598{
599 struct device *dev = &pdev->dev;
600 struct edma_cc *ecc = dev_get_drvdata(dev);
601
602 dma_async_device_unregister(&ecc->dma_slave);
603 edma_free_slot(ecc->dummy_slot);
604
605 return 0;
606}
607
608static struct platform_driver edma_driver = {
609 .probe = edma_probe,
Bill Pembertona7d6e3e2012-11-19 13:20:04 -0500610 .remove = edma_remove,
Matt Porterc2dde5f2012-08-22 21:09:34 -0400611 .driver = {
612 .name = "edma-dma-engine",
613 .owner = THIS_MODULE,
614 },
615};
616
617bool edma_filter_fn(struct dma_chan *chan, void *param)
618{
619 if (chan->device->dev->driver == &edma_driver.driver) {
620 struct edma_chan *echan = to_edma_chan(chan);
621 unsigned ch_req = *(unsigned *)param;
622 return ch_req == echan->ch_num;
623 }
624 return false;
625}
626EXPORT_SYMBOL(edma_filter_fn);
627
628static struct platform_device *pdev0, *pdev1;
629
630static const struct platform_device_info edma_dev_info0 = {
631 .name = "edma-dma-engine",
632 .id = 0,
Matt Porterc2dde5f2012-08-22 21:09:34 -0400633};
634
635static const struct platform_device_info edma_dev_info1 = {
636 .name = "edma-dma-engine",
637 .id = 1,
Matt Porterc2dde5f2012-08-22 21:09:34 -0400638};
639
640static int edma_init(void)
641{
642 int ret = platform_driver_register(&edma_driver);
643
644 if (ret == 0) {
645 pdev0 = platform_device_register_full(&edma_dev_info0);
646 if (IS_ERR(pdev0)) {
647 platform_driver_unregister(&edma_driver);
648 ret = PTR_ERR(pdev0);
649 goto out;
650 }
Andy Shevchenko373459e2013-02-14 11:00:19 +0200651 pdev0->dev.dma_mask = &pdev0->dev.coherent_dma_mask;
652 pdev0->dev.coherent_dma_mask = DMA_BIT_MASK(32);
Matt Porterc2dde5f2012-08-22 21:09:34 -0400653 }
654
655 if (EDMA_CTLRS == 2) {
656 pdev1 = platform_device_register_full(&edma_dev_info1);
657 if (IS_ERR(pdev1)) {
658 platform_driver_unregister(&edma_driver);
659 platform_device_unregister(pdev0);
660 ret = PTR_ERR(pdev1);
661 }
Andy Shevchenko373459e2013-02-14 11:00:19 +0200662 pdev1->dev.dma_mask = &pdev1->dev.coherent_dma_mask;
663 pdev1->dev.coherent_dma_mask = DMA_BIT_MASK(32);
Matt Porterc2dde5f2012-08-22 21:09:34 -0400664 }
665
666out:
667 return ret;
668}
669subsys_initcall(edma_init);
670
671static void __exit edma_exit(void)
672{
673 platform_device_unregister(pdev0);
674 if (pdev1)
675 platform_device_unregister(pdev1);
676 platform_driver_unregister(&edma_driver);
677}
678module_exit(edma_exit);
679
680MODULE_AUTHOR("Matt Porter <mporter@ti.com>");
681MODULE_DESCRIPTION("TI EDMA DMA engine driver");
682MODULE_LICENSE("GPL v2");