ste_dma40_ll.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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_PERIPHID2_REV_POS 4
  143. #define D40_DREG_PERIPHID2_REV_MASK (0xf << D40_DREG_PERIPHID2_REV_POS)
  144. #define D40_DREG_PERIPHID2_DESIGNER_MASK 0xf
  145. #define D40_DREG_PERIPHID3 0xFEC
  146. #define D40_DREG_CELLID0 0xFF0
  147. #define D40_DREG_CELLID1 0xFF4
  148. #define D40_DREG_CELLID2 0xFF8
  149. #define D40_DREG_CELLID3 0xFFC
  150. /* LLI related structures */
  151. /**
  152. * struct d40_phy_lli - The basic configration register for each physical
  153. * channel.
  154. *
  155. * @reg_cfg: The configuration register.
  156. * @reg_elt: The element register.
  157. * @reg_ptr: The pointer register.
  158. * @reg_lnk: The link register.
  159. *
  160. * These registers are set up for both physical and logical transfers
  161. * Note that the bit in each register means differently in logical and
  162. * physical(standard) mode.
  163. *
  164. * This struct must be 16 bytes aligned, and only contain physical registers
  165. * since it will be directly accessed by the DMA.
  166. */
  167. struct d40_phy_lli {
  168. u32 reg_cfg;
  169. u32 reg_elt;
  170. u32 reg_ptr;
  171. u32 reg_lnk;
  172. };
  173. /**
  174. * struct d40_phy_lli_bidir - struct for a transfer.
  175. *
  176. * @src: Register settings for src channel.
  177. * @dst: Register settings for dst channel.
  178. * @dst_addr: Physical destination address.
  179. * @src_addr: Physical source address.
  180. *
  181. * All DMA transfers have a source and a destination.
  182. */
  183. struct d40_phy_lli_bidir {
  184. struct d40_phy_lli *src;
  185. struct d40_phy_lli *dst;
  186. dma_addr_t dst_addr;
  187. dma_addr_t src_addr;
  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. /**
  242. * struct d40_lcla_elem - Info for one LCA element.
  243. *
  244. * @src_id: logical channel src id
  245. * @dst_id: logical channel dst id
  246. * @src: LCPA formated src parameters
  247. * @dst: LCPA formated dst parameters
  248. *
  249. */
  250. struct d40_lcla_elem {
  251. int src_id;
  252. int dst_id;
  253. struct d40_log_lli *src;
  254. struct d40_log_lli *dst;
  255. };
  256. /* Physical channels */
  257. void d40_phy_cfg(struct stedma40_chan_cfg *cfg,
  258. u32 *src_cfg, u32 *dst_cfg, bool is_log);
  259. void d40_log_cfg(struct stedma40_chan_cfg *cfg,
  260. u32 *lcsp1, u32 *lcsp2);
  261. int d40_phy_sg_to_lli(struct scatterlist *sg,
  262. int sg_len,
  263. dma_addr_t target,
  264. struct d40_phy_lli *lli,
  265. dma_addr_t lli_phys,
  266. u32 reg_cfg,
  267. u32 data_width,
  268. int psize);
  269. int d40_phy_fill_lli(struct d40_phy_lli *lli,
  270. dma_addr_t data,
  271. u32 data_size,
  272. int psize,
  273. dma_addr_t next_lli,
  274. u32 reg_cfg,
  275. bool term_int,
  276. u32 data_width,
  277. bool is_device);
  278. void d40_phy_lli_write(void __iomem *virtbase,
  279. u32 phy_chan_num,
  280. struct d40_phy_lli *lli_dst,
  281. struct d40_phy_lli *lli_src);
  282. /* Logical channels */
  283. void d40_log_fill_lli(struct d40_log_lli *lli,
  284. dma_addr_t data, u32 data_size,
  285. u32 lli_next_off, u32 reg_cfg,
  286. u32 data_width,
  287. bool term_int, bool addr_inc);
  288. int d40_log_sg_to_dev(struct d40_lcla_elem *lcla,
  289. struct scatterlist *sg,
  290. int sg_len,
  291. struct d40_log_lli_bidir *lli,
  292. struct d40_def_lcsp *lcsp,
  293. u32 src_data_width,
  294. u32 dst_data_width,
  295. enum dma_data_direction direction,
  296. dma_addr_t dev_addr, int max_len,
  297. int llis_per_log);
  298. int d40_log_lli_write(struct d40_log_lli_full *lcpa,
  299. struct d40_log_lli *lcla_src,
  300. struct d40_log_lli *lcla_dst,
  301. struct d40_log_lli *lli_dst,
  302. struct d40_log_lli *lli_src,
  303. int llis_per_log);
  304. int d40_log_sg_to_lli(int lcla_id,
  305. struct scatterlist *sg,
  306. int sg_len,
  307. struct d40_log_lli *lli_sg,
  308. u32 lcsp13, /* src or dst*/
  309. u32 data_width,
  310. int max_len, int llis_per_log);
  311. #endif /* STE_DMA40_LLI_H */