blob: 39e1bee6f361cca5854b897b608ac78e084390dd [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ying Zhangdfb2b152013-08-16 15:16:12 +08002/*
3 * Copyright 2013 Freescale Semiconductor, Inc.
Ying Zhangdfb2b152013-08-16 15:16:12 +08004 */
5
6#include <common.h>
Simon Glass85d65312019-12-28 10:44:58 -07007#include <clock_legacy.h>
Simon Glassa73bda42015-11-08 23:47:45 -07008#include <console.h>
Simon Glass79fd2142019-08-01 09:46:43 -06009#include <env.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060010#include <env_internal.h>
Simon Glass284f71b2019-12-28 10:44:45 -070011#include <init.h>
Ying Zhangdfb2b152013-08-16 15:16:12 +080012#include <ns16550.h>
13#include <malloc.h>
14#include <mmc.h>
15#include <nand.h>
16#include <i2c.h>
17#include "../common/ngpixis.h"
18#include <fsl_esdhc.h>
Ying Zhang9b155ca2013-08-16 15:16:14 +080019#include <spi_flash.h>
Simon Glassdd8e2242016-09-24 18:20:10 -060020#include "../common/spl.h"
Ying Zhangdfb2b152013-08-16 15:16:12 +080021
22DECLARE_GLOBAL_DATA_PTR;
23
24static const u32 sysclk_tbl[] = {
25 66666000, 7499900, 83332500, 8999900,
26 99999000, 11111000, 12499800, 13333200
27};
28
York Sun863e8d82014-02-11 11:57:26 -080029phys_size_t get_effective_memsize(void)
Ying Zhangdfb2b152013-08-16 15:16:12 +080030{
31 return CONFIG_SYS_L2_SIZE;
32}
33
34void board_init_f(ulong bootflag)
35{
36 int px_spd;
37 u32 plat_ratio, sys_clk, bus_clk;
38 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
39
40 console_init_f();
41
42 /* Set pmuxcr to allow both i2c1 and i2c2 */
43 setbits_be32(&gur->pmuxcr, in_be32(&gur->pmuxcr) | 0x1000);
44 setbits_be32(&gur->pmuxcr,
45 in_be32(&gur->pmuxcr) | MPC85xx_PMUXCR_SD_DATA);
46
Ying Zhang9b155ca2013-08-16 15:16:14 +080047#ifdef CONFIG_SPL_SPI_BOOT
48 /* Enable the SPI */
49 clrsetbits_8(&pixis->brdcfg0, PIXIS_ELBC_SPI_MASK, PIXIS_SPI);
50#endif
51
Ying Zhangdfb2b152013-08-16 15:16:12 +080052 /* Read back the register to synchronize the write. */
53 in_be32(&gur->pmuxcr);
54
55 /* initialize selected port with appropriate baud rate */
56 px_spd = in_8((unsigned char *)(PIXIS_BASE + PIXIS_SPD));
57 sys_clk = sysclk_tbl[px_spd & PIXIS_SPD_SYSCLK_MASK];
58 plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
59 bus_clk = sys_clk * plat_ratio / 2;
60
61 NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
62 bus_clk / 16 / CONFIG_BAUDRATE);
63#ifdef CONFIG_SPL_MMC_BOOT
64 puts("\nSD boot...\n");
Ying Zhang9b155ca2013-08-16 15:16:14 +080065#elif defined(CONFIG_SPL_SPI_BOOT)
66 puts("\nSPI Flash boot...\n");
Ying Zhangdfb2b152013-08-16 15:16:12 +080067#endif
68
69 /* copy code to RAM and jump to it - this should not return */
70 /* NOTE - code has to be copied out of NAND buffer before
71 * other blocks can be read.
72 */
73 relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
74}
75
76void board_init_r(gd_t *gd, ulong dest_addr)
77{
78 /* Pointer is writable since we allocated a register for it */
79 gd = (gd_t *)CONFIG_SPL_GD_ADDR;
80 bd_t *bd;
81
82 memset(gd, 0, sizeof(gd_t));
83 bd = (bd_t *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t));
84 memset(bd, 0, sizeof(bd_t));
85 gd->bd = bd;
86 bd->bi_memstart = CONFIG_SYS_INIT_L2_ADDR;
87 bd->bi_memsize = CONFIG_SYS_L2_SIZE;
88
Simon Glass302445a2017-01-23 13:31:22 -070089 arch_cpu_init();
Ying Zhangdfb2b152013-08-16 15:16:12 +080090 get_clocks();
91 mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
92 CONFIG_SPL_RELOC_MALLOC_SIZE);
Sumit Garg2ff056b2016-05-25 12:41:48 -040093 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
Ying Zhang9c2e84f2013-08-16 15:16:16 +080094#ifndef CONFIG_SPL_NAND_BOOT
Ying Zhangdfb2b152013-08-16 15:16:12 +080095 env_init();
Ying Zhang9c2e84f2013-08-16 15:16:16 +080096#endif
Ying Zhangdfb2b152013-08-16 15:16:12 +080097#ifdef CONFIG_SPL_MMC_BOOT
98 mmc_initialize(bd);
99#endif
100 /* relocate environment function pointers etc. */
Ying Zhang9c2e84f2013-08-16 15:16:16 +0800101#ifdef CONFIG_SPL_NAND_BOOT
102 nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
Tom Rini5cd7ece2019-11-18 20:02:10 -0500103 (uchar *)SPL_ENV_ADDR);
Ying Zhang9c2e84f2013-08-16 15:16:16 +0800104
Tom Rini5cd7ece2019-11-18 20:02:10 -0500105 gd->env_addr = (ulong)(SPL_ENV_ADDR);
Simon Glass4bc2ad22017-08-03 12:21:56 -0600106 gd->env_valid = ENV_VALID;
Ying Zhang9c2e84f2013-08-16 15:16:16 +0800107#else
Ying Zhangdfb2b152013-08-16 15:16:12 +0800108 env_relocate();
Ying Zhang9c2e84f2013-08-16 15:16:16 +0800109#endif
Ying Zhangdfb2b152013-08-16 15:16:12 +0800110
Ying Zhang4393f952013-09-04 17:03:45 +0800111#ifdef CONFIG_SYS_I2C
112 i2c_init_all();
113#else
114 i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
115#endif
Ying Zhangdfb2b152013-08-16 15:16:12 +0800116
Simon Glassd35f3382017-04-06 12:47:05 -0600117 dram_init();
Ying Zhang9c2e84f2013-08-16 15:16:16 +0800118#ifdef CONFIG_SPL_NAND_BOOT
119 puts("Tertiary program loader running in sram...");
120#else
Ying Zhangdfb2b152013-08-16 15:16:12 +0800121 puts("Second program loader running in sram...\n");
Ying Zhang9c2e84f2013-08-16 15:16:16 +0800122#endif
Ying Zhangdfb2b152013-08-16 15:16:12 +0800123
124#ifdef CONFIG_SPL_MMC_BOOT
125 mmc_boot();
Ying Zhang9b155ca2013-08-16 15:16:14 +0800126#elif defined(CONFIG_SPL_SPI_BOOT)
Simon Glassdd8e2242016-09-24 18:20:10 -0600127 fsl_spi_boot();
Ying Zhang9c2e84f2013-08-16 15:16:16 +0800128#elif defined(CONFIG_SPL_NAND_BOOT)
129 nand_boot();
Ying Zhangdfb2b152013-08-16 15:16:12 +0800130#endif
131}