plat_dfd.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2022, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch_helpers.h>
  7. #include <common/debug.h>
  8. #include <lib/mmio.h>
  9. #include <dfd.h>
  10. #include <plat_dfd.h>
  11. static uint64_t dfd_cache_dump;
  12. static bool dfd_enabled;
  13. static uint64_t dfd_base_addr;
  14. static uint64_t dfd_chain_length;
  15. void dfd_setup(uint64_t base_addr, uint64_t chain_length, uint64_t cache_dump)
  16. {
  17. mmio_write_32(MTK_DRM_LATCH_CTL1, MTK_DRM_LATCH_CTL1_VAL);
  18. mmio_write_32(MTK_DRM_LATCH_CTL2, MTK_DRM_LATCH_CTL2_VAL);
  19. mmio_write_32(MTK_WDT_LATCH_CTL2, MTK_WDT_LATCH_CTL2_VAL);
  20. mmio_clrbits_32(DFD_O_INTRF_MCU_PWR_CTL_MASK, BIT(2));
  21. mmio_setbits_32(DFD_V50_GROUP_0_63_DIFF, 0x1);
  22. sync_writel(DFD_INTERNAL_CTL, 0x5);
  23. mmio_setbits_32(DFD_INTERNAL_CTL, BIT(13));
  24. mmio_setbits_32(DFD_INTERNAL_CTL, 0x1F << 3);
  25. mmio_setbits_32(DFD_INTERNAL_CTL, 0x3 << 9);
  26. mmio_setbits_32(DFD_INTERNAL_CTL, 0x3 << 19);
  27. mmio_write_32(DFD_INTERNAL_PWR_ON, 0xB);
  28. mmio_write_32(DFD_CHAIN_LENGTH0, chain_length);
  29. mmio_write_32(DFD_INTERNAL_SHIFT_CLK_RATIO, 0x0);
  30. mmio_write_32(DFD_INTERNAL_TEST_SO_OVER_64, 0x1);
  31. mmio_write_32(DFD_TEST_SI_0, 0x0);
  32. mmio_write_32(DFD_TEST_SI_1, 0x0);
  33. mmio_write_32(DFD_TEST_SI_2, 0x0);
  34. mmio_write_32(DFD_TEST_SI_3, 0x0);
  35. sync_writel(DFD_POWER_CTL, 0xF9);
  36. sync_writel(DFD_READ_ADDR, DFD_READ_ADDR_VAL);
  37. sync_writel(DFD_V30_CTL, 0xD);
  38. mmio_write_32(DFD_O_SET_BASEADDR_REG, base_addr >> 24);
  39. mmio_write_32(DFD_O_REG_0, 0);
  40. /* setup global variables for suspend and resume */
  41. dfd_enabled = true;
  42. dfd_base_addr = base_addr;
  43. dfd_chain_length = chain_length;
  44. dfd_cache_dump = cache_dump;
  45. if ((cache_dump & DFD_CACHE_DUMP_ENABLE) != 0UL) {
  46. mmio_write_32(MTK_DRM_LATCH_CTL2, MTK_DRM_LATCH_CTL2_CACHE_VAL);
  47. sync_writel(DFD_V35_ENABLE, 0x1);
  48. sync_writel(DFD_V35_TAP_NUMBER, 0xB);
  49. sync_writel(DFD_V35_TAP_EN, DFD_V35_TAP_EN_VAL);
  50. sync_writel(DFD_V35_SEQ0_0, DFD_V35_SEQ0_0_VAL);
  51. /* Cache dump only mode */
  52. sync_writel(DFD_V35_CTL, 0x1);
  53. mmio_write_32(DFD_INTERNAL_NUM_OF_TEST_SO_GROUP, 0xF);
  54. mmio_write_32(DFD_CHAIN_LENGTH0, DFD_CHAIN_LENGTH_VAL);
  55. mmio_write_32(DFD_CHAIN_LENGTH1, DFD_CHAIN_LENGTH_VAL);
  56. mmio_write_32(DFD_CHAIN_LENGTH2, DFD_CHAIN_LENGTH_VAL);
  57. mmio_write_32(DFD_CHAIN_LENGTH3, DFD_CHAIN_LENGTH_VAL);
  58. if ((cache_dump & DFD_PARITY_ERR_TRIGGER) != 0UL) {
  59. sync_writel(DFD_HW_TRIGGER_MASK, 0xC);
  60. mmio_setbits_32(DFD_INTERNAL_CTL, 0x1 << 4);
  61. }
  62. }
  63. dsbsy();
  64. }
  65. void dfd_resume(void)
  66. {
  67. if (dfd_enabled == true) {
  68. dfd_setup(dfd_base_addr, dfd_chain_length, dfd_cache_dump);
  69. }
  70. }