qos_init.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /*
  2. * Copyright (c) 2015-2019, 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. #include "qos_init.h"
  10. #include "qos_common.h"
  11. #include "qos_reg.h"
  12. #include "rcar_def.h"
  13. #if RCAR_LSI == RCAR_AUTO
  14. #include "H3/qos_init_h3_v10.h"
  15. #include "H3/qos_init_h3_v11.h"
  16. #include "H3/qos_init_h3_v20.h"
  17. #include "H3/qos_init_h3_v30.h"
  18. #include "M3/qos_init_m3_v10.h"
  19. #include "M3/qos_init_m3_v11.h"
  20. #include "M3/qos_init_m3_v30.h"
  21. #include "M3N/qos_init_m3n_v10.h"
  22. #include "V3M/qos_init_v3m.h"
  23. #endif
  24. #if RCAR_LSI == RCAR_H3 /* H3 */
  25. #include "H3/qos_init_h3_v10.h"
  26. #include "H3/qos_init_h3_v11.h"
  27. #include "H3/qos_init_h3_v20.h"
  28. #include "H3/qos_init_h3_v30.h"
  29. #endif
  30. #if RCAR_LSI == RCAR_H3N /* H3 */
  31. #include "H3/qos_init_h3n_v30.h"
  32. #endif
  33. #if RCAR_LSI == RCAR_M3 /* M3 */
  34. #include "M3/qos_init_m3_v10.h"
  35. #include "M3/qos_init_m3_v11.h"
  36. #include "M3/qos_init_m3_v30.h"
  37. #endif
  38. #if RCAR_LSI == RCAR_M3N /* M3N */
  39. #include "M3N/qos_init_m3n_v10.h"
  40. #endif
  41. #if RCAR_LSI == RCAR_V3M /* V3M */
  42. #include "V3M/qos_init_v3m.h"
  43. #endif
  44. #if RCAR_LSI == RCAR_E3 /* E3 */
  45. #include "E3/qos_init_e3_v10.h"
  46. #endif
  47. #if RCAR_LSI == RCAR_D3 /* D3 */
  48. #include "D3/qos_init_d3.h"
  49. #endif
  50. #if (RCAR_LSI != RCAR_E3) && (RCAR_LSI != RCAR_D3) && (RCAR_LSI != RCAR_V3M)
  51. #define DRAM_CH_CNT 0x04
  52. uint32_t qos_init_ddr_ch;
  53. uint8_t qos_init_ddr_phyvalid;
  54. #endif
  55. #define PRR_PRODUCT_ERR(reg) \
  56. do { \
  57. ERROR("LSI Product ID(PRR=0x%x) QoS " \
  58. "initialize not supported.\n", reg); \
  59. panic(); \
  60. } while (0)
  61. #define PRR_CUT_ERR(reg) \
  62. do { \
  63. ERROR("LSI Cut ID(PRR=0x%x) QoS " \
  64. "initialize not supported.\n", reg); \
  65. panic(); \
  66. } while (0)
  67. void rcar_qos_init(void)
  68. {
  69. uint32_t reg;
  70. #if (RCAR_LSI != RCAR_E3) && (RCAR_LSI != RCAR_D3) && (RCAR_LSI != RCAR_V3M)
  71. uint32_t i;
  72. qos_init_ddr_ch = 0;
  73. qos_init_ddr_phyvalid = get_boardcnf_phyvalid();
  74. for (i = 0; i < DRAM_CH_CNT; i++) {
  75. if ((qos_init_ddr_phyvalid & (1 << i))) {
  76. qos_init_ddr_ch++;
  77. }
  78. }
  79. #endif
  80. reg = mmio_read_32(PRR);
  81. #if (RCAR_LSI == RCAR_AUTO) || RCAR_LSI_CUT_COMPAT
  82. switch (reg & PRR_PRODUCT_MASK) {
  83. case PRR_PRODUCT_H3:
  84. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_H3)
  85. switch (reg & PRR_CUT_MASK) {
  86. case PRR_PRODUCT_10:
  87. qos_init_h3_v10();
  88. break;
  89. case PRR_PRODUCT_11:
  90. qos_init_h3_v11();
  91. break;
  92. case PRR_PRODUCT_20:
  93. qos_init_h3_v20();
  94. break;
  95. case PRR_PRODUCT_30:
  96. default:
  97. qos_init_h3_v30();
  98. break;
  99. }
  100. #elif (RCAR_LSI == RCAR_H3N)
  101. switch (reg & PRR_CUT_MASK) {
  102. case PRR_PRODUCT_30:
  103. default:
  104. qos_init_h3n_v30();
  105. break;
  106. }
  107. #else
  108. PRR_PRODUCT_ERR(reg);
  109. #endif
  110. break;
  111. case PRR_PRODUCT_M3:
  112. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3)
  113. switch (reg & PRR_CUT_MASK) {
  114. case PRR_PRODUCT_10:
  115. qos_init_m3_v10();
  116. break;
  117. case PRR_PRODUCT_21: /* M3 Cut 13 */
  118. qos_init_m3_v11();
  119. break;
  120. case PRR_PRODUCT_30: /* M3 Cut 30 */
  121. default:
  122. qos_init_m3_v30();
  123. break;
  124. }
  125. #else
  126. PRR_PRODUCT_ERR(reg);
  127. #endif
  128. break;
  129. case PRR_PRODUCT_M3N:
  130. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3N)
  131. switch (reg & PRR_CUT_MASK) {
  132. case PRR_PRODUCT_10:
  133. default:
  134. qos_init_m3n_v10();
  135. break;
  136. }
  137. #else
  138. PRR_PRODUCT_ERR(reg);
  139. #endif
  140. break;
  141. case PRR_PRODUCT_V3M:
  142. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_V3M)
  143. switch (reg & PRR_CUT_MASK) {
  144. case PRR_PRODUCT_10:
  145. case PRR_PRODUCT_20:
  146. default:
  147. qos_init_v3m();
  148. break;
  149. }
  150. #else
  151. PRR_PRODUCT_ERR(reg);
  152. #endif
  153. break;
  154. case PRR_PRODUCT_E3:
  155. #if (RCAR_LSI == RCAR_E3)
  156. switch (reg & PRR_CUT_MASK) {
  157. case PRR_PRODUCT_10:
  158. default:
  159. qos_init_e3_v10();
  160. break;
  161. }
  162. #else
  163. PRR_PRODUCT_ERR(reg);
  164. #endif
  165. break;
  166. case PRR_PRODUCT_D3:
  167. #if (RCAR_LSI == RCAR_D3)
  168. switch (reg & PRR_CUT_MASK) {
  169. case PRR_PRODUCT_10:
  170. default:
  171. qos_init_d3();
  172. break;
  173. }
  174. #else
  175. PRR_PRODUCT_ERR(reg);
  176. #endif
  177. break;
  178. default:
  179. PRR_PRODUCT_ERR(reg);
  180. break;
  181. }
  182. #else
  183. #if RCAR_LSI == RCAR_H3 /* H3 */
  184. #if RCAR_LSI_CUT == RCAR_CUT_10
  185. /* H3 Cut 10 */
  186. if ((PRR_PRODUCT_H3 | PRR_PRODUCT_10)
  187. != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
  188. PRR_PRODUCT_ERR(reg);
  189. }
  190. qos_init_h3_v10();
  191. #elif RCAR_LSI_CUT == RCAR_CUT_11
  192. /* H3 Cut 11 */
  193. if ((PRR_PRODUCT_H3 | PRR_PRODUCT_11)
  194. != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
  195. PRR_PRODUCT_ERR(reg);
  196. }
  197. qos_init_h3_v11();
  198. #elif RCAR_LSI_CUT == RCAR_CUT_20
  199. /* H3 Cut 20 */
  200. if ((PRR_PRODUCT_H3 | PRR_PRODUCT_20)
  201. != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
  202. PRR_PRODUCT_ERR(reg);
  203. }
  204. qos_init_h3_v20();
  205. #else
  206. /* H3 Cut 30 or later */
  207. if ((PRR_PRODUCT_H3)
  208. != (reg & (PRR_PRODUCT_MASK))) {
  209. PRR_PRODUCT_ERR(reg);
  210. }
  211. qos_init_h3_v30();
  212. #endif
  213. #elif RCAR_LSI == RCAR_H3N /* H3 */
  214. /* H3N Cut 30 or later */
  215. if ((PRR_PRODUCT_H3)
  216. != (reg & (PRR_PRODUCT_MASK))) {
  217. PRR_PRODUCT_ERR(reg);
  218. }
  219. qos_init_h3n_v30();
  220. #elif RCAR_LSI == RCAR_M3 /* M3 */
  221. #if RCAR_LSI_CUT == RCAR_CUT_10
  222. /* M3 Cut 10 */
  223. if ((PRR_PRODUCT_M3 | PRR_PRODUCT_10)
  224. != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
  225. PRR_PRODUCT_ERR(reg);
  226. }
  227. qos_init_m3_v10();
  228. #elif RCAR_LSI_CUT == RCAR_CUT_11
  229. /* M3 Cut 11 */
  230. if ((PRR_PRODUCT_M3 | PRR_PRODUCT_20)
  231. != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
  232. PRR_PRODUCT_ERR(reg);
  233. }
  234. qos_init_m3_v11();
  235. #elif RCAR_LSI_CUT == RCAR_CUT_13
  236. /* M3 Cut 13 */
  237. if ((PRR_PRODUCT_M3 | PRR_PRODUCT_21)
  238. != (reg & (PRR_PRODUCT_MASK | PRR_CUT_MASK))) {
  239. PRR_PRODUCT_ERR(reg);
  240. }
  241. qos_init_m3_v11();
  242. #else
  243. /* M3 Cut 30 or later */
  244. if ((PRR_PRODUCT_M3)
  245. != (reg & (PRR_PRODUCT_MASK))) {
  246. PRR_PRODUCT_ERR(reg);
  247. }
  248. qos_init_m3_v30();
  249. #endif
  250. #elif RCAR_LSI == RCAR_M3N /* M3N */
  251. /* M3N Cut 10 or later */
  252. if ((PRR_PRODUCT_M3N)
  253. != (reg & (PRR_PRODUCT_MASK))) {
  254. PRR_PRODUCT_ERR(reg);
  255. }
  256. qos_init_m3n_v10();
  257. #elif RCAR_LSI == RCAR_V3M /* V3M */
  258. /* V3M Cut 10 or later */
  259. if ((PRR_PRODUCT_V3M)
  260. != (reg & (PRR_PRODUCT_MASK))) {
  261. PRR_PRODUCT_ERR(reg);
  262. }
  263. qos_init_v3m();
  264. #elif RCAR_LSI == RCAR_D3 /* D3 */
  265. /* D3 Cut 10 or later */
  266. if ((PRR_PRODUCT_D3)
  267. != (reg & (PRR_PRODUCT_MASK))) {
  268. PRR_PRODUCT_ERR(reg);
  269. }
  270. qos_init_d3();
  271. #elif RCAR_LSI == RCAR_E3 /* E3 */
  272. /* E3 Cut 10 or later */
  273. if ((PRR_PRODUCT_E3)
  274. != (reg & (PRR_PRODUCT_MASK))) {
  275. PRR_PRODUCT_ERR(reg);
  276. }
  277. qos_init_e3_v10();
  278. #else
  279. #error "Don't have QoS initialize routine(Unknown chip)."
  280. #endif
  281. #endif
  282. }
  283. #if (RCAR_LSI != RCAR_E3) && (RCAR_LSI != RCAR_D3) && (RCAR_LSI != RCAR_V3M)
  284. uint32_t get_refperiod(void)
  285. {
  286. uint32_t refperiod = QOSWT_WTSET0_CYCLE;
  287. #if (RCAR_LSI == RCAR_AUTO) || RCAR_LSI_CUT_COMPAT
  288. uint32_t reg;
  289. reg = mmio_read_32(PRR);
  290. switch (reg & PRR_PRODUCT_MASK) {
  291. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_H3)
  292. case PRR_PRODUCT_H3:
  293. switch (reg & PRR_CUT_MASK) {
  294. case PRR_PRODUCT_10:
  295. case PRR_PRODUCT_11:
  296. break;
  297. case PRR_PRODUCT_20:
  298. case PRR_PRODUCT_30:
  299. default:
  300. refperiod = REFPERIOD_CYCLE;
  301. break;
  302. }
  303. break;
  304. #elif (RCAR_LSI == RCAR_H3N)
  305. case PRR_PRODUCT_H3:
  306. switch (reg & PRR_CUT_MASK) {
  307. case PRR_PRODUCT_30:
  308. default:
  309. refperiod = REFPERIOD_CYCLE;
  310. break;
  311. }
  312. break;
  313. #endif
  314. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3)
  315. case PRR_PRODUCT_M3:
  316. switch (reg & PRR_CUT_MASK) {
  317. case PRR_PRODUCT_10:
  318. break;
  319. case PRR_PRODUCT_20: /* M3 Cut 11 */
  320. case PRR_PRODUCT_21: /* M3 Cut 13 */
  321. case PRR_PRODUCT_30: /* M3 Cut 30 */
  322. default:
  323. refperiod = REFPERIOD_CYCLE;
  324. break;
  325. }
  326. break;
  327. #endif
  328. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3N)
  329. case PRR_PRODUCT_M3N:
  330. refperiod = REFPERIOD_CYCLE;
  331. break;
  332. #endif
  333. default:
  334. break;
  335. }
  336. #elif RCAR_LSI == RCAR_H3
  337. #if RCAR_LSI_CUT == RCAR_CUT_10
  338. /* H3 Cut 10 */
  339. #elif RCAR_LSI_CUT == RCAR_CUT_11
  340. /* H3 Cut 11 */
  341. #else
  342. /* H3 Cut 20 */
  343. /* H3 Cut 30 or later */
  344. refperiod = REFPERIOD_CYCLE;
  345. #endif
  346. #elif RCAR_LSI == RCAR_H3N
  347. /* H3N Cut 30 or later */
  348. refperiod = REFPERIOD_CYCLE;
  349. #elif RCAR_LSI == RCAR_M3
  350. #if RCAR_LSI_CUT == RCAR_CUT_10
  351. /* M3 Cut 10 */
  352. #else
  353. /* M3 Cut 11 */
  354. /* M3 Cut 13 */
  355. /* M3 Cut 30 or later */
  356. refperiod = REFPERIOD_CYCLE;
  357. #endif
  358. #elif RCAR_LSI == RCAR_M3N /* for M3N */
  359. refperiod = REFPERIOD_CYCLE;
  360. #endif
  361. return refperiod;
  362. }
  363. #endif
  364. void rcar_qos_dbsc_setting(struct rcar_gen3_dbsc_qos_settings *qos,
  365. unsigned int qos_size, bool dbsc_wren)
  366. {
  367. int i;
  368. /* Register write enable */
  369. if (dbsc_wren)
  370. io_write_32(DBSC_DBSYSCNT0, 0x00001234U);
  371. for (i = 0; i < qos_size; i++)
  372. io_write_32(qos[i].reg, qos[i].val);
  373. /* Register write protect */
  374. if (dbsc_wren)
  375. io_write_32(DBSC_DBSYSCNT0, 0x00000000U);
  376. }