wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 1 | /* |
| 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 Warren | 3bf5d83 | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 29 | #include <netdev.h> |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 30 | #include <s3c2410.h> |
Jean-Christophe PLAGNIOL-VILLARD | d4303af | 2009-05-16 12:14:56 +0200 | [diff] [blame] | 31 | #include <stdio_dev.h> |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 32 | #include <i2c.h> |
| 33 | |
| 34 | #include "vcma9.h" |
| 35 | #include "../common/common_util.h" |
| 36 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 37 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 38 | |
| 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 | |
| 63 | static 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 | |
| 74 | int board_init(void) |
| 75 | { |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 76 | S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER(); |
| 77 | S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 78 | |
| 79 | /* to reduce PLL lock time, adjust the LOCKTIME register */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 80 | clk_power->LOCKTIME = 0xFFFFFF; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 81 | |
| 82 | /* configure MPLL */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 83 | clk_power->MPLLCON = ((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 84 | |
| 85 | /* some delay between MPLL and UPLL */ |
| 86 | delay (4000); |
| 87 | |
| 88 | /* configure UPLL */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 89 | clk_power->UPLLCON = ((U_M_MDIV << 12) + (U_M_PDIV << 4) + U_M_SDIV); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 90 | |
| 91 | /* some delay between MPLL and UPLL */ |
| 92 | delay (8000); |
| 93 | |
| 94 | /* set up the I/O ports */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 95 | gpio->GPACON = 0x007FFFFF; |
| 96 | gpio->GPBCON = 0x002AAAAA; |
| 97 | gpio->GPBUP = 0x000002BF; |
| 98 | gpio->GPCCON = 0xAAAAAAAA; |
| 99 | gpio->GPCUP = 0x0000FFFF; |
| 100 | gpio->GPDCON = 0xAAAAAAAA; |
| 101 | gpio->GPDUP = 0x0000FFFF; |
| 102 | gpio->GPECON = 0xAAAAAAAA; |
| 103 | gpio->GPEUP = 0x000037F7; |
| 104 | gpio->GPFCON = 0x00000000; |
| 105 | gpio->GPFUP = 0x00000000; |
| 106 | gpio->GPGCON = 0xFFEAFF5A; |
| 107 | gpio->GPGUP = 0x0000F0DC; |
| 108 | gpio->GPHCON = 0x0028AAAA; |
| 109 | gpio->GPHUP = 0x00000656; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 110 | |
| 111 | /* setup correct IRQ modes for NIC */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 112 | gpio->EXTINT2 = (gpio->EXTINT2 & ~(7<<8)) | (4<<8); /* rising edge mode */ |
| 113 | |
| 114 | /* select USB port 2 to be host or device (fix to host for now) */ |
| 115 | gpio->MISCCR |= 0x08; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 116 | |
| 117 | /* init serial */ |
| 118 | gd->baudrate = CONFIG_BAUDRATE; |
| 119 | gd->have_console = 1; |
| 120 | serial_init(); |
| 121 | |
| 122 | /* arch number of VCMA9-Board */ |
wdenk | 767fbd4 | 2004-10-10 18:41:04 +0000 | [diff] [blame] | 123 | gd->bd->bi_arch_number = MACH_TYPE_MPL_VCMA9; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 124 | |
| 125 | /* adress of boot parameters */ |
| 126 | gd->bd->bi_boot_params = 0x30000100; |
| 127 | |
| 128 | icache_enable(); |
| 129 | dcache_enable(); |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 134 | /* |
| 135 | * NAND flash initialization. |
| 136 | */ |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 137 | #if defined(CONFIG_CMD_NAND) |
wdenk | 934c4f8 | 2003-09-11 19:48:06 +0000 | [diff] [blame] | 138 | extern ulong |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 139 | nand_probe(ulong physadr); |
| 140 | |
| 141 | |
| 142 | static inline void NF_Reset(void) |
| 143 | { |
| 144 | int i; |
| 145 | |
| 146 | NF_SetCE(NFCE_LOW); |
| 147 | NF_Cmd(0xFF); /* reset command */ |
| 148 | for(i = 0; i < 10; i++); /* tWB = 100ns. */ |
| 149 | NF_WaitRB(); /* wait 200~500us; */ |
| 150 | NF_SetCE(NFCE_HIGH); |
| 151 | } |
| 152 | |
| 153 | |
| 154 | static inline void NF_Init(void) |
| 155 | { |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 156 | #if 0 /* a little bit too optimistic */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 157 | #define TACLS 0 |
| 158 | #define TWRPH0 3 |
| 159 | #define TWRPH1 0 |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 160 | #else |
| 161 | #define TACLS 0 |
| 162 | #define TWRPH0 4 |
| 163 | #define TWRPH1 2 |
| 164 | #endif |
| 165 | |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 166 | NF_Conf((1<<15)|(0<<14)|(0<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 167 | /*nand->NFCONF = (1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0); */ |
| 168 | /* 1 1 1 1, 1 xxx, r xxx, r xxx */ |
| 169 | /* En 512B 4step ECCR nFCE=H tACLS tWRPH0 tWRPH1 */ |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 170 | |
| 171 | NF_Reset(); |
| 172 | } |
| 173 | |
| 174 | void |
| 175 | nand_init(void) |
| 176 | { |
| 177 | S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); |
| 178 | |
| 179 | NF_Init(); |
wdenk | 934c4f8 | 2003-09-11 19:48:06 +0000 | [diff] [blame] | 180 | #ifdef DEBUG |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 181 | printf("NAND flash probing at 0x%.8lX\n", (ulong)nand); |
wdenk | 934c4f8 | 2003-09-11 19:48:06 +0000 | [diff] [blame] | 182 | #endif |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 183 | printf ("%4lu MB\n", nand_probe((ulong)nand) >> 20); |
wdenk | 7539dea | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 184 | } |
| 185 | #endif |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 186 | |
| 187 | /* |
| 188 | * Get some Board/PLD Info |
| 189 | */ |
| 190 | |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 191 | static u8 Get_PLD_ID(void) |
| 192 | { |
| 193 | VCMA9_PLD * const pld = VCMA9_GetBase_PLD(); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 194 | |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 195 | return(pld->ID); |
| 196 | } |
| 197 | |
| 198 | static u8 Get_PLD_BOARD(void) |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 199 | { |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 200 | VCMA9_PLD * const pld = VCMA9_GetBase_PLD(); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 201 | |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 202 | return(pld->BOARD); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 203 | } |
| 204 | |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 205 | static u8 Get_PLD_SDRAM(void) |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 206 | { |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 207 | VCMA9_PLD * const pld = VCMA9_GetBase_PLD(); |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 208 | |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 209 | return(pld->SDRAM); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 210 | } |
| 211 | |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 212 | static u8 Get_PLD_Version(void) |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 213 | { |
| 214 | return((Get_PLD_ID() >> 4) & 0x0F); |
| 215 | } |
| 216 | |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 217 | static u8 Get_PLD_Revision(void) |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 218 | { |
| 219 | return(Get_PLD_ID() & 0x0F); |
| 220 | } |
| 221 | |
wdenk | 5c34d45 | 2003-09-16 21:07:28 +0000 | [diff] [blame] | 222 | #if 0 /* not used */ |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 223 | static int Get_Board_Config(void) |
| 224 | { |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 225 | u8 config = Get_PLD_BOARD() & 0x03; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 226 | |
| 227 | if (config == 3) |
| 228 | return 1; |
| 229 | else |
| 230 | return 0; |
| 231 | } |
wdenk | 5c34d45 | 2003-09-16 21:07:28 +0000 | [diff] [blame] | 232 | #endif |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 233 | |
| 234 | static uchar Get_Board_PCB(void) |
| 235 | { |
| 236 | return(((Get_PLD_BOARD() >> 4) & 0x03) + 'A'); |
| 237 | } |
| 238 | |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 239 | static u8 Get_SDRAM_ChipNr(void) |
| 240 | { |
| 241 | switch ((Get_PLD_SDRAM() >> 4) & 0x0F) { |
| 242 | case 0: return 4; |
| 243 | case 1: return 1; |
| 244 | case 2: return 2; |
| 245 | default: return 0; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | static ulong Get_SDRAM_ChipSize(void) |
| 250 | { |
| 251 | switch (Get_PLD_SDRAM() & 0x0F) { |
| 252 | case 0: return 16 * (1024*1024); |
| 253 | case 1: return 32 * (1024*1024); |
| 254 | case 2: return 8 * (1024*1024); |
| 255 | case 3: return 8 * (1024*1024); |
| 256 | default: return 0; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 257 | } |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 258 | } |
| 259 | static const char * Get_SDRAM_ChipGeom(void) |
| 260 | { |
| 261 | switch (Get_PLD_SDRAM() & 0x0F) { |
| 262 | case 0: return "4Mx8x4"; |
| 263 | case 1: return "8Mx8x4"; |
| 264 | case 2: return "2Mx8x4"; |
| 265 | case 3: return "4Mx8x2"; |
| 266 | default: return "unknown"; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | static void Show_VCMA9_Info(char *board_name, char *serial) |
| 271 | { |
| 272 | printf("Board: %s SN: %s PCB Rev: %c PLD(%d,%d)\n", |
| 273 | board_name, serial, Get_Board_PCB(), Get_PLD_Version(), Get_PLD_Revision()); |
| 274 | printf("SDRAM: %d chips %s\n", Get_SDRAM_ChipNr(), Get_SDRAM_ChipGeom()); |
| 275 | } |
| 276 | |
| 277 | int dram_init(void) |
| 278 | { |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 279 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 280 | gd->bd->bi_dram[0].size = Get_SDRAM_ChipSize() * Get_SDRAM_ChipNr(); |
| 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 285 | /* ------------------------------------------------------------------------- */ |
| 286 | |
| 287 | /* |
| 288 | * Check Board Identity: |
| 289 | */ |
| 290 | |
| 291 | int checkboard(void) |
| 292 | { |
Wolfgang Denk | 585f088 | 2007-10-13 23:51:14 +0200 | [diff] [blame] | 293 | char s[50]; |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 294 | int i; |
| 295 | backup_t *b = (backup_t *) s; |
| 296 | |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 297 | i = getenv_r("serial#", s, 32); |
| 298 | if ((i < 0) || strncmp (s, "VCMA9", 5)) { |
| 299 | get_backup_values (b); |
| 300 | if (strncmp (b->signature, "MPL\0", 4) != 0) { |
| 301 | puts ("### No HW ID - assuming VCMA9"); |
| 302 | } else { |
| 303 | b->serial_name[5] = 0; |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 304 | Show_VCMA9_Info(b->serial_name, &b->serial_name[6]); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 305 | } |
| 306 | } else { |
| 307 | s[5] = 0; |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 308 | Show_VCMA9_Info(s, &s[6]); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 309 | } |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 310 | /*printf("\n");*/ |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 311 | return(0); |
| 312 | } |
| 313 | |
| 314 | |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 315 | extern void mem_test_reloc(void); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 316 | |
| 317 | int last_stage_init(void) |
| 318 | { |
wdenk | 7d07641 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 319 | mem_test_reloc(); |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 320 | checkboard(); |
Jean-Christophe PLAGNIOL-VILLARD | d4303af | 2009-05-16 12:14:56 +0200 | [diff] [blame] | 321 | stdio_print_current_devices(); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 322 | check_env(); |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | /*************************************************************************** |
| 327 | * some helping routines |
| 328 | */ |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 329 | #if !CONFIG_USB_KEYBOARD |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 330 | int overwrite_console(void) |
| 331 | { |
| 332 | /* return TRUE if console should be overwritten */ |
| 333 | return 0; |
| 334 | } |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 335 | #endif |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 336 | |
| 337 | /************************************************************************ |
| 338 | * Print VCMA9 Info |
| 339 | ************************************************************************/ |
| 340 | void print_vcma9_info(void) |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 341 | { |
Wolfgang Denk | 585f088 | 2007-10-13 23:51:14 +0200 | [diff] [blame] | 342 | char s[50]; |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 343 | int i; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 344 | |
wdenk | 2552190 | 2003-09-13 19:01:12 +0000 | [diff] [blame] | 345 | if ((i = getenv_r("serial#", s, 32)) < 0) { |
| 346 | puts ("### No HW ID - assuming VCMA9"); |
| 347 | printf("i %d", i*24); |
| 348 | } else { |
| 349 | s[5] = 0; |
| 350 | Show_VCMA9_Info(s, &s[6]); |
| 351 | } |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 352 | } |
Ben Warren | 3bf5d83 | 2009-08-25 13:09:37 -0700 | [diff] [blame] | 353 | |
| 354 | #ifdef CONFIG_CMD_NET |
| 355 | int board_eth_init(bd_t *bis) |
| 356 | { |
| 357 | int rc = 0; |
| 358 | #ifdef CONFIG_CS8900 |
| 359 | rc = cs8900_initialize(0, CONFIG_CS8900_BASE); |
| 360 | #endif |
| 361 | return rc; |
| 362 | } |
| 363 | #endif |