1 /* linux/include/asm-arm/arch-bast/dma.h
3 * Copyright (C) 2003 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
6 * Samsung S3C2410X DMA support
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 * ??-May-2003 BJD Created file
14 * ??-Jun-2003 BJD Added more dma functionality to go with arch
18 #ifndef __ASM_ARCH_DMA_H
19 #define __ASM_ARCH_DMA_H
21 #include <linux/config.h>
26 * This is the maximum DMA address(physical address) that can be DMAd to.
29 #define MAX_DMA_ADDRESS 0x20000000
30 #define MAX_DMA_TRANSFER_SIZE 0x100000 /* Data Unit is half word */
33 /* according to the samsung port, we cannot use the regular
34 * dma channels... we must therefore provide our own interface
35 * for DMA, and allow our drivers to use that.
38 #define MAX_DMA_CHANNELS 0
41 /* we have 4 dma channels */
42 #define S3C2410_DMA_CHANNELS (4)
50 } s3c2410_dma_state_t;
53 /* s3c2410_dma_loadst_t
55 * This represents the state of the DMA engine, wrt to the loaded / running
56 * transfers. Since we don't have any way of knowing exactly the state of
57 * the DMA transfers, we need to know the state to make decisions on wether
62 * There are no buffers loaded (the channel should be inactive)
66 * There is one buffer loaded, however it has not been confirmed to be
67 * loaded by the DMA engine. This may be because the channel is not
68 * yet running, or the DMA driver decided that it was too costly to
69 * sit and wait for it to happen.
71 * S3C2410_DMA_1RUNNING
73 * The buffer has been confirmed running, and not finisged
75 * S3C2410_DMA_1LOADED_1RUNNING
77 * There is a buffer waiting to be loaded by the DMA engine, and one
83 S3C2410_DMALOAD_1LOADED,
84 S3C2410_DMALOAD_1RUNNING,
85 S3C2410_DMALOAD_1LOADED_1RUNNING,
86 } s3c2410_dma_loadst_t;
92 } s3c2410_dma_buffresult_t;
95 typedef enum s3c2410_dmasrc_e s3c2410_dmasrc_t;
97 enum s3c2410_dmasrc_e {
98 S3C2410_DMASRC_HW, /* source is memory */
99 S3C2410_DMASRC_MEM /* source is hardware */
102 /* enum s3c2410_chan_op_e
104 * operation codes passed to the DMA code by the user, and also used
105 * to inform the current channel owner of any changes to the system state
108 enum s3c2410_chan_op_e {
112 S3C2410_DMAOP_RESUME,
114 S3C2410_DMAOP_TIMEOUT, /* internal signal to handler */
117 typedef enum s3c2410_chan_op_e s3c2410_chan_op_t;
121 #define S3C2410_DMAF_SLOW (1<<0) /* slow, so don't worry about
122 * waiting for reloads */
123 #define S3C2410_DMAF_AUTOSTART (1<<1) /* auto-start if buffer queued */
127 typedef struct s3c2410_dma_buf_s s3c2410_dma_buf_t;
129 struct s3c2410_dma_client {
133 typedef struct s3c2410_dma_client s3c2410_dma_client_t;
137 * internally used buffer structure to describe a queued or running
141 struct s3c2410_dma_buf_s {
142 s3c2410_dma_buf_t *next;
143 int magic; /* magic */
144 int size; /* buffer size in bytes */
145 dma_addr_t data; /* start of DMA data */
146 dma_addr_t ptr; /* where the DMA got to [1] */
147 void *id; /* client's id */
150 /* [1] is this updated for both recv/send modes? */
152 typedef struct s3c2410_dma_chan_s s3c2410_dma_chan_t;
154 /* s3c2410_dma_cbfn_t
156 * buffer callback routine type
159 typedef void (*s3c2410_dma_cbfn_t)(s3c2410_dma_chan_t *, void *buf, int size,
160 s3c2410_dma_buffresult_t result);
162 typedef int (*s3c2410_dma_opfn_t)(s3c2410_dma_chan_t *,
165 struct s3c2410_dma_stats_s {
167 unsigned long timeout_longest;
168 unsigned long timeout_shortest;
169 unsigned long timeout_avg;
170 unsigned long timeout_failed;
173 typedef struct s3c2410_dma_stats_s s3c2410_dma_stats_t;
175 /* struct s3c2410_dma_chan_s
177 * full state information for each DMA channel
180 struct s3c2410_dma_chan_s {
181 /* channel state flags and information */
182 unsigned char number; /* number of this dma channel */
183 unsigned char in_use; /* channel allocated */
184 unsigned char irq_claimed; /* irq claimed for channel */
185 unsigned char irq_enabled; /* irq enabled for channel */
186 unsigned char xfer_unit; /* size of an transfer */
190 s3c2410_dma_state_t state;
191 s3c2410_dma_loadst_t load_state;
192 s3c2410_dma_client_t *client;
194 /* channel configuration */
195 s3c2410_dmasrc_t source;
196 unsigned long dev_addr;
197 unsigned long load_timeout;
198 unsigned int flags; /* channel flags */
200 /* channel's hardware position and configuration */
201 unsigned long regs; /* channels registers */
202 unsigned int irq; /* channel irq */
203 unsigned long addr_reg; /* data address register */
204 unsigned long dcon; /* default value of DCON */
207 s3c2410_dma_cbfn_t callback_fn; /* buffer done callback */
208 s3c2410_dma_opfn_t op_fn; /* channel operation callback */
210 /* stats gathering */
211 s3c2410_dma_stats_t *stats;
212 s3c2410_dma_stats_t stats_store;
214 /* buffer list and information */
215 s3c2410_dma_buf_t *curr; /* current dma buffer */
216 s3c2410_dma_buf_t *next; /* next buffer to load */
217 s3c2410_dma_buf_t *end; /* end of queue */
220 /* the currently allocated channel information */
221 extern s3c2410_dma_chan_t s3c2410_chans[];
223 /* note, we don't really use dma_device_t at the moment */
224 typedef unsigned long dma_device_t;
226 /* functions --------------------------------------------------------------- */
228 /* s3c2410_dma_request
230 * request a dma channel exclusivley
233 extern int s3c2410_dma_request(dmach_t channel,
234 s3c2410_dma_client_t *, void *dev);
239 * change the state of the dma channel
242 extern int s3c2410_dma_ctrl(dmach_t channel, s3c2410_chan_op_t op);
244 /* s3c2410_dma_setflags
246 * set the channel's flags to a given state
249 extern int s3c2410_dma_setflags(dmach_t channel,
254 * free the dma channel (will also abort any outstanding operations)
257 extern int s3c2410_dma_free(dmach_t channel, s3c2410_dma_client_t *);
259 /* s3c2410_dma_enqueue
261 * place the given buffer onto the queue of operations for the channel.
262 * The buffer must be allocated from dma coherent memory, or the Dcache/WB
263 * drained before the buffer is given to the DMA system.
266 extern int s3c2410_dma_enqueue(dmach_t channel, void *id,
267 dma_addr_t data, int size);
269 /* s3c2410_dma_config
271 * configure the dma channel
274 extern int s3c2410_dma_config(dmach_t channel, int xferunit, int dcon);
276 /* s3c2410_dma_devconfig
278 * configure the device we're talking to
281 extern int s3c2410_dma_devconfig(int channel, s3c2410_dmasrc_t source,
282 int hwcfg, unsigned long devaddr);
284 extern int s3c2410_dma_set_opfn(dmach_t, s3c2410_dma_opfn_t rtn);
285 extern int s3c2410_dma_set_buffdone_fn(dmach_t, s3c2410_dma_cbfn_t rtn);
287 /* DMA Register definitions */
289 #define S3C2410_DMA_DISRC (0x00)
290 #define S3C2410_DMA_DISRCC (0x04)
291 #define S3C2410_DMA_DIDST (0x08)
292 #define S3C2410_DMA_DIDSTC (0x0C)
293 #define S3C2410_DMA_DCON (0x10)
294 #define S3C2410_DMA_DSTAT (0x14)
295 #define S3C2410_DMA_DCSRC (0x18)
296 #define S3C2410_DMA_DCDST (0x1C)
297 #define S3C2410_DMA_DMASKTRIG (0x20)
299 #define S3C2410_DMASKTRIG_STOP (1<<2)
300 #define S3C2410_DMASKTRIG_ON (1<<1)
301 #define S3C2410_DMASKTRIG_SWTRIG (1<<0)
303 #define S3C2410_DCOM_DEMAND (0<<31)
304 #define S3C2410_DCON_HANDSHAKE (1<<31)
305 #define S3C2410_DCON_SYNC_PCLK (0<<30)
306 #define S3C2410_DCON_SYNC_HCLK (1<<30)
308 #define S3C2410_DCON_INTREQ (1<<29)
310 #define S3C2410_DCON_SRCSHIFT (24)
312 #define S3C2410_DCON_BYTE (0<<20)
313 #define S3C2410_DCON_HALFWORD (1<<20)
314 #define S3C2410_DCON_WORD (2<<20)
316 #define S3C2410_DCON_AUTORELOAD (0<<22)
317 #define S3C2410_DCON_NORELOAD (1<<22)
318 #define S3C2410_DCON_HWTRIG (1<<23)
320 #endif /* __ASM_ARCH_DMA_H */