spl_boot.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Freescale i.MX28 Boot setup
  4. *
  5. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  6. * on behalf of DENX Software Engineering GmbH
  7. */
  8. #include <common.h>
  9. #include <config.h>
  10. #include <init.h>
  11. #include <log.h>
  12. #include <serial.h>
  13. #include <asm/global_data.h>
  14. #include <asm/io.h>
  15. #include <asm/arch/imx-regs.h>
  16. #include <asm/arch/sys_proto.h>
  17. #include <asm/gpio.h>
  18. #include <linux/compiler.h>
  19. #include "mxs_init.h"
  20. DECLARE_GLOBAL_DATA_PTR;
  21. static gd_t gdata __section(".data");
  22. #ifdef CONFIG_SPL_SERIAL_SUPPORT
  23. static struct bd_info bdata __section(".data");
  24. #endif
  25. /*
  26. * This delay function is intended to be used only in early stage of boot, where
  27. * clock are not set up yet.
  28. */
  29. void early_delay(int delay)
  30. {
  31. struct mxs_digctl_regs *digctl_regs =
  32. (struct mxs_digctl_regs *)MXS_DIGCTL_BASE;
  33. uint32_t st = readl(&digctl_regs->hw_digctl_microseconds);
  34. while (readl(&digctl_regs->hw_digctl_microseconds) - st <= delay)
  35. ;
  36. }
  37. #if defined(CONFIG_MX23)
  38. #define MUX_CONFIG_BOOTMODE_PAD (MXS_PAD_3V3 | MXS_PAD_4MA | MXS_PAD_NOPULL)
  39. static const iomux_cfg_t iomux_boot[] = {
  40. MX23_PAD_LCD_D00__GPIO_1_0 | MUX_CONFIG_BOOTMODE_PAD,
  41. MX23_PAD_LCD_D01__GPIO_1_1 | MUX_CONFIG_BOOTMODE_PAD,
  42. MX23_PAD_LCD_D02__GPIO_1_2 | MUX_CONFIG_BOOTMODE_PAD,
  43. MX23_PAD_LCD_D03__GPIO_1_3 | MUX_CONFIG_BOOTMODE_PAD,
  44. MX23_PAD_LCD_D04__GPIO_1_4 | MUX_CONFIG_BOOTMODE_PAD,
  45. MX23_PAD_LCD_D05__GPIO_1_5 | MUX_CONFIG_BOOTMODE_PAD,
  46. };
  47. #endif
  48. static uint8_t mxs_get_bootmode_index(void)
  49. {
  50. uint8_t bootmode = 0;
  51. int i;
  52. uint8_t masked;
  53. #if defined(CONFIG_MX23)
  54. /* Setup IOMUX of bootmode pads to GPIO */
  55. mxs_iomux_setup_multiple_pads(iomux_boot, ARRAY_SIZE(iomux_boot));
  56. /* Setup bootmode pins as GPIO input */
  57. gpio_direction_input(MX23_PAD_LCD_D00__GPIO_1_0);
  58. gpio_direction_input(MX23_PAD_LCD_D01__GPIO_1_1);
  59. gpio_direction_input(MX23_PAD_LCD_D02__GPIO_1_2);
  60. gpio_direction_input(MX23_PAD_LCD_D03__GPIO_1_3);
  61. gpio_direction_input(MX23_PAD_LCD_D05__GPIO_1_5);
  62. /* Read bootmode pads */
  63. bootmode |= (gpio_get_value(MX23_PAD_LCD_D00__GPIO_1_0) ? 1 : 0) << 0;
  64. bootmode |= (gpio_get_value(MX23_PAD_LCD_D01__GPIO_1_1) ? 1 : 0) << 1;
  65. bootmode |= (gpio_get_value(MX23_PAD_LCD_D02__GPIO_1_2) ? 1 : 0) << 2;
  66. bootmode |= (gpio_get_value(MX23_PAD_LCD_D03__GPIO_1_3) ? 1 : 0) << 3;
  67. bootmode |= (gpio_get_value(MX23_PAD_LCD_D05__GPIO_1_5) ? 1 : 0) << 5;
  68. #elif defined(CONFIG_MX28)
  69. /* The global boot mode will be detected by ROM code and its value
  70. * is stored at the fixed address 0x00019BF0 in OCRAM.
  71. */
  72. #define GLOBAL_BOOT_MODE_ADDR 0x00019BF0
  73. bootmode = __raw_readl(GLOBAL_BOOT_MODE_ADDR);
  74. #endif
  75. for (i = 0; i < ARRAY_SIZE(mxs_boot_modes); i++) {
  76. masked = bootmode & mxs_boot_modes[i].boot_mask;
  77. if (masked == mxs_boot_modes[i].boot_pads)
  78. break;
  79. }
  80. return i;
  81. }
  82. static void mxs_spl_fixup_vectors(void)
  83. {
  84. /*
  85. * Copy our vector table to 0x0, since due to HAB, we cannot
  86. * be loaded to 0x0. We want to have working vectoring though,
  87. * thus this fixup. Our vectoring table is PIC, so copying is
  88. * fine.
  89. */
  90. extern uint32_t _start;
  91. /* cppcheck-suppress nullPointer */
  92. memcpy(0x0, &_start, 0x60);
  93. }
  94. static void mxs_spl_console_init(void)
  95. {
  96. #ifdef CONFIG_SPL_SERIAL_SUPPORT
  97. gd->bd = &bdata;
  98. gd->baudrate = CONFIG_BAUDRATE;
  99. serial_init();
  100. gd->have_console = 1;
  101. #endif
  102. }
  103. void mxs_common_spl_init(const uint32_t arg, const uint32_t *resptr,
  104. const iomux_cfg_t *iomux_setup,
  105. const unsigned int iomux_size)
  106. {
  107. struct mxs_spl_data *data = MXS_SPL_DATA;
  108. uint8_t bootmode = mxs_get_bootmode_index();
  109. gd = &gdata;
  110. mxs_spl_fixup_vectors();
  111. mxs_iomux_setup_multiple_pads(iomux_setup, iomux_size);
  112. mxs_spl_console_init();
  113. debug("SPL: Serial Console Initialised\n");
  114. mxs_power_init();
  115. mxs_mem_init();
  116. data->mem_dram_size = mxs_mem_get_size();
  117. data->boot_mode_idx = bootmode;
  118. mxs_power_wait_pswitch();
  119. if (mxs_boot_modes[data->boot_mode_idx].boot_pads == MXS_BM_JTAG) {
  120. debug("SPL: Waiting for JTAG user\n");
  121. asm volatile ("x: b x");
  122. }
  123. }
  124. #ifndef CONFIG_SPL_FRAMEWORK
  125. /* Support aparatus */
  126. inline void board_init_f(unsigned long bootflag)
  127. {
  128. for (;;)
  129. ;
  130. }
  131. inline void board_init_r(gd_t *id, ulong dest_addr)
  132. {
  133. for (;;)
  134. ;
  135. }
  136. #endif