spl_boot.c 4.1 KB

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