fsldma.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Copyright (C) 2007-2010 Freescale Semiconductor, Inc. All rights reserved.
  3. *
  4. * Author:
  5. * Zhang Wei <wei.zhang@freescale.com>, Jul 2007
  6. * Ebony Zhu <ebony.zhu@freescale.com>, May 2007
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. */
  14. #ifndef __DMA_FSLDMA_H
  15. #define __DMA_FSLDMA_H
  16. #include <linux/device.h>
  17. #include <linux/dmapool.h>
  18. #include <linux/dmaengine.h>
  19. /* Define data structures needed by Freescale
  20. * MPC8540 and MPC8349 DMA controller.
  21. */
  22. #define FSL_DMA_MR_CS 0x00000001
  23. #define FSL_DMA_MR_CC 0x00000002
  24. #define FSL_DMA_MR_CA 0x00000008
  25. #define FSL_DMA_MR_EIE 0x00000040
  26. #define FSL_DMA_MR_XFE 0x00000020
  27. #define FSL_DMA_MR_EOLNIE 0x00000100
  28. #define FSL_DMA_MR_EOLSIE 0x00000080
  29. #define FSL_DMA_MR_EOSIE 0x00000200
  30. #define FSL_DMA_MR_CDSM 0x00000010
  31. #define FSL_DMA_MR_CTM 0x00000004
  32. #define FSL_DMA_MR_EMP_EN 0x00200000
  33. #define FSL_DMA_MR_EMS_EN 0x00040000
  34. #define FSL_DMA_MR_DAHE 0x00002000
  35. #define FSL_DMA_MR_SAHE 0x00001000
  36. #define FSL_DMA_MR_SAHTS_MASK 0x0000C000
  37. #define FSL_DMA_MR_DAHTS_MASK 0x00030000
  38. #define FSL_DMA_MR_BWC_MASK 0x0f000000
  39. /*
  40. * Bandwidth/pause control determines how many bytes a given
  41. * channel is allowed to transfer before the DMA engine pauses
  42. * the current channel and switches to the next channel
  43. */
  44. #define FSL_DMA_MR_BWC 0x0A000000
  45. /* Special MR definition for MPC8349 */
  46. #define FSL_DMA_MR_EOTIE 0x00000080
  47. #define FSL_DMA_MR_PRC_RM 0x00000800
  48. #define FSL_DMA_SR_CH 0x00000020
  49. #define FSL_DMA_SR_PE 0x00000010
  50. #define FSL_DMA_SR_CB 0x00000004
  51. #define FSL_DMA_SR_TE 0x00000080
  52. #define FSL_DMA_SR_EOSI 0x00000002
  53. #define FSL_DMA_SR_EOLSI 0x00000001
  54. #define FSL_DMA_SR_EOCDI 0x00000001
  55. #define FSL_DMA_SR_EOLNI 0x00000008
  56. #define FSL_DMA_SATR_SBPATMU 0x20000000
  57. #define FSL_DMA_SATR_STRANSINT_RIO 0x00c00000
  58. #define FSL_DMA_SATR_SREADTYPE_SNOOP_READ 0x00050000
  59. #define FSL_DMA_SATR_SREADTYPE_BP_IORH 0x00020000
  60. #define FSL_DMA_SATR_SREADTYPE_BP_NREAD 0x00040000
  61. #define FSL_DMA_SATR_SREADTYPE_BP_MREAD 0x00070000
  62. #define FSL_DMA_DATR_DBPATMU 0x20000000
  63. #define FSL_DMA_DATR_DTRANSINT_RIO 0x00c00000
  64. #define FSL_DMA_DATR_DWRITETYPE_SNOOP_WRITE 0x00050000
  65. #define FSL_DMA_DATR_DWRITETYPE_BP_FLUSH 0x00010000
  66. #define FSL_DMA_EOL ((u64)0x1)
  67. #define FSL_DMA_SNEN ((u64)0x10)
  68. #define FSL_DMA_EOSIE 0x8
  69. #define FSL_DMA_NLDA_MASK (~(u64)0x1f)
  70. #define FSL_DMA_BCR_MAX_CNT 0x03ffffffu
  71. #define FSL_DMA_DGSR_TE 0x80
  72. #define FSL_DMA_DGSR_CH 0x20
  73. #define FSL_DMA_DGSR_PE 0x10
  74. #define FSL_DMA_DGSR_EOLNI 0x08
  75. #define FSL_DMA_DGSR_CB 0x04
  76. #define FSL_DMA_DGSR_EOSI 0x02
  77. #define FSL_DMA_DGSR_EOLSI 0x01
  78. #define FSL_DMA_BUSWIDTHS (BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \
  79. BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \
  80. BIT(DMA_SLAVE_BUSWIDTH_4_BYTES) | \
  81. BIT(DMA_SLAVE_BUSWIDTH_8_BYTES))
  82. typedef u64 __bitwise v64;
  83. typedef u32 __bitwise v32;
  84. struct fsl_dma_ld_hw {
  85. v64 src_addr;
  86. v64 dst_addr;
  87. v64 next_ln_addr;
  88. v32 count;
  89. v32 reserve;
  90. } __attribute__((aligned(32)));
  91. struct fsl_desc_sw {
  92. struct fsl_dma_ld_hw hw;
  93. struct list_head node;
  94. struct list_head tx_list;
  95. struct dma_async_tx_descriptor async_tx;
  96. } __attribute__((aligned(32)));
  97. struct fsldma_chan_regs {
  98. u32 mr; /* 0x00 - Mode Register */
  99. u32 sr; /* 0x04 - Status Register */
  100. u64 cdar; /* 0x08 - Current descriptor address register */
  101. u64 sar; /* 0x10 - Source Address Register */
  102. u64 dar; /* 0x18 - Destination Address Register */
  103. u32 bcr; /* 0x20 - Byte Count Register */
  104. u64 ndar; /* 0x24 - Next Descriptor Address Register */
  105. };
  106. struct fsldma_chan;
  107. #define FSL_DMA_MAX_CHANS_PER_DEVICE 8
  108. struct fsldma_device {
  109. void __iomem *regs; /* DGSR register base */
  110. struct device *dev;
  111. struct dma_device common;
  112. struct fsldma_chan *chan[FSL_DMA_MAX_CHANS_PER_DEVICE];
  113. u32 feature; /* The same as DMA channels */
  114. int irq; /* Channel IRQ */
  115. };
  116. /* Define macros for fsldma_chan->feature property */
  117. #define FSL_DMA_LITTLE_ENDIAN 0x00000000
  118. #define FSL_DMA_BIG_ENDIAN 0x00000001
  119. #define FSL_DMA_IP_MASK 0x00000ff0
  120. #define FSL_DMA_IP_85XX 0x00000010
  121. #define FSL_DMA_IP_83XX 0x00000020
  122. #define FSL_DMA_CHAN_PAUSE_EXT 0x00001000
  123. #define FSL_DMA_CHAN_START_EXT 0x00002000
  124. #ifdef CONFIG_PM
  125. struct fsldma_chan_regs_save {
  126. u32 mr;
  127. };
  128. enum fsldma_pm_state {
  129. RUNNING = 0,
  130. SUSPENDED,
  131. };
  132. #endif
  133. struct fsldma_chan {
  134. char name[8]; /* Channel name */
  135. struct fsldma_chan_regs __iomem *regs;
  136. spinlock_t desc_lock; /* Descriptor operation lock */
  137. /*
  138. * Descriptors which are queued to run, but have not yet been
  139. * submitted to the hardware for execution
  140. */
  141. struct list_head ld_pending;
  142. /*
  143. * Descriptors which are currently being executed by the hardware
  144. */
  145. struct list_head ld_running;
  146. /*
  147. * Descriptors which have finished execution by the hardware. These
  148. * descriptors have already had their cleanup actions run. They are
  149. * waiting for the ACK bit to be set by the async_tx API.
  150. */
  151. struct list_head ld_completed; /* Link descriptors queue */
  152. struct dma_chan common; /* DMA common channel */
  153. struct dma_pool *desc_pool; /* Descriptors pool */
  154. struct device *dev; /* Channel device */
  155. int irq; /* Channel IRQ */
  156. int id; /* Raw id of this channel */
  157. struct tasklet_struct tasklet;
  158. u32 feature;
  159. bool idle; /* DMA controller is idle */
  160. #ifdef CONFIG_PM
  161. struct fsldma_chan_regs_save regs_save;
  162. enum fsldma_pm_state pm_state;
  163. #endif
  164. void (*toggle_ext_pause)(struct fsldma_chan *fsl_chan, int enable);
  165. void (*toggle_ext_start)(struct fsldma_chan *fsl_chan, int enable);
  166. void (*set_src_loop_size)(struct fsldma_chan *fsl_chan, int size);
  167. void (*set_dst_loop_size)(struct fsldma_chan *fsl_chan, int size);
  168. void (*set_request_count)(struct fsldma_chan *fsl_chan, int size);
  169. };
  170. #define to_fsl_chan(chan) container_of(chan, struct fsldma_chan, common)
  171. #define to_fsl_desc(lh) container_of(lh, struct fsl_desc_sw, node)
  172. #define tx_to_fsl_desc(tx) container_of(tx, struct fsl_desc_sw, async_tx)
  173. #ifndef __powerpc64__
  174. static u64 in_be64(const u64 __iomem *addr)
  175. {
  176. return ((u64)in_be32((u32 __iomem *)addr) << 32) |
  177. (in_be32((u32 __iomem *)addr + 1));
  178. }
  179. static void out_be64(u64 __iomem *addr, u64 val)
  180. {
  181. out_be32((u32 __iomem *)addr, val >> 32);
  182. out_be32((u32 __iomem *)addr + 1, (u32)val);
  183. }
  184. /* There is no asm instructions for 64 bits reverse loads and stores */
  185. static u64 in_le64(const u64 __iomem *addr)
  186. {
  187. return ((u64)in_le32((u32 __iomem *)addr + 1) << 32) |
  188. (in_le32((u32 __iomem *)addr));
  189. }
  190. static void out_le64(u64 __iomem *addr, u64 val)
  191. {
  192. out_le32((u32 __iomem *)addr + 1, val >> 32);
  193. out_le32((u32 __iomem *)addr, (u32)val);
  194. }
  195. #endif
  196. #define DMA_IN(fsl_chan, addr, width) \
  197. (((fsl_chan)->feature & FSL_DMA_BIG_ENDIAN) ? \
  198. in_be##width(addr) : in_le##width(addr))
  199. #define DMA_OUT(fsl_chan, addr, val, width) \
  200. (((fsl_chan)->feature & FSL_DMA_BIG_ENDIAN) ? \
  201. out_be##width(addr, val) : out_le##width(addr, val))
  202. #define DMA_TO_CPU(fsl_chan, d, width) \
  203. (((fsl_chan)->feature & FSL_DMA_BIG_ENDIAN) ? \
  204. be##width##_to_cpu((__force __be##width)(v##width)d) : \
  205. le##width##_to_cpu((__force __le##width)(v##width)d))
  206. #define CPU_TO_DMA(fsl_chan, c, width) \
  207. (((fsl_chan)->feature & FSL_DMA_BIG_ENDIAN) ? \
  208. (__force v##width)cpu_to_be##width(c) : \
  209. (__force v##width)cpu_to_le##width(c))
  210. #endif /* __DMA_FSLDMA_H */