ste_dma40_ll.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * driver/dma/ste_dma40_ll.h
  3. *
  4. * Copyright (C) ST-Ericsson 2007-2010
  5. * License terms: GNU General Public License (GPL) version 2
  6. * Author: Per Friden <per.friden@stericsson.com>
  7. * Author: Jonas Aaberg <jonas.aberg@stericsson.com>
  8. */
  9. #ifndef STE_DMA40_LL_H
  10. #define STE_DMA40_LL_H
  11. #define D40_DREG_PCBASE 0x400
  12. #define D40_DREG_PCDELTA (8 * 4)
  13. #define D40_LLI_ALIGN 16 /* LLI alignment must be 16 bytes. */
  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_LCPA 0x020
  110. #define D40_DREG_LCLA 0x024
  111. #define D40_DREG_ACTIVE 0x050
  112. #define D40_DREG_ACTIVO 0x054
  113. #define D40_DREG_FSEB1 0x058
  114. #define D40_DREG_FSEB2 0x05C
  115. #define D40_DREG_PCMIS 0x060
  116. #define D40_DREG_PCICR 0x064
  117. #define D40_DREG_PCTIS 0x068
  118. #define D40_DREG_PCEIS 0x06C
  119. #define D40_DREG_LCMIS0 0x080
  120. #define D40_DREG_LCMIS1 0x084
  121. #define D40_DREG_LCMIS2 0x088
  122. #define D40_DREG_LCMIS3 0x08C
  123. #define D40_DREG_LCICR0 0x090
  124. #define D40_DREG_LCICR1 0x094
  125. #define D40_DREG_LCICR2 0x098
  126. #define D40_DREG_LCICR3 0x09C
  127. #define D40_DREG_LCTIS0 0x0A0
  128. #define D40_DREG_LCTIS1 0x0A4
  129. #define D40_DREG_LCTIS2 0x0A8
  130. #define D40_DREG_LCTIS3 0x0AC
  131. #define D40_DREG_LCEIS0 0x0B0
  132. #define D40_DREG_LCEIS1 0x0B4
  133. #define D40_DREG_LCEIS2 0x0B8
  134. #define D40_DREG_LCEIS3 0x0BC
  135. #define D40_DREG_STFU 0xFC8
  136. #define D40_DREG_ICFG 0xFCC
  137. #define D40_DREG_PERIPHID0 0xFE0
  138. #define D40_DREG_PERIPHID1 0xFE4
  139. #define D40_DREG_PERIPHID2 0xFE8
  140. #define D40_DREG_PERIPHID3 0xFEC
  141. #define D40_DREG_CELLID0 0xFF0
  142. #define D40_DREG_CELLID1 0xFF4
  143. #define D40_DREG_CELLID2 0xFF8
  144. #define D40_DREG_CELLID3 0xFFC
  145. /* LLI related structures */
  146. /**
  147. * struct d40_phy_lli - The basic configration register for each physical
  148. * channel.
  149. *
  150. * @reg_cfg: The configuration register.
  151. * @reg_elt: The element register.
  152. * @reg_ptr: The pointer register.
  153. * @reg_lnk: The link register.
  154. *
  155. * These registers are set up for both physical and logical transfers
  156. * Note that the bit in each register means differently in logical and
  157. * physical(standard) mode.
  158. *
  159. * This struct must be 16 bytes aligned, and only contain physical registers
  160. * since it will be directly accessed by the DMA.
  161. */
  162. struct d40_phy_lli {
  163. u32 reg_cfg;
  164. u32 reg_elt;
  165. u32 reg_ptr;
  166. u32 reg_lnk;
  167. };
  168. /**
  169. * struct d40_phy_lli_bidir - struct for a transfer.
  170. *
  171. * @src: Register settings for src channel.
  172. * @dst: Register settings for dst channel.
  173. * @dst_addr: Physical destination address.
  174. * @src_addr: Physical source address.
  175. *
  176. * All DMA transfers have a source and a destination.
  177. */
  178. struct d40_phy_lli_bidir {
  179. struct d40_phy_lli *src;
  180. struct d40_phy_lli *dst;
  181. dma_addr_t dst_addr;
  182. dma_addr_t src_addr;
  183. };
  184. /**
  185. * struct d40_log_lli - logical lli configuration
  186. *
  187. * @lcsp02: Either maps to register lcsp0 if src or lcsp2 if dst.
  188. * @lcsp13: Either maps to register lcsp1 if src or lcsp3 if dst.
  189. *
  190. * This struct must be 8 bytes aligned since it will be accessed directy by
  191. * the DMA. Never add any none hw mapped registers to this struct.
  192. */
  193. struct d40_log_lli {
  194. u32 lcsp02;
  195. u32 lcsp13;
  196. };
  197. /**
  198. * struct d40_log_lli_bidir - For both src and dst
  199. *
  200. * @src: pointer to src lli configuration.
  201. * @dst: pointer to dst lli configuration.
  202. *
  203. * You always have a src and a dst when doing DMA transfers.
  204. */
  205. struct d40_log_lli_bidir {
  206. struct d40_log_lli *src;
  207. struct d40_log_lli *dst;
  208. };
  209. /**
  210. * struct d40_log_lli_full - LCPA layout
  211. *
  212. * @lcsp0: Logical Channel Standard Param 0 - Src.
  213. * @lcsp1: Logical Channel Standard Param 1 - Src.
  214. * @lcsp2: Logical Channel Standard Param 2 - Dst.
  215. * @lcsp3: Logical Channel Standard Param 3 - Dst.
  216. *
  217. * This struct maps to LCPA physical memory layout. Must map to
  218. * the hw.
  219. */
  220. struct d40_log_lli_full {
  221. u32 lcsp0;
  222. u32 lcsp1;
  223. u32 lcsp2;
  224. u32 lcsp3;
  225. };
  226. /**
  227. * struct d40_def_lcsp - Default LCSP1 and LCSP3 settings
  228. *
  229. * @lcsp3: The default configuration for dst.
  230. * @lcsp1: The default configuration for src.
  231. */
  232. struct d40_def_lcsp {
  233. u32 lcsp3;
  234. u32 lcsp1;
  235. };
  236. /**
  237. * struct d40_lcla_elem - Info for one LCA element.
  238. *
  239. * @src_id: logical channel src id
  240. * @dst_id: logical channel dst id
  241. * @src: LCPA formated src parameters
  242. * @dst: LCPA formated dst parameters
  243. *
  244. */
  245. struct d40_lcla_elem {
  246. int src_id;
  247. int dst_id;
  248. struct d40_log_lli *src;
  249. struct d40_log_lli *dst;
  250. };
  251. /* Physical channels */
  252. void d40_phy_cfg(struct stedma40_chan_cfg *cfg,
  253. u32 *src_cfg, u32 *dst_cfg, bool is_log);
  254. void d40_log_cfg(struct stedma40_chan_cfg *cfg,
  255. u32 *lcsp1, u32 *lcsp2);
  256. int d40_phy_sg_to_lli(struct scatterlist *sg,
  257. int sg_len,
  258. dma_addr_t target,
  259. struct d40_phy_lli *lli,
  260. dma_addr_t lli_phys,
  261. u32 reg_cfg,
  262. u32 data_width,
  263. int psize,
  264. bool term_int);
  265. int d40_phy_fill_lli(struct d40_phy_lli *lli,
  266. dma_addr_t data,
  267. u32 data_size,
  268. int psize,
  269. dma_addr_t next_lli,
  270. u32 reg_cfg,
  271. bool term_int,
  272. u32 data_width,
  273. bool is_device);
  274. void d40_phy_lli_write(void __iomem *virtbase,
  275. u32 phy_chan_num,
  276. struct d40_phy_lli *lli_dst,
  277. struct d40_phy_lli *lli_src);
  278. /* Logical channels */
  279. void d40_log_fill_lli(struct d40_log_lli *lli,
  280. dma_addr_t data, u32 data_size,
  281. u32 lli_next_off, u32 reg_cfg,
  282. u32 data_width,
  283. bool term_int, bool addr_inc);
  284. int d40_log_sg_to_dev(struct d40_lcla_elem *lcla,
  285. struct scatterlist *sg,
  286. int sg_len,
  287. struct d40_log_lli_bidir *lli,
  288. struct d40_def_lcsp *lcsp,
  289. u32 src_data_width,
  290. u32 dst_data_width,
  291. enum dma_data_direction direction,
  292. bool term_int, dma_addr_t dev_addr, int max_len,
  293. int llis_per_log);
  294. void d40_log_lli_write(struct d40_log_lli_full *lcpa,
  295. struct d40_log_lli *lcla_src,
  296. struct d40_log_lli *lcla_dst,
  297. struct d40_log_lli *lli_dst,
  298. struct d40_log_lli *lli_src,
  299. int llis_per_log);
  300. int d40_log_sg_to_lli(int lcla_id,
  301. struct scatterlist *sg,
  302. int sg_len,
  303. struct d40_log_lli *lli_sg,
  304. u32 lcsp13, /* src or dst*/
  305. u32 data_width,
  306. bool term_int, int max_len, int llis_per_log);
  307. #endif /* STE_DMA40_LLI_H */