imx-dma.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139
  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. unsigned long flags;
  328. spin_lock_irqsave(&imxdma->lock, flags);
  329. if (list_empty(&imxdmac->ld_active)) {
  330. spin_unlock_irqrestore(&imxdma->lock, flags);
  331. goto out;
  332. }
  333. desc = list_first_entry(&imxdmac->ld_active,
  334. struct imxdma_desc,
  335. node);
  336. spin_unlock_irqrestore(&imxdma->lock, flags);
  337. if (desc->sg) {
  338. u32 tmp;
  339. desc->sg = sg_next(desc->sg);
  340. if (desc->sg) {
  341. imxdma_sg_next(desc);
  342. tmp = imx_dmav1_readl(imxdma, DMA_CCR(chno));
  343. if (imxdma_hw_chain(imxdmac)) {
  344. /* FIXME: The timeout should probably be
  345. * configurable
  346. */
  347. mod_timer(&imxdmac->watchdog,
  348. jiffies + msecs_to_jiffies(500));
  349. tmp |= CCR_CEN | CCR_RPT | CCR_ACRPT;
  350. imx_dmav1_writel(imxdma, tmp, DMA_CCR(chno));
  351. } else {
  352. imx_dmav1_writel(imxdma, tmp & ~CCR_CEN,
  353. DMA_CCR(chno));
  354. tmp |= CCR_CEN;
  355. }
  356. imx_dmav1_writel(imxdma, tmp, DMA_CCR(chno));
  357. if (imxdma_chan_is_doing_cyclic(imxdmac))
  358. /* Tasklet progression */
  359. tasklet_schedule(&imxdmac->dma_tasklet);
  360. return;
  361. }
  362. if (imxdma_hw_chain(imxdmac)) {
  363. del_timer(&imxdmac->watchdog);
  364. return;
  365. }
  366. }
  367. out:
  368. imx_dmav1_writel(imxdma, 0, DMA_CCR(chno));
  369. /* Tasklet irq */
  370. tasklet_schedule(&imxdmac->dma_tasklet);
  371. }
  372. static irqreturn_t dma_irq_handler(int irq, void *dev_id)
  373. {
  374. struct imxdma_engine *imxdma = dev_id;
  375. int i, disr;
  376. if (cpu_is_mx21() || cpu_is_mx27())
  377. imxdma_err_handler(irq, dev_id);
  378. disr = imx_dmav1_readl(imxdma, DMA_DISR);
  379. dev_dbg(imxdma->dev, "%s called, disr=0x%08x\n", __func__, disr);
  380. imx_dmav1_writel(imxdma, disr, DMA_DISR);
  381. for (i = 0; i < IMX_DMA_CHANNELS; i++) {
  382. if (disr & (1 << i))
  383. dma_irq_handle_channel(&imxdma->channel[i]);
  384. }
  385. return IRQ_HANDLED;
  386. }
  387. static int imxdma_xfer_desc(struct imxdma_desc *d)
  388. {
  389. struct imxdma_channel *imxdmac = to_imxdma_chan(d->desc.chan);
  390. struct imxdma_engine *imxdma = imxdmac->imxdma;
  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. for (i = 0; i < IMX_DMA_2D_SLOTS; i++) {
  398. if ((imxdma->slots_2d[i].count > 0) &&
  399. ((imxdma->slots_2d[i].xsr != d->x) ||
  400. (imxdma->slots_2d[i].ysr != d->y) ||
  401. (imxdma->slots_2d[i].wsr != d->w)))
  402. continue;
  403. slot = i;
  404. break;
  405. }
  406. if (slot < 0)
  407. return -EBUSY;
  408. imxdma->slots_2d[slot].xsr = d->x;
  409. imxdma->slots_2d[slot].ysr = d->y;
  410. imxdma->slots_2d[slot].wsr = d->w;
  411. imxdma->slots_2d[slot].count++;
  412. imxdmac->slot_2d = slot;
  413. imxdmac->enabled_2d = true;
  414. if (slot == IMX_DMA_2D_SLOT_A) {
  415. d->config_mem &= ~CCR_MSEL_B;
  416. d->config_port &= ~CCR_MSEL_B;
  417. imx_dmav1_writel(imxdma, d->x, DMA_XSRA);
  418. imx_dmav1_writel(imxdma, d->y, DMA_YSRA);
  419. imx_dmav1_writel(imxdma, d->w, DMA_WSRA);
  420. } else {
  421. d->config_mem |= CCR_MSEL_B;
  422. d->config_port |= CCR_MSEL_B;
  423. imx_dmav1_writel(imxdma, d->x, DMA_XSRB);
  424. imx_dmav1_writel(imxdma, d->y, DMA_YSRB);
  425. imx_dmav1_writel(imxdma, d->w, DMA_WSRB);
  426. }
  427. /*
  428. * We fall-through here intentionally, since a 2D transfer is
  429. * similar to MEMCPY just adding the 2D slot configuration.
  430. */
  431. case IMXDMA_DESC_MEMCPY:
  432. imx_dmav1_writel(imxdma, d->src, DMA_SAR(imxdmac->channel));
  433. imx_dmav1_writel(imxdma, d->dest, DMA_DAR(imxdmac->channel));
  434. imx_dmav1_writel(imxdma, d->config_mem | (d->config_port << 2),
  435. DMA_CCR(imxdmac->channel));
  436. imx_dmav1_writel(imxdma, d->len, DMA_CNTR(imxdmac->channel));
  437. dev_dbg(imxdma->dev, "%s channel: %d dest=0x%08x src=0x%08x "
  438. "dma_length=%d\n", __func__, imxdmac->channel,
  439. d->dest, d->src, d->len);
  440. break;
  441. /* Cyclic transfer is the same as slave_sg with special sg configuration. */
  442. case IMXDMA_DESC_CYCLIC:
  443. case IMXDMA_DESC_SLAVE_SG:
  444. if (d->direction == DMA_DEV_TO_MEM) {
  445. imx_dmav1_writel(imxdma, imxdmac->per_address,
  446. DMA_SAR(imxdmac->channel));
  447. imx_dmav1_writel(imxdma, imxdmac->ccr_from_device,
  448. DMA_CCR(imxdmac->channel));
  449. dev_dbg(imxdma->dev, "%s channel: %d sg=%p sgcount=%d "
  450. "total length=%d dev_addr=0x%08x (dev2mem)\n",
  451. __func__, imxdmac->channel, d->sg, d->sgcount,
  452. d->len, imxdmac->per_address);
  453. } else if (d->direction == DMA_MEM_TO_DEV) {
  454. imx_dmav1_writel(imxdma, imxdmac->per_address,
  455. DMA_DAR(imxdmac->channel));
  456. imx_dmav1_writel(imxdma, imxdmac->ccr_to_device,
  457. DMA_CCR(imxdmac->channel));
  458. dev_dbg(imxdma->dev, "%s channel: %d sg=%p sgcount=%d "
  459. "total length=%d dev_addr=0x%08x (mem2dev)\n",
  460. __func__, imxdmac->channel, d->sg, d->sgcount,
  461. d->len, imxdmac->per_address);
  462. } else {
  463. dev_err(imxdma->dev, "%s channel: %d bad dma mode\n",
  464. __func__, imxdmac->channel);
  465. return -EINVAL;
  466. }
  467. imxdma_sg_next(d);
  468. break;
  469. default:
  470. return -EINVAL;
  471. }
  472. imxdma_enable_hw(d);
  473. return 0;
  474. }
  475. static void imxdma_tasklet(unsigned long data)
  476. {
  477. struct imxdma_channel *imxdmac = (void *)data;
  478. struct imxdma_engine *imxdma = imxdmac->imxdma;
  479. struct imxdma_desc *desc;
  480. unsigned long flags;
  481. spin_lock_irqsave(&imxdma->lock, flags);
  482. if (list_empty(&imxdmac->ld_active)) {
  483. /* Someone might have called terminate all */
  484. spin_unlock_irqrestore(&imxdma->lock, flags);
  485. return;
  486. }
  487. desc = list_first_entry(&imxdmac->ld_active, struct imxdma_desc, node);
  488. /* If we are dealing with a cyclic descriptor keep it on ld_active
  489. * and dont mark the descripor as complete.
  490. * Only in non-cyclic cases it would be marked as complete
  491. */
  492. if (imxdma_chan_is_doing_cyclic(imxdmac))
  493. goto out;
  494. else
  495. dma_cookie_complete(&desc->desc);
  496. /* Free 2D slot if it was an interleaved transfer */
  497. if (imxdmac->enabled_2d) {
  498. imxdma->slots_2d[imxdmac->slot_2d].count--;
  499. imxdmac->enabled_2d = false;
  500. }
  501. list_move_tail(imxdmac->ld_active.next, &imxdmac->ld_free);
  502. if (!list_empty(&imxdmac->ld_queue)) {
  503. desc = list_first_entry(&imxdmac->ld_queue, struct imxdma_desc,
  504. node);
  505. list_move_tail(imxdmac->ld_queue.next, &imxdmac->ld_active);
  506. if (imxdma_xfer_desc(desc) < 0)
  507. dev_warn(imxdma->dev, "%s: channel: %d couldn't xfer desc\n",
  508. __func__, imxdmac->channel);
  509. }
  510. out:
  511. spin_unlock_irqrestore(&imxdma->lock, flags);
  512. if (desc->desc.callback)
  513. desc->desc.callback(desc->desc.callback_param);
  514. }
  515. static int imxdma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  516. unsigned long arg)
  517. {
  518. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  519. struct dma_slave_config *dmaengine_cfg = (void *)arg;
  520. struct imxdma_engine *imxdma = imxdmac->imxdma;
  521. unsigned long flags;
  522. unsigned int mode = 0;
  523. switch (cmd) {
  524. case DMA_TERMINATE_ALL:
  525. imxdma_disable_hw(imxdmac);
  526. spin_lock_irqsave(&imxdma->lock, flags);
  527. list_splice_tail_init(&imxdmac->ld_active, &imxdmac->ld_free);
  528. list_splice_tail_init(&imxdmac->ld_queue, &imxdmac->ld_free);
  529. spin_unlock_irqrestore(&imxdma->lock, flags);
  530. return 0;
  531. case DMA_SLAVE_CONFIG:
  532. if (dmaengine_cfg->direction == DMA_DEV_TO_MEM) {
  533. imxdmac->per_address = dmaengine_cfg->src_addr;
  534. imxdmac->watermark_level = dmaengine_cfg->src_maxburst;
  535. imxdmac->word_size = dmaengine_cfg->src_addr_width;
  536. } else {
  537. imxdmac->per_address = dmaengine_cfg->dst_addr;
  538. imxdmac->watermark_level = dmaengine_cfg->dst_maxburst;
  539. imxdmac->word_size = dmaengine_cfg->dst_addr_width;
  540. }
  541. switch (imxdmac->word_size) {
  542. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  543. mode = IMX_DMA_MEMSIZE_8;
  544. break;
  545. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  546. mode = IMX_DMA_MEMSIZE_16;
  547. break;
  548. default:
  549. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  550. mode = IMX_DMA_MEMSIZE_32;
  551. break;
  552. }
  553. imxdmac->hw_chaining = 1;
  554. if (!imxdma_hw_chain(imxdmac))
  555. return -EINVAL;
  556. imxdmac->ccr_from_device = (mode | IMX_DMA_TYPE_FIFO) |
  557. ((IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR) << 2) |
  558. CCR_REN;
  559. imxdmac->ccr_to_device =
  560. (IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR) |
  561. ((mode | IMX_DMA_TYPE_FIFO) << 2) | CCR_REN;
  562. imx_dmav1_writel(imxdma, imxdmac->dma_request,
  563. DMA_RSSR(imxdmac->channel));
  564. /* Set burst length */
  565. imx_dmav1_writel(imxdma, imxdmac->watermark_level *
  566. imxdmac->word_size, DMA_BLR(imxdmac->channel));
  567. return 0;
  568. default:
  569. return -ENOSYS;
  570. }
  571. return -EINVAL;
  572. }
  573. static enum dma_status imxdma_tx_status(struct dma_chan *chan,
  574. dma_cookie_t cookie,
  575. struct dma_tx_state *txstate)
  576. {
  577. return dma_cookie_status(chan, cookie, txstate);
  578. }
  579. static dma_cookie_t imxdma_tx_submit(struct dma_async_tx_descriptor *tx)
  580. {
  581. struct imxdma_channel *imxdmac = to_imxdma_chan(tx->chan);
  582. struct imxdma_engine *imxdma = imxdmac->imxdma;
  583. dma_cookie_t cookie;
  584. unsigned long flags;
  585. spin_lock_irqsave(&imxdma->lock, flags);
  586. list_move_tail(imxdmac->ld_free.next, &imxdmac->ld_queue);
  587. cookie = dma_cookie_assign(tx);
  588. spin_unlock_irqrestore(&imxdma->lock, flags);
  589. return cookie;
  590. }
  591. static int imxdma_alloc_chan_resources(struct dma_chan *chan)
  592. {
  593. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  594. struct imx_dma_data *data = chan->private;
  595. if (data != NULL)
  596. imxdmac->dma_request = data->dma_request;
  597. while (imxdmac->descs_allocated < IMXDMA_MAX_CHAN_DESCRIPTORS) {
  598. struct imxdma_desc *desc;
  599. desc = kzalloc(sizeof(*desc), GFP_KERNEL);
  600. if (!desc)
  601. break;
  602. __memzero(&desc->desc, sizeof(struct dma_async_tx_descriptor));
  603. dma_async_tx_descriptor_init(&desc->desc, chan);
  604. desc->desc.tx_submit = imxdma_tx_submit;
  605. /* txd.flags will be overwritten in prep funcs */
  606. desc->desc.flags = DMA_CTRL_ACK;
  607. desc->status = DMA_SUCCESS;
  608. list_add_tail(&desc->node, &imxdmac->ld_free);
  609. imxdmac->descs_allocated++;
  610. }
  611. if (!imxdmac->descs_allocated)
  612. return -ENOMEM;
  613. return imxdmac->descs_allocated;
  614. }
  615. static void imxdma_free_chan_resources(struct dma_chan *chan)
  616. {
  617. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  618. struct imxdma_engine *imxdma = imxdmac->imxdma;
  619. struct imxdma_desc *desc, *_desc;
  620. unsigned long flags;
  621. spin_lock_irqsave(&imxdma->lock, flags);
  622. imxdma_disable_hw(imxdmac);
  623. list_splice_tail_init(&imxdmac->ld_active, &imxdmac->ld_free);
  624. list_splice_tail_init(&imxdmac->ld_queue, &imxdmac->ld_free);
  625. spin_unlock_irqrestore(&imxdma->lock, flags);
  626. list_for_each_entry_safe(desc, _desc, &imxdmac->ld_free, node) {
  627. kfree(desc);
  628. imxdmac->descs_allocated--;
  629. }
  630. INIT_LIST_HEAD(&imxdmac->ld_free);
  631. if (imxdmac->sg_list) {
  632. kfree(imxdmac->sg_list);
  633. imxdmac->sg_list = NULL;
  634. }
  635. }
  636. static struct dma_async_tx_descriptor *imxdma_prep_slave_sg(
  637. struct dma_chan *chan, struct scatterlist *sgl,
  638. unsigned int sg_len, enum dma_transfer_direction direction,
  639. unsigned long flags, void *context)
  640. {
  641. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  642. struct scatterlist *sg;
  643. int i, dma_length = 0;
  644. struct imxdma_desc *desc;
  645. if (list_empty(&imxdmac->ld_free) ||
  646. imxdma_chan_is_doing_cyclic(imxdmac))
  647. return NULL;
  648. desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  649. for_each_sg(sgl, sg, sg_len, i) {
  650. dma_length += sg->length;
  651. }
  652. switch (imxdmac->word_size) {
  653. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  654. if (sgl->length & 3 || sgl->dma_address & 3)
  655. return NULL;
  656. break;
  657. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  658. if (sgl->length & 1 || sgl->dma_address & 1)
  659. return NULL;
  660. break;
  661. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  662. break;
  663. default:
  664. return NULL;
  665. }
  666. desc->type = IMXDMA_DESC_SLAVE_SG;
  667. desc->sg = sgl;
  668. desc->sgcount = sg_len;
  669. desc->len = dma_length;
  670. desc->direction = direction;
  671. if (direction == DMA_DEV_TO_MEM) {
  672. desc->src = imxdmac->per_address;
  673. } else {
  674. desc->dest = imxdmac->per_address;
  675. }
  676. desc->desc.callback = NULL;
  677. desc->desc.callback_param = NULL;
  678. return &desc->desc;
  679. }
  680. static struct dma_async_tx_descriptor *imxdma_prep_dma_cyclic(
  681. struct dma_chan *chan, dma_addr_t dma_addr, size_t buf_len,
  682. size_t period_len, enum dma_transfer_direction direction,
  683. void *context)
  684. {
  685. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  686. struct imxdma_engine *imxdma = imxdmac->imxdma;
  687. struct imxdma_desc *desc;
  688. int i;
  689. unsigned int periods = buf_len / period_len;
  690. dev_dbg(imxdma->dev, "%s channel: %d buf_len=%d period_len=%d\n",
  691. __func__, imxdmac->channel, buf_len, period_len);
  692. if (list_empty(&imxdmac->ld_free) ||
  693. imxdma_chan_is_doing_cyclic(imxdmac))
  694. return NULL;
  695. desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  696. if (imxdmac->sg_list)
  697. kfree(imxdmac->sg_list);
  698. imxdmac->sg_list = kcalloc(periods + 1,
  699. sizeof(struct scatterlist), GFP_ATOMIC);
  700. if (!imxdmac->sg_list)
  701. return NULL;
  702. sg_init_table(imxdmac->sg_list, periods);
  703. for (i = 0; i < periods; i++) {
  704. imxdmac->sg_list[i].page_link = 0;
  705. imxdmac->sg_list[i].offset = 0;
  706. imxdmac->sg_list[i].dma_address = dma_addr;
  707. imxdmac->sg_list[i].length = period_len;
  708. dma_addr += period_len;
  709. }
  710. /* close the loop */
  711. imxdmac->sg_list[periods].offset = 0;
  712. imxdmac->sg_list[periods].length = 0;
  713. imxdmac->sg_list[periods].page_link =
  714. ((unsigned long)imxdmac->sg_list | 0x01) & ~0x02;
  715. desc->type = IMXDMA_DESC_CYCLIC;
  716. desc->sg = imxdmac->sg_list;
  717. desc->sgcount = periods;
  718. desc->len = IMX_DMA_LENGTH_LOOP;
  719. desc->direction = direction;
  720. if (direction == DMA_DEV_TO_MEM) {
  721. desc->src = imxdmac->per_address;
  722. } else {
  723. desc->dest = imxdmac->per_address;
  724. }
  725. desc->desc.callback = NULL;
  726. desc->desc.callback_param = NULL;
  727. return &desc->desc;
  728. }
  729. static struct dma_async_tx_descriptor *imxdma_prep_dma_memcpy(
  730. struct dma_chan *chan, dma_addr_t dest,
  731. dma_addr_t src, size_t len, unsigned long flags)
  732. {
  733. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  734. struct imxdma_engine *imxdma = imxdmac->imxdma;
  735. struct imxdma_desc *desc;
  736. dev_dbg(imxdma->dev, "%s channel: %d src=0x%x dst=0x%x len=%d\n",
  737. __func__, imxdmac->channel, src, dest, len);
  738. if (list_empty(&imxdmac->ld_free) ||
  739. imxdma_chan_is_doing_cyclic(imxdmac))
  740. return NULL;
  741. desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  742. desc->type = IMXDMA_DESC_MEMCPY;
  743. desc->src = src;
  744. desc->dest = dest;
  745. desc->len = len;
  746. desc->direction = DMA_MEM_TO_MEM;
  747. desc->config_port = IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR;
  748. desc->config_mem = IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR;
  749. desc->desc.callback = NULL;
  750. desc->desc.callback_param = NULL;
  751. return &desc->desc;
  752. }
  753. static struct dma_async_tx_descriptor *imxdma_prep_dma_interleaved(
  754. struct dma_chan *chan, struct dma_interleaved_template *xt,
  755. unsigned long flags)
  756. {
  757. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  758. struct imxdma_engine *imxdma = imxdmac->imxdma;
  759. struct imxdma_desc *desc;
  760. dev_dbg(imxdma->dev, "%s channel: %d src_start=0x%x dst_start=0x%x\n"
  761. " src_sgl=%s dst_sgl=%s numf=%d frame_size=%d\n", __func__,
  762. imxdmac->channel, xt->src_start, xt->dst_start,
  763. xt->src_sgl ? "true" : "false", xt->dst_sgl ? "true" : "false",
  764. xt->numf, xt->frame_size);
  765. if (list_empty(&imxdmac->ld_free) ||
  766. imxdma_chan_is_doing_cyclic(imxdmac))
  767. return NULL;
  768. if (xt->frame_size != 1 || xt->numf <= 0 || xt->dir != DMA_MEM_TO_MEM)
  769. return NULL;
  770. desc = list_first_entry(&imxdmac->ld_free, struct imxdma_desc, node);
  771. desc->type = IMXDMA_DESC_INTERLEAVED;
  772. desc->src = xt->src_start;
  773. desc->dest = xt->dst_start;
  774. desc->x = xt->sgl[0].size;
  775. desc->y = xt->numf;
  776. desc->w = xt->sgl[0].icg + desc->x;
  777. desc->len = desc->x * desc->y;
  778. desc->direction = DMA_MEM_TO_MEM;
  779. desc->config_port = IMX_DMA_MEMSIZE_32;
  780. desc->config_mem = IMX_DMA_MEMSIZE_32;
  781. if (xt->src_sgl)
  782. desc->config_mem |= IMX_DMA_TYPE_2D;
  783. if (xt->dst_sgl)
  784. desc->config_port |= IMX_DMA_TYPE_2D;
  785. desc->desc.callback = NULL;
  786. desc->desc.callback_param = NULL;
  787. return &desc->desc;
  788. }
  789. static void imxdma_issue_pending(struct dma_chan *chan)
  790. {
  791. struct imxdma_channel *imxdmac = to_imxdma_chan(chan);
  792. struct imxdma_engine *imxdma = imxdmac->imxdma;
  793. struct imxdma_desc *desc;
  794. unsigned long flags;
  795. spin_lock_irqsave(&imxdma->lock, flags);
  796. if (list_empty(&imxdmac->ld_active) &&
  797. !list_empty(&imxdmac->ld_queue)) {
  798. desc = list_first_entry(&imxdmac->ld_queue,
  799. struct imxdma_desc, node);
  800. if (imxdma_xfer_desc(desc) < 0) {
  801. dev_warn(imxdma->dev,
  802. "%s: channel: %d couldn't issue DMA xfer\n",
  803. __func__, imxdmac->channel);
  804. } else {
  805. list_move_tail(imxdmac->ld_queue.next,
  806. &imxdmac->ld_active);
  807. }
  808. }
  809. spin_unlock_irqrestore(&imxdma->lock, flags);
  810. }
  811. static int __init imxdma_probe(struct platform_device *pdev)
  812. {
  813. struct imxdma_engine *imxdma;
  814. int ret, i;
  815. imxdma = kzalloc(sizeof(*imxdma), GFP_KERNEL);
  816. if (!imxdma)
  817. return -ENOMEM;
  818. if (cpu_is_mx1()) {
  819. imxdma->base = MX1_IO_ADDRESS(MX1_DMA_BASE_ADDR);
  820. } else if (cpu_is_mx21()) {
  821. imxdma->base = MX21_IO_ADDRESS(MX21_DMA_BASE_ADDR);
  822. } else if (cpu_is_mx27()) {
  823. imxdma->base = MX27_IO_ADDRESS(MX27_DMA_BASE_ADDR);
  824. } else {
  825. kfree(imxdma);
  826. return 0;
  827. }
  828. imxdma->dma_clk = clk_get(NULL, "dma");
  829. if (IS_ERR(imxdma->dma_clk))
  830. return PTR_ERR(imxdma->dma_clk);
  831. clk_enable(imxdma->dma_clk);
  832. /* reset DMA module */
  833. imx_dmav1_writel(imxdma, DCR_DRST, DMA_DCR);
  834. if (cpu_is_mx1()) {
  835. ret = request_irq(MX1_DMA_INT, dma_irq_handler, 0, "DMA", imxdma);
  836. if (ret) {
  837. dev_warn(imxdma->dev, "Can't register IRQ for DMA\n");
  838. kfree(imxdma);
  839. return ret;
  840. }
  841. ret = request_irq(MX1_DMA_ERR, imxdma_err_handler, 0, "DMA", imxdma);
  842. if (ret) {
  843. dev_warn(imxdma->dev, "Can't register ERRIRQ for DMA\n");
  844. free_irq(MX1_DMA_INT, NULL);
  845. kfree(imxdma);
  846. return ret;
  847. }
  848. }
  849. /* enable DMA module */
  850. imx_dmav1_writel(imxdma, DCR_DEN, DMA_DCR);
  851. /* clear all interrupts */
  852. imx_dmav1_writel(imxdma, (1 << IMX_DMA_CHANNELS) - 1, DMA_DISR);
  853. /* disable interrupts */
  854. imx_dmav1_writel(imxdma, (1 << IMX_DMA_CHANNELS) - 1, DMA_DIMR);
  855. INIT_LIST_HEAD(&imxdma->dma_device.channels);
  856. dma_cap_set(DMA_SLAVE, imxdma->dma_device.cap_mask);
  857. dma_cap_set(DMA_CYCLIC, imxdma->dma_device.cap_mask);
  858. dma_cap_set(DMA_MEMCPY, imxdma->dma_device.cap_mask);
  859. dma_cap_set(DMA_INTERLEAVE, imxdma->dma_device.cap_mask);
  860. /* Initialize 2D global parameters */
  861. for (i = 0; i < IMX_DMA_2D_SLOTS; i++)
  862. imxdma->slots_2d[i].count = 0;
  863. spin_lock_init(&imxdma->lock);
  864. /* Initialize channel parameters */
  865. for (i = 0; i < IMX_DMA_CHANNELS; i++) {
  866. struct imxdma_channel *imxdmac = &imxdma->channel[i];
  867. if (cpu_is_mx21() || cpu_is_mx27()) {
  868. ret = request_irq(MX2x_INT_DMACH0 + i,
  869. dma_irq_handler, 0, "DMA", imxdma);
  870. if (ret) {
  871. dev_warn(imxdma->dev, "Can't register IRQ %d "
  872. "for DMA channel %d\n",
  873. MX2x_INT_DMACH0 + i, i);
  874. goto err_init;
  875. }
  876. init_timer(&imxdmac->watchdog);
  877. imxdmac->watchdog.function = &imxdma_watchdog;
  878. imxdmac->watchdog.data = (unsigned long)imxdmac;
  879. }
  880. imxdmac->imxdma = imxdma;
  881. INIT_LIST_HEAD(&imxdmac->ld_queue);
  882. INIT_LIST_HEAD(&imxdmac->ld_free);
  883. INIT_LIST_HEAD(&imxdmac->ld_active);
  884. tasklet_init(&imxdmac->dma_tasklet, imxdma_tasklet,
  885. (unsigned long)imxdmac);
  886. imxdmac->chan.device = &imxdma->dma_device;
  887. dma_cookie_init(&imxdmac->chan);
  888. imxdmac->channel = i;
  889. /* Add the channel to the DMAC list */
  890. list_add_tail(&imxdmac->chan.device_node,
  891. &imxdma->dma_device.channels);
  892. }
  893. imxdma->dev = &pdev->dev;
  894. imxdma->dma_device.dev = &pdev->dev;
  895. imxdma->dma_device.device_alloc_chan_resources = imxdma_alloc_chan_resources;
  896. imxdma->dma_device.device_free_chan_resources = imxdma_free_chan_resources;
  897. imxdma->dma_device.device_tx_status = imxdma_tx_status;
  898. imxdma->dma_device.device_prep_slave_sg = imxdma_prep_slave_sg;
  899. imxdma->dma_device.device_prep_dma_cyclic = imxdma_prep_dma_cyclic;
  900. imxdma->dma_device.device_prep_dma_memcpy = imxdma_prep_dma_memcpy;
  901. imxdma->dma_device.device_prep_interleaved_dma = imxdma_prep_dma_interleaved;
  902. imxdma->dma_device.device_control = imxdma_control;
  903. imxdma->dma_device.device_issue_pending = imxdma_issue_pending;
  904. platform_set_drvdata(pdev, imxdma);
  905. imxdma->dma_device.copy_align = 2; /* 2^2 = 4 bytes alignment */
  906. imxdma->dma_device.dev->dma_parms = &imxdma->dma_parms;
  907. dma_set_max_seg_size(imxdma->dma_device.dev, 0xffffff);
  908. ret = dma_async_device_register(&imxdma->dma_device);
  909. if (ret) {
  910. dev_err(&pdev->dev, "unable to register\n");
  911. goto err_init;
  912. }
  913. return 0;
  914. err_init:
  915. if (cpu_is_mx21() || cpu_is_mx27()) {
  916. while (--i >= 0)
  917. free_irq(MX2x_INT_DMACH0 + i, NULL);
  918. } else if cpu_is_mx1() {
  919. free_irq(MX1_DMA_INT, NULL);
  920. free_irq(MX1_DMA_ERR, NULL);
  921. }
  922. kfree(imxdma);
  923. return ret;
  924. }
  925. static int __exit imxdma_remove(struct platform_device *pdev)
  926. {
  927. struct imxdma_engine *imxdma = platform_get_drvdata(pdev);
  928. int i;
  929. dma_async_device_unregister(&imxdma->dma_device);
  930. if (cpu_is_mx21() || cpu_is_mx27()) {
  931. for (i = 0; i < IMX_DMA_CHANNELS; i++)
  932. free_irq(MX2x_INT_DMACH0 + i, NULL);
  933. } else if cpu_is_mx1() {
  934. free_irq(MX1_DMA_INT, NULL);
  935. free_irq(MX1_DMA_ERR, NULL);
  936. }
  937. kfree(imxdma);
  938. return 0;
  939. }
  940. static struct platform_driver imxdma_driver = {
  941. .driver = {
  942. .name = "imx-dma",
  943. },
  944. .remove = __exit_p(imxdma_remove),
  945. };
  946. static int __init imxdma_module_init(void)
  947. {
  948. return platform_driver_probe(&imxdma_driver, imxdma_probe);
  949. }
  950. subsys_initcall(imxdma_module_init);
  951. MODULE_AUTHOR("Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>");
  952. MODULE_DESCRIPTION("i.MX dma driver");
  953. MODULE_LICENSE("GPL");