spl.c 3.0 KB

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