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
];
29 * Get dma list for /proc/dma
31 int get_dma_list(char *buf
)
37 for (i
= 0, dma
= dma_chan
; i
< MAX_DMA_CHANNELS
; i
++, dma
++)
39 p
+= sprintf(p
, "%2d: %14s %s\n", i
,
40 dma
->d_ops
->type
, dma
->device_id
);
48 * On certain platforms, we have to allocate an interrupt as well...
50 int request_dma(dmach_t channel
, const char *device_id
)
52 dma_t
*dma
= dma_chan
+ channel
;
55 if (channel
>= MAX_DMA_CHANNELS
|| !dma
->d_ops
)
58 if (xchg(&dma
->lock
, 1) != 0)
61 dma
->device_id
= device_id
;
66 if (dma
->d_ops
->request
)
67 ret
= dma
->d_ops
->request(channel
, dma
);
75 printk(KERN_ERR
"dma: trying to allocate DMA%d\n", channel
);
81 EXPORT_SYMBOL(request_dma
);
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
)
96 printk(KERN_ERR
"dma%d: freeing active DMA\n", channel
);
97 dma
->d_ops
->disable(channel
, dma
);
101 if (xchg(&dma
->lock
, 0) != 0) {
102 if (dma
->d_ops
->free
)
103 dma
->d_ops
->free(channel
, dma
);
107 printk(KERN_ERR
"dma%d: trying to free free DMA\n", channel
);
111 printk(KERN_ERR
"dma: trying to free DMA%d\n", channel
);
113 EXPORT_SYMBOL(free_dma
);
115 /* Set DMA Scatter-Gather list
117 void set_dma_sg (dmach_t channel
, struct scatterlist
*sg
, int nr_sg
)
119 dma_t
*dma
= dma_chan
+ channel
;
122 printk(KERN_ERR
"dma%d: altering DMA SG while "
123 "DMA active\n", channel
);
126 dma
->sgcount
= nr_sg
;
129 EXPORT_SYMBOL(set_dma_sg
);
133 * Copy address to the structure, and set the invalid bit
135 void __set_dma_addr (dmach_t channel
, void *addr
)
137 dma_t
*dma
= dma_chan
+ channel
;
140 printk(KERN_ERR
"dma%d: altering DMA address while "
141 "DMA active\n", channel
);
147 EXPORT_SYMBOL(__set_dma_addr
);
149 /* Set DMA byte count
151 * Copy address to the structure, and set the invalid bit
153 void set_dma_count (dmach_t channel
, unsigned long count
)
155 dma_t
*dma
= dma_chan
+ channel
;
158 printk(KERN_ERR
"dma%d: altering DMA count while "
159 "DMA active\n", channel
);
165 EXPORT_SYMBOL(set_dma_count
);
167 /* Set DMA direction mode
169 void set_dma_mode (dmach_t channel
, dmamode_t mode
)
171 dma_t
*dma
= dma_chan
+ channel
;
174 printk(KERN_ERR
"dma%d: altering DMA mode while "
175 "DMA active\n", channel
);
177 dma
->dma_mode
= mode
;
180 EXPORT_SYMBOL(set_dma_mode
);
182 /* Enable DMA channel
184 void enable_dma (dmach_t channel
)
186 dma_t
*dma
= dma_chan
+ channel
;
191 if (dma
->active
== 0) {
193 dma
->d_ops
->enable(channel
, dma
);
198 printk(KERN_ERR
"dma%d: trying to enable free DMA\n", channel
);
201 EXPORT_SYMBOL(enable_dma
);
203 /* Disable DMA channel
205 void disable_dma (dmach_t channel
)
207 dma_t
*dma
= dma_chan
+ channel
;
212 if (dma
->active
== 1) {
214 dma
->d_ops
->disable(channel
, dma
);
219 printk(KERN_ERR
"dma%d: trying to disable free DMA\n", channel
);
222 EXPORT_SYMBOL(disable_dma
);
225 * Is the specified DMA channel active?
227 int dma_channel_active(dmach_t channel
)
229 return dma_chan
[channel
].active
;
232 void set_dma_page(dmach_t channel
, char pagenr
)
234 printk(KERN_ERR
"dma%d: trying to set_dma_page\n", channel
);
236 EXPORT_SYMBOL(set_dma_page
);
238 void set_dma_speed(dmach_t channel
, int cycle_ns
)
240 dma_t
*dma
= dma_chan
+ channel
;
243 if (dma
->d_ops
->setspeed
)
244 ret
= dma
->d_ops
->setspeed(channel
, dma
, cycle_ns
);
247 EXPORT_SYMBOL(set_dma_speed
);
249 int get_dma_residue(dmach_t channel
)
251 dma_t
*dma
= dma_chan
+ channel
;
254 if (dma
->d_ops
->residue
)
255 ret
= dma
->d_ops
->residue(channel
, dma
);
259 EXPORT_SYMBOL(get_dma_residue
);
261 static int __init
init_dma(void)
263 arch_dma_init(dma_chan
);
267 core_initcall(init_dma
);