GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / arm / kernel / dma.c
blob2c4a185f92cdc45d2f7b9eab720d46fc9dfe62f4
1 /*
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
12 * DMA facilities.
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/spinlock.h>
17 #include <linux/errno.h>
18 #include <linux/scatterlist.h>
19 #include <linux/seq_file.h>
20 #include <linux/proc_fs.h>
22 #include <asm/dma.h>
24 #include <asm/mach/dma.h>
26 DEFINE_SPINLOCK(dma_spin_lock);
27 EXPORT_SYMBOL(dma_spin_lock);
29 static dma_t *dma_chan[MAX_DMA_CHANNELS];
31 static inline dma_t *dma_channel(unsigned int chan)
33 if (chan >= MAX_DMA_CHANNELS)
34 return NULL;
36 return dma_chan[chan];
39 int __init isa_dma_add(unsigned int chan, dma_t *dma)
41 if (!dma->d_ops)
42 return -EINVAL;
44 sg_init_table(&dma->buf, 1);
46 if (dma_chan[chan])
47 return -EBUSY;
48 dma_chan[chan] = dma;
49 return 0;
53 * Request DMA channel
55 * On certain platforms, we have to allocate an interrupt as well...
57 int request_dma(unsigned int chan, const char *device_id)
59 dma_t *dma = dma_channel(chan);
60 int ret;
62 if (!dma)
63 goto bad_dma;
65 if (xchg(&dma->lock, 1) != 0)
66 goto busy;
68 dma->device_id = device_id;
69 dma->active = 0;
70 dma->invalid = 1;
72 ret = 0;
73 if (dma->d_ops->request)
74 ret = dma->d_ops->request(chan, dma);
76 if (ret)
77 xchg(&dma->lock, 0);
79 return ret;
81 bad_dma:
82 printk(KERN_ERR "dma: trying to allocate DMA%d\n", chan);
83 return -EINVAL;
85 busy:
86 return -EBUSY;
88 EXPORT_SYMBOL(request_dma);
91 * Free DMA channel
93 * On certain platforms, we have to free interrupt as well...
95 void free_dma(unsigned int chan)
97 dma_t *dma = dma_channel(chan);
99 if (!dma)
100 goto bad_dma;
102 if (dma->active) {
103 printk(KERN_ERR "dma%d: freeing active DMA\n", chan);
104 dma->d_ops->disable(chan, dma);
105 dma->active = 0;
108 if (xchg(&dma->lock, 0) != 0) {
109 if (dma->d_ops->free)
110 dma->d_ops->free(chan, dma);
111 return;
114 printk(KERN_ERR "dma%d: trying to free free DMA\n", chan);
115 return;
117 bad_dma:
118 printk(KERN_ERR "dma: trying to free DMA%d\n", chan);
120 EXPORT_SYMBOL(free_dma);
122 /* Set DMA Scatter-Gather list
124 void set_dma_sg (unsigned int chan, struct scatterlist *sg, int nr_sg)
126 dma_t *dma = dma_channel(chan);
128 if (dma->active)
129 printk(KERN_ERR "dma%d: altering DMA SG while "
130 "DMA active\n", chan);
132 dma->sg = sg;
133 dma->sgcount = nr_sg;
134 dma->invalid = 1;
136 EXPORT_SYMBOL(set_dma_sg);
138 /* Set DMA address
140 * Copy address to the structure, and set the invalid bit
142 void __set_dma_addr (unsigned int chan, void *addr)
144 dma_t *dma = dma_channel(chan);
146 if (dma->active)
147 printk(KERN_ERR "dma%d: altering DMA address while "
148 "DMA active\n", chan);
150 dma->sg = NULL;
151 dma->addr = addr;
152 dma->invalid = 1;
154 EXPORT_SYMBOL(__set_dma_addr);
156 /* Set DMA byte count
158 * Copy address to the structure, and set the invalid bit
160 void set_dma_count (unsigned int chan, unsigned long count)
162 dma_t *dma = dma_channel(chan);
164 if (dma->active)
165 printk(KERN_ERR "dma%d: altering DMA count while "
166 "DMA active\n", chan);
168 dma->sg = NULL;
169 dma->count = count;
170 dma->invalid = 1;
172 EXPORT_SYMBOL(set_dma_count);
174 /* Set DMA direction mode
176 void set_dma_mode (unsigned int chan, unsigned int mode)
178 dma_t *dma = dma_channel(chan);
180 if (dma->active)
181 printk(KERN_ERR "dma%d: altering DMA mode while "
182 "DMA active\n", chan);
184 dma->dma_mode = mode;
185 dma->invalid = 1;
187 EXPORT_SYMBOL(set_dma_mode);
189 /* Enable DMA channel
191 void enable_dma (unsigned int chan)
193 dma_t *dma = dma_channel(chan);
195 if (!dma->lock)
196 goto free_dma;
198 if (dma->active == 0) {
199 dma->active = 1;
200 dma->d_ops->enable(chan, dma);
202 return;
204 free_dma:
205 printk(KERN_ERR "dma%d: trying to enable free DMA\n", chan);
206 BUG();
208 EXPORT_SYMBOL(enable_dma);
210 /* Disable DMA channel
212 void disable_dma (unsigned int chan)
214 dma_t *dma = dma_channel(chan);
216 if (!dma->lock)
217 goto free_dma;
219 if (dma->active == 1) {
220 dma->active = 0;
221 dma->d_ops->disable(chan, dma);
223 return;
225 free_dma:
226 printk(KERN_ERR "dma%d: trying to disable free DMA\n", chan);
227 BUG();
229 EXPORT_SYMBOL(disable_dma);
232 * Is the specified DMA channel active?
234 int dma_channel_active(unsigned int chan)
236 dma_t *dma = dma_channel(chan);
237 return dma->active;
239 EXPORT_SYMBOL(dma_channel_active);
241 void set_dma_page(unsigned int chan, char pagenr)
243 printk(KERN_ERR "dma%d: trying to set_dma_page\n", chan);
245 EXPORT_SYMBOL(set_dma_page);
247 void set_dma_speed(unsigned int chan, int cycle_ns)
249 dma_t *dma = dma_channel(chan);
250 int ret = 0;
252 if (dma->d_ops->setspeed)
253 ret = dma->d_ops->setspeed(chan, dma, cycle_ns);
254 dma->speed = ret;
256 EXPORT_SYMBOL(set_dma_speed);
258 int get_dma_residue(unsigned int chan)
260 dma_t *dma = dma_channel(chan);
261 int ret = 0;
263 if (dma->d_ops->residue)
264 ret = dma->d_ops->residue(chan, dma);
266 return ret;
268 EXPORT_SYMBOL(get_dma_residue);
270 #ifdef CONFIG_PROC_FS
271 static int proc_dma_show(struct seq_file *m, void *v)
273 int i;
275 for (i = 0 ; i < MAX_DMA_CHANNELS ; i++) {
276 dma_t *dma = dma_channel(i);
277 if (dma && dma->lock)
278 seq_printf(m, "%2d: %s\n", i, dma->device_id);
280 return 0;
283 static int proc_dma_open(struct inode *inode, struct file *file)
285 return single_open(file, proc_dma_show, NULL);
288 static const struct file_operations proc_dma_operations = {
289 .open = proc_dma_open,
290 .read = seq_read,
291 .llseek = seq_lseek,
292 .release = single_release,
295 static int __init proc_dma_init(void)
297 proc_create("dma", 0, NULL, &proc_dma_operations);
298 return 0;
301 __initcall(proc_dma_init);
302 #endif