2 * linux/arch/arm/kernel/dma.c
4 * Copyright (C) 1995-2000 Russell King
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 * Front-end to the DMA handling. This handles the allocation/freeing
11 * of DMA channels, and provides a unified interface to the machines
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/spinlock.h>
17 #include <linux/errno.h>
21 #include <asm/mach/dma.h>
23 DEFINE_SPINLOCK(dma_spin_lock);
24 EXPORT_SYMBOL(dma_spin_lock);
26 static dma_t dma_chan[MAX_DMA_CHANNELS];
31 * On certain platforms, we have to allocate an interrupt as well...
33 int request_dma(dmach_t channel, const char *device_id)
35 dma_t *dma = dma_chan + channel;
38 if (channel >= MAX_DMA_CHANNELS || !dma->d_ops)
41 if (xchg(&dma->lock, 1) != 0)
44 dma->device_id = device_id;
49 if (dma->d_ops->request)
50 ret = dma->d_ops->request(channel, dma);
58 printk(KERN_ERR "dma: trying to allocate DMA%d\n", channel);
64 EXPORT_SYMBOL(request_dma);
69 * On certain platforms, we have to free interrupt as well...
71 void free_dma(dmach_t channel)
73 dma_t *dma = dma_chan + channel;
75 if (channel >= MAX_DMA_CHANNELS || !dma->d_ops)
79 printk(KERN_ERR "dma%d: freeing active DMA\n", channel);
80 dma->d_ops->disable(channel, dma);
84 if (xchg(&dma->lock, 0) != 0) {
86 dma->d_ops->free(channel, dma);
90 printk(KERN_ERR "dma%d: trying to free free DMA\n", channel);
94 printk(KERN_ERR "dma: trying to free DMA%d\n", channel);
96 EXPORT_SYMBOL(free_dma);
98 /* Set DMA Scatter-Gather list
100 void set_dma_sg (dmach_t channel, struct scatterlist *sg, int nr_sg)
102 dma_t *dma = dma_chan + channel;
105 printk(KERN_ERR "dma%d: altering DMA SG while "
106 "DMA active\n", channel);
109 dma->sgcount = nr_sg;
112 EXPORT_SYMBOL(set_dma_sg);
116 * Copy address to the structure, and set the invalid bit
118 void __set_dma_addr (dmach_t channel, void *addr)
120 dma_t *dma = dma_chan + channel;
123 printk(KERN_ERR "dma%d: altering DMA address while "
124 "DMA active\n", channel);
130 EXPORT_SYMBOL(__set_dma_addr);
132 /* Set DMA byte count
134 * Copy address to the structure, and set the invalid bit
136 void set_dma_count (dmach_t channel, unsigned long count)
138 dma_t *dma = dma_chan + channel;
141 printk(KERN_ERR "dma%d: altering DMA count while "
142 "DMA active\n", channel);
148 EXPORT_SYMBOL(set_dma_count);
150 /* Set DMA direction mode
152 void set_dma_mode (dmach_t channel, dmamode_t mode)
154 dma_t *dma = dma_chan + channel;
157 printk(KERN_ERR "dma%d: altering DMA mode while "
158 "DMA active\n", channel);
160 dma->dma_mode = mode;
163 EXPORT_SYMBOL(set_dma_mode);
165 /* Enable DMA channel
167 void enable_dma (dmach_t channel)
169 dma_t *dma = dma_chan + channel;
174 if (dma->active == 0) {
176 dma->d_ops->enable(channel, dma);
181 printk(KERN_ERR "dma%d: trying to enable free DMA\n", channel);
184 EXPORT_SYMBOL(enable_dma);
186 /* Disable DMA channel
188 void disable_dma (dmach_t channel)
190 dma_t *dma = dma_chan + channel;
195 if (dma->active == 1) {
197 dma->d_ops->disable(channel, dma);
202 printk(KERN_ERR "dma%d: trying to disable free DMA\n", channel);
205 EXPORT_SYMBOL(disable_dma);
208 * Is the specified DMA channel active?
210 int dma_channel_active(dmach_t channel)
212 return dma_chan[channel].active;
214 EXPORT_SYMBOL(dma_channel_active);
216 void set_dma_page(dmach_t channel, char pagenr)
218 printk(KERN_ERR "dma%d: trying to set_dma_page\n", channel);
220 EXPORT_SYMBOL(set_dma_page);
222 void set_dma_speed(dmach_t channel, int cycle_ns)
224 dma_t *dma = dma_chan + channel;
227 if (dma->d_ops->setspeed)
228 ret = dma->d_ops->setspeed(channel, dma, cycle_ns);
231 EXPORT_SYMBOL(set_dma_speed);
233 int get_dma_residue(dmach_t channel)
235 dma_t *dma = dma_chan + channel;
238 if (dma->d_ops->residue)
239 ret = dma->d_ops->residue(channel, dma);
243 EXPORT_SYMBOL(get_dma_residue);
245 static int __init init_dma(void)
247 arch_dma_init(dma_chan);
251 core_initcall(init_dma);