spl.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2013-2015 Arcturus Networks, Inc.
  4. * http://www.arcturusnetworks.com/products/ucp1020/
  5. * based on board/freescale/p1_p2_rdb_pc/spl.c
  6. * original copyright follows:
  7. * Copyright 2013 Freescale Semiconductor, Inc.
  8. */
  9. #include <common.h>
  10. #include <clock_legacy.h>
  11. #include <console.h>
  12. #include <env.h>
  13. #include <env_internal.h>
  14. #include <init.h>
  15. #include <ns16550.h>
  16. #include <malloc.h>
  17. #include <mmc.h>
  18. #include <nand.h>
  19. #include <i2c.h>
  20. #include <fsl_esdhc.h>
  21. #include <spi_flash.h>
  22. #include <asm/global_data.h>
  23. DECLARE_GLOBAL_DATA_PTR;
  24. static const u32 sysclk_tbl[] = {
  25. 66666000, 7499900, 83332500, 8999900,
  26. 99999000, 11111000, 12499800, 13333200
  27. };
  28. phys_size_t get_effective_memsize(void)
  29. {
  30. return CONFIG_SYS_L2_SIZE;
  31. }
  32. void board_init_f(ulong bootflag)
  33. {
  34. u32 plat_ratio, bus_clk;
  35. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  36. console_init_f();
  37. /* Set pmuxcr to allow both i2c1 and i2c2 */
  38. setbits_be32(&gur->pmuxcr, in_be32(&gur->pmuxcr) | 0x1000);
  39. setbits_be32(&gur->pmuxcr,
  40. in_be32(&gur->pmuxcr) | MPC85xx_PMUXCR_SD_DATA);
  41. /* Read back the register to synchronize the write. */
  42. in_be32(&gur->pmuxcr);
  43. #ifdef CONFIG_SPL_SPI_BOOT
  44. clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_SD_DATA);
  45. #endif
  46. /* initialize selected port with appropriate baud rate */
  47. plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
  48. plat_ratio >>= 1;
  49. bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
  50. gd->bus_clk = bus_clk;
  51. ns16550_init((struct ns16550 *)CONFIG_SYS_NS16550_COM1,
  52. bus_clk / 16 / CONFIG_BAUDRATE);
  53. #ifdef CONFIG_SPL_MMC_BOOT
  54. puts("\nSD boot...\n");
  55. #elif defined(CONFIG_SPL_SPI_BOOT)
  56. puts("\nSPI Flash boot...\n");
  57. #endif
  58. /* copy code to RAM and jump to it - this should not return */
  59. /* NOTE - code has to be copied out of NAND buffer before
  60. * other blocks can be read.
  61. */
  62. relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
  63. }
  64. void board_init_r(gd_t *gd, ulong dest_addr)
  65. {
  66. /* Pointer is writable since we allocated a register for it */
  67. gd = (gd_t *)CONFIG_SPL_GD_ADDR;
  68. struct bd_info *bd;
  69. memset(gd, 0, sizeof(gd_t));
  70. bd = (struct bd_info *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t));
  71. memset(bd, 0, sizeof(struct bd_info));
  72. gd->bd = bd;
  73. arch_cpu_init();
  74. get_clocks();
  75. mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
  76. CONFIG_SPL_RELOC_MALLOC_SIZE);
  77. #ifndef CONFIG_SPL_NAND_BOOT
  78. env_init();
  79. #endif
  80. #ifdef CONFIG_SPL_MMC_BOOT
  81. mmc_initialize(bd);
  82. #endif
  83. /* relocate environment function pointers etc. */
  84. #ifdef CONFIG_SPL_NAND_BOOT
  85. nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
  86. (uchar *)CONFIG_ENV_ADDR);
  87. gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
  88. gd->env_valid = ENV_VALID;
  89. #else
  90. env_relocate();
  91. #endif
  92. #ifdef CONFIG_SYS_I2C_LEGACY
  93. i2c_init_all();
  94. #else
  95. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  96. #endif
  97. dram_init();
  98. #ifdef CONFIG_SPL_NAND_BOOT
  99. puts("Tertiary program loader running in sram...");
  100. #else
  101. puts("Second program loader running in sram...\n");
  102. #endif
  103. #ifdef CONFIG_SPL_MMC_BOOT
  104. mmc_boot();
  105. #elif defined(CONFIG_SPL_NAND_BOOT)
  106. nand_boot();
  107. #endif
  108. }