5068f9071f98e077ff108a96457d27bfb1266b08
[coreboot.git] / src / cpu / ppc / ppc4xx / sdram.c
1 /*
2  * (C) Copyright 2002
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., 51 Franklin St, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #include <ppc_asm.tmpl>
25 #include <ppc.h>
26 #include <ppc4xx.h>
27 #include <timer.h>
28 #include <clock.h>
29 #include <stdint.h>
30
31 #define CONFIG_SDRAM_BANK0
32 #ifdef CONFIG_SDRAM_BANK0
33
34 /*
35  * According to the PPC405GPr Users Manual, only non-reserved
36  * bits of SDRAM registers can be set. This means reading the
37  * contents and masking off bits to be set.
38  */
39 #define CMD_BITS        0x80C00000
40 #define CMD_MASK        0xFFE00000
41 #define TR_BITS         0x010E8016
42 #define TR_MASK         0x018FC01F
43 #define B0CR_BITS       0x00084001
44 #define B0CR_MASK       0xFFCEE001
45 #define RTR_BITS        0x08080000
46 #define RTR_MASK        0xFFFF0000
47 #define ECCCF_BITS      0x00000000
48 #define ECCCF_MASK      0x00F00000
49 #define PMIT_BITS       0x0F000000
50 #define PMIT_MASK       0xFFC00000
51
52 #define mfsdram0(reg, data)  mtdcr(memcfga,reg);data = mfdcr(memcfgd)
53 #define mtsdram0(reg, data)  mtdcr(memcfga,reg);mtdcr(memcfgd,data)
54
55 #define set_sdram0(reg, val) \
56         mfsdram0(reg, reg32); \
57         reg32 &= ~(val##_MASK); \
58         reg32 |= (val##_BITS); \
59         mtsdram0(reg, reg32)
60
61 /*-----------------------------------------------------------------------
62  */
63 void memory_init(void)
64 {
65 #if 0
66         unsigned long speed;
67         unsigned long sdtr1;
68 #endif
69         uint32_t reg32;
70
71 #if 0
72         /*
73          * Determine SDRAM speed
74          */
75         speed = get_pci_bus_freq(); /* parameter not used on ppc4xx */
76
77         /*
78          * Support for 100MHz and 133MHz SDRAM
79          */
80         if (speed > 100000000) {
81                 /*
82                  * 133 MHz SDRAM
83                  */
84                 sdtr1 = 0x01074015;
85                 rtr = 0x07f00000;
86         } else {
87                 /*
88                  * default: 100 MHz SDRAM
89                  */
90                 sdtr1 = 0x0086400d;
91                 rtr = 0x05f00000;
92         }
93 #endif
94
95         /*
96          * Disable memory controller.
97          */
98 /* TODO: work out why this trashes cache ram */
99         //mtsdram0(mem_mcopt1, 0x00000000);
100
101 #if EMBEDDED_RAM_SIZE==128*1024*1024
102         /* TODO */
103 #elif EMBEDDED_RAM_SIZE==64*1024*1024
104         set_sdram0(mem_sdtr1, TR);
105         set_sdram0(mem_mb0cf, B0CR);
106         set_sdram0(mem_rtr, RTR);
107         set_sdram0(mem_ecccf, ECCCF);
108         set_sdram0(mem_pmit, PMIT);
109 #elif EMBEDDED_RAM_SIZE==32*1024*1024
110         /* TODO */
111 #elif EMBEDDED_RAM_SIZE==16*1024*1024
112         /* TODO */
113 #endif
114
115         /*
116          * Wait for 200us
117          */
118         udelay(200);
119
120         /*
121          * Set memory controller options reg, MCOPT1.
122          * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst
123          * read/prefetch.
124          */
125         set_sdram0(mem_mcopt1, CMD);
126
127         /*
128          * Wait for 10ms
129          */
130         udelay(10000);
131 }
132
133 #endif /* CONFIG_SDRAM_BANK0 */