edma.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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. #include <linux/dmaengine.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/err.h>
  18. #include <linux/init.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/list.h>
  21. #include <linux/module.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/slab.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/platform_data/edma.h>
  26. #include "dmaengine.h"
  27. #include "virt-dma.h"
  28. /*
  29. * This will go away when the private EDMA API is folded
  30. * into this driver and the platform device(s) are
  31. * instantiated in the arch code. We can only get away
  32. * with this simplification because DA8XX may not be built
  33. * in the same kernel image with other DaVinci parts. This
  34. * avoids having to sprinkle dmaengine driver platform devices
  35. * and data throughout all the existing board files.
  36. */
  37. #ifdef CONFIG_ARCH_DAVINCI_DA8XX
  38. #define EDMA_CTLRS 2
  39. #define EDMA_CHANS 32
  40. #else
  41. #define EDMA_CTLRS 1
  42. #define EDMA_CHANS 64
  43. #endif /* CONFIG_ARCH_DAVINCI_DA8XX */
  44. /* Max of 16 segments per channel to conserve PaRAM slots */
  45. #define MAX_NR_SG 16
  46. #define EDMA_MAX_SLOTS MAX_NR_SG
  47. #define EDMA_DESCRIPTORS 16
  48. struct edma_desc {
  49. struct virt_dma_desc vdesc;
  50. struct list_head node;
  51. int absync;
  52. int pset_nr;
  53. int processed;
  54. struct edmacc_param pset[0];
  55. };
  56. struct edma_cc;
  57. struct edma_chan {
  58. struct virt_dma_chan vchan;
  59. struct list_head node;
  60. struct edma_desc *edesc;
  61. struct edma_cc *ecc;
  62. int ch_num;
  63. bool alloced;
  64. int slot[EDMA_MAX_SLOTS];
  65. struct dma_slave_config cfg;
  66. };
  67. struct edma_cc {
  68. int ctlr;
  69. struct dma_device dma_slave;
  70. struct edma_chan slave_chans[EDMA_CHANS];
  71. int num_slave_chans;
  72. int dummy_slot;
  73. };
  74. static inline struct edma_cc *to_edma_cc(struct dma_device *d)
  75. {
  76. return container_of(d, struct edma_cc, dma_slave);
  77. }
  78. static inline struct edma_chan *to_edma_chan(struct dma_chan *c)
  79. {
  80. return container_of(c, struct edma_chan, vchan.chan);
  81. }
  82. static inline struct edma_desc
  83. *to_edma_desc(struct dma_async_tx_descriptor *tx)
  84. {
  85. return container_of(tx, struct edma_desc, vdesc.tx);
  86. }
  87. static void edma_desc_free(struct virt_dma_desc *vdesc)
  88. {
  89. kfree(container_of(vdesc, struct edma_desc, vdesc));
  90. }
  91. /* Dispatch a queued descriptor to the controller (caller holds lock) */
  92. static void edma_execute(struct edma_chan *echan)
  93. {
  94. struct virt_dma_desc *vdesc;
  95. struct edma_desc *edesc;
  96. struct device *dev = echan->vchan.chan.device->dev;
  97. int i, j, left, nslots;
  98. /* If either we processed all psets or we're still not started */
  99. if (!echan->edesc ||
  100. echan->edesc->pset_nr == echan->edesc->processed) {
  101. /* Get next vdesc */
  102. vdesc = vchan_next_desc(&echan->vchan);
  103. if (!vdesc) {
  104. echan->edesc = NULL;
  105. return;
  106. }
  107. list_del(&vdesc->node);
  108. echan->edesc = to_edma_desc(&vdesc->tx);
  109. }
  110. edesc = echan->edesc;
  111. /* Find out how many left */
  112. left = edesc->pset_nr - edesc->processed;
  113. nslots = min(MAX_NR_SG, left);
  114. /* Write descriptor PaRAM set(s) */
  115. for (i = 0; i < nslots; i++) {
  116. j = i + edesc->processed;
  117. edma_write_slot(echan->slot[i], &edesc->pset[j]);
  118. dev_dbg(echan->vchan.chan.device->dev,
  119. "\n pset[%d]:\n"
  120. " chnum\t%d\n"
  121. " slot\t%d\n"
  122. " opt\t%08x\n"
  123. " src\t%08x\n"
  124. " dst\t%08x\n"
  125. " abcnt\t%08x\n"
  126. " ccnt\t%08x\n"
  127. " bidx\t%08x\n"
  128. " cidx\t%08x\n"
  129. " lkrld\t%08x\n",
  130. j, echan->ch_num, echan->slot[i],
  131. edesc->pset[j].opt,
  132. edesc->pset[j].src,
  133. edesc->pset[j].dst,
  134. edesc->pset[j].a_b_cnt,
  135. edesc->pset[j].ccnt,
  136. edesc->pset[j].src_dst_bidx,
  137. edesc->pset[j].src_dst_cidx,
  138. edesc->pset[j].link_bcntrld);
  139. /* Link to the previous slot if not the last set */
  140. if (i != (nslots - 1))
  141. edma_link(echan->slot[i], echan->slot[i+1]);
  142. /* Final pset links to the dummy pset */
  143. else
  144. edma_link(echan->slot[i], echan->ecc->dummy_slot);
  145. }
  146. edesc->processed += nslots;
  147. edma_resume(echan->ch_num);
  148. if (edesc->processed <= MAX_NR_SG) {
  149. dev_dbg(dev, "first transfer starting %d\n", echan->ch_num);
  150. edma_start(echan->ch_num);
  151. }
  152. }
  153. static int edma_terminate_all(struct edma_chan *echan)
  154. {
  155. unsigned long flags;
  156. LIST_HEAD(head);
  157. spin_lock_irqsave(&echan->vchan.lock, flags);
  158. /*
  159. * Stop DMA activity: we assume the callback will not be called
  160. * after edma_dma() returns (even if it does, it will see
  161. * echan->edesc is NULL and exit.)
  162. */
  163. if (echan->edesc) {
  164. echan->edesc = NULL;
  165. edma_stop(echan->ch_num);
  166. }
  167. vchan_get_all_descriptors(&echan->vchan, &head);
  168. spin_unlock_irqrestore(&echan->vchan.lock, flags);
  169. vchan_dma_desc_free_list(&echan->vchan, &head);
  170. return 0;
  171. }
  172. static int edma_slave_config(struct edma_chan *echan,
  173. struct dma_slave_config *cfg)
  174. {
  175. if (cfg->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES ||
  176. cfg->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES)
  177. return -EINVAL;
  178. memcpy(&echan->cfg, cfg, sizeof(echan->cfg));
  179. return 0;
  180. }
  181. static int edma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  182. unsigned long arg)
  183. {
  184. int ret = 0;
  185. struct dma_slave_config *config;
  186. struct edma_chan *echan = to_edma_chan(chan);
  187. switch (cmd) {
  188. case DMA_TERMINATE_ALL:
  189. edma_terminate_all(echan);
  190. break;
  191. case DMA_SLAVE_CONFIG:
  192. config = (struct dma_slave_config *)arg;
  193. ret = edma_slave_config(echan, config);
  194. break;
  195. default:
  196. ret = -ENOSYS;
  197. }
  198. return ret;
  199. }
  200. static struct dma_async_tx_descriptor *edma_prep_slave_sg(
  201. struct dma_chan *chan, struct scatterlist *sgl,
  202. unsigned int sg_len, enum dma_transfer_direction direction,
  203. unsigned long tx_flags, void *context)
  204. {
  205. struct edma_chan *echan = to_edma_chan(chan);
  206. struct device *dev = chan->device->dev;
  207. struct edma_desc *edesc;
  208. dma_addr_t dev_addr;
  209. enum dma_slave_buswidth dev_width;
  210. u32 burst;
  211. struct scatterlist *sg;
  212. int acnt, bcnt, ccnt, src, dst, cidx;
  213. int src_bidx, dst_bidx, src_cidx, dst_cidx;
  214. int i, nslots;
  215. if (unlikely(!echan || !sgl || !sg_len))
  216. return NULL;
  217. if (direction == DMA_DEV_TO_MEM) {
  218. dev_addr = echan->cfg.src_addr;
  219. dev_width = echan->cfg.src_addr_width;
  220. burst = echan->cfg.src_maxburst;
  221. } else if (direction == DMA_MEM_TO_DEV) {
  222. dev_addr = echan->cfg.dst_addr;
  223. dev_width = echan->cfg.dst_addr_width;
  224. burst = echan->cfg.dst_maxburst;
  225. } else {
  226. dev_err(dev, "%s: bad direction?\n", __func__);
  227. return NULL;
  228. }
  229. if (dev_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) {
  230. dev_err(dev, "Undefined slave buswidth\n");
  231. return NULL;
  232. }
  233. if (sg_len > MAX_NR_SG) {
  234. dev_err(dev, "Exceeded max SG segments %d > %d\n",
  235. sg_len, MAX_NR_SG);
  236. return NULL;
  237. }
  238. edesc = kzalloc(sizeof(*edesc) + sg_len *
  239. sizeof(edesc->pset[0]), GFP_ATOMIC);
  240. if (!edesc) {
  241. dev_dbg(dev, "Failed to allocate a descriptor\n");
  242. return NULL;
  243. }
  244. edesc->pset_nr = sg_len;
  245. /* Allocate a PaRAM slot, if needed */
  246. nslots = min_t(unsigned, MAX_NR_SG, sg_len);
  247. for (i = 0; i < nslots; i++) {
  248. if (echan->slot[i] < 0) {
  249. echan->slot[i] =
  250. edma_alloc_slot(EDMA_CTLR(echan->ch_num),
  251. EDMA_SLOT_ANY);
  252. if (echan->slot[i] < 0) {
  253. dev_err(dev, "Failed to allocate slot\n");
  254. return NULL;
  255. }
  256. }
  257. }
  258. /* Configure PaRAM sets for each SG */
  259. for_each_sg(sgl, sg, sg_len, i) {
  260. acnt = dev_width;
  261. /*
  262. * If the maxburst is equal to the fifo width, use
  263. * A-synced transfers. This allows for large contiguous
  264. * buffer transfers using only one PaRAM set.
  265. */
  266. if (burst == 1) {
  267. edesc->absync = false;
  268. ccnt = sg_dma_len(sg) / acnt / (SZ_64K - 1);
  269. bcnt = sg_dma_len(sg) / acnt - ccnt * (SZ_64K - 1);
  270. if (bcnt)
  271. ccnt++;
  272. else
  273. bcnt = SZ_64K - 1;
  274. cidx = acnt;
  275. /*
  276. * If maxburst is greater than the fifo address_width,
  277. * use AB-synced transfers where A count is the fifo
  278. * address_width and B count is the maxburst. In this
  279. * case, we are limited to transfers of C count frames
  280. * of (address_width * maxburst) where C count is limited
  281. * to SZ_64K-1. This places an upper bound on the length
  282. * of an SG segment that can be handled.
  283. */
  284. } else {
  285. edesc->absync = true;
  286. bcnt = burst;
  287. ccnt = sg_dma_len(sg) / (acnt * bcnt);
  288. if (ccnt > (SZ_64K - 1)) {
  289. dev_err(dev, "Exceeded max SG segment size\n");
  290. return NULL;
  291. }
  292. cidx = acnt * bcnt;
  293. }
  294. if (direction == DMA_MEM_TO_DEV) {
  295. src = sg_dma_address(sg);
  296. dst = dev_addr;
  297. src_bidx = acnt;
  298. src_cidx = cidx;
  299. dst_bidx = 0;
  300. dst_cidx = 0;
  301. } else {
  302. src = dev_addr;
  303. dst = sg_dma_address(sg);
  304. src_bidx = 0;
  305. src_cidx = 0;
  306. dst_bidx = acnt;
  307. dst_cidx = cidx;
  308. }
  309. edesc->pset[i].opt = EDMA_TCC(EDMA_CHAN_SLOT(echan->ch_num));
  310. /* Configure A or AB synchronized transfers */
  311. if (edesc->absync)
  312. edesc->pset[i].opt |= SYNCDIM;
  313. /* If this is the last in a current SG set of transactions,
  314. enable interrupts so that next set is processed */
  315. if (!((i+1) % MAX_NR_SG))
  316. edesc->pset[i].opt |= TCINTEN;
  317. /* If this is the last set, enable completion interrupt flag */
  318. if (i == sg_len - 1)
  319. edesc->pset[i].opt |= TCINTEN;
  320. edesc->pset[i].src = src;
  321. edesc->pset[i].dst = dst;
  322. edesc->pset[i].src_dst_bidx = (dst_bidx << 16) | src_bidx;
  323. edesc->pset[i].src_dst_cidx = (dst_cidx << 16) | src_cidx;
  324. edesc->pset[i].a_b_cnt = bcnt << 16 | acnt;
  325. edesc->pset[i].ccnt = ccnt;
  326. edesc->pset[i].link_bcntrld = 0xffffffff;
  327. }
  328. return vchan_tx_prep(&echan->vchan, &edesc->vdesc, tx_flags);
  329. }
  330. static void edma_callback(unsigned ch_num, u16 ch_status, void *data)
  331. {
  332. struct edma_chan *echan = data;
  333. struct device *dev = echan->vchan.chan.device->dev;
  334. struct edma_desc *edesc;
  335. unsigned long flags;
  336. /* Pause the channel */
  337. edma_pause(echan->ch_num);
  338. switch (ch_status) {
  339. case DMA_COMPLETE:
  340. spin_lock_irqsave(&echan->vchan.lock, flags);
  341. edesc = echan->edesc;
  342. if (edesc) {
  343. if (edesc->processed == edesc->pset_nr) {
  344. dev_dbg(dev, "Transfer complete, stopping channel %d\n", ch_num);
  345. edma_stop(echan->ch_num);
  346. vchan_cookie_complete(&edesc->vdesc);
  347. } else {
  348. dev_dbg(dev, "Intermediate transfer complete on channel %d\n", ch_num);
  349. }
  350. edma_execute(echan);
  351. }
  352. spin_unlock_irqrestore(&echan->vchan.lock, flags);
  353. break;
  354. case DMA_CC_ERROR:
  355. dev_dbg(dev, "transfer error on channel %d\n", ch_num);
  356. break;
  357. default:
  358. break;
  359. }
  360. }
  361. /* Alloc channel resources */
  362. static int edma_alloc_chan_resources(struct dma_chan *chan)
  363. {
  364. struct edma_chan *echan = to_edma_chan(chan);
  365. struct device *dev = chan->device->dev;
  366. int ret;
  367. int a_ch_num;
  368. LIST_HEAD(descs);
  369. a_ch_num = edma_alloc_channel(echan->ch_num, edma_callback,
  370. chan, EVENTQ_DEFAULT);
  371. if (a_ch_num < 0) {
  372. ret = -ENODEV;
  373. goto err_no_chan;
  374. }
  375. if (a_ch_num != echan->ch_num) {
  376. dev_err(dev, "failed to allocate requested channel %u:%u\n",
  377. EDMA_CTLR(echan->ch_num),
  378. EDMA_CHAN_SLOT(echan->ch_num));
  379. ret = -ENODEV;
  380. goto err_wrong_chan;
  381. }
  382. echan->alloced = true;
  383. echan->slot[0] = echan->ch_num;
  384. dev_info(dev, "allocated channel for %u:%u\n",
  385. EDMA_CTLR(echan->ch_num), EDMA_CHAN_SLOT(echan->ch_num));
  386. return 0;
  387. err_wrong_chan:
  388. edma_free_channel(a_ch_num);
  389. err_no_chan:
  390. return ret;
  391. }
  392. /* Free channel resources */
  393. static void edma_free_chan_resources(struct dma_chan *chan)
  394. {
  395. struct edma_chan *echan = to_edma_chan(chan);
  396. struct device *dev = chan->device->dev;
  397. int i;
  398. /* Terminate transfers */
  399. edma_stop(echan->ch_num);
  400. vchan_free_chan_resources(&echan->vchan);
  401. /* Free EDMA PaRAM slots */
  402. for (i = 1; i < EDMA_MAX_SLOTS; i++) {
  403. if (echan->slot[i] >= 0) {
  404. edma_free_slot(echan->slot[i]);
  405. echan->slot[i] = -1;
  406. }
  407. }
  408. /* Free EDMA channel */
  409. if (echan->alloced) {
  410. edma_free_channel(echan->ch_num);
  411. echan->alloced = false;
  412. }
  413. dev_info(dev, "freeing channel for %u\n", echan->ch_num);
  414. }
  415. /* Send pending descriptor to hardware */
  416. static void edma_issue_pending(struct dma_chan *chan)
  417. {
  418. struct edma_chan *echan = to_edma_chan(chan);
  419. unsigned long flags;
  420. spin_lock_irqsave(&echan->vchan.lock, flags);
  421. if (vchan_issue_pending(&echan->vchan) && !echan->edesc)
  422. edma_execute(echan);
  423. spin_unlock_irqrestore(&echan->vchan.lock, flags);
  424. }
  425. static size_t edma_desc_size(struct edma_desc *edesc)
  426. {
  427. int i;
  428. size_t size;
  429. if (edesc->absync)
  430. for (size = i = 0; i < edesc->pset_nr; i++)
  431. size += (edesc->pset[i].a_b_cnt & 0xffff) *
  432. (edesc->pset[i].a_b_cnt >> 16) *
  433. edesc->pset[i].ccnt;
  434. else
  435. size = (edesc->pset[0].a_b_cnt & 0xffff) *
  436. (edesc->pset[0].a_b_cnt >> 16) +
  437. (edesc->pset[0].a_b_cnt & 0xffff) *
  438. (SZ_64K - 1) * edesc->pset[0].ccnt;
  439. return size;
  440. }
  441. /* Check request completion status */
  442. static enum dma_status edma_tx_status(struct dma_chan *chan,
  443. dma_cookie_t cookie,
  444. struct dma_tx_state *txstate)
  445. {
  446. struct edma_chan *echan = to_edma_chan(chan);
  447. struct virt_dma_desc *vdesc;
  448. enum dma_status ret;
  449. unsigned long flags;
  450. ret = dma_cookie_status(chan, cookie, txstate);
  451. if (ret == DMA_SUCCESS || !txstate)
  452. return ret;
  453. spin_lock_irqsave(&echan->vchan.lock, flags);
  454. vdesc = vchan_find_desc(&echan->vchan, cookie);
  455. if (vdesc) {
  456. txstate->residue = edma_desc_size(to_edma_desc(&vdesc->tx));
  457. } else if (echan->edesc && echan->edesc->vdesc.tx.cookie == cookie) {
  458. struct edma_desc *edesc = echan->edesc;
  459. txstate->residue = edma_desc_size(edesc);
  460. }
  461. spin_unlock_irqrestore(&echan->vchan.lock, flags);
  462. return ret;
  463. }
  464. static void __init edma_chan_init(struct edma_cc *ecc,
  465. struct dma_device *dma,
  466. struct edma_chan *echans)
  467. {
  468. int i, j;
  469. for (i = 0; i < EDMA_CHANS; i++) {
  470. struct edma_chan *echan = &echans[i];
  471. echan->ch_num = EDMA_CTLR_CHAN(ecc->ctlr, i);
  472. echan->ecc = ecc;
  473. echan->vchan.desc_free = edma_desc_free;
  474. vchan_init(&echan->vchan, dma);
  475. INIT_LIST_HEAD(&echan->node);
  476. for (j = 0; j < EDMA_MAX_SLOTS; j++)
  477. echan->slot[j] = -1;
  478. }
  479. }
  480. static void edma_dma_init(struct edma_cc *ecc, struct dma_device *dma,
  481. struct device *dev)
  482. {
  483. dma->device_prep_slave_sg = edma_prep_slave_sg;
  484. dma->device_alloc_chan_resources = edma_alloc_chan_resources;
  485. dma->device_free_chan_resources = edma_free_chan_resources;
  486. dma->device_issue_pending = edma_issue_pending;
  487. dma->device_tx_status = edma_tx_status;
  488. dma->device_control = edma_control;
  489. dma->dev = dev;
  490. INIT_LIST_HEAD(&dma->channels);
  491. }
  492. static int edma_probe(struct platform_device *pdev)
  493. {
  494. struct edma_cc *ecc;
  495. int ret;
  496. ecc = devm_kzalloc(&pdev->dev, sizeof(*ecc), GFP_KERNEL);
  497. if (!ecc) {
  498. dev_err(&pdev->dev, "Can't allocate controller\n");
  499. return -ENOMEM;
  500. }
  501. ecc->ctlr = pdev->id;
  502. ecc->dummy_slot = edma_alloc_slot(ecc->ctlr, EDMA_SLOT_ANY);
  503. if (ecc->dummy_slot < 0) {
  504. dev_err(&pdev->dev, "Can't allocate PaRAM dummy slot\n");
  505. return -EIO;
  506. }
  507. dma_cap_zero(ecc->dma_slave.cap_mask);
  508. dma_cap_set(DMA_SLAVE, ecc->dma_slave.cap_mask);
  509. edma_dma_init(ecc, &ecc->dma_slave, &pdev->dev);
  510. edma_chan_init(ecc, &ecc->dma_slave, ecc->slave_chans);
  511. ret = dma_async_device_register(&ecc->dma_slave);
  512. if (ret)
  513. goto err_reg1;
  514. platform_set_drvdata(pdev, ecc);
  515. dev_info(&pdev->dev, "TI EDMA DMA engine driver\n");
  516. return 0;
  517. err_reg1:
  518. edma_free_slot(ecc->dummy_slot);
  519. return ret;
  520. }
  521. static int edma_remove(struct platform_device *pdev)
  522. {
  523. struct device *dev = &pdev->dev;
  524. struct edma_cc *ecc = dev_get_drvdata(dev);
  525. dma_async_device_unregister(&ecc->dma_slave);
  526. edma_free_slot(ecc->dummy_slot);
  527. return 0;
  528. }
  529. static struct platform_driver edma_driver = {
  530. .probe = edma_probe,
  531. .remove = edma_remove,
  532. .driver = {
  533. .name = "edma-dma-engine",
  534. .owner = THIS_MODULE,
  535. },
  536. };
  537. bool edma_filter_fn(struct dma_chan *chan, void *param)
  538. {
  539. if (chan->device->dev->driver == &edma_driver.driver) {
  540. struct edma_chan *echan = to_edma_chan(chan);
  541. unsigned ch_req = *(unsigned *)param;
  542. return ch_req == echan->ch_num;
  543. }
  544. return false;
  545. }
  546. EXPORT_SYMBOL(edma_filter_fn);
  547. static struct platform_device *pdev0, *pdev1;
  548. static const struct platform_device_info edma_dev_info0 = {
  549. .name = "edma-dma-engine",
  550. .id = 0,
  551. };
  552. static const struct platform_device_info edma_dev_info1 = {
  553. .name = "edma-dma-engine",
  554. .id = 1,
  555. };
  556. static int edma_init(void)
  557. {
  558. int ret = platform_driver_register(&edma_driver);
  559. if (ret == 0) {
  560. pdev0 = platform_device_register_full(&edma_dev_info0);
  561. if (IS_ERR(pdev0)) {
  562. platform_driver_unregister(&edma_driver);
  563. ret = PTR_ERR(pdev0);
  564. goto out;
  565. }
  566. pdev0->dev.dma_mask = &pdev0->dev.coherent_dma_mask;
  567. pdev0->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  568. }
  569. if (EDMA_CTLRS == 2) {
  570. pdev1 = platform_device_register_full(&edma_dev_info1);
  571. if (IS_ERR(pdev1)) {
  572. platform_driver_unregister(&edma_driver);
  573. platform_device_unregister(pdev0);
  574. ret = PTR_ERR(pdev1);
  575. }
  576. pdev1->dev.dma_mask = &pdev1->dev.coherent_dma_mask;
  577. pdev1->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  578. }
  579. out:
  580. return ret;
  581. }
  582. subsys_initcall(edma_init);
  583. static void __exit edma_exit(void)
  584. {
  585. platform_device_unregister(pdev0);
  586. if (pdev1)
  587. platform_device_unregister(pdev1);
  588. platform_driver_unregister(&edma_driver);
  589. }
  590. module_exit(edma_exit);
  591. MODULE_AUTHOR("Matt Porter <mporter@ti.com>");
  592. MODULE_DESCRIPTION("TI EDMA DMA engine driver");
  593. MODULE_LICENSE("GPL v2");