1d1712369SKumar Gala /*
2561e710aSKumar Gala  * Copyright 2009-2011 Freescale Semiconductor, Inc.
3d1712369SKumar Gala  *
41a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
5d1712369SKumar Gala  */
6d1712369SKumar Gala 
7d1712369SKumar Gala #include <common.h>
8d1712369SKumar Gala #include <command.h>
9d1712369SKumar Gala #include <netdev.h>
100e159024SLian Minghuan #include <linux/compiler.h>
11d1712369SKumar Gala #include <asm/mmu.h>
12d1712369SKumar Gala #include <asm/processor.h>
13d1712369SKumar Gala #include <asm/cache.h>
14d1712369SKumar Gala #include <asm/immap_85xx.h>
15d1712369SKumar Gala #include <asm/fsl_law.h>
16d1712369SKumar Gala #include <asm/fsl_serdes.h>
17d1712369SKumar Gala #include <asm/fsl_portals.h>
18d1712369SKumar Gala #include <asm/fsl_liodn.h>
192915609aSAndy Fleming #include <fm_eth.h>
20d1712369SKumar Gala 
21d1712369SKumar Gala #include "../common/ngpixis.h"
222915609aSAndy Fleming #include "corenet_ds.h"
23d1712369SKumar Gala 
24d1712369SKumar Gala DECLARE_GLOBAL_DATA_PTR;
25d1712369SKumar Gala 
26d1712369SKumar Gala int checkboard (void)
27d1712369SKumar Gala {
28d1712369SKumar Gala 	u8 sw;
2967ac13b1SSimon Glass 	struct cpu_type *cpu = gd->arch.cpu;
30f165bc35SYork Sun #if defined(CONFIG_P3041DS) || defined(CONFIG_P5020DS) || \
31f165bc35SYork Sun 	defined(CONFIG_P5040DS)
3246299078STimur Tabi 	unsigned int i;
33f165bc35SYork Sun #endif
34d31e53b4STimur Tabi 	static const char * const freq[] = {"100", "125", "156.25", "212.5" };
35d1712369SKumar Gala 
36d1712369SKumar Gala 	printf("Board: %sDS, ", cpu->name);
37d1712369SKumar Gala 	printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
38d1712369SKumar Gala 		in_8(&pixis->id), in_8(&pixis->arch), in_8(&pixis->scver));
39d1712369SKumar Gala 
40d1712369SKumar Gala 	sw = in_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH));
41d1712369SKumar Gala 	sw = (sw & PIXIS_LBMAP_MASK) >> PIXIS_LBMAP_SHIFT;
42d1712369SKumar Gala 
43d1712369SKumar Gala 	if (sw < 0x8)
44d1712369SKumar Gala 		printf("vBank: %d\n", sw);
45d1712369SKumar Gala 	else if (sw == 0x8)
46d1712369SKumar Gala 		puts("Promjet\n");
47d1712369SKumar Gala 	else if (sw == 0x9)
48d1712369SKumar Gala 		puts("NAND\n");
49d1712369SKumar Gala 	else
50d1712369SKumar Gala 		printf("invalid setting of SW%u\n", PIXIS_LBMAP_SWITCH);
51d1712369SKumar Gala 
52d1712369SKumar Gala 	/* Display the actual SERDES reference clocks as configured by the
53d1712369SKumar Gala 	 * dip switches on the board.  Note that the SWx registers could
54d1712369SKumar Gala 	 * technically be set to force the reference clocks to match the
55d1712369SKumar Gala 	 * values that the SERDES expects (or vice versa).  For now, however,
56d1712369SKumar Gala 	 * we just display both values and hope the user notices when they
57d1712369SKumar Gala 	 * don't match.
58d1712369SKumar Gala 	 */
59d1712369SKumar Gala 	puts("SERDES Reference Clocks: ");
60d31e53b4STimur Tabi #if defined(CONFIG_P3041DS) || defined(CONFIG_P5020DS) \
61d31e53b4STimur Tabi 	|| defined(CONFIG_P5040DS)
62e02aea61SKumar Gala 	sw = in_8(&PIXIS_SW(5));
63e02aea61SKumar Gala 	for (i = 0; i < 3; i++) {
64e02aea61SKumar Gala 		unsigned int clock = (sw >> (6 - (2 * i))) & 3;
65e02aea61SKumar Gala 
66e02aea61SKumar Gala 		printf("Bank%u=%sMhz ", i+1, freq[clock]);
67e02aea61SKumar Gala 	}
68d31e53b4STimur Tabi #ifdef CONFIG_P5040DS
69d31e53b4STimur Tabi 	/* On P5040DS, SW11[7:8] determines the Bank 4 frequency */
70d31e53b4STimur Tabi 	sw = in_8(&PIXIS_SW(9));
71d31e53b4STimur Tabi 	printf("Bank4=%sMhz ", freq[sw & 3]);
72d31e53b4STimur Tabi #endif
73e02aea61SKumar Gala 	puts("\n");
74e02aea61SKumar Gala #else
75d1712369SKumar Gala 	sw = in_8(&PIXIS_SW(3));
76d31e53b4STimur Tabi 	/* SW3[2]: 0 = 100 Mhz, 1 = 125 MHz */
77d31e53b4STimur Tabi 	/* SW3[3]: 0 = 125 Mhz, 1 = 156.25 MHz */
78d31e53b4STimur Tabi 	/* SW3[4]: 0 = 125 Mhz, 1 = 156.25 MHz */
79d31e53b4STimur Tabi 	printf("Bank1=%sMHz ", freq[!!(sw & 0x40)]);
80d31e53b4STimur Tabi 	printf("Bank2=%sMHz ", freq[1 + !!(sw & 0x20)]);
81d31e53b4STimur Tabi 	printf("Bank3=%sMHz\n", freq[1 + !!(sw & 0x10)]);
82e02aea61SKumar Gala #endif
83d1712369SKumar Gala 
84d1712369SKumar Gala 	return 0;
85d1712369SKumar Gala }
86d1712369SKumar Gala 
87d1712369SKumar Gala int board_early_init_f(void)
88d1712369SKumar Gala {
89d1712369SKumar Gala 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
90d1712369SKumar Gala 
91d1712369SKumar Gala 	/*
92d1712369SKumar Gala 	 * P4080 DS board only uses the DDR1_MCK0/3 and DDR2_MCK0/3
93d1712369SKumar Gala 	 * disable the DDR1_MCK1/2/4/5 and DDR2_MCK1/2/4/5 to reduce
94d1712369SKumar Gala 	 * the noise introduced by these unterminated and unused clock pairs.
95d1712369SKumar Gala 	 */
96d1712369SKumar Gala 	setbits_be32(&gur->ddrclkdr, 0x001B001B);
97d1712369SKumar Gala 
98d1712369SKumar Gala 	return 0;
99d1712369SKumar Gala }
100d1712369SKumar Gala 
101d1712369SKumar Gala int board_early_init_r(void)
102d1712369SKumar Gala {
103d1712369SKumar Gala 	const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
104*9d045682SYork Sun 	int flash_esel = find_tlb_idx((void *)flashbase, 1);
105d1712369SKumar Gala 
106d1712369SKumar Gala 	/*
107d1712369SKumar Gala 	 * Remap Boot flash + PROMJET region to caching-inhibited
108d1712369SKumar Gala 	 * so that flash can be erased properly.
109d1712369SKumar Gala 	 */
110d1712369SKumar Gala 
111d1712369SKumar Gala 	/* Flush d-cache and invalidate i-cache of any FLASH data */
112d1712369SKumar Gala 	flush_dcache();
113d1712369SKumar Gala 	invalidate_icache();
114d1712369SKumar Gala 
115*9d045682SYork Sun 	if (flash_esel == -1) {
116*9d045682SYork Sun 		/* very unlikely unless something is messed up */
117*9d045682SYork Sun 		puts("Error: Could not find TLB for FLASH BASE\n");
118*9d045682SYork Sun 		flash_esel = 2;	/* give our best effort to continue */
119*9d045682SYork Sun 	} else {
120d1712369SKumar Gala 		/* invalidate existing TLB entry for flash + promjet */
121d1712369SKumar Gala 		disable_tlb(flash_esel);
122*9d045682SYork Sun 	}
123d1712369SKumar Gala 
124d1712369SKumar Gala 	set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,	/* tlb, epn, rpn */
125d1712369SKumar Gala 			MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,	/* perms, wimge */
126d1712369SKumar Gala 			0, flash_esel, BOOKE_PAGESZ_256M, 1);	/* ts, esel, tsize, iprot */
127d1712369SKumar Gala 
128d1712369SKumar Gala 	set_liodns();
12958b2f96eSKumar Gala #ifdef CONFIG_SYS_DPAA_QBMAN
130d1712369SKumar Gala 	setup_portals();
13158b2f96eSKumar Gala #endif
132d1712369SKumar Gala 
133d1712369SKumar Gala 	return 0;
134d1712369SKumar Gala }
135d1712369SKumar Gala 
136d1712369SKumar Gala #define NUM_SRDS_BANKS	3
137d1712369SKumar Gala 
138d1712369SKumar Gala int misc_init_r(void)
139d1712369SKumar Gala {
140d1712369SKumar Gala 	serdes_corenet_t *srds_regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
141d1712369SKumar Gala 	u32 actual[NUM_SRDS_BANKS];
142d1712369SKumar Gala 	unsigned int i;
143e02aea61SKumar Gala 	u8 sw;
144d1712369SKumar Gala 
145d31e53b4STimur Tabi #if defined(CONFIG_P3041DS) || defined(CONFIG_P5020DS) \
146d31e53b4STimur Tabi 	|| defined(CONFIG_P5040DS)
147e02aea61SKumar Gala 	sw = in_8(&PIXIS_SW(5));
148e02aea61SKumar Gala 	for (i = 0; i < 3; i++) {
149e02aea61SKumar Gala 		unsigned int clock = (sw >> (6 - (2 * i))) & 3;
150e02aea61SKumar Gala 		switch (clock) {
151e02aea61SKumar Gala 		case 0:
152e02aea61SKumar Gala 			actual[i] = SRDS_PLLCR0_RFCK_SEL_100;
153e02aea61SKumar Gala 			break;
154e02aea61SKumar Gala 		case 1:
155e02aea61SKumar Gala 			actual[i] = SRDS_PLLCR0_RFCK_SEL_125;
156e02aea61SKumar Gala 			break;
157e02aea61SKumar Gala 		case 2:
158e02aea61SKumar Gala 			actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25;
159e02aea61SKumar Gala 			break;
160e02aea61SKumar Gala 		default:
161e02aea61SKumar Gala 			printf("Warning: SDREFCLK%u switch setting of '11' is "
162e02aea61SKumar Gala 			       "unsupported\n", i + 1);
163e02aea61SKumar Gala 			break;
164e02aea61SKumar Gala 		}
165e02aea61SKumar Gala 	}
166e02aea61SKumar Gala #else
167d1712369SKumar Gala 	/* Warn if the expected SERDES reference clocks don't match the
168d1712369SKumar Gala 	 * actual reference clocks.  This needs to be done after calling
169d1712369SKumar Gala 	 * p4080_erratum_serdes8(), since that function may modify the clocks.
170d1712369SKumar Gala 	 */
171e02aea61SKumar Gala 	sw = in_8(&PIXIS_SW(3));
172e02aea61SKumar Gala 	actual[0] = (sw & 0x40) ?
173d1712369SKumar Gala 		SRDS_PLLCR0_RFCK_SEL_125 : SRDS_PLLCR0_RFCK_SEL_100;
174e02aea61SKumar Gala 	actual[1] = (sw & 0x20) ?
175d1712369SKumar Gala 		SRDS_PLLCR0_RFCK_SEL_156_25 : SRDS_PLLCR0_RFCK_SEL_125;
176e02aea61SKumar Gala 	actual[2] = (sw & 0x10) ?
177d1712369SKumar Gala 		SRDS_PLLCR0_RFCK_SEL_156_25 : SRDS_PLLCR0_RFCK_SEL_125;
178e02aea61SKumar Gala #endif
179d1712369SKumar Gala 
180d1712369SKumar Gala 	for (i = 0; i < NUM_SRDS_BANKS; i++) {
181d1712369SKumar Gala 		u32 expected = srds_regs->bank[i].pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
182d1712369SKumar Gala 		if (expected != actual[i]) {
183d1712369SKumar Gala 			printf("Warning: SERDES bank %u expects reference clock"
184d1712369SKumar Gala 			       " %sMHz, but actual is %sMHz\n", i + 1,
185d1712369SKumar Gala 			       serdes_clock_to_string(expected),
186d1712369SKumar Gala 			       serdes_clock_to_string(actual[i]));
187d1712369SKumar Gala 		}
188d1712369SKumar Gala 	}
189d1712369SKumar Gala 
190d1712369SKumar Gala 	return 0;
191d1712369SKumar Gala }
192d1712369SKumar Gala 
193d1712369SKumar Gala void ft_board_setup(void *blob, bd_t *bd)
194d1712369SKumar Gala {
195d1712369SKumar Gala 	phys_addr_t base;
196d1712369SKumar Gala 	phys_size_t size;
197d1712369SKumar Gala 
198d1712369SKumar Gala 	ft_cpu_setup(blob, bd);
199d1712369SKumar Gala 
200d1712369SKumar Gala 	base = getenv_bootm_low();
201d1712369SKumar Gala 	size = getenv_bootm_size();
202d1712369SKumar Gala 
203d1712369SKumar Gala 	fdt_fixup_memory(blob, (u64)base, (u64)size);
204d1712369SKumar Gala 
205d1712369SKumar Gala #ifdef CONFIG_PCI
206d1712369SKumar Gala 	pci_of_setup(blob, bd);
207d1712369SKumar Gala #endif
208d1712369SKumar Gala 
209d1712369SKumar Gala 	fdt_fixup_liodn(blob);
210a3a3e7b2SShaohui Xie 	fdt_fixup_dr_usb(blob, bd);
211d1712369SKumar Gala 
2122915609aSAndy Fleming #ifdef CONFIG_SYS_DPAA_FMAN
2132915609aSAndy Fleming 	fdt_fixup_fman_ethernet(blob);
2142915609aSAndy Fleming 	fdt_fixup_board_enet(blob);
2152915609aSAndy Fleming #endif
216d1712369SKumar Gala }
217