ptp3_common.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2022, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch_helpers.h>
  7. #if MTK_PUBEVENT_ENABLE
  8. #include <lib/pm/mtk_pm.h>
  9. #endif
  10. #include <ptp3_plat.h>
  11. #define PTP3_CORE_OFT(core) (0x800 * (core))
  12. static void ptp3_init(unsigned int core)
  13. {
  14. unsigned int i, addr, value;
  15. if (core < PTP3_CFG_CPU_START_ID_B) {
  16. mmio_clrsetbits_32(ptp3_cfg1[0][PTP3_CFG_ADDR], PTP3_CFG1_MASK,
  17. ptp3_cfg1[0][PTP3_CFG_VALUE]);
  18. } else {
  19. mmio_clrsetbits_32(ptp3_cfg1[1][PTP3_CFG_ADDR], PTP3_CFG1_MASK,
  20. ptp3_cfg1[1][PTP3_CFG_VALUE]);
  21. }
  22. if (core < PTP3_CFG_CPU_START_ID_B) {
  23. for (i = 0; i < NR_PTP3_CFG2_DATA; i++) {
  24. addr = ptp3_cfg2[i][PTP3_CFG_ADDR] + PTP3_CORE_OFT(core);
  25. value = ptp3_cfg2[i][PTP3_CFG_VALUE];
  26. mmio_write_32(addr, value);
  27. }
  28. } else {
  29. for (i = 0; i < NR_PTP3_CFG2_DATA; i++) {
  30. addr = ptp3_cfg2[i][PTP3_CFG_ADDR] + PTP3_CORE_OFT(core);
  31. if (i == 2) {
  32. value = ptp3_cfg2[i][PTP3_CFG_VALUE] + 0x5E0;
  33. } else {
  34. value = ptp3_cfg2[i][PTP3_CFG_VALUE];
  35. }
  36. mmio_write_32(addr, value);
  37. }
  38. }
  39. if (core < PTP3_CFG_CPU_START_ID_B) {
  40. addr = ptp3_cfg3[PTP3_CFG_ADDR] + PTP3_CORE_OFT(core);
  41. value = ptp3_cfg3[PTP3_CFG_VALUE];
  42. } else {
  43. addr = ptp3_cfg3_ext[PTP3_CFG_ADDR] + PTP3_CORE_OFT(core);
  44. value = ptp3_cfg3_ext[PTP3_CFG_VALUE];
  45. }
  46. mmio_write_32(addr, value & PTP3_CFG3_MASK1);
  47. mmio_write_32(addr, value & PTP3_CFG3_MASK2);
  48. mmio_write_32(addr, value & PTP3_CFG3_MASK3);
  49. }
  50. static void pdp_proc_arm_write(unsigned int pdp_n)
  51. {
  52. unsigned long v = 0;
  53. dsb();
  54. __asm__ volatile ("mrs %0, S3_6_C15_C2_0" : "=r" (v));
  55. v |= (UL(0x0) << 52);
  56. v |= (UL(0x1) << 53);
  57. v |= (UL(0x0) << 54);
  58. v |= (UL(0x0) << 48);
  59. v |= (UL(0x1) << 49);
  60. __asm__ volatile ("msr S3_6_C15_C2_0, %0" : : "r" (v));
  61. dsb();
  62. }
  63. static void pdp_init(unsigned int pdp_cpu)
  64. {
  65. if ((pdp_cpu >= PTP3_CFG_CPU_START_ID_B) && (pdp_cpu < NR_PTP3_CFG_CPU)) {
  66. pdp_proc_arm_write(pdp_cpu);
  67. }
  68. }
  69. void ptp3_core_init(unsigned int core)
  70. {
  71. ptp3_init(core);
  72. pdp_init(core);
  73. }
  74. void ptp3_core_deinit(unsigned int core)
  75. {
  76. /* TBD */
  77. }
  78. #if MTK_PUBEVENT_ENABLE
  79. /* Handle for power on domain */
  80. void *ptp3_handle_pwr_on_event(const void *arg)
  81. {
  82. if (arg != NULL) {
  83. struct mt_cpupm_event_data *data = (struct mt_cpupm_event_data *)arg;
  84. if ((data->pwr_domain & MT_CPUPM_PWR_DOMAIN_CORE) > 0) {
  85. ptp3_core_init(data->cpuid);
  86. }
  87. }
  88. return (void *)arg;
  89. }
  90. MT_CPUPM_SUBCRIBE_EVENT_PWR_ON(ptp3_handle_pwr_on_event);
  91. /* Handle for power off domain */
  92. void *ptp3_handle_pwr_off_event(const void *arg)
  93. {
  94. if (arg != NULL) {
  95. struct mt_cpupm_event_data *data = (struct mt_cpupm_event_data *)arg;
  96. if ((data->pwr_domain & MT_CPUPM_PWR_DOMAIN_CORE) > 0) {
  97. ptp3_core_deinit(data->cpuid);
  98. }
  99. }
  100. return (void *)arg;
  101. }
  102. MT_CPUPM_SUBCRIBE_EVENT_PWR_OFF(ptp3_handle_pwr_off_event);
  103. #else
  104. #pragma message "PSCI hint not enable"
  105. #endif