plat_psci_handlers.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <arch_helpers.h>
  8. #include <assert.h>
  9. #include <denver.h>
  10. #include <debug.h>
  11. #include <delay_timer.h>
  12. #include <flowctrl.h>
  13. #include <mmio.h>
  14. #include <platform_def.h>
  15. #include <pmc.h>
  16. #include <psci.h>
  17. #include <tegra_def.h>
  18. #include <tegra_private.h>
  19. /*
  20. * Register used to clear CPU reset signals. Each CPU has two reset
  21. * signals: CPU reset (3:0) and Core reset (19:16)
  22. */
  23. #define CPU_CMPLX_RESET_CLR 0x344
  24. #define CPU_CORE_RESET_MASK 0x10001
  25. /* Clock and Reset controller registers for system clock's settings */
  26. #define SCLK_RATE 0x30
  27. #define SCLK_BURST_POLICY 0x28
  28. #define SCLK_BURST_POLICY_DEFAULT 0x10000000
  29. static int cpu_powergate_mask[PLATFORM_MAX_CPUS_PER_CLUSTER];
  30. int32_t tegra_soc_validate_power_state(unsigned int power_state,
  31. psci_power_state_t *req_state)
  32. {
  33. int state_id = psci_get_pstate_id(power_state);
  34. int cpu = read_mpidr() & MPIDR_CPU_MASK;
  35. /*
  36. * Sanity check the requested state id, power level and CPU number.
  37. * Currently T132 only supports SYSTEM_SUSPEND on last standing CPU
  38. * i.e. CPU 0
  39. */
  40. if ((state_id != PSTATE_ID_SOC_POWERDN) || (cpu != 0)) {
  41. ERROR("unsupported state id @ power level\n");
  42. return PSCI_E_INVALID_PARAMS;
  43. }
  44. /* Set lower power states to PLAT_MAX_OFF_STATE */
  45. for (uint32_t i = MPIDR_AFFLVL0; i < PLAT_MAX_PWR_LVL; i++)
  46. req_state->pwr_domain_state[i] = PLAT_MAX_OFF_STATE;
  47. /* Set the SYSTEM_SUSPEND state-id */
  48. req_state->pwr_domain_state[PLAT_MAX_PWR_LVL] =
  49. PSTATE_ID_SOC_POWERDN;
  50. return PSCI_E_SUCCESS;
  51. }
  52. int tegra_soc_pwr_domain_on(u_register_t mpidr)
  53. {
  54. int cpu = mpidr & MPIDR_CPU_MASK;
  55. uint32_t mask = CPU_CORE_RESET_MASK << cpu;
  56. if (cpu_powergate_mask[cpu] == 0) {
  57. /* Deassert CPU reset signals */
  58. mmio_write_32(TEGRA_CAR_RESET_BASE + CPU_CMPLX_RESET_CLR, mask);
  59. /* Power on CPU using PMC */
  60. tegra_pmc_cpu_on(cpu);
  61. /* Fill in the CPU powergate mask */
  62. cpu_powergate_mask[cpu] = 1;
  63. } else {
  64. /* Power on CPU using Flow Controller */
  65. tegra_fc_cpu_on(cpu);
  66. }
  67. return PSCI_E_SUCCESS;
  68. }
  69. int tegra_soc_pwr_domain_on_finish(const psci_power_state_t *target_state)
  70. {
  71. /*
  72. * Lock scratch registers which hold the CPU vectors
  73. */
  74. tegra_pmc_lock_cpu_vectors();
  75. return PSCI_E_SUCCESS;
  76. }
  77. int tegra_soc_pwr_domain_off(const psci_power_state_t *target_state)
  78. {
  79. tegra_fc_cpu_off(read_mpidr() & MPIDR_CPU_MASK);
  80. /* Disable DCO operations */
  81. denver_disable_dco();
  82. /* Power down the CPU */
  83. write_actlr_el1(DENVER_CPU_STATE_POWER_DOWN);
  84. return PSCI_E_SUCCESS;
  85. }
  86. int tegra_soc_pwr_domain_suspend(const psci_power_state_t *target_state)
  87. {
  88. #if ENABLE_ASSERTIONS
  89. int cpu = read_mpidr() & MPIDR_CPU_MASK;
  90. /* SYSTEM_SUSPEND only on CPU0 */
  91. assert(cpu == 0);
  92. #endif
  93. /* Allow restarting CPU #1 using PMC on suspend exit */
  94. cpu_powergate_mask[1] = 0;
  95. /* Program FC to enter suspend state */
  96. tegra_fc_cpu_powerdn(read_mpidr());
  97. /* Disable DCO operations */
  98. denver_disable_dco();
  99. /* Program the suspend state ID */
  100. write_actlr_el1(target_state->pwr_domain_state[PLAT_MAX_PWR_LVL]);
  101. return PSCI_E_SUCCESS;
  102. }
  103. int tegra_soc_prepare_system_reset(void)
  104. {
  105. /*
  106. * Set System Clock (SCLK) to POR default so that the clock source
  107. * for the PMC APB clock would not be changed due to system reset.
  108. */
  109. mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_BURST_POLICY,
  110. SCLK_BURST_POLICY_DEFAULT);
  111. mmio_write_32((uintptr_t)TEGRA_CAR_RESET_BASE + SCLK_RATE, 0);
  112. /* Wait 1 ms to make sure clock source/device logic is stabilized. */
  113. mdelay(1);
  114. return PSCI_E_SUCCESS;
  115. }