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