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>
27 static struct dma_channel {
29 void (*irq_handler)(int, void *, struct pt_regs *);
34 int pxa_request_dma (char *name, pxa_dma_prio prio,
35 void (*irq_handler)(int, void *, struct pt_regs *),
41 /* basic sanity checks */
42 if (!name || !irq_handler)
45 local_irq_save(flags);
47 /* try grabbing a DMA channel with the requested priority */
48 for (i = prio; i < prio + (prio == DMA_PRIO_LOW) ? 8 : 4; i++) {
49 if (!dma_channels[i].name) {
56 /* requested prio group is full, try hier priorities */
57 for (i = prio-1; i >= 0; i--) {
58 if (!dma_channels[i].name) {
66 DCSR(i) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
67 dma_channels[i].name = name;
68 dma_channels[i].irq_handler = irq_handler;
69 dma_channels[i].data = data;
71 printk (KERN_WARNING "No more available DMA channels for %s\n", name);
75 local_irq_restore(flags);
79 void pxa_free_dma (int dma_ch)
83 if (!dma_channels[dma_ch].name) {
85 "%s: trying to free channel %d which is already freed\n",
86 __FUNCTION__, dma_ch);
90 local_irq_save(flags);
91 DCSR(dma_ch) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
92 dma_channels[dma_ch].name = NULL;
93 local_irq_restore(flags);
96 static irqreturn_t dma_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
100 for (i = 0; i < 16; i++) {
101 if (dint & (1 << i)) {
102 struct dma_channel *channel = &dma_channels[i];
103 if (channel->name && channel->irq_handler) {
104 channel->irq_handler(i, channel->data, regs);
107 * IRQ for an unregistered DMA channel:
108 * let's clear the interrupts and disable it.
110 printk (KERN_WARNING "spurious IRQ for DMA channel %d\n", i);
111 DCSR(i) = DCSR_STARTINTR|DCSR_ENDINTR|DCSR_BUSERR;
118 static int __init pxa_dma_init (void)
122 ret = request_irq (IRQ_DMA, dma_irq_handler, 0, "DMA", NULL);
124 printk (KERN_CRIT "Wow! Can't register IRQ for DMA\n");
128 arch_initcall(pxa_dma_init);
130 EXPORT_SYMBOL(pxa_request_dma);
131 EXPORT_SYMBOL(pxa_free_dma);