dma.h 13 KB

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