xref: /rk3399_rockchip-uboot/board/freescale/mpc8569mds/mpc8569mds.c (revision 0e00a84cdedf7a1949486746225b35984b351eca)
1765547dcSHaiying Wang /*
26525d51fSKumar Gala  * Copyright 2009-2010 Freescale Semiconductor.
3765547dcSHaiying Wang  *
4765547dcSHaiying Wang  * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
5765547dcSHaiying Wang  *
61a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
7765547dcSHaiying Wang  */
8765547dcSHaiying Wang 
9765547dcSHaiying Wang #include <common.h>
1024b852a7SSimon Glass #include <console.h>
117f52ed5eSAnton Vorontsov #include <hwconfig.h>
12765547dcSHaiying Wang #include <pci.h>
13765547dcSHaiying Wang #include <asm/processor.h>
14765547dcSHaiying Wang #include <asm/mmu.h>
153aed5507SHaiying Wang #include <asm/cache.h>
16765547dcSHaiying Wang #include <asm/immap_85xx.h>
17c8514622SKumar Gala #include <asm/fsl_pci.h>
185614e71bSYork Sun #include <fsl_ddr_sdram.h>
195d27e02cSKumar Gala #include <asm/fsl_serdes.h>
20765547dcSHaiying Wang #include <asm/io.h>
21765547dcSHaiying Wang #include <spd_sdram.h>
22765547dcSHaiying Wang #include <i2c.h>
23765547dcSHaiying Wang #include <ioports.h>
24*0e00a84cSMasahiro Yamada #include <linux/libfdt.h>
25765547dcSHaiying Wang #include <fdt_support.h>
267f52ed5eSAnton Vorontsov #include <fsl_esdhc.h>
27865ff856SAndy Fleming #include <phy.h>
28765547dcSHaiying Wang 
29765547dcSHaiying Wang #include "bcsr.h"
30d9180382SLiu Yu #if defined(CONFIG_PQ_MDS_PIB)
31d9180382SLiu Yu #include "../common/pq-mds-pib.h"
32d9180382SLiu Yu #endif
33765547dcSHaiying Wang 
34765547dcSHaiying Wang const qe_iop_conf_t qe_iop_conf_tab[] = {
35765547dcSHaiying Wang 	/* QE_MUX_MDC */
36765547dcSHaiying Wang 	{2,  31, 1, 0, 1}, /* QE_MUX_MDC               */
37765547dcSHaiying Wang 
38765547dcSHaiying Wang 	/* QE_MUX_MDIO */
39765547dcSHaiying Wang 	{2,  30, 3, 0, 2}, /* QE_MUX_MDIO              */
40765547dcSHaiying Wang 
41f82107f6SHaiying Wang #if defined(CONFIG_SYS_UCC_RGMII_MODE)
42765547dcSHaiying Wang 	/* UCC_1_RGMII */
43765547dcSHaiying Wang 	{2, 11, 2, 0, 1}, /* CLK12 */
44765547dcSHaiying Wang 	{0,  0, 1, 0, 3}, /* ENET1_TXD0_SER1_TXD0      */
45765547dcSHaiying Wang 	{0,  1, 1, 0, 3}, /* ENET1_TXD1_SER1_TXD1      */
46765547dcSHaiying Wang 	{0,  2, 1, 0, 1}, /* ENET1_TXD2_SER1_TXD2      */
47765547dcSHaiying Wang 	{0,  3, 1, 0, 2}, /* ENET1_TXD3_SER1_TXD3      */
48765547dcSHaiying Wang 	{0,  6, 2, 0, 3}, /* ENET1_RXD0_SER1_RXD0      */
49765547dcSHaiying Wang 	{0,  7, 2, 0, 1}, /* ENET1_RXD1_SER1_RXD1      */
50765547dcSHaiying Wang 	{0,  8, 2, 0, 2}, /* ENET1_RXD2_SER1_RXD2      */
51765547dcSHaiying Wang 	{0,  9, 2, 0, 2}, /* ENET1_RXD3_SER1_RXD3      */
52765547dcSHaiying Wang 	{0,  4, 1, 0, 2}, /* ENET1_TX_EN_SER1_RTS_B    */
53765547dcSHaiying Wang 	{0, 12, 2, 0, 3}, /* ENET1_RX_DV_SER1_CTS_B    */
54765547dcSHaiying Wang 	{2,  8, 2, 0, 1}, /* ENET1_GRXCLK              */
55765547dcSHaiying Wang 	{2, 20, 1, 0, 2}, /* ENET1_GTXCLK              */
56765547dcSHaiying Wang 
57765547dcSHaiying Wang 	/* UCC_2_RGMII */
58765547dcSHaiying Wang 	{2, 16, 2, 0, 3}, /* CLK17 */
59765547dcSHaiying Wang 	{0, 14, 1, 0, 2}, /* ENET2_TXD0_SER2_TXD0      */
60765547dcSHaiying Wang 	{0, 15, 1, 0, 2}, /* ENET2_TXD1_SER2_TXD1      */
61765547dcSHaiying Wang 	{0, 16, 1, 0, 1}, /* ENET2_TXD2_SER2_TXD2      */
62765547dcSHaiying Wang 	{0, 17, 1, 0, 1}, /* ENET2_TXD3_SER2_TXD3      */
63765547dcSHaiying Wang 	{0, 20, 2, 0, 2}, /* ENET2_RXD0_SER2_RXD0      */
64765547dcSHaiying Wang 	{0, 21, 2, 0, 1}, /* ENET2_RXD1_SER2_RXD1      */
65765547dcSHaiying Wang 	{0, 22, 2, 0, 1}, /* ENET2_RXD2_SER2_RXD2      */
66765547dcSHaiying Wang 	{0, 23, 2, 0, 1}, /* ENET2_RXD3_SER2_RXD3      */
67765547dcSHaiying Wang 	{0, 18, 1, 0, 2}, /* ENET2_TX_EN_SER2_RTS_B    */
68765547dcSHaiying Wang 	{0, 26, 2, 0, 3}, /* ENET2_RX_DV_SER2_CTS_B    */
69765547dcSHaiying Wang 	{2,  3, 2, 0, 1}, /* ENET2_GRXCLK              */
70765547dcSHaiying Wang 	{2,  2, 1, 0, 2}, /* ENET2_GTXCLK              */
71765547dcSHaiying Wang 
72750098d3SHaiying Wang 	/* UCC_3_RGMII */
73750098d3SHaiying Wang 	{2, 11, 2, 0, 1}, /* CLK12 */
74750098d3SHaiying Wang 	{0, 29, 1, 0, 2}, /* ENET3_TXD0_SER3_TXD0      */
75750098d3SHaiying Wang 	{0, 30, 1, 0, 3}, /* ENET3_TXD1_SER3_TXD1      */
76750098d3SHaiying Wang 	{0, 31, 1, 0, 2}, /* ENET3_TXD2_SER3_TXD2      */
77750098d3SHaiying Wang 	{1,  0, 1, 0, 3}, /* ENET3_TXD3_SER3_TXD3      */
78750098d3SHaiying Wang 	{1,  3, 2, 0, 3}, /* ENET3_RXD0_SER3_RXD0      */
79750098d3SHaiying Wang 	{1,  4, 2, 0, 1}, /* ENET3_RXD1_SER3_RXD1      */
80750098d3SHaiying Wang 	{1,  5, 2, 0, 2}, /* ENET3_RXD2_SER3_RXD2      */
81750098d3SHaiying Wang 	{1,  6, 2, 0, 3}, /* ENET3_RXD3_SER3_RXD3      */
82750098d3SHaiying Wang 	{1,  1, 1, 0, 1}, /* ENET3_TX_EN_SER3_RTS_B    */
83750098d3SHaiying Wang 	{1,  9, 2, 0, 3}, /* ENET3_RX_DV_SER3_CTS_B    */
84750098d3SHaiying Wang 	{2,  9, 2, 0, 2}, /* ENET3_GRXCLK              */
85750098d3SHaiying Wang 	{2, 25, 1, 0, 2}, /* ENET3_GTXCLK              */
86750098d3SHaiying Wang 
87750098d3SHaiying Wang 	/* UCC_4_RGMII */
88750098d3SHaiying Wang 	{2, 16, 2, 0, 3}, /* CLK17 */
89750098d3SHaiying Wang 	{1, 12, 1, 0, 2}, /* ENET4_TXD0_SER4_TXD0      */
90750098d3SHaiying Wang 	{1, 13, 1, 0, 2}, /* ENET4_TXD1_SER4_TXD1      */
91750098d3SHaiying Wang 	{1, 14, 1, 0, 1}, /* ENET4_TXD2_SER4_TXD2      */
92750098d3SHaiying Wang 	{1, 15, 1, 0, 2}, /* ENET4_TXD3_SER4_TXD3      */
93750098d3SHaiying Wang 	{1, 18, 2, 0, 2}, /* ENET4_RXD0_SER4_RXD0      */
94750098d3SHaiying Wang 	{1, 19, 2, 0, 1}, /* ENET4_RXD1_SER4_RXD1      */
95750098d3SHaiying Wang 	{1, 20, 2, 0, 1}, /* ENET4_RXD2_SER4_RXD2      */
96750098d3SHaiying Wang 	{1, 21, 2, 0, 2}, /* ENET4_RXD3_SER4_RXD3      */
97750098d3SHaiying Wang 	{1, 16, 1, 0, 2}, /* ENET4_TX_EN_SER4_RTS_B    */
98750098d3SHaiying Wang 	{1, 24, 2, 0, 3}, /* ENET4_RX_DV_SER4_CTS_B    */
99750098d3SHaiying Wang 	{2, 17, 2, 0, 2}, /* ENET4_GRXCLK              */
100750098d3SHaiying Wang 	{2, 24, 1, 0, 2}, /* ENET4_GTXCLK              */
101750098d3SHaiying Wang 
102f82107f6SHaiying Wang #elif defined(CONFIG_SYS_UCC_RMII_MODE)
103f82107f6SHaiying Wang 	/* UCC_1_RMII */
104f82107f6SHaiying Wang 	{2, 15, 2, 0, 1}, /* CLK16 */
105f82107f6SHaiying Wang 	{0,  0, 1, 0, 3}, /* ENET1_TXD0_SER1_TXD0      */
106f82107f6SHaiying Wang 	{0,  1, 1, 0, 3}, /* ENET1_TXD1_SER1_TXD1      */
107f82107f6SHaiying Wang 	{0,  6, 2, 0, 3}, /* ENET1_RXD0_SER1_RXD0      */
108f82107f6SHaiying Wang 	{0,  7, 2, 0, 1}, /* ENET1_RXD1_SER1_RXD1      */
109f82107f6SHaiying Wang 	{0,  4, 1, 0, 2}, /* ENET1_TX_EN_SER1_RTS_B    */
110f82107f6SHaiying Wang 	{0, 12, 2, 0, 3}, /* ENET1_RX_DV_SER1_CTS_B    */
111f82107f6SHaiying Wang 
112f82107f6SHaiying Wang 	/* UCC_2_RMII */
113f82107f6SHaiying Wang 	{2, 15, 2, 0, 1}, /* CLK16 */
114f82107f6SHaiying Wang 	{0, 14, 1, 0, 2}, /* ENET2_TXD0_SER2_TXD0      */
115f82107f6SHaiying Wang 	{0, 15, 1, 0, 2}, /* ENET2_TXD1_SER2_TXD1      */
116f82107f6SHaiying Wang 	{0, 20, 2, 0, 2}, /* ENET2_RXD0_SER2_RXD0      */
117f82107f6SHaiying Wang 	{0, 21, 2, 0, 1}, /* ENET2_RXD1_SER2_RXD1      */
118f82107f6SHaiying Wang 	{0, 18, 1, 0, 2}, /* ENET2_TX_EN_SER2_RTS_B    */
119f82107f6SHaiying Wang 	{0, 26, 2, 0, 3}, /* ENET2_RX_DV_SER2_CTS_B    */
120f82107f6SHaiying Wang 
121f82107f6SHaiying Wang 	/* UCC_3_RMII */
122f82107f6SHaiying Wang 	{2, 15, 2, 0, 1}, /* CLK16 */
123f82107f6SHaiying Wang 	{0, 29, 1, 0, 2}, /* ENET3_TXD0_SER3_TXD0      */
124f82107f6SHaiying Wang 	{0, 30, 1, 0, 3}, /* ENET3_TXD1_SER3_TXD1      */
125f82107f6SHaiying Wang 	{1,  3, 2, 0, 3}, /* ENET3_RXD0_SER3_RXD0      */
126f82107f6SHaiying Wang 	{1,  4, 2, 0, 1}, /* ENET3_RXD1_SER3_RXD1      */
127f82107f6SHaiying Wang 	{1,  1, 1, 0, 1}, /* ENET3_TX_EN_SER3_RTS_B    */
128f82107f6SHaiying Wang 	{1,  9, 2, 0, 3}, /* ENET3_RX_DV_SER3_CTS_B    */
129f82107f6SHaiying Wang 
130f82107f6SHaiying Wang 	/* UCC_4_RMII */
131f82107f6SHaiying Wang 	{2, 15, 2, 0, 1}, /* CLK16 */
132f82107f6SHaiying Wang 	{1, 12, 1, 0, 2}, /* ENET4_TXD0_SER4_TXD0      */
133f82107f6SHaiying Wang 	{1, 13, 1, 0, 2}, /* ENET4_TXD1_SER4_TXD1      */
134f82107f6SHaiying Wang 	{1, 18, 2, 0, 2}, /* ENET4_RXD0_SER4_RXD0      */
135f82107f6SHaiying Wang 	{1, 19, 2, 0, 1}, /* ENET4_RXD1_SER4_RXD1      */
136f82107f6SHaiying Wang 	{1, 16, 1, 0, 2}, /* ENET4_TX_EN_SER4_RTS_B    */
137f82107f6SHaiying Wang 	{1, 24, 2, 0, 3}, /* ENET4_RX_DV_SER4_CTS_B    */
138f82107f6SHaiying Wang #endif
139f82107f6SHaiying Wang 
140b2aab386SHaiying Wang 	/* UART1 is muxed with QE PortF bit [9-12].*/
141b2aab386SHaiying Wang 	{5, 12, 2, 0, 3}, /* UART1_SIN */
142b2aab386SHaiying Wang 	{5, 9,  1, 0, 3}, /* UART1_SOUT */
143b2aab386SHaiying Wang 	{5, 10, 2, 0, 3}, /* UART1_CTS_B */
144b2aab386SHaiying Wang 	{5, 11, 1, 0, 2}, /* UART1_RTS_B */
145b2aab386SHaiying Wang 
14614809b6cSAnton Vorontsov 	/* QE UART                                     */
14714809b6cSAnton Vorontsov 	{0, 19, 1, 0, 2}, /* QEUART_TX                 */
14814809b6cSAnton Vorontsov 	{1, 17, 2, 0, 3}, /* QEUART_RX                 */
14914809b6cSAnton Vorontsov 	{0, 25, 1, 0, 1}, /* QEUART_RTS                */
15014809b6cSAnton Vorontsov 	{1, 23, 2, 0, 1}, /* QEUART_CTS                */
15114809b6cSAnton Vorontsov 
1523fca8037SAnton Vorontsov 	/* QE USB                                      */
1533fca8037SAnton Vorontsov 	{5,  3, 1, 0, 1}, /* USB_OE                    */
1543fca8037SAnton Vorontsov 	{5,  4, 1, 0, 2}, /* USB_TP                    */
1553fca8037SAnton Vorontsov 	{5,  5, 1, 0, 2}, /* USB_TN                    */
1563fca8037SAnton Vorontsov 	{5,  6, 2, 0, 2}, /* USB_RP                    */
1573fca8037SAnton Vorontsov 	{5,  7, 2, 0, 1}, /* USB_RX                    */
1583fca8037SAnton Vorontsov 	{5,  8, 2, 0, 1}, /* USB_RN                    */
1593fca8037SAnton Vorontsov 	{2,  4, 2, 0, 2}, /* CLK5                      */
1603fca8037SAnton Vorontsov 
16170d665b1SAnton Vorontsov 	/* SPI Flash, M25P40                           */
16270d665b1SAnton Vorontsov 	{4, 27, 3, 0, 1}, /* SPI_MOSI                  */
16370d665b1SAnton Vorontsov 	{4, 28, 3, 0, 1}, /* SPI_MISO                  */
16470d665b1SAnton Vorontsov 	{4, 29, 3, 0, 1}, /* SPI_CLK                   */
16570d665b1SAnton Vorontsov 	{4, 30, 1, 0, 0}, /* SPI_SEL, GPIO             */
16670d665b1SAnton Vorontsov 
167765547dcSHaiying Wang 	{0,  0, 0, 0, QE_IOP_TAB_END} /* END of table */
168765547dcSHaiying Wang };
169765547dcSHaiying Wang 
170765547dcSHaiying Wang void local_bus_init(void);
171765547dcSHaiying Wang 
board_early_init_f(void)172765547dcSHaiying Wang int board_early_init_f (void)
173765547dcSHaiying Wang {
174765547dcSHaiying Wang 	/*
175765547dcSHaiying Wang 	 * Initialize local bus.
176765547dcSHaiying Wang 	 */
177765547dcSHaiying Wang 	local_bus_init ();
178765547dcSHaiying Wang 
179765547dcSHaiying Wang 	enable_8569mds_flash_write();
180765547dcSHaiying Wang 
181765547dcSHaiying Wang #ifdef CONFIG_QE
182f82107f6SHaiying Wang 	enable_8569mds_qe_uec();
183765547dcSHaiying Wang #endif
184765547dcSHaiying Wang 
185765547dcSHaiying Wang #if CONFIG_SYS_I2C2_OFFSET
186765547dcSHaiying Wang 	/* Enable I2C2 signals instead of SD signals */
187765547dcSHaiying Wang 	volatile struct ccsr_gur *gur;
188765547dcSHaiying Wang 	gur = (struct ccsr_gur *)(CONFIG_SYS_IMMR + 0xe0000);
189765547dcSHaiying Wang 	gur->plppar1 &= ~PLPPAR1_I2C_BIT_MASK;
190765547dcSHaiying Wang 	gur->plppar1 |= PLPPAR1_I2C2_VAL;
191765547dcSHaiying Wang 	gur->plpdir1 &= ~PLPDIR1_I2C_BIT_MASK;
192765547dcSHaiying Wang 	gur->plpdir1 |= PLPDIR1_I2C2_VAL;
193765547dcSHaiying Wang 
194765547dcSHaiying Wang 	disable_8569mds_brd_eeprom_write_protect();
195765547dcSHaiying Wang #endif
196765547dcSHaiying Wang 
197765547dcSHaiying Wang 	return 0;
198765547dcSHaiying Wang }
199765547dcSHaiying Wang 
board_early_init_r(void)2003aed5507SHaiying Wang int board_early_init_r(void)
2013aed5507SHaiying Wang {
2023aed5507SHaiying Wang 	const unsigned int flashbase = CONFIG_SYS_NAND_BASE;
2033aed5507SHaiying Wang 	const u8 flash_esel = 0;
2043aed5507SHaiying Wang 
2053aed5507SHaiying Wang 	/*
2063aed5507SHaiying Wang 	 * Remap Boot flash to caching-inhibited
2073aed5507SHaiying Wang 	 * so that flash can be erased properly.
2083aed5507SHaiying Wang 	 */
2093aed5507SHaiying Wang 
2103aed5507SHaiying Wang 	/* Flush d-cache and invalidate i-cache of any FLASH data */
2113aed5507SHaiying Wang 	flush_dcache();
2123aed5507SHaiying Wang 	invalidate_icache();
2133aed5507SHaiying Wang 
2143aed5507SHaiying Wang 	/* invalidate existing TLB entry for flash */
2153aed5507SHaiying Wang 	disable_tlb(flash_esel);
2163aed5507SHaiying Wang 
2173aed5507SHaiying Wang 	set_tlb(1, flashbase, CONFIG_SYS_NAND_BASE,	/* tlb, epn, rpn */
2183aed5507SHaiying Wang 		MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,	/* perms, wimge */
2193aed5507SHaiying Wang 		0, flash_esel,				/* ts, esel */
2203aed5507SHaiying Wang 		BOOKE_PAGESZ_64M, 1);			/* tsize, iprot */
2213aed5507SHaiying Wang 
2223aed5507SHaiying Wang 	return 0;
2233aed5507SHaiying Wang }
2243aed5507SHaiying Wang 
checkboard(void)225765547dcSHaiying Wang int checkboard (void)
226765547dcSHaiying Wang {
227765547dcSHaiying Wang 	printf ("Board: 8569 MDS\n");
228765547dcSHaiying Wang 
229765547dcSHaiying Wang 	return 0;
230765547dcSHaiying Wang }
231765547dcSHaiying Wang 
232765547dcSHaiying Wang #if !defined(CONFIG_SPD_EEPROM)
fixed_sdram(void)233765547dcSHaiying Wang phys_size_t fixed_sdram(void)
234765547dcSHaiying Wang {
2359a17eb5bSYork Sun 	struct ccsr_ddr __iomem *ddr =
2369a17eb5bSYork Sun 		(struct ccsr_ddr __iomem *)CONFIG_SYS_FSL_DDR_ADDR;
237765547dcSHaiying Wang 	uint d_init;
238765547dcSHaiying Wang 
239765547dcSHaiying Wang 	out_be32(&ddr->cs0_bnds, CONFIG_SYS_DDR_CS0_BNDS);
240765547dcSHaiying Wang 	out_be32(&ddr->cs0_config, CONFIG_SYS_DDR_CS0_CONFIG);
241765547dcSHaiying Wang 	out_be32(&ddr->timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
242765547dcSHaiying Wang 	out_be32(&ddr->timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
243765547dcSHaiying Wang 	out_be32(&ddr->timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
244765547dcSHaiying Wang 	out_be32(&ddr->timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
245765547dcSHaiying Wang 	out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
246765547dcSHaiying Wang 	out_be32(&ddr->sdram_cfg_2, CONFIG_SYS_DDR_SDRAM_CFG_2);
247765547dcSHaiying Wang 	out_be32(&ddr->sdram_mode, CONFIG_SYS_DDR_SDRAM_MODE);
248765547dcSHaiying Wang 	out_be32(&ddr->sdram_mode_2, CONFIG_SYS_DDR_SDRAM_MODE_2);
249765547dcSHaiying Wang 	out_be32(&ddr->sdram_interval, CONFIG_SYS_DDR_SDRAM_INTERVAL);
250765547dcSHaiying Wang 	out_be32(&ddr->sdram_data_init, CONFIG_SYS_DDR_DATA_INIT);
251765547dcSHaiying Wang 	out_be32(&ddr->sdram_clk_cntl, CONFIG_SYS_DDR_SDRAM_CLK_CNTL);
252765547dcSHaiying Wang 	out_be32(&ddr->timing_cfg_4, CONFIG_SYS_DDR_TIMING_4);
253765547dcSHaiying Wang 	out_be32(&ddr->timing_cfg_5, CONFIG_SYS_DDR_TIMING_5);
254765547dcSHaiying Wang 	out_be32(&ddr->ddr_zq_cntl, CONFIG_SYS_DDR_ZQ_CNTL);
255765547dcSHaiying Wang 	out_be32(&ddr->ddr_wrlvl_cntl, CONFIG_SYS_DDR_WRLVL_CNTL);
256765547dcSHaiying Wang 	out_be32(&ddr->sdram_cfg_2, CONFIG_SYS_DDR_SDRAM_CFG_2);
257765547dcSHaiying Wang #if defined (CONFIG_DDR_ECC)
258765547dcSHaiying Wang 	out_be32(&ddr->err_int_en, CONFIG_SYS_DDR_ERR_INT_EN);
259765547dcSHaiying Wang 	out_be32(&ddr->err_disable, CONFIG_SYS_DDR_ERR_DIS);
260765547dcSHaiying Wang 	out_be32(&ddr->err_sbe, CONFIG_SYS_DDR_SBE);
261765547dcSHaiying Wang #endif
262765547dcSHaiying Wang 	udelay(500);
263765547dcSHaiying Wang 
264765547dcSHaiying Wang 	out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL);
265765547dcSHaiying Wang #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
266765547dcSHaiying Wang 	d_init = 1;
267765547dcSHaiying Wang 	debug("DDR - 1st controller: memory initializing\n");
268765547dcSHaiying Wang 	/*
269765547dcSHaiying Wang 	 * Poll until memory is initialized.
270765547dcSHaiying Wang 	 * 512 Meg at 400 might hit this 200 times or so.
271765547dcSHaiying Wang 	 */
272765547dcSHaiying Wang 	while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) {
273765547dcSHaiying Wang 		udelay(1000);
274765547dcSHaiying Wang 	}
275765547dcSHaiying Wang 	debug("DDR: memory initialized\n\n");
276765547dcSHaiying Wang 	udelay(500);
277765547dcSHaiying Wang #endif
278765547dcSHaiying Wang 	return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
279765547dcSHaiying Wang }
280765547dcSHaiying Wang #endif
281765547dcSHaiying Wang 
282765547dcSHaiying Wang /*
283765547dcSHaiying Wang  * Initialize Local Bus
284765547dcSHaiying Wang  */
285765547dcSHaiying Wang void
local_bus_init(void)286765547dcSHaiying Wang local_bus_init(void)
287765547dcSHaiying Wang {
288765547dcSHaiying Wang 	volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
289f51cdaf1SBecky Bruce 	volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
290765547dcSHaiying Wang 
291765547dcSHaiying Wang 	uint clkdiv;
292765547dcSHaiying Wang 	sys_info_t sysinfo;
293765547dcSHaiying Wang 
294765547dcSHaiying Wang 	get_sys_info(&sysinfo);
295765547dcSHaiying Wang 	clkdiv = (lbc->lcrr & LCRR_CLKDIV) * 2;
296765547dcSHaiying Wang 
297765547dcSHaiying Wang 	out_be32(&gur->lbiuiplldcr1, 0x00078080);
298765547dcSHaiying Wang 	if (clkdiv == 16)
299765547dcSHaiying Wang 		out_be32(&gur->lbiuiplldcr0, 0x7c0f1bf0);
300765547dcSHaiying Wang 	else if (clkdiv == 8)
301765547dcSHaiying Wang 		out_be32(&gur->lbiuiplldcr0, 0x6c0f1bf0);
302765547dcSHaiying Wang 	else if (clkdiv == 4)
303765547dcSHaiying Wang 		out_be32(&gur->lbiuiplldcr0, 0x5c0f1bf0);
304765547dcSHaiying Wang 
305765547dcSHaiying Wang 	out_be32(&lbc->lcrr, (u32)in_be32(&lbc->lcrr)| 0x00030000);
306765547dcSHaiying Wang }
307765547dcSHaiying Wang 
fdt_board_disable_serial(void * blob,bd_t * bd,const char * alias)30814809b6cSAnton Vorontsov static void fdt_board_disable_serial(void *blob, bd_t *bd, const char *alias)
30914809b6cSAnton Vorontsov {
31014809b6cSAnton Vorontsov 	const char *status = "disabled";
31114809b6cSAnton Vorontsov 	int off;
31214809b6cSAnton Vorontsov 	int err;
31314809b6cSAnton Vorontsov 
31414809b6cSAnton Vorontsov 	off = fdt_path_offset(blob, alias);
31514809b6cSAnton Vorontsov 	if (off < 0) {
31614809b6cSAnton Vorontsov 		printf("WARNING: could not find %s alias: %s.\n", alias,
31714809b6cSAnton Vorontsov 			fdt_strerror(off));
31814809b6cSAnton Vorontsov 		return;
31914809b6cSAnton Vorontsov 	}
32014809b6cSAnton Vorontsov 
32114809b6cSAnton Vorontsov 	err = fdt_setprop(blob, off, "status", status, strlen(status) + 1);
32214809b6cSAnton Vorontsov 	if (err) {
32314809b6cSAnton Vorontsov 		printf("WARNING: could not set status for serial0: %s.\n",
32414809b6cSAnton Vorontsov 			fdt_strerror(err));
32514809b6cSAnton Vorontsov 		return;
32614809b6cSAnton Vorontsov 	}
32714809b6cSAnton Vorontsov }
3287f52ed5eSAnton Vorontsov 
3297f52ed5eSAnton Vorontsov /*
3307f52ed5eSAnton Vorontsov  * Because of an erratum in prototype boards it is impossible to use eSDHC
3317f52ed5eSAnton Vorontsov  * without disabling UART0 (which makes it quite easy to 'brick' the board
3327f52ed5eSAnton Vorontsov  * by simply issung 'setenv hwconfig esdhc', and not able to interact with
3337f52ed5eSAnton Vorontsov  * U-Boot anylonger).
3347f52ed5eSAnton Vorontsov  *
3357f52ed5eSAnton Vorontsov  * So, but default we assume that the board is a prototype, which is a most
3367f52ed5eSAnton Vorontsov  * safe assumption. There is no way to determine board revision from a
3377f52ed5eSAnton Vorontsov  * register, so we use hwconfig.
3387f52ed5eSAnton Vorontsov  */
3397f52ed5eSAnton Vorontsov 
prototype_board(void)3407f52ed5eSAnton Vorontsov static int prototype_board(void)
3417f52ed5eSAnton Vorontsov {
3427f52ed5eSAnton Vorontsov 	if (hwconfig_subarg("board", "rev", NULL))
3437f52ed5eSAnton Vorontsov 		return hwconfig_subarg_cmp("board", "rev", "prototype");
3447f52ed5eSAnton Vorontsov 	return 1;
3457f52ed5eSAnton Vorontsov }
3467f52ed5eSAnton Vorontsov 
esdhc_disables_uart0(void)3477f52ed5eSAnton Vorontsov static int esdhc_disables_uart0(void)
3487f52ed5eSAnton Vorontsov {
3497f52ed5eSAnton Vorontsov 	return prototype_board() ||
3507f52ed5eSAnton Vorontsov 	       hwconfig_subarg_cmp("esdhc", "mode", "4-bits");
3517f52ed5eSAnton Vorontsov }
3527f52ed5eSAnton Vorontsov 
fdt_board_fixup_qe_uart(void * blob,bd_t * bd)35314809b6cSAnton Vorontsov static void fdt_board_fixup_qe_uart(void *blob, bd_t *bd)
35414809b6cSAnton Vorontsov {
35514809b6cSAnton Vorontsov 	u8 *bcsr = (u8 *)CONFIG_SYS_BCSR_BASE;
35614809b6cSAnton Vorontsov 	const char *devtype = "serial";
35714809b6cSAnton Vorontsov 	const char *compat = "ucc_uart";
35814809b6cSAnton Vorontsov 	const char *clk = "brg9";
35914809b6cSAnton Vorontsov 	u32 portnum = 0;
36014809b6cSAnton Vorontsov 	int off = -1;
36114809b6cSAnton Vorontsov 
36214809b6cSAnton Vorontsov 	if (!hwconfig("qe_uart"))
36314809b6cSAnton Vorontsov 		return;
36414809b6cSAnton Vorontsov 
36514809b6cSAnton Vorontsov 	if (hwconfig("esdhc") && esdhc_disables_uart0()) {
36614809b6cSAnton Vorontsov 		printf("QE UART: won't enable with esdhc.\n");
36714809b6cSAnton Vorontsov 		return;
36814809b6cSAnton Vorontsov 	}
36914809b6cSAnton Vorontsov 
37014809b6cSAnton Vorontsov 	fdt_board_disable_serial(blob, bd, "serial1");
37114809b6cSAnton Vorontsov 
37214809b6cSAnton Vorontsov 	while (1) {
37314809b6cSAnton Vorontsov 		const u32 *idx;
37414809b6cSAnton Vorontsov 		int len;
37514809b6cSAnton Vorontsov 
37614809b6cSAnton Vorontsov 		off = fdt_node_offset_by_compatible(blob, off, "ucc_geth");
37714809b6cSAnton Vorontsov 		if (off < 0) {
37814809b6cSAnton Vorontsov 			printf("WARNING: unable to fixup device tree for "
37914809b6cSAnton Vorontsov 				"QE UART\n");
38014809b6cSAnton Vorontsov 			return;
38114809b6cSAnton Vorontsov 		}
38214809b6cSAnton Vorontsov 
38314809b6cSAnton Vorontsov 		idx = fdt_getprop(blob, off, "cell-index", &len);
38414809b6cSAnton Vorontsov 		if (!idx || len != sizeof(*idx) || *idx != fdt32_to_cpu(2))
38514809b6cSAnton Vorontsov 			continue;
38614809b6cSAnton Vorontsov 		break;
38714809b6cSAnton Vorontsov 	}
38814809b6cSAnton Vorontsov 
38914809b6cSAnton Vorontsov 	fdt_setprop(blob, off, "device_type", devtype, strlen(devtype) + 1);
39014809b6cSAnton Vorontsov 	fdt_setprop(blob, off, "compatible", compat, strlen(compat) + 1);
39114809b6cSAnton Vorontsov 	fdt_setprop(blob, off, "tx-clock-name", clk, strlen(clk) + 1);
39214809b6cSAnton Vorontsov 	fdt_setprop(blob, off, "rx-clock-name", clk, strlen(clk) + 1);
39314809b6cSAnton Vorontsov 	fdt_setprop(blob, off, "port-number", &portnum, sizeof(portnum));
39414809b6cSAnton Vorontsov 
39514809b6cSAnton Vorontsov 	setbits_8(&bcsr[15], BCSR15_QEUART_EN);
39614809b6cSAnton Vorontsov }
39714809b6cSAnton Vorontsov 
39814809b6cSAnton Vorontsov #ifdef CONFIG_FSL_ESDHC
39914809b6cSAnton Vorontsov 
board_mmc_init(bd_t * bd)4007f52ed5eSAnton Vorontsov int board_mmc_init(bd_t *bd)
4017f52ed5eSAnton Vorontsov {
4027f52ed5eSAnton Vorontsov 	struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
4037f52ed5eSAnton Vorontsov 	u8 *bcsr = (u8 *)CONFIG_SYS_BCSR_BASE;
4047f52ed5eSAnton Vorontsov 	u8 bcsr6 = BCSR6_SD_CARD_1BIT;
4057f52ed5eSAnton Vorontsov 
4067f52ed5eSAnton Vorontsov 	if (!hwconfig("esdhc"))
4077f52ed5eSAnton Vorontsov 		return 0;
4087f52ed5eSAnton Vorontsov 
4097f52ed5eSAnton Vorontsov 	printf("Enabling eSDHC...\n"
4107f52ed5eSAnton Vorontsov 	       "  For eSDHC to function, I2C2 ");
4117f52ed5eSAnton Vorontsov 	if (esdhc_disables_uart0()) {
4127f52ed5eSAnton Vorontsov 		printf("and UART0 should be disabled.\n");
4137f52ed5eSAnton Vorontsov 		printf("  Redirecting stderr, stdout and stdin to UART1...\n");
4147f52ed5eSAnton Vorontsov 		console_assign(stderr, "eserial1");
4157f52ed5eSAnton Vorontsov 		console_assign(stdout, "eserial1");
4167f52ed5eSAnton Vorontsov 		console_assign(stdin, "eserial1");
4177f52ed5eSAnton Vorontsov 		printf("Switched to UART1 (initial log has been printed to "
4187f52ed5eSAnton Vorontsov 		       "UART0).\n");
419c4ca10f1SAnton Vorontsov 
420c4ca10f1SAnton Vorontsov 		clrsetbits_be32(&gur->plppar1, PLPPAR1_UART0_BIT_MASK,
421c4ca10f1SAnton Vorontsov 					       PLPPAR1_ESDHC_4BITS_VAL);
422c4ca10f1SAnton Vorontsov 		clrsetbits_be32(&gur->plpdir1, PLPDIR1_UART0_BIT_MASK,
423c4ca10f1SAnton Vorontsov 					       PLPDIR1_ESDHC_4BITS_VAL);
4247f52ed5eSAnton Vorontsov 		bcsr6 |= BCSR6_SD_CARD_4BITS;
4257f52ed5eSAnton Vorontsov 	} else {
4267f52ed5eSAnton Vorontsov 		printf("should be disabled.\n");
4277f52ed5eSAnton Vorontsov 	}
4287f52ed5eSAnton Vorontsov 
4297f52ed5eSAnton Vorontsov 	/* Assign I2C2 signals to eSDHC. */
4307f52ed5eSAnton Vorontsov 	clrsetbits_be32(&gur->plppar1, PLPPAR1_I2C_BIT_MASK,
4317f52ed5eSAnton Vorontsov 				       PLPPAR1_ESDHC_VAL);
4327f52ed5eSAnton Vorontsov 	clrsetbits_be32(&gur->plpdir1, PLPDIR1_I2C_BIT_MASK,
4337f52ed5eSAnton Vorontsov 				       PLPDIR1_ESDHC_VAL);
4347f52ed5eSAnton Vorontsov 
4357f52ed5eSAnton Vorontsov 	/* Mux I2C2 (and optionally UART0) signals to eSDHC. */
4367f52ed5eSAnton Vorontsov 	setbits_8(&bcsr[6], bcsr6);
4377f52ed5eSAnton Vorontsov 
4387f52ed5eSAnton Vorontsov 	return fsl_esdhc_mmc_init(bd);
4397f52ed5eSAnton Vorontsov }
4407f52ed5eSAnton Vorontsov 
fdt_board_fixup_esdhc(void * blob,bd_t * bd)4417f52ed5eSAnton Vorontsov static void fdt_board_fixup_esdhc(void *blob, bd_t *bd)
4427f52ed5eSAnton Vorontsov {
4437f52ed5eSAnton Vorontsov 	const char *status = "disabled";
44414809b6cSAnton Vorontsov 	int off = -1;
4457f52ed5eSAnton Vorontsov 
4467f52ed5eSAnton Vorontsov 	if (!hwconfig("esdhc"))
4477f52ed5eSAnton Vorontsov 		return;
4487f52ed5eSAnton Vorontsov 
44914809b6cSAnton Vorontsov 	if (esdhc_disables_uart0())
45014809b6cSAnton Vorontsov 		fdt_board_disable_serial(blob, bd, "serial0");
4517f52ed5eSAnton Vorontsov 
4527f52ed5eSAnton Vorontsov 	while (1) {
4537f52ed5eSAnton Vorontsov 		const u32 *idx;
4547f52ed5eSAnton Vorontsov 		int len;
4557f52ed5eSAnton Vorontsov 
4567f52ed5eSAnton Vorontsov 		off = fdt_node_offset_by_compatible(blob, off, "fsl-i2c");
4577f52ed5eSAnton Vorontsov 		if (off < 0)
4587f52ed5eSAnton Vorontsov 			break;
4597f52ed5eSAnton Vorontsov 
4607f52ed5eSAnton Vorontsov 		idx = fdt_getprop(blob, off, "cell-index", &len);
4617f52ed5eSAnton Vorontsov 		if (!idx || len != sizeof(*idx))
4627f52ed5eSAnton Vorontsov 			continue;
4637f52ed5eSAnton Vorontsov 
4647f52ed5eSAnton Vorontsov 		if (*idx == 1) {
4657f52ed5eSAnton Vorontsov 			fdt_setprop(blob, off, "status", status,
4667f52ed5eSAnton Vorontsov 				    strlen(status) + 1);
4677f52ed5eSAnton Vorontsov 			break;
4687f52ed5eSAnton Vorontsov 		}
4697f52ed5eSAnton Vorontsov 	}
470c4ca10f1SAnton Vorontsov 
471c4ca10f1SAnton Vorontsov 	if (hwconfig_subarg_cmp("esdhc", "mode", "4-bits")) {
472c4ca10f1SAnton Vorontsov 		off = fdt_node_offset_by_compatible(blob, -1, "fsl,esdhc");
473c4ca10f1SAnton Vorontsov 		if (off < 0) {
474c4ca10f1SAnton Vorontsov 			printf("WARNING: could not find esdhc node\n");
475c4ca10f1SAnton Vorontsov 			return;
476c4ca10f1SAnton Vorontsov 		}
477c4ca10f1SAnton Vorontsov 		fdt_delprop(blob, off, "sdhci,1-bit-only");
478c4ca10f1SAnton Vorontsov 	}
4797f52ed5eSAnton Vorontsov }
4807f52ed5eSAnton Vorontsov #else
fdt_board_fixup_esdhc(void * blob,bd_t * bd)4817f52ed5eSAnton Vorontsov static inline void fdt_board_fixup_esdhc(void *blob, bd_t *bd) {}
4827f52ed5eSAnton Vorontsov #endif
4837f52ed5eSAnton Vorontsov 
fdt_board_fixup_qe_usb(void * blob,bd_t * bd)4843fca8037SAnton Vorontsov static void fdt_board_fixup_qe_usb(void *blob, bd_t *bd)
4853fca8037SAnton Vorontsov {
4863fca8037SAnton Vorontsov 	u8 *bcsr = (u8 *)CONFIG_SYS_BCSR_BASE;
4873fca8037SAnton Vorontsov 
4883fca8037SAnton Vorontsov 	if (hwconfig_subarg_cmp("qe_usb", "speed", "low"))
4893fca8037SAnton Vorontsov 		clrbits_8(&bcsr[17], BCSR17_nUSBLOWSPD);
4903fca8037SAnton Vorontsov 	else
4913fca8037SAnton Vorontsov 		setbits_8(&bcsr[17], BCSR17_nUSBLOWSPD);
4923fca8037SAnton Vorontsov 
4933fca8037SAnton Vorontsov 	if (hwconfig_subarg_cmp("qe_usb", "mode", "peripheral")) {
4943fca8037SAnton Vorontsov 		clrbits_8(&bcsr[17], BCSR17_USBVCC);
4953fca8037SAnton Vorontsov 		clrbits_8(&bcsr[17], BCSR17_USBMODE);
4963fca8037SAnton Vorontsov 		do_fixup_by_compat(blob, "fsl,mpc8569-qe-usb", "mode",
4973fca8037SAnton Vorontsov 				   "peripheral", sizeof("peripheral"), 1);
4983fca8037SAnton Vorontsov 	} else {
4993fca8037SAnton Vorontsov 		setbits_8(&bcsr[17], BCSR17_USBVCC);
5003fca8037SAnton Vorontsov 		setbits_8(&bcsr[17], BCSR17_USBMODE);
5013fca8037SAnton Vorontsov 	}
5023fca8037SAnton Vorontsov 
5033fca8037SAnton Vorontsov 	clrbits_8(&bcsr[17], BCSR17_nUSBEN);
5043fca8037SAnton Vorontsov }
5053fca8037SAnton Vorontsov 
506765547dcSHaiying Wang #ifdef CONFIG_PCI
pci_init_board(void)507c847e98bSKumar Gala void pci_init_board(void)
508765547dcSHaiying Wang {
509d9180382SLiu Yu #if defined(CONFIG_PQ_MDS_PIB)
510d9180382SLiu Yu 	pib_init();
511d9180382SLiu Yu #endif
512d9180382SLiu Yu 
51394f2bc48SKumar Gala 	fsl_pcie_init_board(0);
514765547dcSHaiying Wang }
515765547dcSHaiying Wang #endif /* CONFIG_PCI */
516765547dcSHaiying Wang 
517765547dcSHaiying Wang #if defined(CONFIG_OF_BOARD_SETUP)
ft_board_setup(void * blob,bd_t * bd)518e895a4b0SSimon Glass int ft_board_setup(void *blob, bd_t *bd)
519765547dcSHaiying Wang {
520f82107f6SHaiying Wang #if defined(CONFIG_SYS_UCC_RMII_MODE)
521f82107f6SHaiying Wang 	int nodeoff, off, err;
522f82107f6SHaiying Wang 	unsigned int val;
523f82107f6SHaiying Wang 	const u32 *ph;
524f82107f6SHaiying Wang 	const u32 *index;
525f82107f6SHaiying Wang 
526f82107f6SHaiying Wang 	/* fixup device tree for supporting rmii mode */
527f82107f6SHaiying Wang 	nodeoff = -1;
528f82107f6SHaiying Wang 	while ((nodeoff = fdt_node_offset_by_compatible(blob, nodeoff,
529f82107f6SHaiying Wang 				"ucc_geth")) >= 0) {
530f82107f6SHaiying Wang 		err = fdt_setprop_string(blob, nodeoff, "tx-clock-name",
531f82107f6SHaiying Wang 						"clk16");
532f82107f6SHaiying Wang 		if (err < 0) {
533f82107f6SHaiying Wang 			printf("WARNING: could not set tx-clock-name %s.\n",
534f82107f6SHaiying Wang 				fdt_strerror(err));
535f82107f6SHaiying Wang 			break;
536f82107f6SHaiying Wang 		}
537f82107f6SHaiying Wang 
538865ff856SAndy Fleming 		err = fdt_fixup_phy_connection(blob, nodeoff,
539865ff856SAndy Fleming 				PHY_INTERFACE_MODE_RMII);
540a1964ea5SKumar Gala 
541f82107f6SHaiying Wang 		if (err < 0) {
542f82107f6SHaiying Wang 			printf("WARNING: could not set phy-connection-type "
543f82107f6SHaiying Wang 				"%s.\n", fdt_strerror(err));
544f82107f6SHaiying Wang 			break;
545f82107f6SHaiying Wang 		}
546f82107f6SHaiying Wang 
547f82107f6SHaiying Wang 		index = fdt_getprop(blob, nodeoff, "cell-index", 0);
548f82107f6SHaiying Wang 		if (index == NULL) {
549f82107f6SHaiying Wang 			printf("WARNING: could not get cell-index of ucc\n");
550f82107f6SHaiying Wang 			break;
551f82107f6SHaiying Wang 		}
552f82107f6SHaiying Wang 
553f82107f6SHaiying Wang 		ph = fdt_getprop(blob, nodeoff, "phy-handle", 0);
554f82107f6SHaiying Wang 		if (ph == NULL) {
555f82107f6SHaiying Wang 			printf("WARNING: could not get phy-handle of ucc\n");
556f82107f6SHaiying Wang 			break;
557f82107f6SHaiying Wang 		}
558f82107f6SHaiying Wang 
559f82107f6SHaiying Wang 		off = fdt_node_offset_by_phandle(blob, *ph);
560f82107f6SHaiying Wang 		if (off < 0) {
561f82107f6SHaiying Wang 			printf("WARNING: could not get phy node	%s.\n",
562f82107f6SHaiying Wang 				fdt_strerror(err));
563f82107f6SHaiying Wang 			break;
564f82107f6SHaiying Wang 		}
565f82107f6SHaiying Wang 
566f82107f6SHaiying Wang 		val = 0x7 + *index; /* RMII phy address starts from 0x8 */
567f82107f6SHaiying Wang 
568f82107f6SHaiying Wang 		err = fdt_setprop(blob, off, "reg", &val, sizeof(u32));
569f82107f6SHaiying Wang 		if (err < 0) {
570f82107f6SHaiying Wang 			printf("WARNING: could not set reg for phy-handle "
571f82107f6SHaiying Wang 				"%s.\n", fdt_strerror(err));
572f82107f6SHaiying Wang 			break;
573f82107f6SHaiying Wang 		}
574f82107f6SHaiying Wang 	}
575f82107f6SHaiying Wang #endif
576765547dcSHaiying Wang 	ft_cpu_setup(blob, bd);
577765547dcSHaiying Wang 
5786525d51fSKumar Gala 	FT_FSL_PCI_SETUP;
5796525d51fSKumar Gala 
5807f52ed5eSAnton Vorontsov 	fdt_board_fixup_esdhc(blob, bd);
58114809b6cSAnton Vorontsov 	fdt_board_fixup_qe_uart(blob, bd);
5823fca8037SAnton Vorontsov 	fdt_board_fixup_qe_usb(blob, bd);
583e895a4b0SSimon Glass 
584e895a4b0SSimon Glass 	return 0;
585765547dcSHaiying Wang }
586765547dcSHaiying Wang #endif
587