soc.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <platform_def.h>
  7. #include <arch_helpers.h>
  8. #include <common/debug.h>
  9. #include <drivers/console.h>
  10. #include <drivers/delay_timer.h>
  11. #include <lib/mmio.h>
  12. #include <platform_def.h>
  13. #include <pmu.h>
  14. #include <px30_def.h>
  15. #include <secure.h>
  16. #include <soc.h>
  17. #include <rockchip_sip_svc.h>
  18. /* Aggregate of all devices in the first GB */
  19. #define PX30_DEV_RNG0_BASE 0xff000000
  20. #define PX30_DEV_RNG0_SIZE 0x00ff0000
  21. const mmap_region_t plat_rk_mmap[] = {
  22. MAP_REGION_FLAT(PX30_DEV_RNG0_BASE, PX30_DEV_RNG0_SIZE,
  23. MT_DEVICE | MT_RW | MT_SECURE),
  24. MAP_REGION_FLAT(SHARE_MEM_BASE, SHARE_MEM_SIZE,
  25. MT_DEVICE | MT_RW | MT_SECURE),
  26. MAP_REGION_FLAT(DDR_PARAM_BASE, DDR_PARAM_SIZE,
  27. MT_DEVICE | MT_RW | MT_SECURE),
  28. { 0 }
  29. };
  30. /* The RockChip power domain tree descriptor */
  31. const unsigned char rockchip_power_domain_tree_desc[] = {
  32. /* No of root nodes */
  33. PLATFORM_SYSTEM_COUNT,
  34. /* No of children for the root node */
  35. PLATFORM_CLUSTER_COUNT,
  36. /* No of children for the first cluster node */
  37. PLATFORM_CLUSTER0_CORE_COUNT,
  38. };
  39. void clk_gate_con_save(uint32_t *clkgt_save)
  40. {
  41. uint32_t i, j;
  42. for (i = 0; i < CRU_CLKGATES_CON_CNT; i++)
  43. clkgt_save[i] =
  44. mmio_read_32(CRU_BASE + CRU_CLKGATES_CON(i));
  45. j = i;
  46. for (i = 0; i < CRU_PMU_CLKGATE_CON_CNT; i++, j++)
  47. clkgt_save[j] =
  48. mmio_read_32(PMUCRU_BASE + CRU_PMU_CLKGATES_CON(i));
  49. }
  50. void clk_gate_con_restore(uint32_t *clkgt_save)
  51. {
  52. uint32_t i, j;
  53. for (i = 0; i < CRU_CLKGATES_CON_CNT; i++)
  54. mmio_write_32(CRU_BASE + CRU_CLKGATES_CON(i),
  55. WITH_16BITS_WMSK(clkgt_save[i]));
  56. j = i;
  57. for (i = 0; i < CRU_PMU_CLKGATE_CON_CNT; i++, j++)
  58. mmio_write_32(PMUCRU_BASE + CRU_PMU_CLKGATES_CON(i),
  59. WITH_16BITS_WMSK(clkgt_save[j]));
  60. }
  61. void clk_gate_con_disable(void)
  62. {
  63. uint32_t i;
  64. for (i = 0; i < CRU_CLKGATES_CON_CNT; i++)
  65. mmio_write_32(CRU_BASE + CRU_CLKGATES_CON(i),
  66. 0xffff0000);
  67. for (i = 0; i < CRU_PMU_CLKGATE_CON_CNT; i++)
  68. mmio_write_32(PMUCRU_BASE + CRU_PMU_CLKGATES_CON(i),
  69. 0xffff0000);
  70. }
  71. static void soc_reset_config_all(void)
  72. {
  73. uint32_t tmp;
  74. /* tsadc and wdt can trigger a first rst */
  75. tmp = mmio_read_32(CRU_BASE + CRU_GLB_RST_CON);
  76. tmp |= CRU_GLB_RST_TSADC_FST | CRU_GLB_RST_WDT_FST;
  77. mmio_write_32(CRU_BASE + CRU_GLB_RST_CON, tmp);
  78. return;
  79. tmp = mmio_read_32(PMUGRF_BASE + PMUGRF_SOC_CON(3));
  80. tmp &= ~(PMUGRF_FAILSAFE_SHTDN_TSADC | PMUGRF_FAILSAFE_SHTDN_WDT);
  81. mmio_write_32(PMUGRF_BASE + PMUGRF_SOC_CON(3), tmp);
  82. /* wdt pin rst eable */
  83. mmio_write_32(GRF_BASE + GRF_SOC_CON(2),
  84. BIT_WITH_WMSK(GRF_SOC_CON2_NSWDT_RST_EN));
  85. }
  86. void px30_soc_reset_config(void)
  87. {
  88. uint32_t tmp;
  89. /* enable soc ip rst hold time cfg */
  90. tmp = mmio_read_32(CRU_BASE + CRU_GLB_RST_CON);
  91. tmp |= BIT(CRU_GLB_RST_TSADC_EXT) | BIT(CRU_GLB_RST_WDT_EXT);
  92. mmio_write_32(CRU_BASE + CRU_GLB_RST_CON, tmp);
  93. /* soc ip rst hold time, 24m */
  94. tmp = mmio_read_32(CRU_BASE + CRU_GLB_CNT_TH);
  95. tmp &= ~CRU_GLB_CNT_RST_MSK;
  96. tmp |= (CRU_GLB_CNT_RST_1MS / 2);
  97. mmio_write_32(CRU_BASE + CRU_GLB_CNT_TH, tmp);
  98. mmio_write_32(PMUSGRF_BASE + PMUSGRF_SOC_CON(0),
  99. BIT_WITH_WMSK(PMUSGRF_RSTOUT_FST) |
  100. BIT_WITH_WMSK(PMUSGRF_RSTOUT_TSADC) |
  101. BIT_WITH_WMSK(PMUSGRF_RSTOUT_WDT));
  102. /* rst_out pulse time */
  103. mmio_write_32(PMUGRF_BASE + PMUGRF_SOC_CON(2),
  104. PMUGRF_SOC_CON2_MAX_341US | PMUGRF_SOC_CON2_US_WMSK);
  105. soc_reset_config_all();
  106. }
  107. void plat_rockchip_soc_init(void)
  108. {
  109. secure_timer_init();
  110. sgrf_init();
  111. }