vserver 1.9.3
[linux-2.6.git] / include / asm-arm / arch-s3c2410 / dma.h
1 /* linux/include/asm-arm/arch-bast/dma.h
2  *
3  * Copyright (C) 2003 Simtec Electronics
4  *  Ben Dooks <ben@simtec.co.uk>
5  *
6  * Samsung S3C2410X DMA support
7  *
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.
11  *
12  * Changelog:
13  *  ??-May-2003 BJD   Created file
14  *  ??-Jun-2003 BJD   Added more dma functionality to go with arch
15 */
16
17
18 #ifndef __ASM_ARCH_DMA_H
19 #define __ASM_ARCH_DMA_H
20
21 #include <linux/config.h>
22 #include "hardware.h"
23
24
25 /*
26  * This is the maximum DMA address(physical address) that can be DMAd to.
27  *
28  */
29 #define MAX_DMA_ADDRESS         0x20000000
30 #define MAX_DMA_TRANSFER_SIZE   0x100000 /* Data Unit is half word  */
31
32
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.
36  */
37
38 #define MAX_DMA_CHANNELS        0
39
40
41 /* we have 4 dma channels */
42 #define S3C2410_DMA_CHANNELS        (4)
43
44 /* types */
45
46 typedef enum {
47         S3C2410_DMA_IDLE,
48         S3C2410_DMA_RUNNING,
49         S3C2410_DMA_PAUSED
50 } s3c2410_dma_state_t;
51
52
53 /* s3c2410_dma_loadst_t
54  *
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
58  * we can
59  *
60  * S3C2410_DMA_NONE
61  *
62  * There are no buffers loaded (the channel should be inactive)
63  *
64  * S3C2410_DMA_1LOADED
65  *
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.
70  *
71  * S3C2410_DMA_1RUNNING
72  *
73  * The buffer has been confirmed running, and not finisged
74  *
75  * S3C2410_DMA_1LOADED_1RUNNING
76  *
77  * There is a buffer waiting to be loaded by the DMA engine, and one
78  * currently running.
79 */
80
81 typedef enum {
82         S3C2410_DMALOAD_NONE,
83         S3C2410_DMALOAD_1LOADED,
84         S3C2410_DMALOAD_1RUNNING,
85         S3C2410_DMALOAD_1LOADED_1RUNNING,
86 } s3c2410_dma_loadst_t;
87
88 typedef enum {
89         S3C2410_RES_OK,
90         S3C2410_RES_ERR,
91         S3C2410_RES_ABORT
92 } s3c2410_dma_buffresult_t;
93
94
95 typedef enum s3c2410_dmasrc_e s3c2410_dmasrc_t;
96
97 enum s3c2410_dmasrc_e {
98         S3C2410_DMASRC_HW,      /* source is memory */
99         S3C2410_DMASRC_MEM      /* source is hardware */
100 };
101
102 /* enum s3c2410_chan_op_e
103  *
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
106 */
107
108 enum s3c2410_chan_op_e {
109         S3C2410_DMAOP_START,
110         S3C2410_DMAOP_STOP,
111         S3C2410_DMAOP_PAUSE,
112         S3C2410_DMAOP_RESUME,
113         S3C2410_DMAOP_FLUSH,
114         S3C2410_DMAOP_TIMEOUT,           /* internal signal to handler */
115 };
116
117 typedef enum s3c2410_chan_op_e s3c2410_chan_op_t;
118
119 /* flags */
120
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 */
124
125 /* dma buffer */
126
127 typedef struct s3c2410_dma_buf_s s3c2410_dma_buf_t;
128
129 struct s3c2410_dma_client {
130         char                *name;
131 };
132
133 typedef struct s3c2410_dma_client s3c2410_dma_client_t;
134
135 /* s3c2410_dma_buf_s
136  *
137  * internally used buffer structure to describe a queued or running
138  * buffer.
139 */
140
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 */
148 };
149
150 /* [1] is this updated for both recv/send modes? */
151
152 typedef struct s3c2410_dma_chan_s s3c2410_dma_chan_t;
153
154 /* s3c2410_dma_cbfn_t
155  *
156  * buffer callback routine type
157 */
158
159 typedef void (*s3c2410_dma_cbfn_t)(s3c2410_dma_chan_t *, void *buf, int size,
160                                    s3c2410_dma_buffresult_t result);
161
162 typedef int  (*s3c2410_dma_opfn_t)(s3c2410_dma_chan_t *,
163                                    s3c2410_chan_op_t );
164
165 struct s3c2410_dma_stats_s {
166         unsigned long          loads;
167         unsigned long          timeout_longest;
168         unsigned long          timeout_shortest;
169         unsigned long          timeout_avg;
170         unsigned long          timeout_failed;
171 };
172
173 typedef struct s3c2410_dma_stats_s s3c2410_dma_stats_t;
174
175 /* struct s3c2410_dma_chan_s
176  *
177  * full state information for each DMA channel
178 */
179
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 */
187
188         /* channel state */
189
190         s3c2410_dma_state_t    state;
191         s3c2410_dma_loadst_t   load_state;
192         s3c2410_dma_client_t  *client;
193
194         /* channel configuration */
195         s3c2410_dmasrc_t       source;
196         unsigned long          dev_addr;
197         unsigned long          load_timeout;
198         unsigned int           flags;        /* channel flags */
199
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 */
205
206         /* driver handles */
207         s3c2410_dma_cbfn_t     callback_fn;  /* buffer done callback */
208         s3c2410_dma_opfn_t     op_fn;        /* channel operation callback */
209
210         /* stats gathering */
211         s3c2410_dma_stats_t   *stats;
212         s3c2410_dma_stats_t    stats_store;
213
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 */
218 };
219
220 /* the currently allocated channel information */
221 extern s3c2410_dma_chan_t s3c2410_chans[];
222
223 /* note, we don't really use dma_device_t at the moment */
224 typedef unsigned long dma_device_t;
225
226 /* functions --------------------------------------------------------------- */
227
228 /* s3c2410_dma_request
229  *
230  * request a dma channel exclusivley
231 */
232
233 extern int s3c2410_dma_request(dmach_t channel,
234                                s3c2410_dma_client_t *, void *dev);
235
236
237 /* s3c2410_dma_ctrl
238  *
239  * change the state of the dma channel
240 */
241
242 extern int s3c2410_dma_ctrl(dmach_t channel, s3c2410_chan_op_t op);
243
244 /* s3c2410_dma_setflags
245  *
246  * set the channel's flags to a given state
247 */
248
249 extern int s3c2410_dma_setflags(dmach_t channel,
250                                 unsigned int flags);
251
252 /* s3c2410_dma_free
253  *
254  * free the dma channel (will also abort any outstanding operations)
255 */
256
257 extern int s3c2410_dma_free(dmach_t channel, s3c2410_dma_client_t *);
258
259 /* s3c2410_dma_enqueue
260  *
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.
264 */
265
266 extern int s3c2410_dma_enqueue(dmach_t channel, void *id,
267                                dma_addr_t data, int size);
268
269 /* s3c2410_dma_config
270  *
271  * configure the dma channel
272 */
273
274 extern int s3c2410_dma_config(dmach_t channel, int xferunit, int dcon);
275
276 /* s3c2410_dma_devconfig
277  *
278  * configure the device we're talking to
279 */
280
281 extern int s3c2410_dma_devconfig(int channel, s3c2410_dmasrc_t source,
282                                  int hwcfg, unsigned long devaddr);
283
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);
286
287 /* DMA Register definitions */
288
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)
298
299 #define S3C2410_DMASKTRIG_STOP   (1<<2)
300 #define S3C2410_DMASKTRIG_ON     (1<<1)
301 #define S3C2410_DMASKTRIG_SWTRIG (1<<0)
302
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)
307
308 #define S3C2410_DCON_INTREQ     (1<<29)
309
310 #define S3C2410_DCON_SRCSHIFT   (24)
311
312 #define S3C2410_DCON_BYTE       (0<<20)
313 #define S3C2410_DCON_HALFWORD   (1<<20)
314 #define S3C2410_DCON_WORD       (2<<20)
315
316 #define S3C2410_DCON_AUTORELOAD (0<<22)
317 #define S3C2410_DCON_NORELOAD   (1<<22)
318 #define S3C2410_DCON_HWTRIG     (1<<23)
319
320 #endif /* __ASM_ARCH_DMA_H */