omap-dma.c 16 KB

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