dma.h 9.8 KB

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