perf ui gtk: Rename functions for consistency
[linux-2.6/btrfs-unstable.git] / drivers / dma / mxs-dma.c
blobc81ef7e10e08283ce8eaf4fadf6166b5d3ddc19c
1 /*
2 * Copyright 2011 Freescale Semiconductor, Inc. All Rights Reserved.
4 * Refer to drivers/dma/imx-sdma.c
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
11 #include <linux/init.h>
12 #include <linux/types.h>
13 #include <linux/mm.h>
14 #include <linux/interrupt.h>
15 #include <linux/clk.h>
16 #include <linux/wait.h>
17 #include <linux/sched.h>
18 #include <linux/semaphore.h>
19 #include <linux/device.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/slab.h>
22 #include <linux/platform_device.h>
23 #include <linux/dmaengine.h>
24 #include <linux/delay.h>
25 #include <linux/fsl/mxs-dma.h>
27 #include <asm/irq.h>
28 #include <mach/mxs.h>
29 #include <mach/common.h>
31 #include "dmaengine.h"
34 * NOTE: The term "PIO" throughout the mxs-dma implementation means
35 * PIO mode of mxs apbh-dma and apbx-dma. With this working mode,
36 * dma can program the controller registers of peripheral devices.
39 #define MXS_DMA_APBH 0
40 #define MXS_DMA_APBX 1
41 #define dma_is_apbh() (mxs_dma->dev_id == MXS_DMA_APBH)
43 #define APBH_VERSION_LATEST 3
44 #define apbh_is_old() (mxs_dma->version < APBH_VERSION_LATEST)
46 #define HW_APBHX_CTRL0 0x000
47 #define BM_APBH_CTRL0_APB_BURST8_EN (1 << 29)
48 #define BM_APBH_CTRL0_APB_BURST_EN (1 << 28)
49 #define BP_APBH_CTRL0_RESET_CHANNEL 16
50 #define HW_APBHX_CTRL1 0x010
51 #define HW_APBHX_CTRL2 0x020
52 #define HW_APBHX_CHANNEL_CTRL 0x030
53 #define BP_APBHX_CHANNEL_CTRL_RESET_CHANNEL 16
54 #define HW_APBH_VERSION (cpu_is_mx23() ? 0x3f0 : 0x800)
55 #define HW_APBX_VERSION 0x800
56 #define BP_APBHX_VERSION_MAJOR 24
57 #define HW_APBHX_CHn_NXTCMDAR(n) \
58 (((dma_is_apbh() && apbh_is_old()) ? 0x050 : 0x110) + (n) * 0x70)
59 #define HW_APBHX_CHn_SEMA(n) \
60 (((dma_is_apbh() && apbh_is_old()) ? 0x080 : 0x140) + (n) * 0x70)
63 * ccw bits definitions
65 * COMMAND: 0..1 (2)
66 * CHAIN: 2 (1)
67 * IRQ: 3 (1)
68 * NAND_LOCK: 4 (1) - not implemented
69 * NAND_WAIT4READY: 5 (1) - not implemented
70 * DEC_SEM: 6 (1)
71 * WAIT4END: 7 (1)
72 * HALT_ON_TERMINATE: 8 (1)
73 * TERMINATE_FLUSH: 9 (1)
74 * RESERVED: 10..11 (2)
75 * PIO_NUM: 12..15 (4)
77 #define BP_CCW_COMMAND 0
78 #define BM_CCW_COMMAND (3 << 0)
79 #define CCW_CHAIN (1 << 2)
80 #define CCW_IRQ (1 << 3)
81 #define CCW_DEC_SEM (1 << 6)
82 #define CCW_WAIT4END (1 << 7)
83 #define CCW_HALT_ON_TERM (1 << 8)
84 #define CCW_TERM_FLUSH (1 << 9)
85 #define BP_CCW_PIO_NUM 12
86 #define BM_CCW_PIO_NUM (0xf << 12)
88 #define BF_CCW(value, field) (((value) << BP_CCW_##field) & BM_CCW_##field)
90 #define MXS_DMA_CMD_NO_XFER 0
91 #define MXS_DMA_CMD_WRITE 1
92 #define MXS_DMA_CMD_READ 2
93 #define MXS_DMA_CMD_DMA_SENSE 3 /* not implemented */
95 struct mxs_dma_ccw {
96 u32 next;
97 u16 bits;
98 u16 xfer_bytes;
99 #define MAX_XFER_BYTES 0xff00
100 u32 bufaddr;
101 #define MXS_PIO_WORDS 16
102 u32 pio_words[MXS_PIO_WORDS];
105 #define NUM_CCW (int)(PAGE_SIZE / sizeof(struct mxs_dma_ccw))
107 struct mxs_dma_chan {
108 struct mxs_dma_engine *mxs_dma;
109 struct dma_chan chan;
110 struct dma_async_tx_descriptor desc;
111 struct tasklet_struct tasklet;
112 int chan_irq;
113 struct mxs_dma_ccw *ccw;
114 dma_addr_t ccw_phys;
115 int desc_count;
116 enum dma_status status;
117 unsigned int flags;
118 #define MXS_DMA_SG_LOOP (1 << 0)
121 #define MXS_DMA_CHANNELS 16
122 #define MXS_DMA_CHANNELS_MASK 0xffff
124 struct mxs_dma_engine {
125 int dev_id;
126 unsigned int version;
127 void __iomem *base;
128 struct clk *clk;
129 struct dma_device dma_device;
130 struct device_dma_parameters dma_parms;
131 struct mxs_dma_chan mxs_chans[MXS_DMA_CHANNELS];
134 static void mxs_dma_reset_chan(struct mxs_dma_chan *mxs_chan)
136 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
137 int chan_id = mxs_chan->chan.chan_id;
139 if (dma_is_apbh() && apbh_is_old())
140 writel(1 << (chan_id + BP_APBH_CTRL0_RESET_CHANNEL),
141 mxs_dma->base + HW_APBHX_CTRL0 + MXS_SET_ADDR);
142 else
143 writel(1 << (chan_id + BP_APBHX_CHANNEL_CTRL_RESET_CHANNEL),
144 mxs_dma->base + HW_APBHX_CHANNEL_CTRL + MXS_SET_ADDR);
147 static void mxs_dma_enable_chan(struct mxs_dma_chan *mxs_chan)
149 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
150 int chan_id = mxs_chan->chan.chan_id;
152 /* set cmd_addr up */
153 writel(mxs_chan->ccw_phys,
154 mxs_dma->base + HW_APBHX_CHn_NXTCMDAR(chan_id));
156 /* write 1 to SEMA to kick off the channel */
157 writel(1, mxs_dma->base + HW_APBHX_CHn_SEMA(chan_id));
160 static void mxs_dma_disable_chan(struct mxs_dma_chan *mxs_chan)
162 mxs_chan->status = DMA_SUCCESS;
165 static void mxs_dma_pause_chan(struct mxs_dma_chan *mxs_chan)
167 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
168 int chan_id = mxs_chan->chan.chan_id;
170 /* freeze the channel */
171 if (dma_is_apbh() && apbh_is_old())
172 writel(1 << chan_id,
173 mxs_dma->base + HW_APBHX_CTRL0 + MXS_SET_ADDR);
174 else
175 writel(1 << chan_id,
176 mxs_dma->base + HW_APBHX_CHANNEL_CTRL + MXS_SET_ADDR);
178 mxs_chan->status = DMA_PAUSED;
181 static void mxs_dma_resume_chan(struct mxs_dma_chan *mxs_chan)
183 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
184 int chan_id = mxs_chan->chan.chan_id;
186 /* unfreeze the channel */
187 if (dma_is_apbh() && apbh_is_old())
188 writel(1 << chan_id,
189 mxs_dma->base + HW_APBHX_CTRL0 + MXS_CLR_ADDR);
190 else
191 writel(1 << chan_id,
192 mxs_dma->base + HW_APBHX_CHANNEL_CTRL + MXS_CLR_ADDR);
194 mxs_chan->status = DMA_IN_PROGRESS;
197 static struct mxs_dma_chan *to_mxs_dma_chan(struct dma_chan *chan)
199 return container_of(chan, struct mxs_dma_chan, chan);
202 static dma_cookie_t mxs_dma_tx_submit(struct dma_async_tx_descriptor *tx)
204 struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(tx->chan);
206 mxs_dma_enable_chan(mxs_chan);
208 return dma_cookie_assign(tx);
211 static void mxs_dma_tasklet(unsigned long data)
213 struct mxs_dma_chan *mxs_chan = (struct mxs_dma_chan *) data;
215 if (mxs_chan->desc.callback)
216 mxs_chan->desc.callback(mxs_chan->desc.callback_param);
219 static irqreturn_t mxs_dma_int_handler(int irq, void *dev_id)
221 struct mxs_dma_engine *mxs_dma = dev_id;
222 u32 stat1, stat2;
224 /* completion status */
225 stat1 = readl(mxs_dma->base + HW_APBHX_CTRL1);
226 stat1 &= MXS_DMA_CHANNELS_MASK;
227 writel(stat1, mxs_dma->base + HW_APBHX_CTRL1 + MXS_CLR_ADDR);
229 /* error status */
230 stat2 = readl(mxs_dma->base + HW_APBHX_CTRL2);
231 writel(stat2, mxs_dma->base + HW_APBHX_CTRL2 + MXS_CLR_ADDR);
234 * When both completion and error of termination bits set at the
235 * same time, we do not take it as an error. IOW, it only becomes
236 * an error we need to handle here in case of either it's (1) a bus
237 * error or (2) a termination error with no completion.
239 stat2 = ((stat2 >> MXS_DMA_CHANNELS) & stat2) | /* (1) */
240 (~(stat2 >> MXS_DMA_CHANNELS) & stat2 & ~stat1); /* (2) */
242 /* combine error and completion status for checking */
243 stat1 = (stat2 << MXS_DMA_CHANNELS) | stat1;
244 while (stat1) {
245 int channel = fls(stat1) - 1;
246 struct mxs_dma_chan *mxs_chan =
247 &mxs_dma->mxs_chans[channel % MXS_DMA_CHANNELS];
249 if (channel >= MXS_DMA_CHANNELS) {
250 dev_dbg(mxs_dma->dma_device.dev,
251 "%s: error in channel %d\n", __func__,
252 channel - MXS_DMA_CHANNELS);
253 mxs_chan->status = DMA_ERROR;
254 mxs_dma_reset_chan(mxs_chan);
255 } else {
256 if (mxs_chan->flags & MXS_DMA_SG_LOOP)
257 mxs_chan->status = DMA_IN_PROGRESS;
258 else
259 mxs_chan->status = DMA_SUCCESS;
262 stat1 &= ~(1 << channel);
264 if (mxs_chan->status == DMA_SUCCESS)
265 dma_cookie_complete(&mxs_chan->desc);
267 /* schedule tasklet on this channel */
268 tasklet_schedule(&mxs_chan->tasklet);
271 return IRQ_HANDLED;
274 static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
276 struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
277 struct mxs_dma_data *data = chan->private;
278 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
279 int ret;
281 if (!data)
282 return -EINVAL;
284 mxs_chan->chan_irq = data->chan_irq;
286 mxs_chan->ccw = dma_alloc_coherent(mxs_dma->dma_device.dev, PAGE_SIZE,
287 &mxs_chan->ccw_phys, GFP_KERNEL);
288 if (!mxs_chan->ccw) {
289 ret = -ENOMEM;
290 goto err_alloc;
293 memset(mxs_chan->ccw, 0, PAGE_SIZE);
295 if (mxs_chan->chan_irq != NO_IRQ) {
296 ret = request_irq(mxs_chan->chan_irq, mxs_dma_int_handler,
297 0, "mxs-dma", mxs_dma);
298 if (ret)
299 goto err_irq;
302 ret = clk_prepare_enable(mxs_dma->clk);
303 if (ret)
304 goto err_clk;
306 mxs_dma_reset_chan(mxs_chan);
308 dma_async_tx_descriptor_init(&mxs_chan->desc, chan);
309 mxs_chan->desc.tx_submit = mxs_dma_tx_submit;
311 /* the descriptor is ready */
312 async_tx_ack(&mxs_chan->desc);
314 return 0;
316 err_clk:
317 free_irq(mxs_chan->chan_irq, mxs_dma);
318 err_irq:
319 dma_free_coherent(mxs_dma->dma_device.dev, PAGE_SIZE,
320 mxs_chan->ccw, mxs_chan->ccw_phys);
321 err_alloc:
322 return ret;
325 static void mxs_dma_free_chan_resources(struct dma_chan *chan)
327 struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
328 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
330 mxs_dma_disable_chan(mxs_chan);
332 free_irq(mxs_chan->chan_irq, mxs_dma);
334 dma_free_coherent(mxs_dma->dma_device.dev, PAGE_SIZE,
335 mxs_chan->ccw, mxs_chan->ccw_phys);
337 clk_disable_unprepare(mxs_dma->clk);
341 * How to use the flags for ->device_prep_slave_sg() :
342 * [1] If there is only one DMA command in the DMA chain, the code should be:
343 * ......
344 * ->device_prep_slave_sg(DMA_CTRL_ACK);
345 * ......
346 * [2] If there are two DMA commands in the DMA chain, the code should be
347 * ......
348 * ->device_prep_slave_sg(0);
349 * ......
350 * ->device_prep_slave_sg(DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
351 * ......
352 * [3] If there are more than two DMA commands in the DMA chain, the code
353 * should be:
354 * ......
355 * ->device_prep_slave_sg(0); // First
356 * ......
357 * ->device_prep_slave_sg(DMA_PREP_INTERRUPT [| DMA_CTRL_ACK]);
358 * ......
359 * ->device_prep_slave_sg(DMA_PREP_INTERRUPT | DMA_CTRL_ACK); // Last
360 * ......
362 static struct dma_async_tx_descriptor *mxs_dma_prep_slave_sg(
363 struct dma_chan *chan, struct scatterlist *sgl,
364 unsigned int sg_len, enum dma_transfer_direction direction,
365 unsigned long flags, void *context)
367 struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
368 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
369 struct mxs_dma_ccw *ccw;
370 struct scatterlist *sg;
371 int i, j;
372 u32 *pio;
373 bool append = flags & DMA_PREP_INTERRUPT;
374 int idx = append ? mxs_chan->desc_count : 0;
376 if (mxs_chan->status == DMA_IN_PROGRESS && !append)
377 return NULL;
379 if (sg_len + (append ? idx : 0) > NUM_CCW) {
380 dev_err(mxs_dma->dma_device.dev,
381 "maximum number of sg exceeded: %d > %d\n",
382 sg_len, NUM_CCW);
383 goto err_out;
386 mxs_chan->status = DMA_IN_PROGRESS;
387 mxs_chan->flags = 0;
390 * If the sg is prepared with append flag set, the sg
391 * will be appended to the last prepared sg.
393 if (append) {
394 BUG_ON(idx < 1);
395 ccw = &mxs_chan->ccw[idx - 1];
396 ccw->next = mxs_chan->ccw_phys + sizeof(*ccw) * idx;
397 ccw->bits |= CCW_CHAIN;
398 ccw->bits &= ~CCW_IRQ;
399 ccw->bits &= ~CCW_DEC_SEM;
400 } else {
401 idx = 0;
404 if (direction == DMA_TRANS_NONE) {
405 ccw = &mxs_chan->ccw[idx++];
406 pio = (u32 *) sgl;
408 for (j = 0; j < sg_len;)
409 ccw->pio_words[j++] = *pio++;
411 ccw->bits = 0;
412 ccw->bits |= CCW_IRQ;
413 ccw->bits |= CCW_DEC_SEM;
414 if (flags & DMA_CTRL_ACK)
415 ccw->bits |= CCW_WAIT4END;
416 ccw->bits |= CCW_HALT_ON_TERM;
417 ccw->bits |= CCW_TERM_FLUSH;
418 ccw->bits |= BF_CCW(sg_len, PIO_NUM);
419 ccw->bits |= BF_CCW(MXS_DMA_CMD_NO_XFER, COMMAND);
420 } else {
421 for_each_sg(sgl, sg, sg_len, i) {
422 if (sg->length > MAX_XFER_BYTES) {
423 dev_err(mxs_dma->dma_device.dev, "maximum bytes for sg entry exceeded: %d > %d\n",
424 sg->length, MAX_XFER_BYTES);
425 goto err_out;
428 ccw = &mxs_chan->ccw[idx++];
430 ccw->next = mxs_chan->ccw_phys + sizeof(*ccw) * idx;
431 ccw->bufaddr = sg->dma_address;
432 ccw->xfer_bytes = sg->length;
434 ccw->bits = 0;
435 ccw->bits |= CCW_CHAIN;
436 ccw->bits |= CCW_HALT_ON_TERM;
437 ccw->bits |= CCW_TERM_FLUSH;
438 ccw->bits |= BF_CCW(direction == DMA_DEV_TO_MEM ?
439 MXS_DMA_CMD_WRITE : MXS_DMA_CMD_READ,
440 COMMAND);
442 if (i + 1 == sg_len) {
443 ccw->bits &= ~CCW_CHAIN;
444 ccw->bits |= CCW_IRQ;
445 ccw->bits |= CCW_DEC_SEM;
446 if (flags & DMA_CTRL_ACK)
447 ccw->bits |= CCW_WAIT4END;
451 mxs_chan->desc_count = idx;
453 return &mxs_chan->desc;
455 err_out:
456 mxs_chan->status = DMA_ERROR;
457 return NULL;
460 static struct dma_async_tx_descriptor *mxs_dma_prep_dma_cyclic(
461 struct dma_chan *chan, dma_addr_t dma_addr, size_t buf_len,
462 size_t period_len, enum dma_transfer_direction direction,
463 void *context)
465 struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
466 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
467 int num_periods = buf_len / period_len;
468 int i = 0, buf = 0;
470 if (mxs_chan->status == DMA_IN_PROGRESS)
471 return NULL;
473 mxs_chan->status = DMA_IN_PROGRESS;
474 mxs_chan->flags |= MXS_DMA_SG_LOOP;
476 if (num_periods > NUM_CCW) {
477 dev_err(mxs_dma->dma_device.dev,
478 "maximum number of sg exceeded: %d > %d\n",
479 num_periods, NUM_CCW);
480 goto err_out;
483 if (period_len > MAX_XFER_BYTES) {
484 dev_err(mxs_dma->dma_device.dev,
485 "maximum period size exceeded: %d > %d\n",
486 period_len, MAX_XFER_BYTES);
487 goto err_out;
490 while (buf < buf_len) {
491 struct mxs_dma_ccw *ccw = &mxs_chan->ccw[i];
493 if (i + 1 == num_periods)
494 ccw->next = mxs_chan->ccw_phys;
495 else
496 ccw->next = mxs_chan->ccw_phys + sizeof(*ccw) * (i + 1);
498 ccw->bufaddr = dma_addr;
499 ccw->xfer_bytes = period_len;
501 ccw->bits = 0;
502 ccw->bits |= CCW_CHAIN;
503 ccw->bits |= CCW_IRQ;
504 ccw->bits |= CCW_HALT_ON_TERM;
505 ccw->bits |= CCW_TERM_FLUSH;
506 ccw->bits |= BF_CCW(direction == DMA_DEV_TO_MEM ?
507 MXS_DMA_CMD_WRITE : MXS_DMA_CMD_READ, COMMAND);
509 dma_addr += period_len;
510 buf += period_len;
512 i++;
514 mxs_chan->desc_count = i;
516 return &mxs_chan->desc;
518 err_out:
519 mxs_chan->status = DMA_ERROR;
520 return NULL;
523 static int mxs_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
524 unsigned long arg)
526 struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
527 int ret = 0;
529 switch (cmd) {
530 case DMA_TERMINATE_ALL:
531 mxs_dma_reset_chan(mxs_chan);
532 mxs_dma_disable_chan(mxs_chan);
533 break;
534 case DMA_PAUSE:
535 mxs_dma_pause_chan(mxs_chan);
536 break;
537 case DMA_RESUME:
538 mxs_dma_resume_chan(mxs_chan);
539 break;
540 default:
541 ret = -ENOSYS;
544 return ret;
547 static enum dma_status mxs_dma_tx_status(struct dma_chan *chan,
548 dma_cookie_t cookie, struct dma_tx_state *txstate)
550 struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
551 dma_cookie_t last_used;
553 last_used = chan->cookie;
554 dma_set_tx_state(txstate, chan->completed_cookie, last_used, 0);
556 return mxs_chan->status;
559 static void mxs_dma_issue_pending(struct dma_chan *chan)
562 * Nothing to do. We only have a single descriptor.
566 static int __init mxs_dma_init(struct mxs_dma_engine *mxs_dma)
568 int ret;
570 ret = clk_prepare_enable(mxs_dma->clk);
571 if (ret)
572 return ret;
574 ret = mxs_reset_block(mxs_dma->base);
575 if (ret)
576 goto err_out;
578 /* only major version matters */
579 mxs_dma->version = readl(mxs_dma->base +
580 ((mxs_dma->dev_id == MXS_DMA_APBX) ?
581 HW_APBX_VERSION : HW_APBH_VERSION)) >>
582 BP_APBHX_VERSION_MAJOR;
584 /* enable apbh burst */
585 if (dma_is_apbh()) {
586 writel(BM_APBH_CTRL0_APB_BURST_EN,
587 mxs_dma->base + HW_APBHX_CTRL0 + MXS_SET_ADDR);
588 writel(BM_APBH_CTRL0_APB_BURST8_EN,
589 mxs_dma->base + HW_APBHX_CTRL0 + MXS_SET_ADDR);
592 /* enable irq for all the channels */
593 writel(MXS_DMA_CHANNELS_MASK << MXS_DMA_CHANNELS,
594 mxs_dma->base + HW_APBHX_CTRL1 + MXS_SET_ADDR);
596 err_out:
597 clk_disable_unprepare(mxs_dma->clk);
598 return ret;
601 static int __init mxs_dma_probe(struct platform_device *pdev)
603 const struct platform_device_id *id_entry =
604 platform_get_device_id(pdev);
605 struct mxs_dma_engine *mxs_dma;
606 struct resource *iores;
607 int ret, i;
609 mxs_dma = kzalloc(sizeof(*mxs_dma), GFP_KERNEL);
610 if (!mxs_dma)
611 return -ENOMEM;
613 mxs_dma->dev_id = id_entry->driver_data;
615 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
617 if (!request_mem_region(iores->start, resource_size(iores),
618 pdev->name)) {
619 ret = -EBUSY;
620 goto err_request_region;
623 mxs_dma->base = ioremap(iores->start, resource_size(iores));
624 if (!mxs_dma->base) {
625 ret = -ENOMEM;
626 goto err_ioremap;
629 mxs_dma->clk = clk_get(&pdev->dev, NULL);
630 if (IS_ERR(mxs_dma->clk)) {
631 ret = PTR_ERR(mxs_dma->clk);
632 goto err_clk;
635 dma_cap_set(DMA_SLAVE, mxs_dma->dma_device.cap_mask);
636 dma_cap_set(DMA_CYCLIC, mxs_dma->dma_device.cap_mask);
638 INIT_LIST_HEAD(&mxs_dma->dma_device.channels);
640 /* Initialize channel parameters */
641 for (i = 0; i < MXS_DMA_CHANNELS; i++) {
642 struct mxs_dma_chan *mxs_chan = &mxs_dma->mxs_chans[i];
644 mxs_chan->mxs_dma = mxs_dma;
645 mxs_chan->chan.device = &mxs_dma->dma_device;
646 dma_cookie_init(&mxs_chan->chan);
648 tasklet_init(&mxs_chan->tasklet, mxs_dma_tasklet,
649 (unsigned long) mxs_chan);
652 /* Add the channel to mxs_chan list */
653 list_add_tail(&mxs_chan->chan.device_node,
654 &mxs_dma->dma_device.channels);
657 ret = mxs_dma_init(mxs_dma);
658 if (ret)
659 goto err_init;
661 mxs_dma->dma_device.dev = &pdev->dev;
663 /* mxs_dma gets 65535 bytes maximum sg size */
664 mxs_dma->dma_device.dev->dma_parms = &mxs_dma->dma_parms;
665 dma_set_max_seg_size(mxs_dma->dma_device.dev, MAX_XFER_BYTES);
667 mxs_dma->dma_device.device_alloc_chan_resources = mxs_dma_alloc_chan_resources;
668 mxs_dma->dma_device.device_free_chan_resources = mxs_dma_free_chan_resources;
669 mxs_dma->dma_device.device_tx_status = mxs_dma_tx_status;
670 mxs_dma->dma_device.device_prep_slave_sg = mxs_dma_prep_slave_sg;
671 mxs_dma->dma_device.device_prep_dma_cyclic = mxs_dma_prep_dma_cyclic;
672 mxs_dma->dma_device.device_control = mxs_dma_control;
673 mxs_dma->dma_device.device_issue_pending = mxs_dma_issue_pending;
675 ret = dma_async_device_register(&mxs_dma->dma_device);
676 if (ret) {
677 dev_err(mxs_dma->dma_device.dev, "unable to register\n");
678 goto err_init;
681 dev_info(mxs_dma->dma_device.dev, "initialized\n");
683 return 0;
685 err_init:
686 clk_put(mxs_dma->clk);
687 err_clk:
688 iounmap(mxs_dma->base);
689 err_ioremap:
690 release_mem_region(iores->start, resource_size(iores));
691 err_request_region:
692 kfree(mxs_dma);
693 return ret;
696 static struct platform_device_id mxs_dma_type[] = {
698 .name = "mxs-dma-apbh",
699 .driver_data = MXS_DMA_APBH,
700 }, {
701 .name = "mxs-dma-apbx",
702 .driver_data = MXS_DMA_APBX,
703 }, {
704 /* end of list */
708 static struct platform_driver mxs_dma_driver = {
709 .driver = {
710 .name = "mxs-dma",
712 .id_table = mxs_dma_type,
715 static int __init mxs_dma_module_init(void)
717 return platform_driver_probe(&mxs_dma_driver, mxs_dma_probe);
719 subsys_initcall(mxs_dma_module_init);