2 * linux/arch/arm/mach-pxa/dma.c
4 * PXA DMA registration and IRQ dispatching
6 * Author: Nicolas Pitre
7 * Created: Nov 15, 2001
8 * Copyright: MontaVista Software Inc.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
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 #include <asm/arch/pxa-regs.h>
28 static struct dma_channel
{
30 void (*irq_handler
)(int, void *, struct pt_regs
*);
32 } dma_channels
[PXA_DMA_CHANNELS
];
35 int pxa_request_dma (char *name
, pxa_dma_prio prio
,
36 void (*irq_handler
)(int, void *, struct pt_regs
*),
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
+ PXA_DMA_NBCH(prio
); 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
) {
67 DCSR(i
) = DCSR_STARTINTR
|DCSR_ENDINTR
|DCSR_BUSERR
;
68 dma_channels
[i
].name
= name
;
69 dma_channels
[i
].irq_handler
= irq_handler
;
70 dma_channels
[i
].data
= data
;
72 printk (KERN_WARNING
"No more available DMA channels for %s\n", name
);
76 local_irq_restore(flags
);
80 void pxa_free_dma (int dma_ch
)
84 if (!dma_channels
[dma_ch
].name
) {
86 "%s: trying to free channel %d which is already freed\n",
87 __FUNCTION__
, dma_ch
);
91 local_irq_save(flags
);
92 DCSR(dma_ch
) = DCSR_STARTINTR
|DCSR_ENDINTR
|DCSR_BUSERR
;
93 dma_channels
[dma_ch
].name
= NULL
;
94 local_irq_restore(flags
);
97 static irqreturn_t
dma_irq_handler(int irq
, void *dev_id
, struct pt_regs
*regs
)
101 for (i
= 0; i
< PXA_DMA_CHANNELS
; i
++) {
102 if (dint
& (1 << i
)) {
103 struct dma_channel
*channel
= &dma_channels
[i
];
104 if (channel
->name
&& channel
->irq_handler
) {
105 channel
->irq_handler(i
, channel
->data
, regs
);
108 * IRQ for an unregistered DMA channel:
109 * let's clear the interrupts and disable it.
111 printk (KERN_WARNING
"spurious IRQ for DMA channel %d\n", i
);
112 DCSR(i
) = DCSR_STARTINTR
|DCSR_ENDINTR
|DCSR_BUSERR
;
119 static int __init
pxa_dma_init (void)
123 ret
= request_irq (IRQ_DMA
, dma_irq_handler
, 0, "DMA", NULL
);
125 printk (KERN_CRIT
"Wow! Can't register IRQ for DMA\n");
129 arch_initcall(pxa_dma_init
);
131 EXPORT_SYMBOL(pxa_request_dma
);
132 EXPORT_SYMBOL(pxa_free_dma
);