blob: 4838e707f095dbb77428b0ccfb3552c07dcfe37d [file] [log] [blame]
Timur Tabi2ad6b512006-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 Phillipsbf0b5422006-11-01 00:10:40 -060040#if defined(CONFIG_OF_FLAT_TREE)
41#include <ft_build.h>
42#endif
Timur Tabi2ad6b512006-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 Tabid239d742006-11-03 12:00:28 -060050 volatile immap_t *im = (immap_t *) CFG_IMMR;
Timur Tabi2ad6b512006-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);
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
Timur Tabibe5e6182006-11-03 19:15:00 -0600137/* If MPC8349E-mITX is soldered with SDRAM, then initialize it. */
Timur Tabi2ad6b512006-10-31 18:44:42 -0600138
139void sdram_init(void)
140{
Timur Tabid239d742006-11-03 12:00:28 -0600141 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600142 volatile lbus83xx_t *lbc = &immap->lbus;
143
144#if defined(CFG_BR2_PRELIM) \
145 && defined(CFG_OR2_PRELIM) \
146 && defined(CFG_LBLAWBAR2_PRELIM) \
147 && defined(CFG_LBLAWAR2_PRELIM) \
148 && !defined(CONFIG_COMPACT_FLASH)
149
150 uint *sdram_addr = (uint *) CFG_LBC_SDRAM_BASE;
151
152 puts("\n SDRAM on Local Bus: ");
153 print_size(CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
154
155 /*
156 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
157 */
158
159 /*setup mtrpt, lsrt and lbcr for LB bus */
160 lbc->lbcr = CFG_LBC_LBCR;
161 lbc->mrtpr = CFG_LBC_MRTPR;
162 lbc->lsrt = CFG_LBC_LSRT;
163 asm("sync");
164
165 /*
166 * Configure the SDRAM controller Machine Mode register.
167 */
168 lbc->lsdmr = CFG_LBC_LSDMR_5; /* 0x40636733; normal operation */
169
170 lbc->lsdmr = CFG_LBC_LSDMR_1; /*0x68636733; precharge all the banks */
171 asm("sync");
172 *sdram_addr = 0xff;
173 udelay(100);
174
175 lbc->lsdmr = CFG_LBC_LSDMR_2; /*0x48636733; auto refresh */
176 asm("sync");
177 *sdram_addr = 0xff; /*1 time*/
178 udelay(100);
179 *sdram_addr = 0xff; /*2 times*/
180 udelay(100);
181 *sdram_addr = 0xff; /*3 times*/
182 udelay(100);
183 *sdram_addr = 0xff; /*4 times*/
184 udelay(100);
185 *sdram_addr = 0xff; /*5 times*/
186 udelay(100);
187 *sdram_addr = 0xff; /*6 times*/
188 udelay(100);
189 *sdram_addr = 0xff; /*7 times*/
190 udelay(100);
191 *sdram_addr = 0xff; /*8 times*/
192 udelay(100);
193
194 lbc->lsdmr = CFG_LBC_LSDMR_4; /*0x58636733;mode register write operation */
195 asm("sync");
196 *sdram_addr = 0xff;
197 udelay(100);
198
199 lbc->lsdmr = CFG_LBC_LSDMR_5; /*0x40636733;normal operation */
200 asm("sync");
201 *sdram_addr = 0xff;
202 udelay(100);
203
204#else
205 puts("SDRAM on Local Bus is NOT available!\n");
206
207#ifdef CFG_BR2_PRELIM
208 lbc->bank[2].br = CFG_BR2_PRELIM;
209 lbc->bank[2].or = CFG_OR2_PRELIM;
210#endif
211
212#ifdef CFG_BR3_PRELIM
213 lbc->bank[3].br = CFG_BR3_PRELIM;
214 lbc->bank[3].or = CFG_OR3_PRELIM;
215#endif
216#endif
217}
218
219long int initdram(int board_type)
220{
Timur Tabid239d742006-11-03 12:00:28 -0600221 volatile immap_t *im = (immap_t *) CFG_IMMR;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600222 u32 msize = 0;
223#ifdef CONFIG_DDR_ECC
224 volatile ddr83xx_t *ddr = &im->ddr;
225#endif
226
227 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
228 return -1;
229
230 /* DDR SDRAM - Main SODIMM */
231 im->sysconf.ddrlaw[0].bar = CFG_DDR_BASE & LAWBAR_BAR;
232#ifdef CONFIG_SPD_EEPROM
233 msize = spd_sdram();
234#else
235 msize = fixed_sdram();
236#endif
237
238#ifdef CONFIG_DDR_ECC
239 if (ddr->sdram_cfg & SDRAM_CFG_ECC_EN)
240 /* Unlike every other board, on the 83xx spd_sdram() returns
241 megabytes instead of just bytes. That's why we need to
242 multiple by 1MB when calling ddr_enable_ecc(). */
243 ddr_enable_ecc(msize * 1048576);
244#endif
245
246 /*
247 * Initialize SDRAM if it is on local bus.
248 */
249 sdram_init();
250 puts(" DDR RAM: ");
251 /* return total bus SDRAM size(bytes) -- DDR */
252 return msize * 1024 * 1024;
253}
254
255int checkboard(void)
256{
Timur Tabibe5e6182006-11-03 19:15:00 -0600257 puts("Board: Freescale MPC8349E-mITX\n");
Timur Tabi2ad6b512006-10-31 18:44:42 -0600258
259 return 0;
260}
261
Timur Tabibe5e6182006-11-03 19:15:00 -0600262/*
Timur Tabi2ad6b512006-10-31 18:44:42 -0600263 * Implement a work-around for a hardware problem with compact
264 * flash.
265 *
266 * Program the UPM if compact flash is enabled.
267 */
268int misc_init_f(void)
269{
270 volatile u32 *vsc7385_cpuctrl;
271
272 /* 0x1c0c0 is the VSC7385 CPU Control (CPUCTRL) Register. The power up
273 default of VSC7385 L1_IRQ and L2_IRQ requests are active high. That
274 means it is 0 when the IRQ is not active. This makes the wire-AND
275 logic always assert IRQ7 to CPU even if there is no request from the
276 switch. Since the compact flash and the switch share the same IRQ,
277 the Linux kernel will think that the compact flash is requesting irq
278 and get stuck when it tries to clear the IRQ. Thus we need to set
279 the L2_IRQ0 and L2_IRQ1 to active low.
280
281 The following code sets the L1_IRQ and L2_IRQ polarity to active low.
282 Without this code, compact flash will not work in Linux because
283 unlike U-Boot, Linux uses the IRQ, so this code is necessary if we
284 don't enable compact flash for U-Boot.
285 */
286
287 vsc7385_cpuctrl = (volatile u32 *)(CFG_VSC7385_BASE + 0x1c0c0);
288 *vsc7385_cpuctrl |= 0x0c;
289
290#ifdef CONFIG_COMPACT_FLASH
291 /* UPM Table Configuration Code */
292 static uint UPMATable[] = {
293 0xcffffc00, 0x0fffff00, 0x0fafff00, 0x0fafff00,
294 0x0faffd00, 0x0faffc04, 0x0ffffc00, 0x3ffffc01,
295 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
296 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
297 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfff7fc00,
298 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
299 0xcffffc00, 0x0fffff00, 0x0ff3ff00, 0x0ff3ff00,
300 0x0ff3fe00, 0x0ffffc00, 0x3ffffc05, 0xfffffc00,
301 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
302 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
303 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
304 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
305 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
306 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
307 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
308 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01
309 };
Timur Tabid239d742006-11-03 12:00:28 -0600310 volatile immap_t *immap = (immap_t *) CFG_IMMR;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600311 volatile lbus83xx_t *lbus = &immap->lbus;
312
313 lbus->bank[3].br = CFG_BR3_PRELIM;
314 lbus->bank[3].or = CFG_OR3_PRELIM;
315
316 /* Program the MAMR. RFEN=0, OP=00, UWPL=1, AM=000, DS=01, G0CL=000,
317 GPL4=0, RLF=0001, WLF=0001, TLF=0001, MAD=000000
318 */
319 lbus->mamr = 0x08404440;
320
321 upmconfig(0, UPMATable, sizeof(UPMATable) / sizeof(UPMATable[0]));
322
323 puts("UPMA: Configured for compact flash\n");
324#endif
325
326 return 0;
327}
328
Timur Tabibe5e6182006-11-03 19:15:00 -0600329/*
Timur Tabi2ad6b512006-10-31 18:44:42 -0600330 * Make sure the EEPROM has the HRCW correctly programmed.
331 * Make sure the RTC is correctly programmed.
332 *
333 * The MPC8349E-mITX can be configured to load the HRCW from
334 * EEPROM instead of flash. This is controlled via jumpers
335 * LGPL0, 1, and 3. Normally, these jumpers are set to 000 (all
336 * jumpered), but if they're set to 001 or 010, then the HRCW is
337 * read from the "I2C EEPROM".
338 *
339 * This function makes sure that the I2C EEPROM is programmed
340 * correctly.
341 */
342int misc_init_r(void)
343{
344 int rc = 0;
345
346#ifdef CONFIG_HARD_I2C
347
Timur Tabibe5e6182006-11-03 19:15:00 -0600348 unsigned int orig_bus = i2c_get_bus_num();;
349 u8 i2c_data;
Timur Tabi2ad6b512006-10-31 18:44:42 -0600350
351#ifdef CFG_I2C_RTC_ADDR
Timur Tabie857a5b2006-11-28 12:09:35 -0600352 u8 ds1339_data[17];
Timur Tabi2ad6b512006-10-31 18:44:42 -0600353#endif
354
355#ifdef CFG_I2C_EEPROM_ADDR
356 static u8 eeprom_data[] = /* HRCW data */
357 {
358 0xaa, 0x55, 0xaa,
359 0x7c, 0x02, 0x40, 0x05, 0x04, 0x00, 0x00,
360 0x7c, 0x02, 0x41, 0xb4, 0x60, 0xa0, 0x00,
361 };
362
363 u8 data[sizeof(eeprom_data)];
Timur Tabibe5e6182006-11-03 19:15:00 -0600364#endif
Timur Tabi2ad6b512006-10-31 18:44:42 -0600365
Timur Tabibe5e6182006-11-03 19:15:00 -0600366 printf("Board revision: ");
Timur Tabi9ca880a2006-10-31 21:23:16 -0600367 i2c_set_bus_num(1);
Timur Tabibe5e6182006-11-03 19:15:00 -0600368 if (i2c_read(CFG_I2C_8574A_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
369 printf("%u.%u (PCF8475A)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
370 else if (i2c_read(CFG_I2C_8574_ADDR2, 0, 0, &i2c_data, sizeof(i2c_data)) == 0)
371 printf("%u.%u (PCF8475)\n", (i2c_data & 0x02) >> 1, i2c_data & 0x01);
372 else {
373 printf("Unknown\n");
374 rc = 1;
375 }
376
377#ifdef CFG_I2C_EEPROM_ADDR
378 i2c_set_bus_num(0);
Timur Tabi2ad6b512006-10-31 18:44:42 -0600379
380 if (i2c_read(CFG_I2C_EEPROM_ADDR, 0, 2, data, sizeof(data)) == 0) {
381 if (memcmp(data, eeprom_data, sizeof(data)) != 0) {
382 if (i2c_write
383 (CFG_I2C_EEPROM_ADDR, 0, 2, eeprom_data,
384 sizeof(eeprom_data)) != 0) {
385 puts("Failure writing the HRCW to EEPROM via I2C.\n");
386 rc = 1;
387 }
388 }
389 } else {
390 puts("Failure reading the HRCW from EEPROM via I2C.\n");
391 rc = 1;
392 }
393#endif
394
395#ifdef CFG_I2C_RTC_ADDR
Timur Tabibe5e6182006-11-03 19:15:00 -0600396 i2c_set_bus_num(1);
Timur Tabi2ad6b512006-10-31 18:44:42 -0600397
398 if (i2c_read(CFG_I2C_RTC_ADDR, 0, 1, ds1339_data, sizeof(ds1339_data))
399 == 0) {
400
401 /* Work-around for MPC8349E-mITX bug #13601.
402 If the RTC does not contain valid register values, the DS1339
403 Linux driver will not work.
404 */
405
406 /* Make sure status register bits 6-2 are zero */
407 ds1339_data[0x0f] &= ~0x7c;
408
409 /* Check for a valid day register value */
410 ds1339_data[0x03] &= ~0xf8;
411 if (ds1339_data[0x03] == 0) {
412 ds1339_data[0x03] = 1;
413 }
414
415 /* Check for a valid date register value */
416 ds1339_data[0x04] &= ~0xc0;
417 if ((ds1339_data[0x04] == 0) ||
418 ((ds1339_data[0x04] & 0x0f) > 9) ||
419 (ds1339_data[0x04] >= 0x32)) {
420 ds1339_data[0x04] = 1;
421 }
422
423 /* Check for a valid month register value */
424 ds1339_data[0x05] &= ~0x60;
425
426 if ((ds1339_data[0x05] == 0) ||
427 ((ds1339_data[0x05] & 0x0f) > 9) ||
428 ((ds1339_data[0x05] >= 0x13)
429 && (ds1339_data[0x05] <= 0x19))) {
430 ds1339_data[0x05] = 1;
431 }
432
433 /* Enable Oscillator and rate select */
434 ds1339_data[0x0e] = 0x1c;
435
436 /* Work-around for MPC8349E-mITX bug #13330.
437 Ensure that the RTC control register contains the value 0x1c.
438 This affects SATA performance.
439 */
440
441 if (i2c_write
442 (CFG_I2C_RTC_ADDR, 0, 1, ds1339_data,
443 sizeof(ds1339_data))) {
444 puts("Failure writing to the RTC via I2C.\n");
445 rc = 1;
446 }
447 } else {
448 puts("Failure reading from the RTC via I2C.\n");
449 rc = 1;
450 }
451#endif
452
453 i2c_set_bus_num(orig_bus);
454#endif
455
456 return rc;
457}
Kim Phillipsbf0b5422006-11-01 00:10:40 -0600458
459#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
460void
461ft_board_setup(void *blob, bd_t *bd)
462{
463 u32 *p;
464 int len;
465
466#ifdef CONFIG_PCI
467 ft_pci_setup(blob, bd);
468#endif
469 ft_cpu_setup(blob, bd);
470
471 p = ft_get_prop(blob, "/memory/reg", &len);
472 if (p != NULL) {
473 *p++ = cpu_to_be32(bd->bi_memstart);
474 *p = cpu_to_be32(bd->bi_memsize);
475 }
476}
477#endif