blob: 9ab4029836c852493643477c8f7ddd9ec6ce886b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Matthew McClintockf45210d2013-02-18 10:02:19 +00002/*
3 * Copyright 2011 Freescale Semiconductor, Inc.
Matthew McClintockf45210d2013-02-18 10:02:19 +00004 */
5
6#include <common.h>
7#include <ns16550.h>
8#include <asm/io.h>
9#include <nand.h>
10#include <asm/fsl_law.h>
York Sun5614e712013-09-30 09:22:09 -070011#include <fsl_ddr_sdram.h>
Matthew McClintockf45210d2013-02-18 10:02:19 +000012
13
Matthew McClintockf45210d2013-02-18 10:02:19 +000014const static u32 sysclk_tbl[] = {
15 66666000, 7499900, 83332500, 8999900,
16 99999000, 11111000, 12499800, 13333200
17};
18
19void board_init_f(ulong bootflag)
20{
21 int px_spd;
22 u32 plat_ratio, sys_clk, bus_clk;
23 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
24
Ying Zhang5d97fe22013-08-16 15:16:16 +080025#if defined(CONFIG_SYS_NAND_BR_PRELIM) && defined(CONFIG_SYS_NAND_OR_PRELIM)
26 set_lbc_br(0, CONFIG_SYS_NAND_BR_PRELIM);
27 set_lbc_or(0, CONFIG_SYS_NAND_OR_PRELIM);
28#endif
Matthew McClintockf45210d2013-02-18 10:02:19 +000029 /* for FPGA */
30 set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
31 set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
32
33 /* initialize selected port with appropriate baud rate */
34 px_spd = in_8((unsigned char *)(PIXIS_BASE + PIXIS_SPD));
35 sys_clk = sysclk_tbl[px_spd & PIXIS_SPD_SYSCLK_MASK];
36 plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
37 bus_clk = sys_clk * plat_ratio / 2;
38
39 NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
40 bus_clk / 16 / CONFIG_BAUDRATE);
41
42 puts("\nNAND boot... ");
43
Matthew McClintockf45210d2013-02-18 10:02:19 +000044 /* copy code to RAM and jump to it - this should not return */
45 /* NOTE - code has to be copied out of NAND buffer before
46 * other blocks can be read.
47 */
48 relocate_code(CONFIG_SPL_RELOC_STACK, 0,
49 CONFIG_SPL_RELOC_TEXT_BASE);
50}
51
52void board_init_r(gd_t *gd, ulong dest_addr)
53{
Ying Zhang5d97fe22013-08-16 15:16:16 +080054 puts("\nSecond program loader running in sram...");
Matthew McClintockf45210d2013-02-18 10:02:19 +000055 nand_boot();
56}
57
58void putc(char c)
59{
60 if (c == '\n')
61 NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r');
62
63 NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c);
64}
65
66void puts(const char *str)
67{
68 while (*str)
69 putc(*str++);
70}