11552af70STsiChungLiew /*
21552af70STsiChungLiew  * (C) Copyright 2000-2003
31552af70STsiChungLiew  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
41552af70STsiChungLiew  *
5849fc424SAlison Wang  * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
61552af70STsiChungLiew  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
71552af70STsiChungLiew  *
81a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
91552af70STsiChungLiew  */
101552af70STsiChungLiew 
111552af70STsiChungLiew #include <common.h>
121552af70STsiChungLiew #include <asm/immap.h>
13849fc424SAlison Wang #include <asm/io.h>
141552af70STsiChungLiew 
151552af70STsiChungLiew DECLARE_GLOBAL_DATA_PTR;
161552af70STsiChungLiew 
171552af70STsiChungLiew int checkboard(void)
181552af70STsiChungLiew {
191552af70STsiChungLiew 	puts("Board: ");
201552af70STsiChungLiew 	puts("Freescale M52277 EVB\n");
211552af70STsiChungLiew 	return 0;
221552af70STsiChungLiew };
231552af70STsiChungLiew 
24*f1683aa7SSimon Glass int dram_init(void)
251552af70STsiChungLiew {
26a21d0c2cSTsiChung Liew 	u32 dramsize;
27a21d0c2cSTsiChung Liew 
28a21d0c2cSTsiChung Liew #ifdef CONFIG_CF_SBF
29a21d0c2cSTsiChung Liew 	/*
30a21d0c2cSTsiChung Liew 	 * Serial Boot: The dram is already initialized in start.S
31a21d0c2cSTsiChung Liew 	 * only require to return DRAM size
32a21d0c2cSTsiChung Liew 	 */
33a21d0c2cSTsiChung Liew 	dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
34a21d0c2cSTsiChung Liew #else
35849fc424SAlison Wang 	sdramc_t *sdram = (sdramc_t *)(MMAP_SDRAM);
36849fc424SAlison Wang 	gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
37a21d0c2cSTsiChung Liew 	u32 i;
381552af70STsiChungLiew 
396d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
401552af70STsiChungLiew 
411552af70STsiChungLiew 	for (i = 0x13; i < 0x20; i++) {
421552af70STsiChungLiew 		if (dramsize == (1 << i))
431552af70STsiChungLiew 			break;
441552af70STsiChungLiew 	}
451552af70STsiChungLiew 	i--;
461552af70STsiChungLiew 
47849fc424SAlison Wang 	out_8(&gpio->mscr_sdram, CONFIG_SYS_SDRAM_DRV_STRENGTH);
48a21d0c2cSTsiChung Liew 
49849fc424SAlison Wang 	out_be32(&sdram->sdcs0, CONFIG_SYS_SDRAM_BASE | i);
501552af70STsiChungLiew 
51849fc424SAlison Wang 	out_be32(&sdram->sdcfg1, CONFIG_SYS_SDRAM_CFG1);
52849fc424SAlison Wang 	out_be32(&sdram->sdcfg2, CONFIG_SYS_SDRAM_CFG2);
531552af70STsiChungLiew 
541552af70STsiChungLiew 	/* Issue PALL */
55849fc424SAlison Wang 	out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
56a21d0c2cSTsiChung Liew 	__asm__("nop");
571552af70STsiChungLiew 
581552af70STsiChungLiew 	/* Issue LEMR */
59849fc424SAlison Wang 	out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE);
60a21d0c2cSTsiChung Liew 	__asm__("nop");
61849fc424SAlison Wang 	out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_EMOD);
62a21d0c2cSTsiChung Liew 	__asm__("nop");
631552af70STsiChungLiew 
641552af70STsiChungLiew 	udelay(1000);
651552af70STsiChungLiew 
661552af70STsiChungLiew 	/* Issue PALL */
67849fc424SAlison Wang 	out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
68a21d0c2cSTsiChung Liew 	__asm__("nop");
691552af70STsiChungLiew 
701552af70STsiChungLiew 	/* Perform two refresh cycles */
71849fc424SAlison Wang 	out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
72a21d0c2cSTsiChung Liew 	__asm__("nop");
73849fc424SAlison Wang 	out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
74a21d0c2cSTsiChung Liew 	__asm__("nop");
751552af70STsiChungLiew 
76849fc424SAlison Wang 	out_be32(&sdram->sdcr,
77849fc424SAlison Wang 		(CONFIG_SYS_SDRAM_CTRL & ~0x80000000) | 0x10000c00);
781552af70STsiChungLiew 
791552af70STsiChungLiew 	udelay(100);
80a21d0c2cSTsiChung Liew #endif
81088454cdSSimon Glass 	gd->ram_size = dramsize;
82088454cdSSimon Glass 
83088454cdSSimon Glass 	return 0;
841552af70STsiChungLiew };
851552af70STsiChungLiew 
861552af70STsiChungLiew int testdram(void)
871552af70STsiChungLiew {
881552af70STsiChungLiew 	/* TODO: XXX XXX XXX */
891552af70STsiChungLiew 	printf("DRAM test not implemented!\n");
901552af70STsiChungLiew 
911552af70STsiChungLiew 	return (0);
921552af70STsiChungLiew }
93