dma.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /* linux/include/asm-arm/arch-bast/dma.h
  2. *
  3. * Copyright (C) 2003,2004 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. * 10-Nov-2004 BJD Added sys_device support
  16. */
  17. #ifndef __ASM_ARCH_DMA_H
  18. #define __ASM_ARCH_DMA_H __FILE__
  19. #include <linux/sysdev.h>
  20. #include "hardware.h"
  21. /*
  22. * This is the maximum DMA address(physical address) that can be DMAd to.
  23. *
  24. */
  25. #define MAX_DMA_ADDRESS 0x20000000
  26. #define MAX_DMA_TRANSFER_SIZE 0x100000 /* Data Unit is half word */
  27. /* we have 4 dma channels */
  28. #define S3C2410_DMA_CHANNELS (4)
  29. /* types */
  30. typedef enum {
  31. S3C2410_DMA_IDLE,
  32. S3C2410_DMA_RUNNING,
  33. S3C2410_DMA_PAUSED
  34. } s3c2410_dma_state_t;
  35. /* s3c2410_dma_loadst_t
  36. *
  37. * This represents the state of the DMA engine, wrt to the loaded / running
  38. * transfers. Since we don't have any way of knowing exactly the state of
  39. * the DMA transfers, we need to know the state to make decisions on wether
  40. * we can
  41. *
  42. * S3C2410_DMA_NONE
  43. *
  44. * There are no buffers loaded (the channel should be inactive)
  45. *
  46. * S3C2410_DMA_1LOADED
  47. *
  48. * There is one buffer loaded, however it has not been confirmed to be
  49. * loaded by the DMA engine. This may be because the channel is not
  50. * yet running, or the DMA driver decided that it was too costly to
  51. * sit and wait for it to happen.
  52. *
  53. * S3C2410_DMA_1RUNNING
  54. *
  55. * The buffer has been confirmed running, and not finisged
  56. *
  57. * S3C2410_DMA_1LOADED_1RUNNING
  58. *
  59. * There is a buffer waiting to be loaded by the DMA engine, and one
  60. * currently running.
  61. */
  62. typedef enum {
  63. S3C2410_DMALOAD_NONE,
  64. S3C2410_DMALOAD_1LOADED,
  65. S3C2410_DMALOAD_1RUNNING,
  66. S3C2410_DMALOAD_1LOADED_1RUNNING,
  67. } s3c2410_dma_loadst_t;
  68. typedef enum {
  69. S3C2410_RES_OK,
  70. S3C2410_RES_ERR,
  71. S3C2410_RES_ABORT
  72. } s3c2410_dma_buffresult_t;
  73. typedef enum s3c2410_dmasrc_e s3c2410_dmasrc_t;
  74. enum s3c2410_dmasrc_e {
  75. S3C2410_DMASRC_HW, /* source is memory */
  76. S3C2410_DMASRC_MEM /* source is hardware */
  77. };
  78. /* enum s3c2410_chan_op_e
  79. *
  80. * operation codes passed to the DMA code by the user, and also used
  81. * to inform the current channel owner of any changes to the system state
  82. */
  83. enum s3c2410_chan_op_e {
  84. S3C2410_DMAOP_START,
  85. S3C2410_DMAOP_STOP,
  86. S3C2410_DMAOP_PAUSE,
  87. S3C2410_DMAOP_RESUME,
  88. S3C2410_DMAOP_FLUSH,
  89. S3C2410_DMAOP_TIMEOUT, /* internal signal to handler */
  90. };
  91. typedef enum s3c2410_chan_op_e s3c2410_chan_op_t;
  92. /* flags */
  93. #define S3C2410_DMAF_SLOW (1<<0) /* slow, so don't worry about
  94. * waiting for reloads */
  95. #define S3C2410_DMAF_AUTOSTART (1<<1) /* auto-start if buffer queued */
  96. /* dma buffer */
  97. typedef struct s3c2410_dma_buf_s s3c2410_dma_buf_t;
  98. struct s3c2410_dma_client {
  99. char *name;
  100. };
  101. typedef struct s3c2410_dma_client s3c2410_dma_client_t;
  102. /* s3c2410_dma_buf_s
  103. *
  104. * internally used buffer structure to describe a queued or running
  105. * buffer.
  106. */
  107. struct s3c2410_dma_buf_s {
  108. s3c2410_dma_buf_t *next;
  109. int magic; /* magic */
  110. int size; /* buffer size in bytes */
  111. dma_addr_t data; /* start of DMA data */
  112. dma_addr_t ptr; /* where the DMA got to [1] */
  113. void *id; /* client's id */
  114. };
  115. /* [1] is this updated for both recv/send modes? */
  116. typedef struct s3c2410_dma_chan_s s3c2410_dma_chan_t;
  117. /* s3c2410_dma_cbfn_t
  118. *
  119. * buffer callback routine type
  120. */
  121. typedef void (*s3c2410_dma_cbfn_t)(s3c2410_dma_chan_t *, void *buf, int size,
  122. s3c2410_dma_buffresult_t result);
  123. typedef int (*s3c2410_dma_opfn_t)(s3c2410_dma_chan_t *,
  124. s3c2410_chan_op_t );
  125. struct s3c2410_dma_stats_s {
  126. unsigned long loads;
  127. unsigned long timeout_longest;
  128. unsigned long timeout_shortest;
  129. unsigned long timeout_avg;
  130. unsigned long timeout_failed;
  131. };
  132. typedef struct s3c2410_dma_stats_s s3c2410_dma_stats_t;
  133. /* struct s3c2410_dma_chan_s
  134. *
  135. * full state information for each DMA channel
  136. */
  137. struct s3c2410_dma_chan_s {
  138. /* channel state flags and information */
  139. unsigned char number; /* number of this dma channel */
  140. unsigned char in_use; /* channel allocated */
  141. unsigned char irq_claimed; /* irq claimed for channel */
  142. unsigned char irq_enabled; /* irq enabled for channel */
  143. unsigned char xfer_unit; /* size of an transfer */
  144. /* channel state */
  145. s3c2410_dma_state_t state;
  146. s3c2410_dma_loadst_t load_state;
  147. s3c2410_dma_client_t *client;
  148. /* channel configuration */
  149. s3c2410_dmasrc_t source;
  150. unsigned long dev_addr;
  151. unsigned long load_timeout;
  152. unsigned int flags; /* channel flags */
  153. /* channel's hardware position and configuration */
  154. void __iomem *regs; /* channels registers */
  155. void __iomem *addr_reg; /* data address register */
  156. unsigned int irq; /* channel irq */
  157. unsigned long dcon; /* default value of DCON */
  158. /* driver handles */
  159. s3c2410_dma_cbfn_t callback_fn; /* buffer done callback */
  160. s3c2410_dma_opfn_t op_fn; /* channel operation callback */
  161. /* stats gathering */
  162. s3c2410_dma_stats_t *stats;
  163. s3c2410_dma_stats_t stats_store;
  164. /* buffer list and information */
  165. s3c2410_dma_buf_t *curr; /* current dma buffer */
  166. s3c2410_dma_buf_t *next; /* next buffer to load */
  167. s3c2410_dma_buf_t *end; /* end of queue */
  168. /* system device */
  169. struct sys_device dev;
  170. };
  171. /* the currently allocated channel information */
  172. extern s3c2410_dma_chan_t s3c2410_chans[];
  173. /* note, we don't really use dma_device_t at the moment */
  174. typedef unsigned long dma_device_t;
  175. /* functions --------------------------------------------------------------- */
  176. /* s3c2410_dma_request
  177. *
  178. * request a dma channel exclusivley
  179. */
  180. extern int s3c2410_dma_request(dmach_t channel,
  181. s3c2410_dma_client_t *, void *dev);
  182. /* s3c2410_dma_ctrl
  183. *
  184. * change the state of the dma channel
  185. */
  186. extern int s3c2410_dma_ctrl(dmach_t channel, s3c2410_chan_op_t op);
  187. /* s3c2410_dma_setflags
  188. *
  189. * set the channel's flags to a given state
  190. */
  191. extern int s3c2410_dma_setflags(dmach_t channel,
  192. unsigned int flags);
  193. /* s3c2410_dma_free
  194. *
  195. * free the dma channel (will also abort any outstanding operations)
  196. */
  197. extern int s3c2410_dma_free(dmach_t channel, s3c2410_dma_client_t *);
  198. /* s3c2410_dma_enqueue
  199. *
  200. * place the given buffer onto the queue of operations for the channel.
  201. * The buffer must be allocated from dma coherent memory, or the Dcache/WB
  202. * drained before the buffer is given to the DMA system.
  203. */
  204. extern int s3c2410_dma_enqueue(dmach_t channel, void *id,
  205. dma_addr_t data, int size);
  206. /* s3c2410_dma_config
  207. *
  208. * configure the dma channel
  209. */
  210. extern int s3c2410_dma_config(dmach_t channel, int xferunit, int dcon);
  211. /* s3c2410_dma_devconfig
  212. *
  213. * configure the device we're talking to
  214. */
  215. extern int s3c2410_dma_devconfig(int channel, s3c2410_dmasrc_t source,
  216. int hwcfg, unsigned long devaddr);
  217. /* s3c2410_dma_getposition
  218. *
  219. * get the position that the dma transfer is currently at
  220. */
  221. extern int s3c2410_dma_getposition(dmach_t channel,
  222. dma_addr_t *src, dma_addr_t *dest);
  223. extern int s3c2410_dma_set_opfn(dmach_t, s3c2410_dma_opfn_t rtn);
  224. extern int s3c2410_dma_set_buffdone_fn(dmach_t, s3c2410_dma_cbfn_t rtn);
  225. /* DMA Register definitions */
  226. #define S3C2410_DMA_DISRC (0x00)
  227. #define S3C2410_DMA_DISRCC (0x04)
  228. #define S3C2410_DMA_DIDST (0x08)
  229. #define S3C2410_DMA_DIDSTC (0x0C)
  230. #define S3C2410_DMA_DCON (0x10)
  231. #define S3C2410_DMA_DSTAT (0x14)
  232. #define S3C2410_DMA_DCSRC (0x18)
  233. #define S3C2410_DMA_DCDST (0x1C)
  234. #define S3C2410_DMA_DMASKTRIG (0x20)
  235. #define S3C2410_DISRCC_INC (1<<0)
  236. #define S3C2410_DISRCC_APB (1<<1)
  237. #define S3C2410_DMASKTRIG_STOP (1<<2)
  238. #define S3C2410_DMASKTRIG_ON (1<<1)
  239. #define S3C2410_DMASKTRIG_SWTRIG (1<<0)
  240. #define S3C2410_DCON_DEMAND (0<<31)
  241. #define S3C2410_DCON_HANDSHAKE (1<<31)
  242. #define S3C2410_DCON_SYNC_PCLK (0<<30)
  243. #define S3C2410_DCON_SYNC_HCLK (1<<30)
  244. #define S3C2410_DCON_INTREQ (1<<29)
  245. #define S3C2410_DCON_CH0_XDREQ0 (0<<24)
  246. #define S3C2410_DCON_CH0_UART0 (1<<24)
  247. #define S3C2410_DCON_CH0_SDI (2<<24)
  248. #define S3C2410_DCON_CH0_TIMER (3<<24)
  249. #define S3C2410_DCON_CH0_USBEP1 (4<<24)
  250. #define S3C2410_DCON_CH1_XDREQ1 (0<<24)
  251. #define S3C2410_DCON_CH1_UART1 (1<<24)
  252. #define S3C2410_DCON_CH1_I2SSDI (2<<24)
  253. #define S3C2410_DCON_CH1_SPI (3<<24)
  254. #define S3C2410_DCON_CH1_USBEP2 (4<<24)
  255. #define S3C2410_DCON_CH2_I2SSDO (0<<24)
  256. #define S3C2410_DCON_CH2_I2SSDI (1<<24)
  257. #define S3C2410_DCON_CH2_SDI (2<<24)
  258. #define S3C2410_DCON_CH2_TIMER (3<<24)
  259. #define S3C2410_DCON_CH2_USBEP3 (4<<24)
  260. #define S3C2410_DCON_CH3_UART2 (0<<24)
  261. #define S3C2410_DCON_CH3_SDI (1<<24)
  262. #define S3C2410_DCON_CH3_SPI (2<<24)
  263. #define S3C2410_DCON_CH3_TIMER (3<<24)
  264. #define S3C2410_DCON_CH3_USBEP4 (4<<24)
  265. #define S3C2410_DCON_SRCSHIFT (24)
  266. #define S3C2410_DCON_SRCMASK (7<<24)
  267. #define S3C2410_DCON_BYTE (0<<20)
  268. #define S3C2410_DCON_HALFWORD (1<<20)
  269. #define S3C2410_DCON_WORD (2<<20)
  270. #define S3C2410_DCON_AUTORELOAD (0<<22)
  271. #define S3C2410_DCON_NORELOAD (1<<22)
  272. #define S3C2410_DCON_HWTRIG (1<<23)
  273. #ifdef CONFIG_CPU_S3C2440
  274. #define S3C2440_DIDSTC_CHKINT (1<<2)
  275. #define S3C2440_DCON_CH0_I2SSDO (5<<24)
  276. #define S3C2440_DCON_CH0_PCMIN (6<<24)
  277. #define S3C2440_DCON_CH1_PCMOUT (5<<24)
  278. #define S3C2440_DCON_CH1_SDI (6<<24)
  279. #define S3C2440_DCON_CH2_PCMIN (5<<24)
  280. #define S3C2440_DCON_CH2_MICIN (6<<24)
  281. #define S3C2440_DCON_CH3_MICIN (5<<24)
  282. #define S3C2440_DCON_CH3_PCMOUT (6<<24)
  283. #endif
  284. #endif /* __ASM_ARCH_DMA_H */