pwrc.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. /*
  2. * Copyright (c) 2015-2021, Renesas Electronics Corporation. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <string.h>
  8. #include <arch.h>
  9. #include <arch_helpers.h>
  10. #include <common/debug.h>
  11. #include <lib/bakery_lock.h>
  12. #include <lib/mmio.h>
  13. #include <lib/xlat_tables/xlat_tables_v2.h>
  14. #include <plat/common/platform.h>
  15. #include "iic_dvfs.h"
  16. #include "micro_delay.h"
  17. #include "pwrc.h"
  18. #include "rcar_def.h"
  19. #include "rcar_private.h"
  20. #include "cpg_registers.h"
  21. /*
  22. * Someday there will be a generic power controller api. At the moment each
  23. * platform has its own pwrc so just exporting functions should be acceptable.
  24. */
  25. RCAR_INSTANTIATE_LOCK
  26. #define WUP_IRQ_SHIFT (0U)
  27. #define WUP_FIQ_SHIFT (8U)
  28. #define WUP_CSD_SHIFT (16U)
  29. #define BIT_SOFTRESET (1U << 15)
  30. #define BIT_CA53_SCU (1U << 21)
  31. #define BIT_CA57_SCU (1U << 12)
  32. #define REQ_RESUME (1U << 1)
  33. #define REQ_OFF (1U << 0)
  34. #define STATUS_PWRUP (1U << 4)
  35. #define STATUS_PWRDOWN (1U << 0)
  36. #define STATE_CA57_CPU (27U)
  37. #define STATE_CA53_CPU (22U)
  38. #define MODE_L2_DOWN (0x00000002U)
  39. #define CPU_PWR_OFF (0x00000003U)
  40. #define RCAR_PSTR_MASK (0x00000003U)
  41. #define ST_ALL_STANDBY (0x00003333U)
  42. #define SYSCEXTMASK_EXTMSK0 (0x00000001U)
  43. /* Suspend to ram */
  44. #define DBSC4_REG_BASE (0xE6790000U)
  45. #define DBSC4_REG_DBSYSCNT0 (DBSC4_REG_BASE + 0x0100U)
  46. #define DBSC4_REG_DBACEN (DBSC4_REG_BASE + 0x0200U)
  47. #define DBSC4_REG_DBCMD (DBSC4_REG_BASE + 0x0208U)
  48. #define DBSC4_REG_DBRFEN (DBSC4_REG_BASE + 0x0204U)
  49. #define DBSC4_REG_DBWAIT (DBSC4_REG_BASE + 0x0210U)
  50. #define DBSC4_REG_DBCALCNF (DBSC4_REG_BASE + 0x0424U)
  51. #define DBSC4_REG_DBDFIPMSTRCNF (DBSC4_REG_BASE + 0x0520U)
  52. #define DBSC4_REG_DBPDLK0 (DBSC4_REG_BASE + 0x0620U)
  53. #define DBSC4_REG_DBPDRGA0 (DBSC4_REG_BASE + 0x0624U)
  54. #define DBSC4_REG_DBPDRGD0 (DBSC4_REG_BASE + 0x0628U)
  55. #define DBSC4_REG_DBCAM0CTRL0 (DBSC4_REG_BASE + 0x0940U)
  56. #define DBSC4_REG_DBCAM0STAT0 (DBSC4_REG_BASE + 0x0980U)
  57. #define DBSC4_REG_DBCAM1STAT0 (DBSC4_REG_BASE + 0x0990U)
  58. #define DBSC4_REG_DBCAM2STAT0 (DBSC4_REG_BASE + 0x09A0U)
  59. #define DBSC4_REG_DBCAM3STAT0 (DBSC4_REG_BASE + 0x09B0U)
  60. #define DBSC4_BIT_DBACEN_ACCEN ((uint32_t)(1U << 0))
  61. #define DBSC4_BIT_DBRFEN_ARFEN ((uint32_t)(1U << 0))
  62. #define DBSC4_BIT_DBCAMxSTAT0 (0x00000001U)
  63. #define DBSC4_BIT_DBDFIPMSTRCNF_PMSTREN (0x00000001U)
  64. #define DBSC4_SET_DBCMD_OPC_PRE (0x04000000U)
  65. #define DBSC4_SET_DBCMD_OPC_SR (0x0A000000U)
  66. #define DBSC4_SET_DBCMD_OPC_PD (0x08000000U)
  67. #define DBSC4_SET_DBCMD_OPC_MRW (0x0E000000U)
  68. #define DBSC4_SET_DBCMD_CH_ALL (0x00800000U)
  69. #define DBSC4_SET_DBCMD_RANK_ALL (0x00040000U)
  70. #define DBSC4_SET_DBCMD_ARG_ALL (0x00000010U)
  71. #define DBSC4_SET_DBCMD_ARG_ENTER (0x00000000U)
  72. #define DBSC4_SET_DBCMD_ARG_MRW_ODTC (0x00000B00U)
  73. #define DBSC4_SET_DBSYSCNT0_WRITE_ENABLE (0x00001234U)
  74. #define DBSC4_SET_DBSYSCNT0_WRITE_DISABLE (0x00000000U)
  75. #define DBSC4_SET_DBPDLK0_PHY_ACCESS (0x0000A55AU)
  76. #define DBSC4_SET_DBPDRGA0_ACIOCR0 (0x0000001AU)
  77. #define DBSC4_SET_DBPDRGD0_ACIOCR0 (0x33C03C11U)
  78. #define DBSC4_SET_DBPDRGA0_DXCCR (0x00000020U)
  79. #define DBSC4_SET_DBPDRGD0_DXCCR (0x00181006U)
  80. #define DBSC4_SET_DBPDRGA0_PGCR1 (0x00000003U)
  81. #define DBSC4_SET_DBPDRGD0_PGCR1 (0x0380C600U)
  82. #define DBSC4_SET_DBPDRGA0_ACIOCR1 (0x0000001BU)
  83. #define DBSC4_SET_DBPDRGD0_ACIOCR1 (0xAAAAAAAAU)
  84. #define DBSC4_SET_DBPDRGA0_ACIOCR3 (0x0000001DU)
  85. #define DBSC4_SET_DBPDRGD0_ACIOCR3 (0xAAAAAAAAU)
  86. #define DBSC4_SET_DBPDRGA0_ACIOCR5 (0x0000001FU)
  87. #define DBSC4_SET_DBPDRGD0_ACIOCR5 (0x000000AAU)
  88. #define DBSC4_SET_DBPDRGA0_DX0GCR2 (0x000000A2U)
  89. #define DBSC4_SET_DBPDRGD0_DX0GCR2 (0xAAAA0000U)
  90. #define DBSC4_SET_DBPDRGA0_DX1GCR2 (0x000000C2U)
  91. #define DBSC4_SET_DBPDRGD0_DX1GCR2 (0xAAAA0000U)
  92. #define DBSC4_SET_DBPDRGA0_DX2GCR2 (0x000000E2U)
  93. #define DBSC4_SET_DBPDRGD0_DX2GCR2 (0xAAAA0000U)
  94. #define DBSC4_SET_DBPDRGA0_DX3GCR2 (0x00000102U)
  95. #define DBSC4_SET_DBPDRGD0_DX3GCR2 (0xAAAA0000U)
  96. #define DBSC4_SET_DBPDRGA0_ZQCR (0x00000090U)
  97. #define DBSC4_SET_DBPDRGD0_ZQCR_MD19_0 (0x04058904U)
  98. #define DBSC4_SET_DBPDRGD0_ZQCR_MD19_1 (0x04058A04U)
  99. #define DBSC4_SET_DBPDRGA0_DX0GCR0 (0x000000A0U)
  100. #define DBSC4_SET_DBPDRGD0_DX0GCR0 (0x7C0002E5U)
  101. #define DBSC4_SET_DBPDRGA0_DX1GCR0 (0x000000C0U)
  102. #define DBSC4_SET_DBPDRGD0_DX1GCR0 (0x7C0002E5U)
  103. #define DBSC4_SET_DBPDRGA0_DX2GCR0 (0x000000E0U)
  104. #define DBSC4_SET_DBPDRGD0_DX2GCR0 (0x7C0002E5U)
  105. #define DBSC4_SET_DBPDRGA0_DX3GCR0 (0x00000100U)
  106. #define DBSC4_SET_DBPDRGD0_DX3GCR0 (0x7C0002E5U)
  107. #define DBSC4_SET_DBPDRGA0_DX0GCR1 (0x000000A1U)
  108. #define DBSC4_SET_DBPDRGD0_DX0GCR1 (0x55550000U)
  109. #define DBSC4_SET_DBPDRGA0_DX1GCR1 (0x000000C1U)
  110. #define DBSC4_SET_DBPDRGD0_DX1GCR1 (0x55550000U)
  111. #define DBSC4_SET_DBPDRGA0_DX2GCR1 (0x000000E1U)
  112. #define DBSC4_SET_DBPDRGD0_DX2GCR1 (0x55550000U)
  113. #define DBSC4_SET_DBPDRGA0_DX3GCR1 (0x00000101U)
  114. #define DBSC4_SET_DBPDRGD0_DX3GCR1 (0x55550000U)
  115. #define DBSC4_SET_DBPDRGA0_DX0GCR3 (0x000000A3U)
  116. #define DBSC4_SET_DBPDRGD0_DX0GCR3 (0x00008484U)
  117. #define DBSC4_SET_DBPDRGA0_DX1GCR3 (0x000000C3U)
  118. #define DBSC4_SET_DBPDRGD0_DX1GCR3 (0x00008484U)
  119. #define DBSC4_SET_DBPDRGA0_DX2GCR3 (0x000000E3U)
  120. #define DBSC4_SET_DBPDRGD0_DX2GCR3 (0x00008484U)
  121. #define DBSC4_SET_DBPDRGA0_DX3GCR3 (0x00000103U)
  122. #define DBSC4_SET_DBPDRGD0_DX3GCR3 (0x00008484U)
  123. #define RST_BASE (0xE6160000U)
  124. #define RST_MODEMR (RST_BASE + 0x0060U)
  125. #define RST_MODEMR_BIT0 (0x00000001U)
  126. #define RCAR_CNTCR_OFF (0x00U)
  127. #define RCAR_CNTCVL_OFF (0x08U)
  128. #define RCAR_CNTCVU_OFF (0x0CU)
  129. #define RCAR_CNTFID_OFF (0x20U)
  130. #define RCAR_CNTCR_EN ((uint32_t)1U << 0U)
  131. #define RCAR_CNTCR_FCREQ(x) ((uint32_t)(x) << 8U)
  132. #if PMIC_ROHM_BD9571
  133. #define BIT_BKUP_CTRL_OUT ((uint8_t)(1U << 4))
  134. #define PMIC_BKUP_MODE_CNT (0x20U)
  135. #define PMIC_QLLM_CNT (0x27U)
  136. #define PMIC_RETRY_MAX (100U)
  137. #endif /* PMIC_ROHM_BD9571 */
  138. #define SCTLR_EL3_M_BIT ((uint32_t)1U << 0)
  139. #define RCAR_CA53CPU_NUM_MAX (4U)
  140. #define RCAR_CA57CPU_NUM_MAX (4U)
  141. #define IS_A53A57(c) ((c) == RCAR_CLUSTER_A53A57)
  142. #define IS_CA57(c) ((c) == RCAR_CLUSTER_CA57)
  143. #define IS_CA53(c) ((c) == RCAR_CLUSTER_CA53)
  144. #ifndef __ASSEMBLER__
  145. IMPORT_SYM(unsigned long, __system_ram_start__, SYSTEM_RAM_START);
  146. IMPORT_SYM(unsigned long, __system_ram_end__, SYSTEM_RAM_END);
  147. IMPORT_SYM(unsigned long, __SRAM_COPY_START__, SRAM_COPY_START);
  148. #endif
  149. uint32_t rcar_pwrc_status(u_register_t mpidr)
  150. {
  151. uint32_t ret = 0;
  152. uint64_t cm, cpu;
  153. uint32_t reg;
  154. uint32_t c;
  155. rcar_lock_get();
  156. c = rcar_pwrc_get_cluster();
  157. cm = mpidr & MPIDR_CLUSTER_MASK;
  158. if (!IS_A53A57(c) && cm != 0) {
  159. ret = RCAR_INVALID;
  160. goto done;
  161. }
  162. reg = mmio_read_32(RCAR_PRR);
  163. cpu = mpidr & MPIDR_CPU_MASK;
  164. if (IS_CA53(c))
  165. if (reg & (1 << (STATE_CA53_CPU + cpu)))
  166. ret = RCAR_INVALID;
  167. if (IS_CA57(c))
  168. if (reg & (1 << (STATE_CA57_CPU + cpu)))
  169. ret = RCAR_INVALID;
  170. done:
  171. rcar_lock_release();
  172. return ret;
  173. }
  174. static void scu_power_up(u_register_t mpidr)
  175. {
  176. uintptr_t reg_pwrsr, reg_cpumcr, reg_pwron, reg_pwrer;
  177. uint32_t c, sysc_reg_bit;
  178. uint32_t lsi_product;
  179. uint32_t lsi_cut;
  180. c = rcar_pwrc_get_mpidr_cluster(mpidr);
  181. reg_cpumcr = IS_CA57(c) ? RCAR_CA57CPUCMCR : RCAR_CA53CPUCMCR;
  182. sysc_reg_bit = IS_CA57(c) ? BIT_CA57_SCU : BIT_CA53_SCU;
  183. reg_pwron = IS_CA57(c) ? RCAR_PWRONCR5 : RCAR_PWRONCR3;
  184. reg_pwrer = IS_CA57(c) ? RCAR_PWRER5 : RCAR_PWRER3;
  185. reg_pwrsr = IS_CA57(c) ? RCAR_PWRSR5 : RCAR_PWRSR3;
  186. if ((mmio_read_32(reg_pwrsr) & STATUS_PWRDOWN) == 0)
  187. return;
  188. if (mmio_read_32(reg_cpumcr) != 0)
  189. mmio_write_32(reg_cpumcr, 0);
  190. lsi_product = mmio_read_32((uintptr_t)RCAR_PRR);
  191. lsi_cut = lsi_product & PRR_CUT_MASK;
  192. lsi_product &= PRR_PRODUCT_MASK;
  193. if ((lsi_product == PRR_PRODUCT_M3 && lsi_cut >= PRR_PRODUCT_30) ||
  194. lsi_product == PRR_PRODUCT_H3 ||
  195. lsi_product == PRR_PRODUCT_M3N ||
  196. lsi_product == PRR_PRODUCT_E3) {
  197. mmio_setbits_32(RCAR_SYSCEXTMASK, SYSCEXTMASK_EXTMSK0);
  198. }
  199. mmio_setbits_32(RCAR_SYSCIER, sysc_reg_bit);
  200. mmio_setbits_32(RCAR_SYSCIMR, sysc_reg_bit);
  201. do {
  202. while ((mmio_read_32(RCAR_SYSCSR) & REQ_RESUME) == 0)
  203. ;
  204. mmio_write_32(reg_pwron, 1);
  205. } while (mmio_read_32(reg_pwrer) & 1);
  206. while ((mmio_read_32(RCAR_SYSCISR) & sysc_reg_bit) == 0)
  207. ;
  208. mmio_write_32(RCAR_SYSCISCR, sysc_reg_bit);
  209. if ((lsi_product == PRR_PRODUCT_M3 && lsi_cut >= PRR_PRODUCT_30) ||
  210. lsi_product == PRR_PRODUCT_H3 ||
  211. lsi_product == PRR_PRODUCT_M3N ||
  212. lsi_product == PRR_PRODUCT_E3) {
  213. mmio_clrbits_32(RCAR_SYSCEXTMASK, SYSCEXTMASK_EXTMSK0);
  214. }
  215. while ((mmio_read_32(reg_pwrsr) & STATUS_PWRUP) == 0)
  216. ;
  217. }
  218. void rcar_pwrc_cpuon(u_register_t mpidr)
  219. {
  220. uint32_t res_data, on_data;
  221. uintptr_t res_reg, on_reg;
  222. uint32_t limit, c;
  223. uint64_t cpu;
  224. rcar_lock_get();
  225. c = rcar_pwrc_get_mpidr_cluster(mpidr);
  226. res_reg = IS_CA53(c) ? RCAR_CA53RESCNT : RCAR_CA57RESCNT;
  227. on_reg = IS_CA53(c) ? RCAR_CA53WUPCR : RCAR_CA57WUPCR;
  228. limit = IS_CA53(c) ? 0x5A5A0000 : 0xA5A50000;
  229. res_data = mmio_read_32(res_reg) | limit;
  230. scu_power_up(mpidr);
  231. cpu = mpidr & MPIDR_CPU_MASK;
  232. on_data = 1 << cpu;
  233. mmio_write_32(CPG_CPGWPR, ~on_data);
  234. mmio_write_32(on_reg, on_data);
  235. mmio_write_32(res_reg, res_data & (~(1 << (3 - cpu))));
  236. rcar_lock_release();
  237. }
  238. void rcar_pwrc_cpuoff(u_register_t mpidr)
  239. {
  240. uint32_t c;
  241. uintptr_t reg;
  242. uint64_t cpu;
  243. rcar_lock_get();
  244. cpu = mpidr & MPIDR_CPU_MASK;
  245. c = rcar_pwrc_get_mpidr_cluster(mpidr);
  246. reg = IS_CA53(c) ? RCAR_CA53CPU0CR : RCAR_CA57CPU0CR;
  247. if (read_mpidr_el1() != mpidr)
  248. panic();
  249. mmio_write_32(CPG_CPGWPR, ~CPU_PWR_OFF);
  250. mmio_write_32(reg + cpu * 0x0010, CPU_PWR_OFF);
  251. rcar_lock_release();
  252. }
  253. void rcar_pwrc_enable_interrupt_wakeup(u_register_t mpidr)
  254. {
  255. uint32_t c, shift_irq, shift_fiq;
  256. uintptr_t reg;
  257. uint64_t cpu;
  258. rcar_lock_get();
  259. cpu = mpidr & MPIDR_CPU_MASK;
  260. c = rcar_pwrc_get_mpidr_cluster(mpidr);
  261. reg = IS_CA53(c) ? RCAR_WUPMSKCA53 : RCAR_WUPMSKCA57;
  262. shift_irq = WUP_IRQ_SHIFT + cpu;
  263. shift_fiq = WUP_FIQ_SHIFT + cpu;
  264. mmio_clrbits_32(reg, ((uint32_t) 1 << shift_irq) |
  265. ((uint32_t) 1 << shift_fiq));
  266. rcar_lock_release();
  267. }
  268. void rcar_pwrc_disable_interrupt_wakeup(u_register_t mpidr)
  269. {
  270. uint32_t c, shift_irq, shift_fiq;
  271. uintptr_t reg;
  272. uint64_t cpu;
  273. rcar_lock_get();
  274. cpu = mpidr & MPIDR_CPU_MASK;
  275. c = rcar_pwrc_get_mpidr_cluster(mpidr);
  276. reg = IS_CA53(c) ? RCAR_WUPMSKCA53 : RCAR_WUPMSKCA57;
  277. shift_irq = WUP_IRQ_SHIFT + cpu;
  278. shift_fiq = WUP_FIQ_SHIFT + cpu;
  279. mmio_setbits_32(reg, ((uint32_t) 1 << shift_irq) |
  280. ((uint32_t) 1 << shift_fiq));
  281. rcar_lock_release();
  282. }
  283. void rcar_pwrc_all_disable_interrupt_wakeup(void)
  284. {
  285. uint32_t cpu_num;
  286. u_register_t cl, cpu, mpidr;
  287. const uint32_t cluster[PLATFORM_CLUSTER_COUNT] = {
  288. RCAR_CLUSTER_CA57,
  289. RCAR_CLUSTER_CA53
  290. };
  291. for (cl = 0; cl < PLATFORM_CLUSTER_COUNT; cl++) {
  292. cpu_num = rcar_pwrc_get_cpu_num(cluster[cl]);
  293. for (cpu = 0; cpu < cpu_num; cpu++) {
  294. mpidr = ((cl << MPIDR_AFFINITY_BITS) | cpu);
  295. if (mpidr == rcar_boot_mpidr) {
  296. rcar_pwrc_enable_interrupt_wakeup(mpidr);
  297. } else {
  298. rcar_pwrc_disable_interrupt_wakeup(mpidr);
  299. }
  300. }
  301. }
  302. }
  303. void rcar_pwrc_clusteroff(u_register_t mpidr)
  304. {
  305. uint32_t c, product, cut, reg;
  306. uintptr_t dst;
  307. rcar_lock_get();
  308. reg = mmio_read_32(RCAR_PRR);
  309. product = reg & PRR_PRODUCT_MASK;
  310. cut = reg & PRR_CUT_MASK;
  311. c = rcar_pwrc_get_mpidr_cluster(mpidr);
  312. dst = IS_CA53(c) ? RCAR_CA53CPUCMCR : RCAR_CA57CPUCMCR;
  313. if (product == PRR_PRODUCT_M3 && cut < PRR_PRODUCT_30) {
  314. goto done;
  315. }
  316. if (product == PRR_PRODUCT_H3 && cut <= PRR_PRODUCT_20) {
  317. goto done;
  318. }
  319. /* all of the CPUs in the cluster is in the CoreStandby mode */
  320. mmio_write_32(dst, MODE_L2_DOWN);
  321. done:
  322. rcar_lock_release();
  323. }
  324. static uint64_t rcar_pwrc_saved_cntpct_el0;
  325. static uint32_t rcar_pwrc_saved_cntfid;
  326. #if RCAR_SYSTEM_SUSPEND
  327. static void rcar_pwrc_save_timer_state(void)
  328. {
  329. rcar_pwrc_saved_cntpct_el0 = read_cntpct_el0();
  330. rcar_pwrc_saved_cntfid =
  331. mmio_read_32((uintptr_t)(RCAR_CNTC_BASE + RCAR_CNTFID_OFF));
  332. }
  333. #endif /* RCAR_SYSTEM_SUSPEND */
  334. void rcar_pwrc_restore_timer_state(void)
  335. {
  336. /* Stop timer before restoring counter value */
  337. mmio_write_32((uintptr_t)(RCAR_CNTC_BASE + RCAR_CNTCR_OFF), 0U);
  338. mmio_write_32((uintptr_t)(RCAR_CNTC_BASE + RCAR_CNTCVL_OFF),
  339. (uint32_t)(rcar_pwrc_saved_cntpct_el0 & 0xFFFFFFFFU));
  340. mmio_write_32((uintptr_t)(RCAR_CNTC_BASE + RCAR_CNTCVU_OFF),
  341. (uint32_t)(rcar_pwrc_saved_cntpct_el0 >> 32U));
  342. mmio_write_32((uintptr_t)(RCAR_CNTC_BASE + RCAR_CNTFID_OFF),
  343. rcar_pwrc_saved_cntfid);
  344. /* Start generic timer back */
  345. write_cntfrq_el0((u_register_t)plat_get_syscnt_freq2());
  346. mmio_write_32((uintptr_t)(RCAR_CNTC_BASE + RCAR_CNTCR_OFF),
  347. (RCAR_CNTCR_FCREQ(0U) | RCAR_CNTCR_EN));
  348. }
  349. #if !PMIC_ROHM_BD9571
  350. void rcar_pwrc_system_reset(void)
  351. {
  352. mmio_write_32(RCAR_SRESCR, 0x5AA50000U | BIT_SOFTRESET);
  353. }
  354. #endif /* PMIC_ROHM_BD9571 */
  355. #define RST_CA53_CPU0_BARH (0xE6160080U)
  356. #define RST_CA53_CPU0_BARL (0xE6160084U)
  357. #define RST_CA57_CPU0_BARH (0xE61600C0U)
  358. #define RST_CA57_CPU0_BARL (0xE61600C4U)
  359. void rcar_pwrc_setup(void)
  360. {
  361. uintptr_t rst_barh;
  362. uintptr_t rst_barl;
  363. uint32_t i, j;
  364. uint64_t reset = (uint64_t) (&plat_secondary_reset) & 0xFFFFFFFF;
  365. const uint32_t cluster[PLATFORM_CLUSTER_COUNT] = {
  366. RCAR_CLUSTER_CA53,
  367. RCAR_CLUSTER_CA57
  368. };
  369. const uintptr_t reg_barh[PLATFORM_CLUSTER_COUNT] = {
  370. RST_CA53_CPU0_BARH,
  371. RST_CA57_CPU0_BARH
  372. };
  373. const uintptr_t reg_barl[PLATFORM_CLUSTER_COUNT] = {
  374. RST_CA53_CPU0_BARL,
  375. RST_CA57_CPU0_BARL
  376. };
  377. for (i = 0; i < PLATFORM_CLUSTER_COUNT; i++) {
  378. rst_barh = reg_barh[i];
  379. rst_barl = reg_barl[i];
  380. for (j = 0; j < rcar_pwrc_get_cpu_num(cluster[i]); j++) {
  381. mmio_write_32(rst_barh, 0);
  382. mmio_write_32(rst_barl, (uint32_t) reset);
  383. rst_barh += 0x10;
  384. rst_barl += 0x10;
  385. }
  386. }
  387. rcar_lock_init();
  388. }
  389. #if RCAR_SYSTEM_SUSPEND
  390. #define DBCAM_FLUSH(__bit) \
  391. do { \
  392. ; \
  393. } while (!(mmio_read_32(DBSC4_REG_DBCAM##__bit##STAT0) & DBSC4_BIT_DBCAMxSTAT0))
  394. static void __attribute__ ((section(".system_ram")))
  395. rcar_pwrc_set_self_refresh(void)
  396. {
  397. uint32_t reg = mmio_read_32(RCAR_PRR);
  398. uint32_t cut, product;
  399. product = reg & PRR_PRODUCT_MASK;
  400. cut = reg & PRR_CUT_MASK;
  401. if (product == PRR_PRODUCT_M3 && cut < PRR_PRODUCT_30) {
  402. goto self_refresh;
  403. }
  404. if (product == PRR_PRODUCT_H3 && cut < PRR_PRODUCT_20) {
  405. goto self_refresh;
  406. }
  407. mmio_write_32(DBSC4_REG_DBSYSCNT0, DBSC4_SET_DBSYSCNT0_WRITE_ENABLE);
  408. self_refresh:
  409. /* DFI_PHYMSTR_ACK setting */
  410. mmio_write_32(DBSC4_REG_DBDFIPMSTRCNF,
  411. mmio_read_32(DBSC4_REG_DBDFIPMSTRCNF) &
  412. (~DBSC4_BIT_DBDFIPMSTRCNF_PMSTREN));
  413. /* Set the Self-Refresh mode */
  414. mmio_write_32(DBSC4_REG_DBACEN, 0);
  415. if (product == PRR_PRODUCT_H3 && cut < PRR_PRODUCT_20)
  416. rcar_micro_delay(100);
  417. else if (product == PRR_PRODUCT_H3) {
  418. mmio_write_32(DBSC4_REG_DBCAM0CTRL0, 1);
  419. DBCAM_FLUSH(0);
  420. DBCAM_FLUSH(1);
  421. DBCAM_FLUSH(2);
  422. DBCAM_FLUSH(3);
  423. mmio_write_32(DBSC4_REG_DBCAM0CTRL0, 0);
  424. } else if (product == PRR_PRODUCT_M3) {
  425. mmio_write_32(DBSC4_REG_DBCAM0CTRL0, 1);
  426. DBCAM_FLUSH(0);
  427. DBCAM_FLUSH(1);
  428. mmio_write_32(DBSC4_REG_DBCAM0CTRL0, 0);
  429. } else {
  430. mmio_write_32(DBSC4_REG_DBCAM0CTRL0, 1);
  431. DBCAM_FLUSH(0);
  432. mmio_write_32(DBSC4_REG_DBCAM0CTRL0, 0);
  433. }
  434. /* Set the SDRAM calibration configuration register */
  435. mmio_write_32(DBSC4_REG_DBCALCNF, 0);
  436. reg = DBSC4_SET_DBCMD_OPC_PRE | DBSC4_SET_DBCMD_CH_ALL |
  437. DBSC4_SET_DBCMD_RANK_ALL | DBSC4_SET_DBCMD_ARG_ALL;
  438. mmio_write_32(DBSC4_REG_DBCMD, reg);
  439. while (mmio_read_32(DBSC4_REG_DBWAIT))
  440. ;
  441. /* Self-Refresh entry command */
  442. reg = DBSC4_SET_DBCMD_OPC_SR | DBSC4_SET_DBCMD_CH_ALL |
  443. DBSC4_SET_DBCMD_RANK_ALL | DBSC4_SET_DBCMD_ARG_ENTER;
  444. mmio_write_32(DBSC4_REG_DBCMD, reg);
  445. while (mmio_read_32(DBSC4_REG_DBWAIT))
  446. ;
  447. /* Mode Register Write command. (ODT disabled) */
  448. reg = DBSC4_SET_DBCMD_OPC_MRW | DBSC4_SET_DBCMD_CH_ALL |
  449. DBSC4_SET_DBCMD_RANK_ALL | DBSC4_SET_DBCMD_ARG_MRW_ODTC;
  450. mmio_write_32(DBSC4_REG_DBCMD, reg);
  451. while (mmio_read_32(DBSC4_REG_DBWAIT))
  452. ;
  453. /* Power Down entry command */
  454. reg = DBSC4_SET_DBCMD_OPC_PD | DBSC4_SET_DBCMD_CH_ALL |
  455. DBSC4_SET_DBCMD_RANK_ALL | DBSC4_SET_DBCMD_ARG_ENTER;
  456. mmio_write_32(DBSC4_REG_DBCMD, reg);
  457. while (mmio_read_32(DBSC4_REG_DBWAIT))
  458. ;
  459. /* Set the auto-refresh enable register */
  460. mmio_write_32(DBSC4_REG_DBRFEN, 0U);
  461. rcar_micro_delay(1U);
  462. if (product == PRR_PRODUCT_M3 && cut < PRR_PRODUCT_30)
  463. return;
  464. if (product == PRR_PRODUCT_H3 && cut < PRR_PRODUCT_20)
  465. return;
  466. mmio_write_32(DBSC4_REG_DBSYSCNT0, DBSC4_SET_DBSYSCNT0_WRITE_DISABLE);
  467. }
  468. static void __attribute__ ((section(".system_ram")))
  469. rcar_pwrc_set_self_refresh_e3(void)
  470. {
  471. uint32_t ddr_md;
  472. uint32_t reg;
  473. ddr_md = (mmio_read_32(RST_MODEMR) >> 19) & RST_MODEMR_BIT0;
  474. /* Write enable */
  475. mmio_write_32(DBSC4_REG_DBSYSCNT0, DBSC4_SET_DBSYSCNT0_WRITE_ENABLE);
  476. mmio_write_32(DBSC4_REG_DBACEN, 0);
  477. DBCAM_FLUSH(0);
  478. reg = DBSC4_SET_DBCMD_OPC_PRE | DBSC4_SET_DBCMD_CH_ALL |
  479. DBSC4_SET_DBCMD_RANK_ALL | DBSC4_SET_DBCMD_ARG_ALL;
  480. mmio_write_32(DBSC4_REG_DBCMD, reg);
  481. while (mmio_read_32(DBSC4_REG_DBWAIT))
  482. ;
  483. reg = DBSC4_SET_DBCMD_OPC_SR | DBSC4_SET_DBCMD_CH_ALL |
  484. DBSC4_SET_DBCMD_RANK_ALL | DBSC4_SET_DBCMD_ARG_ENTER;
  485. mmio_write_32(DBSC4_REG_DBCMD, reg);
  486. while (mmio_read_32(DBSC4_REG_DBWAIT))
  487. ;
  488. /*
  489. * Set the auto-refresh enable register
  490. * Set the ARFEN bit to 0 in the DBRFEN
  491. */
  492. mmio_write_32(DBSC4_REG_DBRFEN, 0);
  493. mmio_write_32(DBSC4_REG_DBPDLK0, DBSC4_SET_DBPDLK0_PHY_ACCESS);
  494. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_ACIOCR0);
  495. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_ACIOCR0);
  496. /* DDR_DXCCR */
  497. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DXCCR);
  498. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DXCCR);
  499. /* DDR_PGCR1 */
  500. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_PGCR1);
  501. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_PGCR1);
  502. /* DDR_ACIOCR1 */
  503. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_ACIOCR1);
  504. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_ACIOCR1);
  505. /* DDR_ACIOCR3 */
  506. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_ACIOCR3);
  507. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_ACIOCR3);
  508. /* DDR_ACIOCR5 */
  509. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_ACIOCR5);
  510. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_ACIOCR5);
  511. /* DDR_DX0GCR2 */
  512. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX0GCR2);
  513. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX0GCR2);
  514. /* DDR_DX1GCR2 */
  515. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX1GCR2);
  516. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX1GCR2);
  517. /* DDR_DX2GCR2 */
  518. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX2GCR2);
  519. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX2GCR2);
  520. /* DDR_DX3GCR2 */
  521. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX3GCR2);
  522. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX3GCR2);
  523. /* DDR_ZQCR */
  524. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_ZQCR);
  525. mmio_write_32(DBSC4_REG_DBPDRGD0, ddr_md == 0 ?
  526. DBSC4_SET_DBPDRGD0_ZQCR_MD19_0 :
  527. DBSC4_SET_DBPDRGD0_ZQCR_MD19_1);
  528. /* DDR_DX0GCR0 */
  529. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX0GCR0);
  530. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX0GCR0);
  531. /* DDR_DX1GCR0 */
  532. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX1GCR0);
  533. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX1GCR0);
  534. /* DDR_DX2GCR0 */
  535. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX2GCR0);
  536. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX2GCR0);
  537. /* DDR_DX3GCR0 */
  538. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX3GCR0);
  539. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX3GCR0);
  540. /* DDR_DX0GCR1 */
  541. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX0GCR1);
  542. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX0GCR1);
  543. /* DDR_DX1GCR1 */
  544. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX1GCR1);
  545. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX1GCR1);
  546. /* DDR_DX2GCR1 */
  547. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX2GCR1);
  548. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX2GCR1);
  549. /* DDR_DX3GCR1 */
  550. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX3GCR1);
  551. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX3GCR1);
  552. /* DDR_DX0GCR3 */
  553. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX0GCR3);
  554. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX0GCR3);
  555. /* DDR_DX1GCR3 */
  556. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX1GCR3);
  557. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX1GCR3);
  558. /* DDR_DX2GCR3 */
  559. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX2GCR3);
  560. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX2GCR3);
  561. /* DDR_DX3GCR3 */
  562. mmio_write_32(DBSC4_REG_DBPDRGA0, DBSC4_SET_DBPDRGA0_DX3GCR3);
  563. mmio_write_32(DBSC4_REG_DBPDRGD0, DBSC4_SET_DBPDRGD0_DX3GCR3);
  564. /* Write disable */
  565. mmio_write_32(DBSC4_REG_DBSYSCNT0, DBSC4_SET_DBSYSCNT0_WRITE_DISABLE);
  566. }
  567. void __attribute__ ((section(".system_ram"))) __attribute__ ((noinline))
  568. rcar_pwrc_go_suspend_to_ram(void)
  569. {
  570. #if PMIC_ROHM_BD9571
  571. int32_t rc = -1, qllm = -1;
  572. uint8_t mode;
  573. uint32_t i;
  574. #endif
  575. uint32_t reg, product;
  576. reg = mmio_read_32(RCAR_PRR);
  577. product = reg & PRR_PRODUCT_MASK;
  578. if (product != PRR_PRODUCT_E3)
  579. rcar_pwrc_set_self_refresh();
  580. else
  581. rcar_pwrc_set_self_refresh_e3();
  582. #if PMIC_ROHM_BD9571
  583. /* Set QLLM Cnt Disable */
  584. for (i = 0; (i < PMIC_RETRY_MAX) && (qllm != 0); i++)
  585. qllm = rcar_iic_dvfs_send(PMIC, PMIC_QLLM_CNT, 0);
  586. /* Set trigger of power down to PMIV */
  587. for (i = 0; (i < PMIC_RETRY_MAX) && (rc != 0) && (qllm == 0); i++) {
  588. rc = rcar_iic_dvfs_receive(PMIC, PMIC_BKUP_MODE_CNT, &mode);
  589. if (rc == 0) {
  590. mode |= BIT_BKUP_CTRL_OUT;
  591. rc = rcar_iic_dvfs_send(PMIC, PMIC_BKUP_MODE_CNT, mode);
  592. }
  593. }
  594. #endif
  595. wfi();
  596. while (1)
  597. ;
  598. }
  599. void rcar_pwrc_set_suspend_to_ram(void)
  600. {
  601. uintptr_t jump = (uintptr_t) &rcar_pwrc_go_suspend_to_ram;
  602. uintptr_t stack = (uintptr_t) (DEVICE_SRAM_STACK_BASE +
  603. DEVICE_SRAM_STACK_SIZE);
  604. uint32_t sctlr;
  605. rcar_pwrc_save_timer_state();
  606. /* disable MMU */
  607. sctlr = (uint32_t) read_sctlr_el3();
  608. sctlr &= (uint32_t) ~SCTLR_EL3_M_BIT;
  609. write_sctlr_el3((uint64_t) sctlr);
  610. rcar_pwrc_switch_stack(jump, stack, NULL);
  611. }
  612. void rcar_pwrc_init_suspend_to_ram(void)
  613. {
  614. #if PMIC_ROHM_BD9571
  615. uint8_t mode;
  616. if (rcar_iic_dvfs_receive(PMIC, PMIC_BKUP_MODE_CNT, &mode))
  617. panic();
  618. mode &= (uint8_t) (~BIT_BKUP_CTRL_OUT);
  619. if (rcar_iic_dvfs_send(PMIC, PMIC_BKUP_MODE_CNT, mode))
  620. panic();
  621. #endif
  622. }
  623. void rcar_pwrc_suspend_to_ram(void)
  624. {
  625. #if RCAR_SYSTEM_RESET_KEEPON_DDR
  626. int32_t error;
  627. error = rcar_iic_dvfs_send(PMIC, REG_KEEP10, 0);
  628. if (error) {
  629. ERROR("Failed send KEEP10 init ret=%d\n", error);
  630. return;
  631. }
  632. #endif
  633. rcar_pwrc_set_suspend_to_ram();
  634. }
  635. #endif
  636. void rcar_pwrc_code_copy_to_system_ram(void)
  637. {
  638. int ret __attribute__ ((unused)); /* in assert */
  639. uint32_t attr;
  640. struct device_sram_t {
  641. uintptr_t base;
  642. size_t len;
  643. } sram = {
  644. .base = (uintptr_t) DEVICE_SRAM_BASE,
  645. .len = DEVICE_SRAM_SIZE,
  646. };
  647. struct ddr_code_t {
  648. void *base;
  649. size_t len;
  650. } code = {
  651. .base = (void *) SRAM_COPY_START,
  652. .len = SYSTEM_RAM_END - SYSTEM_RAM_START,
  653. };
  654. attr = MT_MEMORY | MT_RW | MT_SECURE | MT_EXECUTE_NEVER;
  655. ret = xlat_change_mem_attributes(sram.base, sram.len, attr);
  656. assert(ret == 0);
  657. memcpy((void *)sram.base, code.base, code.len);
  658. flush_dcache_range((uint64_t) sram.base, code.len);
  659. attr = MT_MEMORY | MT_RO | MT_SECURE | MT_EXECUTE;
  660. ret = xlat_change_mem_attributes(sram.base, sram.len, attr);
  661. assert(ret == 0);
  662. /* Invalidate instruction cache */
  663. plat_invalidate_icache();
  664. dsb();
  665. isb();
  666. }
  667. uint32_t rcar_pwrc_get_cluster(void)
  668. {
  669. uint32_t reg;
  670. reg = mmio_read_32(RCAR_PRR);
  671. if (reg & (1U << (STATE_CA53_CPU + RCAR_CA53CPU_NUM_MAX)))
  672. return RCAR_CLUSTER_CA57;
  673. if (reg & (1U << (STATE_CA57_CPU + RCAR_CA57CPU_NUM_MAX)))
  674. return RCAR_CLUSTER_CA53;
  675. return RCAR_CLUSTER_A53A57;
  676. }
  677. uint32_t rcar_pwrc_get_mpidr_cluster(u_register_t mpidr)
  678. {
  679. uint32_t c = rcar_pwrc_get_cluster();
  680. if (IS_A53A57(c)) {
  681. if (mpidr & MPIDR_CLUSTER_MASK)
  682. return RCAR_CLUSTER_CA53;
  683. return RCAR_CLUSTER_CA57;
  684. }
  685. return c;
  686. }
  687. #if RCAR_LSI == RCAR_D3
  688. uint32_t rcar_pwrc_get_cpu_num(uint32_t c)
  689. {
  690. return 1;
  691. }
  692. #else
  693. uint32_t rcar_pwrc_get_cpu_num(uint32_t c)
  694. {
  695. uint32_t reg = mmio_read_32(RCAR_PRR);
  696. uint32_t count = 0, i;
  697. if (IS_A53A57(c) || IS_CA53(c)) {
  698. if (reg & (1 << (STATE_CA53_CPU + RCAR_CA53CPU_NUM_MAX)))
  699. goto count_ca57;
  700. for (i = 0; i < RCAR_CA53CPU_NUM_MAX; i++) {
  701. if (reg & (1 << (STATE_CA53_CPU + i)))
  702. continue;
  703. count++;
  704. }
  705. }
  706. count_ca57:
  707. if (IS_A53A57(c) || IS_CA57(c)) {
  708. if (reg & (1U << (STATE_CA57_CPU + RCAR_CA57CPU_NUM_MAX)))
  709. goto done;
  710. for (i = 0; i < RCAR_CA57CPU_NUM_MAX; i++) {
  711. if (reg & (1 << (STATE_CA57_CPU + i)))
  712. continue;
  713. count++;
  714. }
  715. }
  716. done:
  717. return count;
  718. }
  719. #endif
  720. int32_t rcar_pwrc_cpu_on_check(u_register_t mpidr)
  721. {
  722. uint64_t i;
  723. uint64_t j;
  724. uint64_t cpu_count;
  725. uintptr_t reg_PSTR;
  726. uint32_t status;
  727. uint64_t my_cpu;
  728. int32_t rtn;
  729. uint32_t my_cluster_type;
  730. const uint32_t cluster_type[PLATFORM_CLUSTER_COUNT] = {
  731. RCAR_CLUSTER_CA53,
  732. RCAR_CLUSTER_CA57
  733. };
  734. const uintptr_t registerPSTR[PLATFORM_CLUSTER_COUNT] = {
  735. RCAR_CA53PSTR,
  736. RCAR_CA57PSTR
  737. };
  738. my_cluster_type = rcar_pwrc_get_cluster();
  739. rtn = 0;
  740. my_cpu = mpidr & ((uint64_t)(MPIDR_CPU_MASK));
  741. for (i = 0U; i < ((uint64_t)(PLATFORM_CLUSTER_COUNT)); i++) {
  742. cpu_count = rcar_pwrc_get_cpu_num(cluster_type[i]);
  743. reg_PSTR = registerPSTR[i];
  744. for (j = 0U; j < cpu_count; j++) {
  745. if ((my_cluster_type != cluster_type[i]) || (my_cpu != j)) {
  746. status = mmio_read_32(reg_PSTR) >> (j * 4U);
  747. if ((status & 0x00000003U) == 0U) {
  748. rtn--;
  749. }
  750. }
  751. }
  752. }
  753. return rtn;
  754. }