blob: bb02dab2f1539fdd103aee35c42d5abab37aa2d7 [file] [log] [blame]
Shengzhou Liub19e2882014-04-18 16:43:39 +08001/* Copyright 2013 Freescale Semiconductor, Inc.
2 *
3 * SPDX-License-Identifier: GPL-2.0+
4 */
5
6#include <common.h>
Simon Glass24b852a2015-11-08 23:47:45 -07007#include <console.h>
Shengzhou Liub19e2882014-04-18 16:43:39 +08008#include <malloc.h>
9#include <ns16550.h>
10#include <nand.h>
11#include <i2c.h>
12#include <mmc.h>
13#include <fsl_esdhc.h>
14#include <spi_flash.h>
15#include "../common/qixis.h"
16#include "t208xqds_qixis.h"
17
18DECLARE_GLOBAL_DATA_PTR;
19
20phys_size_t get_effective_memsize(void)
21{
22 return CONFIG_SYS_L3_SIZE;
23}
24
25unsigned long get_board_sys_clk(void)
26{
27 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
28
29 switch (sysclk_conf & 0x0F) {
30 case QIXIS_SYSCLK_83:
31 return 83333333;
32 case QIXIS_SYSCLK_100:
33 return 100000000;
34 case QIXIS_SYSCLK_125:
35 return 125000000;
36 case QIXIS_SYSCLK_133:
37 return 133333333;
38 case QIXIS_SYSCLK_150:
39 return 150000000;
40 case QIXIS_SYSCLK_160:
41 return 160000000;
42 case QIXIS_SYSCLK_166:
43 return 166666666;
44 }
45 return 66666666;
46}
47
48unsigned long get_board_ddr_clk(void)
49{
50 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
51
52 switch ((ddrclk_conf & 0x30) >> 4) {
53 case QIXIS_DDRCLK_100:
54 return 100000000;
55 case QIXIS_DDRCLK_125:
56 return 125000000;
57 case QIXIS_DDRCLK_133:
58 return 133333333;
59 }
60 return 66666666;
61}
62
63void board_init_f(ulong bootflag)
64{
65 u32 plat_ratio, sys_clk, ccb_clk;
66 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
67
68 /* Memcpy existing GD at CONFIG_SPL_GD_ADDR */
69 memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
70
71 /* Update GD pointer */
72 gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
73
74 console_init_f();
75
76 /* initialize selected port with appropriate baud rate */
77 sys_clk = get_board_sys_clk();
78 plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f;
79 ccb_clk = sys_clk * plat_ratio / 2;
80
81 NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
82 ccb_clk / 16 / CONFIG_BAUDRATE);
83
84#if defined(CONFIG_SPL_MMC_BOOT)
85 puts("\nSD boot...\n");
86#elif defined(CONFIG_SPL_SPI_BOOT)
87 puts("\nSPI boot...\n");
88#elif defined(CONFIG_SPL_NAND_BOOT)
89 puts("\nNAND boot...\n");
90#endif
91
92 relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0);
93}
94
95void board_init_r(gd_t *gd, ulong dest_addr)
96{
97 bd_t *bd;
98
99 bd = (bd_t *)(gd + sizeof(gd_t));
100 memset(bd, 0, sizeof(bd_t));
101 gd->bd = bd;
102 bd->bi_memstart = CONFIG_SYS_INIT_L3_ADDR;
103 bd->bi_memsize = CONFIG_SYS_L3_SIZE;
104
105 probecpu();
106 get_clocks();
107 mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
108 CONFIG_SPL_RELOC_MALLOC_SIZE);
Sumit Garged4708a2016-05-25 12:41:48 -0400109 gd->flags |= GD_FLG_FULL_MALLOC_INIT;
Shengzhou Liub19e2882014-04-18 16:43:39 +0800110
111#ifdef CONFIG_SPL_NAND_BOOT
112 nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
113 (uchar *)CONFIG_ENV_ADDR);
114#endif
115#ifdef CONFIG_SPL_MMC_BOOT
116 mmc_initialize(bd);
117 mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
118 (uchar *)CONFIG_ENV_ADDR);
119#endif
120#ifdef CONFIG_SPL_SPI_BOOT
121 spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
122 (uchar *)CONFIG_ENV_ADDR);
123#endif
124
125 gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
126 gd->env_valid = 1;
127
128 i2c_init_all();
129
130 gd->ram_size = initdram(0);
131
132#ifdef CONFIG_SPL_MMC_BOOT
133 mmc_boot();
134#elif defined(CONFIG_SPL_SPI_BOOT)
135 spi_boot();
136#elif defined(CONFIG_SPL_NAND_BOOT)
137 nand_boot();
138#endif
139}