fsldma.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /*
  2. * Copyright (C) 2007 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. /* Special MR definition for MPC8349 */
  37. #define FSL_DMA_MR_EOTIE 0x00000080
  38. #define FSL_DMA_SR_CH 0x00000020
  39. #define FSL_DMA_SR_PE 0x00000010
  40. #define FSL_DMA_SR_CB 0x00000004
  41. #define FSL_DMA_SR_TE 0x00000080
  42. #define FSL_DMA_SR_EOSI 0x00000002
  43. #define FSL_DMA_SR_EOLSI 0x00000001
  44. #define FSL_DMA_SR_EOCDI 0x00000001
  45. #define FSL_DMA_SR_EOLNI 0x00000008
  46. #define FSL_DMA_SATR_SBPATMU 0x20000000
  47. #define FSL_DMA_SATR_STRANSINT_RIO 0x00c00000
  48. #define FSL_DMA_SATR_SREADTYPE_SNOOP_READ 0x00050000
  49. #define FSL_DMA_SATR_SREADTYPE_BP_IORH 0x00020000
  50. #define FSL_DMA_SATR_SREADTYPE_BP_NREAD 0x00040000
  51. #define FSL_DMA_SATR_SREADTYPE_BP_MREAD 0x00070000
  52. #define FSL_DMA_DATR_DBPATMU 0x20000000
  53. #define FSL_DMA_DATR_DTRANSINT_RIO 0x00c00000
  54. #define FSL_DMA_DATR_DWRITETYPE_SNOOP_WRITE 0x00050000
  55. #define FSL_DMA_DATR_DWRITETYPE_BP_FLUSH 0x00010000
  56. #define FSL_DMA_EOL ((u64)0x1)
  57. #define FSL_DMA_SNEN ((u64)0x10)
  58. #define FSL_DMA_EOSIE 0x8
  59. #define FSL_DMA_NLDA_MASK (~(u64)0x1f)
  60. #define FSL_DMA_BCR_MAX_CNT 0x03ffffffu
  61. #define FSL_DMA_DGSR_TE 0x80
  62. #define FSL_DMA_DGSR_CH 0x20
  63. #define FSL_DMA_DGSR_PE 0x10
  64. #define FSL_DMA_DGSR_EOLNI 0x08
  65. #define FSL_DMA_DGSR_CB 0x04
  66. #define FSL_DMA_DGSR_EOSI 0x02
  67. #define FSL_DMA_DGSR_EOLSI 0x01
  68. struct fsl_dma_ld_hw {
  69. u64 __bitwise src_addr;
  70. u64 __bitwise dst_addr;
  71. u64 __bitwise next_ln_addr;
  72. u32 __bitwise count;
  73. u32 __bitwise reserve;
  74. } __attribute__((aligned(32)));
  75. struct fsl_desc_sw {
  76. struct fsl_dma_ld_hw hw;
  77. struct list_head node;
  78. struct dma_async_tx_descriptor async_tx;
  79. struct list_head *ld;
  80. void *priv;
  81. } __attribute__((aligned(32)));
  82. struct fsl_dma_chan_regs {
  83. u32 __bitwise mr; /* 0x00 - Mode Register */
  84. u32 __bitwise sr; /* 0x04 - Status Register */
  85. u64 __bitwise cdar; /* 0x08 - Current descriptor address register */
  86. u64 __bitwise sar; /* 0x10 - Source Address Register */
  87. u64 __bitwise dar; /* 0x18 - Destination Address Register */
  88. u32 __bitwise bcr; /* 0x20 - Byte Count Register */
  89. u64 __bitwise ndar; /* 0x24 - Next Descriptor Address Register */
  90. };
  91. struct fsl_dma_chan;
  92. #define FSL_DMA_MAX_CHANS_PER_DEVICE 4
  93. struct fsl_dma_device {
  94. void __iomem *reg_base; /* DGSR register base */
  95. struct resource reg; /* Resource for register */
  96. struct device *dev;
  97. struct dma_device common;
  98. struct fsl_dma_chan *chan[FSL_DMA_MAX_CHANS_PER_DEVICE];
  99. u32 feature; /* The same as DMA channels */
  100. };
  101. /* Define macros for fsl_dma_chan->feature property */
  102. #define FSL_DMA_LITTLE_ENDIAN 0x00000000
  103. #define FSL_DMA_BIG_ENDIAN 0x00000001
  104. #define FSL_DMA_IP_MASK 0x00000ff0
  105. #define FSL_DMA_IP_85XX 0x00000010
  106. #define FSL_DMA_IP_83XX 0x00000020
  107. #define FSL_DMA_CHAN_PAUSE_EXT 0x00001000
  108. #define FSL_DMA_CHAN_START_EXT 0x00002000
  109. struct fsl_dma_chan {
  110. struct fsl_dma_chan_regs __iomem *reg_base;
  111. dma_cookie_t completed_cookie; /* The maximum cookie completed */
  112. spinlock_t desc_lock; /* Descriptor operation lock */
  113. struct list_head ld_queue; /* Link descriptors queue */
  114. struct dma_chan common; /* DMA common channel */
  115. struct dma_pool *desc_pool; /* Descriptors pool */
  116. struct device *dev; /* Channel device */
  117. struct resource reg; /* Resource for register */
  118. int irq; /* Channel IRQ */
  119. int id; /* Raw id of this channel */
  120. struct tasklet_struct tasklet;
  121. u32 feature;
  122. void (*toggle_ext_pause)(struct fsl_dma_chan *fsl_chan, int size);
  123. void (*toggle_ext_start)(struct fsl_dma_chan *fsl_chan, int enable);
  124. void (*set_src_loop_size)(struct fsl_dma_chan *fsl_chan, int size);
  125. void (*set_dest_loop_size)(struct fsl_dma_chan *fsl_chan, int size);
  126. };
  127. #define to_fsl_chan(chan) container_of(chan, struct fsl_dma_chan, common)
  128. #define to_fsl_desc(lh) container_of(lh, struct fsl_desc_sw, node)
  129. #define tx_to_fsl_desc(tx) container_of(tx, struct fsl_desc_sw, async_tx)
  130. #ifndef __powerpc64__
  131. static u64 in_be64(const u64 __iomem *addr)
  132. {
  133. return ((u64)in_be32((u32 *)addr) << 32) | (in_be32((u32 *)addr + 1));
  134. }
  135. static void out_be64(u64 __iomem *addr, u64 val)
  136. {
  137. out_be32((u32 *)addr, val >> 32);
  138. out_be32((u32 *)addr + 1, (u32)val);
  139. }
  140. /* There is no asm instructions for 64 bits reverse loads and stores */
  141. static u64 in_le64(const u64 __iomem *addr)
  142. {
  143. return ((u64)in_le32((u32 *)addr + 1) << 32) | (in_le32((u32 *)addr));
  144. }
  145. static void out_le64(u64 __iomem *addr, u64 val)
  146. {
  147. out_le32((u32 *)addr + 1, val >> 32);
  148. out_le32((u32 *)addr, (u32)val);
  149. }
  150. #endif
  151. #define DMA_IN(fsl_chan, addr, width) \
  152. (((fsl_chan)->feature & FSL_DMA_BIG_ENDIAN) ? \
  153. in_be##width(addr) : in_le##width(addr))
  154. #define DMA_OUT(fsl_chan, addr, val, width) \
  155. (((fsl_chan)->feature & FSL_DMA_BIG_ENDIAN) ? \
  156. out_be##width(addr, val) : out_le##width(addr, val))
  157. #define DMA_TO_CPU(fsl_chan, d, width) \
  158. (((fsl_chan)->feature & FSL_DMA_BIG_ENDIAN) ? \
  159. be##width##_to_cpu(d) : le##width##_to_cpu(d))
  160. #define CPU_TO_DMA(fsl_chan, c, width) \
  161. (((fsl_chan)->feature & FSL_DMA_BIG_ENDIAN) ? \
  162. cpu_to_be##width(c) : cpu_to_le##width(c))
  163. #endif /* __DMA_FSLDMA_H */