dma.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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 use `virtual` dma channels to hide the fact we have only a limited
  23. * number of DMA channels, and not of all of them (dependant on the device)
  24. * can be attached to any DMA source. We therefore let the DMA core handle
  25. * the allocation of hardware channels to clients.
  26. */
  27. enum dma_ch {
  28. DMACH_XD0,
  29. DMACH_XD1,
  30. DMACH_SDI,
  31. DMACH_SPI0,
  32. DMACH_SPI1,
  33. DMACH_UART0,
  34. DMACH_UART1,
  35. DMACH_UART2,
  36. DMACH_TIMER,
  37. DMACH_I2S_IN,
  38. DMACH_I2S_OUT,
  39. DMACH_PCM_IN,
  40. DMACH_PCM_OUT,
  41. DMACH_MIC_IN,
  42. DMACH_USB_EP1,
  43. DMACH_USB_EP2,
  44. DMACH_USB_EP3,
  45. DMACH_USB_EP4,
  46. DMACH_UART0_SRC2, /* s3c2412 second uart sources */
  47. DMACH_UART1_SRC2,
  48. DMACH_UART2_SRC2,
  49. DMACH_MAX, /* the end entry */
  50. };
  51. #define DMACH_LOW_LEVEL (1<<28) /* use this to specifiy hardware ch no */
  52. /* we have 4 dma channels */
  53. #define S3C2410_DMA_CHANNELS (4)
  54. /* types */
  55. enum s3c2410_dma_state {
  56. S3C2410_DMA_IDLE,
  57. S3C2410_DMA_RUNNING,
  58. S3C2410_DMA_PAUSED
  59. };
  60. /* enum s3c2410_dma_loadst
  61. *
  62. * This represents the state of the DMA engine, wrt to the loaded / running
  63. * transfers. Since we don't have any way of knowing exactly the state of
  64. * the DMA transfers, we need to know the state to make decisions on wether
  65. * we can
  66. *
  67. * S3C2410_DMA_NONE
  68. *
  69. * There are no buffers loaded (the channel should be inactive)
  70. *
  71. * S3C2410_DMA_1LOADED
  72. *
  73. * There is one buffer loaded, however it has not been confirmed to be
  74. * loaded by the DMA engine. This may be because the channel is not
  75. * yet running, or the DMA driver decided that it was too costly to
  76. * sit and wait for it to happen.
  77. *
  78. * S3C2410_DMA_1RUNNING
  79. *
  80. * The buffer has been confirmed running, and not finisged
  81. *
  82. * S3C2410_DMA_1LOADED_1RUNNING
  83. *
  84. * There is a buffer waiting to be loaded by the DMA engine, and one
  85. * currently running.
  86. */
  87. enum s3c2410_dma_loadst {
  88. S3C2410_DMALOAD_NONE,
  89. S3C2410_DMALOAD_1LOADED,
  90. S3C2410_DMALOAD_1RUNNING,
  91. S3C2410_DMALOAD_1LOADED_1RUNNING,
  92. };
  93. enum s3c2410_dma_buffresult {
  94. S3C2410_RES_OK,
  95. S3C2410_RES_ERR,
  96. S3C2410_RES_ABORT
  97. };
  98. enum s3c2410_dmasrc {
  99. S3C2410_DMASRC_HW, /* source is memory */
  100. S3C2410_DMASRC_MEM /* source is hardware */
  101. };
  102. /* enum s3c2410_chan_op
  103. *
  104. * operation codes passed to the DMA code by the user, and also used
  105. * to inform the current channel owner of any changes to the system state
  106. */
  107. enum s3c2410_chan_op {
  108. S3C2410_DMAOP_START,
  109. S3C2410_DMAOP_STOP,
  110. S3C2410_DMAOP_PAUSE,
  111. S3C2410_DMAOP_RESUME,
  112. S3C2410_DMAOP_FLUSH,
  113. S3C2410_DMAOP_TIMEOUT, /* internal signal to handler */
  114. S3C2410_DMAOP_STARTED, /* indicate channel started */
  115. };
  116. /* flags */
  117. #define S3C2410_DMAF_SLOW (1<<0) /* slow, so don't worry about
  118. * waiting for reloads */
  119. #define S3C2410_DMAF_AUTOSTART (1<<1) /* auto-start if buffer queued */
  120. /* dma buffer */
  121. struct s3c2410_dma_client {
  122. char *name;
  123. };
  124. /* s3c2410_dma_buf_s
  125. *
  126. * internally used buffer structure to describe a queued or running
  127. * buffer.
  128. */
  129. struct s3c2410_dma_buf;
  130. struct s3c2410_dma_buf {
  131. struct s3c2410_dma_buf *next;
  132. int magic; /* magic */
  133. int size; /* buffer size in bytes */
  134. dma_addr_t data; /* start of DMA data */
  135. dma_addr_t ptr; /* where the DMA got to [1] */
  136. void *id; /* client's id */
  137. };
  138. /* [1] is this updated for both recv/send modes? */
  139. struct s3c2410_dma_chan;
  140. /* s3c2410_dma_cbfn_t
  141. *
  142. * buffer callback routine type
  143. */
  144. typedef void (*s3c2410_dma_cbfn_t)(struct s3c2410_dma_chan *,
  145. void *buf, int size,
  146. enum s3c2410_dma_buffresult result);
  147. typedef int (*s3c2410_dma_opfn_t)(struct s3c2410_dma_chan *,
  148. enum s3c2410_chan_op );
  149. struct s3c2410_dma_stats {
  150. unsigned long loads;
  151. unsigned long timeout_longest;
  152. unsigned long timeout_shortest;
  153. unsigned long timeout_avg;
  154. unsigned long timeout_failed;
  155. };
  156. struct s3c2410_dma_map;
  157. /* struct s3c2410_dma_chan
  158. *
  159. * full state information for each DMA channel
  160. */
  161. struct s3c2410_dma_chan {
  162. /* channel state flags and information */
  163. unsigned char number; /* number of this dma channel */
  164. unsigned char in_use; /* channel allocated */
  165. unsigned char irq_claimed; /* irq claimed for channel */
  166. unsigned char irq_enabled; /* irq enabled for channel */
  167. unsigned char xfer_unit; /* size of an transfer */
  168. /* channel state */
  169. enum s3c2410_dma_state state;
  170. enum s3c2410_dma_loadst load_state;
  171. struct s3c2410_dma_client *client;
  172. /* channel configuration */
  173. enum s3c2410_dmasrc source;
  174. unsigned long dev_addr;
  175. unsigned long load_timeout;
  176. unsigned int flags; /* channel flags */
  177. struct s3c24xx_dma_map *map; /* channel hw maps */
  178. /* channel's hardware position and configuration */
  179. void __iomem *regs; /* channels registers */
  180. void __iomem *addr_reg; /* data address register */
  181. unsigned int irq; /* channel irq */
  182. unsigned long dcon; /* default value of DCON */
  183. /* driver handles */
  184. s3c2410_dma_cbfn_t callback_fn; /* buffer done callback */
  185. s3c2410_dma_opfn_t op_fn; /* channel op callback */
  186. /* stats gathering */
  187. struct s3c2410_dma_stats *stats;
  188. struct s3c2410_dma_stats stats_store;
  189. /* buffer list and information */
  190. struct s3c2410_dma_buf *curr; /* current dma buffer */
  191. struct s3c2410_dma_buf *next; /* next buffer to load */
  192. struct s3c2410_dma_buf *end; /* end of queue */
  193. /* system device */
  194. struct sys_device dev;
  195. };
  196. /* the currently allocated channel information */
  197. extern struct s3c2410_dma_chan s3c2410_chans[];
  198. /* note, we don't really use dma_device_t at the moment */
  199. typedef unsigned long dma_device_t;
  200. /* functions --------------------------------------------------------------- */
  201. /* s3c2410_dma_request
  202. *
  203. * request a dma channel exclusivley
  204. */
  205. extern int s3c2410_dma_request(dmach_t channel,
  206. struct s3c2410_dma_client *, void *dev);
  207. /* s3c2410_dma_ctrl
  208. *
  209. * change the state of the dma channel
  210. */
  211. extern int s3c2410_dma_ctrl(dmach_t channel, enum s3c2410_chan_op op);
  212. /* s3c2410_dma_setflags
  213. *
  214. * set the channel's flags to a given state
  215. */
  216. extern int s3c2410_dma_setflags(dmach_t channel,
  217. unsigned int flags);
  218. /* s3c2410_dma_free
  219. *
  220. * free the dma channel (will also abort any outstanding operations)
  221. */
  222. extern int s3c2410_dma_free(dmach_t channel, struct s3c2410_dma_client *);
  223. /* s3c2410_dma_enqueue
  224. *
  225. * place the given buffer onto the queue of operations for the channel.
  226. * The buffer must be allocated from dma coherent memory, or the Dcache/WB
  227. * drained before the buffer is given to the DMA system.
  228. */
  229. extern int s3c2410_dma_enqueue(dmach_t channel, void *id,
  230. dma_addr_t data, int size);
  231. /* s3c2410_dma_config
  232. *
  233. * configure the dma channel
  234. */
  235. extern int s3c2410_dma_config(dmach_t channel, int xferunit, int dcon);
  236. /* s3c2410_dma_devconfig
  237. *
  238. * configure the device we're talking to
  239. */
  240. extern int s3c2410_dma_devconfig(int channel, enum s3c2410_dmasrc source,
  241. int hwcfg, unsigned long devaddr);
  242. /* s3c2410_dma_getposition
  243. *
  244. * get the position that the dma transfer is currently at
  245. */
  246. extern int s3c2410_dma_getposition(dmach_t channel,
  247. dma_addr_t *src, dma_addr_t *dest);
  248. extern int s3c2410_dma_set_opfn(dmach_t, s3c2410_dma_opfn_t rtn);
  249. extern int s3c2410_dma_set_buffdone_fn(dmach_t, s3c2410_dma_cbfn_t rtn);
  250. /* DMA Register definitions */
  251. #define S3C2410_DMA_DISRC (0x00)
  252. #define S3C2410_DMA_DISRCC (0x04)
  253. #define S3C2410_DMA_DIDST (0x08)
  254. #define S3C2410_DMA_DIDSTC (0x0C)
  255. #define S3C2410_DMA_DCON (0x10)
  256. #define S3C2410_DMA_DSTAT (0x14)
  257. #define S3C2410_DMA_DCSRC (0x18)
  258. #define S3C2410_DMA_DCDST (0x1C)
  259. #define S3C2410_DMA_DMASKTRIG (0x20)
  260. #define S3C2412_DMA_DMAREQSEL (0x24)
  261. #define S3C2410_DISRCC_INC (1<<0)
  262. #define S3C2410_DISRCC_APB (1<<1)
  263. #define S3C2410_DMASKTRIG_STOP (1<<2)
  264. #define S3C2410_DMASKTRIG_ON (1<<1)
  265. #define S3C2410_DMASKTRIG_SWTRIG (1<<0)
  266. #define S3C2410_DCON_DEMAND (0<<31)
  267. #define S3C2410_DCON_HANDSHAKE (1<<31)
  268. #define S3C2410_DCON_SYNC_PCLK (0<<30)
  269. #define S3C2410_DCON_SYNC_HCLK (1<<30)
  270. #define S3C2410_DCON_INTREQ (1<<29)
  271. #define S3C2410_DCON_CH0_XDREQ0 (0<<24)
  272. #define S3C2410_DCON_CH0_UART0 (1<<24)
  273. #define S3C2410_DCON_CH0_SDI (2<<24)
  274. #define S3C2410_DCON_CH0_TIMER (3<<24)
  275. #define S3C2410_DCON_CH0_USBEP1 (4<<24)
  276. #define S3C2410_DCON_CH1_XDREQ1 (0<<24)
  277. #define S3C2410_DCON_CH1_UART1 (1<<24)
  278. #define S3C2410_DCON_CH1_I2SSDI (2<<24)
  279. #define S3C2410_DCON_CH1_SPI (3<<24)
  280. #define S3C2410_DCON_CH1_USBEP2 (4<<24)
  281. #define S3C2410_DCON_CH2_I2SSDO (0<<24)
  282. #define S3C2410_DCON_CH2_I2SSDI (1<<24)
  283. #define S3C2410_DCON_CH2_SDI (2<<24)
  284. #define S3C2410_DCON_CH2_TIMER (3<<24)
  285. #define S3C2410_DCON_CH2_USBEP3 (4<<24)
  286. #define S3C2410_DCON_CH3_UART2 (0<<24)
  287. #define S3C2410_DCON_CH3_SDI (1<<24)
  288. #define S3C2410_DCON_CH3_SPI (2<<24)
  289. #define S3C2410_DCON_CH3_TIMER (3<<24)
  290. #define S3C2410_DCON_CH3_USBEP4 (4<<24)
  291. #define S3C2410_DCON_SRCSHIFT (24)
  292. #define S3C2410_DCON_SRCMASK (7<<24)
  293. #define S3C2410_DCON_BYTE (0<<20)
  294. #define S3C2410_DCON_HALFWORD (1<<20)
  295. #define S3C2410_DCON_WORD (2<<20)
  296. #define S3C2410_DCON_AUTORELOAD (0<<22)
  297. #define S3C2410_DCON_NORELOAD (1<<22)
  298. #define S3C2410_DCON_HWTRIG (1<<23)
  299. #ifdef CONFIG_CPU_S3C2440
  300. #define S3C2440_DIDSTC_CHKINT (1<<2)
  301. #define S3C2440_DCON_CH0_I2SSDO (5<<24)
  302. #define S3C2440_DCON_CH0_PCMIN (6<<24)
  303. #define S3C2440_DCON_CH1_PCMOUT (5<<24)
  304. #define S3C2440_DCON_CH1_SDI (6<<24)
  305. #define S3C2440_DCON_CH2_PCMIN (5<<24)
  306. #define S3C2440_DCON_CH2_MICIN (6<<24)
  307. #define S3C2440_DCON_CH3_MICIN (5<<24)
  308. #define S3C2440_DCON_CH3_PCMOUT (6<<24)
  309. #endif
  310. #ifdef CONFIG_CPU_S3C2412
  311. #define S3C2412_DMAREQSEL_SRC(x) ((x)<<1)
  312. #define S3C2412_DMAREQSEL_HW (1)
  313. #define S3C2412_DMAREQSEL_SPI0TX S3C2412_DMAREQSEL_SRC(0)
  314. #define S3C2412_DMAREQSEL_SPI0RX S3C2412_DMAREQSEL_SRC(1)
  315. #define S3C2412_DMAREQSEL_SPI1TX S3C2412_DMAREQSEL_SRC(2)
  316. #define S3C2412_DMAREQSEL_SPI1RX S3C2412_DMAREQSEL_SRC(3)
  317. #define S3C2412_DMAREQSEL_I2STX S3C2412_DMAREQSEL_SRC(4)
  318. #define S3C2412_DMAREQSEL_I2SRX S3C2412_DMAREQSEL_SRC(5)
  319. #define S3C2412_DMAREQSEL_TIMER S3C2412_DMAREQSEL_SRC(9)
  320. #define S3C2412_DMAREQSEL_SDI S3C2412_DMAREQSEL_SRC(10)
  321. #define S3C2412_DMAREQSEL_USBEP1 S3C2412_DMAREQSEL_SRC(13)
  322. #define S3C2412_DMAREQSEL_USBEP2 S3C2412_DMAREQSEL_SRC(14)
  323. #define S3C2412_DMAREQSEL_USBEP3 S3C2412_DMAREQSEL_SRC(15)
  324. #define S3C2412_DMAREQSEL_USBEP4 S3C2412_DMAREQSEL_SRC(16)
  325. #define S3C2412_DMAREQSEL_XDREQ0 S3C2412_DMAREQSEL_SRC(17)
  326. #define S3C2412_DMAREQSEL_XDREQ1 S3C2412_DMAREQSEL_SRC(18)
  327. #define S3C2412_DMAREQSEL_UART0_0 S3C2412_DMAREQSEL_SRC(19)
  328. #define S3C2412_DMAREQSEL_UART0_1 S3C2412_DMAREQSEL_SRC(20)
  329. #define S3C2412_DMAREQSEL_UART1_0 S3C2412_DMAREQSEL_SRC(21)
  330. #define S3C2412_DMAREQSEL_UART1_1 S3C2412_DMAREQSEL_SRC(22)
  331. #define S3C2412_DMAREQSEL_UART2_0 S3C2412_DMAREQSEL_SRC(23)
  332. #define S3C2412_DMAREQSEL_UART2_1 S3C2412_DMAREQSEL_SRC(24)
  333. #endif
  334. #endif /* __ASM_ARCH_DMA_H */