blob: 7cbcd433ea800b318f442bdedf9eb7b17bf2c6cf [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
Heiko Schocher1ae91442010-12-04 08:34:04 +010057#if defined(CONFIG_VIDEO)
58/*
59 * EDID block has been generated using Phoenix EDID Designer 1.3.
60 * This tool creates a text file containing:
61 *
62 * EDID BYTES:
63 *
64 * 0x 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
65 * ------------------------------------------------
66 * 00 | 00 FF FF FF FF FF FF 00 04 21 00 00 00 00 00 00
67 * 10 | 01 00 01 03 00 00 00 00 00 00 00 00 00 00 00 00
68 * 20 | 00 00 00 21 00 00 01 01 01 01 01 01 01 01 01 01
69 * 30 | 01 01 01 01 01 01 64 00 00 00 00 00 00 00 00 00
70 * 40 | 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00
71 * 50 | 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00
72 * 60 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10
73 * 70 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17
74 *
75 * Then this data has been manually converted to the char
76 * array below.
77 */
78static unsigned char edid_buf[128] = {
79 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
80 0x04, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x01, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x01, 0x01,
84 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
85 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x64, 0x00,
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17,
95};
96#endif
97
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098#ifndef CONFIG_SYS_RAMBOOT
wdenk64519362004-07-11 17:40:54 +000099static void sdram_start (int hi_addr)
100{
101 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
102
103 /* unlock mode register */
104 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 |
105 hi_addr_bit;
106 __asm__ volatile ("sync");
107
108 /* precharge all banks */
109 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
110 hi_addr_bit;
111 __asm__ volatile ("sync");
112
113#if SDRAM_DDR
114 /* set mode register: extended mode */
115 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
116 __asm__ volatile ("sync");
117
118 /* set mode register: reset DLL */
119 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
120 __asm__ volatile ("sync");
121#endif
122
123 /* precharge all banks */
124 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
125 hi_addr_bit;
126 __asm__ volatile ("sync");
127
128 /* auto refresh */
129 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
130 hi_addr_bit;
131 __asm__ volatile ("sync");
132
133 /* set mode register */
134 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
135 __asm__ volatile ("sync");
136
137 /* normal operation */
138 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
139 __asm__ volatile ("sync");
140}
141#endif
142
143/*
144 * ATTENTION: Although partially referenced initdram does NOT make real use
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200145 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
wdenk7dd13292004-07-11 20:04:51 +0000146 * is something else than 0x00000000.
wdenk64519362004-07-11 17:40:54 +0000147 */
148
Becky Brucebd99ae72008-06-09 16:03:40 -0500149phys_size_t initdram (int board_type)
wdenk64519362004-07-11 17:40:54 +0000150{
151 ulong dramsize = 0;
152 ulong dramsize2 = 0;
Wolfgang Denkc98368a2006-07-19 17:52:30 +0200153 uint svr, pvr;
154
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200155#ifndef CONFIG_SYS_RAMBOOT
wdenk64519362004-07-11 17:40:54 +0000156 ulong test1, test2;
157
158 /* setup SDRAM chip selects */
159 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
160 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
161 __asm__ volatile ("sync");
162
163 /* setup config registers */
164 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
165 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
166 __asm__ volatile ("sync");
167
168#if SDRAM_DDR
169 /* set tap delay */
170 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
171 __asm__ volatile ("sync");
172#endif
173
174 /* find RAM size using SDRAM CS0 only */
175 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200176 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
wdenk64519362004-07-11 17:40:54 +0000177 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200178 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
wdenk64519362004-07-11 17:40:54 +0000179 if (test1 > test2) {
180 sdram_start(0);
181 dramsize = test1;
182 } else {
183 dramsize = test2;
184 }
185
186 /* memory smaller than 1MB is impossible */
187 if (dramsize < (1 << 20)) {
188 dramsize = 0;
189 }
190
191 /* set SDRAM CS0 size according to the amount of RAM found */
192 if (dramsize > 0) {
193 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
194 __builtin_ffs(dramsize >> 20) - 1;
195 } else {
196 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
197 }
198
199 /* let SDRAM CS1 start right after CS0 */
200 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001c; /* 512MB */
201
202 /* find RAM size using SDRAM CS1 only */
Martin Krausec03d80a2008-02-25 13:27:52 +0100203 if (!dramsize)
204 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200205 test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
Martin Krausec03d80a2008-02-25 13:27:52 +0100206 if (!dramsize) {
207 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200208 test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
Martin Krausec03d80a2008-02-25 13:27:52 +0100209 }
wdenk64519362004-07-11 17:40:54 +0000210 if (test1 > test2) {
211 sdram_start(0);
212 dramsize2 = test1;
213 } else {
214 dramsize2 = test2;
215 }
216
217 /* memory smaller than 1MB is impossible */
218 if (dramsize2 < (1 << 20)) {
219 dramsize2 = 0;
220 }
221
222 /* set SDRAM CS1 size according to the amount of RAM found */
223 if (dramsize2 > 0) {
224 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
225 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
226 } else {
227 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
228 }
229
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200230#else /* CONFIG_SYS_RAMBOOT */
wdenk64519362004-07-11 17:40:54 +0000231
232 /* retrieve size of memory connected to SDRAM CS0 */
233 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
234 if (dramsize >= 0x13) {
235 dramsize = (1 << (dramsize - 0x13)) << 20;
236 } else {
237 dramsize = 0;
238 }
239
240 /* retrieve size of memory connected to SDRAM CS1 */
241 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
242 if (dramsize2 >= 0x13) {
243 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
244 } else {
245 dramsize2 = 0;
246 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200247#endif /* CONFIG_SYS_RAMBOOT */
wdenk64519362004-07-11 17:40:54 +0000248
Wolfgang Denkc98368a2006-07-19 17:52:30 +0200249 /*
250 * On MPC5200B we need to set the special configuration delay in the
251 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
252 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
253 *
254 * "The SDelay should be written to a value of 0x00000004. It is
255 * required to account for changes caused by normal wafer processing
256 * parameters."
257 */
258 svr = get_svr();
259 pvr = get_pvr();
260 if ((SVR_MJREV(svr) >= 2) &&
261 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
262
263 *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
264 __asm__ volatile ("sync");
265 }
266
267#if defined(CONFIG_TQM5200_B)
268 return dramsize + dramsize2;
269#else
wdenk64519362004-07-11 17:40:54 +0000270 return dramsize;
Wolfgang Denkc98368a2006-07-19 17:52:30 +0200271#endif /* CONFIG_TQM5200_B */
wdenk64519362004-07-11 17:40:54 +0000272}
273
wdenk64519362004-07-11 17:40:54 +0000274int checkboard (void)
275{
Wolfgang Denk99753142006-07-21 11:16:34 +0200276#if defined(CONFIG_AEVFIFO)
Wolfgang Denkeb95c852005-08-10 15:14:32 +0200277 puts ("Board: AEVFIFO\n");
278 return 0;
279#endif
Wolfgang Denk99753142006-07-21 11:16:34 +0200280
281#if defined(CONFIG_TQM5200S)
282# define MODULE_NAME "TQM5200S"
Wolfgang Denkc98368a2006-07-19 17:52:30 +0200283#else
Wolfgang Denk99753142006-07-21 11:16:34 +0200284# define MODULE_NAME "TQM5200"
wdenkdc130442004-12-12 22:06:17 +0000285#endif
Wolfgang Denk99753142006-07-21 11:16:34 +0200286
287#if defined(CONFIG_STK52XX)
288# define CARRIER_NAME "STK52xx"
289#elif defined(CONFIG_TB5200)
290# define CARRIER_NAME "TB5200"
Wolfgang Denk641e3572006-07-22 01:20:03 +0200291#elif defined(CONFIG_CAM5200)
Wolfgang Denk0129dcd2006-11-23 22:58:58 +0100292# define CARRIER_NAME "CAM5200"
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200293#elif defined(CONFIG_FO300)
294# define CARRIER_NAME "FO300"
Heiko Schocher1ae91442010-12-04 08:34:04 +0100295#elif defined(CONFIG_CHARON)
296# define CARRIER_NAME "CHARON"
Wolfgang Denk99753142006-07-21 11:16:34 +0200297#else
Wolfgang Denk9018bc92006-08-18 23:27:33 +0200298# error "UNKNOWN"
Wolfgang Denkba940932006-07-19 13:50:38 +0200299#endif
wdenkdc130442004-12-12 22:06:17 +0000300
Wolfgang Denk99753142006-07-21 11:16:34 +0200301 puts ( "Board: " MODULE_NAME " (TQ-Components GmbH)\n"
302 " on a " CARRIER_NAME " carrier board\n");
303
wdenk64519362004-07-11 17:40:54 +0000304 return 0;
305}
306
Wolfgang Denk99753142006-07-21 11:16:34 +0200307#undef MODULE_NAME
308#undef CARRIER_NAME
309
wdenk64519362004-07-11 17:40:54 +0000310void flash_preinit(void)
311{
312 /*
313 * Now, when we are in RAM, enable flash write
314 * access for detection process.
315 * Note that CS_BOOT cannot be cleared when
316 * executing in flash.
317 */
wdenk64519362004-07-11 17:40:54 +0000318 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
319}
320
321
322#ifdef CONFIG_PCI
323static struct pci_controller hose;
324
325extern void pci_mpc5xxx_init(struct pci_controller *);
326
327void pci_init_board(void)
328{
329 pci_mpc5xxx_init(&hose);
330}
331#endif
332
Jon Loeliger761ea742007-07-10 10:48:22 -0500333#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
wdenk64519362004-07-11 17:40:54 +0000334
335#if defined (CONFIG_MINIFAP)
336#define SM501_POWER_MODE0_GATE 0x00000040UL
337#define SM501_POWER_MODE1_GATE 0x00000048UL
338#define POWER_MODE_GATE_GPIO_PWM_I2C 0x00000040UL
339#define SM501_GPIO_DATA_DIR_HIGH 0x0001000CUL
340#define SM501_GPIO_DATA_HIGH 0x00010004UL
341#define SM501_GPIO_51 0x00080000UL
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100342#endif /* CONFIG MINIFAP */
wdenk64519362004-07-11 17:40:54 +0000343
344void init_ide_reset (void)
345{
346 debug ("init_ide_reset\n");
347
348#if defined (CONFIG_MINIFAP)
349 /* Configure GPIO_51 of the SM501 grafic controller as ATA reset */
350
351 /* enable GPIO control (in both power modes) */
352 *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE0_GATE) |=
353 POWER_MODE_GATE_GPIO_PWM_I2C;
354 *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE1_GATE) |=
355 POWER_MODE_GATE_GPIO_PWM_I2C;
356 /* configure GPIO51 as output */
357 *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_DIR_HIGH) |=
358 SM501_GPIO_51;
359#else
360 /* Configure PSC1_4 as GPIO output for ATA reset */
361 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
362 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
Martin Krause5f7c6f92008-04-03 14:29:01 +0200363
364 /* by default the ATA reset is de-asserted */
365 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
wdenk64519362004-07-11 17:40:54 +0000366#endif
367}
368
369void ide_set_reset (int idereset)
370{
371 debug ("ide_reset(%d)\n", idereset);
372
373#if defined (CONFIG_MINIFAP)
374 if (idereset) {
375 *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) &=
376 ~SM501_GPIO_51;
377 } else {
378 *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) |=
379 SM501_GPIO_51;
380 }
381#else
382 if (idereset) {
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100383 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
wdenk64519362004-07-11 17:40:54 +0000384 } else {
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100385 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
wdenk64519362004-07-11 17:40:54 +0000386 }
387#endif
388}
Jon Loeliger761ea742007-07-10 10:48:22 -0500389#endif
wdenk64519362004-07-11 17:40:54 +0000390
391#ifdef CONFIG_POST
392/*
393 * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
394 * is left open, no keypress is detected.
395 */
396int post_hotkeys_pressed(void)
397{
Wolfgang Denkf67272a2006-10-09 01:07:53 +0200398#ifdef CONFIG_STK52XX
wdenk64519362004-07-11 17:40:54 +0000399 struct mpc5xxx_gpio *gpio;
400
401 gpio = (struct mpc5xxx_gpio*) MPC5XXX_GPIO;
402
403 /*
Detlev Zundel3ba0fa72009-10-07 16:38:05 +0200404 * Configure PSC6_0 through PSC6_3 as GPIO.
wdenk7dd13292004-07-11 20:04:51 +0000405 */
Detlev Zundel3ba0fa72009-10-07 16:38:05 +0200406 gpio->port_config &= ~(0x00700000);
wdenk64519362004-07-11 17:40:54 +0000407
408 /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
409 gpio->simple_gpioe |= 0x20000000;
410
411 /* Configure GPIO_IRDA_1 as input */
412 gpio->simple_ddr &= ~(0x20000000);
413
414 return ((gpio->simple_ival & 0x20000000) ? 0 : 1);
Wolfgang Denkf67272a2006-10-09 01:07:53 +0200415#else
416 return 0;
417#endif
wdenk64519362004-07-11 17:40:54 +0000418}
419#endif
420
wdenkdc130442004-12-12 22:06:17 +0000421#ifdef CONFIG_BOARD_EARLY_INIT_R
422int board_early_init_r (void)
423{
Markus Klotzbuecher2f1a4ce2008-01-09 13:57:10 +0100424
Wolfgang Denk92254112007-11-18 16:36:27 +0100425 extern int usb_cpu_init(void);
426
Marian Balakowiczfa65a4a2007-10-24 01:37:36 +0200427#ifdef CONFIG_PS2MULT
wdenkdc130442004-12-12 22:06:17 +0000428 ps2mult_early_init();
Marian Balakowiczfa65a4a2007-10-24 01:37:36 +0200429#endif /* CONFIG_PS2MULT */
430
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200431#if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
Marian Balakowiczfa65a4a2007-10-24 01:37:36 +0200432 /* Low level USB init, required for proper kernel operation */
433 usb_cpu_init();
434#endif
435
wdenkdc130442004-12-12 22:06:17 +0000436 return (0);
437}
438#endif
wdenkdc130442004-12-12 22:06:17 +0000439
Wolfgang Denk573a3ad2006-09-13 10:47:05 +0200440#ifdef CONFIG_FO300
441int silent_boot (void)
442{
443 vu_long timer3_status;
444
445 /* Configure GPT3 as GPIO input */
446 *(vu_long *)MPC5XXX_GPT3_ENABLE = 0x00000004;
447
448 /* Read in TIMER_3 pin status */
449 timer3_status = *(vu_long *)MPC5XXX_GPT3_STATUS;
450
451#ifdef FO300_SILENT_CONSOLE_WHEN_S1_CLOSED
452 /* Force silent console mode if S1 switch
453 * is in closed position (TIMER_3 pin status is LOW). */
454 if (MPC5XXX_GPT_GPIO_PIN(timer3_status) == 0)
455 return 1;
456#else
457 /* Force silent console mode if S1 switch
458 * is in open position (TIMER_3 pin status is HIGH). */
459 if (MPC5XXX_GPT_GPIO_PIN(timer3_status) == 1)
460 return 1;
461#endif
462
463 return 0;
464}
465
466int board_early_init_f (void)
467{
Wolfgang Denk573a3ad2006-09-13 10:47:05 +0200468 if (silent_boot())
469 gd->flags |= GD_FLG_SILENT;
470
471 return 0;
472}
473#endif /* CONFIG_FO300 */
474
Heiko Schocher1ae91442010-12-04 08:34:04 +0100475#if defined(CONFIG_CHARON)
476#include <i2c.h>
477#include <asm/io.h>
478
479/* The TFP410 registers */
480#define TFP410_REG_VEN_ID_L 0x00
481#define TFP410_REG_VEN_ID_H 0x01
482#define TFP410_REG_DEV_ID_L 0x02
483#define TFP410_REG_DEV_ID_H 0x03
484#define TFP410_REG_REV_ID 0x04
485
486#define TFP410_REG_CTL_1_MODE 0x08
487#define TFP410_REG_CTL_2_MODE 0x09
488#define TFP410_REG_CTL_3_MODE 0x0A
489
490#define TFP410_REG_CFG 0x0B
491
492#define TFP410_REG_DE_DLY 0x32
493#define TFP410_REG_DE_CTL 0x33
494#define TFP410_REG_DE_TOP 0x34
495#define TFP410_REG_DE_CNT_L 0x36
496#define TFP410_REG_DE_CNT_H 0x37
497#define TFP410_REG_DE_LIN_L 0x38
498#define TFP410_REG_DE_LIN_H 0x39
499
500#define TFP410_REG_H_RES_L 0x3A
501#define TFP410_REG_H_RES_H 0x3B
502#define TFP410_REG_V_RES_L 0x3C
503#define TFP410_REG_V_RES_H 0x3D
504
505static int tfp410_read_reg(int reg, uchar *buf)
506{
507 if (i2c_read(CONFIG_SYS_TFP410_ADDR, reg, 1, buf, 1) != 0) {
508 puts ("Error reading the chip.\n");
509 return 1;
510 }
511 return 0;
512}
513
514static int tfp410_write_reg(int reg, uchar buf)
515{
516 if (i2c_write(CONFIG_SYS_TFP410_ADDR, reg, 1, &buf, 1) != 0) {
517 puts ("Error writing the chip.\n");
518 return 1;
519 }
520 return 0;
521}
522
523typedef struct _tfp410_config {
524 int reg;
525 uchar val;
526}TFP410_CONFIG;
527
528static TFP410_CONFIG tfp410_configtbl[] = {
529 {TFP410_REG_CTL_1_MODE, 0x37},
530 {TFP410_REG_CTL_2_MODE, 0x20},
531 {TFP410_REG_CTL_3_MODE, 0x80},
532 {TFP410_REG_DE_DLY, 0x90},
533 {TFP410_REG_DE_CTL, 0x00},
534 {TFP410_REG_DE_TOP, 0x23},
535 {TFP410_REG_DE_CNT_H, 0x02},
536 {TFP410_REG_DE_CNT_L, 0x80},
537 {TFP410_REG_DE_LIN_H, 0x01},
538 {TFP410_REG_DE_LIN_L, 0xe0},
539 {-1, 0},
540};
541
542static int charon_last_stage_init(void)
543{
544 volatile struct mpc5xxx_lpb *lpb =
545 (struct mpc5xxx_lpb *) MPC5XXX_LPB;
546 int oldbus = i2c_get_bus_num();
547 uchar buf;
548 int i = 0;
549
550 i2c_set_bus_num(CONFIG_SYS_TFP410_BUS);
551
552 /* check version */
553 if (tfp410_read_reg(TFP410_REG_DEV_ID_H, &buf) != 0)
554 return -1;
555 if (!(buf & 0x04))
556 return -1;
557 if (tfp410_read_reg(TFP410_REG_DEV_ID_L, &buf) != 0)
558 return -1;
559 if (!(buf & 0x10))
560 return -1;
561 /* OK, now init the chip */
562 while (tfp410_configtbl[i].reg != -1) {
563 int ret;
564
565 ret = tfp410_write_reg(tfp410_configtbl[i].reg,
566 tfp410_configtbl[i].val);
567 if (ret != 0)
568 return -1;
569 i++;
570 }
571 printf("TFP410 initialized.\n");
572 i2c_set_bus_num(oldbus);
573
574 /* set deadcycle for cs3 to 0 */
575 setbits_be32(&lpb->cs_deadcycle, 0xffffcfff);
576 return 0;
577}
578#endif
579
wdenkdc130442004-12-12 22:06:17 +0000580int last_stage_init (void)
581{
582 /*
583 * auto scan for really existing devices and re-set chip select
584 * configuration.
585 */
586 u16 save, tmp;
587 int restore;
588
589 /*
590 * Check for SRAM and SRAM size
591 */
592
Wolfgang Denk71112152005-08-18 11:55:22 +0200593 /* save original SRAM content */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200594 save = *(volatile u16 *)CONFIG_SYS_CS2_START;
wdenkdc130442004-12-12 22:06:17 +0000595 restore = 1;
wdenk07d7e6b2004-12-16 21:44:03 +0000596
wdenkdc130442004-12-12 22:06:17 +0000597 /* write test pattern to SRAM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200598 *(volatile u16 *)CONFIG_SYS_CS2_START = 0xA5A5;
wdenkdc130442004-12-12 22:06:17 +0000599 __asm__ volatile ("sync");
600 /*
601 * Put a different pattern on the data lines: otherwise they may float
602 * long enough to read back what we wrote.
603 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200604 tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
wdenkdc130442004-12-12 22:06:17 +0000605 if (tmp == 0xA5A5)
606 puts ("!! possible error in SRAM detection\n");
wdenk07d7e6b2004-12-16 21:44:03 +0000607
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200608 if (*(volatile u16 *)CONFIG_SYS_CS2_START != 0xA5A5) {
wdenkdc130442004-12-12 22:06:17 +0000609 /* no SRAM at all, disable cs */
610 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 18);
611 *(vu_long *)MPC5XXX_CS2_START = 0x0000FFFF;
612 *(vu_long *)MPC5XXX_CS2_STOP = 0x0000FFFF;
613 restore = 0;
614 __asm__ volatile ("sync");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200615 } else if (*(volatile u16 *)(CONFIG_SYS_CS2_START + (1<<19)) == 0xA5A5) {
wdenkdc130442004-12-12 22:06:17 +0000616 /* make sure that we access a mirrored address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200617 *(volatile u16 *)CONFIG_SYS_CS2_START = 0x1111;
wdenkdc130442004-12-12 22:06:17 +0000618 __asm__ volatile ("sync");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200619 if (*(volatile u16 *)(CONFIG_SYS_CS2_START + (1<<19)) == 0x1111) {
wdenkdc130442004-12-12 22:06:17 +0000620 /* SRAM size = 512 kByte */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200621 *(vu_long *)MPC5XXX_CS2_STOP = STOP_REG(CONFIG_SYS_CS2_START,
wdenkdc130442004-12-12 22:06:17 +0000622 0x80000);
623 __asm__ volatile ("sync");
624 puts ("SRAM: 512 kB\n");
625 }
626 else
wdenk07d7e6b2004-12-16 21:44:03 +0000627 puts ("!! possible error in SRAM detection\n");
Wolfgang Denk71112152005-08-18 11:55:22 +0200628 } else {
wdenk07d7e6b2004-12-16 21:44:03 +0000629 puts ("SRAM: 1 MB\n");
wdenkdc130442004-12-12 22:06:17 +0000630 }
631 /* restore origianl SRAM content */
632 if (restore) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200633 *(volatile u16 *)CONFIG_SYS_CS2_START = save;
wdenkdc130442004-12-12 22:06:17 +0000634 __asm__ volatile ("sync");
635 }
wdenk07d7e6b2004-12-16 21:44:03 +0000636
Martin Krause8dcc9f62007-10-22 16:40:06 +0200637#ifndef CONFIG_TQM5200S /* The TQM5200S has no SM501 grafic controller */
wdenk07d7e6b2004-12-16 21:44:03 +0000638 /*
wdenkdc130442004-12-12 22:06:17 +0000639 * Check for Grafic Controller
640 */
641
642 /* save origianl FB content */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200643 save = *(volatile u16 *)CONFIG_SYS_CS1_START;
wdenkdc130442004-12-12 22:06:17 +0000644 restore = 1;
wdenk07d7e6b2004-12-16 21:44:03 +0000645
wdenkdc130442004-12-12 22:06:17 +0000646 /* write test pattern to FB memory */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200647 *(volatile u16 *)CONFIG_SYS_CS1_START = 0xA5A5;
wdenkdc130442004-12-12 22:06:17 +0000648 __asm__ volatile ("sync");
649 /*
650 * Put a different pattern on the data lines: otherwise they may float
651 * long enough to read back what we wrote.
652 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200653 tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
wdenkdc130442004-12-12 22:06:17 +0000654 if (tmp == 0xA5A5)
655 puts ("!! possible error in grafic controller detection\n");
wdenk07d7e6b2004-12-16 21:44:03 +0000656
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200657 if (*(volatile u16 *)CONFIG_SYS_CS1_START != 0xA5A5) {
wdenkdc130442004-12-12 22:06:17 +0000658 /* no grafic controller at all, disable cs */
659 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 17);
660 *(vu_long *)MPC5XXX_CS1_START = 0x0000FFFF;
661 *(vu_long *)MPC5XXX_CS1_STOP = 0x0000FFFF;
662 restore = 0;
663 __asm__ volatile ("sync");
Wolfgang Denk71112152005-08-18 11:55:22 +0200664 } else {
wdenk07d7e6b2004-12-16 21:44:03 +0000665 puts ("VGA: SMI501 (Voyager) with 8 MB\n");
wdenkdc130442004-12-12 22:06:17 +0000666 }
667 /* restore origianl FB content */
668 if (restore) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200669 *(volatile u16 *)CONFIG_SYS_CS1_START = save;
wdenkdc130442004-12-12 22:06:17 +0000670 __asm__ volatile ("sync");
671 }
wdenk07d7e6b2004-12-16 21:44:03 +0000672
Wolfgang Denk573a3ad2006-09-13 10:47:05 +0200673#ifdef CONFIG_FO300
674 if (silent_boot()) {
675 setenv("bootdelay", "0");
676 disable_ctrlc(1);
677 }
678#endif
Wolfgang Denk92254112007-11-18 16:36:27 +0100679#endif /* !CONFIG_TQM5200S */
Wolfgang Denk573a3ad2006-09-13 10:47:05 +0200680
Heiko Schocher1ae91442010-12-04 08:34:04 +0100681#if defined(CONFIG_CHARON)
682 charon_last_stage_init();
683#endif
wdenkdc130442004-12-12 22:06:17 +0000684 return 0;
685}
wdenka5948882005-03-27 23:41:39 +0000686
687#ifdef CONFIG_VIDEO_SM501
688
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200689#ifdef CONFIG_FO300
690#define DISPLAY_WIDTH 800
691#else
wdenka5948882005-03-27 23:41:39 +0000692#define DISPLAY_WIDTH 640
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200693#endif
wdenka5948882005-03-27 23:41:39 +0000694#define DISPLAY_HEIGHT 480
695
696#ifdef CONFIG_VIDEO_SM501_8BPP
697#error CONFIG_VIDEO_SM501_8BPP not supported.
698#endif /* CONFIG_VIDEO_SM501_8BPP */
699
700#ifdef CONFIG_VIDEO_SM501_16BPP
701#error CONFIG_VIDEO_SM501_16BPP not supported.
702#endif /* CONFIG_VIDEO_SM501_16BPP */
703#ifdef CONFIG_VIDEO_SM501_32BPP
704static const SMI_REGS init_regs [] =
705{
706#if 0 /* CRT only */
707 {0x00004, 0x0},
708 {0x00048, 0x00021807},
709 {0x0004C, 0x10090a01},
710 {0x00054, 0x1},
711 {0x00040, 0x00021807},
712 {0x00044, 0x10090a01},
713 {0x00054, 0x0},
714 {0x80200, 0x00010000},
715 {0x80204, 0x0},
716 {0x80208, 0x0A000A00},
717 {0x8020C, 0x02fa027f},
718 {0x80210, 0x004a028b},
719 {0x80214, 0x020c01df},
720 {0x80218, 0x000201e9},
721 {0x80200, 0x00013306},
722#else /* panel + CRT */
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200723#ifdef CONFIG_FO300
wdenka5948882005-03-27 23:41:39 +0000724 {0x00004, 0x0},
725 {0x00048, 0x00021807},
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200726 {0x0004C, 0x301a0a01},
727 {0x00054, 0x1},
728 {0x00040, 0x00021807},
729 {0x00044, 0x091a0a01},
730 {0x00054, 0x0},
731 {0x80000, 0x0f013106},
732 {0x80004, 0xc428bb17},
733 {0x8000C, 0x00000000},
734 {0x80010, 0x0C800C80},
735 {0x80014, 0x03200000},
736 {0x80018, 0x01e00000},
737 {0x8001C, 0x00000000},
738 {0x80020, 0x01e00320},
739 {0x80024, 0x042a031f},
740 {0x80028, 0x0086034a},
741 {0x8002C, 0x020c01df},
742 {0x80030, 0x000201ea},
743 {0x80200, 0x00010000},
744#else
745 {0x00004, 0x0},
746 {0x00048, 0x00021807},
wdenka5948882005-03-27 23:41:39 +0000747 {0x0004C, 0x091a0a01},
748 {0x00054, 0x1},
749 {0x00040, 0x00021807},
750 {0x00044, 0x091a0a01},
751 {0x00054, 0x0},
752 {0x80000, 0x0f013106},
753 {0x80004, 0xc428bb17},
754 {0x8000C, 0x00000000},
755 {0x80010, 0x0a000a00},
756 {0x80014, 0x02800000},
757 {0x80018, 0x01e00000},
758 {0x8001C, 0x00000000},
759 {0x80020, 0x01e00280},
760 {0x80024, 0x02fa027f},
761 {0x80028, 0x004a028b},
762 {0x8002C, 0x020c01df},
763 {0x80030, 0x000201e9},
764 {0x80200, 0x00010000},
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200765#endif /* #ifdef CONFIG_FO300 */
wdenka5948882005-03-27 23:41:39 +0000766#endif
767 {0, 0}
768};
769#endif /* CONFIG_VIDEO_SM501_32BPP */
770
771#ifdef CONFIG_CONSOLE_EXTRA_INFO
772/*
773 * Return text to be printed besides the logo.
774 */
775void video_get_info_str (int line_number, char *info)
776{
777 if (line_number == 1) {
Wolfgang Denk3f2f9dd2006-06-16 16:11:34 +0200778 strcpy (info, " Board: TQM5200 (TQ-Components GmbH)");
Heiko Schocher1ae91442010-12-04 08:34:04 +0100779#if defined (CONFIG_CHARON) || defined (CONFIG_FO300) || \
780 defined(CONFIG_STK52XX) || defined(CONFIG_TB5200)
wdenka5948882005-03-27 23:41:39 +0000781 } else if (line_number == 2) {
Heiko Schocher1ae91442010-12-04 08:34:04 +0100782#if defined (CONFIG_CHARON)
783 strcpy (info, " on a CHARON carrier board");
784#endif
Wolfgang Denkba940932006-07-19 13:50:38 +0200785#if defined (CONFIG_STK52XX)
Wolfgang Denk99753142006-07-21 11:16:34 +0200786 strcpy (info, " on a STK52xx carrier board");
wdenka5948882005-03-27 23:41:39 +0000787#endif
Wolfgang Denkba940932006-07-19 13:50:38 +0200788#if defined (CONFIG_TB5200)
Wolfgang Denk99753142006-07-21 11:16:34 +0200789 strcpy (info, " on a TB5200 carrier board");
Wolfgang Denkba940932006-07-19 13:50:38 +0200790#endif
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200791#if defined (CONFIG_FO300)
792 strcpy (info, " on a FO300 carrier board");
793#endif
Wolfgang Denkba940932006-07-19 13:50:38 +0200794#endif
wdenka5948882005-03-27 23:41:39 +0000795 }
796 else {
797 info [0] = '\0';
798 }
799}
800#endif
801
802/*
Wolfgang Denk71112152005-08-18 11:55:22 +0200803 * Returns SM501 register base address. First thing called in the
804 * driver. Checks if SM501 is physically present.
wdenka5948882005-03-27 23:41:39 +0000805 */
806unsigned int board_video_init (void)
807{
Wolfgang Denk71112152005-08-18 11:55:22 +0200808 u16 save, tmp;
809 int restore, ret;
810
811 /*
812 * Check for Grafic Controller
813 */
814
815 /* save origianl FB content */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200816 save = *(volatile u16 *)CONFIG_SYS_CS1_START;
Wolfgang Denk71112152005-08-18 11:55:22 +0200817 restore = 1;
818
819 /* write test pattern to FB memory */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200820 *(volatile u16 *)CONFIG_SYS_CS1_START = 0xA5A5;
Wolfgang Denk71112152005-08-18 11:55:22 +0200821 __asm__ volatile ("sync");
822 /*
823 * Put a different pattern on the data lines: otherwise they may float
824 * long enough to read back what we wrote.
825 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200826 tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
Wolfgang Denk71112152005-08-18 11:55:22 +0200827 if (tmp == 0xA5A5)
828 puts ("!! possible error in grafic controller detection\n");
829
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200830 if (*(volatile u16 *)CONFIG_SYS_CS1_START != 0xA5A5) {
Wolfgang Denk71112152005-08-18 11:55:22 +0200831 /* no grafic controller found */
832 restore = 0;
833 ret = 0;
834 } else {
835 ret = SM501_MMIO_BASE;
836 }
837
838 if (restore) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200839 *(volatile u16 *)CONFIG_SYS_CS1_START = save;
Wolfgang Denk71112152005-08-18 11:55:22 +0200840 __asm__ volatile ("sync");
841 }
842 return ret;
wdenka5948882005-03-27 23:41:39 +0000843}
844
845/*
846 * Returns SM501 framebuffer address
847 */
848unsigned int board_video_get_fb (void)
849{
850 return SM501_FB_BASE;
851}
852
853/*
854 * Called after initializing the SM501 and before clearing the screen.
855 */
856void board_validate_screen (unsigned int base)
857{
858}
859
860/*
861 * Return a pointer to the initialization sequence.
862 */
863const SMI_REGS *board_get_regs (void)
864{
865 return init_regs;
866}
867
868int board_get_width (void)
869{
870 return DISPLAY_WIDTH;
871}
872
873int board_get_height (void)
874{
875 return DISPLAY_HEIGHT;
876}
877
878#endif /* CONFIG_VIDEO_SM501 */
Bartlomiej Sieka7a432ce2007-06-08 14:52:22 +0200879
Grant Likely8d1e6e72007-09-06 09:46:23 -0600880#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Bartlomiej Sieka7a432ce2007-06-08 14:52:22 +0200881void ft_board_setup(void *blob, bd_t *bd)
882{
883 ft_cpu_setup(blob, bd);
Heiko Schocher1ae91442010-12-04 08:34:04 +0100884#if defined(CONFIG_VIDEO)
885 fdt_add_edid(blob, "smi,sm501", edid_buf);
886#endif
Bartlomiej Sieka7a432ce2007-06-08 14:52:22 +0200887}
Grant Likely8d1e6e72007-09-06 09:46:23 -0600888#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
Ben Warrenf2c1acb2008-08-31 10:03:22 -0700889
Heiko Schocher1ae91442010-12-04 08:34:04 +0100890#if defined(CONFIG_RESET_PHY_R)
891#include <miiphy.h>
892
893void reset_phy(void)
894{
895 /* init Micrel KSZ8993 PHY */
896 miiphy_write("FEC", CONFIG_PHY_ADDR, 0x01, 0x09);
897}
898#endif
899
Ben Warrenf2c1acb2008-08-31 10:03:22 -0700900int board_eth_init(bd_t *bis)
901{
Ben Warrencba88512008-08-31 10:39:12 -0700902 cpu_eth_init(bis); /* Built in FEC comes first */
Ben Warrenf2c1acb2008-08-31 10:03:22 -0700903 return pci_eth_init(bis);
904}