intel_mid_dma_regs.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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.1.0"
  31. #define REG_BIT0 0x00000001
  32. #define REG_BIT8 0x00000100
  33. #define INT_MASK_WE 0x8
  34. #define CLEAR_DONE 0xFFFFEFFF
  35. #define UNMASK_INTR_REG(chan_num) \
  36. ((REG_BIT0 << chan_num) | (REG_BIT8 << chan_num))
  37. #define MASK_INTR_REG(chan_num) (REG_BIT8 << chan_num)
  38. #define ENABLE_CHANNEL(chan_num) \
  39. ((REG_BIT0 << chan_num) | (REG_BIT8 << chan_num))
  40. #define DISABLE_CHANNEL(chan_num) \
  41. (REG_BIT8 << chan_num)
  42. #define DESCS_PER_CHANNEL 16
  43. /*DMA Registers*/
  44. /*registers associated with channel programming*/
  45. #define DMA_REG_SIZE 0x400
  46. #define DMA_CH_SIZE 0x58
  47. /*CH X REG = (DMA_CH_SIZE)*CH_NO + REG*/
  48. #define SAR 0x00 /* Source Address Register*/
  49. #define DAR 0x08 /* Destination Address Register*/
  50. #define LLP 0x10 /* Linked List Pointer Register*/
  51. #define CTL_LOW 0x18 /* Control Register*/
  52. #define CTL_HIGH 0x1C /* Control Register*/
  53. #define CFG_LOW 0x40 /* Configuration Register Low*/
  54. #define CFG_HIGH 0x44 /* Configuration Register high*/
  55. #define STATUS_TFR 0x2E8
  56. #define STATUS_BLOCK 0x2F0
  57. #define STATUS_ERR 0x308
  58. #define RAW_TFR 0x2C0
  59. #define RAW_BLOCK 0x2C8
  60. #define RAW_ERR 0x2E0
  61. #define MASK_TFR 0x310
  62. #define MASK_BLOCK 0x318
  63. #define MASK_SRC_TRAN 0x320
  64. #define MASK_DST_TRAN 0x328
  65. #define MASK_ERR 0x330
  66. #define CLEAR_TFR 0x338
  67. #define CLEAR_BLOCK 0x340
  68. #define CLEAR_SRC_TRAN 0x348
  69. #define CLEAR_DST_TRAN 0x350
  70. #define CLEAR_ERR 0x358
  71. #define INTR_STATUS 0x360
  72. #define DMA_CFG 0x398
  73. #define DMA_CHAN_EN 0x3A0
  74. /*DMA channel control registers*/
  75. union intel_mid_dma_ctl_lo {
  76. struct {
  77. u32 int_en:1; /*enable or disable interrupts*/
  78. /*should be 0*/
  79. u32 dst_tr_width:3; /*destination transfer width*/
  80. /*usually 32 bits = 010*/
  81. u32 src_tr_width:3; /*source transfer width*/
  82. /*usually 32 bits = 010*/
  83. u32 dinc:2; /*destination address inc/dec*/
  84. /*For mem:INC=00, Periphral NoINC=11*/
  85. u32 sinc:2; /*source address inc or dec, as above*/
  86. u32 dst_msize:3; /*destination burst transaction length*/
  87. /*always = 16 ie 011*/
  88. u32 src_msize:3; /*source burst transaction length*/
  89. /*always = 16 ie 011*/
  90. u32 reser1:3;
  91. u32 tt_fc:3; /*transfer type and flow controller*/
  92. /*M-M = 000
  93. P-M = 010
  94. M-P = 001*/
  95. u32 dms:2; /*destination master select = 0*/
  96. u32 sms:2; /*source master select = 0*/
  97. u32 llp_dst_en:1; /*enable/disable destination LLP = 0*/
  98. u32 llp_src_en:1; /*enable/disable source LLP = 0*/
  99. u32 reser2:3;
  100. } ctlx;
  101. u32 ctl_lo;
  102. };
  103. union intel_mid_dma_ctl_hi {
  104. struct {
  105. u32 block_ts:12; /*block transfer size*/
  106. u32 done:1; /*Done - updated by DMAC*/
  107. u32 reser:19; /*configured by DMAC*/
  108. } ctlx;
  109. u32 ctl_hi;
  110. };
  111. /*DMA channel configuration registers*/
  112. union intel_mid_dma_cfg_lo {
  113. struct {
  114. u32 reser1:5;
  115. u32 ch_prior:3; /*channel priority = 0*/
  116. u32 ch_susp:1; /*channel suspend = 0*/
  117. u32 fifo_empty:1; /*FIFO empty or not R bit = 0*/
  118. u32 hs_sel_dst:1; /*select HW/SW destn handshaking*/
  119. /*HW = 0, SW = 1*/
  120. u32 hs_sel_src:1; /*select HW/SW src handshaking*/
  121. u32 reser2:6;
  122. u32 dst_hs_pol:1; /*dest HS interface polarity*/
  123. u32 src_hs_pol:1; /*src HS interface polarity*/
  124. u32 max_abrst:10; /*max AMBA burst len = 0 (no sw limit*/
  125. u32 reload_src:1; /*auto reload src addr =1 if src is P*/
  126. u32 reload_dst:1; /*AR destn addr =1 if dstn is P*/
  127. } cfgx;
  128. u32 cfg_lo;
  129. };
  130. union intel_mid_dma_cfg_hi {
  131. struct {
  132. u32 fcmode:1; /*flow control mode = 1*/
  133. u32 fifo_mode:1; /*FIFO mode select = 1*/
  134. u32 protctl:3; /*protection control = 0*/
  135. u32 rsvd:2;
  136. u32 src_per:4; /*src hw HS interface*/
  137. u32 dst_per:4; /*dstn hw HS interface*/
  138. u32 reser2:17;
  139. } cfgx;
  140. u32 cfg_hi;
  141. };
  142. /**
  143. * struct intel_mid_dma_chan - internal mid representation of a DMA channel
  144. * @chan: dma_chan strcture represetation for mid chan
  145. * @ch_regs: MMIO register space pointer to channel register
  146. * @dma_base: MMIO register space DMA engine base pointer
  147. * @ch_id: DMA channel id
  148. * @lock: channel spinlock
  149. * @active_list: current active descriptors
  150. * @queue: current queued up descriptors
  151. * @free_list: current free descriptors
  152. * @slave: dma slave struture
  153. * @descs_allocated: total number of decsiptors allocated
  154. * @dma: dma device struture pointer
  155. * @busy: bool representing if ch is busy (active txn) or not
  156. * @in_use: bool representing if ch is in use or not
  157. * @raw_tfr: raw trf interrupt received
  158. * @raw_block: raw block interrupt received
  159. */
  160. struct intel_mid_dma_chan {
  161. struct dma_chan chan;
  162. void __iomem *ch_regs;
  163. void __iomem *dma_base;
  164. int ch_id;
  165. spinlock_t lock;
  166. struct list_head active_list;
  167. struct list_head queue;
  168. struct list_head free_list;
  169. unsigned int descs_allocated;
  170. struct middma_device *dma;
  171. bool busy;
  172. bool in_use;
  173. u32 raw_tfr;
  174. u32 raw_block;
  175. struct intel_mid_dma_slave *mid_slave;
  176. };
  177. static inline struct intel_mid_dma_chan *to_intel_mid_dma_chan(
  178. struct dma_chan *chan)
  179. {
  180. return container_of(chan, struct intel_mid_dma_chan, chan);
  181. }
  182. enum intel_mid_dma_state {
  183. RUNNING = 0,
  184. SUSPENDED,
  185. };
  186. /**
  187. * struct middma_device - internal representation of a DMA device
  188. * @pdev: PCI device
  189. * @dma_base: MMIO register space pointer of DMA
  190. * @dma_pool: for allocating DMA descriptors
  191. * @common: embedded struct dma_device
  192. * @tasklet: dma tasklet for processing interrupts
  193. * @ch: per channel data
  194. * @pci_id: DMA device PCI ID
  195. * @intr_mask: Interrupt mask to be used
  196. * @mask_reg: MMIO register for periphral mask
  197. * @chan_base: Base ch index (read from driver data)
  198. * @max_chan: max number of chs supported (from drv_data)
  199. * @block_size: Block size of DMA transfer supported (from drv_data)
  200. * @pimr_mask: MMIO register addr for periphral interrupt (from drv_data)
  201. * @state: dma PM device state
  202. */
  203. struct middma_device {
  204. struct pci_dev *pdev;
  205. void __iomem *dma_base;
  206. struct pci_pool *dma_pool;
  207. struct dma_device common;
  208. struct tasklet_struct tasklet;
  209. struct intel_mid_dma_chan ch[MAX_CHAN];
  210. unsigned int pci_id;
  211. unsigned int intr_mask;
  212. void __iomem *mask_reg;
  213. int chan_base;
  214. int max_chan;
  215. int block_size;
  216. unsigned int pimr_mask;
  217. enum intel_mid_dma_state state;
  218. };
  219. static inline struct middma_device *to_middma_device(struct dma_device *common)
  220. {
  221. return container_of(common, struct middma_device, common);
  222. }
  223. struct intel_mid_dma_desc {
  224. void __iomem *block; /*ch ptr*/
  225. struct list_head desc_node;
  226. struct dma_async_tx_descriptor txd;
  227. size_t len;
  228. dma_addr_t sar;
  229. dma_addr_t dar;
  230. u32 cfg_hi;
  231. u32 cfg_lo;
  232. u32 ctl_lo;
  233. u32 ctl_hi;
  234. struct pci_pool *lli_pool;
  235. struct intel_mid_dma_lli *lli;
  236. dma_addr_t lli_phys;
  237. unsigned int lli_length;
  238. unsigned int current_lli;
  239. dma_addr_t next;
  240. enum dma_transfer_direction dirn;
  241. enum dma_status status;
  242. enum dma_slave_buswidth width; /*width of DMA txn*/
  243. enum intel_mid_dma_mode cfg_mode; /*mode configuration*/
  244. };
  245. struct intel_mid_dma_lli {
  246. dma_addr_t sar;
  247. dma_addr_t dar;
  248. dma_addr_t llp;
  249. u32 ctl_lo;
  250. u32 ctl_hi;
  251. } __attribute__ ((packed));
  252. static inline int test_ch_en(void __iomem *dma, u32 ch_no)
  253. {
  254. u32 en_reg = ioread32(dma + DMA_CHAN_EN);
  255. return (en_reg >> ch_no) & 0x1;
  256. }
  257. static inline struct intel_mid_dma_desc *to_intel_mid_dma_desc
  258. (struct dma_async_tx_descriptor *txd)
  259. {
  260. return container_of(txd, struct intel_mid_dma_desc, txd);
  261. }
  262. static inline struct intel_mid_dma_slave *to_intel_mid_dma_slave
  263. (struct dma_slave_config *slave)
  264. {
  265. return container_of(slave, struct intel_mid_dma_slave, dma_slave);
  266. }
  267. int dma_resume(struct device *dev);
  268. #endif /*__INTEL_MID_DMAC_REGS_H__*/