sunxi_cpu_ops.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2017-2021, 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/debug.h>
  10. #include <drivers/delay_timer.h>
  11. #include <lib/mmio.h>
  12. #include <lib/utils_def.h>
  13. #include <plat/common/platform.h>
  14. #include <sunxi_cpucfg.h>
  15. #include <sunxi_mmap.h>
  16. #include <sunxi_private.h>
  17. #ifndef SUNXI_C0_CPU_CTRL_REG
  18. #define SUNXI_C0_CPU_CTRL_REG(n) 0
  19. #define SUNXI_CPU_UNK_REG(n) 0
  20. #define SUNXI_CPU_CTRL_REG(n) 0
  21. #endif
  22. static void sunxi_cpu_disable_power(unsigned int cluster, unsigned int core)
  23. {
  24. if (mmio_read_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core)) == 0xff)
  25. return;
  26. VERBOSE("PSCI: Disabling power to cluster %d core %d\n", cluster, core);
  27. mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0xff);
  28. }
  29. static void sunxi_cpu_enable_power(unsigned int cluster, unsigned int core)
  30. {
  31. if (mmio_read_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core)) == 0)
  32. return;
  33. VERBOSE("PSCI: Enabling power to cluster %d core %d\n", cluster, core);
  34. /* Power enable sequence from original Allwinner sources */
  35. mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0xfe);
  36. mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0xf8);
  37. mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0xe0);
  38. mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0x80);
  39. mmio_write_32(SUNXI_CPU_POWER_CLAMP_REG(cluster, core), 0x00);
  40. udelay(1);
  41. }
  42. /* We can't turn ourself off like this, but it works for other cores. */
  43. static void sunxi_cpu_off(u_register_t mpidr)
  44. {
  45. unsigned int cluster = MPIDR_AFFLVL1_VAL(mpidr);
  46. unsigned int core = MPIDR_AFFLVL0_VAL(mpidr);
  47. VERBOSE("PSCI: Powering off cluster %d core %d\n", cluster, core);
  48. if (sunxi_cpucfg_has_per_cluster_regs()) {
  49. /* Deassert DBGPWRDUP */
  50. mmio_clrbits_32(SUNXI_CPUCFG_DBG_REG0, BIT(core));
  51. /* Activate the core output clamps, but not for core 0. */
  52. if (core != 0) {
  53. mmio_setbits_32(SUNXI_POWEROFF_GATING_REG(cluster),
  54. BIT(core));
  55. }
  56. /* Assert CPU power-on reset */
  57. mmio_clrbits_32(SUNXI_POWERON_RST_REG(cluster), BIT(core));
  58. /* Remove power from the CPU */
  59. sunxi_cpu_disable_power(cluster, core);
  60. } else {
  61. /* power down(?) debug core */
  62. mmio_clrbits_32(SUNXI_C0_CPU_CTRL_REG(core), BIT(8));
  63. /* ??? Activate the core output clamps, but not for core 0 */
  64. if (core != 0) {
  65. mmio_setbits_32(SUNXI_CPU_UNK_REG(core), BIT(1));
  66. }
  67. /* ??? Assert CPU power-on reset ??? */
  68. mmio_clrbits_32(SUNXI_CPU_UNK_REG(core), BIT(0));
  69. /* Remove power from the CPU */
  70. sunxi_cpu_disable_power(cluster, core);
  71. }
  72. }
  73. void sunxi_cpu_on(u_register_t mpidr)
  74. {
  75. unsigned int cluster = MPIDR_AFFLVL1_VAL(mpidr);
  76. unsigned int core = MPIDR_AFFLVL0_VAL(mpidr);
  77. VERBOSE("PSCI: Powering on cluster %d core %d\n", cluster, core);
  78. if (sunxi_cpucfg_has_per_cluster_regs()) {
  79. /* Assert CPU core reset */
  80. mmio_clrbits_32(SUNXI_CPUCFG_RST_CTRL_REG(cluster), BIT(core));
  81. /* Assert CPU power-on reset */
  82. mmio_clrbits_32(SUNXI_POWERON_RST_REG(cluster), BIT(core));
  83. /* Set CPU to start in AArch64 mode */
  84. mmio_setbits_32(SUNXI_AA64nAA32_REG(cluster),
  85. BIT(SUNXI_AA64nAA32_OFFSET + core));
  86. /* Apply power to the CPU */
  87. sunxi_cpu_enable_power(cluster, core);
  88. /* Release the core output clamps */
  89. mmio_clrbits_32(SUNXI_POWEROFF_GATING_REG(cluster), BIT(core));
  90. /* Deassert CPU power-on reset */
  91. mmio_setbits_32(SUNXI_POWERON_RST_REG(cluster), BIT(core));
  92. /* Deassert CPU core reset */
  93. mmio_setbits_32(SUNXI_CPUCFG_RST_CTRL_REG(cluster), BIT(core));
  94. /* Assert DBGPWRDUP */
  95. mmio_setbits_32(SUNXI_CPUCFG_DBG_REG0, BIT(core));
  96. } else {
  97. /* Assert CPU core reset */
  98. mmio_clrbits_32(SUNXI_C0_CPU_CTRL_REG(core), BIT(0));
  99. /* ??? Assert CPU power-on reset ??? */
  100. mmio_clrbits_32(SUNXI_CPU_UNK_REG(core), BIT(0));
  101. /* Set CPU to start in AArch64 mode */
  102. mmio_setbits_32(SUNXI_CPU_CTRL_REG(core), BIT(0));
  103. /* Apply power to the CPU */
  104. sunxi_cpu_enable_power(cluster, core);
  105. /* ??? Release the core output clamps ??? */
  106. mmio_clrbits_32(SUNXI_CPU_UNK_REG(core), BIT(1));
  107. /* ??? Deassert CPU power-on reset ??? */
  108. mmio_setbits_32(SUNXI_CPU_UNK_REG(core), BIT(0));
  109. /* Deassert CPU core reset */
  110. mmio_setbits_32(SUNXI_C0_CPU_CTRL_REG(core), BIT(0));
  111. /* power up(?) debug core */
  112. mmio_setbits_32(SUNXI_C0_CPU_CTRL_REG(core), BIT(8));
  113. }
  114. }
  115. void sunxi_cpu_power_off_others(void)
  116. {
  117. u_register_t self = read_mpidr();
  118. unsigned int cluster;
  119. unsigned int core;
  120. for (cluster = 0; cluster < PLATFORM_CLUSTER_COUNT; ++cluster) {
  121. for (core = 0; core < PLATFORM_MAX_CPUS_PER_CLUSTER; ++core) {
  122. u_register_t mpidr = (cluster << MPIDR_AFF1_SHIFT) |
  123. (core << MPIDR_AFF0_SHIFT) |
  124. BIT(31);
  125. if (mpidr != self)
  126. sunxi_cpu_off(mpidr);
  127. }
  128. }
  129. }