blob: dd56ad6b2b3454ade4da5c91af413d5766fa8c46 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwaha83e0c2b2013-04-16 13:28:40 +05302/*
3 * Copyright 2013 Freescale Semiconductor, Inc.
Prabhakar Kushwaha83e0c2b2013-04-16 13:28:40 +05304 */
5
6#include <common.h>
Simon Glass94133872019-12-28 10:44:45 -07007#include <init.h>
Prabhakar Kushwaha83e0c2b2013-04-16 13:28:40 +05308#include <ns16550.h>
9#include <asm/io.h>
10#include <nand.h>
11#include <linux/compiler.h>
12#include <asm/fsl_law.h>
York Sun5614e712013-09-30 09:22:09 -070013#include <fsl_ddr_sdram.h>
Prabhakar Kushwaha83e0c2b2013-04-16 13:28:40 +053014#include <asm/global_data.h>
Simon Glassc05ed002020-05-10 11:40:11 -060015#include <linux/delay.h>
Prabhakar Kushwaha83e0c2b2013-04-16 13:28:40 +053016
17DECLARE_GLOBAL_DATA_PTR;
18
19static void sdram_init(void)
20{
York Sun9a17eb52013-11-18 10:29:32 -080021 struct ccsr_ddr __iomem *ddr =
22 (struct ccsr_ddr __iomem *)CONFIG_SYS_FSL_DDR_ADDR;
Prabhakar Kushwaha83e0c2b2013-04-16 13:28:40 +053023#if CONFIG_DDR_CLK_FREQ == 100000000
24 __raw_writel(CONFIG_SYS_DDR_CS0_BNDS, &ddr->cs0_bnds);
25 __raw_writel(CONFIG_SYS_DDR_CS0_CONFIG, &ddr->cs0_config);
26 __raw_writel(CONFIG_SYS_DDR_CONTROL_800 | SDRAM_CFG_32_BE, &ddr->sdram_cfg);
27 __raw_writel(CONFIG_SYS_DDR_CONTROL_2_800, &ddr->sdram_cfg_2);
28 __raw_writel(CONFIG_SYS_DDR_DATA_INIT, &ddr->sdram_data_init);
29
30 __raw_writel(CONFIG_SYS_DDR_TIMING_3_800, &ddr->timing_cfg_3);
31 __raw_writel(CONFIG_SYS_DDR_TIMING_0_800, &ddr->timing_cfg_0);
32 __raw_writel(CONFIG_SYS_DDR_TIMING_1_800, &ddr->timing_cfg_1);
33 __raw_writel(CONFIG_SYS_DDR_TIMING_2_800, &ddr->timing_cfg_2);
34 __raw_writel(CONFIG_SYS_DDR_MODE_1_800, &ddr->sdram_mode);
35 __raw_writel(CONFIG_SYS_DDR_MODE_2_800, &ddr->sdram_mode_2);
36 __raw_writel(CONFIG_SYS_DDR_INTERVAL_800, &ddr->sdram_interval);
37 __raw_writel(CONFIG_SYS_DDR_CLK_CTRL_800, &ddr->sdram_clk_cntl);
38 __raw_writel(CONFIG_SYS_DDR_WRLVL_CONTROL_800, &ddr->ddr_wrlvl_cntl);
39
40 __raw_writel(CONFIG_SYS_DDR_TIMING_4_800, &ddr->timing_cfg_4);
41 __raw_writel(CONFIG_SYS_DDR_TIMING_5_800, &ddr->timing_cfg_5);
42 __raw_writel(CONFIG_SYS_DDR_ZQ_CONTROL, &ddr->ddr_zq_cntl);
43#elif CONFIG_DDR_CLK_FREQ == 133000000
44 __raw_writel(CONFIG_SYS_DDR_CS0_BNDS, &ddr->cs0_bnds);
45 __raw_writel(CONFIG_SYS_DDR_CS0_CONFIG, &ddr->cs0_config);
46 __raw_writel(CONFIG_SYS_DDR_CONTROL_1333 | SDRAM_CFG_32_BE, &ddr->sdram_cfg);
47 __raw_writel(CONFIG_SYS_DDR_CONTROL_2_1333, &ddr->sdram_cfg_2);
48 __raw_writel(CONFIG_SYS_DDR_DATA_INIT, &ddr->sdram_data_init);
49
50 __raw_writel(CONFIG_SYS_DDR_TIMING_3_1333, &ddr->timing_cfg_3);
51 __raw_writel(CONFIG_SYS_DDR_TIMING_0_1333, &ddr->timing_cfg_0);
52 __raw_writel(CONFIG_SYS_DDR_TIMING_1_1333, &ddr->timing_cfg_1);
53 __raw_writel(CONFIG_SYS_DDR_TIMING_2_1333, &ddr->timing_cfg_2);
54 __raw_writel(CONFIG_SYS_DDR_MODE_1_1333, &ddr->sdram_mode);
55 __raw_writel(CONFIG_SYS_DDR_MODE_2_1333, &ddr->sdram_mode_2);
56 __raw_writel(CONFIG_SYS_DDR_INTERVAL_1333, &ddr->sdram_interval);
57 __raw_writel(CONFIG_SYS_DDR_CLK_CTRL_1333, &ddr->sdram_clk_cntl);
58 __raw_writel(CONFIG_SYS_DDR_WRLVL_CONTROL_1333, &ddr->ddr_wrlvl_cntl);
59
60 __raw_writel(CONFIG_SYS_DDR_TIMING_4_1333, &ddr->timing_cfg_4);
61 __raw_writel(CONFIG_SYS_DDR_TIMING_5_1333, &ddr->timing_cfg_5);
62 __raw_writel(CONFIG_SYS_DDR_ZQ_CONTROL, &ddr->ddr_zq_cntl);
63#else
64 puts("Not a valid DDR Freq Found! Please Reset\n");
65#endif
66 asm volatile("sync;isync");
67 udelay(500);
68
69 /* Let the controller go */
70 out_be32(&ddr->sdram_cfg, in_be32(&ddr->sdram_cfg) | SDRAM_CFG_MEM_EN);
71
72 set_next_law(CONFIG_SYS_NAND_DDR_LAW, LAW_SIZE_1G, LAW_TRGT_IF_DDR_1);
73}
74
75void board_init_f(ulong bootflag)
76{
77 u32 plat_ratio;
78 ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
79
80 /* initialize selected port with appropriate baud rate */
81 plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
82 plat_ratio >>= 1;
83 gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
84
85 NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
86 gd->bus_clk / 16 / CONFIG_BAUDRATE);
87
88 puts("\nNAND boot... ");
89
90 /* Initialize the DDR3 */
91 sdram_init();
92
93 /* copy code to RAM and jump to it - this should not return */
94 /* NOTE - code has to be copied out of NAND buffer before
95 * other blocks can be read.
96 */
97 relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
98}
99
100void board_init_r(gd_t *gd, ulong dest_addr)
101{
102 nand_boot();
103}
104
105void putc(char c)
106{
107 if (c == '\n')
108 NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r');
109
110 NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c);
111}
112
113void puts(const char *str)
114{
115 while (*str)
116 putc(*str++);
117}