dma.h 10.0 KB

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