spl_boot.c 4.1 KB

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