qos_init.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * Copyright (c) 2021, Renesas Electronics Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include <common/debug.h>
  8. #include <lib/mmio.h>
  9. #if RCAR_LSI == RCAR_AUTO
  10. #include "G2E/qos_init_g2e_v10.h"
  11. #include "G2H/qos_init_g2h_v30.h"
  12. #include "G2M/qos_init_g2m_v10.h"
  13. #include "G2M/qos_init_g2m_v11.h"
  14. #include "G2M/qos_init_g2m_v30.h"
  15. #include "G2N/qos_init_g2n_v10.h"
  16. #endif /* RCAR_LSI == RCAR_AUTO */
  17. #if (RCAR_LSI == RZ_G2M)
  18. #include "G2M/qos_init_g2m_v10.h"
  19. #include "G2M/qos_init_g2m_v11.h"
  20. #include "G2M/qos_init_g2m_v30.h"
  21. #endif /* RCAR_LSI == RZ_G2M */
  22. #if RCAR_LSI == RZ_G2H
  23. #include "G2H/qos_init_g2h_v30.h"
  24. #endif /* RCAR_LSI == RZ_G2H */
  25. #if RCAR_LSI == RZ_G2N
  26. #include "G2N/qos_init_g2n_v10.h"
  27. #endif /* RCAR_LSI == RZ_G2N */
  28. #if RCAR_LSI == RZ_G2E
  29. #include "G2E/qos_init_g2e_v10.h"
  30. #endif /* RCAR_LSI == RZ_G2E */
  31. #include "qos_common.h"
  32. #include "qos_init.h"
  33. #include "qos_reg.h"
  34. #include "rcar_def.h"
  35. #if (RCAR_LSI != RZ_G2E)
  36. #define DRAM_CH_CNT 0x04U
  37. uint32_t qos_init_ddr_ch;
  38. uint8_t qos_init_ddr_phyvalid;
  39. #endif /* RCAR_LSI != RZ_G2E */
  40. #define PRR_PRODUCT_ERR(reg) \
  41. { \
  42. ERROR("LSI Product ID(PRR=0x%x) QoS " \
  43. "initialize not supported.\n", reg); \
  44. panic(); \
  45. }
  46. #define PRR_CUT_ERR(reg) \
  47. { \
  48. ERROR("LSI Cut ID(PRR=0x%x) QoS " \
  49. "initialize not supported.\n", reg); \
  50. panic(); \
  51. }
  52. void rzg_qos_init(void)
  53. {
  54. uint32_t reg;
  55. #if (RCAR_LSI != RZ_G2E)
  56. uint32_t i;
  57. qos_init_ddr_ch = 0U;
  58. qos_init_ddr_phyvalid = get_boardcnf_phyvalid();
  59. for (i = 0U; i < DRAM_CH_CNT; i++) {
  60. if ((qos_init_ddr_phyvalid & (1U << i))) {
  61. qos_init_ddr_ch++;
  62. }
  63. }
  64. #endif /* RCAR_LSI != RZ_G2E */
  65. reg = mmio_read_32(PRR);
  66. #if (RCAR_LSI == RCAR_AUTO) || RCAR_LSI_CUT_COMPAT
  67. switch (reg & PRR_PRODUCT_MASK) {
  68. case PRR_PRODUCT_M3:
  69. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M)
  70. switch (reg & PRR_CUT_MASK) {
  71. case PRR_PRODUCT_10:
  72. qos_init_g2m_v10();
  73. break;
  74. case PRR_PRODUCT_21: /* G2M Cut 13 */
  75. qos_init_g2m_v11();
  76. break;
  77. case PRR_PRODUCT_30: /* G2M Cut 30 */
  78. default:
  79. qos_init_g2m_v30();
  80. break;
  81. }
  82. #else /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M) */
  83. PRR_PRODUCT_ERR(reg);
  84. #endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M) */
  85. break;
  86. case PRR_PRODUCT_H3:
  87. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2H)
  88. switch (reg & PRR_CUT_MASK) {
  89. case PRR_PRODUCT_30:
  90. default:
  91. qos_init_g2h_v30();
  92. break;
  93. }
  94. #else
  95. PRR_PRODUCT_ERR(reg);
  96. #endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2H) */
  97. break;
  98. case PRR_PRODUCT_M3N:
  99. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2N)
  100. switch (reg & PRR_CUT_MASK) {
  101. case PRR_PRODUCT_10:
  102. default:
  103. qos_init_g2n_v10();
  104. break;
  105. }
  106. #else
  107. PRR_PRODUCT_ERR(reg);
  108. #endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2N) */
  109. break;
  110. case PRR_PRODUCT_E3:
  111. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2E)
  112. switch (reg & PRR_CUT_MASK) {
  113. case PRR_PRODUCT_10:
  114. default:
  115. qos_init_g2e_v10();
  116. break;
  117. }
  118. #else
  119. PRR_PRODUCT_ERR(reg);
  120. #endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2E) */
  121. break;
  122. default:
  123. PRR_PRODUCT_ERR(reg);
  124. break;
  125. }
  126. #else /* RCAR_LSI == RCAR_AUTO || RCAR_LSI_CUT_COMPAT */
  127. #if (RCAR_LSI == RZ_G2M)
  128. #if RCAR_LSI_CUT == RCAR_CUT_10
  129. /* G2M Cut 10 */
  130. if ((PRR_PRODUCT_M3 | PRR_PRODUCT_10)
  131. != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
  132. PRR_PRODUCT_ERR(reg);
  133. }
  134. qos_init_g2m_v10();
  135. #elif RCAR_LSI_CUT == RCAR_CUT_11
  136. /* G2M Cut 11 */
  137. if ((PRR_PRODUCT_M3 | PRR_PRODUCT_20)
  138. != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
  139. PRR_PRODUCT_ERR(reg);
  140. }
  141. qos_init_g2m_v11();
  142. #elif RCAR_LSI_CUT == RCAR_CUT_13
  143. /* G2M Cut 13 */
  144. if ((PRR_PRODUCT_M3 | PRR_PRODUCT_21)
  145. != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
  146. PRR_PRODUCT_ERR(reg);
  147. }
  148. qos_init_g2m_v11();
  149. #else
  150. /* G2M Cut 30 or later */
  151. if ((PRR_PRODUCT_M3)
  152. != (reg & (PRR_PRODUCT_MASK))) {
  153. PRR_PRODUCT_ERR(reg);
  154. }
  155. qos_init_g2m_v30();
  156. #endif /* RCAR_LSI_CUT == RCAR_CUT_10 */
  157. #elif (RCAR_LSI == RZ_G2H)
  158. /* G2H Cut 30 or later */
  159. if ((reg & PRR_PRODUCT_MASK) != PRR_PRODUCT_H3) {
  160. PRR_PRODUCT_ERR(reg);
  161. }
  162. qos_init_g2h_v30();
  163. #elif (RCAR_LSI == RZ_G2N)
  164. /* G2N Cut 10 or later */
  165. if ((reg & (PRR_PRODUCT_MASK)) != PRR_PRODUCT_M3N) {
  166. PRR_PRODUCT_ERR(reg);
  167. }
  168. qos_init_g2n_v10();
  169. #elif RCAR_LSI == RZ_G2E
  170. /* G2E Cut 10 or later */
  171. if ((reg & (PRR_PRODUCT_MASK)) != PRR_PRODUCT_E3) {
  172. PRR_PRODUCT_ERR(reg);
  173. }
  174. qos_init_g2e_v10();
  175. #else /* (RCAR_LSI == RZ_G2M) */
  176. #error "Don't have QoS initialize routine(Unknown chip)."
  177. #endif /* (RCAR_LSI == RZ_G2M) */
  178. #endif /* RCAR_LSI == RCAR_AUTO || RCAR_LSI_CUT_COMPAT */
  179. }
  180. #if (RCAR_LSI != RZ_G2E)
  181. uint32_t get_refperiod(void)
  182. {
  183. uint32_t refperiod = QOSWT_WTSET0_CYCLE;
  184. #if (RCAR_LSI == RCAR_AUTO) || RCAR_LSI_CUT_COMPAT
  185. uint32_t reg;
  186. reg = mmio_read_32(PRR);
  187. switch (reg & PRR_PRODUCT_MASK) {
  188. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M)
  189. case PRR_PRODUCT_M3:
  190. switch (reg & PRR_CUT_MASK) {
  191. case PRR_PRODUCT_10:
  192. break;
  193. case PRR_PRODUCT_20: /* G2M Cut 11 */
  194. case PRR_PRODUCT_21: /* G2M Cut 13 */
  195. case PRR_PRODUCT_30: /* G2M Cut 30 */
  196. default:
  197. refperiod = REFPERIOD_CYCLE;
  198. break;
  199. }
  200. break;
  201. #endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2M) */
  202. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2H)
  203. case PRR_PRODUCT_H3:
  204. switch (reg & PRR_CUT_MASK) {
  205. case PRR_PRODUCT_30:
  206. default:
  207. refperiod = REFPERIOD_CYCLE;
  208. break;
  209. }
  210. break;
  211. #endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2H) */
  212. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2N)
  213. case PRR_PRODUCT_M3N:
  214. refperiod = REFPERIOD_CYCLE;
  215. break;
  216. #endif /* (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RZ_G2N) */
  217. default:
  218. break;
  219. }
  220. #elif RCAR_LSI == RZ_G2M
  221. #if RCAR_LSI_CUT == RCAR_CUT_10
  222. /* G2M Cut 10 */
  223. #else /* RCAR_LSI_CUT == RCAR_CUT_10 */
  224. /* G2M Cut 11|13|30 or later */
  225. refperiod = REFPERIOD_CYCLE;
  226. #endif /* RCAR_LSI_CUT == RCAR_CUT_10 */
  227. #elif RCAR_LSI == RZ_G2N
  228. refperiod = REFPERIOD_CYCLE;
  229. #elif RCAR_LSI == RZ_G2H
  230. /* G2H Cut 30 or later */
  231. refperiod = REFPERIOD_CYCLE;
  232. #endif /* RCAR_LSI == RCAR_AUTO || RCAR_LSI_CUT_COMPAT */
  233. return refperiod;
  234. }
  235. #endif /* RCAR_LSI != RZ_G2E */
  236. void rzg_qos_dbsc_setting(const struct rcar_gen3_dbsc_qos_settings *qos,
  237. unsigned int qos_size, bool dbsc_wren)
  238. {
  239. unsigned int i;
  240. /* Register write enable */
  241. if (dbsc_wren) {
  242. mmio_write_32(DBSC_DBSYSCNT0, 0x00001234U);
  243. }
  244. for (i = 0; i < qos_size; i++) {
  245. mmio_write_32(qos[i].reg, qos[i].val);
  246. }
  247. /* Register write protect */
  248. if (dbsc_wren) {
  249. mmio_write_32(DBSC_DBSYSCNT0, 0x00000000U);
  250. }
  251. }