bl2_cpg_init.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /*
  2. * Copyright (c) 2015-2021, Renesas Electronics Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include <lib/mmio.h>
  8. #include "cpg_registers.h"
  9. #include "rcar_def.h"
  10. #include "rcar_private.h"
  11. static void bl2_secure_cpg_init(void);
  12. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_H3) || \
  13. (RCAR_LSI == RCAR_H3N) || (RCAR_LSI == RZ_G2H)
  14. static void bl2_realtime_cpg_init_h3(void);
  15. static void bl2_system_cpg_init_h3(void);
  16. #endif
  17. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3) || (RCAR_LSI == RZ_G2M)
  18. static void bl2_realtime_cpg_init_m3(void);
  19. static void bl2_system_cpg_init_m3(void);
  20. #endif
  21. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3N) || (RCAR_LSI == RZ_G2N)
  22. static void bl2_realtime_cpg_init_m3n(void);
  23. static void bl2_system_cpg_init_m3n(void);
  24. #endif
  25. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_V3M)
  26. static void bl2_realtime_cpg_init_v3m(void);
  27. static void bl2_system_cpg_init_v3m(void);
  28. #endif
  29. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RZ_G2E)
  30. static void bl2_realtime_cpg_init_e3(void);
  31. static void bl2_system_cpg_init_e3(void);
  32. #endif
  33. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_D3)
  34. static void bl2_system_cpg_init_d3(void);
  35. #endif
  36. typedef struct {
  37. uintptr_t adr;
  38. uint32_t val;
  39. } reg_setting_t;
  40. static void bl2_secure_cpg_init(void)
  41. {
  42. uint32_t stop_cr2, reset_cr2;
  43. uint32_t stop_cr4, reset_cr4;
  44. uint32_t stop_cr5, reset_cr5;
  45. #if (RCAR_LSI == RCAR_D3)
  46. reset_cr2 = 0x00000000U;
  47. stop_cr2 = 0xFFFFFFFFU;
  48. #elif (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RZ_G2E)
  49. reset_cr2 = 0x10000000U;
  50. stop_cr2 = 0xEFFFFFFFU;
  51. #else
  52. reset_cr2 = 0x14000000U;
  53. stop_cr2 = 0xEBFFFFFFU;
  54. #endif
  55. #if (RCAR_LSI == RCAR_D3)
  56. reset_cr4 = 0x00000000U;
  57. stop_cr4 = 0xFFFFFFFFU;
  58. reset_cr5 = 0x00000000U;
  59. stop_cr5 = 0xFFFFFFFFU;
  60. #else
  61. reset_cr4 = 0x80000003U;
  62. stop_cr4 = 0x7FFFFFFFU;
  63. reset_cr5 = 0x40000000U;
  64. stop_cr5 = 0xBFFFFFFFU;
  65. #endif
  66. /* Secure Module Stop Control Registers */
  67. cpg_write(SCMSTPCR0, 0xFFFFFFFFU);
  68. cpg_write(SCMSTPCR1, 0xFFFFFFFFU);
  69. cpg_write(SCMSTPCR2, stop_cr2);
  70. cpg_write(SCMSTPCR3, 0xFFFFFFFFU);
  71. cpg_write(SCMSTPCR4, stop_cr4);
  72. cpg_write(SCMSTPCR5, stop_cr5);
  73. cpg_write(SCMSTPCR6, 0xFFFFFFFFU);
  74. cpg_write(SCMSTPCR7, 0xFFFFFFFFU);
  75. cpg_write(SCMSTPCR8, 0xFFFFFFFFU);
  76. cpg_write(SCMSTPCR9, 0xFFFDFFFFU);
  77. cpg_write(SCMSTPCR10, 0xFFFFFFFFU);
  78. cpg_write(SCMSTPCR11, 0xFFFFFFFFU);
  79. /* Secure Software Reset Access Enable Control Registers */
  80. cpg_write(SCSRSTECR0, 0x00000000U);
  81. cpg_write(SCSRSTECR1, 0x00000000U);
  82. cpg_write(SCSRSTECR2, reset_cr2);
  83. cpg_write(SCSRSTECR3, 0x00000000U);
  84. cpg_write(SCSRSTECR4, reset_cr4);
  85. cpg_write(SCSRSTECR5, reset_cr5);
  86. cpg_write(SCSRSTECR6, 0x00000000U);
  87. cpg_write(SCSRSTECR7, 0x00000000U);
  88. cpg_write(SCSRSTECR8, 0x00000000U);
  89. cpg_write(SCSRSTECR9, 0x00020000U);
  90. cpg_write(SCSRSTECR10, 0x00000000U);
  91. cpg_write(SCSRSTECR11, 0x00000000U);
  92. }
  93. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_H3) || \
  94. (RCAR_LSI == RCAR_H3N) || (RCAR_LSI == RZ_G2H)
  95. static void bl2_realtime_cpg_init_h3(void)
  96. {
  97. uint32_t cut = mmio_read_32(RCAR_PRR) & PRR_CUT_MASK;
  98. uint32_t cr0, cr8;
  99. cr0 = (cut == PRR_PRODUCT_10 || cut == PRR_PRODUCT_11) ?
  100. 0x00200000U : 0x00210000U;
  101. cr8 = (cut == PRR_PRODUCT_10 || cut == PRR_PRODUCT_11) ?
  102. 0x01F1FFF4U : 0x01F1FFF7U;
  103. cpg_write(RMSTPCR0, cr0);
  104. cpg_write(RMSTPCR1, 0xFFFFFFFFU);
  105. cpg_write(RMSTPCR2, 0x040E0FDCU);
  106. cpg_write(RMSTPCR3, 0xFFFFFFDFU);
  107. cpg_write(RMSTPCR4, 0x80000004U);
  108. cpg_write(RMSTPCR5, 0xC3FFFFFFU);
  109. cpg_write(RMSTPCR6, 0xFFFFFFFFU);
  110. cpg_write(RMSTPCR7, 0xFFFFFFFFU);
  111. cpg_write(RMSTPCR8, cr8);
  112. cpg_write(RMSTPCR9, 0xFFFFFFFEU);
  113. cpg_write(RMSTPCR10, 0xFFFEFFE0U);
  114. cpg_write(RMSTPCR11, 0x000000B7U);
  115. }
  116. static void bl2_system_cpg_init_h3(void)
  117. {
  118. /** System Module Stop Control Registers */
  119. cpg_write(SMSTPCR0, 0x00210000U);
  120. cpg_write(SMSTPCR1, 0xFFFFFFFFU);
  121. cpg_write(SMSTPCR2, 0x040E2FDCU);
  122. cpg_write(SMSTPCR3, 0xFFFFFBDFU);
  123. cpg_write(SMSTPCR4, 0x80000000U | (mmio_read_32(SMSTPCR4) & 0x4));
  124. cpg_write(SMSTPCR5, 0xC3FFFFFFU);
  125. cpg_write(SMSTPCR6, 0xFFFFFFFFU);
  126. cpg_write(SMSTPCR7, 0xFFFFFFFFU);
  127. cpg_write(SMSTPCR8, 0x01F1FFF5U);
  128. cpg_write(SMSTPCR9, 0xFFFFFFFFU);
  129. cpg_write(SMSTPCR10, 0xFFFEFFE0U);
  130. cpg_write(SMSTPCR11, 0x000000B7U);
  131. }
  132. #endif
  133. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3) || (RCAR_LSI == RZ_G2M)
  134. static void bl2_realtime_cpg_init_m3(void)
  135. {
  136. /* Realtime Module Stop Control Registers */
  137. cpg_write(RMSTPCR0, 0x00200000U);
  138. cpg_write(RMSTPCR1, 0xFFFFFFFFU);
  139. cpg_write(RMSTPCR2, 0x040E0FDCU);
  140. cpg_write(RMSTPCR3, 0xFFFFFFDFU);
  141. cpg_write(RMSTPCR4, 0x80000004U);
  142. cpg_write(RMSTPCR5, 0xC3FFFFFFU);
  143. cpg_write(RMSTPCR6, 0xFFFFFFFFU);
  144. cpg_write(RMSTPCR7, 0xFFFFFFFFU);
  145. cpg_write(RMSTPCR8, 0x01F1FFF7U);
  146. cpg_write(RMSTPCR9, 0xFFFFFFFEU);
  147. cpg_write(RMSTPCR10, 0xFFFEFFE0U);
  148. cpg_write(RMSTPCR11, 0x000000B7U);
  149. }
  150. static void bl2_system_cpg_init_m3(void)
  151. {
  152. /* System Module Stop Control Registers */
  153. cpg_write(SMSTPCR0, 0x00200000U);
  154. cpg_write(SMSTPCR1, 0xFFFFFFFFU);
  155. cpg_write(SMSTPCR2, 0x040E2FDCU);
  156. cpg_write(SMSTPCR3, 0xFFFFFBDFU);
  157. cpg_write(SMSTPCR4, 0x80000000U | (mmio_read_32(SMSTPCR4) & 0x4));
  158. cpg_write(SMSTPCR5, 0xC3FFFFFFU);
  159. cpg_write(SMSTPCR6, 0xFFFFFFFFU);
  160. cpg_write(SMSTPCR7, 0xFFFFFFFFU);
  161. cpg_write(SMSTPCR8, 0x01F1FFF7U);
  162. cpg_write(SMSTPCR9, 0xFFFFFFFFU);
  163. cpg_write(SMSTPCR10, 0xFFFEFFE0U);
  164. cpg_write(SMSTPCR11, 0x000000B7U);
  165. }
  166. #endif
  167. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_M3N) || (RCAR_LSI == RZ_G2N)
  168. static void bl2_realtime_cpg_init_m3n(void)
  169. {
  170. /* Realtime Module Stop Control Registers */
  171. cpg_write(RMSTPCR0, 0x00210000U);
  172. cpg_write(RMSTPCR1, 0xFFFFFFFFU);
  173. cpg_write(RMSTPCR2, 0x040E0FDCU);
  174. cpg_write(RMSTPCR3, 0xFFFFFFDFU);
  175. cpg_write(RMSTPCR4, 0x80000004U);
  176. cpg_write(RMSTPCR5, 0xC3FFFFFFU);
  177. cpg_write(RMSTPCR6, 0xFFFFFFFFU);
  178. cpg_write(RMSTPCR7, 0xFFFFFFFFU);
  179. cpg_write(RMSTPCR8, 0x00F1FFF7U);
  180. cpg_write(RMSTPCR9, 0xFFFFFFFFU);
  181. cpg_write(RMSTPCR10, 0xFFFFFFE0U);
  182. cpg_write(RMSTPCR11, 0x000000B7U);
  183. }
  184. static void bl2_system_cpg_init_m3n(void)
  185. {
  186. /* System Module Stop Control Registers */
  187. cpg_write(SMSTPCR0, 0x00210000U);
  188. cpg_write(SMSTPCR1, 0xFFFFFFFFU);
  189. cpg_write(SMSTPCR2, 0x040E2FDCU);
  190. cpg_write(SMSTPCR3, 0xFFFFFBDFU);
  191. cpg_write(SMSTPCR4, 0x80000000U | (mmio_read_32(SMSTPCR4) & 0x4));
  192. cpg_write(SMSTPCR5, 0xC3FFFFFFU);
  193. cpg_write(SMSTPCR6, 0xFFFFFFFFU);
  194. cpg_write(SMSTPCR7, 0xFFFFFFFFU);
  195. cpg_write(SMSTPCR8, 0x00F1FFF7U);
  196. cpg_write(SMSTPCR9, 0xFFFFFFFFU);
  197. cpg_write(SMSTPCR10, 0xFFFFFFE0U);
  198. cpg_write(SMSTPCR11, 0x000000B7U);
  199. }
  200. #endif
  201. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_V3M)
  202. static void bl2_realtime_cpg_init_v3m(void)
  203. {
  204. /* Realtime Module Stop Control Registers */
  205. cpg_write(RMSTPCR0, 0x00230000U);
  206. cpg_write(RMSTPCR1, 0xFFFFFFFFU);
  207. cpg_write(RMSTPCR2, 0x14062FD8U);
  208. cpg_write(RMSTPCR3, 0xFFFFFFDFU);
  209. cpg_write(RMSTPCR4, 0x80000184U);
  210. cpg_write(RMSTPCR5, 0x83FFFFFFU);
  211. cpg_write(RMSTPCR6, 0xFFFFFFFFU);
  212. cpg_write(RMSTPCR7, 0xFFFFFFFFU);
  213. cpg_write(RMSTPCR8, 0x7FF3FFF4U);
  214. cpg_write(RMSTPCR9, 0xFFFFFFFEU);
  215. }
  216. static void bl2_system_cpg_init_v3m(void)
  217. {
  218. /* System Module Stop Control Registers */
  219. cpg_write(SMSTPCR0, 0x00210000U);
  220. cpg_write(SMSTPCR1, 0xFFFFFFFFU);
  221. cpg_write(SMSTPCR2, 0x340E2FDCU);
  222. cpg_write(SMSTPCR3, 0xFFFFFBDFU);
  223. cpg_write(SMSTPCR4, 0x80000000U | (mmio_read_32(SMSTPCR4) & 0x4));
  224. cpg_write(SMSTPCR5, 0xC3FFFFFFU);
  225. cpg_write(SMSTPCR6, 0xFFFFFFFFU);
  226. cpg_write(SMSTPCR7, 0xFFFFFFFFU);
  227. cpg_write(SMSTPCR8, 0x01F1FFF5U);
  228. cpg_write(SMSTPCR9, 0xFFFFFFFEU);
  229. }
  230. #endif
  231. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_E3) || (RCAR_LSI == RZ_G2E)
  232. static void bl2_realtime_cpg_init_e3(void)
  233. {
  234. /* Realtime Module Stop Control Registers */
  235. cpg_write(RMSTPCR0, 0x00210000U);
  236. cpg_write(RMSTPCR1, 0xFFFFFFFFU);
  237. cpg_write(RMSTPCR2, 0x000E0FDCU);
  238. cpg_write(RMSTPCR3, 0xFFFFFFDFU);
  239. cpg_write(RMSTPCR4, 0x80000004U);
  240. cpg_write(RMSTPCR5, 0xC3FFFFFFU);
  241. cpg_write(RMSTPCR6, 0xFFFFFFFFU);
  242. cpg_write(RMSTPCR7, 0xFFFFFFFFU);
  243. cpg_write(RMSTPCR8, 0x00F1FFF7U);
  244. cpg_write(RMSTPCR9, 0xFFFFFFDFU);
  245. cpg_write(RMSTPCR10, 0xFFFFFFE8U);
  246. cpg_write(RMSTPCR11, 0x000000B7U);
  247. }
  248. static void bl2_system_cpg_init_e3(void)
  249. {
  250. /* System Module Stop Control Registers */
  251. cpg_write(SMSTPCR0, 0x00210000U);
  252. cpg_write(SMSTPCR1, 0xFFFFFFFFU);
  253. cpg_write(SMSTPCR2, 0x000E2FDCU);
  254. cpg_write(SMSTPCR3, 0xFFFFFBDFU);
  255. cpg_write(SMSTPCR4, 0x80000000U | (mmio_read_32(SMSTPCR4) & 0x4));
  256. cpg_write(SMSTPCR5, 0xC3FFFFFFU);
  257. cpg_write(SMSTPCR6, 0xFFFFFFFFU);
  258. cpg_write(SMSTPCR7, 0xFFFFFFFFU);
  259. cpg_write(SMSTPCR8, 0x00F1FFF7U);
  260. cpg_write(SMSTPCR9, 0xFFFFFFDFU);
  261. cpg_write(SMSTPCR10, 0xFFFFFFE8U);
  262. cpg_write(SMSTPCR11, 0x000000B7U);
  263. }
  264. #endif
  265. #if (RCAR_LSI == RCAR_AUTO) || (RCAR_LSI == RCAR_D3)
  266. static void bl2_system_cpg_init_d3(void)
  267. {
  268. /* System Module Stop Control Registers */
  269. cpg_write(SMSTPCR0, 0x00010000U);
  270. cpg_write(SMSTPCR1, 0xFFFFFFFFU);
  271. cpg_write(SMSTPCR2, 0x00060FDCU);
  272. cpg_write(SMSTPCR3, 0xFFFFFBDFU);
  273. cpg_write(SMSTPCR4, 0x00000080U | (mmio_read_32(SMSTPCR4) & 0x4));
  274. cpg_write(SMSTPCR5, 0x83FFFFFFU);
  275. cpg_write(SMSTPCR6, 0xFFFFFFFFU);
  276. cpg_write(SMSTPCR7, 0xFFFFFFFFU);
  277. cpg_write(SMSTPCR8, 0x00F1FFF7U);
  278. cpg_write(SMSTPCR9, 0xF3F5E016U);
  279. cpg_write(SMSTPCR10, 0xFFFEFFE0U);
  280. cpg_write(SMSTPCR11, 0x000000B7U);
  281. }
  282. #endif
  283. void bl2_cpg_init(void)
  284. {
  285. uint32_t boot_cpu = mmio_read_32(RCAR_MODEMR) & MODEMR_BOOT_CPU_MASK;
  286. #if RCAR_LSI == RCAR_AUTO
  287. uint32_t product = mmio_read_32(RCAR_PRR) & PRR_PRODUCT_MASK;
  288. #endif
  289. bl2_secure_cpg_init();
  290. if (boot_cpu == MODEMR_BOOT_CPU_CA57 ||
  291. boot_cpu == MODEMR_BOOT_CPU_CA53) {
  292. #if RCAR_LSI == RCAR_AUTO
  293. switch (product) {
  294. case PRR_PRODUCT_H3:
  295. bl2_realtime_cpg_init_h3();
  296. break;
  297. case PRR_PRODUCT_M3:
  298. bl2_realtime_cpg_init_m3();
  299. break;
  300. case PRR_PRODUCT_M3N:
  301. bl2_realtime_cpg_init_m3n();
  302. break;
  303. case PRR_PRODUCT_V3M:
  304. bl2_realtime_cpg_init_v3m();
  305. break;
  306. case PRR_PRODUCT_E3:
  307. bl2_realtime_cpg_init_e3();
  308. break;
  309. case PRR_PRODUCT_D3:
  310. /* no need */
  311. break;
  312. default:
  313. panic();
  314. break;
  315. }
  316. #elif (RCAR_LSI == RCAR_H3) || (RCAR_LSI == RCAR_H3N) || (RCAR_LSI == RZ_G2H)
  317. bl2_realtime_cpg_init_h3();
  318. #elif (RCAR_LSI == RCAR_M3) || (RCAR_LSI == RZ_G2M)
  319. bl2_realtime_cpg_init_m3();
  320. #elif RCAR_LSI == RCAR_M3N || (RCAR_LSI == RZ_G2N)
  321. bl2_realtime_cpg_init_m3n();
  322. #elif RCAR_LSI == RCAR_V3M
  323. bl2_realtime_cpg_init_v3m();
  324. #elif RCAR_LSI == RCAR_E3 || RCAR_LSI == RZ_G2E
  325. bl2_realtime_cpg_init_e3();
  326. #elif RCAR_LSI == RCAR_D3
  327. /* no need */
  328. #else
  329. #error "Don't have CPG initialize routine(unknown)."
  330. #endif
  331. }
  332. }
  333. void bl2_system_cpg_init(void)
  334. {
  335. #if RCAR_LSI == RCAR_AUTO
  336. uint32_t product = mmio_read_32(RCAR_PRR) & PRR_PRODUCT_MASK;
  337. switch (product) {
  338. case PRR_PRODUCT_H3:
  339. bl2_system_cpg_init_h3();
  340. break;
  341. case PRR_PRODUCT_M3:
  342. bl2_system_cpg_init_m3();
  343. break;
  344. case PRR_PRODUCT_M3N:
  345. bl2_system_cpg_init_m3n();
  346. break;
  347. case PRR_PRODUCT_V3M:
  348. bl2_system_cpg_init_v3m();
  349. break;
  350. case PRR_PRODUCT_E3:
  351. bl2_system_cpg_init_e3();
  352. break;
  353. case PRR_PRODUCT_D3:
  354. bl2_system_cpg_init_d3();
  355. break;
  356. default:
  357. panic();
  358. break;
  359. }
  360. #elif (RCAR_LSI == RCAR_H3) || (RCAR_LSI == RCAR_H3N) || (RCAR_LSI == RZ_G2H)
  361. bl2_system_cpg_init_h3();
  362. #elif (RCAR_LSI == RCAR_M3) || (RCAR_LSI == RZ_G2M)
  363. bl2_system_cpg_init_m3();
  364. #elif RCAR_LSI == RCAR_M3N || (RCAR_LSI == RZ_G2N)
  365. bl2_system_cpg_init_m3n();
  366. #elif RCAR_LSI == RCAR_V3M
  367. bl2_system_cpg_init_v3m();
  368. #elif RCAR_LSI == RCAR_E3 || RCAR_LSI == RZ_G2E
  369. bl2_system_cpg_init_e3();
  370. #elif RCAR_LSI == RCAR_D3
  371. bl2_system_cpg_init_d3();
  372. #else
  373. #error "Don't have CPG initialize routine(unknown)."
  374. #endif
  375. }