blob: 88c6480d4151a792fdd9a40e36c78d1644f848e0 [file] [log] [blame]
Kumar Gala9490a7f2008-07-25 13:31:05 -05001/*
2 * Copyright 2008 Freescale Semiconductor.
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24#include <command.h>
25#include <pci.h>
26#include <asm/processor.h>
27#include <asm/mmu.h>
Kumar Gala7c0d4a72008-09-22 14:11:11 -050028#include <asm/cache.h>
Kumar Gala9490a7f2008-07-25 13:31:05 -050029#include <asm/immap_85xx.h>
Kumar Galac8514622009-04-02 13:22:48 -050030#include <asm/fsl_pci.h>
Kumar Gala9490a7f2008-07-25 13:31:05 -050031#include <asm/fsl_ddr_sdram.h>
32#include <asm/io.h>
33#include <spd.h>
34#include <miiphy.h>
35#include <libfdt.h>
36#include <spd_sdram.h>
37#include <fdt_support.h>
Jason Jin2e26d832008-10-10 11:41:00 +080038#include <tsec.h>
39#include <netdev.h>
Wolfgang Denk54a7cc42009-01-28 09:25:31 +010040#include <sata.h>
Kumar Gala9490a7f2008-07-25 13:31:05 -050041
42#include "../common/pixis.h"
Jason Jin2e26d832008-10-10 11:41:00 +080043#include "../common/sgmii_riser.h"
Kumar Gala9490a7f2008-07-25 13:31:05 -050044
Kumar Gala9490a7f2008-07-25 13:31:05 -050045phys_size_t fixed_sdram(void);
46
Andy Fleming80522dc2008-10-30 16:51:33 -050047int board_early_init_f (void)
48{
49#ifdef CONFIG_MMC
50 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
51
52 setbits_be32(&gur->pmuxcr,
53 (MPC85xx_PMUXCR_SD_DATA |
54 MPC85xx_PMUXCR_SDHC_CD |
55 MPC85xx_PMUXCR_SDHC_WP));
56
57#endif
58 return 0;
59}
60
Kumar Gala9490a7f2008-07-25 13:31:05 -050061int checkboard (void)
62{
63 printf ("Board: MPC8536DS, System ID: 0x%02x, "
64 "System Version: 0x%02x, FPGA Version: 0x%02x\n",
65 in8(PIXIS_BASE + PIXIS_ID), in8(PIXIS_BASE + PIXIS_VER),
66 in8(PIXIS_BASE + PIXIS_PVER));
67 return 0;
68}
69
70phys_size_t
71initdram(int board_type)
72{
73 phys_size_t dram_size = 0;
74
75 puts("Initializing....");
76
77#ifdef CONFIG_SPD_EEPROM
78 dram_size = fsl_ddr_sdram();
Kumar Gala9490a7f2008-07-25 13:31:05 -050079#else
80 dram_size = fixed_sdram();
81#endif
Dave Liue57f0fa2008-10-28 17:53:45 +080082 dram_size = setup_ddr_tlbs(dram_size / 0x100000);
83 dram_size *= 0x100000;
Kumar Gala9490a7f2008-07-25 13:31:05 -050084
Kumar Gala9490a7f2008-07-25 13:31:05 -050085 puts(" DDR: ");
86 return dram_size;
87}
88
89#if !defined(CONFIG_SPD_EEPROM)
90/*
91 * Fixed sdram init -- doesn't use serial presence detect.
92 */
93
94phys_size_t fixed_sdram (void)
95{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020096 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Kumar Gala9490a7f2008-07-25 13:31:05 -050097 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
98 uint d_init;
99
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200100 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
101 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500102
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200103 ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
104 ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
105 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
106 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
107 ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
108 ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
109 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
110 ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
111 ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
112 ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500113
114#if defined (CONFIG_DDR_ECC)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200115 ddr->err_int_en = CONFIG_SYS_DDR_ERR_INT_EN;
116 ddr->err_disable = CONFIG_SYS_DDR_ERR_DIS;
117 ddr->err_sbe = CONFIG_SYS_DDR_SBE;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500118#endif
119 asm("sync;isync");
120
121 udelay(500);
122
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200123 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500124
125#if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
126 d_init = 1;
127 debug("DDR - 1st controller: memory initializing\n");
128 /*
129 * Poll until memory is initialized.
130 * 512 Meg at 400 might hit this 200 times or so.
131 */
132 while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) {
133 udelay(1000);
134 }
135 debug("DDR: memory initialized\n\n");
136 asm("sync; isync");
137 udelay(500);
138#endif
139
140 return 512 * 1024 * 1024;
141}
142
143#endif
144
145#ifdef CONFIG_PCI1
146static struct pci_controller pci1_hose;
147#endif
148
149#ifdef CONFIG_PCIE1
150static struct pci_controller pcie1_hose;
151#endif
152
153#ifdef CONFIG_PCIE2
154static struct pci_controller pcie2_hose;
155#endif
156
157#ifdef CONFIG_PCIE3
158static struct pci_controller pcie3_hose;
159#endif
160
Kumar Gala2dba0de2008-10-21 08:28:33 -0500161extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
162extern void fsl_pci_init(struct pci_controller *hose);
163
Kumar Gala9490a7f2008-07-25 13:31:05 -0500164int first_free_busno=0;
165
166void
167pci_init_board(void)
168{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200169 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Kumar Gala9490a7f2008-07-25 13:31:05 -0500170 uint devdisr = gur->devdisr;
171 uint sdrs2_io_sel =
172 (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27;
173 uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
174 uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
175
176 debug(" pci_init_board: devdisr=%x, sdrs2_io_sel=%x, io_sel=%x,\
177 host_agent=%x\n", devdisr, sdrs2_io_sel, io_sel, host_agent);
178
179 if (sdrs2_io_sel == 7)
180 printf(" Serdes2 disalbed\n");
181 else if (sdrs2_io_sel == 4) {
182 printf(" eTSEC1 is in sgmii mode.\n");
183 printf(" eTSEC3 is in sgmii mode.\n");
184 } else if (sdrs2_io_sel == 6)
185 printf(" eTSEC1 is in sgmii mode.\n");
186
187#ifdef CONFIG_PCIE3
188{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200189 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500190 struct pci_controller *hose = &pcie3_hose;
191 int pcie_ep = (host_agent == 1);
192 int pcie_configured = (io_sel == 7);
Kumar Gala2dba0de2008-10-21 08:28:33 -0500193 struct pci_region *r = hose->regions;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500194
195 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
196 printf ("\n PCIE3 connected to Slot3 as %s (base address %x)",
197 pcie_ep ? "End Point" : "Root Complex",
198 (uint)pci);
199 if (pci->pme_msg_det) {
200 pci->pme_msg_det = 0xffffffff;
201 debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
202 }
203 printf ("\n");
204
205 /* inbound */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500206 r += fsl_pci_setup_inbound_windows(r);
Kumar Gala9490a7f2008-07-25 13:31:05 -0500207
208 /* outbound memory */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500209 pci_set_region(r++,
Kumar Gala10795f42008-12-02 16:08:36 -0600210 CONFIG_SYS_PCIE3_MEM_BUS,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200211 CONFIG_SYS_PCIE3_MEM_PHYS,
212 CONFIG_SYS_PCIE3_MEM_SIZE,
Kumar Gala9490a7f2008-07-25 13:31:05 -0500213 PCI_REGION_MEM);
214
215 /* outbound io */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500216 pci_set_region(r++,
Kumar Gala5f91ef62008-12-02 16:08:37 -0600217 CONFIG_SYS_PCIE3_IO_BUS,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200218 CONFIG_SYS_PCIE3_IO_PHYS,
219 CONFIG_SYS_PCIE3_IO_SIZE,
Kumar Gala9490a7f2008-07-25 13:31:05 -0500220 PCI_REGION_IO);
221
Kumar Gala2dba0de2008-10-21 08:28:33 -0500222 hose->region_count = r - hose->regions;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500223
224 hose->first_busno=first_free_busno;
225 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
226
227 fsl_pci_init(hose);
228
229 first_free_busno=hose->last_busno+1;
230 printf (" PCIE3 on bus %02x - %02x\n",
231 hose->first_busno,hose->last_busno);
232 } else {
233 printf (" PCIE3: disabled\n");
234 }
235
236 }
237#else
238 gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
239#endif
240
241#ifdef CONFIG_PCIE1
242 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200243 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500244 struct pci_controller *hose = &pcie1_hose;
245 int pcie_ep = (host_agent == 5);
246 int pcie_configured = (io_sel == 2 || io_sel == 3
247 || io_sel == 5 || io_sel == 7);
Kumar Gala2dba0de2008-10-21 08:28:33 -0500248 struct pci_region *r = hose->regions;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500249
250 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
251 printf ("\n PCIE1 connected to Slot1 as %s (base address %x)",
252 pcie_ep ? "End Point" : "Root Complex",
253 (uint)pci);
254 if (pci->pme_msg_det) {
255 pci->pme_msg_det = 0xffffffff;
256 debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
257 }
258 printf ("\n");
259
260 /* inbound */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500261 r += fsl_pci_setup_inbound_windows(r);
Kumar Gala9490a7f2008-07-25 13:31:05 -0500262
263 /* outbound memory */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500264 pci_set_region(r++,
Kumar Gala10795f42008-12-02 16:08:36 -0600265 CONFIG_SYS_PCIE1_MEM_BUS,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200266 CONFIG_SYS_PCIE1_MEM_PHYS,
267 CONFIG_SYS_PCIE1_MEM_SIZE,
Kumar Gala9490a7f2008-07-25 13:31:05 -0500268 PCI_REGION_MEM);
269
270 /* outbound io */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500271 pci_set_region(r++,
Kumar Gala5f91ef62008-12-02 16:08:37 -0600272 CONFIG_SYS_PCIE1_IO_BUS,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200273 CONFIG_SYS_PCIE1_IO_PHYS,
274 CONFIG_SYS_PCIE1_IO_SIZE,
Kumar Gala9490a7f2008-07-25 13:31:05 -0500275 PCI_REGION_IO);
276
Kumar Gala10795f42008-12-02 16:08:36 -0600277#ifdef CONFIG_SYS_PCIE1_MEM_BUS2
Kumar Gala9490a7f2008-07-25 13:31:05 -0500278 /* outbound memory */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500279 pci_set_region(r++,
Kumar Gala10795f42008-12-02 16:08:36 -0600280 CONFIG_SYS_PCIE1_MEM_BUS2,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200281 CONFIG_SYS_PCIE1_MEM_PHYS2,
282 CONFIG_SYS_PCIE1_MEM_SIZE2,
Kumar Gala9490a7f2008-07-25 13:31:05 -0500283 PCI_REGION_MEM);
Kumar Gala9490a7f2008-07-25 13:31:05 -0500284#endif
Kumar Gala2dba0de2008-10-21 08:28:33 -0500285 hose->region_count = r - hose->regions;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500286 hose->first_busno=first_free_busno;
287
288 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
289
290 fsl_pci_init(hose);
291
292 first_free_busno=hose->last_busno+1;
293 printf(" PCIE1 on bus %02x - %02x\n",
294 hose->first_busno,hose->last_busno);
295
296 } else {
297 printf (" PCIE1: disabled\n");
298 }
299
300 }
301#else
302 gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
303#endif
304
305#ifdef CONFIG_PCIE2
306 {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200307 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500308 struct pci_controller *hose = &pcie2_hose;
309 int pcie_ep = (host_agent == 3);
310 int pcie_configured = (io_sel == 5 || io_sel == 7);
Kumar Gala2dba0de2008-10-21 08:28:33 -0500311 struct pci_region *r = hose->regions;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500312
313 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
314 printf ("\n PCIE2 connected to Slot 2 as %s (base address %x)",
315 pcie_ep ? "End Point" : "Root Complex",
316 (uint)pci);
317 if (pci->pme_msg_det) {
318 pci->pme_msg_det = 0xffffffff;
319 debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
320 }
321 printf ("\n");
322
323 /* inbound */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500324 r += fsl_pci_setup_inbound_windows(r);
Kumar Gala9490a7f2008-07-25 13:31:05 -0500325
326 /* outbound memory */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500327 pci_set_region(r++,
Kumar Gala10795f42008-12-02 16:08:36 -0600328 CONFIG_SYS_PCIE2_MEM_BUS,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200329 CONFIG_SYS_PCIE2_MEM_PHYS,
330 CONFIG_SYS_PCIE2_MEM_SIZE,
Kumar Gala9490a7f2008-07-25 13:31:05 -0500331 PCI_REGION_MEM);
332
333 /* outbound io */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500334 pci_set_region(r++,
Kumar Gala5f91ef62008-12-02 16:08:37 -0600335 CONFIG_SYS_PCIE2_IO_BUS,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200336 CONFIG_SYS_PCIE2_IO_PHYS,
337 CONFIG_SYS_PCIE2_IO_SIZE,
Kumar Gala9490a7f2008-07-25 13:31:05 -0500338 PCI_REGION_IO);
339
Kumar Gala10795f42008-12-02 16:08:36 -0600340#ifdef CONFIG_SYS_PCIE2_MEM_BUS2
Kumar Gala9490a7f2008-07-25 13:31:05 -0500341 /* outbound memory */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500342 pci_set_region(r++,
Kumar Gala10795f42008-12-02 16:08:36 -0600343 CONFIG_SYS_PCIE2_MEM_BUS2,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200344 CONFIG_SYS_PCIE2_MEM_PHYS2,
345 CONFIG_SYS_PCIE2_MEM_SIZE2,
Kumar Gala9490a7f2008-07-25 13:31:05 -0500346 PCI_REGION_MEM);
Kumar Gala9490a7f2008-07-25 13:31:05 -0500347#endif
Kumar Gala2dba0de2008-10-21 08:28:33 -0500348 hose->region_count = r - hose->regions;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500349 hose->first_busno=first_free_busno;
350 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
351
352 fsl_pci_init(hose);
353 first_free_busno=hose->last_busno+1;
354 printf (" PCIE2 on bus %02x - %02x\n",
355 hose->first_busno,hose->last_busno);
356
357 } else {
358 printf (" PCIE2: disabled\n");
359 }
360
361 }
362#else
363 gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
364#endif
365
366
367#ifdef CONFIG_PCI1
368{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200369 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500370 struct pci_controller *hose = &pci1_hose;
Kumar Gala2dba0de2008-10-21 08:28:33 -0500371 struct pci_region *r = hose->regions;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500372
373 uint pci_agent = (host_agent == 6);
374 uint pci_speed = 66666000; /*get_clock_freq (); PCI PSPEED in [4:5] */
375 uint pci_32 = 1;
376 uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
377 uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
378
379
380 if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
381 printf ("\n PCI: %d bit, %s MHz, %s, %s, %s (base address %x)\n",
382 (pci_32) ? 32 : 64,
383 (pci_speed == 33333000) ? "33" :
384 (pci_speed == 66666000) ? "66" : "unknown",
385 pci_clk_sel ? "sync" : "async",
386 pci_agent ? "agent" : "host",
387 pci_arb ? "arbiter" : "external-arbiter",
388 (uint)pci
389 );
390
391 /* inbound */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500392 r += fsl_pci_setup_inbound_windows(r);
Kumar Gala9490a7f2008-07-25 13:31:05 -0500393
394 /* outbound memory */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500395 pci_set_region(r++,
Kumar Gala10795f42008-12-02 16:08:36 -0600396 CONFIG_SYS_PCI1_MEM_BUS,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200397 CONFIG_SYS_PCI1_MEM_PHYS,
398 CONFIG_SYS_PCI1_MEM_SIZE,
Kumar Gala9490a7f2008-07-25 13:31:05 -0500399 PCI_REGION_MEM);
400
401 /* outbound io */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500402 pci_set_region(r++,
Kumar Gala5f91ef62008-12-02 16:08:37 -0600403 CONFIG_SYS_PCI1_IO_BUS,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200404 CONFIG_SYS_PCI1_IO_PHYS,
405 CONFIG_SYS_PCI1_IO_SIZE,
Kumar Gala9490a7f2008-07-25 13:31:05 -0500406 PCI_REGION_IO);
Kumar Gala2dba0de2008-10-21 08:28:33 -0500407
Kumar Gala10795f42008-12-02 16:08:36 -0600408#ifdef CONFIG_SYS_PCI1_MEM_BUS2
Kumar Gala9490a7f2008-07-25 13:31:05 -0500409 /* outbound memory */
Kumar Gala2dba0de2008-10-21 08:28:33 -0500410 pci_set_region(r++,
Kumar Gala10795f42008-12-02 16:08:36 -0600411 CONFIG_SYS_PCI1_MEM_BUS2,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200412 CONFIG_SYS_PCI1_MEM_PHYS2,
413 CONFIG_SYS_PCI1_MEM_SIZE2,
Kumar Gala9490a7f2008-07-25 13:31:05 -0500414 PCI_REGION_MEM);
Kumar Gala9490a7f2008-07-25 13:31:05 -0500415#endif
Kumar Gala2dba0de2008-10-21 08:28:33 -0500416 hose->region_count = r - hose->regions;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500417 hose->first_busno=first_free_busno;
418 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
419
420 fsl_pci_init(hose);
421 first_free_busno=hose->last_busno+1;
422 printf ("PCI on bus %02x - %02x\n",
423 hose->first_busno,hose->last_busno);
424 } else {
425 printf (" PCI: disabled\n");
426 }
427}
428#else
429 gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
430#endif
431}
432
433
434int board_early_init_r(void)
435{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200436 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
Kumar Gala9490a7f2008-07-25 13:31:05 -0500437 const u8 flash_esel = 1;
438
439 /*
440 * Remap Boot flash + PROMJET region to caching-inhibited
441 * so that flash can be erased properly.
442 */
443
Kumar Gala7c0d4a72008-09-22 14:11:11 -0500444 /* Flush d-cache and invalidate i-cache of any FLASH data */
Wolfgang Denk3cbd8232008-11-02 16:14:22 +0100445 flush_dcache();
446 invalidate_icache();
Kumar Gala9490a7f2008-07-25 13:31:05 -0500447
448 /* invalidate existing TLB entry for flash + promjet */
449 disable_tlb(flash_esel);
450
Kumar Galac953ddf2008-12-02 14:19:34 -0600451 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, /* tlb, epn, rpn */
Kumar Gala9490a7f2008-07-25 13:31:05 -0500452 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
453 0, flash_esel, BOOKE_PAGESZ_256M, 1); /* ts, esel, tsize, iprot */
454
455 return 0;
456}
457
458#ifdef CONFIG_GET_CLK_FROM_ICS307
459/* decode S[0-2] to Output Divider (OD) */
460static unsigned char
461ics307_S_to_OD[] = {
462 10, 2, 8, 4, 5, 7, 3, 6
463};
464
465/* Calculate frequency being generated by ICS307-02 clock chip based upon
466 * the control bytes being programmed into it. */
467/* XXX: This function should probably go into a common library */
468static unsigned long
469ics307_clk_freq (unsigned char cw0, unsigned char cw1, unsigned char cw2)
470{
471 const unsigned long long InputFrequency = CONFIG_ICS307_REFCLK_HZ;
472 unsigned long VDW = ((cw1 << 1) & 0x1FE) + ((cw2 >> 7) & 1);
473 unsigned long RDW = cw2 & 0x7F;
474 unsigned long OD = ics307_S_to_OD[cw0 & 0x7];
475 unsigned long freq;
476
477 /* CLK1Frequency = InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD) */
478
479 /* cw0: C1 C0 TTL F1 F0 S2 S1 S0
480 * cw1: V8 V7 V6 V5 V4 V3 V2 V1
481 * cw2: V0 R6 R5 R4 R3 R2 R1 R0
482 *
483 * R6:R0 = Reference Divider Word (RDW)
484 * V8:V0 = VCO Divider Word (VDW)
485 * S2:S0 = Output Divider Select (OD)
486 * F1:F0 = Function of CLK2 Output
487 * TTL = duty cycle
488 * C1:C0 = internal load capacitance for cyrstal
489 */
490
491 /* Adding 1 to get a "nicely" rounded number, but this needs
492 * more tweaking to get a "properly" rounded number. */
493
494 freq = 1 + (InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD));
495
496 debug("ICS307: CW[0-2]: %02X %02X %02X => %u Hz\n", cw0, cw1, cw2,
497 freq);
498 return freq;
499}
500
501unsigned long
502get_board_sys_clk(ulong dummy)
503{
504 return ics307_clk_freq (
505 in8(PIXIS_BASE + PIXIS_VSYSCLK0),
506 in8(PIXIS_BASE + PIXIS_VSYSCLK1),
507 in8(PIXIS_BASE + PIXIS_VSYSCLK2)
508 );
509}
510
511unsigned long
512get_board_ddr_clk(ulong dummy)
513{
514 return ics307_clk_freq (
515 in8(PIXIS_BASE + PIXIS_VDDRCLK0),
516 in8(PIXIS_BASE + PIXIS_VDDRCLK1),
517 in8(PIXIS_BASE + PIXIS_VDDRCLK2)
518 );
519}
520#else
521unsigned long
522get_board_sys_clk(ulong dummy)
523{
524 u8 i;
525 ulong val = 0;
526
527 i = in8(PIXIS_BASE + PIXIS_SPD);
528 i &= 0x07;
529
530 switch (i) {
531 case 0:
532 val = 33333333;
533 break;
534 case 1:
535 val = 40000000;
536 break;
537 case 2:
538 val = 50000000;
539 break;
540 case 3:
541 val = 66666666;
542 break;
543 case 4:
544 val = 83333333;
545 break;
546 case 5:
547 val = 100000000;
548 break;
549 case 6:
550 val = 133333333;
551 break;
552 case 7:
553 val = 166666666;
554 break;
555 }
556
557 return val;
558}
559
560unsigned long
561get_board_ddr_clk(ulong dummy)
562{
563 u8 i;
564 ulong val = 0;
565
566 i = in8(PIXIS_BASE + PIXIS_SPD);
567 i &= 0x38;
568 i >>= 3;
569
570 switch (i) {
571 case 0:
572 val = 33333333;
573 break;
574 case 1:
575 val = 40000000;
576 break;
577 case 2:
578 val = 50000000;
579 break;
580 case 3:
581 val = 66666666;
582 break;
583 case 4:
584 val = 83333333;
585 break;
586 case 5:
587 val = 100000000;
588 break;
589 case 6:
590 val = 133333333;
591 break;
592 case 7:
593 val = 166666666;
594 break;
595 }
596 return val;
597}
598#endif
599
Mike Frysingercf7e3992009-01-27 16:12:21 -0500600int sata_initialize(void)
Jason Jin0f8cbc12008-10-10 11:41:01 +0800601{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200602 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Jason Jin0f8cbc12008-10-10 11:41:01 +0800603 uint sdrs2_io_sel =
604 (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27;
605 if (sdrs2_io_sel & 0x04)
Mike Frysingercf7e3992009-01-27 16:12:21 -0500606 return 1;
Jason Jin0f8cbc12008-10-10 11:41:01 +0800607
Mike Frysingercf7e3992009-01-27 16:12:21 -0500608 return __sata_initialize();
Jason Jin0f8cbc12008-10-10 11:41:01 +0800609}
610
Jason Jin2e26d832008-10-10 11:41:00 +0800611int board_eth_init(bd_t *bis)
612{
613#ifdef CONFIG_TSEC_ENET
614 struct tsec_info_struct tsec_info[2];
615 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
616 int num = 0;
617 uint sdrs2_io_sel =
618 (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27;
619
620#ifdef CONFIG_TSEC1
621 SET_STD_TSEC_INFO(tsec_info[num], 1);
622 if ((sdrs2_io_sel == 4) || (sdrs2_io_sel == 6)) {
623 tsec_info[num].phyaddr = 0;
624 tsec_info[num].flags |= TSEC_SGMII;
625 }
626 num++;
627#endif
628#ifdef CONFIG_TSEC3
629 SET_STD_TSEC_INFO(tsec_info[num], 3);
630 if (sdrs2_io_sel == 4) {
631 tsec_info[num].phyaddr = 1;
632 tsec_info[num].flags |= TSEC_SGMII;
633 }
634 num++;
635#endif
636
637 if (!num) {
638 printf("No TSECs initialized\n");
639 return 0;
640 }
641
Andy Flemingfeede8b2008-12-05 20:10:22 -0600642#ifdef CONFIG_FSL_SGMII_RISER
Jason Jin2e26d832008-10-10 11:41:00 +0800643 if ((sdrs2_io_sel == 4) || (sdrs2_io_sel == 6))
644 fsl_sgmii_riser_init(tsec_info, num);
Andy Flemingfeede8b2008-12-05 20:10:22 -0600645#endif
Jason Jin2e26d832008-10-10 11:41:00 +0800646
647 tsec_eth_init(bis, tsec_info, num);
648#endif
649 return pci_eth_init(bis);
650}
651
Kumar Gala9490a7f2008-07-25 13:31:05 -0500652#if defined(CONFIG_OF_BOARD_SETUP)
Kumar Gala2dba0de2008-10-21 08:28:33 -0500653extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
Wolfgang Denk3cbd8232008-11-02 16:14:22 +0100654 struct pci_controller *hose);
Kumar Gala9490a7f2008-07-25 13:31:05 -0500655
Kumar Gala2dba0de2008-10-21 08:28:33 -0500656void ft_board_setup(void *blob, bd_t *bd)
657{
Kumar Gala9490a7f2008-07-25 13:31:05 -0500658 ft_cpu_setup(blob, bd);
659
Kumar Gala9490a7f2008-07-25 13:31:05 -0500660#ifdef CONFIG_PCI1
Kumar Gala2dba0de2008-10-21 08:28:33 -0500661 ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
Kumar Gala9490a7f2008-07-25 13:31:05 -0500662#endif
663#ifdef CONFIG_PCIE2
Kumar Gala2dba0de2008-10-21 08:28:33 -0500664 ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
665#endif
666#ifdef CONFIG_PCIE2
667 ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
Kumar Gala9490a7f2008-07-25 13:31:05 -0500668#endif
669#ifdef CONFIG_PCIE1
Kumar Gala2dba0de2008-10-21 08:28:33 -0500670 ft_fsl_pci_setup(blob, "pci3", &pcie3_hose);
Kumar Gala9490a7f2008-07-25 13:31:05 -0500671#endif
Andy Flemingfeede8b2008-12-05 20:10:22 -0600672#ifdef CONFIG_FSL_SGMII_RISER
673 fsl_sgmii_riser_fdt_fixup(blob);
674#endif
Kumar Gala9490a7f2008-07-25 13:31:05 -0500675}
676#endif