blob: e9548cdcf3dff7fb1fbe464b6dd245ef2a3da5ad [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
Stefan Roesec443fe92005-11-22 13:20:42 +01002 * (C) Copyright 2005
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
stroese55ca7492004-07-15 14:41:13 +00005 * (C) Copyright 2002-2004
wdenkc6097192002-11-03 00:24:07 +00006 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27#include <common.h>
28#include <ppc4xx.h>
29#include <asm/processor.h>
wdenkc6097192002-11-03 00:24:07 +000030
31
32#ifdef CONFIG_SDRAM_BANK0
33
34
stroese55ca7492004-07-15 14:41:13 +000035#define mtsdram0(reg, data) mtdcr(memcfga,reg);mtdcr(memcfgd,data)
wdenkc6097192002-11-03 00:24:07 +000036
wdenkc6097192002-11-03 00:24:07 +000037
stroese55ca7492004-07-15 14:41:13 +000038struct sdram_conf_s {
39 unsigned long size;
40 unsigned long reg;
41};
wdenkc6097192002-11-03 00:24:07 +000042
stroese55ca7492004-07-15 14:41:13 +000043typedef struct sdram_conf_s sdram_conf_t;
wdenkc6097192002-11-03 00:24:07 +000044
Stefan Roesec443fe92005-11-22 13:20:42 +010045#ifndef CFG_SDRAM_TABLE
stroese55ca7492004-07-15 14:41:13 +000046sdram_conf_t mb0cf[] = {
47 {(128 << 20), 0x000A4001}, /* (0-128MB) Address Mode 3, 13x10(4) */
48 {(64 << 20), 0x00084001}, /* (0-64MB) Address Mode 3, 13x9(4) */
49 {(32 << 20), 0x00062001}, /* (0-32MB) Address Mode 2, 12x9(4) */
50 {(16 << 20), 0x00046001}, /* (0-16MB) Address Mode 4, 12x8(4) */
51 {(4 << 20), 0x00008001}, /* (0-4MB) Address Mode 5, 11x8(2) */
52};
Stefan Roesec443fe92005-11-22 13:20:42 +010053#else
54sdram_conf_t mb0cf[] = CFG_SDRAM_TABLE;
55#endif
56
stroese55ca7492004-07-15 14:41:13 +000057#define N_MB0CF (sizeof(mb0cf) / sizeof(mb0cf[0]))
58
59
Stefan Roesec443fe92005-11-22 13:20:42 +010060#ifndef CONFIG_440
61
62/*
63 * Autodetect onboard SDRAM on 405 platforms
64 */
wdenkc6097192002-11-03 00:24:07 +000065void sdram_init(void)
66{
wdenkc6097192002-11-03 00:24:07 +000067 ulong sdtr1;
68 ulong rtr;
stroese55ca7492004-07-15 14:41:13 +000069 int i;
wdenkc6097192002-11-03 00:24:07 +000070
71 /*
wdenkc6097192002-11-03 00:24:07 +000072 * Support for 100MHz and 133MHz SDRAM
73 */
stroese55ca7492004-07-15 14:41:13 +000074 if (get_bus_freq(0) > 100000000) {
wdenkc6097192002-11-03 00:24:07 +000075 /*
76 * 133 MHz SDRAM
77 */
78 sdtr1 = 0x01074015;
79 rtr = 0x07f00000;
80 } else {
81 /*
82 * default: 100 MHz SDRAM
83 */
84 sdtr1 = 0x0086400d;
85 rtr = 0x05f00000;
86 }
87
stroese55ca7492004-07-15 14:41:13 +000088 for (i=0; i<N_MB0CF; i++) {
stroese51c57b92003-02-10 16:26:37 +000089 /*
stroese55ca7492004-07-15 14:41:13 +000090 * Disable memory controller.
stroese51c57b92003-02-10 16:26:37 +000091 */
stroese55ca7492004-07-15 14:41:13 +000092 mtsdram0(mem_mcopt1, 0x00000000);
wdenk41e2e052003-02-11 01:49:43 +000093
wdenkc6097192002-11-03 00:24:07 +000094 /*
stroese55ca7492004-07-15 14:41:13 +000095 * Set MB0CF for bank 0.
wdenkc6097192002-11-03 00:24:07 +000096 */
stroese55ca7492004-07-15 14:41:13 +000097 mtsdram0(mem_mb0cf, mb0cf[i].reg);
98 mtsdram0(mem_sdtr1, sdtr1);
99 mtsdram0(mem_rtr, rtr);
wdenk41e2e052003-02-11 01:49:43 +0000100
stroese55ca7492004-07-15 14:41:13 +0000101 udelay(200);
wdenkc6097192002-11-03 00:24:07 +0000102
wdenkc6097192002-11-03 00:24:07 +0000103 /*
stroese55ca7492004-07-15 14:41:13 +0000104 * Set memory controller options reg, MCOPT1.
105 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
106 * read/prefetch.
wdenkc6097192002-11-03 00:24:07 +0000107 */
stroese55ca7492004-07-15 14:41:13 +0000108 mtsdram0(mem_mcopt1, 0x80800000);
wdenkc6097192002-11-03 00:24:07 +0000109
stroese55ca7492004-07-15 14:41:13 +0000110 udelay(10000);
wdenkc6097192002-11-03 00:24:07 +0000111
stroese55ca7492004-07-15 14:41:13 +0000112 if (get_ram_size(0, mb0cf[i].size) == mb0cf[i].size) {
113 /*
114 * OK, size detected -> all done
115 */
116 return;
117 }
stroese51c57b92003-02-10 16:26:37 +0000118 }
wdenkc6097192002-11-03 00:24:07 +0000119}
120
Stefan Roesec443fe92005-11-22 13:20:42 +0100121#else /* CONFIG_440 */
122
123/*
124 * Autodetect onboard DDR SDRAM on 440 platforms
125 *
126 * NOTE: Some of the hardcoded values are hardware dependant,
127 * so this should be extended for other future boards
128 * using this routine!
129 */
130long int initdram(int board_type)
131{
132 int i;
133
134 for (i=0; i<N_MB0CF; i++) {
135 /*
136 * Disable memory controller.
137 */
138 mtsdram(mem_cfg0, 0x00000000);
139
140 /*
141 * Setup some default
142 */
143 mtsdram(mem_uabba, 0x00000000); /* ubba=0 (default) */
144 mtsdram(mem_slio, 0x00000000); /* rdre=0 wrre=0 rarw=0 */
145 mtsdram(mem_devopt, 0x00000000); /* dll=0 ds=0 (normal) */
146 mtsdram(mem_wddctr, 0x00000000); /* wrcp=0 dcd=0 */
147 mtsdram(mem_clktr, 0x40000000); /* clkp=1 (90 deg wr) dcdt=0 */
148
149 /*
150 * Following for CAS Latency = 2.5 @ 133 MHz PLB
151 */
152 mtsdram(mem_b0cr, mb0cf[i].reg);
153 mtsdram(mem_tr0, 0x41094012);
154 mtsdram(mem_tr1, 0x80800800); /* SS=T2 SL=STAGE 3 CD=1 CT=0x00*/
155 mtsdram(mem_rtr, 0x7e000000); /* Interval 15.20µs @ 133MHz PLB*/
156 mtsdram(mem_cfg1, 0x00000000); /* Self-refresh exit, disable PM*/
157 udelay(400); /* Delay 200 usecs (min) */
158
159 /*
160 * Enable the controller, then wait for DCEN to complete
161 */
162 mtsdram(mem_cfg0, 0x86000000); /* DCEN=1, PMUD=1, 64-bit */
163 udelay(10000);
164
165 if (get_ram_size(0, mb0cf[i].size) == mb0cf[i].size) {
166 /*
167 * OK, size detected -> all done
168 */
169 return mb0cf[i].size;
170 }
171 }
172
173 return 0; /* nothing found ! */
174}
175
176#endif /* CONFIG_440 */
177
wdenkc6097192002-11-03 00:24:07 +0000178#endif /* CONFIG_SDRAM_BANK0 */