blob: d1ad21203da11bbf93c9a0eb6f54b03d8c38d71c [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
stroesede8d5a32004-07-15 14:41:13 +00002 * (C) Copyright 2002-2004
wdenkc6097192002-11-03 00:24:07 +00003 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
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 <ppc4xx.h>
26#include <asm/processor.h>
wdenkc6097192002-11-03 00:24:07 +000027
28
29#ifdef CONFIG_SDRAM_BANK0
30
31
wdenkc6097192002-11-03 00:24:07 +000032#define mtsdram0(reg, data) mtdcr(memcfga,reg);mtdcr(memcfgd,data)
33
34
stroesede8d5a32004-07-15 14:41:13 +000035struct sdram_conf_s {
36 unsigned long size;
37 unsigned long reg;
38};
39
40typedef struct sdram_conf_s sdram_conf_t;
41
42sdram_conf_t mb0cf[] = {
43 {(128 << 20), 0x000A4001}, /* (0-128MB) Address Mode 3, 13x10(4) */
44 {(64 << 20), 0x00084001}, /* (0-64MB) Address Mode 3, 13x9(4) */
45 {(32 << 20), 0x00062001}, /* (0-32MB) Address Mode 2, 12x9(4) */
46 {(16 << 20), 0x00046001}, /* (0-16MB) Address Mode 4, 12x8(4) */
47 {(4 << 20), 0x00008001}, /* (0-4MB) Address Mode 5, 11x8(2) */
48};
49#define N_MB0CF (sizeof(mb0cf) / sizeof(mb0cf[0]))
50
51
wdenkc6097192002-11-03 00:24:07 +000052void sdram_init(void)
53{
wdenkc6097192002-11-03 00:24:07 +000054 ulong sdtr1;
55 ulong rtr;
stroesede8d5a32004-07-15 14:41:13 +000056 int i;
wdenkc6097192002-11-03 00:24:07 +000057
58 /*
59 * Support for 100MHz and 133MHz SDRAM
60 */
stroesede8d5a32004-07-15 14:41:13 +000061 if (get_bus_freq(0) > 100000000) {
wdenkc6097192002-11-03 00:24:07 +000062 /*
63 * 133 MHz SDRAM
64 */
65 sdtr1 = 0x01074015;
66 rtr = 0x07f00000;
67 } else {
68 /*
69 * default: 100 MHz SDRAM
70 */
71 sdtr1 = 0x0086400d;
72 rtr = 0x05f00000;
73 }
74
stroesede8d5a32004-07-15 14:41:13 +000075 for (i=0; i<N_MB0CF; i++) {
stroese61774452003-02-10 16:26:37 +000076 /*
stroesede8d5a32004-07-15 14:41:13 +000077 * Disable memory controller.
stroese61774452003-02-10 16:26:37 +000078 */
stroesede8d5a32004-07-15 14:41:13 +000079 mtsdram0(mem_mcopt1, 0x00000000);
wdenke5ad56b2003-02-11 01:49:43 +000080
wdenkc6097192002-11-03 00:24:07 +000081 /*
stroesede8d5a32004-07-15 14:41:13 +000082 * Set MB0CF for bank 0.
wdenkc6097192002-11-03 00:24:07 +000083 */
stroesede8d5a32004-07-15 14:41:13 +000084 mtsdram0(mem_mb0cf, mb0cf[i].reg);
85 mtsdram0(mem_sdtr1, sdtr1);
86 mtsdram0(mem_rtr, rtr);
wdenke5ad56b2003-02-11 01:49:43 +000087
stroesede8d5a32004-07-15 14:41:13 +000088 udelay(200);
wdenke5ad56b2003-02-11 01:49:43 +000089
wdenkc6097192002-11-03 00:24:07 +000090 /*
stroesede8d5a32004-07-15 14:41:13 +000091 * Set memory controller options reg, MCOPT1.
92 * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
93 * read/prefetch.
wdenkc6097192002-11-03 00:24:07 +000094 */
stroesede8d5a32004-07-15 14:41:13 +000095 mtsdram0(mem_mcopt1, 0x80800000);
96
97 udelay(10000);
98
99 if (get_ram_size(0, mb0cf[i].size) == mb0cf[i].size) {
100 /*
101 * OK, size detected -> all done
102 */
103 return;
104 }
wdenkc6097192002-11-03 00:24:07 +0000105 }
wdenkc6097192002-11-03 00:24:07 +0000106}
107
108#endif /* CONFIG_SDRAM_BANK0 */