dma.h 9.1 KB

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