mtk_mfgsys.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #include <platform/spm.h>
  2. #include <debug.h>
  3. #include "spm.h"
  4. #include <mtk_wdt.h>
  5. #ifdef MTK_GPU_DFD_SUPPORT
  6. /* GPU DFD */
  7. #define MFG_MISC_CON 0x10001600
  8. #define MFG_DFD_TRIGGER (1<<19)
  9. #define MFG_DFD_COMPLETE (1<<18)
  10. #define MFG_DFD_CON_0 0x13FBFA00
  11. #define MFG1_PORT_STEP2_0_MASK (0x3 << 21)
  12. #define MFG1_PORT_STEP1_0_MASK (0x7 << 19)
  13. #define DRM_MFG_REG 0x1000D060
  14. void show_gpu_dfd_debug_msg(void)
  15. {
  16. unsigned int status = spm_read(MFG_MISC_CON);
  17. unsigned int pwr = spm_read(DRM_MFG_REG);
  18. dprintf(CRITICAL, "%s: GPU DFD MFG_MISC_CON:0x%x, DRM_MFG_REG:0x%x\n",
  19. __func__, status, pwr);
  20. dprintf(CRITICAL, "%s: PWR_STATUS[0x1000616c]:0x%x, MFG0_PWR_CON[0x10006308]:0x%x\n",
  21. __func__, spm_read(0x1000616c), spm_read(0x10006308));
  22. }
  23. unsigned int mfg_set_power_off(void);
  24. unsigned int mfg_set_power_on(void)
  25. {
  26. unsigned int status = spm_read(MFG_MISC_CON);
  27. show_gpu_dfd_debug_msg();
  28. /* Read register MFG_MISC_CON (@ 0x1000_1600) bit [19:18] = 0x3 */
  29. if ((status & MFG_DFD_TRIGGER) == 0) {
  30. dprintf(CRITICAL, "%s: GPU DFD was not triggered (0x%x)\n", __func__, status);
  31. return 0;
  32. }
  33. if ((status & MFG_DFD_COMPLETE) == 0) {
  34. dprintf(CRITICAL, "%s: GPU DFD was not triggered completely(0x%x)\n", __func__, status);
  35. mfg_set_power_off();
  36. return 0;
  37. }
  38. // power on GPU
  39. dprintf(CRITICAL, "%s: GPU DFD Begin GPU0 MTCMOS\n", __func__);
  40. spm_mtcmos_ctrl_mfg0(STA_POWER_ON);
  41. dprintf(CRITICAL, "%s: GPU DFD end GPU0 MTCMOS\n", __func__);
  42. dprintf(CRITICAL, "%s: GPU DFD Begin GPU1 MTCMOS\n", __func__);
  43. spm_mtcmos_ctrl_mfg1(STA_POWER_ON);
  44. dprintf(CRITICAL, "%s: GPU DFD end GPU1 MTCMOS\n", __func__);
  45. {
  46. unsigned int dfd = spm_read(MFG_DFD_CON_0);
  47. dprintf(CRITICAL, "%s: GPU DFD MFG_DFD_CON_0:0x%x\n",
  48. __func__, dfd);
  49. }
  50. /* 2. Write register MFG_DFD_CON_0 (@ 0x13FB_FA00) = 0x0f000011 */
  51. spm_write(MFG_DFD_CON_0, 0x0F000011);
  52. return 1;
  53. }
  54. unsigned int mfg_set_power_off(void)
  55. {
  56. /* 0. gpu hard reset */
  57. /*
  58. * // [2] = mfg_rst, reset mfg
  59. * Write register WDT_SWSYSRST (@ 0x1000_7018) = 0x88000004;
  60. * Wait 10us;
  61. * // [2] = mfg_rst, release reset
  62. * Write register WDT_SWSYSRST (@ 0x1000_7018) = 0x88000000;
  63. */
  64. dprintf(CRITICAL, "%s: gpu hard reset\n", __func__);
  65. mtk_wdt_swsysret_config(MTK_WDT_SWSYS_RST_GPU_RST, 1);
  66. udelay(10);
  67. mtk_wdt_swsysret_config(MTK_WDT_SWSYS_RST_GPU_RST, 0);
  68. /* 1. do fake power on */
  69. dprintf(CRITICAL, "%s: do fake power on\n", __func__);
  70. spm_mtcmos_ctrl_mfg0(STA_POWER_ON);
  71. spm_mtcmos_ctrl_mfg1(STA_POWER_ON);
  72. /* 2. disable gpu dfd */
  73. dprintf(CRITICAL, "%s: disable MFG_DFD_CON_0\n", __func__);
  74. spm_write(MFG_DFD_CON_0, 0x0);
  75. /* 3. clear wdt_mfg_pwr_on */
  76. dprintf(CRITICAL, "%s: DRM_MFG_REG, wdt_mfg_por_on = 0 \n", __func__);
  77. spm_write(DRM_MFG_REG, 0x77 << 24);
  78. /* 4. fake power off */
  79. dprintf(CRITICAL, "%s: GPU DFD Begin GPU1 MTCMOS off\n", __func__);
  80. spm_mtcmos_ctrl_mfg1(STA_POWER_DOWN);
  81. dprintf(CRITICAL, "%s: GPU DFD End GPU1 MTCMOS off\n", __func__);
  82. dprintf(CRITICAL, "%s: GPU DFD Begin GPU0 MTCMOS off\n", __func__);
  83. spm_mtcmos_ctrl_mfg0(STA_POWER_DOWN);
  84. dprintf(CRITICAL, "%s: GPU DFD End GPU0 MTCMOS off\n", __func__);
  85. return 1;
  86. }
  87. void mfg_clear_dfd(void)
  88. {
  89. unsigned int status = spm_read(MFG_MISC_CON);
  90. /* Read register MFG_MISC_CON (@ 0x1000_1600) bit [19:18] = 0x3 */
  91. if ((status & MFG_DFD_TRIGGER) == 0) {
  92. dprintf(CRITICAL, "%s: GPU DFD was not triggered (0x%x)\n", __func__, status);
  93. return;
  94. }
  95. dprintf(CRITICAL, "%s: GPU DFD was triggered, clear it.\n", __func__);
  96. mfg_set_power_off();
  97. }
  98. #else
  99. unsigned int mfg_set_power_on(void)
  100. {
  101. return 0;
  102. }
  103. unsigned int mfg_set_power_off(void)
  104. {
  105. return 0;
  106. }
  107. unsigned int mfg_clear_dfd(void)
  108. {
  109. return 0;
  110. }
  111. #endif // MTK_GPU_DFD_SUPPORT