2 * dma.h - Blackfin DMA defines/structures/etc...
4 * Copyright 2004-2008 Analog Devices Inc.
5 * Licensed under the GPL-2 or later.
8 #ifndef _BLACKFIN_DMA_H_
9 #define _BLACKFIN_DMA_H_
11 #include <linux/interrupt.h>
13 #include <asm/blackfin.h>
16 #define MAX_DMA_ADDRESS PAGE_OFFSET
18 /*****************************************************************************
19 * Generic DMA Declarations
21 ****************************************************************************/
22 enum dma_chan_status {
24 DMA_CHANNEL_REQUESTED,
28 /*-------------------------
29 * config reg bits value
30 *-------------------------*/
32 #define DATA_SIZE_16 1
33 #define DATA_SIZE_32 2
35 #define DMA_FLOW_STOP 0
36 #define DMA_FLOW_AUTO 1
37 #define DMA_FLOW_ARRAY 4
38 #define DMA_FLOW_SMALL 6
39 #define DMA_FLOW_LARGE 7
41 #define DIMENSION_LINEAR 0
42 #define DIMENSION_2D 1
47 #define INTR_DISABLE 0
51 #define DMA_NOSYNC_KEEP_DMA_BUF 0
52 #define DMA_SYNC_RESTART 1
55 unsigned long next_desc_addr;
56 unsigned long start_addr;
58 unsigned short x_count;
60 unsigned short y_count;
62 } __attribute__((packed));
65 unsigned long next_desc_ptr; /* DMA Next Descriptor Pointer register */
66 unsigned long start_addr; /* DMA Start address register */
68 unsigned short cfg; /* DMA Configuration register */
69 unsigned short dummy1; /* DMA Configuration register */
71 unsigned long reserved;
73 unsigned short x_count; /* DMA x_count register */
74 unsigned short dummy2;
76 short x_modify; /* DMA x_modify register */
77 unsigned short dummy3;
79 unsigned short y_count; /* DMA y_count register */
80 unsigned short dummy4;
82 short y_modify; /* DMA y_modify register */
83 unsigned short dummy5;
85 unsigned long curr_desc_ptr; /* DMA Current Descriptor Pointer
87 unsigned long curr_addr_ptr; /* DMA Current Address Pointer
89 unsigned short irq_status; /* DMA irq status register */
90 unsigned short dummy6;
92 unsigned short peripheral_map; /* DMA peripheral map register */
93 unsigned short dummy7;
95 unsigned short curr_x_count; /* DMA Current x-count register */
96 unsigned short dummy8;
98 unsigned long reserved2;
100 unsigned short curr_y_count; /* DMA Current y-count register */
101 unsigned short dummy9;
103 unsigned long reserved3;
109 struct mutex dmalock;
110 const char *device_id;
111 enum dma_chan_status chan_status;
112 struct dma_register *regs;
113 struct dmasg *sg; /* large mode descriptor */
114 unsigned int ctrl_num; /* controller number */
117 unsigned int dma_enable_flag;
118 unsigned int loopback_flag;
120 unsigned short saved_peripheral_map;
125 int blackfin_dma_suspend(void);
126 void blackfin_dma_resume(void);
129 /*******************************************************************************
131 *******************************************************************************/
132 extern struct dma_channel dma_ch[MAX_DMA_CHANNELS];
133 extern struct dma_register *dma_io_base_addr[MAX_DMA_CHANNELS];
134 extern int channel2irq(unsigned int channel);
136 static inline void set_dma_start_addr(unsigned int channel, unsigned long addr)
138 dma_ch[channel].regs->start_addr = addr;
140 static inline void set_dma_next_desc_addr(unsigned int channel, unsigned long addr)
142 dma_ch[channel].regs->next_desc_ptr = addr;
144 static inline void set_dma_curr_desc_addr(unsigned int channel, unsigned long addr)
146 dma_ch[channel].regs->curr_desc_ptr = addr;
148 static inline void set_dma_x_count(unsigned int channel, unsigned short x_count)
150 dma_ch[channel].regs->x_count = x_count;
152 static inline void set_dma_y_count(unsigned int channel, unsigned short y_count)
154 dma_ch[channel].regs->y_count = y_count;
156 static inline void set_dma_x_modify(unsigned int channel, short x_modify)
158 dma_ch[channel].regs->x_modify = x_modify;
160 static inline void set_dma_y_modify(unsigned int channel, short y_modify)
162 dma_ch[channel].regs->y_modify = y_modify;
164 static inline void set_dma_config(unsigned int channel, unsigned short config)
166 dma_ch[channel].regs->cfg = config;
168 static inline void set_dma_curr_addr(unsigned int channel, unsigned long addr)
170 dma_ch[channel].regs->curr_addr_ptr = addr;
173 static inline unsigned short
174 set_bfin_dma_config(char direction, char flow_mode,
175 char intr_mode, char dma_mode, char width, char syncmode)
177 return (direction << 1) | (width << 2) | (dma_mode << 4) |
178 (intr_mode << 6) | (flow_mode << 12) | (syncmode << 5);
181 static inline unsigned short get_dma_curr_irqstat(unsigned int channel)
183 return dma_ch[channel].regs->irq_status;
185 static inline unsigned short get_dma_curr_xcount(unsigned int channel)
187 return dma_ch[channel].regs->curr_x_count;
189 static inline unsigned short get_dma_curr_ycount(unsigned int channel)
191 return dma_ch[channel].regs->curr_y_count;
193 static inline unsigned long get_dma_next_desc_ptr(unsigned int channel)
195 return dma_ch[channel].regs->next_desc_ptr;
197 static inline unsigned long get_dma_curr_desc_ptr(unsigned int channel)
199 return dma_ch[channel].regs->curr_desc_ptr;
201 static inline unsigned long get_dma_curr_addr(unsigned int channel)
203 return dma_ch[channel].regs->curr_addr_ptr;
206 static inline void set_dma_sg(unsigned int channel, struct dmasg *sg, int ndsize)
208 dma_ch[channel].regs->cfg |= ((ndsize & 0x0F) << 8);
209 dma_ch[channel].regs->next_desc_ptr = (unsigned long)sg;
212 static inline int dma_channel_active(unsigned int channel)
214 if (dma_ch[channel].chan_status == DMA_CHANNEL_FREE)
220 static inline void disable_dma(unsigned int channel)
222 dma_ch[channel].regs->cfg &= ~DMAEN;
224 dma_ch[channel].chan_status = DMA_CHANNEL_REQUESTED;
226 static inline void enable_dma(unsigned int channel)
228 dma_ch[channel].regs->curr_x_count = 0;
229 dma_ch[channel].regs->curr_y_count = 0;
230 dma_ch[channel].regs->cfg |= DMAEN;
231 dma_ch[channel].chan_status = DMA_CHANNEL_ENABLED;
233 void free_dma(unsigned int channel);
234 int request_dma(unsigned int channel, const char *device_id);
235 int set_dma_callback(unsigned int channel, irq_handler_t callback, void *data);
237 static inline void dma_disable_irq(unsigned int channel)
239 disable_irq(dma_ch[channel].irq);
241 static inline void dma_enable_irq(unsigned int channel)
243 enable_irq(dma_ch[channel].irq);
245 static inline void clear_dma_irqstat(unsigned int channel)
247 dma_ch[channel].regs->irq_status = DMA_DONE | DMA_ERR;
250 void *dma_memcpy(void *dest, const void *src, size_t count);
251 void *safe_dma_memcpy(void *dest, const void *src, size_t count);
252 void blackfin_dma_early_init(void);