194a45bb1SScott Wood /*
294a45bb1SScott Wood  * Copyright 2011 Freescale Semiconductor, Inc.
394a45bb1SScott Wood  *
494a45bb1SScott Wood  * This program is free software; you can redistribute it and/or
594a45bb1SScott Wood  * modify it under the terms of the GNU General Public License as
694a45bb1SScott Wood  * published by the Free Software Foundation; either version 2 of
794a45bb1SScott Wood  * the License, or (at your option) any later version.
894a45bb1SScott Wood  *
994a45bb1SScott Wood  * This program is distributed in the hope that it will be useful,
1094a45bb1SScott Wood  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1194a45bb1SScott Wood  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1294a45bb1SScott Wood  *
1394a45bb1SScott Wood  * GNU General Public License for more details.
1494a45bb1SScott Wood  *
1594a45bb1SScott Wood  * You should have received a copy of the GNU General Public License
1694a45bb1SScott Wood  * along with this program; if not, write to the Free Software
1794a45bb1SScott Wood  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
1894a45bb1SScott Wood  * MA 02111-1307 USA
1994a45bb1SScott Wood  *
2094a45bb1SScott Wood  */
2194a45bb1SScott Wood 
2294a45bb1SScott Wood #include <common.h>
2394a45bb1SScott Wood #include <ns16550.h>
2494a45bb1SScott Wood #include <asm/io.h>
2594a45bb1SScott Wood #include <nand.h>
26*13d1143fSScott Wood #include <linux/compiler.h>
2794a45bb1SScott Wood #include <asm/fsl_law.h>
2894a45bb1SScott Wood #include <asm/fsl_ddr_sdram.h>
2994a45bb1SScott Wood #include <asm/global_data.h>
3094a45bb1SScott Wood 
3194a45bb1SScott Wood DECLARE_GLOBAL_DATA_PTR;
3294a45bb1SScott Wood 
33*13d1143fSScott Wood #ifndef CONFIG_SYS_INIT_L2_ADDR
3494a45bb1SScott Wood /*
3594a45bb1SScott Wood  * Fixed sdram init -- doesn't use serial presence detect.
3694a45bb1SScott Wood  */
37*13d1143fSScott Wood static void sdram_init(void)
3894a45bb1SScott Wood {
3994a45bb1SScott Wood 	ccsr_ddr_t *ddr = (ccsr_ddr_t *)CONFIG_SYS_MPC85xx_DDR_ADDR;
4094a45bb1SScott Wood 
4194a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_CS0_BNDS, &ddr->cs0_bnds);
4294a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_CS0_CONFIG, &ddr->cs0_config);
4394a45bb1SScott Wood #if CONFIG_CHIP_SELECTS_PER_CTRL > 1
4494a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_CS1_BNDS, &ddr->cs1_bnds);
4594a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_CS1_CONFIG, &ddr->cs1_config);
4694a45bb1SScott Wood #endif
4794a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_TIMING_3, &ddr->timing_cfg_3);
4894a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_TIMING_0, &ddr->timing_cfg_0);
4994a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_TIMING_1, &ddr->timing_cfg_1);
5094a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_TIMING_2, &ddr->timing_cfg_2);
5194a45bb1SScott Wood 
5294a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_CONTROL_2, &ddr->sdram_cfg_2);
5394a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_MODE_1, &ddr->sdram_mode);
5494a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_MODE_2, &ddr->sdram_mode_2);
5594a45bb1SScott Wood 
5694a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_INTERVAL, &ddr->sdram_interval);
5794a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_DATA_INIT, &ddr->sdram_data_init);
5894a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_CLK_CTRL, &ddr->sdram_clk_cntl);
5994a45bb1SScott Wood 
6094a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_TIMING_4, &ddr->timing_cfg_4);
6194a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_TIMING_5, &ddr->timing_cfg_5);
6294a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_ZQ_CONTROL, &ddr->ddr_zq_cntl);
6394a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_WRLVL_CONTROL, &ddr->ddr_wrlvl_cntl);
6494a45bb1SScott Wood 
6594a45bb1SScott Wood 	/* Set, but do not enable the memory */
6694a45bb1SScott Wood 	__raw_writel(CONFIG_SYS_DDR_CONTROL & ~SDRAM_CFG_MEM_EN, &ddr->sdram_cfg);
6794a45bb1SScott Wood 
6894a45bb1SScott Wood 	asm volatile("sync;isync");
6994a45bb1SScott Wood 	udelay(500);
7094a45bb1SScott Wood 
7194a45bb1SScott Wood 	/* Let the controller go */
7294a45bb1SScott Wood 	out_be32(&ddr->sdram_cfg, in_be32(&ddr->sdram_cfg) | SDRAM_CFG_MEM_EN);
7394a45bb1SScott Wood 
7494a45bb1SScott Wood 	set_next_law(0, CONFIG_SYS_SDRAM_SIZE_LAW, LAW_TRGT_IF_DDR_1);
7594a45bb1SScott Wood }
76*13d1143fSScott Wood #endif
7794a45bb1SScott Wood 
7894a45bb1SScott Wood void board_init_f(ulong bootflag)
7994a45bb1SScott Wood {
8094a45bb1SScott Wood 	u32 plat_ratio;
8194a45bb1SScott Wood 	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
8294a45bb1SScott Wood #ifndef CONFIG_QE
8394a45bb1SScott Wood 	ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
8494a45bb1SScott Wood #endif
8594a45bb1SScott Wood 
8694a45bb1SScott Wood 	/* initialize selected port with appropriate baud rate */
8794a45bb1SScott Wood 	plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
8894a45bb1SScott Wood 	plat_ratio >>= 1;
8994a45bb1SScott Wood 	gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
9094a45bb1SScott Wood 
9194a45bb1SScott Wood 	NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
9294a45bb1SScott Wood 			gd->bus_clk / 16 / CONFIG_BAUDRATE);
9394a45bb1SScott Wood 
9494a45bb1SScott Wood 	puts("\nNAND boot... ");
9594a45bb1SScott Wood 
9694a45bb1SScott Wood #ifndef CONFIG_QE
9794a45bb1SScott Wood 	/* init DDR3 reset signal */
9894a45bb1SScott Wood 	__raw_writel(0x02000000, &pgpio->gpdir);
9994a45bb1SScott Wood 	__raw_writel(0x00200000, &pgpio->gpodr);
10094a45bb1SScott Wood 	__raw_writel(0x00000000, &pgpio->gpdat);
10194a45bb1SScott Wood 	udelay(1000);
10294a45bb1SScott Wood 	__raw_writel(0x00200000, &pgpio->gpdat);
10394a45bb1SScott Wood 	udelay(1000);
10494a45bb1SScott Wood 	__raw_writel(0x00000000, &pgpio->gpdir);
10594a45bb1SScott Wood #endif
10694a45bb1SScott Wood 
107*13d1143fSScott Wood #ifndef CONFIG_SYS_INIT_L2_ADDR
10894a45bb1SScott Wood 	/* Initialize the DDR3 */
10994a45bb1SScott Wood 	sdram_init();
110*13d1143fSScott Wood #endif
11194a45bb1SScott Wood 
11294a45bb1SScott Wood 	/* copy code to RAM and jump to it - this should not return */
11394a45bb1SScott Wood 	/* NOTE - code has to be copied out of NAND buffer before
11494a45bb1SScott Wood 	 * other blocks can be read.
11594a45bb1SScott Wood 	 */
11694a45bb1SScott Wood 	relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
11794a45bb1SScott Wood }
11894a45bb1SScott Wood 
11994a45bb1SScott Wood void board_init_r(gd_t *gd, ulong dest_addr)
12094a45bb1SScott Wood {
12194a45bb1SScott Wood 	nand_boot();
12294a45bb1SScott Wood }
12394a45bb1SScott Wood 
12494a45bb1SScott Wood void putc(char c)
12594a45bb1SScott Wood {
12694a45bb1SScott Wood 	if (c == '\n')
12794a45bb1SScott Wood 		NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r');
12894a45bb1SScott Wood 
12994a45bb1SScott Wood 	NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c);
13094a45bb1SScott Wood }
13194a45bb1SScott Wood 
13294a45bb1SScott Wood void puts(const char *str)
13394a45bb1SScott Wood {
13494a45bb1SScott Wood 	while (*str)
13594a45bb1SScott Wood 		putc(*str++);
13694a45bb1SScott Wood }
137