2 * Copyright (C) 2006,2010-2011 Freescale Semiconductor, Inc.
3 * Dave Liu <daveliu@freescale.com>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
20 #if defined(CONFIG_PCI)
23 #include <spd_sdram.h>
26 #include <asm/fsl_enet.h>
28 #if defined(CONFIG_OF_LIBFDT)
32 #include <fdt_support.h>
33 #if defined(CONFIG_PQ_MDS_PIB)
34 #include "../common/pq-mds-pib.h"
36 #include "../../../drivers/qe/uec.h"
38 const qe_iop_conf_t qe_iop_conf_tab[] = {
40 {0, 3, 1, 0, 1}, /* TxD0 */
41 {0, 4, 1, 0, 1}, /* TxD1 */
42 {0, 5, 1, 0, 1}, /* TxD2 */
43 {0, 6, 1, 0, 1}, /* TxD3 */
44 {1, 6, 1, 0, 3}, /* TxD4 */
45 {1, 7, 1, 0, 1}, /* TxD5 */
46 {1, 9, 1, 0, 2}, /* TxD6 */
47 {1, 10, 1, 0, 2}, /* TxD7 */
48 {0, 9, 2, 0, 1}, /* RxD0 */
49 {0, 10, 2, 0, 1}, /* RxD1 */
50 {0, 11, 2, 0, 1}, /* RxD2 */
51 {0, 12, 2, 0, 1}, /* RxD3 */
52 {0, 13, 2, 0, 1}, /* RxD4 */
53 {1, 1, 2, 0, 2}, /* RxD5 */
54 {1, 0, 2, 0, 2}, /* RxD6 */
55 {1, 4, 2, 0, 2}, /* RxD7 */
56 {0, 7, 1, 0, 1}, /* TX_EN */
57 {0, 8, 1, 0, 1}, /* TX_ER */
58 {0, 15, 2, 0, 1}, /* RX_DV */
59 {0, 16, 2, 0, 1}, /* RX_ER */
60 {0, 0, 2, 0, 1}, /* RX_CLK */
61 {2, 9, 1, 0, 3}, /* GTX_CLK - CLK10 */
62 {2, 8, 2, 0, 1}, /* GTX125 - CLK9 */
64 {0, 17, 1, 0, 1}, /* TxD0 */
65 {0, 18, 1, 0, 1}, /* TxD1 */
66 {0, 19, 1, 0, 1}, /* TxD2 */
67 {0, 20, 1, 0, 1}, /* TxD3 */
68 {1, 2, 1, 0, 1}, /* TxD4 */
69 {1, 3, 1, 0, 2}, /* TxD5 */
70 {1, 5, 1, 0, 3}, /* TxD6 */
71 {1, 8, 1, 0, 3}, /* TxD7 */
72 {0, 23, 2, 0, 1}, /* RxD0 */
73 {0, 24, 2, 0, 1}, /* RxD1 */
74 {0, 25, 2, 0, 1}, /* RxD2 */
75 {0, 26, 2, 0, 1}, /* RxD3 */
76 {0, 27, 2, 0, 1}, /* RxD4 */
77 {1, 12, 2, 0, 2}, /* RxD5 */
78 {1, 13, 2, 0, 3}, /* RxD6 */
79 {1, 11, 2, 0, 2}, /* RxD7 */
80 {0, 21, 1, 0, 1}, /* TX_EN */
81 {0, 22, 1, 0, 1}, /* TX_ER */
82 {0, 29, 2, 0, 1}, /* RX_DV */
83 {0, 30, 2, 0, 1}, /* RX_ER */
84 {0, 31, 2, 0, 1}, /* RX_CLK */
85 {2, 2, 1, 0, 2}, /* GTX_CLK = CLK10 */
86 {2, 3, 2, 0, 1}, /* GTX125 - CLK4 */
88 {0, 1, 3, 0, 2}, /* MDIO */
89 {0, 2, 1, 0, 1}, /* MDC */
91 {5, 0, 1, 0, 2}, /* UART2_SOUT */
92 {5, 1, 2, 0, 3}, /* UART2_CTS */
93 {5, 2, 1, 0, 1}, /* UART2_RTS */
94 {5, 3, 2, 0, 2}, /* UART2_SIN */
96 {0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
99 /* Handle "mpc8360ea rev.2.1 erratum 2: RGMII Timing"? */
100 static int board_handle_erratum2(void)
102 const immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
104 return REVID_MAJOR(immr->sysconf.spridr) == 2 &&
105 REVID_MINOR(immr->sysconf.spridr) == 1;
108 int board_early_init_f(void)
110 const immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
111 u8 *bcsr = (u8 *)CONFIG_SYS_BCSR;
113 /* Enable flash write */
116 /* Disable G1TXCLK, G2TXCLK h/w buffers (rev.2.x h/w bug workaround) */
117 if (REVID_MAJOR(immr->sysconf.spridr) == 2)
120 /* Enable second UART */
123 if (board_handle_erratum2()) {
124 void *immap = (immap_t *)(CONFIG_SYS_IMMR + 0x14a8);
127 * IMMR + 0x14A8[4:5] = 11 (clk delay for UCC 2)
128 * IMMR + 0x14A8[18:19] = 11 (clk delay for UCC 1)
130 setbits_be32(immap, 0x0c003000);
133 * IMMR + 0x14AC[20:27] = 10101010
134 * (data delay for both UCC's)
136 clrsetbits_be32(immap + 4, 0xff0, 0xaa0);
141 int board_early_init_r(void)
144 #ifdef CONFIG_PQ_MDS_PIB
148 * BAT6 is used for SDRAM when DDR size is 512MB or larger than 256MB
149 * So re-setup PCI MEM space used BAT5 after relocated to DDR
151 gd = (gd_t *)(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
152 if (gd->ram_size > CONFIG_MAX_MEM_MAPPED) {
153 write_bat(DBAT5, CONFIG_SYS_DBAT6U, CONFIG_SYS_DBAT6L);
154 write_bat(IBAT5, CONFIG_SYS_IBAT6U, CONFIG_SYS_IBAT6L);
160 #ifdef CONFIG_UEC_ETH
161 static uec_info_t uec_info[] = {
162 #ifdef CONFIG_UEC_ETH1
165 #ifdef CONFIG_UEC_ETH2
170 int board_eth_init(bd_t *bd)
172 if (board_handle_erratum2()) {
175 for (i = 0; i < ARRAY_SIZE(uec_info); i++)
176 uec_info[i].enet_interface_type =
177 PHY_INTERFACE_MODE_RGMII_RXID;
178 uec_info[i].speed = SPEED_1000;
180 return uec_eth_init(bd, uec_info, ARRAY_SIZE(uec_info));
182 #endif /* CONFIG_UEC_ETH */
184 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
185 extern void ddr_enable_ecc(unsigned int dram_size);
187 int fixed_sdram(void);
188 static int sdram_init(unsigned int base);
190 phys_size_t initdram(int board_type)
192 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
196 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
199 /* DDR SDRAM - Main SODIMM */
200 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
201 #if defined(CONFIG_SPD_EEPROM)
204 msize = fixed_sdram();
207 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
209 * Initialize DDR ECC byte
211 ddr_enable_ecc(msize * 1024 * 1024);
214 * Initialize SDRAM if it is on local bus.
216 lbc_sdram_size = sdram_init(msize * 1024 * 1024);
218 msize = lbc_sdram_size;
220 /* return total bus SDRAM size(bytes) -- DDR */
221 return (msize * 1024 * 1024);
224 #if !defined(CONFIG_SPD_EEPROM)
225 /*************************************************************************
226 * fixed sdram init -- doesn't use serial presence detect.
227 ************************************************************************/
228 int fixed_sdram(void)
230 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
231 u32 msize = CONFIG_SYS_DDR_SIZE;
232 u32 ddr_size = msize << 20;
233 u32 ddr_size_log2 = __ilog2(ddr_size);
234 u32 half_ddr_size = ddr_size >> 1;
236 im->sysconf.ddrlaw[0].bar =
237 CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
238 im->sysconf.ddrlaw[0].ar =
239 LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
240 #if (CONFIG_SYS_DDR_SIZE != 256)
241 #warning Currenly any ddr size other than 256 is not supported
244 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
245 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
246 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
247 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
248 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
249 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
250 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
251 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
252 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
253 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
254 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
255 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
258 #if ((CONFIG_SYS_DDR_SDRAM_BASE & 0x00FFFFFF) != 0)
259 #warning Chip select bounds is only configurable in 16MB increments
261 im->ddr.csbnds[0].csbnds =
262 ((CONFIG_SYS_DDR_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
263 (((CONFIG_SYS_DDR_SDRAM_BASE + half_ddr_size - 1) >>
264 CSBNDS_EA_SHIFT) & CSBNDS_EA);
265 im->ddr.csbnds[1].csbnds =
266 (((CONFIG_SYS_DDR_SDRAM_BASE + half_ddr_size) >>
267 CSBNDS_SA_SHIFT) & CSBNDS_SA) |
268 (((CONFIG_SYS_DDR_SDRAM_BASE + ddr_size - 1) >>
269 CSBNDS_EA_SHIFT) & CSBNDS_EA);
271 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
272 im->ddr.cs_config[1] = CONFIG_SYS_DDR_CS1_CONFIG;
274 im->ddr.cs_config[2] = 0;
275 im->ddr.cs_config[3] = 0;
277 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
278 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
279 im->ddr.sdram_cfg = CONFIG_SYS_DDR_CONTROL;
281 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
282 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
285 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
289 #endif /*!CONFIG_SYS_SPD_EEPROM */
293 puts("Board: Freescale MPC8360EMDS\n");
298 * if MPC8360EMDS is soldered with SDRAM
300 #ifdef CONFIG_SYS_LB_SDRAM
302 * Initialize SDRAM memory on the Local Bus.
305 static int sdram_init(unsigned int base)
307 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
308 fsl_lbc_t *lbc = LBC_BASE_ADDR;
309 const int sdram_size = CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024;
310 int rem = base % sdram_size;
313 /* window base address should be aligned to the window size */
315 base = base - rem + sdram_size;
318 * Setup BAT6 for SDRAM when DDR size is 512MB or larger than 256MB
319 * After relocated to DDR, reuse BAT5 for PCI MEM space
321 if (base > CONFIG_MAX_MEM_MAPPED) {
322 unsigned long batl = base | BATL_PP_10 | BATL_MEMCOHERENCE;
323 unsigned long batu = base | BATU_BL_64M | BATU_VS | BATU_VP;
325 /* Setup the BAT6 for SDRAM */
326 write_bat(DBAT6, batu, batl);
327 write_bat(IBAT6, batu, batl);
330 sdram_addr = (uint *)base;
332 * Setup SDRAM Base and Option Registers
334 set_lbc_br(2, base | CONFIG_SYS_BR2);
335 set_lbc_or(2, CONFIG_SYS_OR2);
336 immap->sysconf.lblaw[2].bar = base;
337 immap->sysconf.lblaw[2].ar = CONFIG_SYS_LBLAWAR2;
339 /*setup mtrpt, lsrt and lbcr for LB bus */
340 lbc->lbcr = CONFIG_SYS_LBC_LBCR;
341 lbc->mrtpr = CONFIG_SYS_LBC_MRTPR;
342 lbc->lsrt = CONFIG_SYS_LBC_LSRT;
346 * Configure the SDRAM controller Machine Mode Register.
348 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5; /* Normal Operation */
349 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_1; /* Precharge All Banks */
355 * We need do 8 times auto refresh operation.
357 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_2;
359 *sdram_addr = 0xff; /* 1 times */
361 *sdram_addr = 0xff; /* 2 times */
363 *sdram_addr = 0xff; /* 3 times */
365 *sdram_addr = 0xff; /* 4 times */
367 *sdram_addr = 0xff; /* 5 times */
369 *sdram_addr = 0xff; /* 6 times */
371 *sdram_addr = 0xff; /* 7 times */
373 *sdram_addr = 0xff; /* 8 times */
376 /* Mode register write operation */
377 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_4;
379 *(sdram_addr + 0xcc) = 0xff;
382 /* Normal operation */
383 lbc->lsdmr = CONFIG_SYS_LBC_LSDMR_5 | 0x40000000;
389 * In non-aligned case we don't [normally] use that memory because
394 return CONFIG_SYS_LBC_SDRAM_SIZE;
397 static int sdram_init(unsigned int base) { return 0; }
400 #if defined(CONFIG_OF_BOARD_SETUP)
401 static void ft_board_fixup_qe_usb(void *blob, bd_t *bd)
403 if (!hwconfig_subarg_cmp("qe_usb", "mode", "peripheral"))
406 do_fixup_by_compat(blob, "fsl,mpc8323-qe-usb", "mode",
407 "peripheral", sizeof("peripheral"), 1);
410 void ft_board_setup(void *blob, bd_t *bd)
412 ft_cpu_setup(blob, bd);
414 ft_pci_setup(blob, bd);
416 ft_board_fixup_qe_usb(blob, bd);
418 * mpc8360ea pb mds errata 2: RGMII timing
419 * if on mpc8360ea rev. 2.1,
420 * change both ucc phy-connection-types from rgmii-id to rgmii-rxid
422 if (board_handle_erratum2()) {
427 nodeoffset = fdt_path_offset(blob, "/aliases");
428 if (nodeoffset >= 0) {
429 #if defined(CONFIG_HAS_ETH0)
430 /* fixup UCC 1 if using rgmii-id mode */
431 prop = fdt_getprop(blob, nodeoffset, "ethernet0", NULL);
433 path = fdt_path_offset(blob, prop);
434 prop = fdt_getprop(blob, path,
435 "phy-connection-type", 0);
436 if (prop && (strcmp(prop, "rgmii-id") == 0))
437 fdt_fixup_phy_connection(blob, path,
438 PHY_INTERFACE_MODE_RGMII_RXID);
441 #if defined(CONFIG_HAS_ETH1)
442 /* fixup UCC 2 if using rgmii-id mode */
443 prop = fdt_getprop(blob, nodeoffset, "ethernet1", NULL);
445 path = fdt_path_offset(blob, prop);
446 prop = fdt_getprop(blob, path,
447 "phy-connection-type", 0);
448 if (prop && (strcmp(prop, "rgmii-id") == 0))
449 fdt_fixup_phy_connection(blob, path,
450 PHY_INTERFACE_MODE_RGMII_RXID);