imx-dma.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. * drivers/dma/imx-dma.c
  3. *
  4. * This file contains a driver for the Freescale i.MX DMA engine
  5. * found on i.MX1/21/27
  6. *
  7. * Copyright 2010 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
  8. * Copyright 2012 Javier Martin, Vista Silicon <javier.martin@vista-silicon.com>
  9. *
  10. * The code contained herein is licensed under the GNU General Public
  11. * License. You may obtain a copy of the GNU General Public License
  12. * Version 2 or later at the following locations:
  13. *
  14. * http://www.opensource.org/licenses/gpl-license.html
  15. * http://www.gnu.org/copyleft/gpl.html
  16. */
  17. #include <linux/init.h>
  18. #include <linux/module.h>
  19. #include <linux/types.h>
  20. #include <linux/mm.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/device.h>
  24. #include <linux/dma-mapping.h>
  25. #include <linux/slab.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/dmaengine.h>
  28. #include <asm/irq.h>
  29. #include <mach/dma-v1.h>
  30. #include <mach/hardware.h>
  31. #define IMXDMA_MAX_CHAN_DESCRIPTORS 16
  32. enum imxdma_prep_type {
  33. IMXDMA_DESC_MEMCPY,
  34. IMXDMA_DESC_INTERLEAVED,
  35. IMXDMA_DESC_SLAVE_SG,
  36. IMXDMA_DESC_CYCLIC,
  37. };
  38. struct imxdma_desc {
  39. struct list_head node;
  40. struct dma_async_tx_descriptor desc;
  41. enum dma_status status;
  42. dma_addr_t src;
  43. dma_addr_t dest;
  44. size_t len;
  45. unsigned int dmamode;
  46. enum imxdma_prep_type type;
  47. /* For memcpy and interleaved */
  48. unsigned int config_port;
  49. unsigned int config_mem;
  50. /* For interleaved transfers */
  51. unsigned int x;
  52. unsigned int y;
  53. unsigned int w;
  54. /* For slave sg and cyclic */
  55. struct scatterlist *sg;
  56. unsigned int sgcount;
  57. };
  58. struct imxdma_channel {
  59. struct imxdma_engine *imxdma;
  60. unsigned int channel;
  61. unsigned int imxdma_channel;
  62. struct tasklet_struct dma_tasklet;
  63. struct list_head ld_free;
  64. struct list_head ld_queue;
  65. struct list_head ld_active;
  66. int descs_allocated;
  67. enum dma_slave_buswidth word_size;
  68. dma_addr_t per_address;
  69. u32 watermark_level;
  70. struct dma_chan chan;
  71. spinlock_t lock;
  72. dma_cookie_t last_completed;
  73. int dma_request;
  74. struct scatterlist *sg_list;
  75. };
  76. #define MAX_DMA_CHANNELS 8
  77. struct imxdma_engine {
  78. struct device *dev;
  79. struct device_dma_parameters dma_parms;
  80. struct dma_device dma_device;
  81. struct imxdma_channel channel[MAX_DMA_CHANNELS];
  82. };
  83. static struct imxdma_channel *to_imxdma_chan(struct dma_chan *chan)
  84. {
  85. return container_of(chan, struct imxdma_channel, chan);
  86. }
  87. static inline bool imxdma_chan_is_doing_cyclic(struct imxdma_channel *imxdmac)
  88. {
  89. struct imxdma_desc *desc;
  90. if (!list_empty(&imxdmac->ld_active)) {
  91. desc = list_first_entry(&imxdmac->ld_active, struct imxdma_desc,
  92. node);
  93. if (desc->type == IMXDMA_DESC_CYCLIC)
  94. return true;
  95. }
  96. return false;
  97. }
  98. static void imxdma_irq_handler(int channel, void *data)
  99. {
  100. struct imxdma_channel *imxdmac = data;
  101. tasklet_schedule(&imxdmac->dma_tasklet);
  102. }
  103. static void imxdma_err_handler(int channel, void *data, int error)
  104. {
  105. struct imxdma_channel *imxdmac = data;
  106. tasklet_schedule(&imxdmac->dma_tasklet);
  107. }
  108. static void imxdma_progression(int channel, void *data,
  109. struct scatterlist *sg)
  110. {
  111. struct imxdma_channel *imxdmac = data;
  112. tasklet_schedule(&imxdmac->dma_tasklet);
  113. }
  114. static int imxdma_xfer_desc(struct imxdma_desc *d)
  115. {
  116. struct imxdma_channel *imxdmac = to_imxdma_chan(d->desc.chan);
  117. int ret;
  118. /* Configure and enable */
  119. switch (d->type) {
  120. case IMXDMA_DESC_MEMCPY:
  121. ret = imx_dma_config_channel(imxdmac->imxdma_channel,
  122. d->config_port, d->config_mem, 0, 0);
  123. if (ret < 0)
  124. return ret;
  125. ret = imx_dma_setup_single(imxdmac->imxdma_channel, d->src,
  126. d->len, d->dest, d->dmamode);
  127. if (ret < 0)
  128. return ret;
  129. break;
  130. case IMXDMA_DESC_CYCLIC:
  131. ret = imx_dma_setup_progression_handler(imxdmac->imxdma_channel,
  132. imxdma_progression);
  133. if (ret < 0)
  134. return ret;
  135. /*
  136. * We fall through here since cyclic transfer is the same as
  137. * slave_sg adding a progression handler and a specific sg
  138. * configuration which is done in 'imxdma_prep_dma_cyclic'.
  139. */
  140. case IMXDMA_DESC_SLAVE_SG:
  141. if (d->dmamode == DMA_MODE_READ)
  142. ret = imx_dma_setup_sg(imxdmac->imxdma_channel, d->sg,
  143. d->sgcount, d->len, d->src, d->dmamode);
  144. else
  145. ret = imx_dma_setup_sg(imxdmac->imxdma_channel, d->sg,
  146. d->sgcount, d->len, d->dest, d->dmamode);
  147. if (ret < 0)
  148. return ret;
  149. break;
  150. default:
  151. return -EINVAL;
  152. }
  153. imx_dma_enable(imxdmac->imxdma_channel);
  154. return 0;
  155. }
  156. static void imxdma_tasklet(unsigned long data)
  157. {
  158. struct imxdma_channel *imxdmac = (void *)data;
  159. struct imxdma_engine *imxdma = imxdmac->imxdma;
  160. struct imxdma_desc *desc;
  161. spin_lock(&imxdmac->lock);
  162. if (list_empty(&imxdmac->ld_active)) {
  163. /* Someone might have called terminate all */
  164. goto out;
  165. }
  166. desc = list_first_entry(&imxdmac->ld_active, struct imxdma_desc, node);
  167. if (desc->desc.callback)
  168. desc->desc.callback(desc->desc.callback_param);
  169. imxdmac->last_completed = desc->desc.cookie;
  170. /* If we are dealing with a cyclic descriptor keep it on ld_active */
  171. if (imxdma_chan_is_doing_cyclic(imxdmac))
  172. goto out;
  173. list_move_tail(imxdmac->ld_active.next, &imxdmac->ld_free);
  174. if (!list_empty(&imxdmac->ld_queue)) {
  175. desc = list_first_entry(&imxdmac->ld_queue, struct imxdma_desc,
  176. node);
  177. list_move_tail(imxdmac->ld_queue.next, &imxdmac->ld_active);
  178. if (imxdma_xfer_desc(desc) < 0)
  179. dev_warn(imxdma->dev, "%s: channel: %d couldn't xfer desc\n",
  180. __func__, imxdmac->channel);
  181. }
  182. out:
  183. spin_unlock(&imxdmac->lock);
  184. }
  185. static int imxdma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  186. unsigned long arg)
  187. {
  188. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  189. struct dma_slave_config *dmaengine_cfg = (void *)arg;
  190. int ret;
  191. unsigned long flags;
  192. unsigned int mode = 0;
  193. switch (cmd) {
  194. case DMA_TERMINATE_ALL:
  195. imx_dma_disable(imxdmac->imxdma_channel);
  196. spin_lock_irqsave(&imxdmac->lock, flags);
  197. list_splice_tail_init(&imxdmac->ld_active, &imxdmac->ld_free);
  198. list_splice_tail_init(&imxdmac->ld_queue, &imxdmac->ld_free);
  199. spin_unlock_irqrestore(&imxdmac->lock, flags);
  200. return 0;
  201. case DMA_SLAVE_CONFIG:
  202. if (dmaengine_cfg->direction == DMA_DEV_TO_MEM) {
  203. imxdmac->per_address = dmaengine_cfg->src_addr;
  204. imxdmac->watermark_level = dmaengine_cfg->src_maxburst;
  205. imxdmac->word_size = dmaengine_cfg->src_addr_width;
  206. } else {
  207. imxdmac->per_address = dmaengine_cfg->dst_addr;
  208. imxdmac->watermark_level = dmaengine_cfg->dst_maxburst;
  209. imxdmac->word_size = dmaengine_cfg->dst_addr_width;
  210. }
  211. switch (imxdmac->word_size) {
  212. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  213. mode = IMX_DMA_MEMSIZE_8;
  214. break;
  215. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  216. mode = IMX_DMA_MEMSIZE_16;
  217. break;
  218. default:
  219. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  220. mode = IMX_DMA_MEMSIZE_32;
  221. break;
  222. }
  223. ret = imx_dma_config_channel(imxdmac->imxdma_channel,
  224. mode | IMX_DMA_TYPE_FIFO,
  225. IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR,
  226. imxdmac->dma_request, 1);
  227. if (ret)
  228. return ret;
  229. imx_dma_config_burstlen(imxdmac->imxdma_channel,
  230. imxdmac->watermark_level * imxdmac->word_size);
  231. return 0;
  232. default:
  233. return -ENOSYS;
  234. }
  235. return -EINVAL;
  236. }
  237. static enum dma_status imxdma_tx_status(struct dma_chan *chan,
  238. dma_cookie_t cookie,
  239. struct dma_tx_state *txstate)
  240. {
  241. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  242. dma_cookie_t last_used;
  243. enum dma_status ret;
  244. unsigned long flags;
  245. spin_lock_irqsave(&imxdmac->lock, flags);
  246. last_used = chan->cookie;
  247. ret = dma_async_is_complete(cookie, imxdmac->last_completed, last_used);
  248. dma_set_tx_state(txstate, imxdmac->last_completed, last_used, 0);
  249. spin_unlock_irqrestore(&imxdmac->lock, flags);
  250. return ret;
  251. }
  252. static dma_cookie_t imxdma_assign_cookie(struct imxdma_channel *imxdma)
  253. {
  254. dma_cookie_t cookie = imxdma->chan.cookie;
  255. if (++cookie < 0)
  256. cookie = 1;
  257. imxdma->chan.cookie = cookie;
  258. return cookie;
  259. }
  260. static dma_cookie_t imxdma_tx_submit(struct dma_async_tx_descriptor *tx)
  261. {
  262. struct imxdma_channel *imxdmac = to_imxdma_chan(tx->chan);
  263. dma_cookie_t cookie;
  264. unsigned long flags;
  265. spin_lock_irqsave(&imxdmac->lock, flags);
  266. list_move_tail(imxdmac->ld_free.next, &imxdmac->ld_queue);
  267. cookie = imxdma_assign_cookie(imxdmac);
  268. tx->cookie = cookie;
  269. spin_unlock_irqrestore(&imxdmac->lock, flags);
  270. return cookie;
  271. }
  272. static int imxdma_alloc_chan_resources(struct dma_chan *chan)
  273. {
  274. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  275. struct imx_dma_data *data = chan->private;
  276. if (data != NULL)
  277. imxdmac->dma_request = data->dma_request;
  278. while (imxdmac->descs_allocated < IMXDMA_MAX_CHAN_DESCRIPTORS) {
  279. struct imxdma_desc *desc;
  280. desc = kzalloc(sizeof(*desc), GFP_KERNEL);
  281. if (!desc)
  282. break;
  283. __memzero(&desc->desc, sizeof(struct dma_async_tx_descriptor));
  284. dma_async_tx_descriptor_init(&desc->desc, chan);
  285. desc->desc.tx_submit = imxdma_tx_submit;
  286. /* txd.flags will be overwritten in prep funcs */
  287. desc->desc.flags = DMA_CTRL_ACK;
  288. desc->status = DMA_SUCCESS;
  289. list_add_tail(&desc->node, &imxdmac->ld_free);
  290. imxdmac->descs_allocated++;
  291. }
  292. if (!imxdmac->descs_allocated)
  293. return -ENOMEM;
  294. return imxdmac->descs_allocated;
  295. }
  296. static void imxdma_free_chan_resources(struct dma_chan *chan)
  297. {
  298. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  299. struct imxdma_desc *desc, *_desc;
  300. unsigned long flags;
  301. spin_lock_irqsave(&imxdmac->lock, flags);
  302. imx_dma_disable(imxdmac->imxdma_channel);
  303. list_splice_tail_init(&imxdmac->ld_active, &imxdmac->ld_free);
  304. list_splice_tail_init(&imxdmac->ld_queue, &imxdmac->ld_free);
  305. spin_unlock_irqrestore(&imxdmac->lock, flags);
  306. list_for_each_entry_safe(desc, _desc, &imxdmac->ld_free, node) {
  307. kfree(desc);
  308. imxdmac->descs_allocated--;
  309. }
  310. INIT_LIST_HEAD(&imxdmac->ld_free);
  311. if (imxdmac->sg_list) {
  312. kfree(imxdmac->sg_list);
  313. imxdmac->sg_list = NULL;
  314. }
  315. }
  316. static struct dma_async_tx_descriptor *imxdma_prep_slave_sg(
  317. struct dma_chan *chan, struct scatterlist *sgl,
  318. unsigned int sg_len, enum dma_transfer_direction direction,
  319. unsigned long flags)
  320. {
  321. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  322. struct scatterlist *sg;
  323. int i, dma_length = 0;
  324. struct imxdma_desc *desc;
  325. if (list_empty(&imxdmac->ld_free) ||
  326. imxdma_chan_is_doing_cyclic(imxdmac))
  327. return NULL;
  328. desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  329. for_each_sg(sgl, sg, sg_len, i) {
  330. dma_length += sg->length;
  331. }
  332. switch (imxdmac->word_size) {
  333. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  334. if (sgl->length & 3 || sgl->dma_address & 3)
  335. return NULL;
  336. break;
  337. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  338. if (sgl->length & 1 || sgl->dma_address & 1)
  339. return NULL;
  340. break;
  341. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  342. break;
  343. default:
  344. return NULL;
  345. }
  346. desc->type = IMXDMA_DESC_SLAVE_SG;
  347. desc->sg = sgl;
  348. desc->sgcount = sg_len;
  349. desc->len = dma_length;
  350. if (direction == DMA_DEV_TO_MEM) {
  351. desc->dmamode = DMA_MODE_READ;
  352. desc->src = imxdmac->per_address;
  353. } else {
  354. desc->dmamode = DMA_MODE_WRITE;
  355. desc->dest = imxdmac->per_address;
  356. }
  357. desc->desc.callback = NULL;
  358. desc->desc.callback_param = NULL;
  359. return &desc->desc;
  360. }
  361. static struct dma_async_tx_descriptor *imxdma_prep_dma_cyclic(
  362. struct dma_chan *chan, dma_addr_t dma_addr, size_t buf_len,
  363. size_t period_len, enum dma_transfer_direction direction)
  364. {
  365. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  366. struct imxdma_engine *imxdma = imxdmac->imxdma;
  367. struct imxdma_desc *desc;
  368. int i;
  369. unsigned int periods = buf_len / period_len;
  370. dev_dbg(imxdma->dev, "%s channel: %d buf_len=%d period_len=%d\n",
  371. __func__, imxdmac->channel, buf_len, period_len);
  372. if (list_empty(&imxdmac->ld_free) ||
  373. imxdma_chan_is_doing_cyclic(imxdmac))
  374. return NULL;
  375. desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  376. if (imxdmac->sg_list)
  377. kfree(imxdmac->sg_list);
  378. imxdmac->sg_list = kcalloc(periods + 1,
  379. sizeof(struct scatterlist), GFP_KERNEL);
  380. if (!imxdmac->sg_list)
  381. return NULL;
  382. sg_init_table(imxdmac->sg_list, periods);
  383. for (i = 0; i < periods; i++) {
  384. imxdmac->sg_list[i].page_link = 0;
  385. imxdmac->sg_list[i].offset = 0;
  386. imxdmac->sg_list[i].dma_address = dma_addr;
  387. imxdmac->sg_list[i].length = period_len;
  388. dma_addr += period_len;
  389. }
  390. /* close the loop */
  391. imxdmac->sg_list[periods].offset = 0;
  392. imxdmac->sg_list[periods].length = 0;
  393. imxdmac->sg_list[periods].page_link =
  394. ((unsigned long)imxdmac->sg_list | 0x01) & ~0x02;
  395. desc->type = IMXDMA_DESC_CYCLIC;
  396. desc->sg = imxdmac->sg_list;
  397. desc->sgcount = periods;
  398. desc->len = IMX_DMA_LENGTH_LOOP;
  399. if (direction == DMA_DEV_TO_MEM) {
  400. desc->dmamode = DMA_MODE_READ;
  401. desc->src = imxdmac->per_address;
  402. } else {
  403. desc->dmamode = DMA_MODE_WRITE;
  404. desc->dest = imxdmac->per_address;
  405. }
  406. desc->desc.callback = NULL;
  407. desc->desc.callback_param = NULL;
  408. return &desc->desc;
  409. }
  410. static struct dma_async_tx_descriptor *imxdma_prep_dma_memcpy(
  411. struct dma_chan *chan, dma_addr_t dest,
  412. dma_addr_t src, size_t len, unsigned long flags)
  413. {
  414. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  415. struct imxdma_engine *imxdma = imxdmac->imxdma;
  416. struct imxdma_desc *desc;
  417. dev_dbg(imxdma->dev, "%s channel: %d src=0x%x dst=0x%x len=%d\n",
  418. __func__, imxdmac->channel, src, dest, len);
  419. if (list_empty(&imxdmac->ld_free) ||
  420. imxdma_chan_is_doing_cyclic(imxdmac))
  421. return NULL;
  422. desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  423. desc->type = IMXDMA_DESC_MEMCPY;
  424. desc->src = src;
  425. desc->dest = dest;
  426. desc->len = len;
  427. desc->dmamode = DMA_MODE_WRITE;
  428. desc->config_port = IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR;
  429. desc->config_mem = IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR;
  430. desc->desc.callback = NULL;
  431. desc->desc.callback_param = NULL;
  432. return &desc->desc;
  433. }
  434. static void imxdma_issue_pending(struct dma_chan *chan)
  435. {
  436. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  437. struct imxdma_engine *imxdma = imxdmac->imxdma;
  438. struct imxdma_desc *desc;
  439. unsigned long flags;
  440. spin_lock_irqsave(&imxdmac->lock, flags);
  441. if (list_empty(&imxdmac->ld_active) &&
  442. !list_empty(&imxdmac->ld_queue)) {
  443. desc = list_first_entry(&imxdmac->ld_queue,
  444. struct imxdma_desc, node);
  445. if (imxdma_xfer_desc(desc) < 0) {
  446. dev_warn(imxdma->dev,
  447. "%s: channel: %d couldn't issue DMA xfer\n",
  448. __func__, imxdmac->channel);
  449. } else {
  450. list_move_tail(imxdmac->ld_queue.next,
  451. &imxdmac->ld_active);
  452. }
  453. }
  454. spin_unlock_irqrestore(&imxdmac->lock, flags);
  455. }
  456. static int __init imxdma_probe(struct platform_device *pdev)
  457. {
  458. struct imxdma_engine *imxdma;
  459. int ret, i;
  460. imxdma = kzalloc(sizeof(*imxdma), GFP_KERNEL);
  461. if (!imxdma)
  462. return -ENOMEM;
  463. INIT_LIST_HEAD(&imxdma->dma_device.channels);
  464. dma_cap_set(DMA_SLAVE, imxdma->dma_device.cap_mask);
  465. dma_cap_set(DMA_CYCLIC, imxdma->dma_device.cap_mask);
  466. dma_cap_set(DMA_MEMCPY, imxdma->dma_device.cap_mask);
  467. /* Initialize channel parameters */
  468. for (i = 0; i < MAX_DMA_CHANNELS; i++) {
  469. struct imxdma_channel *imxdmac = &imxdma->channel[i];
  470. imxdmac->imxdma_channel = imx_dma_request_by_prio("dmaengine",
  471. DMA_PRIO_MEDIUM);
  472. if ((int)imxdmac->channel < 0) {
  473. ret = -ENODEV;
  474. goto err_init;
  475. }
  476. imx_dma_setup_handlers(imxdmac->imxdma_channel,
  477. imxdma_irq_handler, imxdma_err_handler, imxdmac);
  478. imxdmac->imxdma = imxdma;
  479. spin_lock_init(&imxdmac->lock);
  480. INIT_LIST_HEAD(&imxdmac->ld_queue);
  481. INIT_LIST_HEAD(&imxdmac->ld_free);
  482. INIT_LIST_HEAD(&imxdmac->ld_active);
  483. tasklet_init(&imxdmac->dma_tasklet, imxdma_tasklet,
  484. (unsigned long)imxdmac);
  485. imxdmac->chan.device = &imxdma->dma_device;
  486. imxdmac->channel = i;
  487. /* Add the channel to the DMAC list */
  488. list_add_tail(&imxdmac->chan.device_node,
  489. &imxdma->dma_device.channels);
  490. }
  491. imxdma->dev = &pdev->dev;
  492. imxdma->dma_device.dev = &pdev->dev;
  493. imxdma->dma_device.device_alloc_chan_resources = imxdma_alloc_chan_resources;
  494. imxdma->dma_device.device_free_chan_resources = imxdma_free_chan_resources;
  495. imxdma->dma_device.device_tx_status = imxdma_tx_status;
  496. imxdma->dma_device.device_prep_slave_sg = imxdma_prep_slave_sg;
  497. imxdma->dma_device.device_prep_dma_cyclic = imxdma_prep_dma_cyclic;
  498. imxdma->dma_device.device_prep_dma_memcpy = imxdma_prep_dma_memcpy;
  499. imxdma->dma_device.device_control = imxdma_control;
  500. imxdma->dma_device.device_issue_pending = imxdma_issue_pending;
  501. platform_set_drvdata(pdev, imxdma);
  502. imxdma->dma_device.copy_align = 2; /* 2^2 = 4 bytes alignment */
  503. imxdma->dma_device.dev->dma_parms = &imxdma->dma_parms;
  504. dma_set_max_seg_size(imxdma->dma_device.dev, 0xffffff);
  505. ret = dma_async_device_register(&imxdma->dma_device);
  506. if (ret) {
  507. dev_err(&pdev->dev, "unable to register\n");
  508. goto err_init;
  509. }
  510. return 0;
  511. err_init:
  512. while (--i >= 0) {
  513. struct imxdma_channel *imxdmac = &imxdma->channel[i];
  514. imx_dma_free(imxdmac->imxdma_channel);
  515. }
  516. kfree(imxdma);
  517. return ret;
  518. }
  519. static int __exit imxdma_remove(struct platform_device *pdev)
  520. {
  521. struct imxdma_engine *imxdma = platform_get_drvdata(pdev);
  522. int i;
  523. dma_async_device_unregister(&imxdma->dma_device);
  524. for (i = 0; i < MAX_DMA_CHANNELS; i++) {
  525. struct imxdma_channel *imxdmac = &imxdma->channel[i];
  526. imx_dma_free(imxdmac->imxdma_channel);
  527. }
  528. kfree(imxdma);
  529. return 0;
  530. }
  531. static struct platform_driver imxdma_driver = {
  532. .driver = {
  533. .name = "imx-dma",
  534. },
  535. .remove = __exit_p(imxdma_remove),
  536. };
  537. static int __init imxdma_module_init(void)
  538. {
  539. return platform_driver_probe(&imxdma_driver, imxdma_probe);
  540. }
  541. subsys_initcall(imxdma_module_init);
  542. MODULE_AUTHOR("Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>");
  543. MODULE_DESCRIPTION("i.MX dma driver");
  544. MODULE_LICENSE("GPL");