dma.h 9.6 KB

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