blob: 7433ebf25bc7c96daa838817b07e15279d63efa2 [file] [log] [blame]
Jon Loeliger77a4f6e2005-07-25 14:05:07 -05001/*
2 * Copyright 2004 Freescale Semiconductor.
3 *
4 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <pci.h>
27#include <asm/processor.h>
28#include <asm/immap_85xx.h>
29#include <spd.h>
Andy Fleming239e75f2006-09-13 10:34:18 -050030#include <miiphy.h>
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050031
32#include "../common/cadmus.h"
33#include "../common/eeprom.h"
Matthew McClintockaa6dd062006-06-28 10:46:13 -050034#include "../common/via.h"
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050035
36#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
37extern void ddr_enable_ecc(unsigned int dram_size);
38#endif
39
40extern long int spd_sdram(void);
41
42void local_bus_init(void);
43void sdram_init(void);
44
45int board_early_init_f (void)
46{
47 return 0;
48}
49
50int checkboard (void)
51{
52 volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
53 volatile ccsr_gur_t *gur = &immap->im_gur;
54
55 /* PCI slot in USER bits CSR[6:7] by convention. */
56 uint pci_slot = get_pci_slot ();
57
58 uint pci_dual = get_pci_dual (); /* PCI DUAL in CM_PCI[3] */
59 uint pci1_32 = gur->pordevsr & 0x10000; /* PORDEVSR[15] */
60 uint pci1_clk_sel = gur->porpllsr & 0x8000; /* PORPLLSR[16] */
61 uint pci2_clk_sel = gur->porpllsr & 0x4000; /* PORPLLSR[17] */
62
63 uint pci1_speed = get_clock_freq (); /* PCI PSPEED in [4:5] */
64
65 uint cpu_board_rev = get_cpu_board_revision ();
66
67 printf ("Board: CDS Version 0x%02x, PCI Slot %d\n",
68 get_board_version (), pci_slot);
69
70 printf ("CPU Board Revision %d.%d (0x%04x)\n",
71 MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
72 MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
73
74 printf (" PCI1: %d bit, %s MHz, %s\n",
75 (pci1_32) ? 32 : 64,
76 (pci1_speed == 33000000) ? "33" :
77 (pci1_speed == 66000000) ? "66" : "unknown",
78 pci1_clk_sel ? "sync" : "async");
79
80 if (pci_dual) {
81 printf (" PCI2: 32 bit, 66 MHz, %s\n",
82 pci2_clk_sel ? "sync" : "async");
83 } else {
84 printf (" PCI2: disabled\n");
85 }
86
87 /*
88 * Initialize local bus.
89 */
90 local_bus_init ();
91
92
93 /*
94 * Hack TSEC 3 and 4 IO voltages.
95 */
96 gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */
97
98 return 0;
99}
100
101long int
102initdram(int board_type)
103{
104 long dram_size = 0;
105 volatile immap_t *immap = (immap_t *)CFG_IMMR;
106
107 puts("Initializing\n");
108
109#if defined(CONFIG_DDR_DLL)
110 {
111 /*
112 * Work around to stabilize DDR DLL MSYNC_IN.
113 * Errata DDR9 seems to have been fixed.
114 * This is now the workaround for Errata DDR11:
115 * Override DLL = 1, Course Adj = 1, Tap Select = 0
116 */
117
118 volatile ccsr_gur_t *gur= &immap->im_gur;
119
120 gur->ddrdllcr = 0x81000000;
121 asm("sync;isync;msync");
122 udelay(200);
123 }
124#endif
125 dram_size = spd_sdram();
126
127#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
128 /*
129 * Initialize and enable DDR ECC.
130 */
131 ddr_enable_ecc(dram_size);
132#endif
133 /*
134 * SDRAM Initialization
135 */
136 sdram_init();
137
138 puts(" DDR: ");
139 return dram_size;
140}
141
142/*
143 * Initialize Local Bus
144 */
145void
146local_bus_init(void)
147{
148 volatile immap_t *immap = (immap_t *)CFG_IMMR;
149 volatile ccsr_gur_t *gur = &immap->im_gur;
150 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
151
152 uint clkdiv;
153 uint lbc_hz;
154 sys_info_t sysinfo;
155
156 get_sys_info(&sysinfo);
157 clkdiv = (lbc->lcrr & 0x0f) * 2;
158 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
159
160 gur->lbiuiplldcr1 = 0x00078080;
161 if (clkdiv == 16) {
162 gur->lbiuiplldcr0 = 0x7c0f1bf0;
163 } else if (clkdiv == 8) {
164 gur->lbiuiplldcr0 = 0x6c0f1bf0;
165 } else if (clkdiv == 4) {
166 gur->lbiuiplldcr0 = 0x5c0f1bf0;
167 }
168
169 lbc->lcrr |= 0x00030000;
170
171 asm("sync;isync;msync");
172}
173
174/*
175 * Initialize SDRAM memory on the Local Bus.
176 */
177void
178sdram_init(void)
179{
180#if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
181
182 uint idx;
183 volatile immap_t *immap = (immap_t *)CFG_IMMR;
184 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
185 uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
186 uint cpu_board_rev;
187 uint lsdmr_common;
188
189 puts(" SDRAM: ");
190
191 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
192
193 /*
194 * Setup SDRAM Base and Option Registers
195 */
196 lbc->or2 = CFG_OR2_PRELIM;
197 asm("msync");
198
199 lbc->br2 = CFG_BR2_PRELIM;
200 asm("msync");
201
202 lbc->lbcr = CFG_LBC_LBCR;
203 asm("msync");
204
205
206 lbc->lsrt = CFG_LBC_LSRT;
207 lbc->mrtpr = CFG_LBC_MRTPR;
208 asm("msync");
209
210 /*
211 * MPC8548 uses "new" 15-16 style addressing.
212 */
213 cpu_board_rev = get_cpu_board_revision();
214 lsdmr_common = CFG_LBC_LSDMR_COMMON;
215 lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
216
217 /*
218 * Issue PRECHARGE ALL command.
219 */
220 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
221 asm("sync;msync");
222 *sdram_addr = 0xff;
223 ppcDcbf((unsigned long) sdram_addr);
224 udelay(100);
225
226 /*
227 * Issue 8 AUTO REFRESH commands.
228 */
229 for (idx = 0; idx < 8; idx++) {
230 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
231 asm("sync;msync");
232 *sdram_addr = 0xff;
233 ppcDcbf((unsigned long) sdram_addr);
234 udelay(100);
235 }
236
237 /*
238 * Issue 8 MODE-set command.
239 */
240 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
241 asm("sync;msync");
242 *sdram_addr = 0xff;
243 ppcDcbf((unsigned long) sdram_addr);
244 udelay(100);
245
246 /*
247 * Issue NORMAL OP command.
248 */
249 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
250 asm("sync;msync");
251 *sdram_addr = 0xff;
252 ppcDcbf((unsigned long) sdram_addr);
253 udelay(200); /* Overkill. Must wait > 200 bus cycles */
254
255#endif /* enable SDRAM init */
256}
257
258#if defined(CFG_DRAM_TEST)
259int
260testdram(void)
261{
262 uint *pstart = (uint *) CFG_MEMTEST_START;
263 uint *pend = (uint *) CFG_MEMTEST_END;
264 uint *p;
265
266 printf("Testing DRAM from 0x%08x to 0x%08x\n",
267 CFG_MEMTEST_START,
268 CFG_MEMTEST_END);
269
270 printf("DRAM test phase 1:\n");
271 for (p = pstart; p < pend; p++)
272 *p = 0xaaaaaaaa;
273
274 for (p = pstart; p < pend; p++) {
275 if (*p != 0xaaaaaaaa) {
276 printf ("DRAM test fails at: %08x\n", (uint) p);
277 return 1;
278 }
279 }
280
281 printf("DRAM test phase 2:\n");
282 for (p = pstart; p < pend; p++)
283 *p = 0x55555555;
284
285 for (p = pstart; p < pend; p++) {
286 if (*p != 0x55555555) {
287 printf ("DRAM test fails at: %08x\n", (uint) p);
288 return 1;
289 }
290 }
291
292 printf("DRAM test passed.\n");
293 return 0;
294}
295#endif
296
297#if defined(CONFIG_PCI)
Matthew McClintockaa6dd062006-06-28 10:46:13 -0500298/* For some reason the Tundra PCI bridge shows up on itself as a
299 * different device. Work around that by refusing to configure it.
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500300 */
Matthew McClintockaa6dd062006-06-28 10:46:13 -0500301void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500302
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500303static struct pci_config_table pci_mpc85xxcds_config_table[] = {
Matthew McClintockaa6dd062006-06-28 10:46:13 -0500304 {0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
305 {0x1106, 0x0686, PCI_ANY_ID, 1, 2, 0, mpc85xx_config_via, {0,0,0}},
306 {0x1106, 0x0571, PCI_ANY_ID, 1, 2, 1, mpc85xx_config_via_usbide, {0,0,0}},
307 {0x1105, 0x3038, PCI_ANY_ID, 1, 2, 2, mpc85xx_config_via_usb, {0,0,0}},
308 {0x1106, 0x3038, PCI_ANY_ID, 1, 2, 3, mpc85xx_config_via_usb2, {0,0,0}},
309 {0x1106, 0x3058, PCI_ANY_ID, 1, 2, 5, mpc85xx_config_via_power, {0,0,0}},
310 {0x1106, 0x3068, PCI_ANY_ID, 1, 2, 6, mpc85xx_config_via_ac97, {0,0,0}}
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500311};
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500312
Matthew McClintockaa6dd062006-06-28 10:46:13 -0500313static struct pci_controller hose[] = {
314 { config_table: pci_mpc85xxcds_config_table,},
315#ifdef CONFIG_MPC85XX_PCI2
316 {},
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500317#endif
318};
319
320#endif /* CONFIG_PCI */
321
322void
323pci_init_board(void)
324{
325#ifdef CONFIG_PCI
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500326 pci_mpc85xx_init(&hose);
327#endif
328}
Andy Fleming239e75f2006-09-13 10:34:18 -0500329
330int last_stage_init(void)
331{
Jon Loeliger249688a2006-10-20 15:54:34 -0500332 unsigned short temp;
Andy Fleming239e75f2006-09-13 10:34:18 -0500333
334 /* Change the resistors for the PHY */
335 /* This is needed to get the RGMII working for the 1.3+
336 * CDS cards */
337 if (get_board_version() == 0x13) {
338 miiphy_write(CONFIG_MPC85XX_TSEC1_NAME,
339 TSEC1_PHY_ADDR, 29, 18);
340
341 miiphy_read(CONFIG_MPC85XX_TSEC1_NAME,
342 TSEC1_PHY_ADDR, 30, &temp);
343
344 temp = (temp & 0xf03f);
345 temp |= 2 << 9; /* 36 ohm */
346 temp |= 2 << 6; /* 39 ohm */
347
348 miiphy_write(CONFIG_MPC85XX_TSEC1_NAME,
349 TSEC1_PHY_ADDR, 30, temp);
350
351 miiphy_write(CONFIG_MPC85XX_TSEC1_NAME,
352 TSEC1_PHY_ADDR, 29, 3);
353
354 miiphy_write(CONFIG_MPC85XX_TSEC1_NAME,
355 TSEC1_PHY_ADDR, 30, 0x8000);
356 }
357
358 return 0;
359}