Merge branch 'master' of git://git.denx.de/u-boot
[oweals/u-boot.git] / board / freescale / m54451evb / m54451evb.c
1 /*
2  * (C) Copyright 2000-2003
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * Copyright (C) 2004-2008, 2012 Freescale Semiconductor, Inc.
6  * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
7  *
8  * SPDX-License-Identifier:     GPL-2.0+
9  */
10
11 #include <common.h>
12 #include <spi.h>
13 #include <asm/immap.h>
14 #include <asm/io.h>
15
16 DECLARE_GLOBAL_DATA_PTR;
17
18 int checkboard(void)
19 {
20         /*
21          * need to to:
22          * Check serial flash size. if 2mb evb, else 8mb demo
23          */
24         puts("Board: ");
25         puts("Freescale M54451 EVB\n");
26         return 0;
27 };
28
29 phys_size_t initdram(int board_type)
30 {
31         u32 dramsize;
32 #ifdef CONFIG_CF_SBF
33         /*
34          * Serial Boot: The dram is already initialized in start.S
35          * only require to return DRAM size
36          */
37         dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
38 #else
39         sdramc_t *sdram = (sdramc_t *)(MMAP_SDRAM);
40         gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
41         u32 i;
42
43         dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
44
45         if ((in_be32(&sdram->sdcfg1) == CONFIG_SYS_SDRAM_CFG1) &&
46             (in_be32(&sdram->sdcfg2) == CONFIG_SYS_SDRAM_CFG2))
47                 return dramsize;
48
49         for (i = 0x13; i < 0x20; i++) {
50                 if (dramsize == (1 << i))
51                         break;
52         }
53         i--;
54
55         out_8(&gpio->mscr_sdram, CONFIG_SYS_SDRAM_DRV_STRENGTH);
56
57         out_be32(&sdram->sdcs0, CONFIG_SYS_SDRAM_BASE | i);
58
59         out_be32(&sdram->sdcfg1, CONFIG_SYS_SDRAM_CFG1);
60         out_be32(&sdram->sdcfg2, CONFIG_SYS_SDRAM_CFG2);
61
62         udelay(200);
63
64         /* Issue PALL */
65         out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
66         __asm__("nop");
67
68         /* Perform two refresh cycles */
69         out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
70         __asm__("nop");
71         out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
72         __asm__("nop");
73
74         /* Issue LEMR */
75         out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE);
76         __asm__("nop");
77         out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE);
78         __asm__("nop");
79
80         out_be32(&sdram->sdcr,
81                 (CONFIG_SYS_SDRAM_CTRL & ~0x80000000) | 0x10000000);
82
83         udelay(100);
84 #endif
85         return (dramsize);
86 };
87
88 int testdram(void)
89 {
90         /* TODO: XXX XXX XXX */
91         printf("DRAM test not implemented!\n");
92
93         return (0);
94 }