2 * linux/arch/arm/mach-imx/dma.c
4 * imx DMA registration and IRQ dispatching
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.
10 * 03/03/2004 Sascha Hauer <sascha@saschahauer.de>
11 * initial version heavily inspired by
12 * linux/arch/arm/mach-pxa/dma.c
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/kernel.h>
18 #include <linux/interrupt.h>
19 #include <linux/errno.h>
21 #include <asm/system.h>
23 #include <asm/hardware.h>
26 static struct dma_channel
{
28 void (*irq_handler
) (int, void *, struct pt_regs
*);
29 void (*err_handler
) (int, void *, struct pt_regs
*);
33 /* set err_handler to NULL to have the standard info-only error handler */
35 imx_request_dma(char *name
, imx_dma_prio prio
,
36 void (*irq_handler
) (int, void *, struct pt_regs
*),
37 void (*err_handler
) (int, void *, struct pt_regs
*), void *data
)
42 /* basic sanity checks */
43 if (!name
|| !irq_handler
)
46 local_irq_save(flags
);
48 /* try grabbing a DMA channel with the requested priority */
49 for (i
= prio
; i
< prio
+ (prio
== DMA_PRIO_LOW
) ? 8 : 4; i
++) {
50 if (!dma_channels
[i
].name
) {
57 /* requested prio group is full, try hier priorities */
58 for (i
= prio
- 1; i
>= 0; i
--) {
59 if (!dma_channels
[i
].name
) {
68 dma_channels
[i
].name
= name
;
69 dma_channels
[i
].irq_handler
= irq_handler
;
70 dma_channels
[i
].err_handler
= err_handler
;
71 dma_channels
[i
].data
= data
;
73 printk(KERN_WARNING
"No more available DMA channels for %s\n",
78 local_irq_restore(flags
);
83 imx_free_dma(int dma_ch
)
87 if (!dma_channels
[dma_ch
].name
) {
89 "%s: trying to free channel %d which is already freed\n",
90 __FUNCTION__
, dma_ch
);
94 local_irq_save(flags
);
95 DIMR
&= ~(1 << dma_ch
);
96 dma_channels
[dma_ch
].name
= NULL
;
97 local_irq_restore(flags
);
101 dma_err_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
104 struct dma_channel
*channel
;
105 unsigned int err_mask
= DBTOSR
| DRTOSR
| DSESR
| DBOSR
;
108 for (i
= 0; i
< 11; i
++) {
109 channel
= &dma_channels
[i
];
111 if ( (err_mask
& 1<<i
) && channel
->name
&& channel
->err_handler
) {
112 channel
->err_handler(i
, channel
->data
, regs
);
116 if (DBTOSR
& (1 << i
)) {
118 "Burst timeout on channel %d (%s)\n",
122 if (DRTOSR
& (1 << i
)) {
124 "Request timeout on channel %d (%s)\n",
128 if (DSESR
& (1 << i
)) {
130 "Transfer timeout on channel %d (%s)\n",
134 if (DBOSR
& (1 << i
)) {
136 "Buffer overflow timeout on channel %d (%s)\n",
145 dma_irq_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
150 for (i
= 0; i
< 11; i
++) {
151 if (disr
& (1 << i
)) {
152 struct dma_channel
*channel
= &dma_channels
[i
];
153 if (channel
->name
&& channel
->irq_handler
) {
154 channel
->irq_handler(i
, channel
->data
, regs
);
157 * IRQ for an unregistered DMA channel:
158 * let's clear the interrupts and disable it.
161 "spurious IRQ for DMA channel %d\n", i
);
173 /* reset DMA module */
176 ret
= request_irq(DMA_INT
, dma_irq_handler
, 0, "DMA", NULL
);
178 printk(KERN_CRIT
"Wow! Can't register IRQ for DMA\n");
182 ret
= request_irq(DMA_ERR
, dma_err_handler
, 0, "DMA", NULL
);
184 printk(KERN_CRIT
"Wow! Can't register ERRIRQ for DMA\n");
185 free_irq(DMA_INT
, NULL
);
188 /* enable DMA module */
191 /* clear all interrupts */
194 /* enable interrupts */
200 arch_initcall(imx_dma_init
);
202 EXPORT_SYMBOL(imx_request_dma
);
203 EXPORT_SYMBOL(imx_free_dma
);