blob: 44ad4e68d9f6cd22f81557bfd81e4e18dea65fda [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Shengzhou Liud11b3cb2014-04-18 16:43:39 +08002/* Copyright 2013 Freescale Semiconductor, Inc.
Shengzhou Liud11b3cb2014-04-18 16:43:39 +08003 */
4
Tom Rinidec7ea02024-05-20 13:35:03 -06005#include <config.h>
Simon Glass85d65312019-12-28 10:44:58 -07006#include <clock_legacy.h>
Simon Glassa73bda42015-11-08 23:47:45 -07007#include <console.h>
Simon Glass9d1f6192019-08-02 09:44:25 -06008#include <env_internal.h>
Simon Glass284f71b2019-12-28 10:44:45 -07009#include <init.h>
Shengzhou Liud11b3cb2014-04-18 16:43:39 +080010#include <malloc.h>
11#include <ns16550.h>
12#include <nand.h>
13#include <i2c.h>
14#include <mmc.h>
15#include <fsl_esdhc.h>
16#include <spi_flash.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Shengzhou Liud11b3cb2014-04-18 16:43:39 +080018#include "../common/qixis.h"
19#include "t208xqds_qixis.h"
Simon Glassdd8e2242016-09-24 18:20:10 -060020#include "../common/spl.h"
Shengzhou Liud11b3cb2014-04-18 16:43:39 +080021
22DECLARE_GLOBAL_DATA_PTR;
23
24phys_size_t get_effective_memsize(void)
25{
26 return CONFIG_SYS_L3_SIZE;
27}
28
29unsigned long get_board_sys_clk(void)
30{
31 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
32
33 switch (sysclk_conf & 0x0F) {
34 case QIXIS_SYSCLK_83:
35 return 83333333;
36 case QIXIS_SYSCLK_100:
37 return 100000000;
38 case QIXIS_SYSCLK_125:
39 return 125000000;
40 case QIXIS_SYSCLK_133:
41 return 133333333;
42 case QIXIS_SYSCLK_150:
43 return 150000000;
44 case QIXIS_SYSCLK_160:
45 return 160000000;
46 case QIXIS_SYSCLK_166:
47 return 166666666;
48 }
49 return 66666666;
50}
51
52unsigned long get_board_ddr_clk(void)
53{
54 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
55
56 switch ((ddrclk_conf & 0x30) >> 4) {
57 case QIXIS_DDRCLK_100:
58 return 100000000;
59 case QIXIS_DDRCLK_125:
60 return 125000000;
61 case QIXIS_DDRCLK_133:
62 return 133333333;
63 }
64 return 66666666;
65}
66
67void board_init_f(ulong bootflag)
68{
69 u32 plat_ratio, sys_clk, ccb_clk;
Tom Rinid5c3bf22022-10-28 20:27:12 -040070 ccsr_gur_t *gur = (void *)CFG_SYS_MPC85xx_GUTS_ADDR;
Shengzhou Liud11b3cb2014-04-18 16:43:39 +080071
72 /* Memcpy existing GD at CONFIG_SPL_GD_ADDR */
73 memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
74
75 /* Update GD pointer */
76 gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
77
78 console_init_f();
79
80 /* initialize selected port with appropriate baud rate */
81 sys_clk = get_board_sys_clk();
82 plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
83 ccb_clk = sys_clk * plat_ratio / 2;
84
Tom Rinidf6a2152022-11-16 13:10:28 -050085 ns16550_init((struct ns16550 *)CFG_SYS_NS16550_COM1,
Shengzhou Liud11b3cb2014-04-18 16:43:39 +080086 ccb_clk / 16 / CONFIG_BAUDRATE);
87
88#if defined(CONFIG_SPL_MMC_BOOT)
89 puts("\nSD boot...\n");
90#elif defined(CONFIG_SPL_SPI_BOOT)
91 puts("\nSPI boot...\n");
92#elif defined(CONFIG_SPL_NAND_BOOT)
93 puts("\nNAND boot...\n");
94#endif
95
96 relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
97}
98
99void board_init_r(gd_t *gd, ulong dest_addr)
100{
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900101 struct bd_info *bd;
Shengzhou Liud11b3cb2014-04-18 16:43:39 +0800102
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900103 bd = (struct bd_info *)(gd + sizeof(gd_t));
104 memset(bd, 0, sizeof(struct bd_info));
Shengzhou Liud11b3cb2014-04-18 16:43:39 +0800105 gd->bd = bd;
Shengzhou Liud11b3cb2014-04-18 16:43:39 +0800106
Simon Glass302445a2017-01-23 13:31:22 -0700107 arch_cpu_init();
Shengzhou Liud11b3cb2014-04-18 16:43:39 +0800108 get_clocks();
109 mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
110 CONFIG_SPL_RELOC_MALLOC_SIZE);
Sumit Garg2ff056b2016-05-25 12:41:48 -0400111 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
Shengzhou Liud11b3cb2014-04-18 16:43:39 +0800112
113#ifdef CONFIG_SPL_NAND_BOOT
114 nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
Tom Rini5cd7ece2019-11-18 20:02:10 -0500115 (uchar *)SPL_ENV_ADDR);
Shengzhou Liud11b3cb2014-04-18 16:43:39 +0800116#endif
117#ifdef CONFIG_SPL_MMC_BOOT
118 mmc_initialize(bd);
119 mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
Tom Rini5cd7ece2019-11-18 20:02:10 -0500120 (uchar *)SPL_ENV_ADDR);
Shengzhou Liud11b3cb2014-04-18 16:43:39 +0800121#endif
122#ifdef CONFIG_SPL_SPI_BOOT
Simon Glassdd8e2242016-09-24 18:20:10 -0600123 fsl_spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
Tom Rini5cd7ece2019-11-18 20:02:10 -0500124 (uchar *)SPL_ENV_ADDR);
Shengzhou Liud11b3cb2014-04-18 16:43:39 +0800125#endif
126
Tom Rini5cd7ece2019-11-18 20:02:10 -0500127 gd->env_addr = (ulong)(SPL_ENV_ADDR);
Simon Glass4bc2ad22017-08-03 12:21:56 -0600128 gd->env_valid = ENV_VALID;
Shengzhou Liud11b3cb2014-04-18 16:43:39 +0800129
130 i2c_init_all();
131
Simon Glassd35f3382017-04-06 12:47:05 -0600132 dram_init();
Shengzhou Liud11b3cb2014-04-18 16:43:39 +0800133
134#ifdef CONFIG_SPL_MMC_BOOT
135 mmc_boot();
136#elif defined(CONFIG_SPL_SPI_BOOT)
Simon Glassdd8e2242016-09-24 18:20:10 -0600137 fsl_spi_boot();
Shengzhou Liud11b3cb2014-04-18 16:43:39 +0800138#elif defined(CONFIG_SPL_NAND_BOOT)
139 nand_boot();
140#endif
141}