diff options
author | Russell King <rmk@dyn-67.arm.linux.org.uk> | 2008-12-08 11:08:48 -0500 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2008-12-08 11:56:22 -0500 |
commit | 3afb6e9c635f735c751148beddc195daec0e35ec (patch) | |
tree | 5ce51a4a09d3d11df751a43c7c6f4b5eeee0cf8e /arch | |
parent | 1df8130278c4543555fea697e5714fbac300b899 (diff) |
[ARM] dma: factor out code looking up the DMA channel
This is a preparitory patch to allow us to easily change the way we
add and lookup DMA channel structures.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arm/kernel/dma.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/arch/arm/kernel/dma.c b/arch/arm/kernel/dma.c index c31bf00e5bae..0ffea3fc22db 100644 --- a/arch/arm/kernel/dma.c +++ b/arch/arm/kernel/dma.c | |||
@@ -25,6 +25,16 @@ EXPORT_SYMBOL(dma_spin_lock); | |||
25 | 25 | ||
26 | static dma_t dma_chan[MAX_DMA_CHANNELS]; | 26 | static dma_t dma_chan[MAX_DMA_CHANNELS]; |
27 | 27 | ||
28 | static inline dma_t *dma_channel(unsigned int chan) | ||
29 | { | ||
30 | dma_t *dma = dma_chan + chan; | ||
31 | |||
32 | if (chan >= MAX_DMA_CHANNELS || !dma->d_ops) | ||
33 | return NULL; | ||
34 | |||
35 | return dma; | ||
36 | } | ||
37 | |||
28 | /* | 38 | /* |
29 | * Request DMA channel | 39 | * Request DMA channel |
30 | * | 40 | * |
@@ -32,10 +42,10 @@ static dma_t dma_chan[MAX_DMA_CHANNELS]; | |||
32 | */ | 42 | */ |
33 | int request_dma(unsigned int chan, const char *device_id) | 43 | int request_dma(unsigned int chan, const char *device_id) |
34 | { | 44 | { |
35 | dma_t *dma = dma_chan + chan; | 45 | dma_t *dma = dma_channel(chan); |
36 | int ret; | 46 | int ret; |
37 | 47 | ||
38 | if (chan >= MAX_DMA_CHANNELS || !dma->d_ops) | 48 | if (!dma) |
39 | goto bad_dma; | 49 | goto bad_dma; |
40 | 50 | ||
41 | if (xchg(&dma->lock, 1) != 0) | 51 | if (xchg(&dma->lock, 1) != 0) |
@@ -70,9 +80,9 @@ EXPORT_SYMBOL(request_dma); | |||
70 | */ | 80 | */ |
71 | void free_dma(unsigned int chan) | 81 | void free_dma(unsigned int chan) |
72 | { | 82 | { |
73 | dma_t *dma = dma_chan + chan; | 83 | dma_t *dma = dma_channel(chan); |
74 | 84 | ||
75 | if (chan >= MAX_DMA_CHANNELS || !dma->d_ops) | 85 | if (!dma) |
76 | goto bad_dma; | 86 | goto bad_dma; |
77 | 87 | ||
78 | if (dma->active) { | 88 | if (dma->active) { |
@@ -99,7 +109,7 @@ EXPORT_SYMBOL(free_dma); | |||
99 | */ | 109 | */ |
100 | void set_dma_sg (unsigned int chan, struct scatterlist *sg, int nr_sg) | 110 | void set_dma_sg (unsigned int chan, struct scatterlist *sg, int nr_sg) |
101 | { | 111 | { |
102 | dma_t *dma = dma_chan + chan; | 112 | dma_t *dma = dma_channel(chan); |
103 | 113 | ||
104 | if (dma->active) | 114 | if (dma->active) |
105 | printk(KERN_ERR "dma%d: altering DMA SG while " | 115 | printk(KERN_ERR "dma%d: altering DMA SG while " |
@@ -117,7 +127,7 @@ EXPORT_SYMBOL(set_dma_sg); | |||
117 | */ | 127 | */ |
118 | void __set_dma_addr (unsigned int chan, void *addr) | 128 | void __set_dma_addr (unsigned int chan, void *addr) |
119 | { | 129 | { |
120 | dma_t *dma = dma_chan + chan; | 130 | dma_t *dma = dma_channel(chan); |
121 | 131 | ||
122 | if (dma->active) | 132 | if (dma->active) |
123 | printk(KERN_ERR "dma%d: altering DMA address while " | 133 | printk(KERN_ERR "dma%d: altering DMA address while " |
@@ -135,7 +145,7 @@ EXPORT_SYMBOL(__set_dma_addr); | |||
135 | */ | 145 | */ |
136 | void set_dma_count (unsigned int chan, unsigned long count) | 146 | void set_dma_count (unsigned int chan, unsigned long count) |
137 | { | 147 | { |
138 | dma_t *dma = dma_chan + chan; | 148 | dma_t *dma = dma_channel(chan); |
139 | 149 | ||
140 | if (dma->active) | 150 | if (dma->active) |
141 | printk(KERN_ERR "dma%d: altering DMA count while " | 151 | printk(KERN_ERR "dma%d: altering DMA count while " |
@@ -151,7 +161,7 @@ EXPORT_SYMBOL(set_dma_count); | |||
151 | */ | 161 | */ |
152 | void set_dma_mode (unsigned int chan, dmamode_t mode) | 162 | void set_dma_mode (unsigned int chan, dmamode_t mode) |
153 | { | 163 | { |
154 | dma_t *dma = dma_chan + chan; | 164 | dma_t *dma = dma_channel(chan); |
155 | 165 | ||
156 | if (dma->active) | 166 | if (dma->active) |
157 | printk(KERN_ERR "dma%d: altering DMA mode while " | 167 | printk(KERN_ERR "dma%d: altering DMA mode while " |
@@ -166,7 +176,7 @@ EXPORT_SYMBOL(set_dma_mode); | |||
166 | */ | 176 | */ |
167 | void enable_dma (unsigned int chan) | 177 | void enable_dma (unsigned int chan) |
168 | { | 178 | { |
169 | dma_t *dma = dma_chan + chan; | 179 | dma_t *dma = dma_channel(chan); |
170 | 180 | ||
171 | if (!dma->lock) | 181 | if (!dma->lock) |
172 | goto free_dma; | 182 | goto free_dma; |
@@ -187,7 +197,7 @@ EXPORT_SYMBOL(enable_dma); | |||
187 | */ | 197 | */ |
188 | void disable_dma (unsigned int chan) | 198 | void disable_dma (unsigned int chan) |
189 | { | 199 | { |
190 | dma_t *dma = dma_chan + chan; | 200 | dma_t *dma = dma_channel(chan); |
191 | 201 | ||
192 | if (!dma->lock) | 202 | if (!dma->lock) |
193 | goto free_dma; | 203 | goto free_dma; |
@@ -209,7 +219,8 @@ EXPORT_SYMBOL(disable_dma); | |||
209 | */ | 219 | */ |
210 | int dma_channel_active(unsigned int chan) | 220 | int dma_channel_active(unsigned int chan) |
211 | { | 221 | { |
212 | return dma_chan[chan].active; | 222 | dma_t *dma = dma_channel(chan); |
223 | return dma->active; | ||
213 | } | 224 | } |
214 | EXPORT_SYMBOL(dma_channel_active); | 225 | EXPORT_SYMBOL(dma_channel_active); |
215 | 226 | ||
@@ -221,7 +232,7 @@ EXPORT_SYMBOL(set_dma_page); | |||
221 | 232 | ||
222 | void set_dma_speed(unsigned int chan, int cycle_ns) | 233 | void set_dma_speed(unsigned int chan, int cycle_ns) |
223 | { | 234 | { |
224 | dma_t *dma = dma_chan + chan; | 235 | dma_t *dma = dma_channel(chan); |
225 | int ret = 0; | 236 | int ret = 0; |
226 | 237 | ||
227 | if (dma->d_ops->setspeed) | 238 | if (dma->d_ops->setspeed) |
@@ -232,7 +243,7 @@ EXPORT_SYMBOL(set_dma_speed); | |||
232 | 243 | ||
233 | int get_dma_residue(unsigned int chan) | 244 | int get_dma_residue(unsigned int chan) |
234 | { | 245 | { |
235 | dma_t *dma = dma_chan + chan; | 246 | dma_t *dma = dma_channel(chan); |
236 | int ret = 0; | 247 | int ret = 0; |
237 | 248 | ||
238 | if (dma->d_ops->residue) | 249 | if (dma->d_ops->residue) |
@@ -247,5 +258,4 @@ static int __init init_dma(void) | |||
247 | arch_dma_init(dma_chan); | 258 | arch_dma_init(dma_chan); |
248 | return 0; | 259 | return 0; |
249 | } | 260 | } |
250 | |||
251 | core_initcall(init_dma); | 261 | core_initcall(init_dma); |