aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-imx/dma.c
diff options
context:
space:
mode:
authorPavel Pisa <ppisa@pikron.com>2006-04-02 11:58:37 -0400
committerRussell King <rmk+kernel@arm.linux.org.uk>2006-04-02 11:58:37 -0400
commit999331af456bf6fc1520ea7b68b6a3dbb4af8ff6 (patch)
treed7610740f58f942fcb46e07bb790dfd785e21508 /arch/arm/mach-imx/dma.c
parent7ba01f9728a9f1cd1a3e1e2d5206f76061182675 (diff)
[ARM] 3444/1: i.MX: Scatter-gather DMA emulation for i.MX/MX1
Patch from Pavel Pisa This patch contains simplified set of changes to add scatter-gather emulation capability into MX1 DMA support. The result should be still usable for next combination of DMA transfers Statter-Gather/linear/2D/FIFO to linear/2D/FIFO and linear/2D/FIFO to Statter-Gather/2D/FIFO The patch corrects channel priority allocation to be compatible with MX1 hardware implementation. Previous code has not been adapted from its PXA original. Signed-off-by: Pavel Pisa <pisa@cmp.felk.cvut.cz> Acked-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm/mach-imx/dma.c')
-rw-r--r--arch/arm/mach-imx/dma.c511
1 files changed, 448 insertions, 63 deletions
diff --git a/arch/arm/mach-imx/dma.c b/arch/arm/mach-imx/dma.c
index 71a59e196166..4ca51dcf13ac 100644
--- a/arch/arm/mach-imx/dma.c
+++ b/arch/arm/mach-imx/dma.c
@@ -7,11 +7,18 @@
7 * it under the terms of the GNU General Public License version 2 as 7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 * 9 *
10 * 03/03/2004 Sascha Hauer <sascha@saschahauer.de> 10 * 2004-03-03 Sascha Hauer <sascha@saschahauer.de>
11 * initial version heavily inspired by 11 * initial version heavily inspired by
12 * linux/arch/arm/mach-pxa/dma.c 12 * linux/arch/arm/mach-pxa/dma.c
13 *
14 * 2005-04-17 Pavel Pisa <pisa@cmp.felk.cvut.cz>
15 * Changed to support scatter gather DMA
16 * by taking Russell's code from RiscPC
17 *
13 */ 18 */
14 19
20#undef DEBUG
21
15#include <linux/module.h> 22#include <linux/module.h>
16#include <linux/init.h> 23#include <linux/init.h>
17#include <linux/kernel.h> 24#include <linux/kernel.h>
@@ -22,69 +29,368 @@
22#include <asm/irq.h> 29#include <asm/irq.h>
23#include <asm/hardware.h> 30#include <asm/hardware.h>
24#include <asm/dma.h> 31#include <asm/dma.h>
32#include <asm/arch/imx-dma.h>
33
34struct imx_dma_channel imx_dma_channels[IMX_DMA_CHANNELS];
35
36/*
37 * imx_dma_sg_next - prepare next chunk for scatter-gather DMA emulation
38 * @dma_ch: i.MX DMA channel number
39 * @lastcount: number of bytes transferred during last transfer
40 *
41 * Functions prepares DMA controller for next sg data chunk transfer.
42 * The @lastcount argument informs function about number of bytes transferred
43 * during last block. Zero value can be used for @lastcount to setup DMA
44 * for the first chunk.
45 */
46static inline int imx_dma_sg_next(imx_dmach_t dma_ch, unsigned int lastcount)
47{
48 struct imx_dma_channel *imxdma = &imx_dma_channels[dma_ch];
49 unsigned int nextcount;
50 unsigned int nextaddr;
51
52 if (!imxdma->name) {
53 printk(KERN_CRIT "%s: called for not allocated channel %d\n",
54 __FUNCTION__, dma_ch);
55 return 0;
56 }
57
58 imxdma->resbytes -= lastcount;
59
60 if (!imxdma->sg) {
61 pr_debug("imxdma%d: no sg data\n", dma_ch);
62 return 0;
63 }
64
65 imxdma->sgbc += lastcount;
66 if ((imxdma->sgbc >= imxdma->sg->length) || !imxdma->resbytes) {
67 if ((imxdma->sgcount <= 1) || !imxdma->resbytes) {
68 pr_debug("imxdma%d: sg transfer limit reached\n",
69 dma_ch);
70 imxdma->sgcount=0;
71 imxdma->sg = NULL;
72 return 0;
73 } else {
74 imxdma->sgcount--;
75 imxdma->sg++;
76 imxdma->sgbc = 0;
77 }
78 }
79 nextcount = imxdma->sg->length - imxdma->sgbc;
80 nextaddr = imxdma->sg->dma_address + imxdma->sgbc;
25 81
26static struct dma_channel { 82 if(imxdma->resbytes < nextcount)
27 char *name; 83 nextcount = imxdma->resbytes;
28 void (*irq_handler) (int, void *, struct pt_regs *);
29 void (*err_handler) (int, void *, struct pt_regs *);
30 void *data;
31} dma_channels[11];
32 84
33/* set err_handler to NULL to have the standard info-only error handler */ 85 if ((imxdma->dma_mode & DMA_MODE_MASK) == DMA_MODE_READ)
86 DAR(dma_ch) = nextaddr;
87 else
88 SAR(dma_ch) = nextaddr;
89
90 CNTR(dma_ch) = nextcount;
91 pr_debug("imxdma%d: next sg chunk dst 0x%08x, src 0x%08x, size 0x%08x\n",
92 dma_ch, DAR(dma_ch), SAR(dma_ch), CNTR(dma_ch));
93
94 return nextcount;
95}
96
97/*
98 * imx_dma_setup_sg_base - scatter-gather DMA emulation
99 * @dma_ch: i.MX DMA channel number
100 * @sg: pointer to the scatter-gather list/vector
101 * @sgcount: scatter-gather list hungs count
102 *
103 * Functions sets up i.MX DMA state for emulated scatter-gather transfer
104 * and sets up channel registers to be ready for the first chunk
105 */
106static int
107imx_dma_setup_sg_base(imx_dmach_t dma_ch,
108 struct scatterlist *sg, unsigned int sgcount)
109{
110 struct imx_dma_channel *imxdma = &imx_dma_channels[dma_ch];
111
112 imxdma->sg = sg;
113 imxdma->sgcount = sgcount;
114 imxdma->sgbc = 0;
115 return imx_dma_sg_next(dma_ch, 0);
116}
117
118/**
119 * imx_dma_setup_single - setup i.MX DMA channel for linear memory to/from device transfer
120 * @dma_ch: i.MX DMA channel number
121 * @dma_address: the DMA/physical memory address of the linear data block
122 * to transfer
123 * @dma_length: length of the data block in bytes
124 * @dev_addr: physical device port address
125 * @dmamode: DMA transfer mode, %DMA_MODE_READ from the device to the memory
126 * or %DMA_MODE_WRITE from memory to the device
127 *
128 * The function setups DMA channel source and destination addresses for transfer
129 * specified by provided parameters. The scatter-gather emulation is disabled,
130 * because linear data block
131 * form the physical address range is transfered.
132 * Return value: if incorrect parameters are provided -%EINVAL.
133 * Zero indicates success.
134 */
34int 135int
35imx_request_dma(char *name, imx_dma_prio prio, 136imx_dma_setup_single(imx_dmach_t dma_ch, dma_addr_t dma_address,
36 void (*irq_handler) (int, void *, struct pt_regs *), 137 unsigned int dma_length, unsigned int dev_addr,
37 void (*err_handler) (int, void *, struct pt_regs *), void *data) 138 dmamode_t dmamode)
38{ 139{
39 unsigned long flags; 140 struct imx_dma_channel *imxdma = &imx_dma_channels[dma_ch];
40 int i, found = 0;
41 141
42 /* basic sanity checks */ 142 imxdma->sg = NULL;
43 if (!name || !irq_handler) 143 imxdma->sgcount = 0;
144 imxdma->dma_mode = dmamode;
145 imxdma->resbytes = dma_length;
146
147 if (!dma_address) {
148 printk(KERN_ERR "imxdma%d: imx_dma_setup_single null address\n",
149 dma_ch);
44 return -EINVAL; 150 return -EINVAL;
151 }
45 152
46 local_irq_save(flags); 153 if (!dma_length) {
154 printk(KERN_ERR "imxdma%d: imx_dma_setup_single zero length\n",
155 dma_ch);
156 return -EINVAL;
157 }
47 158
48 /* try grabbing a DMA channel with the requested priority */ 159 if ((dmamode & DMA_MODE_MASK) == DMA_MODE_READ) {
49 for (i = prio; i < prio + (prio == DMA_PRIO_LOW) ? 8 : 4; i++) { 160 pr_debug("imxdma%d: mx_dma_setup_single2dev dma_addressg=0x%08x dma_length=%d dev_addr=0x%08x for read\n",
50 if (!dma_channels[i].name) { 161 dma_ch, (unsigned int)dma_address, dma_length,
51 found = 1; 162 dev_addr);
52 break; 163 SAR(dma_ch) = dev_addr;
53 } 164 DAR(dma_ch) = (unsigned int)dma_address;
165 } else if ((dmamode & DMA_MODE_MASK) == DMA_MODE_WRITE) {
166 pr_debug("imxdma%d: mx_dma_setup_single2dev dma_addressg=0x%08x dma_length=%d dev_addr=0x%08x for write\n",
167 dma_ch, (unsigned int)dma_address, dma_length,
168 dev_addr);
169 SAR(dma_ch) = (unsigned int)dma_address;
170 DAR(dma_ch) = dev_addr;
171 } else {
172 printk(KERN_ERR "imxdma%d: imx_dma_setup_single bad dmamode\n",
173 dma_ch);
174 return -EINVAL;
54 } 175 }
55 176
56 if (!found) { 177 CNTR(dma_ch) = dma_length;
57 /* requested prio group is full, try hier priorities */ 178
58 for (i = prio - 1; i >= 0; i--) { 179 return 0;
59 if (!dma_channels[i].name) { 180}
60 found = 1; 181
61 break; 182/**
62 } 183 * imx_dma_setup_sg - setup i.MX DMA channel SG list to/from device transfer
63 } 184 * @dma_ch: i.MX DMA channel number
185 * @sg: pointer to the scatter-gather list/vector
186 * @sgcount: scatter-gather list hungs count
187 * @dma_length: total length of the transfer request in bytes
188 * @dev_addr: physical device port address
189 * @dmamode: DMA transfer mode, %DMA_MODE_READ from the device to the memory
190 * or %DMA_MODE_WRITE from memory to the device
191 *
192 * The function setups DMA channel state and registers to be ready for transfer
193 * specified by provided parameters. The scatter-gather emulation is set up
194 * according to the parameters.
195 *
196 * The full preparation of the transfer requires setup of more register
197 * by the caller before imx_dma_enable() can be called.
198 *
199 * %BLR(dma_ch) holds transfer burst length in bytes, 0 means 64 bytes
200 *
201 * %RSSR(dma_ch) has to be set to the DMA request line source %DMA_REQ_xxx
202 *
203 * %CCR(dma_ch) has to specify transfer parameters, the next settings is typical
204 * for linear or simple scatter-gather transfers if %DMA_MODE_READ is specified
205 *
206 * %CCR_DMOD_LINEAR | %CCR_DSIZ_32 | %CCR_SMOD_FIFO | %CCR_SSIZ_x
207 *
208 * The typical setup for %DMA_MODE_WRITE is specified by next options combination
209 *
210 * %CCR_SMOD_LINEAR | %CCR_SSIZ_32 | %CCR_DMOD_FIFO | %CCR_DSIZ_x
211 *
212 * Be carefull there and do not mistakenly mix source and target device
213 * port sizes constants, they are really different:
214 * %CCR_SSIZ_8, %CCR_SSIZ_16, %CCR_SSIZ_32,
215 * %CCR_DSIZ_8, %CCR_DSIZ_16, %CCR_DSIZ_32
216 *
217 * Return value: if incorrect parameters are provided -%EINVAL.
218 * Zero indicates success.
219 */
220int
221imx_dma_setup_sg(imx_dmach_t dma_ch,
222 struct scatterlist *sg, unsigned int sgcount, unsigned int dma_length,
223 unsigned int dev_addr, dmamode_t dmamode)
224{
225 int res;
226 struct imx_dma_channel *imxdma = &imx_dma_channels[dma_ch];
227
228 imxdma->sg = NULL;
229 imxdma->sgcount = 0;
230 imxdma->dma_mode = dmamode;
231 imxdma->resbytes = dma_length;
232
233 if (!sg || !sgcount) {
234 printk(KERN_ERR "imxdma%d: imx_dma_setup_sg epty sg list\n",
235 dma_ch);
236 return -EINVAL;
237 }
238
239 if (!sg->length) {
240 printk(KERN_ERR "imxdma%d: imx_dma_setup_sg zero length\n",
241 dma_ch);
242 return -EINVAL;
64 } 243 }
65 244
66 if (found) { 245 if ((dmamode & DMA_MODE_MASK) == DMA_MODE_READ) {
67 DIMR &= ~(1 << i); 246 pr_debug("imxdma%d: mx_dma_setup_sg2dev sg=%p sgcount=%d total length=%d dev_addr=0x%08x for read\n",
68 dma_channels[i].name = name; 247 dma_ch, sg, sgcount, dma_length, dev_addr);
69 dma_channels[i].irq_handler = irq_handler; 248 SAR(dma_ch) = dev_addr;
70 dma_channels[i].err_handler = err_handler; 249 } else if ((dmamode & DMA_MODE_MASK) == DMA_MODE_WRITE) {
71 dma_channels[i].data = data; 250 pr_debug("imxdma%d: mx_dma_setup_sg2dev sg=%p sgcount=%d total length=%d dev_addr=0x%08x for write\n",
251 dma_ch, sg, sgcount, dma_length, dev_addr);
252 DAR(dma_ch) = dev_addr;
72 } else { 253 } else {
73 printk(KERN_WARNING "No more available DMA channels for %s\n", 254 printk(KERN_ERR "imxdma%d: imx_dma_setup_sg bad dmamode\n",
74 name); 255 dma_ch);
75 i = -ENODEV; 256 return -EINVAL;
257 }
258
259 res = imx_dma_setup_sg_base(dma_ch, sg, sgcount);
260 if (res <= 0) {
261 printk(KERN_ERR "imxdma%d: no sg chunk ready\n", dma_ch);
262 return -EINVAL;
263 }
264
265 return 0;
266}
267
268/**
269 * imx_dma_setup_handlers - setup i.MX DMA channel end and error notification handlers
270 * @dma_ch: i.MX DMA channel number
271 * @irq_handler: the pointer to the function called if the transfer
272 * ends successfully
273 * @err_handler: the pointer to the function called if the premature
274 * end caused by error occurs
275 * @data: user specified value to be passed to the handlers
276 */
277int
278imx_dma_setup_handlers(imx_dmach_t dma_ch,
279 void (*irq_handler) (int, void *, struct pt_regs *),
280 void (*err_handler) (int, void *, struct pt_regs *),
281 void *data)
282{
283 struct imx_dma_channel *imxdma = &imx_dma_channels[dma_ch];
284 unsigned long flags;
285
286 if (!imxdma->name) {
287 printk(KERN_CRIT "%s: called for not allocated channel %d\n",
288 __FUNCTION__, dma_ch);
289 return -ENODEV;
290 }
291
292 local_irq_save(flags);
293 DISR = (1 << dma_ch);
294 imxdma->irq_handler = irq_handler;
295 imxdma->err_handler = err_handler;
296 imxdma->data = data;
297 local_irq_restore(flags);
298 return 0;
299}
300
301/**
302 * imx_dma_enable - function to start i.MX DMA channel operation
303 * @dma_ch: i.MX DMA channel number
304 *
305 * The channel has to be allocated by driver through imx_dma_request()
306 * or imx_dma_request_by_prio() function.
307 * The transfer parameters has to be set to the channel registers through
308 * call of the imx_dma_setup_single() or imx_dma_setup_sg() function
309 * and registers %BLR(dma_ch), %RSSR(dma_ch) and %CCR(dma_ch) has to
310 * be set prior this function call by the channel user.
311 */
312void imx_dma_enable(imx_dmach_t dma_ch)
313{
314 struct imx_dma_channel *imxdma = &imx_dma_channels[dma_ch];
315 unsigned long flags;
316
317 pr_debug("imxdma%d: imx_dma_enable\n", dma_ch);
318
319 if (!imxdma->name) {
320 printk(KERN_CRIT "%s: called for not allocated channel %d\n",
321 __FUNCTION__, dma_ch);
322 return;
323 }
324
325 local_irq_save(flags);
326 DISR = (1 << dma_ch);
327 DIMR &= ~(1 << dma_ch);
328 CCR(dma_ch) |= CCR_CEN;
329 local_irq_restore(flags);
330}
331
332/**
333 * imx_dma_disable - stop, finish i.MX DMA channel operatin
334 * @dma_ch: i.MX DMA channel number
335 */
336void imx_dma_disable(imx_dmach_t dma_ch)
337{
338 unsigned long flags;
339
340 pr_debug("imxdma%d: imx_dma_disable\n", dma_ch);
341
342 local_irq_save(flags);
343 DIMR |= (1 << dma_ch);
344 CCR(dma_ch) &= ~CCR_CEN;
345 DISR = (1 << dma_ch);
346 local_irq_restore(flags);
347}
348
349/**
350 * imx_dma_request - request/allocate specified channel number
351 * @dma_ch: i.MX DMA channel number
352 * @name: the driver/caller own non-%NULL identification
353 */
354int imx_dma_request(imx_dmach_t dma_ch, const char *name)
355{
356 struct imx_dma_channel *imxdma = &imx_dma_channels[dma_ch];
357 unsigned long flags;
358
359 /* basic sanity checks */
360 if (!name)
361 return -EINVAL;
362
363 if (dma_ch >= IMX_DMA_CHANNELS) {
364 printk(KERN_CRIT "%s: called for non-existed channel %d\n",
365 __FUNCTION__, dma_ch);
366 return -EINVAL;
76 } 367 }
77 368
369 local_irq_save(flags);
370 if (imxdma->name) {
371 local_irq_restore(flags);
372 return -ENODEV;
373 }
374
375 imxdma->name = name;
376 imxdma->irq_handler = NULL;
377 imxdma->err_handler = NULL;
378 imxdma->data = NULL;
379 imxdma->sg = NULL;
78 local_irq_restore(flags); 380 local_irq_restore(flags);
79 return i; 381 return 0;
80} 382}
81 383
82void 384/**
83imx_free_dma(int dma_ch) 385 * imx_dma_free - release previously acquired channel
386 * @dma_ch: i.MX DMA channel number
387 */
388void imx_dma_free(imx_dmach_t dma_ch)
84{ 389{
85 unsigned long flags; 390 unsigned long flags;
391 struct imx_dma_channel *imxdma = &imx_dma_channels[dma_ch];
86 392
87 if (!dma_channels[dma_ch].name) { 393 if (!imxdma->name) {
88 printk(KERN_CRIT 394 printk(KERN_CRIT
89 "%s: trying to free channel %d which is already freed\n", 395 "%s: trying to free channel %d which is already freed\n",
90 __FUNCTION__, dma_ch); 396 __FUNCTION__, dma_ch);
@@ -92,27 +398,84 @@ imx_free_dma(int dma_ch)
92 } 398 }
93 399
94 local_irq_save(flags); 400 local_irq_save(flags);
95 DIMR &= ~(1 << dma_ch); 401 /* Disable interrupts */
96 dma_channels[dma_ch].name = NULL; 402 DIMR |= (1 << dma_ch);
403 CCR(dma_ch) &= ~CCR_CEN;
404 imxdma->name = NULL;
97 local_irq_restore(flags); 405 local_irq_restore(flags);
98} 406}
99 407
100static irqreturn_t 408/**
101dma_err_handler(int irq, void *dev_id, struct pt_regs *regs) 409 * imx_dma_request_by_prio - find and request some of free channels best suiting requested priority
410 * @dma_ch: i.MX DMA channel number
411 * @name: the driver/caller own non-%NULL identification
412 * @prio: one of the hardware distinguished priority level:
413 * %DMA_PRIO_HIGH, %DMA_PRIO_MEDIUM, %DMA_PRIO_LOW
414 *
415 * This function tries to find free channel in the specified priority group
416 * if the priority cannot be achieved it tries to look for free channel
417 * in the higher and then even lower priority groups.
418 *
419 * Return value: If there is no free channel to allocate, -%ENODEV is returned.
420 * Zero value indicates successful channel allocation.
421 */
422int
423imx_dma_request_by_prio(imx_dmach_t * pdma_ch, const char *name,
424 imx_dma_prio prio)
425{
426 int i;
427 int best;
428
429 switch (prio) {
430 case (DMA_PRIO_HIGH):
431 best = 8;
432 break;
433 case (DMA_PRIO_MEDIUM):
434 best = 4;
435 break;
436 case (DMA_PRIO_LOW):
437 default:
438 best = 0;
439 break;
440 }
441
442 for (i = best; i < IMX_DMA_CHANNELS; i++) {
443 if (!imx_dma_request(i, name)) {
444 *pdma_ch = i;
445 return 0;
446 }
447 }
448
449 for (i = best - 1; i >= 0; i--) {
450 if (!imx_dma_request(i, name)) {
451 *pdma_ch = i;
452 return 0;
453 }
454 }
455
456 printk(KERN_ERR "%s: no free DMA channel found\n", __FUNCTION__);
457
458 return -ENODEV;
459}
460
461static irqreturn_t dma_err_handler(int irq, void *dev_id, struct pt_regs *regs)
102{ 462{
103 int i, disr = DISR; 463 int i, disr = DISR;
104 struct dma_channel *channel; 464 struct imx_dma_channel *channel;
105 unsigned int err_mask = DBTOSR | DRTOSR | DSESR | DBOSR; 465 unsigned int err_mask = DBTOSR | DRTOSR | DSESR | DBOSR;
106 466
107 DISR = disr; 467 DISR = disr;
108 for (i = 0; i < 11; i++) { 468 for (i = 0; i < IMX_DMA_CHANNELS; i++) {
109 channel = &dma_channels[i]; 469 channel = &imx_dma_channels[i];
110 470
111 if ( (err_mask & 1<<i) && channel->name && channel->err_handler) { 471 if ((err_mask & 1 << i) && channel->name
472 && channel->err_handler) {
112 channel->err_handler(i, channel->data, regs); 473 channel->err_handler(i, channel->data, regs);
113 continue; 474 continue;
114 } 475 }
115 476
477 imx_dma_channels[i].sg = NULL;
478
116 if (DBTOSR & (1 << i)) { 479 if (DBTOSR & (1 << i)) {
117 printk(KERN_WARNING 480 printk(KERN_WARNING
118 "Burst timeout on channel %d (%s)\n", 481 "Burst timeout on channel %d (%s)\n",
@@ -141,17 +504,27 @@ dma_err_handler(int irq, void *dev_id, struct pt_regs *regs)
141 return IRQ_HANDLED; 504 return IRQ_HANDLED;
142} 505}
143 506
144static irqreturn_t 507static irqreturn_t dma_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
145dma_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
146{ 508{
147 int i, disr = DISR; 509 int i, disr = DISR;
148 510
511 pr_debug("imxdma: dma_irq_handler called, disr=0x%08x\n",
512 disr);
513
149 DISR = disr; 514 DISR = disr;
150 for (i = 0; i < 11; i++) { 515 for (i = 0; i < IMX_DMA_CHANNELS; i++) {
151 if (disr & (1 << i)) { 516 if (disr & (1 << i)) {
152 struct dma_channel *channel = &dma_channels[i]; 517 struct imx_dma_channel *channel = &imx_dma_channels[i];
153 if (channel->name && channel->irq_handler) { 518 if (channel->name) {
154 channel->irq_handler(i, channel->data, regs); 519 if (imx_dma_sg_next(i, CNTR(i))) {
520 CCR(i) &= ~CCR_CEN;
521 mb();
522 CCR(i) |= CCR_CEN;
523 } else {
524 if (channel->irq_handler)
525 channel->irq_handler(i,
526 channel->data, regs);
527 }
155 } else { 528 } else {
156 /* 529 /*
157 * IRQ for an unregistered DMA channel: 530 * IRQ for an unregistered DMA channel:
@@ -165,10 +538,10 @@ dma_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
165 return IRQ_HANDLED; 538 return IRQ_HANDLED;
166} 539}
167 540
168static int __init 541static int __init imx_dma_init(void)
169imx_dma_init(void)
170{ 542{
171 int ret; 543 int ret;
544 int i;
172 545
173 /* reset DMA module */ 546 /* reset DMA module */
174 DCR = DCR_DRST; 547 DCR = DCR_DRST;
@@ -189,15 +562,27 @@ imx_dma_init(void)
189 DCR = DCR_DEN; 562 DCR = DCR_DEN;
190 563
191 /* clear all interrupts */ 564 /* clear all interrupts */
192 DISR = 0x3ff; 565 DISR = (1 << IMX_DMA_CHANNELS) - 1;
193 566
194 /* enable interrupts */ 567 /* enable interrupts */
195 DIMR = 0; 568 DIMR = (1 << IMX_DMA_CHANNELS) - 1;
569
570 for (i = 0; i < IMX_DMA_CHANNELS; i++) {
571 imx_dma_channels[i].sg = NULL;
572 imx_dma_channels[i].dma_num = i;
573 }
196 574
197 return ret; 575 return ret;
198} 576}
199 577
200arch_initcall(imx_dma_init); 578arch_initcall(imx_dma_init);
201 579
202EXPORT_SYMBOL(imx_request_dma); 580EXPORT_SYMBOL(imx_dma_setup_single);
203EXPORT_SYMBOL(imx_free_dma); 581EXPORT_SYMBOL(imx_dma_setup_sg);
582EXPORT_SYMBOL(imx_dma_setup_handlers);
583EXPORT_SYMBOL(imx_dma_enable);
584EXPORT_SYMBOL(imx_dma_disable);
585EXPORT_SYMBOL(imx_dma_request);
586EXPORT_SYMBOL(imx_dma_free);
587EXPORT_SYMBOL(imx_dma_request_by_prio);
588EXPORT_SYMBOL(imx_dma_channels);