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>
26 #include <asm/arch/pxa-regs.h>
28 static struct dma_channel {
30 void (*irq_handler)(int, void *);
32 } dma_channels[PXA_DMA_CHANNELS];
35 int pxa_request_dma (char *name, pxa_dma_prio prio,
36 void (*irq_handler)(int, void *),
42 /* basic sanity checks */
43 if (!name || !irq_handler)
46 local_irq_save(flags);
49 /* try grabbing a DMA channel with the requested priority */
50 pxa_for_each_dma_prio (i, prio) {
51 if (!dma_channels[i].name) {
56 /* if requested prio group is full, try a hier priority */
57 } while (!found && prio--);
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;
65 printk (KERN_WARNING "No more available DMA channels for %s\n", name);
69 local_irq_restore(flags);
73 void pxa_free_dma (int dma_ch)
77 if (!dma_channels[dma_ch].name) {
79 "%s: trying to free channel %d which is already freed\n",
80 __FUNCTION__, dma_ch);
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)
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);
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;
112 static int __init pxa_dma_init (void)
116 ret = request_irq (IRQ_DMA, dma_irq_handler, 0, "DMA", NULL);
118 printk (KERN_CRIT "Wow! Can't register IRQ for DMA\n");
122 arch_initcall(pxa_dma_init);
124 EXPORT_SYMBOL(pxa_request_dma);
125 EXPORT_SYMBOL(pxa_free_dma);