bestcomm_priv.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * Private header for the MPC52xx processor BestComm driver
  3. *
  4. * By private, we mean that driver should not use it directly. It's meant
  5. * to be used by the BestComm engine driver itself and by the intermediate
  6. * layer between the core and the drivers.
  7. *
  8. * Copyright (C) 2006 Sylvain Munaut <tnt@246tNt.com>
  9. * Copyright (C) 2005 Varma Electronics Oy,
  10. * ( by Andrey Volkov <avolkov@varma-el.com> )
  11. * Copyright (C) 2003-2004 MontaVista, Software, Inc.
  12. * ( by Dale Farnsworth <dfarnsworth@mvista.com> )
  13. *
  14. * This file is licensed under the terms of the GNU General Public License
  15. * version 2. This program is licensed "as is" without any warranty of any
  16. * kind, whether express or implied.
  17. */
  18. #ifndef __BESTCOMM_PRIV_H__
  19. #define __BESTCOMM_PRIV_H__
  20. #include <linux/spinlock.h>
  21. #include <linux/of.h>
  22. #include <asm/io.h>
  23. #include <asm/mpc52xx.h>
  24. #include "sram.h"
  25. /* ======================================================================== */
  26. /* Engine related stuff */
  27. /* ======================================================================== */
  28. /* Zones sizes and needed alignments */
  29. #define BCOM_MAX_TASKS 16
  30. #define BCOM_MAX_VAR 24
  31. #define BCOM_MAX_INC 8
  32. #define BCOM_MAX_FDT 64
  33. #define BCOM_MAX_CTX 20
  34. #define BCOM_CTX_SIZE (BCOM_MAX_CTX * sizeof(u32))
  35. #define BCOM_CTX_ALIGN 0x100
  36. #define BCOM_VAR_SIZE (BCOM_MAX_VAR * sizeof(u32))
  37. #define BCOM_INC_SIZE (BCOM_MAX_INC * sizeof(u32))
  38. #define BCOM_VAR_ALIGN 0x80
  39. #define BCOM_FDT_SIZE (BCOM_MAX_FDT * sizeof(u32))
  40. #define BCOM_FDT_ALIGN 0x100
  41. /**
  42. * struct bcom_tdt - Task Descriptor Table Entry
  43. *
  44. */
  45. struct bcom_tdt {
  46. u32 start;
  47. u32 stop;
  48. u32 var;
  49. u32 fdt;
  50. u32 exec_status; /* used internally by BestComm engine */
  51. u32 mvtp; /* used internally by BestComm engine */
  52. u32 context;
  53. u32 litbase;
  54. };
  55. /**
  56. * struct bcom_engine
  57. *
  58. * This holds all info needed globaly to handle the engine
  59. */
  60. struct bcom_engine {
  61. struct device_node *ofnode;
  62. struct mpc52xx_sdma __iomem *regs;
  63. phys_addr_t regs_base;
  64. struct bcom_tdt *tdt;
  65. u32 *ctx;
  66. u32 *var;
  67. u32 *fdt;
  68. spinlock_t lock;
  69. };
  70. extern struct bcom_engine *bcom_eng;
  71. /* ======================================================================== */
  72. /* Tasks related stuff */
  73. /* ======================================================================== */
  74. /* Tasks image header */
  75. #define BCOM_TASK_MAGIC 0x4243544B /* 'BCTK' */
  76. struct bcom_task_header {
  77. u32 magic;
  78. u8 desc_size; /* the size fields */
  79. u8 var_size; /* are given in number */
  80. u8 inc_size; /* of 32-bits words */
  81. u8 first_var;
  82. u8 reserved[8];
  83. };
  84. /* Descriptors structure & co */
  85. #define BCOM_DESC_NOP 0x000001f8
  86. #define BCOM_LCD_MASK 0x80000000
  87. #define BCOM_DRD_EXTENDED 0x40000000
  88. #define BCOM_DRD_INITIATOR_SHIFT 21
  89. /* Tasks pragma */
  90. #define BCOM_PRAGMA_BIT_RSV 7 /* reserved pragma bit */
  91. #define BCOM_PRAGMA_BIT_PRECISE_INC 6 /* increment 0=when possible, */
  92. /* 1=iter end */
  93. #define BCOM_PRAGMA_BIT_RST_ERROR_NO 5 /* don't reset errors on */
  94. /* task enable */
  95. #define BCOM_PRAGMA_BIT_PACK 4 /* pack data enable */
  96. #define BCOM_PRAGMA_BIT_INTEGER 3 /* data alignment */
  97. /* 0=frac(msb), 1=int(lsb) */
  98. #define BCOM_PRAGMA_BIT_SPECREAD 2 /* XLB speculative read */
  99. #define BCOM_PRAGMA_BIT_CW 1 /* write line buffer enable */
  100. #define BCOM_PRAGMA_BIT_RL 0 /* read line buffer enable */
  101. /* Looks like XLB speculative read generates XLB errors when a buffer
  102. * is at the end of the physical memory. i.e. when accessing the
  103. * lasts words, the engine tries to prefetch the next but there is no
  104. * next ...
  105. */
  106. #define BCOM_STD_PRAGMA ((0 << BCOM_PRAGMA_BIT_RSV) | \
  107. (0 << BCOM_PRAGMA_BIT_PRECISE_INC) | \
  108. (0 << BCOM_PRAGMA_BIT_RST_ERROR_NO) | \
  109. (0 << BCOM_PRAGMA_BIT_PACK) | \
  110. (0 << BCOM_PRAGMA_BIT_INTEGER) | \
  111. (0 << BCOM_PRAGMA_BIT_SPECREAD) | \
  112. (1 << BCOM_PRAGMA_BIT_CW) | \
  113. (1 << BCOM_PRAGMA_BIT_RL))
  114. #define BCOM_PCI_PRAGMA ((0 << BCOM_PRAGMA_BIT_RSV) | \
  115. (0 << BCOM_PRAGMA_BIT_PRECISE_INC) | \
  116. (0 << BCOM_PRAGMA_BIT_RST_ERROR_NO) | \
  117. (0 << BCOM_PRAGMA_BIT_PACK) | \
  118. (1 << BCOM_PRAGMA_BIT_INTEGER) | \
  119. (0 << BCOM_PRAGMA_BIT_SPECREAD) | \
  120. (1 << BCOM_PRAGMA_BIT_CW) | \
  121. (1 << BCOM_PRAGMA_BIT_RL))
  122. #define BCOM_ATA_PRAGMA BCOM_STD_PRAGMA
  123. #define BCOM_CRC16_DP_0_PRAGMA BCOM_STD_PRAGMA
  124. #define BCOM_CRC16_DP_1_PRAGMA BCOM_STD_PRAGMA
  125. #define BCOM_FEC_RX_BD_PRAGMA BCOM_STD_PRAGMA
  126. #define BCOM_FEC_TX_BD_PRAGMA BCOM_STD_PRAGMA
  127. #define BCOM_GEN_DP_0_PRAGMA BCOM_STD_PRAGMA
  128. #define BCOM_GEN_DP_1_PRAGMA BCOM_STD_PRAGMA
  129. #define BCOM_GEN_DP_2_PRAGMA BCOM_STD_PRAGMA
  130. #define BCOM_GEN_DP_3_PRAGMA BCOM_STD_PRAGMA
  131. #define BCOM_GEN_DP_BD_0_PRAGMA BCOM_STD_PRAGMA
  132. #define BCOM_GEN_DP_BD_1_PRAGMA BCOM_STD_PRAGMA
  133. #define BCOM_GEN_RX_BD_PRAGMA BCOM_STD_PRAGMA
  134. #define BCOM_GEN_TX_BD_PRAGMA BCOM_STD_PRAGMA
  135. #define BCOM_GEN_LPC_PRAGMA BCOM_STD_PRAGMA
  136. #define BCOM_PCI_RX_PRAGMA BCOM_PCI_PRAGMA
  137. #define BCOM_PCI_TX_PRAGMA BCOM_PCI_PRAGMA
  138. /* Initiators number */
  139. #define BCOM_INITIATOR_ALWAYS 0
  140. #define BCOM_INITIATOR_SCTMR_0 1
  141. #define BCOM_INITIATOR_SCTMR_1 2
  142. #define BCOM_INITIATOR_FEC_RX 3
  143. #define BCOM_INITIATOR_FEC_TX 4
  144. #define BCOM_INITIATOR_ATA_RX 5
  145. #define BCOM_INITIATOR_ATA_TX 6
  146. #define BCOM_INITIATOR_SCPCI_RX 7
  147. #define BCOM_INITIATOR_SCPCI_TX 8
  148. #define BCOM_INITIATOR_PSC3_RX 9
  149. #define BCOM_INITIATOR_PSC3_TX 10
  150. #define BCOM_INITIATOR_PSC2_RX 11
  151. #define BCOM_INITIATOR_PSC2_TX 12
  152. #define BCOM_INITIATOR_PSC1_RX 13
  153. #define BCOM_INITIATOR_PSC1_TX 14
  154. #define BCOM_INITIATOR_SCTMR_2 15
  155. #define BCOM_INITIATOR_SCLPC 16
  156. #define BCOM_INITIATOR_PSC5_RX 17
  157. #define BCOM_INITIATOR_PSC5_TX 18
  158. #define BCOM_INITIATOR_PSC4_RX 19
  159. #define BCOM_INITIATOR_PSC4_TX 20
  160. #define BCOM_INITIATOR_I2C2_RX 21
  161. #define BCOM_INITIATOR_I2C2_TX 22
  162. #define BCOM_INITIATOR_I2C1_RX 23
  163. #define BCOM_INITIATOR_I2C1_TX 24
  164. #define BCOM_INITIATOR_PSC6_RX 25
  165. #define BCOM_INITIATOR_PSC6_TX 26
  166. #define BCOM_INITIATOR_IRDA_RX 25
  167. #define BCOM_INITIATOR_IRDA_TX 26
  168. #define BCOM_INITIATOR_SCTMR_3 27
  169. #define BCOM_INITIATOR_SCTMR_4 28
  170. #define BCOM_INITIATOR_SCTMR_5 29
  171. #define BCOM_INITIATOR_SCTMR_6 30
  172. #define BCOM_INITIATOR_SCTMR_7 31
  173. /* Initiators priorities */
  174. #define BCOM_IPR_ALWAYS 7
  175. #define BCOM_IPR_SCTMR_0 2
  176. #define BCOM_IPR_SCTMR_1 2
  177. #define BCOM_IPR_FEC_RX 6
  178. #define BCOM_IPR_FEC_TX 5
  179. #define BCOM_IPR_ATA_RX 7
  180. #define BCOM_IPR_ATA_TX 7
  181. #define BCOM_IPR_SCPCI_RX 2
  182. #define BCOM_IPR_SCPCI_TX 2
  183. #define BCOM_IPR_PSC3_RX 2
  184. #define BCOM_IPR_PSC3_TX 2
  185. #define BCOM_IPR_PSC2_RX 2
  186. #define BCOM_IPR_PSC2_TX 2
  187. #define BCOM_IPR_PSC1_RX 2
  188. #define BCOM_IPR_PSC1_TX 2
  189. #define BCOM_IPR_SCTMR_2 2
  190. #define BCOM_IPR_SCLPC 2
  191. #define BCOM_IPR_PSC5_RX 2
  192. #define BCOM_IPR_PSC5_TX 2
  193. #define BCOM_IPR_PSC4_RX 2
  194. #define BCOM_IPR_PSC4_TX 2
  195. #define BCOM_IPR_I2C2_RX 2
  196. #define BCOM_IPR_I2C2_TX 2
  197. #define BCOM_IPR_I2C1_RX 2
  198. #define BCOM_IPR_I2C1_TX 2
  199. #define BCOM_IPR_PSC6_RX 2
  200. #define BCOM_IPR_PSC6_TX 2
  201. #define BCOM_IPR_IRDA_RX 2
  202. #define BCOM_IPR_IRDA_TX 2
  203. #define BCOM_IPR_SCTMR_3 2
  204. #define BCOM_IPR_SCTMR_4 2
  205. #define BCOM_IPR_SCTMR_5 2
  206. #define BCOM_IPR_SCTMR_6 2
  207. #define BCOM_IPR_SCTMR_7 2
  208. /* ======================================================================== */
  209. /* API */
  210. /* ======================================================================== */
  211. extern struct bcom_task *bcom_task_alloc(int bd_count, int bd_size, int priv_size);
  212. extern void bcom_task_free(struct bcom_task *tsk);
  213. extern int bcom_load_image(int task, u32 *task_image);
  214. extern void bcom_set_initiator(int task, int initiator);
  215. #define TASK_ENABLE 0x8000
  216. /**
  217. * bcom_disable_prefetch - Hook to disable bus prefetching
  218. *
  219. * ATA DMA and the original MPC5200 need this due to silicon bugs. At the
  220. * moment disabling prefetch is a one-way street. There is no mechanism
  221. * in place to turn prefetch back on after it has been disabled. There is
  222. * no reason it couldn't be done, it would just be more complex to implement.
  223. */
  224. static inline void bcom_disable_prefetch(void)
  225. {
  226. u16 regval;
  227. regval = in_be16(&bcom_eng->regs->PtdCntrl);
  228. out_be16(&bcom_eng->regs->PtdCntrl, regval | 1);
  229. };
  230. static inline void
  231. bcom_enable_task(int task)
  232. {
  233. u16 reg;
  234. reg = in_be16(&bcom_eng->regs->tcr[task]);
  235. out_be16(&bcom_eng->regs->tcr[task], reg | TASK_ENABLE);
  236. }
  237. static inline void
  238. bcom_disable_task(int task)
  239. {
  240. u16 reg = in_be16(&bcom_eng->regs->tcr[task]);
  241. out_be16(&bcom_eng->regs->tcr[task], reg & ~TASK_ENABLE);
  242. }
  243. static inline u32 *
  244. bcom_task_desc(int task)
  245. {
  246. return bcom_sram_pa2va(bcom_eng->tdt[task].start);
  247. }
  248. static inline int
  249. bcom_task_num_descs(int task)
  250. {
  251. return (bcom_eng->tdt[task].stop - bcom_eng->tdt[task].start)/sizeof(u32) + 1;
  252. }
  253. static inline u32 *
  254. bcom_task_var(int task)
  255. {
  256. return bcom_sram_pa2va(bcom_eng->tdt[task].var);
  257. }
  258. static inline u32 *
  259. bcom_task_inc(int task)
  260. {
  261. return &bcom_task_var(task)[BCOM_MAX_VAR];
  262. }
  263. static inline int
  264. bcom_drd_is_extended(u32 desc)
  265. {
  266. return (desc) & BCOM_DRD_EXTENDED;
  267. }
  268. static inline int
  269. bcom_desc_is_drd(u32 desc)
  270. {
  271. return !(desc & BCOM_LCD_MASK) && desc != BCOM_DESC_NOP;
  272. }
  273. static inline int
  274. bcom_desc_initiator(u32 desc)
  275. {
  276. return (desc >> BCOM_DRD_INITIATOR_SHIFT) & 0x1f;
  277. }
  278. static inline void
  279. bcom_set_desc_initiator(u32 *desc, int initiator)
  280. {
  281. *desc = (*desc & ~(0x1f << BCOM_DRD_INITIATOR_SHIFT)) |
  282. ((initiator & 0x1f) << BCOM_DRD_INITIATOR_SHIFT);
  283. }
  284. static inline void
  285. bcom_set_task_pragma(int task, int pragma)
  286. {
  287. u32 *fdt = &bcom_eng->tdt[task].fdt;
  288. *fdt = (*fdt & ~0xff) | pragma;
  289. }
  290. static inline void
  291. bcom_set_task_auto_start(int task, int next_task)
  292. {
  293. u16 __iomem *tcr = &bcom_eng->regs->tcr[task];
  294. out_be16(tcr, (in_be16(tcr) & ~0xff) | 0x00c0 | next_task);
  295. }
  296. static inline void
  297. bcom_set_tcr_initiator(int task, int initiator)
  298. {
  299. u16 __iomem *tcr = &bcom_eng->regs->tcr[task];
  300. out_be16(tcr, (in_be16(tcr) & ~0x1f00) | ((initiator & 0x1f) << 8));
  301. }
  302. #endif /* __BESTCOMM_PRIV_H__ */