1#ifndef _M68K_DMA_H
2#define _M68K_DMA_H 1
3
4#ifdef CONFIG_COLDFIRE
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28#include <asm/coldfire.h>
29#include <asm/mcfsim.h>
30#include <asm/mcfdma.h>
31
32
33
34
35#if defined(CONFIG_M5249) || defined(CONFIG_M5307) || defined(CONFIG_M5407) || \
36 defined(CONFIG_M523x) || defined(CONFIG_M527x) || \
37 defined(CONFIG_M528x) || defined(CONFIG_M525x)
38
39#define MAX_M68K_DMA_CHANNELS 4
40#elif defined(CONFIG_M5272)
41#define MAX_M68K_DMA_CHANNELS 1
42#elif defined(CONFIG_M53xx)
43#define MAX_M68K_DMA_CHANNELS 0
44#else
45#define MAX_M68K_DMA_CHANNELS 2
46#endif
47
48extern unsigned int dma_base_addr[MAX_M68K_DMA_CHANNELS];
49extern unsigned int dma_device_address[MAX_M68K_DMA_CHANNELS];
50
51#if !defined(CONFIG_M5272)
52#define DMA_MODE_WRITE_BIT 0x01
53#define DMA_MODE_WORD_BIT 0x02
54#define DMA_MODE_LONG_BIT 0x04
55#define DMA_MODE_SINGLE_BIT 0x08
56
57
58#define DMA_MODE_READ 0
59
60#define DMA_MODE_WRITE 1
61
62#define DMA_MODE_READ_WORD 2
63
64#define DMA_MODE_WRITE_WORD 3
65
66#define DMA_MODE_READ_LONG 4
67
68#define DMA_MODE_WRITE_LONG 5
69
70#define DMA_MODE_READ_SINGLE 8
71
72#define DMA_MODE_WRITE_SINGLE 9
73
74#define DMA_MODE_READ_WORD_SINGLE 10
75
76#define DMA_MODE_WRITE_WORD_SINGLE 11
77
78#define DMA_MODE_READ_LONG_SINGLE 12
79
80#define DMA_MODE_WRITE_LONG_SINGLE 13
81
82#else
83
84
85#define DMA_MODE_SRC_SA_BIT 0x01
86
87#define DMA_MODE_SSIZE_MASK 0x06
88
89#define DMA_MODE_SSIZE_OFF 0x01
90
91#define DMA_MODE_DES_SA_BIT 0x10
92
93#define DMA_MODE_DSIZE_MASK 0x60
94
95#define DMA_MODE_DSIZE_OFF 0x05
96
97#define DMA_MODE_SIZE_LONG 0x00
98#define DMA_MODE_SIZE_BYTE 0x01
99#define DMA_MODE_SIZE_WORD 0x02
100#define DMA_MODE_SIZE_LINE 0x03
101
102
103
104
105
106
107
108
109#define DMA_MODE_READ ((DMA_MODE_SIZE_BYTE << DMA_MODE_DSIZE_OFF) | (DMA_MODE_SIZE_BYTE << DMA_MODE_SSIZE_OFF) | DMA_SRC_SA_BIT)
110
111#define DMA_MODE_WRITE ((DMA_MODE_SIZE_BYTE << DMA_MODE_DSIZE_OFF) | (DMA_MODE_SIZE_BYTE << DMA_MODE_SSIZE_OFF) | DMA_DES_SA_BIT)
112
113#define DMA_MODE_READ_WORD ((DMA_MODE_SIZE_WORD << DMA_MODE_DSIZE_OFF) | (DMA_MODE_SIZE_WORD << DMA_MODE_SSIZE_OFF) | DMA_SRC_SA_BIT)
114
115#define DMA_MODE_WRITE_WORD ((DMA_MODE_SIZE_WORD << DMA_MODE_DSIZE_OFF) | (DMA_MODE_SIZE_WORD << DMA_MODE_SSIZE_OFF) | DMA_DES_SA_BIT)
116
117#define DMA_MODE_READ_LONG ((DMA_MODE_SIZE_LONG << DMA_MODE_DSIZE_OFF) | (DMA_MODE_SIZE_LONG << DMA_MODE_SSIZE_OFF) | DMA_SRC_SA_BIT)
118
119#define DMA_MODE_WRITE_LONG ((DMA_MODE_SIZE_LONG << DMA_MODE_DSIZE_OFF) | (DMA_MODE_SIZE_LONG << DMA_MODE_SSIZE_OFF) | DMA_DES_SA_BIT)
120
121#endif
122
123#if !defined(CONFIG_M5272)
124
125static __inline__ void enable_dma(unsigned int dmanr)
126{
127 volatile unsigned short *dmawp;
128
129#ifdef DMA_DEBUG
130 printk("enable_dma(dmanr=%d)\n", dmanr);
131#endif
132
133 dmawp = (unsigned short *) dma_base_addr[dmanr];
134 dmawp[MCFDMA_DCR] |= MCFDMA_DCR_EEXT;
135}
136
137static __inline__ void disable_dma(unsigned int dmanr)
138{
139 volatile unsigned short *dmawp;
140 volatile unsigned char *dmapb;
141
142#ifdef DMA_DEBUG
143 printk("disable_dma(dmanr=%d)\n", dmanr);
144#endif
145
146 dmawp = (unsigned short *) dma_base_addr[dmanr];
147 dmapb = (unsigned char *) dma_base_addr[dmanr];
148
149
150 dmawp[MCFDMA_DCR] &= ~MCFDMA_DCR_EEXT;
151 dmapb[MCFDMA_DSR] = MCFDMA_DSR_DONE;
152}
153
154
155
156
157
158
159
160
161
162
163
164static __inline__ void clear_dma_ff(unsigned int dmanr)
165{
166}
167
168
169static __inline__ void set_dma_mode(unsigned int dmanr, char mode)
170{
171
172 volatile unsigned char *dmabp;
173 volatile unsigned short *dmawp;
174
175#ifdef DMA_DEBUG
176 printk("set_dma_mode(dmanr=%d,mode=%d)\n", dmanr, mode);
177#endif
178
179 dmabp = (unsigned char *) dma_base_addr[dmanr];
180 dmawp = (unsigned short *) dma_base_addr[dmanr];
181
182
183 dmabp[MCFDMA_DSR] = MCFDMA_DSR_DONE;
184
185
186 dmawp[MCFDMA_DCR] =
187 MCFDMA_DCR_INT |
188 MCFDMA_DCR_CS |
189 MCFDMA_DCR_AA |
190
191 ((mode & DMA_MODE_SINGLE_BIT) ? MCFDMA_DCR_SAA : 0) |
192
193 ((mode & DMA_MODE_WRITE_BIT) ? MCFDMA_DCR_S_RW : 0) |
194
195 ((mode & DMA_MODE_WRITE_BIT) ? MCFDMA_DCR_SINC : MCFDMA_DCR_DINC) |
196
197 ((mode & DMA_MODE_WORD_BIT) ? MCFDMA_DCR_SSIZE_WORD :
198 ((mode & DMA_MODE_LONG_BIT) ? MCFDMA_DCR_SSIZE_LONG :
199 MCFDMA_DCR_SSIZE_BYTE)) |
200 ((mode & DMA_MODE_WORD_BIT) ? MCFDMA_DCR_DSIZE_WORD :
201 ((mode & DMA_MODE_LONG_BIT) ? MCFDMA_DCR_DSIZE_LONG :
202 MCFDMA_DCR_DSIZE_BYTE));
203
204#ifdef DEBUG_DMA
205 printk("%s(%d): dmanr=%d DSR[%x]=%x DCR[%x]=%x\n", __FILE__, __LINE__,
206 dmanr, (int) &dmabp[MCFDMA_DSR], dmabp[MCFDMA_DSR],
207 (int) &dmawp[MCFDMA_DCR], dmawp[MCFDMA_DCR]);
208#endif
209}
210
211
212static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int a)
213{
214 volatile unsigned short *dmawp;
215 volatile unsigned int *dmalp;
216
217#ifdef DMA_DEBUG
218 printk("set_dma_addr(dmanr=%d,a=%x)\n", dmanr, a);
219#endif
220
221 dmawp = (unsigned short *) dma_base_addr[dmanr];
222 dmalp = (unsigned int *) dma_base_addr[dmanr];
223
224
225 if (dmawp[MCFDMA_DCR] & MCFDMA_DCR_SINC) {
226
227 dmalp[MCFDMA_SAR] = a;
228
229 dmalp[MCFDMA_DAR] = dma_device_address[dmanr];
230 } else {
231
232 dmalp[MCFDMA_DAR] = a;
233
234 dmalp[MCFDMA_SAR] = dma_device_address[dmanr];
235 }
236
237#ifdef DEBUG_DMA
238 printk("%s(%d): dmanr=%d DCR[%x]=%x SAR[%x]=%08x DAR[%x]=%08x\n",
239 __FILE__, __LINE__, dmanr, (int) &dmawp[MCFDMA_DCR], dmawp[MCFDMA_DCR],
240 (int) &dmalp[MCFDMA_SAR], dmalp[MCFDMA_SAR],
241 (int) &dmalp[MCFDMA_DAR], dmalp[MCFDMA_DAR]);
242#endif
243}
244
245
246
247
248
249static __inline__ void set_dma_device_addr(unsigned int dmanr, unsigned int a)
250{
251#ifdef DMA_DEBUG
252 printk("set_dma_device_addr(dmanr=%d,a=%x)\n", dmanr, a);
253#endif
254
255 dma_device_address[dmanr] = a;
256}
257
258
259
260
261static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
262{
263 volatile unsigned short *dmawp;
264
265#ifdef DMA_DEBUG
266 printk("set_dma_count(dmanr=%d,count=%d)\n", dmanr, count);
267#endif
268
269 dmawp = (unsigned short *) dma_base_addr[dmanr];
270 dmawp[MCFDMA_BCR] = (unsigned short)count;
271}
272
273
274
275
276
277
278
279static __inline__ int get_dma_residue(unsigned int dmanr)
280{
281 volatile unsigned short *dmawp;
282 unsigned short count;
283
284#ifdef DMA_DEBUG
285 printk("get_dma_residue(dmanr=%d)\n", dmanr);
286#endif
287
288 dmawp = (unsigned short *) dma_base_addr[dmanr];
289 count = dmawp[MCFDMA_BCR];
290 return((int) count);
291}
292#else
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318static __inline__ void enable_dma(unsigned int dmanr)
319{
320 volatile unsigned int *dmalp;
321
322#ifdef DMA_DEBUG
323 printk("enable_dma(dmanr=%d)\n", dmanr);
324#endif
325
326 dmalp = (unsigned int *) dma_base_addr[dmanr];
327 dmalp[MCFDMA_DMR] |= MCFDMA_DMR_EN;
328}
329
330static __inline__ void disable_dma(unsigned int dmanr)
331{
332 volatile unsigned int *dmalp;
333
334#ifdef DMA_DEBUG
335 printk("disable_dma(dmanr=%d)\n", dmanr);
336#endif
337
338 dmalp = (unsigned int *) dma_base_addr[dmanr];
339
340
341 dmalp[MCFDMA_DMR] &= ~MCFDMA_DMR_EN;
342 dmalp[MCFDMA_DMR] |= MCFDMA_DMR_RESET;
343}
344
345
346
347
348
349
350
351
352
353
354
355static __inline__ void clear_dma_ff(unsigned int dmanr)
356{
357}
358
359
360static __inline__ void set_dma_mode(unsigned int dmanr, char mode)
361{
362
363 volatile unsigned int *dmalp;
364 volatile unsigned short *dmawp;
365
366#ifdef DMA_DEBUG
367 printk("set_dma_mode(dmanr=%d,mode=%d)\n", dmanr, mode);
368#endif
369 dmalp = (unsigned int *) dma_base_addr[dmanr];
370 dmawp = (unsigned short *) dma_base_addr[dmanr];
371
372
373 dmalp[MCFDMA_DMR] |= MCFDMA_DMR_RESET;
374
375
376 dmalp[MCFDMA_DMR] =
377 MCFDMA_DMR_RQM_DUAL |
378 MCFDMA_DMR_DSTT_SD |
379 MCFDMA_DMR_SRCT_SD |
380
381 ((mode & DMA_MODE_SRC_SA_BIT) ? MCFDMA_DMR_SRCM_SA : MCFDMA_DMR_SRCM_IA) |
382
383 ((mode & DMA_MODE_DES_SA_BIT) ? MCFDMA_DMR_DSTM_SA : MCFDMA_DMR_DSTM_IA) |
384
385 (((mode & DMA_MODE_SSIZE_MASK) >> DMA_MODE_SSIZE_OFF) << MCFDMA_DMR_DSTS_OFF) |
386 (((mode & DMA_MODE_SSIZE_MASK) >> DMA_MODE_SSIZE_OFF) << MCFDMA_DMR_SRCS_OFF);
387
388 dmawp[MCFDMA_DIR] |= MCFDMA_DIR_ASCEN;
389
390#ifdef DEBUG_DMA
391 printk("%s(%d): dmanr=%d DMR[%x]=%x DIR[%x]=%x\n", __FILE__, __LINE__,
392 dmanr, (int) &dmalp[MCFDMA_DMR], dmabp[MCFDMA_DMR],
393 (int) &dmawp[MCFDMA_DIR], dmawp[MCFDMA_DIR]);
394#endif
395}
396
397
398static __inline__ void set_dma_addr(unsigned int dmanr, unsigned int a)
399{
400 volatile unsigned int *dmalp;
401
402#ifdef DMA_DEBUG
403 printk("set_dma_addr(dmanr=%d,a=%x)\n", dmanr, a);
404#endif
405
406 dmalp = (unsigned int *) dma_base_addr[dmanr];
407
408
409 if (dmalp[MCFDMA_DMR] & MCFDMA_DMR_SRCM) {
410
411 dmalp[MCFDMA_DSAR] = a;
412
413 dmalp[MCFDMA_DDAR] = dma_device_address[dmanr];
414 } else {
415
416 dmalp[MCFDMA_DDAR] = a;
417
418 dmalp[MCFDMA_DSAR] = dma_device_address[dmanr];
419 }
420
421#ifdef DEBUG_DMA
422 printk("%s(%d): dmanr=%d DMR[%x]=%x SAR[%x]=%08x DAR[%x]=%08x\n",
423 __FILE__, __LINE__, dmanr, (int) &dmawp[MCFDMA_DMR], dmawp[MCFDMA_DMR],
424 (int) &dmalp[MCFDMA_DSAR], dmalp[MCFDMA_DSAR],
425 (int) &dmalp[MCFDMA_DDAR], dmalp[MCFDMA_DDAR]);
426#endif
427}
428
429
430
431
432
433static __inline__ void set_dma_device_addr(unsigned int dmanr, unsigned int a)
434{
435#ifdef DMA_DEBUG
436 printk("set_dma_device_addr(dmanr=%d,a=%x)\n", dmanr, a);
437#endif
438
439 dma_device_address[dmanr] = a;
440}
441
442
443
444
445
446
447static __inline__ void set_dma_count(unsigned int dmanr, unsigned int count)
448{
449 volatile unsigned int *dmalp;
450
451#ifdef DMA_DEBUG
452 printk("set_dma_count(dmanr=%d,count=%d)\n", dmanr, count);
453#endif
454
455 dmalp = (unsigned int *) dma_base_addr[dmanr];
456 dmalp[MCFDMA_DBCR] = count;
457}
458
459
460
461
462
463
464
465static __inline__ int get_dma_residue(unsigned int dmanr)
466{
467 volatile unsigned int *dmalp;
468 unsigned int count;
469
470#ifdef DMA_DEBUG
471 printk("get_dma_residue(dmanr=%d)\n", dmanr);
472#endif
473
474 dmalp = (unsigned int *) dma_base_addr[dmanr];
475 count = dmalp[MCFDMA_DBCR];
476 return(count);
477}
478
479#endif
480#endif
481
482
483
484#define MAX_DMA_ADDRESS PAGE_OFFSET
485
486#define MAX_DMA_CHANNELS 8
487
488extern int request_dma(unsigned int dmanr, const char * device_id);
489extern void free_dma(unsigned int dmanr);
490
491#ifdef CONFIG_PCI
492extern int isa_dma_bridge_buggy;
493#else
494#define isa_dma_bridge_buggy (0)
495#endif
496
497#endif
498