summaryrefslogtreecommitdiff
path: root/board/amcc/makalu/memory.c
blob: b03b60b8f4ad86916868501d83eb8699e0187c1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*
 * (C) Copyright 2007
 * Stefan Roese, DENX Software Engineering, sr@denx.de.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <common.h>
#include <asm/processor.h>

void sdram_init(void)
{
	return;
}

long int initdram(int board_type)
{
	/*
	 * Same as on Kilauea, Makalu generates exception 0x200
	 * (machine check) after trap_init() in board_init_f,
	 * when SDRAM is initialized here (late) and d-cache is
	 * used earlier as INIT_RAM.
	 * So for now, initialize DDR2 in init.S very early and
	 * also use it for INIT_RAM. Then this exception doesn't
	 * occur.
	 */
#if 0
	u32 val;

	/* base=00000000, size=128MByte (5), mode=2 (n*10*4) */
	mtsdram(SDRAM_MB0CF, 0x00005201);

	/* SET SDRAM_MB1CF - Not enabled */
	mtsdram(SDRAM_MB1CF, 0x00000000);

	/* SET SDRAM_MB2CF  - Not enabled */
	mtsdram(SDRAM_MB2CF, 0x00000000);

	/* SET SDRAM_MB3CF  - Not enabled */
	mtsdram(SDRAM_MB3CF, 0x00000000);

	/* SDRAM_CLKTR: Adv Addr clock by 90 deg */
	mtsdram(SDRAM_CLKTR, 0x80000000);

	/* Refresh Time register (0x30) Refresh every 7.8125uS */
	mtsdram(SDRAM_RTR, 0x06180000);

	/* SDRAM_SDTR1 */
	mtsdram(SDRAM_SDTR1, 0x80201000);

	/* SDRAM_SDTR2	*/
	mtsdram(SDRAM_SDTR2, 0x32204232);

	/* SDRAM_SDTR3	*/
	mtsdram(SDRAM_SDTR3, 0x080b0d1a);

	mtsdram(SDRAM_MMODE, 0x00000442);
	mtsdram(SDRAM_MEMODE, 0x00000404);

	/* SDRAM0_MCOPT1 (0X20) No ECC Gen */
	mtsdram(SDRAM_MCOPT1, 0x04322000);

	/* NOP */
	mtsdram(SDRAM_INITPLR0, 0xa8380000);
	/* precharge 3 DDR clock cycle */
	mtsdram(SDRAM_INITPLR1, 0x81900400);
	/* EMR2 twr = 2tck */
	mtsdram(SDRAM_INITPLR2, 0x81020000);
	/* EMR3  twr = 2tck */
	mtsdram(SDRAM_INITPLR3, 0x81030000);
	/* EMR DLL ENABLE twr = 2tck */
	mtsdram(SDRAM_INITPLR4, 0x81010404);
	/* MR w/ DLL reset
	 * Note: 5 is CL.  May need to be changed
	 */
	mtsdram(SDRAM_INITPLR5, 0x81000542);
	/* precharge 3 DDR clock cycle */
	mtsdram(SDRAM_INITPLR6, 0x81900400);
	/* Auto-refresh trfc = 26tck */
	mtsdram(SDRAM_INITPLR7, 0x8D080000);
	/* Auto-refresh trfc = 26tck */
	mtsdram(SDRAM_INITPLR8, 0x8D080000);
	/* Auto-refresh */
	mtsdram(SDRAM_INITPLR9, 0x8D080000);
	/* Auto-refresh */
	mtsdram(SDRAM_INITPLR10, 0x8D080000);
	/* MRS - normal operation; wait 2 cycle (set wait to tMRD) */
	mtsdram(SDRAM_INITPLR11, 0x81000442);
	mtsdram(SDRAM_INITPLR12, 0x81010780);
	mtsdram(SDRAM_INITPLR13, 0x81010400);
	mtsdram(SDRAM_INITPLR14, 0x00000000);
	mtsdram(SDRAM_INITPLR15, 0x00000000);

	/* SET MCIF0_CODT   Die Termination On */
	mtsdram(SDRAM_CODT, 0x0080f837);
	mtsdram(SDRAM_MODT0, 0x01800000);
	mtsdram(SDRAM_MODT1, 0x00000000);

	mtsdram(SDRAM_WRDTR, 0x00000000);

	/* SDRAM0_MCOPT2 (0X21) Start initialization */
	mtsdram(SDRAM_MCOPT2, 0x20000000);

	/* Step 5 */
	do {
		mfsdram(SDRAM_MCSTAT, val);
	} while ((val & SDRAM_MCSTAT_MIC_COMP) != SDRAM_MCSTAT_MIC_COMP);

	/* Step 6 */

	/* SDRAM_DLCR */
	mtsdram(SDRAM_DLCR, 0x030000a5);

	/* SDRAM_RDCC */
	mtsdram(SDRAM_RDCC, 0x40000000);

	/* SDRAM_RQDC */
	mtsdram(SDRAM_RQDC, 0x80000038);

	/* SDRAM_RFDC */
	mtsdram(SDRAM_RFDC, 0x00000209);

	/* Enable memory controller */
	mfsdram(SDRAM_MCOPT2, val);
	val |= SDRAM_MCOPT2_DCEN_ENABLE;
	mtsdram(SDRAM_MCOPT2, val);
#endif
	return (CFG_MBYTES_SDRAM << 20);
}

#if defined(CFG_DRAM_TEST)
int testdram (void)
{
    printf ("testdram\n");
#if defined (CONFIG_NAND_U_BOOT)
    return 0;
#endif
	uint *pstart = (uint *) 0x00000000;
	uint *pend = (uint *) 0x00001000;
	uint *p;

	for (p = pstart; p < pend; p++) {
		*p = 0xaaaaaaaa;
	}

	for (p = pstart; p < pend; p++) {
		if (*p != 0xaaaaaaaa) {
#if !defined (CONFIG_NAND_SPL)
			printf ("SDRAM test fails at: %08x\n", (uint) p);
#endif
			return 1;
		}
	}

	for (p = pstart; p < pend; p++) {
		*p = 0x55555555;
	}

	for (p = pstart; p < pend; p++) {
		if (*p != 0x55555555) {
#if !defined (CONFIG_NAND_SPL)
			printf ("SDRAM test fails at: %08x\n", (uint) p);
#endif
			return 1;
		}
	}
#if !defined (CONFIG_NAND_SPL)
	printf ("SDRAM test passed!!!\n");
#endif
	return 0;
}
#endif