hisi_pwrc.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdarg.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <platform_def.h>
  10. #include <common/debug.h>
  11. #include <lib/mmio.h>
  12. #include <hi6220_regs_acpu.h>
  13. #include <hi6220_regs_ao.h>
  14. #include <hisi_ipc.h>
  15. #include <hisi_pwrc.h>
  16. #include <hisi_sram_map.h>
  17. #define CLUSTER_CORE_COUNT (4)
  18. #define CLUSTER_CORE_MASK ((1 << CLUSTER_CORE_COUNT) - 1)
  19. void hisi_pwrc_set_core_bx_addr(unsigned int core, unsigned int cluster,
  20. uintptr_t entry_point)
  21. {
  22. uintptr_t *core_entry = (uintptr_t *)PWRCTRL_ACPU_ASM_D_ARM_PARA_AD;
  23. unsigned int i;
  24. if (!core_entry) {
  25. INFO("%s: core entry point is null!\n", __func__);
  26. return;
  27. }
  28. i = cluster * CLUSTER_CORE_COUNT + core;
  29. mmio_write_64((uintptr_t)(core_entry + i), entry_point);
  30. }
  31. void hisi_pwrc_set_cluster_wfi(unsigned int cluster)
  32. {
  33. unsigned int reg = 0;
  34. if (cluster == 0) {
  35. reg = mmio_read_32(ACPU_SC_SNOOP_PWD);
  36. reg |= PD_DETECT_START0;
  37. mmio_write_32(ACPU_SC_SNOOP_PWD, reg);
  38. } else if (cluster == 1) {
  39. reg = mmio_read_32(ACPU_SC_SNOOP_PWD);
  40. reg |= PD_DETECT_START1;
  41. mmio_write_32(ACPU_SC_SNOOP_PWD, reg);
  42. }
  43. }
  44. void hisi_pwrc_enable_debug(unsigned int core, unsigned int cluster)
  45. {
  46. unsigned int val, enable;
  47. enable = 1U << (core + PDBGUP_CLUSTER1_SHIFT * cluster);
  48. /* Enable debug module */
  49. val = mmio_read_32(ACPU_SC_PDBGUP_MBIST);
  50. mmio_write_32(ACPU_SC_PDBGUP_MBIST, val | enable);
  51. do {
  52. /* RAW barrier */
  53. val = mmio_read_32(ACPU_SC_PDBGUP_MBIST);
  54. } while (!(val & enable));
  55. }
  56. int hisi_pwrc_setup(void)
  57. {
  58. unsigned int reg, sec_entrypoint;
  59. extern char pm_asm_code[], pm_asm_code_end[];
  60. extern char v7_asm[], v7_asm_end[];
  61. sec_entrypoint = PWRCTRL_ACPU_ASM_CODE_BASE;
  62. mmio_write_32(ACPU_SC_CPUx_RVBARADDR(0), sec_entrypoint >> 2);
  63. mmio_write_32(ACPU_SC_CPUx_RVBARADDR(1), sec_entrypoint >> 2);
  64. mmio_write_32(ACPU_SC_CPUx_RVBARADDR(2), sec_entrypoint >> 2);
  65. mmio_write_32(ACPU_SC_CPUx_RVBARADDR(3), sec_entrypoint >> 2);
  66. mmio_write_32(ACPU_SC_CPUx_RVBARADDR(4), sec_entrypoint >> 2);
  67. mmio_write_32(ACPU_SC_CPUx_RVBARADDR(5), sec_entrypoint >> 2);
  68. mmio_write_32(ACPU_SC_CPUx_RVBARADDR(6), sec_entrypoint >> 2);
  69. mmio_write_32(ACPU_SC_CPUx_RVBARADDR(7), sec_entrypoint >> 2);
  70. memset((void *)PWRCTRL_ACPU_ASM_SPACE_ADDR, 0, 0x400);
  71. memcpy((void *)PWRCTRL_ACPU_ASM_SPACE_ADDR, (void *)v7_asm,
  72. v7_asm_end - v7_asm);
  73. memcpy((void *)PWRCTRL_ACPU_ASM_CODE_BASE, (void *)pm_asm_code,
  74. pm_asm_code_end - pm_asm_code);
  75. reg = mmio_read_32(AO_SC_SYS_CTRL1);
  76. /* Remap SRAM address for ACPU */
  77. reg |= AO_SC_SYS_CTRL1_REMAP_SRAM_AARM |
  78. AO_SC_SYS_CTRL1_REMAP_SRAM_AARM_MSK;
  79. /* Enable reset signal for watchdog */
  80. reg |= AO_SC_SYS_CTRL1_AARM_WD_RST_CFG |
  81. AO_SC_SYS_CTRL1_AARM_WD_RST_CFG_MSK;
  82. mmio_write_32(AO_SC_SYS_CTRL1, reg);
  83. return 0;
  84. }