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 | |
| 35 | /* ------------------------------------------------------------------------- */ |
| 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 | { |
| 74 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 75 | S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER(); |
| 76 | S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO(); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 77 | |
| 78 | /* to reduce PLL lock time, adjust the LOCKTIME register */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 79 | clk_power->LOCKTIME = 0xFFFFFF; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 80 | |
| 81 | /* configure MPLL */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 82 | clk_power->MPLLCON = ((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 83 | |
| 84 | /* some delay between MPLL and UPLL */ |
| 85 | delay (4000); |
| 86 | |
| 87 | /* configure UPLL */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 88 | 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] | 89 | |
| 90 | /* some delay between MPLL and UPLL */ |
| 91 | delay (8000); |
| 92 | |
| 93 | /* set up the I/O ports */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 94 | 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; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 109 | |
| 110 | /* setup correct IRQ modes for NIC */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 111 | 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; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 115 | |
| 116 | /* init serial */ |
| 117 | gd->baudrate = CONFIG_BAUDRATE; |
| 118 | gd->have_console = 1; |
| 119 | serial_init(); |
| 120 | |
| 121 | /* arch number of VCMA9-Board */ |
| 122 | gd->bd->bi_arch_number = 227; |
| 123 | |
| 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 | |
| 133 | int dram_init(void) |
| 134 | { |
| 135 | DECLARE_GLOBAL_DATA_PTR; |
| 136 | |
| 137 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 138 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | /* |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 144 | * NAND flash initialization. |
| 145 | */ |
| 146 | #if (CONFIG_COMMANDS & CFG_CMD_NAND) |
wdenk | a43278a | 2003-09-11 19:48:06 +0000 | [diff] [blame^] | 147 | extern ulong |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 148 | nand_probe(ulong physadr); |
| 149 | |
| 150 | |
| 151 | static inline void NF_Reset(void) |
| 152 | { |
| 153 | int i; |
| 154 | |
| 155 | NF_SetCE(NFCE_LOW); |
| 156 | NF_Cmd(0xFF); /* reset command */ |
| 157 | for(i = 0; i < 10; i++); /* tWB = 100ns. */ |
| 158 | NF_WaitRB(); /* wait 200~500us; */ |
| 159 | NF_SetCE(NFCE_HIGH); |
| 160 | } |
| 161 | |
| 162 | |
| 163 | static inline void NF_Init(void) |
| 164 | { |
| 165 | #define TACLS 0 |
| 166 | #define TWRPH0 3 |
| 167 | #define TWRPH1 0 |
| 168 | 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] | 169 | /*nand->NFCONF = (1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0); */ |
| 170 | /* 1 1 1 1, 1 xxx, r xxx, r xxx */ |
| 171 | /* En 512B 4step ECCR nFCE=H tACLS tWRPH0 tWRPH1 */ |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 172 | |
| 173 | NF_Reset(); |
| 174 | } |
| 175 | |
| 176 | void |
| 177 | nand_init(void) |
| 178 | { |
| 179 | S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); |
wdenk | a43278a | 2003-09-11 19:48:06 +0000 | [diff] [blame^] | 180 | unsigned totlen; |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 181 | |
| 182 | NF_Init(); |
wdenk | a43278a | 2003-09-11 19:48:06 +0000 | [diff] [blame^] | 183 | #ifdef DEBUG |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 184 | printf("NAND flash probing at 0x%.8lX\n", (ulong)nand); |
wdenk | a43278a | 2003-09-11 19:48:06 +0000 | [diff] [blame^] | 185 | #endif |
| 186 | totlen = nand_probe((ulong)nand) >> 20; |
| 187 | |
| 188 | printf ("%4lu MB\n", totlen >> 20); |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 189 | } |
| 190 | #endif |
| 191 | |
| 192 | /* |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 193 | * Get some Board/PLD Info |
| 194 | */ |
| 195 | |
| 196 | static uchar Get_PLD_ID(void) |
| 197 | { |
| 198 | return(*(volatile uchar *)PLD_ID_REG); |
| 199 | } |
| 200 | |
| 201 | static uchar Get_PLD_BOARD(void) |
| 202 | { |
| 203 | return(*(volatile uchar *)PLD_BOARD_REG); |
| 204 | } |
| 205 | |
| 206 | static uchar Get_PLD_Version(void) |
| 207 | { |
| 208 | return((Get_PLD_ID() >> 4) & 0x0F); |
| 209 | } |
| 210 | |
| 211 | static uchar Get_PLD_Revision(void) |
| 212 | { |
| 213 | return(Get_PLD_ID() & 0x0F); |
| 214 | } |
| 215 | |
| 216 | static int Get_Board_Config(void) |
| 217 | { |
| 218 | uchar config = Get_PLD_BOARD() & 0x03; |
| 219 | |
| 220 | if (config == 3) |
| 221 | return 1; |
| 222 | else |
| 223 | return 0; |
| 224 | } |
| 225 | |
| 226 | static uchar Get_Board_PCB(void) |
| 227 | { |
| 228 | return(((Get_PLD_BOARD() >> 4) & 0x03) + 'A'); |
| 229 | } |
| 230 | |
| 231 | /* ------------------------------------------------------------------------- */ |
| 232 | |
| 233 | /* |
| 234 | * Check Board Identity: |
| 235 | */ |
| 236 | |
| 237 | int checkboard(void) |
| 238 | { |
| 239 | unsigned char s[50]; |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 240 | int i; |
| 241 | backup_t *b = (backup_t *) s; |
| 242 | |
| 243 | puts("Board: "); |
| 244 | |
| 245 | i = getenv_r("serial#", s, 32); |
| 246 | if ((i < 0) || strncmp (s, "VCMA9", 5)) { |
| 247 | get_backup_values (b); |
| 248 | if (strncmp (b->signature, "MPL\0", 4) != 0) { |
| 249 | puts ("### No HW ID - assuming VCMA9"); |
| 250 | } else { |
| 251 | b->serial_name[5] = 0; |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 252 | printf ("%s-%d PCB Rev %c SN: %s", b->serial_name, Get_Board_Config(), |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 253 | Get_Board_PCB(), &b->serial_name[6]); |
| 254 | } |
| 255 | } else { |
| 256 | s[5] = 0; |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 257 | printf ("%s-%d PCB Rev %c SN: %s", s, Get_Board_Config(), Get_Board_PCB(), |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 258 | &s[6]); |
| 259 | } |
| 260 | printf("\n"); |
| 261 | return(0); |
| 262 | } |
| 263 | |
| 264 | |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 265 | void print_vcma9_rev(void) |
| 266 | { |
wdenk | 48b4261 | 2003-06-19 23:01:32 +0000 | [diff] [blame] | 267 | printf("Board: VCMA9-%d PCB Rev: %c (PLD Ver: %d, Rev: %d)\n", |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 268 | Get_Board_Config(), Get_Board_PCB(), |
| 269 | Get_PLD_Version(), Get_PLD_Revision()); |
| 270 | } |
| 271 | |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 272 | extern void mem_test_reloc(void); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 273 | |
| 274 | int last_stage_init(void) |
| 275 | { |
wdenk | 33149b8 | 2003-05-23 11:38:58 +0000 | [diff] [blame] | 276 | mem_test_reloc(); |
wdenk | 1cb8e98 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 277 | print_vcma9_rev(); |
| 278 | show_stdio_dev(); |
| 279 | check_env(); |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | /*************************************************************************** |
| 284 | * some helping routines |
| 285 | */ |
| 286 | |
| 287 | int overwrite_console(void) |
| 288 | { |
| 289 | /* return TRUE if console should be overwritten */ |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | |
| 294 | /************************************************************************ |
| 295 | * Print VCMA9 Info |
| 296 | ************************************************************************/ |
| 297 | void print_vcma9_info(void) |
| 298 | { |
| 299 | print_vcma9_rev(); |
| 300 | } |