omap-dma.c 17 KB

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