msm8916_setup.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (c) 2021-2023, Stephan Gerhold <stephan@gerhold.net>
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <common/bl_common.h>
  7. #include <drivers/console.h>
  8. #include <drivers/generic_delay_timer.h>
  9. #include <lib/mmio.h>
  10. #include <lib/xlat_tables/xlat_mmu_helpers.h>
  11. #include <lib/xlat_tables/xlat_tables_v2.h>
  12. #include "msm8916_gicv2.h"
  13. #include <msm8916_mmap.h>
  14. #include "msm8916_setup.h"
  15. #include <uartdm_console.h>
  16. static const mmap_region_t msm8916_mmap[] = {
  17. MAP_REGION_FLAT(PCNOC_BASE, PCNOC_SIZE,
  18. MT_DEVICE | MT_RW | MT_SECURE | MT_EXECUTE_NEVER),
  19. MAP_REGION_FLAT(APCS_BASE, APCS_SIZE,
  20. MT_DEVICE | MT_RW | MT_SECURE | MT_EXECUTE_NEVER),
  21. {},
  22. };
  23. static console_t console;
  24. unsigned int plat_get_syscnt_freq2(void)
  25. {
  26. return PLAT_SYSCNT_FREQ;
  27. }
  28. #define GPIO_CFG_FUNC(n) ((n) << 2)
  29. #define GPIO_CFG_DRV_STRENGTH_MA(ma) (((ma) / 2 - 1) << 6)
  30. #define CLK_ENABLE BIT_32(0)
  31. #define CLK_OFF BIT_32(31)
  32. #define GCC_BLSP1_AHB_CBCR (GCC_BASE + 0x01008)
  33. #define GCC_BLSP1_UART_APPS_CBCR(n) (GCC_BASE + \
  34. (((n) == 2) ? (0x0302c) : (0x0203c + (((n) - 1) * 0x1000))))
  35. #define GCC_APCS_CLOCK_BRANCH_ENA_VOTE (GCC_BASE + 0x45004)
  36. #define BLSP1_AHB_CLK_ENA BIT_32(10)
  37. struct uartdm_gpios {
  38. unsigned int tx, rx, func;
  39. };
  40. static const struct uartdm_gpios uartdm_gpio_map[] = {
  41. #if defined(PLAT_msm8909)
  42. {4, 5, 0x2}, {20, 21, 0x3},
  43. #elif defined(PLAT_msm8916) || defined(PLAT_msm8939)
  44. {0, 1, 0x2}, {4, 5, 0x2},
  45. #elif defined(PLAT_mdm9607)
  46. {12, 13, 0x2}, {4, 5, 0x2}, {0, 1, 0x1},
  47. {16, 17, 0x2}, {8, 9, 0x2}, {20, 21, 0x2},
  48. #endif
  49. };
  50. /*
  51. * The previous boot stage seems to disable most of the UART setup before exit
  52. * so it must be enabled here again before the UART console can be used.
  53. */
  54. static void msm8916_enable_blsp_uart(void)
  55. {
  56. const struct uartdm_gpios *gpios = &uartdm_gpio_map[QTI_UART_NUM - 1];
  57. CASSERT(QTI_UART_NUM > 0 && QTI_UART_NUM <= ARRAY_SIZE(uartdm_gpio_map),
  58. assert_qti_blsp_uart_valid);
  59. /* Route GPIOs to BLSP UART */
  60. mmio_write_32(TLMM_GPIO_CFG(gpios->tx), GPIO_CFG_FUNC(gpios->func) |
  61. GPIO_CFG_DRV_STRENGTH_MA(8));
  62. mmio_write_32(TLMM_GPIO_CFG(gpios->rx), GPIO_CFG_FUNC(gpios->func) |
  63. GPIO_CFG_DRV_STRENGTH_MA(8));
  64. /* Enable AHB clock */
  65. mmio_setbits_32(GCC_APCS_CLOCK_BRANCH_ENA_VOTE, BLSP1_AHB_CLK_ENA);
  66. while (mmio_read_32(GCC_BLSP1_AHB_CBCR) & CLK_OFF) {
  67. }
  68. /* Enable BLSP UART clock */
  69. mmio_setbits_32(GCC_BLSP1_UART_APPS_CBCR(QTI_UART_NUM), CLK_ENABLE);
  70. while (mmio_read_32(GCC_BLSP1_UART_APPS_CBCR(QTI_UART_NUM)) & CLK_OFF) {
  71. }
  72. }
  73. void msm8916_early_platform_setup(void)
  74. {
  75. /* Initialize the debug console as early as possible */
  76. msm8916_enable_blsp_uart();
  77. console_uartdm_register(&console, BLSP_UART_BASE);
  78. if (QTI_RUNTIME_UART) {
  79. /* Mark UART as runtime usable */
  80. console_set_scope(&console, CONSOLE_FLAG_BOOT |
  81. CONSOLE_FLAG_RUNTIME | CONSOLE_FLAG_CRASH);
  82. }
  83. }
  84. void msm8916_plat_arch_setup(uintptr_t base, size_t size)
  85. {
  86. mmap_add_region(base, base, size, MT_RW_DATA | MT_SECURE);
  87. mmap_add_region(BL_CODE_BASE, BL_CODE_BASE,
  88. BL_CODE_END - BL_CODE_BASE,
  89. MT_CODE | MT_SECURE);
  90. mmap_add_region(BL_RO_DATA_BASE, BL_RO_DATA_BASE,
  91. BL_RO_DATA_END - BL_RO_DATA_BASE,
  92. MT_RO_DATA | MT_SECURE);
  93. mmap_add_region(BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_BASE,
  94. BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
  95. MT_DEVICE | MT_RW | MT_SECURE | MT_EXECUTE_NEVER);
  96. mmap_add(msm8916_mmap);
  97. init_xlat_tables();
  98. }
  99. void msm8916_platform_setup(void)
  100. {
  101. generic_delay_timer_init();
  102. msm8916_gicv2_init();
  103. }