plat_pm.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <platform_def.h>
  8. #include <arch_helpers.h>
  9. #include <common/bl_common.h>
  10. #include <common/debug.h>
  11. #include <context.h>
  12. #include <lib/el3_runtime/context_mgmt.h>
  13. #include <lib/mmio.h>
  14. #include <lib/psci/psci.h>
  15. #include <plat/common/platform.h>
  16. #include "hi3798cv200.h"
  17. #include "plat_private.h"
  18. #define REG_PERI_CPU_RVBARADDR 0xF8A80034
  19. #define REG_PERI_CPU_AARCH_MODE 0xF8A80030
  20. #define REG_CPU_LP_CPU_SW_BEGIN 10
  21. #define CPU_REG_COREPO_SRST 12
  22. #define CPU_REG_CORE_SRST 8
  23. static void poplar_cpu_standby(plat_local_state_t cpu_state)
  24. {
  25. dsb();
  26. wfi();
  27. }
  28. static int poplar_pwr_domain_on(u_register_t mpidr)
  29. {
  30. unsigned int cpu = plat_core_pos_by_mpidr(mpidr);
  31. unsigned int regval, regval_bak;
  32. /* Select 400MHz before start slave cores */
  33. regval_bak = mmio_read_32((uintptr_t)(REG_BASE_CRG + REG_CPU_LP));
  34. mmio_write_32((uintptr_t)(REG_BASE_CRG + REG_CPU_LP), 0x206);
  35. mmio_write_32((uintptr_t)(REG_BASE_CRG + REG_CPU_LP), 0x606);
  36. /* Clear the slave cpu arm_por_srst_req reset */
  37. regval = mmio_read_32((uintptr_t)(REG_BASE_CRG + REG_CPU_RST));
  38. regval &= ~(1 << (cpu + CPU_REG_COREPO_SRST));
  39. mmio_write_32((uintptr_t)(REG_BASE_CRG + REG_CPU_RST), regval);
  40. /* Clear the slave cpu reset */
  41. regval = mmio_read_32((uintptr_t)(REG_BASE_CRG + REG_CPU_RST));
  42. regval &= ~(1 << (cpu + CPU_REG_CORE_SRST));
  43. mmio_write_32((uintptr_t)(REG_BASE_CRG + REG_CPU_RST), regval);
  44. /* Restore cpu frequency */
  45. regval = regval_bak & (~(1 << REG_CPU_LP_CPU_SW_BEGIN));
  46. mmio_write_32((uintptr_t)(REG_BASE_CRG + REG_CPU_LP), regval);
  47. mmio_write_32((uintptr_t)(REG_BASE_CRG + REG_CPU_LP), regval_bak);
  48. return PSCI_E_SUCCESS;
  49. }
  50. static void poplar_pwr_domain_off(const psci_power_state_t *target_state)
  51. {
  52. assert(0);
  53. }
  54. static void poplar_pwr_domain_suspend(const psci_power_state_t *target_state)
  55. {
  56. assert(0);
  57. }
  58. static void poplar_pwr_domain_on_finish(const psci_power_state_t *target_state)
  59. {
  60. assert(target_state->pwr_domain_state[MPIDR_AFFLVL0] ==
  61. PLAT_MAX_OFF_STATE);
  62. /* Enable the gic cpu interface */
  63. poplar_gic_pcpu_init();
  64. /* Program the gic per-cpu distributor or re-distributor interface */
  65. poplar_gic_cpuif_enable();
  66. }
  67. static void poplar_pwr_domain_suspend_finish(
  68. const psci_power_state_t *target_state)
  69. {
  70. assert(0);
  71. }
  72. static void __dead2 poplar_system_off(void)
  73. {
  74. ERROR("Poplar System Off: operation not handled.\n");
  75. /* Turn off watchdog0 before panic() */
  76. mmio_write_32((uintptr_t)(HISI_WDG0_BASE + 0xc00), 0x1ACCE551);
  77. mmio_write_32((uintptr_t)(HISI_WDG0_BASE + 0x8), 0x00000000);
  78. panic();
  79. }
  80. static void __dead2 poplar_system_reset(void)
  81. {
  82. /* Unlock Sysctrl critical registers */
  83. mmio_write_32((uintptr_t)(REG_BASE_SCTL + REG_SC_LOCKEN), SC_UNLOCK_MAGIC);
  84. /* Assert system reset */
  85. mmio_write_32((uintptr_t)(REG_BASE_SCTL + REG_SC_SYSRES), 0xfee1dead);
  86. wfi();
  87. ERROR("Poplar System Reset: operation not handled.\n");
  88. panic();
  89. }
  90. static int32_t poplar_validate_power_state(unsigned int power_state,
  91. psci_power_state_t *req_state)
  92. {
  93. VERBOSE("%s: power_state: 0x%x\n", __func__, power_state);
  94. int pstate = psci_get_pstate_type(power_state);
  95. assert(req_state);
  96. /* Sanity check the requested state */
  97. if (pstate == PSTATE_TYPE_STANDBY)
  98. req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_RET_STATE;
  99. else
  100. req_state->pwr_domain_state[MPIDR_AFFLVL0] = PLAT_MAX_OFF_STATE;
  101. /* We expect the 'state id' to be zero */
  102. if (psci_get_pstate_id(power_state))
  103. return PSCI_E_INVALID_PARAMS;
  104. return PSCI_E_SUCCESS;
  105. }
  106. static int poplar_validate_ns_entrypoint(uintptr_t entrypoint)
  107. {
  108. /*
  109. * Check if the non secure entrypoint lies within the non
  110. * secure DRAM.
  111. */
  112. if ((entrypoint >= DDR_BASE) && (entrypoint < (DDR_BASE + DDR_SIZE)))
  113. return PSCI_E_SUCCESS;
  114. return PSCI_E_INVALID_ADDRESS;
  115. }
  116. static void poplar_get_sys_suspend_power_state(psci_power_state_t *req_state)
  117. {
  118. int i;
  119. for (i = MPIDR_AFFLVL0; i <= PLAT_MAX_PWR_LVL; i++)
  120. req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE;
  121. }
  122. static const plat_psci_ops_t poplar_plat_psci_ops = {
  123. .cpu_standby = poplar_cpu_standby,
  124. .pwr_domain_on = poplar_pwr_domain_on,
  125. .pwr_domain_off = poplar_pwr_domain_off,
  126. .pwr_domain_suspend = poplar_pwr_domain_suspend,
  127. .pwr_domain_on_finish = poplar_pwr_domain_on_finish,
  128. .pwr_domain_suspend_finish = poplar_pwr_domain_suspend_finish,
  129. .system_off = poplar_system_off,
  130. .system_reset = poplar_system_reset,
  131. .validate_power_state = poplar_validate_power_state,
  132. .validate_ns_entrypoint = poplar_validate_ns_entrypoint,
  133. .get_sys_suspend_power_state = poplar_get_sys_suspend_power_state,
  134. };
  135. int plat_setup_psci_ops(uintptr_t sec_entrypoint,
  136. const plat_psci_ops_t **psci_ops)
  137. {
  138. *psci_ops = &poplar_plat_psci_ops;
  139. mmio_write_32((uintptr_t)REG_PERI_CPU_AARCH_MODE, 0xF);
  140. mmio_write_32((uintptr_t)REG_PERI_CPU_RVBARADDR, sec_entrypoint);
  141. return 0;
  142. }