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/atomic.h>
14 #include <asm/blackfin.h>
17 #define MAX_DMA_ADDRESS PAGE_OFFSET
19 /*****************************************************************************
20 * Generic DMA Declarations
22 ****************************************************************************/
24 /*-------------------------
25 * config reg bits value
26 *-------------------------*/
28 #define DATA_SIZE_16 1
29 #define DATA_SIZE_32 2
31 #define DMA_FLOW_STOP 0
32 #define DMA_FLOW_AUTO 1
33 #define DMA_FLOW_ARRAY 4
34 #define DMA_FLOW_SMALL 6
35 #define DMA_FLOW_LARGE 7
37 #define DIMENSION_LINEAR 0
38 #define DIMENSION_2D 1
43 #define INTR_DISABLE 0
47 #define DMA_NOSYNC_KEEP_DMA_BUF 0
48 #define DMA_SYNC_RESTART 1
52 unsigned long start_addr;
54 unsigned short x_count;
56 unsigned short y_count;
58 } __attribute__((packed));
61 void *next_desc_ptr; /* DMA Next Descriptor Pointer register */
62 unsigned long start_addr; /* DMA Start address register */
64 unsigned short cfg; /* DMA Configuration register */
65 unsigned short dummy1; /* DMA Configuration register */
67 unsigned long reserved;
69 unsigned short x_count; /* DMA x_count register */
70 unsigned short dummy2;
72 short x_modify; /* DMA x_modify register */
73 unsigned short dummy3;
75 unsigned short y_count; /* DMA y_count register */
76 unsigned short dummy4;
78 short y_modify; /* DMA y_modify register */
79 unsigned short dummy5;
81 void *curr_desc_ptr; /* DMA Current Descriptor Pointer
83 unsigned long curr_addr_ptr; /* DMA Current Address Pointer
85 unsigned short irq_status; /* DMA irq status register */
86 unsigned short dummy6;
88 unsigned short peripheral_map; /* DMA peripheral map register */
89 unsigned short dummy7;
91 unsigned short curr_x_count; /* DMA Current x-count register */
92 unsigned short dummy8;
94 unsigned long reserved2;
96 unsigned short curr_y_count; /* DMA Current y-count register */
97 unsigned short dummy9;
99 unsigned long reserved3;
104 const char *device_id;
105 atomic_t chan_status;
106 volatile struct dma_register *regs;
107 struct dmasg *sg; /* large mode descriptor */
111 unsigned short saved_peripheral_map;
116 int blackfin_dma_suspend(void);
117 void blackfin_dma_resume(void);
120 /*******************************************************************************
122 *******************************************************************************/
123 extern struct dma_channel dma_ch[MAX_DMA_CHANNELS];
124 extern struct dma_register *dma_io_base_addr[MAX_DMA_CHANNELS];
125 extern int channel2irq(unsigned int channel);
127 static inline void set_dma_start_addr(unsigned int channel, unsigned long addr)
129 dma_ch[channel].regs->start_addr = addr;
131 static inline void set_dma_next_desc_addr(unsigned int channel, void *addr)
133 dma_ch[channel].regs->next_desc_ptr = addr;
135 static inline void set_dma_curr_desc_addr(unsigned int channel, void *addr)
137 dma_ch[channel].regs->curr_desc_ptr = addr;
139 static inline void set_dma_x_count(unsigned int channel, unsigned short x_count)
141 dma_ch[channel].regs->x_count = x_count;
143 static inline void set_dma_y_count(unsigned int channel, unsigned short y_count)
145 dma_ch[channel].regs->y_count = y_count;
147 static inline void set_dma_x_modify(unsigned int channel, short x_modify)
149 dma_ch[channel].regs->x_modify = x_modify;
151 static inline void set_dma_y_modify(unsigned int channel, short y_modify)
153 dma_ch[channel].regs->y_modify = y_modify;
155 static inline void set_dma_config(unsigned int channel, unsigned short config)
157 dma_ch[channel].regs->cfg = config;
159 static inline void set_dma_curr_addr(unsigned int channel, unsigned long addr)
161 dma_ch[channel].regs->curr_addr_ptr = addr;
164 static inline unsigned short
165 set_bfin_dma_config(char direction, char flow_mode,
166 char intr_mode, char dma_mode, char width, char syncmode)
168 return (direction << 1) | (width << 2) | (dma_mode << 4) |
169 (intr_mode << 6) | (flow_mode << 12) | (syncmode << 5);
172 static inline unsigned short get_dma_curr_irqstat(unsigned int channel)
174 return dma_ch[channel].regs->irq_status;
176 static inline unsigned short get_dma_curr_xcount(unsigned int channel)
178 return dma_ch[channel].regs->curr_x_count;
180 static inline unsigned short get_dma_curr_ycount(unsigned int channel)
182 return dma_ch[channel].regs->curr_y_count;
184 static inline void *get_dma_next_desc_ptr(unsigned int channel)
186 return dma_ch[channel].regs->next_desc_ptr;
188 static inline void *get_dma_curr_desc_ptr(unsigned int channel)
190 return dma_ch[channel].regs->curr_desc_ptr;
192 static inline unsigned short get_dma_config(unsigned int channel)
194 return dma_ch[channel].regs->cfg;
196 static inline unsigned long get_dma_curr_addr(unsigned int channel)
198 return dma_ch[channel].regs->curr_addr_ptr;
201 static inline void set_dma_sg(unsigned int channel, struct dmasg *sg, int ndsize)
203 /* Make sure the internal data buffers in the core are drained
204 * so that the DMA descriptors are completely written when the
205 * DMA engine goes to fetch them below.
209 dma_ch[channel].regs->next_desc_ptr = sg;
210 dma_ch[channel].regs->cfg =
211 (dma_ch[channel].regs->cfg & ~(0xf << 8)) |
212 ((ndsize & 0xf) << 8);
215 static inline int dma_channel_active(unsigned int channel)
217 return atomic_read(&dma_ch[channel].chan_status);
220 static inline void disable_dma(unsigned int channel)
222 dma_ch[channel].regs->cfg &= ~DMAEN;
225 static inline void enable_dma(unsigned int channel)
227 dma_ch[channel].regs->curr_x_count = 0;
228 dma_ch[channel].regs->curr_y_count = 0;
229 dma_ch[channel].regs->cfg |= DMAEN;
231 void free_dma(unsigned int channel);
232 int request_dma(unsigned int channel, const char *device_id);
233 int set_dma_callback(unsigned int channel, irq_handler_t callback, void *data);
235 static inline void dma_disable_irq(unsigned int channel)
237 disable_irq(dma_ch[channel].irq);
239 static inline void dma_enable_irq(unsigned int channel)
241 enable_irq(dma_ch[channel].irq);
243 static inline void clear_dma_irqstat(unsigned int channel)
245 dma_ch[channel].regs->irq_status = DMA_DONE | DMA_ERR;
248 void *dma_memcpy(void *dest, const void *src, size_t count);
249 void *safe_dma_memcpy(void *dest, const void *src, size_t count);
250 void blackfin_dma_early_init(void);
251 void early_dma_memcpy(void *dest, const void *src, size_t count);
252 void early_dma_memcpy_done(void);