mtk_pm.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * Copyright (c) 2022, Mediatek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef MTK_PM_H
  7. #define MTK_PM_H
  8. #include <lib/psci/psci.h>
  9. #if MTK_PUBEVENT_ENABLE
  10. #include <vendor_pubsub_events.h>
  11. #endif
  12. #define MTK_CPUPM_E_OK (0)
  13. #define MTK_CPUPM_E_UNKNOWN (-1)
  14. #define MTK_CPUPM_E_ERR (-2)
  15. #define MTK_CPUPM_E_FAIL (-3)
  16. #define MTK_CPUPM_E_NOT_SUPPORT (-4)
  17. #define MTK_CPUPM_FN_PWR_LOCK_AQUIRE BIT(0)
  18. #define MTK_CPUPM_FN_INIT BIT(1)
  19. #define MTK_CPUPM_FN_PWR_STATE_VALID BIT(2)
  20. #define MTK_CPUPM_FN_PWR_ON_CORE_PREPARE BIT(3)
  21. #define MTK_CPUPM_FN_SUSPEND_CORE BIT(4)
  22. #define MTK_CPUPM_FN_RESUME_CORE BIT(5)
  23. #define MTK_CPUPM_FN_SUSPEND_CLUSTER BIT(6)
  24. #define MTK_CPUPM_FN_RESUME_CLUSTER BIT(7)
  25. #define MTK_CPUPM_FN_SUSPEND_MCUSYS BIT(8)
  26. #define MTK_CPUPM_FN_RESUME_MCUSYS BIT(9)
  27. #define MTK_CPUPM_FN_CPUPM_GET_PWR_STATE BIT(10)
  28. #define MTK_CPUPM_FN_SMP_INIT BIT(11)
  29. #define MTK_CPUPM_FN_SMP_CORE_ON BIT(12)
  30. #define MTK_CPUPM_FN_SMP_CORE_OFF BIT(13)
  31. enum mtk_cpupm_pstate {
  32. MTK_CPUPM_CORE_ON,
  33. MTK_CPUPM_CORE_OFF,
  34. MTK_CPUPM_CORE_SUSPEND,
  35. MTK_CPUPM_CORE_RESUME,
  36. MTK_CPUPM_CLUSTER_SUSPEND,
  37. MTK_CPUPM_CLUSTER_RESUME,
  38. MTK_CPUPM_MCUSYS_SUSPEND,
  39. MTK_CPUPM_MCUSYS_RESUME,
  40. };
  41. enum mtk_cpu_pm_mode {
  42. MTK_CPU_PM_CPUIDLE,
  43. MTK_CPU_PM_SMP,
  44. };
  45. #define MT_IRQ_REMAIN_MAX (32)
  46. #define MT_IRQ_REMAIN_CAT_LOG BIT(31)
  47. struct mt_irqremain {
  48. unsigned int count;
  49. unsigned int irqs[MT_IRQ_REMAIN_MAX];
  50. unsigned int wakeupsrc_cat[MT_IRQ_REMAIN_MAX];
  51. unsigned int wakeupsrc[MT_IRQ_REMAIN_MAX];
  52. };
  53. typedef void (*plat_init_func)(unsigned int, uintptr_t);
  54. struct plat_pm_smp_ctrl {
  55. plat_init_func init;
  56. int (*pwr_domain_on)(u_register_t mpidr);
  57. void (*pwr_domain_off)(const psci_power_state_t *target_state);
  58. void (*pwr_domain_on_finish)(const psci_power_state_t *target_state);
  59. };
  60. struct plat_pm_pwr_ctrl {
  61. void (*pwr_domain_suspend)(const psci_power_state_t *target_state);
  62. void (*pwr_domain_on_finish_late)(const psci_power_state_t *target_state);
  63. void (*pwr_domain_suspend_finish)(const psci_power_state_t *target_state);
  64. int (*validate_power_state)(unsigned int power_state, psci_power_state_t *req_state);
  65. void (*get_sys_suspend_power_state)(psci_power_state_t *req_state);
  66. };
  67. struct plat_pm_reset_ctrl {
  68. __dead2 void (*system_off)();
  69. __dead2 void (*system_reset)();
  70. int (*system_reset2)(int is_vendor, int reset_type, u_register_t cookie);
  71. };
  72. struct mtk_cpu_pm_info {
  73. unsigned int cpuid;
  74. unsigned int mode;
  75. };
  76. struct mtk_cpu_pm_state {
  77. unsigned int afflv;
  78. unsigned int state_id;
  79. const psci_power_state_t *raw;
  80. };
  81. struct mtk_cpupm_pwrstate {
  82. struct mtk_cpu_pm_info info;
  83. struct mtk_cpu_pm_state pwr;
  84. };
  85. struct mtk_cpu_smp_ops {
  86. void (*init)(unsigned int cpu, uintptr_t sec_entrypoint);
  87. int (*cpu_pwr_on_prepare)(unsigned int cpu, uintptr_t entry);
  88. void (*cpu_on)(const struct mtk_cpupm_pwrstate *state);
  89. void (*cpu_off)(const struct mtk_cpupm_pwrstate *state);
  90. int (*invoke)(unsigned int funcID, void *priv);
  91. };
  92. #define MT_CPUPM_PWR_DOMAIN_CORE BIT(0)
  93. #define MT_CPUPM_PWR_DOMAIN_PERCORE_DSU BIT(1)
  94. #define MT_CPUPM_PWR_DOMAIN_PERCORE_DSU_MEM BIT(2)
  95. #define MT_CPUPM_PWR_DOMAIN_CLUSTER BIT(3)
  96. #define MT_CPUPM_PWR_DOMAIN_MCUSYS BIT(4)
  97. #define MT_CPUPM_PWR_DOMAIN_SUSPEND BIT(5)
  98. enum mt_cpupm_pwr_domain {
  99. CPUPM_PWR_ON,
  100. CPUPM_PWR_OFF,
  101. };
  102. typedef unsigned int mtk_pstate_type;
  103. struct mtk_cpu_pm_ops {
  104. void (*init)(unsigned int cpu, uintptr_t sec_entrypoint);
  105. unsigned int (*get_pstate)(enum mt_cpupm_pwr_domain domain,
  106. const mtk_pstate_type psci_state,
  107. const struct mtk_cpupm_pwrstate *state);
  108. int (*pwr_state_valid)(unsigned int afflv, unsigned int state);
  109. void (*cpu_suspend)(const struct mtk_cpupm_pwrstate *state);
  110. void (*cpu_resume)(const struct mtk_cpupm_pwrstate *state);
  111. void (*cluster_suspend)(const struct mtk_cpupm_pwrstate *state);
  112. void (*cluster_resume)(const struct mtk_cpupm_pwrstate *state);
  113. void (*mcusys_suspend)(const struct mtk_cpupm_pwrstate *state);
  114. void (*mcusys_resume)(const struct mtk_cpupm_pwrstate *state);
  115. int (*invoke)(unsigned int funcID, void *priv);
  116. };
  117. int register_cpu_pm_ops(unsigned int fn_flags, struct mtk_cpu_pm_ops *ops);
  118. int register_cpu_smp_ops(unsigned int fn_flags, struct mtk_cpu_smp_ops *ops);
  119. struct mt_cpupm_event_data {
  120. unsigned int cpuid;
  121. unsigned int pwr_domain;
  122. };
  123. /* Extension event for platform driver */
  124. #if MTK_PUBEVENT_ENABLE
  125. /* [PUB_EVENT] Core power on */
  126. #define MT_CPUPM_SUBCRIBE_EVENT_PWR_ON(_fn) \
  127. SUBSCRIBE_TO_EVENT(mt_cpupm_publish_pwr_on, _fn)
  128. /* [PUB_EVENT] Core power off */
  129. #define MT_CPUPM_SUBCRIBE_EVENT_PWR_OFF(_fn) \
  130. SUBSCRIBE_TO_EVENT(mt_cpupm_publish_pwr_off, _fn)
  131. /* [PUB_EVENT] Cluster power on */
  132. #define MT_CPUPM_SUBCRIBE_CLUSTER_PWR_ON(_fn) \
  133. SUBSCRIBE_TO_EVENT(mt_cpupm_publish_afflv_pwr_on, _fn)
  134. /* [PUB_EVENT] Cluster power off */
  135. #define MT_CPUPM_SUBCRIBE_CLUSTER_PWR_OFF(_fn) \
  136. SUBSCRIBE_TO_EVENT(mt_cpupm_publish_afflv_pwr_off, _fn)
  137. /* [PUB_EVENT] Mcusys power on */
  138. #define MT_CPUPM_SUBCRIBE_MCUSYS_PWR_ON(_fn) \
  139. SUBSCRIBE_TO_EVENT(mt_cpupm_publish_afflv_pwr_on, _fn)
  140. /* [PUB_EVENT] Mcusys power off */
  141. #define MT_CPUPM_SUBCRIBE_MCUSYS_PWR_OFF(_fn) \
  142. SUBSCRIBE_TO_EVENT(mt_cpupm_publish_afflv_pwr_off, _fn)
  143. #else
  144. #define MT_CPUPM_SUBCRIBE_EVENT_PWR_ON(_fn)
  145. #define MT_CPUPM_SUBCRIBE_EVENT_PWR_OFF(_fn)
  146. #define MT_CPUPM_SUBCRIBE_CLUSTER_PWR_ON(_fn)
  147. #define MT_CPUPM_SUBCRIBE_CLUSTER_PWR_OFF(_fn)
  148. #define MT_CPUPM_SUBCRIBE_MCUSYS_PWR_ON(_fn)
  149. #define MT_CPUPM_SUBCRIBE_MCUSYS_PWR_OFF(_fn)
  150. #endif
  151. /*
  152. * Definition c-state power domain.
  153. * bit[7:4] (main state id):
  154. * - 1: Cluster.
  155. * - 2: Mcusys.
  156. * - 3: Memory.
  157. * - 4: System pll.
  158. * - 5: System bus.
  159. * - 6: SoC 26m/DCXO.
  160. * - 7: Vcore buck.
  161. * - 15: Suspend.
  162. * bit[3:0] (reserved for state_id extension):
  163. * - 4: CPU buck.
  164. */
  165. #define MT_PLAT_PWR_STATE_CLUSTER (0x0010)
  166. #define MT_PLAT_PWR_STATE_MCUSYS (0x0020)
  167. #define MT_PLAT_PWR_STATE_MCUSYS_BUCK (0x0024)
  168. #define MT_PLAT_PWR_STATE_SYSTEM_MEM (0x0030)
  169. #define MT_PLAT_PWR_STATE_SYSTEM_PLL (0x0040)
  170. #define MT_PLAT_PWR_STATE_SYSTEM_BUS (0x0050)
  171. #define MT_PLAT_PWR_STATE_SUSPEND (0x00f0)
  172. #define IS_MT_PLAT_PWR_STATE(state, target_state) ((state & target_state) == target_state)
  173. #define IS_MT_PLAT_PWR_STATE_MCUSYS(state) IS_MT_PLAT_PWR_STATE(state, MT_PLAT_PWR_STATE_MCUSYS)
  174. #define PLAT_MT_SYSTEM_SUSPEND PLAT_MAX_OFF_STATE
  175. #define PLAT_MT_CPU_SUSPEND_CLUSTER PLAT_MAX_RET_STATE
  176. #define PLAT_MT_CPU_SUSPEND_MCUSYS PLAT_MAX_RET_STATE
  177. #define IS_PLAT_SYSTEM_SUSPEND(aff) (aff == PLAT_MT_SYSTEM_SUSPEND)
  178. #define IS_PLAT_SYSTEM_RETENTION(aff) (aff >= PLAT_MAX_RET_STATE)
  179. #define IS_PLAT_SUSPEND_ID(stateid) (stateid == MT_PLAT_PWR_STATE_SUSPEND)
  180. #define IS_PLAT_MCUSYSOFF_AFFLV(afflv) (afflv >= PLAT_MT_CPU_SUSPEND_MCUSYS)
  181. int plat_pm_ops_setup_pwr(struct plat_pm_pwr_ctrl *ops);
  182. int plat_pm_ops_setup_reset(struct plat_pm_reset_ctrl *ops);
  183. int plat_pm_ops_setup_smp(struct plat_pm_smp_ctrl *ops);
  184. uintptr_t plat_pm_get_warm_entry(void);
  185. #endif