]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/tqm8540/tqm8540.c
8e25081aeff639a6a7a7408ddbdaef9c6f3d7296
[karo-tx-uboot.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         puts ("Initializing\n");
76
77 #if defined(CONFIG_DDR_DLL)
78         {
79                 volatile ccsr_gur_t *gur = &immap->im_gur;
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)
98         /*
99          * Initialize and enable DDR ECC.
100          */
101         ddr_enable_ecc (dram_size);
102 #endif
103
104         puts ("    DDR: ");
105         return dram_size;
106 }
107
108
109 /*
110  * Initialize Local Bus
111  */
112
113 void local_bus_init (void)
114 {
115         volatile immap_t *immap = (immap_t *) CFG_IMMR;
116         volatile ccsr_gur_t *gur = &immap->im_gur;
117         volatile ccsr_lbc_t *lbc = &immap->im_lbc;
118
119         uint clkdiv;
120         uint lbc_hz;
121         sys_info_t sysinfo;
122
123         /*
124          * Errata LBC11.
125          * Fix Local Bus clock glitch when DLL is enabled.
126          *
127          * If localbus freq is < 66Mhz, DLL bypass mode must be used.
128          * If localbus freq is > 133Mhz, DLL can be safely enabled.
129          * Between 66 and 133, the DLL is enabled with an override workaround.
130          */
131
132         get_sys_info (&sysinfo);
133         clkdiv = lbc->lcrr & 0x0f;
134         lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
135
136         if (lbc_hz < 66) {
137                 lbc->lcrr = CFG_LBC_LCRR | 0x80000000;  /* DLL Bypass */
138                 lbc->ltedr = 0xa4c80000;        /* DK: !!! */
139
140         } else if (lbc_hz >= 133) {
141                 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000);       /* DLL Enabled */
142
143         } else {
144                 /*
145                  * On REV1 boards, need to change CLKDIV before enable DLL.
146                  * Default CLKDIV is 8, change it to 4 temporarily.
147                  */
148                 uint pvr = get_pvr ();
149                 uint temp_lbcdll = 0;
150
151                 if (pvr == PVR_85xx_REV1) {
152                         /* FIXME: Justify the high bit here. */
153                         lbc->lcrr = 0x10000004;
154                 }
155
156                 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000);       /* DLL Enabled */
157                 udelay (200);
158
159                 /*
160                  * Sample LBC DLL ctrl reg, upshift it to set the
161                  * override bits.
162                  */
163                 temp_lbcdll = gur->lbcdllcr;
164                 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
165                 asm ("sync;isync;msync");
166         }
167 }
168
169
170 #if defined(CFG_DRAM_TEST)
171 int testdram (void)
172 {
173         uint *pstart = (uint *) CFG_MEMTEST_START;
174         uint *pend = (uint *) CFG_MEMTEST_END;
175         uint *p;
176
177         printf ("SDRAM test phase 1:\n");
178         for (p = pstart; p < pend; p++)
179                 *p = 0xaaaaaaaa;
180
181         for (p = pstart; p < pend; p++) {
182                 if (*p != 0xaaaaaaaa) {
183                         printf ("SDRAM test fails at: %08x\n", (uint) p);
184                         return 1;
185                 }
186         }
187
188         printf ("SDRAM test phase 2:\n");
189         for (p = pstart; p < pend; p++)
190                 *p = 0x55555555;
191
192         for (p = pstart; p < pend; p++) {
193                 if (*p != 0x55555555) {
194                         printf ("SDRAM test fails at: %08x\n", (uint) p);
195                         return 1;
196                 }
197         }
198
199         printf ("SDRAM test passed.\n");
200         return 0;
201 }
202 #endif
203
204
205 #if !defined(CONFIG_SPD_EEPROM)
206 /*************************************************************************
207  *  fixed sdram init -- doesn't use serial presence detect.
208  ************************************************************************/
209 long int fixed_sdram (void)
210 {
211 #ifndef CFG_RAMBOOT
212         volatile immap_t *immap = (immap_t *) CFG_IMMR;
213         volatile ccsr_ddr_t *ddr = &immap->im_ddr;
214
215         ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
216         ddr->cs0_config = CFG_DDR_CS0_CONFIG;
217         ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
218         ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
219         ddr->sdram_mode = CFG_DDR_MODE;
220         ddr->sdram_interval = CFG_DDR_INTERVAL;
221         ddr->err_disable = 0x0000000D;
222 #if defined (CONFIG_DDR_ECC)
223         ddr->err_disable = 0x0000000D;
224         ddr->err_sbe = 0x00ff0000;
225 #endif
226         asm ("sync;isync;msync");
227         udelay (500);
228 #if defined (CONFIG_DDR_ECC)
229         /* Enable ECC checking */
230         ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
231 #else
232         ddr->sdram_cfg = CFG_DDR_CONTROL;
233 #endif
234         asm ("sync; isync; msync");
235         udelay (500);
236 #endif
237         return get_ram_size (0, CFG_SDRAM_SIZE * 1024 * 1024);
238 }
239 #endif /* !defined(CONFIG_SPD_EEPROM) */
240
241
242 #if defined(CONFIG_PCI)
243 /*
244  * Initialize PCI Devices, report devices found.
245  */
246
247 #ifndef CONFIG_PCI_PNP
248 static struct pci_config_table pci_mpc85xxads_config_table[] = {
249         {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
250          PCI_IDSEL_NUMBER, PCI_ANY_ID,
251          pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
252                                      PCI_ENET0_MEMADDR,
253                                      PCI_COMMAND_MEMORY |
254                                      PCI_COMMAND_MASTER}},
255         {}
256 };
257 #endif
258
259
260 static struct pci_controller hose = {
261 #ifndef CONFIG_PCI_PNP
262         config_table:pci_mpc85xxads_config_table,
263 #endif
264 };
265
266 #endif /* CONFIG_PCI */
267
268
269 void pci_init_board (void)
270 {
271 #ifdef CONFIG_PCI
272         extern void pci_mpc85xx_init (struct pci_controller *hose);
273
274         pci_mpc85xx_init (&hose);
275 #endif /* CONFIG_PCI */
276 }