2 * BRIEF MODULE DESCRIPTION
3 * Defines for using and allocating dma channels on the Alchemy
4 * Au1000 mips processor.
6 * Copyright 2000 MontaVista Software Inc.
7 * Author: MontaVista Software, Inc.
8 * stevel@mvista.com or source@mvista.com
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
18 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
21 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
22 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, write to the Free Software Foundation, Inc.,
28 * 675 Mass Ave, Cambridge, MA 02139, USA.
31 #ifndef __ASM_AU1000_DMA_H
32 #define __ASM_AU1000_DMA_H
34 #include <asm/io.h> /* need byte IO */
35 #include <linux/spinlock.h> /* And spinlocks */
36 #include <linux/delay.h>
37 #include <asm/system.h>
39 #define NUM_AU1000_DMA_CHANNELS 8
41 /* DMA Channel Base Addresses */
42 #define DMA_CHANNEL_BASE 0xB4002000
43 #define DMA_CHANNEL_LEN 0x00000100
45 /* DMA Channel Register Offsets */
46 #define DMA_MODE_SET 0x00000000
47 #define DMA_MODE_READ DMA_MODE_SET
48 #define DMA_MODE_CLEAR 0x00000004
49 /* DMA Mode register bits follow */
50 #define DMA_DAH_MASK (0x0f << 20)
51 #define DMA_DID_BIT 16
52 #define DMA_DID_MASK (0x0f << DMA_DID_BIT)
53 #define DMA_DS (1<<15)
54 #define DMA_BE (1<<13)
55 #define DMA_DR (1<<12)
56 #define DMA_TS8 (1<<11)
58 #define DMA_DW_MASK (0x03 << DMA_DW_BIT)
59 #define DMA_DW8 (0 << DMA_DW_BIT)
60 #define DMA_DW16 (1 << DMA_DW_BIT)
61 #define DMA_DW32 (2 << DMA_DW_BIT)
64 #define DMA_HALT (1<<6)
68 #define DMA_BE1 (1<<2)
70 #define DMA_BE0 (1<<0)
72 #define DMA_PERIPHERAL_ADDR 0x00000008
73 #define DMA_BUFFER0_START 0x0000000C
74 #define DMA_BUFFER1_START 0x00000014
75 #define DMA_BUFFER0_COUNT 0x00000010
76 #define DMA_BUFFER1_COUNT 0x00000018
77 #define DMA_BAH_BIT 16
78 #define DMA_BAH_MASK (0x0f << DMA_BAH_BIT)
79 #define DMA_COUNT_BIT 0
80 #define DMA_COUNT_MASK (0xffff << DMA_COUNT_BIT)
82 /* DMA Device ID's follow */
103 /* DMA Device ID's for 2nd bank (AU1100) follow */
113 int dev_id
; // this channel is allocated if >=0, free otherwise
118 unsigned int fifo_addr
;
122 /* These are in arch/mips/au1000/common/dma.c */
123 extern struct dma_chan au1000_dma_table
[];
124 extern int request_au1000_dma(int dev_id
,
126 irq_handler_t irqhandler
,
127 unsigned long irqflags
,
129 extern void free_au1000_dma(unsigned int dmanr
);
130 extern int au1000_dma_read_proc(char *buf
, char **start
, off_t fpos
,
131 int length
, int *eof
, void *data
);
132 extern void dump_au1000_dma_channel(unsigned int dmanr
);
133 extern spinlock_t au1000_dma_spin_lock
;
136 static __inline__
struct dma_chan
*get_dma_chan(unsigned int dmanr
)
138 if (dmanr
>= NUM_AU1000_DMA_CHANNELS
139 || au1000_dma_table
[dmanr
].dev_id
< 0)
141 return &au1000_dma_table
[dmanr
];
144 static __inline__
unsigned long claim_dma_lock(void)
147 spin_lock_irqsave(&au1000_dma_spin_lock
, flags
);
151 static __inline__
void release_dma_lock(unsigned long flags
)
153 spin_unlock_irqrestore(&au1000_dma_spin_lock
, flags
);
157 * Set the DMA buffer enable bits in the mode register.
159 static __inline__
void enable_dma_buffer0(unsigned int dmanr
)
161 struct dma_chan
*chan
= get_dma_chan(dmanr
);
164 au_writel(DMA_BE0
, chan
->io
+ DMA_MODE_SET
);
166 static __inline__
void enable_dma_buffer1(unsigned int dmanr
)
168 struct dma_chan
*chan
= get_dma_chan(dmanr
);
171 au_writel(DMA_BE1
, chan
->io
+ DMA_MODE_SET
);
173 static __inline__
void enable_dma_buffers(unsigned int dmanr
)
175 struct dma_chan
*chan
= get_dma_chan(dmanr
);
178 au_writel(DMA_BE0
| DMA_BE1
, chan
->io
+ DMA_MODE_SET
);
181 static __inline__
void start_dma(unsigned int dmanr
)
183 struct dma_chan
*chan
= get_dma_chan(dmanr
);
187 au_writel(DMA_GO
, chan
->io
+ DMA_MODE_SET
);
190 #define DMA_HALT_POLL 0x5000
192 static __inline__
void halt_dma(unsigned int dmanr
)
194 struct dma_chan
*chan
= get_dma_chan(dmanr
);
199 au_writel(DMA_GO
, chan
->io
+ DMA_MODE_CLEAR
);
201 for (i
= 0; i
< DMA_HALT_POLL
; i
++)
202 if (au_readl(chan
->io
+ DMA_MODE_READ
) & DMA_HALT
)
204 if (i
== DMA_HALT_POLL
)
205 printk(KERN_INFO
"halt_dma: HALT poll expired!\n");
209 static __inline__
void disable_dma(unsigned int dmanr
)
211 struct dma_chan
*chan
= get_dma_chan(dmanr
);
217 // now we can disable the buffers
218 au_writel(~DMA_GO
, chan
->io
+ DMA_MODE_CLEAR
);
221 static __inline__
int dma_halted(unsigned int dmanr
)
223 struct dma_chan
*chan
= get_dma_chan(dmanr
);
226 return (au_readl(chan
->io
+ DMA_MODE_READ
) & DMA_HALT
) ? 1 : 0;
229 /* initialize a DMA channel */
230 static __inline__
void init_dma(unsigned int dmanr
)
232 struct dma_chan
*chan
= get_dma_chan(dmanr
);
239 // set device FIFO address
240 au_writel(CPHYSADDR(chan
->fifo_addr
),
241 chan
->io
+ DMA_PERIPHERAL_ADDR
);
243 mode
= chan
->mode
| (chan
->dev_id
<< DMA_DID_BIT
);
247 au_writel(~mode
, chan
->io
+ DMA_MODE_CLEAR
);
248 au_writel(mode
, chan
->io
+ DMA_MODE_SET
);
252 * set mode for a specific DMA channel
254 static __inline__
void set_dma_mode(unsigned int dmanr
, unsigned int mode
)
256 struct dma_chan
*chan
= get_dma_chan(dmanr
);
260 * set_dma_mode is only allowed to change endianess, direction,
261 * transfer size, device FIFO width, and coherency settings.
262 * Make sure anything else is masked off.
264 mode
&= (DMA_BE
| DMA_DR
| DMA_TS8
| DMA_DW_MASK
| DMA_NC
);
265 chan
->mode
&= ~(DMA_BE
| DMA_DR
| DMA_TS8
| DMA_DW_MASK
| DMA_NC
);
269 static __inline__
unsigned int get_dma_mode(unsigned int dmanr
)
271 struct dma_chan
*chan
= get_dma_chan(dmanr
);
277 static __inline__
int get_dma_active_buffer(unsigned int dmanr
)
279 struct dma_chan
*chan
= get_dma_chan(dmanr
);
282 return (au_readl(chan
->io
+ DMA_MODE_READ
) & DMA_AB
) ? 1 : 0;
287 * set the device FIFO address for a specific DMA channel - only
288 * applicable to GPO4 and GPO5. All the other devices have fixed
291 static __inline__
void set_dma_fifo_addr(unsigned int dmanr
,
294 struct dma_chan
*chan
= get_dma_chan(dmanr
);
298 if (chan
->mode
& DMA_DS
) /* second bank of device ids */
301 if (chan
->dev_id
!= DMA_ID_GP04
&& chan
->dev_id
!= DMA_ID_GP05
)
304 au_writel(CPHYSADDR(a
), chan
->io
+ DMA_PERIPHERAL_ADDR
);
308 * Clear the DMA buffer done bits in the mode register.
310 static __inline__
void clear_dma_done0(unsigned int dmanr
)
312 struct dma_chan
*chan
= get_dma_chan(dmanr
);
315 au_writel(DMA_D0
, chan
->io
+ DMA_MODE_CLEAR
);
317 static __inline__
void clear_dma_done1(unsigned int dmanr
)
319 struct dma_chan
*chan
= get_dma_chan(dmanr
);
322 au_writel(DMA_D1
, chan
->io
+ DMA_MODE_CLEAR
);
326 * This does nothing - not applicable to Au1000 DMA.
328 static __inline__
void set_dma_page(unsigned int dmanr
, char pagenr
)
333 * Set Buffer 0 transfer address for specific DMA channel.
335 static __inline__
void set_dma_addr0(unsigned int dmanr
, unsigned int a
)
337 struct dma_chan
*chan
= get_dma_chan(dmanr
);
340 au_writel(a
, chan
->io
+ DMA_BUFFER0_START
);
344 * Set Buffer 1 transfer address for specific DMA channel.
346 static __inline__
void set_dma_addr1(unsigned int dmanr
, unsigned int a
)
348 struct dma_chan
*chan
= get_dma_chan(dmanr
);
351 au_writel(a
, chan
->io
+ DMA_BUFFER1_START
);
356 * Set Buffer 0 transfer size (max 64k) for a specific DMA channel.
358 static __inline__
void set_dma_count0(unsigned int dmanr
,
361 struct dma_chan
*chan
= get_dma_chan(dmanr
);
364 count
&= DMA_COUNT_MASK
;
365 au_writel(count
, chan
->io
+ DMA_BUFFER0_COUNT
);
369 * Set Buffer 1 transfer size (max 64k) for a specific DMA channel.
371 static __inline__
void set_dma_count1(unsigned int dmanr
,
374 struct dma_chan
*chan
= get_dma_chan(dmanr
);
377 count
&= DMA_COUNT_MASK
;
378 au_writel(count
, chan
->io
+ DMA_BUFFER1_COUNT
);
382 * Set both buffer transfer sizes (max 64k) for a specific DMA channel.
384 static __inline__
void set_dma_count(unsigned int dmanr
,
387 struct dma_chan
*chan
= get_dma_chan(dmanr
);
390 count
&= DMA_COUNT_MASK
;
391 au_writel(count
, chan
->io
+ DMA_BUFFER0_COUNT
);
392 au_writel(count
, chan
->io
+ DMA_BUFFER1_COUNT
);
396 * Returns which buffer has its done bit set in the mode register.
397 * Returns -1 if neither or both done bits set.
399 static __inline__
unsigned int get_dma_buffer_done(unsigned int dmanr
)
401 struct dma_chan
*chan
= get_dma_chan(dmanr
);
405 return au_readl(chan
->io
+ DMA_MODE_READ
) & (DMA_D0
| DMA_D1
);
410 * Returns the DMA channel's Buffer Done IRQ number.
412 static __inline__
int get_dma_done_irq(unsigned int dmanr
)
414 struct dma_chan
*chan
= get_dma_chan(dmanr
);
422 * Get DMA residue count. Returns the number of _bytes_ left to transfer.
424 static __inline__
int get_dma_residue(unsigned int dmanr
)
426 int curBufCntReg
, count
;
427 struct dma_chan
*chan
= get_dma_chan(dmanr
);
431 curBufCntReg
= (au_readl(chan
->io
+ DMA_MODE_READ
) & DMA_AB
) ?
432 DMA_BUFFER1_COUNT
: DMA_BUFFER0_COUNT
;
434 count
= au_readl(chan
->io
+ curBufCntReg
) & DMA_COUNT_MASK
;
436 if ((chan
->mode
& DMA_DW_MASK
) == DMA_DW16
)
438 else if ((chan
->mode
& DMA_DW_MASK
) == DMA_DW32
)
444 #endif /* __ASM_AU1000_DMA_H */