mtk_pm.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) 2022, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <plat/common/platform.h>
  8. #include <lib/pm/mtk_pm.h>
  9. #define MTK_PM_ST_SMP_READY BIT(0)
  10. #define MTK_PM_ST_PWR_READY BIT(1)
  11. #define MTK_PM_ST_RESET_READY BIT(2)
  12. static uintptr_t mtk_secure_entrypoint;
  13. static plat_init_func mtk_plat_smp_init;
  14. static plat_psci_ops_t mtk_pm_ops;
  15. static unsigned int mtk_pm_status;
  16. uintptr_t plat_pm_get_warm_entry(void)
  17. {
  18. return mtk_secure_entrypoint;
  19. }
  20. int plat_pm_ops_setup_pwr(struct plat_pm_pwr_ctrl *ops)
  21. {
  22. if (!ops) {
  23. return MTK_CPUPM_E_FAIL;
  24. }
  25. #if CONFIG_MTK_CPU_SUSPEND_EN
  26. if (!mtk_pm_ops.pwr_domain_suspend) {
  27. mtk_pm_ops.pwr_domain_suspend = ops->pwr_domain_suspend;
  28. }
  29. if (!mtk_pm_ops.pwr_domain_suspend_finish) {
  30. mtk_pm_ops.pwr_domain_suspend_finish = ops->pwr_domain_suspend_finish;
  31. }
  32. if (!mtk_pm_ops.validate_power_state) {
  33. mtk_pm_ops.validate_power_state = ops->validate_power_state;
  34. }
  35. if (!mtk_pm_ops.get_sys_suspend_power_state) {
  36. mtk_pm_ops.get_sys_suspend_power_state = ops->get_sys_suspend_power_state;
  37. }
  38. mtk_pm_status |= MTK_PM_ST_PWR_READY;
  39. #endif
  40. return MTK_CPUPM_E_OK;
  41. }
  42. int plat_pm_ops_setup_smp(struct plat_pm_smp_ctrl *ops)
  43. {
  44. if (!ops) {
  45. return MTK_CPUPM_E_FAIL;
  46. }
  47. #if CONFIG_MTK_SMP_EN
  48. if (!mtk_pm_ops.pwr_domain_on) {
  49. mtk_pm_ops.pwr_domain_on = ops->pwr_domain_on;
  50. }
  51. if (!mtk_pm_ops.pwr_domain_on_finish) {
  52. mtk_pm_ops.pwr_domain_on_finish = ops->pwr_domain_on_finish;
  53. }
  54. if (!mtk_pm_ops.pwr_domain_off) {
  55. mtk_pm_ops.pwr_domain_off = ops->pwr_domain_off;
  56. }
  57. if (!mtk_plat_smp_init) {
  58. mtk_plat_smp_init = ops->init;
  59. }
  60. mtk_pm_status |= MTK_PM_ST_SMP_READY;
  61. #endif
  62. return MTK_CPUPM_E_OK;
  63. }
  64. int plat_pm_ops_setup_reset(struct plat_pm_reset_ctrl *ops)
  65. {
  66. if (!ops) {
  67. return MTK_CPUPM_E_FAIL;
  68. }
  69. if (!mtk_pm_ops.system_off) {
  70. mtk_pm_ops.system_off = ops->system_off;
  71. }
  72. if (!mtk_pm_ops.system_reset) {
  73. mtk_pm_ops.system_reset = ops->system_reset;
  74. }
  75. if (!mtk_pm_ops.system_reset2) {
  76. mtk_pm_ops.system_reset2 = ops->system_reset2;
  77. }
  78. mtk_pm_status |= MTK_PM_ST_RESET_READY;
  79. return MTK_CPUPM_E_OK;
  80. }
  81. int plat_setup_psci_ops(uintptr_t sec_entrypoint,
  82. const plat_psci_ops_t **psci_ops)
  83. {
  84. *psci_ops = &mtk_pm_ops;
  85. mtk_secure_entrypoint = sec_entrypoint;
  86. if (mtk_plat_smp_init) {
  87. unsigned int cpu_id = plat_my_core_pos();
  88. mtk_plat_smp_init(cpu_id, mtk_secure_entrypoint);
  89. }
  90. INFO("%s, smp:(%d), pwr_ctrl:(%d), system_reset:(%d)\n", __func__,
  91. !!(mtk_pm_status & MTK_PM_ST_SMP_READY),
  92. !!(mtk_pm_status & MTK_PM_ST_PWR_READY),
  93. !!(mtk_pm_status & MTK_PM_ST_RESET_READY));
  94. return 0;
  95. }