blob: 2b3fad2513e16b8ac5e1322214072fada39219ce [file] [log] [blame]
wdenk1cb8e982003-03-06 21:55:29 +00001/*
2 * (C) Copyright 2002
3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
5 *
6 * (C) Copyright 2002
7 * David Mueller, ELSOFT AG, <d.mueller@elsoft.ch>
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#include <common.h>
29#include <s3c2410.h>
Jean-Christophe PLAGNIOL-VILLARD28c34502009-05-16 12:14:56 +020030#include <stdio_dev.h>
wdenk1cb8e982003-03-06 21:55:29 +000031#include <i2c.h>
32
33#include "vcma9.h"
34#include "../common/common_util.h"
35
Wolfgang Denkd87080b2006-03-31 18:32:53 +020036DECLARE_GLOBAL_DATA_PTR;
wdenk1cb8e982003-03-06 21:55:29 +000037
38#define FCLK_SPEED 1
39
40#if FCLK_SPEED==0 /* Fout = 203MHz, Fin = 12MHz for Audio */
41#define M_MDIV 0xC3
42#define M_PDIV 0x4
43#define M_SDIV 0x1
44#elif FCLK_SPEED==1 /* Fout = 202.8MHz */
45#define M_MDIV 0xA1
46#define M_PDIV 0x3
47#define M_SDIV 0x1
48#endif
49
50#define USB_CLOCK 1
51
52#if USB_CLOCK==0
53#define U_M_MDIV 0xA1
54#define U_M_PDIV 0x3
55#define U_M_SDIV 0x1
56#elif USB_CLOCK==1
57#define U_M_MDIV 0x48
58#define U_M_PDIV 0x3
59#define U_M_SDIV 0x2
60#endif
61
62static inline void delay(unsigned long loops)
63{
64 __asm__ volatile ("1:\n"
65 "subs %0, %1, #1\n"
66 "bne 1b":"=r" (loops):"0" (loops));
67}
68
69/*
70 * Miscellaneous platform dependent initialisations
71 */
72
73int board_init(void)
74{
wdenk48b42612003-06-19 23:01:32 +000075 S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
76 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
wdenk1cb8e982003-03-06 21:55:29 +000077
78 /* to reduce PLL lock time, adjust the LOCKTIME register */
wdenk48b42612003-06-19 23:01:32 +000079 clk_power->LOCKTIME = 0xFFFFFF;
wdenk1cb8e982003-03-06 21:55:29 +000080
81 /* configure MPLL */
wdenk48b42612003-06-19 23:01:32 +000082 clk_power->MPLLCON = ((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV);
wdenk1cb8e982003-03-06 21:55:29 +000083
84 /* some delay between MPLL and UPLL */
85 delay (4000);
86
87 /* configure UPLL */
wdenk48b42612003-06-19 23:01:32 +000088 clk_power->UPLLCON = ((U_M_MDIV << 12) + (U_M_PDIV << 4) + U_M_SDIV);
wdenk1cb8e982003-03-06 21:55:29 +000089
90 /* some delay between MPLL and UPLL */
91 delay (8000);
92
93 /* set up the I/O ports */
wdenk48b42612003-06-19 23:01:32 +000094 gpio->GPACON = 0x007FFFFF;
95 gpio->GPBCON = 0x002AAAAA;
96 gpio->GPBUP = 0x000002BF;
97 gpio->GPCCON = 0xAAAAAAAA;
98 gpio->GPCUP = 0x0000FFFF;
99 gpio->GPDCON = 0xAAAAAAAA;
100 gpio->GPDUP = 0x0000FFFF;
101 gpio->GPECON = 0xAAAAAAAA;
102 gpio->GPEUP = 0x000037F7;
103 gpio->GPFCON = 0x00000000;
104 gpio->GPFUP = 0x00000000;
105 gpio->GPGCON = 0xFFEAFF5A;
106 gpio->GPGUP = 0x0000F0DC;
107 gpio->GPHCON = 0x0028AAAA;
108 gpio->GPHUP = 0x00000656;
wdenk1cb8e982003-03-06 21:55:29 +0000109
110 /* setup correct IRQ modes for NIC */
wdenk48b42612003-06-19 23:01:32 +0000111 gpio->EXTINT2 = (gpio->EXTINT2 & ~(7<<8)) | (4<<8); /* rising edge mode */
112
113 /* select USB port 2 to be host or device (fix to host for now) */
114 gpio->MISCCR |= 0x08;
wdenk1cb8e982003-03-06 21:55:29 +0000115
116 /* init serial */
117 gd->baudrate = CONFIG_BAUDRATE;
118 gd->have_console = 1;
119 serial_init();
120
121 /* arch number of VCMA9-Board */
wdenk731215e2004-10-10 18:41:04 +0000122 gd->bd->bi_arch_number = MACH_TYPE_MPL_VCMA9;
wdenk1cb8e982003-03-06 21:55:29 +0000123
124 /* adress of boot parameters */
125 gd->bd->bi_boot_params = 0x30000100;
126
127 icache_enable();
128 dcache_enable();
129
130 return 0;
131}
132
wdenk1cb8e982003-03-06 21:55:29 +0000133/*
wdenk48b42612003-06-19 23:01:32 +0000134 * NAND flash initialization.
135 */
Jon Loeliger3fe00102007-07-09 18:38:39 -0500136#if defined(CONFIG_CMD_NAND)
wdenka43278a2003-09-11 19:48:06 +0000137extern ulong
wdenk48b42612003-06-19 23:01:32 +0000138nand_probe(ulong physadr);
139
140
141static inline void NF_Reset(void)
142{
143 int i;
144
145 NF_SetCE(NFCE_LOW);
146 NF_Cmd(0xFF); /* reset command */
147 for(i = 0; i < 10; i++); /* tWB = 100ns. */
148 NF_WaitRB(); /* wait 200~500us; */
149 NF_SetCE(NFCE_HIGH);
150}
151
152
153static inline void NF_Init(void)
154{
wdenk531716e2003-09-13 19:01:12 +0000155#if 0 /* a little bit too optimistic */
wdenk48b42612003-06-19 23:01:32 +0000156#define TACLS 0
157#define TWRPH0 3
158#define TWRPH1 0
wdenk531716e2003-09-13 19:01:12 +0000159#else
160#define TACLS 0
161#define TWRPH0 4
162#define TWRPH1 2
163#endif
164
wdenk48b42612003-06-19 23:01:32 +0000165 NF_Conf((1<<15)|(0<<14)|(0<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0));
wdenk8bde7f72003-06-27 21:31:46 +0000166 /*nand->NFCONF = (1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0); */
167 /* 1 1 1 1, 1 xxx, r xxx, r xxx */
168 /* En 512B 4step ECCR nFCE=H tACLS tWRPH0 tWRPH1 */
wdenk48b42612003-06-19 23:01:32 +0000169
170 NF_Reset();
171}
172
173void
174nand_init(void)
175{
176 S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
177
178 NF_Init();
wdenka43278a2003-09-11 19:48:06 +0000179#ifdef DEBUG
wdenk48b42612003-06-19 23:01:32 +0000180 printf("NAND flash probing at 0x%.8lX\n", (ulong)nand);
wdenka43278a2003-09-11 19:48:06 +0000181#endif
wdenk531716e2003-09-13 19:01:12 +0000182 printf ("%4lu MB\n", nand_probe((ulong)nand) >> 20);
wdenk48b42612003-06-19 23:01:32 +0000183}
184#endif
185
186/*
wdenk1cb8e982003-03-06 21:55:29 +0000187 * Get some Board/PLD Info
188 */
189
wdenk531716e2003-09-13 19:01:12 +0000190static u8 Get_PLD_ID(void)
wdenk1cb8e982003-03-06 21:55:29 +0000191{
wdenk531716e2003-09-13 19:01:12 +0000192 VCMA9_PLD * const pld = VCMA9_GetBase_PLD();
wdenk42d1f032003-10-15 23:53:47 +0000193
wdenk531716e2003-09-13 19:01:12 +0000194 return(pld->ID);
wdenk1cb8e982003-03-06 21:55:29 +0000195}
196
wdenk531716e2003-09-13 19:01:12 +0000197static u8 Get_PLD_BOARD(void)
wdenk1cb8e982003-03-06 21:55:29 +0000198{
wdenk531716e2003-09-13 19:01:12 +0000199 VCMA9_PLD * const pld = VCMA9_GetBase_PLD();
wdenk42d1f032003-10-15 23:53:47 +0000200
wdenk531716e2003-09-13 19:01:12 +0000201 return(pld->BOARD);
wdenk1cb8e982003-03-06 21:55:29 +0000202}
203
wdenk531716e2003-09-13 19:01:12 +0000204static u8 Get_PLD_SDRAM(void)
205{
206 VCMA9_PLD * const pld = VCMA9_GetBase_PLD();
wdenk42d1f032003-10-15 23:53:47 +0000207
wdenk531716e2003-09-13 19:01:12 +0000208 return(pld->SDRAM);
209}
210
211static u8 Get_PLD_Version(void)
wdenk1cb8e982003-03-06 21:55:29 +0000212{
213 return((Get_PLD_ID() >> 4) & 0x0F);
214}
215
wdenk531716e2003-09-13 19:01:12 +0000216static u8 Get_PLD_Revision(void)
wdenk1cb8e982003-03-06 21:55:29 +0000217{
218 return(Get_PLD_ID() & 0x0F);
219}
220
wdenk34b30492003-09-16 21:07:28 +0000221#if 0 /* not used */
wdenk1cb8e982003-03-06 21:55:29 +0000222static int Get_Board_Config(void)
223{
wdenk531716e2003-09-13 19:01:12 +0000224 u8 config = Get_PLD_BOARD() & 0x03;
wdenk1cb8e982003-03-06 21:55:29 +0000225
226 if (config == 3)
227 return 1;
228 else
229 return 0;
230}
wdenk34b30492003-09-16 21:07:28 +0000231#endif
wdenk1cb8e982003-03-06 21:55:29 +0000232
233static uchar Get_Board_PCB(void)
234{
235 return(((Get_PLD_BOARD() >> 4) & 0x03) + 'A');
236}
237
wdenk531716e2003-09-13 19:01:12 +0000238static u8 Get_SDRAM_ChipNr(void)
239{
240 switch ((Get_PLD_SDRAM() >> 4) & 0x0F) {
241 case 0: return 4;
242 case 1: return 1;
243 case 2: return 2;
244 default: return 0;
245 }
246}
247
248static ulong Get_SDRAM_ChipSize(void)
249{
250 switch (Get_PLD_SDRAM() & 0x0F) {
251 case 0: return 16 * (1024*1024);
252 case 1: return 32 * (1024*1024);
253 case 2: return 8 * (1024*1024);
254 case 3: return 8 * (1024*1024);
255 default: return 0;
wdenk42d1f032003-10-15 23:53:47 +0000256 }
wdenk531716e2003-09-13 19:01:12 +0000257}
258static const char * Get_SDRAM_ChipGeom(void)
259{
260 switch (Get_PLD_SDRAM() & 0x0F) {
261 case 0: return "4Mx8x4";
262 case 1: return "8Mx8x4";
263 case 2: return "2Mx8x4";
264 case 3: return "4Mx8x2";
265 default: return "unknown";
266 }
267}
268
269static void Show_VCMA9_Info(char *board_name, char *serial)
270{
271 printf("Board: %s SN: %s PCB Rev: %c PLD(%d,%d)\n",
272 board_name, serial, Get_Board_PCB(), Get_PLD_Version(), Get_PLD_Revision());
273 printf("SDRAM: %d chips %s\n", Get_SDRAM_ChipNr(), Get_SDRAM_ChipGeom());
274}
275
276int dram_init(void)
277{
wdenk531716e2003-09-13 19:01:12 +0000278 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
279 gd->bd->bi_dram[0].size = Get_SDRAM_ChipSize() * Get_SDRAM_ChipNr();
280
281 return 0;
282}
283
wdenk1cb8e982003-03-06 21:55:29 +0000284/* ------------------------------------------------------------------------- */
285
286/*
287 * Check Board Identity:
288 */
289
290int checkboard(void)
291{
Wolfgang Denkfc19e362007-10-13 23:51:14 +0200292 char s[50];
wdenk1cb8e982003-03-06 21:55:29 +0000293 int i;
294 backup_t *b = (backup_t *) s;
295
wdenk1cb8e982003-03-06 21:55:29 +0000296 i = getenv_r("serial#", s, 32);
297 if ((i < 0) || strncmp (s, "VCMA9", 5)) {
298 get_backup_values (b);
299 if (strncmp (b->signature, "MPL\0", 4) != 0) {
300 puts ("### No HW ID - assuming VCMA9");
301 } else {
302 b->serial_name[5] = 0;
wdenk531716e2003-09-13 19:01:12 +0000303 Show_VCMA9_Info(b->serial_name, &b->serial_name[6]);
wdenk1cb8e982003-03-06 21:55:29 +0000304 }
305 } else {
306 s[5] = 0;
wdenk531716e2003-09-13 19:01:12 +0000307 Show_VCMA9_Info(s, &s[6]);
wdenk1cb8e982003-03-06 21:55:29 +0000308 }
wdenk531716e2003-09-13 19:01:12 +0000309 /*printf("\n");*/
wdenk1cb8e982003-03-06 21:55:29 +0000310 return(0);
311}
312
313
wdenk33149b82003-05-23 11:38:58 +0000314extern void mem_test_reloc(void);
wdenk1cb8e982003-03-06 21:55:29 +0000315
316int last_stage_init(void)
317{
wdenk33149b82003-05-23 11:38:58 +0000318 mem_test_reloc();
wdenk531716e2003-09-13 19:01:12 +0000319 checkboard();
Jean-Christophe PLAGNIOL-VILLARD28c34502009-05-16 12:14:56 +0200320 stdio_print_current_devices();
wdenk1cb8e982003-03-06 21:55:29 +0000321 check_env();
322 return 0;
323}
324
325/***************************************************************************
326 * some helping routines
327 */
wdenka2663ea2003-12-07 18:32:37 +0000328#if !CONFIG_USB_KEYBOARD
wdenk1cb8e982003-03-06 21:55:29 +0000329int overwrite_console(void)
330{
331 /* return TRUE if console should be overwritten */
332 return 0;
333}
wdenka2663ea2003-12-07 18:32:37 +0000334#endif
wdenk1cb8e982003-03-06 21:55:29 +0000335
336/************************************************************************
337* Print VCMA9 Info
338************************************************************************/
339void print_vcma9_info(void)
wdenk42d1f032003-10-15 23:53:47 +0000340{
Wolfgang Denkfc19e362007-10-13 23:51:14 +0200341 char s[50];
wdenk531716e2003-09-13 19:01:12 +0000342 int i;
wdenk42d1f032003-10-15 23:53:47 +0000343
wdenk531716e2003-09-13 19:01:12 +0000344 if ((i = getenv_r("serial#", s, 32)) < 0) {
345 puts ("### No HW ID - assuming VCMA9");
346 printf("i %d", i*24);
347 } else {
348 s[5] = 0;
349 Show_VCMA9_Info(s, &s[6]);
350 }
wdenk1cb8e982003-03-06 21:55:29 +0000351}