blob: 7cb840346c8a7e395bb5b693ab03b922bbf8760a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChung Liew05316f82008-08-11 13:41:49 +00002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wang198cafb2012-03-26 21:49:08 +00006 * Copyright (C) 2004-2008, 2012 Freescale Semiconductor, Inc.
TsiChung Liew05316f82008-08-11 13:41:49 +00007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChung Liew05316f82008-08-11 13:41:49 +00008 */
9
10#include <common.h>
11#include <spi.h>
12#include <asm/immap.h>
Alison Wang198cafb2012-03-26 21:49:08 +000013#include <asm/io.h>
TsiChung Liew05316f82008-08-11 13:41:49 +000014
15DECLARE_GLOBAL_DATA_PTR;
16
17int checkboard(void)
18{
19 /*
20 * need to to:
21 * Check serial flash size. if 2mb evb, else 8mb demo
22 */
23 puts("Board: ");
24 puts("Freescale M54451 EVB\n");
25 return 0;
26};
27
Simon Glassf1683aa2017-04-06 12:47:05 -060028int dram_init(void)
TsiChung Liew05316f82008-08-11 13:41:49 +000029{
30 u32 dramsize;
31#ifdef CONFIG_CF_SBF
32 /*
33 * Serial Boot: The dram is already initialized in start.S
34 * only require to return DRAM size
35 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020036 dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
TsiChung Liew05316f82008-08-11 13:41:49 +000037#else
Alison Wang198cafb2012-03-26 21:49:08 +000038 sdramc_t *sdram = (sdramc_t *)(MMAP_SDRAM);
39 gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
TsiChung Liew05316f82008-08-11 13:41:49 +000040 u32 i;
41
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020042 dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
TsiChung Liew05316f82008-08-11 13:41:49 +000043
Alison Wang198cafb2012-03-26 21:49:08 +000044 if ((in_be32(&sdram->sdcfg1) == CONFIG_SYS_SDRAM_CFG1) &&
45 (in_be32(&sdram->sdcfg2) == CONFIG_SYS_SDRAM_CFG2))
TsiChung Liew05316f82008-08-11 13:41:49 +000046 return dramsize;
47
48 for (i = 0x13; i < 0x20; i++) {
49 if (dramsize == (1 << i))
50 break;
51 }
52 i--;
53
Alison Wang198cafb2012-03-26 21:49:08 +000054 out_8(&gpio->mscr_sdram, CONFIG_SYS_SDRAM_DRV_STRENGTH);
TsiChung Liew05316f82008-08-11 13:41:49 +000055
Alison Wang198cafb2012-03-26 21:49:08 +000056 out_be32(&sdram->sdcs0, CONFIG_SYS_SDRAM_BASE | i);
TsiChung Liew05316f82008-08-11 13:41:49 +000057
Alison Wang198cafb2012-03-26 21:49:08 +000058 out_be32(&sdram->sdcfg1, CONFIG_SYS_SDRAM_CFG1);
59 out_be32(&sdram->sdcfg2, CONFIG_SYS_SDRAM_CFG2);
TsiChung Liew05316f82008-08-11 13:41:49 +000060
61 udelay(200);
62
63 /* Issue PALL */
Alison Wang198cafb2012-03-26 21:49:08 +000064 out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
TsiChung Liew05316f82008-08-11 13:41:49 +000065 __asm__("nop");
66
67 /* Perform two refresh cycles */
Alison Wang198cafb2012-03-26 21:49:08 +000068 out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
TsiChung Liew05316f82008-08-11 13:41:49 +000069 __asm__("nop");
Alison Wang198cafb2012-03-26 21:49:08 +000070 out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
TsiChung Liew05316f82008-08-11 13:41:49 +000071 __asm__("nop");
72
73 /* Issue LEMR */
Alison Wang198cafb2012-03-26 21:49:08 +000074 out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE);
TsiChung Liew05316f82008-08-11 13:41:49 +000075 __asm__("nop");
Alison Wang198cafb2012-03-26 21:49:08 +000076 out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE);
TsiChung Liew05316f82008-08-11 13:41:49 +000077 __asm__("nop");
78
Alison Wang198cafb2012-03-26 21:49:08 +000079 out_be32(&sdram->sdcr,
80 (CONFIG_SYS_SDRAM_CTRL & ~0x80000000) | 0x10000000);
TsiChung Liew05316f82008-08-11 13:41:49 +000081
82 udelay(100);
83#endif
Simon Glass088454c2017-03-31 08:40:25 -060084 gd->ram_size = dramsize;
85
86 return 0;
TsiChung Liew05316f82008-08-11 13:41:49 +000087};
88
89int testdram(void)
90{
91 /* TODO: XXX XXX XXX */
92 printf("DRAM test not implemented!\n");
93
94 return (0);
95}