blob: 166fc89d62d71c39638bf38f4ac3c4837cbe10b5 [file] [log] [blame]
Ben Dooks57bcdaf2006-08-31 15:26:41 +01001/* linux/include/asm-arm/arch-s3c2410/dma.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
Ben Dooks57bcdaf2006-08-31 15:26:41 +01003 * Copyright (C) 2003,2004,2006 Simtec Electronics
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Ben Dooks <ben@simtec.co.uk>
5 *
Ben Dooks57bcdaf2006-08-31 15:26:41 +01006 * Samsung S3C241XX DMA support
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070011*/
12
13#ifndef __ASM_ARCH_DMA_H
14#define __ASM_ARCH_DMA_H __FILE__
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/sysdev.h>
17#include "hardware.h"
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/*
20 * This is the maximum DMA address(physical address) that can be DMAd to.
21 *
22 */
Ben Dooks57bcdaf2006-08-31 15:26:41 +010023#define MAX_DMA_ADDRESS 0x40000000
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#define MAX_DMA_TRANSFER_SIZE 0x100000 /* Data Unit is half word */
25
Ben Dooks505788c2006-09-15 23:42:24 +010026/* We use `virtual` dma channels to hide the fact we have only a limited
27 * number of DMA channels, and not of all of them (dependant on the device)
28 * can be attached to any DMA source. We therefore let the DMA core handle
29 * the allocation of hardware channels to clients.
30*/
31
32enum dma_ch {
33 DMACH_XD0,
34 DMACH_XD1,
35 DMACH_SDI,
36 DMACH_SPI0,
37 DMACH_SPI1,
38 DMACH_UART0,
39 DMACH_UART1,
40 DMACH_UART2,
41 DMACH_TIMER,
42 DMACH_I2S_IN,
43 DMACH_I2S_OUT,
44 DMACH_PCM_IN,
45 DMACH_PCM_OUT,
46 DMACH_MIC_IN,
47 DMACH_USB_EP1,
48 DMACH_USB_EP2,
49 DMACH_USB_EP3,
50 DMACH_USB_EP4,
51 DMACH_MAX, /* the end entry */
52};
53
54#define DMACH_LOW_LEVEL (1<<28) /* use this to specifiy hardware ch no */
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/* we have 4 dma channels */
57#define S3C2410_DMA_CHANNELS (4)
58
59/* types */
60
Ben Dooksf105a7d2006-08-31 15:26:37 +010061enum s3c2410_dma_state {
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 S3C2410_DMA_IDLE,
63 S3C2410_DMA_RUNNING,
64 S3C2410_DMA_PAUSED
Ben Dooksf105a7d2006-08-31 15:26:37 +010065};
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67
Ben Dooksf105a7d2006-08-31 15:26:37 +010068/* enum s3c2410_dma_loadst
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 *
70 * This represents the state of the DMA engine, wrt to the loaded / running
71 * transfers. Since we don't have any way of knowing exactly the state of
72 * the DMA transfers, we need to know the state to make decisions on wether
73 * we can
74 *
75 * S3C2410_DMA_NONE
76 *
77 * There are no buffers loaded (the channel should be inactive)
78 *
79 * S3C2410_DMA_1LOADED
80 *
81 * There is one buffer loaded, however it has not been confirmed to be
82 * loaded by the DMA engine. This may be because the channel is not
83 * yet running, or the DMA driver decided that it was too costly to
84 * sit and wait for it to happen.
85 *
86 * S3C2410_DMA_1RUNNING
87 *
88 * The buffer has been confirmed running, and not finisged
89 *
90 * S3C2410_DMA_1LOADED_1RUNNING
91 *
92 * There is a buffer waiting to be loaded by the DMA engine, and one
93 * currently running.
94*/
95
Ben Dooksf105a7d2006-08-31 15:26:37 +010096enum s3c2410_dma_loadst {
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 S3C2410_DMALOAD_NONE,
98 S3C2410_DMALOAD_1LOADED,
99 S3C2410_DMALOAD_1RUNNING,
100 S3C2410_DMALOAD_1LOADED_1RUNNING,
Ben Dooksf105a7d2006-08-31 15:26:37 +0100101};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Ben Dooksf105a7d2006-08-31 15:26:37 +0100103enum s3c2410_dma_buffresult {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 S3C2410_RES_OK,
105 S3C2410_RES_ERR,
106 S3C2410_RES_ABORT
Ben Dooksf105a7d2006-08-31 15:26:37 +0100107};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Ben Dooksf105a7d2006-08-31 15:26:37 +0100109enum s3c2410_dmasrc {
Ben Dooks57bcdaf2006-08-31 15:26:41 +0100110 S3C2410_DMASRC_HW, /* source is memory */
111 S3C2410_DMASRC_MEM /* source is hardware */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112};
113
Ben Dooksf105a7d2006-08-31 15:26:37 +0100114/* enum s3c2410_chan_op
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 *
116 * operation codes passed to the DMA code by the user, and also used
117 * to inform the current channel owner of any changes to the system state
118*/
119
Ben Dooksf105a7d2006-08-31 15:26:37 +0100120enum s3c2410_chan_op {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 S3C2410_DMAOP_START,
122 S3C2410_DMAOP_STOP,
123 S3C2410_DMAOP_PAUSE,
124 S3C2410_DMAOP_RESUME,
125 S3C2410_DMAOP_FLUSH,
Ben Dooks57bcdaf2006-08-31 15:26:41 +0100126 S3C2410_DMAOP_TIMEOUT, /* internal signal to handler */
Ben Dooksf57e1ab2006-08-18 15:32:10 +0100127 S3C2410_DMAOP_STARTED, /* indicate channel started */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128};
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130/* flags */
131
132#define S3C2410_DMAF_SLOW (1<<0) /* slow, so don't worry about
133 * waiting for reloads */
134#define S3C2410_DMAF_AUTOSTART (1<<1) /* auto-start if buffer queued */
135
136/* dma buffer */
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138struct s3c2410_dma_client {
139 char *name;
140};
141
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142/* s3c2410_dma_buf_s
143 *
144 * internally used buffer structure to describe a queued or running
145 * buffer.
146*/
147
Ben Dooksf105a7d2006-08-31 15:26:37 +0100148struct s3c2410_dma_buf;
149struct s3c2410_dma_buf {
Ben Dooks57bcdaf2006-08-31 15:26:41 +0100150 struct s3c2410_dma_buf *next;
151 int magic; /* magic */
152 int size; /* buffer size in bytes */
153 dma_addr_t data; /* start of DMA data */
154 dma_addr_t ptr; /* where the DMA got to [1] */
155 void *id; /* client's id */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156};
157
158/* [1] is this updated for both recv/send modes? */
159
Ben Dooksf105a7d2006-08-31 15:26:37 +0100160struct s3c2410_dma_chan;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162/* s3c2410_dma_cbfn_t
163 *
164 * buffer callback routine type
165*/
166
Ben Dooksf105a7d2006-08-31 15:26:37 +0100167typedef void (*s3c2410_dma_cbfn_t)(struct s3c2410_dma_chan *,
168 void *buf, int size,
169 enum s3c2410_dma_buffresult result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
Ben Dooksf105a7d2006-08-31 15:26:37 +0100171typedef int (*s3c2410_dma_opfn_t)(struct s3c2410_dma_chan *,
172 enum s3c2410_chan_op );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Ben Dooksf105a7d2006-08-31 15:26:37 +0100174struct s3c2410_dma_stats {
Ben Dooks57bcdaf2006-08-31 15:26:41 +0100175 unsigned long loads;
176 unsigned long timeout_longest;
177 unsigned long timeout_shortest;
178 unsigned long timeout_avg;
179 unsigned long timeout_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180};
181
Ben Dooks505788c2006-09-15 23:42:24 +0100182struct s3c2410_dma_map;
183
Ben Dooksf105a7d2006-08-31 15:26:37 +0100184/* struct s3c2410_dma_chan
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 *
186 * full state information for each DMA channel
187*/
188
Ben Dooksf105a7d2006-08-31 15:26:37 +0100189struct s3c2410_dma_chan {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 /* channel state flags and information */
Ben Dooks57bcdaf2006-08-31 15:26:41 +0100191 unsigned char number; /* number of this dma channel */
192 unsigned char in_use; /* channel allocated */
193 unsigned char irq_claimed; /* irq claimed for channel */
194 unsigned char irq_enabled; /* irq enabled for channel */
195 unsigned char xfer_unit; /* size of an transfer */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 /* channel state */
198
Ben Dooks57bcdaf2006-08-31 15:26:41 +0100199 enum s3c2410_dma_state state;
200 enum s3c2410_dma_loadst load_state;
201 struct s3c2410_dma_client *client;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 /* channel configuration */
Ben Dooks57bcdaf2006-08-31 15:26:41 +0100204 enum s3c2410_dmasrc source;
205 unsigned long dev_addr;
206 unsigned long load_timeout;
207 unsigned int flags; /* channel flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Ben Dooks505788c2006-09-15 23:42:24 +0100209 struct s3c24xx_dma_map *map; /* channel hw maps */
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 /* channel's hardware position and configuration */
Ben Dooks57bcdaf2006-08-31 15:26:41 +0100212 void __iomem *regs; /* channels registers */
213 void __iomem *addr_reg; /* data address register */
214 unsigned int irq; /* channel irq */
215 unsigned long dcon; /* default value of DCON */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 /* driver handles */
Ben Dooks57bcdaf2006-08-31 15:26:41 +0100218 s3c2410_dma_cbfn_t callback_fn; /* buffer done callback */
219 s3c2410_dma_opfn_t op_fn; /* channel op callback */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 /* stats gathering */
Ben Dooks57bcdaf2006-08-31 15:26:41 +0100222 struct s3c2410_dma_stats *stats;
223 struct s3c2410_dma_stats stats_store;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 /* buffer list and information */
Ben Dooks57bcdaf2006-08-31 15:26:41 +0100226 struct s3c2410_dma_buf *curr; /* current dma buffer */
227 struct s3c2410_dma_buf *next; /* next buffer to load */
228 struct s3c2410_dma_buf *end; /* end of queue */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 /* system device */
231 struct sys_device dev;
232};
233
234/* the currently allocated channel information */
Ben Dooksf105a7d2006-08-31 15:26:37 +0100235extern struct s3c2410_dma_chan s3c2410_chans[];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237/* note, we don't really use dma_device_t at the moment */
238typedef unsigned long dma_device_t;
239
240/* functions --------------------------------------------------------------- */
241
242/* s3c2410_dma_request
243 *
244 * request a dma channel exclusivley
245*/
246
247extern int s3c2410_dma_request(dmach_t channel,
Ben Dooksf105a7d2006-08-31 15:26:37 +0100248 struct s3c2410_dma_client *, void *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250
251/* s3c2410_dma_ctrl
252 *
253 * change the state of the dma channel
254*/
255
Ben Dooksf105a7d2006-08-31 15:26:37 +0100256extern int s3c2410_dma_ctrl(dmach_t channel, enum s3c2410_chan_op op);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258/* s3c2410_dma_setflags
259 *
260 * set the channel's flags to a given state
261*/
262
263extern int s3c2410_dma_setflags(dmach_t channel,
264 unsigned int flags);
265
266/* s3c2410_dma_free
267 *
268 * free the dma channel (will also abort any outstanding operations)
269*/
270
Ben Dooksf105a7d2006-08-31 15:26:37 +0100271extern int s3c2410_dma_free(dmach_t channel, struct s3c2410_dma_client *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
273/* s3c2410_dma_enqueue
274 *
275 * place the given buffer onto the queue of operations for the channel.
276 * The buffer must be allocated from dma coherent memory, or the Dcache/WB
277 * drained before the buffer is given to the DMA system.
278*/
279
280extern int s3c2410_dma_enqueue(dmach_t channel, void *id,
281 dma_addr_t data, int size);
282
283/* s3c2410_dma_config
284 *
285 * configure the dma channel
286*/
287
288extern int s3c2410_dma_config(dmach_t channel, int xferunit, int dcon);
289
290/* s3c2410_dma_devconfig
291 *
292 * configure the device we're talking to
293*/
294
Ben Dooksf105a7d2006-08-31 15:26:37 +0100295extern int s3c2410_dma_devconfig(int channel, enum s3c2410_dmasrc source,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 int hwcfg, unsigned long devaddr);
297
298/* s3c2410_dma_getposition
299 *
300 * get the position that the dma transfer is currently at
301*/
302
303extern int s3c2410_dma_getposition(dmach_t channel,
304 dma_addr_t *src, dma_addr_t *dest);
305
306extern int s3c2410_dma_set_opfn(dmach_t, s3c2410_dma_opfn_t rtn);
307extern int s3c2410_dma_set_buffdone_fn(dmach_t, s3c2410_dma_cbfn_t rtn);
308
309/* DMA Register definitions */
310
311#define S3C2410_DMA_DISRC (0x00)
312#define S3C2410_DMA_DISRCC (0x04)
313#define S3C2410_DMA_DIDST (0x08)
314#define S3C2410_DMA_DIDSTC (0x0C)
315#define S3C2410_DMA_DCON (0x10)
316#define S3C2410_DMA_DSTAT (0x14)
317#define S3C2410_DMA_DCSRC (0x18)
318#define S3C2410_DMA_DCDST (0x1C)
319#define S3C2410_DMA_DMASKTRIG (0x20)
320
321#define S3C2410_DISRCC_INC (1<<0)
322#define S3C2410_DISRCC_APB (1<<1)
323
324#define S3C2410_DMASKTRIG_STOP (1<<2)
325#define S3C2410_DMASKTRIG_ON (1<<1)
326#define S3C2410_DMASKTRIG_SWTRIG (1<<0)
327
328#define S3C2410_DCON_DEMAND (0<<31)
329#define S3C2410_DCON_HANDSHAKE (1<<31)
330#define S3C2410_DCON_SYNC_PCLK (0<<30)
331#define S3C2410_DCON_SYNC_HCLK (1<<30)
332
333#define S3C2410_DCON_INTREQ (1<<29)
334
335#define S3C2410_DCON_CH0_XDREQ0 (0<<24)
336#define S3C2410_DCON_CH0_UART0 (1<<24)
337#define S3C2410_DCON_CH0_SDI (2<<24)
338#define S3C2410_DCON_CH0_TIMER (3<<24)
339#define S3C2410_DCON_CH0_USBEP1 (4<<24)
340
341#define S3C2410_DCON_CH1_XDREQ1 (0<<24)
342#define S3C2410_DCON_CH1_UART1 (1<<24)
343#define S3C2410_DCON_CH1_I2SSDI (2<<24)
344#define S3C2410_DCON_CH1_SPI (3<<24)
345#define S3C2410_DCON_CH1_USBEP2 (4<<24)
346
347#define S3C2410_DCON_CH2_I2SSDO (0<<24)
348#define S3C2410_DCON_CH2_I2SSDI (1<<24)
349#define S3C2410_DCON_CH2_SDI (2<<24)
350#define S3C2410_DCON_CH2_TIMER (3<<24)
351#define S3C2410_DCON_CH2_USBEP3 (4<<24)
352
353#define S3C2410_DCON_CH3_UART2 (0<<24)
354#define S3C2410_DCON_CH3_SDI (1<<24)
355#define S3C2410_DCON_CH3_SPI (2<<24)
356#define S3C2410_DCON_CH3_TIMER (3<<24)
357#define S3C2410_DCON_CH3_USBEP4 (4<<24)
358
359#define S3C2410_DCON_SRCSHIFT (24)
360#define S3C2410_DCON_SRCMASK (7<<24)
361
362#define S3C2410_DCON_BYTE (0<<20)
363#define S3C2410_DCON_HALFWORD (1<<20)
364#define S3C2410_DCON_WORD (2<<20)
365
366#define S3C2410_DCON_AUTORELOAD (0<<22)
367#define S3C2410_DCON_NORELOAD (1<<22)
368#define S3C2410_DCON_HWTRIG (1<<23)
369
370#ifdef CONFIG_CPU_S3C2440
371#define S3C2440_DIDSTC_CHKINT (1<<2)
372
373#define S3C2440_DCON_CH0_I2SSDO (5<<24)
374#define S3C2440_DCON_CH0_PCMIN (6<<24)
375
376#define S3C2440_DCON_CH1_PCMOUT (5<<24)
377#define S3C2440_DCON_CH1_SDI (6<<24)
378
379#define S3C2440_DCON_CH2_PCMIN (5<<24)
380#define S3C2440_DCON_CH2_MICIN (6<<24)
381
382#define S3C2440_DCON_CH3_MICIN (5<<24)
383#define S3C2440_DCON_CH3_PCMOUT (6<<24)
384#endif
385
386#endif /* __ASM_ARCH_DMA_H */