85xx: Remove unused and unconfigured memory test code.
[platform/kernel/u-boot.git] / board / freescale / 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 <pci.h>
30 #include <asm/processor.h>
31 #include <asm/immap_85xx.h>
32 #include <spd_sdram.h>
33 #include <libfdt.h>
34 #include <fdt_support.h>
35
36 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
37 extern void ddr_enable_ecc(unsigned int dram_size);
38 #endif
39
40 void local_bus_init(void);
41 void sdram_init(void);
42 long int fixed_sdram(void);
43
44
45 int board_early_init_f (void)
46 {
47     return 0;
48 }
49
50 int checkboard (void)
51 {
52         puts("Board: ADS\n");
53
54 #ifdef CONFIG_PCI
55         printf("    PCI1: 32 bit, %d MHz (compiled)\n",
56                CONFIG_SYS_CLK_FREQ / 1000000);
57 #else
58         printf("    PCI1: disabled\n");
59 #endif
60
61         /*
62          * Initialize local bus.
63          */
64         local_bus_init();
65
66         return 0;
67 }
68
69
70 long int
71 initdram(int board_type)
72 {
73         long dram_size = 0;
74
75         puts("Initializing\n");
76
77 #if defined(CONFIG_DDR_DLL)
78         {
79             volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
80             uint temp_ddrdll = 0;
81
82             /*
83              * Work around to stabilize DDR DLL
84              */
85             temp_ddrdll = gur->ddrdllcr;
86             gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
87             asm("sync;isync;msync");
88         }
89 #endif
90
91 #if defined(CONFIG_SPD_EEPROM)
92         dram_size = spd_sdram ();
93 #else
94         dram_size = fixed_sdram ();
95 #endif
96
97 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
98         /*
99          * Initialize and enable DDR ECC.
100          */
101         ddr_enable_ecc(dram_size);
102 #endif
103
104         /*
105          * Initialize SDRAM.
106          */
107         sdram_init();
108
109         puts("    DDR: ");
110         return dram_size;
111 }
112
113
114 /*
115  * Initialize Local Bus
116  */
117
118 void
119 local_bus_init(void)
120 {
121         volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
122         volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
123
124         uint clkdiv;
125         uint lbc_hz;
126         sys_info_t sysinfo;
127
128         /*
129          * Errata LBC11.
130          * Fix Local Bus clock glitch when DLL is enabled.
131          *
132          * If localbus freq is < 66Mhz, DLL bypass mode must be used.
133          * If localbus freq is > 133Mhz, DLL can be safely enabled.
134          * Between 66 and 133, the DLL is enabled with an override workaround.
135          */
136
137         get_sys_info(&sysinfo);
138         clkdiv = lbc->lcrr & 0x0f;
139         lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
140
141         if (lbc_hz < 66) {
142                 lbc->lcrr = CFG_LBC_LCRR | 0x80000000;  /* DLL Bypass */
143
144         } else if (lbc_hz >= 133) {
145                 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
146
147         } else {
148                 /*
149                  * On REV1 boards, need to change CLKDIV before enable DLL.
150                  * Default CLKDIV is 8, change it to 4 temporarily.
151                  */
152                 uint pvr = get_pvr();
153                 uint temp_lbcdll = 0;
154
155                 if (pvr == PVR_85xx_REV1) {
156                         /* FIXME: Justify the high bit here. */
157                         lbc->lcrr = 0x10000004;
158                 }
159
160                 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
161                 udelay(200);
162
163                 /*
164                  * Sample LBC DLL ctrl reg, upshift it to set the
165                  * override bits.
166                  */
167                 temp_lbcdll = gur->lbcdllcr;
168                 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
169                 asm("sync;isync;msync");
170         }
171 }
172
173
174 /*
175  * Initialize SDRAM memory on the Local Bus.
176  */
177
178 void
179 sdram_init(void)
180 {
181         volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
182         uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
183
184         puts("    SDRAM: ");
185         print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
186
187         /*
188          * Setup SDRAM Base and Option Registers
189          */
190         lbc->or2 = CFG_OR2_PRELIM;
191         lbc->br2 = CFG_BR2_PRELIM;
192         lbc->lbcr = CFG_LBC_LBCR;
193         asm("msync");
194
195         lbc->lsrt = CFG_LBC_LSRT;
196         lbc->mrtpr = CFG_LBC_MRTPR;
197         asm("sync");
198
199         /*
200          * Configure the SDRAM controller.
201          */
202         lbc->lsdmr = CFG_LBC_LSDMR_1;
203         asm("sync");
204         *sdram_addr = 0xff;
205         ppcDcbf((unsigned long) sdram_addr);
206         udelay(100);
207
208         lbc->lsdmr = CFG_LBC_LSDMR_2;
209         asm("sync");
210         *sdram_addr = 0xff;
211         ppcDcbf((unsigned long) sdram_addr);
212         udelay(100);
213
214         lbc->lsdmr = CFG_LBC_LSDMR_3;
215         asm("sync");
216         *sdram_addr = 0xff;
217         ppcDcbf((unsigned long) sdram_addr);
218         udelay(100);
219
220         lbc->lsdmr = CFG_LBC_LSDMR_4;
221         asm("sync");
222         *sdram_addr = 0xff;
223         ppcDcbf((unsigned long) sdram_addr);
224         udelay(100);
225
226         lbc->lsdmr = CFG_LBC_LSDMR_5;
227         asm("sync");
228         *sdram_addr = 0xff;
229         ppcDcbf((unsigned long) sdram_addr);
230         udelay(100);
231 }
232
233 #if !defined(CONFIG_SPD_EEPROM)
234 /*************************************************************************
235  *  fixed sdram init -- doesn't use serial presence detect.
236  ************************************************************************/
237 long int fixed_sdram (void)
238 {
239   #ifndef CFG_RAMBOOT
240         volatile ccsr_ddr_t *ddr= (void *)(CFG_MPC85xx_DDR_ADDR);
241
242         ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
243         ddr->cs0_config = CFG_DDR_CS0_CONFIG;
244         ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
245         ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
246         ddr->sdram_mode = CFG_DDR_MODE;
247         ddr->sdram_interval = CFG_DDR_INTERVAL;
248     #if defined (CONFIG_DDR_ECC)
249         ddr->err_disable = 0x0000000D;
250         ddr->err_sbe = 0x00ff0000;
251     #endif
252         asm("sync;isync;msync");
253         udelay(500);
254     #if defined (CONFIG_DDR_ECC)
255         /* Enable ECC checking */
256         ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
257     #else
258         ddr->sdram_cfg = CFG_DDR_CONTROL;
259     #endif
260         asm("sync; isync; msync");
261         udelay(500);
262   #endif
263         return CFG_SDRAM_SIZE * 1024 * 1024;
264 }
265 #endif  /* !defined(CONFIG_SPD_EEPROM) */
266
267
268 #if defined(CONFIG_PCI)
269 /*
270  * Initialize PCI Devices, report devices found.
271  */
272
273
274 static struct pci_controller hose;
275
276 #endif  /* CONFIG_PCI */
277
278
279 void
280 pci_init_board(void)
281 {
282 #ifdef CONFIG_PCI
283         pci_mpc85xx_init(&hose);
284 #endif /* CONFIG_PCI */
285 }
286
287
288 #if defined(CONFIG_OF_BOARD_SETUP)
289 void
290 ft_board_setup(void *blob, bd_t *bd)
291 {
292         int node, tmp[2];
293         const char *path;
294
295         ft_cpu_setup(blob, bd);
296
297         node = fdt_path_offset(blob, "/aliases");
298         tmp[0] = 0;
299         if (node >= 0) {
300 #ifdef CONFIG_PCI
301                 path = fdt_getprop(blob, node, "pci0", NULL);
302                 if (path) {
303                         tmp[1] = hose.last_busno - hose.first_busno;
304                         do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
305                 }
306 #endif
307         }
308 }
309 #endif