dma.h 13 KB

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