blob: acf8ada7b2e6c5b3b79704df7a361620a404e638 [file] [log] [blame]
Dave Liu19580e62007-09-18 12:37:57 +08001/*
2 * Copyright (C) 2007 Freescale Semiconductor, Inc.
3 * 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>
14#include <i2c.h>
Dave Liu6f8c85e2008-03-26 22:56:36 +080015#include <asm/io.h>
16#include <asm/fsl_serdes.h>
Dave Liu19580e62007-09-18 12:37:57 +080017#include <spd_sdram.h>
Anton Vorontsov1da83a62008-10-02 18:32:25 +040018#include <tsec.h>
Dave Liu19580e62007-09-18 12:37:57 +080019#include <libfdt.h>
Anton Vorontsov3bf1be32008-10-14 22:58:53 +040020#include <fdt_support.h>
Dave Liu19580e62007-09-18 12:37:57 +080021#include "../common/pq-mds-pib.h"
Dave Liu19580e62007-09-18 12:37:57 +080022
23int board_early_init_f(void)
24{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020025 u8 *bcsr = (u8 *)CONFIG_SYS_BCSR;
Dave Liu19580e62007-09-18 12:37:57 +080026
27 /* Enable flash write */
28 bcsr[0x9] &= ~0x04;
29 /* Clear all of the interrupt of BCSR */
30 bcsr[0xe] = 0xff;
31
Dave Liu6f8c85e2008-03-26 22:56:36 +080032#ifdef CONFIG_FSL_SERDES
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020033 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
Dave Liu6f8c85e2008-03-26 22:56:36 +080034 u32 spridr = in_be32(&immr->sysconf.spridr);
35
36 /* we check only part num, and don't look for CPU revisions */
Dave Liu5fb5a682008-03-31 17:05:12 +080037 switch (PARTID_NO_E(spridr)) {
Kim Phillipse5c4ade2008-03-28 10:19:07 -050038 case SPR_8377:
Dave Liu6f8c85e2008-03-26 22:56:36 +080039 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
40 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
41 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
42 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
43 break;
Kim Phillipse5c4ade2008-03-28 10:19:07 -050044 case SPR_8378:
Anton Vorontsov1da83a62008-10-02 18:32:25 +040045 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SGMII,
46 FSL_SERDES_CLK_125, FSL_SERDES_VDD_1V);
Anton Vorontsov55c53192008-10-02 18:31:53 +040047 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
Kim Phillipse5c4ade2008-03-28 10:19:07 -050048 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
49 break;
50 case SPR_8379:
51 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
52 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
53 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA,
54 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
55 break;
Dave Liu6f8c85e2008-03-26 22:56:36 +080056 default:
57 printf("serdes not configured: unknown CPU part number: "
58 "%04x\n", spridr >> 16);
59 break;
60 }
61#endif /* CONFIG_FSL_SERDES */
Dave Liu19580e62007-09-18 12:37:57 +080062 return 0;
63}
64
Anton Vorontsov1da83a62008-10-02 18:32:25 +040065#if defined(CONFIG_TSEC1) || defined(CONFIG_TSEC2)
66int board_eth_init(bd_t *bd)
67{
68 struct tsec_info_struct tsec_info[2];
69 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
70 u32 rcwh = in_be32(&im->reset.rcwh);
71 u32 tsec_mode;
72 int num = 0;
73
74 /* New line after Net: */
75 printf("\n");
76
77#ifdef CONFIG_TSEC1
78 SET_STD_TSEC_INFO(tsec_info[num], 1);
79
80 printf(CONFIG_TSEC1_NAME ": ");
81
82 tsec_mode = rcwh & HRCWH_TSEC1M_MASK;
83 if (tsec_mode == HRCWH_TSEC1M_IN_RGMII) {
84 printf("RGMII\n");
85 /* this is default, no need to fixup */
86 } else if (tsec_mode == HRCWH_TSEC1M_IN_SGMII) {
87 printf("SGMII\n");
88 tsec_info[num].phyaddr = TSEC1_PHY_ADDR_SGMII;
89 tsec_info[num].flags = TSEC_GIGABIT;
90 } else {
91 printf("unsupported PHY type\n");
92 }
93 num++;
94#endif
95#ifdef CONFIG_TSEC2
96 SET_STD_TSEC_INFO(tsec_info[num], 2);
97
98 printf(CONFIG_TSEC2_NAME ": ");
99
100 tsec_mode = rcwh & HRCWH_TSEC2M_MASK;
101 if (tsec_mode == HRCWH_TSEC2M_IN_RGMII) {
102 printf("RGMII\n");
103 /* this is default, no need to fixup */
104 } else if (tsec_mode == HRCWH_TSEC2M_IN_SGMII) {
105 printf("SGMII\n");
106 tsec_info[num].phyaddr = TSEC2_PHY_ADDR_SGMII;
107 tsec_info[num].flags = TSEC_GIGABIT;
108 } else {
109 printf("unsupported PHY type\n");
110 }
111 num++;
112#endif
113 return tsec_eth_init(bd, tsec_info, num);
114}
115
116static void __ft_tsec_fixup(void *blob, bd_t *bd, const char *alias,
117 int phy_addr)
118{
119 const char *phy_type = "sgmii";
120 const u32 *ph;
121 int off;
122 int err;
123
124 off = fdt_path_offset(blob, alias);
125 if (off < 0) {
126 printf("WARNING: could not find %s alias: %s.\n", alias,
127 fdt_strerror(off));
128 return;
129 }
130
131 err = fdt_setprop(blob, off, "phy-connection-type", phy_type,
132 strlen(phy_type) + 1);
133 if (err) {
134 printf("WARNING: could not set phy-connection-type for %s: "
135 "%s.\n", alias, fdt_strerror(err));
136 return;
137 }
138
139 ph = (u32 *)fdt_getprop(blob, off, "phy-handle", 0);
140 if (!ph) {
141 printf("WARNING: could not get phy-handle for %s.\n",
142 alias);
143 return;
144 }
145
146 off = fdt_node_offset_by_phandle(blob, *ph);
147 if (off < 0) {
148 printf("WARNING: could not get phy node for %s: %s\n", alias,
149 fdt_strerror(off));
150 return;
151 }
152
153 phy_addr = cpu_to_fdt32(phy_addr);
154 err = fdt_setprop(blob, off, "reg", &phy_addr, sizeof(phy_addr));
155 if (err < 0) {
156 printf("WARNING: could not set phy node's reg for %s: "
157 "%s.\n", alias, fdt_strerror(err));
158 return;
159 }
160}
161
162static void ft_tsec_fixup(void *blob, bd_t *bd)
163{
164 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
165 u32 rcwh = in_be32(&im->reset.rcwh);
166 u32 tsec_mode;
167
168#ifdef CONFIG_TSEC1
169 tsec_mode = rcwh & HRCWH_TSEC1M_MASK;
170 if (tsec_mode == HRCWH_TSEC1M_IN_SGMII)
171 __ft_tsec_fixup(blob, bd, "ethernet0", TSEC1_PHY_ADDR_SGMII);
172#endif
173
174#ifdef CONFIG_TSEC2
175 tsec_mode = rcwh & HRCWH_TSEC2M_MASK;
176 if (tsec_mode == HRCWH_TSEC2M_IN_SGMII)
177 __ft_tsec_fixup(blob, bd, "ethernet1", TSEC2_PHY_ADDR_SGMII);
178#endif
179}
180#else
181static inline void ft_tsec_fixup(void *blob, bd_t *bd) {}
182#endif /* defined(CONFIG_TSEC1) || defined(CONFIG_TSEC2) */
183
Dave Liu19580e62007-09-18 12:37:57 +0800184int board_early_init_r(void)
185{
186#ifdef CONFIG_PQ_MDS_PIB
187 pib_init();
188#endif
189 return 0;
190}
191
192#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
193extern void ddr_enable_ecc(unsigned int dram_size);
194#endif
195int fixed_sdram(void);
196
Becky Bruce9973e3c2008-06-09 16:03:40 -0500197phys_size_t initdram(int board_type)
Dave Liu19580e62007-09-18 12:37:57 +0800198{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200199 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Dave Liu19580e62007-09-18 12:37:57 +0800200 u32 msize = 0;
201
202 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
203 return -1;
204
205#if defined(CONFIG_SPD_EEPROM)
206 msize = spd_sdram();
207#else
208 msize = fixed_sdram();
209#endif
210
211#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
212 /* Initialize DDR ECC byte */
213 ddr_enable_ecc(msize * 1024 * 1024);
214#endif
215
216 /* return total bus DDR size(bytes) */
217 return (msize * 1024 * 1024);
218}
219
220#if !defined(CONFIG_SPD_EEPROM)
221/*************************************************************************
222 * fixed sdram init -- doesn't use serial presence detect.
223 ************************************************************************/
224int fixed_sdram(void)
225{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200226 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
227 u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
Dave Liu19580e62007-09-18 12:37:57 +0800228 u32 msize_log2 = __ilog2(msize);
229
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200230 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
Dave Liu19580e62007-09-18 12:37:57 +0800231 im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
232
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200233#if (CONFIG_SYS_DDR_SIZE != 512)
Dave Liu19580e62007-09-18 12:37:57 +0800234#warning Currenly any ddr size other than 512 is not supported
235#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200236 im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
Dave Liu19580e62007-09-18 12:37:57 +0800237 udelay(50000);
238
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200239 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
Dave Liu19580e62007-09-18 12:37:57 +0800240 udelay(1000);
241
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200242 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
243 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
Dave Liu19580e62007-09-18 12:37:57 +0800244 udelay(1000);
245
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200246 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;
Dave Liu19580e62007-09-18 12:37:57 +0800255 __asm__ __volatile__("sync");
256 udelay(1000);
257
258 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
259 udelay(2000);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200260 return CONFIG_SYS_DDR_SIZE;
Dave Liu19580e62007-09-18 12:37:57 +0800261}
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200262#endif /*!CONFIG_SYS_SPD_EEPROM */
Dave Liu19580e62007-09-18 12:37:57 +0800263
264int checkboard(void)
265{
266 puts("Board: Freescale MPC837xEMDS\n");
267 return 0;
268}
269
Anton Vorontsov00f7bba2008-10-02 19:17:33 +0400270#ifdef CONFIG_PCI
271int board_pci_host_broken(void)
272{
273 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
274 const u32 rcw_mask = HRCWH_PCI1_ARBITER_ENABLE | HRCWH_PCI_HOST;
275 const char *pci_ea = getenv("pci_external_arbiter");
276
277 /* It's always OK in case of external arbiter. */
278 if (pci_ea && !strcmp(pci_ea, "yes"))
279 return 0;
280
281 if ((in_be32(&im->reset.rcwh) & rcw_mask) != rcw_mask)
282 return 1;
283
284 return 0;
285}
286
287static void ft_pci_fixup(void *blob, bd_t *bd)
288{
289 const char *status = "broken (no arbiter)";
290 int off;
291 int err;
292
293 off = fdt_path_offset(blob, "pci0");
294 if (off < 0) {
295 printf("WARNING: could not find pci0 alias: %s.\n",
296 fdt_strerror(off));
297 return;
298 }
299
300 err = fdt_setprop(blob, off, "status", status, strlen(status) + 1);
301 if (err) {
302 printf("WARNING: could not set status for pci0: %s.\n",
303 fdt_strerror(err));
304 return;
305 }
306}
307#endif
308
Dave Liu19580e62007-09-18 12:37:57 +0800309#if defined(CONFIG_OF_BOARD_SETUP)
310void ft_board_setup(void *blob, bd_t *bd)
311{
Dave Liu19580e62007-09-18 12:37:57 +0800312 ft_cpu_setup(blob, bd);
Anton Vorontsov1da83a62008-10-02 18:32:25 +0400313 ft_tsec_fixup(blob, bd);
Anton Vorontsov3bf1be32008-10-14 22:58:53 +0400314 fdt_fixup_dr_usb(blob, bd);
Dave Liu19580e62007-09-18 12:37:57 +0800315#ifdef CONFIG_PCI
316 ft_pci_setup(blob, bd);
Anton Vorontsov00f7bba2008-10-02 19:17:33 +0400317 if (board_pci_host_broken())
318 ft_pci_fixup(blob, bd);
Dave Liu19580e62007-09-18 12:37:57 +0800319#endif
320}
321#endif /* CONFIG_OF_BOARD_SETUP */