blob: 1cf3497aa688a62ba85fb0df3bbf2c0424a4419e [file] [log] [blame]
Ying Zhang28027d72013-09-06 17:30:56 +08001/*
2 * Copyright 2013 Freescale Semiconductor, Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -07008#include <console.h>
Ying Zhang28027d72013-09-06 17:30:56 +08009#include <ns16550.h>
10#include <malloc.h>
11#include <mmc.h>
12#include <nand.h>
13#include <i2c.h>
14#include <fsl_esdhc.h>
Ying Zhangf74fd4e2013-09-06 17:30:57 +080015#include <spi_flash.h>
Simon Glassdd8e2242016-09-24 18:20:10 -060016#include "../common/spl.h"
Ying Zhang28027d72013-09-06 17:30:56 +080017
18DECLARE_GLOBAL_DATA_PTR;
19
20static const u32 sysclk_tbl[] = {
21 66666000, 7499900, 83332500, 8999900,
22 99999000, 11111000, 12499800, 13333200
23};
24
York Sun863e8d82014-02-11 11:57:26 -080025phys_size_t get_effective_memsize(void)
Ying Zhang28027d72013-09-06 17:30:56 +080026{
27 return CONFIG_SYS_L2_SIZE;
28}
29
30void board_init_f(ulong bootflag)
31{
32 u32 plat_ratio, bus_clk;
33 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
34
35 console_init_f();
36
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
42 /* Read back the register to synchronize the write. */
43 in_be32(&gur->pmuxcr);
44
Ying Zhangf74fd4e2013-09-06 17:30:57 +080045#ifdef CONFIG_SPL_SPI_BOOT
46 clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_SD_DATA);
47#endif
48
Ying Zhang28027d72013-09-06 17:30:56 +080049 /* initialize selected port with appropriate baud rate */
50 plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
51 plat_ratio >>= 1;
52 bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
53 gd->bus_clk = bus_clk;
54
55 NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
56 bus_clk / 16 / CONFIG_BAUDRATE);
57#ifdef CONFIG_SPL_MMC_BOOT
58 puts("\nSD boot...\n");
Ying Zhangf74fd4e2013-09-06 17:30:57 +080059#elif defined(CONFIG_SPL_SPI_BOOT)
60 puts("\nSPI Flash boot...\n");
Ying Zhang28027d72013-09-06 17:30:56 +080061#endif
62
63 /* copy code to RAM and jump to it - this should not return */
64 /* NOTE - code has to be copied out of NAND buffer before
65 * other blocks can be read.
66 */
67 relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
68}
69
70void board_init_r(gd_t *gd, ulong dest_addr)
71{
72 /* Pointer is writable since we allocated a register for it */
73 gd = (gd_t *)CONFIG_SPL_GD_ADDR;
74 bd_t *bd;
75
76 memset(gd, 0, sizeof(gd_t));
77 bd = (bd_t *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t));
78 memset(bd, 0, sizeof(bd_t));
79 gd->bd = bd;
80 bd->bi_memstart = CONFIG_SYS_INIT_L2_ADDR;
81 bd->bi_memsize = CONFIG_SYS_L2_SIZE;
82
Simon Glass302445a2017-01-23 13:31:22 -070083 arch_cpu_init();
Ying Zhang28027d72013-09-06 17:30:56 +080084 get_clocks();
85 mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
86 CONFIG_SPL_RELOC_MALLOC_SIZE);
Sumit Garg2ff056b2016-05-25 12:41:48 -040087 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
Ying Zhang28027d72013-09-06 17:30:56 +080088
Ying Zhangb8b404d2013-09-06 17:30:58 +080089#ifndef CONFIG_SPL_NAND_BOOT
Ying Zhang28027d72013-09-06 17:30:56 +080090 env_init();
Ying Zhangb8b404d2013-09-06 17:30:58 +080091#endif
Ying Zhang28027d72013-09-06 17:30:56 +080092#ifdef CONFIG_SPL_MMC_BOOT
93 mmc_initialize(bd);
94#endif
95 /* relocate environment function pointers etc. */
Ying Zhangb8b404d2013-09-06 17:30:58 +080096#ifdef CONFIG_SPL_NAND_BOOT
97 nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
98 (uchar *)CONFIG_ENV_ADDR);
99 gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
100 gd->env_valid = 1;
101#else
Ying Zhang28027d72013-09-06 17:30:56 +0800102 env_relocate();
Ying Zhangb8b404d2013-09-06 17:30:58 +0800103#endif
Ying Zhang28027d72013-09-06 17:30:56 +0800104
105#ifdef CONFIG_SYS_I2C
106 i2c_init_all();
107#else
108 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
109#endif
110
Simon Glassd35f3382017-04-06 12:47:05 -0600111 dram_init();
Ying Zhangb8b404d2013-09-06 17:30:58 +0800112#ifdef CONFIG_SPL_NAND_BOOT
113 puts("Tertiary program loader running in sram...");
114#else
Ying Zhang28027d72013-09-06 17:30:56 +0800115 puts("Second program loader running in sram...\n");
Ying Zhangb8b404d2013-09-06 17:30:58 +0800116#endif
Ying Zhang28027d72013-09-06 17:30:56 +0800117
118#ifdef CONFIG_SPL_MMC_BOOT
119 mmc_boot();
Ying Zhangf74fd4e2013-09-06 17:30:57 +0800120#elif defined(CONFIG_SPL_SPI_BOOT)
Simon Glassdd8e2242016-09-24 18:20:10 -0600121 fsl_spi_boot();
Ying Zhangb8b404d2013-09-06 17:30:58 +0800122#elif defined(CONFIG_SPL_NAND_BOOT)
123 nand_boot();
Ying Zhang28027d72013-09-06 17:30:56 +0800124#endif
125}