imx8mm_bl2_el3_setup.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright 2017-2021 NXP
  3. * Copyright 2021 Arm
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #include <assert.h>
  8. #include <arch_helpers.h>
  9. #include <common/bl_common.h>
  10. #include <common/debug.h>
  11. #include <common/desc_image_load.h>
  12. #include <context.h>
  13. #include <drivers/console.h>
  14. #include <drivers/generic_delay_timer.h>
  15. #include <drivers/mmc.h>
  16. #include <lib/mmio.h>
  17. #include <lib/optee_utils.h>
  18. #include <lib/utils.h>
  19. #include <stdbool.h>
  20. #include <tbbr_img_def.h>
  21. #include <imx_aipstz.h>
  22. #include <imx_csu.h>
  23. #include <imx_uart.h>
  24. #include <imx_usdhc.h>
  25. #include <plat/common/platform.h>
  26. #include "imx8mm_private.h"
  27. #include "platform_def.h"
  28. static const struct aipstz_cfg aipstz[] = {
  29. {IMX_AIPSTZ1, 0x77777777, 0x77777777, .opacr = {0x0, 0x0, 0x0, 0x0, 0x0}, },
  30. {IMX_AIPSTZ2, 0x77777777, 0x77777777, .opacr = {0x0, 0x0, 0x0, 0x0, 0x0}, },
  31. {IMX_AIPSTZ3, 0x77777777, 0x77777777, .opacr = {0x0, 0x0, 0x0, 0x0, 0x0}, },
  32. {IMX_AIPSTZ4, 0x77777777, 0x77777777, .opacr = {0x0, 0x0, 0x0, 0x0, 0x0}, },
  33. {0},
  34. };
  35. static void imx8mm_usdhc_setup(void)
  36. {
  37. imx_usdhc_params_t params;
  38. struct mmc_device_info info;
  39. params.reg_base = PLAT_IMX8MM_BOOT_MMC_BASE;
  40. /*
  41. The imx8mm SD Card Speed modes for USDHC2
  42. +--------------+--------------------+--------------+--------------+
  43. |Bus Speed Mode|Max. Clock Frequency|Max. Bus Speed|Signal Voltage|
  44. +--------------+--------------------+--------------+--------------+
  45. |Default Speed | 25 MHz | 12.5 MB/s | 3.3V |
  46. |High Speed | 50 MHz | 25 MB/s | 3.3V |
  47. +--------------+--------------------+--------------+--------------+
  48. We pick 50 Mhz here for High Speed access.
  49. */
  50. params.clk_rate = 50000000;
  51. params.bus_width = MMC_BUS_WIDTH_1;
  52. params.flags = 0;
  53. info.mmc_dev_type = MMC_IS_SD;
  54. info.ocr_voltage = OCR_3_3_3_4 | OCR_3_2_3_3;
  55. imx_usdhc_init(&params, &info);
  56. }
  57. void bl2_el3_early_platform_setup(u_register_t arg1, u_register_t arg2,
  58. u_register_t arg3, u_register_t arg4)
  59. {
  60. int i;
  61. static console_t console;
  62. /* enable CSU NS access permission */
  63. for (i = 0; i < MAX_CSU_NUM; i++) {
  64. mmio_write_32(IMX_CSU_BASE + i * 4, CSU_CSL_OPEN_ACCESS);
  65. }
  66. /* config the aips access permission */
  67. imx_aipstz_init(aipstz);
  68. console_imx_uart_register(IMX_BOOT_UART_BASE, IMX_BOOT_UART_CLK_IN_HZ,
  69. IMX_CONSOLE_BAUDRATE, &console);
  70. generic_delay_timer_init();
  71. /* select the CKIL source to 32K OSC */
  72. mmio_write_32(0x30360124, 0x1);
  73. imx8mm_usdhc_setup();
  74. /* Open handles to a FIP image */
  75. plat_imx_io_setup();
  76. }
  77. void bl2_el3_plat_arch_setup(void)
  78. {
  79. }
  80. void bl2_platform_setup(void)
  81. {
  82. }
  83. int bl2_plat_handle_post_image_load(unsigned int image_id)
  84. {
  85. int err = 0;
  86. bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
  87. bl_mem_params_node_t *pager_mem_params = NULL;
  88. bl_mem_params_node_t *paged_mem_params = NULL;
  89. assert(bl_mem_params);
  90. switch (image_id) {
  91. case BL32_IMAGE_ID:
  92. pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID);
  93. assert(pager_mem_params);
  94. paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID);
  95. assert(paged_mem_params);
  96. err = parse_optee_header(&bl_mem_params->ep_info,
  97. &pager_mem_params->image_info,
  98. &paged_mem_params->image_info);
  99. if (err != 0) {
  100. WARN("OPTEE header parse error.\n");
  101. }
  102. break;
  103. default:
  104. /* Do nothing in default case */
  105. break;
  106. }
  107. return err;
  108. }
  109. unsigned int plat_get_syscnt_freq2(void)
  110. {
  111. return COUNTER_FREQUENCY;
  112. }
  113. void bl2_plat_runtime_setup(void)
  114. {
  115. return;
  116. }