Merge branch 'akpm'
[linux-2.6/next.git] / arch / blackfin / include / asm / dma.h
blobdac0c97242bbf6ef3e4a45bcc2914cad8522f046
1 /*
2 * dma.h - Blackfin DMA defines/structures/etc...
4 * Copyright 2004-2008 Analog Devices Inc.
5 * Licensed under the GPL-2 or later.
6 */
8 #ifndef _BLACKFIN_DMA_H_
9 #define _BLACKFIN_DMA_H_
11 #include <linux/interrupt.h>
12 #include <mach/dma.h>
13 #include <linux/atomic.h>
14 #include <asm/blackfin.h>
15 #include <asm/page.h>
16 #include <asm-generic/dma.h>
17 #include <asm/bfin_dma.h>
19 /*-------------------------
20 * config reg bits value
21 *-------------------------*/
22 #define DATA_SIZE_8 0
23 #define DATA_SIZE_16 1
24 #define DATA_SIZE_32 2
26 #define DMA_FLOW_STOP 0
27 #define DMA_FLOW_AUTO 1
28 #define DMA_FLOW_ARRAY 4
29 #define DMA_FLOW_SMALL 6
30 #define DMA_FLOW_LARGE 7
32 #define DIMENSION_LINEAR 0
33 #define DIMENSION_2D 1
35 #define DIR_READ 0
36 #define DIR_WRITE 1
38 #define INTR_DISABLE 0
39 #define INTR_ON_BUF 2
40 #define INTR_ON_ROW 3
42 #define DMA_NOSYNC_KEEP_DMA_BUF 0
43 #define DMA_SYNC_RESTART 1
45 struct dmasg {
46 void *next_desc_addr;
47 unsigned long start_addr;
48 unsigned short cfg;
49 unsigned short x_count;
50 short x_modify;
51 unsigned short y_count;
52 short y_modify;
53 } __attribute__((packed));
55 struct dma_register {
56 void *next_desc_ptr; /* DMA Next Descriptor Pointer register */
57 unsigned long start_addr; /* DMA Start address register */
59 unsigned short cfg; /* DMA Configuration register */
60 unsigned short dummy1; /* DMA Configuration register */
62 unsigned long reserved;
64 unsigned short x_count; /* DMA x_count register */
65 unsigned short dummy2;
67 short x_modify; /* DMA x_modify register */
68 unsigned short dummy3;
70 unsigned short y_count; /* DMA y_count register */
71 unsigned short dummy4;
73 short y_modify; /* DMA y_modify register */
74 unsigned short dummy5;
76 void *curr_desc_ptr; /* DMA Current Descriptor Pointer
77 register */
78 unsigned long curr_addr_ptr; /* DMA Current Address Pointer
79 register */
80 unsigned short irq_status; /* DMA irq status register */
81 unsigned short dummy6;
83 unsigned short peripheral_map; /* DMA peripheral map register */
84 unsigned short dummy7;
86 unsigned short curr_x_count; /* DMA Current x-count register */
87 unsigned short dummy8;
89 unsigned long reserved2;
91 unsigned short curr_y_count; /* DMA Current y-count register */
92 unsigned short dummy9;
94 unsigned long reserved3;
98 struct dma_channel {
99 const char *device_id;
100 atomic_t chan_status;
101 volatile struct dma_register *regs;
102 struct dmasg *sg; /* large mode descriptor */
103 unsigned int irq;
104 void *data;
105 #ifdef CONFIG_PM
106 unsigned short saved_peripheral_map;
107 #endif
110 #ifdef CONFIG_PM
111 int blackfin_dma_suspend(void);
112 void blackfin_dma_resume(void);
113 #endif
115 /*******************************************************************************
116 * DMA API's
117 *******************************************************************************/
118 extern struct dma_channel dma_ch[MAX_DMA_CHANNELS];
119 extern struct dma_register * const dma_io_base_addr[MAX_DMA_CHANNELS];
120 extern int channel2irq(unsigned int channel);
122 static inline void set_dma_start_addr(unsigned int channel, unsigned long addr)
124 dma_ch[channel].regs->start_addr = addr;
126 static inline void set_dma_next_desc_addr(unsigned int channel, void *addr)
128 dma_ch[channel].regs->next_desc_ptr = addr;
130 static inline void set_dma_curr_desc_addr(unsigned int channel, void *addr)
132 dma_ch[channel].regs->curr_desc_ptr = addr;
134 static inline void set_dma_x_count(unsigned int channel, unsigned short x_count)
136 dma_ch[channel].regs->x_count = x_count;
138 static inline void set_dma_y_count(unsigned int channel, unsigned short y_count)
140 dma_ch[channel].regs->y_count = y_count;
142 static inline void set_dma_x_modify(unsigned int channel, short x_modify)
144 dma_ch[channel].regs->x_modify = x_modify;
146 static inline void set_dma_y_modify(unsigned int channel, short y_modify)
148 dma_ch[channel].regs->y_modify = y_modify;
150 static inline void set_dma_config(unsigned int channel, unsigned short config)
152 dma_ch[channel].regs->cfg = config;
154 static inline void set_dma_curr_addr(unsigned int channel, unsigned long addr)
156 dma_ch[channel].regs->curr_addr_ptr = addr;
159 static inline unsigned short
160 set_bfin_dma_config(char direction, char flow_mode,
161 char intr_mode, char dma_mode, char width, char syncmode)
163 return (direction << 1) | (width << 2) | (dma_mode << 4) |
164 (intr_mode << 6) | (flow_mode << 12) | (syncmode << 5);
167 static inline unsigned short get_dma_curr_irqstat(unsigned int channel)
169 return dma_ch[channel].regs->irq_status;
171 static inline unsigned short get_dma_curr_xcount(unsigned int channel)
173 return dma_ch[channel].regs->curr_x_count;
175 static inline unsigned short get_dma_curr_ycount(unsigned int channel)
177 return dma_ch[channel].regs->curr_y_count;
179 static inline void *get_dma_next_desc_ptr(unsigned int channel)
181 return dma_ch[channel].regs->next_desc_ptr;
183 static inline void *get_dma_curr_desc_ptr(unsigned int channel)
185 return dma_ch[channel].regs->curr_desc_ptr;
187 static inline unsigned short get_dma_config(unsigned int channel)
189 return dma_ch[channel].regs->cfg;
191 static inline unsigned long get_dma_curr_addr(unsigned int channel)
193 return dma_ch[channel].regs->curr_addr_ptr;
196 static inline void set_dma_sg(unsigned int channel, struct dmasg *sg, int ndsize)
198 /* Make sure the internal data buffers in the core are drained
199 * so that the DMA descriptors are completely written when the
200 * DMA engine goes to fetch them below.
202 SSYNC();
204 dma_ch[channel].regs->next_desc_ptr = sg;
205 dma_ch[channel].regs->cfg =
206 (dma_ch[channel].regs->cfg & ~(0xf << 8)) |
207 ((ndsize & 0xf) << 8);
210 static inline int dma_channel_active(unsigned int channel)
212 return atomic_read(&dma_ch[channel].chan_status);
215 static inline void disable_dma(unsigned int channel)
217 dma_ch[channel].regs->cfg &= ~DMAEN;
218 SSYNC();
220 static inline void enable_dma(unsigned int channel)
222 dma_ch[channel].regs->curr_x_count = 0;
223 dma_ch[channel].regs->curr_y_count = 0;
224 dma_ch[channel].regs->cfg |= DMAEN;
226 int set_dma_callback(unsigned int channel, irq_handler_t callback, void *data);
228 static inline void dma_disable_irq(unsigned int channel)
230 disable_irq(dma_ch[channel].irq);
232 static inline void dma_disable_irq_nosync(unsigned int channel)
234 disable_irq_nosync(dma_ch[channel].irq);
236 static inline void dma_enable_irq(unsigned int channel)
238 enable_irq(dma_ch[channel].irq);
240 static inline void clear_dma_irqstat(unsigned int channel)
242 dma_ch[channel].regs->irq_status = DMA_DONE | DMA_ERR;
245 void *dma_memcpy(void *dest, const void *src, size_t count);
246 void *dma_memcpy_nocache(void *dest, const void *src, size_t count);
247 void *safe_dma_memcpy(void *dest, const void *src, size_t count);
248 void blackfin_dma_early_init(void);
249 void early_dma_memcpy(void *dest, const void *src, size_t count);
250 void early_dma_memcpy_done(void);
252 #endif