spl.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright 2013 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <console.h>
  8. #include <ns16550.h>
  9. #include <malloc.h>
  10. #include <mmc.h>
  11. #include <nand.h>
  12. #include <i2c.h>
  13. #include "../common/ngpixis.h"
  14. #include <fsl_esdhc.h>
  15. #include <spi_flash.h>
  16. #include "../common/spl.h"
  17. DECLARE_GLOBAL_DATA_PTR;
  18. static const u32 sysclk_tbl[] = {
  19. 66666000, 7499900, 83332500, 8999900,
  20. 99999000, 11111000, 12499800, 13333200
  21. };
  22. phys_size_t get_effective_memsize(void)
  23. {
  24. return CONFIG_SYS_L2_SIZE;
  25. }
  26. void board_init_f(ulong bootflag)
  27. {
  28. int px_spd;
  29. u32 plat_ratio, sys_clk, bus_clk;
  30. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  31. console_init_f();
  32. /* Set pmuxcr to allow both i2c1 and i2c2 */
  33. setbits_be32(&gur->pmuxcr, in_be32(&gur->pmuxcr) | 0x1000);
  34. setbits_be32(&gur->pmuxcr,
  35. in_be32(&gur->pmuxcr) | MPC85xx_PMUXCR_SD_DATA);
  36. #ifdef CONFIG_SPL_SPI_BOOT
  37. /* Enable the SPI */
  38. clrsetbits_8(&pixis->brdcfg0, PIXIS_ELBC_SPI_MASK, PIXIS_SPI);
  39. #endif
  40. /* Read back the register to synchronize the write. */
  41. in_be32(&gur->pmuxcr);
  42. /* initialize selected port with appropriate baud rate */
  43. px_spd = in_8((unsigned char *)(PIXIS_BASE + PIXIS_SPD));
  44. sys_clk = sysclk_tbl[px_spd & PIXIS_SPD_SYSCLK_MASK];
  45. plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
  46. bus_clk = sys_clk * plat_ratio / 2;
  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. gd->flags |= GD_FLG_FULL_MALLOC_INIT;
  76. #ifndef CONFIG_SPL_NAND_BOOT
  77. env_init();
  78. #endif
  79. #ifdef CONFIG_SPL_MMC_BOOT
  80. mmc_initialize(bd);
  81. #endif
  82. /* relocate environment function pointers etc. */
  83. #ifdef CONFIG_SPL_NAND_BOOT
  84. nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
  85. (uchar *)CONFIG_ENV_ADDR);
  86. gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
  87. gd->env_valid = 1;
  88. #else
  89. env_relocate();
  90. #endif
  91. #ifdef CONFIG_SYS_I2C
  92. i2c_init_all();
  93. #else
  94. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  95. #endif
  96. gd->ram_size = initdram(0);
  97. #ifdef CONFIG_SPL_NAND_BOOT
  98. puts("Tertiary program loader running in sram...");
  99. #else
  100. puts("Second program loader running in sram...\n");
  101. #endif
  102. #ifdef CONFIG_SPL_MMC_BOOT
  103. mmc_boot();
  104. #elif defined(CONFIG_SPL_SPI_BOOT)
  105. fsl_spi_boot();
  106. #elif defined(CONFIG_SPL_NAND_BOOT)
  107. nand_boot();
  108. #endif
  109. }