1d1712369SKumar Gala /*
2561e710aSKumar Gala  * Copyright 2009-2011 Freescale Semiconductor, Inc.
3d1712369SKumar Gala  *
4d1712369SKumar Gala  * See file CREDITS for list of people who contributed to this
5d1712369SKumar Gala  * project.
6d1712369SKumar Gala  *
7d1712369SKumar Gala  * This program is free software; you can redistribute it and/or
8d1712369SKumar Gala  * modify it under the terms of the GNU General Public License as
9d1712369SKumar Gala  * published by the Free Software Foundation; either version 2 of
10d1712369SKumar Gala  * the License, or (at your option) any later version.
11d1712369SKumar Gala  *
12d1712369SKumar Gala  * This program is distributed in the hope that it will be useful,
13d1712369SKumar Gala  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14d1712369SKumar Gala  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15d1712369SKumar Gala  * GNU General Public License for more details.
16d1712369SKumar Gala  *
17d1712369SKumar Gala  * You should have received a copy of the GNU General Public License
18d1712369SKumar Gala  * along with this program; if not, write to the Free Software
19d1712369SKumar Gala  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20d1712369SKumar Gala  * MA 02111-1307 USA
21d1712369SKumar Gala  */
22d1712369SKumar Gala 
23d1712369SKumar Gala #include <common.h>
24d1712369SKumar Gala #include <command.h>
25d1712369SKumar Gala #include <netdev.h>
260e159024SLian Minghuan #include <linux/compiler.h>
27d1712369SKumar Gala #include <asm/mmu.h>
28d1712369SKumar Gala #include <asm/processor.h>
29d1712369SKumar Gala #include <asm/cache.h>
30d1712369SKumar Gala #include <asm/immap_85xx.h>
31d1712369SKumar Gala #include <asm/fsl_law.h>
32d1712369SKumar Gala #include <asm/fsl_serdes.h>
33d1712369SKumar Gala #include <asm/fsl_portals.h>
34d1712369SKumar Gala #include <asm/fsl_liodn.h>
35d1712369SKumar Gala 
36d1712369SKumar Gala extern void pci_of_setup(void *blob, bd_t *bd);
37d1712369SKumar Gala 
38d1712369SKumar Gala #include "../common/ngpixis.h"
39d1712369SKumar Gala 
40d1712369SKumar Gala DECLARE_GLOBAL_DATA_PTR;
41d1712369SKumar Gala 
42d1712369SKumar Gala int checkboard (void)
43d1712369SKumar Gala {
44d1712369SKumar Gala 	u8 sw;
45d1712369SKumar Gala 	struct cpu_type *cpu = gd->cpu;
4646299078STimur Tabi 	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
4746299078STimur Tabi 	unsigned int i;
48d1712369SKumar Gala 
49d1712369SKumar Gala 	printf("Board: %sDS, ", cpu->name);
50d1712369SKumar Gala 	printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
51d1712369SKumar Gala 		in_8(&pixis->id), in_8(&pixis->arch), in_8(&pixis->scver));
52d1712369SKumar Gala 
53d1712369SKumar Gala 	sw = in_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH));
54d1712369SKumar Gala 	sw = (sw & PIXIS_LBMAP_MASK) >> PIXIS_LBMAP_SHIFT;
55d1712369SKumar Gala 
56d1712369SKumar Gala 	if (sw < 0x8)
57d1712369SKumar Gala 		printf("vBank: %d\n", sw);
58d1712369SKumar Gala 	else if (sw == 0x8)
59d1712369SKumar Gala 		puts("Promjet\n");
60d1712369SKumar Gala 	else if (sw == 0x9)
61d1712369SKumar Gala 		puts("NAND\n");
62d1712369SKumar Gala 	else
63d1712369SKumar Gala 		printf("invalid setting of SW%u\n", PIXIS_LBMAP_SWITCH);
64d1712369SKumar Gala 
65d1712369SKumar Gala #ifdef CONFIG_PHYS_64BIT
66d1712369SKumar Gala 	puts("36-bit Addressing\n");
67d1712369SKumar Gala #endif
68d1712369SKumar Gala 
6946299078STimur Tabi 	/* Display the RCW, so that no one gets confused as to what RCW
7046299078STimur Tabi 	 * we're actually using for this boot.
7146299078STimur Tabi 	 */
7246299078STimur Tabi 	puts("Reset Configuration Word (RCW):");
7346299078STimur Tabi 	for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
7446299078STimur Tabi 		u32 rcw = in_be32(&gur->rcwsr[i]);
7546299078STimur Tabi 
7646299078STimur Tabi 		if ((i % 4) == 0)
7746299078STimur Tabi 			printf("\n       %08x:", i * 4);
7846299078STimur Tabi 		printf(" %08x", rcw);
7946299078STimur Tabi 	}
8046299078STimur Tabi 	puts("\n");
8146299078STimur Tabi 
82d1712369SKumar Gala 	/* Display the actual SERDES reference clocks as configured by the
83d1712369SKumar Gala 	 * dip switches on the board.  Note that the SWx registers could
84d1712369SKumar Gala 	 * technically be set to force the reference clocks to match the
85d1712369SKumar Gala 	 * values that the SERDES expects (or vice versa).  For now, however,
86d1712369SKumar Gala 	 * we just display both values and hope the user notices when they
87d1712369SKumar Gala 	 * don't match.
88d1712369SKumar Gala 	 */
89d1712369SKumar Gala 	puts("SERDES Reference Clocks: ");
90*e02aea61SKumar Gala #if defined(CONFIG_P3041DS) || defined(CONFIG_P5020DS)
91*e02aea61SKumar Gala 	sw = in_8(&PIXIS_SW(5));
92*e02aea61SKumar Gala 	for (i = 0; i < 3; i++) {
93*e02aea61SKumar Gala 		static const char *freq[] = {"100", "125", "156.25", "212.5" };
94*e02aea61SKumar Gala 		unsigned int clock = (sw >> (6 - (2 * i))) & 3;
95*e02aea61SKumar Gala 
96*e02aea61SKumar Gala 		printf("Bank%u=%sMhz ", i+1, freq[clock]);
97*e02aea61SKumar Gala 	}
98*e02aea61SKumar Gala 	puts("\n");
99*e02aea61SKumar Gala #else
100d1712369SKumar Gala 	sw = in_8(&PIXIS_SW(3));
101d1712369SKumar Gala 	printf("Bank1=%uMHz ", (sw & 0x40) ? 125 : 100);
102d1712369SKumar Gala 	printf("Bank2=%sMHz ", (sw & 0x20) ? "156.25" : "125");
103d1712369SKumar Gala 	printf("Bank3=%sMHz\n", (sw & 0x10) ? "156.25" : "125");
104*e02aea61SKumar Gala #endif
105d1712369SKumar Gala 
106d1712369SKumar Gala 	return 0;
107d1712369SKumar Gala }
108d1712369SKumar Gala 
109d1712369SKumar Gala int board_early_init_f(void)
110d1712369SKumar Gala {
111d1712369SKumar Gala 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
112d1712369SKumar Gala 
113d1712369SKumar Gala 	/*
114d1712369SKumar Gala 	 * P4080 DS board only uses the DDR1_MCK0/3 and DDR2_MCK0/3
115d1712369SKumar Gala 	 * disable the DDR1_MCK1/2/4/5 and DDR2_MCK1/2/4/5 to reduce
116d1712369SKumar Gala 	 * the noise introduced by these unterminated and unused clock pairs.
117d1712369SKumar Gala 	 */
118d1712369SKumar Gala 	setbits_be32(&gur->ddrclkdr, 0x001B001B);
119d1712369SKumar Gala 
120d1712369SKumar Gala 	return 0;
121d1712369SKumar Gala }
122d1712369SKumar Gala 
123d1712369SKumar Gala int board_early_init_r(void)
124d1712369SKumar Gala {
125d1712369SKumar Gala 	const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
126d1712369SKumar Gala 	const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
127d1712369SKumar Gala 
128d1712369SKumar Gala 	/*
129d1712369SKumar Gala 	 * Remap Boot flash + PROMJET region to caching-inhibited
130d1712369SKumar Gala 	 * so that flash can be erased properly.
131d1712369SKumar Gala 	 */
132d1712369SKumar Gala 
133d1712369SKumar Gala 	/* Flush d-cache and invalidate i-cache of any FLASH data */
134d1712369SKumar Gala 	flush_dcache();
135d1712369SKumar Gala 	invalidate_icache();
136d1712369SKumar Gala 
137d1712369SKumar Gala 	/* invalidate existing TLB entry for flash + promjet */
138d1712369SKumar Gala 	disable_tlb(flash_esel);
139d1712369SKumar Gala 
140d1712369SKumar Gala 	set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,	/* tlb, epn, rpn */
141d1712369SKumar Gala 			MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,	/* perms, wimge */
142d1712369SKumar Gala 			0, flash_esel, BOOKE_PAGESZ_256M, 1);	/* ts, esel, tsize, iprot */
143d1712369SKumar Gala 
144d1712369SKumar Gala 	set_liodns();
145d1712369SKumar Gala 	setup_portals();
146d1712369SKumar Gala 
147d1712369SKumar Gala 	return 0;
148d1712369SKumar Gala }
149d1712369SKumar Gala 
150d1712369SKumar Gala static const char *serdes_clock_to_string(u32 clock)
151d1712369SKumar Gala {
152d1712369SKumar Gala 	switch(clock) {
153d1712369SKumar Gala 	case SRDS_PLLCR0_RFCK_SEL_100:
154d1712369SKumar Gala 		return "100";
155d1712369SKumar Gala 	case SRDS_PLLCR0_RFCK_SEL_125:
156d1712369SKumar Gala 		return "125";
157d1712369SKumar Gala 	case SRDS_PLLCR0_RFCK_SEL_156_25:
158d1712369SKumar Gala 		return "156.25";
159d1712369SKumar Gala 	default:
160*e02aea61SKumar Gala 		return "150";
161d1712369SKumar Gala 	}
162d1712369SKumar Gala }
163d1712369SKumar Gala 
164d1712369SKumar Gala #define NUM_SRDS_BANKS	3
165d1712369SKumar Gala 
166d1712369SKumar Gala int misc_init_r(void)
167d1712369SKumar Gala {
168d1712369SKumar Gala 	serdes_corenet_t *srds_regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
169d1712369SKumar Gala 	u32 actual[NUM_SRDS_BANKS];
170d1712369SKumar Gala 	unsigned int i;
171*e02aea61SKumar Gala 	u8 sw;
172d1712369SKumar Gala 
173*e02aea61SKumar Gala #if defined(CONFIG_P3041DS) || defined(CONFIG_P5020DS)
174*e02aea61SKumar Gala 	sw = in_8(&PIXIS_SW(5));
175*e02aea61SKumar Gala 	for (i = 0; i < 3; i++) {
176*e02aea61SKumar Gala 		unsigned int clock = (sw >> (6 - (2 * i))) & 3;
177*e02aea61SKumar Gala 		switch (clock) {
178*e02aea61SKumar Gala 		case 0:
179*e02aea61SKumar Gala 			actual[i] = SRDS_PLLCR0_RFCK_SEL_100;
180*e02aea61SKumar Gala 			break;
181*e02aea61SKumar Gala 		case 1:
182*e02aea61SKumar Gala 			actual[i] = SRDS_PLLCR0_RFCK_SEL_125;
183*e02aea61SKumar Gala 			break;
184*e02aea61SKumar Gala 		case 2:
185*e02aea61SKumar Gala 			actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25;
186*e02aea61SKumar Gala 			break;
187*e02aea61SKumar Gala 		default:
188*e02aea61SKumar Gala 			printf("Warning: SDREFCLK%u switch setting of '11' is "
189*e02aea61SKumar Gala 			       "unsupported\n", i + 1);
190*e02aea61SKumar Gala 			break;
191*e02aea61SKumar Gala 		}
192*e02aea61SKumar Gala 	}
193*e02aea61SKumar Gala #else
194d1712369SKumar Gala 	/* Warn if the expected SERDES reference clocks don't match the
195d1712369SKumar Gala 	 * actual reference clocks.  This needs to be done after calling
196d1712369SKumar Gala 	 * p4080_erratum_serdes8(), since that function may modify the clocks.
197d1712369SKumar Gala 	 */
198*e02aea61SKumar Gala 	sw = in_8(&PIXIS_SW(3));
199*e02aea61SKumar Gala 	actual[0] = (sw & 0x40) ?
200d1712369SKumar Gala 		SRDS_PLLCR0_RFCK_SEL_125 : SRDS_PLLCR0_RFCK_SEL_100;
201*e02aea61SKumar Gala 	actual[1] = (sw & 0x20) ?
202d1712369SKumar Gala 		SRDS_PLLCR0_RFCK_SEL_156_25 : SRDS_PLLCR0_RFCK_SEL_125;
203*e02aea61SKumar Gala 	actual[2] = (sw & 0x10) ?
204d1712369SKumar Gala 		SRDS_PLLCR0_RFCK_SEL_156_25 : SRDS_PLLCR0_RFCK_SEL_125;
205*e02aea61SKumar Gala #endif
206d1712369SKumar Gala 
207d1712369SKumar Gala 	for (i = 0; i < NUM_SRDS_BANKS; i++) {
208d1712369SKumar Gala 		u32 expected = srds_regs->bank[i].pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
209d1712369SKumar Gala 		if (expected != actual[i]) {
210d1712369SKumar Gala 			printf("Warning: SERDES bank %u expects reference clock"
211d1712369SKumar Gala 			       " %sMHz, but actual is %sMHz\n", i + 1,
212d1712369SKumar Gala 			       serdes_clock_to_string(expected),
213d1712369SKumar Gala 			       serdes_clock_to_string(actual[i]));
214d1712369SKumar Gala 		}
215d1712369SKumar Gala 	}
216d1712369SKumar Gala 
217d1712369SKumar Gala 	return 0;
218d1712369SKumar Gala }
219d1712369SKumar Gala 
220d1712369SKumar Gala void ft_board_setup(void *blob, bd_t *bd)
221d1712369SKumar Gala {
222d1712369SKumar Gala 	phys_addr_t base;
223d1712369SKumar Gala 	phys_size_t size;
224d1712369SKumar Gala 
225d1712369SKumar Gala 	ft_cpu_setup(blob, bd);
226d1712369SKumar Gala 
227d1712369SKumar Gala 	base = getenv_bootm_low();
228d1712369SKumar Gala 	size = getenv_bootm_size();
229d1712369SKumar Gala 
230d1712369SKumar Gala 	fdt_fixup_memory(blob, (u64)base, (u64)size);
231d1712369SKumar Gala 
232d1712369SKumar Gala #ifdef CONFIG_PCI
233d1712369SKumar Gala 	pci_of_setup(blob, bd);
234d1712369SKumar Gala #endif
235d1712369SKumar Gala 
236d1712369SKumar Gala 	fdt_fixup_liodn(blob);
237d1712369SKumar Gala }
238d1712369SKumar Gala 
239d1712369SKumar Gala int board_eth_init(bd_t *bis)
240d1712369SKumar Gala {
241d1712369SKumar Gala 	return pci_eth_init(bis);
242d1712369SKumar Gala }
243