]> git.sur5r.net Git - u-boot/blob - board/mpc8540ads/mpc8540ads.c
Patch by Jon Loeliger, 17 June 2004:
[u-boot] / board / mpc8540ads / mpc8540ads.c
1  /*
2  * Copyright 2004 Freescale Semiconductor.
3  * (C) Copyright 2002,2003, Motorola Inc.
4  * Xianghua Xiao, (X.Xiao@motorola.com)
5  *
6  * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.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
28 #include <common.h>
29 #include <asm/processor.h>
30 #include <asm/immap_85xx.h>
31 #include <spd.h>
32
33 #if defined(CONFIG_DDR_ECC)
34 extern void ddr_enable_ecc(unsigned int dram_size);
35 #endif
36
37 extern long int spd_sdram(void);
38
39 void sdram_init(void);
40 long int fixed_sdram(void);
41
42
43 int board_early_init_f (void)
44 {
45 #if defined(CONFIG_PCI)
46         volatile immap_t *immr = (immap_t *) CFG_IMMR;
47         volatile ccsr_pcix_t *pci = &immr->im_pcix;
48
49         pci->peer &= 0xffffffdf;        /* disable master abort */
50 #endif
51
52         return 0;
53 }
54
55 int checkboard (void)
56 {
57         puts("Board: ADS\n");
58
59 #ifdef CONFIG_PCI
60         printf("    PCI1: 32 bit, %d MHz (compiled)\n",
61                CONFIG_SYS_CLK_FREQ / 1000000);
62 #else
63         printf("    PCI1: disabled\n");
64 #endif
65
66         return 0;
67 }
68
69
70 long int
71 initdram(int board_type)
72 {
73         long dram_size = 0;
74         extern long spd_sdram (void);
75         volatile immap_t *immap = (immap_t *)CFG_IMMR;
76
77         puts("Initializing\n");
78
79 #if defined(CONFIG_DDR_DLL)
80         {
81                 volatile ccsr_gur_t *gur= &immap->im_gur;
82                 uint temp_ddrdll = 0;
83
84                 /*
85                 * Work around to stabilize DDR DLL
86                 */
87                 temp_ddrdll = gur->ddrdllcr;
88                 gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
89                 asm("sync;isync;msync");
90         }
91 #endif
92
93 #if defined(CONFIG_SPD_EEPROM)
94         dram_size = spd_sdram ();
95 #else
96         dram_size = fixed_sdram ();
97 #endif
98
99 #if defined(CONFIG_DDR_ECC)
100         /*
101          * Initialize and enable DDR ECC.
102          */
103         ddr_enable_ecc(dram_size);
104 #endif
105
106         /*
107          * Initialize SDRAM.
108          */
109         sdram_init();
110
111         puts("    DDR: ");
112         return dram_size;
113 }
114
115
116 /*
117  * Initialize SDRAM memory on the Local Bus.
118  */
119
120 void sdram_init (void)
121 {
122 #if !defined(CONFIG_RAM_AS_FLASH)
123         sys_info_t sysinfo;
124         volatile immap_t *immap = (immap_t *) CFG_IMMR;
125         volatile ccsr_lbc_t *lbc = &immap->im_lbc;
126         uint *sdram_addr = (uint *) CFG_LBC_SDRAM_BASE;
127
128         puts ("    SDRAM: ");
129         print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
130
131         /*
132          * LocalBus SDRAM is not emulating flash.
133          */
134
135         /*
136          * Fix Local Bus clock glitch.  Errata LBC11.
137          *
138          * If localbus freq is less than 66Mhz, use bypass mode,
139          * otherwise use DLL.
140          * lcrr is the local-bus clock ratio register.
141          */
142         get_sys_info (&sysinfo);
143         if (sysinfo.freqSystemBus / (CFG_LBC_LCRR & 0x0f) < 66000000) {
144                 lbc->lcrr = (CFG_LBC_LCRR & 0x0fffffff) | 0x80000000;
145
146         } else {
147                 /*
148                  * On REV1 boards, need to change CLKDIV before enable DLL.
149                  * Default CLKDIV is 8, change it to 4 temporarily.
150                  */
151                 volatile ccsr_gur_t *gur = &immap->im_gur;
152                 uint pvr = get_pvr ();
153                 uint temp_lbcdll = 0;
154
155                 if (pvr == PVR_85xx_REV1) {
156                         lbc->lcrr = 0x10000004;
157                 }
158
159                 /* FIXME: jdl  Should lcrr have 0x8000000 OR'ed in here too? */
160                 lbc->lcrr = CFG_LBC_LCRR & 0x7fffffff;
161                 udelay (200);
162                 temp_lbcdll = gur->lbcdllcr;
163                 gur->lbcdllcr = ((temp_lbcdll & 0xff) << 16) | 0x80000000;
164                 asm ("sync;isync;msync");
165         }
166
167         /*
168          * Setup SDRAM Base and Option Registers
169          */
170         lbc->or2 = CFG_OR2_PRELIM;
171         lbc->br2 = CFG_BR2_PRELIM;
172         lbc->lbcr = CFG_LBC_LBCR;
173         asm ("msync");
174
175         lbc->lsrt = CFG_LBC_LSRT;
176         lbc->mrtpr = CFG_LBC_MRTPR;
177         asm ("sync");
178
179         /*
180          * Configure the SDRAM controller.
181          */
182         lbc->lsdmr = CFG_LBC_LSDMR_1;
183         asm ("sync");
184         *sdram_addr = 0xff;
185         ppcDcbf ((unsigned long) sdram_addr);
186         udelay (100);
187
188         lbc->lsdmr = CFG_LBC_LSDMR_2;
189         asm ("sync");
190         *sdram_addr = 0xff;
191         ppcDcbf ((unsigned long) sdram_addr);
192         udelay (100);
193
194         lbc->lsdmr = CFG_LBC_LSDMR_3;
195         asm ("sync");
196         *sdram_addr = 0xff;
197         ppcDcbf ((unsigned long) sdram_addr);
198         udelay (100);
199
200         lbc->lsdmr = CFG_LBC_LSDMR_4;
201         asm ("sync");
202         *sdram_addr = 0xff;
203         ppcDcbf ((unsigned long) sdram_addr);
204         udelay (100);
205
206         lbc->lsdmr = CFG_LBC_LSDMR_5;
207         asm ("sync");
208         *sdram_addr = 0xff;
209         ppcDcbf ((unsigned long) sdram_addr);
210         udelay (100);
211
212 #endif
213 }
214
215
216 #if defined(CFG_DRAM_TEST)
217 int testdram (void)
218 {
219         uint *pstart = (uint *) CFG_MEMTEST_START;
220         uint *pend = (uint *) CFG_MEMTEST_END;
221         uint *p;
222
223         printf("SDRAM test phase 1:\n");
224         for (p = pstart; p < pend; p++)
225                 *p = 0xaaaaaaaa;
226
227         for (p = pstart; p < pend; p++) {
228                 if (*p != 0xaaaaaaaa) {
229                         printf ("SDRAM test fails at: %08x\n", (uint) p);
230                         return 1;
231                 }
232         }
233
234         printf("SDRAM test phase 2:\n");
235         for (p = pstart; p < pend; p++)
236                 *p = 0x55555555;
237
238         for (p = pstart; p < pend; p++) {
239                 if (*p != 0x55555555) {
240                         printf ("SDRAM test fails at: %08x\n", (uint) p);
241                         return 1;
242                 }
243         }
244
245         printf("SDRAM test passed.\n");
246         return 0;
247 }
248 #endif
249
250
251 #if !defined(CONFIG_SPD_EEPROM)
252 /*************************************************************************
253  *  fixed sdram init -- doesn't use serial presence detect.
254  ************************************************************************/
255 long int fixed_sdram (void)
256 {
257   #ifndef CFG_RAMBOOT
258         volatile immap_t *immap = (immap_t *)CFG_IMMR;
259         volatile ccsr_ddr_t *ddr= &immap->im_ddr;
260
261         ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
262         ddr->cs0_config = CFG_DDR_CS0_CONFIG;
263         ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
264         ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
265         ddr->sdram_mode = CFG_DDR_MODE;
266         ddr->sdram_interval = CFG_DDR_INTERVAL;
267     #if defined (CONFIG_DDR_ECC)
268         ddr->err_disable = 0x0000000D;
269         ddr->err_sbe = 0x00ff0000;
270     #endif
271         asm("sync;isync;msync");
272         udelay(500);
273     #if defined (CONFIG_DDR_ECC)
274         /* Enable ECC checking */
275         ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
276     #else
277         ddr->sdram_cfg = CFG_DDR_CONTROL;
278     #endif
279         asm("sync; isync; msync");
280         udelay(500);
281   #endif
282         return CFG_SDRAM_SIZE * 1024 * 1024;
283 }
284 #endif  /* !defined(CONFIG_SPD_EEPROM) */