1f45210d6SMatthew McClintock /*
2f45210d6SMatthew McClintock * Copyright 2011 Freescale Semiconductor, Inc.
3f45210d6SMatthew McClintock *
41a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+
5f45210d6SMatthew McClintock */
6f45210d6SMatthew McClintock
7f45210d6SMatthew McClintock #include <common.h>
8f45210d6SMatthew McClintock #include <ns16550.h>
9f45210d6SMatthew McClintock #include <asm/io.h>
10f45210d6SMatthew McClintock #include <nand.h>
11f45210d6SMatthew McClintock #include <asm/fsl_law.h>
12*5614e71bSYork Sun #include <fsl_ddr_sdram.h>
13f45210d6SMatthew McClintock
14f45210d6SMatthew McClintock
15f45210d6SMatthew McClintock const static u32 sysclk_tbl[] = {
16f45210d6SMatthew McClintock 66666000, 7499900, 83332500, 8999900,
17f45210d6SMatthew McClintock 99999000, 11111000, 12499800, 13333200
18f45210d6SMatthew McClintock };
19f45210d6SMatthew McClintock
board_init_f(ulong bootflag)20f45210d6SMatthew McClintock void board_init_f(ulong bootflag)
21f45210d6SMatthew McClintock {
22f45210d6SMatthew McClintock int px_spd;
23f45210d6SMatthew McClintock u32 plat_ratio, sys_clk, bus_clk;
24f45210d6SMatthew McClintock ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
25f45210d6SMatthew McClintock
265d97fe2aSYing Zhang #if defined(CONFIG_SYS_NAND_BR_PRELIM) && defined(CONFIG_SYS_NAND_OR_PRELIM)
275d97fe2aSYing Zhang set_lbc_br(0, CONFIG_SYS_NAND_BR_PRELIM);
285d97fe2aSYing Zhang set_lbc_or(0, CONFIG_SYS_NAND_OR_PRELIM);
295d97fe2aSYing Zhang #endif
30f45210d6SMatthew McClintock /* for FPGA */
31f45210d6SMatthew McClintock set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
32f45210d6SMatthew McClintock set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
33f45210d6SMatthew McClintock
34f45210d6SMatthew McClintock /* initialize selected port with appropriate baud rate */
35f45210d6SMatthew McClintock px_spd = in_8((unsigned char *)(PIXIS_BASE + PIXIS_SPD));
36f45210d6SMatthew McClintock sys_clk = sysclk_tbl[px_spd & PIXIS_SPD_SYSCLK_MASK];
37f45210d6SMatthew McClintock plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
38f45210d6SMatthew McClintock bus_clk = sys_clk * plat_ratio / 2;
39f45210d6SMatthew McClintock
40f45210d6SMatthew McClintock NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
41f45210d6SMatthew McClintock bus_clk / 16 / CONFIG_BAUDRATE);
42f45210d6SMatthew McClintock
43f45210d6SMatthew McClintock puts("\nNAND boot... ");
44f45210d6SMatthew McClintock
45f45210d6SMatthew McClintock /* copy code to RAM and jump to it - this should not return */
46f45210d6SMatthew McClintock /* NOTE - code has to be copied out of NAND buffer before
47f45210d6SMatthew McClintock * other blocks can be read.
48f45210d6SMatthew McClintock */
49f45210d6SMatthew McClintock relocate_code(CONFIG_SPL_RELOC_STACK, 0,
50f45210d6SMatthew McClintock CONFIG_SPL_RELOC_TEXT_BASE);
51f45210d6SMatthew McClintock }
52f45210d6SMatthew McClintock
board_init_r(gd_t * gd,ulong dest_addr)53f45210d6SMatthew McClintock void board_init_r(gd_t *gd, ulong dest_addr)
54f45210d6SMatthew McClintock {
555d97fe2aSYing Zhang puts("\nSecond program loader running in sram...");
56f45210d6SMatthew McClintock nand_boot();
57f45210d6SMatthew McClintock }
58f45210d6SMatthew McClintock
putc(char c)59f45210d6SMatthew McClintock void putc(char c)
60f45210d6SMatthew McClintock {
61f45210d6SMatthew McClintock if (c == '\n')
62f45210d6SMatthew McClintock NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r');
63f45210d6SMatthew McClintock
64f45210d6SMatthew McClintock NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c);
65f45210d6SMatthew McClintock }
66f45210d6SMatthew McClintock
puts(const char * str)67f45210d6SMatthew McClintock void puts(const char *str)
68f45210d6SMatthew McClintock {
69f45210d6SMatthew McClintock while (*str)
70f45210d6SMatthew McClintock putc(*str++);
71f45210d6SMatthew McClintock }
72