Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / arm / mach-pxa / dma.c
blob2228da0e3ba5f561864602d8601abfb4f226cd14
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 struct dma_channel {
29 char *name;
30 pxa_dma_prio prio;
31 void (*irq_handler)(int, void *);
32 void *data;
35 static struct dma_channel *dma_channels;
36 static int num_dma_channels;
38 int pxa_request_dma (char *name, pxa_dma_prio prio,
39 void (*irq_handler)(int, void *),
40 void *data)
42 unsigned long flags;
43 int i, found = 0;
45 /* basic sanity checks */
46 if (!name || !irq_handler)
47 return -EINVAL;
49 local_irq_save(flags);
51 do {
52 /* try grabbing a DMA channel with the requested priority */
53 for (i = 0; i < num_dma_channels; i++) {
54 if ((dma_channels[i].prio == prio) &&
55 !dma_channels[i].name) {
56 found = 1;
57 break;
60 /* if requested prio group is full, try a hier priority */
61 } while (!found && prio--);
63 if (found) {
64 DCSR(i) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
65 dma_channels[i].name = name;
66 dma_channels[i].irq_handler = irq_handler;
67 dma_channels[i].data = data;
68 } else {
69 printk (KERN_WARNING "No more available DMA channels for %s\n", name);
70 i = -ENODEV;
73 local_irq_restore(flags);
74 return i;
77 void pxa_free_dma (int dma_ch)
79 unsigned long flags;
81 if (!dma_channels[dma_ch].name) {
82 printk (KERN_CRIT
83 "%s: trying to free channel %d which is already freed\n",
84 <<<<<<< HEAD:arch/arm/mach-pxa/dma.c
85 __FUNCTION__, dma_ch);
86 =======
87 __func__, dma_ch);
88 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/arm/mach-pxa/dma.c
89 return;
92 local_irq_save(flags);
93 DCSR(dma_ch) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
94 dma_channels[dma_ch].name = NULL;
95 local_irq_restore(flags);
98 static irqreturn_t dma_irq_handler(int irq, void *dev_id)
100 int i, dint = DINT;
102 for (i = 0; i < num_dma_channels; i++) {
103 if (dint & (1 << i)) {
104 struct dma_channel *channel = &dma_channels[i];
105 if (channel->name && channel->irq_handler) {
106 channel->irq_handler(i, channel->data);
107 } else {
109 * IRQ for an unregistered DMA channel:
110 * let's clear the interrupts and disable it.
112 printk (KERN_WARNING "spurious IRQ for DMA channel %d\n", i);
113 DCSR(i) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
117 return IRQ_HANDLED;
120 int __init pxa_init_dma(int num_ch)
122 int i, ret;
124 dma_channels = kzalloc(sizeof(struct dma_channel) * num_ch, GFP_KERNEL);
125 if (dma_channels == NULL)
126 return -ENOMEM;
128 ret = request_irq(IRQ_DMA, dma_irq_handler, IRQF_DISABLED, "DMA", NULL);
129 if (ret) {
130 printk (KERN_CRIT "Wow! Can't register IRQ for DMA\n");
131 kfree(dma_channels);
132 return ret;
135 /* dma channel priorities on pxa2xx processors:
136 * ch 0 - 3, 16 - 19 <--> (0) DMA_PRIO_HIGH
137 * ch 4 - 7, 20 - 23 <--> (1) DMA_PRIO_MEDIUM
138 * ch 8 - 15, 24 - 31 <--> (2) DMA_PRIO_LOW
140 for (i = 0; i < num_ch; i++)
141 dma_channels[i].prio = min((i & 0xf) >> 2, DMA_PRIO_LOW);
143 num_dma_channels = num_ch;
144 return 0;
147 EXPORT_SYMBOL(pxa_request_dma);
148 EXPORT_SYMBOL(pxa_free_dma);