allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / arch / arm / mach-pxa / dma.c
blob4440babe7b97595dabe3330082ffd8aad9b6d674
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 *);
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 *),
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 do {
49 /* try grabbing a DMA channel with the requested priority */
50 pxa_for_each_dma_prio (i, prio) {
51 if (!dma_channels[i].name) {
52 found = 1;
53 break;
56 /* if requested prio group is full, try a hier priority */
57 } while (!found && prio--);
59 if (found) {
60 DCSR(i) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
61 dma_channels[i].name = name;
62 dma_channels[i].irq_handler = irq_handler;
63 dma_channels[i].data = data;
64 } else {
65 printk (KERN_WARNING "No more available DMA channels for %s\n", name);
66 i = -ENODEV;
69 local_irq_restore(flags);
70 return i;
73 void pxa_free_dma (int dma_ch)
75 unsigned long flags;
77 if (!dma_channels[dma_ch].name) {
78 printk (KERN_CRIT
79 "%s: trying to free channel %d which is already freed\n",
80 __FUNCTION__, dma_ch);
81 return;
84 local_irq_save(flags);
85 DCSR(dma_ch) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
86 dma_channels[dma_ch].name = NULL;
87 local_irq_restore(flags);
90 static irqreturn_t dma_irq_handler(int irq, void *dev_id)
92 int i, dint = DINT;
94 for (i = 0; i < PXA_DMA_CHANNELS; i++) {
95 if (dint & (1 << i)) {
96 struct dma_channel *channel = &dma_channels[i];
97 if (channel->name && channel->irq_handler) {
98 channel->irq_handler(i, channel->data);
99 } else {
101 * IRQ for an unregistered DMA channel:
102 * let's clear the interrupts and disable it.
104 printk (KERN_WARNING "spurious IRQ for DMA channel %d\n", i);
105 DCSR(i) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
109 return IRQ_HANDLED;
112 static int __init pxa_dma_init (void)
114 int ret;
116 ret = request_irq (IRQ_DMA, dma_irq_handler, 0, "DMA", NULL);
117 if (ret)
118 printk (KERN_CRIT "Wow! Can't register IRQ for DMA\n");
119 return ret;
122 arch_initcall(pxa_dma_init);
124 EXPORT_SYMBOL(pxa_request_dma);
125 EXPORT_SYMBOL(pxa_free_dma);