blob: fef9d2b29a94290b4d3f47fc9af8d8de6b858ab7 [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 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +020011 * SPDX-License-Identifier: GPL-2.0+
wdenk64519362004-07-11 17:40:54 +000012 */
13
14#include <common.h>
Simon Glassa73bda42015-11-08 23:47:45 -070015#include <console.h>
wdenk64519362004-07-11 17:40:54 +000016#include <mpc5xxx.h>
17#include <pci.h>
Wolfgang Denkc98368a2006-07-19 17:52:30 +020018#include <asm/processor.h>
Grant Likely8d1e6e72007-09-06 09:46:23 -060019#include <libfdt.h>
Ben Warrenf2c1acb2008-08-31 10:03:22 -070020#include <netdev.h>
Simon Glass88ecb9b2016-10-17 20:12:54 -060021#include <video.h>
Bartlomiej Sieka7a432ce2007-06-08 14:52:22 +020022
wdenka5948882005-03-27 23:41:39 +000023#ifdef CONFIG_VIDEO_SM501
24#include <sm501.h>
25#endif
26
wdenk64519362004-07-11 17:40:54 +000027#if defined(CONFIG_MPC5200_DDR)
28#include "mt46v16m16-75.h"
29#else
30#include "mt48lc16m16a2-75.h"
31#endif
wdenka5948882005-03-27 23:41:39 +000032
Martin Krause3b09b9d2008-02-25 17:52:40 +010033#ifdef CONFIG_OF_LIBFDT
34#include <fdt_support.h>
35#endif /* CONFIG_OF_LIBFDT */
36
Wolfgang Denkd112a2c2007-09-15 20:48:41 +020037DECLARE_GLOBAL_DATA_PTR;
38
wdenkdc130442004-12-12 22:06:17 +000039#ifdef CONFIG_PS2MULT
40void ps2mult_early_init(void);
41#endif
wdenk64519362004-07-11 17:40:54 +000042
Wolfgang Denk3c0d4872010-12-23 19:57:31 +010043#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) && \
44 defined(CONFIG_VIDEO)
Heiko Schocher1ae91442010-12-04 08:34:04 +010045/*
46 * EDID block has been generated using Phoenix EDID Designer 1.3.
47 * This tool creates a text file containing:
48 *
49 * EDID BYTES:
50 *
51 * 0x 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
52 * ------------------------------------------------
53 * 00 | 00 FF FF FF FF FF FF 00 04 21 00 00 00 00 00 00
54 * 10 | 01 00 01 03 00 00 00 00 00 00 00 00 00 00 00 00
55 * 20 | 00 00 00 21 00 00 01 01 01 01 01 01 01 01 01 01
56 * 30 | 01 01 01 01 01 01 64 00 00 00 00 00 00 00 00 00
57 * 40 | 00 00 00 00 00 00 00 00 00 00 00 10 00 00 00 00
58 * 50 | 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 00
59 * 60 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10
60 * 70 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17
61 *
62 * Then this data has been manually converted to the char
63 * array below.
64 */
65static unsigned char edid_buf[128] = {
66 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00,
67 0x04, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68 0x01, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00,
69 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
70 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x01, 0x01,
71 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
72 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x64, 0x00,
73 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
75 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
76 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
77 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
78 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17,
82};
83#endif
84
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020085#ifndef CONFIG_SYS_RAMBOOT
wdenk64519362004-07-11 17:40:54 +000086static void sdram_start (int hi_addr)
87{
88 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
89
90 /* unlock mode register */
91 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 |
92 hi_addr_bit;
93 __asm__ volatile ("sync");
94
95 /* precharge all banks */
96 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
97 hi_addr_bit;
98 __asm__ volatile ("sync");
99
100#if SDRAM_DDR
101 /* set mode register: extended mode */
102 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
103 __asm__ volatile ("sync");
104
105 /* set mode register: reset DLL */
106 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
107 __asm__ volatile ("sync");
108#endif
109
110 /* precharge all banks */
111 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
112 hi_addr_bit;
113 __asm__ volatile ("sync");
114
115 /* auto refresh */
116 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
117 hi_addr_bit;
118 __asm__ volatile ("sync");
119
120 /* set mode register */
121 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
122 __asm__ volatile ("sync");
123
124 /* normal operation */
125 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
126 __asm__ volatile ("sync");
127}
128#endif
129
130/*
131 * ATTENTION: Although partially referenced initdram does NOT make real use
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200132 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
wdenk7dd13292004-07-11 20:04:51 +0000133 * is something else than 0x00000000.
wdenk64519362004-07-11 17:40:54 +0000134 */
135
Becky Brucebd99ae72008-06-09 16:03:40 -0500136phys_size_t initdram (int board_type)
wdenk64519362004-07-11 17:40:54 +0000137{
138 ulong dramsize = 0;
139 ulong dramsize2 = 0;
Wolfgang Denkc98368a2006-07-19 17:52:30 +0200140 uint svr, pvr;
141
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200142#ifndef CONFIG_SYS_RAMBOOT
wdenk64519362004-07-11 17:40:54 +0000143 ulong test1, test2;
144
145 /* setup SDRAM chip selects */
146 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
147 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
148 __asm__ volatile ("sync");
149
150 /* setup config registers */
151 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
152 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
153 __asm__ volatile ("sync");
154
155#if SDRAM_DDR
156 /* set tap delay */
157 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
158 __asm__ volatile ("sync");
159#endif
160
161 /* find RAM size using SDRAM CS0 only */
162 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200163 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
wdenk64519362004-07-11 17:40:54 +0000164 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200165 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
wdenk64519362004-07-11 17:40:54 +0000166 if (test1 > test2) {
167 sdram_start(0);
168 dramsize = test1;
169 } else {
170 dramsize = test2;
171 }
172
173 /* memory smaller than 1MB is impossible */
174 if (dramsize < (1 << 20)) {
175 dramsize = 0;
176 }
177
178 /* set SDRAM CS0 size according to the amount of RAM found */
179 if (dramsize > 0) {
180 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
181 __builtin_ffs(dramsize >> 20) - 1;
182 } else {
183 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
184 }
185
186 /* let SDRAM CS1 start right after CS0 */
187 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001c; /* 512MB */
188
189 /* find RAM size using SDRAM CS1 only */
Martin Krausec03d80a2008-02-25 13:27:52 +0100190 if (!dramsize)
191 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200192 test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
Martin Krausec03d80a2008-02-25 13:27:52 +0100193 if (!dramsize) {
194 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200195 test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
Martin Krausec03d80a2008-02-25 13:27:52 +0100196 }
wdenk64519362004-07-11 17:40:54 +0000197 if (test1 > test2) {
198 sdram_start(0);
199 dramsize2 = test1;
200 } else {
201 dramsize2 = test2;
202 }
203
204 /* memory smaller than 1MB is impossible */
205 if (dramsize2 < (1 << 20)) {
206 dramsize2 = 0;
207 }
208
209 /* set SDRAM CS1 size according to the amount of RAM found */
210 if (dramsize2 > 0) {
211 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
212 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
213 } else {
214 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
215 }
216
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200217#else /* CONFIG_SYS_RAMBOOT */
wdenk64519362004-07-11 17:40:54 +0000218
219 /* retrieve size of memory connected to SDRAM CS0 */
220 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
221 if (dramsize >= 0x13) {
222 dramsize = (1 << (dramsize - 0x13)) << 20;
223 } else {
224 dramsize = 0;
225 }
226
227 /* retrieve size of memory connected to SDRAM CS1 */
228 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
229 if (dramsize2 >= 0x13) {
230 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
231 } else {
232 dramsize2 = 0;
233 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200234#endif /* CONFIG_SYS_RAMBOOT */
wdenk64519362004-07-11 17:40:54 +0000235
Wolfgang Denkc98368a2006-07-19 17:52:30 +0200236 /*
237 * On MPC5200B we need to set the special configuration delay in the
238 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
239 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
240 *
241 * "The SDelay should be written to a value of 0x00000004. It is
242 * required to account for changes caused by normal wafer processing
243 * parameters."
244 */
245 svr = get_svr();
246 pvr = get_pvr();
247 if ((SVR_MJREV(svr) >= 2) &&
248 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
249
250 *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
251 __asm__ volatile ("sync");
252 }
253
254#if defined(CONFIG_TQM5200_B)
255 return dramsize + dramsize2;
256#else
wdenk64519362004-07-11 17:40:54 +0000257 return dramsize;
Wolfgang Denkc98368a2006-07-19 17:52:30 +0200258#endif /* CONFIG_TQM5200_B */
wdenk64519362004-07-11 17:40:54 +0000259}
260
wdenk64519362004-07-11 17:40:54 +0000261int checkboard (void)
262{
Wolfgang Denk99753142006-07-21 11:16:34 +0200263#if defined(CONFIG_TQM5200S)
264# define MODULE_NAME "TQM5200S"
Wolfgang Denkc98368a2006-07-19 17:52:30 +0200265#else
Wolfgang Denk99753142006-07-21 11:16:34 +0200266# define MODULE_NAME "TQM5200"
wdenkdc130442004-12-12 22:06:17 +0000267#endif
Wolfgang Denk99753142006-07-21 11:16:34 +0200268
269#if defined(CONFIG_STK52XX)
270# define CARRIER_NAME "STK52xx"
Wolfgang Denk641e3572006-07-22 01:20:03 +0200271#elif defined(CONFIG_CAM5200)
Wolfgang Denk0129dcd2006-11-23 22:58:58 +0100272# define CARRIER_NAME "CAM5200"
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200273#elif defined(CONFIG_FO300)
274# define CARRIER_NAME "FO300"
Heiko Schocher1ae91442010-12-04 08:34:04 +0100275#elif defined(CONFIG_CHARON)
276# define CARRIER_NAME "CHARON"
Wolfgang Denk99753142006-07-21 11:16:34 +0200277#else
Wolfgang Denk9018bc92006-08-18 23:27:33 +0200278# error "UNKNOWN"
Wolfgang Denkba940932006-07-19 13:50:38 +0200279#endif
wdenkdc130442004-12-12 22:06:17 +0000280
Wolfgang Denk99753142006-07-21 11:16:34 +0200281 puts ( "Board: " MODULE_NAME " (TQ-Components GmbH)\n"
282 " on a " CARRIER_NAME " carrier board\n");
283
wdenk64519362004-07-11 17:40:54 +0000284 return 0;
285}
286
Wolfgang Denk99753142006-07-21 11:16:34 +0200287#undef MODULE_NAME
288#undef CARRIER_NAME
289
wdenk64519362004-07-11 17:40:54 +0000290void flash_preinit(void)
291{
292 /*
293 * Now, when we are in RAM, enable flash write
294 * access for detection process.
295 * Note that CS_BOOT cannot be cleared when
296 * executing in flash.
297 */
wdenk64519362004-07-11 17:40:54 +0000298 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
299}
300
301
302#ifdef CONFIG_PCI
303static struct pci_controller hose;
304
305extern void pci_mpc5xxx_init(struct pci_controller *);
306
307void pci_init_board(void)
308{
309 pci_mpc5xxx_init(&hose);
310}
311#endif
312
Jon Loeliger761ea742007-07-10 10:48:22 -0500313#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
wdenk64519362004-07-11 17:40:54 +0000314
315#if defined (CONFIG_MINIFAP)
316#define SM501_POWER_MODE0_GATE 0x00000040UL
317#define SM501_POWER_MODE1_GATE 0x00000048UL
318#define POWER_MODE_GATE_GPIO_PWM_I2C 0x00000040UL
319#define SM501_GPIO_DATA_DIR_HIGH 0x0001000CUL
320#define SM501_GPIO_DATA_HIGH 0x00010004UL
321#define SM501_GPIO_51 0x00080000UL
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100322#endif /* CONFIG MINIFAP */
wdenk64519362004-07-11 17:40:54 +0000323
324void init_ide_reset (void)
325{
326 debug ("init_ide_reset\n");
327
328#if defined (CONFIG_MINIFAP)
329 /* Configure GPIO_51 of the SM501 grafic controller as ATA reset */
330
331 /* enable GPIO control (in both power modes) */
332 *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE0_GATE) |=
333 POWER_MODE_GATE_GPIO_PWM_I2C;
334 *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE1_GATE) |=
335 POWER_MODE_GATE_GPIO_PWM_I2C;
336 /* configure GPIO51 as output */
337 *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_DIR_HIGH) |=
338 SM501_GPIO_51;
339#else
340 /* Configure PSC1_4 as GPIO output for ATA reset */
341 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
342 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
Martin Krause5f7c6f92008-04-03 14:29:01 +0200343
344 /* by default the ATA reset is de-asserted */
345 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
wdenk64519362004-07-11 17:40:54 +0000346#endif
347}
348
349void ide_set_reset (int idereset)
350{
351 debug ("ide_reset(%d)\n", idereset);
352
353#if defined (CONFIG_MINIFAP)
354 if (idereset) {
355 *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) &=
356 ~SM501_GPIO_51;
357 } else {
358 *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) |=
359 SM501_GPIO_51;
360 }
361#else
362 if (idereset) {
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100363 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
wdenk64519362004-07-11 17:40:54 +0000364 } else {
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100365 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
wdenk64519362004-07-11 17:40:54 +0000366 }
367#endif
368}
Jon Loeliger761ea742007-07-10 10:48:22 -0500369#endif
wdenk64519362004-07-11 17:40:54 +0000370
371#ifdef CONFIG_POST
372/*
373 * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
374 * is left open, no keypress is detected.
375 */
376int post_hotkeys_pressed(void)
377{
Wolfgang Denkf67272a2006-10-09 01:07:53 +0200378#ifdef CONFIG_STK52XX
wdenk64519362004-07-11 17:40:54 +0000379 struct mpc5xxx_gpio *gpio;
380
381 gpio = (struct mpc5xxx_gpio*) MPC5XXX_GPIO;
382
383 /*
Detlev Zundel3ba0fa72009-10-07 16:38:05 +0200384 * Configure PSC6_0 through PSC6_3 as GPIO.
wdenk7dd13292004-07-11 20:04:51 +0000385 */
Detlev Zundel3ba0fa72009-10-07 16:38:05 +0200386 gpio->port_config &= ~(0x00700000);
wdenk64519362004-07-11 17:40:54 +0000387
388 /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
389 gpio->simple_gpioe |= 0x20000000;
390
391 /* Configure GPIO_IRDA_1 as input */
392 gpio->simple_ddr &= ~(0x20000000);
393
394 return ((gpio->simple_ival & 0x20000000) ? 0 : 1);
Wolfgang Denkf67272a2006-10-09 01:07:53 +0200395#else
396 return 0;
397#endif
wdenk64519362004-07-11 17:40:54 +0000398}
399#endif
400
wdenkdc130442004-12-12 22:06:17 +0000401#ifdef CONFIG_BOARD_EARLY_INIT_R
402int board_early_init_r (void)
403{
Markus Klotzbuecher2f1a4ce2008-01-09 13:57:10 +0100404
Wolfgang Denk92254112007-11-18 16:36:27 +0100405 extern int usb_cpu_init(void);
406
Marian Balakowiczfa65a4a2007-10-24 01:37:36 +0200407#ifdef CONFIG_PS2MULT
wdenkdc130442004-12-12 22:06:17 +0000408 ps2mult_early_init();
Marian Balakowiczfa65a4a2007-10-24 01:37:36 +0200409#endif /* CONFIG_PS2MULT */
410
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200411#if defined(CONFIG_USB_OHCI_NEW) && defined(CONFIG_SYS_USB_OHCI_CPU_INIT)
Marian Balakowiczfa65a4a2007-10-24 01:37:36 +0200412 /* Low level USB init, required for proper kernel operation */
413 usb_cpu_init();
414#endif
415
wdenkdc130442004-12-12 22:06:17 +0000416 return (0);
417}
418#endif
wdenkdc130442004-12-12 22:06:17 +0000419
Wolfgang Denk573a3ad2006-09-13 10:47:05 +0200420#ifdef CONFIG_FO300
421int silent_boot (void)
422{
423 vu_long timer3_status;
424
425 /* Configure GPT3 as GPIO input */
426 *(vu_long *)MPC5XXX_GPT3_ENABLE = 0x00000004;
427
428 /* Read in TIMER_3 pin status */
429 timer3_status = *(vu_long *)MPC5XXX_GPT3_STATUS;
430
431#ifdef FO300_SILENT_CONSOLE_WHEN_S1_CLOSED
432 /* Force silent console mode if S1 switch
433 * is in closed position (TIMER_3 pin status is LOW). */
434 if (MPC5XXX_GPT_GPIO_PIN(timer3_status) == 0)
435 return 1;
436#else
437 /* Force silent console mode if S1 switch
438 * is in open position (TIMER_3 pin status is HIGH). */
439 if (MPC5XXX_GPT_GPIO_PIN(timer3_status) == 1)
440 return 1;
441#endif
442
443 return 0;
444}
445
446int board_early_init_f (void)
447{
Wolfgang Denk573a3ad2006-09-13 10:47:05 +0200448 if (silent_boot())
449 gd->flags |= GD_FLG_SILENT;
450
451 return 0;
452}
453#endif /* CONFIG_FO300 */
454
Heiko Schocher1ae91442010-12-04 08:34:04 +0100455#if defined(CONFIG_CHARON)
456#include <i2c.h>
457#include <asm/io.h>
458
459/* The TFP410 registers */
460#define TFP410_REG_VEN_ID_L 0x00
461#define TFP410_REG_VEN_ID_H 0x01
462#define TFP410_REG_DEV_ID_L 0x02
463#define TFP410_REG_DEV_ID_H 0x03
464#define TFP410_REG_REV_ID 0x04
465
466#define TFP410_REG_CTL_1_MODE 0x08
467#define TFP410_REG_CTL_2_MODE 0x09
468#define TFP410_REG_CTL_3_MODE 0x0A
469
470#define TFP410_REG_CFG 0x0B
471
472#define TFP410_REG_DE_DLY 0x32
473#define TFP410_REG_DE_CTL 0x33
474#define TFP410_REG_DE_TOP 0x34
475#define TFP410_REG_DE_CNT_L 0x36
476#define TFP410_REG_DE_CNT_H 0x37
477#define TFP410_REG_DE_LIN_L 0x38
478#define TFP410_REG_DE_LIN_H 0x39
479
480#define TFP410_REG_H_RES_L 0x3A
481#define TFP410_REG_H_RES_H 0x3B
482#define TFP410_REG_V_RES_L 0x3C
483#define TFP410_REG_V_RES_H 0x3D
484
485static int tfp410_read_reg(int reg, uchar *buf)
486{
487 if (i2c_read(CONFIG_SYS_TFP410_ADDR, reg, 1, buf, 1) != 0) {
488 puts ("Error reading the chip.\n");
489 return 1;
490 }
491 return 0;
492}
493
494static int tfp410_write_reg(int reg, uchar buf)
495{
496 if (i2c_write(CONFIG_SYS_TFP410_ADDR, reg, 1, &buf, 1) != 0) {
497 puts ("Error writing the chip.\n");
498 return 1;
499 }
500 return 0;
501}
502
503typedef struct _tfp410_config {
504 int reg;
505 uchar val;
506}TFP410_CONFIG;
507
508static TFP410_CONFIG tfp410_configtbl[] = {
509 {TFP410_REG_CTL_1_MODE, 0x37},
510 {TFP410_REG_CTL_2_MODE, 0x20},
511 {TFP410_REG_CTL_3_MODE, 0x80},
512 {TFP410_REG_DE_DLY, 0x90},
513 {TFP410_REG_DE_CTL, 0x00},
514 {TFP410_REG_DE_TOP, 0x23},
515 {TFP410_REG_DE_CNT_H, 0x02},
516 {TFP410_REG_DE_CNT_L, 0x80},
517 {TFP410_REG_DE_LIN_H, 0x01},
518 {TFP410_REG_DE_LIN_L, 0xe0},
519 {-1, 0},
520};
521
522static int charon_last_stage_init(void)
523{
524 volatile struct mpc5xxx_lpb *lpb =
525 (struct mpc5xxx_lpb *) MPC5XXX_LPB;
526 int oldbus = i2c_get_bus_num();
527 uchar buf;
528 int i = 0;
529
530 i2c_set_bus_num(CONFIG_SYS_TFP410_BUS);
531
532 /* check version */
533 if (tfp410_read_reg(TFP410_REG_DEV_ID_H, &buf) != 0)
534 return -1;
535 if (!(buf & 0x04))
536 return -1;
537 if (tfp410_read_reg(TFP410_REG_DEV_ID_L, &buf) != 0)
538 return -1;
539 if (!(buf & 0x10))
540 return -1;
541 /* OK, now init the chip */
542 while (tfp410_configtbl[i].reg != -1) {
543 int ret;
544
545 ret = tfp410_write_reg(tfp410_configtbl[i].reg,
546 tfp410_configtbl[i].val);
547 if (ret != 0)
548 return -1;
549 i++;
550 }
551 printf("TFP410 initialized.\n");
552 i2c_set_bus_num(oldbus);
553
554 /* set deadcycle for cs3 to 0 */
555 setbits_be32(&lpb->cs_deadcycle, 0xffffcfff);
556 return 0;
557}
558#endif
559
wdenkdc130442004-12-12 22:06:17 +0000560int last_stage_init (void)
561{
562 /*
563 * auto scan for really existing devices and re-set chip select
564 * configuration.
565 */
566 u16 save, tmp;
567 int restore;
568
569 /*
570 * Check for SRAM and SRAM size
571 */
572
Wolfgang Denk71112152005-08-18 11:55:22 +0200573 /* save original SRAM content */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200574 save = *(volatile u16 *)CONFIG_SYS_CS2_START;
wdenkdc130442004-12-12 22:06:17 +0000575 restore = 1;
wdenk07d7e6b2004-12-16 21:44:03 +0000576
wdenkdc130442004-12-12 22:06:17 +0000577 /* write test pattern to SRAM */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200578 *(volatile u16 *)CONFIG_SYS_CS2_START = 0xA5A5;
wdenkdc130442004-12-12 22:06:17 +0000579 __asm__ volatile ("sync");
580 /*
581 * Put a different pattern on the data lines: otherwise they may float
582 * long enough to read back what we wrote.
583 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200584 tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
wdenkdc130442004-12-12 22:06:17 +0000585 if (tmp == 0xA5A5)
586 puts ("!! possible error in SRAM detection\n");
wdenk07d7e6b2004-12-16 21:44:03 +0000587
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200588 if (*(volatile u16 *)CONFIG_SYS_CS2_START != 0xA5A5) {
wdenkdc130442004-12-12 22:06:17 +0000589 /* no SRAM at all, disable cs */
590 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 18);
591 *(vu_long *)MPC5XXX_CS2_START = 0x0000FFFF;
592 *(vu_long *)MPC5XXX_CS2_STOP = 0x0000FFFF;
593 restore = 0;
594 __asm__ volatile ("sync");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200595 } else if (*(volatile u16 *)(CONFIG_SYS_CS2_START + (1<<19)) == 0xA5A5) {
wdenkdc130442004-12-12 22:06:17 +0000596 /* make sure that we access a mirrored address */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200597 *(volatile u16 *)CONFIG_SYS_CS2_START = 0x1111;
wdenkdc130442004-12-12 22:06:17 +0000598 __asm__ volatile ("sync");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200599 if (*(volatile u16 *)(CONFIG_SYS_CS2_START + (1<<19)) == 0x1111) {
wdenkdc130442004-12-12 22:06:17 +0000600 /* SRAM size = 512 kByte */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200601 *(vu_long *)MPC5XXX_CS2_STOP = STOP_REG(CONFIG_SYS_CS2_START,
wdenkdc130442004-12-12 22:06:17 +0000602 0x80000);
603 __asm__ volatile ("sync");
604 puts ("SRAM: 512 kB\n");
605 }
606 else
wdenk07d7e6b2004-12-16 21:44:03 +0000607 puts ("!! possible error in SRAM detection\n");
Wolfgang Denk71112152005-08-18 11:55:22 +0200608 } else {
wdenk07d7e6b2004-12-16 21:44:03 +0000609 puts ("SRAM: 1 MB\n");
wdenkdc130442004-12-12 22:06:17 +0000610 }
611 /* restore origianl SRAM content */
612 if (restore) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200613 *(volatile u16 *)CONFIG_SYS_CS2_START = save;
wdenkdc130442004-12-12 22:06:17 +0000614 __asm__ volatile ("sync");
615 }
wdenk07d7e6b2004-12-16 21:44:03 +0000616
Martin Krause8dcc9f62007-10-22 16:40:06 +0200617#ifndef CONFIG_TQM5200S /* The TQM5200S has no SM501 grafic controller */
wdenk07d7e6b2004-12-16 21:44:03 +0000618 /*
wdenkdc130442004-12-12 22:06:17 +0000619 * Check for Grafic Controller
620 */
621
622 /* save origianl FB content */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200623 save = *(volatile u16 *)CONFIG_SYS_CS1_START;
wdenkdc130442004-12-12 22:06:17 +0000624 restore = 1;
wdenk07d7e6b2004-12-16 21:44:03 +0000625
wdenkdc130442004-12-12 22:06:17 +0000626 /* write test pattern to FB memory */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200627 *(volatile u16 *)CONFIG_SYS_CS1_START = 0xA5A5;
wdenkdc130442004-12-12 22:06:17 +0000628 __asm__ volatile ("sync");
629 /*
630 * Put a different pattern on the data lines: otherwise they may float
631 * long enough to read back what we wrote.
632 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200633 tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
wdenkdc130442004-12-12 22:06:17 +0000634 if (tmp == 0xA5A5)
635 puts ("!! possible error in grafic controller detection\n");
wdenk07d7e6b2004-12-16 21:44:03 +0000636
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200637 if (*(volatile u16 *)CONFIG_SYS_CS1_START != 0xA5A5) {
wdenkdc130442004-12-12 22:06:17 +0000638 /* no grafic controller at all, disable cs */
639 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 17);
640 *(vu_long *)MPC5XXX_CS1_START = 0x0000FFFF;
641 *(vu_long *)MPC5XXX_CS1_STOP = 0x0000FFFF;
642 restore = 0;
643 __asm__ volatile ("sync");
Wolfgang Denk71112152005-08-18 11:55:22 +0200644 } else {
wdenk07d7e6b2004-12-16 21:44:03 +0000645 puts ("VGA: SMI501 (Voyager) with 8 MB\n");
wdenkdc130442004-12-12 22:06:17 +0000646 }
647 /* restore origianl FB content */
648 if (restore) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200649 *(volatile u16 *)CONFIG_SYS_CS1_START = save;
wdenkdc130442004-12-12 22:06:17 +0000650 __asm__ volatile ("sync");
651 }
wdenk07d7e6b2004-12-16 21:44:03 +0000652
Wolfgang Denk573a3ad2006-09-13 10:47:05 +0200653#ifdef CONFIG_FO300
654 if (silent_boot()) {
655 setenv("bootdelay", "0");
656 disable_ctrlc(1);
657 }
658#endif
Wolfgang Denk92254112007-11-18 16:36:27 +0100659#endif /* !CONFIG_TQM5200S */
Wolfgang Denk573a3ad2006-09-13 10:47:05 +0200660
Heiko Schocher1ae91442010-12-04 08:34:04 +0100661#if defined(CONFIG_CHARON)
662 charon_last_stage_init();
663#endif
wdenkdc130442004-12-12 22:06:17 +0000664 return 0;
665}
wdenka5948882005-03-27 23:41:39 +0000666
667#ifdef CONFIG_VIDEO_SM501
668
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200669#ifdef CONFIG_FO300
670#define DISPLAY_WIDTH 800
671#else
wdenka5948882005-03-27 23:41:39 +0000672#define DISPLAY_WIDTH 640
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200673#endif
wdenka5948882005-03-27 23:41:39 +0000674#define DISPLAY_HEIGHT 480
675
676#ifdef CONFIG_VIDEO_SM501_8BPP
677#error CONFIG_VIDEO_SM501_8BPP not supported.
678#endif /* CONFIG_VIDEO_SM501_8BPP */
679
680#ifdef CONFIG_VIDEO_SM501_16BPP
681#error CONFIG_VIDEO_SM501_16BPP not supported.
682#endif /* CONFIG_VIDEO_SM501_16BPP */
683#ifdef CONFIG_VIDEO_SM501_32BPP
684static const SMI_REGS init_regs [] =
685{
686#if 0 /* CRT only */
687 {0x00004, 0x0},
688 {0x00048, 0x00021807},
689 {0x0004C, 0x10090a01},
690 {0x00054, 0x1},
691 {0x00040, 0x00021807},
692 {0x00044, 0x10090a01},
693 {0x00054, 0x0},
694 {0x80200, 0x00010000},
695 {0x80204, 0x0},
696 {0x80208, 0x0A000A00},
697 {0x8020C, 0x02fa027f},
698 {0x80210, 0x004a028b},
699 {0x80214, 0x020c01df},
700 {0x80218, 0x000201e9},
701 {0x80200, 0x00013306},
702#else /* panel + CRT */
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200703#ifdef CONFIG_FO300
wdenka5948882005-03-27 23:41:39 +0000704 {0x00004, 0x0},
705 {0x00048, 0x00021807},
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200706 {0x0004C, 0x301a0a01},
707 {0x00054, 0x1},
708 {0x00040, 0x00021807},
709 {0x00044, 0x091a0a01},
710 {0x00054, 0x0},
711 {0x80000, 0x0f013106},
712 {0x80004, 0xc428bb17},
713 {0x8000C, 0x00000000},
714 {0x80010, 0x0C800C80},
715 {0x80014, 0x03200000},
716 {0x80018, 0x01e00000},
717 {0x8001C, 0x00000000},
718 {0x80020, 0x01e00320},
719 {0x80024, 0x042a031f},
720 {0x80028, 0x0086034a},
721 {0x8002C, 0x020c01df},
722 {0x80030, 0x000201ea},
723 {0x80200, 0x00010000},
724#else
725 {0x00004, 0x0},
726 {0x00048, 0x00021807},
wdenka5948882005-03-27 23:41:39 +0000727 {0x0004C, 0x091a0a01},
728 {0x00054, 0x1},
729 {0x00040, 0x00021807},
730 {0x00044, 0x091a0a01},
731 {0x00054, 0x0},
732 {0x80000, 0x0f013106},
733 {0x80004, 0xc428bb17},
734 {0x8000C, 0x00000000},
735 {0x80010, 0x0a000a00},
736 {0x80014, 0x02800000},
737 {0x80018, 0x01e00000},
738 {0x8001C, 0x00000000},
739 {0x80020, 0x01e00280},
740 {0x80024, 0x02fa027f},
741 {0x80028, 0x004a028b},
742 {0x8002C, 0x020c01df},
743 {0x80030, 0x000201e9},
744 {0x80200, 0x00010000},
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200745#endif /* #ifdef CONFIG_FO300 */
wdenka5948882005-03-27 23:41:39 +0000746#endif
747 {0, 0}
748};
749#endif /* CONFIG_VIDEO_SM501_32BPP */
750
751#ifdef CONFIG_CONSOLE_EXTRA_INFO
752/*
753 * Return text to be printed besides the logo.
754 */
755void video_get_info_str (int line_number, char *info)
756{
757 if (line_number == 1) {
Wolfgang Denk3f2f9dd2006-06-16 16:11:34 +0200758 strcpy (info, " Board: TQM5200 (TQ-Components GmbH)");
Heiko Schocher1ae91442010-12-04 08:34:04 +0100759#if defined (CONFIG_CHARON) || defined (CONFIG_FO300) || \
Masahiro Yamada49c6e602015-03-17 12:28:06 +0900760 defined(CONFIG_STK52XX)
wdenka5948882005-03-27 23:41:39 +0000761 } else if (line_number == 2) {
Heiko Schocher1ae91442010-12-04 08:34:04 +0100762#if defined (CONFIG_CHARON)
763 strcpy (info, " on a CHARON carrier board");
764#endif
Wolfgang Denkba940932006-07-19 13:50:38 +0200765#if defined (CONFIG_STK52XX)
Wolfgang Denk99753142006-07-21 11:16:34 +0200766 strcpy (info, " on a STK52xx carrier board");
wdenka5948882005-03-27 23:41:39 +0000767#endif
Marian Balakowiczbcb0cca2006-08-18 19:14:46 +0200768#if defined (CONFIG_FO300)
769 strcpy (info, " on a FO300 carrier board");
770#endif
Wolfgang Denkba940932006-07-19 13:50:38 +0200771#endif
wdenka5948882005-03-27 23:41:39 +0000772 }
773 else {
774 info [0] = '\0';
775 }
776}
777#endif
778
779/*
Wolfgang Denk71112152005-08-18 11:55:22 +0200780 * Returns SM501 register base address. First thing called in the
781 * driver. Checks if SM501 is physically present.
wdenka5948882005-03-27 23:41:39 +0000782 */
783unsigned int board_video_init (void)
784{
Wolfgang Denk71112152005-08-18 11:55:22 +0200785 u16 save, tmp;
786 int restore, ret;
787
788 /*
789 * Check for Grafic Controller
790 */
791
792 /* save origianl FB content */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200793 save = *(volatile u16 *)CONFIG_SYS_CS1_START;
Wolfgang Denk71112152005-08-18 11:55:22 +0200794 restore = 1;
795
796 /* write test pattern to FB memory */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200797 *(volatile u16 *)CONFIG_SYS_CS1_START = 0xA5A5;
Wolfgang Denk71112152005-08-18 11:55:22 +0200798 __asm__ volatile ("sync");
799 /*
800 * Put a different pattern on the data lines: otherwise they may float
801 * long enough to read back what we wrote.
802 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200803 tmp = *(volatile u16 *)CONFIG_SYS_FLASH_BASE;
Wolfgang Denk71112152005-08-18 11:55:22 +0200804 if (tmp == 0xA5A5)
805 puts ("!! possible error in grafic controller detection\n");
806
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200807 if (*(volatile u16 *)CONFIG_SYS_CS1_START != 0xA5A5) {
Wolfgang Denk71112152005-08-18 11:55:22 +0200808 /* no grafic controller found */
809 restore = 0;
810 ret = 0;
811 } else {
812 ret = SM501_MMIO_BASE;
813 }
814
815 if (restore) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200816 *(volatile u16 *)CONFIG_SYS_CS1_START = save;
Wolfgang Denk71112152005-08-18 11:55:22 +0200817 __asm__ volatile ("sync");
818 }
819 return ret;
wdenka5948882005-03-27 23:41:39 +0000820}
821
822/*
823 * Returns SM501 framebuffer address
824 */
825unsigned int board_video_get_fb (void)
826{
827 return SM501_FB_BASE;
828}
829
830/*
831 * Called after initializing the SM501 and before clearing the screen.
832 */
833void board_validate_screen (unsigned int base)
834{
835}
836
837/*
838 * Return a pointer to the initialization sequence.
839 */
840const SMI_REGS *board_get_regs (void)
841{
842 return init_regs;
843}
844
845int board_get_width (void)
846{
847 return DISPLAY_WIDTH;
848}
849
850int board_get_height (void)
851{
852 return DISPLAY_HEIGHT;
853}
854
855#endif /* CONFIG_VIDEO_SM501 */
Bartlomiej Sieka7a432ce2007-06-08 14:52:22 +0200856
Grant Likely8d1e6e72007-09-06 09:46:23 -0600857#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Simon Glass2aec3cc2014-10-23 18:58:47 -0600858int ft_board_setup(void *blob, bd_t *bd)
Bartlomiej Sieka7a432ce2007-06-08 14:52:22 +0200859{
860 ft_cpu_setup(blob, bd);
Heiko Schocher1ae91442010-12-04 08:34:04 +0100861#if defined(CONFIG_VIDEO)
862 fdt_add_edid(blob, "smi,sm501", edid_buf);
863#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600864
865 return 0;
Bartlomiej Sieka7a432ce2007-06-08 14:52:22 +0200866}
Grant Likely8d1e6e72007-09-06 09:46:23 -0600867#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
Ben Warrenf2c1acb2008-08-31 10:03:22 -0700868
Heiko Schocher1ae91442010-12-04 08:34:04 +0100869#if defined(CONFIG_RESET_PHY_R)
870#include <miiphy.h>
871
872void reset_phy(void)
873{
874 /* init Micrel KSZ8993 PHY */
875 miiphy_write("FEC", CONFIG_PHY_ADDR, 0x01, 0x09);
876}
877#endif
878
Ben Warrenf2c1acb2008-08-31 10:03:22 -0700879int board_eth_init(bd_t *bis)
880{
Ben Warrencba88512008-08-31 10:39:12 -0700881 cpu_eth_init(bis); /* Built in FEC comes first */
Ben Warrenf2c1acb2008-08-31 10:03:22 -0700882 return pci_eth_init(bis);
883}