omap-dma.c 16 KB

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