mtk_dcm.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Copyright (c) 2022, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/debug.h>
  7. #include <lib/mmio.h>
  8. #include <lib/mtk_init/mtk_init.h>
  9. #include <mtk_dcm.h>
  10. #include <mtk_dcm_utils.h>
  11. static void dcm_armcore(bool mode)
  12. {
  13. dcm_mp_cpusys_top_bus_pll_div_dcm(mode);
  14. dcm_mp_cpusys_top_cpu_pll_div_0_dcm(mode);
  15. dcm_mp_cpusys_top_cpu_pll_div_1_dcm(mode);
  16. }
  17. static void dcm_mcusys(bool on)
  18. {
  19. dcm_mp_cpusys_top_adb_dcm(on);
  20. dcm_mp_cpusys_top_apb_dcm(on);
  21. dcm_mp_cpusys_top_cpubiu_dcm(on);
  22. dcm_mp_cpusys_top_misc_dcm(on);
  23. dcm_mp_cpusys_top_mp0_qdcm(on);
  24. /* CPCCFG_REG */
  25. dcm_cpccfg_reg_emi_wfifo(on);
  26. dcm_mp_cpusys_top_last_cor_idle_dcm(on);
  27. }
  28. static void dcm_stall(bool on)
  29. {
  30. dcm_mp_cpusys_top_core_stall_dcm(on);
  31. dcm_mp_cpusys_top_fcm_stall_dcm(on);
  32. }
  33. static bool check_dcm_state(void)
  34. {
  35. bool ret = true;
  36. ret &= dcm_mp_cpusys_top_bus_pll_div_dcm_is_on();
  37. ret &= dcm_mp_cpusys_top_cpu_pll_div_0_dcm_is_on();
  38. ret &= dcm_mp_cpusys_top_cpu_pll_div_1_dcm_is_on();
  39. ret &= dcm_mp_cpusys_top_adb_dcm_is_on();
  40. ret &= dcm_mp_cpusys_top_apb_dcm_is_on();
  41. ret &= dcm_mp_cpusys_top_cpubiu_dcm_is_on();
  42. ret &= dcm_mp_cpusys_top_misc_dcm_is_on();
  43. ret &= dcm_mp_cpusys_top_mp0_qdcm_is_on();
  44. ret &= dcm_cpccfg_reg_emi_wfifo_is_on();
  45. ret &= dcm_mp_cpusys_top_last_cor_idle_dcm_is_on();
  46. ret &= dcm_mp_cpusys_top_core_stall_dcm_is_on();
  47. ret &= dcm_mp_cpusys_top_fcm_stall_dcm_is_on();
  48. return ret;
  49. }
  50. bool dcm_check_state(uintptr_t addr, unsigned int mask, unsigned int compare)
  51. {
  52. return ((mmio_read_32(addr) & mask) == compare);
  53. }
  54. int dcm_set_init(void)
  55. {
  56. int ret;
  57. dcm_armcore(true);
  58. dcm_mcusys(true);
  59. dcm_stall(true);
  60. if (check_dcm_state() == false) {
  61. ERROR("Failed to set default dcm on!!\n");
  62. ret = -1;
  63. } else {
  64. INFO("%s, dcm pass\n", __func__);
  65. ret = 0;
  66. }
  67. return ret;
  68. }
  69. MTK_PLAT_SETUP_0_INIT(dcm_set_init);