scc.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * (C) Copyright 2009 Stefan Roese <sr@denx.de>, DENX Software Engineering
  3. *
  4. * Copyright (C) 2006 Micronas GmbH
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <linux/errno.h>
  10. #include "vct.h"
  11. /*
  12. * List of statically defined buffers per SCC.
  13. * The first entry in the table is the number of fixed buffers
  14. * followed by the list of buffer IDs
  15. */
  16. static u32 buffer_list_0[] = { 6, 120, 121, 122, 123, 139, 140 };
  17. static u32 buffer_list_1[] = { 6, 120, 121, 122, 123, 139, 140 };
  18. static u32 buffer_list_2[] = { 5, 124, 125, 126, 139, 140 };
  19. static u32 buffer_list_3[] = { 5, 124, 125, 126, 139, 140 };
  20. static u32 buffer_list_4[] = { 5, 124, 125, 126, 139, 140 };
  21. static u32 buffer_list_5[] = { 3, 127, 139, 140 };
  22. static u32 buffer_list_6[] = { 3, 127, 139, 140 };
  23. static u32 buffer_list_7[] = { 6, 128, 129, 130, 131, 139, 140 };
  24. static u32 buffer_list_8[] = { 6, 128, 129, 130, 131, 139, 140 };
  25. static u32 buffer_list_9[] = { 5, 124, 125, 126, 139, 140 };
  26. static u32 buffer_list_10[] = { 5, 124, 125, 126, 139, 140 };
  27. static u32 buffer_list_11[] = { 5, 124, 125, 126, 139, 140 };
  28. static u32 buffer_list_12[] = { 6, 132, 133, 134, 135, 139, 140 };
  29. static u32 buffer_list_13[] = { 6, 132, 133, 134, 135, 139, 140 };
  30. static u32 buffer_list_14[] = { 4, 137, 138, 139, 140 };
  31. static u32 buffer_list_15[] = { 6, 136, 136, 137, 138, 139, 140 };
  32. /** Issue#7674 (new) - DP/DVP buffer assignment */
  33. static u32 buffer_list_16[] = { 6, 106, 108, 109, 107, 139, 140 };
  34. static u32 buffer_list_17[] = { 6, 106, 110, 107, 111, 139, 140 };
  35. static u32 buffer_list_18[] = { 6, 106, 113, 107, 114, 139, 140 };
  36. static u32 buffer_list_19[] = { 3, 112, 139, 140 };
  37. static u32 buffer_list_20[] = { 35, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  38. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  39. 79, 80, 81, 82, 83, 84, 85, 86, 139, 140 };
  40. static u32 buffer_list_21[] = { 27, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  41. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  42. 139, 140 };
  43. static u32 buffer_list_22[] = { 81, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  44. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  45. 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
  46. 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
  47. 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
  48. 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
  49. 73, 74, 75, 76, 77, 78, 139, 140 };
  50. static u32 buffer_list_23[] = { 29, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  51. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  52. 88, 89, 139, 140 };
  53. static u32 buffer_list_24[] = { 6, 90, 91, 92, 93, 139, 140 };
  54. static u32 buffer_list_25[] = { 18, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
  55. 100, 101, 102, 103, 104, 105, 139, 140 };
  56. static u32 buffer_list_26[] = { 5, 94, 95, 96, 139, 140 };
  57. static u32 buffer_list_27[] = { 5, 97, 98, 99, 139, 140 };
  58. static u32 buffer_list_28[] = { 5, 100, 101, 102, 139, 140 };
  59. static u32 buffer_list_29[] = { 5, 103, 104, 105, 139, 140 };
  60. static u32 buffer_list_30[] = { 10, 108, 109, 110, 111, 113, 114, 116, 117,
  61. 139, 140 };
  62. static u32 buffer_list_31[] = { 13, 106, 107, 108, 109, 110, 111, 113, 114,
  63. 115, 116, 117, 139, 140 };
  64. static u32 buffer_list_32[] = { 13, 106, 107, 108, 109, 110, 111, 113, 114,
  65. 115, 116, 117, 139, 140 };
  66. static u32 buffer_list_33[] = { 27, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  67. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  68. 139, 140 };
  69. static u32 buffer_list_34[] = { 27, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  70. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  71. 139, 140 };
  72. static u32 buffer_list_35[] = { 28, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  73. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  74. 87, 139, 140 };
  75. static u32 buffer_list_36[] = { 28, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  76. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  77. 87, 139, 140 };
  78. static u32 buffer_list_37[] = { 27, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  79. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  80. 139, 140 };
  81. static u32 buffer_list_38[] = { 29, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  82. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  83. 118, 119, 139, 140 };
  84. static u32 buffer_list_39[] = { 91, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
  85. 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
  86. 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
  87. 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
  88. 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
  89. 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
  90. 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
  91. 85, 86, 118, 119, 139, 140 };
  92. static u32 buffer_list_40[] = { 0 };
  93. /*
  94. * List of statically defined vcid.csize values.
  95. * The first entry in the table is the number of possible csize values
  96. * followed by the list of data path values in bits.
  97. */
  98. static u32 csize_list_0[] = { 2, 0, 1 };
  99. static u32 csize_list_1[] = { 2, 0, 1 };
  100. static u32 csize_list_2[] = { 1, 1 };
  101. static u32 csize_list_3[] = { 1, 1 };
  102. static u32 csize_list_4[] = { 1, 1 };
  103. static u32 csize_list_5[] = { 1, 0 };
  104. static u32 csize_list_6[] = { 1, 0 };
  105. static u32 csize_list_7[] = { 1, 1 };
  106. static u32 csize_list_8[] = { 1, 1 };
  107. static u32 csize_list_9[] = { 1, 1 };
  108. static u32 csize_list_10[] = { 1, 1 };
  109. static u32 csize_list_11[] = { 1, 1 };
  110. static u32 csize_list_12[] = { 1, 1 };
  111. static u32 csize_list_13[] = { 1, 1 };
  112. static u32 csize_list_14[] = { 1, 2 };
  113. static u32 csize_list_15[] = { 1, 4 };
  114. static u32 csize_list_16[] = { 3, 0, 1, 2 };
  115. static u32 csize_list_17[] = { 3, 0, 1, 2 };
  116. static u32 csize_list_18[] = { 3, 0, 1, 2 };
  117. static u32 csize_list_19[] = { 1, 2 };
  118. static u32 csize_list_20[] = { 1, 0 };
  119. static u32 csize_list_21[] = { 1, 0 };
  120. static u32 csize_list_22[] = { 1, 2 };
  121. static u32 csize_list_23[] = { 1, 3 };
  122. static u32 csize_list_24[] = { 1, 3 };
  123. static u32 csize_list_25[] = { 1, 3 };
  124. static u32 csize_list_26[] = { 1, 0 };
  125. static u32 csize_list_27[] = { 1, 0 };
  126. static u32 csize_list_28[] = { 1, 0 };
  127. static u32 csize_list_29[] = { 1, 0 };
  128. static u32 csize_list_30[] = { 1, 2 };
  129. static u32 csize_list_31[] = { 1, 2 };
  130. static u32 csize_list_32[] = { 1, 2 };
  131. static u32 csize_list_33[] = { 1, 2 };
  132. static u32 csize_list_34[] = { 1, 2 };
  133. static u32 csize_list_35[] = { 1, 2 };
  134. static u32 csize_list_36[] = { 1, 2 };
  135. static u32 csize_list_37[] = { 2, 0, 1 };
  136. static u32 csize_list_38[] = { 1, 2 };
  137. static u32 csize_list_39[] = { 1, 3 };
  138. static u32 csize_list_40[] = { 1, 3 };
  139. /*
  140. * SCC_Configuration table
  141. */
  142. static const struct scc_descriptor scc_descriptor_table[] = {
  143. /* scn scc_name profile SCC scc_id mci_id rd wr m p fh si cfg sta */
  144. {"fe_", "fe_3dcomb_wr", STRM_P, SCC0_BASE, 0, 0, 0, 4, 1, 1, 0, 0, 0, 1,
  145. buffer_list_0, csize_list_0},
  146. {"fe_", "fe_3dcomb_rd", STRM_P, SCC1_BASE, 1, 18, 4, 0, 1, 1, 0, 1, 0,
  147. 1, buffer_list_1, csize_list_1},
  148. {"di_", "di_tnr_wr", STRM_P, SCC2_BASE, 2, 1, 0, 3, 1, 1, 0, 2, 0, 1,
  149. buffer_list_2, csize_list_2},
  150. {"di_", "di_tnr_field_rd", STRM_P, SCC3_BASE, 3, 19, 3, 0, 1, 1, 0, 3,
  151. 0, 1, buffer_list_3, csize_list_3},
  152. {"di_", "di_tnr_frame_rd", STRM_P, SCC4_BASE, 4, 20, 3, 0, 1, 1, 0, 4,
  153. 0, 1, buffer_list_4, csize_list_4},
  154. {"di_", "di_mval_wr", STRM_P, SCC5_BASE, 5, 2, 0, 1, 1, 1, 0, 5, 0, 1,
  155. buffer_list_5, csize_list_5},
  156. {"di_", "di_mval_rd", STRM_P, SCC6_BASE, 6, 21, 1, 0, 1, 1, 0, 6, 0, 1,
  157. buffer_list_6, csize_list_6},
  158. {"rc_", "rc_frame_wr", STRM_P, SCC7_BASE, 7, 3, 0, 4, 1, 1, 0, 7, 0, 1,
  159. buffer_list_7, csize_list_7},
  160. {"rc_", "rc_frame0_rd", STRM_P, SCC8_BASE, 8, 22, 4, 0, 1, 1, 0, 8, 0,
  161. 1, buffer_list_8, csize_list_8},
  162. {"opt", "opt_field0_rd", STRM_P, SCC9_BASE, 9, 23, 3, 0, 1, 1, 0, 9, 0,
  163. 1, buffer_list_9, csize_list_9},
  164. {"opt", "opt_field1_rd", STRM_P, SCC10_BASE, 10, 24, 3, 0, 1, 1, 0, 10,
  165. 0, 1, buffer_list_10, csize_list_10},
  166. {"opt", "opt_field2_rd", STRM_P, SCC11_BASE, 11, 25, 3, 0, 1, 1, 0, 11,
  167. 0, 1, buffer_list_11, csize_list_11},
  168. {"pip", "pip_frame_wr", STRM_P, SCC12_BASE, 12, 4, 0, 4, 1, 1, 0, 12, 0,
  169. 1, buffer_list_12, csize_list_12},
  170. {"pip", "pip_frame_rd", STRM_P, SCC13_BASE, 13, 26, 4, 0, 1, 1, 0, 13,
  171. 0, 1, buffer_list_13, csize_list_13},
  172. {"dp_", "dp_agpu_rd", STRM_P, SCC14_BASE, 14, 27, 2, 0, 2, 1, 0, 14, 0,
  173. 1, buffer_list_14, csize_list_14},
  174. {"ewa", "ewarp_rw", SRMD, SCC15_BASE, 15, 11, 1, 1, 0, 0, 0, -1, 0, 0,
  175. buffer_list_15, csize_list_15},
  176. {"dp_", "dp_osd_rd", STRM_P, SCC16_BASE, 16, 28, 3, 0, 2, 1, 0, 15, 0,
  177. 1, buffer_list_16, csize_list_16},
  178. {"dp_", "dp_graphic_rd", STRM_P, SCC17_BASE, 17, 29, 3, 0, 2, 1, 0, 16,
  179. 0, 1, buffer_list_17, csize_list_17},
  180. {"dvp", "dvp_osd_rd", STRM_P, SCC18_BASE, 18, 30, 2, 0, 2, 1, 0, 17, 0,
  181. 1, buffer_list_18, csize_list_18},
  182. {"dvp", "dvp_vbi_rd", STRM_D, SCC19_BASE, 19, 31, 1, 0, 0, 1, 0, -1, 0,
  183. 0, buffer_list_19, csize_list_19},
  184. {"tsi", "tsio_wr", STRM_P, SCC20_BASE, 20, 5, 0, 8, 2, 1, 1, -1, 0, 0,
  185. buffer_list_20, csize_list_20},
  186. {"tsi", "tsio_rd", STRM_P, SCC21_BASE, 21, 32, 4, 0, 2, 1, 1, -1, 0, 0,
  187. buffer_list_21, csize_list_21},
  188. {"tsd", "tsd_wr", SRMD, SCC22_BASE, 22, 6, 0, 64, 0, 0, 1, -1, 0, 0,
  189. buffer_list_22, csize_list_22},
  190. {"vd_", "vd_ud_st_rw", SRMD, SCC23_BASE, 23, 12, 2, 2, 0, 0, 1, -1, 0,
  191. 0, buffer_list_23, csize_list_23},
  192. {"vd_", "vd_frr_rd", SRMD, SCC24_BASE, 24, 33, 4, 0, 0, 0, 0, -1, 0, 0,
  193. buffer_list_24, csize_list_24},
  194. {"vd_", "vd_frw_disp_wr", SRMD, SCC25_BASE, 25, 7, 0, 16, 0, 0, 0, -1,
  195. 0, 0, buffer_list_25, csize_list_25},
  196. {"mr_", "mr_vd_m_y_rd", STRM_P, SCC26_BASE, 26, 34, 3, 0, 2, 1, 0, 18,
  197. 0, 1, buffer_list_26, csize_list_26},
  198. {"mr_", "mr_vd_m_c_rd", STRM_P, SCC27_BASE, 27, 35, 3, 0, 2, 1, 0, 19,
  199. 0, 1, buffer_list_27, csize_list_27},
  200. {"mr_", "mr_vd_s_y_rd", STRM_P, SCC28_BASE, 28, 36, 3, 0, 2, 1, 0, 20,
  201. 0, 1, buffer_list_28, csize_list_28},
  202. {"mr_", "mr_vd_s_c_rd", STRM_P, SCC29_BASE, 29, 37, 3, 0, 2, 1, 0, 21,
  203. 0, 1, buffer_list_29, csize_list_29},
  204. {"ga_", "ga_wr", STRM_P, SCC30_BASE, 30, 8, 0, 1, 1, 1, 0, -1, 1, 1,
  205. buffer_list_30, csize_list_30},
  206. {"ga_", "ga_src1_rd", STRM_P, SCC31_BASE, 31, 38, 1, 0, 1, 1, 0, -1, 1,
  207. 1, buffer_list_31, csize_list_31},
  208. {"ga_", "ga_src2_rd", STRM_P, SCC32_BASE, 32, 39, 1, 0, 1, 1, 0, -1, 1,
  209. 1, buffer_list_32, csize_list_32},
  210. {"ad_", "ad_rd", STRM_D, SCC33_BASE, 33, 40, 2, 0, 0, 1, 1, -1, 0, 0,
  211. buffer_list_33, csize_list_33},
  212. {"ad_", "ad_wr", STRM_D, SCC34_BASE, 34, 9, 0, 3, 0, 1, 1, -1, 0, 0,
  213. buffer_list_34, csize_list_34},
  214. {"abp", "abp_rd", STRM_D, SCC35_BASE, 35, 41, 5, 0, 0, 1, 1, -1, 0, 0,
  215. buffer_list_35, csize_list_35},
  216. {"abp", "abp_wr", STRM_D, SCC36_BASE, 36, 10, 0, 3, 0, 1, 1, -1, 0, 0,
  217. buffer_list_36, csize_list_36},
  218. {"ebi", "ebi_rw", STRM_P, SCC37_BASE, 37, 13, 4, 4, 2, 1, 1, -1, 0, 0,
  219. buffer_list_37, csize_list_37},
  220. {"usb", "usb_rw", SRMD, SCC38_BASE, 38, 14, 1, 1, 0, 0, 1, -1, 0, 0,
  221. buffer_list_38, csize_list_38},
  222. {"cpu", "cpu1_spdma_rw", SRMD, SCC39_BASE, 39, 15, 1, 1, 0, 0, 1, -1, 0,
  223. 0, buffer_list_39, csize_list_39},
  224. {"cpu", "cpu1_bridge_rw", SRMD, SCC40_BASE, 40, 16, 0, 0, 0, 0, 0, -1,
  225. 0, 0, buffer_list_40, csize_list_40},
  226. };
  227. /* DMA state structures for read and write channels for each SCC */
  228. static struct scc_dma_state scc_state_rd_0[] = { {-1} };
  229. static struct scc_dma_state scc_state_wr_0[] = { {0}, {0}, {0}, {0} };
  230. static struct scc_dma_state scc_state_rd_1[] = { {0}, {0}, {0}, {0} };
  231. static struct scc_dma_state scc_state_wr_1[] = { {-1} };
  232. static struct scc_dma_state scc_state_rd_2[] = { {-1} };
  233. static struct scc_dma_state scc_state_wr_2[] = { {0}, {0}, {0} };
  234. static struct scc_dma_state scc_state_rd_3[] = { {0}, {0}, {0} };
  235. static struct scc_dma_state scc_state_wr_3[] = { {-1} };
  236. static struct scc_dma_state scc_state_rd_4[] = { {0}, {0}, {0} };
  237. static struct scc_dma_state scc_state_wr_4[] = { {-1} };
  238. static struct scc_dma_state scc_state_rd_5[] = { {-1} };
  239. static struct scc_dma_state scc_state_wr_5[] = { {0} };
  240. static struct scc_dma_state scc_state_rd_6[] = { {0} };
  241. static struct scc_dma_state scc_state_wr_6[] = { {-1} };
  242. static struct scc_dma_state scc_state_rd_7[] = { {-1} };
  243. static struct scc_dma_state scc_state_wr_7[] = { {0}, {0}, {0}, {0} };
  244. static struct scc_dma_state scc_state_rd_8[] = { {0}, {0}, {0}, {0} };
  245. static struct scc_dma_state scc_state_wr_8[] = { {-1} };
  246. static struct scc_dma_state scc_state_rd_9[] = { {0}, {0}, {0}, };
  247. static struct scc_dma_state scc_state_wr_9[] = { {-1} };
  248. static struct scc_dma_state scc_state_rd_10[] = { {0}, {0}, {0} };
  249. static struct scc_dma_state scc_state_wr_10[] = { {-1} };
  250. static struct scc_dma_state scc_state_rd_11[] = { {0}, {0}, {0} };
  251. static struct scc_dma_state scc_state_wr_11[] = { {-1} };
  252. static struct scc_dma_state scc_state_rd_12[] = { {-1} };
  253. static struct scc_dma_state scc_state_wr_12[] = { {0}, {0}, {0}, {0} };
  254. static struct scc_dma_state scc_state_rd_13[] = { {0}, {0}, {0}, {0} };
  255. static struct scc_dma_state scc_state_wr_13[] = { {-1} };
  256. static struct scc_dma_state scc_state_rd_14[] = { {0}, {0} };
  257. static struct scc_dma_state scc_state_wr_14[] = { {-1} };
  258. static struct scc_dma_state scc_state_rd_15[] = { {0} };
  259. static struct scc_dma_state scc_state_wr_15[] = { {0} };
  260. static struct scc_dma_state scc_state_rd_16[] = { {0}, {0}, {0} };
  261. static struct scc_dma_state scc_state_wr_16[] = { {-1} };
  262. static struct scc_dma_state scc_state_rd_17[] = { {0}, {0}, {0} };
  263. static struct scc_dma_state scc_state_wr_17[] = { {-1} };
  264. static struct scc_dma_state scc_state_rd_18[] = { {0}, {0} };
  265. static struct scc_dma_state scc_state_wr_18[] = { {-1} };
  266. static struct scc_dma_state scc_state_rd_19[] = { {0} };
  267. static struct scc_dma_state scc_state_wr_19[] = { {-1} };
  268. static struct scc_dma_state scc_state_rd_20[] = { {-1} };
  269. static struct scc_dma_state scc_state_wr_20[] = {
  270. {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
  271. static struct scc_dma_state scc_state_rd_21[] = { {0}, {0}, {0}, {0} };
  272. static struct scc_dma_state scc_state_wr_21[] = { {-1} };
  273. static struct scc_dma_state scc_state_rd_22[] = { {-1} };
  274. static struct scc_dma_state scc_state_wr_22[] = {
  275. {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
  276. {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
  277. {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
  278. {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
  279. {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
  280. static struct scc_dma_state scc_state_rd_23[] = { {0}, {0} };
  281. static struct scc_dma_state scc_state_wr_23[] = { {0}, {0} };
  282. static struct scc_dma_state scc_state_rd_24[] = { {0}, {0}, {0}, {0} };
  283. static struct scc_dma_state scc_state_wr_24[] = { {-1} };
  284. static struct scc_dma_state scc_state_rd_25[] = { {-1} };
  285. static struct scc_dma_state scc_state_wr_25[] = {
  286. {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
  287. {0}, {0} };
  288. static struct scc_dma_state scc_state_rd_26[] = { {0}, {0}, {0} };
  289. static struct scc_dma_state scc_state_wr_26[] = { {-1} };
  290. static struct scc_dma_state scc_state_rd_27[] = { {0}, {0}, {0} };
  291. static struct scc_dma_state scc_state_wr_27[] = { {-1} };
  292. static struct scc_dma_state scc_state_rd_28[] = { {0}, {0}, {0} };
  293. static struct scc_dma_state scc_state_wr_28[] = { {-1} };
  294. static struct scc_dma_state scc_state_rd_29[] = { {0}, {0}, {0} };
  295. static struct scc_dma_state scc_state_wr_29[] = { {-1} };
  296. static struct scc_dma_state scc_state_rd_30[] = { {-1} };
  297. static struct scc_dma_state scc_state_wr_30[] = { {0} };
  298. static struct scc_dma_state scc_state_rd_31[] = { {0} };
  299. static struct scc_dma_state scc_state_wr_31[] = { {-1} };
  300. static struct scc_dma_state scc_state_rd_32[] = { {0} };
  301. static struct scc_dma_state scc_state_wr_32[] = { {-1} };
  302. static struct scc_dma_state scc_state_rd_33[] = { {0}, {0} };
  303. static struct scc_dma_state scc_state_wr_33[] = { {-1} };
  304. static struct scc_dma_state scc_state_rd_34[] = { {-1} };
  305. static struct scc_dma_state scc_state_wr_34[] = { {0}, {0}, {0} };
  306. static struct scc_dma_state scc_state_rd_35[] = { {0}, {0}, {0}, {0}, {0} };
  307. static struct scc_dma_state scc_state_wr_35[] = { {-1} };
  308. static struct scc_dma_state scc_state_rd_36[] = { {-1} };
  309. static struct scc_dma_state scc_state_wr_36[] = { {0}, {0}, {0} };
  310. static struct scc_dma_state scc_state_rd_37[] = { {0}, {0}, {0}, {0} };
  311. static struct scc_dma_state scc_state_wr_37[] = { {0}, {0}, {0}, {0} };
  312. static struct scc_dma_state scc_state_rd_38[] = { {0} };
  313. static struct scc_dma_state scc_state_wr_38[] = { {0} };
  314. static struct scc_dma_state scc_state_rd_39[] = { {0} };
  315. static struct scc_dma_state scc_state_wr_39[] = { {0} };
  316. static struct scc_dma_state scc_state_rd_40[] = { {-1} };
  317. static struct scc_dma_state scc_state_wr_40[] = { {-1} };
  318. /* DMA state references to access from the driver */
  319. static struct scc_dma_state *scc_state_rd[] = {
  320. scc_state_rd_0,
  321. scc_state_rd_1,
  322. scc_state_rd_2,
  323. scc_state_rd_3,
  324. scc_state_rd_4,
  325. scc_state_rd_5,
  326. scc_state_rd_6,
  327. scc_state_rd_7,
  328. scc_state_rd_8,
  329. scc_state_rd_9,
  330. scc_state_rd_10,
  331. scc_state_rd_11,
  332. scc_state_rd_12,
  333. scc_state_rd_13,
  334. scc_state_rd_14,
  335. scc_state_rd_15,
  336. scc_state_rd_16,
  337. scc_state_rd_17,
  338. scc_state_rd_18,
  339. scc_state_rd_19,
  340. scc_state_rd_20,
  341. scc_state_rd_21,
  342. scc_state_rd_22,
  343. scc_state_rd_23,
  344. scc_state_rd_24,
  345. scc_state_rd_25,
  346. scc_state_rd_26,
  347. scc_state_rd_27,
  348. scc_state_rd_28,
  349. scc_state_rd_29,
  350. scc_state_rd_30,
  351. scc_state_rd_31,
  352. scc_state_rd_32,
  353. scc_state_rd_33,
  354. scc_state_rd_34,
  355. scc_state_rd_35,
  356. scc_state_rd_36,
  357. scc_state_rd_37,
  358. scc_state_rd_38,
  359. scc_state_rd_39,
  360. scc_state_rd_40,
  361. };
  362. static struct scc_dma_state *scc_state_wr[] = {
  363. scc_state_wr_0,
  364. scc_state_wr_1,
  365. scc_state_wr_2,
  366. scc_state_wr_3,
  367. scc_state_wr_4,
  368. scc_state_wr_5,
  369. scc_state_wr_6,
  370. scc_state_wr_7,
  371. scc_state_wr_8,
  372. scc_state_wr_9,
  373. scc_state_wr_10,
  374. scc_state_wr_11,
  375. scc_state_wr_12,
  376. scc_state_wr_13,
  377. scc_state_wr_14,
  378. scc_state_wr_15,
  379. scc_state_wr_16,
  380. scc_state_wr_17,
  381. scc_state_wr_18,
  382. scc_state_wr_19,
  383. scc_state_wr_20,
  384. scc_state_wr_21,
  385. scc_state_wr_22,
  386. scc_state_wr_23,
  387. scc_state_wr_24,
  388. scc_state_wr_25,
  389. scc_state_wr_26,
  390. scc_state_wr_27,
  391. scc_state_wr_28,
  392. scc_state_wr_29,
  393. scc_state_wr_30,
  394. scc_state_wr_31,
  395. scc_state_wr_32,
  396. scc_state_wr_33,
  397. scc_state_wr_34,
  398. scc_state_wr_35,
  399. scc_state_wr_36,
  400. scc_state_wr_37,
  401. scc_state_wr_38,
  402. scc_state_wr_39,
  403. scc_state_wr_40,
  404. };
  405. static u32 scc_takeover_mode = SCC_TO_IMMEDIATE;
  406. /* Change mode of the SPDMA for given direction */
  407. static u32 scc_agu_mode_sp = AGU_BYPASS;
  408. /* Change mode of the USB for given direction */
  409. static u32 scc_agu_mode_usb = AGU_BYPASS;
  410. static union scc_softwareconfiguration scc_software_configuration[SCC_MAX];
  411. static u32 dma_fsm[4][4] = {
  412. /* DMA_CMD_RESET DMA_CMD_SETUP DMA_CMD_START DMA_CMD_STOP */
  413. /* DMA_STATE_RESET */
  414. {DMA_STATE_RESET, DMA_STATE_SETUP, DMA_STATE_ERROR, DMA_STATE_ERROR},
  415. /* DMA_STATE_SETUP */
  416. {DMA_STATE_RESET, DMA_STATE_SETUP, DMA_STATE_START, DMA_STATE_SETUP},
  417. /* DMA_STATE_START */
  418. {DMA_STATE_RESET, DMA_STATE_ERROR, DMA_STATE_START, DMA_STATE_SETUP},
  419. /* DMA_STATE_ERROR */
  420. {DMA_STATE_RESET, DMA_STATE_ERROR, DMA_STATE_ERROR, DMA_STATE_ERROR},
  421. };
  422. static void dma_state_process(struct scc_dma_state *dma_state, u32 cmd)
  423. {
  424. dma_state->dma_status = dma_fsm[dma_state->dma_status][cmd];
  425. dma_state->dma_cmd = cmd;
  426. }
  427. static void dma_state_process_dma_command(struct scc_dma_state *dma_state,
  428. u32 dma_cmd)
  429. {
  430. dma_state->dma_cmd = dma_cmd;
  431. switch (dma_cmd) {
  432. case DMA_START:
  433. case DMA_START_FH_RESET:
  434. dma_state_process(dma_state, DMA_CMD_START);
  435. break;
  436. case DMA_STOP:
  437. dma_state_process(dma_state, DMA_CMD_STOP);
  438. break;
  439. default:
  440. break;
  441. }
  442. }
  443. static void scc_takeover_dma(enum scc_id id, u32 dma_id, u32 drs)
  444. {
  445. union scc_cmd dma_cmd;
  446. dma_cmd.reg = 0;
  447. /* Prepare the takeover for the DMA channel */
  448. dma_cmd.bits.action = DMA_TAKEOVER;
  449. dma_cmd.bits.id = dma_id;
  450. dma_cmd.bits.rid = TO_DMA_CFG; /* this is DMA_CFG register takeover */
  451. if (drs == DMA_WRITE)
  452. dma_cmd.bits.drs = DMA_WRITE;
  453. reg_write(SCC_CMD(scc_descriptor_table[id].base_address), dma_cmd.reg);
  454. }
  455. int scc_dma_cmd(enum scc_id id, u32 cmd, u32 dma_id, u32 drs)
  456. {
  457. union scc_cmd dma_cmd;
  458. struct scc_dma_state *dma_state;
  459. if ((id >= SCC_MAX) || (id < 0))
  460. return -EINVAL;
  461. dma_cmd.reg = 0;
  462. /* Prepare the takeover for the DMA channel */
  463. dma_cmd.bits.action = cmd;
  464. dma_cmd.bits.id = dma_id;
  465. if (drs == DMA_WRITE) {
  466. dma_cmd.bits.drs = DMA_WRITE;
  467. dma_state = &scc_state_wr[id][dma_id];
  468. } else {
  469. dma_state = &scc_state_rd[id][dma_id];
  470. }
  471. dma_state->scc_id = id;
  472. dma_state->dma_id = dma_id;
  473. dma_state_process_dma_command(dma_state, cmd);
  474. reg_write(SCC_CMD(scc_descriptor_table[id].base_address), dma_cmd.reg);
  475. return 0;
  476. }
  477. int scc_set_usb_address_generation_mode(u32 agu_mode)
  478. {
  479. if (AGU_ACTIVE == agu_mode) {
  480. /* Ensure both DMAs are stopped */
  481. scc_dma_cmd(SCC_USB_RW, DMA_STOP, 0, DMA_WRITE);
  482. scc_dma_cmd(SCC_USB_RW, DMA_STOP, 0, DMA_READ);
  483. } else {
  484. agu_mode = AGU_BYPASS;
  485. }
  486. scc_agu_mode_usb = agu_mode;
  487. return 0;
  488. }
  489. int scc_setup_dma(enum scc_id id, u32 buffer_tag,
  490. u32 type, u32 fh_mode, u32 drs, u32 dma_id)
  491. {
  492. struct scc_dma_state *dma_state;
  493. int return_value = 0;
  494. union scc_dma_cfg dma_cfg;
  495. u32 *buffer_tag_list = scc_descriptor_table[id].buffer_tag_list;
  496. u32 tag_count, t, t_valid;
  497. if ((id >= SCC_MAX) || (id < 0))
  498. return -EINVAL;
  499. /* if the register is only configured by hw, cannot write! */
  500. if (1 == scc_descriptor_table[id].hw_dma_cfg)
  501. return -EACCES;
  502. if (DMA_WRITE == drs) {
  503. if (dma_id >= scc_descriptor_table[id].p_dma_channels_wr)
  504. return -EINVAL;
  505. dma_state = &scc_state_wr[id][dma_id];
  506. } else {
  507. if (dma_id >= scc_descriptor_table[id].p_dma_channels_rd)
  508. return -EINVAL;
  509. dma_state = &scc_state_rd[id][dma_id];
  510. }
  511. /* Compose the DMA configuration register */
  512. tag_count = buffer_tag_list[0];
  513. t_valid = 0;
  514. for (t = 1; t <= tag_count; t++) {
  515. if (buffer_tag == buffer_tag_list[t]) {
  516. /* Tag found - validate */
  517. t_valid = 1;
  518. break;
  519. }
  520. }
  521. if (!t_valid)
  522. return -EACCES;
  523. /*
  524. * Read the register first -- two functions write into the register
  525. * it does not make sense to read the DMA config back, because there
  526. * are two register configuration sets (drs)
  527. */
  528. dma_cfg.reg = 0;
  529. dma_cfg.bits.buffer_id = buffer_tag;
  530. dma_state_process(dma_state, DMA_CMD_SETUP);
  531. /*
  532. * This is Packet CFG set select - usable for TSIO, EBI and those SCCs
  533. * which habe 2 packet configs
  534. */
  535. dma_cfg.bits.packet_cfg_id =
  536. scc_software_configuration[id].bits.packet_select;
  537. if (type == DMA_CYCLIC)
  538. dma_cfg.bits.buffer_type = 1;
  539. else
  540. dma_cfg.bits.buffer_type = 0;
  541. if (fh_mode == USE_FH)
  542. dma_cfg.bits.fh_mode = 1;
  543. else
  544. dma_cfg.bits.fh_mode = 0;
  545. if (id == SCC_CPU1_SPDMA_RW)
  546. dma_cfg.bits.agu_mode = scc_agu_mode_sp;
  547. if (id == SCC_USB_RW)
  548. dma_cfg.bits.agu_mode = scc_agu_mode_usb;
  549. reg_write(SCC_DMA_CFG(scc_descriptor_table[id].base_address),
  550. dma_cfg.reg);
  551. /* The DMA_CFG needs a takeover! */
  552. if (SCC_TO_IMMEDIATE == scc_takeover_mode)
  553. scc_takeover_dma(id, dma_id, drs);
  554. /* if (buffer_tag is not used) */
  555. dma_state->buffer_tag = buffer_tag;
  556. dma_state->scc_id = id;
  557. dma_state->dma_id = dma_id;
  558. return return_value;
  559. }
  560. int scc_enable(enum scc_id id, u32 value)
  561. {
  562. if ((id >= SCC_MAX) || (id < 0))
  563. return -EINVAL;
  564. if (value == 0) {
  565. scc_software_configuration[id].bits.enable_status = 0;
  566. } else {
  567. value = 1;
  568. scc_software_configuration[id].bits.enable_status = 1;
  569. }
  570. reg_write(SCC_ENABLE(scc_descriptor_table[id].base_address), value);
  571. return 0;
  572. }
  573. static inline void ehb(void)
  574. {
  575. __asm__ __volatile__(
  576. " .set mips32r2 \n"
  577. " ehb \n"
  578. " .set mips0 \n");
  579. }
  580. int scc_reset(enum scc_id id, u32 value)
  581. {
  582. if ((id >= SCC_MAX) || (id < 0))
  583. return -EINVAL;
  584. /* Invert value to the strait logic from the negative hardware logic */
  585. if (value == 0)
  586. value = 1;
  587. else
  588. value = 0;
  589. /* Write the value to the register */
  590. reg_write(SCC_RESET(scc_descriptor_table[id].base_address), value);
  591. /* sync flush */
  592. asm("sync"); /* request bus write queue flush */
  593. ehb(); /* wait until previous bus commit instr has finished */
  594. asm("nop"); /* wait for flush to occur */
  595. asm("nop"); /* wait for flush to occur */
  596. udelay(100);
  597. return 0;
  598. }