mt_cpu_pm_cpc.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2021, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef MT_CPU_PM_CPC_H
  7. #define MT_CPU_PM_CPC_H
  8. #include <lib/mmio.h>
  9. #include <lib/utils_def.h>
  10. #include <mcucfg.h>
  11. #include <platform_def.h>
  12. #define NEED_CPUSYS_PROT_WORKAROUND 1
  13. /* system sram registers */
  14. #define CPUIDLE_SRAM_REG(r) (0x11B000 + (r))
  15. /* db dump */
  16. #define CPC_TRACE_SIZE U(0x20)
  17. #define CPC_TRACE_ID_NUM U(10)
  18. #define CPC_TRACE_SRAM(id) (CPUIDLE_SRAM_REG(0x10) + (id) * CPC_TRACE_SIZE)
  19. /* buckup off count */
  20. #define CPC_CLUSTER_CNT_BACKUP CPUIDLE_SRAM_REG(0x1F0)
  21. #define CPC_MCUSYS_CNT CPUIDLE_SRAM_REG(0x1F4)
  22. /* CPC_MCUSYS_CPC_FLOW_CTRL_CFG(0xA814): debug setting */
  23. #define CPC_PWR_ON_SEQ_DIS BIT(1)
  24. #define CPC_PWR_ON_PRIORITY BIT(2)
  25. #define CPC_AUTO_OFF_EN BIT(5)
  26. #define CPC_DORMANT_WAIT_EN BIT(14)
  27. #define CPC_CTRL_EN BIT(16)
  28. #define CPC_OFF_PRE_EN BIT(29)
  29. /* CPC_MCUSYS_LAST_CORE_REQ(0xA818) : last core protection */
  30. #define CPUSYS_PROT_SET BIT(0)
  31. #define MCUSYS_PROT_SET BIT(8)
  32. #define CPUSYS_PROT_CLR BIT(8)
  33. #define MCUSYS_PROT_CLR BIT(9)
  34. #define CPC_PROT_RESP_MASK U(0x3)
  35. #define CPUSYS_RESP_OFS U(16)
  36. #define MCUSYS_RESP_OFS U(30)
  37. #define cpusys_resp(r) (((r) >> CPUSYS_RESP_OFS) & CPC_PROT_RESP_MASK)
  38. #define mcusys_resp(r) (((r) >> MCUSYS_RESP_OFS) & CPC_PROT_RESP_MASK)
  39. #define RETRY_CNT_MAX U(1000)
  40. #define PROT_RETRY U(0)
  41. #define PROT_SUCCESS U(1)
  42. #define PROT_GIVEUP U(2)
  43. /* CPC_MCUSYS_CPC_DBG_SETTING(0xAB00): debug setting */
  44. #define CPC_PROF_EN BIT(0)
  45. #define CPC_DBG_EN BIT(1)
  46. #define CPC_FREEZE BIT(2)
  47. #define CPC_CALC_EN BIT(3)
  48. enum {
  49. CPC_SUCCESS = 0U,
  50. CPC_ERR_FAIL = 1U,
  51. CPC_ERR_TIMEOUT = 2U,
  52. NF_CPC_ERR = 3U,
  53. };
  54. enum {
  55. CPC_SMC_EVENT_DUMP_TRACE_DATA = 0U,
  56. CPC_SMC_EVENT_GIC_DPG_SET = 1U,
  57. CPC_SMC_EVENT_CPC_CONFIG = 2U,
  58. CPC_SMC_EVENT_READ_CONFIG = 3U,
  59. NF_CPC_SMC_EVENT = 4U,
  60. };
  61. enum {
  62. CPC_SMC_CONFIG_PROF = 0U,
  63. CPC_SMC_CONFIG_AUTO_OFF = 1U,
  64. CPC_SMC_CONFIG_AUTO_OFF_THRES = 2U,
  65. CPC_SMC_CONFIG_CNT_CLR = 3U,
  66. CPC_SMC_CONFIG_TIME_SYNC = 4U,
  67. NF_CPC_SMC_CONFIG = 5U,
  68. };
  69. #define us_to_ticks(us) ((us) * 13)
  70. #define ticks_to_us(tick) ((tick) / 13)
  71. int mtk_cpu_pm_cluster_prot_aquire(unsigned int cluster);
  72. void mtk_cpu_pm_cluster_prot_release(unsigned int cluster);
  73. void mtk_cpc_mcusys_off_reflect(void);
  74. int mtk_cpc_mcusys_off_prepare(void);
  75. void mtk_cpc_core_on_hint_set(unsigned int cpu);
  76. void mtk_cpc_core_on_hint_clr(unsigned int cpu);
  77. void mtk_cpc_time_sync(void);
  78. uint64_t mtk_cpc_handler(uint64_t act, uint64_t arg1, uint64_t arg2);
  79. void mtk_cpc_init(void);
  80. #endif /* MT_CPU_PM_CPC_H */