blob: 58cdba1e13698dcb5a8e6113f79036db2d044b36 [file] [log] [blame]
Bartlomiej Siekadaa6e412006-12-20 00:27:32 +01001/*
2 * (C) Copyright 2000-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <asm/m5271.h>
26#include <asm/immap_5271.h>
27
28int checkboard (void) {
29 puts ("Board: iDMR\n");
30 return 0;
31};
32
33long int initdram (int board_type) {
34 int i;
35
36 /*
37 * After reset, CS0 is configured to cover entire address space. We
38 * need to configure it to its proper values, so that writes to
39 * CFG_SDRAM_BASE and vicinity during SDRAM controller setup below do
40 * now fall under CS0 (see 16.3.1 of the MCF5271 Reference Manual).
41 */
42
43 /* Flash chipselect, CS0 */
44 /* ;CSAR0: Flash at 0xFF800000 */
45 mbar_writeShort(0x0080, 0xFF80);
46
47 /* CSCR0: Flash 6 waits, 16bit */
48 mbar_writeShort(0x008A, 0x1980);
49
50 /* CSMR0: Flash 8MB, R/W, valid */
51 mbar_writeLong(0x0084, 0x007F0001);
52
53
54 /*
55 * SDRAM configuration proper
56 */
57
58 /*
59 * Address/Data Pin Assignment Reg.: enable address lines 23-21; do
60 * not enable data pins D[15:0], as we have 16 bit port to SDRAM
61 */
62 mbar_writeByte(MCF_GPIO_PAR_AD,
63 MCF_GPIO_AD_ADDR23 |
64 MCF_GPIO_AD_ADDR22 |
65 MCF_GPIO_AD_ADDR21);
66
67 /* No need to configure BS pins - reset values are OK */
68
69 /* Chip Select Pin Assignment Reg.: set CS[1-7] to GPIO */
70 mbar_writeByte(MCF_GPIO_PAR_CS, 0x00);
71
72 /* SDRAM Control Pin Assignment Reg. */
73 mbar_writeByte(MCF_GPIO_PAR_SDRAM,
74 MCF_GPIO_SDRAM_CSSDCS_00 | /* no matter: PAR_CS=0 */
75 MCF_GPIO_SDRAM_SDWE |
76 MCF_GPIO_SDRAM_SCAS |
77 MCF_GPIO_SDRAM_SRAS |
78 MCF_GPIO_SDRAM_SCKE |
79 MCF_GPIO_SDRAM_SDCS_01);
80
81 /*
82 * Wait 100us. We run the bus at 50Mhz, one cycle is 20ns. So 5
83 * iterations will do, but we do 10 just to be safe.
84 */
85 for (i = 0; i < 10; ++i)
86 asm(" nop");
87
88
89 /* 1. Initialize DRAM Control Register: DCR */
90 mbar_writeShort(MCF_SDRAMC_DCR,
91 MCF_SDRAMC_DCR_RTIM(0x10) | /* 65ns */
92 MCF_SDRAMC_DCR_RC(0x60)); /* 1562 cycles */
93
94
95 /*
96 * 2. Initialize DACR0
97 *
98 * CL: 11 (CL=3: 0x03, 0x02; CL=2: 0x1)
99 * CBM: cmd at A20, bank select bits 21 and up
100 * PS: 16 bit
101 */
102 mbar_writeLong(MCF_SDRAMC_DACR0,
103 MCF_SDRAMC_DACRn_BA(CFG_SDRAM_BASE>>18) |
104 MCF_SDRAMC_DACRn_BA(0x00) |
105 MCF_SDRAMC_DACRn_CASL(0x03) |
106 MCF_SDRAMC_DACRn_CBM(0x03) |
107 MCF_SDRAMC_DACRn_PS(0x03));
108
109 /* Initialize DMR0 */
110 mbar_writeLong(MCF_SDRAMC_DMR0,
111 MCF_SDRAMC_DMRn_BAM_16M |
112 MCF_SDRAMC_DMRn_V);
113
114
115 /* 3. Set IP bit in DACR to initiate PALL command */
116 mbar_writeLong(MCF_SDRAMC_DACR0,
117 mbar_readLong(MCF_SDRAMC_DACR0) |
118 MCF_SDRAMC_DACRn_IP);
119
120 /* Write to this block to initiate precharge */
121 *(volatile u16 *)(CFG_SDRAM_BASE) = 0xa5a5;
122
123 /*
124 * Wait at least 20ns to allow banks to precharge (t_RP = 20ns). We
125 * wait a wee longer, just to be safe.
126 */
127 for (i = 0; i < 5; ++i)
128 asm(" nop");
129
130
131 /* 4. Set RE bit in DACR */
132 mbar_writeLong(MCF_SDRAMC_DACR0,
133 mbar_readLong(MCF_SDRAMC_DACR0) |
134 MCF_SDRAMC_DACRn_RE);
135
136 /*
137 * Wait for at least 8 auto refresh cycles to occur, i.e. at least
138 * 781 bus cycles.
139 */
140 for (i = 0; i < 1000; ++i)
141 asm(" nop");
142
143 /* Finish the configuration by issuing the MRS */
144 mbar_writeLong(MCF_SDRAMC_DACR0,
145 mbar_readLong(MCF_SDRAMC_DACR0) |
146 MCF_SDRAMC_DACRn_MRS);
147
148 /*
149 * Write to the SDRAM Mode Register A0-A11 = 0x400
150 *
151 * Write Burst Mode = Programmed Burst Length
152 * Op Mode = Standard Op
153 * CAS Latency = 3
154 * Burst Type = Sequential
155 * Burst Length = 1
156 */
157 *(volatile u32 *)(CFG_SDRAM_BASE + 0x1800) = 0xa5a5a5a5;
158
159 return CFG_SDRAM_SIZE * 1024 * 1024;
160};
161
162
163int testdram (void) {
164
165 /* TODO: XXX XXX XXX */
166 printf ("DRAM test not implemented!\n");
167
168 return (0);
169}