ste_dma40_ll.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2007-2010
  3. * Author: Per Friden <per.friden@stericsson.com> for ST-Ericsson SA
  4. * Author: Jonas Aaberg <jonas.aberg@stericsson.com> for ST-Ericsson SA
  5. * License terms: GNU General Public License (GPL) version 2
  6. */
  7. #ifndef STE_DMA40_LL_H
  8. #define STE_DMA40_LL_H
  9. #define D40_DREG_PCBASE 0x400
  10. #define D40_DREG_PCDELTA (8 * 4)
  11. #define D40_LLI_ALIGN 16 /* LLI alignment must be 16 bytes. */
  12. #define D40_LCPA_CHAN_SIZE 32
  13. #define D40_LCPA_CHAN_DST_DELTA 16
  14. #define D40_TYPE_TO_GROUP(type) (type / 16)
  15. #define D40_TYPE_TO_EVENT(type) (type % 16)
  16. /* Most bits of the CFG register are the same in log as in phy mode */
  17. #define D40_SREG_CFG_MST_POS 15
  18. #define D40_SREG_CFG_TIM_POS 14
  19. #define D40_SREG_CFG_EIM_POS 13
  20. #define D40_SREG_CFG_LOG_INCR_POS 12
  21. #define D40_SREG_CFG_PHY_PEN_POS 12
  22. #define D40_SREG_CFG_PSIZE_POS 10
  23. #define D40_SREG_CFG_ESIZE_POS 8
  24. #define D40_SREG_CFG_PRI_POS 7
  25. #define D40_SREG_CFG_LBE_POS 6
  26. #define D40_SREG_CFG_LOG_GIM_POS 5
  27. #define D40_SREG_CFG_LOG_MFU_POS 4
  28. #define D40_SREG_CFG_PHY_TM_POS 4
  29. #define D40_SREG_CFG_PHY_EVTL_POS 0
  30. /* Standard channel parameters - basic mode (element register) */
  31. #define D40_SREG_ELEM_PHY_ECNT_POS 16
  32. #define D40_SREG_ELEM_PHY_EIDX_POS 0
  33. #define D40_SREG_ELEM_PHY_ECNT_MASK (0xFFFF << D40_SREG_ELEM_PHY_ECNT_POS)
  34. /* Standard channel parameters - basic mode (Link register) */
  35. #define D40_SREG_LNK_PHY_TCP_POS 0
  36. #define D40_SREG_LNK_PHY_LMP_POS 1
  37. #define D40_SREG_LNK_PHY_PRE_POS 2
  38. /*
  39. * Source destination link address. Contains the
  40. * 29-bit byte word aligned address of the reload area.
  41. */
  42. #define D40_SREG_LNK_PHYS_LNK_MASK 0xFFFFFFF8UL
  43. /* Standard basic channel logical mode */
  44. /* Element register */
  45. #define D40_SREG_ELEM_LOG_ECNT_POS 16
  46. #define D40_SREG_ELEM_LOG_LIDX_POS 8
  47. #define D40_SREG_ELEM_LOG_LOS_POS 1
  48. #define D40_SREG_ELEM_LOG_TCP_POS 0
  49. #define D40_SREG_ELEM_LOG_LIDX_MASK (0xFF << D40_SREG_ELEM_LOG_LIDX_POS)
  50. /* Link register */
  51. #define D40_DEACTIVATE_EVENTLINE 0x0
  52. #define D40_ACTIVATE_EVENTLINE 0x1
  53. #define D40_EVENTLINE_POS(i) (2 * i)
  54. #define D40_EVENTLINE_MASK(i) (0x3 << D40_EVENTLINE_POS(i))
  55. /* Standard basic channel logical params in memory */
  56. /* LCSP0 */
  57. #define D40_MEM_LCSP0_ECNT_POS 16
  58. #define D40_MEM_LCSP0_SPTR_POS 0
  59. #define D40_MEM_LCSP0_ECNT_MASK (0xFFFF << D40_MEM_LCSP0_ECNT_POS)
  60. #define D40_MEM_LCSP0_SPTR_MASK (0xFFFF << D40_MEM_LCSP0_SPTR_POS)
  61. /* LCSP1 */
  62. #define D40_MEM_LCSP1_SPTR_POS 16
  63. #define D40_MEM_LCSP1_SCFG_MST_POS 15
  64. #define D40_MEM_LCSP1_SCFG_TIM_POS 14
  65. #define D40_MEM_LCSP1_SCFG_EIM_POS 13
  66. #define D40_MEM_LCSP1_SCFG_INCR_POS 12
  67. #define D40_MEM_LCSP1_SCFG_PSIZE_POS 10
  68. #define D40_MEM_LCSP1_SCFG_ESIZE_POS 8
  69. #define D40_MEM_LCSP1_SLOS_POS 1
  70. #define D40_MEM_LCSP1_STCP_POS 0
  71. #define D40_MEM_LCSP1_SPTR_MASK (0xFFFF << D40_MEM_LCSP1_SPTR_POS)
  72. #define D40_MEM_LCSP1_SCFG_TIM_MASK (0x1 << D40_MEM_LCSP1_SCFG_TIM_POS)
  73. #define D40_MEM_LCSP1_SCFG_INCR_MASK (0x1 << D40_MEM_LCSP1_SCFG_INCR_POS)
  74. #define D40_MEM_LCSP1_SCFG_PSIZE_MASK (0x3 << D40_MEM_LCSP1_SCFG_PSIZE_POS)
  75. #define D40_MEM_LCSP1_SLOS_MASK (0x7F << D40_MEM_LCSP1_SLOS_POS)
  76. #define D40_MEM_LCSP1_STCP_MASK (0x1 << D40_MEM_LCSP1_STCP_POS)
  77. /* LCSP2 */
  78. #define D40_MEM_LCSP2_ECNT_POS 16
  79. #define D40_MEM_LCSP2_ECNT_MASK (0xFFFF << D40_MEM_LCSP2_ECNT_POS)
  80. /* LCSP3 */
  81. #define D40_MEM_LCSP3_DCFG_MST_POS 15
  82. #define D40_MEM_LCSP3_DCFG_TIM_POS 14
  83. #define D40_MEM_LCSP3_DCFG_EIM_POS 13
  84. #define D40_MEM_LCSP3_DCFG_INCR_POS 12
  85. #define D40_MEM_LCSP3_DCFG_PSIZE_POS 10
  86. #define D40_MEM_LCSP3_DCFG_ESIZE_POS 8
  87. #define D40_MEM_LCSP3_DLOS_POS 1
  88. #define D40_MEM_LCSP3_DTCP_POS 0
  89. #define D40_MEM_LCSP3_DLOS_MASK (0x7F << D40_MEM_LCSP3_DLOS_POS)
  90. #define D40_MEM_LCSP3_DTCP_MASK (0x1 << D40_MEM_LCSP3_DTCP_POS)
  91. /* Standard channel parameter register offsets */
  92. #define D40_CHAN_REG_SSCFG 0x00
  93. #define D40_CHAN_REG_SSELT 0x04
  94. #define D40_CHAN_REG_SSPTR 0x08
  95. #define D40_CHAN_REG_SSLNK 0x0C
  96. #define D40_CHAN_REG_SDCFG 0x10
  97. #define D40_CHAN_REG_SDELT 0x14
  98. #define D40_CHAN_REG_SDPTR 0x18
  99. #define D40_CHAN_REG_SDLNK 0x1C
  100. /* DMA Register Offsets */
  101. #define D40_DREG_GCC 0x000
  102. #define D40_DREG_PRTYP 0x004
  103. #define D40_DREG_PRSME 0x008
  104. #define D40_DREG_PRSMO 0x00C
  105. #define D40_DREG_PRMSE 0x010
  106. #define D40_DREG_PRMSO 0x014
  107. #define D40_DREG_PRMOE 0x018
  108. #define D40_DREG_PRMOO 0x01C
  109. #define D40_DREG_PRMO_PCHAN_BASIC 0x1
  110. #define D40_DREG_PRMO_PCHAN_MODULO 0x2
  111. #define D40_DREG_PRMO_PCHAN_DOUBLE_DST 0x3
  112. #define D40_DREG_PRMO_LCHAN_SRC_PHY_DST_LOG 0x1
  113. #define D40_DREG_PRMO_LCHAN_SRC_LOG_DST_PHY 0x2
  114. #define D40_DREG_PRMO_LCHAN_SRC_LOG_DST_LOG 0x3
  115. #define D40_DREG_LCPA 0x020
  116. #define D40_DREG_LCLA 0x024
  117. #define D40_DREG_ACTIVE 0x050
  118. #define D40_DREG_ACTIVO 0x054
  119. #define D40_DREG_FSEB1 0x058
  120. #define D40_DREG_FSEB2 0x05C
  121. #define D40_DREG_PCMIS 0x060
  122. #define D40_DREG_PCICR 0x064
  123. #define D40_DREG_PCTIS 0x068
  124. #define D40_DREG_PCEIS 0x06C
  125. #define D40_DREG_LCMIS0 0x080
  126. #define D40_DREG_LCMIS1 0x084
  127. #define D40_DREG_LCMIS2 0x088
  128. #define D40_DREG_LCMIS3 0x08C
  129. #define D40_DREG_LCICR0 0x090
  130. #define D40_DREG_LCICR1 0x094
  131. #define D40_DREG_LCICR2 0x098
  132. #define D40_DREG_LCICR3 0x09C
  133. #define D40_DREG_LCTIS0 0x0A0
  134. #define D40_DREG_LCTIS1 0x0A4
  135. #define D40_DREG_LCTIS2 0x0A8
  136. #define D40_DREG_LCTIS3 0x0AC
  137. #define D40_DREG_LCEIS0 0x0B0
  138. #define D40_DREG_LCEIS1 0x0B4
  139. #define D40_DREG_LCEIS2 0x0B8
  140. #define D40_DREG_LCEIS3 0x0BC
  141. #define D40_DREG_STFU 0xFC8
  142. #define D40_DREG_ICFG 0xFCC
  143. #define D40_DREG_PERIPHID0 0xFE0
  144. #define D40_DREG_PERIPHID1 0xFE4
  145. #define D40_DREG_PERIPHID2 0xFE8
  146. #define D40_DREG_PERIPHID2_REV_POS 4
  147. #define D40_DREG_PERIPHID2_REV_MASK (0xf << D40_DREG_PERIPHID2_REV_POS)
  148. #define D40_DREG_PERIPHID2_DESIGNER_MASK 0xf
  149. #define D40_DREG_PERIPHID3 0xFEC
  150. #define D40_DREG_CELLID0 0xFF0
  151. #define D40_DREG_CELLID1 0xFF4
  152. #define D40_DREG_CELLID2 0xFF8
  153. #define D40_DREG_CELLID3 0xFFC
  154. /* LLI related structures */
  155. /**
  156. * struct d40_phy_lli - The basic configration register for each physical
  157. * channel.
  158. *
  159. * @reg_cfg: The configuration register.
  160. * @reg_elt: The element register.
  161. * @reg_ptr: The pointer register.
  162. * @reg_lnk: The link register.
  163. *
  164. * These registers are set up for both physical and logical transfers
  165. * Note that the bit in each register means differently in logical and
  166. * physical(standard) mode.
  167. *
  168. * This struct must be 16 bytes aligned, and only contain physical registers
  169. * since it will be directly accessed by the DMA.
  170. */
  171. struct d40_phy_lli {
  172. u32 reg_cfg;
  173. u32 reg_elt;
  174. u32 reg_ptr;
  175. u32 reg_lnk;
  176. };
  177. /**
  178. * struct d40_phy_lli_bidir - struct for a transfer.
  179. *
  180. * @src: Register settings for src channel.
  181. * @dst: Register settings for dst channel.
  182. *
  183. * All DMA transfers have a source and a destination.
  184. */
  185. struct d40_phy_lli_bidir {
  186. struct d40_phy_lli *src;
  187. struct d40_phy_lli *dst;
  188. };
  189. /**
  190. * struct d40_log_lli - logical lli configuration
  191. *
  192. * @lcsp02: Either maps to register lcsp0 if src or lcsp2 if dst.
  193. * @lcsp13: Either maps to register lcsp1 if src or lcsp3 if dst.
  194. *
  195. * This struct must be 8 bytes aligned since it will be accessed directy by
  196. * the DMA. Never add any none hw mapped registers to this struct.
  197. */
  198. struct d40_log_lli {
  199. u32 lcsp02;
  200. u32 lcsp13;
  201. };
  202. /**
  203. * struct d40_log_lli_bidir - For both src and dst
  204. *
  205. * @src: pointer to src lli configuration.
  206. * @dst: pointer to dst lli configuration.
  207. *
  208. * You always have a src and a dst when doing DMA transfers.
  209. */
  210. struct d40_log_lli_bidir {
  211. struct d40_log_lli *src;
  212. struct d40_log_lli *dst;
  213. };
  214. /**
  215. * struct d40_log_lli_full - LCPA layout
  216. *
  217. * @lcsp0: Logical Channel Standard Param 0 - Src.
  218. * @lcsp1: Logical Channel Standard Param 1 - Src.
  219. * @lcsp2: Logical Channel Standard Param 2 - Dst.
  220. * @lcsp3: Logical Channel Standard Param 3 - Dst.
  221. *
  222. * This struct maps to LCPA physical memory layout. Must map to
  223. * the hw.
  224. */
  225. struct d40_log_lli_full {
  226. u32 lcsp0;
  227. u32 lcsp1;
  228. u32 lcsp2;
  229. u32 lcsp3;
  230. };
  231. /**
  232. * struct d40_def_lcsp - Default LCSP1 and LCSP3 settings
  233. *
  234. * @lcsp3: The default configuration for dst.
  235. * @lcsp1: The default configuration for src.
  236. */
  237. struct d40_def_lcsp {
  238. u32 lcsp3;
  239. u32 lcsp1;
  240. };
  241. /* Physical channels */
  242. void d40_phy_cfg(struct stedma40_chan_cfg *cfg,
  243. u32 *src_cfg,
  244. u32 *dst_cfg,
  245. bool is_log);
  246. void d40_log_cfg(struct stedma40_chan_cfg *cfg,
  247. u32 *lcsp1,
  248. u32 *lcsp2);
  249. int d40_phy_sg_to_lli(struct scatterlist *sg,
  250. int sg_len,
  251. dma_addr_t target,
  252. struct d40_phy_lli *lli,
  253. dma_addr_t lli_phys,
  254. u32 reg_cfg,
  255. u32 data_width1,
  256. u32 data_width2,
  257. int psize);
  258. struct d40_phy_lli *d40_phy_buf_to_lli(struct d40_phy_lli *lli,
  259. dma_addr_t data,
  260. u32 data_size,
  261. int psize,
  262. dma_addr_t next_lli,
  263. u32 reg_cfg,
  264. bool term_int,
  265. u32 data_width1,
  266. u32 data_width2,
  267. bool is_device);
  268. void d40_phy_lli_write(void __iomem *virtbase,
  269. u32 phy_chan_num,
  270. struct d40_phy_lli *lli_dst,
  271. struct d40_phy_lli *lli_src);
  272. /* Logical channels */
  273. struct d40_log_lli *d40_log_buf_to_lli(struct d40_log_lli *lli_sg,
  274. dma_addr_t addr,
  275. int size,
  276. u32 lcsp13, /* src or dst*/
  277. u32 data_width1, u32 data_width2,
  278. bool addr_inc);
  279. int d40_log_sg_to_dev(struct scatterlist *sg,
  280. int sg_len,
  281. struct d40_log_lli_bidir *lli,
  282. struct d40_def_lcsp *lcsp,
  283. u32 src_data_width,
  284. u32 dst_data_width,
  285. enum dma_data_direction direction,
  286. dma_addr_t dev_addr);
  287. int d40_log_sg_to_lli(struct scatterlist *sg,
  288. int sg_len,
  289. struct d40_log_lli *lli_sg,
  290. u32 lcsp13, /* src or dst*/
  291. u32 data_width1, u32 data_width2);
  292. void d40_log_lli_lcpa_write(struct d40_log_lli_full *lcpa,
  293. struct d40_log_lli *lli_dst,
  294. struct d40_log_lli *lli_src,
  295. int next);
  296. void d40_log_lli_lcla_write(struct d40_log_lli *lcla,
  297. struct d40_log_lli *lli_dst,
  298. struct d40_log_lli *lli_src,
  299. int next);
  300. #endif /* STE_DMA40_LLI_H */