msm8916_cpu_boot.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2021-2022, Stephan Gerhold <stephan@gerhold.net>
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch_helpers.h>
  7. #include <common/debug.h>
  8. #include <drivers/delay_timer.h>
  9. #include <lib/mmio.h>
  10. #include "msm8916_pm.h"
  11. #define CPU_PWR_CTL 0x4
  12. #define APC_PWR_GATE_CTL 0x14
  13. #define CPU_PWR_CTL_CLAMP BIT_32(0)
  14. #define CPU_PWR_CTL_CORE_MEM_CLAMP BIT_32(1)
  15. #define CPU_PWR_CTL_L1_RST_DIS BIT_32(2)
  16. #define CPU_PWR_CTL_CORE_MEM_HS BIT_32(3)
  17. #define CPU_PWR_CTL_CORE_RST BIT_32(4)
  18. #define CPU_PWR_CTL_COREPOR_RST BIT_32(5)
  19. #define CPU_PWR_CTL_GATE_CLK BIT_32(6)
  20. #define CPU_PWR_CTL_CORE_PWRD_UP BIT_32(7)
  21. #define APC_PWR_GATE_CTL_GHDS_EN BIT_32(0)
  22. #define APC_PWR_GATE_CTL_GHDS_CNT(cnt) ((cnt) << 24)
  23. #define PWR_CTL_OVERRIDE 0xc
  24. #define L2_PWR_CTL 0x14
  25. #define L2_PWR_STATUS 0x18
  26. #define CORE_CBCR 0x58
  27. #define PWR_CTL_OVERRIDE_PRESETDBG BIT_32(22)
  28. #define L2_PWR_CTL_L2_ARRAY_HS BIT_32(0)
  29. #define L2_PWR_CTL_SCU_ARRAY_HS BIT_32(1)
  30. #define L2_PWR_CTL_L2_RST_DIS BIT_32(2)
  31. #define L2_PWR_CTL_L2_HS_CLAMP BIT_32(8)
  32. #define L2_PWR_CTL_L2_HS_EN BIT_32(9)
  33. #define L2_PWR_CTL_L2_HS_RST BIT_32(10)
  34. #define L2_PWR_CTL_L2_SLEEP_STATE BIT_32(11)
  35. #define L2_PWR_CTL_SYS_RESET BIT_32(12)
  36. #define L2_PWR_CTL_L2_RET_SLP BIT_32(13)
  37. #define L2_PWR_CTL_SCU_ARRAY_HS_CLAMP BIT_32(14)
  38. #define L2_PWR_CTL_L2_ARRAY_HS_CLAMP BIT_32(15)
  39. #define L2_PWR_CTL_L2_HS_CNT(cnt) ((cnt) << 16)
  40. #define L2_PWR_CTL_PMIC_APC_ON BIT_32(28)
  41. #define L2_PWR_STATUS_L2_HS_STS BIT_32(9)
  42. #define CORE_CBCR_CLK_ENABLE BIT_32(0)
  43. #define CORE_CBCR_HW_CTL BIT_32(1)
  44. /* Boot a secondary CPU core for the first time. */
  45. void msm8916_cpu_boot(uintptr_t acs)
  46. {
  47. uint32_t pwr_ctl;
  48. VERBOSE("PSCI: Powering on CPU @ 0x%08lx\n", acs);
  49. pwr_ctl = CPU_PWR_CTL_CLAMP | CPU_PWR_CTL_CORE_MEM_CLAMP |
  50. CPU_PWR_CTL_CORE_RST | CPU_PWR_CTL_COREPOR_RST;
  51. mmio_write_32(acs + CPU_PWR_CTL, pwr_ctl);
  52. dsb();
  53. mmio_write_32(acs + APC_PWR_GATE_CTL, APC_PWR_GATE_CTL_GHDS_EN |
  54. APC_PWR_GATE_CTL_GHDS_CNT(16));
  55. dsb();
  56. udelay(2);
  57. pwr_ctl &= ~CPU_PWR_CTL_CORE_MEM_CLAMP;
  58. mmio_write_32(acs + CPU_PWR_CTL, pwr_ctl);
  59. dsb();
  60. pwr_ctl |= CPU_PWR_CTL_CORE_MEM_HS;
  61. mmio_write_32(acs + CPU_PWR_CTL, pwr_ctl);
  62. dsb();
  63. udelay(2);
  64. pwr_ctl &= ~CPU_PWR_CTL_CLAMP;
  65. mmio_write_32(acs + CPU_PWR_CTL, pwr_ctl);
  66. dsb();
  67. udelay(2);
  68. pwr_ctl &= ~(CPU_PWR_CTL_CORE_RST | CPU_PWR_CTL_COREPOR_RST);
  69. mmio_write_32(acs + CPU_PWR_CTL, pwr_ctl);
  70. dsb();
  71. pwr_ctl |= CPU_PWR_CTL_CORE_PWRD_UP;
  72. mmio_write_32(acs + CPU_PWR_CTL, pwr_ctl);
  73. dsb();
  74. }
  75. /* Power on cluster L2 cache for the first time. */
  76. void msm8916_l2_boot(uintptr_t base)
  77. {
  78. uint32_t pwr_ctl, cbcr, ovr;
  79. /* Skip if cluster L2 is already powered on */
  80. if (mmio_read_32(base + L2_PWR_STATUS) & L2_PWR_STATUS_L2_HS_STS) {
  81. VERBOSE("PSCI: L2 cache @ 0x%08lx is already powered on\n", base);
  82. return;
  83. }
  84. VERBOSE("PSCI: Powering on L2 cache @ 0x%08lx\n", base);
  85. pwr_ctl = L2_PWR_CTL_L2_HS_CLAMP | L2_PWR_CTL_L2_HS_EN |
  86. L2_PWR_CTL_L2_HS_RST | L2_PWR_CTL_SYS_RESET |
  87. L2_PWR_CTL_SCU_ARRAY_HS_CLAMP | L2_PWR_CTL_L2_ARRAY_HS_CLAMP |
  88. L2_PWR_CTL_L2_HS_CNT(16);
  89. mmio_write_32(base + L2_PWR_CTL, pwr_ctl);
  90. ovr = PWR_CTL_OVERRIDE_PRESETDBG;
  91. mmio_write_32(base + PWR_CTL_OVERRIDE, ovr);
  92. dsb();
  93. udelay(2);
  94. pwr_ctl &= ~(L2_PWR_CTL_SCU_ARRAY_HS_CLAMP |
  95. L2_PWR_CTL_L2_ARRAY_HS_CLAMP);
  96. mmio_write_32(base + L2_PWR_CTL, pwr_ctl);
  97. pwr_ctl |= (L2_PWR_CTL_L2_ARRAY_HS | L2_PWR_CTL_SCU_ARRAY_HS);
  98. mmio_write_32(base + L2_PWR_CTL, pwr_ctl);
  99. dsb();
  100. udelay(2);
  101. cbcr = CORE_CBCR_CLK_ENABLE;
  102. mmio_write_32(base + CORE_CBCR, cbcr);
  103. pwr_ctl &= ~L2_PWR_CTL_L2_HS_CLAMP;
  104. mmio_write_32(base + L2_PWR_CTL, pwr_ctl);
  105. dsb();
  106. udelay(2);
  107. ovr &= ~PWR_CTL_OVERRIDE_PRESETDBG;
  108. mmio_write_32(base + PWR_CTL_OVERRIDE, ovr);
  109. pwr_ctl &= ~(L2_PWR_CTL_L2_HS_RST | L2_PWR_CTL_SYS_RESET);
  110. mmio_write_32(base + L2_PWR_CTL, pwr_ctl);
  111. dsb();
  112. udelay(54);
  113. pwr_ctl |= L2_PWR_CTL_PMIC_APC_ON;
  114. mmio_write_32(base + L2_PWR_CTL, pwr_ctl);
  115. cbcr |= CORE_CBCR_HW_CTL;
  116. mmio_write_32(base + CORE_CBCR, cbcr);
  117. dsb();
  118. }