[ARM] Use core_initcall() to initialise ARM DMA
[linux-2.6/mini2440.git] / arch / arm / kernel / dma.c
blob3b325ef55a28e9cd3b2a9a4fc5e32a7badc4671e
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>
19 #include <asm/dma.h>
21 #include <asm/mach/dma.h>
23 DEFINE_SPINLOCK(dma_spin_lock);
25 #if MAX_DMA_CHANNELS > 0
27 static dma_t dma_chan[MAX_DMA_CHANNELS];
30 * Get dma list for /proc/dma
32 int get_dma_list(char *buf)
34 dma_t *dma;
35 char *p = buf;
36 int i;
38 for (i = 0, dma = dma_chan; i < MAX_DMA_CHANNELS; i++, dma++)
39 if (dma->lock)
40 p += sprintf(p, "%2d: %14s %s\n", i,
41 dma->d_ops->type, dma->device_id);
43 return p - buf;
47 * Request DMA channel
49 * On certain platforms, we have to allocate an interrupt as well...
51 int request_dma(dmach_t channel, const char *device_id)
53 dma_t *dma = dma_chan + channel;
54 int ret;
56 if (channel >= MAX_DMA_CHANNELS || !dma->d_ops)
57 goto bad_dma;
59 if (xchg(&dma->lock, 1) != 0)
60 goto busy;
62 dma->device_id = device_id;
63 dma->active = 0;
64 dma->invalid = 1;
66 ret = 0;
67 if (dma->d_ops->request)
68 ret = dma->d_ops->request(channel, dma);
70 if (ret)
71 xchg(&dma->lock, 0);
73 return ret;
75 bad_dma:
76 printk(KERN_ERR "dma: trying to allocate DMA%d\n", channel);
77 return -EINVAL;
79 busy:
80 return -EBUSY;
84 * Free DMA channel
86 * On certain platforms, we have to free interrupt as well...
88 void free_dma(dmach_t channel)
90 dma_t *dma = dma_chan + channel;
92 if (channel >= MAX_DMA_CHANNELS || !dma->d_ops)
93 goto bad_dma;
95 if (dma->active) {
96 printk(KERN_ERR "dma%d: freeing active DMA\n", channel);
97 dma->d_ops->disable(channel, dma);
98 dma->active = 0;
101 if (xchg(&dma->lock, 0) != 0) {
102 if (dma->d_ops->free)
103 dma->d_ops->free(channel, dma);
104 return;
107 printk(KERN_ERR "dma%d: trying to free free DMA\n", channel);
108 return;
110 bad_dma:
111 printk(KERN_ERR "dma: trying to free DMA%d\n", channel);
114 /* Set DMA Scatter-Gather list
116 void set_dma_sg (dmach_t channel, struct scatterlist *sg, int nr_sg)
118 dma_t *dma = dma_chan + channel;
120 if (dma->active)
121 printk(KERN_ERR "dma%d: altering DMA SG while "
122 "DMA active\n", channel);
124 dma->sg = sg;
125 dma->sgcount = nr_sg;
126 dma->invalid = 1;
129 /* Set DMA address
131 * Copy address to the structure, and set the invalid bit
133 void __set_dma_addr (dmach_t channel, void *addr)
135 dma_t *dma = dma_chan + channel;
137 if (dma->active)
138 printk(KERN_ERR "dma%d: altering DMA address while "
139 "DMA active\n", channel);
141 dma->sg = NULL;
142 dma->addr = addr;
143 dma->invalid = 1;
146 /* Set DMA byte count
148 * Copy address to the structure, and set the invalid bit
150 void set_dma_count (dmach_t channel, unsigned long count)
152 dma_t *dma = dma_chan + channel;
154 if (dma->active)
155 printk(KERN_ERR "dma%d: altering DMA count while "
156 "DMA active\n", channel);
158 dma->sg = NULL;
159 dma->count = count;
160 dma->invalid = 1;
163 /* Set DMA direction mode
165 void set_dma_mode (dmach_t channel, dmamode_t mode)
167 dma_t *dma = dma_chan + channel;
169 if (dma->active)
170 printk(KERN_ERR "dma%d: altering DMA mode while "
171 "DMA active\n", channel);
173 dma->dma_mode = mode;
174 dma->invalid = 1;
177 /* Enable DMA channel
179 void enable_dma (dmach_t channel)
181 dma_t *dma = dma_chan + channel;
183 if (!dma->lock)
184 goto free_dma;
186 if (dma->active == 0) {
187 dma->active = 1;
188 dma->d_ops->enable(channel, dma);
190 return;
192 free_dma:
193 printk(KERN_ERR "dma%d: trying to enable free DMA\n", channel);
194 BUG();
197 /* Disable DMA channel
199 void disable_dma (dmach_t channel)
201 dma_t *dma = dma_chan + channel;
203 if (!dma->lock)
204 goto free_dma;
206 if (dma->active == 1) {
207 dma->active = 0;
208 dma->d_ops->disable(channel, dma);
210 return;
212 free_dma:
213 printk(KERN_ERR "dma%d: trying to disable free DMA\n", channel);
214 BUG();
218 * Is the specified DMA channel active?
220 int dma_channel_active(dmach_t channel)
222 return dma_chan[channel].active;
225 void set_dma_page(dmach_t channel, char pagenr)
227 printk(KERN_ERR "dma%d: trying to set_dma_page\n", channel);
230 void set_dma_speed(dmach_t channel, int cycle_ns)
232 dma_t *dma = dma_chan + channel;
233 int ret = 0;
235 if (dma->d_ops->setspeed)
236 ret = dma->d_ops->setspeed(channel, dma, cycle_ns);
237 dma->speed = ret;
240 int get_dma_residue(dmach_t channel)
242 dma_t *dma = dma_chan + channel;
243 int ret = 0;
245 if (dma->d_ops->residue)
246 ret = dma->d_ops->residue(channel, dma);
248 return ret;
251 static int __init init_dma(void)
253 arch_dma_init(dma_chan);
254 return 0;
257 core_initcall(init_dma);
259 #else
261 int request_dma(dmach_t channel, const char *device_id)
263 return -EINVAL;
266 int get_dma_residue(dmach_t channel)
268 return 0;
271 #define GLOBAL_ALIAS(_a,_b) asm (".set " #_a "," #_b "; .globl " #_a)
272 GLOBAL_ALIAS(disable_dma, get_dma_residue);
273 GLOBAL_ALIAS(enable_dma, get_dma_residue);
274 GLOBAL_ALIAS(free_dma, get_dma_residue);
275 GLOBAL_ALIAS(get_dma_list, get_dma_residue);
276 GLOBAL_ALIAS(set_dma_mode, get_dma_residue);
277 GLOBAL_ALIAS(set_dma_page, get_dma_residue);
278 GLOBAL_ALIAS(set_dma_count, get_dma_residue);
279 GLOBAL_ALIAS(__set_dma_addr, get_dma_residue);
280 GLOBAL_ALIAS(set_dma_sg, get_dma_residue);
281 GLOBAL_ALIAS(set_dma_speed, get_dma_residue);
283 #endif
285 EXPORT_SYMBOL(request_dma);
286 EXPORT_SYMBOL(free_dma);
287 EXPORT_SYMBOL(enable_dma);
288 EXPORT_SYMBOL(disable_dma);
289 EXPORT_SYMBOL(__set_dma_addr);
290 EXPORT_SYMBOL(set_dma_count);
291 EXPORT_SYMBOL(set_dma_mode);
292 EXPORT_SYMBOL(set_dma_page);
293 EXPORT_SYMBOL(get_dma_residue);
294 EXPORT_SYMBOL(set_dma_sg);
295 EXPORT_SYMBOL(set_dma_speed);
297 EXPORT_SYMBOL(dma_spin_lock);