ste_dma40_ll.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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_PSEG1 0x110
  142. #define D40_DREG_PSEG2 0x114
  143. #define D40_DREG_PSEG3 0x118
  144. #define D40_DREG_PSEG4 0x11C
  145. #define D40_DREG_PCEG1 0x120
  146. #define D40_DREG_PCEG2 0x124
  147. #define D40_DREG_PCEG3 0x128
  148. #define D40_DREG_PCEG4 0x12C
  149. #define D40_DREG_RSEG1 0x130
  150. #define D40_DREG_RSEG2 0x134
  151. #define D40_DREG_RSEG3 0x138
  152. #define D40_DREG_RSEG4 0x13C
  153. #define D40_DREG_RCEG1 0x140
  154. #define D40_DREG_RCEG2 0x144
  155. #define D40_DREG_RCEG3 0x148
  156. #define D40_DREG_RCEG4 0x14C
  157. #define D40_DREG_STFU 0xFC8
  158. #define D40_DREG_ICFG 0xFCC
  159. #define D40_DREG_PERIPHID0 0xFE0
  160. #define D40_DREG_PERIPHID1 0xFE4
  161. #define D40_DREG_PERIPHID2 0xFE8
  162. #define D40_DREG_PERIPHID2_REV_POS 4
  163. #define D40_DREG_PERIPHID2_REV_MASK (0xf << D40_DREG_PERIPHID2_REV_POS)
  164. #define D40_DREG_PERIPHID2_DESIGNER_MASK 0xf
  165. #define D40_DREG_PERIPHID3 0xFEC
  166. #define D40_DREG_CELLID0 0xFF0
  167. #define D40_DREG_CELLID1 0xFF4
  168. #define D40_DREG_CELLID2 0xFF8
  169. #define D40_DREG_CELLID3 0xFFC
  170. /* LLI related structures */
  171. /**
  172. * struct d40_phy_lli - The basic configration register for each physical
  173. * channel.
  174. *
  175. * @reg_cfg: The configuration register.
  176. * @reg_elt: The element register.
  177. * @reg_ptr: The pointer register.
  178. * @reg_lnk: The link register.
  179. *
  180. * These registers are set up for both physical and logical transfers
  181. * Note that the bit in each register means differently in logical and
  182. * physical(standard) mode.
  183. *
  184. * This struct must be 16 bytes aligned, and only contain physical registers
  185. * since it will be directly accessed by the DMA.
  186. */
  187. struct d40_phy_lli {
  188. u32 reg_cfg;
  189. u32 reg_elt;
  190. u32 reg_ptr;
  191. u32 reg_lnk;
  192. };
  193. /**
  194. * struct d40_phy_lli_bidir - struct for a transfer.
  195. *
  196. * @src: Register settings for src channel.
  197. * @dst: Register settings for dst channel.
  198. *
  199. * All DMA transfers have a source and a destination.
  200. */
  201. struct d40_phy_lli_bidir {
  202. struct d40_phy_lli *src;
  203. struct d40_phy_lli *dst;
  204. };
  205. /**
  206. * struct d40_log_lli - logical lli configuration
  207. *
  208. * @lcsp02: Either maps to register lcsp0 if src or lcsp2 if dst.
  209. * @lcsp13: Either maps to register lcsp1 if src or lcsp3 if dst.
  210. *
  211. * This struct must be 8 bytes aligned since it will be accessed directy by
  212. * the DMA. Never add any none hw mapped registers to this struct.
  213. */
  214. struct d40_log_lli {
  215. u32 lcsp02;
  216. u32 lcsp13;
  217. };
  218. /**
  219. * struct d40_log_lli_bidir - For both src and dst
  220. *
  221. * @src: pointer to src lli configuration.
  222. * @dst: pointer to dst lli configuration.
  223. *
  224. * You always have a src and a dst when doing DMA transfers.
  225. */
  226. struct d40_log_lli_bidir {
  227. struct d40_log_lli *src;
  228. struct d40_log_lli *dst;
  229. };
  230. /**
  231. * struct d40_log_lli_full - LCPA layout
  232. *
  233. * @lcsp0: Logical Channel Standard Param 0 - Src.
  234. * @lcsp1: Logical Channel Standard Param 1 - Src.
  235. * @lcsp2: Logical Channel Standard Param 2 - Dst.
  236. * @lcsp3: Logical Channel Standard Param 3 - Dst.
  237. *
  238. * This struct maps to LCPA physical memory layout. Must map to
  239. * the hw.
  240. */
  241. struct d40_log_lli_full {
  242. u32 lcsp0;
  243. u32 lcsp1;
  244. u32 lcsp2;
  245. u32 lcsp3;
  246. };
  247. /**
  248. * struct d40_def_lcsp - Default LCSP1 and LCSP3 settings
  249. *
  250. * @lcsp3: The default configuration for dst.
  251. * @lcsp1: The default configuration for src.
  252. */
  253. struct d40_def_lcsp {
  254. u32 lcsp3;
  255. u32 lcsp1;
  256. };
  257. /* Physical channels */
  258. enum d40_lli_flags {
  259. LLI_ADDR_INC = 1 << 0,
  260. LLI_TERM_INT = 1 << 1,
  261. LLI_CYCLIC = 1 << 2,
  262. LLI_LAST_LINK = 1 << 3,
  263. };
  264. void d40_phy_cfg(struct stedma40_chan_cfg *cfg,
  265. u32 *src_cfg,
  266. u32 *dst_cfg,
  267. bool is_log);
  268. void d40_log_cfg(struct stedma40_chan_cfg *cfg,
  269. u32 *lcsp1,
  270. u32 *lcsp2);
  271. int d40_phy_sg_to_lli(struct scatterlist *sg,
  272. int sg_len,
  273. dma_addr_t target,
  274. struct d40_phy_lli *lli,
  275. dma_addr_t lli_phys,
  276. u32 reg_cfg,
  277. struct stedma40_half_channel_info *info,
  278. struct stedma40_half_channel_info *otherinfo,
  279. unsigned long flags);
  280. /* Logical channels */
  281. int d40_log_sg_to_lli(struct scatterlist *sg,
  282. int sg_len,
  283. dma_addr_t dev_addr,
  284. struct d40_log_lli *lli_sg,
  285. u32 lcsp13, /* src or dst*/
  286. u32 data_width1, u32 data_width2);
  287. void d40_log_lli_lcpa_write(struct d40_log_lli_full *lcpa,
  288. struct d40_log_lli *lli_dst,
  289. struct d40_log_lli *lli_src,
  290. int next, unsigned int flags);
  291. void d40_log_lli_lcla_write(struct d40_log_lli *lcla,
  292. struct d40_log_lli *lli_dst,
  293. struct d40_log_lli *lli_src,
  294. int next, unsigned int flags);
  295. #endif /* STE_DMA40_LLI_H */