imx-dma.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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/types.h>
  19. #include <linux/mm.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/device.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/slab.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/clk.h>
  27. #include <linux/dmaengine.h>
  28. #include <linux/module.h>
  29. #include <asm/irq.h>
  30. #include <mach/dma.h>
  31. #include <mach/hardware.h>
  32. #include "dmaengine.h"
  33. #define IMXDMA_MAX_CHAN_DESCRIPTORS 16
  34. #define IMX_DMA_CHANNELS 16
  35. #define IMX_DMA_2D_SLOTS 2
  36. #define IMX_DMA_2D_SLOT_A 0
  37. #define IMX_DMA_2D_SLOT_B 1
  38. #define IMX_DMA_LENGTH_LOOP ((unsigned int)-1)
  39. #define IMX_DMA_MEMSIZE_32 (0 << 4)
  40. #define IMX_DMA_MEMSIZE_8 (1 << 4)
  41. #define IMX_DMA_MEMSIZE_16 (2 << 4)
  42. #define IMX_DMA_TYPE_LINEAR (0 << 10)
  43. #define IMX_DMA_TYPE_2D (1 << 10)
  44. #define IMX_DMA_TYPE_FIFO (2 << 10)
  45. #define IMX_DMA_ERR_BURST (1 << 0)
  46. #define IMX_DMA_ERR_REQUEST (1 << 1)
  47. #define IMX_DMA_ERR_TRANSFER (1 << 2)
  48. #define IMX_DMA_ERR_BUFFER (1 << 3)
  49. #define IMX_DMA_ERR_TIMEOUT (1 << 4)
  50. #define DMA_DCR 0x00 /* Control Register */
  51. #define DMA_DISR 0x04 /* Interrupt status Register */
  52. #define DMA_DIMR 0x08 /* Interrupt mask Register */
  53. #define DMA_DBTOSR 0x0c /* Burst timeout status Register */
  54. #define DMA_DRTOSR 0x10 /* Request timeout Register */
  55. #define DMA_DSESR 0x14 /* Transfer Error Status Register */
  56. #define DMA_DBOSR 0x18 /* Buffer overflow status Register */
  57. #define DMA_DBTOCR 0x1c /* Burst timeout control Register */
  58. #define DMA_WSRA 0x40 /* W-Size Register A */
  59. #define DMA_XSRA 0x44 /* X-Size Register A */
  60. #define DMA_YSRA 0x48 /* Y-Size Register A */
  61. #define DMA_WSRB 0x4c /* W-Size Register B */
  62. #define DMA_XSRB 0x50 /* X-Size Register B */
  63. #define DMA_YSRB 0x54 /* Y-Size Register B */
  64. #define DMA_SAR(x) (0x80 + ((x) << 6)) /* Source Address Registers */
  65. #define DMA_DAR(x) (0x84 + ((x) << 6)) /* Destination Address Registers */
  66. #define DMA_CNTR(x) (0x88 + ((x) << 6)) /* Count Registers */
  67. #define DMA_CCR(x) (0x8c + ((x) << 6)) /* Control Registers */
  68. #define DMA_RSSR(x) (0x90 + ((x) << 6)) /* Request source select Registers */
  69. #define DMA_BLR(x) (0x94 + ((x) << 6)) /* Burst length Registers */
  70. #define DMA_RTOR(x) (0x98 + ((x) << 6)) /* Request timeout Registers */
  71. #define DMA_BUCR(x) (0x98 + ((x) << 6)) /* Bus Utilization Registers */
  72. #define DMA_CCNR(x) (0x9C + ((x) << 6)) /* Channel counter Registers */
  73. #define DCR_DRST (1<<1)
  74. #define DCR_DEN (1<<0)
  75. #define DBTOCR_EN (1<<15)
  76. #define DBTOCR_CNT(x) ((x) & 0x7fff)
  77. #define CNTR_CNT(x) ((x) & 0xffffff)
  78. #define CCR_ACRPT (1<<14)
  79. #define CCR_DMOD_LINEAR (0x0 << 12)
  80. #define CCR_DMOD_2D (0x1 << 12)
  81. #define CCR_DMOD_FIFO (0x2 << 12)
  82. #define CCR_DMOD_EOBFIFO (0x3 << 12)
  83. #define CCR_SMOD_LINEAR (0x0 << 10)
  84. #define CCR_SMOD_2D (0x1 << 10)
  85. #define CCR_SMOD_FIFO (0x2 << 10)
  86. #define CCR_SMOD_EOBFIFO (0x3 << 10)
  87. #define CCR_MDIR_DEC (1<<9)
  88. #define CCR_MSEL_B (1<<8)
  89. #define CCR_DSIZ_32 (0x0 << 6)
  90. #define CCR_DSIZ_8 (0x1 << 6)
  91. #define CCR_DSIZ_16 (0x2 << 6)
  92. #define CCR_SSIZ_32 (0x0 << 4)
  93. #define CCR_SSIZ_8 (0x1 << 4)
  94. #define CCR_SSIZ_16 (0x2 << 4)
  95. #define CCR_REN (1<<3)
  96. #define CCR_RPT (1<<2)
  97. #define CCR_FRC (1<<1)
  98. #define CCR_CEN (1<<0)
  99. #define RTOR_EN (1<<15)
  100. #define RTOR_CLK (1<<14)
  101. #define RTOR_PSC (1<<13)
  102. enum imxdma_prep_type {
  103. IMXDMA_DESC_MEMCPY,
  104. IMXDMA_DESC_INTERLEAVED,
  105. IMXDMA_DESC_SLAVE_SG,
  106. IMXDMA_DESC_CYCLIC,
  107. };
  108. struct imx_dma_2d_config {
  109. u16 xsr;
  110. u16 ysr;
  111. u16 wsr;
  112. int count;
  113. };
  114. struct imxdma_desc {
  115. struct list_head node;
  116. struct dma_async_tx_descriptor desc;
  117. enum dma_status status;
  118. dma_addr_t src;
  119. dma_addr_t dest;
  120. size_t len;
  121. enum dma_transfer_direction direction;
  122. enum imxdma_prep_type type;
  123. /* For memcpy and interleaved */
  124. unsigned int config_port;
  125. unsigned int config_mem;
  126. /* For interleaved transfers */
  127. unsigned int x;
  128. unsigned int y;
  129. unsigned int w;
  130. /* For slave sg and cyclic */
  131. struct scatterlist *sg;
  132. unsigned int sgcount;
  133. };
  134. struct imxdma_channel {
  135. int hw_chaining;
  136. struct timer_list watchdog;
  137. struct imxdma_engine *imxdma;
  138. unsigned int channel;
  139. struct tasklet_struct dma_tasklet;
  140. struct list_head ld_free;
  141. struct list_head ld_queue;
  142. struct list_head ld_active;
  143. int descs_allocated;
  144. enum dma_slave_buswidth word_size;
  145. dma_addr_t per_address;
  146. u32 watermark_level;
  147. struct dma_chan chan;
  148. struct dma_async_tx_descriptor desc;
  149. enum dma_status status;
  150. int dma_request;
  151. struct scatterlist *sg_list;
  152. u32 ccr_from_device;
  153. u32 ccr_to_device;
  154. bool enabled_2d;
  155. int slot_2d;
  156. };
  157. struct imxdma_engine {
  158. struct device *dev;
  159. struct device_dma_parameters dma_parms;
  160. struct dma_device dma_device;
  161. void __iomem *base;
  162. struct clk *dma_clk;
  163. spinlock_t lock;
  164. struct imx_dma_2d_config slots_2d[IMX_DMA_2D_SLOTS];
  165. struct imxdma_channel channel[IMX_DMA_CHANNELS];
  166. };
  167. static struct imxdma_channel *to_imxdma_chan(struct dma_chan *chan)
  168. {
  169. return container_of(chan, struct imxdma_channel, chan);
  170. }
  171. static inline bool imxdma_chan_is_doing_cyclic(struct imxdma_channel *imxdmac)
  172. {
  173. struct imxdma_desc *desc;
  174. if (!list_empty(&imxdmac->ld_active)) {
  175. desc = list_first_entry(&imxdmac->ld_active, struct imxdma_desc,
  176. node);
  177. if (desc->type == IMXDMA_DESC_CYCLIC)
  178. return true;
  179. }
  180. return false;
  181. }
  182. static void imx_dmav1_writel(struct imxdma_engine *imxdma, unsigned val,
  183. unsigned offset)
  184. {
  185. __raw_writel(val, imxdma->base + offset);
  186. }
  187. static unsigned imx_dmav1_readl(struct imxdma_engine *imxdma, unsigned offset)
  188. {
  189. return __raw_readl(imxdma->base + offset);
  190. }
  191. static int imxdma_hw_chain(struct imxdma_channel *imxdmac)
  192. {
  193. if (cpu_is_mx27())
  194. return imxdmac->hw_chaining;
  195. else
  196. return 0;
  197. }
  198. /*
  199. * imxdma_sg_next - prepare next chunk for scatter-gather DMA emulation
  200. */
  201. static inline int imxdma_sg_next(struct imxdma_desc *d)
  202. {
  203. struct imxdma_channel *imxdmac = to_imxdma_chan(d->desc.chan);
  204. struct imxdma_engine *imxdma = imxdmac->imxdma;
  205. struct scatterlist *sg = d->sg;
  206. unsigned long now;
  207. now = min(d->len, sg->length);
  208. if (d->len != IMX_DMA_LENGTH_LOOP)
  209. d->len -= now;
  210. if (d->direction == DMA_DEV_TO_MEM)
  211. imx_dmav1_writel(imxdma, sg->dma_address,
  212. DMA_DAR(imxdmac->channel));
  213. else
  214. imx_dmav1_writel(imxdma, sg->dma_address,
  215. DMA_SAR(imxdmac->channel));
  216. imx_dmav1_writel(imxdma, now, DMA_CNTR(imxdmac->channel));
  217. dev_dbg(imxdma->dev, " %s channel: %d dst 0x%08x, src 0x%08x, "
  218. "size 0x%08x\n", __func__, imxdmac->channel,
  219. imx_dmav1_readl(imxdma, DMA_DAR(imxdmac->channel)),
  220. imx_dmav1_readl(imxdma, DMA_SAR(imxdmac->channel)),
  221. imx_dmav1_readl(imxdma, DMA_CNTR(imxdmac->channel)));
  222. return now;
  223. }
  224. static void imxdma_enable_hw(struct imxdma_desc *d)
  225. {
  226. struct imxdma_channel *imxdmac = to_imxdma_chan(d->desc.chan);
  227. struct imxdma_engine *imxdma = imxdmac->imxdma;
  228. int channel = imxdmac->channel;
  229. unsigned long flags;
  230. dev_dbg(imxdma->dev, "%s channel %d\n", __func__, channel);
  231. local_irq_save(flags);
  232. imx_dmav1_writel(imxdma, 1 << channel, DMA_DISR);
  233. imx_dmav1_writel(imxdma, imx_dmav1_readl(imxdma, DMA_DIMR) &
  234. ~(1 << channel), DMA_DIMR);
  235. imx_dmav1_writel(imxdma, imx_dmav1_readl(imxdma, DMA_CCR(channel)) |
  236. CCR_CEN | CCR_ACRPT, DMA_CCR(channel));
  237. if ((cpu_is_mx21() || cpu_is_mx27()) &&
  238. d->sg && imxdma_hw_chain(imxdmac)) {
  239. d->sg = sg_next(d->sg);
  240. if (d->sg) {
  241. u32 tmp;
  242. imxdma_sg_next(d);
  243. tmp = imx_dmav1_readl(imxdma, DMA_CCR(channel));
  244. imx_dmav1_writel(imxdma, tmp | CCR_RPT | CCR_ACRPT,
  245. DMA_CCR(channel));
  246. }
  247. }
  248. local_irq_restore(flags);
  249. }
  250. static void imxdma_disable_hw(struct imxdma_channel *imxdmac)
  251. {
  252. struct imxdma_engine *imxdma = imxdmac->imxdma;
  253. int channel = imxdmac->channel;
  254. unsigned long flags;
  255. dev_dbg(imxdma->dev, "%s channel %d\n", __func__, channel);
  256. if (imxdma_hw_chain(imxdmac))
  257. del_timer(&imxdmac->watchdog);
  258. local_irq_save(flags);
  259. imx_dmav1_writel(imxdma, imx_dmav1_readl(imxdma, DMA_DIMR) |
  260. (1 << channel), DMA_DIMR);
  261. imx_dmav1_writel(imxdma, imx_dmav1_readl(imxdma, DMA_CCR(channel)) &
  262. ~CCR_CEN, DMA_CCR(channel));
  263. imx_dmav1_writel(imxdma, 1 << channel, DMA_DISR);
  264. local_irq_restore(flags);
  265. }
  266. static void imxdma_watchdog(unsigned long data)
  267. {
  268. struct imxdma_channel *imxdmac = (struct imxdma_channel *)data;
  269. struct imxdma_engine *imxdma = imxdmac->imxdma;
  270. int channel = imxdmac->channel;
  271. imx_dmav1_writel(imxdma, 0, DMA_CCR(channel));
  272. /* Tasklet watchdog error handler */
  273. tasklet_schedule(&imxdmac->dma_tasklet);
  274. dev_dbg(imxdma->dev, "channel %d: watchdog timeout!\n",
  275. imxdmac->channel);
  276. }
  277. static irqreturn_t imxdma_err_handler(int irq, void *dev_id)
  278. {
  279. struct imxdma_engine *imxdma = dev_id;
  280. unsigned int err_mask;
  281. int i, disr;
  282. int errcode;
  283. disr = imx_dmav1_readl(imxdma, DMA_DISR);
  284. err_mask = imx_dmav1_readl(imxdma, DMA_DBTOSR) |
  285. imx_dmav1_readl(imxdma, DMA_DRTOSR) |
  286. imx_dmav1_readl(imxdma, DMA_DSESR) |
  287. imx_dmav1_readl(imxdma, DMA_DBOSR);
  288. if (!err_mask)
  289. return IRQ_HANDLED;
  290. imx_dmav1_writel(imxdma, disr & err_mask, DMA_DISR);
  291. for (i = 0; i < IMX_DMA_CHANNELS; i++) {
  292. if (!(err_mask & (1 << i)))
  293. continue;
  294. errcode = 0;
  295. if (imx_dmav1_readl(imxdma, DMA_DBTOSR) & (1 << i)) {
  296. imx_dmav1_writel(imxdma, 1 << i, DMA_DBTOSR);
  297. errcode |= IMX_DMA_ERR_BURST;
  298. }
  299. if (imx_dmav1_readl(imxdma, DMA_DRTOSR) & (1 << i)) {
  300. imx_dmav1_writel(imxdma, 1 << i, DMA_DRTOSR);
  301. errcode |= IMX_DMA_ERR_REQUEST;
  302. }
  303. if (imx_dmav1_readl(imxdma, DMA_DSESR) & (1 << i)) {
  304. imx_dmav1_writel(imxdma, 1 << i, DMA_DSESR);
  305. errcode |= IMX_DMA_ERR_TRANSFER;
  306. }
  307. if (imx_dmav1_readl(imxdma, DMA_DBOSR) & (1 << i)) {
  308. imx_dmav1_writel(imxdma, 1 << i, DMA_DBOSR);
  309. errcode |= IMX_DMA_ERR_BUFFER;
  310. }
  311. /* Tasklet error handler */
  312. tasklet_schedule(&imxdma->channel[i].dma_tasklet);
  313. printk(KERN_WARNING
  314. "DMA timeout on channel %d -%s%s%s%s\n", i,
  315. errcode & IMX_DMA_ERR_BURST ? " burst" : "",
  316. errcode & IMX_DMA_ERR_REQUEST ? " request" : "",
  317. errcode & IMX_DMA_ERR_TRANSFER ? " transfer" : "",
  318. errcode & IMX_DMA_ERR_BUFFER ? " buffer" : "");
  319. }
  320. return IRQ_HANDLED;
  321. }
  322. static void dma_irq_handle_channel(struct imxdma_channel *imxdmac)
  323. {
  324. struct imxdma_engine *imxdma = imxdmac->imxdma;
  325. int chno = imxdmac->channel;
  326. struct imxdma_desc *desc;
  327. spin_lock(&imxdma->lock);
  328. if (list_empty(&imxdmac->ld_active)) {
  329. spin_unlock(&imxdma->lock);
  330. goto out;
  331. }
  332. desc = list_first_entry(&imxdmac->ld_active,
  333. struct imxdma_desc,
  334. node);
  335. spin_unlock(&imxdma->lock);
  336. if (desc->sg) {
  337. u32 tmp;
  338. desc->sg = sg_next(desc->sg);
  339. if (desc->sg) {
  340. imxdma_sg_next(desc);
  341. tmp = imx_dmav1_readl(imxdma, DMA_CCR(chno));
  342. if (imxdma_hw_chain(imxdmac)) {
  343. /* FIXME: The timeout should probably be
  344. * configurable
  345. */
  346. mod_timer(&imxdmac->watchdog,
  347. jiffies + msecs_to_jiffies(500));
  348. tmp |= CCR_CEN | CCR_RPT | CCR_ACRPT;
  349. imx_dmav1_writel(imxdma, tmp, DMA_CCR(chno));
  350. } else {
  351. imx_dmav1_writel(imxdma, tmp & ~CCR_CEN,
  352. DMA_CCR(chno));
  353. tmp |= CCR_CEN;
  354. }
  355. imx_dmav1_writel(imxdma, tmp, DMA_CCR(chno));
  356. if (imxdma_chan_is_doing_cyclic(imxdmac))
  357. /* Tasklet progression */
  358. tasklet_schedule(&imxdmac->dma_tasklet);
  359. return;
  360. }
  361. if (imxdma_hw_chain(imxdmac)) {
  362. del_timer(&imxdmac->watchdog);
  363. return;
  364. }
  365. }
  366. out:
  367. imx_dmav1_writel(imxdma, 0, DMA_CCR(chno));
  368. /* Tasklet irq */
  369. tasklet_schedule(&imxdmac->dma_tasklet);
  370. }
  371. static irqreturn_t dma_irq_handler(int irq, void *dev_id)
  372. {
  373. struct imxdma_engine *imxdma = dev_id;
  374. int i, disr;
  375. if (cpu_is_mx21() || cpu_is_mx27())
  376. imxdma_err_handler(irq, dev_id);
  377. disr = imx_dmav1_readl(imxdma, DMA_DISR);
  378. dev_dbg(imxdma->dev, "%s called, disr=0x%08x\n", __func__, disr);
  379. imx_dmav1_writel(imxdma, disr, DMA_DISR);
  380. for (i = 0; i < IMX_DMA_CHANNELS; i++) {
  381. if (disr & (1 << i))
  382. dma_irq_handle_channel(&imxdma->channel[i]);
  383. }
  384. return IRQ_HANDLED;
  385. }
  386. static int imxdma_xfer_desc(struct imxdma_desc *d)
  387. {
  388. struct imxdma_channel *imxdmac = to_imxdma_chan(d->desc.chan);
  389. struct imxdma_engine *imxdma = imxdmac->imxdma;
  390. unsigned long flags;
  391. int slot = -1;
  392. int i;
  393. /* Configure and enable */
  394. switch (d->type) {
  395. case IMXDMA_DESC_INTERLEAVED:
  396. /* Try to get a free 2D slot */
  397. spin_lock_irqsave(&imxdma->lock, flags);
  398. for (i = 0; i < IMX_DMA_2D_SLOTS; i++) {
  399. if ((imxdma->slots_2d[i].count > 0) &&
  400. ((imxdma->slots_2d[i].xsr != d->x) ||
  401. (imxdma->slots_2d[i].ysr != d->y) ||
  402. (imxdma->slots_2d[i].wsr != d->w)))
  403. continue;
  404. slot = i;
  405. break;
  406. }
  407. if (slot < 0)
  408. return -EBUSY;
  409. imxdma->slots_2d[slot].xsr = d->x;
  410. imxdma->slots_2d[slot].ysr = d->y;
  411. imxdma->slots_2d[slot].wsr = d->w;
  412. imxdma->slots_2d[slot].count++;
  413. imxdmac->slot_2d = slot;
  414. imxdmac->enabled_2d = true;
  415. spin_unlock_irqrestore(&imxdma->lock, flags);
  416. if (slot == IMX_DMA_2D_SLOT_A) {
  417. d->config_mem &= ~CCR_MSEL_B;
  418. d->config_port &= ~CCR_MSEL_B;
  419. imx_dmav1_writel(imxdma, d->x, DMA_XSRA);
  420. imx_dmav1_writel(imxdma, d->y, DMA_YSRA);
  421. imx_dmav1_writel(imxdma, d->w, DMA_WSRA);
  422. } else {
  423. d->config_mem |= CCR_MSEL_B;
  424. d->config_port |= CCR_MSEL_B;
  425. imx_dmav1_writel(imxdma, d->x, DMA_XSRB);
  426. imx_dmav1_writel(imxdma, d->y, DMA_YSRB);
  427. imx_dmav1_writel(imxdma, d->w, DMA_WSRB);
  428. }
  429. /*
  430. * We fall-through here intentionally, since a 2D transfer is
  431. * similar to MEMCPY just adding the 2D slot configuration.
  432. */
  433. case IMXDMA_DESC_MEMCPY:
  434. imx_dmav1_writel(imxdma, d->src, DMA_SAR(imxdmac->channel));
  435. imx_dmav1_writel(imxdma, d->dest, DMA_DAR(imxdmac->channel));
  436. imx_dmav1_writel(imxdma, d->config_mem | (d->config_port << 2),
  437. DMA_CCR(imxdmac->channel));
  438. imx_dmav1_writel(imxdma, d->len, DMA_CNTR(imxdmac->channel));
  439. dev_dbg(imxdma->dev, "%s channel: %d dest=0x%08x src=0x%08x "
  440. "dma_length=%d\n", __func__, imxdmac->channel,
  441. d->dest, d->src, d->len);
  442. break;
  443. /* Cyclic transfer is the same as slave_sg with special sg configuration. */
  444. case IMXDMA_DESC_CYCLIC:
  445. case IMXDMA_DESC_SLAVE_SG:
  446. if (d->direction == DMA_DEV_TO_MEM) {
  447. imx_dmav1_writel(imxdma, imxdmac->per_address,
  448. DMA_SAR(imxdmac->channel));
  449. imx_dmav1_writel(imxdma, imxdmac->ccr_from_device,
  450. DMA_CCR(imxdmac->channel));
  451. dev_dbg(imxdma->dev, "%s channel: %d sg=%p sgcount=%d "
  452. "total length=%d dev_addr=0x%08x (dev2mem)\n",
  453. __func__, imxdmac->channel, d->sg, d->sgcount,
  454. d->len, imxdmac->per_address);
  455. } else if (d->direction == DMA_MEM_TO_DEV) {
  456. imx_dmav1_writel(imxdma, imxdmac->per_address,
  457. DMA_DAR(imxdmac->channel));
  458. imx_dmav1_writel(imxdma, imxdmac->ccr_to_device,
  459. DMA_CCR(imxdmac->channel));
  460. dev_dbg(imxdma->dev, "%s channel: %d sg=%p sgcount=%d "
  461. "total length=%d dev_addr=0x%08x (mem2dev)\n",
  462. __func__, imxdmac->channel, d->sg, d->sgcount,
  463. d->len, imxdmac->per_address);
  464. } else {
  465. dev_err(imxdma->dev, "%s channel: %d bad dma mode\n",
  466. __func__, imxdmac->channel);
  467. return -EINVAL;
  468. }
  469. imxdma_sg_next(d);
  470. break;
  471. default:
  472. return -EINVAL;
  473. }
  474. imxdma_enable_hw(d);
  475. return 0;
  476. }
  477. static void imxdma_tasklet(unsigned long data)
  478. {
  479. struct imxdma_channel *imxdmac = (void *)data;
  480. struct imxdma_engine *imxdma = imxdmac->imxdma;
  481. struct imxdma_desc *desc;
  482. spin_lock(&imxdma->lock);
  483. if (list_empty(&imxdmac->ld_active)) {
  484. /* Someone might have called terminate all */
  485. goto out;
  486. }
  487. desc = list_first_entry(&imxdmac->ld_active, struct imxdma_desc, node);
  488. if (desc->desc.callback)
  489. desc->desc.callback(desc->desc.callback_param);
  490. dma_cookie_complete(&desc->desc);
  491. /* If we are dealing with a cyclic descriptor keep it on ld_active */
  492. if (imxdma_chan_is_doing_cyclic(imxdmac))
  493. goto out;
  494. /* Free 2D slot if it was an interleaved transfer */
  495. if (imxdmac->enabled_2d) {
  496. imxdma->slots_2d[imxdmac->slot_2d].count--;
  497. imxdmac->enabled_2d = false;
  498. }
  499. list_move_tail(imxdmac->ld_active.next, &imxdmac->ld_free);
  500. if (!list_empty(&imxdmac->ld_queue)) {
  501. desc = list_first_entry(&imxdmac->ld_queue, struct imxdma_desc,
  502. node);
  503. list_move_tail(imxdmac->ld_queue.next, &imxdmac->ld_active);
  504. if (imxdma_xfer_desc(desc) < 0)
  505. dev_warn(imxdma->dev, "%s: channel: %d couldn't xfer desc\n",
  506. __func__, imxdmac->channel);
  507. }
  508. out:
  509. spin_unlock(&imxdma->lock);
  510. }
  511. static int imxdma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  512. unsigned long arg)
  513. {
  514. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  515. struct dma_slave_config *dmaengine_cfg = (void *)arg;
  516. struct imxdma_engine *imxdma = imxdmac->imxdma;
  517. unsigned long flags;
  518. unsigned int mode = 0;
  519. switch (cmd) {
  520. case DMA_TERMINATE_ALL:
  521. imxdma_disable_hw(imxdmac);
  522. spin_lock_irqsave(&imxdma->lock, flags);
  523. list_splice_tail_init(&imxdmac->ld_active, &imxdmac->ld_free);
  524. list_splice_tail_init(&imxdmac->ld_queue, &imxdmac->ld_free);
  525. spin_unlock_irqrestore(&imxdma->lock, flags);
  526. return 0;
  527. case DMA_SLAVE_CONFIG:
  528. if (dmaengine_cfg->direction == DMA_DEV_TO_MEM) {
  529. imxdmac->per_address = dmaengine_cfg->src_addr;
  530. imxdmac->watermark_level = dmaengine_cfg->src_maxburst;
  531. imxdmac->word_size = dmaengine_cfg->src_addr_width;
  532. } else {
  533. imxdmac->per_address = dmaengine_cfg->dst_addr;
  534. imxdmac->watermark_level = dmaengine_cfg->dst_maxburst;
  535. imxdmac->word_size = dmaengine_cfg->dst_addr_width;
  536. }
  537. switch (imxdmac->word_size) {
  538. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  539. mode = IMX_DMA_MEMSIZE_8;
  540. break;
  541. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  542. mode = IMX_DMA_MEMSIZE_16;
  543. break;
  544. default:
  545. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  546. mode = IMX_DMA_MEMSIZE_32;
  547. break;
  548. }
  549. imxdmac->hw_chaining = 1;
  550. if (!imxdma_hw_chain(imxdmac))
  551. return -EINVAL;
  552. imxdmac->ccr_from_device = (mode | IMX_DMA_TYPE_FIFO) |
  553. ((IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR) << 2) |
  554. CCR_REN;
  555. imxdmac->ccr_to_device =
  556. (IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR) |
  557. ((mode | IMX_DMA_TYPE_FIFO) << 2) | CCR_REN;
  558. imx_dmav1_writel(imxdma, imxdmac->dma_request,
  559. DMA_RSSR(imxdmac->channel));
  560. /* Set burst length */
  561. imx_dmav1_writel(imxdma, imxdmac->watermark_level *
  562. imxdmac->word_size, DMA_BLR(imxdmac->channel));
  563. return 0;
  564. default:
  565. return -ENOSYS;
  566. }
  567. return -EINVAL;
  568. }
  569. static enum dma_status imxdma_tx_status(struct dma_chan *chan,
  570. dma_cookie_t cookie,
  571. struct dma_tx_state *txstate)
  572. {
  573. return dma_cookie_status(chan, cookie, txstate);
  574. }
  575. static dma_cookie_t imxdma_tx_submit(struct dma_async_tx_descriptor *tx)
  576. {
  577. struct imxdma_channel *imxdmac = to_imxdma_chan(tx->chan);
  578. struct imxdma_engine *imxdma = imxdmac->imxdma;
  579. dma_cookie_t cookie;
  580. unsigned long flags;
  581. spin_lock_irqsave(&imxdma->lock, flags);
  582. list_move_tail(imxdmac->ld_free.next, &imxdmac->ld_queue);
  583. cookie = dma_cookie_assign(tx);
  584. spin_unlock_irqrestore(&imxdma->lock, flags);
  585. return cookie;
  586. }
  587. static int imxdma_alloc_chan_resources(struct dma_chan *chan)
  588. {
  589. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  590. struct imx_dma_data *data = chan->private;
  591. if (data != NULL)
  592. imxdmac->dma_request = data->dma_request;
  593. while (imxdmac->descs_allocated < IMXDMA_MAX_CHAN_DESCRIPTORS) {
  594. struct imxdma_desc *desc;
  595. desc = kzalloc(sizeof(*desc), GFP_KERNEL);
  596. if (!desc)
  597. break;
  598. __memzero(&desc->desc, sizeof(struct dma_async_tx_descriptor));
  599. dma_async_tx_descriptor_init(&desc->desc, chan);
  600. desc->desc.tx_submit = imxdma_tx_submit;
  601. /* txd.flags will be overwritten in prep funcs */
  602. desc->desc.flags = DMA_CTRL_ACK;
  603. desc->status = DMA_SUCCESS;
  604. list_add_tail(&desc->node, &imxdmac->ld_free);
  605. imxdmac->descs_allocated++;
  606. }
  607. if (!imxdmac->descs_allocated)
  608. return -ENOMEM;
  609. return imxdmac->descs_allocated;
  610. }
  611. static void imxdma_free_chan_resources(struct dma_chan *chan)
  612. {
  613. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  614. struct imxdma_engine *imxdma = imxdmac->imxdma;
  615. struct imxdma_desc *desc, *_desc;
  616. unsigned long flags;
  617. spin_lock_irqsave(&imxdma->lock, flags);
  618. imxdma_disable_hw(imxdmac);
  619. list_splice_tail_init(&imxdmac->ld_active, &imxdmac->ld_free);
  620. list_splice_tail_init(&imxdmac->ld_queue, &imxdmac->ld_free);
  621. spin_unlock_irqrestore(&imxdma->lock, flags);
  622. list_for_each_entry_safe(desc, _desc, &imxdmac->ld_free, node) {
  623. kfree(desc);
  624. imxdmac->descs_allocated--;
  625. }
  626. INIT_LIST_HEAD(&imxdmac->ld_free);
  627. if (imxdmac->sg_list) {
  628. kfree(imxdmac->sg_list);
  629. imxdmac->sg_list = NULL;
  630. }
  631. }
  632. static struct dma_async_tx_descriptor *imxdma_prep_slave_sg(
  633. struct dma_chan *chan, struct scatterlist *sgl,
  634. unsigned int sg_len, enum dma_transfer_direction direction,
  635. unsigned long flags, void *context)
  636. {
  637. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  638. struct scatterlist *sg;
  639. int i, dma_length = 0;
  640. struct imxdma_desc *desc;
  641. if (list_empty(&imxdmac->ld_free) ||
  642. imxdma_chan_is_doing_cyclic(imxdmac))
  643. return NULL;
  644. desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  645. for_each_sg(sgl, sg, sg_len, i) {
  646. dma_length += sg->length;
  647. }
  648. switch (imxdmac->word_size) {
  649. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  650. if (sgl->length & 3 || sgl->dma_address & 3)
  651. return NULL;
  652. break;
  653. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  654. if (sgl->length & 1 || sgl->dma_address & 1)
  655. return NULL;
  656. break;
  657. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  658. break;
  659. default:
  660. return NULL;
  661. }
  662. desc->type = IMXDMA_DESC_SLAVE_SG;
  663. desc->sg = sgl;
  664. desc->sgcount = sg_len;
  665. desc->len = dma_length;
  666. desc->direction = direction;
  667. if (direction == DMA_DEV_TO_MEM) {
  668. desc->src = imxdmac->per_address;
  669. } else {
  670. desc->dest = imxdmac->per_address;
  671. }
  672. desc->desc.callback = NULL;
  673. desc->desc.callback_param = NULL;
  674. return &desc->desc;
  675. }
  676. static struct dma_async_tx_descriptor *imxdma_prep_dma_cyclic(
  677. struct dma_chan *chan, dma_addr_t dma_addr, size_t buf_len,
  678. size_t period_len, enum dma_transfer_direction direction,
  679. void *context)
  680. {
  681. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  682. struct imxdma_engine *imxdma = imxdmac->imxdma;
  683. struct imxdma_desc *desc;
  684. int i;
  685. unsigned int periods = buf_len / period_len;
  686. dev_dbg(imxdma->dev, "%s channel: %d buf_len=%d period_len=%d\n",
  687. __func__, imxdmac->channel, buf_len, period_len);
  688. if (list_empty(&imxdmac->ld_free) ||
  689. imxdma_chan_is_doing_cyclic(imxdmac))
  690. return NULL;
  691. desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  692. if (imxdmac->sg_list)
  693. kfree(imxdmac->sg_list);
  694. imxdmac->sg_list = kcalloc(periods + 1,
  695. sizeof(struct scatterlist), GFP_KERNEL);
  696. if (!imxdmac->sg_list)
  697. return NULL;
  698. sg_init_table(imxdmac->sg_list, periods);
  699. for (i = 0; i < periods; i++) {
  700. imxdmac->sg_list[i].page_link = 0;
  701. imxdmac->sg_list[i].offset = 0;
  702. imxdmac->sg_list[i].dma_address = dma_addr;
  703. imxdmac->sg_list[i].length = period_len;
  704. dma_addr += period_len;
  705. }
  706. /* close the loop */
  707. imxdmac->sg_list[periods].offset = 0;
  708. imxdmac->sg_list[periods].length = 0;
  709. imxdmac->sg_list[periods].page_link =
  710. ((unsigned long)imxdmac->sg_list | 0x01) & ~0x02;
  711. desc->type = IMXDMA_DESC_CYCLIC;
  712. desc->sg = imxdmac->sg_list;
  713. desc->sgcount = periods;
  714. desc->len = IMX_DMA_LENGTH_LOOP;
  715. desc->direction = direction;
  716. if (direction == DMA_DEV_TO_MEM) {
  717. desc->src = imxdmac->per_address;
  718. } else {
  719. desc->dest = imxdmac->per_address;
  720. }
  721. desc->desc.callback = NULL;
  722. desc->desc.callback_param = NULL;
  723. return &desc->desc;
  724. }
  725. static struct dma_async_tx_descriptor *imxdma_prep_dma_memcpy(
  726. struct dma_chan *chan, dma_addr_t dest,
  727. dma_addr_t src, size_t len, unsigned long flags)
  728. {
  729. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  730. struct imxdma_engine *imxdma = imxdmac->imxdma;
  731. struct imxdma_desc *desc;
  732. dev_dbg(imxdma->dev, "%s channel: %d src=0x%x dst=0x%x len=%d\n",
  733. __func__, imxdmac->channel, src, dest, len);
  734. if (list_empty(&imxdmac->ld_free) ||
  735. imxdma_chan_is_doing_cyclic(imxdmac))
  736. return NULL;
  737. desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  738. desc->type = IMXDMA_DESC_MEMCPY;
  739. desc->src = src;
  740. desc->dest = dest;
  741. desc->len = len;
  742. desc->direction = DMA_MEM_TO_MEM;
  743. desc->config_port = IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR;
  744. desc->config_mem = IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR;
  745. desc->desc.callback = NULL;
  746. desc->desc.callback_param = NULL;
  747. return &desc->desc;
  748. }
  749. static struct dma_async_tx_descriptor *imxdma_prep_dma_interleaved(
  750. struct dma_chan *chan, struct dma_interleaved_template *xt,
  751. unsigned long flags)
  752. {
  753. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  754. struct imxdma_engine *imxdma = imxdmac->imxdma;
  755. struct imxdma_desc *desc;
  756. dev_dbg(imxdma->dev, "%s channel: %d src_start=0x%x dst_start=0x%x\n"
  757. " src_sgl=%s dst_sgl=%s numf=%d frame_size=%d\n", __func__,
  758. imxdmac->channel, xt->src_start, xt->dst_start,
  759. xt->src_sgl ? "true" : "false", xt->dst_sgl ? "true" : "false",
  760. xt->numf, xt->frame_size);
  761. if (list_empty(&imxdmac->ld_free) ||
  762. imxdma_chan_is_doing_cyclic(imxdmac))
  763. return NULL;
  764. if (xt->frame_size != 1 || xt->numf <= 0 || xt->dir != DMA_MEM_TO_MEM)
  765. return NULL;
  766. desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  767. desc->type = IMXDMA_DESC_INTERLEAVED;
  768. desc->src = xt->src_start;
  769. desc->dest = xt->dst_start;
  770. desc->x = xt->sgl[0].size;
  771. desc->y = xt->numf;
  772. desc->w = xt->sgl[0].icg + desc->x;
  773. desc->len = desc->x * desc->y;
  774. desc->direction = DMA_MEM_TO_MEM;
  775. desc->config_port = IMX_DMA_MEMSIZE_32;
  776. desc->config_mem = IMX_DMA_MEMSIZE_32;
  777. if (xt->src_sgl)
  778. desc->config_mem |= IMX_DMA_TYPE_2D;
  779. if (xt->dst_sgl)
  780. desc->config_port |= IMX_DMA_TYPE_2D;
  781. desc->desc.callback = NULL;
  782. desc->desc.callback_param = NULL;
  783. return &desc->desc;
  784. }
  785. static void imxdma_issue_pending(struct dma_chan *chan)
  786. {
  787. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  788. struct imxdma_engine *imxdma = imxdmac->imxdma;
  789. struct imxdma_desc *desc;
  790. unsigned long flags;
  791. spin_lock_irqsave(&imxdma->lock, flags);
  792. if (list_empty(&imxdmac->ld_active) &&
  793. !list_empty(&imxdmac->ld_queue)) {
  794. desc = list_first_entry(&imxdmac->ld_queue,
  795. struct imxdma_desc, node);
  796. if (imxdma_xfer_desc(desc) < 0) {
  797. dev_warn(imxdma->dev,
  798. "%s: channel: %d couldn't issue DMA xfer\n",
  799. __func__, imxdmac->channel);
  800. } else {
  801. list_move_tail(imxdmac->ld_queue.next,
  802. &imxdmac->ld_active);
  803. }
  804. }
  805. spin_unlock_irqrestore(&imxdma->lock, flags);
  806. }
  807. static int __init imxdma_probe(struct platform_device *pdev)
  808. {
  809. struct imxdma_engine *imxdma;
  810. int ret, i;
  811. imxdma = kzalloc(sizeof(*imxdma), GFP_KERNEL);
  812. if (!imxdma)
  813. return -ENOMEM;
  814. if (cpu_is_mx1()) {
  815. imxdma->base = MX1_IO_ADDRESS(MX1_DMA_BASE_ADDR);
  816. } else if (cpu_is_mx21()) {
  817. imxdma->base = MX21_IO_ADDRESS(MX21_DMA_BASE_ADDR);
  818. } else if (cpu_is_mx27()) {
  819. imxdma->base = MX27_IO_ADDRESS(MX27_DMA_BASE_ADDR);
  820. } else {
  821. kfree(imxdma);
  822. return 0;
  823. }
  824. imxdma->dma_clk = clk_get(NULL, "dma");
  825. if (IS_ERR(imxdma->dma_clk))
  826. return PTR_ERR(imxdma->dma_clk);
  827. clk_enable(imxdma->dma_clk);
  828. /* reset DMA module */
  829. imx_dmav1_writel(imxdma, DCR_DRST, DMA_DCR);
  830. if (cpu_is_mx1()) {
  831. ret = request_irq(MX1_DMA_INT, dma_irq_handler, 0, "DMA", imxdma);
  832. if (ret) {
  833. dev_warn(imxdma->dev, "Can't register IRQ for DMA\n");
  834. kfree(imxdma);
  835. return ret;
  836. }
  837. ret = request_irq(MX1_DMA_ERR, imxdma_err_handler, 0, "DMA", imxdma);
  838. if (ret) {
  839. dev_warn(imxdma->dev, "Can't register ERRIRQ for DMA\n");
  840. free_irq(MX1_DMA_INT, NULL);
  841. kfree(imxdma);
  842. return ret;
  843. }
  844. }
  845. /* enable DMA module */
  846. imx_dmav1_writel(imxdma, DCR_DEN, DMA_DCR);
  847. /* clear all interrupts */
  848. imx_dmav1_writel(imxdma, (1 << IMX_DMA_CHANNELS) - 1, DMA_DISR);
  849. /* disable interrupts */
  850. imx_dmav1_writel(imxdma, (1 << IMX_DMA_CHANNELS) - 1, DMA_DIMR);
  851. INIT_LIST_HEAD(&imxdma->dma_device.channels);
  852. dma_cap_set(DMA_SLAVE, imxdma->dma_device.cap_mask);
  853. dma_cap_set(DMA_CYCLIC, imxdma->dma_device.cap_mask);
  854. dma_cap_set(DMA_MEMCPY, imxdma->dma_device.cap_mask);
  855. dma_cap_set(DMA_INTERLEAVE, imxdma->dma_device.cap_mask);
  856. /* Initialize 2D global parameters */
  857. for (i = 0; i < IMX_DMA_2D_SLOTS; i++)
  858. imxdma->slots_2d[i].count = 0;
  859. spin_lock_init(&imxdma->lock);
  860. /* Initialize channel parameters */
  861. for (i = 0; i < IMX_DMA_CHANNELS; i++) {
  862. struct imxdma_channel *imxdmac = &imxdma->channel[i];
  863. if (cpu_is_mx21() || cpu_is_mx27()) {
  864. ret = request_irq(MX2x_INT_DMACH0 + i,
  865. dma_irq_handler, 0, "DMA", imxdma);
  866. if (ret) {
  867. dev_warn(imxdma->dev, "Can't register IRQ %d "
  868. "for DMA channel %d\n",
  869. MX2x_INT_DMACH0 + i, i);
  870. goto err_init;
  871. }
  872. init_timer(&imxdmac->watchdog);
  873. imxdmac->watchdog.function = &imxdma_watchdog;
  874. imxdmac->watchdog.data = (unsigned long)imxdmac;
  875. }
  876. imxdmac->imxdma = imxdma;
  877. INIT_LIST_HEAD(&imxdmac->ld_queue);
  878. INIT_LIST_HEAD(&imxdmac->ld_free);
  879. INIT_LIST_HEAD(&imxdmac->ld_active);
  880. tasklet_init(&imxdmac->dma_tasklet, imxdma_tasklet,
  881. (unsigned long)imxdmac);
  882. imxdmac->chan.device = &imxdma->dma_device;
  883. dma_cookie_init(&imxdmac->chan);
  884. imxdmac->channel = i;
  885. /* Add the channel to the DMAC list */
  886. list_add_tail(&imxdmac->chan.device_node,
  887. &imxdma->dma_device.channels);
  888. }
  889. imxdma->dev = &pdev->dev;
  890. imxdma->dma_device.dev = &pdev->dev;
  891. imxdma->dma_device.device_alloc_chan_resources = imxdma_alloc_chan_resources;
  892. imxdma->dma_device.device_free_chan_resources = imxdma_free_chan_resources;
  893. imxdma->dma_device.device_tx_status = imxdma_tx_status;
  894. imxdma->dma_device.device_prep_slave_sg = imxdma_prep_slave_sg;
  895. imxdma->dma_device.device_prep_dma_cyclic = imxdma_prep_dma_cyclic;
  896. imxdma->dma_device.device_prep_dma_memcpy = imxdma_prep_dma_memcpy;
  897. imxdma->dma_device.device_prep_interleaved_dma = imxdma_prep_dma_interleaved;
  898. imxdma->dma_device.device_control = imxdma_control;
  899. imxdma->dma_device.device_issue_pending = imxdma_issue_pending;
  900. platform_set_drvdata(pdev, imxdma);
  901. imxdma->dma_device.copy_align = 2; /* 2^2 = 4 bytes alignment */
  902. imxdma->dma_device.dev->dma_parms = &imxdma->dma_parms;
  903. dma_set_max_seg_size(imxdma->dma_device.dev, 0xffffff);
  904. ret = dma_async_device_register(&imxdma->dma_device);
  905. if (ret) {
  906. dev_err(&pdev->dev, "unable to register\n");
  907. goto err_init;
  908. }
  909. return 0;
  910. err_init:
  911. if (cpu_is_mx21() || cpu_is_mx27()) {
  912. while (--i >= 0)
  913. free_irq(MX2x_INT_DMACH0 + i, NULL);
  914. } else if cpu_is_mx1() {
  915. free_irq(MX1_DMA_INT, NULL);
  916. free_irq(MX1_DMA_ERR, NULL);
  917. }
  918. kfree(imxdma);
  919. return ret;
  920. }
  921. static int __exit imxdma_remove(struct platform_device *pdev)
  922. {
  923. struct imxdma_engine *imxdma = platform_get_drvdata(pdev);
  924. int i;
  925. dma_async_device_unregister(&imxdma->dma_device);
  926. if (cpu_is_mx21() || cpu_is_mx27()) {
  927. for (i = 0; i < IMX_DMA_CHANNELS; i++)
  928. free_irq(MX2x_INT_DMACH0 + i, NULL);
  929. } else if cpu_is_mx1() {
  930. free_irq(MX1_DMA_INT, NULL);
  931. free_irq(MX1_DMA_ERR, NULL);
  932. }
  933. kfree(imxdma);
  934. return 0;
  935. }
  936. static struct platform_driver imxdma_driver = {
  937. .driver = {
  938. .name = "imx-dma",
  939. },
  940. .remove = __exit_p(imxdma_remove),
  941. };
  942. static int __init imxdma_module_init(void)
  943. {
  944. return platform_driver_probe(&imxdma_driver, imxdma_probe);
  945. }
  946. subsys_initcall(imxdma_module_init);
  947. MODULE_AUTHOR("Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>");
  948. MODULE_DESCRIPTION("i.MX dma driver");
  949. MODULE_LICENSE("GPL");