[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / arm / mach-pxa / dma.c
blob458112b21e25df5008783edab1d288d51e338dd5
1 /*
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>
22 #include <asm/irq.h>
23 #include <asm/hardware.h>
24 #include <asm/dma.h>
26 #include <asm/arch/pxa-regs.h>
28 static struct dma_channel {
29 char *name;
30 void (*irq_handler)(int, void *, struct pt_regs *);
31 void *data;
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 *),
37 void *data)
39 unsigned long flags;
40 int i, found = 0;
42 /* basic sanity checks */
43 if (!name || !irq_handler)
44 return -EINVAL;
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) {
51 found = 1;
52 break;
56 if (!found) {
57 /* requested prio group is full, try hier priorities */
58 for (i = prio-1; i >= 0; i--) {
59 if (!dma_channels[i].name) {
60 found = 1;
61 break;
66 if (found) {
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;
71 } else {
72 printk (KERN_WARNING "No more available DMA channels for %s\n", name);
73 i = -ENODEV;
76 local_irq_restore(flags);
77 return i;
80 void pxa_free_dma (int dma_ch)
82 unsigned long flags;
84 if (!dma_channels[dma_ch].name) {
85 printk (KERN_CRIT
86 "%s: trying to free channel %d which is already freed\n",
87 __FUNCTION__, dma_ch);
88 return;
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)
99 int i, dint = DINT;
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);
106 } else {
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;
116 return IRQ_HANDLED;
119 static int __init pxa_dma_init (void)
121 int ret;
123 ret = request_irq (IRQ_DMA, dma_irq_handler, 0, "DMA", NULL);
124 if (ret)
125 printk (KERN_CRIT "Wow! Can't register IRQ for DMA\n");
126 return ret;
129 arch_initcall(pxa_dma_init);
131 EXPORT_SYMBOL(pxa_request_dma);
132 EXPORT_SYMBOL(pxa_free_dma);