blob: 9fce973df0c9840c02b8340cd7c0a90391a3c5d1 [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{
50 volatile immap_t *im = (immap_t *) CFG_IMMRBAR;
51 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);
83 im->ddr.sdram_clk_cntl =
84 DDR_SDRAM_CLK_CNTL_SS_EN | DDR_SDRAM_CLK_CNTL_CLK_ADJUST_05;
85
86 udelay(200);
87
88 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
89
90 debug("DDR:timing_cfg_1=0x%08x\n", im->ddr.timing_cfg_1);
91 debug("DDR:timing_cfg_2=0x%08x\n", im->ddr.timing_cfg_2);
92 debug("DDR:sdram_mode=0x%08x\n", im->ddr.sdram_mode);
93 debug("DDR:sdram_interval=0x%08x\n", im->ddr.sdram_interval);
94 debug("DDR:sdram_cfg=0x%08x\n", im->ddr.sdram_cfg);
95
96 return CFG_DDR_SIZE;
97}
98#endif
99
100#ifdef CONFIG_PCI
101/*
102 * Initialize PCI Devices, report devices found
103 */
104#ifndef CONFIG_PCI_PNP
105static struct pci_config_table pci_mpc83xxmitx_config_table[] = {
106 {
107 PCI_ANY_ID,
108 PCI_ANY_ID,
109 PCI_ANY_ID,
110 PCI_ANY_ID,
111 0x0f,
112 PCI_ANY_ID,
113 pci_cfgfunc_config_device,
114 {
115 PCI_ENET0_IOADDR,
116 PCI_ENET0_MEMADDR,
117 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}
118 },
119 {}
120}
121#endif
122
123volatile static struct pci_controller hose[] = {
124 {
125#ifndef CONFIG_PCI_PNP
126 config_table:pci_mpc83xxmitx_config_table,
127#endif
128 },
129 {
130#ifndef CONFIG_PCI_PNP
131 config_table:pci_mpc83xxmitx_config_table,
132#endif
133 }
134};
135#endif /* CONFIG_PCI */
136
137/* If MPC8349E-mITX is soldered with SDRAM, then initialize it.
138*/
139
140void sdram_init(void)
141{
142 volatile immap_t *immap = (immap_t *) CFG_IMMRBAR;
143 volatile lbus83xx_t *lbc = &immap->lbus;
144
145#if defined(CFG_BR2_PRELIM) \
146 && defined(CFG_OR2_PRELIM) \
147 && defined(CFG_LBLAWBAR2_PRELIM) \
148 && defined(CFG_LBLAWAR2_PRELIM) \
149 && !defined(CONFIG_COMPACT_FLASH)
150
151 uint *sdram_addr = (uint *) CFG_LBC_SDRAM_BASE;
152
153 puts("\n SDRAM on Local Bus: ");
154 print_size(CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
155
156 /*
157 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
158 */
159
160 /*setup mtrpt, lsrt and lbcr for LB bus */
161 lbc->lbcr = CFG_LBC_LBCR;
162 lbc->mrtpr = CFG_LBC_MRTPR;
163 lbc->lsrt = CFG_LBC_LSRT;
164 asm("sync");
165
166 /*
167 * Configure the SDRAM controller Machine Mode register.
168 */
169 lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
170
171 lbc->lsdmr = CFG_LBC_LSDMR_1; /*0x68636733; precharge all the banks */
172 asm("sync");
173 *sdram_addr = 0xff;
174 udelay(100);
175
176 lbc->lsdmr = CFG_LBC_LSDMR_2; /*0x48636733; auto refresh */
177 asm("sync");
178 *sdram_addr = 0xff; /*1 time*/
179 udelay(100);
180 *sdram_addr = 0xff; /*2 times*/
181 udelay(100);
182 *sdram_addr = 0xff; /*3 times*/
183 udelay(100);
184 *sdram_addr = 0xff; /*4 times*/
185 udelay(100);
186 *sdram_addr = 0xff; /*5 times*/
187 udelay(100);
188 *sdram_addr = 0xff; /*6 times*/
189 udelay(100);
190 *sdram_addr = 0xff; /*7 times*/
191 udelay(100);
192 *sdram_addr = 0xff; /*8 times*/
193 udelay(100);
194
195 lbc->lsdmr = CFG_LBC_LSDMR_4; /*0x58636733;mode register write operation */
196 asm("sync");
197 *sdram_addr = 0xff;
198 udelay(100);
199
200 lbc->lsdmr = CFG_LBC_LSDMR_5; /*0x40636733;normal operation */
201 asm("sync");
202 *sdram_addr = 0xff;
203 udelay(100);
204
205#else
206 puts("SDRAM on Local Bus is NOT available!\n");
207
208#ifdef CFG_BR2_PRELIM
209 lbc->bank[2].br = CFG_BR2_PRELIM;
210 lbc->bank[2].or = CFG_OR2_PRELIM;
211#endif
212
213#ifdef CFG_BR3_PRELIM
214 lbc->bank[3].br = CFG_BR3_PRELIM;
215 lbc->bank[3].or = CFG_OR3_PRELIM;
216#endif
217#endif
218}
219
220long int initdram(int board_type)
221{
222 volatile immap_t *im = (immap_t *) CFG_IMMRBAR;
223 u32 msize = 0;
224#ifdef CONFIG_DDR_ECC
225 volatile ddr83xx_t *ddr = &im->ddr;
226#endif
227
228 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
229 return -1;
230
231 /* DDR SDRAM - Main SODIMM */
232 im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
233#ifdef CONFIG_SPD_EEPROM
234 msize = spd_sdram();
235#else
236 msize = fixed_sdram();
237#endif
238
239#ifdef CONFIG_DDR_ECC
240 if (ddr->sdram_cfg & SDRAM_CFG_ECC_EN)
241 /* Unlike every other board, on the 83xx spd_sdram() returns
242 megabytes instead of just bytes. That's why we need to
243 multiple by 1MB when calling ddr_enable_ecc(). */
244 ddr_enable_ecc(msize * 1048576);
245#endif
246
247 /*
248 * Initialize SDRAM if it is on local bus.
249 */
250 sdram_init();
251 puts(" DDR RAM: ");
252 /* return total bus SDRAM size(bytes) -- DDR */
253 return msize * 1024 * 1024;
254}
255
256int checkboard(void)
257{
258#ifdef CONFIG_HARD_I2C
259 u8 i2c_data;
260#endif
261
262 puts("Board: Freescale MPC8349E-mITX");
263
264#ifdef CONFIG_HARD_I2C
Timur Tabic0b114a2006-10-31 21:23:16 -0600265 i2c_set_bus_num(2);
Timur Tabi054838e2006-10-31 18:44:42 -0600266 if (i2c_read(CFG_I2C_8574A_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) ==
267 0)
268 printf(" %u.%u (PCF8475A)", (i2c_data & 0x02) >> 1,
269 i2c_data & 0x01);
270 else if (i2c_read(CFG_I2C_8574_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data))
271 == 0)
272 printf(" %u.%u (PCF8475)", (i2c_data & 0x02) >> 1,
273 i2c_data & 0x01);
274 else
275 printf(" ?.?");
276#endif
277
278 puts("\n");
279
280 return 0;
281}
282
283/**
284 * Implement a work-around for a hardware problem with compact
285 * flash.
286 *
287 * Program the UPM if compact flash is enabled.
288 */
289int misc_init_f(void)
290{
291 volatile u32 *vsc7385_cpuctrl;
292
293 /* 0x1c0c0 is the VSC7385 CPU Control (CPUCTRL) Register. The power up
294 default of VSC7385 L1_IRQ and L2_IRQ requests are active high. That
295 means it is 0 when the IRQ is not active. This makes the wire-AND
296 logic always assert IRQ7 to CPU even if there is no request from the
297 switch. Since the compact flash and the switch share the same IRQ,
298 the Linux kernel will think that the compact flash is requesting irq
299 and get stuck when it tries to clear the IRQ. Thus we need to set
300 the L2_IRQ0 and L2_IRQ1 to active low.
301
302 The following code sets the L1_IRQ and L2_IRQ polarity to active low.
303 Without this code, compact flash will not work in Linux because
304 unlike U-Boot, Linux uses the IRQ, so this code is necessary if we
305 don't enable compact flash for U-Boot.
306 */
307
308 vsc7385_cpuctrl = (volatile u32 *)(CFG_VSC7385_BASE + 0x1c0c0);
309 *vsc7385_cpuctrl |= 0x0c;
310
311#ifdef CONFIG_COMPACT_FLASH
312 /* UPM Table Configuration Code */
313 static uint UPMATable[] = {
314 0xcffffc00, 0x0fffff00, 0x0fafff00, 0x0fafff00,
315 0x0faffd00, 0x0faffc04, 0x0ffffc00, 0x3ffffc01,
316 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
317 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
318 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfff7fc00,
319 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
320 0xcffffc00, 0x0fffff00, 0x0ff3ff00, 0x0ff3ff00,
321 0x0ff3fe00, 0x0ffffc00, 0x3ffffc05, 0xfffffc00,
322 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
323 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
324 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
325 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
326 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
327 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
328 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
329 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01
330 };
331 volatile immap_t *immap = (immap_t *) CFG_IMMRBAR;
332 volatile lbus83xx_t *lbus = &immap->lbus;
333
334 lbus->bank[3].br = CFG_BR3_PRELIM;
335 lbus->bank[3].or = CFG_OR3_PRELIM;
336
337 /* Program the MAMR. RFEN=0, OP=00, UWPL=1, AM=000, DS=01, G0CL=000,
338 GPL4=0, RLF=0001, WLF=0001, TLF=0001, MAD=000000
339 */
340 lbus->mamr = 0x08404440;
341
342 upmconfig(0, UPMATable, sizeof(UPMATable) / sizeof(UPMATable[0]));
343
344 puts("UPMA: Configured for compact flash\n");
345#endif
346
347 return 0;
348}
349
350/**
351 * Make sure the EEPROM has the HRCW correctly programmed.
352 * Make sure the RTC is correctly programmed.
353 *
354 * The MPC8349E-mITX can be configured to load the HRCW from
355 * EEPROM instead of flash. This is controlled via jumpers
356 * LGPL0, 1, and 3. Normally, these jumpers are set to 000 (all
357 * jumpered), but if they're set to 001 or 010, then the HRCW is
358 * read from the "I2C EEPROM".
359 *
360 * This function makes sure that the I2C EEPROM is programmed
361 * correctly.
362 */
363int misc_init_r(void)
364{
365 int rc = 0;
366
367#ifdef CONFIG_HARD_I2C
368
369 uchar orig_bus = i2c_get_bus_num();;
370
371#ifdef CFG_I2C_RTC_ADDR
372 char ds1339_data[17];
373#endif
374
375#ifdef CFG_I2C_EEPROM_ADDR
376 static u8 eeprom_data[] = /* HRCW data */
377 {
378 0xaa, 0x55, 0xaa,
379 0x7c, 0x02, 0x40, 0x05, 0x04, 0x00, 0x00,
380 0x7c, 0x02, 0x41, 0xb4, 0x60, 0xa0, 0x00,
381 };
382
383 u8 data[sizeof(eeprom_data)];
384
Timur Tabic0b114a2006-10-31 21:23:16 -0600385 i2c_set_bus_num(1);
Timur Tabi054838e2006-10-31 18:44:42 -0600386
387 if (i2c_read(CFG_I2C_EEPROM_ADDR, 0, 2, data, sizeof(data)) == 0) {
388 if (memcmp(data, eeprom_data, sizeof(data)) != 0) {
389 if (i2c_write
390 (CFG_I2C_EEPROM_ADDR, 0, 2, eeprom_data,
391 sizeof(eeprom_data)) != 0) {
392 puts("Failure writing the HRCW to EEPROM via I2C.\n");
393 rc = 1;
394 }
395 }
396 } else {
397 puts("Failure reading the HRCW from EEPROM via I2C.\n");
398 rc = 1;
399 }
400#endif
401
402#ifdef CFG_I2C_RTC_ADDR
Timur Tabic0b114a2006-10-31 21:23:16 -0600403 i2c_set_bus_num(2);
Timur Tabi054838e2006-10-31 18:44:42 -0600404
405 if (i2c_read(CFG_I2C_RTC_ADDR, 0, 1, ds1339_data, sizeof(ds1339_data))
406 == 0) {
407
408 /* Work-around for MPC8349E-mITX bug #13601.
409 If the RTC does not contain valid register values, the DS1339
410 Linux driver will not work.
411 */
412
413 /* Make sure status register bits 6-2 are zero */
414 ds1339_data[0x0f] &= ~0x7c;
415
416 /* Check for a valid day register value */
417 ds1339_data[0x03] &= ~0xf8;
418 if (ds1339_data[0x03] == 0) {
419 ds1339_data[0x03] = 1;
420 }
421
422 /* Check for a valid date register value */
423 ds1339_data[0x04] &= ~0xc0;
424 if ((ds1339_data[0x04] == 0) ||
425 ((ds1339_data[0x04] & 0x0f) > 9) ||
426 (ds1339_data[0x04] >= 0x32)) {
427 ds1339_data[0x04] = 1;
428 }
429
430 /* Check for a valid month register value */
431 ds1339_data[0x05] &= ~0x60;
432
433 if ((ds1339_data[0x05] == 0) ||
434 ((ds1339_data[0x05] & 0x0f) > 9) ||
435 ((ds1339_data[0x05] >= 0x13)
436 && (ds1339_data[0x05] <= 0x19))) {
437 ds1339_data[0x05] = 1;
438 }
439
440 /* Enable Oscillator and rate select */
441 ds1339_data[0x0e] = 0x1c;
442
443 /* Work-around for MPC8349E-mITX bug #13330.
444 Ensure that the RTC control register contains the value 0x1c.
445 This affects SATA performance.
446 */
447
448 if (i2c_write
449 (CFG_I2C_RTC_ADDR, 0, 1, ds1339_data,
450 sizeof(ds1339_data))) {
451 puts("Failure writing to the RTC via I2C.\n");
452 rc = 1;
453 }
454 } else {
455 puts("Failure reading from the RTC via I2C.\n");
456 rc = 1;
457 }
458#endif
459
460 i2c_set_bus_num(orig_bus);
461#endif
462
463 return rc;
464}
Kim Phillips774e1b52006-11-01 00:10:40 -0600465
466#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
467void
468ft_board_setup(void *blob, bd_t *bd)
469{
470 u32 *p;
471 int len;
472
473#ifdef CONFIG_PCI
474 ft_pci_setup(blob, bd);
475#endif
476 ft_cpu_setup(blob, bd);
477
478 p = ft_get_prop(blob, "/memory/reg", &len);
479 if (p != NULL) {
480 *p++ = cpu_to_be32(bd->bi_memstart);
481 *p = cpu_to_be32(bd->bi_memsize);
482 }
483}
484#endif