blob: 352226f2050600e3ad363da37bea1dc1a433f887 [file] [log] [blame]
wdenk64519362004-07-11 17:40:54 +00001/*
Wolfgang Denkc98368a2006-07-19 17:52:30 +02002 * (C) Copyright 2003-2006
wdenk64519362004-07-11 17:40:54 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2004
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
7 *
Wolfgang Denkc98368a2006-07-19 17:52:30 +02008 * (C) Copyright 2004-2006
wdenk64519362004-07-11 17:40:54 +00009 * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
10 *
11 * See file CREDITS for list of people who contributed to this
12 * project.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
wdenk7dd13292004-07-11 20:04:51 +000021 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
wdenk64519362004-07-11 17:40:54 +000022 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
28 */
29
30#include <common.h>
31#include <mpc5xxx.h>
32#include <pci.h>
Wolfgang Denkc98368a2006-07-19 17:52:30 +020033#include <asm/processor.h>
Grant Likely8d1e6e72007-09-06 09:46:23 -060034#include <libfdt.h>
Ben Warrenf2c1acb2008-08-31 10:03:22 -070035#include <netdev.h>
Bartlomiej Sieka7a432ce2007-06-08 14:52:22 +020036
wdenka5948882005-03-27 23:41:39 +000037#ifdef CONFIG_VIDEO_SM501
38#include <sm501.h>
39#endif
40
wdenk64519362004-07-11 17:40:54 +000041#if defined(CONFIG_MPC5200_DDR)
42#include "mt46v16m16-75.h"
43#else
44#include "mt48lc16m16a2-75.h"
45#endif
wdenka5948882005-03-27 23:41:39 +000046
Martin Krause3b09b9d2008-02-25 17:52:40 +010047#ifdef CONFIG_OF_LIBFDT
48#include <fdt_support.h>
49#endif /* CONFIG_OF_LIBFDT */
50
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020051DECLARE_GLOBAL_DATA_PTR;
52
wdenkdc130442004-12-12 22:06:17 +000053#ifdef CONFIG_PS2MULT
54void ps2mult_early_init(void);
55#endif
wdenk64519362004-07-11 17:40:54 +000056
Wolfgang Denk3c0d4872010-12-23 19:57:31 +010057#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) && \
58 defined(CONFIG_VIDEO)
Heiko Schocher1ae91442010-12-04 08:34:04 +010059/*
60 * EDID block has been generated using Phoenix EDID Designer 1.3.
61 * This tool creates a text file containing:
62 *
63 * EDID BYTES:
64 *
65 * 0x 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
66 * ------------------------------------------------
67 * 00 | 00 FF FF FF FF FF FF 00 04 21 00 00 00 00 00 00
68 * 10 | 01 00 01 03 00 00 00 00 00 00 00 00 00 00 00 00
69 * 20 | 00 00 00 21 00 00 01 01 01 01 01 01 01 01 01 01
70 * 30 | 01 01 01 01 01 01 64 00 00 00 00 00 00 00 00 00
71 * 40 | 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00
72 * 50 | 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00
73 * 60 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10
74 * 70 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17
75 *
76 * Then this data has been manually converted to the char
77 * array below.
78 */
79static unsigned char edid_buf[128] = {
80 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
81 0x04, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82 0x01, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x01, 0x01,
85 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
86 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x64, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
89 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17,
96};
97#endif
98
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020099#ifndef CONFIG_SYS_RAMBOOT
wdenk64519362004-07-11 17:40:54 +0000100static void sdram_start (int hi_addr)
101{
102 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
103
104 /* unlock mode register */
105 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 |
106 hi_addr_bit;
107 __asm__ volatile ("sync");
108
109 /* precharge all banks */
110 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
111 hi_addr_bit;
112 __asm__ volatile ("sync");
113
114#if SDRAM_DDR
115 /* set mode register: extended mode */
116 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
117 __asm__ volatile ("sync");
118
119 /* set mode register: reset DLL */
120 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
121 __asm__ volatile ("sync");
122#endif
123
124 /* precharge all banks */
125 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
126 hi_addr_bit;
127 __asm__ volatile ("sync");
128
129 /* auto refresh */
130 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
131 hi_addr_bit;
132 __asm__ volatile ("sync");
133
134 /* set mode register */
135 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
136 __asm__ volatile ("sync");
137
138 /* normal operation */
139 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
140 __asm__ volatile ("sync");
141}
142#endif
143
144/*
145 * ATTENTION: Although partially referenced initdram does NOT make real use
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200146 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
wdenk7dd13292004-07-11 20:04:51 +0000147 * is something else than 0x00000000.
wdenk64519362004-07-11 17:40:54 +0000148 */
149
Becky Brucebd99ae72008-06-09 16:03:40 -0500150phys_size_t initdram (int board_type)
wdenk64519362004-07-11 17:40:54 +0000151{
152 ulong dramsize = 0;
153 ulong dramsize2 = 0;
Wolfgang Denkc98368a2006-07-19 17:52:30 +0200154 uint svr, pvr;
155
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200156#ifndef CONFIG_SYS_RAMBOOT
wdenk64519362004-07-11 17:40:54 +0000157 ulong test1, test2;
158
159 /* setup SDRAM chip selects */
160 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
161 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
162 __asm__ volatile ("sync");
163
164 /* setup config registers */
165 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
166 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
167 __asm__ volatile ("sync");
168
169#if SDRAM_DDR
170 /* set tap delay */
171 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
172 __asm__ volatile ("sync");
173#endif
174
175 /* find RAM size using SDRAM CS0 only */
176 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200177 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
wdenk64519362004-07-11 17:40:54 +0000178 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200179 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
wdenk64519362004-07-11 17:40:54 +0000180 if (test1 > test2) {
181 sdram_start(0);
182 dramsize = test1;
183 } else {
184 dramsize = test2;
185 }
186
187 /* memory smaller than 1MB is impossible */
188 if (dramsize < (1 << 20)) {
189 dramsize = 0;
190 }
191
192 /* set SDRAM CS0 size according to the amount of RAM found */
193 if (dramsize > 0) {
194 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
195 __builtin_ffs(dramsize >> 20) - 1;
196 } else {
197 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
198 }
199
200 /* let SDRAM CS1 start right after CS0 */
201 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001c; /* 512MB */
202
203 /* find RAM size using SDRAM CS1 only */
Martin Krausec03d80a2008-02-25 13:27:52 +0100204 if (!dramsize)
205 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200206 test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
Martin Krausec03d80a2008-02-25 13:27:52 +0100207 if (!dramsize) {
208 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200209 test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
Martin Krausec03d80a2008-02-25 13:27:52 +0100210 }
wdenk64519362004-07-11 17:40:54 +0000211 if (test1 > test2) {
212 sdram_start(0);
213 dramsize2 = test1;
214 } else {
215 dramsize2 = test2;
216 }
217
218 /* memory smaller than 1MB is impossible */
219 if (dramsize2 < (1 << 20)) {
220 dramsize2 = 0;
221 }
222
223 /* set SDRAM CS1 size according to the amount of RAM found */
224 if (dramsize2 > 0) {
225 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
226 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
227 } else {
228 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
229 }
230
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200231#else /* CONFIG_SYS_RAMBOOT */
wdenk64519362004-07-11 17:40:54 +0000232
233 /* retrieve size of memory connected to SDRAM CS0 */
234 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
235 if (dramsize >= 0x13) {
236 dramsize = (1 << (dramsize - 0x13)) << 20;
237 } else {
238 dramsize = 0;
239 }
240
241 /* retrieve size of memory connected to SDRAM CS1 */
242 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
243 if (dramsize2 >= 0x13) {
244 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
245 } else {
246 dramsize2 = 0;
247 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200248#endif /* CONFIG_SYS_RAMBOOT */
wdenk64519362004-07-11 17:40:54 +0000249
Wolfgang Denkc98368a2006-07-19 17:52:30 +0200250 /*
251 * On MPC5200B we need to set the special configuration delay in the
252 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
253 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
254 *
255 * "The SDelay should be written to a value of 0x00000004. It is
256 * required to account for changes caused by normal wafer processing
257 * parameters."
258 */
259 svr = get_svr();
260 pvr = get_pvr();
261 if ((SVR_MJREV(svr) >= 2) &&
262 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
263
264 *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
265 __asm__ volatile ("sync");
266 }
267
268#if defined(CONFIG_TQM5200_B)
269 return dramsize + dramsize2;
270#else
wdenk64519362004-07-11 17:40:54 +0000271 return dramsize;
Wolfgang Denkc98368a2006-07-19 17:52:30 +0200272#endif /* CONFIG_TQM5200_B */
wdenk64519362004-07-11 17:40:54 +0000273}
274
wdenk64519362004-07-11 17:40:54 +0000275int checkboard (void)
276{
Wolfgang Denk99753142006-07-21 11:16:34 +0200277#if defined(CONFIG_AEVFIFO)
Wolfgang Denkeb95c852005-08-10 15:14:32 +0200278 puts ("Board: AEVFIFO\n");
279 return 0;
280#endif
Wolfgang Denk99753142006-07-21 11:16:34 +0200281
282#if defined(CONFIG_TQM5200S)
283# define MODULE_NAME "TQM5200S"
Wolfgang Denkc98368a2006-07-19 17:52:30 +0200284#else
Wolfgang Denk99753142006-07-21 11:16:34 +0200285# define MODULE_NAME "TQM5200"
wdenkdc130442004-12-12 22:06:17 +0000286#endif
Wolfgang Denk99753142006-07-21 11:16:34 +0200287
288#if defined(CONFIG_STK52XX)
289# define CARRIER_NAME "STK52xx"
290#elif defined(CONFIG_TB5200)
291# define CARRIER_NAME "TB5200"
Wolfgang Denk641e3572006-07-22 01:20:03 +0200292#elif defined(CONFIG_CAM5200)
Wolfgang Denk0129dcd2006-11-23 22:58:58 +0100293# define CARRIER_NAME "CAM5200"
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200294#elif defined(CONFIG_FO300)
295# define CARRIER_NAME "FO300"
Heiko Schocher1ae91442010-12-04 08:34:04 +0100296#elif defined(CONFIG_CHARON)
297# define CARRIER_NAME "CHARON"
Wolfgang Denk99753142006-07-21 11:16:34 +0200298#else
Wolfgang Denk9018bc92006-08-18 23:27:33 +0200299# error "UNKNOWN"
Wolfgang Denkba940932006-07-19 13:50:38 +0200300#endif
wdenkdc130442004-12-12 22:06:17 +0000301
Wolfgang Denk99753142006-07-21 11:16:34 +0200302 puts ( "Board: " MODULE_NAME " (TQ-Components GmbH)\n"
303 " on a " CARRIER_NAME " carrier board\n");
304
wdenk64519362004-07-11 17:40:54 +0000305 return 0;
306}
307
Wolfgang Denk99753142006-07-21 11:16:34 +0200308#undef MODULE_NAME
309#undef CARRIER_NAME
310
wdenk64519362004-07-11 17:40:54 +0000311void flash_preinit(void)
312{
313 /*
314 * Now, when we are in RAM, enable flash write
315 * access for detection process.
316 * Note that CS_BOOT cannot be cleared when
317 * executing in flash.
318 */
wdenk64519362004-07-11 17:40:54 +0000319 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
320}
321
322
323#ifdef CONFIG_PCI
324static struct pci_controller hose;
325
326extern void pci_mpc5xxx_init(struct pci_controller *);
327
328void pci_init_board(void)
329{
330 pci_mpc5xxx_init(&hose);
331}
332#endif
333
Jon Loeliger761ea742007-07-10 10:48:22 -0500334#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
wdenk64519362004-07-11 17:40:54 +0000335
336#if defined (CONFIG_MINIFAP)
337#define SM501_POWER_MODE0_GATE 0x00000040UL
338#define SM501_POWER_MODE1_GATE 0x00000048UL
339#define POWER_MODE_GATE_GPIO_PWM_I2C 0x00000040UL
340#define SM501_GPIO_DATA_DIR_HIGH 0x0001000CUL
341#define SM501_GPIO_DATA_HIGH 0x00010004UL
342#define SM501_GPIO_51 0x00080000UL
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100343#endif /* CONFIG MINIFAP */
wdenk64519362004-07-11 17:40:54 +0000344
345void init_ide_reset (void)
346{
347 debug ("init_ide_reset\n");
348
349#if defined (CONFIG_MINIFAP)
350 /* Configure GPIO_51 of the SM501 grafic controller as ATA reset */
351
352 /* enable GPIO control (in both power modes) */
353 *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE0_GATE) |=
354 POWER_MODE_GATE_GPIO_PWM_I2C;
355 *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE1_GATE) |=
356 POWER_MODE_GATE_GPIO_PWM_I2C;
357 /* configure GPIO51 as output */
358 *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_DIR_HIGH) |=
359 SM501_GPIO_51;
360#else
361 /* Configure PSC1_4 as GPIO output for ATA reset */
362 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
363 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
Martin Krause5f7c6f92008-04-03 14:29:01 +0200364
365 /* by default the ATA reset is de-asserted */
366 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
wdenk64519362004-07-11 17:40:54 +0000367#endif
368}
369
370void ide_set_reset (int idereset)
371{
372 debug ("ide_reset(%d)\n", idereset);
373
374#if defined (CONFIG_MINIFAP)
375 if (idereset) {
376 *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) &=
377 ~SM501_GPIO_51;
378 } else {
379 *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) |=
380 SM501_GPIO_51;
381 }
382#else
383 if (idereset) {
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100384 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
wdenk64519362004-07-11 17:40:54 +0000385 } else {
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100386 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
wdenk64519362004-07-11 17:40:54 +0000387 }
388#endif
389}
Jon Loeliger761ea742007-07-10 10:48:22 -0500390#endif
wdenk64519362004-07-11 17:40:54 +0000391
392#ifdef CONFIG_POST
393/*
394 * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
395 * is left open, no keypress is detected.
396 */
397int post_hotkeys_pressed(void)
398{
Wolfgang Denkf67272a2006-10-09 01:07:53 +0200399#ifdef CONFIG_STK52XX
wdenk64519362004-07-11 17:40:54 +0000400 struct mpc5xxx_gpio *gpio;
401
402 gpio = (struct mpc5xxx_gpio*) MPC5XXX_GPIO;
403
404 /*
Detlev Zundel3ba0fa72009-10-07 16:38:05 +0200405 * Configure PSC6_0 through PSC6_3 as GPIO.
wdenk7dd13292004-07-11 20:04:51 +0000406 */
Detlev Zundel3ba0fa72009-10-07 16:38:05 +0200407 gpio->port_config &= ~(0x00700000);
wdenk64519362004-07-11 17:40:54 +0000408
409 /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
410 gpio->simple_gpioe |= 0x20000000;
411
412 /* Configure GPIO_IRDA_1 as input */
413 gpio->simple_ddr &= ~(0x20000000);
414
415 return ((gpio->simple_ival & 0x20000000) ? 0 : 1);
Wolfgang Denkf67272a2006-10-09 01:07:53 +0200416#else
417 return 0;
418#endif
wdenk64519362004-07-11 17:40:54 +0000419}
420#endif
421
wdenkdc130442004-12-12 22:06:17 +0000422#ifdef CONFIG_BOARD_EARLY_INIT_R
423int board_early_init_r (void)
424{
Markus Klotzbuecher2f1a4ce2008-01-09 13:57:10 +0100425
Wolfgang Denk92254112007-11-18 16:36:27 +0100426 extern int usb_cpu_init(void);
427
Marian Balakowiczfa65a4a2007-10-24 01:37:36 +0200428#ifdef CONFIG_PS2MULT
wdenkdc130442004-12-12 22:06:17 +0000429 ps2mult_early_init();
Marian Balakowiczfa65a4a2007-10-24 01:37:36 +0200430#endif /* CONFIG_PS2MULT */
431
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200432#if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
Marian Balakowiczfa65a4a2007-10-24 01:37:36 +0200433 /* Low level USB init, required for proper kernel operation */
434 usb_cpu_init();
435#endif
436
wdenkdc130442004-12-12 22:06:17 +0000437 return (0);
438}
439#endif
wdenkdc130442004-12-12 22:06:17 +0000440
Wolfgang Denk573a3ad2006-09-13 10:47:05 +0200441#ifdef CONFIG_FO300
442int silent_boot (void)
443{
444 vu_long timer3_status;
445
446 /* Configure GPT3 as GPIO input */
447 *(vu_long *)MPC5XXX_GPT3_ENABLE = 0x00000004;
448
449 /* Read in TIMER_3 pin status */
450 timer3_status = *(vu_long *)MPC5XXX_GPT3_STATUS;
451
452#ifdef FO300_SILENT_CONSOLE_WHEN_S1_CLOSED
453 /* Force silent console mode if S1 switch
454 * is in closed position (TIMER_3 pin status is LOW). */
455 if (MPC5XXX_GPT_GPIO_PIN(timer3_status) == 0)
456 return 1;
457#else
458 /* Force silent console mode if S1 switch
459 * is in open position (TIMER_3 pin status is HIGH). */
460 if (MPC5XXX_GPT_GPIO_PIN(timer3_status) == 1)
461 return 1;
462#endif
463
464 return 0;
465}
466
467int board_early_init_f (void)
468{
Wolfgang Denk573a3ad2006-09-13 10:47:05 +0200469 if (silent_boot())
470 gd->flags |= GD_FLG_SILENT;
471
472 return 0;
473}
474#endif /* CONFIG_FO300 */
475
Heiko Schocher1ae91442010-12-04 08:34:04 +0100476#if defined(CONFIG_CHARON)
477#include <i2c.h>
478#include <asm/io.h>
479
480/* The TFP410 registers */
481#define TFP410_REG_VEN_ID_L 0x00
482#define TFP410_REG_VEN_ID_H 0x01
483#define TFP410_REG_DEV_ID_L 0x02
484#define TFP410_REG_DEV_ID_H 0x03
485#define TFP410_REG_REV_ID 0x04
486
487#define TFP410_REG_CTL_1_MODE 0x08
488#define TFP410_REG_CTL_2_MODE 0x09
489#define TFP410_REG_CTL_3_MODE 0x0A
490
491#define TFP410_REG_CFG 0x0B
492
493#define TFP410_REG_DE_DLY 0x32
494#define TFP410_REG_DE_CTL 0x33
495#define TFP410_REG_DE_TOP 0x34
496#define TFP410_REG_DE_CNT_L 0x36
497#define TFP410_REG_DE_CNT_H 0x37
498#define TFP410_REG_DE_LIN_L 0x38
499#define TFP410_REG_DE_LIN_H 0x39
500
501#define TFP410_REG_H_RES_L 0x3A
502#define TFP410_REG_H_RES_H 0x3B
503#define TFP410_REG_V_RES_L 0x3C
504#define TFP410_REG_V_RES_H 0x3D
505
506static int tfp410_read_reg(int reg, uchar *buf)
507{
508 if (i2c_read(CONFIG_SYS_TFP410_ADDR, reg, 1, buf, 1) != 0) {
509 puts ("Error reading the chip.\n");
510 return 1;
511 }
512 return 0;
513}
514
515static int tfp410_write_reg(int reg, uchar buf)
516{
517 if (i2c_write(CONFIG_SYS_TFP410_ADDR, reg, 1, &buf, 1) != 0) {
518 puts ("Error writing the chip.\n");
519 return 1;
520 }
521 return 0;
522}
523
524typedef struct _tfp410_config {
525 int reg;
526 uchar val;
527}TFP410_CONFIG;
528
529static TFP410_CONFIG tfp410_configtbl[] = {
530 {TFP410_REG_CTL_1_MODE, 0x37},
531 {TFP410_REG_CTL_2_MODE, 0x20},
532 {TFP410_REG_CTL_3_MODE, 0x80},
533 {TFP410_REG_DE_DLY, 0x90},
534 {TFP410_REG_DE_CTL, 0x00},
535 {TFP410_REG_DE_TOP, 0x23},
536 {TFP410_REG_DE_CNT_H, 0x02},
537 {TFP410_REG_DE_CNT_L, 0x80},
538 {TFP410_REG_DE_LIN_H, 0x01},
539 {TFP410_REG_DE_LIN_L, 0xe0},
540 {-1, 0},
541};
542
543static int charon_last_stage_init(void)
544{
545 volatile struct mpc5xxx_lpb *lpb =
546 (struct mpc5xxx_lpb *) MPC5XXX_LPB;
547 int oldbus = i2c_get_bus_num();
548 uchar buf;
549 int i = 0;
550
551 i2c_set_bus_num(CONFIG_SYS_TFP410_BUS);
552
553 /* check version */
554 if (tfp410_read_reg(TFP410_REG_DEV_ID_H, &buf) != 0)
555 return -1;
556 if (!(buf & 0x04))
557 return -1;
558 if (tfp410_read_reg(TFP410_REG_DEV_ID_L, &buf) != 0)
559 return -1;
560 if (!(buf & 0x10))
561 return -1;
562 /* OK, now init the chip */
563 while (tfp410_configtbl[i].reg != -1) {
564 int ret;
565
566 ret = tfp410_write_reg(tfp410_configtbl[i].reg,
567 tfp410_configtbl[i].val);
568 if (ret != 0)
569 return -1;
570 i++;
571 }
572 printf("TFP410 initialized.\n");
573 i2c_set_bus_num(oldbus);
574
575 /* set deadcycle for cs3 to 0 */
576 setbits_be32(&lpb->cs_deadcycle, 0xffffcfff);
577 return 0;
578}
579#endif
580
wdenkdc130442004-12-12 22:06:17 +0000581int last_stage_init (void)
582{
583 /*
584 * auto scan for really existing devices and re-set chip select
585 * configuration.
586 */
587 u16 save, tmp;
588 int restore;
589
590 /*
591 * Check for SRAM and SRAM size
592 */
593
Wolfgang Denk71112152005-08-18 11:55:22 +0200594 /* save original SRAM content */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200595 save = *(volatile u16 *)CONFIG_SYS_CS2_START;
wdenkdc130442004-12-12 22:06:17 +0000596 restore = 1;
wdenk07d7e6b2004-12-16 21:44:03 +0000597
wdenkdc130442004-12-12 22:06:17 +0000598 /* write test pattern to SRAM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200599 *(volatile u16 *)CONFIG_SYS_CS2_START = 0xA5A5;
wdenkdc130442004-12-12 22:06:17 +0000600 __asm__ volatile ("sync");
601 /*
602 * Put a different pattern on the data lines: otherwise they may float
603 * long enough to read back what we wrote.
604 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200605 tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
wdenkdc130442004-12-12 22:06:17 +0000606 if (tmp == 0xA5A5)
607 puts ("!! possible error in SRAM detection\n");
wdenk07d7e6b2004-12-16 21:44:03 +0000608
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200609 if (*(volatile u16 *)CONFIG_SYS_CS2_START != 0xA5A5) {
wdenkdc130442004-12-12 22:06:17 +0000610 /* no SRAM at all, disable cs */
611 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 18);
612 *(vu_long *)MPC5XXX_CS2_START = 0x0000FFFF;
613 *(vu_long *)MPC5XXX_CS2_STOP = 0x0000FFFF;
614 restore = 0;
615 __asm__ volatile ("sync");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200616 } else if (*(volatile u16 *)(CONFIG_SYS_CS2_START + (1<<19)) == 0xA5A5) {
wdenkdc130442004-12-12 22:06:17 +0000617 /* make sure that we access a mirrored address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200618 *(volatile u16 *)CONFIG_SYS_CS2_START = 0x1111;
wdenkdc130442004-12-12 22:06:17 +0000619 __asm__ volatile ("sync");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200620 if (*(volatile u16 *)(CONFIG_SYS_CS2_START + (1<<19)) == 0x1111) {
wdenkdc130442004-12-12 22:06:17 +0000621 /* SRAM size = 512 kByte */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200622 *(vu_long *)MPC5XXX_CS2_STOP = STOP_REG(CONFIG_SYS_CS2_START,
wdenkdc130442004-12-12 22:06:17 +0000623 0x80000);
624 __asm__ volatile ("sync");
625 puts ("SRAM: 512 kB\n");
626 }
627 else
wdenk07d7e6b2004-12-16 21:44:03 +0000628 puts ("!! possible error in SRAM detection\n");
Wolfgang Denk71112152005-08-18 11:55:22 +0200629 } else {
wdenk07d7e6b2004-12-16 21:44:03 +0000630 puts ("SRAM: 1 MB\n");
wdenkdc130442004-12-12 22:06:17 +0000631 }
632 /* restore origianl SRAM content */
633 if (restore) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200634 *(volatile u16 *)CONFIG_SYS_CS2_START = save;
wdenkdc130442004-12-12 22:06:17 +0000635 __asm__ volatile ("sync");
636 }
wdenk07d7e6b2004-12-16 21:44:03 +0000637
Martin Krause8dcc9f62007-10-22 16:40:06 +0200638#ifndef CONFIG_TQM5200S /* The TQM5200S has no SM501 grafic controller */
wdenk07d7e6b2004-12-16 21:44:03 +0000639 /*
wdenkdc130442004-12-12 22:06:17 +0000640 * Check for Grafic Controller
641 */
642
643 /* save origianl FB content */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200644 save = *(volatile u16 *)CONFIG_SYS_CS1_START;
wdenkdc130442004-12-12 22:06:17 +0000645 restore = 1;
wdenk07d7e6b2004-12-16 21:44:03 +0000646
wdenkdc130442004-12-12 22:06:17 +0000647 /* write test pattern to FB memory */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200648 *(volatile u16 *)CONFIG_SYS_CS1_START = 0xA5A5;
wdenkdc130442004-12-12 22:06:17 +0000649 __asm__ volatile ("sync");
650 /*
651 * Put a different pattern on the data lines: otherwise they may float
652 * long enough to read back what we wrote.
653 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200654 tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
wdenkdc130442004-12-12 22:06:17 +0000655 if (tmp == 0xA5A5)
656 puts ("!! possible error in grafic controller detection\n");
wdenk07d7e6b2004-12-16 21:44:03 +0000657
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200658 if (*(volatile u16 *)CONFIG_SYS_CS1_START != 0xA5A5) {
wdenkdc130442004-12-12 22:06:17 +0000659 /* no grafic controller at all, disable cs */
660 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 17);
661 *(vu_long *)MPC5XXX_CS1_START = 0x0000FFFF;
662 *(vu_long *)MPC5XXX_CS1_STOP = 0x0000FFFF;
663 restore = 0;
664 __asm__ volatile ("sync");
Wolfgang Denk71112152005-08-18 11:55:22 +0200665 } else {
wdenk07d7e6b2004-12-16 21:44:03 +0000666 puts ("VGA: SMI501 (Voyager) with 8 MB\n");
wdenkdc130442004-12-12 22:06:17 +0000667 }
668 /* restore origianl FB content */
669 if (restore) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200670 *(volatile u16 *)CONFIG_SYS_CS1_START = save;
wdenkdc130442004-12-12 22:06:17 +0000671 __asm__ volatile ("sync");
672 }
wdenk07d7e6b2004-12-16 21:44:03 +0000673
Wolfgang Denk573a3ad2006-09-13 10:47:05 +0200674#ifdef CONFIG_FO300
675 if (silent_boot()) {
676 setenv("bootdelay", "0");
677 disable_ctrlc(1);
678 }
679#endif
Wolfgang Denk92254112007-11-18 16:36:27 +0100680#endif /* !CONFIG_TQM5200S */
Wolfgang Denk573a3ad2006-09-13 10:47:05 +0200681
Heiko Schocher1ae91442010-12-04 08:34:04 +0100682#if defined(CONFIG_CHARON)
683 charon_last_stage_init();
684#endif
wdenkdc130442004-12-12 22:06:17 +0000685 return 0;
686}
wdenka5948882005-03-27 23:41:39 +0000687
688#ifdef CONFIG_VIDEO_SM501
689
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200690#ifdef CONFIG_FO300
691#define DISPLAY_WIDTH 800
692#else
wdenka5948882005-03-27 23:41:39 +0000693#define DISPLAY_WIDTH 640
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200694#endif
wdenka5948882005-03-27 23:41:39 +0000695#define DISPLAY_HEIGHT 480
696
697#ifdef CONFIG_VIDEO_SM501_8BPP
698#error CONFIG_VIDEO_SM501_8BPP not supported.
699#endif /* CONFIG_VIDEO_SM501_8BPP */
700
701#ifdef CONFIG_VIDEO_SM501_16BPP
702#error CONFIG_VIDEO_SM501_16BPP not supported.
703#endif /* CONFIG_VIDEO_SM501_16BPP */
704#ifdef CONFIG_VIDEO_SM501_32BPP
705static const SMI_REGS init_regs [] =
706{
707#if 0 /* CRT only */
708 {0x00004, 0x0},
709 {0x00048, 0x00021807},
710 {0x0004C, 0x10090a01},
711 {0x00054, 0x1},
712 {0x00040, 0x00021807},
713 {0x00044, 0x10090a01},
714 {0x00054, 0x0},
715 {0x80200, 0x00010000},
716 {0x80204, 0x0},
717 {0x80208, 0x0A000A00},
718 {0x8020C, 0x02fa027f},
719 {0x80210, 0x004a028b},
720 {0x80214, 0x020c01df},
721 {0x80218, 0x000201e9},
722 {0x80200, 0x00013306},
723#else /* panel + CRT */
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200724#ifdef CONFIG_FO300
wdenka5948882005-03-27 23:41:39 +0000725 {0x00004, 0x0},
726 {0x00048, 0x00021807},
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200727 {0x0004C, 0x301a0a01},
728 {0x00054, 0x1},
729 {0x00040, 0x00021807},
730 {0x00044, 0x091a0a01},
731 {0x00054, 0x0},
732 {0x80000, 0x0f013106},
733 {0x80004, 0xc428bb17},
734 {0x8000C, 0x00000000},
735 {0x80010, 0x0C800C80},
736 {0x80014, 0x03200000},
737 {0x80018, 0x01e00000},
738 {0x8001C, 0x00000000},
739 {0x80020, 0x01e00320},
740 {0x80024, 0x042a031f},
741 {0x80028, 0x0086034a},
742 {0x8002C, 0x020c01df},
743 {0x80030, 0x000201ea},
744 {0x80200, 0x00010000},
745#else
746 {0x00004, 0x0},
747 {0x00048, 0x00021807},
wdenka5948882005-03-27 23:41:39 +0000748 {0x0004C, 0x091a0a01},
749 {0x00054, 0x1},
750 {0x00040, 0x00021807},
751 {0x00044, 0x091a0a01},
752 {0x00054, 0x0},
753 {0x80000, 0x0f013106},
754 {0x80004, 0xc428bb17},
755 {0x8000C, 0x00000000},
756 {0x80010, 0x0a000a00},
757 {0x80014, 0x02800000},
758 {0x80018, 0x01e00000},
759 {0x8001C, 0x00000000},
760 {0x80020, 0x01e00280},
761 {0x80024, 0x02fa027f},
762 {0x80028, 0x004a028b},
763 {0x8002C, 0x020c01df},
764 {0x80030, 0x000201e9},
765 {0x80200, 0x00010000},
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200766#endif /* #ifdef CONFIG_FO300 */
wdenka5948882005-03-27 23:41:39 +0000767#endif
768 {0, 0}
769};
770#endif /* CONFIG_VIDEO_SM501_32BPP */
771
772#ifdef CONFIG_CONSOLE_EXTRA_INFO
773/*
774 * Return text to be printed besides the logo.
775 */
776void video_get_info_str (int line_number, char *info)
777{
778 if (line_number == 1) {
Wolfgang Denk3f2f9dd2006-06-16 16:11:34 +0200779 strcpy (info, " Board: TQM5200 (TQ-Components GmbH)");
Heiko Schocher1ae91442010-12-04 08:34:04 +0100780#if defined (CONFIG_CHARON) || defined (CONFIG_FO300) || \
781 defined(CONFIG_STK52XX) || defined(CONFIG_TB5200)
wdenka5948882005-03-27 23:41:39 +0000782 } else if (line_number == 2) {
Heiko Schocher1ae91442010-12-04 08:34:04 +0100783#if defined (CONFIG_CHARON)
784 strcpy (info, " on a CHARON carrier board");
785#endif
Wolfgang Denkba940932006-07-19 13:50:38 +0200786#if defined (CONFIG_STK52XX)
Wolfgang Denk99753142006-07-21 11:16:34 +0200787 strcpy (info, " on a STK52xx carrier board");
wdenka5948882005-03-27 23:41:39 +0000788#endif
Wolfgang Denkba940932006-07-19 13:50:38 +0200789#if defined (CONFIG_TB5200)
Wolfgang Denk99753142006-07-21 11:16:34 +0200790 strcpy (info, " on a TB5200 carrier board");
Wolfgang Denkba940932006-07-19 13:50:38 +0200791#endif
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200792#if defined (CONFIG_FO300)
793 strcpy (info, " on a FO300 carrier board");
794#endif
Wolfgang Denkba940932006-07-19 13:50:38 +0200795#endif
wdenka5948882005-03-27 23:41:39 +0000796 }
797 else {
798 info [0] = '\0';
799 }
800}
801#endif
802
803/*
Wolfgang Denk71112152005-08-18 11:55:22 +0200804 * Returns SM501 register base address. First thing called in the
805 * driver. Checks if SM501 is physically present.
wdenka5948882005-03-27 23:41:39 +0000806 */
807unsigned int board_video_init (void)
808{
Wolfgang Denk71112152005-08-18 11:55:22 +0200809 u16 save, tmp;
810 int restore, ret;
811
812 /*
813 * Check for Grafic Controller
814 */
815
816 /* save origianl FB content */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200817 save = *(volatile u16 *)CONFIG_SYS_CS1_START;
Wolfgang Denk71112152005-08-18 11:55:22 +0200818 restore = 1;
819
820 /* write test pattern to FB memory */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200821 *(volatile u16 *)CONFIG_SYS_CS1_START = 0xA5A5;
Wolfgang Denk71112152005-08-18 11:55:22 +0200822 __asm__ volatile ("sync");
823 /*
824 * Put a different pattern on the data lines: otherwise they may float
825 * long enough to read back what we wrote.
826 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200827 tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
Wolfgang Denk71112152005-08-18 11:55:22 +0200828 if (tmp == 0xA5A5)
829 puts ("!! possible error in grafic controller detection\n");
830
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200831 if (*(volatile u16 *)CONFIG_SYS_CS1_START != 0xA5A5) {
Wolfgang Denk71112152005-08-18 11:55:22 +0200832 /* no grafic controller found */
833 restore = 0;
834 ret = 0;
835 } else {
836 ret = SM501_MMIO_BASE;
837 }
838
839 if (restore) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200840 *(volatile u16 *)CONFIG_SYS_CS1_START = save;
Wolfgang Denk71112152005-08-18 11:55:22 +0200841 __asm__ volatile ("sync");
842 }
843 return ret;
wdenka5948882005-03-27 23:41:39 +0000844}
845
846/*
847 * Returns SM501 framebuffer address
848 */
849unsigned int board_video_get_fb (void)
850{
851 return SM501_FB_BASE;
852}
853
854/*
855 * Called after initializing the SM501 and before clearing the screen.
856 */
857void board_validate_screen (unsigned int base)
858{
859}
860
861/*
862 * Return a pointer to the initialization sequence.
863 */
864const SMI_REGS *board_get_regs (void)
865{
866 return init_regs;
867}
868
869int board_get_width (void)
870{
871 return DISPLAY_WIDTH;
872}
873
874int board_get_height (void)
875{
876 return DISPLAY_HEIGHT;
877}
878
879#endif /* CONFIG_VIDEO_SM501 */
Bartlomiej Sieka7a432ce2007-06-08 14:52:22 +0200880
Grant Likely8d1e6e72007-09-06 09:46:23 -0600881#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Bartlomiej Sieka7a432ce2007-06-08 14:52:22 +0200882void ft_board_setup(void *blob, bd_t *bd)
883{
884 ft_cpu_setup(blob, bd);
Heiko Schocher1ae91442010-12-04 08:34:04 +0100885#if defined(CONFIG_VIDEO)
886 fdt_add_edid(blob, "smi,sm501", edid_buf);
887#endif
Bartlomiej Sieka7a432ce2007-06-08 14:52:22 +0200888}
Grant Likely8d1e6e72007-09-06 09:46:23 -0600889#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
Ben Warrenf2c1acb2008-08-31 10:03:22 -0700890
Heiko Schocher1ae91442010-12-04 08:34:04 +0100891#if defined(CONFIG_RESET_PHY_R)
892#include <miiphy.h>
893
894void reset_phy(void)
895{
896 /* init Micrel KSZ8993 PHY */
897 miiphy_write("FEC", CONFIG_PHY_ADDR, 0x01, 0x09);
898}
899#endif
900
Ben Warrenf2c1acb2008-08-31 10:03:22 -0700901int board_eth_init(bd_t *bis)
902{
Ben Warrencba88512008-08-31 10:39:12 -0700903 cpu_eth_init(bis); /* Built in FEC comes first */
Ben Warrenf2c1acb2008-08-31 10:03:22 -0700904 return pci_eth_init(bis);
905}