blob: 178b1d36fbf683faa44fefd6a4be57809b0f1022 [file] [log] [blame]
Timur Tabi054838e2006-10-31 18:44:42 -06001/*
2 * Copyright (C) Freescale Semiconductor, Inc. 2006. All rights reserved.
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
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 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24#include <ioports.h>
25#include <mpc83xx.h>
26#include <i2c.h>
27#include <spd.h>
28#include <miiphy.h>
29
30#ifdef CONFIG_PCI
31#include <asm/mpc8349_pci.h>
32#include <pci.h>
33#endif
34
35#ifdef CONFIG_SPD_EEPROM
36#include <spd_sdram.h>
37#else
38#include <asm/mmu.h>
39#endif
Kim Phillips774e1b52006-11-01 00:10:40 -060040#if defined(CONFIG_OF_FLAT_TREE)
41#include <ft_build.h>
42#endif
Timur Tabi054838e2006-10-31 18:44:42 -060043
44#ifndef CONFIG_SPD_EEPROM
45/*************************************************************************
46 * fixed sdram init -- doesn't use serial presence detect.
47 ************************************************************************/
48int fixed_sdram(void)
49{
Timur Tabi386a2802006-11-03 12:00:28 -060050 volatile immap_t *im = (immap_t *) CFG_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -060051 u32 ddr_size; /* The size of RAM, in bytes */
52 u32 ddr_size_log2 = 0;
53
54 for (ddr_size = CFG_DDR_SIZE * 0x100000; ddr_size > 1; ddr_size >>= 1) {
55 if (ddr_size & 1) {
56 return -1;
57 }
58 ddr_size_log2++;
59 }
60
61 im->sysconf.ddrlaw[0].ar =
62 LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
63 im->sysconf.ddrlaw[0].bar = (CFG_DDR_SDRAM_BASE >> 12) & 0xfffff;
64
65 /* Only one CS0 for DDR */
66 im->ddr.csbnds[0].csbnds = 0x0000000f;
67 im->ddr.cs_config[0] = CFG_DDR_CONFIG;
68
69 debug("cs0_bnds = 0x%08x\n", im->ddr.csbnds[0].csbnds);
70 debug("cs0_config = 0x%08x\n", im->ddr.cs_config[0]);
71
72 debug("DDR:bar=0x%08x\n", im->sysconf.ddrlaw[0].bar);
73 debug("DDR:ar=0x%08x\n", im->sysconf.ddrlaw[0].ar);
74
75 im->ddr.timing_cfg_1 = CFG_DDR_TIMING_1;
76 im->ddr.timing_cfg_2 = CFG_DDR_TIMING_2;/* Was "2 << TIMING_CFG2_WR_DATA_DELAY_SHIFT" */
77 im->ddr.sdram_cfg = SDRAM_CFG_SREN | SDRAM_CFG_SDRAM_TYPE_DDR;
78 im->ddr.sdram_mode =
79 (0x0000 << SDRAM_MODE_ESD_SHIFT) | (0x0032 << SDRAM_MODE_SD_SHIFT);
80 im->ddr.sdram_interval =
81 (0x0410 << SDRAM_INTERVAL_REFINT_SHIFT) | (0x0100 <<
82 SDRAM_INTERVAL_BSTOPRE_SHIFT);
Timur Tabi83d47822007-04-30 13:59:50 -050083 im->ddr.sdram_clk_cntl = CFG_DDR_SDRAM_CLK_CNTL;
Timur Tabi054838e2006-10-31 18:44:42 -060084
85 udelay(200);
86
87 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
88
89 debug("DDR:timing_cfg_1=0x%08x\n", im->ddr.timing_cfg_1);
90 debug("DDR:timing_cfg_2=0x%08x\n", im->ddr.timing_cfg_2);
91 debug("DDR:sdram_mode=0x%08x\n", im->ddr.sdram_mode);
92 debug("DDR:sdram_interval=0x%08x\n", im->ddr.sdram_interval);
93 debug("DDR:sdram_cfg=0x%08x\n", im->ddr.sdram_cfg);
94
95 return CFG_DDR_SIZE;
96}
97#endif
98
99#ifdef CONFIG_PCI
100/*
101 * Initialize PCI Devices, report devices found
102 */
103#ifndef CONFIG_PCI_PNP
104static struct pci_config_table pci_mpc83xxmitx_config_table[] = {
105 {
106 PCI_ANY_ID,
107 PCI_ANY_ID,
108 PCI_ANY_ID,
109 PCI_ANY_ID,
110 0x0f,
111 PCI_ANY_ID,
112 pci_cfgfunc_config_device,
113 {
114 PCI_ENET0_IOADDR,
115 PCI_ENET0_MEMADDR,
116 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}
117 },
118 {}
119}
120#endif
121
122volatile static struct pci_controller hose[] = {
123 {
124#ifndef CONFIG_PCI_PNP
125 config_table:pci_mpc83xxmitx_config_table,
126#endif
127 },
128 {
129#ifndef CONFIG_PCI_PNP
130 config_table:pci_mpc83xxmitx_config_table,
131#endif
132 }
133};
134#endif /* CONFIG_PCI */
135
Timur Tabi054838e2006-10-31 18:44:42 -0600136long int initdram(int board_type)
137{
Timur Tabi386a2802006-11-03 12:00:28 -0600138 volatile immap_t *im = (immap_t *) CFG_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600139 u32 msize = 0;
140#ifdef CONFIG_DDR_ECC
141 volatile ddr83xx_t *ddr = &im->ddr;
142#endif
143
144 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
145 return -1;
146
147 /* DDR SDRAM - Main SODIMM */
148 im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
149#ifdef CONFIG_SPD_EEPROM
150 msize = spd_sdram();
151#else
152 msize = fixed_sdram();
153#endif
154
155#ifdef CONFIG_DDR_ECC
156 if (ddr->sdram_cfg & SDRAM_CFG_ECC_EN)
157 /* Unlike every other board, on the 83xx spd_sdram() returns
158 megabytes instead of just bytes. That's why we need to
159 multiple by 1MB when calling ddr_enable_ecc(). */
160 ddr_enable_ecc(msize * 1048576);
161#endif
162
Timur Tabi054838e2006-10-31 18:44:42 -0600163 puts(" DDR RAM: ");
Timur Tabi3ff11182007-01-31 15:54:20 -0600164 /* return total bus RAM size(bytes) */
Timur Tabi054838e2006-10-31 18:44:42 -0600165 return msize * 1024 * 1024;
166}
167
168int checkboard(void)
169{
Timur Tabi435e3a72007-01-31 15:54:29 -0600170#ifdef CONFIG_MPC8349ITX
Timur Tabiab347542006-11-03 19:15:00 -0600171 puts("Board: Freescale MPC8349E-mITX\n");
Timur Tabi435e3a72007-01-31 15:54:29 -0600172#else
173 puts("Board: Freescale MPC8349E-mITX-GP\n");
174#endif
Timur Tabi054838e2006-10-31 18:44:42 -0600175
176 return 0;
177}
178
Timur Tabiab347542006-11-03 19:15:00 -0600179/*
Timur Tabi054838e2006-10-31 18:44:42 -0600180 * Implement a work-around for a hardware problem with compact
181 * flash.
182 *
183 * Program the UPM if compact flash is enabled.
184 */
185int misc_init_f(void)
186{
Timur Tabi435e3a72007-01-31 15:54:29 -0600187#ifdef CONFIG_VSC7385
Timur Tabi054838e2006-10-31 18:44:42 -0600188 volatile u32 *vsc7385_cpuctrl;
189
190 /* 0x1c0c0 is the VSC7385 CPU Control (CPUCTRL) Register. The power up
191 default of VSC7385 L1_IRQ and L2_IRQ requests are active high. That
192 means it is 0 when the IRQ is not active. This makes the wire-AND
193 logic always assert IRQ7 to CPU even if there is no request from the
194 switch. Since the compact flash and the switch share the same IRQ,
195 the Linux kernel will think that the compact flash is requesting irq
196 and get stuck when it tries to clear the IRQ. Thus we need to set
197 the L2_IRQ0 and L2_IRQ1 to active low.
198
199 The following code sets the L1_IRQ and L2_IRQ polarity to active low.
200 Without this code, compact flash will not work in Linux because
201 unlike U-Boot, Linux uses the IRQ, so this code is necessary if we
202 don't enable compact flash for U-Boot.
203 */
204
205 vsc7385_cpuctrl = (volatile u32 *)(CFG_VSC7385_BASE + 0x1c0c0);
206 *vsc7385_cpuctrl |= 0x0c;
Timur Tabi435e3a72007-01-31 15:54:29 -0600207#endif
Timur Tabi054838e2006-10-31 18:44:42 -0600208
209#ifdef CONFIG_COMPACT_FLASH
210 /* UPM Table Configuration Code */
211 static uint UPMATable[] = {
212 0xcffffc00, 0x0fffff00, 0x0fafff00, 0x0fafff00,
213 0x0faffd00, 0x0faffc04, 0x0ffffc00, 0x3ffffc01,
214 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
215 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
216 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfff7fc00,
217 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
218 0xcffffc00, 0x0fffff00, 0x0ff3ff00, 0x0ff3ff00,
219 0x0ff3fe00, 0x0ffffc00, 0x3ffffc05, 0xfffffc00,
220 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
221 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
222 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
223 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
224 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
225 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
226 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
227 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01
228 };
Timur Tabi386a2802006-11-03 12:00:28 -0600229 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Timur Tabi054838e2006-10-31 18:44:42 -0600230 volatile lbus83xx_t *lbus = &immap->lbus;
231
232 lbus->bank[3].br = CFG_BR3_PRELIM;
233 lbus->bank[3].or = CFG_OR3_PRELIM;
234
235 /* Program the MAMR. RFEN=0, OP=00, UWPL=1, AM=000, DS=01, G0CL=000,
236 GPL4=0, RLF=0001, WLF=0001, TLF=0001, MAD=000000
237 */
238 lbus->mamr = 0x08404440;
239
240 upmconfig(0, UPMATable, sizeof(UPMATable) / sizeof(UPMATable[0]));
241
242 puts("UPMA: Configured for compact flash\n");
243#endif
244
245 return 0;
246}
247
Timur Tabiab347542006-11-03 19:15:00 -0600248/*
Timur Tabi054838e2006-10-31 18:44:42 -0600249 * Make sure the EEPROM has the HRCW correctly programmed.
250 * Make sure the RTC is correctly programmed.
251 *
252 * The MPC8349E-mITX can be configured to load the HRCW from
253 * EEPROM instead of flash. This is controlled via jumpers
254 * LGPL0, 1, and 3. Normally, these jumpers are set to 000 (all
255 * jumpered), but if they're set to 001 or 010, then the HRCW is
256 * read from the "I2C EEPROM".
257 *
258 * This function makes sure that the I2C EEPROM is programmed
259 * correctly.
260 */
261int misc_init_r(void)
262{
263 int rc = 0;
264
265#ifdef CONFIG_HARD_I2C
266
Sam Songb7bf05c2006-12-14 19:03:21 +0800267 unsigned int orig_bus = i2c_get_bus_num();
Timur Tabiab347542006-11-03 19:15:00 -0600268 u8 i2c_data;
Timur Tabi054838e2006-10-31 18:44:42 -0600269
270#ifdef CFG_I2C_RTC_ADDR
Timur Tabiff0215a2006-11-28 12:09:35 -0600271 u8 ds1339_data[17];
Timur Tabi054838e2006-10-31 18:44:42 -0600272#endif
273
274#ifdef CFG_I2C_EEPROM_ADDR
275 static u8 eeprom_data[] = /* HRCW data */
276 {
Timur Tabi435e3a72007-01-31 15:54:29 -0600277 0xAA, 0x55, 0xAA, /* Preamble */
278 0x7C, /* ACS=0, BYTE_EN=1111, CONT=1 */
279 0x02, 0x40, /* RCWL ADDR=0x0_0900 */
280 (CFG_HRCW_LOW >> 24) & 0xFF,
281 (CFG_HRCW_LOW >> 16) & 0xFF,
282 (CFG_HRCW_LOW >> 8) & 0xFF,
283 CFG_HRCW_LOW & 0xFF,
284 0x7C, /* ACS=0, BYTE_EN=1111, CONT=1 */
285 0x02, 0x41, /* RCWH ADDR=0x0_0904 */
286 (CFG_HRCW_HIGH >> 24) & 0xFF,
287 (CFG_HRCW_HIGH >> 16) & 0xFF,
288 (CFG_HRCW_HIGH >> 8) & 0xFF,
289 CFG_HRCW_HIGH & 0xFF
Timur Tabi054838e2006-10-31 18:44:42 -0600290 };
291
292 u8 data[sizeof(eeprom_data)];
Timur Tabiab347542006-11-03 19:15:00 -0600293#endif
Timur Tabi054838e2006-10-31 18:44:42 -0600294
Timur Tabiab347542006-11-03 19:15:00 -0600295 printf("Board revision: ");
Timur Tabic0b114a2006-10-31 21:23:16 -0600296 i2c_set_bus_num(1);
Timur Tabiab347542006-11-03 19:15:00 -0600297 if (i2c_read(CFG_I2C_8574A_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
298 printf("%u.%u (PCF8475A)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
299 else if (i2c_read(CFG_I2C_8574_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
300 printf("%u.%u (PCF8475)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
301 else {
302 printf("Unknown\n");
303 rc = 1;
304 }
305
306#ifdef CFG_I2C_EEPROM_ADDR
307 i2c_set_bus_num(0);
Timur Tabi054838e2006-10-31 18:44:42 -0600308
309 if (i2c_read(CFG_I2C_EEPROM_ADDR, 0, 2, data, sizeof(data)) == 0) {
310 if (memcmp(data, eeprom_data, sizeof(data)) != 0) {
311 if (i2c_write
312 (CFG_I2C_EEPROM_ADDR, 0, 2, eeprom_data,
313 sizeof(eeprom_data)) != 0) {
314 puts("Failure writing the HRCW to EEPROM via I2C.\n");
315 rc = 1;
316 }
317 }
318 } else {
319 puts("Failure reading the HRCW from EEPROM via I2C.\n");
320 rc = 1;
321 }
322#endif
323
324#ifdef CFG_I2C_RTC_ADDR
Timur Tabiab347542006-11-03 19:15:00 -0600325 i2c_set_bus_num(1);
Timur Tabi054838e2006-10-31 18:44:42 -0600326
327 if (i2c_read(CFG_I2C_RTC_ADDR, 0, 1, ds1339_data, sizeof(ds1339_data))
328 == 0) {
329
330 /* Work-around for MPC8349E-mITX bug #13601.
331 If the RTC does not contain valid register values, the DS1339
332 Linux driver will not work.
333 */
334
335 /* Make sure status register bits 6-2 are zero */
336 ds1339_data[0x0f] &= ~0x7c;
337
338 /* Check for a valid day register value */
339 ds1339_data[0x03] &= ~0xf8;
340 if (ds1339_data[0x03] == 0) {
341 ds1339_data[0x03] = 1;
342 }
343
344 /* Check for a valid date register value */
345 ds1339_data[0x04] &= ~0xc0;
346 if ((ds1339_data[0x04] == 0) ||
347 ((ds1339_data[0x04] & 0x0f) > 9) ||
348 (ds1339_data[0x04] >= 0x32)) {
349 ds1339_data[0x04] = 1;
350 }
351
352 /* Check for a valid month register value */
353 ds1339_data[0x05] &= ~0x60;
354
355 if ((ds1339_data[0x05] == 0) ||
356 ((ds1339_data[0x05] & 0x0f) > 9) ||
357 ((ds1339_data[0x05] >= 0x13)
358 && (ds1339_data[0x05] <= 0x19))) {
359 ds1339_data[0x05] = 1;
360 }
361
362 /* Enable Oscillator and rate select */
363 ds1339_data[0x0e] = 0x1c;
364
365 /* Work-around for MPC8349E-mITX bug #13330.
366 Ensure that the RTC control register contains the value 0x1c.
367 This affects SATA performance.
368 */
369
370 if (i2c_write
371 (CFG_I2C_RTC_ADDR, 0, 1, ds1339_data,
372 sizeof(ds1339_data))) {
373 puts("Failure writing to the RTC via I2C.\n");
374 rc = 1;
375 }
376 } else {
377 puts("Failure reading from the RTC via I2C.\n");
378 rc = 1;
379 }
380#endif
381
382 i2c_set_bus_num(orig_bus);
383#endif
384
385 return rc;
386}
Kim Phillips774e1b52006-11-01 00:10:40 -0600387
388#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
389void
390ft_board_setup(void *blob, bd_t *bd)
391{
392 u32 *p;
393 int len;
394
395#ifdef CONFIG_PCI
396 ft_pci_setup(blob, bd);
397#endif
398 ft_cpu_setup(blob, bd);
399
400 p = ft_get_prop(blob, "/memory/reg", &len);
401 if (p != NULL) {
402 *p++ = cpu_to_be32(bd->bi_memstart);
403 *p = cpu_to_be32(bd->bi_memsize);
404 }
405}
406#endif