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