intel_mid_dma_regs.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * intel_mid_dma_regs.h - Intel MID DMA Drivers
  3. *
  4. * Copyright (C) 2008-10 Intel Corp
  5. * Author: Vinod Koul <vinod.koul@intel.com>
  6. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  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 as published by
  10. * the Free Software Foundation; version 2 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  20. *
  21. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  22. *
  23. *
  24. */
  25. #ifndef __INTEL_MID_DMAC_REGS_H__
  26. #define __INTEL_MID_DMAC_REGS_H__
  27. #include <linux/dmaengine.h>
  28. #include <linux/dmapool.h>
  29. #include <linux/pci_ids.h>
  30. #define INTEL_MID_DMA_DRIVER_VERSION "1.0.5"
  31. #define REG_BIT0 0x00000001
  32. #define REG_BIT8 0x00000100
  33. #define UNMASK_INTR_REG(chan_num) \
  34. ((REG_BIT0 << chan_num) | (REG_BIT8 << chan_num))
  35. #define MASK_INTR_REG(chan_num) (REG_BIT8 << chan_num)
  36. #define ENABLE_CHANNEL(chan_num) \
  37. ((REG_BIT0 << chan_num) | (REG_BIT8 << chan_num))
  38. #define DESCS_PER_CHANNEL 16
  39. /*DMA Registers*/
  40. /*registers associated with channel programming*/
  41. #define DMA_REG_SIZE 0x400
  42. #define DMA_CH_SIZE 0x58
  43. /*CH X REG = (DMA_CH_SIZE)*CH_NO + REG*/
  44. #define SAR 0x00 /* Source Address Register*/
  45. #define DAR 0x08 /* Destination Address Register*/
  46. #define CTL_LOW 0x18 /* Control Register*/
  47. #define CTL_HIGH 0x1C /* Control Register*/
  48. #define CFG_LOW 0x40 /* Configuration Register Low*/
  49. #define CFG_HIGH 0x44 /* Configuration Register high*/
  50. #define STATUS_TFR 0x2E8
  51. #define STATUS_BLOCK 0x2F0
  52. #define STATUS_ERR 0x308
  53. #define RAW_TFR 0x2C0
  54. #define RAW_BLOCK 0x2C8
  55. #define RAW_ERR 0x2E0
  56. #define MASK_TFR 0x310
  57. #define MASK_BLOCK 0x318
  58. #define MASK_SRC_TRAN 0x320
  59. #define MASK_DST_TRAN 0x328
  60. #define MASK_ERR 0x330
  61. #define CLEAR_TFR 0x338
  62. #define CLEAR_BLOCK 0x340
  63. #define CLEAR_SRC_TRAN 0x348
  64. #define CLEAR_DST_TRAN 0x350
  65. #define CLEAR_ERR 0x358
  66. #define INTR_STATUS 0x360
  67. #define DMA_CFG 0x398
  68. #define DMA_CHAN_EN 0x3A0
  69. /*DMA channel control registers*/
  70. union intel_mid_dma_ctl_lo {
  71. struct {
  72. u32 int_en:1; /*enable or disable interrupts*/
  73. /*should be 0*/
  74. u32 dst_tr_width:3; /*destination transfer width*/
  75. /*usually 32 bits = 010*/
  76. u32 src_tr_width:3; /*source transfer width*/
  77. /*usually 32 bits = 010*/
  78. u32 dinc:2; /*destination address inc/dec*/
  79. /*For mem:INC=00, Periphral NoINC=11*/
  80. u32 sinc:2; /*source address inc or dec, as above*/
  81. u32 dst_msize:3; /*destination burst transaction length*/
  82. /*always = 16 ie 011*/
  83. u32 src_msize:3; /*source burst transaction length*/
  84. /*always = 16 ie 011*/
  85. u32 reser1:3;
  86. u32 tt_fc:3; /*transfer type and flow controller*/
  87. /*M-M = 000
  88. P-M = 010
  89. M-P = 001*/
  90. u32 dms:2; /*destination master select = 0*/
  91. u32 sms:2; /*source master select = 0*/
  92. u32 llp_dst_en:1; /*enable/disable destination LLP = 0*/
  93. u32 llp_src_en:1; /*enable/disable source LLP = 0*/
  94. u32 reser2:3;
  95. } ctlx;
  96. u32 ctl_lo;
  97. };
  98. union intel_mid_dma_ctl_hi {
  99. struct {
  100. u32 block_ts:12; /*block transfer size*/
  101. /*configured by DMAC*/
  102. u32 reser:20;
  103. } ctlx;
  104. u32 ctl_hi;
  105. };
  106. /*DMA channel configuration registers*/
  107. union intel_mid_dma_cfg_lo {
  108. struct {
  109. u32 reser1:5;
  110. u32 ch_prior:3; /*channel priority = 0*/
  111. u32 ch_susp:1; /*channel suspend = 0*/
  112. u32 fifo_empty:1; /*FIFO empty or not R bit = 0*/
  113. u32 hs_sel_dst:1; /*select HW/SW destn handshaking*/
  114. /*HW = 0, SW = 1*/
  115. u32 hs_sel_src:1; /*select HW/SW src handshaking*/
  116. u32 reser2:6;
  117. u32 dst_hs_pol:1; /*dest HS interface polarity*/
  118. u32 src_hs_pol:1; /*src HS interface polarity*/
  119. u32 max_abrst:10; /*max AMBA burst len = 0 (no sw limit*/
  120. u32 reload_src:1; /*auto reload src addr =1 if src is P*/
  121. u32 reload_dst:1; /*AR destn addr =1 if dstn is P*/
  122. } cfgx;
  123. u32 cfg_lo;
  124. };
  125. union intel_mid_dma_cfg_hi {
  126. struct {
  127. u32 fcmode:1; /*flow control mode = 1*/
  128. u32 fifo_mode:1; /*FIFO mode select = 1*/
  129. u32 protctl:3; /*protection control = 0*/
  130. u32 rsvd:2;
  131. u32 src_per:4; /*src hw HS interface*/
  132. u32 dst_per:4; /*dstn hw HS interface*/
  133. u32 reser2:17;
  134. } cfgx;
  135. u32 cfg_hi;
  136. };
  137. /**
  138. * struct intel_mid_dma_chan - internal mid representation of a DMA channel
  139. * @chan: dma_chan strcture represetation for mid chan
  140. * @ch_regs: MMIO register space pointer to channel register
  141. * @dma_base: MMIO register space DMA engine base pointer
  142. * @ch_id: DMA channel id
  143. * @lock: channel spinlock
  144. * @completed: DMA cookie
  145. * @active_list: current active descriptors
  146. * @queue: current queued up descriptors
  147. * @free_list: current free descriptors
  148. * @slave: dma slave struture
  149. * @descs_allocated: total number of decsiptors allocated
  150. * @dma: dma device struture pointer
  151. * @in_use: bool representing if ch is in use or not
  152. */
  153. struct intel_mid_dma_chan {
  154. struct dma_chan chan;
  155. void __iomem *ch_regs;
  156. void __iomem *dma_base;
  157. int ch_id;
  158. spinlock_t lock;
  159. dma_cookie_t completed;
  160. struct list_head active_list;
  161. struct list_head queue;
  162. struct list_head free_list;
  163. struct intel_mid_dma_slave *slave;
  164. unsigned int descs_allocated;
  165. struct middma_device *dma;
  166. bool in_use;
  167. };
  168. static inline struct intel_mid_dma_chan *to_intel_mid_dma_chan(
  169. struct dma_chan *chan)
  170. {
  171. return container_of(chan, struct intel_mid_dma_chan, chan);
  172. }
  173. /**
  174. * struct middma_device - internal representation of a DMA device
  175. * @pdev: PCI device
  176. * @dma_base: MMIO register space pointer of DMA
  177. * @dma_pool: for allocating DMA descriptors
  178. * @common: embedded struct dma_device
  179. * @tasklet: dma tasklet for processing interrupts
  180. * @ch: per channel data
  181. * @pci_id: DMA device PCI ID
  182. * @intr_mask: Interrupt mask to be used
  183. * @mask_reg: MMIO register for periphral mask
  184. * @chan_base: Base ch index (read from driver data)
  185. * @max_chan: max number of chs supported (from drv_data)
  186. * @block_size: Block size of DMA transfer supported (from drv_data)
  187. * @pimr_mask: MMIO register addr for periphral interrupt (from drv_data)
  188. */
  189. struct middma_device {
  190. struct pci_dev *pdev;
  191. void __iomem *dma_base;
  192. struct pci_pool *dma_pool;
  193. struct dma_device common;
  194. struct tasklet_struct tasklet;
  195. struct intel_mid_dma_chan ch[MAX_CHAN];
  196. unsigned int pci_id;
  197. unsigned int intr_mask;
  198. void __iomem *mask_reg;
  199. int chan_base;
  200. int max_chan;
  201. int block_size;
  202. unsigned int pimr_mask;
  203. };
  204. static inline struct middma_device *to_middma_device(struct dma_device *common)
  205. {
  206. return container_of(common, struct middma_device, common);
  207. }
  208. struct intel_mid_dma_desc {
  209. void __iomem *block; /*ch ptr*/
  210. struct list_head desc_node;
  211. struct dma_async_tx_descriptor txd;
  212. size_t len;
  213. dma_addr_t sar;
  214. dma_addr_t dar;
  215. u32 cfg_hi;
  216. u32 cfg_lo;
  217. u32 ctl_lo;
  218. u32 ctl_hi;
  219. dma_addr_t next;
  220. enum dma_data_direction dirn;
  221. enum dma_status status;
  222. enum intel_mid_dma_width width; /*width of DMA txn*/
  223. enum intel_mid_dma_mode cfg_mode; /*mode configuration*/
  224. };
  225. static inline int test_ch_en(void __iomem *dma, u32 ch_no)
  226. {
  227. u32 en_reg = ioread32(dma + DMA_CHAN_EN);
  228. return (en_reg >> ch_no) & 0x1;
  229. }
  230. static inline struct intel_mid_dma_desc *to_intel_mid_dma_desc
  231. (struct dma_async_tx_descriptor *txd)
  232. {
  233. return container_of(txd, struct intel_mid_dma_desc, txd);
  234. }
  235. #endif /*__INTEL_MID_DMAC_REGS_H__*/