blob: ee1ebd98ba2f7b2614020f9cfdf5a6ac8fd432f4 [file] [log] [blame]
Dave Liu19580e62007-09-18 12:37:57 +08001/*
Kumar Galaa1964ea2010-09-30 09:15:03 -05002 * Copyright (C) 2007,2010 Freescale Semiconductor, Inc.
Dave Liu19580e62007-09-18 12:37:57 +08003 * Dave Liu <daveliu@freescale.com>
4 *
5 * CREDITS: Kim Phillips contribute to LIBFDT code
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 */
12
13#include <common.h>
Anton Vorontsovc78c6782009-06-10 00:25:31 +040014#include <hwconfig.h>
Dave Liu19580e62007-09-18 12:37:57 +080015#include <i2c.h>
Dave Liu6f8c85e2008-03-26 22:56:36 +080016#include <asm/io.h>
Kumar Gala7e1afb62010-04-20 10:02:24 -050017#include <asm/fsl_mpc83xx_serdes.h>
Kumar Galaa1964ea2010-09-30 09:15:03 -050018#include <asm/fsl_enet.h>
Dave Liu19580e62007-09-18 12:37:57 +080019#include <spd_sdram.h>
Anton Vorontsov1da83a62008-10-02 18:32:25 +040020#include <tsec.h>
Dave Liu19580e62007-09-18 12:37:57 +080021#include <libfdt.h>
Anton Vorontsov3bf1be32008-10-14 22:58:53 +040022#include <fdt_support.h>
Anton Vorontsovc78c6782009-06-10 00:25:31 +040023#include <fsl_esdhc.h>
Andy Fleming063c1262011-04-08 02:10:54 -050024#include <fsl_mdio.h>
Anton Vorontsov8b345572009-01-08 04:26:19 +030025#include "pci.h"
Dave Liu19580e62007-09-18 12:37:57 +080026#include "../common/pq-mds-pib.h"
Dave Liu19580e62007-09-18 12:37:57 +080027
28int board_early_init_f(void)
29{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020030 u8 *bcsr = (u8 *)CONFIG_SYS_BCSR;
Dave Liu19580e62007-09-18 12:37:57 +080031
32 /* Enable flash write */
33 bcsr[0x9] &= ~0x04;
34 /* Clear all of the interrupt of BCSR */
35 bcsr[0xe] = 0xff;
36
Dave Liu6f8c85e2008-03-26 22:56:36 +080037#ifdef CONFIG_FSL_SERDES
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020038 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
Dave Liu6f8c85e2008-03-26 22:56:36 +080039 u32 spridr = in_be32(&immr->sysconf.spridr);
40
41 /* we check only part num, and don't look for CPU revisions */
Dave Liu5fb5a682008-03-31 17:05:12 +080042 switch (PARTID_NO_E(spridr)) {
Kim Phillipse5c4ade2008-03-28 10:19:07 -050043 case SPR_8377:
Dave Liu6f8c85e2008-03-26 22:56:36 +080044 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
Andy Fleminge1ac3872008-10-30 16:50:14 -050045 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
Dave Liu6f8c85e2008-03-26 22:56:36 +080046 break;
Kim Phillipse5c4ade2008-03-28 10:19:07 -050047 case SPR_8378:
Anton Vorontsov1da83a62008-10-02 18:32:25 +040048 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SGMII,
Andy Fleminge1ac3872008-10-30 16:50:14 -050049 FSL_SERDES_CLK_125, FSL_SERDES_VDD_1V);
Kim Phillipse5c4ade2008-03-28 10:19:07 -050050 break;
51 case SPR_8379:
52 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
Andy Fleminge1ac3872008-10-30 16:50:14 -050053 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
Kim Phillipse5c4ade2008-03-28 10:19:07 -050054 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA,
Andy Fleminge1ac3872008-10-30 16:50:14 -050055 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
Kim Phillipse5c4ade2008-03-28 10:19:07 -050056 break;
Dave Liu6f8c85e2008-03-26 22:56:36 +080057 default:
58 printf("serdes not configured: unknown CPU part number: "
Andy Fleminge1ac3872008-10-30 16:50:14 -050059 "%04x\n", spridr >> 16);
Dave Liu6f8c85e2008-03-26 22:56:36 +080060 break;
61 }
62#endif /* CONFIG_FSL_SERDES */
Dave Liu19580e62007-09-18 12:37:57 +080063 return 0;
64}
65
Anton Vorontsovc78c6782009-06-10 00:25:31 +040066#ifdef CONFIG_FSL_ESDHC
67int board_mmc_init(bd_t *bd)
68{
69 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
70 u8 *bcsr = (u8 *)CONFIG_SYS_BCSR;
71
72 if (!hwconfig("esdhc"))
73 return 0;
74
75 /* Set SPI_SD, SER_SD, and IRQ4_WP so that SD signals go through */
76 bcsr[0xc] |= 0x4c;
77
78 /* Set proper bits in SICR to allow SD signals through */
79 clrsetbits_be32(&im->sysconf.sicrl, SICRL_USB_B, SICRL_USB_B_SD);
80 clrsetbits_be32(&im->sysconf.sicrh, SICRH_GPIO2_E | SICRH_SPI,
81 SICRH_GPIO2_E_SD | SICRH_SPI_SD);
82
83 return fsl_esdhc_mmc_init(bd);
84}
85#endif
86
Anton Vorontsov1da83a62008-10-02 18:32:25 +040087#if defined(CONFIG_TSEC1) || defined(CONFIG_TSEC2)
88int board_eth_init(bd_t *bd)
89{
Andy Fleming063c1262011-04-08 02:10:54 -050090 struct fsl_pq_mdio_info mdio_info;
Anton Vorontsov1da83a62008-10-02 18:32:25 +040091 struct tsec_info_struct tsec_info[2];
92 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
93 u32 rcwh = in_be32(&im->reset.rcwh);
94 u32 tsec_mode;
95 int num = 0;
96
97 /* New line after Net: */
98 printf("\n");
99
100#ifdef CONFIG_TSEC1
101 SET_STD_TSEC_INFO(tsec_info[num], 1);
102
103 printf(CONFIG_TSEC1_NAME ": ");
104
105 tsec_mode = rcwh & HRCWH_TSEC1M_MASK;
106 if (tsec_mode == HRCWH_TSEC1M_IN_RGMII) {
107 printf("RGMII\n");
108 /* this is default, no need to fixup */
109 } else if (tsec_mode == HRCWH_TSEC1M_IN_SGMII) {
110 printf("SGMII\n");
111 tsec_info[num].phyaddr = TSEC1_PHY_ADDR_SGMII;
112 tsec_info[num].flags = TSEC_GIGABIT;
113 } else {
114 printf("unsupported PHY type\n");
115 }
116 num++;
117#endif
118#ifdef CONFIG_TSEC2
119 SET_STD_TSEC_INFO(tsec_info[num], 2);
120
121 printf(CONFIG_TSEC2_NAME ": ");
122
123 tsec_mode = rcwh & HRCWH_TSEC2M_MASK;
124 if (tsec_mode == HRCWH_TSEC2M_IN_RGMII) {
125 printf("RGMII\n");
126 /* this is default, no need to fixup */
127 } else if (tsec_mode == HRCWH_TSEC2M_IN_SGMII) {
128 printf("SGMII\n");
129 tsec_info[num].phyaddr = TSEC2_PHY_ADDR_SGMII;
130 tsec_info[num].flags = TSEC_GIGABIT;
131 } else {
132 printf("unsupported PHY type\n");
133 }
134 num++;
135#endif
Andy Fleming063c1262011-04-08 02:10:54 -0500136
137 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
138 mdio_info.name = DEFAULT_MII_NAME;
139 fsl_pq_mdio_init(bd, &mdio_info);
140
Anton Vorontsov1da83a62008-10-02 18:32:25 +0400141 return tsec_eth_init(bd, tsec_info, num);
142}
143
144static void __ft_tsec_fixup(void *blob, bd_t *bd, const char *alias,
145 int phy_addr)
146{
Anton Vorontsov1da83a62008-10-02 18:32:25 +0400147 const u32 *ph;
148 int off;
149 int err;
150
151 off = fdt_path_offset(blob, alias);
152 if (off < 0) {
153 printf("WARNING: could not find %s alias: %s.\n", alias,
154 fdt_strerror(off));
155 return;
156 }
157
Kumar Galaa1964ea2010-09-30 09:15:03 -0500158 err = fdt_fixup_phy_connection(blob, off, SGMII);
159
Anton Vorontsov1da83a62008-10-02 18:32:25 +0400160 if (err) {
161 printf("WARNING: could not set phy-connection-type for %s: "
162 "%s.\n", alias, fdt_strerror(err));
163 return;
164 }
165
166 ph = (u32 *)fdt_getprop(blob, off, "phy-handle", 0);
167 if (!ph) {
168 printf("WARNING: could not get phy-handle for %s.\n",
169 alias);
170 return;
171 }
172
173 off = fdt_node_offset_by_phandle(blob, *ph);
174 if (off < 0) {
175 printf("WARNING: could not get phy node for %s: %s\n", alias,
176 fdt_strerror(off));
177 return;
178 }
179
180 phy_addr = cpu_to_fdt32(phy_addr);
181 err = fdt_setprop(blob, off, "reg", &phy_addr, sizeof(phy_addr));
182 if (err < 0) {
183 printf("WARNING: could not set phy node's reg for %s: "
184 "%s.\n", alias, fdt_strerror(err));
185 return;
186 }
187}
188
189static void ft_tsec_fixup(void *blob, bd_t *bd)
190{
191 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
192 u32 rcwh = in_be32(&im->reset.rcwh);
193 u32 tsec_mode;
194
195#ifdef CONFIG_TSEC1
196 tsec_mode = rcwh & HRCWH_TSEC1M_MASK;
197 if (tsec_mode == HRCWH_TSEC1M_IN_SGMII)
198 __ft_tsec_fixup(blob, bd, "ethernet0", TSEC1_PHY_ADDR_SGMII);
199#endif
200
201#ifdef CONFIG_TSEC2
202 tsec_mode = rcwh & HRCWH_TSEC2M_MASK;
203 if (tsec_mode == HRCWH_TSEC2M_IN_SGMII)
204 __ft_tsec_fixup(blob, bd, "ethernet1", TSEC2_PHY_ADDR_SGMII);
205#endif
206}
207#else
208static inline void ft_tsec_fixup(void *blob, bd_t *bd) {}
209#endif /* defined(CONFIG_TSEC1) || defined(CONFIG_TSEC2) */
210
Dave Liu19580e62007-09-18 12:37:57 +0800211int board_early_init_r(void)
212{
213#ifdef CONFIG_PQ_MDS_PIB
214 pib_init();
215#endif
216 return 0;
217}
218
Peter Tyser9adda542009-06-30 17:15:50 -0500219#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
Dave Liu19580e62007-09-18 12:37:57 +0800220extern void ddr_enable_ecc(unsigned int dram_size);
221#endif
222int fixed_sdram(void);
223
Becky Bruce9973e3c2008-06-09 16:03:40 -0500224phys_size_t initdram(int board_type)
Dave Liu19580e62007-09-18 12:37:57 +0800225{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200226 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Dave Liu19580e62007-09-18 12:37:57 +0800227 u32 msize = 0;
228
229 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
230 return -1;
231
232#if defined(CONFIG_SPD_EEPROM)
233 msize = spd_sdram();
234#else
235 msize = fixed_sdram();
236#endif
237
Peter Tyser9adda542009-06-30 17:15:50 -0500238#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
Dave Liu19580e62007-09-18 12:37:57 +0800239 /* Initialize DDR ECC byte */
240 ddr_enable_ecc(msize * 1024 * 1024);
241#endif
242
243 /* return total bus DDR size(bytes) */
244 return (msize * 1024 * 1024);
245}
246
247#if !defined(CONFIG_SPD_EEPROM)
248/*************************************************************************
249 * fixed sdram init -- doesn't use serial presence detect.
250 ************************************************************************/
251int fixed_sdram(void)
252{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200253 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
254 u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
Dave Liu19580e62007-09-18 12:37:57 +0800255 u32 msize_log2 = __ilog2(msize);
256
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200257 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
Dave Liu19580e62007-09-18 12:37:57 +0800258 im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
259
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200260#if (CONFIG_SYS_DDR_SIZE != 512)
Dave Liu19580e62007-09-18 12:37:57 +0800261#warning Currenly any ddr size other than 512 is not supported
262#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200263 im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
Dave Liu19580e62007-09-18 12:37:57 +0800264 udelay(50000);
265
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200266 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
Dave Liu19580e62007-09-18 12:37:57 +0800267 udelay(1000);
268
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200269 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
270 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
Dave Liu19580e62007-09-18 12:37:57 +0800271 udelay(1000);
272
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200273 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
274 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
275 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
276 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
277 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
278 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
279 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
280 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
281 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Dave Liu19580e62007-09-18 12:37:57 +0800282 __asm__ __volatile__("sync");
283 udelay(1000);
284
285 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
286 udelay(2000);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200287 return CONFIG_SYS_DDR_SIZE;
Dave Liu19580e62007-09-18 12:37:57 +0800288}
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200289#endif /*!CONFIG_SYS_SPD_EEPROM */
Dave Liu19580e62007-09-18 12:37:57 +0800290
291int checkboard(void)
292{
293 puts("Board: Freescale MPC837xEMDS\n");
294 return 0;
295}
296
Anton Vorontsov00f7bba2008-10-02 19:17:33 +0400297#ifdef CONFIG_PCI
298int board_pci_host_broken(void)
299{
300 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
301 const u32 rcw_mask = HRCWH_PCI1_ARBITER_ENABLE | HRCWH_PCI_HOST;
Anton Vorontsov00f7bba2008-10-02 19:17:33 +0400302
303 /* It's always OK in case of external arbiter. */
Anton Vorontsovbfadb172009-06-10 00:25:38 +0400304 if (hwconfig_subarg_cmp("pci", "arbiter", "external"))
Anton Vorontsov00f7bba2008-10-02 19:17:33 +0400305 return 0;
306
307 if ((in_be32(&im->reset.rcwh) & rcw_mask) != rcw_mask)
308 return 1;
309
310 return 0;
311}
312
313static void ft_pci_fixup(void *blob, bd_t *bd)
314{
315 const char *status = "broken (no arbiter)";
316 int off;
317 int err;
318
319 off = fdt_path_offset(blob, "pci0");
320 if (off < 0) {
321 printf("WARNING: could not find pci0 alias: %s.\n",
322 fdt_strerror(off));
323 return;
324 }
325
326 err = fdt_setprop(blob, off, "status", status, strlen(status) + 1);
327 if (err) {
328 printf("WARNING: could not set status for pci0: %s.\n",
329 fdt_strerror(err));
330 return;
331 }
332}
333#endif
334
Dave Liu19580e62007-09-18 12:37:57 +0800335#if defined(CONFIG_OF_BOARD_SETUP)
336void ft_board_setup(void *blob, bd_t *bd)
337{
Dave Liu19580e62007-09-18 12:37:57 +0800338 ft_cpu_setup(blob, bd);
Anton Vorontsov1da83a62008-10-02 18:32:25 +0400339 ft_tsec_fixup(blob, bd);
Anton Vorontsov3bf1be32008-10-14 22:58:53 +0400340 fdt_fixup_dr_usb(blob, bd);
Anton Vorontsovc78c6782009-06-10 00:25:31 +0400341 fdt_fixup_esdhc(blob, bd);
Dave Liu19580e62007-09-18 12:37:57 +0800342#ifdef CONFIG_PCI
343 ft_pci_setup(blob, bd);
Anton Vorontsov00f7bba2008-10-02 19:17:33 +0400344 if (board_pci_host_broken())
345 ft_pci_fixup(blob, bd);
Anton Vorontsov8b345572009-01-08 04:26:19 +0300346 ft_pcie_fixup(blob, bd);
Dave Liu19580e62007-09-18 12:37:57 +0800347#endif
348}
349#endif /* CONFIG_OF_BOARD_SETUP */