105316f8eSTsiChung Liew /*
205316f8eSTsiChung Liew * (C) Copyright 2000-2003
305316f8eSTsiChung Liew * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
405316f8eSTsiChung Liew *
5198cafbfSAlison Wang * Copyright (C) 2004-2008, 2012 Freescale Semiconductor, Inc.
605316f8eSTsiChung Liew * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
705316f8eSTsiChung Liew *
81a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+
905316f8eSTsiChung Liew */
1005316f8eSTsiChung Liew
1105316f8eSTsiChung Liew #include <common.h>
1205316f8eSTsiChung Liew #include <spi.h>
1305316f8eSTsiChung Liew #include <asm/immap.h>
14198cafbfSAlison Wang #include <asm/io.h>
1505316f8eSTsiChung Liew
1605316f8eSTsiChung Liew DECLARE_GLOBAL_DATA_PTR;
1705316f8eSTsiChung Liew
checkboard(void)1805316f8eSTsiChung Liew int checkboard(void)
1905316f8eSTsiChung Liew {
2005316f8eSTsiChung Liew /*
2105316f8eSTsiChung Liew * need to to:
2205316f8eSTsiChung Liew * Check serial flash size. if 2mb evb, else 8mb demo
2305316f8eSTsiChung Liew */
2405316f8eSTsiChung Liew puts("Board: ");
2505316f8eSTsiChung Liew puts("Freescale M54451 EVB\n");
2605316f8eSTsiChung Liew return 0;
2705316f8eSTsiChung Liew };
2805316f8eSTsiChung Liew
dram_init(void)29*f1683aa7SSimon Glass int dram_init(void)
3005316f8eSTsiChung Liew {
3105316f8eSTsiChung Liew u32 dramsize;
3205316f8eSTsiChung Liew #ifdef CONFIG_CF_SBF
3305316f8eSTsiChung Liew /*
3405316f8eSTsiChung Liew * Serial Boot: The dram is already initialized in start.S
3505316f8eSTsiChung Liew * only require to return DRAM size
3605316f8eSTsiChung Liew */
376d0f6bcfSJean-Christophe PLAGNIOL-VILLARD dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
3805316f8eSTsiChung Liew #else
39198cafbfSAlison Wang sdramc_t *sdram = (sdramc_t *)(MMAP_SDRAM);
40198cafbfSAlison Wang gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
4105316f8eSTsiChung Liew u32 i;
4205316f8eSTsiChung Liew
436d0f6bcfSJean-Christophe PLAGNIOL-VILLARD dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
4405316f8eSTsiChung Liew
45198cafbfSAlison Wang if ((in_be32(&sdram->sdcfg1) == CONFIG_SYS_SDRAM_CFG1) &&
46198cafbfSAlison Wang (in_be32(&sdram->sdcfg2) == CONFIG_SYS_SDRAM_CFG2))
4705316f8eSTsiChung Liew return dramsize;
4805316f8eSTsiChung Liew
4905316f8eSTsiChung Liew for (i = 0x13; i < 0x20; i++) {
5005316f8eSTsiChung Liew if (dramsize == (1 << i))
5105316f8eSTsiChung Liew break;
5205316f8eSTsiChung Liew }
5305316f8eSTsiChung Liew i--;
5405316f8eSTsiChung Liew
55198cafbfSAlison Wang out_8(&gpio->mscr_sdram, CONFIG_SYS_SDRAM_DRV_STRENGTH);
5605316f8eSTsiChung Liew
57198cafbfSAlison Wang out_be32(&sdram->sdcs0, CONFIG_SYS_SDRAM_BASE | i);
5805316f8eSTsiChung Liew
59198cafbfSAlison Wang out_be32(&sdram->sdcfg1, CONFIG_SYS_SDRAM_CFG1);
60198cafbfSAlison Wang out_be32(&sdram->sdcfg2, CONFIG_SYS_SDRAM_CFG2);
6105316f8eSTsiChung Liew
6205316f8eSTsiChung Liew udelay(200);
6305316f8eSTsiChung Liew
6405316f8eSTsiChung Liew /* Issue PALL */
65198cafbfSAlison Wang out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
6605316f8eSTsiChung Liew __asm__("nop");
6705316f8eSTsiChung Liew
6805316f8eSTsiChung Liew /* Perform two refresh cycles */
69198cafbfSAlison Wang out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
7005316f8eSTsiChung Liew __asm__("nop");
71198cafbfSAlison Wang out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
7205316f8eSTsiChung Liew __asm__("nop");
7305316f8eSTsiChung Liew
7405316f8eSTsiChung Liew /* Issue LEMR */
75198cafbfSAlison Wang out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE);
7605316f8eSTsiChung Liew __asm__("nop");
77198cafbfSAlison Wang out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE);
7805316f8eSTsiChung Liew __asm__("nop");
7905316f8eSTsiChung Liew
80198cafbfSAlison Wang out_be32(&sdram->sdcr,
81198cafbfSAlison Wang (CONFIG_SYS_SDRAM_CTRL & ~0x80000000) | 0x10000000);
8205316f8eSTsiChung Liew
8305316f8eSTsiChung Liew udelay(100);
8405316f8eSTsiChung Liew #endif
85088454cdSSimon Glass gd->ram_size = dramsize;
86088454cdSSimon Glass
87088454cdSSimon Glass return 0;
8805316f8eSTsiChung Liew };
8905316f8eSTsiChung Liew
testdram(void)9005316f8eSTsiChung Liew int testdram(void)
9105316f8eSTsiChung Liew {
9205316f8eSTsiChung Liew /* TODO: XXX XXX XXX */
9305316f8eSTsiChung Liew printf("DRAM test not implemented!\n");
9405316f8eSTsiChung Liew
9505316f8eSTsiChung Liew return (0);
9605316f8eSTsiChung Liew }
97