Compile warning fixed
[oweals/u-boot.git] / board / tqm8540 / tqm8540.c
1 /*
2  * Copyright 2005 DENX Software Engineering
3  * Copyright 2004 Freescale Semiconductor.
4  * (C) Copyright 2002,2003, Motorola Inc.
5  * Xianghua Xiao, (X.Xiao@motorola.com)
6  *
7  * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28
29 #include <common.h>
30 #include <pci.h>
31 #include <asm/processor.h>
32 #include <asm/immap_85xx.h>
33 #include <spd.h>
34
35 #if defined(CONFIG_DDR_ECC)
36 extern void ddr_enable_ecc (unsigned int dram_size);
37 #endif
38
39 extern long int spd_sdram (void);
40
41 void local_bus_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: TQM8540\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          * Initialize local bus.
62          */
63         local_bus_init ();
64
65         return 0;
66 }
67
68
69 long int initdram (int board_type)
70 {
71         long dram_size = 0;
72         extern long spd_sdram (void);
73         volatile immap_t *immap = (immap_t *) CFG_IMMR;
74
75 #if defined(CONFIG_DDR_DLL)
76         {
77                 volatile ccsr_gur_t *gur= &immap->im_gur;
78                 int i,x;
79
80                 x = 10;
81
82                 /*
83                  * Work around to stabilize DDR DLL
84                  */
85                 gur->ddrdllcr = 0x81000000;
86                 asm("sync;isync;msync");
87                 udelay (200);
88                 while (gur->ddrdllcr != 0x81000100) {
89                         gur->devdisr = gur->devdisr | 0x00010000;
90                         asm("sync;isync;msync");
91                         for (i=0; i<x; i++)
92                                 ;
93                         gur->devdisr = gur->devdisr & 0xfff7ffff;
94                         asm("sync;isync;msync");
95                         x++;
96                 }
97         }
98 #endif
99
100 #if defined(CONFIG_SPD_EEPROM)
101         dram_size = spd_sdram ();
102 #else
103         dram_size = fixed_sdram ();
104 #endif
105
106 #if defined(CONFIG_DDR_ECC)
107         /*
108          * Initialize and enable DDR ECC.
109          */
110         ddr_enable_ecc (dram_size);
111 #endif
112
113         return dram_size;
114 }
115
116
117 /*
118  * Initialize Local Bus
119  */
120
121 void local_bus_init (void)
122 {
123         volatile immap_t *immap = (immap_t *) CFG_IMMR;
124         volatile ccsr_gur_t *gur = &immap->im_gur;
125         volatile ccsr_lbc_t *lbc = &immap->im_lbc;
126
127         uint clkdiv;
128         uint lbc_hz;
129         sys_info_t sysinfo;
130
131         /*
132          * Errata LBC11.
133          * Fix Local Bus clock glitch when DLL is enabled.
134          *
135          * If localbus freq is < 66Mhz, DLL bypass mode must be used.
136          * If localbus freq is > 133Mhz, DLL can be safely enabled.
137          * Between 66 and 133, the DLL is enabled with an override workaround.
138          */
139
140         get_sys_info (&sysinfo);
141         clkdiv = lbc->lcrr & 0x0f;
142         lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
143
144         if (lbc_hz < 66) {
145                 lbc->lcrr = CFG_LBC_LCRR | 0x80000000;  /* DLL Bypass */
146                 lbc->ltedr = 0xa4c80000;        /* DK: !!! */
147
148         } else if (lbc_hz >= 133) {
149                 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000);       /* DLL Enabled */
150
151         } else {
152                 /*
153                  * On REV1 boards, need to change CLKDIV before enable DLL.
154                  * Default CLKDIV is 8, change it to 4 temporarily.
155                  */
156                 uint pvr = get_pvr ();
157                 uint temp_lbcdll = 0;
158
159                 if (pvr == PVR_85xx_REV1) {
160                         /* FIXME: Justify the high bit here. */
161                         lbc->lcrr = 0x10000004;
162                 }
163
164                 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000);       /* DLL Enabled */
165                 udelay (200);
166
167                 /*
168                  * Sample LBC DLL ctrl reg, upshift it to set the
169                  * override bits.
170                  */
171                 temp_lbcdll = gur->lbcdllcr;
172                 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
173                 asm ("sync;isync;msync");
174         }
175 }
176
177
178 #if defined(CFG_DRAM_TEST)
179 int testdram (void)
180 {
181         uint *pstart = (uint *) CFG_MEMTEST_START;
182         uint *pend = (uint *) CFG_MEMTEST_END;
183         uint *p;
184
185         printf ("SDRAM test phase 1:\n");
186         for (p = pstart; p < pend; p++)
187                 *p = 0xaaaaaaaa;
188
189         for (p = pstart; p < pend; p++) {
190                 if (*p != 0xaaaaaaaa) {
191                         printf ("SDRAM test fails at: %08x\n", (uint) p);
192                         return 1;
193                 }
194         }
195
196         printf ("SDRAM test phase 2:\n");
197         for (p = pstart; p < pend; p++)
198                 *p = 0x55555555;
199
200         for (p = pstart; p < pend; p++) {
201                 if (*p != 0x55555555) {
202                         printf ("SDRAM test fails at: %08x\n", (uint) p);
203                         return 1;
204                 }
205         }
206
207         printf ("SDRAM test passed.\n");
208         return 0;
209 }
210 #endif
211
212
213 #if !defined(CONFIG_SPD_EEPROM)
214 /*************************************************************************
215  *  fixed sdram init -- doesn't use serial presence detect.
216  ************************************************************************/
217 long int fixed_sdram (void)
218 {
219 #ifndef CFG_RAMBOOT
220         volatile immap_t *immap = (immap_t *) CFG_IMMR;
221         volatile ccsr_ddr_t *ddr = &immap->im_ddr;
222
223         ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
224         ddr->cs0_config = CFG_DDR_CS0_CONFIG;
225         ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
226         ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
227         ddr->sdram_mode = CFG_DDR_MODE;
228         ddr->sdram_interval = CFG_DDR_INTERVAL;
229         ddr->err_disable = 0x0000000D;
230 #if defined (CONFIG_DDR_ECC)
231         ddr->err_disable = 0x0000000D;
232         ddr->err_sbe = 0x00ff0000;
233 #endif
234         asm ("sync;isync;msync");
235         udelay (500);
236 #if defined (CONFIG_DDR_ECC)
237         /* Enable ECC checking */
238         ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
239 #else
240         ddr->sdram_cfg = CFG_DDR_CONTROL;
241 #endif
242         asm ("sync; isync; msync");
243         udelay (500);
244 #endif
245         return get_ram_size (0, CFG_SDRAM_SIZE * 1024 * 1024);
246 }
247 #endif /* !defined(CONFIG_SPD_EEPROM) */
248
249
250 #if defined(CONFIG_PCI)
251 /*
252  * Initialize PCI Devices, report devices found.
253  */
254
255 #ifndef CONFIG_PCI_PNP
256 static struct pci_config_table pci_mpc85xxads_config_table[] = {
257         {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
258          PCI_IDSEL_NUMBER, PCI_ANY_ID,
259          pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
260                                      PCI_ENET0_MEMADDR,
261                                      PCI_COMMAND_MEMORY |
262                                      PCI_COMMAND_MASTER}},
263         {}
264 };
265 #endif
266
267
268 static struct pci_controller hose = {
269 #ifndef CONFIG_PCI_PNP
270         config_table:pci_mpc85xxads_config_table,
271 #endif
272 };
273
274 #endif /* CONFIG_PCI */
275
276
277 void pci_init_board (void)
278 {
279 #ifdef CONFIG_PCI
280         extern void pci_mpc85xx_init (struct pci_controller *hose);
281
282         pci_mpc85xx_init (&hose);
283 #endif /* CONFIG_PCI */
284 }