1415a613bSKumar Gala /*
2568336ecSchenhui zhao  * Copyright 2004, 2011 Freescale Semiconductor.
3415a613bSKumar Gala  *
4415a613bSKumar Gala  * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
5415a613bSKumar Gala  *
61a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
7415a613bSKumar Gala  */
8415a613bSKumar Gala 
9415a613bSKumar Gala #include <common.h>
10415a613bSKumar Gala #include <pci.h>
11415a613bSKumar Gala #include <asm/processor.h>
12aa11d85cSJon Loeliger #include <asm/mmu.h>
13415a613bSKumar Gala #include <asm/immap_85xx.h>
145614e71bSYork Sun #include <fsl_ddr_sdram.h>
15415a613bSKumar Gala #include <ioports.h>
16a30a549aSJon Loeliger #include <spd_sdram.h>
17*b08c8c48SMasahiro Yamada #include <linux/libfdt.h>
18415a613bSKumar Gala #include <fdt_support.h>
19415a613bSKumar Gala 
20415a613bSKumar Gala #include "../common/cadmus.h"
21415a613bSKumar Gala #include "../common/eeprom.h"
22415a613bSKumar Gala #include "../common/via.h"
23415a613bSKumar Gala 
24415a613bSKumar Gala #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
25415a613bSKumar Gala extern void ddr_enable_ecc(unsigned int dram_size);
26415a613bSKumar Gala #endif
27415a613bSKumar Gala 
28415a613bSKumar Gala void local_bus_init(void);
29415a613bSKumar Gala 
30415a613bSKumar Gala /*
31415a613bSKumar Gala  * I/O Port configuration table
32415a613bSKumar Gala  *
33415a613bSKumar Gala  * if conf is 1, then that port pin will be configured at boot time
34415a613bSKumar Gala  * according to the five values podr/pdir/ppar/psor/pdat for that entry
35415a613bSKumar Gala  */
36415a613bSKumar Gala 
37415a613bSKumar Gala const iop_conf_t iop_conf_tab[4][32] = {
38415a613bSKumar Gala 
39415a613bSKumar Gala     /* Port A configuration */
40415a613bSKumar Gala     {   /*            conf ppar psor pdir podr pdat */
41415a613bSKumar Gala 	/* PA31 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 TxENB */
42415a613bSKumar Gala 	/* PA30 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 TxClav   */
43415a613bSKumar Gala 	/* PA29 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 TxSOC  */
44415a613bSKumar Gala 	/* PA28 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 RxENB */
45415a613bSKumar Gala 	/* PA27 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 RxSOC */
46415a613bSKumar Gala 	/* PA26 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 RxClav */
47415a613bSKumar Gala 	/* PA25 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 ATMTXD[0] */
48415a613bSKumar Gala 	/* PA24 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 ATMTXD[1] */
49415a613bSKumar Gala 	/* PA23 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 ATMTXD[2] */
50415a613bSKumar Gala 	/* PA22 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 ATMTXD[3] */
51415a613bSKumar Gala 	/* PA21 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 ATMTXD[4] */
52415a613bSKumar Gala 	/* PA20 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 ATMTXD[5] */
53415a613bSKumar Gala 	/* PA19 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 ATMTXD[6] */
54415a613bSKumar Gala 	/* PA18 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 ATMTXD[7] */
55415a613bSKumar Gala 	/* PA17 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 ATMRXD[7] */
56415a613bSKumar Gala 	/* PA16 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 ATMRXD[6] */
57415a613bSKumar Gala 	/* PA15 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 ATMRXD[5] */
58415a613bSKumar Gala 	/* PA14 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 ATMRXD[4] */
59415a613bSKumar Gala 	/* PA13 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 ATMRXD[3] */
60415a613bSKumar Gala 	/* PA12 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 ATMRXD[2] */
61415a613bSKumar Gala 	/* PA11 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 ATMRXD[1] */
62415a613bSKumar Gala 	/* PA10 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 ATMRXD[0] */
63415a613bSKumar Gala 	/* PA9  */ {   0,   1,   1,   1,   0,   0   }, /* FCC1 L1TXD */
64415a613bSKumar Gala 	/* PA8  */ {   0,   1,   1,   0,   0,   0   }, /* FCC1 L1RXD */
65415a613bSKumar Gala 	/* PA7  */ {   0,   0,   0,   1,   0,   0   }, /* PA7 */
66415a613bSKumar Gala 	/* PA6  */ {   0,   1,   1,   1,   0,   0   }, /* TDM A1 L1RSYNC */
67415a613bSKumar Gala 	/* PA5  */ {   0,   0,   0,   1,   0,   0   }, /* PA5 */
68415a613bSKumar Gala 	/* PA4  */ {   0,   0,   0,   1,   0,   0   }, /* PA4 */
69415a613bSKumar Gala 	/* PA3  */ {   0,   0,   0,   1,   0,   0   }, /* PA3 */
70415a613bSKumar Gala 	/* PA2  */ {   0,   0,   0,   1,   0,   0   }, /* PA2 */
71415a613bSKumar Gala 	/* PA1  */ {   1,   0,   0,   0,   0,   0   }, /* FREERUN */
72415a613bSKumar Gala 	/* PA0  */ {   0,   0,   0,   1,   0,   0   }  /* PA0 */
73415a613bSKumar Gala     },
74415a613bSKumar Gala 
75415a613bSKumar Gala     /* Port B configuration */
76415a613bSKumar Gala     {   /*            conf ppar psor pdir podr pdat */
77415a613bSKumar Gala 	/* PB31 */ {   1,   1,   0,   1,   0,   0   }, /* FCC2 MII TX_ER */
78415a613bSKumar Gala 	/* PB30 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RX_DV */
79415a613bSKumar Gala 	/* PB29 */ {   1,   1,   1,   1,   0,   0   }, /* FCC2 MII TX_EN */
80415a613bSKumar Gala 	/* PB28 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RX_ER */
81415a613bSKumar Gala 	/* PB27 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII COL */
82415a613bSKumar Gala 	/* PB26 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII CRS */
83415a613bSKumar Gala 	/* PB25 */ {   1,   1,   0,   1,   0,   0   }, /* FCC2 MII TxD[3] */
84415a613bSKumar Gala 	/* PB24 */ {   1,   1,   0,   1,   0,   0   }, /* FCC2 MII TxD[2] */
85415a613bSKumar Gala 	/* PB23 */ {   1,   1,   0,   1,   0,   0   }, /* FCC2 MII TxD[1] */
86415a613bSKumar Gala 	/* PB22 */ {   1,   1,   0,   1,   0,   0   }, /* FCC2 MII TxD[0] */
87415a613bSKumar Gala 	/* PB21 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RxD[0] */
88415a613bSKumar Gala 	/* PB20 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RxD[1] */
89415a613bSKumar Gala 	/* PB19 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RxD[2] */
90415a613bSKumar Gala 	/* PB18 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RxD[3] */
91415a613bSKumar Gala 	/* PB17 */ {   0,   1,   0,   0,   0,   0   }, /* FCC3:RX_DIV */
92415a613bSKumar Gala 	/* PB16 */ {   0,   1,   0,   0,   0,   0   }, /* FCC3:RX_ERR */
93415a613bSKumar Gala 	/* PB15 */ {   0,   1,   0,   1,   0,   0   }, /* FCC3:TX_ERR */
94415a613bSKumar Gala 	/* PB14 */ {   0,   1,   0,   1,   0,   0   }, /* FCC3:TX_EN */
95415a613bSKumar Gala 	/* PB13 */ {   0,   1,   0,   0,   0,   0   }, /* FCC3:COL */
96415a613bSKumar Gala 	/* PB12 */ {   0,   1,   0,   0,   0,   0   }, /* FCC3:CRS */
97415a613bSKumar Gala 	/* PB11 */ {   0,   1,   0,   0,   0,   0   }, /* FCC3:RXD */
98415a613bSKumar Gala 	/* PB10 */ {   0,   1,   0,   0,   0,   0   }, /* FCC3:RXD */
99415a613bSKumar Gala 	/* PB9  */ {   0,   1,   0,   0,   0,   0   }, /* FCC3:RXD */
100415a613bSKumar Gala 	/* PB8  */ {   0,   1,   0,   0,   0,   0   }, /* FCC3:RXD */
101415a613bSKumar Gala 	/* PB7  */ {   0,   1,   0,   1,   0,   0   }, /* FCC3:TXD */
102415a613bSKumar Gala 	/* PB6  */ {   0,   1,   0,   1,   0,   0   }, /* FCC3:TXD */
103415a613bSKumar Gala 	/* PB5  */ {   0,   1,   0,   1,   0,   0   }, /* FCC3:TXD */
104415a613bSKumar Gala 	/* PB4  */ {   0,   1,   0,   1,   0,   0   }, /* FCC3:TXD */
105415a613bSKumar Gala 	/* PB3  */ {   0,   0,   0,   0,   0,   0   }, /* pin doesn't exist */
106415a613bSKumar Gala 	/* PB2  */ {   0,   0,   0,   0,   0,   0   }, /* pin doesn't exist */
107415a613bSKumar Gala 	/* PB1  */ {   0,   0,   0,   0,   0,   0   }, /* pin doesn't exist */
108415a613bSKumar Gala 	/* PB0  */ {   0,   0,   0,   0,   0,   0   }  /* pin doesn't exist */
109415a613bSKumar Gala     },
110415a613bSKumar Gala 
111415a613bSKumar Gala     /* Port C */
112415a613bSKumar Gala     {   /*            conf ppar psor pdir podr pdat */
113415a613bSKumar Gala 	/* PC31 */ {   0,   0,   0,   1,   0,   0   }, /* PC31 */
114415a613bSKumar Gala 	/* PC30 */ {   0,   0,   0,   1,   0,   0   }, /* PC30 */
115415a613bSKumar Gala 	/* PC29 */ {   0,   1,   1,   0,   0,   0   }, /* SCC1 EN *CLSN */
116415a613bSKumar Gala 	/* PC28 */ {   0,   0,   0,   1,   0,   0   }, /* PC28 */
117415a613bSKumar Gala 	/* PC27 */ {   0,   0,   0,   1,   0,   0   }, /* UART Clock in */
118415a613bSKumar Gala 	/* PC26 */ {   0,   0,   0,   1,   0,   0   }, /* PC26 */
119415a613bSKumar Gala 	/* PC25 */ {   0,   0,   0,   1,   0,   0   }, /* PC25 */
120415a613bSKumar Gala 	/* PC24 */ {   0,   0,   0,   1,   0,   0   }, /* PC24 */
121415a613bSKumar Gala 	/* PC23 */ {   0,   1,   0,   1,   0,   0   }, /* ATMTFCLK */
122415a613bSKumar Gala 	/* PC22 */ {   0,   1,   0,   0,   0,   0   }, /* ATMRFCLK */
123415a613bSKumar Gala 	/* PC21 */ {   0,   1,   0,   0,   0,   0   }, /* SCC1 EN RXCLK */
124415a613bSKumar Gala 	/* PC20 */ {   0,   1,   0,   0,   0,   0   }, /* SCC1 EN TXCLK */
125415a613bSKumar Gala 	/* PC19 */ {   1,   1,   0,   0,   0,   0   }, /* FCC2 MII RX_CLK CLK13 */
126415a613bSKumar Gala 	/* PC18 */ {   1,   1,   0,   0,   0,   0   }, /* FCC Tx Clock (CLK14) */
127415a613bSKumar Gala 	/* PC17 */ {   0,   0,   0,   1,   0,   0   }, /* PC17 */
128415a613bSKumar Gala 	/* PC16 */ {   0,   1,   0,   0,   0,   0   }, /* FCC Tx Clock (CLK16) */
129415a613bSKumar Gala 	/* PC15 */ {   1,   1,   0,   0,   0,   0   }, /* PC15 */
130415a613bSKumar Gala 	/* PC14 */ {   0,   1,   0,   0,   0,   0   }, /* SCC1 EN *CD */
131415a613bSKumar Gala 	/* PC13 */ {   0,   0,   0,   1,   0,   0   }, /* PC13 */
132415a613bSKumar Gala 	/* PC12 */ {   0,   1,   0,   1,   0,   0   }, /* PC12 */
133415a613bSKumar Gala 	/* PC11 */ {   0,   0,   0,   1,   0,   0   }, /* LXT971 transmit control */
134415a613bSKumar Gala 	/* PC10 */ {   1,   0,   0,   1,   0,   0   }, /* FETHMDC */
135415a613bSKumar Gala 	/* PC9  */ {   1,   0,   0,   0,   0,   0   }, /* FETHMDIO */
136415a613bSKumar Gala 	/* PC8  */ {   0,   0,   0,   1,   0,   0   }, /* PC8 */
137415a613bSKumar Gala 	/* PC7  */ {   0,   0,   0,   1,   0,   0   }, /* PC7 */
138415a613bSKumar Gala 	/* PC6  */ {   0,   0,   0,   1,   0,   0   }, /* PC6 */
139415a613bSKumar Gala 	/* PC5  */ {   0,   0,   0,   1,   0,   0   }, /* PC5 */
140415a613bSKumar Gala 	/* PC4  */ {   0,   0,   0,   1,   0,   0   }, /* PC4 */
141415a613bSKumar Gala 	/* PC3  */ {   0,   0,   0,   1,   0,   0   }, /* PC3 */
142415a613bSKumar Gala 	/* PC2  */ {   0,   0,   0,   1,   0,   1   }, /* ENET FDE */
143415a613bSKumar Gala 	/* PC1  */ {   0,   0,   0,   1,   0,   0   }, /* ENET DSQE */
144415a613bSKumar Gala 	/* PC0  */ {   0,   0,   0,   1,   0,   0   }, /* ENET LBK */
145415a613bSKumar Gala     },
146415a613bSKumar Gala 
147415a613bSKumar Gala     /* Port D */
148415a613bSKumar Gala     {   /*            conf ppar psor pdir podr pdat */
149415a613bSKumar Gala 	/* PD31 */ {   1,   1,   0,   0,   0,   0   }, /* SCC1 EN RxD */
150415a613bSKumar Gala 	/* PD30 */ {   1,   1,   1,   1,   0,   0   }, /* SCC1 EN TxD */
151415a613bSKumar Gala 	/* PD29 */ {   1,   1,   0,   1,   0,   0   }, /* SCC1 EN TENA */
152415a613bSKumar Gala 	/* PD28 */ {   0,   1,   0,   0,   0,   0   }, /* PD28 */
153415a613bSKumar Gala 	/* PD27 */ {   0,   1,   1,   1,   0,   0   }, /* PD27 */
154415a613bSKumar Gala 	/* PD26 */ {   0,   0,   0,   1,   0,   0   }, /* PD26 */
155415a613bSKumar Gala 	/* PD25 */ {   0,   0,   0,   1,   0,   0   }, /* PD25 */
156415a613bSKumar Gala 	/* PD24 */ {   0,   0,   0,   1,   0,   0   }, /* PD24 */
157415a613bSKumar Gala 	/* PD23 */ {   0,   0,   0,   1,   0,   0   }, /* PD23 */
158415a613bSKumar Gala 	/* PD22 */ {   0,   0,   0,   1,   0,   0   }, /* PD22 */
159415a613bSKumar Gala 	/* PD21 */ {   0,   0,   0,   1,   0,   0   }, /* PD21 */
160415a613bSKumar Gala 	/* PD20 */ {   0,   0,   0,   1,   0,   0   }, /* PD20 */
161415a613bSKumar Gala 	/* PD19 */ {   0,   0,   0,   1,   0,   0   }, /* PD19 */
162415a613bSKumar Gala 	/* PD18 */ {   0,   0,   0,   1,   0,   0   }, /* PD18 */
163415a613bSKumar Gala 	/* PD17 */ {   0,   1,   0,   0,   0,   0   }, /* FCC1 ATMRXPRTY */
164415a613bSKumar Gala 	/* PD16 */ {   0,   1,   0,   1,   0,   0   }, /* FCC1 ATMTXPRTY */
165415a613bSKumar Gala 	/* PD15 */ {   0,   1,   1,   0,   1,   0   }, /* I2C SDA */
166415a613bSKumar Gala 	/* PD14 */ {   0,   0,   0,   1,   0,   0   }, /* LED */
167415a613bSKumar Gala 	/* PD13 */ {   0,   0,   0,   0,   0,   0   }, /* PD13 */
168415a613bSKumar Gala 	/* PD12 */ {   0,   0,   0,   0,   0,   0   }, /* PD12 */
169415a613bSKumar Gala 	/* PD11 */ {   0,   0,   0,   0,   0,   0   }, /* PD11 */
170415a613bSKumar Gala 	/* PD10 */ {   0,   0,   0,   0,   0,   0   }, /* PD10 */
171415a613bSKumar Gala 	/* PD9  */ {   0,   1,   0,   1,   0,   0   }, /* SMC1 TXD */
172415a613bSKumar Gala 	/* PD8  */ {   0,   1,   0,   0,   0,   0   }, /* SMC1 RXD */
173415a613bSKumar Gala 	/* PD7  */ {   0,   0,   0,   1,   0,   1   }, /* PD7 */
174415a613bSKumar Gala 	/* PD6  */ {   0,   0,   0,   1,   0,   1   }, /* PD6 */
175415a613bSKumar Gala 	/* PD5  */ {   0,   0,   0,   1,   0,   1   }, /* PD5 */
176415a613bSKumar Gala 	/* PD4  */ {   0,   0,   0,   1,   0,   1   }, /* PD4 */
177415a613bSKumar Gala 	/* PD3  */ {   0,   0,   0,   0,   0,   0   }, /* pin doesn't exist */
178415a613bSKumar Gala 	/* PD2  */ {   0,   0,   0,   0,   0,   0   }, /* pin doesn't exist */
179415a613bSKumar Gala 	/* PD1  */ {   0,   0,   0,   0,   0,   0   }, /* pin doesn't exist */
180415a613bSKumar Gala 	/* PD0  */ {   0,   0,   0,   0,   0,   0   }  /* pin doesn't exist */
181415a613bSKumar Gala     }
182415a613bSKumar Gala };
183415a613bSKumar Gala 
184415a613bSKumar Gala int checkboard (void)
185415a613bSKumar Gala {
1866d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
187568336ecSchenhui zhao 	char buf[32];
188415a613bSKumar Gala 
189415a613bSKumar Gala 	/* PCI slot in USER bits CSR[6:7] by convention. */
190415a613bSKumar Gala 	uint pci_slot = get_pci_slot ();
191415a613bSKumar Gala 
192415a613bSKumar Gala 	uint pci_dual = get_pci_dual ();	/* PCI DUAL in CM_PCI[3] */
193415a613bSKumar Gala 	uint pci1_32 = gur->pordevsr & 0x10000;	/* PORDEVSR[15] */
194415a613bSKumar Gala 	uint pci1_clk_sel = gur->porpllsr & 0x8000;	/* PORPLLSR[16] */
195415a613bSKumar Gala 	uint pci2_clk_sel = gur->porpllsr & 0x4000;	/* PORPLLSR[17] */
196415a613bSKumar Gala 
197415a613bSKumar Gala 	uint pci1_speed = get_clock_freq ();	/* PCI PSPEED in [4:5] */
198415a613bSKumar Gala 
199415a613bSKumar Gala 	uint cpu_board_rev = get_cpu_board_revision ();
200415a613bSKumar Gala 
201415a613bSKumar Gala 	printf ("Board: CDS Version 0x%02x, PCI Slot %d\n",
202415a613bSKumar Gala 		get_board_version (), pci_slot);
203415a613bSKumar Gala 
204415a613bSKumar Gala 	printf ("CPU Board Revision %d.%d (0x%04x)\n",
205415a613bSKumar Gala 		MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
206415a613bSKumar Gala 		MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
207415a613bSKumar Gala 
208415a613bSKumar Gala 	printf("PCI1: %d bit, %s MHz, %s\n",
209415a613bSKumar Gala 		(pci1_32) ? 32 : 64,
210568336ecSchenhui zhao 		strmhz(buf, pci1_speed),
211415a613bSKumar Gala 		pci1_clk_sel ? "sync" : "async");
212415a613bSKumar Gala 
213415a613bSKumar Gala 	if (pci_dual) {
214415a613bSKumar Gala 		printf("PCI2: 32 bit, 66 MHz, %s\n",
215415a613bSKumar Gala 			pci2_clk_sel ? "sync" : "async");
216415a613bSKumar Gala 	} else {
217415a613bSKumar Gala 		printf("PCI2: disabled\n");
218415a613bSKumar Gala 	}
219415a613bSKumar Gala 
220415a613bSKumar Gala 	/*
221415a613bSKumar Gala 	 * Initialize local bus.
222415a613bSKumar Gala 	 */
223415a613bSKumar Gala 	local_bus_init ();
224415a613bSKumar Gala 
225415a613bSKumar Gala 	return 0;
226415a613bSKumar Gala }
227415a613bSKumar Gala 
228415a613bSKumar Gala /*
229415a613bSKumar Gala  * Initialize Local Bus
230415a613bSKumar Gala  */
231415a613bSKumar Gala void
232415a613bSKumar Gala local_bus_init(void)
233415a613bSKumar Gala {
2346d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
235f51cdaf1SBecky Bruce 	volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
236415a613bSKumar Gala 
237415a613bSKumar Gala 	uint clkdiv;
238415a613bSKumar Gala 	uint lbc_hz;
239415a613bSKumar Gala 	sys_info_t sysinfo;
240415a613bSKumar Gala 	uint temp_lbcdll;
241415a613bSKumar Gala 
242415a613bSKumar Gala 	/*
243415a613bSKumar Gala 	 * Errata LBC11.
244415a613bSKumar Gala 	 * Fix Local Bus clock glitch when DLL is enabled.
245415a613bSKumar Gala 	 *
2468ed44d91SWolfgang Denk 	 * If localbus freq is < 66MHz, DLL bypass mode must be used.
2478ed44d91SWolfgang Denk 	 * If localbus freq is > 133MHz, DLL can be safely enabled.
248415a613bSKumar Gala 	 * Between 66 and 133, the DLL is enabled with an override workaround.
249415a613bSKumar Gala 	 */
250415a613bSKumar Gala 
251415a613bSKumar Gala 	get_sys_info(&sysinfo);
252a5d212a2STrent Piepho 	clkdiv = lbc->lcrr & LCRR_CLKDIV;
253997399faSPrabhakar Kushwaha 	lbc_hz = sysinfo.freq_systembus / 1000000 / clkdiv;
254415a613bSKumar Gala 
255415a613bSKumar Gala 	if (lbc_hz < 66) {
256a2af6a7aSPaul Gortmaker 		lbc->lcrr |= LCRR_DBYP;	/* DLL Bypass */
257415a613bSKumar Gala 
258415a613bSKumar Gala 	} else if (lbc_hz >= 133) {
259a2af6a7aSPaul Gortmaker 		lbc->lcrr &= (~LCRR_DBYP);		/* DLL Enabled */
260415a613bSKumar Gala 
261415a613bSKumar Gala 	} else {
262a2af6a7aSPaul Gortmaker 		lbc->lcrr &= (~LCRR_DBYP);	/* DLL Enabled */
263415a613bSKumar Gala 		udelay(200);
264415a613bSKumar Gala 
265415a613bSKumar Gala 		/*
266415a613bSKumar Gala 		 * Sample LBC DLL ctrl reg, upshift it to set the
267415a613bSKumar Gala 		 * override bits.
268415a613bSKumar Gala 		 */
269415a613bSKumar Gala 		temp_lbcdll = gur->lbcdllcr;
270415a613bSKumar Gala 		gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
271415a613bSKumar Gala 		asm("sync;isync;msync");
272415a613bSKumar Gala 	}
273415a613bSKumar Gala }
274415a613bSKumar Gala 
275415a613bSKumar Gala /*
276415a613bSKumar Gala  * Initialize SDRAM memory on the Local Bus.
277415a613bSKumar Gala  */
27870961ba4SBecky Bruce void lbc_sdram_init(void)
279415a613bSKumar Gala {
2806d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #if defined(CONFIG_SYS_OR2_PRELIM) && defined(CONFIG_SYS_BR2_PRELIM)
281415a613bSKumar Gala 
282415a613bSKumar Gala 	uint idx;
283f51cdaf1SBecky Bruce 	volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
2846d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
285415a613bSKumar Gala 	uint cpu_board_rev;
286415a613bSKumar Gala 	uint lsdmr_common;
287415a613bSKumar Gala 
2887ea3871eSBecky Bruce 	puts("LBC SDRAM: ");
2897ea3871eSBecky Bruce 	print_size(CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024,
2907ea3871eSBecky Bruce 		   "\n       ");
291415a613bSKumar Gala 
292415a613bSKumar Gala 	/*
293415a613bSKumar Gala 	 * Setup SDRAM Base and Option Registers
294415a613bSKumar Gala 	 */
295f51cdaf1SBecky Bruce 	set_lbc_or(2, CONFIG_SYS_OR2_PRELIM);
296f51cdaf1SBecky Bruce 	set_lbc_br(2, CONFIG_SYS_BR2_PRELIM);
2976d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lbc->lbcr = CONFIG_SYS_LBC_LBCR;
298415a613bSKumar Gala 	asm("msync");
299415a613bSKumar Gala 
3006d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lbc->lsrt = CONFIG_SYS_LBC_LSRT;
3016d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
302415a613bSKumar Gala 	asm("msync");
303415a613bSKumar Gala 
304415a613bSKumar Gala 	/*
305415a613bSKumar Gala 	 * Determine which address lines to use baed on CPU board rev.
306415a613bSKumar Gala 	 */
307415a613bSKumar Gala 	cpu_board_rev = get_cpu_board_revision();
3086d0f6bcfSJean-Christophe PLAGNIOL-VILLARD 	lsdmr_common = CONFIG_SYS_LBC_LSDMR_COMMON;
309415a613bSKumar Gala 	if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_0) {
310b0fe93edSKumar Gala 		lsdmr_common |= LSDMR_BSMA1617;
311415a613bSKumar Gala 	} else if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_1) {
312b0fe93edSKumar Gala 		lsdmr_common |= LSDMR_BSMA1516;
313415a613bSKumar Gala 	} else {
314415a613bSKumar Gala 		/*
315415a613bSKumar Gala 		 * Assume something unable to identify itself is
316415a613bSKumar Gala 		 * really old, and likely has lines 16/17 mapped.
317415a613bSKumar Gala 		 */
318b0fe93edSKumar Gala 		lsdmr_common |= LSDMR_BSMA1617;
319415a613bSKumar Gala 	}
320415a613bSKumar Gala 
321415a613bSKumar Gala 	/*
322415a613bSKumar Gala 	 * Issue PRECHARGE ALL command.
323415a613bSKumar Gala 	 */
324b0fe93edSKumar Gala 	lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
325415a613bSKumar Gala 	asm("sync;msync");
326415a613bSKumar Gala 	*sdram_addr = 0xff;
327415a613bSKumar Gala 	ppcDcbf((unsigned long) sdram_addr);
328415a613bSKumar Gala 	udelay(100);
329415a613bSKumar Gala 
330415a613bSKumar Gala 	/*
331415a613bSKumar Gala 	 * Issue 8 AUTO REFRESH commands.
332415a613bSKumar Gala 	 */
333415a613bSKumar Gala 	for (idx = 0; idx < 8; idx++) {
334b0fe93edSKumar Gala 		lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
335415a613bSKumar Gala 		asm("sync;msync");
336415a613bSKumar Gala 		*sdram_addr = 0xff;
337415a613bSKumar Gala 		ppcDcbf((unsigned long) sdram_addr);
338415a613bSKumar Gala 		udelay(100);
339415a613bSKumar Gala 	}
340415a613bSKumar Gala 
341415a613bSKumar Gala 	/*
342415a613bSKumar Gala 	 * Issue 8 MODE-set command.
343415a613bSKumar Gala 	 */
344b0fe93edSKumar Gala 	lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
345415a613bSKumar Gala 	asm("sync;msync");
346415a613bSKumar Gala 	*sdram_addr = 0xff;
347415a613bSKumar Gala 	ppcDcbf((unsigned long) sdram_addr);
348415a613bSKumar Gala 	udelay(100);
349415a613bSKumar Gala 
350415a613bSKumar Gala 	/*
351415a613bSKumar Gala 	 * Issue NORMAL OP command.
352415a613bSKumar Gala 	 */
353b0fe93edSKumar Gala 	lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
354415a613bSKumar Gala 	asm("sync;msync");
355415a613bSKumar Gala 	*sdram_addr = 0xff;
356415a613bSKumar Gala 	ppcDcbf((unsigned long) sdram_addr);
357415a613bSKumar Gala 	udelay(200);    /* Overkill. Must wait > 200 bus cycles */
358415a613bSKumar Gala 
359415a613bSKumar Gala #endif	/* enable SDRAM init */
360415a613bSKumar Gala }
361415a613bSKumar Gala 
362415a613bSKumar Gala #if defined(CONFIG_PCI)
363415a613bSKumar Gala /* For some reason the Tundra PCI bridge shows up on itself as a
364415a613bSKumar Gala  * different device.  Work around that by refusing to configure it.
365415a613bSKumar Gala  */
366415a613bSKumar Gala void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
367415a613bSKumar Gala 
368415a613bSKumar Gala static struct pci_config_table pci_mpc85xxcds_config_table[] = {
369415a613bSKumar Gala 	{0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
370415a613bSKumar Gala 	{0x1106, 0x0686, PCI_ANY_ID, 1, VIA_ID, 0, mpc85xx_config_via, {0,0,0}},
371415a613bSKumar Gala 	{0x1106, 0x0571, PCI_ANY_ID, 1, VIA_ID, 1,
372415a613bSKumar Gala 		mpc85xx_config_via_usbide, {0,0,0}},
373415a613bSKumar Gala 	{0x1105, 0x3038, PCI_ANY_ID, 1, VIA_ID, 2,
374415a613bSKumar Gala 		mpc85xx_config_via_usb, {0,0,0}},
375415a613bSKumar Gala 	{0x1106, 0x3038, PCI_ANY_ID, 1, VIA_ID, 3,
376415a613bSKumar Gala 		mpc85xx_config_via_usb2, {0,0,0}},
377415a613bSKumar Gala 	{0x1106, 0x3058, PCI_ANY_ID, 1, VIA_ID, 5,
378415a613bSKumar Gala 		mpc85xx_config_via_power, {0,0,0}},
379415a613bSKumar Gala 	{0x1106, 0x3068, PCI_ANY_ID, 1, VIA_ID, 6,
380415a613bSKumar Gala 		mpc85xx_config_via_ac97, {0,0,0}},
381415a613bSKumar Gala 	{},
382415a613bSKumar Gala };
383415a613bSKumar Gala 
384415a613bSKumar Gala static struct pci_controller hose[] = {
385415a613bSKumar Gala 	{ config_table: pci_mpc85xxcds_config_table,},
386415a613bSKumar Gala #ifdef CONFIG_MPC85XX_PCI2
387415a613bSKumar Gala 	{},
388415a613bSKumar Gala #endif
389415a613bSKumar Gala };
390415a613bSKumar Gala 
391415a613bSKumar Gala #endif	/* CONFIG_PCI */
392415a613bSKumar Gala 
393415a613bSKumar Gala void
394415a613bSKumar Gala pci_init_board(void)
395415a613bSKumar Gala {
396415a613bSKumar Gala #ifdef CONFIG_PCI
397415a613bSKumar Gala 	pci_mpc85xx_init(hose);
398415a613bSKumar Gala #endif
399415a613bSKumar Gala }
400415a613bSKumar Gala 
401415a613bSKumar Gala #if defined(CONFIG_OF_BOARD_SETUP)
402415a613bSKumar Gala void
403415a613bSKumar Gala ft_pci_setup(void *blob, bd_t *bd)
404415a613bSKumar Gala {
405415a613bSKumar Gala 	int node, tmp[2];
406415a613bSKumar Gala 	const char *path;
407415a613bSKumar Gala 
408415a613bSKumar Gala 	node = fdt_path_offset(blob, "/aliases");
409415a613bSKumar Gala 	tmp[0] = 0;
410415a613bSKumar Gala 	if (node >= 0) {
411415a613bSKumar Gala #ifdef CONFIG_PCI1
412415a613bSKumar Gala 		path = fdt_getprop(blob, node, "pci0", NULL);
413415a613bSKumar Gala 		if (path) {
414415a613bSKumar Gala 			tmp[1] = hose[0].last_busno - hose[0].first_busno;
415415a613bSKumar Gala 			do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
416415a613bSKumar Gala 		}
417415a613bSKumar Gala #endif
418415a613bSKumar Gala #ifdef CONFIG_MPC85XX_PCI2
419415a613bSKumar Gala 		path = fdt_getprop(blob, node, "pci1", NULL);
420415a613bSKumar Gala 		if (path) {
421415a613bSKumar Gala 			tmp[1] = hose[1].last_busno - hose[1].first_busno;
422415a613bSKumar Gala 			do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
423415a613bSKumar Gala 		}
424415a613bSKumar Gala #endif
425415a613bSKumar Gala 	}
426415a613bSKumar Gala }
427415a613bSKumar Gala #endif
428