omap-dma.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /*
  2. * OMAP DMAengine support
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/dmaengine.h>
  9. #include <linux/dma-mapping.h>
  10. #include <linux/err.h>
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/list.h>
  14. #include <linux/module.h>
  15. #include <linux/omap-dma.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/slab.h>
  18. #include <linux/spinlock.h>
  19. #include "virt-dma.h"
  20. struct omap_dmadev {
  21. struct dma_device ddev;
  22. spinlock_t lock;
  23. struct tasklet_struct task;
  24. struct list_head pending;
  25. };
  26. struct omap_chan {
  27. struct virt_dma_chan vc;
  28. struct list_head node;
  29. struct dma_slave_config cfg;
  30. unsigned dma_sig;
  31. bool cyclic;
  32. bool paused;
  33. int dma_ch;
  34. struct omap_desc *desc;
  35. unsigned sgidx;
  36. };
  37. struct omap_sg {
  38. dma_addr_t addr;
  39. uint32_t en; /* number of elements (24-bit) */
  40. uint32_t fn; /* number of frames (16-bit) */
  41. };
  42. struct omap_desc {
  43. struct virt_dma_desc vd;
  44. enum dma_transfer_direction dir;
  45. dma_addr_t dev_addr;
  46. int16_t fi; /* for OMAP_DMA_SYNC_PACKET */
  47. uint8_t es; /* OMAP_DMA_DATA_TYPE_xxx */
  48. uint8_t sync_mode; /* OMAP_DMA_SYNC_xxx */
  49. uint8_t sync_type; /* OMAP_DMA_xxx_SYNC* */
  50. uint8_t periph_port; /* Peripheral port */
  51. unsigned sglen;
  52. struct omap_sg sg[0];
  53. };
  54. static const unsigned es_bytes[] = {
  55. [OMAP_DMA_DATA_TYPE_S8] = 1,
  56. [OMAP_DMA_DATA_TYPE_S16] = 2,
  57. [OMAP_DMA_DATA_TYPE_S32] = 4,
  58. };
  59. static inline struct omap_dmadev *to_omap_dma_dev(struct dma_device *d)
  60. {
  61. return container_of(d, struct omap_dmadev, ddev);
  62. }
  63. static inline struct omap_chan *to_omap_dma_chan(struct dma_chan *c)
  64. {
  65. return container_of(c, struct omap_chan, vc.chan);
  66. }
  67. static inline struct omap_desc *to_omap_dma_desc(struct dma_async_tx_descriptor *t)
  68. {
  69. return container_of(t, struct omap_desc, vd.tx);
  70. }
  71. static void omap_dma_desc_free(struct virt_dma_desc *vd)
  72. {
  73. kfree(container_of(vd, struct omap_desc, vd));
  74. }
  75. static void omap_dma_start_sg(struct omap_chan *c, struct omap_desc *d,
  76. unsigned idx)
  77. {
  78. struct omap_sg *sg = d->sg + idx;
  79. if (d->dir == DMA_DEV_TO_MEM)
  80. omap_set_dma_dest_params(c->dma_ch, OMAP_DMA_PORT_EMIFF,
  81. OMAP_DMA_AMODE_POST_INC, sg->addr, 0, 0);
  82. else
  83. omap_set_dma_src_params(c->dma_ch, OMAP_DMA_PORT_EMIFF,
  84. OMAP_DMA_AMODE_POST_INC, sg->addr, 0, 0);
  85. omap_set_dma_transfer_params(c->dma_ch, d->es, sg->en, sg->fn,
  86. d->sync_mode, c->dma_sig, d->sync_type);
  87. omap_start_dma(c->dma_ch);
  88. }
  89. static void omap_dma_start_desc(struct omap_chan *c)
  90. {
  91. struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
  92. struct omap_desc *d;
  93. if (!vd) {
  94. c->desc = NULL;
  95. return;
  96. }
  97. list_del(&vd->node);
  98. c->desc = d = to_omap_dma_desc(&vd->tx);
  99. c->sgidx = 0;
  100. if (d->dir == DMA_DEV_TO_MEM)
  101. omap_set_dma_src_params(c->dma_ch, d->periph_port,
  102. OMAP_DMA_AMODE_CONSTANT, d->dev_addr, 0, d->fi);
  103. else
  104. omap_set_dma_dest_params(c->dma_ch, d->periph_port,
  105. OMAP_DMA_AMODE_CONSTANT, d->dev_addr, 0, d->fi);
  106. omap_dma_start_sg(c, d, 0);
  107. }
  108. static void omap_dma_callback(int ch, u16 status, void *data)
  109. {
  110. struct omap_chan *c = data;
  111. struct omap_desc *d;
  112. unsigned long flags;
  113. spin_lock_irqsave(&c->vc.lock, flags);
  114. d = c->desc;
  115. if (d) {
  116. if (!c->cyclic) {
  117. if (++c->sgidx < d->sglen) {
  118. omap_dma_start_sg(c, d, c->sgidx);
  119. } else {
  120. omap_dma_start_desc(c);
  121. vchan_cookie_complete(&d->vd);
  122. }
  123. } else {
  124. vchan_cyclic_callback(&d->vd);
  125. }
  126. }
  127. spin_unlock_irqrestore(&c->vc.lock, flags);
  128. }
  129. /*
  130. * This callback schedules all pending channels. We could be more
  131. * clever here by postponing allocation of the real DMA channels to
  132. * this point, and freeing them when our virtual channel becomes idle.
  133. *
  134. * We would then need to deal with 'all channels in-use'
  135. */
  136. static void omap_dma_sched(unsigned long data)
  137. {
  138. struct omap_dmadev *d = (struct omap_dmadev *)data;
  139. LIST_HEAD(head);
  140. spin_lock_irq(&d->lock);
  141. list_splice_tail_init(&d->pending, &head);
  142. spin_unlock_irq(&d->lock);
  143. while (!list_empty(&head)) {
  144. struct omap_chan *c = list_first_entry(&head,
  145. struct omap_chan, node);
  146. spin_lock_irq(&c->vc.lock);
  147. list_del_init(&c->node);
  148. omap_dma_start_desc(c);
  149. spin_unlock_irq(&c->vc.lock);
  150. }
  151. }
  152. static int omap_dma_alloc_chan_resources(struct dma_chan *chan)
  153. {
  154. struct omap_chan *c = to_omap_dma_chan(chan);
  155. dev_info(c->vc.chan.device->dev, "allocating channel for %u\n", c->dma_sig);
  156. return omap_request_dma(c->dma_sig, "DMA engine",
  157. omap_dma_callback, c, &c->dma_ch);
  158. }
  159. static void omap_dma_free_chan_resources(struct dma_chan *chan)
  160. {
  161. struct omap_chan *c = to_omap_dma_chan(chan);
  162. vchan_free_chan_resources(&c->vc);
  163. omap_free_dma(c->dma_ch);
  164. dev_info(c->vc.chan.device->dev, "freeing channel for %u\n", c->dma_sig);
  165. }
  166. static size_t omap_dma_sg_size(struct omap_sg *sg)
  167. {
  168. return sg->en * sg->fn;
  169. }
  170. static size_t omap_dma_desc_size(struct omap_desc *d)
  171. {
  172. unsigned i;
  173. size_t size;
  174. for (size = i = 0; i < d->sglen; i++)
  175. size += omap_dma_sg_size(&d->sg[i]);
  176. return size * es_bytes[d->es];
  177. }
  178. static size_t omap_dma_desc_size_pos(struct omap_desc *d, dma_addr_t addr)
  179. {
  180. unsigned i;
  181. size_t size, es_size = es_bytes[d->es];
  182. for (size = i = 0; i < d->sglen; i++) {
  183. size_t this_size = omap_dma_sg_size(&d->sg[i]) * es_size;
  184. if (size)
  185. size += this_size;
  186. else if (addr >= d->sg[i].addr &&
  187. addr < d->sg[i].addr + this_size)
  188. size += d->sg[i].addr + this_size - addr;
  189. }
  190. return size;
  191. }
  192. static enum dma_status omap_dma_tx_status(struct dma_chan *chan,
  193. dma_cookie_t cookie, struct dma_tx_state *txstate)
  194. {
  195. struct omap_chan *c = to_omap_dma_chan(chan);
  196. struct virt_dma_desc *vd;
  197. enum dma_status ret;
  198. unsigned long flags;
  199. ret = dma_cookie_status(chan, cookie, txstate);
  200. if (ret == DMA_SUCCESS || !txstate)
  201. return ret;
  202. spin_lock_irqsave(&c->vc.lock, flags);
  203. vd = vchan_find_desc(&c->vc, cookie);
  204. if (vd) {
  205. txstate->residue = omap_dma_desc_size(to_omap_dma_desc(&vd->tx));
  206. } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
  207. struct omap_desc *d = c->desc;
  208. dma_addr_t pos;
  209. if (d->dir == DMA_MEM_TO_DEV)
  210. pos = omap_get_dma_src_pos(c->dma_ch);
  211. else if (d->dir == DMA_DEV_TO_MEM)
  212. pos = omap_get_dma_dst_pos(c->dma_ch);
  213. else
  214. pos = 0;
  215. txstate->residue = omap_dma_desc_size_pos(d, pos);
  216. } else {
  217. txstate->residue = 0;
  218. }
  219. spin_unlock_irqrestore(&c->vc.lock, flags);
  220. return ret;
  221. }
  222. static void omap_dma_issue_pending(struct dma_chan *chan)
  223. {
  224. struct omap_chan *c = to_omap_dma_chan(chan);
  225. unsigned long flags;
  226. spin_lock_irqsave(&c->vc.lock, flags);
  227. if (vchan_issue_pending(&c->vc) && !c->desc) {
  228. /*
  229. * c->cyclic is used only by audio and in this case the DMA need
  230. * to be started without delay.
  231. */
  232. if (!c->cyclic) {
  233. struct omap_dmadev *d = to_omap_dma_dev(chan->device);
  234. spin_lock(&d->lock);
  235. if (list_empty(&c->node))
  236. list_add_tail(&c->node, &d->pending);
  237. spin_unlock(&d->lock);
  238. tasklet_schedule(&d->task);
  239. } else {
  240. omap_dma_start_desc(c);
  241. }
  242. }
  243. spin_unlock_irqrestore(&c->vc.lock, flags);
  244. }
  245. static struct dma_async_tx_descriptor *omap_dma_prep_slave_sg(
  246. struct dma_chan *chan, struct scatterlist *sgl, unsigned sglen,
  247. enum dma_transfer_direction dir, unsigned long tx_flags, void *context)
  248. {
  249. struct omap_chan *c = to_omap_dma_chan(chan);
  250. enum dma_slave_buswidth dev_width;
  251. struct scatterlist *sgent;
  252. struct omap_desc *d;
  253. dma_addr_t dev_addr;
  254. unsigned i, j = 0, es, en, frame_bytes, sync_type;
  255. u32 burst;
  256. if (dir == DMA_DEV_TO_MEM) {
  257. dev_addr = c->cfg.src_addr;
  258. dev_width = c->cfg.src_addr_width;
  259. burst = c->cfg.src_maxburst;
  260. sync_type = OMAP_DMA_SRC_SYNC;
  261. } else if (dir == DMA_MEM_TO_DEV) {
  262. dev_addr = c->cfg.dst_addr;
  263. dev_width = c->cfg.dst_addr_width;
  264. burst = c->cfg.dst_maxburst;
  265. sync_type = OMAP_DMA_DST_SYNC;
  266. } else {
  267. dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  268. return NULL;
  269. }
  270. /* Bus width translates to the element size (ES) */
  271. switch (dev_width) {
  272. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  273. es = OMAP_DMA_DATA_TYPE_S8;
  274. break;
  275. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  276. es = OMAP_DMA_DATA_TYPE_S16;
  277. break;
  278. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  279. es = OMAP_DMA_DATA_TYPE_S32;
  280. break;
  281. default: /* not reached */
  282. return NULL;
  283. }
  284. /* Now allocate and setup the descriptor. */
  285. d = kzalloc(sizeof(*d) + sglen * sizeof(d->sg[0]), GFP_ATOMIC);
  286. if (!d)
  287. return NULL;
  288. d->dir = dir;
  289. d->dev_addr = dev_addr;
  290. d->es = es;
  291. d->sync_mode = OMAP_DMA_SYNC_FRAME;
  292. d->sync_type = sync_type;
  293. d->periph_port = OMAP_DMA_PORT_TIPB;
  294. /*
  295. * Build our scatterlist entries: each contains the address,
  296. * the number of elements (EN) in each frame, and the number of
  297. * frames (FN). Number of bytes for this entry = ES * EN * FN.
  298. *
  299. * Burst size translates to number of elements with frame sync.
  300. * Note: DMA engine defines burst to be the number of dev-width
  301. * transfers.
  302. */
  303. en = burst;
  304. frame_bytes = es_bytes[es] * en;
  305. for_each_sg(sgl, sgent, sglen, i) {
  306. d->sg[j].addr = sg_dma_address(sgent);
  307. d->sg[j].en = en;
  308. d->sg[j].fn = sg_dma_len(sgent) / frame_bytes;
  309. j++;
  310. }
  311. d->sglen = j;
  312. return vchan_tx_prep(&c->vc, &d->vd, tx_flags);
  313. }
  314. static struct dma_async_tx_descriptor *omap_dma_prep_dma_cyclic(
  315. struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  316. size_t period_len, enum dma_transfer_direction dir, unsigned long flags,
  317. void *context)
  318. {
  319. struct omap_chan *c = to_omap_dma_chan(chan);
  320. enum dma_slave_buswidth dev_width;
  321. struct omap_desc *d;
  322. dma_addr_t dev_addr;
  323. unsigned es, sync_type;
  324. u32 burst;
  325. if (dir == DMA_DEV_TO_MEM) {
  326. dev_addr = c->cfg.src_addr;
  327. dev_width = c->cfg.src_addr_width;
  328. burst = c->cfg.src_maxburst;
  329. sync_type = OMAP_DMA_SRC_SYNC;
  330. } else if (dir == DMA_MEM_TO_DEV) {
  331. dev_addr = c->cfg.dst_addr;
  332. dev_width = c->cfg.dst_addr_width;
  333. burst = c->cfg.dst_maxburst;
  334. sync_type = OMAP_DMA_DST_SYNC;
  335. } else {
  336. dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  337. return NULL;
  338. }
  339. /* Bus width translates to the element size (ES) */
  340. switch (dev_width) {
  341. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  342. es = OMAP_DMA_DATA_TYPE_S8;
  343. break;
  344. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  345. es = OMAP_DMA_DATA_TYPE_S16;
  346. break;
  347. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  348. es = OMAP_DMA_DATA_TYPE_S32;
  349. break;
  350. default: /* not reached */
  351. return NULL;
  352. }
  353. /* Now allocate and setup the descriptor. */
  354. d = kzalloc(sizeof(*d) + sizeof(d->sg[0]), GFP_ATOMIC);
  355. if (!d)
  356. return NULL;
  357. d->dir = dir;
  358. d->dev_addr = dev_addr;
  359. d->fi = burst;
  360. d->es = es;
  361. if (burst)
  362. d->sync_mode = OMAP_DMA_SYNC_PACKET;
  363. else
  364. d->sync_mode = OMAP_DMA_SYNC_ELEMENT;
  365. d->sync_type = sync_type;
  366. d->periph_port = OMAP_DMA_PORT_MPUI;
  367. d->sg[0].addr = buf_addr;
  368. d->sg[0].en = period_len / es_bytes[es];
  369. d->sg[0].fn = buf_len / period_len;
  370. d->sglen = 1;
  371. if (!c->cyclic) {
  372. c->cyclic = true;
  373. omap_dma_link_lch(c->dma_ch, c->dma_ch);
  374. if (flags & DMA_PREP_INTERRUPT)
  375. omap_enable_dma_irq(c->dma_ch, OMAP_DMA_FRAME_IRQ);
  376. omap_disable_dma_irq(c->dma_ch, OMAP_DMA_BLOCK_IRQ);
  377. }
  378. if (dma_omap2plus()) {
  379. omap_set_dma_src_burst_mode(c->dma_ch, OMAP_DMA_DATA_BURST_16);
  380. omap_set_dma_dest_burst_mode(c->dma_ch, OMAP_DMA_DATA_BURST_16);
  381. }
  382. return vchan_tx_prep(&c->vc, &d->vd, flags);
  383. }
  384. static int omap_dma_slave_config(struct omap_chan *c, struct dma_slave_config *cfg)
  385. {
  386. if (cfg->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES ||
  387. cfg->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES)
  388. return -EINVAL;
  389. memcpy(&c->cfg, cfg, sizeof(c->cfg));
  390. return 0;
  391. }
  392. static int omap_dma_terminate_all(struct omap_chan *c)
  393. {
  394. struct omap_dmadev *d = to_omap_dma_dev(c->vc.chan.device);
  395. unsigned long flags;
  396. LIST_HEAD(head);
  397. spin_lock_irqsave(&c->vc.lock, flags);
  398. /* Prevent this channel being scheduled */
  399. spin_lock(&d->lock);
  400. list_del_init(&c->node);
  401. spin_unlock(&d->lock);
  402. /*
  403. * Stop DMA activity: we assume the callback will not be called
  404. * after omap_stop_dma() returns (even if it does, it will see
  405. * c->desc is NULL and exit.)
  406. */
  407. if (c->desc) {
  408. c->desc = NULL;
  409. /* Avoid stopping the dma twice */
  410. if (!c->paused)
  411. omap_stop_dma(c->dma_ch);
  412. }
  413. if (c->cyclic) {
  414. c->cyclic = false;
  415. c->paused = false;
  416. omap_dma_unlink_lch(c->dma_ch, c->dma_ch);
  417. }
  418. vchan_get_all_descriptors(&c->vc, &head);
  419. spin_unlock_irqrestore(&c->vc.lock, flags);
  420. vchan_dma_desc_free_list(&c->vc, &head);
  421. return 0;
  422. }
  423. static int omap_dma_pause(struct omap_chan *c)
  424. {
  425. /* Pause/Resume only allowed with cyclic mode */
  426. if (!c->cyclic)
  427. return -EINVAL;
  428. if (!c->paused) {
  429. omap_stop_dma(c->dma_ch);
  430. c->paused = true;
  431. }
  432. return 0;
  433. }
  434. static int omap_dma_resume(struct omap_chan *c)
  435. {
  436. /* Pause/Resume only allowed with cyclic mode */
  437. if (!c->cyclic)
  438. return -EINVAL;
  439. if (c->paused) {
  440. omap_start_dma(c->dma_ch);
  441. c->paused = false;
  442. }
  443. return 0;
  444. }
  445. static int omap_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  446. unsigned long arg)
  447. {
  448. struct omap_chan *c = to_omap_dma_chan(chan);
  449. int ret;
  450. switch (cmd) {
  451. case DMA_SLAVE_CONFIG:
  452. ret = omap_dma_slave_config(c, (struct dma_slave_config *)arg);
  453. break;
  454. case DMA_TERMINATE_ALL:
  455. ret = omap_dma_terminate_all(c);
  456. break;
  457. case DMA_PAUSE:
  458. ret = omap_dma_pause(c);
  459. break;
  460. case DMA_RESUME:
  461. ret = omap_dma_resume(c);
  462. break;
  463. default:
  464. ret = -ENXIO;
  465. break;
  466. }
  467. return ret;
  468. }
  469. static int omap_dma_chan_init(struct omap_dmadev *od, int dma_sig)
  470. {
  471. struct omap_chan *c;
  472. c = kzalloc(sizeof(*c), GFP_KERNEL);
  473. if (!c)
  474. return -ENOMEM;
  475. c->dma_sig = dma_sig;
  476. c->vc.desc_free = omap_dma_desc_free;
  477. vchan_init(&c->vc, &od->ddev);
  478. INIT_LIST_HEAD(&c->node);
  479. od->ddev.chancnt++;
  480. return 0;
  481. }
  482. static void omap_dma_free(struct omap_dmadev *od)
  483. {
  484. tasklet_kill(&od->task);
  485. while (!list_empty(&od->ddev.channels)) {
  486. struct omap_chan *c = list_first_entry(&od->ddev.channels,
  487. struct omap_chan, vc.chan.device_node);
  488. list_del(&c->vc.chan.device_node);
  489. tasklet_kill(&c->vc.task);
  490. kfree(c);
  491. }
  492. kfree(od);
  493. }
  494. static int omap_dma_probe(struct platform_device *pdev)
  495. {
  496. struct omap_dmadev *od;
  497. int rc, i;
  498. od = kzalloc(sizeof(*od), GFP_KERNEL);
  499. if (!od)
  500. return -ENOMEM;
  501. dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  502. dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  503. od->ddev.device_alloc_chan_resources = omap_dma_alloc_chan_resources;
  504. od->ddev.device_free_chan_resources = omap_dma_free_chan_resources;
  505. od->ddev.device_tx_status = omap_dma_tx_status;
  506. od->ddev.device_issue_pending = omap_dma_issue_pending;
  507. od->ddev.device_prep_slave_sg = omap_dma_prep_slave_sg;
  508. od->ddev.device_prep_dma_cyclic = omap_dma_prep_dma_cyclic;
  509. od->ddev.device_control = omap_dma_control;
  510. od->ddev.dev = &pdev->dev;
  511. INIT_LIST_HEAD(&od->ddev.channels);
  512. INIT_LIST_HEAD(&od->pending);
  513. spin_lock_init(&od->lock);
  514. tasklet_init(&od->task, omap_dma_sched, (unsigned long)od);
  515. for (i = 0; i < 127; i++) {
  516. rc = omap_dma_chan_init(od, i);
  517. if (rc) {
  518. omap_dma_free(od);
  519. return rc;
  520. }
  521. }
  522. rc = dma_async_device_register(&od->ddev);
  523. if (rc) {
  524. pr_warn("OMAP-DMA: failed to register slave DMA engine device: %d\n",
  525. rc);
  526. omap_dma_free(od);
  527. } else {
  528. platform_set_drvdata(pdev, od);
  529. }
  530. dev_info(&pdev->dev, "OMAP DMA engine driver\n");
  531. return rc;
  532. }
  533. static int omap_dma_remove(struct platform_device *pdev)
  534. {
  535. struct omap_dmadev *od = platform_get_drvdata(pdev);
  536. dma_async_device_unregister(&od->ddev);
  537. omap_dma_free(od);
  538. return 0;
  539. }
  540. static struct platform_driver omap_dma_driver = {
  541. .probe = omap_dma_probe,
  542. .remove = omap_dma_remove,
  543. .driver = {
  544. .name = "omap-dma-engine",
  545. .owner = THIS_MODULE,
  546. },
  547. };
  548. bool omap_dma_filter_fn(struct dma_chan *chan, void *param)
  549. {
  550. if (chan->device->dev->driver == &omap_dma_driver.driver) {
  551. struct omap_chan *c = to_omap_dma_chan(chan);
  552. unsigned req = *(unsigned *)param;
  553. return req == c->dma_sig;
  554. }
  555. return false;
  556. }
  557. EXPORT_SYMBOL_GPL(omap_dma_filter_fn);
  558. static int omap_dma_init(void)
  559. {
  560. return platform_driver_register(&omap_dma_driver);
  561. }
  562. subsys_initcall(omap_dma_init);
  563. static void __exit omap_dma_exit(void)
  564. {
  565. platform_driver_unregister(&omap_dma_driver);
  566. }
  567. module_exit(omap_dma_exit);
  568. MODULE_AUTHOR("Russell King");
  569. MODULE_LICENSE("GPL");