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