1d1712369SKumar Gala /*
2*561e710aSKumar 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: ");
90d1712369SKumar Gala 	sw = in_8(&PIXIS_SW(3));
91d1712369SKumar Gala 	printf("Bank1=%uMHz ", (sw & 0x40) ? 125 : 100);
92d1712369SKumar Gala 	printf("Bank2=%sMHz ", (sw & 0x20) ? "156.25" : "125");
93d1712369SKumar Gala 	printf("Bank3=%sMHz\n", (sw & 0x10) ? "156.25" : "125");
94d1712369SKumar Gala 
95d1712369SKumar Gala 	return 0;
96d1712369SKumar Gala }
97d1712369SKumar Gala 
98d1712369SKumar Gala int board_early_init_f(void)
99d1712369SKumar Gala {
100d1712369SKumar Gala 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
101d1712369SKumar Gala 
102d1712369SKumar Gala 	/*
103d1712369SKumar Gala 	 * P4080 DS board only uses the DDR1_MCK0/3 and DDR2_MCK0/3
104d1712369SKumar Gala 	 * disable the DDR1_MCK1/2/4/5 and DDR2_MCK1/2/4/5 to reduce
105d1712369SKumar Gala 	 * the noise introduced by these unterminated and unused clock pairs.
106d1712369SKumar Gala 	 */
107d1712369SKumar Gala 	setbits_be32(&gur->ddrclkdr, 0x001B001B);
108d1712369SKumar Gala 
109d1712369SKumar Gala 	return 0;
110d1712369SKumar Gala }
111d1712369SKumar Gala 
112d1712369SKumar Gala int board_early_init_r(void)
113d1712369SKumar Gala {
114d1712369SKumar Gala 	const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
115d1712369SKumar Gala 	const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
116d1712369SKumar Gala 
117d1712369SKumar Gala 	/*
118d1712369SKumar Gala 	 * Remap Boot flash + PROMJET region to caching-inhibited
119d1712369SKumar Gala 	 * so that flash can be erased properly.
120d1712369SKumar Gala 	 */
121d1712369SKumar Gala 
122d1712369SKumar Gala 	/* Flush d-cache and invalidate i-cache of any FLASH data */
123d1712369SKumar Gala 	flush_dcache();
124d1712369SKumar Gala 	invalidate_icache();
125d1712369SKumar Gala 
126d1712369SKumar Gala 	/* invalidate existing TLB entry for flash + promjet */
127d1712369SKumar Gala 	disable_tlb(flash_esel);
128d1712369SKumar Gala 
129d1712369SKumar Gala 	set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,	/* tlb, epn, rpn */
130d1712369SKumar Gala 			MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,	/* perms, wimge */
131d1712369SKumar Gala 			0, flash_esel, BOOKE_PAGESZ_256M, 1);	/* ts, esel, tsize, iprot */
132d1712369SKumar Gala 
133d1712369SKumar Gala 	set_liodns();
134d1712369SKumar Gala 	setup_portals();
135d1712369SKumar Gala 
136d1712369SKumar Gala 	return 0;
137d1712369SKumar Gala }
138d1712369SKumar Gala 
139d1712369SKumar Gala static const char *serdes_clock_to_string(u32 clock)
140d1712369SKumar Gala {
141d1712369SKumar Gala 	switch(clock) {
142d1712369SKumar Gala 	case SRDS_PLLCR0_RFCK_SEL_100:
143d1712369SKumar Gala 		return "100";
144d1712369SKumar Gala 	case SRDS_PLLCR0_RFCK_SEL_125:
145d1712369SKumar Gala 		return "125";
146d1712369SKumar Gala 	case SRDS_PLLCR0_RFCK_SEL_156_25:
147d1712369SKumar Gala 		return "156.25";
148d1712369SKumar Gala 	default:
149d1712369SKumar Gala 		return "???";
150d1712369SKumar Gala 	}
151d1712369SKumar Gala }
152d1712369SKumar Gala 
153d1712369SKumar Gala #define NUM_SRDS_BANKS	3
154d1712369SKumar Gala 
155d1712369SKumar Gala int misc_init_r(void)
156d1712369SKumar Gala {
157d1712369SKumar Gala 	serdes_corenet_t *srds_regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
158d1712369SKumar Gala 	u32 actual[NUM_SRDS_BANKS];
159d1712369SKumar Gala 	unsigned int i;
160d1712369SKumar Gala 	u8 sw3;
161d1712369SKumar Gala 
162d1712369SKumar Gala 	/* Warn if the expected SERDES reference clocks don't match the
163d1712369SKumar Gala 	 * actual reference clocks.  This needs to be done after calling
164d1712369SKumar Gala 	 * p4080_erratum_serdes8(), since that function may modify the clocks.
165d1712369SKumar Gala 	 */
166d1712369SKumar Gala 	sw3 = in_8(&PIXIS_SW(3));
167d1712369SKumar Gala 	actual[0] = (sw3 & 0x40) ?
168d1712369SKumar Gala 		SRDS_PLLCR0_RFCK_SEL_125 : SRDS_PLLCR0_RFCK_SEL_100;
169d1712369SKumar Gala 	actual[1] = (sw3 & 0x20) ?
170d1712369SKumar Gala 		SRDS_PLLCR0_RFCK_SEL_156_25 : SRDS_PLLCR0_RFCK_SEL_125;
171d1712369SKumar Gala 	actual[2] = (sw3 & 0x10) ?
172d1712369SKumar Gala 		SRDS_PLLCR0_RFCK_SEL_156_25 : SRDS_PLLCR0_RFCK_SEL_125;
173d1712369SKumar Gala 
174d1712369SKumar Gala 	for (i = 0; i < NUM_SRDS_BANKS; i++) {
175d1712369SKumar Gala 		u32 expected = srds_regs->bank[i].pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
176d1712369SKumar Gala 		if (expected != actual[i]) {
177d1712369SKumar Gala 			printf("Warning: SERDES bank %u expects reference clock"
178d1712369SKumar Gala 			       " %sMHz, but actual is %sMHz\n", i + 1,
179d1712369SKumar Gala 			       serdes_clock_to_string(expected),
180d1712369SKumar Gala 			       serdes_clock_to_string(actual[i]));
181d1712369SKumar Gala 		}
182d1712369SKumar Gala 	}
183d1712369SKumar Gala 
184d1712369SKumar Gala 	return 0;
185d1712369SKumar Gala }
186d1712369SKumar Gala 
187d1712369SKumar Gala void ft_board_setup(void *blob, bd_t *bd)
188d1712369SKumar Gala {
189d1712369SKumar Gala 	phys_addr_t base;
190d1712369SKumar Gala 	phys_size_t size;
191d1712369SKumar Gala 
192d1712369SKumar Gala 	ft_cpu_setup(blob, bd);
193d1712369SKumar Gala 
194d1712369SKumar Gala 	base = getenv_bootm_low();
195d1712369SKumar Gala 	size = getenv_bootm_size();
196d1712369SKumar Gala 
197d1712369SKumar Gala 	fdt_fixup_memory(blob, (u64)base, (u64)size);
198d1712369SKumar Gala 
199d1712369SKumar Gala #ifdef CONFIG_PCI
200d1712369SKumar Gala 	pci_of_setup(blob, bd);
201d1712369SKumar Gala #endif
202d1712369SKumar Gala 
203d1712369SKumar Gala 	fdt_fixup_liodn(blob);
204d1712369SKumar Gala }
205d1712369SKumar Gala 
206d1712369SKumar Gala int board_eth_init(bd_t *bis)
207d1712369SKumar Gala {
208d1712369SKumar Gala 	return pci_eth_init(bis);
209d1712369SKumar Gala }
210