ste_dma40_ll.h 9.8 KB

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