blob: 1d2cffbacdf53ac0d59f60a5a3da6621b5e2a6d1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Haiying Wangbd255372009-03-27 17:02:45 -04002/*
Kumar Galad0f27d32010-07-08 22:37:44 -05003 * Copyright 2009-2010 Freescale Semiconductor.
Haiying Wangbd255372009-03-27 17:02:45 -04004 *
5 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
Haiying Wangbd255372009-03-27 17:02:45 -04006 */
7
8#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -07009#include <console.h>
Simon Glass8e201882020-05-10 11:39:54 -060010#include <flash.h>
Anton Vorontsovda225942009-10-15 17:47:06 +040011#include <hwconfig.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Haiying Wangbd255372009-03-27 17:02:45 -040014#include <pci.h>
15#include <asm/processor.h>
16#include <asm/mmu.h>
Haiying Wangfac23852010-09-29 13:31:35 -040017#include <asm/cache.h>
Haiying Wangbd255372009-03-27 17:02:45 -040018#include <asm/immap_85xx.h>
Kumar Gala9bbd6432009-04-02 13:22:48 -050019#include <asm/fsl_pci.h>
York Sunf0626592013-09-30 09:22:09 -070020#include <fsl_ddr_sdram.h>
Kumar Gala3d020382010-12-15 04:55:20 -060021#include <asm/fsl_serdes.h>
Haiying Wangbd255372009-03-27 17:02:45 -040022#include <asm/io.h>
23#include <spd_sdram.h>
24#include <i2c.h>
25#include <ioports.h>
Simon Glassdbd79542020-05-10 11:40:11 -060026#include <linux/delay.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090027#include <linux/libfdt.h>
Haiying Wangbd255372009-03-27 17:02:45 -040028#include <fdt_support.h>
Anton Vorontsovda225942009-10-15 17:47:06 +040029#include <fsl_esdhc.h>
Andy Fleming7832a462011-04-13 00:37:12 -050030#include <phy.h>
Haiying Wangbd255372009-03-27 17:02:45 -040031
32#include "bcsr.h"
Liu Yuc39aa4f2009-11-27 15:31:51 +080033#if defined(CONFIG_PQ_MDS_PIB)
34#include "../common/pq-mds-pib.h"
35#endif
Haiying Wangbd255372009-03-27 17:02:45 -040036
Haiying Wangbd255372009-03-27 17:02:45 -040037const qe_iop_conf_t qe_iop_conf_tab[] = {
38 /* QE_MUX_MDC */
39 {2, 31, 1, 0, 1}, /* QE_MUX_MDC */
40
41 /* QE_MUX_MDIO */
42 {2, 30, 3, 0, 2}, /* QE_MUX_MDIO */
43
Haiying Wangbc759ee2009-05-20 12:30:37 -040044#if defined(CONFIG_SYS_UCC_RGMII_MODE)
Haiying Wangbd255372009-03-27 17:02:45 -040045 /* UCC_1_RGMII */
46 {2, 11, 2, 0, 1}, /* CLK12 */
47 {0, 0, 1, 0, 3}, /* ENET1_TXD0_SER1_TXD0 */
48 {0, 1, 1, 0, 3}, /* ENET1_TXD1_SER1_TXD1 */
49 {0, 2, 1, 0, 1}, /* ENET1_TXD2_SER1_TXD2 */
50 {0, 3, 1, 0, 2}, /* ENET1_TXD3_SER1_TXD3 */
51 {0, 6, 2, 0, 3}, /* ENET1_RXD0_SER1_RXD0 */
52 {0, 7, 2, 0, 1}, /* ENET1_RXD1_SER1_RXD1 */
53 {0, 8, 2, 0, 2}, /* ENET1_RXD2_SER1_RXD2 */
54 {0, 9, 2, 0, 2}, /* ENET1_RXD3_SER1_RXD3 */
55 {0, 4, 1, 0, 2}, /* ENET1_TX_EN_SER1_RTS_B */
56 {0, 12, 2, 0, 3}, /* ENET1_RX_DV_SER1_CTS_B */
57 {2, 8, 2, 0, 1}, /* ENET1_GRXCLK */
58 {2, 20, 1, 0, 2}, /* ENET1_GTXCLK */
59
60 /* UCC_2_RGMII */
61 {2, 16, 2, 0, 3}, /* CLK17 */
62 {0, 14, 1, 0, 2}, /* ENET2_TXD0_SER2_TXD0 */
63 {0, 15, 1, 0, 2}, /* ENET2_TXD1_SER2_TXD1 */
64 {0, 16, 1, 0, 1}, /* ENET2_TXD2_SER2_TXD2 */
65 {0, 17, 1, 0, 1}, /* ENET2_TXD3_SER2_TXD3 */
66 {0, 20, 2, 0, 2}, /* ENET2_RXD0_SER2_RXD0 */
67 {0, 21, 2, 0, 1}, /* ENET2_RXD1_SER2_RXD1 */
68 {0, 22, 2, 0, 1}, /* ENET2_RXD2_SER2_RXD2 */
69 {0, 23, 2, 0, 1}, /* ENET2_RXD3_SER2_RXD3 */
70 {0, 18, 1, 0, 2}, /* ENET2_TX_EN_SER2_RTS_B */
71 {0, 26, 2, 0, 3}, /* ENET2_RX_DV_SER2_CTS_B */
72 {2, 3, 2, 0, 1}, /* ENET2_GRXCLK */
73 {2, 2, 1, 0, 2}, /* ENET2_GTXCLK */
74
Haiying Wangdf1bbbd2009-05-20 12:30:36 -040075 /* UCC_3_RGMII */
76 {2, 11, 2, 0, 1}, /* CLK12 */
77 {0, 29, 1, 0, 2}, /* ENET3_TXD0_SER3_TXD0 */
78 {0, 30, 1, 0, 3}, /* ENET3_TXD1_SER3_TXD1 */
79 {0, 31, 1, 0, 2}, /* ENET3_TXD2_SER3_TXD2 */
80 {1, 0, 1, 0, 3}, /* ENET3_TXD3_SER3_TXD3 */
81 {1, 3, 2, 0, 3}, /* ENET3_RXD0_SER3_RXD0 */
82 {1, 4, 2, 0, 1}, /* ENET3_RXD1_SER3_RXD1 */
83 {1, 5, 2, 0, 2}, /* ENET3_RXD2_SER3_RXD2 */
84 {1, 6, 2, 0, 3}, /* ENET3_RXD3_SER3_RXD3 */
85 {1, 1, 1, 0, 1}, /* ENET3_TX_EN_SER3_RTS_B */
86 {1, 9, 2, 0, 3}, /* ENET3_RX_DV_SER3_CTS_B */
87 {2, 9, 2, 0, 2}, /* ENET3_GRXCLK */
88 {2, 25, 1, 0, 2}, /* ENET3_GTXCLK */
89
90 /* UCC_4_RGMII */
91 {2, 16, 2, 0, 3}, /* CLK17 */
92 {1, 12, 1, 0, 2}, /* ENET4_TXD0_SER4_TXD0 */
93 {1, 13, 1, 0, 2}, /* ENET4_TXD1_SER4_TXD1 */
94 {1, 14, 1, 0, 1}, /* ENET4_TXD2_SER4_TXD2 */
95 {1, 15, 1, 0, 2}, /* ENET4_TXD3_SER4_TXD3 */
96 {1, 18, 2, 0, 2}, /* ENET4_RXD0_SER4_RXD0 */
97 {1, 19, 2, 0, 1}, /* ENET4_RXD1_SER4_RXD1 */
98 {1, 20, 2, 0, 1}, /* ENET4_RXD2_SER4_RXD2 */
99 {1, 21, 2, 0, 2}, /* ENET4_RXD3_SER4_RXD3 */
100 {1, 16, 1, 0, 2}, /* ENET4_TX_EN_SER4_RTS_B */
101 {1, 24, 2, 0, 3}, /* ENET4_RX_DV_SER4_CTS_B */
102 {2, 17, 2, 0, 2}, /* ENET4_GRXCLK */
103 {2, 24, 1, 0, 2}, /* ENET4_GTXCLK */
104
Haiying Wangbc759ee2009-05-20 12:30:37 -0400105#elif defined(CONFIG_SYS_UCC_RMII_MODE)
106 /* UCC_1_RMII */
107 {2, 15, 2, 0, 1}, /* CLK16 */
108 {0, 0, 1, 0, 3}, /* ENET1_TXD0_SER1_TXD0 */
109 {0, 1, 1, 0, 3}, /* ENET1_TXD1_SER1_TXD1 */
110 {0, 6, 2, 0, 3}, /* ENET1_RXD0_SER1_RXD0 */
111 {0, 7, 2, 0, 1}, /* ENET1_RXD1_SER1_RXD1 */
112 {0, 4, 1, 0, 2}, /* ENET1_TX_EN_SER1_RTS_B */
113 {0, 12, 2, 0, 3}, /* ENET1_RX_DV_SER1_CTS_B */
114
115 /* UCC_2_RMII */
116 {2, 15, 2, 0, 1}, /* CLK16 */
117 {0, 14, 1, 0, 2}, /* ENET2_TXD0_SER2_TXD0 */
118 {0, 15, 1, 0, 2}, /* ENET2_TXD1_SER2_TXD1 */
119 {0, 20, 2, 0, 2}, /* ENET2_RXD0_SER2_RXD0 */
120 {0, 21, 2, 0, 1}, /* ENET2_RXD1_SER2_RXD1 */
121 {0, 18, 1, 0, 2}, /* ENET2_TX_EN_SER2_RTS_B */
122 {0, 26, 2, 0, 3}, /* ENET2_RX_DV_SER2_CTS_B */
123
124 /* UCC_3_RMII */
125 {2, 15, 2, 0, 1}, /* CLK16 */
126 {0, 29, 1, 0, 2}, /* ENET3_TXD0_SER3_TXD0 */
127 {0, 30, 1, 0, 3}, /* ENET3_TXD1_SER3_TXD1 */
128 {1, 3, 2, 0, 3}, /* ENET3_RXD0_SER3_RXD0 */
129 {1, 4, 2, 0, 1}, /* ENET3_RXD1_SER3_RXD1 */
130 {1, 1, 1, 0, 1}, /* ENET3_TX_EN_SER3_RTS_B */
131 {1, 9, 2, 0, 3}, /* ENET3_RX_DV_SER3_CTS_B */
132
133 /* UCC_4_RMII */
134 {2, 15, 2, 0, 1}, /* CLK16 */
135 {1, 12, 1, 0, 2}, /* ENET4_TXD0_SER4_TXD0 */
136 {1, 13, 1, 0, 2}, /* ENET4_TXD1_SER4_TXD1 */
137 {1, 18, 2, 0, 2}, /* ENET4_RXD0_SER4_RXD0 */
138 {1, 19, 2, 0, 1}, /* ENET4_RXD1_SER4_RXD1 */
139 {1, 16, 1, 0, 2}, /* ENET4_TX_EN_SER4_RTS_B */
140 {1, 24, 2, 0, 3}, /* ENET4_RX_DV_SER4_CTS_B */
141#endif
142
Haiying Wang32250bf2009-05-20 12:30:33 -0400143 /* UART1 is muxed with QE PortF bit [9-12].*/
144 {5, 12, 2, 0, 3}, /* UART1_SIN */
145 {5, 9, 1, 0, 3}, /* UART1_SOUT */
146 {5, 10, 2, 0, 3}, /* UART1_CTS_B */
147 {5, 11, 1, 0, 2}, /* UART1_RTS_B */
148
Anton Vorontsov0a154a02009-10-15 17:47:13 +0400149 /* QE UART */
150 {0, 19, 1, 0, 2}, /* QEUART_TX */
151 {1, 17, 2, 0, 3}, /* QEUART_RX */
152 {0, 25, 1, 0, 1}, /* QEUART_RTS */
153 {1, 23, 2, 0, 1}, /* QEUART_CTS */
154
Anton Vorontsovd8e75822009-10-15 17:47:16 +0400155 /* QE USB */
156 {5, 3, 1, 0, 1}, /* USB_OE */
157 {5, 4, 1, 0, 2}, /* USB_TP */
158 {5, 5, 1, 0, 2}, /* USB_TN */
159 {5, 6, 2, 0, 2}, /* USB_RP */
160 {5, 7, 2, 0, 1}, /* USB_RX */
161 {5, 8, 2, 0, 1}, /* USB_RN */
162 {2, 4, 2, 0, 2}, /* CLK5 */
163
Anton Vorontsovb1f075e2009-10-15 17:47:11 +0400164 /* SPI Flash, M25P40 */
165 {4, 27, 3, 0, 1}, /* SPI_MOSI */
166 {4, 28, 3, 0, 1}, /* SPI_MISO */
167 {4, 29, 3, 0, 1}, /* SPI_CLK */
168 {4, 30, 1, 0, 0}, /* SPI_SEL, GPIO */
169
Haiying Wangbd255372009-03-27 17:02:45 -0400170 {0, 0, 0, 0, QE_IOP_TAB_END} /* END of table */
171};
172
173void local_bus_init(void);
174
175int board_early_init_f (void)
176{
177 /*
178 * Initialize local bus.
179 */
180 local_bus_init ();
181
182 enable_8569mds_flash_write();
183
184#ifdef CONFIG_QE
Haiying Wangbc759ee2009-05-20 12:30:37 -0400185 enable_8569mds_qe_uec();
Haiying Wangbd255372009-03-27 17:02:45 -0400186#endif
187
188#if CONFIG_SYS_I2C2_OFFSET
189 /* Enable I2C2 signals instead of SD signals */
190 volatile struct ccsr_gur *gur;
191 gur = (struct ccsr_gur *)(CONFIG_SYS_IMMR + 0xe0000);
192 gur->plppar1 &= ~PLPPAR1_I2C_BIT_MASK;
193 gur->plppar1 |= PLPPAR1_I2C2_VAL;
194 gur->plpdir1 &= ~PLPDIR1_I2C_BIT_MASK;
195 gur->plpdir1 |= PLPDIR1_I2C2_VAL;
196
197 disable_8569mds_brd_eeprom_write_protect();
198#endif
199
200 return 0;
201}
202
Haiying Wangfac23852010-09-29 13:31:35 -0400203int board_early_init_r(void)
204{
205 const unsigned int flashbase = CONFIG_SYS_NAND_BASE;
206 const u8 flash_esel = 0;
207
208 /*
209 * Remap Boot flash to caching-inhibited
210 * so that flash can be erased properly.
211 */
212
213 /* Flush d-cache and invalidate i-cache of any FLASH data */
214 flush_dcache();
215 invalidate_icache();
216
217 /* invalidate existing TLB entry for flash */
218 disable_tlb(flash_esel);
219
220 set_tlb(1, flashbase, CONFIG_SYS_NAND_BASE, /* tlb, epn, rpn */
221 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
222 0, flash_esel, /* ts, esel */
223 BOOKE_PAGESZ_64M, 1); /* tsize, iprot */
224
225 return 0;
226}
227
Haiying Wangbd255372009-03-27 17:02:45 -0400228int checkboard (void)
229{
230 printf ("Board: 8569 MDS\n");
231
232 return 0;
233}
234
Haiying Wangbd255372009-03-27 17:02:45 -0400235#if !defined(CONFIG_SPD_EEPROM)
236phys_size_t fixed_sdram(void)
237{
York Suna21803d2013-11-18 10:29:32 -0800238 struct ccsr_ddr __iomem *ddr =
239 (struct ccsr_ddr __iomem *)CONFIG_SYS_FSL_DDR_ADDR;
Haiying Wangbd255372009-03-27 17:02:45 -0400240 uint d_init;
241
242 out_be32(&ddr->cs0_bnds, CONFIG_SYS_DDR_CS0_BNDS);
243 out_be32(&ddr->cs0_config, CONFIG_SYS_DDR_CS0_CONFIG);
244 out_be32(&ddr->timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
245 out_be32(&ddr->timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
246 out_be32(&ddr->timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
247 out_be32(&ddr->timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
248 out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
249 out_be32(&ddr->sdram_cfg_2, CONFIG_SYS_DDR_SDRAM_CFG_2);
250 out_be32(&ddr->sdram_mode, CONFIG_SYS_DDR_SDRAM_MODE);
251 out_be32(&ddr->sdram_mode_2, CONFIG_SYS_DDR_SDRAM_MODE_2);
252 out_be32(&ddr->sdram_interval, CONFIG_SYS_DDR_SDRAM_INTERVAL);
253 out_be32(&ddr->sdram_data_init, CONFIG_SYS_DDR_DATA_INIT);
254 out_be32(&ddr->sdram_clk_cntl, CONFIG_SYS_DDR_SDRAM_CLK_CNTL);
255 out_be32(&ddr->timing_cfg_4, CONFIG_SYS_DDR_TIMING_4);
256 out_be32(&ddr->timing_cfg_5, CONFIG_SYS_DDR_TIMING_5);
257 out_be32(&ddr->ddr_zq_cntl, CONFIG_SYS_DDR_ZQ_CNTL);
258 out_be32(&ddr->ddr_wrlvl_cntl, CONFIG_SYS_DDR_WRLVL_CNTL);
259 out_be32(&ddr->sdram_cfg_2, CONFIG_SYS_DDR_SDRAM_CFG_2);
260#if defined (CONFIG_DDR_ECC)
261 out_be32(&ddr->err_int_en, CONFIG_SYS_DDR_ERR_INT_EN);
262 out_be32(&ddr->err_disable, CONFIG_SYS_DDR_ERR_DIS);
263 out_be32(&ddr->err_sbe, CONFIG_SYS_DDR_SBE);
264#endif
265 udelay(500);
266
267 out_be32(&ddr->sdram_cfg, CONFIG_SYS_DDR_CONTROL);
268#if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
269 d_init = 1;
270 debug("DDR - 1st controller: memory initializing\n");
271 /*
272 * Poll until memory is initialized.
273 * 512 Meg at 400 might hit this 200 times or so.
274 */
275 while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) {
276 udelay(1000);
277 }
278 debug("DDR: memory initialized\n\n");
279 udelay(500);
280#endif
281 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
282}
283#endif
284
285/*
286 * Initialize Local Bus
287 */
288void
289local_bus_init(void)
290{
291 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Becky Bruce0d4cee12010-06-17 11:37:20 -0500292 volatile fsl_lbc_t *lbc = LBC_BASE_ADDR;
Haiying Wangbd255372009-03-27 17:02:45 -0400293
294 uint clkdiv;
Haiying Wangbd255372009-03-27 17:02:45 -0400295 sys_info_t sysinfo;
296
297 get_sys_info(&sysinfo);
298 clkdiv = (lbc->lcrr & LCRR_CLKDIV) * 2;
Haiying Wangbd255372009-03-27 17:02:45 -0400299
300 out_be32(&gur->lbiuiplldcr1, 0x00078080);
301 if (clkdiv == 16)
302 out_be32(&gur->lbiuiplldcr0, 0x7c0f1bf0);
303 else if (clkdiv == 8)
304 out_be32(&gur->lbiuiplldcr0, 0x6c0f1bf0);
305 else if (clkdiv == 4)
306 out_be32(&gur->lbiuiplldcr0, 0x5c0f1bf0);
307
308 out_be32(&lbc->lcrr, (u32)in_be32(&lbc->lcrr)| 0x00030000);
309}
310
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900311static void fdt_board_disable_serial(void *blob, struct bd_info *bd,
312 const char *alias)
Anton Vorontsov0a154a02009-10-15 17:47:13 +0400313{
314 const char *status = "disabled";
315 int off;
316 int err;
317
318 off = fdt_path_offset(blob, alias);
319 if (off < 0) {
320 printf("WARNING: could not find %s alias: %s.\n", alias,
321 fdt_strerror(off));
322 return;
323 }
324
325 err = fdt_setprop(blob, off, "status", status, strlen(status) + 1);
326 if (err) {
327 printf("WARNING: could not set status for serial0: %s.\n",
328 fdt_strerror(err));
329 return;
330 }
331}
Anton Vorontsovda225942009-10-15 17:47:06 +0400332
333/*
334 * Because of an erratum in prototype boards it is impossible to use eSDHC
335 * without disabling UART0 (which makes it quite easy to 'brick' the board
336 * by simply issung 'setenv hwconfig esdhc', and not able to interact with
337 * U-Boot anylonger).
338 *
339 * So, but default we assume that the board is a prototype, which is a most
340 * safe assumption. There is no way to determine board revision from a
341 * register, so we use hwconfig.
342 */
343
344static int prototype_board(void)
345{
346 if (hwconfig_subarg("board", "rev", NULL))
347 return hwconfig_subarg_cmp("board", "rev", "prototype");
348 return 1;
349}
350
351static int esdhc_disables_uart0(void)
352{
353 return prototype_board() ||
354 hwconfig_subarg_cmp("esdhc", "mode", "4-bits");
355}
356
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900357static void fdt_board_fixup_qe_uart(void *blob, struct bd_info *bd)
Anton Vorontsov0a154a02009-10-15 17:47:13 +0400358{
359 u8 *bcsr = (u8 *)CONFIG_SYS_BCSR_BASE;
360 const char *devtype = "serial";
361 const char *compat = "ucc_uart";
362 const char *clk = "brg9";
363 u32 portnum = 0;
364 int off = -1;
365
366 if (!hwconfig("qe_uart"))
367 return;
368
369 if (hwconfig("esdhc") && esdhc_disables_uart0()) {
370 printf("QE UART: won't enable with esdhc.\n");
371 return;
372 }
373
374 fdt_board_disable_serial(blob, bd, "serial1");
375
376 while (1) {
377 const u32 *idx;
378 int len;
379
380 off = fdt_node_offset_by_compatible(blob, off, "ucc_geth");
381 if (off < 0) {
382 printf("WARNING: unable to fixup device tree for "
383 "QE UART\n");
384 return;
385 }
386
387 idx = fdt_getprop(blob, off, "cell-index", &len);
388 if (!idx || len != sizeof(*idx) || *idx != fdt32_to_cpu(2))
389 continue;
390 break;
391 }
392
393 fdt_setprop(blob, off, "device_type", devtype, strlen(devtype) + 1);
394 fdt_setprop(blob, off, "compatible", compat, strlen(compat) + 1);
395 fdt_setprop(blob, off, "tx-clock-name", clk, strlen(clk) + 1);
396 fdt_setprop(blob, off, "rx-clock-name", clk, strlen(clk) + 1);
397 fdt_setprop(blob, off, "port-number", &portnum, sizeof(portnum));
398
399 setbits_8(&bcsr[15], BCSR15_QEUART_EN);
400}
401
402#ifdef CONFIG_FSL_ESDHC
403
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900404int board_mmc_init(struct bd_info *bd)
Anton Vorontsovda225942009-10-15 17:47:06 +0400405{
406 struct ccsr_gur *gur = (struct ccsr_gur *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
407 u8 *bcsr = (u8 *)CONFIG_SYS_BCSR_BASE;
408 u8 bcsr6 = BCSR6_SD_CARD_1BIT;
409
410 if (!hwconfig("esdhc"))
411 return 0;
412
413 printf("Enabling eSDHC...\n"
414 " For eSDHC to function, I2C2 ");
415 if (esdhc_disables_uart0()) {
416 printf("and UART0 should be disabled.\n");
417 printf(" Redirecting stderr, stdout and stdin to UART1...\n");
418 console_assign(stderr, "eserial1");
419 console_assign(stdout, "eserial1");
420 console_assign(stdin, "eserial1");
421 printf("Switched to UART1 (initial log has been printed to "
422 "UART0).\n");
Anton Vorontsov05241172009-12-16 01:14:31 +0300423
424 clrsetbits_be32(&gur->plppar1, PLPPAR1_UART0_BIT_MASK,
425 PLPPAR1_ESDHC_4BITS_VAL);
426 clrsetbits_be32(&gur->plpdir1, PLPDIR1_UART0_BIT_MASK,
427 PLPDIR1_ESDHC_4BITS_VAL);
Anton Vorontsovda225942009-10-15 17:47:06 +0400428 bcsr6 |= BCSR6_SD_CARD_4BITS;
429 } else {
430 printf("should be disabled.\n");
431 }
432
433 /* Assign I2C2 signals to eSDHC. */
434 clrsetbits_be32(&gur->plppar1, PLPPAR1_I2C_BIT_MASK,
435 PLPPAR1_ESDHC_VAL);
436 clrsetbits_be32(&gur->plpdir1, PLPDIR1_I2C_BIT_MASK,
437 PLPDIR1_ESDHC_VAL);
438
439 /* Mux I2C2 (and optionally UART0) signals to eSDHC. */
440 setbits_8(&bcsr[6], bcsr6);
441
442 return fsl_esdhc_mmc_init(bd);
443}
444
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900445static void fdt_board_fixup_esdhc(void *blob, struct bd_info *bd)
Anton Vorontsovda225942009-10-15 17:47:06 +0400446{
447 const char *status = "disabled";
Anton Vorontsov0a154a02009-10-15 17:47:13 +0400448 int off = -1;
Anton Vorontsovda225942009-10-15 17:47:06 +0400449
450 if (!hwconfig("esdhc"))
451 return;
452
Anton Vorontsov0a154a02009-10-15 17:47:13 +0400453 if (esdhc_disables_uart0())
454 fdt_board_disable_serial(blob, bd, "serial0");
Anton Vorontsovda225942009-10-15 17:47:06 +0400455
Anton Vorontsovda225942009-10-15 17:47:06 +0400456 while (1) {
457 const u32 *idx;
458 int len;
459
460 off = fdt_node_offset_by_compatible(blob, off, "fsl-i2c");
461 if (off < 0)
462 break;
463
464 idx = fdt_getprop(blob, off, "cell-index", &len);
465 if (!idx || len != sizeof(*idx))
466 continue;
467
468 if (*idx == 1) {
469 fdt_setprop(blob, off, "status", status,
470 strlen(status) + 1);
471 break;
472 }
Anton Vorontsov05241172009-12-16 01:14:31 +0300473 }
474
475 if (hwconfig_subarg_cmp("esdhc", "mode", "4-bits")) {
476 off = fdt_node_offset_by_compatible(blob, -1, "fsl,esdhc");
477 if (off < 0) {
478 printf("WARNING: could not find esdhc node\n");
479 return;
480 }
481 fdt_delprop(blob, off, "sdhci,1-bit-only");
Anton Vorontsovda225942009-10-15 17:47:06 +0400482 }
483}
484#else
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900485static inline void fdt_board_fixup_esdhc(void *blob, struct bd_info *bd) {}
Anton Vorontsovda225942009-10-15 17:47:06 +0400486#endif
487
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900488static void fdt_board_fixup_qe_usb(void *blob, struct bd_info *bd)
Anton Vorontsovd8e75822009-10-15 17:47:16 +0400489{
490 u8 *bcsr = (u8 *)CONFIG_SYS_BCSR_BASE;
491
492 if (hwconfig_subarg_cmp("qe_usb", "speed", "low"))
493 clrbits_8(&bcsr[17], BCSR17_nUSBLOWSPD);
494 else
495 setbits_8(&bcsr[17], BCSR17_nUSBLOWSPD);
496
497 if (hwconfig_subarg_cmp("qe_usb", "mode", "peripheral")) {
498 clrbits_8(&bcsr[17], BCSR17_USBVCC);
499 clrbits_8(&bcsr[17], BCSR17_USBMODE);
500 do_fixup_by_compat(blob, "fsl,mpc8569-qe-usb", "mode",
501 "peripheral", sizeof("peripheral"), 1);
502 } else {
503 setbits_8(&bcsr[17], BCSR17_USBVCC);
504 setbits_8(&bcsr[17], BCSR17_USBMODE);
505 }
506
507 clrbits_8(&bcsr[17], BCSR17_nUSBEN);
508}
509
Haiying Wangbd255372009-03-27 17:02:45 -0400510#ifdef CONFIG_PCI
Kumar Galaf9a96032009-11-04 10:26:30 -0600511void pci_init_board(void)
Haiying Wangbd255372009-03-27 17:02:45 -0400512{
Liu Yuc39aa4f2009-11-27 15:31:51 +0800513#if defined(CONFIG_PQ_MDS_PIB)
514 pib_init();
515#endif
516
Kumar Galab999ae82010-12-17 10:18:07 -0600517 fsl_pcie_init_board(0);
Haiying Wangbd255372009-03-27 17:02:45 -0400518}
519#endif /* CONFIG_PCI */
520
521#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900522int ft_board_setup(void *blob, struct bd_info *bd)
Haiying Wangbd255372009-03-27 17:02:45 -0400523{
Haiying Wangbc759ee2009-05-20 12:30:37 -0400524#if defined(CONFIG_SYS_UCC_RMII_MODE)
525 int nodeoff, off, err;
526 unsigned int val;
527 const u32 *ph;
528 const u32 *index;
529
530 /* fixup device tree for supporting rmii mode */
531 nodeoff = -1;
532 while ((nodeoff = fdt_node_offset_by_compatible(blob, nodeoff,
533 "ucc_geth")) >= 0) {
534 err = fdt_setprop_string(blob, nodeoff, "tx-clock-name",
535 "clk16");
536 if (err < 0) {
537 printf("WARNING: could not set tx-clock-name %s.\n",
538 fdt_strerror(err));
539 break;
540 }
541
Andy Fleming7832a462011-04-13 00:37:12 -0500542 err = fdt_fixup_phy_connection(blob, nodeoff,
543 PHY_INTERFACE_MODE_RMII);
Kumar Gala6bc9fd52010-09-30 09:15:03 -0500544
Haiying Wangbc759ee2009-05-20 12:30:37 -0400545 if (err < 0) {
546 printf("WARNING: could not set phy-connection-type "
547 "%s.\n", fdt_strerror(err));
548 break;
549 }
550
551 index = fdt_getprop(blob, nodeoff, "cell-index", 0);
552 if (index == NULL) {
553 printf("WARNING: could not get cell-index of ucc\n");
554 break;
555 }
556
557 ph = fdt_getprop(blob, nodeoff, "phy-handle", 0);
558 if (ph == NULL) {
559 printf("WARNING: could not get phy-handle of ucc\n");
560 break;
561 }
562
563 off = fdt_node_offset_by_phandle(blob, *ph);
564 if (off < 0) {
565 printf("WARNING: could not get phy node %s.\n",
566 fdt_strerror(err));
567 break;
568 }
569
570 val = 0x7 + *index; /* RMII phy address starts from 0x8 */
571
572 err = fdt_setprop(blob, off, "reg", &val, sizeof(u32));
573 if (err < 0) {
574 printf("WARNING: could not set reg for phy-handle "
575 "%s.\n", fdt_strerror(err));
576 break;
577 }
578 }
579#endif
Haiying Wangbd255372009-03-27 17:02:45 -0400580 ft_cpu_setup(blob, bd);
581
Kumar Galad0f27d32010-07-08 22:37:44 -0500582 FT_FSL_PCI_SETUP;
583
Anton Vorontsovda225942009-10-15 17:47:06 +0400584 fdt_board_fixup_esdhc(blob, bd);
Anton Vorontsov0a154a02009-10-15 17:47:13 +0400585 fdt_board_fixup_qe_uart(blob, bd);
Anton Vorontsovd8e75822009-10-15 17:47:16 +0400586 fdt_board_fixup_qe_usb(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600587
588 return 0;
Haiying Wangbd255372009-03-27 17:02:45 -0400589}
590#endif