omap-dma.c 16 KB

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