[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / arm / mach-imx / dma.c
blob71a59e196166cc00c4d9d31821f1f1aa3a16f44c
1 /*
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>
22 #include <asm/irq.h>
23 #include <asm/hardware.h>
24 #include <asm/dma.h>
26 static struct dma_channel {
27 char *name;
28 void (*irq_handler) (int, void *, struct pt_regs *);
29 void (*err_handler) (int, void *, struct pt_regs *);
30 void *data;
31 } dma_channels[11];
33 /* set err_handler to NULL to have the standard info-only error handler */
34 int
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)
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 + (prio == DMA_PRIO_LOW) ? 8 : 4; 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 DIMR &= ~(1 << i);
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;
72 } else {
73 printk(KERN_WARNING "No more available DMA channels for %s\n",
74 name);
75 i = -ENODEV;
78 local_irq_restore(flags);
79 return i;
82 void
83 imx_free_dma(int dma_ch)
85 unsigned long flags;
87 if (!dma_channels[dma_ch].name) {
88 printk(KERN_CRIT
89 "%s: trying to free channel %d which is already freed\n",
90 __FUNCTION__, dma_ch);
91 return;
94 local_irq_save(flags);
95 DIMR &= ~(1 << dma_ch);
96 dma_channels[dma_ch].name = NULL;
97 local_irq_restore(flags);
100 static irqreturn_t
101 dma_err_handler(int irq, void *dev_id, struct pt_regs *regs)
103 int i, disr = DISR;
104 struct dma_channel *channel;
105 unsigned int err_mask = DBTOSR | DRTOSR | DSESR | DBOSR;
107 DISR = disr;
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);
113 continue;
116 if (DBTOSR & (1 << i)) {
117 printk(KERN_WARNING
118 "Burst timeout on channel %d (%s)\n",
119 i, channel->name);
120 DBTOSR |= (1 << i);
122 if (DRTOSR & (1 << i)) {
123 printk(KERN_WARNING
124 "Request timeout on channel %d (%s)\n",
125 i, channel->name);
126 DRTOSR |= (1 << i);
128 if (DSESR & (1 << i)) {
129 printk(KERN_WARNING
130 "Transfer timeout on channel %d (%s)\n",
131 i, channel->name);
132 DSESR |= (1 << i);
134 if (DBOSR & (1 << i)) {
135 printk(KERN_WARNING
136 "Buffer overflow timeout on channel %d (%s)\n",
137 i, channel->name);
138 DBOSR |= (1 << i);
141 return IRQ_HANDLED;
144 static irqreturn_t
145 dma_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
147 int i, disr = DISR;
149 DISR = disr;
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);
155 } else {
157 * IRQ for an unregistered DMA channel:
158 * let's clear the interrupts and disable it.
160 printk(KERN_WARNING
161 "spurious IRQ for DMA channel %d\n", i);
165 return IRQ_HANDLED;
168 static int __init
169 imx_dma_init(void)
171 int ret;
173 /* reset DMA module */
174 DCR = DCR_DRST;
176 ret = request_irq(DMA_INT, dma_irq_handler, 0, "DMA", NULL);
177 if (ret) {
178 printk(KERN_CRIT "Wow! Can't register IRQ for DMA\n");
179 return ret;
182 ret = request_irq(DMA_ERR, dma_err_handler, 0, "DMA", NULL);
183 if (ret) {
184 printk(KERN_CRIT "Wow! Can't register ERRIRQ for DMA\n");
185 free_irq(DMA_INT, NULL);
188 /* enable DMA module */
189 DCR = DCR_DEN;
191 /* clear all interrupts */
192 DISR = 0x3ff;
194 /* enable interrupts */
195 DIMR = 0;
197 return ret;
200 arch_initcall(imx_dma_init);
202 EXPORT_SYMBOL(imx_request_dma);
203 EXPORT_SYMBOL(imx_free_dma);