blob: eaeec828d70b0407c7cd27b529a73be3b2ef413e [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>
Ben Warrenb1c0eaa2009-08-25 13:09:37 -070029#include <netdev.h>
kevin.morfitt@fearnside-systems.co.ukac678042009-11-17 18:30:34 +090030#include <asm/arch/s3c24x0_cpu.h>
Jean-Christophe PLAGNIOL-VILLARD28c34502009-05-16 12:14:56 +020031#include <stdio_dev.h>
wdenk1cb8e982003-03-06 21:55:29 +000032#include <i2c.h>
33
34#include "vcma9.h"
35#include "../common/common_util.h"
36
Wolfgang Denkd87080b2006-03-31 18:32:53 +020037DECLARE_GLOBAL_DATA_PTR;
wdenk1cb8e982003-03-06 21:55:29 +000038
39#define FCLK_SPEED 1
40
41#if FCLK_SPEED==0 /* Fout = 203MHz, Fin = 12MHz for Audio */
42#define M_MDIV 0xC3
43#define M_PDIV 0x4
44#define M_SDIV 0x1
45#elif FCLK_SPEED==1 /* Fout = 202.8MHz */
46#define M_MDIV 0xA1
47#define M_PDIV 0x3
48#define M_SDIV 0x1
49#endif
50
51#define USB_CLOCK 1
52
53#if USB_CLOCK==0
54#define U_M_MDIV 0xA1
55#define U_M_PDIV 0x3
56#define U_M_SDIV 0x1
57#elif USB_CLOCK==1
58#define U_M_MDIV 0x48
59#define U_M_PDIV 0x3
60#define U_M_SDIV 0x2
61#endif
62
63static inline void delay(unsigned long loops)
64{
65 __asm__ volatile ("1:\n"
66 "subs %0, %1, #1\n"
67 "bne 1b":"=r" (loops):"0" (loops));
68}
69
70/*
71 * Miscellaneous platform dependent initialisations
72 */
73
74int board_init(void)
75{
kevin.morfitt@fearnside-systems.co.ukeb0ae7f2009-10-10 13:33:11 +090076 struct s3c24x0_clock_power * const clk_power =
77 s3c24x0_get_base_clock_power();
78 struct s3c24x0_gpio * const gpio = s3c24x0_get_base_gpio();
wdenk1cb8e982003-03-06 21:55:29 +000079
80 /* to reduce PLL lock time, adjust the LOCKTIME register */
wdenk48b42612003-06-19 23:01:32 +000081 clk_power->LOCKTIME = 0xFFFFFF;
wdenk1cb8e982003-03-06 21:55:29 +000082
83 /* configure MPLL */
wdenk48b42612003-06-19 23:01:32 +000084 clk_power->MPLLCON = ((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV);
wdenk1cb8e982003-03-06 21:55:29 +000085
86 /* some delay between MPLL and UPLL */
87 delay (4000);
88
89 /* configure UPLL */
wdenk48b42612003-06-19 23:01:32 +000090 clk_power->UPLLCON = ((U_M_MDIV << 12) + (U_M_PDIV << 4) + U_M_SDIV);
wdenk1cb8e982003-03-06 21:55:29 +000091
92 /* some delay between MPLL and UPLL */
93 delay (8000);
94
95 /* set up the I/O ports */
wdenk48b42612003-06-19 23:01:32 +000096 gpio->GPACON = 0x007FFFFF;
97 gpio->GPBCON = 0x002AAAAA;
98 gpio->GPBUP = 0x000002BF;
99 gpio->GPCCON = 0xAAAAAAAA;
100 gpio->GPCUP = 0x0000FFFF;
101 gpio->GPDCON = 0xAAAAAAAA;
102 gpio->GPDUP = 0x0000FFFF;
103 gpio->GPECON = 0xAAAAAAAA;
104 gpio->GPEUP = 0x000037F7;
105 gpio->GPFCON = 0x00000000;
106 gpio->GPFUP = 0x00000000;
107 gpio->GPGCON = 0xFFEAFF5A;
108 gpio->GPGUP = 0x0000F0DC;
109 gpio->GPHCON = 0x0028AAAA;
110 gpio->GPHUP = 0x00000656;
wdenk1cb8e982003-03-06 21:55:29 +0000111
112 /* setup correct IRQ modes for NIC */
wdenk48b42612003-06-19 23:01:32 +0000113 gpio->EXTINT2 = (gpio->EXTINT2 & ~(7<<8)) | (4<<8); /* rising edge mode */
114
115 /* select USB port 2 to be host or device (fix to host for now) */
116 gpio->MISCCR |= 0x08;
wdenk1cb8e982003-03-06 21:55:29 +0000117
118 /* init serial */
119 gd->baudrate = CONFIG_BAUDRATE;
120 gd->have_console = 1;
121 serial_init();
122
123 /* arch number of VCMA9-Board */
wdenk731215e2004-10-10 18:41:04 +0000124 gd->bd->bi_arch_number = MACH_TYPE_MPL_VCMA9;
wdenk1cb8e982003-03-06 21:55:29 +0000125
126 /* adress of boot parameters */
127 gd->bd->bi_boot_params = 0x30000100;
128
129 icache_enable();
130 dcache_enable();
131
132 return 0;
133}
134
wdenk1cb8e982003-03-06 21:55:29 +0000135/*
wdenk48b42612003-06-19 23:01:32 +0000136 * NAND flash initialization.
137 */
Jon Loeliger3fe00102007-07-09 18:38:39 -0500138#if defined(CONFIG_CMD_NAND)
wdenka43278a2003-09-11 19:48:06 +0000139extern ulong
wdenk48b42612003-06-19 23:01:32 +0000140nand_probe(ulong physadr);
141
142
143static inline void NF_Reset(void)
144{
145 int i;
146
147 NF_SetCE(NFCE_LOW);
148 NF_Cmd(0xFF); /* reset command */
149 for(i = 0; i < 10; i++); /* tWB = 100ns. */
150 NF_WaitRB(); /* wait 200~500us; */
151 NF_SetCE(NFCE_HIGH);
152}
153
154
155static inline void NF_Init(void)
156{
wdenk531716e2003-09-13 19:01:12 +0000157#if 0 /* a little bit too optimistic */
wdenk48b42612003-06-19 23:01:32 +0000158#define TACLS 0
159#define TWRPH0 3
160#define TWRPH1 0
wdenk531716e2003-09-13 19:01:12 +0000161#else
162#define TACLS 0
163#define TWRPH0 4
164#define TWRPH1 2
165#endif
166
wdenk48b42612003-06-19 23:01:32 +0000167 NF_Conf((1<<15)|(0<<14)|(0<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0));
wdenk8bde7f72003-06-27 21:31:46 +0000168 /*nand->NFCONF = (1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0); */
169 /* 1 1 1 1, 1 xxx, r xxx, r xxx */
170 /* En 512B 4step ECCR nFCE=H tACLS tWRPH0 tWRPH1 */
wdenk48b42612003-06-19 23:01:32 +0000171
172 NF_Reset();
173}
174
175void
176nand_init(void)
177{
kevin.morfitt@fearnside-systems.co.ukeb0ae7f2009-10-10 13:33:11 +0900178 struct s3c2410_nand * const nand = s3c2410_get_base_nand();
wdenk48b42612003-06-19 23:01:32 +0000179
180 NF_Init();
wdenka43278a2003-09-11 19:48:06 +0000181#ifdef DEBUG
wdenk48b42612003-06-19 23:01:32 +0000182 printf("NAND flash probing at 0x%.8lX\n", (ulong)nand);
wdenka43278a2003-09-11 19:48:06 +0000183#endif
wdenk531716e2003-09-13 19:01:12 +0000184 printf ("%4lu MB\n", nand_probe((ulong)nand) >> 20);
wdenk48b42612003-06-19 23:01:32 +0000185}
186#endif
187
188/*
wdenk1cb8e982003-03-06 21:55:29 +0000189 * Get some Board/PLD Info
190 */
191
wdenk531716e2003-09-13 19:01:12 +0000192static u8 Get_PLD_ID(void)
wdenk1cb8e982003-03-06 21:55:29 +0000193{
kevin.morfitt@fearnside-systems.co.ukeb0ae7f2009-10-10 13:33:11 +0900194 VCMA9_PLD * const pld = VCMA9_get_base_PLD();
wdenk42d1f032003-10-15 23:53:47 +0000195
wdenk531716e2003-09-13 19:01:12 +0000196 return(pld->ID);
wdenk1cb8e982003-03-06 21:55:29 +0000197}
198
wdenk531716e2003-09-13 19:01:12 +0000199static u8 Get_PLD_BOARD(void)
wdenk1cb8e982003-03-06 21:55:29 +0000200{
kevin.morfitt@fearnside-systems.co.ukeb0ae7f2009-10-10 13:33:11 +0900201 VCMA9_PLD * const pld = VCMA9_get_base_PLD();
wdenk42d1f032003-10-15 23:53:47 +0000202
wdenk531716e2003-09-13 19:01:12 +0000203 return(pld->BOARD);
wdenk1cb8e982003-03-06 21:55:29 +0000204}
205
wdenk531716e2003-09-13 19:01:12 +0000206static u8 Get_PLD_SDRAM(void)
207{
kevin.morfitt@fearnside-systems.co.ukeb0ae7f2009-10-10 13:33:11 +0900208 VCMA9_PLD * const pld = VCMA9_get_base_PLD();
wdenk42d1f032003-10-15 23:53:47 +0000209
wdenk531716e2003-09-13 19:01:12 +0000210 return(pld->SDRAM);
211}
212
213static u8 Get_PLD_Version(void)
wdenk1cb8e982003-03-06 21:55:29 +0000214{
215 return((Get_PLD_ID() >> 4) & 0x0F);
216}
217
wdenk531716e2003-09-13 19:01:12 +0000218static u8 Get_PLD_Revision(void)
wdenk1cb8e982003-03-06 21:55:29 +0000219{
220 return(Get_PLD_ID() & 0x0F);
221}
222
wdenk34b30492003-09-16 21:07:28 +0000223#if 0 /* not used */
wdenk1cb8e982003-03-06 21:55:29 +0000224static int Get_Board_Config(void)
225{
wdenk531716e2003-09-13 19:01:12 +0000226 u8 config = Get_PLD_BOARD() & 0x03;
wdenk1cb8e982003-03-06 21:55:29 +0000227
228 if (config == 3)
229 return 1;
230 else
231 return 0;
232}
wdenk34b30492003-09-16 21:07:28 +0000233#endif
wdenk1cb8e982003-03-06 21:55:29 +0000234
235static uchar Get_Board_PCB(void)
236{
237 return(((Get_PLD_BOARD() >> 4) & 0x03) + 'A');
238}
239
wdenk531716e2003-09-13 19:01:12 +0000240static u8 Get_SDRAM_ChipNr(void)
241{
242 switch ((Get_PLD_SDRAM() >> 4) & 0x0F) {
243 case 0: return 4;
244 case 1: return 1;
245 case 2: return 2;
246 default: return 0;
247 }
248}
249
250static ulong Get_SDRAM_ChipSize(void)
251{
252 switch (Get_PLD_SDRAM() & 0x0F) {
253 case 0: return 16 * (1024*1024);
254 case 1: return 32 * (1024*1024);
255 case 2: return 8 * (1024*1024);
256 case 3: return 8 * (1024*1024);
257 default: return 0;
wdenk42d1f032003-10-15 23:53:47 +0000258 }
wdenk531716e2003-09-13 19:01:12 +0000259}
260static const char * Get_SDRAM_ChipGeom(void)
261{
262 switch (Get_PLD_SDRAM() & 0x0F) {
263 case 0: return "4Mx8x4";
264 case 1: return "8Mx8x4";
265 case 2: return "2Mx8x4";
266 case 3: return "4Mx8x2";
267 default: return "unknown";
268 }
269}
270
271static void Show_VCMA9_Info(char *board_name, char *serial)
272{
273 printf("Board: %s SN: %s PCB Rev: %c PLD(%d,%d)\n",
274 board_name, serial, Get_Board_PCB(), Get_PLD_Version(), Get_PLD_Revision());
275 printf("SDRAM: %d chips %s\n", Get_SDRAM_ChipNr(), Get_SDRAM_ChipGeom());
276}
277
278int dram_init(void)
279{
wdenk531716e2003-09-13 19:01:12 +0000280 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
281 gd->bd->bi_dram[0].size = Get_SDRAM_ChipSize() * Get_SDRAM_ChipNr();
282
283 return 0;
284}
285
wdenk1cb8e982003-03-06 21:55:29 +0000286/* ------------------------------------------------------------------------- */
287
288/*
289 * Check Board Identity:
290 */
291
292int checkboard(void)
293{
Wolfgang Denkfc19e362007-10-13 23:51:14 +0200294 char s[50];
wdenk1cb8e982003-03-06 21:55:29 +0000295 int i;
296 backup_t *b = (backup_t *) s;
297
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200298 i = getenv_f("serial#", s, 32);
wdenk1cb8e982003-03-06 21:55:29 +0000299 if ((i < 0) || strncmp (s, "VCMA9", 5)) {
300 get_backup_values (b);
301 if (strncmp (b->signature, "MPL\0", 4) != 0) {
302 puts ("### No HW ID - assuming VCMA9");
303 } else {
304 b->serial_name[5] = 0;
wdenk531716e2003-09-13 19:01:12 +0000305 Show_VCMA9_Info(b->serial_name, &b->serial_name[6]);
wdenk1cb8e982003-03-06 21:55:29 +0000306 }
307 } else {
308 s[5] = 0;
wdenk531716e2003-09-13 19:01:12 +0000309 Show_VCMA9_Info(s, &s[6]);
wdenk1cb8e982003-03-06 21:55:29 +0000310 }
wdenk531716e2003-09-13 19:01:12 +0000311 /*printf("\n");*/
wdenk1cb8e982003-03-06 21:55:29 +0000312 return(0);
313}
314
315
wdenk1cb8e982003-03-06 21:55:29 +0000316int last_stage_init(void)
317{
wdenk531716e2003-09-13 19:01:12 +0000318 checkboard();
Jean-Christophe PLAGNIOL-VILLARD28c34502009-05-16 12:14:56 +0200319 stdio_print_current_devices();
wdenk1cb8e982003-03-06 21:55:29 +0000320 check_env();
321 return 0;
322}
323
324/***************************************************************************
325 * some helping routines
326 */
wdenka2663ea2003-12-07 18:32:37 +0000327#if !CONFIG_USB_KEYBOARD
wdenk1cb8e982003-03-06 21:55:29 +0000328int overwrite_console(void)
329{
330 /* return TRUE if console should be overwritten */
331 return 0;
332}
wdenka2663ea2003-12-07 18:32:37 +0000333#endif
wdenk1cb8e982003-03-06 21:55:29 +0000334
335/************************************************************************
336* Print VCMA9 Info
337************************************************************************/
338void print_vcma9_info(void)
wdenk42d1f032003-10-15 23:53:47 +0000339{
Wolfgang Denkfc19e362007-10-13 23:51:14 +0200340 char s[50];
wdenk531716e2003-09-13 19:01:12 +0000341 int i;
wdenk42d1f032003-10-15 23:53:47 +0000342
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200343 if ((i = getenv_f("serial#", s, 32)) < 0) {
wdenk531716e2003-09-13 19:01:12 +0000344 puts ("### No HW ID - assuming VCMA9");
345 printf("i %d", i*24);
346 } else {
347 s[5] = 0;
348 Show_VCMA9_Info(s, &s[6]);
349 }
wdenk1cb8e982003-03-06 21:55:29 +0000350}
Ben Warrenb1c0eaa2009-08-25 13:09:37 -0700351
352#ifdef CONFIG_CMD_NET
353int board_eth_init(bd_t *bis)
354{
355 int rc = 0;
356#ifdef CONFIG_CS8900
357 rc = cs8900_initialize(0, CONFIG_CS8900_BASE);
358#endif
359 return rc;
360}
361#endif