]> git.karo-electronics.de Git - karo-tx-uboot.git/blob - cpu/ppc4xx/sdram.c
cpu/ppc4xx/sdram.c rewritten now using get_ram_size()
[karo-tx-uboot.git] / cpu / ppc4xx / sdram.c
1 /*
2  * (C) Copyright 2002-2004
3  * 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>
27
28
29 #ifdef CONFIG_SDRAM_BANK0
30
31
32 #define mtsdram0(reg, data)  mtdcr(memcfga,reg);mtdcr(memcfgd,data)
33
34
35 struct sdram_conf_s {
36         unsigned long size;
37         unsigned long reg;
38 };
39
40 typedef struct sdram_conf_s sdram_conf_t;
41
42 sdram_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
52 void sdram_init(void)
53 {
54         ulong sdtr1;
55         ulong rtr;
56         int i;
57
58         /*
59          * Support for 100MHz and 133MHz SDRAM
60          */
61         if (get_bus_freq(0) > 100000000) {
62                 /*
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
75         for (i=0; i<N_MB0CF; i++) {
76                 /*
77                  * Disable memory controller.
78                  */
79                 mtsdram0(mem_mcopt1, 0x00000000);
80
81                 /*
82                  * Set MB0CF for bank 0.
83                  */
84                 mtsdram0(mem_mb0cf, mb0cf[i].reg);
85                 mtsdram0(mem_sdtr1, sdtr1);
86                 mtsdram0(mem_rtr, rtr);
87
88                 udelay(200);
89
90                 /*
91                  * 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.
94                  */
95                 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                 }
105         }
106 }
107
108 #endif /* CONFIG_SDRAM_BANK0 */