dcfg.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright 2020-2022 NXP
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #include <common/debug.h>
  8. #include "dcfg.h"
  9. #include <lib/mmio.h>
  10. #ifdef NXP_SFP_ENABLED
  11. #include <sfp.h>
  12. #endif
  13. static soc_info_t soc_info = {0};
  14. static devdisr5_info_t devdisr5_info = {0};
  15. static dcfg_init_info_t *dcfg_init_info;
  16. /* Read the PORSR1 register */
  17. uint32_t read_reg_porsr1(void)
  18. {
  19. unsigned int *porsr1_addr = NULL;
  20. if (dcfg_init_info->porsr1 != 0U) {
  21. return dcfg_init_info->porsr1;
  22. }
  23. porsr1_addr = (void *)
  24. (dcfg_init_info->g_nxp_dcfg_addr + DCFG_PORSR1_OFFSET);
  25. dcfg_init_info->porsr1 = gur_in32(porsr1_addr);
  26. return dcfg_init_info->porsr1;
  27. }
  28. const soc_info_t *get_soc_info(void)
  29. {
  30. uint32_t reg;
  31. if (soc_info.is_populated == true) {
  32. return (const soc_info_t *) &soc_info;
  33. }
  34. reg = gur_in32(dcfg_init_info->g_nxp_dcfg_addr + DCFG_SVR_OFFSET);
  35. soc_info.svr_reg.val = reg;
  36. /* zero means SEC enabled. */
  37. soc_info.sec_enabled =
  38. (((reg & SVR_SEC_MASK) >> SVR_SEC_SHIFT) == 0) ? true : false;
  39. soc_info.is_populated = true;
  40. return (const soc_info_t *) &soc_info;
  41. }
  42. void dcfg_init(dcfg_init_info_t *dcfg_init_data)
  43. {
  44. dcfg_init_info = dcfg_init_data;
  45. read_reg_porsr1();
  46. get_soc_info();
  47. }
  48. bool is_sec_enabled(void)
  49. {
  50. return soc_info.sec_enabled;
  51. }
  52. const devdisr5_info_t *get_devdisr5_info(void)
  53. {
  54. uint32_t reg;
  55. if (devdisr5_info.is_populated == true)
  56. return (const devdisr5_info_t *) &devdisr5_info;
  57. reg = gur_in32(dcfg_init_info->g_nxp_dcfg_addr + DCFG_DEVDISR5_OFFSET);
  58. devdisr5_info.ddrc1_present = (reg & DISR5_DDRC1_MASK) ? 0 : 1;
  59. #if defined(CONFIG_CHASSIS_3_2)
  60. devdisr5_info.ddrc2_present = (reg & DISR5_DDRC2_MASK) ? 0 : 1;
  61. #endif
  62. devdisr5_info.ocram_present = (reg & DISR5_OCRAM_MASK) ? 0 : 1;
  63. devdisr5_info.is_populated = true;
  64. return (const devdisr5_info_t *) &devdisr5_info;
  65. }
  66. int get_clocks(struct sysinfo *sys)
  67. {
  68. unsigned int *rcwsr0 = NULL;
  69. const unsigned long sysclk = dcfg_init_info->nxp_sysclk_freq;
  70. const unsigned long ddrclk = dcfg_init_info->nxp_ddrclk_freq;
  71. rcwsr0 = (void *)(dcfg_init_info->g_nxp_dcfg_addr + RCWSR0_OFFSET);
  72. sys->freq_platform = sysclk;
  73. sys->freq_ddr_pll0 = ddrclk;
  74. sys->freq_ddr_pll1 = ddrclk;
  75. sys->freq_platform *= (gur_in32(rcwsr0) >>
  76. RCWSR0_SYS_PLL_RAT_SHIFT) &
  77. RCWSR0_SYS_PLL_RAT_MASK;
  78. sys->freq_platform /= dcfg_init_info->nxp_plat_clk_divider;
  79. sys->freq_ddr_pll0 *= (gur_in32(rcwsr0) >>
  80. RCWSR0_MEM_PLL_RAT_SHIFT) &
  81. RCWSR0_MEM_PLL_RAT_MASK;
  82. sys->freq_ddr_pll1 *= (gur_in32(rcwsr0) >>
  83. RCWSR0_MEM2_PLL_RAT_SHIFT) &
  84. RCWSR0_MEM2_PLL_RAT_MASK;
  85. if (sys->freq_platform == 0) {
  86. return 1;
  87. } else {
  88. return 0;
  89. }
  90. }
  91. #ifdef NXP_SFP_ENABLED
  92. /*******************************************************************************
  93. * Returns true if secur eboot is enabled on board
  94. * mode = 0 (development mode - sb_en = 1)
  95. * mode = 1 (production mode - ITS = 1)
  96. ******************************************************************************/
  97. bool check_boot_mode_secure(uint32_t *mode)
  98. {
  99. uint32_t val = 0U;
  100. uint32_t *rcwsr = NULL;
  101. *mode = 0U;
  102. if (sfp_check_its() == 1) {
  103. /* ITS =1 , Production mode */
  104. *mode = 1U;
  105. return true;
  106. }
  107. rcwsr = (void *)(dcfg_init_info->g_nxp_dcfg_addr + RCWSR_SB_EN_OFFSET);
  108. val = (gur_in32(rcwsr) >> RCWSR_SBEN_SHIFT) &
  109. RCWSR_SBEN_MASK;
  110. if (val == RCWSR_SBEN_MASK) {
  111. *mode = 0U;
  112. return true;
  113. }
  114. return false;
  115. }
  116. #endif
  117. void error_handler(int error_code)
  118. {
  119. /* Dump error code in SCRATCH4 register */
  120. INFO("Error in Fuse Provisioning: %x\n", error_code);
  121. gur_out32((void *)
  122. (dcfg_init_info->g_nxp_dcfg_addr + DCFG_SCRATCH4_OFFSET),
  123. error_code);
  124. }